| 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 300 |
| 301 // Test cases | 301 // Test cases |
| 302 | 302 |
| 303 // Try to open, start, stop and close a device. | 303 // Try to open, start, stop and close a device. |
| 304 TEST_F(VideoCaptureManagerTest, CreateAndClose) { | 304 TEST_F(VideoCaptureManagerTest, CreateAndClose) { |
| 305 InSequence s; | 305 InSequence s; |
| 306 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 306 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 307 EXPECT_CALL(*frame_observer_, OnStarted(_)); | 307 EXPECT_CALL(*frame_observer_, OnStarted(_)); |
| 308 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 308 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 309 | 309 |
| 310 int video_session_id = vcm_->Open(devices_.front()); | 310 int video_session_id = vcm_->Open(devices_.front().device); |
| 311 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 311 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 312 | 312 |
| 313 StopClient(client_id); | 313 StopClient(client_id); |
| 314 vcm_->Close(video_session_id); | 314 vcm_->Close(video_session_id); |
| 315 | 315 |
| 316 // Wait to check callbacks before removing the listener. | 316 // Wait to check callbacks before removing the listener. |
| 317 base::RunLoop().RunUntilIdle(); | 317 base::RunLoop().RunUntilIdle(); |
| 318 vcm_->UnregisterListener(); | 318 vcm_->UnregisterListener(listener_.get()); |
| 319 } | 319 } |
| 320 | 320 |
| 321 TEST_F(VideoCaptureManagerTest, CreateAndCloseMultipleTimes) { | 321 TEST_F(VideoCaptureManagerTest, CreateAndCloseMultipleTimes) { |
| 322 InSequence s; | 322 InSequence s; |
| 323 for (int i = 1 ; i < 3 ; ++i) { | 323 for (int i = 1 ; i < 3 ; ++i) { |
| 324 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, i)); | 324 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, i)); |
| 325 EXPECT_CALL(*frame_observer_, OnStarted(_)); | 325 EXPECT_CALL(*frame_observer_, OnStarted(_)); |
| 326 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, i)); | 326 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, i)); |
| 327 int video_session_id = vcm_->Open(devices_.front()); | 327 int video_session_id = vcm_->Open(devices_.front().device); |
| 328 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 328 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 329 | 329 |
| 330 StopClient(client_id); | 330 StopClient(client_id); |
| 331 vcm_->Close(video_session_id); | 331 vcm_->Close(video_session_id); |
| 332 } | 332 } |
| 333 | 333 |
| 334 // Wait to check callbacks before removing the listener. | 334 // Wait to check callbacks before removing the listener. |
| 335 base::RunLoop().RunUntilIdle(); | 335 base::RunLoop().RunUntilIdle(); |
| 336 vcm_->UnregisterListener(); | 336 vcm_->UnregisterListener(listener_.get()); |
| 337 } | 337 } |
| 338 | 338 |
| 339 // Try to open, start, and abort a device. | 339 // Try to open, start, and abort a device. |
| 340 TEST_F(VideoCaptureManagerTest, CreateAndAbort) { | 340 TEST_F(VideoCaptureManagerTest, CreateAndAbort) { |
| 341 InSequence s; | 341 InSequence s; |
| 342 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 342 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 343 EXPECT_CALL(*frame_observer_, OnStarted(_)); | 343 EXPECT_CALL(*frame_observer_, OnStarted(_)); |
| 344 EXPECT_CALL(*listener_, Aborted(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 344 EXPECT_CALL(*listener_, Aborted(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 345 | 345 |
| 346 int video_session_id = vcm_->Open(devices_.front()); | 346 int video_session_id = vcm_->Open(devices_.front().device); |
| 347 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 347 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 348 | 348 |
| 349 // Wait for device opened. | 349 // Wait for device opened. |
| 350 base::RunLoop().RunUntilIdle(); | 350 base::RunLoop().RunUntilIdle(); |
| 351 | 351 |
| 352 vcm_->StopCaptureForClient(controllers_[client_id], client_id, | 352 vcm_->StopCaptureForClient(controllers_[client_id], client_id, |
| 353 frame_observer_.get(), true); | 353 frame_observer_.get(), true); |
| 354 | 354 |
| 355 // Wait to check callbacks before removing the listener. | 355 // Wait to check callbacks before removing the listener. |
| 356 base::RunLoop().RunUntilIdle(); | 356 base::RunLoop().RunUntilIdle(); |
| 357 vcm_->UnregisterListener(); | 357 vcm_->UnregisterListener(listener_.get()); |
| 358 } | 358 } |
| 359 | 359 |
| 360 TEST_F(VideoCaptureManagerTest, AddObserver) { | 360 TEST_F(VideoCaptureManagerTest, AddObserver) { |
| 361 InSequence s; | 361 InSequence s; |
| 362 MockVideoCaptureObserver observer; | 362 MockVideoCaptureObserver observer; |
| 363 vcm_->AddVideoCaptureObserver(&observer); | 363 vcm_->AddVideoCaptureObserver(&observer); |
| 364 | 364 |
| 365 EXPECT_CALL(observer, | 365 EXPECT_CALL(observer, |
| 366 OnVideoCaptureStarted(WrappedDeviceFactory::DEFAULT_FACING)); | 366 OnVideoCaptureStarted(WrappedDeviceFactory::DEFAULT_FACING)); |
| 367 EXPECT_CALL(observer, | 367 EXPECT_CALL(observer, |
| 368 OnVideoCaptureStopped(WrappedDeviceFactory::DEFAULT_FACING)); | 368 OnVideoCaptureStopped(WrappedDeviceFactory::DEFAULT_FACING)); |
| 369 | 369 |
| 370 int video_session_id = vcm_->Open(devices_.front()); | 370 int video_session_id = vcm_->Open(devices_.front().device); |
| 371 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 371 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 372 | 372 |
| 373 StopClient(client_id); | 373 StopClient(client_id); |
| 374 vcm_->Close(video_session_id); | 374 vcm_->Close(video_session_id); |
| 375 | 375 |
| 376 // Wait to check callbacks before removing the listener. | 376 // Wait to check callbacks before removing the listener. |
| 377 base::RunLoop().RunUntilIdle(); | 377 base::RunLoop().RunUntilIdle(); |
| 378 vcm_->UnregisterListener(); | 378 vcm_->UnregisterListener(listener_.get()); |
| 379 } | 379 } |
| 380 | 380 |
| 381 // Open the same device twice. | 381 // Open the same device twice. |
| 382 TEST_F(VideoCaptureManagerTest, OpenTwice) { | 382 TEST_F(VideoCaptureManagerTest, OpenTwice) { |
| 383 InSequence s; | 383 InSequence s; |
| 384 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 384 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 385 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 385 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 386 | 386 |
| 387 int video_session_id_first = vcm_->Open(devices_.front()); | 387 int video_session_id_first = vcm_->Open(devices_.front().device); |
| 388 | 388 |
| 389 // This should trigger an error callback with error code | 389 // This should trigger an error callback with error code |
| 390 // 'kDeviceAlreadyInUse'. | 390 // 'kDeviceAlreadyInUse'. |
| 391 int video_session_id_second = vcm_->Open(devices_.front()); | 391 int video_session_id_second = vcm_->Open(devices_.front().device); |
| 392 EXPECT_NE(video_session_id_first, video_session_id_second); | 392 EXPECT_NE(video_session_id_first, video_session_id_second); |
| 393 | 393 |
| 394 vcm_->Close(video_session_id_first); | 394 vcm_->Close(video_session_id_first); |
| 395 vcm_->Close(video_session_id_second); | 395 vcm_->Close(video_session_id_second); |
| 396 | 396 |
| 397 // Wait to check callbacks before removing the listener. | 397 // Wait to check callbacks before removing the listener. |
| 398 base::RunLoop().RunUntilIdle(); | 398 base::RunLoop().RunUntilIdle(); |
| 399 vcm_->UnregisterListener(); | 399 vcm_->UnregisterListener(listener_.get()); |
| 400 } | 400 } |
| 401 | 401 |
| 402 // Connect and disconnect devices. | 402 // Connect and disconnect devices. |
| 403 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) { | 403 TEST_F(VideoCaptureManagerTest, ConnectAndDisconnectDevices) { |
| 404 int number_of_devices_keep = | 404 int number_of_devices_keep = |
| 405 video_capture_device_factory_->number_of_devices(); | 405 video_capture_device_factory_->number_of_devices(); |
| 406 | 406 |
| 407 // Simulate we remove 1 fake device. | 407 // Simulate we remove 1 fake device. |
| 408 video_capture_device_factory_->SetToDefaultDevicesConfig(1); | 408 video_capture_device_factory_->SetToDefaultDevicesConfig(1); |
| 409 base::RunLoop run_loop; | 409 base::RunLoop run_loop; |
| 410 vcm_->EnumerateDevices( | 410 vcm_->EnumerateDevices( |
| 411 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, | 411 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, |
| 412 base::Unretained(this), run_loop.QuitClosure())); | 412 base::Unretained(this), run_loop.QuitClosure())); |
| 413 run_loop.Run(); | 413 run_loop.Run(); |
| 414 ASSERT_EQ(devices_.size(), 1u); | 414 ASSERT_EQ(devices_.size(), 1u); |
| 415 | 415 |
| 416 // Simulate we add 2 fake devices. | 416 // Simulate we add 2 fake devices. |
| 417 video_capture_device_factory_->SetToDefaultDevicesConfig(3); | 417 video_capture_device_factory_->SetToDefaultDevicesConfig(3); |
| 418 base::RunLoop run_loop2; | 418 base::RunLoop run_loop2; |
| 419 vcm_->EnumerateDevices( | 419 vcm_->EnumerateDevices( |
| 420 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, | 420 base::Bind(&VideoCaptureManagerTest::HandleEnumerationResult, |
| 421 base::Unretained(this), run_loop2.QuitClosure())); | 421 base::Unretained(this), run_loop2.QuitClosure())); |
| 422 run_loop2.Run(); | 422 run_loop2.Run(); |
| 423 ASSERT_EQ(devices_.size(), 3u); | 423 ASSERT_EQ(devices_.size(), 3u); |
| 424 | 424 |
| 425 vcm_->UnregisterListener(); | 425 vcm_->UnregisterListener(listener_.get()); |
| 426 video_capture_device_factory_->SetToDefaultDevicesConfig( | 426 video_capture_device_factory_->SetToDefaultDevicesConfig( |
| 427 number_of_devices_keep); | 427 number_of_devices_keep); |
| 428 } | 428 } |
| 429 | 429 |
| 430 // 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 |
| 431 // 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 |
| 432 // 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. |
| 433 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { | 433 TEST_F(VideoCaptureManagerTest, ManipulateDeviceAndCheckCapabilities) { |
| 434 // Before enumerating the devices, requesting formats should return false. | 434 // Before enumerating the devices, requesting formats should return false. |
| 435 int video_session_id = 0; | 435 int video_session_id = 0; |
| 436 media::VideoCaptureFormats supported_formats; | 436 media::VideoCaptureFormats supported_formats; |
| 437 supported_formats.clear(); | 437 supported_formats.clear(); |
| 438 EXPECT_FALSE( | 438 EXPECT_FALSE( |
| 439 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats)); | 439 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats)); |
| 440 | 440 |
| 441 InSequence s; | 441 InSequence s; |
| 442 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 442 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 443 video_session_id = vcm_->Open(devices_.front()); | 443 video_session_id = vcm_->Open(devices_.front().device); |
| 444 base::RunLoop().RunUntilIdle(); | 444 base::RunLoop().RunUntilIdle(); |
| 445 | 445 |
| 446 // Right after opening the device, we should see all its formats. | 446 // Right after opening the device, we should see all its formats. |
| 447 supported_formats.clear(); | 447 supported_formats.clear(); |
| 448 EXPECT_TRUE( | 448 EXPECT_TRUE( |
| 449 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats)); | 449 vcm_->GetDeviceSupportedFormats(video_session_id, &supported_formats)); |
| 450 ASSERT_GT(supported_formats.size(), 1u); | 450 ASSERT_GT(supported_formats.size(), 1u); |
| 451 EXPECT_GT(supported_formats[0].frame_size.width(), 1); | 451 EXPECT_GT(supported_formats[0].frame_size.width(), 1); |
| 452 EXPECT_GT(supported_formats[0].frame_size.height(), 1); | 452 EXPECT_GT(supported_formats[0].frame_size.height(), 1); |
| 453 EXPECT_GT(supported_formats[0].frame_rate, 1); | 453 EXPECT_GT(supported_formats[0].frame_rate, 1); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 478 ASSERT_GE(supported_formats.size(), 2u); | 478 ASSERT_GE(supported_formats.size(), 2u); |
| 479 EXPECT_GT(supported_formats[0].frame_size.width(), 1); | 479 EXPECT_GT(supported_formats[0].frame_size.width(), 1); |
| 480 EXPECT_GT(supported_formats[0].frame_size.height(), 1); | 480 EXPECT_GT(supported_formats[0].frame_size.height(), 1); |
| 481 EXPECT_GT(supported_formats[0].frame_rate, 1); | 481 EXPECT_GT(supported_formats[0].frame_rate, 1); |
| 482 EXPECT_GT(supported_formats[1].frame_size.width(), 1); | 482 EXPECT_GT(supported_formats[1].frame_size.width(), 1); |
| 483 EXPECT_GT(supported_formats[1].frame_size.height(), 1); | 483 EXPECT_GT(supported_formats[1].frame_size.height(), 1); |
| 484 EXPECT_GT(supported_formats[1].frame_rate, 1); | 484 EXPECT_GT(supported_formats[1].frame_rate, 1); |
| 485 | 485 |
| 486 vcm_->Close(video_session_id); | 486 vcm_->Close(video_session_id); |
| 487 base::RunLoop().RunUntilIdle(); | 487 base::RunLoop().RunUntilIdle(); |
| 488 vcm_->UnregisterListener(); | 488 vcm_->UnregisterListener(listener_.get()); |
| 489 } | 489 } |
| 490 | 490 |
| 491 // Enumerate devices, then check the list of supported formats. Then open and | 491 // Enumerate devices, then check the list of supported formats. Then open and |
| 492 // start the first device. The capability list should stay the same. Finally | 492 // start the first device. The capability list should stay the same. Finally |
| 493 // stop the device and check that the capabilities stay unchanged. | 493 // stop the device and check that the capabilities stay unchanged. |
| 494 TEST_F(VideoCaptureManagerTest, | 494 TEST_F(VideoCaptureManagerTest, |
| 495 ManipulateDeviceAndCheckCapabilitiesWithDeviceId) { | 495 ManipulateDeviceAndCheckCapabilitiesWithDeviceId) { |
| 496 // Requesting formats should work even before enumerating/opening devices. | 496 // Requesting formats should work even before enumerating/opening devices. |
| 497 std::string device_id = devices_.front().device.id; | 497 std::string device_id = devices_.front().device.id; |
| 498 media::VideoCaptureFormats supported_formats; | 498 media::VideoCaptureFormats supported_formats; |
| 499 supported_formats.clear(); | 499 supported_formats.clear(); |
| 500 EXPECT_TRUE(vcm_->GetDeviceSupportedFormats(device_id, &supported_formats)); | 500 EXPECT_TRUE(vcm_->GetDeviceSupportedFormats(device_id, &supported_formats)); |
| 501 ASSERT_GE(supported_formats.size(), 2u); | 501 ASSERT_GE(supported_formats.size(), 2u); |
| 502 EXPECT_GT(supported_formats[0].frame_size.width(), 1); | 502 EXPECT_GT(supported_formats[0].frame_size.width(), 1); |
| 503 EXPECT_GT(supported_formats[0].frame_size.height(), 1); | 503 EXPECT_GT(supported_formats[0].frame_size.height(), 1); |
| 504 EXPECT_GT(supported_formats[0].frame_rate, 1); | 504 EXPECT_GT(supported_formats[0].frame_rate, 1); |
| 505 EXPECT_GT(supported_formats[1].frame_size.width(), 1); | 505 EXPECT_GT(supported_formats[1].frame_size.width(), 1); |
| 506 EXPECT_GT(supported_formats[1].frame_size.height(), 1); | 506 EXPECT_GT(supported_formats[1].frame_size.height(), 1); |
| 507 EXPECT_GT(supported_formats[1].frame_rate, 1); | 507 EXPECT_GT(supported_formats[1].frame_rate, 1); |
| 508 | 508 |
| 509 InSequence s; | 509 InSequence s; |
| 510 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 510 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 511 int video_session_id = vcm_->Open(devices_.front()); | 511 int video_session_id = vcm_->Open(devices_.front().device); |
| 512 base::RunLoop().RunUntilIdle(); | 512 base::RunLoop().RunUntilIdle(); |
| 513 | 513 |
| 514 // Right after opening the device, we should see all its formats. | 514 // Right after opening the device, we should see all its formats. |
| 515 supported_formats.clear(); | 515 supported_formats.clear(); |
| 516 EXPECT_TRUE(vcm_->GetDeviceSupportedFormats(device_id, &supported_formats)); | 516 EXPECT_TRUE(vcm_->GetDeviceSupportedFormats(device_id, &supported_formats)); |
| 517 ASSERT_GE(supported_formats.size(), 2u); | 517 ASSERT_GE(supported_formats.size(), 2u); |
| 518 EXPECT_GT(supported_formats[0].frame_size.width(), 1); | 518 EXPECT_GT(supported_formats[0].frame_size.width(), 1); |
| 519 EXPECT_GT(supported_formats[0].frame_size.height(), 1); | 519 EXPECT_GT(supported_formats[0].frame_size.height(), 1); |
| 520 EXPECT_GT(supported_formats[0].frame_rate, 1); | 520 EXPECT_GT(supported_formats[0].frame_rate, 1); |
| 521 EXPECT_GT(supported_formats[1].frame_size.width(), 1); | 521 EXPECT_GT(supported_formats[1].frame_size.width(), 1); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 543 ASSERT_GE(supported_formats.size(), 2u); | 543 ASSERT_GE(supported_formats.size(), 2u); |
| 544 EXPECT_GT(supported_formats[0].frame_size.width(), 1); | 544 EXPECT_GT(supported_formats[0].frame_size.width(), 1); |
| 545 EXPECT_GT(supported_formats[0].frame_size.height(), 1); | 545 EXPECT_GT(supported_formats[0].frame_size.height(), 1); |
| 546 EXPECT_GT(supported_formats[0].frame_rate, 1); | 546 EXPECT_GT(supported_formats[0].frame_rate, 1); |
| 547 EXPECT_GT(supported_formats[1].frame_size.width(), 1); | 547 EXPECT_GT(supported_formats[1].frame_size.width(), 1); |
| 548 EXPECT_GT(supported_formats[1].frame_size.height(), 1); | 548 EXPECT_GT(supported_formats[1].frame_size.height(), 1); |
| 549 EXPECT_GT(supported_formats[1].frame_rate, 1); | 549 EXPECT_GT(supported_formats[1].frame_rate, 1); |
| 550 | 550 |
| 551 vcm_->Close(video_session_id); | 551 vcm_->Close(video_session_id); |
| 552 base::RunLoop().RunUntilIdle(); | 552 base::RunLoop().RunUntilIdle(); |
| 553 vcm_->UnregisterListener(); | 553 vcm_->UnregisterListener(listener_.get()); |
| 554 } | 554 } |
| 555 | 555 |
| 556 // Enumerate devices and open the first, then check the formats currently in | 556 // Enumerate devices and open the first, then check the formats currently in |
| 557 // use, which should be an empty vector. Then start the opened device. The | 557 // use, which should be an empty vector. Then start the opened device. The |
| 558 // format(s) in use should be just one format (the one used when configuring- | 558 // format(s) in use should be just one format (the one used when configuring- |
| 559 // starting the device). Finally stop the device and check that the formats in | 559 // starting the device). Finally stop the device and check that the formats in |
| 560 // use is an empty vector. | 560 // use is an empty vector. |
| 561 TEST_F(VideoCaptureManagerTest, StartDeviceAndGetDeviceFormatInUse) { | 561 TEST_F(VideoCaptureManagerTest, StartDeviceAndGetDeviceFormatInUse) { |
| 562 InSequence s; | 562 InSequence s; |
| 563 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 563 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 564 int video_session_id = vcm_->Open(devices_.front()); | 564 int video_session_id = vcm_->Open(devices_.front().device); |
| 565 base::RunLoop().RunUntilIdle(); | 565 base::RunLoop().RunUntilIdle(); |
| 566 | 566 |
| 567 // Right after opening the device, we should see no format in use. | 567 // Right after opening the device, we should see no format in use. |
| 568 media::VideoCaptureFormats formats_in_use; | 568 media::VideoCaptureFormats formats_in_use; |
| 569 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(video_session_id, &formats_in_use)); | 569 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(video_session_id, &formats_in_use)); |
| 570 EXPECT_TRUE(formats_in_use.empty()); | 570 EXPECT_TRUE(formats_in_use.empty()); |
| 571 | 571 |
| 572 EXPECT_CALL(*frame_observer_, OnStarted(_)); | 572 EXPECT_CALL(*frame_observer_, OnStarted(_)); |
| 573 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 573 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 574 base::RunLoop().RunUntilIdle(); | 574 base::RunLoop().RunUntilIdle(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 586 | 586 |
| 587 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 587 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 588 StopClient(client_id); | 588 StopClient(client_id); |
| 589 base::RunLoop().RunUntilIdle(); | 589 base::RunLoop().RunUntilIdle(); |
| 590 // After StopClient(), the device's formats in use should be empty again. | 590 // After StopClient(), the device's formats in use should be empty again. |
| 591 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(video_session_id, &formats_in_use)); | 591 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(video_session_id, &formats_in_use)); |
| 592 EXPECT_TRUE(formats_in_use.empty()); | 592 EXPECT_TRUE(formats_in_use.empty()); |
| 593 | 593 |
| 594 vcm_->Close(video_session_id); | 594 vcm_->Close(video_session_id); |
| 595 base::RunLoop().RunUntilIdle(); | 595 base::RunLoop().RunUntilIdle(); |
| 596 vcm_->UnregisterListener(); | 596 vcm_->UnregisterListener(listener_.get()); |
| 597 } | 597 } |
| 598 | 598 |
| 599 // Enumerate devices and open the first, then check the formats currently in | 599 // Enumerate devices and open the first, then check the formats currently in |
| 600 // use, which should be an empty vector. Then start the opened device. The | 600 // use, which should be an empty vector. Then start the opened device. The |
| 601 // format(s) in use should be just one format (the one used when configuring- | 601 // format(s) in use should be just one format (the one used when configuring- |
| 602 // starting the device). Finally stop the device and check that the formats in | 602 // starting the device). Finally stop the device and check that the formats in |
| 603 // use is an empty vector. | 603 // use is an empty vector. |
| 604 TEST_F(VideoCaptureManagerTest, | 604 TEST_F(VideoCaptureManagerTest, |
| 605 StartDeviceAndGetDeviceFormatInUseWithDeviceId) { | 605 StartDeviceAndGetDeviceFormatInUseWithDeviceId) { |
| 606 std::string device_id = devices_.front().device.id; | 606 std::string device_id = devices_.front().device.id; |
| 607 InSequence s; | 607 InSequence s; |
| 608 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 608 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 609 int video_session_id = vcm_->Open(devices_.front()); | 609 int video_session_id = vcm_->Open(devices_.front().device); |
| 610 base::RunLoop().RunUntilIdle(); | 610 base::RunLoop().RunUntilIdle(); |
| 611 | 611 |
| 612 // Right after opening the device, we should see no format in use. | 612 // Right after opening the device, we should see no format in use. |
| 613 media::VideoCaptureFormats formats_in_use; | 613 media::VideoCaptureFormats formats_in_use; |
| 614 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(MEDIA_DEVICE_VIDEO_CAPTURE, device_id, | 614 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(MEDIA_DEVICE_VIDEO_CAPTURE, device_id, |
| 615 &formats_in_use)); | 615 &formats_in_use)); |
| 616 EXPECT_TRUE(formats_in_use.empty()); | 616 EXPECT_TRUE(formats_in_use.empty()); |
| 617 | 617 |
| 618 EXPECT_CALL(*frame_observer_, OnStarted(_)); | 618 EXPECT_CALL(*frame_observer_, OnStarted(_)); |
| 619 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 619 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 634 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 634 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 635 StopClient(client_id); | 635 StopClient(client_id); |
| 636 base::RunLoop().RunUntilIdle(); | 636 base::RunLoop().RunUntilIdle(); |
| 637 // After StopClient(), the device's formats in use should be empty again. | 637 // After StopClient(), the device's formats in use should be empty again. |
| 638 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(MEDIA_DEVICE_VIDEO_CAPTURE, device_id, | 638 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(MEDIA_DEVICE_VIDEO_CAPTURE, device_id, |
| 639 &formats_in_use)); | 639 &formats_in_use)); |
| 640 EXPECT_TRUE(formats_in_use.empty()); | 640 EXPECT_TRUE(formats_in_use.empty()); |
| 641 | 641 |
| 642 vcm_->Close(video_session_id); | 642 vcm_->Close(video_session_id); |
| 643 base::RunLoop().RunUntilIdle(); | 643 base::RunLoop().RunUntilIdle(); |
| 644 vcm_->UnregisterListener(); | 644 vcm_->UnregisterListener(listener_.get()); |
| 645 } | 645 } |
| 646 | 646 |
| 647 // Open two different devices. | 647 // Open two different devices. |
| 648 TEST_F(VideoCaptureManagerTest, OpenTwo) { | 648 TEST_F(VideoCaptureManagerTest, OpenTwo) { |
| 649 InSequence s; | 649 InSequence s; |
| 650 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 650 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 651 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 651 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 652 | 652 |
| 653 StreamDeviceInfoArray::iterator it = devices_.begin(); | 653 StreamDeviceInfoArray::iterator it = devices_.begin(); |
| 654 | 654 |
| 655 int video_session_id_first = vcm_->Open(*it); | 655 int video_session_id_first = vcm_->Open(it->device); |
| 656 ++it; | 656 ++it; |
| 657 int video_session_id_second = vcm_->Open(*it); | 657 int video_session_id_second = vcm_->Open(it->device); |
| 658 | 658 |
| 659 vcm_->Close(video_session_id_first); | 659 vcm_->Close(video_session_id_first); |
| 660 vcm_->Close(video_session_id_second); | 660 vcm_->Close(video_session_id_second); |
| 661 | 661 |
| 662 // Wait to check callbacks before removing the listener. | 662 // Wait to check callbacks before removing the listener. |
| 663 base::RunLoop().RunUntilIdle(); | 663 base::RunLoop().RunUntilIdle(); |
| 664 vcm_->UnregisterListener(); | 664 vcm_->UnregisterListener(listener_.get()); |
| 665 } | 665 } |
| 666 | 666 |
| 667 // Try open a non-existing device. | 667 // Try open a non-existing device. |
| 668 TEST_F(VideoCaptureManagerTest, OpenNotExisting) { | 668 TEST_F(VideoCaptureManagerTest, OpenNotExisting) { |
| 669 InSequence s; | 669 InSequence s; |
| 670 EXPECT_CALL(*frame_observer_, OnError(_)); | 670 EXPECT_CALL(*frame_observer_, OnError(_)); |
| 671 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 671 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 672 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 672 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 673 | 673 |
| 674 MediaStreamType stream_type = MEDIA_DEVICE_VIDEO_CAPTURE; | 674 MediaStreamType stream_type = MEDIA_DEVICE_VIDEO_CAPTURE; |
| 675 std::string device_name("device_doesnt_exist"); | 675 std::string device_name("device_doesnt_exist"); |
| 676 std::string device_id("id_doesnt_exist"); | 676 std::string device_id("id_doesnt_exist"); |
| 677 StreamDeviceInfo dummy_device(stream_type, device_name, device_id); | 677 MediaStreamDevice dummy_device(stream_type, device_id, device_name); |
| 678 | 678 |
| 679 // This should fail with an error to the controller. | 679 // This should fail with an error to the controller. |
| 680 int session_id = vcm_->Open(dummy_device); | 680 int session_id = vcm_->Open(dummy_device); |
| 681 VideoCaptureControllerID client_id = StartClient(session_id, true); | 681 VideoCaptureControllerID client_id = StartClient(session_id, true); |
| 682 base::RunLoop().RunUntilIdle(); | 682 base::RunLoop().RunUntilIdle(); |
| 683 | 683 |
| 684 StopClient(client_id); | 684 StopClient(client_id); |
| 685 vcm_->Close(session_id); | 685 vcm_->Close(session_id); |
| 686 base::RunLoop().RunUntilIdle(); | 686 base::RunLoop().RunUntilIdle(); |
| 687 | 687 |
| 688 vcm_->UnregisterListener(); | 688 vcm_->UnregisterListener(listener_.get()); |
| 689 } | 689 } |
| 690 | 690 |
| 691 // Start a device without calling Open, using a non-magic ID. | 691 // Start a device without calling Open, using a non-magic ID. |
| 692 TEST_F(VideoCaptureManagerTest, StartInvalidSession) { | 692 TEST_F(VideoCaptureManagerTest, StartInvalidSession) { |
| 693 StartClient(22, false); | 693 StartClient(22, false); |
| 694 | 694 |
| 695 // Wait to check callbacks before removing the listener. | 695 // Wait to check callbacks before removing the listener. |
| 696 base::RunLoop().RunUntilIdle(); | 696 base::RunLoop().RunUntilIdle(); |
| 697 vcm_->UnregisterListener(); | 697 vcm_->UnregisterListener(listener_.get()); |
| 698 } | 698 } |
| 699 | 699 |
| 700 // Open and start a device, close it before calling Stop. | 700 // Open and start a device, close it before calling Stop. |
| 701 TEST_F(VideoCaptureManagerTest, CloseWithoutStop) { | 701 TEST_F(VideoCaptureManagerTest, CloseWithoutStop) { |
| 702 InSequence s; | 702 InSequence s; |
| 703 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 703 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 704 EXPECT_CALL(*frame_observer_, OnStarted(_)); | 704 EXPECT_CALL(*frame_observer_, OnStarted(_)); |
| 705 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 705 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 706 | 706 |
| 707 int video_session_id = vcm_->Open(devices_.front()); | 707 int video_session_id = vcm_->Open(devices_.front().device); |
| 708 | 708 |
| 709 VideoCaptureControllerID client_id = StartClient(video_session_id, true); | 709 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 710 | 710 |
| 711 // Close will stop the running device, an assert will be triggered in | 711 // Close will stop the running device, an assert will be triggered in |
| 712 // VideoCaptureManager destructor otherwise. | 712 // VideoCaptureManager destructor otherwise. |
| 713 vcm_->Close(video_session_id); | 713 vcm_->Close(video_session_id); |
| 714 StopClient(client_id); | 714 StopClient(client_id); |
| 715 | 715 |
| 716 // Wait to check callbacks before removing the listener | 716 // Wait to check callbacks before removing the listener |
| 717 base::RunLoop().RunUntilIdle(); | 717 base::RunLoop().RunUntilIdle(); |
| 718 vcm_->UnregisterListener(); | 718 vcm_->UnregisterListener(listener_.get()); |
| 719 } | 719 } |
| 720 | 720 |
| 721 // Try to open, start, pause and resume a device. Confirm the device is | 721 // Try to open, start, pause and resume a device. Confirm the device is |
| 722 // paused/resumed at the correct times in both single-client and multiple-client | 722 // paused/resumed at the correct times in both single-client and multiple-client |
| 723 // scenarios. | 723 // scenarios. |
| 724 TEST_F(VideoCaptureManagerTest, PauseAndResumeClient) { | 724 TEST_F(VideoCaptureManagerTest, PauseAndResumeClient) { |
| 725 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 725 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 726 EXPECT_CALL(*frame_observer_, OnStarted(_)); | 726 EXPECT_CALL(*frame_observer_, OnStarted(_)); |
| 727 | 727 |
| 728 const int video_session_id = vcm_->Open(devices_.front()); | 728 const int video_session_id = vcm_->Open(devices_.front().device); |
| 729 const VideoCaptureControllerID client_id = | 729 const VideoCaptureControllerID client_id = |
| 730 StartClient(video_session_id, true); | 730 StartClient(video_session_id, true); |
| 731 | 731 |
| 732 // Test pause/resume when only one client is present. | 732 // Test pause/resume when only one client is present. |
| 733 EXPECT_CALL(*video_capture_device_factory_, WillSuspendDevice()).Times(1); | 733 EXPECT_CALL(*video_capture_device_factory_, WillSuspendDevice()).Times(1); |
| 734 PauseClient(client_id); | 734 PauseClient(client_id); |
| 735 EXPECT_CALL(*video_capture_device_factory_, WillResumeDevice()).Times(1); | 735 EXPECT_CALL(*video_capture_device_factory_, WillResumeDevice()).Times(1); |
| 736 ResumeClient(video_session_id, client_id); | 736 ResumeClient(video_session_id, client_id); |
| 737 | 737 |
| 738 // Attempting to resume the client a second time should not cause any calls to | 738 // Attempting to resume the client a second time should not cause any calls to |
| 739 // VideoCaptureDevice::Resume(). | 739 // VideoCaptureDevice::Resume(). |
| 740 ResumeClient(video_session_id, client_id); | 740 ResumeClient(video_session_id, client_id); |
| 741 | 741 |
| 742 // Add a second client that is never paused, then pause/resume the first | 742 // Add a second client that is never paused, then pause/resume the first |
| 743 // client, and no calls to VideoCaptureDevice::MaybeSuspend() or Resume() are | 743 // client, and no calls to VideoCaptureDevice::MaybeSuspend() or Resume() are |
| 744 // made. | 744 // made. |
| 745 const VideoCaptureControllerID client_id2 = | 745 const VideoCaptureControllerID client_id2 = |
| 746 StartClient(video_session_id, true); | 746 StartClient(video_session_id, true); |
| 747 PauseClient(client_id); | 747 PauseClient(client_id); |
| 748 ResumeClient(video_session_id, client_id); | 748 ResumeClient(video_session_id, client_id); |
| 749 | 749 |
| 750 StopClient(client_id); | 750 StopClient(client_id); |
| 751 StopClient(client_id2); | 751 StopClient(client_id2); |
| 752 | 752 |
| 753 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 753 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 754 vcm_->Close(video_session_id); | 754 vcm_->Close(video_session_id); |
| 755 | 755 |
| 756 // Wait to check callbacks before removing the listener. | 756 // Wait to check callbacks before removing the listener. |
| 757 base::RunLoop().RunUntilIdle(); | 757 base::RunLoop().RunUntilIdle(); |
| 758 vcm_->UnregisterListener(); | 758 vcm_->UnregisterListener(listener_.get()); |
| 759 } | 759 } |
| 760 | 760 |
| 761 #if defined(OS_ANDROID) | 761 #if defined(OS_ANDROID) |
| 762 // Try to open, start, pause and resume a device. | 762 // Try to open, start, pause and resume a device. |
| 763 TEST_F(VideoCaptureManagerTest, PauseAndResumeDevice) { | 763 TEST_F(VideoCaptureManagerTest, PauseAndResumeDevice) { |
| 764 InSequence s; | 764 InSequence s; |
| 765 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 765 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 766 EXPECT_CALL(*frame_observer_, OnStarted(_)); | 766 EXPECT_CALL(*frame_observer_, OnStarted(_)); |
| 767 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 767 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 768 | 768 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 780 ApplicationStateChange( | 780 ApplicationStateChange( |
| 781 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); | 781 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); |
| 782 ApplicationStateChange( | 782 ApplicationStateChange( |
| 783 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); | 783 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES); |
| 784 | 784 |
| 785 StopClient(client_id); | 785 StopClient(client_id); |
| 786 vcm_->Close(video_session_id); | 786 vcm_->Close(video_session_id); |
| 787 | 787 |
| 788 // Wait to check callbacks before removing the listener. | 788 // Wait to check callbacks before removing the listener. |
| 789 base::RunLoop().RunUntilIdle(); | 789 base::RunLoop().RunUntilIdle(); |
| 790 vcm_->UnregisterListener(); | 790 vcm_->UnregisterListener(listener_.get()); |
| 791 } | 791 } |
| 792 #endif | 792 #endif |
| 793 | 793 |
| 794 // 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 |
| 795 // provided by the device when http://crbug.com/323913 is closed. | 795 // provided by the device when http://crbug.com/323913 is closed. |
| 796 | 796 |
| 797 } // namespace content | 797 } // namespace content |
| OLD | NEW |