Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: content/browser/renderer_host/media/media_stream_dispatcher_host_unittest.cc

Issue 88283002: Reland review 34393006: Refactor MediaStreamManager to not output real device id. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 #include <queue> 6 #include <queue>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "content/browser/browser_thread_impl.h" 12 #include "content/browser/browser_thread_impl.h"
13 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" 13 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h"
14 #include "content/browser/renderer_host/media/media_stream_manager.h" 14 #include "content/browser/renderer_host/media/media_stream_manager.h"
15 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 15 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
16 #include "content/common/media/media_stream_messages.h" 16 #include "content/common/media/media_stream_messages.h"
17 #include "content/common/media/media_stream_options.h" 17 #include "content/common/media/media_stream_options.h"
18 #include "content/public/browser/media_device_id.h"
18 #include "content/public/test/mock_resource_context.h" 19 #include "content/public/test/mock_resource_context.h"
19 #include "content/public/test/test_browser_thread_bundle.h" 20 #include "content/public/test/test_browser_thread_bundle.h"
20 #include "content/test/test_content_browser_client.h" 21 #include "content/test/test_content_browser_client.h"
21 #include "content/test/test_content_client.h" 22 #include "content/test/test_content_client.h"
22 #include "ipc/ipc_message_macros.h" 23 #include "ipc/ipc_message_macros.h"
23 #include "media/audio/audio_manager.h" 24 #include "media/audio/mock_audio_manager.h"
24 #include "media/video/capture/fake_video_capture_device.h" 25 #include "media/video/capture/fake_video_capture_device.h"
25 #include "net/url_request/url_request_context.h" 26 #include "net/url_request/url_request_context.h"
26 #include "testing/gmock/include/gmock/gmock.h" 27 #include "testing/gmock/include/gmock/gmock.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 29
29 using ::testing::_; 30 using ::testing::_;
30 using ::testing::DeleteArg; 31 using ::testing::DeleteArg;
31 using ::testing::DoAll; 32 using ::testing::DoAll;
32 using ::testing::Return; 33 using ::testing::Return;
33 using ::testing::SaveArg; 34 using ::testing::SaveArg;
(...skipping 18 matching lines...) Expand all
52 void(int routing_id, int request_id, int audio_array_size, 53 void(int routing_id, int request_id, int audio_array_size,
53 int video_array_size)); 54 int video_array_size));
54 MOCK_METHOD2(OnStreamGenerationFailed, void(int routing_id, int request_id)); 55 MOCK_METHOD2(OnStreamGenerationFailed, void(int routing_id, int request_id));
55 MOCK_METHOD1(OnDeviceStopped, void(int routing_id)); 56 MOCK_METHOD1(OnDeviceStopped, void(int routing_id));
56 MOCK_METHOD2(OnDeviceOpened, void(int routing_id, int request_id)); 57 MOCK_METHOD2(OnDeviceOpened, void(int routing_id, int request_id));
57 58
58 // Accessor to private functions. 59 // Accessor to private functions.
59 void OnGenerateStream(int render_view_id, 60 void OnGenerateStream(int render_view_id,
60 int page_request_id, 61 int page_request_id,
61 const StreamOptions& components, 62 const StreamOptions& components,
63 const GURL& security_origin,
62 const base::Closure& quit_closure) { 64 const base::Closure& quit_closure) {
63 quit_closures_.push(quit_closure); 65 quit_closures_.push(quit_closure);
64 MediaStreamDispatcherHost::OnGenerateStream( 66 MediaStreamDispatcherHost::OnGenerateStream(
65 render_view_id, page_request_id, components, GURL()); 67 render_view_id, page_request_id, components, security_origin);
66 } 68 }
67 69
68 void OnStopStreamDevice(int render_view_id, 70 void OnStopStreamDevice(int render_view_id,
69 const std::string& device_id) { 71 const std::string& device_id) {
70 MediaStreamDispatcherHost::OnStopStreamDevice(render_view_id, device_id); 72 MediaStreamDispatcherHost::OnStopStreamDevice(render_view_id, device_id);
71 } 73 }
72 74
73 void OnOpenDevice(int render_view_id, 75 void OnOpenDevice(int render_view_id,
74 int page_request_id, 76 int page_request_id,
75 const std::string& device_id, 77 const std::string& device_id,
76 MediaStreamType type, 78 MediaStreamType type,
79 const GURL& security_origin,
77 const base::Closure& quit_closure) { 80 const base::Closure& quit_closure) {
78 quit_closures_.push(quit_closure); 81 quit_closures_.push(quit_closure);
79 MediaStreamDispatcherHost::OnOpenDevice( 82 MediaStreamDispatcherHost::OnOpenDevice(
80 render_view_id, page_request_id, device_id, type, GURL()); 83 render_view_id, page_request_id, device_id, type, security_origin);
81 } 84 }
82 85
83 bool FindExistingRequestedDeviceInfo(const std::string& device_id, 86 void OnEnumerateDevices(int render_view_id,
84 MediaStreamRequestType request_type, 87 int page_request_id,
85 StreamDeviceInfo* device_info) { 88 MediaStreamType type,
86 MediaRequestState request_state; 89 const GURL& security_origin,
87 return media_stream_manager_->FindExistingRequestedDeviceInfo( 90 const base::Closure& quit_closure) {
88 kProcessId, kRenderId, request_type, device_id, device_info, 91 quit_closures_.push(quit_closure);
89 &request_state); 92 MediaStreamDispatcherHost::OnEnumerateDevices(
93 render_view_id, page_request_id, type, security_origin);
90 } 94 }
91 95
92 std::string label_; 96 std::string label_;
93 StreamDeviceInfoArray audio_devices_; 97 StreamDeviceInfoArray audio_devices_;
94 StreamDeviceInfoArray video_devices_; 98 StreamDeviceInfoArray video_devices_;
95 StreamDeviceInfo opened_device_; 99 StreamDeviceInfo opened_device_;
100 StreamDeviceInfoArray enumerated_devices_;
96 101
97 private: 102 private:
98 virtual ~MockMediaStreamDispatcherHost() {} 103 virtual ~MockMediaStreamDispatcherHost() {}
99 104
100 // This method is used to dispatch IPC messages to the renderer. We intercept 105 // This method is used to dispatch IPC messages to the renderer. We intercept
101 // these messages here and dispatch to our mock methods to verify the 106 // these messages here and dispatch to our mock methods to verify the
102 // conversation between this object and the renderer. 107 // conversation between this object and the renderer.
103 virtual bool Send(IPC::Message* message) OVERRIDE { 108 virtual bool Send(IPC::Message* message) OVERRIDE {
104 CHECK(message); 109 CHECK(message);
105 110
106 // In this method we dispatch the messages to the according handlers as if 111 // In this method we dispatch the messages to the according handlers as if
107 // we are the renderer. 112 // we are the renderer.
108 bool handled = true; 113 bool handled = true;
109 IPC_BEGIN_MESSAGE_MAP(MockMediaStreamDispatcherHost, *message) 114 IPC_BEGIN_MESSAGE_MAP(MockMediaStreamDispatcherHost, *message)
110 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerated, OnStreamGenerated) 115 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerated, OnStreamGenerated)
111 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerationFailed, 116 IPC_MESSAGE_HANDLER(MediaStreamMsg_StreamGenerationFailed,
112 OnStreamGenerationFailed) 117 OnStreamGenerationFailed)
113 IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceStopped, OnDeviceStopped) 118 IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceStopped, OnDeviceStopped)
114 IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceOpened, OnDeviceOpened) 119 IPC_MESSAGE_HANDLER(MediaStreamMsg_DeviceOpened, OnDeviceOpened)
120 IPC_MESSAGE_HANDLER(MediaStreamMsg_DevicesEnumerated,
121 OnDevicesEnumerated)
115 IPC_MESSAGE_UNHANDLED(handled = false) 122 IPC_MESSAGE_UNHANDLED(handled = false)
116 IPC_END_MESSAGE_MAP() 123 IPC_END_MESSAGE_MAP()
117 EXPECT_TRUE(handled); 124 EXPECT_TRUE(handled);
118 125
119 delete message; 126 delete message;
120 return true; 127 return true;
121 } 128 }
122 129
123 // These handler methods do minimal things and delegate to the mock methods. 130 // These handler methods do minimal things and delegate to the mock methods.
124 void OnStreamGenerated( 131 void OnStreamGenerated(
(...skipping 21 matching lines...) Expand all
146 quit_closures_.pop(); 153 quit_closures_.pop();
147 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); 154 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure));
148 } 155 }
149 156
150 label_= ""; 157 label_= "";
151 } 158 }
152 159
153 void OnDeviceStopped(const IPC::Message& msg, 160 void OnDeviceStopped(const IPC::Message& msg,
154 const std::string& label, 161 const std::string& label,
155 const content::StreamDeviceInfo& device) { 162 const content::StreamDeviceInfo& device) {
163 if (IsVideoMediaType(device.device.type))
164 EXPECT_TRUE(StreamDeviceInfo::IsEqual(device, video_devices_[0]));
165 if (IsAudioMediaType(device.device.type))
166 EXPECT_TRUE(StreamDeviceInfo::IsEqual(device, audio_devices_[0]));
167
156 OnDeviceStopped(msg.routing_id()); 168 OnDeviceStopped(msg.routing_id());
157 // Notify that the event have occurred.
158 if (!quit_closures_.empty()) {
159 base::Closure quit_closure = quit_closures_.front();
160 quit_closures_.pop();
161 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure));
162 }
163 label_ = "";
164 } 169 }
165 170
166 void OnDeviceOpened(const IPC::Message& msg, 171 void OnDeviceOpened(const IPC::Message& msg,
167 int request_id, 172 int request_id,
168 const std::string& label, 173 const std::string& label,
169 const StreamDeviceInfo& device) { 174 const StreamDeviceInfo& device) {
170 base::Closure quit_closure = quit_closures_.front(); 175 base::Closure quit_closure = quit_closures_.front();
171 quit_closures_.pop(); 176 quit_closures_.pop();
172 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure)); 177 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure));
173 label_ = label; 178 label_ = label;
174 opened_device_ = device; 179 opened_device_ = device;
175 } 180 }
176 181
182 void OnDevicesEnumerated(const IPC::Message& msg,
183 int request_id,
184 const std::string& label,
185 const StreamDeviceInfoArray& devices) {
186 base::Closure quit_closure = quit_closures_.front();
187 quit_closures_.pop();
188 message_loop_->PostTask(FROM_HERE, base::ResetAndReturn(&quit_closure));
189 label_ = label;
190 enumerated_devices_ = devices;
191 }
192
177 scoped_refptr<base::MessageLoopProxy> message_loop_; 193 scoped_refptr<base::MessageLoopProxy> message_loop_;
178 194
179 std::queue<base::Closure> quit_closures_; 195 std::queue<base::Closure> quit_closures_;
180 }; 196 };
181 197
182 class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy { 198 class MockMediaStreamUIProxy : public FakeMediaStreamUIProxy {
183 public: 199 public:
184 MOCK_METHOD1(OnStarted, void(const base::Closure& stop)); 200 MOCK_METHOD1(OnStarted, void(const base::Closure& stop));
185 }; 201 };
186 202
187 class MediaStreamDispatcherHostTest : public testing::Test { 203 class MediaStreamDispatcherHostTest : public testing::Test {
188 public: 204 public:
189 MediaStreamDispatcherHostTest() 205 MediaStreamDispatcherHostTest()
190 : old_browser_client_(NULL), 206 : old_browser_client_(NULL),
191 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { 207 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
208 origin_("https://test.com") {
209 audio_manager_.reset(
210 new media::MockAudioManager(base::MessageLoopProxy::current()));
192 // Create our own MediaStreamManager. 211 // Create our own MediaStreamManager.
193 audio_manager_.reset(media::AudioManager::Create());
194 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); 212 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get()));
195 // Make sure we use fake devices to avoid long delays. 213 // Make sure we use fake devices to avoid long delays.
196 media_stream_manager_->UseFakeDevice(); 214 media_stream_manager_->UseFakeDevice();
197 215
198 host_ = new MockMediaStreamDispatcherHost(base::MessageLoopProxy::current(), 216 host_ = new MockMediaStreamDispatcherHost(base::MessageLoopProxy::current(),
199 media_stream_manager_.get()); 217 media_stream_manager_.get());
200 218
201 // Use the fake content client and browser. 219 // Use the fake content client and browser.
202 content_client_.reset(new TestContentClient()); 220 content_client_.reset(new TestContentClient());
203 SetContentClient(content_client_.get()); 221 SetContentClient(content_client_.get());
204 old_browser_client_ = SetBrowserClientForTesting(host_.get()); 222 old_browser_client_ = SetBrowserClientForTesting(host_.get());
205 } 223 }
206 224
207 virtual ~MediaStreamDispatcherHostTest() { 225 virtual ~MediaStreamDispatcherHostTest() {
208 // Recover the old browser client and content client. 226 }
209 SetBrowserClientForTesting(old_browser_client_); 227
210 content_client_.reset(); 228 virtual void SetUp() OVERRIDE {
211 media_stream_manager_->WillDestroyCurrentMessageLoop(); 229 media::FakeVideoCaptureDevice::GetDeviceNames(&physical_video_devices_);
230 ASSERT_GT(physical_video_devices_.size(), 0u);
231
232 audio_manager_->GetAudioInputDeviceNames(&physical_audio_devices_);
233 ASSERT_GT(physical_audio_devices_.size(), 0u);
212 } 234 }
213 235
214 virtual void TearDown() OVERRIDE { 236 virtual void TearDown() OVERRIDE {
215 host_->OnChannelClosing(); 237 host_->OnChannelClosing();
216 } 238 }
217 239
218 protected: 240 protected:
219 virtual void SetupFakeUI(bool expect_started) { 241 virtual void SetupFakeUI(bool expect_started) {
220 scoped_ptr<MockMediaStreamUIProxy> stream_ui(new MockMediaStreamUIProxy()); 242 scoped_ptr<MockMediaStreamUIProxy> stream_ui(new MockMediaStreamUIProxy());
221 if (expect_started) { 243 if (expect_started) {
222 EXPECT_CALL(*stream_ui, OnStarted(_)); 244 EXPECT_CALL(*stream_ui, OnStarted(_));
223 } 245 }
224 media_stream_manager_->UseFakeUI( 246 media_stream_manager_->UseFakeUI(
225 stream_ui.PassAs<FakeMediaStreamUIProxy>()); 247 stream_ui.PassAs<FakeMediaStreamUIProxy>());
226 } 248 }
227 249
228 void GenerateStreamAndWaitForResult(int render_view_id, 250 void GenerateStreamAndWaitForResult(int render_view_id,
229 int page_request_id, 251 int page_request_id,
230 const StreamOptions& options) { 252 const StreamOptions& options) {
231 base::RunLoop run_loop; 253 base::RunLoop run_loop;
232 host_->OnGenerateStream(render_view_id, page_request_id, options, 254 int expected_audio_array_size =
255 (options.audio_type != MEDIA_NO_SERVICE &&
256 physical_audio_devices_.size() > 0) ? 1 : 0;
257 int expected_video_array_size =
258 (options.video_type != MEDIA_NO_SERVICE &&
259 physical_video_devices_.size() > 0) ? 1 : 0;
260 EXPECT_CALL(*host_.get(), OnStreamGenerated(render_view_id, page_request_id,
261 expected_audio_array_size,
262 expected_video_array_size));
263 host_->OnGenerateStream(render_view_id, page_request_id, options, origin_,
233 run_loop.QuitClosure()); 264 run_loop.QuitClosure());
234 run_loop.Run(); 265 run_loop.Run();
266 EXPECT_FALSE(DoesContainRawIds(host_->audio_devices_));
267 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_));
268 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->audio_devices_, origin_));
269 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_));
270 }
271
272 void GenerateStreamAndWaitForFailure(int render_view_id,
273 int page_request_id,
274 const StreamOptions& options) {
275 base::RunLoop run_loop;
276 EXPECT_CALL(*host_.get(),
277 OnStreamGenerationFailed(render_view_id, page_request_id));
278 host_->OnGenerateStream(render_view_id, page_request_id, options, origin_,
279 run_loop.QuitClosure());
280 run_loop.Run();
235 } 281 }
236 282
237 void OpenVideoDeviceAndWaitForResult(int render_view_id, 283 void OpenVideoDeviceAndWaitForResult(int render_view_id,
238 int page_request_id, 284 int page_request_id,
239 const std::string& device_id) { 285 const std::string& device_id) {
240 base::RunLoop run_loop; 286 base::RunLoop run_loop;
241 host_->OnOpenDevice(render_view_id, page_request_id, device_id, 287 host_->OnOpenDevice(render_view_id, page_request_id, device_id,
242 MEDIA_DEVICE_VIDEO_CAPTURE, 288 MEDIA_DEVICE_VIDEO_CAPTURE, origin_,
243 run_loop.QuitClosure()); 289 run_loop.QuitClosure());
244 run_loop.Run(); 290 run_loop.Run();
291 EXPECT_FALSE(DoesContainRawIds(host_->video_devices_));
292 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->video_devices_, origin_));
293 }
294
295 void EnumerateDevicesAndWaitForResult(int render_view_id,
296 int page_request_id,
297 MediaStreamType type) {
298 base::RunLoop run_loop;
299 host_->OnEnumerateDevices(render_view_id, page_request_id, type, origin_,
300 run_loop.QuitClosure());
301 run_loop.Run();
302 ASSERT_FALSE(host_->enumerated_devices_.empty());
303 EXPECT_FALSE(DoesContainRawIds(host_->enumerated_devices_));
304 EXPECT_TRUE(DoesEveryDeviceMapToRawId(host_->enumerated_devices_, origin_));
305 }
306
307 bool DoesContainRawIds(const StreamDeviceInfoArray& devices) {
308 for (size_t i = 0; i < devices.size(); ++i) {
309 media::AudioDeviceNames::const_iterator audio_it =
310 physical_audio_devices_.begin();
311 for (; audio_it != physical_audio_devices_.end(); ++audio_it) {
312 if (audio_it->unique_id == devices[i].device.id)
313 return true;
314 }
315 media::VideoCaptureDevice::Names::const_iterator video_it =
316 physical_video_devices_.begin();
317 for (; video_it != physical_video_devices_.end(); ++video_it) {
318 if (video_it->id() == devices[i].device.id)
319 return true;
320 }
321 }
322 return false;
323 }
324
325 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices,
326 const GURL& origin) {
327 for (size_t i = 0; i < devices.size(); ++i) {
328 bool found_match = false;
329 media::AudioDeviceNames::const_iterator audio_it =
330 physical_audio_devices_.begin();
331 for (; audio_it != physical_audio_devices_.end(); ++audio_it) {
332 if (content::DoesMediaDeviceIDMatchHMAC(origin,
333 devices[i].device.id,
334 audio_it->unique_id)) {
335 EXPECT_FALSE(found_match);
336 found_match = true;
337 }
338 }
339 media::VideoCaptureDevice::Names::const_iterator video_it =
340 physical_video_devices_.begin();
341 for (; video_it != physical_video_devices_.end(); ++video_it) {
342 if (content::DoesMediaDeviceIDMatchHMAC(origin,
343 devices[i].device.id,
344 video_it->id())) {
345 EXPECT_FALSE(found_match);
346 found_match = true;
347 }
348 }
349 if (!found_match)
350 return false;
351 }
352 return true;
245 } 353 }
246 354
247 scoped_refptr<MockMediaStreamDispatcherHost> host_; 355 scoped_refptr<MockMediaStreamDispatcherHost> host_;
248 scoped_ptr<media::AudioManager> audio_manager_; 356 scoped_ptr<media::AudioManager> audio_manager_;
249 scoped_ptr<MediaStreamManager> media_stream_manager_; 357 scoped_ptr<MediaStreamManager> media_stream_manager_;
250 ContentBrowserClient* old_browser_client_; 358 ContentBrowserClient* old_browser_client_;
251 scoped_ptr<ContentClient> content_client_; 359 scoped_ptr<ContentClient> content_client_;
252 content::TestBrowserThreadBundle thread_bundle_; 360 content::TestBrowserThreadBundle thread_bundle_;
361 media::AudioDeviceNames physical_audio_devices_;
362 media::VideoCaptureDevice::Names physical_video_devices_;
363 GURL origin_;
253 }; 364 };
254 365
255 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { 366 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) {
256 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); 367 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE);
257 368
258 SetupFakeUI(true); 369 SetupFakeUI(true);
259 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1));
260 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); 370 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
261 371
262 EXPECT_EQ(host_->audio_devices_.size(), 0u); 372 EXPECT_EQ(host_->audio_devices_.size(), 0u);
263 EXPECT_EQ(host_->video_devices_.size(), 1u); 373 EXPECT_EQ(host_->video_devices_.size(), 1u);
264 } 374 }
265 375
376 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithAudioOnly) {
377 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, MEDIA_NO_SERVICE);
378
379 SetupFakeUI(true);
380 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
381
382 EXPECT_EQ(host_->audio_devices_.size(), 1u);
383 EXPECT_EQ(host_->video_devices_.size(), 0u);
384 }
385
266 // This test generates two streams with video only using the same render view 386 // This test generates two streams with video only using the same render view
267 // id. The same capture device with the same device and session id is expected 387 // id. The same capture device with the same device and session id is expected
268 // to be used. 388 // to be used.
269 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsFromSameRenderId) { 389 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsFromSameRenderId) {
270 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); 390 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE);
271 391
272 // Generate first stream. 392 // Generate first stream.
273 SetupFakeUI(true); 393 SetupFakeUI(true);
274 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1));
275 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); 394 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
276 395
277 // Check the latest generated stream. 396 // Check the latest generated stream.
278 EXPECT_EQ(host_->audio_devices_.size(), 0u); 397 EXPECT_EQ(host_->audio_devices_.size(), 0u);
279 EXPECT_EQ(host_->video_devices_.size(), 1u); 398 EXPECT_EQ(host_->video_devices_.size(), 1u);
280 const std::string label1 = host_->label_; 399 const std::string label1 = host_->label_;
281 const std::string device_id1 = host_->video_devices_.front().device.id; 400 const std::string device_id1 = host_->video_devices_.front().device.id;
282 const int session_id1 = host_->video_devices_.front().session_id; 401 const int session_id1 = host_->video_devices_.front().session_id;
283 402
284 // Generate second stream. 403 // Generate second stream.
285 SetupFakeUI(true); 404 SetupFakeUI(true);
286 EXPECT_CALL(*host_.get(),
287 OnStreamGenerated(kRenderId, kPageRequestId + 1, 0, 1));
288 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId + 1, options); 405 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId + 1, options);
289 406
290 // Check the latest generated stream. 407 // Check the latest generated stream.
291 EXPECT_EQ(host_->audio_devices_.size(), 0u); 408 EXPECT_EQ(host_->audio_devices_.size(), 0u);
292 EXPECT_EQ(host_->video_devices_.size(), 1u); 409 EXPECT_EQ(host_->video_devices_.size(), 1u);
293 const std::string label2 = host_->label_; 410 const std::string label2 = host_->label_;
294 const std::string device_id2 = host_->video_devices_.front().device.id; 411 const std::string device_id2 = host_->video_devices_.front().device.id;
295 int session_id2 = host_->video_devices_.front().session_id; 412 int session_id2 = host_->video_devices_.front().session_id;
296 EXPECT_EQ(device_id1, device_id2); 413 EXPECT_EQ(device_id1, device_id2);
297 EXPECT_EQ(session_id1, session_id2); 414 EXPECT_EQ(session_id1, session_id2);
298 EXPECT_NE(label1, label2); 415 EXPECT_NE(label1, label2);
299 } 416 }
300 417
301 TEST_F(MediaStreamDispatcherHostTest, 418 TEST_F(MediaStreamDispatcherHostTest,
302 GenerateStreamAndOpenDeviceFromSameRenderId) { 419 GenerateStreamAndOpenDeviceFromSameRenderId) {
303 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); 420 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE);
304 421
305 // Generate first stream. 422 // Generate first stream.
306 SetupFakeUI(true); 423 SetupFakeUI(true);
307 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1));
308 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); 424 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
309 425
310 EXPECT_EQ(host_->audio_devices_.size(), 0u); 426 EXPECT_EQ(host_->audio_devices_.size(), 0u);
311 EXPECT_EQ(host_->video_devices_.size(), 1u); 427 EXPECT_EQ(host_->video_devices_.size(), 1u);
312 const std::string label1 = host_->label_; 428 const std::string label1 = host_->label_;
313 const std::string device_id1 = host_->video_devices_.front().device.id; 429 const std::string device_id1 = host_->video_devices_.front().device.id;
314 const int session_id1 = host_->video_devices_.front().session_id; 430 const int session_id1 = host_->video_devices_.front().session_id;
315 431
316 // Generate second stream. 432 // Generate second stream.
317 OpenVideoDeviceAndWaitForResult(kRenderId, kPageRequestId, device_id1); 433 OpenVideoDeviceAndWaitForResult(kRenderId, kPageRequestId, device_id1);
318 434
319 const std::string device_id2 = host_->opened_device_.device.id; 435 const std::string device_id2 = host_->opened_device_.device.id;
320 const int session_id2 = host_->opened_device_.session_id; 436 const int session_id2 = host_->opened_device_.session_id;
321 const std::string label2 = host_->label_; 437 const std::string label2 = host_->label_;
322 438
323 EXPECT_EQ(device_id1, device_id2); 439 EXPECT_EQ(device_id1, device_id2);
324 EXPECT_NE(session_id1, session_id2); 440 EXPECT_NE(session_id1, session_id2);
325 EXPECT_NE(label1, label2); 441 EXPECT_NE(label1, label2);
326 } 442 }
327 443
328 444
329 // This test generates two streams with video only using two separate render 445 // This test generates two streams with video only using two separate render
330 // view ids. The same device id but different session ids are expected. 446 // view ids. The same device id but different session ids are expected.
331 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsDifferentRenderId) { 447 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsDifferentRenderId) {
332 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); 448 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE);
333 449
334 // Generate first stream. 450 // Generate first stream.
335 SetupFakeUI(true); 451 SetupFakeUI(true);
336 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1));
337 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); 452 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
338 453
339 // Check the latest generated stream. 454 // Check the latest generated stream.
340 EXPECT_EQ(host_->audio_devices_.size(), 0u); 455 EXPECT_EQ(host_->audio_devices_.size(), 0u);
341 EXPECT_EQ(host_->video_devices_.size(), 1u); 456 EXPECT_EQ(host_->video_devices_.size(), 1u);
342 const std::string label1 = host_->label_; 457 const std::string label1 = host_->label_;
343 const std::string device_id1 = host_->video_devices_.front().device.id; 458 const std::string device_id1 = host_->video_devices_.front().device.id;
344 const int session_id1 = host_->video_devices_.front().session_id; 459 const int session_id1 = host_->video_devices_.front().session_id;
345 460
346 // Generate second stream from another render view. 461 // Generate second stream from another render view.
347 SetupFakeUI(true); 462 SetupFakeUI(true);
348 EXPECT_CALL(*host_.get(),
349 OnStreamGenerated(kRenderId+1, kPageRequestId + 1, 0, 1));
350 GenerateStreamAndWaitForResult(kRenderId+1, kPageRequestId + 1, options); 463 GenerateStreamAndWaitForResult(kRenderId+1, kPageRequestId + 1, options);
351 464
352 // Check the latest generated stream. 465 // Check the latest generated stream.
353 EXPECT_EQ(host_->audio_devices_.size(), 0u); 466 EXPECT_EQ(host_->audio_devices_.size(), 0u);
354 EXPECT_EQ(host_->video_devices_.size(), 1u); 467 EXPECT_EQ(host_->video_devices_.size(), 1u);
355 const std::string label2 = host_->label_; 468 const std::string label2 = host_->label_;
356 const std::string device_id2 = host_->video_devices_.front().device.id; 469 const std::string device_id2 = host_->video_devices_.front().device.id;
357 const int session_id2 = host_->video_devices_.front().session_id; 470 const int session_id2 = host_->video_devices_.front().session_id;
358 EXPECT_EQ(device_id1, device_id2); 471 EXPECT_EQ(device_id1, device_id2);
359 EXPECT_NE(session_id1, session_id2); 472 EXPECT_NE(session_id1, session_id2);
360 EXPECT_NE(label1, label2); 473 EXPECT_NE(label1, label2);
361 } 474 }
362 475
363 // This test request two streams with video only without waiting for the first 476 // This test request two streams with video only without waiting for the first
364 // stream to be generated before requesting the second. 477 // stream to be generated before requesting the second.
365 // The same device id and session ids are expected. 478 // The same device id and session ids are expected.
366 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithoutWaiting) { 479 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithoutWaiting) {
367 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); 480 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE);
368 481
369 // Generate first stream. 482 // Generate first stream.
370 SetupFakeUI(true); 483 SetupFakeUI(true);
371 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1)); 484 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1));
372 485
373 // Generate second stream. 486 // Generate second stream.
374 EXPECT_CALL(*host_.get(), 487 EXPECT_CALL(*host_.get(),
375 OnStreamGenerated(kRenderId, kPageRequestId + 1, 0, 1)); 488 OnStreamGenerated(kRenderId, kPageRequestId + 1, 0, 1));
376 489
377 base::RunLoop run_loop1; 490 base::RunLoop run_loop1;
378 base::RunLoop run_loop2; 491 base::RunLoop run_loop2;
379 host_->OnGenerateStream(kRenderId, kPageRequestId, options, 492 host_->OnGenerateStream(kRenderId, kPageRequestId, options, origin_,
380 run_loop1.QuitClosure()); 493 run_loop1.QuitClosure());
381 host_->OnGenerateStream(kRenderId, kPageRequestId + 1, options, 494 host_->OnGenerateStream(kRenderId, kPageRequestId + 1, options, origin_,
382 run_loop2.QuitClosure()); 495 run_loop2.QuitClosure());
383 496
384 run_loop1.Run(); 497 run_loop1.Run();
385 run_loop2.Run(); 498 run_loop2.Run();
386 } 499 }
387 500
501 // Test that we can generate streams where a sourceId is specified in the
502 // request.
503 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) {
504 ASSERT_GE(physical_audio_devices_.size(), 1u);
505 ASSERT_GE(physical_video_devices_.size(), 1u);
506
507 media::AudioDeviceNames::const_iterator audio_it =
508 physical_audio_devices_.begin();
509 for (; audio_it != physical_audio_devices_.end(); ++audio_it) {
510 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE,
511 MEDIA_DEVICE_VIDEO_CAPTURE);
512 options.audio_device_id = content::GetHMACForMediaDeviceID(
513 origin_,
514 audio_it->unique_id);
515 ASSERT_FALSE(options.audio_device_id.empty());
516
517 // Generate first stream.
518 SetupFakeUI(true);
519 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
520 EXPECT_EQ(host_->audio_devices_[0].device.id, options.audio_device_id);
521 }
522
523 media::VideoCaptureDevice::Names::const_iterator video_it =
524 physical_video_devices_.begin();
525 for (; video_it != physical_video_devices_.end(); ++video_it) {
526 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE,
527 MEDIA_DEVICE_VIDEO_CAPTURE);
528 options.video_device_id = content::GetHMACForMediaDeviceID(origin_,
529 video_it->id());
530 ASSERT_FALSE(options.video_device_id.empty());
531
532 // Generate first stream.
533 SetupFakeUI(true);
534 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
535 EXPECT_EQ(host_->video_devices_[0].device.id, options.video_device_id);
536 }
537 }
538
539 // Test that generating a stream with an invalid video source id fail.
540 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithInvalidVideoSourceId) {
541 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE,
542 MEDIA_DEVICE_VIDEO_CAPTURE);
543 options.video_device_id = "invalid source id";
544
545 GenerateStreamAndWaitForFailure(kRenderId, kRenderId, options);
546 }
547
548 // Test that generating a stream with an invalid audio source id fail.
549 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithInvalidAudioSourceId) {
550 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE,
551 MEDIA_DEVICE_VIDEO_CAPTURE);
552 options.audio_device_id = "invalid source id";
553
554 GenerateStreamAndWaitForFailure(kRenderId, kRenderId, options);
555 }
556
557 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsNoAvailableVideoDevice) {
558 size_t number_of_fake_devices = physical_video_devices_.size();
559 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(0);
560 media::FakeVideoCaptureDevice::GetDeviceNames(&physical_video_devices_);
561 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, MEDIA_DEVICE_VIDEO_CAPTURE);
562
563 SetupFakeUI(true);
564 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
565 EXPECT_TRUE(host_->video_devices_.empty());
566
567 // Reset the number of fake devices for next test.
568 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(number_of_fake_devices);
569 }
570
571 // Test that if a OnStopStreamDevice message is received for a device that has
572 // been opened in a MediaStream and by pepper, the device is only stopped for
573 // the MediaStream.
388 TEST_F(MediaStreamDispatcherHostTest, StopDeviceInStream) { 574 TEST_F(MediaStreamDispatcherHostTest, StopDeviceInStream) {
389 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); 575 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE);
390 576
391 SetupFakeUI(true); 577 SetupFakeUI(true);
392 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1));
393 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); 578 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
394 579
395 const std::string device_id = host_->video_devices_.front().device.id; 580 std::string stream_request_label = host_->label_;
396 const int session_id = host_->video_devices_.front().session_id; 581 StreamDeviceInfo video_device_info = host_->video_devices_.front();
397 StreamDeviceInfo video_device_info; 582 ASSERT_EQ(1u, media_stream_manager_->GetDevicesOpenedByRequest(
398 EXPECT_TRUE(host_->FindExistingRequestedDeviceInfo(device_id, 583 stream_request_label).size());
399 MEDIA_GENERATE_STREAM,
400 &video_device_info));
401 EXPECT_EQ(video_device_info.device.id, device_id);
402 EXPECT_EQ(video_device_info.session_id, session_id);
403 584
404 OpenVideoDeviceAndWaitForResult(kRenderId, kPageRequestId, device_id); 585 // Open the same device by Pepper.
586 OpenVideoDeviceAndWaitForResult(kRenderId, kPageRequestId,
587 video_device_info.device.id);
588 std::string open_device_request_label = host_->label_;
405 589
406 host_->OnStopStreamDevice(kRenderId, device_id); 590 // Stop the device in the MediaStream.
591 host_->OnStopStreamDevice(kRenderId, video_device_info.device.id);
407 592
408 EXPECT_FALSE(host_->FindExistingRequestedDeviceInfo(device_id, 593 EXPECT_EQ(0u, media_stream_manager_->GetDevicesOpenedByRequest(
409 MEDIA_GENERATE_STREAM, 594 stream_request_label).size());
410 &video_device_info)); 595 EXPECT_EQ(1u, media_stream_manager_->GetDevicesOpenedByRequest(
411 EXPECT_TRUE(host_->FindExistingRequestedDeviceInfo(device_id, 596 open_device_request_label).size());
412 MEDIA_OPEN_DEVICE, 597 }
413 &video_device_info)); 598
599 TEST_F(MediaStreamDispatcherHostTest, StopDeviceInStreamAndRestart) {
600 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE,
601 MEDIA_DEVICE_VIDEO_CAPTURE);
602
603 SetupFakeUI(true);
604 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
605
606 std::string request_label1 = host_->label_;
607 StreamDeviceInfo video_device_info = host_->video_devices_.front();
608 // Expect that 1 audio and 1 video device has been opened.
609 EXPECT_EQ(2u, media_stream_manager_->GetDevicesOpenedByRequest(
610 request_label1).size());
611
612 host_->OnStopStreamDevice(kRenderId, video_device_info.device.id);
613 EXPECT_EQ(1u, media_stream_manager_->GetDevicesOpenedByRequest(
614 request_label1).size());
615
616 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
617 std::string request_label2 = host_->label_;
618
619 StreamDeviceInfoArray request1_devices =
620 media_stream_manager_->GetDevicesOpenedByRequest(request_label1);
621 StreamDeviceInfoArray request2_devices =
622 media_stream_manager_->GetDevicesOpenedByRequest(request_label2);
623
624 ASSERT_EQ(1u, request1_devices.size());
625 ASSERT_EQ(2u, request2_devices.size());
626
627 // Test that the same audio device has been opened in both streams.
628 EXPECT_TRUE(StreamDeviceInfo::IsEqual(request1_devices[0],
629 request2_devices[0]) ||
630 StreamDeviceInfo::IsEqual(request1_devices[0],
631 request2_devices[1]));
414 } 632 }
415 633
416 TEST_F(MediaStreamDispatcherHostTest, CancelPendingStreamsOnChannelClosing) { 634 TEST_F(MediaStreamDispatcherHostTest, CancelPendingStreamsOnChannelClosing) {
417 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); 635 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE);
418 636
419 base::RunLoop run_loop; 637 base::RunLoop run_loop;
420 638
421 // Create multiple GenerateStream requests. 639 // Create multiple GenerateStream requests.
422 size_t streams = 5; 640 size_t streams = 5;
423 for (size_t i = 1; i <= streams; ++i) { 641 for (size_t i = 1; i <= streams; ++i) {
424 host_->OnGenerateStream(kRenderId, kPageRequestId + i, options, 642 host_->OnGenerateStream(kRenderId, kPageRequestId + i, options, origin_,
425 run_loop.QuitClosure()); 643 run_loop.QuitClosure());
426 } 644 }
427 645
428 // Calling OnChannelClosing() to cancel all the pending requests. 646 // Calling OnChannelClosing() to cancel all the pending requests.
429 host_->OnChannelClosing(); 647 host_->OnChannelClosing();
430 run_loop.RunUntilIdle(); 648 run_loop.RunUntilIdle();
431 } 649 }
432 650
433 TEST_F(MediaStreamDispatcherHostTest, StopGeneratedStreamsOnChannelClosing) { 651 TEST_F(MediaStreamDispatcherHostTest, StopGeneratedStreamsOnChannelClosing) {
434 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); 652 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE);
435 653
436 // Create first group of streams. 654 // Create first group of streams.
437 size_t generated_streams = 3; 655 size_t generated_streams = 3;
438 for (size_t i = 0; i < generated_streams; ++i) { 656 for (size_t i = 0; i < generated_streams; ++i) {
439 SetupFakeUI(true); 657 SetupFakeUI(true);
440 EXPECT_CALL(*host_.get(),
441 OnStreamGenerated(kRenderId, kPageRequestId + i, 0, 1));
442 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId + i, options); 658 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId + i, options);
443 } 659 }
444 660
445 // Calling OnChannelClosing() to cancel all the pending/generated streams. 661 // Calling OnChannelClosing() to cancel all the pending/generated streams.
446 host_->OnChannelClosing(); 662 host_->OnChannelClosing();
447 base::RunLoop().RunUntilIdle(); 663 base::RunLoop().RunUntilIdle();
448 } 664 }
449 665
450 TEST_F(MediaStreamDispatcherHostTest, CloseFromUI) { 666 TEST_F(MediaStreamDispatcherHostTest, CloseFromUI) {
451 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); 667 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE);
452 668
453 base::Closure close_callback; 669 base::Closure close_callback;
454 scoped_ptr<MockMediaStreamUIProxy> stream_ui(new MockMediaStreamUIProxy()); 670 scoped_ptr<MockMediaStreamUIProxy> stream_ui(new MockMediaStreamUIProxy());
455 EXPECT_CALL(*stream_ui, OnStarted(_)) 671 EXPECT_CALL(*stream_ui, OnStarted(_))
456 .WillOnce(SaveArg<0>(&close_callback)); 672 .WillOnce(SaveArg<0>(&close_callback));
457 media_stream_manager_->UseFakeUI(stream_ui.PassAs<FakeMediaStreamUIProxy>()); 673 media_stream_manager_->UseFakeUI(stream_ui.PassAs<FakeMediaStreamUIProxy>());
458 674
459 EXPECT_CALL(*host_.get(), OnStreamGenerated(kRenderId, kPageRequestId, 0, 1));
460 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId));
461 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); 675 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
462 676
463 EXPECT_EQ(host_->audio_devices_.size(), 0u); 677 EXPECT_EQ(host_->audio_devices_.size(), 0u);
464 EXPECT_EQ(host_->video_devices_.size(), 1u); 678 EXPECT_EQ(host_->video_devices_.size(), 1u);
465 679
466 ASSERT_FALSE(close_callback.is_null()); 680 ASSERT_FALSE(close_callback.is_null());
681 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId));
467 close_callback.Run(); 682 close_callback.Run();
468 base::RunLoop().RunUntilIdle(); 683 base::RunLoop().RunUntilIdle();
469 } 684 }
470 685
686 // Test that the dispatcher is notified if a video device that is in use is
687 // being unplugged.
688 TEST_F(MediaStreamDispatcherHostTest, VideoDeviceUnplugged) {
689 size_t number_of_fake_devices = physical_video_devices_.size();
690 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, MEDIA_DEVICE_VIDEO_CAPTURE);
691 SetupFakeUI(true);
692 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
693 EXPECT_EQ(host_->audio_devices_.size(), 1u);
694 EXPECT_EQ(host_->video_devices_.size(), 1u);
695
696 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(0);
697
698 base::RunLoop run_loop;
699 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId))
700 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
701 media_stream_manager_->OnDevicesChanged(
702 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE);
703
704 run_loop.Run();
705
706 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(number_of_fake_devices);
707 }
708
709 TEST_F(MediaStreamDispatcherHostTest, EnumerateAudioDevices) {
710 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId,
711 MEDIA_DEVICE_AUDIO_CAPTURE);
712 }
713
714 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) {
715 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId,
716 MEDIA_DEVICE_VIDEO_CAPTURE);
717 }
718
471 }; // namespace content 719 }; // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698