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()); |
| 86 video_capture_device_factory_->set_number_of_devices(kNumberOfFakeDevices); |
84 vcm_->Register(listener_.get(), message_loop_->message_loop_proxy().get()); | 87 vcm_->Register(listener_.get(), message_loop_->message_loop_proxy().get()); |
85 frame_observer_.reset(new MockFrameObserver()); | 88 frame_observer_.reset(new MockFrameObserver()); |
86 } | 89 } |
87 | 90 |
88 virtual void TearDown() OVERRIDE {} | 91 virtual void TearDown() OVERRIDE {} |
89 | 92 |
90 void OnGotControllerCallback( | 93 void OnGotControllerCallback( |
91 VideoCaptureControllerID id, | 94 VideoCaptureControllerID id, |
92 base::Closure quit_closure, | 95 base::Closure quit_closure, |
93 bool expect_success, | 96 bool expect_success, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 controllers_.erase(client_id); | 134 controllers_.erase(client_id); |
132 } | 135 } |
133 | 136 |
134 int next_client_id_; | 137 int next_client_id_; |
135 std::map<VideoCaptureControllerID, VideoCaptureController*> controllers_; | 138 std::map<VideoCaptureControllerID, VideoCaptureController*> controllers_; |
136 scoped_refptr<VideoCaptureManager> vcm_; | 139 scoped_refptr<VideoCaptureManager> vcm_; |
137 scoped_ptr<MockMediaStreamProviderListener> listener_; | 140 scoped_ptr<MockMediaStreamProviderListener> listener_; |
138 scoped_ptr<base::MessageLoop> message_loop_; | 141 scoped_ptr<base::MessageLoop> message_loop_; |
139 scoped_ptr<BrowserThreadImpl> io_thread_; | 142 scoped_ptr<BrowserThreadImpl> io_thread_; |
140 scoped_ptr<MockFrameObserver> frame_observer_; | 143 scoped_ptr<MockFrameObserver> frame_observer_; |
| 144 media::FakeVideoCaptureDeviceFactory* video_capture_device_factory_; |
141 | 145 |
142 private: | 146 private: |
| 147 const int32 kNumberOfFakeDevices = 2; |
| 148 |
143 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManagerTest); | 149 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManagerTest); |
144 }; | 150 }; |
145 | 151 |
146 // Test cases | 152 // Test cases |
147 | 153 |
148 // Try to open, start, stop and close a device. | 154 // Try to open, start, stop and close a device. |
149 TEST_F(VideoCaptureManagerTest, CreateAndClose) { | 155 TEST_F(VideoCaptureManagerTest, CreateAndClose) { |
150 StreamDeviceInfoArray devices; | 156 StreamDeviceInfoArray devices; |
151 | 157 |
152 InSequence s; | 158 InSequence s; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 204 |
199 // Wait to check callbacks before removing the listener. | 205 // Wait to check callbacks before removing the listener. |
200 message_loop_->RunUntilIdle(); | 206 message_loop_->RunUntilIdle(); |
201 vcm_->Unregister(); | 207 vcm_->Unregister(); |
202 } | 208 } |
203 | 209 |
204 // Connect and disconnect devices. | 210 // Connect and disconnect devices. |
205 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) { | 211 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) { |
206 StreamDeviceInfoArray devices; | 212 StreamDeviceInfoArray devices; |
207 int number_of_devices_keep = | 213 int number_of_devices_keep = |
208 media::FakeVideoCaptureDevice::NumberOfFakeDevices(); | 214 video_capture_device_factory_->number_of_devices(); |
209 | 215 |
210 InSequence s; | 216 InSequence s; |
211 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 217 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
212 .WillOnce(SaveArg<1>(&devices)); | 218 .WillOnce(SaveArg<1>(&devices)); |
213 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 219 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
214 message_loop_->RunUntilIdle(); | 220 message_loop_->RunUntilIdle(); |
215 ASSERT_EQ(devices.size(), 2u); | 221 ASSERT_EQ(devices.size(), 2u); |
216 | 222 |
217 // Simulate we remove 1 fake device. | 223 // Simulate we remove 1 fake device. |
218 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(1); | 224 video_capture_device_factory_->set_number_of_devices(1); |
219 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 225 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
220 .WillOnce(SaveArg<1>(&devices)); | 226 .WillOnce(SaveArg<1>(&devices)); |
221 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 227 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
222 message_loop_->RunUntilIdle(); | 228 message_loop_->RunUntilIdle(); |
223 ASSERT_EQ(devices.size(), 1u); | 229 ASSERT_EQ(devices.size(), 1u); |
224 | 230 |
225 // Simulate we add 2 fake devices. | 231 // Simulate we add 2 fake devices. |
226 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(3); | 232 video_capture_device_factory_->set_number_of_devices(3); |
227 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 233 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
228 .WillOnce(SaveArg<1>(&devices)); | 234 .WillOnce(SaveArg<1>(&devices)); |
229 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 235 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
230 message_loop_->RunUntilIdle(); | 236 message_loop_->RunUntilIdle(); |
231 ASSERT_EQ(devices.size(), 3u); | 237 ASSERT_EQ(devices.size(), 3u); |
232 | 238 |
233 vcm_->Unregister(); | 239 vcm_->Unregister(); |
234 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(number_of_devices_keep); | 240 video_capture_device_factory_->set_number_of_devices(number_of_devices_keep); |
235 } | 241 } |
236 | 242 |
237 // Enumerate devices and open the first, then check the list of supported | 243 // 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 | 244 // 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. | 245 // same. Finally stop the device and check that the capabilities stay unchanged. |
240 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { | 246 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { |
241 StreamDeviceInfoArray devices; | 247 StreamDeviceInfoArray devices; |
242 | 248 |
243 // Before enumerating the devices, requesting formats should return false. | 249 // Before enumerating the devices, requesting formats should return false. |
244 int video_session_id = 0; | 250 int video_session_id = 0; |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 | 455 |
450 // Wait to check callbacks before removing the listener | 456 // Wait to check callbacks before removing the listener |
451 message_loop_->RunUntilIdle(); | 457 message_loop_->RunUntilIdle(); |
452 vcm_->Unregister(); | 458 vcm_->Unregister(); |
453 } | 459 } |
454 | 460 |
455 // TODO(mcasas): Add a test to check consolidation of the supported formats | 461 // TODO(mcasas): Add a test to check consolidation of the supported formats |
456 // provided by the device when http://crbug.com/323913 is closed. | 462 // provided by the device when http://crbug.com/323913 is closed. |
457 | 463 |
458 } // namespace content | 464 } // namespace content |
OLD | NEW |