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 #include "content/browser/media/capture/web_contents_video_capture_device.h" | 5 #include "content/browser/media/capture/web_contents_video_capture_device.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 MOCK_METHOD7(OnIncomingCapturedData, | 236 MOCK_METHOD7(OnIncomingCapturedData, |
237 void(const uint8_t* data, | 237 void(const uint8_t* data, |
238 int length, | 238 int length, |
239 const media::VideoCaptureFormat& frame_format, | 239 const media::VideoCaptureFormat& frame_format, |
240 int rotation, | 240 int rotation, |
241 base::TimeTicks reference_time, | 241 base::TimeTicks reference_time, |
242 base::TimeDelta timestamp, | 242 base::TimeDelta timestamp, |
243 int frame_feedback_id)); | 243 int frame_feedback_id)); |
244 | 244 |
245 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); | 245 MOCK_METHOD0(DoOnIncomingCapturedBuffer, void(void)); |
| 246 MOCK_METHOD0(OnStarted, void(void)); |
246 | 247 |
247 media::VideoCaptureDevice::Client::Buffer ReserveOutputBuffer( | 248 media::VideoCaptureDevice::Client::Buffer ReserveOutputBuffer( |
248 const gfx::Size& dimensions, | 249 const gfx::Size& dimensions, |
249 media::VideoPixelFormat format, | 250 media::VideoPixelFormat format, |
250 media::VideoPixelStorage storage, | 251 media::VideoPixelStorage storage, |
251 int frame_feedback_id) override { | 252 int frame_feedback_id) override { |
252 CHECK_EQ(format, media::PIXEL_FORMAT_I420); | 253 CHECK_EQ(format, media::PIXEL_FORMAT_I420); |
253 int buffer_id_to_drop = | 254 int buffer_id_to_drop = |
254 media::VideoCaptureBufferPool::kInvalidId; // Ignored. | 255 media::VideoCaptureBufferPool::kInvalidId; // Ignored. |
255 const int buffer_id = buffer_pool_->ReserveForProducer( | 256 const int buffer_id = buffer_pool_->ReserveForProducer( |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 wait_color_yuv_(kWaitColorNotSet), | 339 wait_color_yuv_(kWaitColorNotSet), |
339 expecting_frames_(true) { | 340 expecting_frames_(true) { |
340 client_.reset(new StubClient( | 341 client_.reset(new StubClient( |
341 base::Bind(&StubClientObserver::DidDeliverFrame, | 342 base::Bind(&StubClientObserver::DidDeliverFrame, |
342 base::Unretained(this)), | 343 base::Unretained(this)), |
343 base::Bind(&StubClientObserver::OnError, base::Unretained(this)))); | 344 base::Bind(&StubClientObserver::OnError, base::Unretained(this)))); |
344 } | 345 } |
345 | 346 |
346 virtual ~StubClientObserver() {} | 347 virtual ~StubClientObserver() {} |
347 | 348 |
348 std::unique_ptr<media::VideoCaptureDevice::Client> PassClient() { | 349 std::unique_ptr<StubClient> PassClient() { return std::move(client_); } |
349 return std::move(client_); | |
350 } | |
351 | 350 |
352 void SetIsExpectingFrames(bool expecting_frames) { | 351 void SetIsExpectingFrames(bool expecting_frames) { |
353 expecting_frames_ = expecting_frames; | 352 expecting_frames_ = expecting_frames; |
354 } | 353 } |
355 | 354 |
356 void QuitIfConditionsMet(SkColor color, const gfx::Size& size) { | 355 void QuitIfConditionsMet(SkColor color, const gfx::Size& size) { |
357 EXPECT_TRUE(expecting_frames_); | 356 EXPECT_TRUE(expecting_frames_); |
358 if (error_encountered_ || wait_color_yuv_ == kNotInterested || | 357 if (error_encountered_ || wait_color_yuv_ == kNotInterested || |
359 wait_color_yuv_ == color) { | 358 wait_color_yuv_ == color) { |
360 last_frame_color_yuv_ = color; | 359 last_frame_color_yuv_ = color; |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 std::unique_ptr<media::VideoCaptureDevice> device_; | 627 std::unique_ptr<media::VideoCaptureDevice> device_; |
629 }; | 628 }; |
630 | 629 |
631 // In real-world use cases, there can exist a race condition between starting | 630 // In real-world use cases, there can exist a race condition between starting |
632 // capture on a WebContents and having the WebContents be destroyed in the | 631 // capture on a WebContents and having the WebContents be destroyed in the |
633 // meantime. This tests that WebContentsVideoCaptureDevice errors-out | 632 // meantime. This tests that WebContentsVideoCaptureDevice errors-out |
634 // gracefully. | 633 // gracefully. |
635 TEST_F(WebContentsVideoCaptureDeviceTest, | 634 TEST_F(WebContentsVideoCaptureDeviceTest, |
636 SafelyStartsUpAfterWebContentsHasGone) { | 635 SafelyStartsUpAfterWebContentsHasGone) { |
637 ResetWebContents(); | 636 ResetWebContents(); |
638 device()->AllocateAndStart(DefaultCaptureParams(), | 637 auto client = client_observer()->PassClient(); |
639 client_observer()->PassClient()); | 638 EXPECT_CALL(*client, OnStarted()); |
| 639 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client)); |
640 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForError()); | 640 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForError()); |
641 device()->StopAndDeAllocate(); | 641 device()->StopAndDeAllocate(); |
642 } | 642 } |
643 | 643 |
644 // Tests that WebContentsVideoCaptureDevice starts, captures a frame, and then | 644 // Tests that WebContentsVideoCaptureDevice starts, captures a frame, and then |
645 // gracefully errors-out if the WebContents is destroyed before the device is | 645 // gracefully errors-out if the WebContents is destroyed before the device is |
646 // stopped. | 646 // stopped. |
647 TEST_F(WebContentsVideoCaptureDeviceTest, | 647 TEST_F(WebContentsVideoCaptureDeviceTest, |
648 RunsThenErrorsOutWhenWebContentsIsDestroyed) { | 648 RunsThenErrorsOutWhenWebContentsIsDestroyed) { |
649 // We'll simulate the tab being closed after the capture pipeline is up and | 649 // We'll simulate the tab being closed after the capture pipeline is up and |
650 // running. | 650 // running. |
651 device()->AllocateAndStart(DefaultCaptureParams(), | 651 auto client = client_observer()->PassClient(); |
652 client_observer()->PassClient()); | 652 EXPECT_CALL(*client, OnStarted()); |
| 653 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client)); |
653 | 654 |
654 // Do one capture to prove the tab is initially open and being captured | 655 // Do one capture to prove the tab is initially open and being captured |
655 // normally. | 656 // normally. |
656 test_view()->SetSolidColor(SK_ColorRED); | 657 test_view()->SetSolidColor(SK_ColorRED); |
657 SimulateDrawEvent(); | 658 SimulateDrawEvent(); |
658 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); | 659 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); |
659 | 660 |
660 base::RunLoop().RunUntilIdle(); | 661 base::RunLoop().RunUntilIdle(); |
661 | 662 |
662 // Post a task to close the tab. We should see an error reported to the | 663 // Post a task to close the tab. We should see an error reported to the |
(...skipping 23 matching lines...) Expand all Loading... |
686 // wind up in the idle state. | 687 // wind up in the idle state. |
687 base::RunLoop().RunUntilIdle(); | 688 base::RunLoop().RunUntilIdle(); |
688 } | 689 } |
689 | 690 |
690 // Tests that frames are delivered to different clients across restarts of the | 691 // Tests that frames are delivered to different clients across restarts of the |
691 // same instance. | 692 // same instance. |
692 TEST_F(WebContentsVideoCaptureDeviceTest, | 693 TEST_F(WebContentsVideoCaptureDeviceTest, |
693 DeliversToCorrectClientAcrossRestarts) { | 694 DeliversToCorrectClientAcrossRestarts) { |
694 // While the device is up-and-running, expect frame captures. | 695 // While the device is up-and-running, expect frame captures. |
695 client_observer()->SetIsExpectingFrames(true); | 696 client_observer()->SetIsExpectingFrames(true); |
696 device()->AllocateAndStart(DefaultCaptureParams(), | 697 auto client = client_observer()->PassClient(); |
697 client_observer()->PassClient()); | 698 EXPECT_CALL(*client, OnStarted()); |
| 699 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client)); |
698 base::RunLoop().RunUntilIdle(); | 700 base::RunLoop().RunUntilIdle(); |
699 test_view()->SetSolidColor(SK_ColorRED); | 701 test_view()->SetSolidColor(SK_ColorRED); |
700 SimulateDrawEvent(); | 702 SimulateDrawEvent(); |
701 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); | 703 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); |
702 SimulateDrawEvent(); | 704 SimulateDrawEvent(); |
703 test_view()->SetSolidColor(SK_ColorGREEN); | 705 test_view()->SetSolidColor(SK_ColorGREEN); |
704 SimulateDrawEvent(); | 706 SimulateDrawEvent(); |
705 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); | 707 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); |
706 SimulateDrawEvent(); | 708 SimulateDrawEvent(); |
707 device()->StopAndDeAllocate(); | 709 device()->StopAndDeAllocate(); |
708 | 710 |
709 base::RunLoop().RunUntilIdle(); | 711 base::RunLoop().RunUntilIdle(); |
710 | 712 |
711 // Now that the device is stopped, expect frames are no longer captured. | 713 // Now that the device is stopped, expect frames are no longer captured. |
712 client_observer()->SetIsExpectingFrames(false); | 714 client_observer()->SetIsExpectingFrames(false); |
713 SimulateDrawEvent(); | 715 SimulateDrawEvent(); |
714 SimulateDrawEvent(); | 716 SimulateDrawEvent(); |
715 base::RunLoop().RunUntilIdle(); | 717 base::RunLoop().RunUntilIdle(); |
716 | 718 |
717 // Re-start the device with a different client. Only the second client should | 719 // Re-start the device with a different client. Only the second client should |
718 // expect to see any frame captures. | 720 // expect to see any frame captures. |
719 StubClientObserver observer2; | 721 StubClientObserver observer2; |
720 observer2.SetIsExpectingFrames(true); | 722 observer2.SetIsExpectingFrames(true); |
721 device()->AllocateAndStart(DefaultCaptureParams(), observer2.PassClient()); | 723 auto client2 = observer2.PassClient(); |
| 724 EXPECT_CALL(*client2, OnStarted()); |
| 725 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client2)); |
722 test_view()->SetSolidColor(SK_ColorBLUE); | 726 test_view()->SetSolidColor(SK_ColorBLUE); |
723 SimulateDrawEvent(); | 727 SimulateDrawEvent(); |
724 ASSERT_NO_FATAL_FAILURE(observer2.WaitForNextColor(SK_ColorBLUE)); | 728 ASSERT_NO_FATAL_FAILURE(observer2.WaitForNextColor(SK_ColorBLUE)); |
725 test_view()->SetSolidColor(SK_ColorYELLOW); | 729 test_view()->SetSolidColor(SK_ColorYELLOW); |
726 SimulateDrawEvent(); | 730 SimulateDrawEvent(); |
727 ASSERT_NO_FATAL_FAILURE(observer2.WaitForNextColor(SK_ColorYELLOW)); | 731 ASSERT_NO_FATAL_FAILURE(observer2.WaitForNextColor(SK_ColorYELLOW)); |
728 device()->StopAndDeAllocate(); | 732 device()->StopAndDeAllocate(); |
729 } | 733 } |
730 | 734 |
731 // The "happy case" test. No scaling is needed, so we should be able to change | 735 // The "happy case" test. No scaling is needed, so we should be able to change |
732 // the picture emitted from the source and expect to see each delivered to the | 736 // the picture emitted from the source and expect to see each delivered to the |
733 // consumer. The test will alternate between the RGB/SkBitmap and YUV/VideoFrame | 737 // consumer. The test will alternate between the RGB/SkBitmap and YUV/VideoFrame |
734 // capture paths. | 738 // capture paths. |
735 TEST_F(WebContentsVideoCaptureDeviceTest, GoesThroughAllTheMotions) { | 739 TEST_F(WebContentsVideoCaptureDeviceTest, GoesThroughAllTheMotions) { |
736 device()->AllocateAndStart(DefaultCaptureParams(), | 740 auto client = client_observer()->PassClient(); |
737 client_observer()->PassClient()); | 741 EXPECT_CALL(*client, OnStarted()); |
| 742 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client)); |
738 | 743 |
739 for (int i = 0; i < 3; i++) { | 744 for (int i = 0; i < 3; i++) { |
740 SCOPED_TRACE(base::StringPrintf("Iteration #%d", i)); | 745 SCOPED_TRACE(base::StringPrintf("Iteration #%d", i)); |
741 | 746 |
742 test_view()->SetSolidColor(SK_ColorRED); | 747 test_view()->SetSolidColor(SK_ColorRED); |
743 for (int j = 0; j <= i; j++) | 748 for (int j = 0; j <= i; j++) |
744 SimulateDrawEvent(); | 749 SimulateDrawEvent(); |
745 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); | 750 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); |
746 | 751 |
747 test_view()->SetSolidColor(SK_ColorGREEN); | 752 test_view()->SetSolidColor(SK_ColorGREEN); |
(...skipping 15 matching lines...) Expand all Loading... |
763 device()->StopAndDeAllocate(); | 768 device()->StopAndDeAllocate(); |
764 } | 769 } |
765 | 770 |
766 // Tests that, when configured with the FIXED_ASPECT_RATIO resolution change | 771 // Tests that, when configured with the FIXED_ASPECT_RATIO resolution change |
767 // policy, the source size changes result in video frames of possibly varying | 772 // policy, the source size changes result in video frames of possibly varying |
768 // resolutions, but all with the same aspect ratio. | 773 // resolutions, but all with the same aspect ratio. |
769 TEST_F(WebContentsVideoCaptureDeviceTest, VariableResolution_FixedAspectRatio) { | 774 TEST_F(WebContentsVideoCaptureDeviceTest, VariableResolution_FixedAspectRatio) { |
770 auto capture_params = DefaultCaptureParams(); | 775 auto capture_params = DefaultCaptureParams(); |
771 capture_params.resolution_change_policy = | 776 capture_params.resolution_change_policy = |
772 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO; | 777 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO; |
773 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); | 778 auto client = client_observer()->PassClient(); |
| 779 EXPECT_CALL(*client, OnStarted()); |
| 780 device()->AllocateAndStart(capture_params, std::move(client)); |
774 | 781 |
775 // Source size equals maximum size. Expect delivered frames to be | 782 // Source size equals maximum size. Expect delivered frames to be |
776 // kTestWidth by kTestHeight. | 783 // kTestWidth by kTestHeight. |
777 test_view()->SetSolidColor(SK_ColorRED); | 784 test_view()->SetSolidColor(SK_ColorRED); |
778 const float device_scale_factor = GetDeviceScaleFactor(); | 785 const float device_scale_factor = GetDeviceScaleFactor(); |
779 SimulateSourceSizeChange(gfx::ConvertSizeToDIP( | 786 SimulateSourceSizeChange(gfx::ConvertSizeToDIP( |
780 device_scale_factor, gfx::Size(kTestWidth, kTestHeight))); | 787 device_scale_factor, gfx::Size(kTestWidth, kTestHeight))); |
781 SimulateDrawsUntilNewFrameSizeArrives( | 788 SimulateDrawsUntilNewFrameSizeArrives( |
782 SK_ColorRED, gfx::Size(kTestWidth, kTestHeight)); | 789 SK_ColorRED, gfx::Size(kTestWidth, kTestHeight)); |
783 | 790 |
(...skipping 25 matching lines...) Expand all Loading... |
809 device()->StopAndDeAllocate(); | 816 device()->StopAndDeAllocate(); |
810 } | 817 } |
811 | 818 |
812 // Tests that, when configured with the ANY_WITHIN_LIMIT resolution change | 819 // Tests that, when configured with the ANY_WITHIN_LIMIT resolution change |
813 // policy, the source size changes result in video frames of possibly varying | 820 // policy, the source size changes result in video frames of possibly varying |
814 // resolutions. | 821 // resolutions. |
815 TEST_F(WebContentsVideoCaptureDeviceTest, VariableResolution_AnyWithinLimits) { | 822 TEST_F(WebContentsVideoCaptureDeviceTest, VariableResolution_AnyWithinLimits) { |
816 auto capture_params = DefaultCaptureParams(); | 823 auto capture_params = DefaultCaptureParams(); |
817 capture_params.resolution_change_policy = | 824 capture_params.resolution_change_policy = |
818 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; | 825 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; |
819 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); | 826 auto client = client_observer()->PassClient(); |
| 827 EXPECT_CALL(*client, OnStarted()); |
| 828 device()->AllocateAndStart(capture_params, std::move(client)); |
820 | 829 |
821 // Source size equals maximum size. Expect delivered frames to be | 830 // Source size equals maximum size. Expect delivered frames to be |
822 // kTestWidth by kTestHeight. | 831 // kTestWidth by kTestHeight. |
823 test_view()->SetSolidColor(SK_ColorRED); | 832 test_view()->SetSolidColor(SK_ColorRED); |
824 const float device_scale_factor = GetDeviceScaleFactor(); | 833 const float device_scale_factor = GetDeviceScaleFactor(); |
825 SimulateSourceSizeChange(gfx::ConvertSizeToDIP( | 834 SimulateSourceSizeChange(gfx::ConvertSizeToDIP( |
826 device_scale_factor, gfx::Size(kTestWidth, kTestHeight))); | 835 device_scale_factor, gfx::Size(kTestWidth, kTestHeight))); |
827 SimulateDrawsUntilNewFrameSizeArrives( | 836 SimulateDrawsUntilNewFrameSizeArrives( |
828 SK_ColorRED, gfx::Size(kTestWidth, kTestHeight)); | 837 SK_ColorRED, gfx::Size(kTestWidth, kTestHeight)); |
829 | 838 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 policy == media::RESOLUTION_POLICY_FIXED_RESOLUTION ? oddball_size | 889 policy == media::RESOLUTION_POLICY_FIXED_RESOLUTION ? oddball_size |
881 : standard_size, | 890 : standard_size, |
882 1.0f / GetDeviceScaleFactor()); | 891 1.0f / GetDeviceScaleFactor()); |
883 ASSERT_NE(capture_preferred_size, web_contents()->GetPreferredSize()); | 892 ASSERT_NE(capture_preferred_size, web_contents()->GetPreferredSize()); |
884 | 893 |
885 // Start the WebContentsVideoCaptureDevice. | 894 // Start the WebContentsVideoCaptureDevice. |
886 auto capture_params = DefaultCaptureParams(); | 895 auto capture_params = DefaultCaptureParams(); |
887 capture_params.requested_format.frame_size = oddball_size; | 896 capture_params.requested_format.frame_size = oddball_size; |
888 capture_params.resolution_change_policy = policy; | 897 capture_params.resolution_change_policy = policy; |
889 StubClientObserver unused_observer; | 898 StubClientObserver unused_observer; |
890 device()->AllocateAndStart(capture_params, unused_observer.PassClient()); | 899 auto client = unused_observer.PassClient(); |
| 900 EXPECT_CALL(*client, OnStarted()); |
| 901 device()->AllocateAndStart(capture_params, std::move(client)); |
891 base::RunLoop().RunUntilIdle(); | 902 base::RunLoop().RunUntilIdle(); |
892 | 903 |
893 // Check that the preferred size of the WebContents matches the one provided | 904 // Check that the preferred size of the WebContents matches the one provided |
894 // by WebContentsVideoCaptureDevice. | 905 // by WebContentsVideoCaptureDevice. |
895 EXPECT_EQ(capture_preferred_size, web_contents()->GetPreferredSize()); | 906 EXPECT_EQ(capture_preferred_size, web_contents()->GetPreferredSize()); |
896 | 907 |
897 // Stop the WebContentsVideoCaptureDevice. | 908 // Stop the WebContentsVideoCaptureDevice. |
898 device()->StopAndDeAllocate(); | 909 device()->StopAndDeAllocate(); |
899 base::RunLoop().RunUntilIdle(); | 910 base::RunLoop().RunUntilIdle(); |
900 }; | 911 }; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 policies[i], gfx::Size(1000, 1000), gfx::Size(1000, 1000)); | 957 policies[i], gfx::Size(1000, 1000), gfx::Size(1000, 1000)); |
947 RunTestForPreferredSize( | 958 RunTestForPreferredSize( |
948 policies[i], gfx::Size(1600, 1000), gfx::Size(1600, 1000)); | 959 policies[i], gfx::Size(1600, 1000), gfx::Size(1600, 1000)); |
949 RunTestForPreferredSize( | 960 RunTestForPreferredSize( |
950 policies[i], gfx::Size(837, 999), gfx::Size(837, 999)); | 961 policies[i], gfx::Size(837, 999), gfx::Size(837, 999)); |
951 } | 962 } |
952 } | 963 } |
953 | 964 |
954 // Tests the Suspend/Resume() functionality. | 965 // Tests the Suspend/Resume() functionality. |
955 TEST_F(WebContentsVideoCaptureDeviceTest, SuspendsAndResumes) { | 966 TEST_F(WebContentsVideoCaptureDeviceTest, SuspendsAndResumes) { |
956 device()->AllocateAndStart(DefaultCaptureParams(), | 967 auto client = client_observer()->PassClient(); |
957 client_observer()->PassClient()); | 968 EXPECT_CALL(*client, OnStarted()); |
| 969 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client)); |
958 | 970 |
959 for (int i = 0; i < 3; ++i) { | 971 for (int i = 0; i < 3; ++i) { |
960 // Draw a RED frame and wait for a normal frame capture to occur. | 972 // Draw a RED frame and wait for a normal frame capture to occur. |
961 test_view()->SetSolidColor(SK_ColorRED); | 973 test_view()->SetSolidColor(SK_ColorRED); |
962 SimulateDrawEvent(); | 974 SimulateDrawEvent(); |
963 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); | 975 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); |
964 | 976 |
965 // Suspend capture and then draw a GREEN frame. No frame capture should | 977 // Suspend capture and then draw a GREEN frame. No frame capture should |
966 // occur. | 978 // occur. |
967 device()->MaybeSuspend(); | 979 device()->MaybeSuspend(); |
(...skipping 12 matching lines...) Expand all Loading... |
980 test_view()->SetSolidColor(SK_ColorBLUE); | 992 test_view()->SetSolidColor(SK_ColorBLUE); |
981 SimulateDrawEvent(); | 993 SimulateDrawEvent(); |
982 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorBLUE)); | 994 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorBLUE)); |
983 } | 995 } |
984 | 996 |
985 device()->StopAndDeAllocate(); | 997 device()->StopAndDeAllocate(); |
986 } | 998 } |
987 | 999 |
988 // Tests the RequestRefreshFrame() functionality. | 1000 // Tests the RequestRefreshFrame() functionality. |
989 TEST_F(WebContentsVideoCaptureDeviceTest, ProvidesRefreshFrames) { | 1001 TEST_F(WebContentsVideoCaptureDeviceTest, ProvidesRefreshFrames) { |
990 device()->AllocateAndStart(DefaultCaptureParams(), | 1002 auto client = client_observer()->PassClient(); |
991 client_observer()->PassClient()); | 1003 EXPECT_CALL(*client, OnStarted()); |
| 1004 device()->AllocateAndStart(DefaultCaptureParams(), std::move(client)); |
992 | 1005 |
993 // Request a refresh frame before the first frame has been drawn. This forces | 1006 // Request a refresh frame before the first frame has been drawn. This forces |
994 // a capture. | 1007 // a capture. |
995 test_view()->SetSolidColor(SK_ColorRED); | 1008 test_view()->SetSolidColor(SK_ColorRED); |
996 SimulateRefreshFrameRequest(); | 1009 SimulateRefreshFrameRequest(); |
997 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); | 1010 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); |
998 | 1011 |
999 // Now, draw a frame and wait for a normal frame capture to occur. | 1012 // Now, draw a frame and wait for a normal frame capture to occur. |
1000 test_view()->SetSolidColor(SK_ColorGREEN); | 1013 test_view()->SetSolidColor(SK_ColorGREEN); |
1001 SimulateDrawEvent(); | 1014 SimulateDrawEvent(); |
1002 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); | 1015 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); |
1003 | 1016 |
1004 // Now, make three more refresh frame requests. Although the source has | 1017 // Now, make three more refresh frame requests. Although the source has |
1005 // changed to BLUE, no draw event has occurred. Therefore, expect the refresh | 1018 // changed to BLUE, no draw event has occurred. Therefore, expect the refresh |
1006 // frames to contain the content from the last drawn frame, which is GREEN. | 1019 // frames to contain the content from the last drawn frame, which is GREEN. |
1007 test_view()->SetSolidColor(SK_ColorBLUE); | 1020 test_view()->SetSolidColor(SK_ColorBLUE); |
1008 for (int i = 0; i < 3; ++i) { | 1021 for (int i = 0; i < 3; ++i) { |
1009 SimulateRefreshFrameRequest(); | 1022 SimulateRefreshFrameRequest(); |
1010 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); | 1023 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); |
1011 } | 1024 } |
1012 | 1025 |
1013 device()->StopAndDeAllocate(); | 1026 device()->StopAndDeAllocate(); |
1014 } | 1027 } |
1015 | 1028 |
1016 } // namespace | 1029 } // namespace |
1017 } // namespace content | 1030 } // namespace content |
OLD | NEW |