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 "content/browser/browser_thread_impl.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
22 #include "content/browser/renderer_host/media/media_stream_provider.h" | 22 #include "content/browser/renderer_host/media/media_stream_provider.h" |
23 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" | 23 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" |
24 #include "content/common/media/media_stream_options.h" | 24 #include "content/common/media/media_stream_options.h" |
| 25 #include "content/public/test/test_browser_thread_bundle.h" |
25 #include "media/capture/video/fake_video_capture_device_factory.h" | 26 #include "media/capture/video/fake_video_capture_device_factory.h" |
26 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
27 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
28 | 29 |
29 using ::testing::_; | 30 using ::testing::_; |
30 using ::testing::AnyNumber; | 31 using ::testing::AnyNumber; |
31 using ::testing::DoAll; | 32 using ::testing::DoAll; |
32 using ::testing::InSequence; | 33 using ::testing::InSequence; |
33 using ::testing::InvokeWithoutArgs; | 34 using ::testing::InvokeWithoutArgs; |
34 using ::testing::Return; | 35 using ::testing::Return; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 devices.emplace_back(MEDIA_DEVICE_VIDEO_CAPTURE, | 166 devices.emplace_back(MEDIA_DEVICE_VIDEO_CAPTURE, |
166 descriptor.GetNameAndModel(), descriptor.device_id); | 167 descriptor.GetNameAndModel(), descriptor.device_id); |
167 } | 168 } |
168 devices_ = std::move(devices); | 169 devices_ = std::move(devices); |
169 quit_closure.Run(); | 170 quit_closure.Run(); |
170 } | 171 } |
171 | 172 |
172 protected: | 173 protected: |
173 void SetUp() override { | 174 void SetUp() override { |
174 listener_.reset(new MockMediaStreamProviderListener()); | 175 listener_.reset(new MockMediaStreamProviderListener()); |
175 message_loop_.reset(new base::MessageLoopForIO); | |
176 ui_thread_.reset(new BrowserThreadImpl(BrowserThread::UI, | |
177 message_loop_.get())); | |
178 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, | |
179 message_loop_.get())); | |
180 vcm_ = new VideoCaptureManager( | 176 vcm_ = new VideoCaptureManager( |
181 std::unique_ptr<media::VideoCaptureDeviceFactory>( | 177 std::unique_ptr<media::VideoCaptureDeviceFactory>( |
182 new WrappedDeviceFactory())); | 178 new WrappedDeviceFactory())); |
183 video_capture_device_factory_ = static_cast<WrappedDeviceFactory*>( | 179 video_capture_device_factory_ = static_cast<WrappedDeviceFactory*>( |
184 vcm_->video_capture_device_factory()); | 180 vcm_->video_capture_device_factory()); |
185 const int32_t kNumberOfFakeDevices = 2; | 181 const int32_t kNumberOfFakeDevices = 2; |
186 video_capture_device_factory_->set_number_of_devices(kNumberOfFakeDevices); | 182 video_capture_device_factory_->set_number_of_devices(kNumberOfFakeDevices); |
187 vcm_->Register(listener_.get(), message_loop_->task_runner().get()); | 183 vcm_->Register(listener_.get(), base::ThreadTaskRunnerHandle::Get()); |
188 frame_observer_.reset(new MockFrameObserver()); | 184 frame_observer_.reset(new MockFrameObserver()); |
189 | 185 |
190 base::RunLoop run_loop; | 186 base::RunLoop run_loop; |
191 vcm_->EnumerateDevices( | 187 vcm_->EnumerateDevices( |
192 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, | 188 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, |
193 base::Unretained(this), run_loop.QuitClosure())); | 189 base::Unretained(this), run_loop.QuitClosure())); |
194 run_loop.Run(); | 190 run_loop.Run(); |
195 ASSERT_GE(devices_.size(), 2u); | 191 ASSERT_GE(devices_.size(), 2u); |
196 } | 192 } |
197 | 193 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 #if defined(OS_ANDROID) | 258 #if defined(OS_ANDROID) |
263 void ApplicationStateChange(base::android::ApplicationState state) { | 259 void ApplicationStateChange(base::android::ApplicationState state) { |
264 vcm_->OnApplicationStateChange(state); | 260 vcm_->OnApplicationStateChange(state); |
265 } | 261 } |
266 #endif | 262 #endif |
267 | 263 |
268 int next_client_id_; | 264 int next_client_id_; |
269 std::map<VideoCaptureControllerID, VideoCaptureController*> controllers_; | 265 std::map<VideoCaptureControllerID, VideoCaptureController*> controllers_; |
270 scoped_refptr<VideoCaptureManager> vcm_; | 266 scoped_refptr<VideoCaptureManager> vcm_; |
271 std::unique_ptr<MockMediaStreamProviderListener> listener_; | 267 std::unique_ptr<MockMediaStreamProviderListener> listener_; |
272 std::unique_ptr<base::MessageLoop> message_loop_; | 268 TestBrowserThreadBundle thread_bundle_; |
273 std::unique_ptr<BrowserThreadImpl> ui_thread_; | |
274 std::unique_ptr<BrowserThreadImpl> io_thread_; | |
275 std::unique_ptr<MockFrameObserver> frame_observer_; | 269 std::unique_ptr<MockFrameObserver> frame_observer_; |
276 WrappedDeviceFactory* video_capture_device_factory_; | 270 WrappedDeviceFactory* video_capture_device_factory_; |
277 StreamDeviceInfoArray devices_; | 271 StreamDeviceInfoArray devices_; |
278 | 272 |
279 private: | 273 private: |
280 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManagerTest); | 274 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManagerTest); |
281 }; | 275 }; |
282 | 276 |
283 // Test cases | 277 // Test cases |
284 | 278 |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 // Wait to check callbacks before removing the listener. | 621 // Wait to check callbacks before removing the listener. |
628 base::RunLoop().RunUntilIdle(); | 622 base::RunLoop().RunUntilIdle(); |
629 vcm_->Unregister(); | 623 vcm_->Unregister(); |
630 } | 624 } |
631 #endif | 625 #endif |
632 | 626 |
633 // TODO(mcasas): Add a test to check consolidation of the supported formats | 627 // TODO(mcasas): Add a test to check consolidation of the supported formats |
634 // provided by the device when http://crbug.com/323913 is closed. | 628 // provided by the device when http://crbug.com/323913 is closed. |
635 | 629 |
636 } // namespace content | 630 } // namespace content |
OLD | NEW |