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 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 protected: | 195 protected: |
196 void SetUp() override { | 196 void SetUp() override { |
197 listener_.reset(new MockMediaStreamProviderListener()); | 197 listener_.reset(new MockMediaStreamProviderListener()); |
198 vcm_ = new VideoCaptureManager( | 198 vcm_ = new VideoCaptureManager( |
199 std::unique_ptr<media::VideoCaptureDeviceFactory>( | 199 std::unique_ptr<media::VideoCaptureDeviceFactory>( |
200 new WrappedDeviceFactory()), | 200 new WrappedDeviceFactory()), |
201 base::ThreadTaskRunnerHandle::Get()); | 201 base::ThreadTaskRunnerHandle::Get()); |
202 video_capture_device_factory_ = static_cast<WrappedDeviceFactory*>( | 202 video_capture_device_factory_ = static_cast<WrappedDeviceFactory*>( |
203 vcm_->video_capture_device_factory()); | 203 vcm_->video_capture_device_factory()); |
204 const int32_t kNumberOfFakeDevices = 2; | 204 const int32_t kNumberOfFakeDevices = 2; |
205 video_capture_device_factory_->set_number_of_devices(kNumberOfFakeDevices); | 205 video_capture_device_factory_->SetToDefaultDevicesConfig( |
| 206 kNumberOfFakeDevices); |
206 vcm_->RegisterListener(listener_.get()); | 207 vcm_->RegisterListener(listener_.get()); |
207 frame_observer_.reset(new MockFrameObserver()); | 208 frame_observer_.reset(new MockFrameObserver()); |
208 | 209 |
209 base::RunLoop run_loop; | 210 base::RunLoop run_loop; |
210 vcm_->EnumerateDevices( | 211 vcm_->EnumerateDevices( |
211 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, | 212 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, |
212 base::Unretained(this), run_loop.QuitClosure())); | 213 base::Unretained(this), run_loop.QuitClosure())); |
213 run_loop.Run(); | 214 run_loop.Run(); |
214 ASSERT_GE(devices_.size(), 2u); | 215 ASSERT_GE(devices_.size(), 2u); |
215 } | 216 } |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 base::RunLoop().RunUntilIdle(); | 398 base::RunLoop().RunUntilIdle(); |
398 vcm_->UnregisterListener(); | 399 vcm_->UnregisterListener(); |
399 } | 400 } |
400 | 401 |
401 // Connect and disconnect devices. | 402 // Connect and disconnect devices. |
402 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) { | 403 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) { |
403 int number_of_devices_keep = | 404 int number_of_devices_keep = |
404 video_capture_device_factory_->number_of_devices(); | 405 video_capture_device_factory_->number_of_devices(); |
405 | 406 |
406 // Simulate we remove 1 fake device. | 407 // Simulate we remove 1 fake device. |
407 video_capture_device_factory_->set_number_of_devices(1); | 408 video_capture_device_factory_->SetToDefaultDevicesConfig(1); |
408 base::RunLoop run_loop; | 409 base::RunLoop run_loop; |
409 vcm_->EnumerateDevices( | 410 vcm_->EnumerateDevices( |
410 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, | 411 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, |
411 base::Unretained(this), run_loop.QuitClosure())); | 412 base::Unretained(this), run_loop.QuitClosure())); |
412 run_loop.Run(); | 413 run_loop.Run(); |
413 ASSERT_EQ(devices_.size(), 1u); | 414 ASSERT_EQ(devices_.size(), 1u); |
414 | 415 |
415 // Simulate we add 2 fake devices. | 416 // Simulate we add 2 fake devices. |
416 video_capture_device_factory_->set_number_of_devices(3); | 417 video_capture_device_factory_->SetToDefaultDevicesConfig(3); |
417 base::RunLoop run_loop2; | 418 base::RunLoop run_loop2; |
418 vcm_->EnumerateDevices( | 419 vcm_->EnumerateDevices( |
419 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, | 420 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, |
420 base::Unretained(this), run_loop2.QuitClosure())); | 421 base::Unretained(this), run_loop2.QuitClosure())); |
421 run_loop2.Run(); | 422 run_loop2.Run(); |
422 ASSERT_EQ(devices_.size(), 3u); | 423 ASSERT_EQ(devices_.size(), 3u); |
423 | 424 |
424 vcm_->UnregisterListener(); | 425 vcm_->UnregisterListener(); |
425 video_capture_device_factory_->set_number_of_devices(number_of_devices_keep); | 426 video_capture_device_factory_->SetToDefaultDevicesConfig( |
| 427 number_of_devices_keep); |
426 } | 428 } |
427 | 429 |
428 // Enumerate devices and open the first, then check the list of supported | 430 // Enumerate devices and open the first, then check the list of supported |
429 // formats. Then start the opened device. The capability list should stay the | 431 // formats. Then start the opened device. The capability list should stay the |
430 // same. Finally stop the device and check that the capabilities stay unchanged. | 432 // same. Finally stop the device and check that the capabilities stay unchanged. |
431 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { | 433 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { |
432 // Before enumerating the devices, requesting formats should return false. | 434 // Before enumerating the devices, requesting formats should return false. |
433 int video_session_id = 0; | 435 int video_session_id = 0; |
434 media::VideoCaptureFormats supported_formats; | 436 media::VideoCaptureFormats supported_formats; |
435 supported_formats.clear(); | 437 supported_formats.clear(); |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 // Wait to check callbacks before removing the listener. | 788 // Wait to check callbacks before removing the listener. |
787 base::RunLoop().RunUntilIdle(); | 789 base::RunLoop().RunUntilIdle(); |
788 vcm_->UnregisterListener(); | 790 vcm_->UnregisterListener(); |
789 } | 791 } |
790 #endif | 792 #endif |
791 | 793 |
792 // TODO(mcasas): Add a test to check consolidation of the supported formats | 794 // TODO(mcasas): Add a test to check consolidation of the supported formats |
793 // provided by the device when http://crbug.com/323913 is closed. | 795 // provided by the device when http://crbug.com/323913 is closed. |
794 | 796 |
795 } // namespace content | 797 } // namespace content |
OLD | NEW |