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 "content/browser/renderer_host/media/media_stream_dispatcher_host.h" | 5 #include "content/browser/renderer_host/media/media_stream_dispatcher_host.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <memory> | 8 #include <memory> |
9 #include <queue> | 9 #include <queue> |
10 #include <string> | 10 #include <string> |
(...skipping 20 matching lines...) Expand all Loading... |
31 #include "content/public/browser/media_device_id.h" | 31 #include "content/public/browser/media_device_id.h" |
32 #include "content/public/common/content_switches.h" | 32 #include "content/public/common/content_switches.h" |
33 #include "content/public/test/test_browser_context.h" | 33 #include "content/public/test/test_browser_context.h" |
34 #include "content/public/test/test_browser_thread_bundle.h" | 34 #include "content/public/test/test_browser_thread_bundle.h" |
35 #include "content/test/test_content_browser_client.h" | 35 #include "content/test/test_content_browser_client.h" |
36 #include "content/test/test_content_client.h" | 36 #include "content/test/test_content_client.h" |
37 #include "ipc/ipc_message_macros.h" | 37 #include "ipc/ipc_message_macros.h" |
38 #include "media/audio/audio_device_description.h" | 38 #include "media/audio/audio_device_description.h" |
39 #include "media/audio/audio_system_impl.h" | 39 #include "media/audio/audio_system_impl.h" |
40 #include "media/audio/mock_audio_manager.h" | 40 #include "media/audio/mock_audio_manager.h" |
| 41 #include "media/audio/test_audio_thread.h" |
41 #include "media/base/media_switches.h" | 42 #include "media/base/media_switches.h" |
42 #include "media/capture/video/fake_video_capture_device_factory.h" | 43 #include "media/capture/video/fake_video_capture_device_factory.h" |
43 #include "net/url_request/url_request_context.h" | 44 #include "net/url_request/url_request_context.h" |
44 #include "testing/gmock/include/gmock/gmock.h" | 45 #include "testing/gmock/include/gmock/gmock.h" |
45 #include "testing/gtest/include/gtest/gtest.h" | 46 #include "testing/gtest/include/gtest/gtest.h" |
46 #include "url/gurl.h" | 47 #include "url/gurl.h" |
47 #include "url/origin.h" | 48 #include "url/origin.h" |
48 | 49 |
49 #if defined(OS_CHROMEOS) | 50 #if defined(OS_CHROMEOS) |
50 #include "chromeos/audio/cras_audio_handler.h" | 51 #include "chromeos/audio/cras_audio_handler.h" |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 void(const base::Closure& stop, | 238 void(const base::Closure& stop, |
238 const MediaStreamUIProxy::WindowIdCallback& window_id_callback)); | 239 const MediaStreamUIProxy::WindowIdCallback& window_id_callback)); |
239 }; | 240 }; |
240 | 241 |
241 class MediaStreamDispatcherHostTest : public testing::Test { | 242 class MediaStreamDispatcherHostTest : public testing::Test { |
242 public: | 243 public: |
243 MediaStreamDispatcherHostTest() | 244 MediaStreamDispatcherHostTest() |
244 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 245 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
245 old_browser_client_(NULL), | 246 old_browser_client_(NULL), |
246 origin_(GURL("https://test.com")) { | 247 origin_(GURL("https://test.com")) { |
247 audio_manager_.reset( | 248 audio_manager_.reset(new media::MockAudioManager( |
248 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get())); | 249 base::MakeUnique<media::TestAudioThread>())); |
249 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); | 250 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); |
250 // Make sure we use fake devices to avoid long delays. | 251 // Make sure we use fake devices to avoid long delays. |
251 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 252 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
252 switches::kUseFakeDeviceForMediaStream); | 253 switches::kUseFakeDeviceForMediaStream); |
253 auto mock_video_capture_provider = | 254 auto mock_video_capture_provider = |
254 base::MakeUnique<MockVideoCaptureProvider>(); | 255 base::MakeUnique<MockVideoCaptureProvider>(); |
255 mock_video_capture_provider_ = mock_video_capture_provider.get(); | 256 mock_video_capture_provider_ = mock_video_capture_provider.get(); |
256 // Create our own MediaStreamManager. | 257 // Create our own MediaStreamManager. |
257 media_stream_manager_ = base::MakeUnique<MediaStreamManager>( | 258 media_stream_manager_ = base::MakeUnique<MediaStreamManager>( |
258 audio_system_.get(), std::move(mock_video_capture_provider)); | 259 audio_system_.get(), std::move(mock_video_capture_provider)); |
259 | 260 |
260 host_ = new MockMediaStreamDispatcherHost( | 261 host_ = new MockMediaStreamDispatcherHost( |
261 browser_context_.GetMediaDeviceIDSalt(), | 262 browser_context_.GetMediaDeviceIDSalt(), |
262 base::ThreadTaskRunnerHandle::Get(), media_stream_manager_.get()); | 263 base::ThreadTaskRunnerHandle::Get(), media_stream_manager_.get()); |
263 | 264 |
264 // Use the fake content client and browser. | 265 // Use the fake content client and browser. |
265 content_client_.reset(new TestContentClient()); | 266 content_client_.reset(new TestContentClient()); |
266 SetContentClient(content_client_.get()); | 267 SetContentClient(content_client_.get()); |
267 old_browser_client_ = SetBrowserClientForTesting(host_.get()); | 268 old_browser_client_ = SetBrowserClientForTesting(host_.get()); |
268 | 269 |
269 #if defined(OS_CHROMEOS) | 270 #if defined(OS_CHROMEOS) |
270 chromeos::CrasAudioHandler::InitializeForTesting(); | 271 chromeos::CrasAudioHandler::InitializeForTesting(); |
271 #endif | 272 #endif |
272 } | 273 } |
273 | 274 |
274 ~MediaStreamDispatcherHostTest() override { | 275 ~MediaStreamDispatcherHostTest() override { |
| 276 audio_manager_->Shutdown(); |
275 #if defined(OS_CHROMEOS) | 277 #if defined(OS_CHROMEOS) |
276 chromeos::CrasAudioHandler::Shutdown(); | 278 chromeos::CrasAudioHandler::Shutdown(); |
277 #endif | 279 #endif |
278 } | 280 } |
279 | 281 |
280 void SetUp() override { | 282 void SetUp() override { |
281 stub_video_device_ids_.emplace_back(kRegularVideoDeviceId); | 283 stub_video_device_ids_.emplace_back(kRegularVideoDeviceId); |
282 stub_video_device_ids_.emplace_back(kDepthVideoDeviceId); | 284 stub_video_device_ids_.emplace_back(kDepthVideoDeviceId); |
283 ON_CALL(*mock_video_capture_provider_, GetDeviceInfosAsync(_)) | 285 ON_CALL(*mock_video_capture_provider_, GetDeviceInfosAsync(_)) |
284 .WillByDefault(Invoke( | 286 .WillByDefault(Invoke( |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 for (size_t i = 0; i < devices.size(); ++i) { | 441 for (size_t i = 0; i < devices.size(); ++i) { |
440 if (!devices[i].device.name.empty()) | 442 if (!devices[i].device.name.empty()) |
441 return false; | 443 return false; |
442 } | 444 } |
443 return true; | 445 return true; |
444 } | 446 } |
445 | 447 |
446 scoped_refptr<MockMediaStreamDispatcherHost> host_; | 448 scoped_refptr<MockMediaStreamDispatcherHost> host_; |
447 std::unique_ptr<MediaStreamManager> media_stream_manager_; | 449 std::unique_ptr<MediaStreamManager> media_stream_manager_; |
448 content::TestBrowserThreadBundle thread_bundle_; | 450 content::TestBrowserThreadBundle thread_bundle_; |
449 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter> | 451 std::unique_ptr<media::AudioManager> audio_manager_; |
450 audio_manager_; | |
451 std::unique_ptr<media::AudioSystem> audio_system_; | 452 std::unique_ptr<media::AudioSystem> audio_system_; |
452 MockMediaStreamUIProxy* stream_ui_; | 453 MockMediaStreamUIProxy* stream_ui_; |
453 ContentBrowserClient* old_browser_client_; | 454 ContentBrowserClient* old_browser_client_; |
454 std::unique_ptr<ContentClient> content_client_; | 455 std::unique_ptr<ContentClient> content_client_; |
455 content::TestBrowserContext browser_context_; | 456 content::TestBrowserContext browser_context_; |
456 media::AudioDeviceDescriptions audio_device_descriptions_; | 457 media::AudioDeviceDescriptions audio_device_descriptions_; |
457 std::vector<std::string> stub_video_device_ids_; | 458 std::vector<std::string> stub_video_device_ids_; |
458 url::Origin origin_; | 459 url::Origin origin_; |
459 MockVideoCaptureProvider* mock_video_capture_provider_; | 460 MockVideoCaptureProvider* mock_video_capture_provider_; |
460 }; | 461 }; |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 base::RunLoop run_loop; | 860 base::RunLoop run_loop; |
860 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) | 861 EXPECT_CALL(*host_.get(), OnDeviceStopped(kRenderId)) |
861 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); | 862 .WillOnce(testing::InvokeWithoutArgs(&run_loop, &base::RunLoop::Quit)); |
862 media_stream_manager_->media_devices_manager()->OnDevicesChanged( | 863 media_stream_manager_->media_devices_manager()->OnDevicesChanged( |
863 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); | 864 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); |
864 | 865 |
865 run_loop.Run(); | 866 run_loop.Run(); |
866 } | 867 } |
867 | 868 |
868 }; // namespace content | 869 }; // namespace content |
OLD | NEW |