| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "content/browser/browser_thread_impl.h" | 14 #include "content/browser/browser_thread_impl.h" |
| 15 #include "content/browser/renderer_host/media/media_stream_provider.h" | 15 #include "content/browser/renderer_host/media/media_stream_provider.h" |
| 16 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" | 16 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" |
| 17 #include "content/browser/renderer_host/media/video_capture_manager.h" | 17 #include "content/browser/renderer_host/media/video_capture_manager.h" |
| 18 #include "content/common/media/media_stream_options.h" | 18 #include "content/common/media/media_stream_options.h" |
| 19 #include "media/video/capture/fake_video_capture_device.h" | 19 #include "media/video/capture/fake_video_capture_device_factory.h" |
| 20 #include "media/video/capture/video_capture_device.h" | |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 22 |
| 24 using ::testing::_; | 23 using ::testing::_; |
| 25 using ::testing::AnyNumber; | 24 using ::testing::AnyNumber; |
| 26 using ::testing::InSequence; | 25 using ::testing::InSequence; |
| 27 using ::testing::Return; | 26 using ::testing::Return; |
| 28 using ::testing::SaveArg; | 27 using ::testing::SaveArg; |
| 29 | 28 |
| 30 namespace content { | 29 namespace content { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 public: | 71 public: |
| 73 VideoCaptureManagerTest() : next_client_id_(1) {} | 72 VideoCaptureManagerTest() : next_client_id_(1) {} |
| 74 virtual ~VideoCaptureManagerTest() {} | 73 virtual ~VideoCaptureManagerTest() {} |
| 75 | 74 |
| 76 protected: | 75 protected: |
| 77 virtual void SetUp() OVERRIDE { | 76 virtual void SetUp() OVERRIDE { |
| 78 listener_.reset(new MockMediaStreamProviderListener()); | 77 listener_.reset(new MockMediaStreamProviderListener()); |
| 79 message_loop_.reset(new base::MessageLoopForIO); | 78 message_loop_.reset(new base::MessageLoopForIO); |
| 80 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, | 79 io_thread_.reset(new BrowserThreadImpl(BrowserThread::IO, |
| 81 message_loop_.get())); | 80 message_loop_.get())); |
| 82 vcm_ = new VideoCaptureManager(); | 81 vcm_ = new VideoCaptureManager(scoped_ptr<media::VideoCaptureDeviceFactory>( |
| 83 vcm_->UseFakeDevice(); | 82 new media::FakeVideoCaptureDeviceFactory())); |
| 83 video_capture_device_factory_ = |
| 84 static_cast<media::FakeVideoCaptureDeviceFactory*>( |
| 85 vcm_->video_capture_device_factory()); |
| 84 vcm_->Register(listener_.get(), message_loop_->message_loop_proxy().get()); | 86 vcm_->Register(listener_.get(), message_loop_->message_loop_proxy().get()); |
| 85 frame_observer_.reset(new MockFrameObserver()); | 87 frame_observer_.reset(new MockFrameObserver()); |
| 86 } | 88 } |
| 87 | 89 |
| 88 virtual void TearDown() OVERRIDE {} | 90 virtual void TearDown() OVERRIDE {} |
| 89 | 91 |
| 90 void OnGotControllerCallback( | 92 void OnGotControllerCallback( |
| 91 VideoCaptureControllerID id, | 93 VideoCaptureControllerID id, |
| 92 base::Closure quit_closure, | 94 base::Closure quit_closure, |
| 93 bool expect_success, | 95 bool expect_success, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 controllers_.erase(client_id); | 133 controllers_.erase(client_id); |
| 132 } | 134 } |
| 133 | 135 |
| 134 int next_client_id_; | 136 int next_client_id_; |
| 135 std::map<VideoCaptureControllerID, VideoCaptureController*> controllers_; | 137 std::map<VideoCaptureControllerID, VideoCaptureController*> controllers_; |
| 136 scoped_refptr<VideoCaptureManager> vcm_; | 138 scoped_refptr<VideoCaptureManager> vcm_; |
| 137 scoped_ptr<MockMediaStreamProviderListener> listener_; | 139 scoped_ptr<MockMediaStreamProviderListener> listener_; |
| 138 scoped_ptr<base::MessageLoop> message_loop_; | 140 scoped_ptr<base::MessageLoop> message_loop_; |
| 139 scoped_ptr<BrowserThreadImpl> io_thread_; | 141 scoped_ptr<BrowserThreadImpl> io_thread_; |
| 140 scoped_ptr<MockFrameObserver> frame_observer_; | 142 scoped_ptr<MockFrameObserver> frame_observer_; |
| 143 media::FakeVideoCaptureDeviceFactory* video_capture_device_factory_; |
| 141 | 144 |
| 142 private: | 145 private: |
| 143 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManagerTest); | 146 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManagerTest); |
| 144 }; | 147 }; |
| 145 | 148 |
| 146 // Test cases | 149 // Test cases |
| 147 | 150 |
| 148 // Try to open, start, stop and close a device. | 151 // Try to open, start, stop and close a device. |
| 149 TEST_F(VideoCaptureManagerTest, CreateAndClose) { | 152 TEST_F(VideoCaptureManagerTest, CreateAndClose) { |
| 150 StreamDeviceInfoArray devices; | 153 StreamDeviceInfoArray devices; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 201 |
| 199 // Wait to check callbacks before removing the listener. | 202 // Wait to check callbacks before removing the listener. |
| 200 message_loop_->RunUntilIdle(); | 203 message_loop_->RunUntilIdle(); |
| 201 vcm_->Unregister(); | 204 vcm_->Unregister(); |
| 202 } | 205 } |
| 203 | 206 |
| 204 // Connect and disconnect devices. | 207 // Connect and disconnect devices. |
| 205 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) { | 208 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) { |
| 206 StreamDeviceInfoArray devices; | 209 StreamDeviceInfoArray devices; |
| 207 int number_of_devices_keep = | 210 int number_of_devices_keep = |
| 208 media::FakeVideoCaptureDevice::NumberOfFakeDevices(); | 211 video_capture_device_factory_->number_of_devices(); |
| 209 | 212 |
| 210 InSequence s; | 213 InSequence s; |
| 211 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 214 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 212 .WillOnce(SaveArg<1>(&devices)); | 215 .WillOnce(SaveArg<1>(&devices)); |
| 213 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 216 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 214 message_loop_->RunUntilIdle(); | 217 message_loop_->RunUntilIdle(); |
| 215 ASSERT_EQ(devices.size(), 2u); | 218 ASSERT_EQ(devices.size(), 2u); |
| 216 | 219 |
| 217 // Simulate we remove 1 fake device. | 220 // Simulate we remove 1 fake device. |
| 218 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(1); | 221 video_capture_device_factory_->set_number_of_devices(1); |
| 219 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 222 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 220 .WillOnce(SaveArg<1>(&devices)); | 223 .WillOnce(SaveArg<1>(&devices)); |
| 221 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 224 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 222 message_loop_->RunUntilIdle(); | 225 message_loop_->RunUntilIdle(); |
| 223 ASSERT_EQ(devices.size(), 1u); | 226 ASSERT_EQ(devices.size(), 1u); |
| 224 | 227 |
| 225 // Simulate we add 2 fake devices. | 228 // Simulate we add 2 fake devices. |
| 226 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(3); | 229 video_capture_device_factory_->set_number_of_devices(3); |
| 227 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 230 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 228 .WillOnce(SaveArg<1>(&devices)); | 231 .WillOnce(SaveArg<1>(&devices)); |
| 229 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 232 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 230 message_loop_->RunUntilIdle(); | 233 message_loop_->RunUntilIdle(); |
| 231 ASSERT_EQ(devices.size(), 3u); | 234 ASSERT_EQ(devices.size(), 3u); |
| 232 | 235 |
| 233 vcm_->Unregister(); | 236 vcm_->Unregister(); |
| 234 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(number_of_devices_keep); | 237 video_capture_device_factory_->set_number_of_devices(number_of_devices_keep); |
| 235 } | 238 } |
| 236 | 239 |
| 237 // Enumerate devices and open the first, then check the list of supported | 240 // Enumerate devices and open the first, then check the list of supported |
| 238 // formats. Then start the opened device. The capability list should stay the | 241 // formats. Then start the opened device. The capability list should stay the |
| 239 // same. Finally stop the device and check that the capabilities stay unchanged. | 242 // same. Finally stop the device and check that the capabilities stay unchanged. |
| 240 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { | 243 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { |
| 241 StreamDeviceInfoArray devices; | 244 StreamDeviceInfoArray devices; |
| 242 | 245 |
| 243 // Before enumerating the devices, requesting formats should return false. | 246 // Before enumerating the devices, requesting formats should return false. |
| 244 int video_session_id = 0; | 247 int video_session_id = 0; |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 | 452 |
| 450 // Wait to check callbacks before removing the listener | 453 // Wait to check callbacks before removing the listener |
| 451 message_loop_->RunUntilIdle(); | 454 message_loop_->RunUntilIdle(); |
| 452 vcm_->Unregister(); | 455 vcm_->Unregister(); |
| 453 } | 456 } |
| 454 | 457 |
| 455 // TODO(mcasas): Add a test to check consolidation of the supported formats | 458 // TODO(mcasas): Add a test to check consolidation of the supported formats |
| 456 // provided by the device when http://crbug.com/323913 is closed. | 459 // provided by the device when http://crbug.com/323913 is closed. |
| 457 | 460 |
| 458 } // namespace content | 461 } // namespace content |
| OLD | NEW |