| 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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 EXPECT_GT(supported_formats[0].frame_rate, 1); | 431 EXPECT_GT(supported_formats[0].frame_rate, 1); |
| 432 EXPECT_GT(supported_formats[1].frame_size.width(), 1); | 432 EXPECT_GT(supported_formats[1].frame_size.width(), 1); |
| 433 EXPECT_GT(supported_formats[1].frame_size.height(), 1); | 433 EXPECT_GT(supported_formats[1].frame_size.height(), 1); |
| 434 EXPECT_GT(supported_formats[1].frame_rate, 1); | 434 EXPECT_GT(supported_formats[1].frame_rate, 1); |
| 435 | 435 |
| 436 vcm_->Close(video_session_id); | 436 vcm_->Close(video_session_id); |
| 437 base::RunLoop().RunUntilIdle(); | 437 base::RunLoop().RunUntilIdle(); |
| 438 vcm_->Unregister(); | 438 vcm_->Unregister(); |
| 439 } | 439 } |
| 440 | 440 |
| 441 // Enumerate devices, then check the list of supported formats. Then open and |
| 442 // start the first device. The capability list should stay the same. Finally |
| 443 // stop the device and check that the capabilities stay unchanged. |
| 444 TEST_F(VideoCaptureManagerTest, |
| 445 ManipulateDeviceAndCheckCapabilitiesWithDeviceId) { |
| 446 // Requesting formats should work even before enumerating/opening devices. |
| 447 std::string device_id = devices_.front().device.id; |
| 448 media::VideoCaptureFormats supported_formats; |
| 449 supported_formats.clear(); |
| 450 EXPECT_TRUE(vcm_->GetDeviceSupportedFormats(device_id, &supported_formats)); |
| 451 ASSERT_GE(supported_formats.size(), 2u); |
| 452 EXPECT_GT(supported_formats[0].frame_size.width(), 1); |
| 453 EXPECT_GT(supported_formats[0].frame_size.height(), 1); |
| 454 EXPECT_GT(supported_formats[0].frame_rate, 1); |
| 455 EXPECT_GT(supported_formats[1].frame_size.width(), 1); |
| 456 EXPECT_GT(supported_formats[1].frame_size.height(), 1); |
| 457 EXPECT_GT(supported_formats[1].frame_rate, 1); |
| 458 |
| 459 InSequence s; |
| 460 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 461 int video_session_id = vcm_->Open(devices_.front()); |
| 462 base::RunLoop().RunUntilIdle(); |
| 463 |
| 464 // Right after opening the device, we should see all its formats. |
| 465 supported_formats.clear(); |
| 466 EXPECT_TRUE(vcm_->GetDeviceSupportedFormats(device_id, &supported_formats)); |
| 467 ASSERT_GE(supported_formats.size(), 2u); |
| 468 EXPECT_GT(supported_formats[0].frame_size.width(), 1); |
| 469 EXPECT_GT(supported_formats[0].frame_size.height(), 1); |
| 470 EXPECT_GT(supported_formats[0].frame_rate, 1); |
| 471 EXPECT_GT(supported_formats[1].frame_size.width(), 1); |
| 472 EXPECT_GT(supported_formats[1].frame_size.height(), 1); |
| 473 EXPECT_GT(supported_formats[1].frame_rate, 1); |
| 474 |
| 475 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 476 base::RunLoop().RunUntilIdle(); |
| 477 // After StartClient(), device's supported formats should stay the same. |
| 478 supported_formats.clear(); |
| 479 EXPECT_TRUE(vcm_->GetDeviceSupportedFormats(device_id, &supported_formats)); |
| 480 ASSERT_GE(supported_formats.size(), 2u); |
| 481 EXPECT_GT(supported_formats[0].frame_size.width(), 1); |
| 482 EXPECT_GT(supported_formats[0].frame_size.height(), 1); |
| 483 EXPECT_GT(supported_formats[0].frame_rate, 1); |
| 484 EXPECT_GT(supported_formats[1].frame_size.width(), 1); |
| 485 EXPECT_GT(supported_formats[1].frame_size.height(), 1); |
| 486 EXPECT_GT(supported_formats[1].frame_rate, 1); |
| 487 |
| 488 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 489 StopClient(client_id); |
| 490 supported_formats.clear(); |
| 491 EXPECT_TRUE(vcm_->GetDeviceSupportedFormats(device_id, &supported_formats)); |
| 492 ASSERT_GE(supported_formats.size(), 2u); |
| 493 EXPECT_GT(supported_formats[0].frame_size.width(), 1); |
| 494 EXPECT_GT(supported_formats[0].frame_size.height(), 1); |
| 495 EXPECT_GT(supported_formats[0].frame_rate, 1); |
| 496 EXPECT_GT(supported_formats[1].frame_size.width(), 1); |
| 497 EXPECT_GT(supported_formats[1].frame_size.height(), 1); |
| 498 EXPECT_GT(supported_formats[1].frame_rate, 1); |
| 499 |
| 500 vcm_->Close(video_session_id); |
| 501 base::RunLoop().RunUntilIdle(); |
| 502 vcm_->Unregister(); |
| 503 } |
| 504 |
| 441 // Enumerate devices and open the first, then check the formats currently in | 505 // Enumerate devices and open the first, then check the formats currently in |
| 442 // use, which should be an empty vector. Then start the opened device. The | 506 // use, which should be an empty vector. Then start the opened device. The |
| 443 // format(s) in use should be just one format (the one used when configuring- | 507 // format(s) in use should be just one format (the one used when configuring- |
| 444 // starting the device). Finally stop the device and check that the formats in | 508 // starting the device). Finally stop the device and check that the formats in |
| 445 // use is an empty vector. | 509 // use is an empty vector. |
| 446 TEST_F(VideoCaptureManagerTest, StartDeviceAndGetDeviceFormatInUse) { | 510 TEST_F(VideoCaptureManagerTest, StartDeviceAndGetDeviceFormatInUse) { |
| 447 InSequence s; | 511 InSequence s; |
| 448 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); | 512 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 449 int video_session_id = vcm_->Open(devices_.front()); | 513 int video_session_id = vcm_->Open(devices_.front()); |
| 450 base::RunLoop().RunUntilIdle(); | 514 base::RunLoop().RunUntilIdle(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 473 base::RunLoop().RunUntilIdle(); | 537 base::RunLoop().RunUntilIdle(); |
| 474 // After StopClient(), the device's formats in use should be empty again. | 538 // After StopClient(), the device's formats in use should be empty again. |
| 475 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(video_session_id, &formats_in_use)); | 539 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(video_session_id, &formats_in_use)); |
| 476 EXPECT_TRUE(formats_in_use.empty()); | 540 EXPECT_TRUE(formats_in_use.empty()); |
| 477 | 541 |
| 478 vcm_->Close(video_session_id); | 542 vcm_->Close(video_session_id); |
| 479 base::RunLoop().RunUntilIdle(); | 543 base::RunLoop().RunUntilIdle(); |
| 480 vcm_->Unregister(); | 544 vcm_->Unregister(); |
| 481 } | 545 } |
| 482 | 546 |
| 547 // Enumerate devices and open the first, then check the formats currently in |
| 548 // use, which should be an empty vector. Then start the opened device. The |
| 549 // format(s) in use should be just one format (the one used when configuring- |
| 550 // starting the device). Finally stop the device and check that the formats in |
| 551 // use is an empty vector. |
| 552 TEST_F(VideoCaptureManagerTest, |
| 553 StartDeviceAndGetDeviceFormatInUseWithDeviceId) { |
| 554 std::string device_id = devices_.front().device.id; |
| 555 InSequence s; |
| 556 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 557 int video_session_id = vcm_->Open(devices_.front()); |
| 558 base::RunLoop().RunUntilIdle(); |
| 559 |
| 560 // Right after opening the device, we should see no format in use. |
| 561 media::VideoCaptureFormats formats_in_use; |
| 562 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(MEDIA_DEVICE_VIDEO_CAPTURE, device_id, |
| 563 &formats_in_use)); |
| 564 EXPECT_TRUE(formats_in_use.empty()); |
| 565 |
| 566 VideoCaptureControllerID client_id = StartClient(video_session_id, true); |
| 567 base::RunLoop().RunUntilIdle(); |
| 568 // After StartClient(), |formats_in_use| should contain one valid format. |
| 569 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(MEDIA_DEVICE_VIDEO_CAPTURE, device_id, |
| 570 &formats_in_use)); |
| 571 EXPECT_EQ(formats_in_use.size(), 1u); |
| 572 if (formats_in_use.size()) { |
| 573 media::VideoCaptureFormat& format_in_use = formats_in_use.front(); |
| 574 EXPECT_TRUE(format_in_use.IsValid()); |
| 575 EXPECT_GT(format_in_use.frame_size.width(), 1); |
| 576 EXPECT_GT(format_in_use.frame_size.height(), 1); |
| 577 EXPECT_GT(format_in_use.frame_rate, 1); |
| 578 } |
| 579 formats_in_use.clear(); |
| 580 |
| 581 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)); |
| 582 StopClient(client_id); |
| 583 base::RunLoop().RunUntilIdle(); |
| 584 // After StopClient(), the device's formats in use should be empty again. |
| 585 EXPECT_TRUE(vcm_->GetDeviceFormatsInUse(MEDIA_DEVICE_VIDEO_CAPTURE, device_id, |
| 586 &formats_in_use)); |
| 587 EXPECT_TRUE(formats_in_use.empty()); |
| 588 |
| 589 vcm_->Close(video_session_id); |
| 590 base::RunLoop().RunUntilIdle(); |
| 591 vcm_->Unregister(); |
| 592 } |
| 593 |
| 483 // Open two different devices. | 594 // Open two different devices. |
| 484 TEST_F(VideoCaptureManagerTest, OpenTwo) { | 595 TEST_F(VideoCaptureManagerTest, OpenTwo) { |
| 485 InSequence s; | 596 InSequence s; |
| 486 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 597 EXPECT_CALL(*listener_, Opened(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 487 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); | 598 EXPECT_CALL(*listener_, Closed(MEDIA_DEVICE_VIDEO_CAPTURE, _)).Times(2); |
| 488 | 599 |
| 489 StreamDeviceInfoArray::iterator it = devices_.begin(); | 600 StreamDeviceInfoArray::iterator it = devices_.begin(); |
| 490 | 601 |
| 491 int video_session_id_first = vcm_->Open(*it); | 602 int video_session_id_first = vcm_->Open(*it); |
| 492 ++it; | 603 ++it; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 // Wait to check callbacks before removing the listener. | 732 // Wait to check callbacks before removing the listener. |
| 622 base::RunLoop().RunUntilIdle(); | 733 base::RunLoop().RunUntilIdle(); |
| 623 vcm_->Unregister(); | 734 vcm_->Unregister(); |
| 624 } | 735 } |
| 625 #endif | 736 #endif |
| 626 | 737 |
| 627 // TODO(mcasas): Add a test to check consolidation of the supported formats | 738 // TODO(mcasas): Add a test to check consolidation of the supported formats |
| 628 // provided by the device when http://crbug.com/323913 is closed. | 739 // provided by the device when http://crbug.com/323913 is closed. |
| 629 | 740 |
| 630 } // namespace content | 741 } // namespace content |
| OLD | NEW |