OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/browser/renderer_host/media/media_devices_dispatcher_host.h" | 5 #include "content/browser/renderer_host/media/media_devices_dispatcher_host.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <queue> | 10 #include <queue> |
11 #include <utility> | 11 #include <utility> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
20 #include "content/browser/renderer_host/media/media_stream_manager.h" | 20 #include "content/browser/renderer_host/media/media_stream_manager.h" |
21 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 21 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
22 #include "content/browser/renderer_host/media/video_capture_manager.h" | 22 #include "content/browser/renderer_host/media/video_capture_manager.h" |
23 #include "content/public/browser/browser_context.h" | 23 #include "content/public/browser/browser_context.h" |
24 #include "content/public/browser/media_device_id.h" | 24 #include "content/public/browser/media_device_id.h" |
25 #include "content/public/test/test_browser_context.h" | 25 #include "content/public/test/test_browser_context.h" |
26 #include "content/public/test/test_browser_thread_bundle.h" | 26 #include "content/public/test/test_browser_thread_bundle.h" |
27 #include "media/audio/audio_device_description.h" | 27 #include "media/audio/audio_device_description.h" |
28 #include "media/audio/audio_system_impl.h" | 28 #include "media/audio/audio_system_impl.h" |
29 #include "media/audio/mock_audio_manager.h" | 29 #include "media/audio/mock_audio_manager.h" |
| 30 #include "media/audio/test_audio_thread.h" |
30 #include "media/base/media_switches.h" | 31 #include "media/base/media_switches.h" |
31 #include "media/capture/video/fake_video_capture_device_factory.h" | 32 #include "media/capture/video/fake_video_capture_device_factory.h" |
32 #include "mojo/public/cpp/bindings/binding.h" | 33 #include "mojo/public/cpp/bindings/binding.h" |
33 #include "testing/gmock/include/gmock/gmock.h" | 34 #include "testing/gmock/include/gmock/gmock.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 35 #include "testing/gtest/include/gtest/gtest.h" |
35 #include "url/origin.h" | 36 #include "url/origin.h" |
36 | 37 |
37 using testing::_; | 38 using testing::_; |
38 using testing::SaveArg; | 39 using testing::SaveArg; |
39 using testing::InvokeWithoutArgs; | 40 using testing::InvokeWithoutArgs; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 class MediaDevicesDispatcherHostTest : public testing::Test { | 75 class MediaDevicesDispatcherHostTest : public testing::Test { |
75 public: | 76 public: |
76 MediaDevicesDispatcherHostTest() | 77 MediaDevicesDispatcherHostTest() |
77 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 78 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
78 origin_(GURL("https://test.com")) { | 79 origin_(GURL("https://test.com")) { |
79 // Make sure we use fake devices to avoid long delays. | 80 // Make sure we use fake devices to avoid long delays. |
80 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 81 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
81 switches::kUseFakeDeviceForMediaStream, | 82 switches::kUseFakeDeviceForMediaStream, |
82 base::StringPrintf("device-count=%zu, video-input-default-id=%s", | 83 base::StringPrintf("device-count=%zu, video-input-default-id=%s", |
83 kNumFakeVideoDevices, kDefaultVideoDeviceID)); | 84 kNumFakeVideoDevices, kDefaultVideoDeviceID)); |
84 audio_manager_.reset( | 85 audio_manager_.reset(new media::MockAudioManager( |
85 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get())); | 86 base::MakeUnique<media::TestAudioThread>())); |
86 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); | 87 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); |
87 media_stream_manager_ = | 88 media_stream_manager_ = |
88 base::MakeUnique<MediaStreamManager>(audio_system_.get()); | 89 base::MakeUnique<MediaStreamManager>(audio_system_.get()); |
89 | 90 |
90 host_ = base::MakeUnique<MediaDevicesDispatcherHost>( | 91 host_ = base::MakeUnique<MediaDevicesDispatcherHost>( |
91 kProcessId, kRenderId, browser_context_.GetMediaDeviceIDSalt(), | 92 kProcessId, kRenderId, browser_context_.GetMediaDeviceIDSalt(), |
92 media_stream_manager_.get()); | 93 media_stream_manager_.get()); |
93 } | 94 } |
| 95 ~MediaDevicesDispatcherHostTest() override { audio_manager_->Shutdown(); } |
94 | 96 |
95 void SetUp() override { | 97 void SetUp() override { |
96 base::RunLoop run_loop; | 98 base::RunLoop run_loop; |
97 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; | 99 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; |
98 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = true; | 100 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = true; |
99 devices_to_enumerate[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = true; | 101 devices_to_enumerate[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = true; |
100 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = true; | 102 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = true; |
101 media_stream_manager_->media_devices_manager()->EnumerateDevices( | 103 media_stream_manager_->media_devices_manager()->EnumerateDevices( |
102 devices_to_enumerate, | 104 devices_to_enumerate, |
103 base::Bind(&PhysicalDevicesEnumerated, run_loop.QuitClosure(), | 105 base::Bind(&PhysicalDevicesEnumerated, run_loop.QuitClosure(), |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 } | 279 } |
278 | 280 |
279 // The order of these members is important on teardown: | 281 // The order of these members is important on teardown: |
280 // MediaDevicesDispatcherHost expects to be destroyed on the IO thread while | 282 // MediaDevicesDispatcherHost expects to be destroyed on the IO thread while |
281 // MediaStreamManager expects to be destroyed after the IO thread has been | 283 // MediaStreamManager expects to be destroyed after the IO thread has been |
282 // uninitialized. | 284 // uninitialized. |
283 std::unique_ptr<MediaStreamManager> media_stream_manager_; | 285 std::unique_ptr<MediaStreamManager> media_stream_manager_; |
284 content::TestBrowserThreadBundle thread_bundle_; | 286 content::TestBrowserThreadBundle thread_bundle_; |
285 std::unique_ptr<MediaDevicesDispatcherHost> host_; | 287 std::unique_ptr<MediaDevicesDispatcherHost> host_; |
286 | 288 |
287 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter> | 289 std::unique_ptr<media::AudioManager> audio_manager_; |
288 audio_manager_; | |
289 std::unique_ptr<media::AudioSystem> audio_system_; | 290 std::unique_ptr<media::AudioSystem> audio_system_; |
290 content::TestBrowserContext browser_context_; | 291 content::TestBrowserContext browser_context_; |
291 MediaDeviceEnumeration physical_devices_; | 292 MediaDeviceEnumeration physical_devices_; |
292 url::Origin origin_; | 293 url::Origin origin_; |
293 | 294 |
294 std::vector<MediaDeviceInfoArray> enumerated_devices_; | 295 std::vector<MediaDeviceInfoArray> enumerated_devices_; |
295 }; | 296 }; |
296 | 297 |
297 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAudioInputDevices) { | 298 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAudioInputDevices) { |
298 EnumerateDevicesAndWaitForResult(true, false, false); | 299 EnumerateDevicesAndWaitForResult(true, false, false); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); | 368 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); |
368 host_->GetVideoInputCapabilities( | 369 host_->GetVideoInputCapabilities( |
369 origin_, | 370 origin_, |
370 base::Bind( | 371 base::Bind( |
371 &MediaDevicesDispatcherHostTest::VideoInputCapabilitiesCallback, | 372 &MediaDevicesDispatcherHostTest::VideoInputCapabilitiesCallback, |
372 base::Unretained(this))); | 373 base::Unretained(this))); |
373 run_loop.Run(); | 374 run_loop.Run(); |
374 } | 375 } |
375 | 376 |
376 }; // namespace content | 377 }; // namespace content |
OLD | NEW |