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/video_capture_device.h" | 20 #include "media/video/capture/video_capture_device.h" |
20 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
23 using ::testing::_; | 24 using ::testing::_; |
24 using ::testing::AnyNumber; | 25 using ::testing::AnyNumber; |
25 using ::testing::InSequence; | 26 using ::testing::InSequence; |
26 using ::testing::Return; | 27 using ::testing::Return; |
27 using ::testing::SaveArg; | 28 using ::testing::SaveArg; |
28 | 29 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 message_loop_->RunUntilIdle(); | 161 message_loop_->RunUntilIdle(); |
161 vcm_->Unregister(); | 162 vcm_->Unregister(); |
162 } | 163 } |
163 | 164 |
164 // Open the same device twice. | 165 // Open the same device twice. |
165 TEST_F(VideoCaptureManagerTest, OpenTwice) { | 166 TEST_F(VideoCaptureManagerTest, OpenTwice) { |
166 StreamDeviceInfoArray devices; | 167 StreamDeviceInfoArray devices; |
167 | 168 |
168 InSequence s; | 169 InSequence s; |
169 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 170 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
170 .Times(1).WillOnce(SaveArg<1>(&devices)); | 171 .Times(1) |
| 172 .WillOnce(SaveArg<1>(&devices)); |
171 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 173 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
172 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 174 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
173 | 175 |
174 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 176 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
175 | 177 |
176 // Wait to get device callback. | 178 // Wait to get device callback. |
177 message_loop_->RunUntilIdle(); | 179 message_loop_->RunUntilIdle(); |
178 | 180 |
179 int video_session_id_first = vcm_->Open(devices.front()); | 181 int video_session_id_first = vcm_->Open(devices.front()); |
180 | 182 |
181 // This should trigger an error callback with error code | 183 // This should trigger an error callback with error code |
182 // 'kDeviceAlreadyInUse'. | 184 // 'kDeviceAlreadyInUse'. |
183 int video_session_id_second = vcm_->Open(devices.front()); | 185 int video_session_id_second = vcm_->Open(devices.front()); |
184 EXPECT_NE(video_session_id_first, video_session_id_second); | 186 EXPECT_NE(video_session_id_first, video_session_id_second); |
185 | 187 |
186 vcm_->Close(video_session_id_first); | 188 vcm_->Close(video_session_id_first); |
187 vcm_->Close(video_session_id_second); | 189 vcm_->Close(video_session_id_second); |
188 | 190 |
189 // Wait to check callbacks before removing the listener. | 191 // Wait to check callbacks before removing the listener. |
190 message_loop_->RunUntilIdle(); | 192 message_loop_->RunUntilIdle(); |
191 vcm_->Unregister(); | 193 vcm_->Unregister(); |
192 } | 194 } |
193 | 195 |
| 196 // Connect and disconnect devices. |
| 197 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) { |
| 198 StreamDeviceInfoArray devices; |
| 199 int number_of_devices_keep = |
| 200 media::FakeVideoCaptureDevice::NumberOfFakeDevices(); |
| 201 |
| 202 InSequence s; |
| 203 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 204 .Times(1) |
| 205 .WillOnce(SaveArg<1>(&devices)); |
| 206 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 207 message_loop_->RunUntilIdle(); |
| 208 ASSERT_EQ(devices.size(), 2u); |
| 209 |
| 210 // Simulate we remove 1 fake device. |
| 211 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(1); |
| 212 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 213 .Times(1) |
| 214 .WillOnce(SaveArg<1>(&devices)); |
| 215 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 216 message_loop_->RunUntilIdle(); |
| 217 ASSERT_EQ(devices.size(), 1u); |
| 218 |
| 219 // Simulate we add 2 fake devices. |
| 220 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(3); |
| 221 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 222 .Times(1) |
| 223 .WillOnce(SaveArg<1>(&devices)); |
| 224 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 225 message_loop_->RunUntilIdle(); |
| 226 ASSERT_EQ(devices.size(), 3u); |
| 227 |
| 228 vcm_->Unregister(); |
| 229 media::FakeVideoCaptureDevice::SetNumberOfFakeDevices(number_of_devices_keep); |
| 230 } |
| 231 |
| 232 // Enumerate devices and open the first, then check the capabilities. Then start |
| 233 // the opened device. The capability list should be reduced to just one format, |
| 234 // and this should be the one used when configuring-starting the device. Finally |
| 235 // stop the device and check that the capabilities have been restored. |
| 236 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { |
| 237 StreamDeviceInfoArray devices; |
| 238 |
| 239 InSequence s; |
| 240 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 241 .Times(1) |
| 242 .WillOnce(SaveArg<1>(&devices)); |
| 243 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 244 message_loop_->RunUntilIdle(); |
| 245 |
| 246 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1); |
| 247 int video_session_id = vcm_->Open(devices.front()); |
| 248 message_loop_->RunUntilIdle(); |
| 249 |
| 250 // When the device has been opened, we should see all the devices' |
| 251 // capabilities. |
| 252 media::VideoCaptureCapabilities device_capabilities; |
| 253 vcm_->GetDeviceCapabilities(video_session_id, &device_capabilities); |
| 254 ASSERT_EQ(devices.size(), 2u); |
| 255 ASSERT_GT(device_capabilities.size(), 1u); |
| 256 EXPECT_GT(device_capabilities[0].width, 1); |
| 257 EXPECT_GT(device_capabilities[0].height, 1); |
| 258 EXPECT_GT(device_capabilities[0].frame_rate, 1); |
| 259 EXPECT_GT(device_capabilities[1].width, 1); |
| 260 EXPECT_GT(device_capabilities[1].height, 1); |
| 261 EXPECT_GT(device_capabilities[1].frame_rate, 1); |
| 262 |
| 263 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 264 message_loop_->RunUntilIdle(); |
| 265 // After StartClient(), the device's capabilities should be reduced to one. |
| 266 vcm_->GetDeviceCapabilities(video_session_id, &device_capabilities); |
| 267 ASSERT_EQ(device_capabilities.size(), 1u); |
| 268 EXPECT_GT(device_capabilities[0].width, 1); |
| 269 EXPECT_GT(device_capabilities[0].height, 1); |
| 270 EXPECT_GT(device_capabilities[0].frame_rate, 1); |
| 271 |
| 272 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(1); |
| 273 StopClient(client_id); |
| 274 message_loop_->RunUntilIdle(); |
| 275 // After StopClient(), the device's list of capabilities should be restored |
| 276 // to the original one. |
| 277 vcm_->GetDeviceCapabilities(video_session_id, &device_capabilities); |
| 278 ASSERT_GT(device_capabilities.size(), 1u); |
| 279 EXPECT_GT(device_capabilities[0].width, 1); |
| 280 EXPECT_GT(device_capabilities[0].height, 1); |
| 281 EXPECT_GT(device_capabilities[0].frame_rate, 1); |
| 282 EXPECT_GT(device_capabilities[1].width, 1); |
| 283 EXPECT_GT(device_capabilities[1].height, 1); |
| 284 EXPECT_GT(device_capabilities[1].frame_rate, 1); |
| 285 |
| 286 vcm_->Close(video_session_id); |
| 287 message_loop_->RunUntilIdle(); |
| 288 vcm_->Unregister(); |
| 289 } |
| 290 |
194 // Open two different devices. | 291 // Open two different devices. |
195 TEST_F(VideoCaptureManagerTest, OpenTwo) { | 292 TEST_F(VideoCaptureManagerTest, OpenTwo) { |
196 StreamDeviceInfoArray devices; | 293 StreamDeviceInfoArray devices; |
197 | 294 |
198 InSequence s; | 295 InSequence s; |
199 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 296 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
200 .Times(1).WillOnce(SaveArg<1>(&devices)); | 297 .Times(1).WillOnce(SaveArg<1>(&devices)); |
201 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 298 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
202 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 299 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
203 | 300 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 // VideoCaptureManager destructor otherwise. | 382 // VideoCaptureManager destructor otherwise. |
286 vcm_->Close(video_session_id); | 383 vcm_->Close(video_session_id); |
287 StopClient(client_id); | 384 StopClient(client_id); |
288 | 385 |
289 // Wait to check callbacks before removing the listener | 386 // Wait to check callbacks before removing the listener |
290 message_loop_->RunUntilIdle(); | 387 message_loop_->RunUntilIdle(); |
291 vcm_->Unregister(); | 388 vcm_->Unregister(); |
292 } | 389 } |
293 | 390 |
294 } // namespace content | 391 } // namespace content |
OLD | NEW |