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

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

Issue 235353002: Extract VideoCaptureDeviceFactory out of VideoCaptureDevice and use for File and FakeVCD. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: perkj@s comments Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 #include <queue> 6 #include <queue>
7 7
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/command_line.h"
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h" 12 #include "base/run_loop.h"
12 #include "content/browser/browser_thread_impl.h" 13 #include "content/browser/browser_thread_impl.h"
13 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" 14 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h"
14 #include "content/browser/renderer_host/media/media_stream_manager.h" 15 #include "content/browser/renderer_host/media/media_stream_manager.h"
15 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 16 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
17 #include "content/browser/renderer_host/media/video_capture_manager.h"
16 #include "content/common/media/media_stream_messages.h" 18 #include "content/common/media/media_stream_messages.h"
17 #include "content/common/media/media_stream_options.h" 19 #include "content/common/media/media_stream_options.h"
18 #include "content/public/browser/media_device_id.h" 20 #include "content/public/browser/media_device_id.h"
21 #include "content/public/common/content_switches.h"
19 #include "content/public/test/mock_resource_context.h" 22 #include "content/public/test/mock_resource_context.h"
20 #include "content/public/test/test_browser_context.h" 23 #include "content/public/test/test_browser_context.h"
21 #include "content/public/test/test_browser_thread_bundle.h" 24 #include "content/public/test/test_browser_thread_bundle.h"
22 #include "content/test/test_content_browser_client.h" 25 #include "content/test/test_content_browser_client.h"
23 #include "content/test/test_content_client.h" 26 #include "content/test/test_content_client.h"
24 #include "ipc/ipc_message_macros.h" 27 #include "ipc/ipc_message_macros.h"
25 #include "media/audio/mock_audio_manager.h" 28 #include "media/audio/mock_audio_manager.h"
26 #include "media/video/capture/fake_video_capture_device.h" 29 #include "media/video/capture/fake_video_capture_device_factory.h"
27 #include "net/url_request/url_request_context.h" 30 #include "net/url_request/url_request_context.h"
28 #include "testing/gmock/include/gmock/gmock.h" 31 #include "testing/gmock/include/gmock/gmock.h"
29 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
30 33
31 using ::testing::_; 34 using ::testing::_;
32 using ::testing::DeleteArg; 35 using ::testing::DeleteArg;
33 using ::testing::DoAll; 36 using ::testing::DoAll;
34 using ::testing::Return; 37 using ::testing::Return;
35 using ::testing::SaveArg; 38 using ::testing::SaveArg;
36 39
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 }; 212 };
210 213
211 class MediaStreamDispatcherHostTest : public testing::Test { 214 class MediaStreamDispatcherHostTest : public testing::Test {
212 public: 215 public:
213 MediaStreamDispatcherHostTest() 216 MediaStreamDispatcherHostTest()
214 : old_browser_client_(NULL), 217 : old_browser_client_(NULL),
215 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 218 thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
216 origin_("https://test.com") { 219 origin_("https://test.com") {
217 audio_manager_.reset( 220 audio_manager_.reset(
218 new media::MockAudioManager(base::MessageLoopProxy::current())); 221 new media::MockAudioManager(base::MessageLoopProxy::current()));
222 // Make sure we use fake devices to avoid long delays.
223 CommandLine::ForCurrentProcess()->AppendSwitch(
224 switches::kUseFakeDeviceForMediaStream);
219 // Create our own MediaStreamManager. 225 // Create our own MediaStreamManager.
220 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get())); 226 media_stream_manager_.reset(new MediaStreamManager(audio_manager_.get()));
221 // Make sure we use fake devices to avoid long delays. 227 video_capture_device_factory_ =
222 media_stream_manager_->UseFakeDevice(); 228 static_cast<media::FakeVideoCaptureDeviceFactory*>(
229 media_stream_manager_->video_capture_manager()
230 ->video_capture_device_factory());
231 DCHECK(video_capture_device_factory_);
223 232
224 host_ = new MockMediaStreamDispatcherHost( 233 host_ = new MockMediaStreamDispatcherHost(
225 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(), 234 browser_context_.GetResourceContext()->GetMediaDeviceIDSalt(),
226 base::MessageLoopProxy::current(), 235 base::MessageLoopProxy::current(),
227 media_stream_manager_.get()); 236 media_stream_manager_.get());
228 237
229 // Use the fake content client and browser. 238 // Use the fake content client and browser.
230 content_client_.reset(new TestContentClient()); 239 content_client_.reset(new TestContentClient());
231 SetContentClient(content_client_.get()); 240 SetContentClient(content_client_.get());
232 old_browser_client_ = SetBrowserClientForTesting(host_.get()); 241 old_browser_client_ = SetBrowserClientForTesting(host_.get());
233 } 242 }
234 243
235 virtual ~MediaStreamDispatcherHostTest() { 244 virtual ~MediaStreamDispatcherHostTest() {
236 } 245 }
237 246
238 virtual void SetUp() OVERRIDE { 247 virtual void SetUp() OVERRIDE {
239 media::FakeVideoCaptureDevice::GetDeviceNames(&physical_video_devices_); 248 video_capture_device_factory_->GetDeviceNames(&physical_video_devices_);
240 ASSERT_GT(physical_video_devices_.size(), 0u); 249 ASSERT_GT(physical_video_devices_.size(), 0u);
241 250
242 audio_manager_->GetAudioInputDeviceNames(&physical_audio_devices_); 251 audio_manager_->GetAudioInputDeviceNames(&physical_audio_devices_);
243 ASSERT_GT(physical_audio_devices_.size(), 0u); 252 ASSERT_GT(physical_audio_devices_.size(), 0u);
244 } 253 }
245 254
246 virtual void TearDown() OVERRIDE { 255 virtual void TearDown() OVERRIDE {
247 host_->OnChannelClosing(); 256 host_->OnChannelClosing();
248 } 257 }
249 258
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 scoped_refptr<MockMediaStreamDispatcherHost> host_; 388 scoped_refptr<MockMediaStreamDispatcherHost> host_;
380 scoped_ptr<media::AudioManager> audio_manager_; 389 scoped_ptr<media::AudioManager> audio_manager_;
381 scoped_ptr<MediaStreamManager> media_stream_manager_; 390 scoped_ptr<MediaStreamManager> media_stream_manager_;
382 ContentBrowserClient* old_browser_client_; 391 ContentBrowserClient* old_browser_client_;
383 scoped_ptr<ContentClient> content_client_; 392 scoped_ptr<ContentClient> content_client_;
384 content::TestBrowserThreadBundle thread_bundle_; 393 content::TestBrowserThreadBundle thread_bundle_;
385 content::TestBrowserContext browser_context_; 394 content::TestBrowserContext browser_context_;
386 media::AudioDeviceNames physical_audio_devices_; 395 media::AudioDeviceNames physical_audio_devices_;
387 media::VideoCaptureDevice::Names physical_video_devices_; 396 media::VideoCaptureDevice::Names physical_video_devices_;
388 GURL origin_; 397 GURL origin_;
398 media::FakeVideoCaptureDeviceFactory* video_capture_device_factory_;
389 }; 399 };
390 400
391 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) { 401 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamWithVideoOnly) {
392 StreamOptions options(false, true); 402 StreamOptions options(false, true);
393 403
394 SetupFakeUI(true); 404 SetupFakeUI(true);
395 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); 405 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
396 406
397 EXPECT_EQ(host_->audio_devices_.size(), 0u); 407 EXPECT_EQ(host_->audio_devices_.size(), 0u);
398 EXPECT_EQ(host_->video_devices_.size(), 1u); 408 EXPECT_EQ(host_->video_devices_.size(), 1u);
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 TEST_F(MediaStreamDispatcherHostTest, 673 TEST_F(MediaStreamDispatcherHostTest,
664 GenerateStreamsWithInvalidOptionalAudioSourceId) { 674 GenerateStreamsWithInvalidOptionalAudioSourceId) {
665 StreamOptions options(true, true); 675 StreamOptions options(true, true);
666 AddSourceIdConstraint("invalid source id", &options.optional_audio); 676 AddSourceIdConstraint("invalid source id", &options.optional_audio);
667 677
668 SetupFakeUI(true); 678 SetupFakeUI(true);
669 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); 679 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
670 } 680 }
671 681
672 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsNoAvailableVideoDevice) { 682 TEST_F(MediaStreamDispatcherHostTest, GenerateStreamsNoAvailableVideoDevice) {
673 size_t number_of_fake_devices = physical_video_devices_.size(); 683 physical_video_devices_.clear();
674 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(0); 684 video_capture_device_factory_->set_number_of_devices(0);
675 media::FakeVideoCaptureDevice::GetDeviceNames(&physical_video_devices_); 685 video_capture_device_factory_->GetDeviceNames(&physical_video_devices_);
676 StreamOptions options(true, true); 686 StreamOptions options(true, true);
677 687
678 SetupFakeUI(false); 688 SetupFakeUI(false);
679 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, options, 689 GenerateStreamAndWaitForFailure(kRenderId, kPageRequestId, options,
680 MEDIA_DEVICE_NO_HARDWARE); 690 MEDIA_DEVICE_NO_HARDWARE);
681
682 // Reset the number of fake devices for next test.
683 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(number_of_fake_devices);
684 } 691 }
685 692
686 // Test that if a OnStopStreamDevice message is received for a device that has 693 // Test that if a OnStopStreamDevice message is received for a device that has
687 // been opened in a MediaStream and by pepper, the device is only stopped for 694 // been opened in a MediaStream and by pepper, the device is only stopped for
688 // the MediaStream. 695 // the MediaStream.
689 TEST_F(MediaStreamDispatcherHostTest, StopDeviceInStream) { 696 TEST_F(MediaStreamDispatcherHostTest, StopDeviceInStream) {
690 StreamOptions options(false, true); 697 StreamOptions options(false, true);
691 698
692 SetupFakeUI(true); 699 SetupFakeUI(true);
693 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); 700 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 824
818 ASSERT_FALSE(close_callback.is_null()); 825 ASSERT_FALSE(close_callback.is_null());
819 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)); 826 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId));
820 close_callback.Run(); 827 close_callback.Run();
821 base::RunLoop().RunUntilIdle(); 828 base::RunLoop().RunUntilIdle();
822 } 829 }
823 830
824 // Test that the dispatcher is notified if a video device that is in use is 831 // Test that the dispatcher is notified if a video device that is in use is
825 // being unplugged. 832 // being unplugged.
826 TEST_F(MediaStreamDispatcherHostTest, VideoDeviceUnplugged) { 833 TEST_F(MediaStreamDispatcherHostTest, VideoDeviceUnplugged) {
827 size_t number_of_fake_devices = physical_video_devices_.size();
828 StreamOptions options(true, true); 834 StreamOptions options(true, true);
829 SetupFakeUI(true); 835 SetupFakeUI(true);
830 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options); 836 GenerateStreamAndWaitForResult(kRenderId, kPageRequestId, options);
831 EXPECT_EQ(host_->audio_devices_.size(), 1u); 837 EXPECT_EQ(host_->audio_devices_.size(), 1u);
832 EXPECT_EQ(host_->video_devices_.size(), 1u); 838 EXPECT_EQ(host_->video_devices_.size(), 1u);
833 839
834 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(0); 840 video_capture_device_factory_->set_number_of_devices(0);
835 841
836 base::RunLoop run_loop; 842 base::RunLoop run_loop;
837 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) 843 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId))
838 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); 844 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit));
839 media_stream_manager_->OnDevicesChanged( 845 media_stream_manager_->OnDevicesChanged(
840 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); 846 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE);
841 847
842 run_loop.Run(); 848 run_loop.Run();
843
844 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(number_of_fake_devices);
845 } 849 }
846 850
847 TEST_F(MediaStreamDispatcherHostTest, EnumerateAudioDevices) { 851 TEST_F(MediaStreamDispatcherHostTest, EnumerateAudioDevices) {
848 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, 852 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId,
849 MEDIA_DEVICE_AUDIO_CAPTURE); 853 MEDIA_DEVICE_AUDIO_CAPTURE);
850 } 854 }
851 855
852 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) { 856 TEST_F(MediaStreamDispatcherHostTest, EnumerateVideoDevices) {
853 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId, 857 EnumerateDevicesAndWaitForResult(kRenderId, kPageRequestId,
854 MEDIA_DEVICE_VIDEO_CAPTURE); 858 MEDIA_DEVICE_VIDEO_CAPTURE);
855 } 859 }
856 860
857 }; // namespace content 861 }; // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698