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 // Unit test for VideoCaptureManager. | 5 // Unit test for VideoCaptureManager. |
6 | 6 |
7 #include "content/browser/renderer_host/media/video_capture_manager.h" | 7 #include "content/browser/renderer_host/media/video_capture_manager.h" |
8 | 8 |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <memory> | 12 #include <memory> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
20 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
21 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "component/arc/video_facing.h" |
22 #include "content/browser/renderer_host/media/media_stream_provider.h" | 23 #include "content/browser/renderer_host/media/media_stream_provider.h" |
23 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" | 24 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" |
24 #include "content/common/media/media_stream_options.h" | 25 #include "content/common/media/media_stream_options.h" |
25 #include "content/public/test/test_browser_thread_bundle.h" | 26 #include "content/public/test/test_browser_thread_bundle.h" |
26 #include "media/capture/video/fake_video_capture_device_factory.h" | 27 #include "media/capture/video/fake_video_capture_device_factory.h" |
27 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
29 | 30 |
30 using ::testing::_; | 31 using ::testing::_; |
31 using ::testing::AnyNumber; | 32 using ::testing::AnyNumber; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 int length, int buffer_id) override {} | 144 int length, int buffer_id) override {} |
144 void OnBufferDestroyed(VideoCaptureControllerID id, int buffer_id) override {} | 145 void OnBufferDestroyed(VideoCaptureControllerID id, int buffer_id) override {} |
145 void OnBufferReady(VideoCaptureControllerID id, | 146 void OnBufferReady(VideoCaptureControllerID id, |
146 int buffer_id, | 147 int buffer_id, |
147 const scoped_refptr<media::VideoFrame>& frame) override {} | 148 const scoped_refptr<media::VideoFrame>& frame) override {} |
148 void OnEnded(VideoCaptureControllerID id) override {} | 149 void OnEnded(VideoCaptureControllerID id) override {} |
149 | 150 |
150 void OnGotControllerCallback(VideoCaptureControllerID) {} | 151 void OnGotControllerCallback(VideoCaptureControllerID) {} |
151 }; | 152 }; |
152 | 153 |
| 154 class MockVideoCaptureObserver : public component::VideoCaptureObserver { |
| 155 public: |
| 156 MOCK_METHOD1(OnVideoCaptureStarted, void(component::VideoFacingMode)); |
| 157 MOCK_METHOD1(OnVideoCaptureStopped, void(component::VideoFacingMode)); |
| 158 }; |
| 159 |
153 } // namespace | 160 } // namespace |
154 | 161 |
155 // Test class | 162 // Test class |
156 class VideoCaptureManagerTest : public testing::Test { | 163 class VideoCaptureManagerTest : public testing::Test { |
157 public: | 164 public: |
158 VideoCaptureManagerTest() : next_client_id_(1) {} | 165 VideoCaptureManagerTest() : next_client_id_(1) {} |
159 ~VideoCaptureManagerTest() override {} | 166 ~VideoCaptureManagerTest() override {} |
160 | 167 |
161 void HandleEnumerationResult( | 168 void HandleEnumerationResult( |
162 const base::Closure& quit_closure, | 169 const base::Closure& quit_closure, |
163 const media::VideoCaptureDeviceDescriptors& descriptors) { | 170 const media::VideoCaptureDeviceDescriptors& descriptors) { |
164 StreamDeviceInfoArray devices; | 171 StreamDeviceInfoArray devices; |
165 for (const auto& descriptor : descriptors) { | 172 for (const auto& descriptor : descriptors) { |
166 devices.emplace_back(MEDIA_DEVICE_VIDEO_CAPTURE, | 173 devices.emplace_back(MEDIA_DEVICE_VIDEO_CAPTURE, |
167 descriptor.GetNameAndModel(), descriptor.device_id); | 174 descriptor.GetNameAndModel(), descriptor.device_id); |
168 } | 175 } |
169 devices_ = std::move(devices); | 176 devices_ = std::move(devices); |
170 quit_closure.Run(); | 177 quit_closure.Run(); |
171 } | 178 } |
172 | 179 |
173 protected: | 180 protected: |
174 void SetUp() override { | 181 void SetUp() override { |
175 listener_.reset(new MockMediaStreamProviderListener()); | 182 listener_.reset(new MockMediaStreamProviderListener()); |
176 vcm_ = new VideoCaptureManager( | 183 vcm_ = new VideoCaptureManager( |
177 std::unique_ptr<media::VideoCaptureDeviceFactory>( | 184 std::unique_ptr<media::VideoCaptureDeviceFactory>( |
178 new WrappedDeviceFactory())); | 185 new WrappedDeviceFactory()), |
| 186 new MockVideoCaptureObserver()); |
179 video_capture_device_factory_ = static_cast<WrappedDeviceFactory*>( | 187 video_capture_device_factory_ = static_cast<WrappedDeviceFactory*>( |
180 vcm_->video_capture_device_factory()); | 188 vcm_->video_capture_device_factory()); |
181 const int32_t kNumberOfFakeDevices = 2; | 189 const int32_t kNumberOfFakeDevices = 2; |
182 video_capture_device_factory_->set_number_of_devices(kNumberOfFakeDevices); | 190 video_capture_device_factory_->set_number_of_devices(kNumberOfFakeDevices); |
183 vcm_->Register(listener_.get(), base::ThreadTaskRunnerHandle::Get()); | 191 vcm_->Register(listener_.get(), base::ThreadTaskRunnerHandle::Get()); |
184 frame_observer_.reset(new MockFrameObserver()); | 192 frame_observer_.reset(new MockFrameObserver()); |
185 | 193 |
186 base::RunLoop run_loop; | 194 base::RunLoop run_loop; |
187 vcm_->EnumerateDevices( | 195 vcm_->EnumerateDevices( |
188 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, | 196 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, |
(...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 // Wait to check callbacks before removing the listener. | 629 // Wait to check callbacks before removing the listener. |
622 base::RunLoop().RunUntilIdle(); | 630 base::RunLoop().RunUntilIdle(); |
623 vcm_->Unregister(); | 631 vcm_->Unregister(); |
624 } | 632 } |
625 #endif | 633 #endif |
626 | 634 |
627 // TODO(mcasas): Add a test to check consolidation of the supported formats | 635 // TODO(mcasas): Add a test to check consolidation of the supported formats |
628 // provided by the device when http://crbug.com/323913 is closed. | 636 // provided by the device when http://crbug.com/323913 is closed. |
629 | 637 |
630 } // namespace content | 638 } // namespace content |
OLD | NEW |