| 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/browser/media_device_id.h" |
| 19 #include "content/public/test/mock_resource_context.h" | 19 #include "content/public/test/mock_resource_context.h" |
| 20 #include "content/public/test/test_browser_context.h" |
| 20 #include "content/public/test/test_browser_thread_bundle.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
| 21 #include "content/test/test_content_browser_client.h" | 22 #include "content/test/test_content_browser_client.h" |
| 22 #include "content/test/test_content_client.h" | 23 #include "content/test/test_content_client.h" |
| 23 #include "ipc/ipc_message_macros.h" | 24 #include "ipc/ipc_message_macros.h" |
| 24 #include "media/audio/audio_manager.h" | 25 #include "media/audio/audio_manager.h" |
| 25 #include "media/audio/audio_manager_base.h" | 26 #include "media/audio/audio_manager_base.h" |
| 26 #if defined(OS_ANDROID) | 27 #if defined(OS_ANDROID) |
| 27 #include "media/audio/android/audio_manager_android.h" | 28 #include "media/audio/android/audio_manager_android.h" |
| 28 #elif defined(OS_LINUX) || defined(OS_OPENBSD) | 29 #elif defined(OS_LINUX) || defined(OS_OPENBSD) |
| 29 #include "media/audio/linux/audio_manager_linux.h" | 30 #include "media/audio/linux/audio_manager_linux.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } | 78 } |
| 78 private: | 79 private: |
| 79 DISALLOW_COPY_AND_ASSIGN(MockAudioManager); | 80 DISALLOW_COPY_AND_ASSIGN(MockAudioManager); |
| 80 }; | 81 }; |
| 81 | 82 |
| 82 | 83 |
| 83 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, | 84 class MockMediaStreamDispatcherHost : public MediaStreamDispatcherHost, |
| 84 public TestContentBrowserClient { | 85 public TestContentBrowserClient { |
| 85 public: | 86 public: |
| 86 MockMediaStreamDispatcherHost( | 87 MockMediaStreamDispatcherHost( |
| 88 ResourceContext* resource_context, |
| 87 const scoped_refptr<base::MessageLoopProxy>& message_loop, | 89 const scoped_refptr<base::MessageLoopProxy>& message_loop, |
| 88 MediaStreamManager* manager) | 90 MediaStreamManager* manager) |
| 89 : MediaStreamDispatcherHost(kProcessId, manager), | 91 : MediaStreamDispatcherHost(kProcessId, resource_context, manager), |
| 90 message_loop_(message_loop) {} | 92 message_loop_(message_loop) {} |
| 91 | 93 |
| 92 // A list of mock methods. | 94 // A list of mock methods. |
| 93 MOCK_METHOD4(OnStreamGenerated, | 95 MOCK_METHOD4(OnStreamGenerated, |
| 94 void(int routing_id, int request_id, int audio_array_size, | 96 void(int routing_id, int request_id, int audio_array_size, |
| 95 int video_array_size)); | 97 int video_array_size)); |
| 96 MOCK_METHOD2(OnStreamGenerationFailed, void(int routing_id, int request_id)); | 98 MOCK_METHOD2(OnStreamGenerationFailed, void(int routing_id, int request_id)); |
| 97 MOCK_METHOD1(OnStopGeneratedStreamFromBrowser, | 99 MOCK_METHOD1(OnStopGeneratedStreamFromBrowser, |
| 98 void(int routing_id)); | 100 void(int routing_id)); |
| 99 MOCK_METHOD2(OnDeviceOpened, | 101 MOCK_METHOD2(OnDeviceOpened, |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 MediaStreamDispatcherHostTest() | 252 MediaStreamDispatcherHostTest() |
| 251 : old_browser_client_(NULL), | 253 : old_browser_client_(NULL), |
| 252 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 254 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 253 origin_("https://test.com") { | 255 origin_("https://test.com") { |
| 254 // Create our own MediaStreamManager. | 256 // Create our own MediaStreamManager. |
| 255 audio_manager_.reset(new MockAudioManager()); | 257 audio_manager_.reset(new MockAudioManager()); |
| 256 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); | 258 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); |
| 257 // Make sure we use fake devices to avoid long delays. | 259 // Make sure we use fake devices to avoid long delays. |
| 258 media_stream_manager_->UseFakeDevice(); | 260 media_stream_manager_->UseFakeDevice(); |
| 259 | 261 |
| 260 host_ = new MockMediaStreamDispatcherHost(base::MessageLoopProxy::current(), | 262 host_ = new MockMediaStreamDispatcherHost( |
| 261 media_stream_manager_.get()); | 263 browser_context_.GetResourceContext(), |
| 264 base::MessageLoopProxy::current(), |
| 265 media_stream_manager_.get()); |
| 262 | 266 |
| 263 // Use the fake content client and browser. | 267 // Use the fake content client and browser. |
| 264 content_client_.reset(new TestContentClient()); | 268 content_client_.reset(new TestContentClient()); |
| 265 SetContentClient(content_client_.get()); | 269 SetContentClient(content_client_.get()); |
| 266 old_browser_client_ = SetBrowserClientForTesting(host_.get()); | 270 old_browser_client_ = SetBrowserClientForTesting(host_.get()); |
| 267 } | 271 } |
| 268 | 272 |
| 269 virtual ~MediaStreamDispatcherHostTest() { | 273 virtual ~MediaStreamDispatcherHostTest() { |
| 270 } | 274 } |
| 271 | 275 |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 } | 389 } |
| 386 | 390 |
| 387 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, | 391 bool DoesEveryDeviceMapToRawId(const StreamDeviceInfoArray& devices, |
| 388 const GURL& origin) { | 392 const GURL& origin) { |
| 389 for (size_t i = 0; i < devices.size(); ++i) { | 393 for (size_t i = 0; i < devices.size(); ++i) { |
| 390 bool found_match = false; | 394 bool found_match = false; |
| 391 media::AudioDeviceNames::const_iterator audio_it = | 395 media::AudioDeviceNames::const_iterator audio_it = |
| 392 physical_audio_devices_.begin(); | 396 physical_audio_devices_.begin(); |
| 393 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | 397 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { |
| 394 if (content::DoesMediaDeviceIDMatchHMAC( | 398 if (content::DoesMediaDeviceIDMatchHMAC( |
| 399 browser_context_.GetResourceContext(), |
| 395 origin, | 400 origin, |
| 396 devices[i].device.id, | 401 devices[i].device.id, |
| 397 audio_it->unique_id)) { | 402 audio_it->unique_id)) { |
| 398 EXPECT_FALSE(found_match); | 403 EXPECT_FALSE(found_match); |
| 399 found_match = true; | 404 found_match = true; |
| 400 } | 405 } |
| 401 } | 406 } |
| 402 media::VideoCaptureDevice::Names::const_iterator video_it = | 407 media::VideoCaptureDevice::Names::const_iterator video_it = |
| 403 physical_video_devices_.begin(); | 408 physical_video_devices_.begin(); |
| 404 for (; video_it != physical_video_devices_.end(); ++video_it) { | 409 for (; video_it != physical_video_devices_.end(); ++video_it) { |
| 405 if (content::DoesMediaDeviceIDMatchHMAC( | 410 if (content::DoesMediaDeviceIDMatchHMAC( |
| 411 browser_context_.GetResourceContext(), |
| 406 origin, | 412 origin, |
| 407 devices[i].device.id, | 413 devices[i].device.id, |
| 408 video_it->id())) { | 414 video_it->id())) { |
| 409 EXPECT_FALSE(found_match); | 415 EXPECT_FALSE(found_match); |
| 410 found_match = true; | 416 found_match = true; |
| 411 } | 417 } |
| 412 } | 418 } |
| 413 if (!found_match) | 419 if (!found_match) |
| 414 return false; | 420 return false; |
| 415 } | 421 } |
| 416 return true; | 422 return true; |
| 417 } | 423 } |
| 418 | 424 |
| 419 scoped_refptr<MockMediaStreamDispatcherHost> host_; | 425 scoped_refptr<MockMediaStreamDispatcherHost> host_; |
| 420 scoped_ptr<media::AudioManager> audio_manager_; | 426 scoped_ptr<media::AudioManager> audio_manager_; |
| 421 scoped_ptr<MediaStreamManager> media_stream_manager_; | 427 scoped_ptr<MediaStreamManager> media_stream_manager_; |
| 422 ContentBrowserClient* old_browser_client_; | 428 ContentBrowserClient* old_browser_client_; |
| 423 scoped_ptr<ContentClient> content_client_; | 429 scoped_ptr<ContentClient> content_client_; |
| 424 content::TestBrowserThreadBundle thread_bundle_; | 430 content::TestBrowserThreadBundle thread_bundle_; |
| 431 content::TestBrowserContext browser_context_; |
| 425 media::AudioDeviceNames physical_audio_devices_; | 432 media::AudioDeviceNames physical_audio_devices_; |
| 426 media::VideoCaptureDevice::Names physical_video_devices_; | 433 media::VideoCaptureDevice::Names physical_video_devices_; |
| 427 GURL origin_; | 434 GURL origin_; |
| 428 }; | 435 }; |
| 429 | 436 |
| 430 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { | 437 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { |
| 431 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); | 438 StreamOptions options(MEDIA_NO_SERVICE, MEDIA_DEVICE_VIDEO_CAPTURE); |
| 432 | 439 |
| 433 SetupFakeUI(true); | 440 SetupFakeUI(true); |
| 434 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | 441 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) { | 574 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsWithSourceId) { |
| 568 ASSERT_GE(physical_audio_devices_.size(), 1u); | 575 ASSERT_GE(physical_audio_devices_.size(), 1u); |
| 569 ASSERT_GE(physical_video_devices_.size(), 1u); | 576 ASSERT_GE(physical_video_devices_.size(), 1u); |
| 570 | 577 |
| 571 media::AudioDeviceNames::const_iterator audio_it = | 578 media::AudioDeviceNames::const_iterator audio_it = |
| 572 physical_audio_devices_.begin(); | 579 physical_audio_devices_.begin(); |
| 573 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { | 580 for (; audio_it != physical_audio_devices_.end(); ++audio_it) { |
| 574 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, | 581 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, |
| 575 MEDIA_DEVICE_VIDEO_CAPTURE); | 582 MEDIA_DEVICE_VIDEO_CAPTURE); |
| 576 options.audio_device_id = content::GetHMACForMediaDeviceID( | 583 options.audio_device_id = content::GetHMACForMediaDeviceID( |
| 584 browser_context_.GetResourceContext(), |
| 577 origin_, | 585 origin_, |
| 578 audio_it->unique_id); | 586 audio_it->unique_id); |
| 579 ASSERT_FALSE(options.audio_device_id.empty()); | 587 ASSERT_FALSE(options.audio_device_id.empty()); |
| 580 | 588 |
| 581 // Generate first stream. | 589 // Generate first stream. |
| 582 SetupFakeUI(true); | 590 SetupFakeUI(true); |
| 583 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | 591 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
| 584 EXPECT_EQ(host_->audio_devices_[0].device.id, options.audio_device_id); | 592 EXPECT_EQ(host_->audio_devices_[0].device.id, options.audio_device_id); |
| 585 } | 593 } |
| 586 | 594 |
| 587 media::VideoCaptureDevice::Names::const_iterator video_it = | 595 media::VideoCaptureDevice::Names::const_iterator video_it = |
| 588 physical_video_devices_.begin(); | 596 physical_video_devices_.begin(); |
| 589 for (; video_it != physical_video_devices_.end(); ++video_it) { | 597 for (; video_it != physical_video_devices_.end(); ++video_it) { |
| 590 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, | 598 StreamOptions options(MEDIA_DEVICE_AUDIO_CAPTURE, |
| 591 MEDIA_DEVICE_VIDEO_CAPTURE); | 599 MEDIA_DEVICE_VIDEO_CAPTURE); |
| 592 options.video_device_id = content::GetHMACForMediaDeviceID( | 600 options.video_device_id = content::GetHMACForMediaDeviceID( |
| 593 origin_, | 601 browser_context_.GetResourceContext(), |
| 594 video_it->id()); | 602 origin_, |
| 603 video_it->id()); |
| 595 ASSERT_FALSE(options.video_device_id.empty()); | 604 ASSERT_FALSE(options.video_device_id.empty()); |
| 596 | 605 |
| 597 // Generate first stream. | 606 // Generate first stream. |
| 598 SetupFakeUI(true); | 607 SetupFakeUI(true); |
| 599 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); | 608 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); |
| 600 EXPECT_EQ(host_->video_devices_[0].device.id, options.video_device_id); | 609 EXPECT_EQ(host_->video_devices_[0].device.id, options.video_device_id); |
| 601 } | 610 } |
| 602 } | 611 } |
| 603 | 612 |
| 604 // Test that generating a stream with an invalid video source id fail. | 613 // Test that generating a stream with an invalid video source id fail. |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 MEDIA_DEVICE_AUDIO_CAPTURE); | 710 MEDIA_DEVICE_AUDIO_CAPTURE); |
| 702 } | 711 } |
| 703 | 712 |
| 704 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) { | 713 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) { |
| 705 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, | 714 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, |
| 706 MEDIA_DEVICE_VIDEO_CAPTURE); | 715 MEDIA_DEVICE_VIDEO_CAPTURE); |
| 707 } | 716 } |
| 708 | 717 |
| 709 | 718 |
| 710 }; // namespace content | 719 }; // namespace content |
| OLD | NEW |