| 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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 187 |
| 188 InSequence s; | 188 InSequence s; |
| 189 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 189 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 190 .WillOnce(SaveArg<1>(&devices)); | 190 .WillOnce(SaveArg<1>(&devices)); |
| 191 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 191 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 192 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 192 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 193 | 193 |
| 194 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 194 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 195 | 195 |
| 196 // Wait to get device callback. | 196 // Wait to get device callback. |
| 197 message_loop_->RunUntilIdle(); | 197 base::RunLoop().RunUntilIdle(); |
| 198 | 198 |
| 199 int video_session_id = vcm_->Open(devices.front()); | 199 int video_session_id = vcm_->Open(devices.front()); |
| 200 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 200 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 201 | 201 |
| 202 StopClient(client_id); | 202 StopClient(client_id); |
| 203 vcm_->Close(video_session_id); | 203 vcm_->Close(video_session_id); |
| 204 | 204 |
| 205 // Wait to check callbacks before removing the listener. | 205 // Wait to check callbacks before removing the listener. |
| 206 message_loop_->RunUntilIdle(); | 206 base::RunLoop().RunUntilIdle(); |
| 207 vcm_->Unregister(); | 207 vcm_->Unregister(); |
| 208 } | 208 } |
| 209 | 209 |
| 210 TEST_F(VideoCaptureManagerTest, CreateAndCloseMultipleTimes) { | 210 TEST_F(VideoCaptureManagerTest, CreateAndCloseMultipleTimes) { |
| 211 StreamDeviceInfoArray devices; | 211 StreamDeviceInfoArray devices; |
| 212 | 212 |
| 213 InSequence s; | 213 InSequence s; |
| 214 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 214 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 215 .WillOnce(SaveArg<1>(&devices)); | 215 .WillOnce(SaveArg<1>(&devices)); |
| 216 | 216 |
| 217 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 217 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 218 | 218 |
| 219 // Wait to get device callback. | 219 // Wait to get device callback. |
| 220 message_loop_->RunUntilIdle(); | 220 base::RunLoop().RunUntilIdle(); |
| 221 | 221 |
| 222 for (int i = 1 ; i < 3 ; ++i) { | 222 for (int i = 1 ; i < 3 ; ++i) { |
| 223 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, i)); | 223 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, i)); |
| 224 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, i)); | 224 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, i)); |
| 225 int video_session_id = vcm_->Open(devices.front()); | 225 int video_session_id = vcm_->Open(devices.front()); |
| 226 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 226 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 227 | 227 |
| 228 StopClient(client_id); | 228 StopClient(client_id); |
| 229 vcm_->Close(video_session_id); | 229 vcm_->Close(video_session_id); |
| 230 } | 230 } |
| 231 | 231 |
| 232 // Wait to check callbacks before removing the listener. | 232 // Wait to check callbacks before removing the listener. |
| 233 message_loop_->RunUntilIdle(); | 233 base::RunLoop().RunUntilIdle(); |
| 234 vcm_->Unregister(); | 234 vcm_->Unregister(); |
| 235 } | 235 } |
| 236 | 236 |
| 237 // Try to open, start, and abort a device. | 237 // Try to open, start, and abort a device. |
| 238 TEST_F(VideoCaptureManagerTest, CreateAndAbort) { | 238 TEST_F(VideoCaptureManagerTest, CreateAndAbort) { |
| 239 StreamDeviceInfoArray devices; | 239 StreamDeviceInfoArray devices; |
| 240 | 240 |
| 241 InSequence s; | 241 InSequence s; |
| 242 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 242 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 243 .WillOnce(SaveArg<1>(&devices)); | 243 .WillOnce(SaveArg<1>(&devices)); |
| 244 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 244 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 245 EXPECT_CALL(*listener_, Aborted(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 245 EXPECT_CALL(*listener_, Aborted(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 246 | 246 |
| 247 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 247 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 248 | 248 |
| 249 // Wait to get device callback. | 249 // Wait to get device callback. |
| 250 message_loop_->RunUntilIdle(); | 250 base::RunLoop().RunUntilIdle(); |
| 251 | 251 |
| 252 int video_session_id = vcm_->Open(devices.front()); | 252 int video_session_id = vcm_->Open(devices.front()); |
| 253 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 253 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 254 | 254 |
| 255 // Wait for device opened. | 255 // Wait for device opened. |
| 256 message_loop_->RunUntilIdle(); | 256 base::RunLoop().RunUntilIdle(); |
| 257 | 257 |
| 258 vcm_->StopCaptureForClient(controllers_[client_id], client_id, | 258 vcm_->StopCaptureForClient(controllers_[client_id], client_id, |
| 259 frame_observer_.get(), true); | 259 frame_observer_.get(), true); |
| 260 | 260 |
| 261 // Wait to check callbacks before removing the listener. | 261 // Wait to check callbacks before removing the listener. |
| 262 message_loop_->RunUntilIdle(); | 262 base::RunLoop().RunUntilIdle(); |
| 263 vcm_->Unregister(); | 263 vcm_->Unregister(); |
| 264 } | 264 } |
| 265 | 265 |
| 266 // Open the same device twice. | 266 // Open the same device twice. |
| 267 TEST_F(VideoCaptureManagerTest, OpenTwice) { | 267 TEST_F(VideoCaptureManagerTest, OpenTwice) { |
| 268 StreamDeviceInfoArray devices; | 268 StreamDeviceInfoArray devices; |
| 269 | 269 |
| 270 InSequence s; | 270 InSequence s; |
| 271 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 271 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 272 .WillOnce(SaveArg<1>(&devices)); | 272 .WillOnce(SaveArg<1>(&devices)); |
| 273 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 273 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 274 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 274 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 275 | 275 |
| 276 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 276 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 277 | 277 |
| 278 // Wait to get device callback. | 278 // Wait to get device callback. |
| 279 message_loop_->RunUntilIdle(); | 279 base::RunLoop().RunUntilIdle(); |
| 280 | 280 |
| 281 int video_session_id_first = vcm_->Open(devices.front()); | 281 int video_session_id_first = vcm_->Open(devices.front()); |
| 282 | 282 |
| 283 // This should trigger an error callback with error code | 283 // This should trigger an error callback with error code |
| 284 // 'kDeviceAlreadyInUse'. | 284 // 'kDeviceAlreadyInUse'. |
| 285 int video_session_id_second = vcm_->Open(devices.front()); | 285 int video_session_id_second = vcm_->Open(devices.front()); |
| 286 EXPECT_NE(video_session_id_first, video_session_id_second); | 286 EXPECT_NE(video_session_id_first, video_session_id_second); |
| 287 | 287 |
| 288 vcm_->Close(video_session_id_first); | 288 vcm_->Close(video_session_id_first); |
| 289 vcm_->Close(video_session_id_second); | 289 vcm_->Close(video_session_id_second); |
| 290 | 290 |
| 291 // Wait to check callbacks before removing the listener. | 291 // Wait to check callbacks before removing the listener. |
| 292 message_loop_->RunUntilIdle(); | 292 base::RunLoop().RunUntilIdle(); |
| 293 vcm_->Unregister(); | 293 vcm_->Unregister(); |
| 294 } | 294 } |
| 295 | 295 |
| 296 // Connect and disconnect devices. | 296 // Connect and disconnect devices. |
| 297 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) { | 297 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) { |
| 298 StreamDeviceInfoArray devices; | 298 StreamDeviceInfoArray devices; |
| 299 int number_of_devices_keep = | 299 int number_of_devices_keep = |
| 300 video_capture_device_factory_->number_of_devices(); | 300 video_capture_device_factory_->number_of_devices(); |
| 301 | 301 |
| 302 InSequence s; | 302 InSequence s; |
| 303 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 303 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 304 .WillOnce(SaveArg<1>(&devices)); | 304 .WillOnce(SaveArg<1>(&devices)); |
| 305 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 305 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 306 message_loop_->RunUntilIdle(); | 306 base::RunLoop().RunUntilIdle(); |
| 307 ASSERT_EQ(devices.size(), 2u); | 307 ASSERT_EQ(devices.size(), 2u); |
| 308 | 308 |
| 309 // Simulate we remove 1 fake device. | 309 // Simulate we remove 1 fake device. |
| 310 video_capture_device_factory_->set_number_of_devices(1); | 310 video_capture_device_factory_->set_number_of_devices(1); |
| 311 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 311 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 312 .WillOnce(SaveArg<1>(&devices)); | 312 .WillOnce(SaveArg<1>(&devices)); |
| 313 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 313 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 314 message_loop_->RunUntilIdle(); | 314 base::RunLoop().RunUntilIdle(); |
| 315 ASSERT_EQ(devices.size(), 1u); | 315 ASSERT_EQ(devices.size(), 1u); |
| 316 | 316 |
| 317 // Simulate we add 2 fake devices. | 317 // Simulate we add 2 fake devices. |
| 318 video_capture_device_factory_->set_number_of_devices(3); | 318 video_capture_device_factory_->set_number_of_devices(3); |
| 319 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 319 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 320 .WillOnce(SaveArg<1>(&devices)); | 320 .WillOnce(SaveArg<1>(&devices)); |
| 321 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 321 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 322 message_loop_->RunUntilIdle(); | 322 base::RunLoop().RunUntilIdle(); |
| 323 ASSERT_EQ(devices.size(), 3u); | 323 ASSERT_EQ(devices.size(), 3u); |
| 324 | 324 |
| 325 vcm_->Unregister(); | 325 vcm_->Unregister(); |
| 326 video_capture_device_factory_->set_number_of_devices(number_of_devices_keep); | 326 video_capture_device_factory_->set_number_of_devices(number_of_devices_keep); |
| 327 } | 327 } |
| 328 | 328 |
| 329 // Enumerate devices and open the first, then check the list of supported | 329 // Enumerate devices and open the first, then check the list of supported |
| 330 // formats. Then start the opened device. The capability list should stay the | 330 // formats. Then start the opened device. The capability list should stay the |
| 331 // same. Finally stop the device and check that the capabilities stay unchanged. | 331 // same. Finally stop the device and check that the capabilities stay unchanged. |
| 332 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { | 332 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { |
| 333 StreamDeviceInfoArray devices; | 333 StreamDeviceInfoArray devices; |
| 334 | 334 |
| 335 // Before enumerating the devices, requesting formats should return false. | 335 // Before enumerating the devices, requesting formats should return false. |
| 336 int video_session_id = 0; | 336 int video_session_id = 0; |
| 337 media::VideoCaptureFormats supported_formats; | 337 media::VideoCaptureFormats supported_formats; |
| 338 supported_formats.clear(); | 338 supported_formats.clear(); |
| 339 EXPECT_FALSE( | 339 EXPECT_FALSE( |
| 340 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats)); | 340 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats)); |
| 341 | 341 |
| 342 InSequence s; | 342 InSequence s; |
| 343 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 343 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 344 .WillOnce(SaveArg<1>(&devices)); | 344 .WillOnce(SaveArg<1>(&devices)); |
| 345 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 345 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 346 message_loop_->RunUntilIdle(); | 346 base::RunLoop().RunUntilIdle(); |
| 347 ASSERT_GE(devices.size(), 2u); | 347 ASSERT_GE(devices.size(), 2u); |
| 348 | 348 |
| 349 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 349 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 350 video_session_id = vcm_->Open(devices.front()); | 350 video_session_id = vcm_->Open(devices.front()); |
| 351 message_loop_->RunUntilIdle(); | 351 base::RunLoop().RunUntilIdle(); |
| 352 | 352 |
| 353 // Right after opening the device, we should see all its formats. | 353 // Right after opening the device, we should see all its formats. |
| 354 supported_formats.clear(); | 354 supported_formats.clear(); |
| 355 EXPECT_TRUE( | 355 EXPECT_TRUE( |
| 356 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats)); | 356 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats)); |
| 357 ASSERT_GT(supported_formats.size(), 1u); | 357 ASSERT_GT(supported_formats.size(), 1u); |
| 358 EXPECT_GT(supported_formats[0].frame_size.width(), 1); | 358 EXPECT_GT(supported_formats[0].frame_size.width(), 1); |
| 359 EXPECT_GT(supported_formats[0].frame_size.height(), 1); | 359 EXPECT_GT(supported_formats[0].frame_size.height(), 1); |
| 360 EXPECT_GT(supported_formats[0].frame_rate, 1); | 360 EXPECT_GT(supported_formats[0].frame_rate, 1); |
| 361 EXPECT_GT(supported_formats[1].frame_size.width(), 1); | 361 EXPECT_GT(supported_formats[1].frame_size.width(), 1); |
| 362 EXPECT_GT(supported_formats[1].frame_size.height(), 1); | 362 EXPECT_GT(supported_formats[1].frame_size.height(), 1); |
| 363 EXPECT_GT(supported_formats[1].frame_rate, 1); | 363 EXPECT_GT(supported_formats[1].frame_rate, 1); |
| 364 | 364 |
| 365 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 365 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 366 message_loop_->RunUntilIdle(); | 366 base::RunLoop().RunUntilIdle(); |
| 367 // After StartClient(), device's supported formats should stay the same. | 367 // After StartClient(), device's supported formats should stay the same. |
| 368 supported_formats.clear(); | 368 supported_formats.clear(); |
| 369 EXPECT_TRUE( | 369 EXPECT_TRUE( |
| 370 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats)); | 370 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats)); |
| 371 ASSERT_GE(supported_formats.size(), 2u); | 371 ASSERT_GE(supported_formats.size(), 2u); |
| 372 EXPECT_GT(supported_formats[0].frame_size.width(), 1); | 372 EXPECT_GT(supported_formats[0].frame_size.width(), 1); |
| 373 EXPECT_GT(supported_formats[0].frame_size.height(), 1); | 373 EXPECT_GT(supported_formats[0].frame_size.height(), 1); |
| 374 EXPECT_GT(supported_formats[0].frame_rate, 1); | 374 EXPECT_GT(supported_formats[0].frame_rate, 1); |
| 375 EXPECT_GT(supported_formats[1].frame_size.width(), 1); | 375 EXPECT_GT(supported_formats[1].frame_size.width(), 1); |
| 376 EXPECT_GT(supported_formats[1].frame_size.height(), 1); | 376 EXPECT_GT(supported_formats[1].frame_size.height(), 1); |
| 377 EXPECT_GT(supported_formats[1].frame_rate, 1); | 377 EXPECT_GT(supported_formats[1].frame_rate, 1); |
| 378 | 378 |
| 379 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 379 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 380 StopClient(client_id); | 380 StopClient(client_id); |
| 381 supported_formats.clear(); | 381 supported_formats.clear(); |
| 382 EXPECT_TRUE( | 382 EXPECT_TRUE( |
| 383 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats)); | 383 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats)); |
| 384 ASSERT_GE(supported_formats.size(), 2u); | 384 ASSERT_GE(supported_formats.size(), 2u); |
| 385 EXPECT_GT(supported_formats[0].frame_size.width(), 1); | 385 EXPECT_GT(supported_formats[0].frame_size.width(), 1); |
| 386 EXPECT_GT(supported_formats[0].frame_size.height(), 1); | 386 EXPECT_GT(supported_formats[0].frame_size.height(), 1); |
| 387 EXPECT_GT(supported_formats[0].frame_rate, 1); | 387 EXPECT_GT(supported_formats[0].frame_rate, 1); |
| 388 EXPECT_GT(supported_formats[1].frame_size.width(), 1); | 388 EXPECT_GT(supported_formats[1].frame_size.width(), 1); |
| 389 EXPECT_GT(supported_formats[1].frame_size.height(), 1); | 389 EXPECT_GT(supported_formats[1].frame_size.height(), 1); |
| 390 EXPECT_GT(supported_formats[1].frame_rate, 1); | 390 EXPECT_GT(supported_formats[1].frame_rate, 1); |
| 391 | 391 |
| 392 vcm_->Close(video_session_id); | 392 vcm_->Close(video_session_id); |
| 393 message_loop_->RunUntilIdle(); | 393 base::RunLoop().RunUntilIdle(); |
| 394 vcm_->Unregister(); | 394 vcm_->Unregister(); |
| 395 } | 395 } |
| 396 | 396 |
| 397 // Enumerate devices and open the first, then check the formats currently in | 397 // Enumerate devices and open the first, then check the formats currently in |
| 398 // use, which should be an empty vector. Then start the opened device. The | 398 // use, which should be an empty vector. Then start the opened device. The |
| 399 // format(s) in use should be just one format (the one used when configuring- | 399 // format(s) in use should be just one format (the one used when configuring- |
| 400 // starting the device). Finally stop the device and check that the formats in | 400 // starting the device). Finally stop the device and check that the formats in |
| 401 // use is an empty vector. | 401 // use is an empty vector. |
| 402 TEST_F(VideoCaptureManagerTest, StartDeviceAndGetDeviceFormatInUse) { | 402 TEST_F(VideoCaptureManagerTest, StartDeviceAndGetDeviceFormatInUse) { |
| 403 StreamDeviceInfoArray devices; | 403 StreamDeviceInfoArray devices; |
| 404 | 404 |
| 405 InSequence s; | 405 InSequence s; |
| 406 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 406 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 407 .WillOnce(SaveArg<1>(&devices)); | 407 .WillOnce(SaveArg<1>(&devices)); |
| 408 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 408 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 409 message_loop_->RunUntilIdle(); | 409 base::RunLoop().RunUntilIdle(); |
| 410 ASSERT_GE(devices.size(), 2u); | 410 ASSERT_GE(devices.size(), 2u); |
| 411 | 411 |
| 412 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 412 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 413 int video_session_id = vcm_->Open(devices.front()); | 413 int video_session_id = vcm_->Open(devices.front()); |
| 414 message_loop_->RunUntilIdle(); | 414 base::RunLoop().RunUntilIdle(); |
| 415 | 415 |
| 416 // Right after opening the device, we should see no format in use. | 416 // Right after opening the device, we should see no format in use. |
| 417 media::VideoCaptureFormats formats_in_use; | 417 media::VideoCaptureFormats formats_in_use; |
| 418 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(video_session_id, &formats_in_use)); | 418 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(video_session_id, &formats_in_use)); |
| 419 EXPECT_TRUE(formats_in_use.empty()); | 419 EXPECT_TRUE(formats_in_use.empty()); |
| 420 | 420 |
| 421 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 421 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 422 message_loop_->RunUntilIdle(); | 422 base::RunLoop().RunUntilIdle(); |
| 423 // After StartClient(), |formats_in_use| should contain one valid format. | 423 // After StartClient(), |formats_in_use| should contain one valid format. |
| 424 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(video_session_id, &formats_in_use)); | 424 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(video_session_id, &formats_in_use)); |
| 425 EXPECT_EQ(formats_in_use.size(), 1u); | 425 EXPECT_EQ(formats_in_use.size(), 1u); |
| 426 if (formats_in_use.size()) { | 426 if (formats_in_use.size()) { |
| 427 media::VideoCaptureFormat& format_in_use = formats_in_use.front(); | 427 media::VideoCaptureFormat& format_in_use = formats_in_use.front(); |
| 428 EXPECT_TRUE(format_in_use.IsValid()); | 428 EXPECT_TRUE(format_in_use.IsValid()); |
| 429 EXPECT_GT(format_in_use.frame_size.width(), 1); | 429 EXPECT_GT(format_in_use.frame_size.width(), 1); |
| 430 EXPECT_GT(format_in_use.frame_size.height(), 1); | 430 EXPECT_GT(format_in_use.frame_size.height(), 1); |
| 431 EXPECT_GT(format_in_use.frame_rate, 1); | 431 EXPECT_GT(format_in_use.frame_rate, 1); |
| 432 } | 432 } |
| 433 formats_in_use.clear(); | 433 formats_in_use.clear(); |
| 434 | 434 |
| 435 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 435 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 436 StopClient(client_id); | 436 StopClient(client_id); |
| 437 message_loop_->RunUntilIdle(); | 437 base::RunLoop().RunUntilIdle(); |
| 438 // After StopClient(), the device's formats in use should be empty again. | 438 // After StopClient(), the device's formats in use should be empty again. |
| 439 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(video_session_id, &formats_in_use)); | 439 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(video_session_id, &formats_in_use)); |
| 440 EXPECT_TRUE(formats_in_use.empty()); | 440 EXPECT_TRUE(formats_in_use.empty()); |
| 441 | 441 |
| 442 vcm_->Close(video_session_id); | 442 vcm_->Close(video_session_id); |
| 443 message_loop_->RunUntilIdle(); | 443 base::RunLoop().RunUntilIdle(); |
| 444 vcm_->Unregister(); | 444 vcm_->Unregister(); |
| 445 } | 445 } |
| 446 | 446 |
| 447 // Open two different devices. | 447 // Open two different devices. |
| 448 TEST_F(VideoCaptureManagerTest, OpenTwo) { | 448 TEST_F(VideoCaptureManagerTest, OpenTwo) { |
| 449 StreamDeviceInfoArray devices; | 449 StreamDeviceInfoArray devices; |
| 450 | 450 |
| 451 InSequence s; | 451 InSequence s; |
| 452 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 452 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 453 .WillOnce(SaveArg<1>(&devices)); | 453 .WillOnce(SaveArg<1>(&devices)); |
| 454 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 454 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 455 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 455 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 456 | 456 |
| 457 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 457 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 458 | 458 |
| 459 // Wait to get device callback. | 459 // Wait to get device callback. |
| 460 message_loop_->RunUntilIdle(); | 460 base::RunLoop().RunUntilIdle(); |
| 461 | 461 |
| 462 StreamDeviceInfoArray::iterator it = devices.begin(); | 462 StreamDeviceInfoArray::iterator it = devices.begin(); |
| 463 | 463 |
| 464 int video_session_id_first = vcm_->Open(*it); | 464 int video_session_id_first = vcm_->Open(*it); |
| 465 ++it; | 465 ++it; |
| 466 int video_session_id_second = vcm_->Open(*it); | 466 int video_session_id_second = vcm_->Open(*it); |
| 467 | 467 |
| 468 vcm_->Close(video_session_id_first); | 468 vcm_->Close(video_session_id_first); |
| 469 vcm_->Close(video_session_id_second); | 469 vcm_->Close(video_session_id_second); |
| 470 | 470 |
| 471 // Wait to check callbacks before removing the listener. | 471 // Wait to check callbacks before removing the listener. |
| 472 message_loop_->RunUntilIdle(); | 472 base::RunLoop().RunUntilIdle(); |
| 473 vcm_->Unregister(); | 473 vcm_->Unregister(); |
| 474 } | 474 } |
| 475 | 475 |
| 476 // Try open a non-existing device. | 476 // Try open a non-existing device. |
| 477 TEST_F(VideoCaptureManagerTest, OpenNotExisting) { | 477 TEST_F(VideoCaptureManagerTest, OpenNotExisting) { |
| 478 StreamDeviceInfoArray devices; | 478 StreamDeviceInfoArray devices; |
| 479 | 479 |
| 480 InSequence s; | 480 InSequence s; |
| 481 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 481 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 482 .WillOnce(SaveArg<1>(&devices)); | 482 .WillOnce(SaveArg<1>(&devices)); |
| 483 EXPECT_CALL(*frame_observer_, OnError(_)); | 483 EXPECT_CALL(*frame_observer_, OnError(_)); |
| 484 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 484 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 485 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 485 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 486 | 486 |
| 487 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 487 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 488 | 488 |
| 489 // Wait to get device callback. | 489 // Wait to get device callback. |
| 490 message_loop_->RunUntilIdle(); | 490 base::RunLoop().RunUntilIdle(); |
| 491 | 491 |
| 492 MediaStreamType stream_type = MEDIA_DEVICE_VIDEO_CAPTURE; | 492 MediaStreamType stream_type = MEDIA_DEVICE_VIDEO_CAPTURE; |
| 493 std::string device_name("device_doesnt_exist"); | 493 std::string device_name("device_doesnt_exist"); |
| 494 std::string device_id("id_doesnt_exist"); | 494 std::string device_id("id_doesnt_exist"); |
| 495 StreamDeviceInfo dummy_device(stream_type, device_name, device_id); | 495 StreamDeviceInfo dummy_device(stream_type, device_name, device_id); |
| 496 | 496 |
| 497 // This should fail with an error to the controller. | 497 // This should fail with an error to the controller. |
| 498 int session_id = vcm_->Open(dummy_device); | 498 int session_id = vcm_->Open(dummy_device); |
| 499 VideoCaptureControllerID client_id = StartClient(session_id, true); | 499 VideoCaptureControllerID client_id = StartClient(session_id, true); |
| 500 message_loop_->RunUntilIdle(); | 500 base::RunLoop().RunUntilIdle(); |
| 501 | 501 |
| 502 StopClient(client_id); | 502 StopClient(client_id); |
| 503 vcm_->Close(session_id); | 503 vcm_->Close(session_id); |
| 504 message_loop_->RunUntilIdle(); | 504 base::RunLoop().RunUntilIdle(); |
| 505 | 505 |
| 506 vcm_->Unregister(); | 506 vcm_->Unregister(); |
| 507 } | 507 } |
| 508 | 508 |
| 509 // Start a device without calling Open, using a non-magic ID. | 509 // Start a device without calling Open, using a non-magic ID. |
| 510 TEST_F(VideoCaptureManagerTest, StartInvalidSession) { | 510 TEST_F(VideoCaptureManagerTest, StartInvalidSession) { |
| 511 StartClient(22, false); | 511 StartClient(22, false); |
| 512 | 512 |
| 513 // Wait to check callbacks before removing the listener. | 513 // Wait to check callbacks before removing the listener. |
| 514 message_loop_->RunUntilIdle(); | 514 base::RunLoop().RunUntilIdle(); |
| 515 vcm_->Unregister(); | 515 vcm_->Unregister(); |
| 516 } | 516 } |
| 517 | 517 |
| 518 // Open and start a device, close it before calling Stop. | 518 // Open and start a device, close it before calling Stop. |
| 519 TEST_F(VideoCaptureManagerTest, CloseWithoutStop) { | 519 TEST_F(VideoCaptureManagerTest, CloseWithoutStop) { |
| 520 StreamDeviceInfoArray devices; | 520 StreamDeviceInfoArray devices; |
| 521 base::RunLoop run_loop; | 521 base::RunLoop run_loop; |
| 522 | 522 |
| 523 InSequence s; | 523 InSequence s; |
| 524 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 524 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 536 int video_session_id = vcm_->Open(devices.front()); | 536 int video_session_id = vcm_->Open(devices.front()); |
| 537 | 537 |
| 538 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 538 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 539 | 539 |
| 540 // Close will stop the running device, an assert will be triggered in | 540 // Close will stop the running device, an assert will be triggered in |
| 541 // VideoCaptureManager destructor otherwise. | 541 // VideoCaptureManager destructor otherwise. |
| 542 vcm_->Close(video_session_id); | 542 vcm_->Close(video_session_id); |
| 543 StopClient(client_id); | 543 StopClient(client_id); |
| 544 | 544 |
| 545 // Wait to check callbacks before removing the listener | 545 // Wait to check callbacks before removing the listener |
| 546 message_loop_->RunUntilIdle(); | 546 base::RunLoop().RunUntilIdle(); |
| 547 vcm_->Unregister(); | 547 vcm_->Unregister(); |
| 548 } | 548 } |
| 549 | 549 |
| 550 // Try to open, start, pause and resume a device. | 550 // Try to open, start, pause and resume a device. |
| 551 TEST_F(VideoCaptureManagerTest, PauseAndResumeClient) { | 551 TEST_F(VideoCaptureManagerTest, PauseAndResumeClient) { |
| 552 StreamDeviceInfoArray devices; | 552 StreamDeviceInfoArray devices; |
| 553 | 553 |
| 554 InSequence s; | 554 InSequence s; |
| 555 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 555 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 556 .WillOnce(SaveArg<1>(&devices)); | 556 .WillOnce(SaveArg<1>(&devices)); |
| 557 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 557 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 558 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 558 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 559 | 559 |
| 560 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 560 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 561 | 561 |
| 562 // Wait to get device callback. | 562 // Wait to get device callback. |
| 563 message_loop_->RunUntilIdle(); | 563 base::RunLoop().RunUntilIdle(); |
| 564 | 564 |
| 565 int video_session_id = vcm_->Open(devices.front()); | 565 int video_session_id = vcm_->Open(devices.front()); |
| 566 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 566 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 567 | 567 |
| 568 // Resume client a second time should cause no problem. | 568 // Resume client a second time should cause no problem. |
| 569 PauseClient(client_id); | 569 PauseClient(client_id); |
| 570 ResumeClient(video_session_id, client_id); | 570 ResumeClient(video_session_id, client_id); |
| 571 ResumeClient(video_session_id, client_id); | 571 ResumeClient(video_session_id, client_id); |
| 572 | 572 |
| 573 StopClient(client_id); | 573 StopClient(client_id); |
| 574 vcm_->Close(video_session_id); | 574 vcm_->Close(video_session_id); |
| 575 | 575 |
| 576 // Wait to check callbacks before removing the listener. | 576 // Wait to check callbacks before removing the listener. |
| 577 message_loop_->RunUntilIdle(); | 577 base::RunLoop().RunUntilIdle(); |
| 578 vcm_->Unregister(); | 578 vcm_->Unregister(); |
| 579 } | 579 } |
| 580 | 580 |
| 581 #if defined(OS_ANDROID) | 581 #if defined(OS_ANDROID) |
| 582 // Try to open, start, pause and resume a device. | 582 // Try to open, start, pause and resume a device. |
| 583 TEST_F(VideoCaptureManagerTest, PauseAndResumeDevice) { | 583 TEST_F(VideoCaptureManagerTest, PauseAndResumeDevice) { |
| 584 StreamDeviceInfoArray devices; | 584 StreamDeviceInfoArray devices; |
| 585 | 585 |
| 586 InSequence s; | 586 InSequence s; |
| 587 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) | 587 EXPECT_CALL(*listener_, DevicesEnumerated(MEDIA_DEVICE_VIDEO_CAPTURE, _)) |
| 588 .WillOnce(SaveArg<1>(&devices)); | 588 .WillOnce(SaveArg<1>(&devices)); |
| 589 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 589 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 590 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 590 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 591 | 591 |
| 592 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); | 592 vcm_->EnumerateDevices(MEDIA_DEVICE_VIDEO_CAPTURE); |
| 593 | 593 |
| 594 // Wait to get device callback. | 594 // Wait to get device callback. |
| 595 message_loop_->RunUntilIdle(); | 595 base::RunLoop().RunUntilIdle(); |
| 596 | 596 |
| 597 int video_session_id = vcm_->Open(devices.front()); | 597 int video_session_id = vcm_->Open(devices.front()); |
| 598 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 598 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 599 | 599 |
| 600 // Release/ResumeDevices according to ApplicationStatus. Should cause no | 600 // Release/ResumeDevices according to ApplicationStatus. Should cause no |
| 601 // problem in any order. Check https://crbug.com/615557 for more details. | 601 // problem in any order. Check https://crbug.com/615557 for more details. |
| 602 ApplicationStateChange( | 602 ApplicationStateChange( |
| 603 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); | 603 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); |
| 604 ApplicationStateChange( | 604 ApplicationStateChange( |
| 605 base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES); | 605 base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES); |
| 606 ApplicationStateChange( | 606 ApplicationStateChange( |
| 607 base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES); | 607 base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES); |
| 608 ApplicationStateChange( | 608 ApplicationStateChange( |
| 609 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); | 609 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); |
| 610 ApplicationStateChange( | 610 ApplicationStateChange( |
| 611 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); | 611 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); |
| 612 | 612 |
| 613 StopClient(client_id); | 613 StopClient(client_id); |
| 614 vcm_->Close(video_session_id); | 614 vcm_->Close(video_session_id); |
| 615 | 615 |
| 616 // Wait to check callbacks before removing the listener. | 616 // Wait to check callbacks before removing the listener. |
| 617 message_loop_->RunUntilIdle(); | 617 base::RunLoop().RunUntilIdle(); |
| 618 vcm_->Unregister(); | 618 vcm_->Unregister(); |
| 619 } | 619 } |
| 620 #endif | 620 #endif |
| 621 | 621 |
| 622 // TODO(mcasas): Add a test to check consolidation of the supported formats | 622 // TODO(mcasas): Add a test to check consolidation of the supported formats |
| 623 // provided by the device when http://crbug.com/323913 is closed. | 623 // provided by the device when http://crbug.com/323913 is closed. |
| 624 | 624 |
| 625 } // namespace content | 625 } // namespace content |
| OLD | NEW |