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