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