| 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_manager.h" | 5 #include "content/browser/renderer_host/media/media_devices_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 16 #include "component/arc/video_facing.h" |
| 16 #include "content/browser/renderer_host/media/video_capture_manager.h" | 17 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 17 #include "content/public/test/test_browser_thread_bundle.h" | 18 #include "content/public/test/test_browser_thread_bundle.h" |
| 18 #include "media/audio/audio_device_name.h" | 19 #include "media/audio/audio_device_name.h" |
| 19 #include "media/audio/fake_audio_log_factory.h" | 20 #include "media/audio/fake_audio_log_factory.h" |
| 20 #include "media/audio/fake_audio_manager.h" | 21 #include "media/audio/fake_audio_manager.h" |
| 21 #include "media/capture/video/fake_video_capture_device_factory.h" | 22 #include "media/capture/video/fake_video_capture_device_factory.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" | 23 #include "testing/gmock/include/gmock/gmock.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 24 | 25 |
| 25 using testing::_; | 26 using testing::_; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 MockGetDeviceDescriptors(); | 114 MockGetDeviceDescriptors(); |
| 114 } | 115 } |
| 115 }; | 116 }; |
| 116 | 117 |
| 117 class MockMediaDeviceChangeSubscriber : public MediaDeviceChangeSubscriber { | 118 class MockMediaDeviceChangeSubscriber : public MediaDeviceChangeSubscriber { |
| 118 public: | 119 public: |
| 119 MOCK_METHOD2(OnDevicesChanged, | 120 MOCK_METHOD2(OnDevicesChanged, |
| 120 void(MediaDeviceType, const MediaDeviceInfoArray&)); | 121 void(MediaDeviceType, const MediaDeviceInfoArray&)); |
| 121 }; | 122 }; |
| 122 | 123 |
| 124 class MockVideoCaptureObserver : public component::VideoCaptureObserver { |
| 125 public: |
| 126 MOCK_METHOD1(OnVideoCaptureStarted, void(component::VideoFacingMode)); |
| 127 MOCK_METHOD1(OnVideoCaptureStopped, void(component::VideoFacingMode)); |
| 128 }; |
| 129 |
| 123 } // namespace | 130 } // namespace |
| 124 | 131 |
| 125 class MediaDevicesManagerTest : public ::testing::Test { | 132 class MediaDevicesManagerTest : public ::testing::Test { |
| 126 public: | 133 public: |
| 127 MediaDevicesManagerTest() | 134 MediaDevicesManagerTest() |
| 128 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 135 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 129 video_capture_device_factory_(nullptr) {} | 136 video_capture_device_factory_(nullptr) {} |
| 130 ~MediaDevicesManagerTest() override {} | 137 ~MediaDevicesManagerTest() override {} |
| 131 | 138 |
| 132 MOCK_METHOD1(MockCallback, void(const MediaDeviceEnumeration&)); | 139 MOCK_METHOD1(MockCallback, void(const MediaDeviceEnumeration&)); |
| 133 | 140 |
| 134 void EnumerateCallback(base::RunLoop* run_loop, | 141 void EnumerateCallback(base::RunLoop* run_loop, |
| 135 const MediaDeviceEnumeration& result) { | 142 const MediaDeviceEnumeration& result) { |
| 136 MockCallback(result); | 143 MockCallback(result); |
| 137 run_loop->Quit(); | 144 run_loop->Quit(); |
| 138 } | 145 } |
| 139 | 146 |
| 140 protected: | 147 protected: |
| 141 void SetUp() override { | 148 void SetUp() override { |
| 142 audio_manager_.reset(new MockAudioManager()); | 149 audio_manager_.reset(new MockAudioManager()); |
| 143 video_capture_manager_ = new VideoCaptureManager( | 150 video_capture_manager_ = new VideoCaptureManager( |
| 144 std::unique_ptr<media::VideoCaptureDeviceFactory>( | 151 std::unique_ptr<media::VideoCaptureDeviceFactory>( |
| 145 new MockVideoCaptureDeviceFactory())); | 152 new MockVideoCaptureDeviceFactory()), |
| 153 new MockVideoCaptureObserver()); |
| 146 video_capture_manager_->Register(nullptr, | 154 video_capture_manager_->Register(nullptr, |
| 147 base::ThreadTaskRunnerHandle::Get()); | 155 base::ThreadTaskRunnerHandle::Get()); |
| 148 video_capture_device_factory_ = static_cast<MockVideoCaptureDeviceFactory*>( | 156 video_capture_device_factory_ = static_cast<MockVideoCaptureDeviceFactory*>( |
| 149 video_capture_manager_->video_capture_device_factory()); | 157 video_capture_manager_->video_capture_device_factory()); |
| 150 media_devices_manager_.reset(new MediaDevicesManager( | 158 media_devices_manager_.reset(new MediaDevicesManager( |
| 151 audio_manager_.get(), video_capture_manager_, nullptr)); | 159 audio_manager_.get(), video_capture_manager_, nullptr)); |
| 152 } | 160 } |
| 153 | 161 |
| 154 void EnableCache(MediaDeviceType type) { | 162 void EnableCache(MediaDeviceType type) { |
| 155 media_devices_manager_->SetCachePolicy( | 163 media_devices_manager_->SetCachePolicy( |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 media_devices_manager_->OnDevicesChanged(base::SystemMonitor::DEVTYPE_AUDIO); | 568 media_devices_manager_->OnDevicesChanged(base::SystemMonitor::DEVTYPE_AUDIO); |
| 561 media_devices_manager_->OnDevicesChanged( | 569 media_devices_manager_->OnDevicesChanged( |
| 562 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); | 570 base::SystemMonitor::DEVTYPE_VIDEO_CAPTURE); |
| 563 base::RunLoop().RunUntilIdle(); | 571 base::RunLoop().RunUntilIdle(); |
| 564 EXPECT_EQ(num_audio_input_devices, notification_all_audio_input.size()); | 572 EXPECT_EQ(num_audio_input_devices, notification_all_audio_input.size()); |
| 565 EXPECT_EQ(num_video_input_devices, notification_all_video_input.size()); | 573 EXPECT_EQ(num_video_input_devices, notification_all_video_input.size()); |
| 566 EXPECT_EQ(num_audio_output_devices, notification_all_audio_output.size()); | 574 EXPECT_EQ(num_audio_output_devices, notification_all_audio_output.size()); |
| 567 } | 575 } |
| 568 | 576 |
| 569 } // namespace content | 577 } // namespace content |
| OLD | NEW |