Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(651)

Side by Side Diff: content/browser/media/capture/web_contents_video_capture_device_unittest.cc

Issue 1865283003: Revert of Tab/Desktop Capture: Use requests instead of timer-based refreshing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@video_refresh_from_sinks
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/debug/debugger.h" 12 #include "base/debug/debugger.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/run_loop.h" 14 #include "base/run_loop.h"
15 #include "base/test/test_timeouts.h" 15 #include "base/test/test_timeouts.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "base/timer/timer.h" 17 #include "base/timer/timer.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 #include "content/browser/browser_thread_impl.h" 19 #include "content/browser/browser_thread_impl.h"
20 #include "content/browser/frame_host/render_frame_host_impl.h" 20 #include "content/browser/frame_host/render_frame_host_impl.h"
21 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" 21 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h"
22 #include "content/browser/renderer_host/render_view_host_factory.h" 22 #include "content/browser/renderer_host/render_view_host_factory.h"
23 #include "content/browser/renderer_host/render_widget_host_impl.h" 23 #include "content/browser/renderer_host/render_widget_host_impl.h"
24 #include "content/browser/web_contents/web_contents_impl.h" 24 #include "content/browser/web_contents/web_contents_impl.h"
25 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/notification_types.h"
25 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" 27 #include "content/public/browser/render_widget_host_view_frame_subscriber.h"
26 #include "content/public/browser/web_contents_media_capture_id.h" 28 #include "content/public/browser/web_contents_media_capture_id.h"
27 #include "content/public/test/mock_render_process_host.h" 29 #include "content/public/test/mock_render_process_host.h"
28 #include "content/public/test/test_browser_context.h" 30 #include "content/public/test/test_browser_context.h"
29 #include "content/public/test/test_browser_thread_bundle.h" 31 #include "content/public/test/test_browser_thread_bundle.h"
30 #include "content/public/test/test_utils.h" 32 #include "content/public/test/test_utils.h"
31 #include "content/test/test_render_frame_host_factory.h" 33 #include "content/test/test_render_frame_host_factory.h"
32 #include "content/test/test_render_view_host.h" 34 #include "content/test/test_render_view_host.h"
33 #include "content/test/test_web_contents.h" 35 #include "content/test/test_web_contents.h"
34 #include "media/base/video_capture_types.h" 36 #include "media/base/video_capture_types.h"
(...skipping 16 matching lines...) Expand all
51 53
52 const int kTestWidth = 320; 54 const int kTestWidth = 320;
53 const int kTestHeight = 240; 55 const int kTestHeight = 240;
54 const int kTestFramesPerSecond = 20; 56 const int kTestFramesPerSecond = 20;
55 const float kTestDeviceScaleFactor = 2.0f; 57 const float kTestDeviceScaleFactor = 2.0f;
56 const SkColor kNothingYet = 0xdeadbeef; 58 const SkColor kNothingYet = 0xdeadbeef;
57 const SkColor kNotInterested = ~kNothingYet; 59 const SkColor kNotInterested = ~kNothingYet;
58 60
59 void DeadlineExceeded(base::Closure quit_closure) { 61 void DeadlineExceeded(base::Closure quit_closure) {
60 if (!base::debug::BeingDebugged()) { 62 if (!base::debug::BeingDebugged()) {
61 if (!quit_closure.is_null()) 63 quit_closure.Run();
62 quit_closure.Run();
63 FAIL() << "Deadline exceeded while waiting, quitting"; 64 FAIL() << "Deadline exceeded while waiting, quitting";
64 } else { 65 } else {
65 LOG(WARNING) << "Deadline exceeded; test would fail if debugger weren't " 66 LOG(WARNING) << "Deadline exceeded; test would fail if debugger weren't "
66 << "attached."; 67 << "attached.";
67 } 68 }
68 } 69 }
69 70
70 void RunCurrentLoopWithDeadline() { 71 void RunCurrentLoopWithDeadline() {
71 base::Timer deadline(false, false); 72 base::Timer deadline(false, false);
72 deadline.Start( 73 deadline.Start(
(...skipping 13 matching lines...) Expand all
86 87
87 // Thread-safe class that controls the source pattern to be captured by the 88 // Thread-safe class that controls the source pattern to be captured by the
88 // system under test. The lifetime of this class is greater than the lifetime 89 // system under test. The lifetime of this class is greater than the lifetime
89 // of all objects that reference it, so it does not need to be reference 90 // of all objects that reference it, so it does not need to be reference
90 // counted. 91 // counted.
91 class CaptureTestSourceController { 92 class CaptureTestSourceController {
92 public: 93 public:
93 CaptureTestSourceController() 94 CaptureTestSourceController()
94 : color_(SK_ColorMAGENTA), 95 : color_(SK_ColorMAGENTA),
95 copy_result_size_(kTestWidth, kTestHeight), 96 copy_result_size_(kTestWidth, kTestHeight),
96 can_copy_to_video_frame_(true) {} 97 can_copy_to_video_frame_(false),
98 use_frame_subscriber_(false) {}
97 99
98 void SetSolidColor(SkColor color) { 100 void SetSolidColor(SkColor color) {
99 base::AutoLock guard(lock_); 101 base::AutoLock guard(lock_);
100 color_ = color; 102 color_ = color;
101 } 103 }
102 104
103 SkColor GetSolidColor() { 105 SkColor GetSolidColor() {
104 base::AutoLock guard(lock_); 106 base::AutoLock guard(lock_);
105 return color_; 107 return color_;
106 } 108 }
(...skipping 20 matching lines...) Expand all
127 void SetCanCopyToVideoFrame(bool value) { 129 void SetCanCopyToVideoFrame(bool value) {
128 base::AutoLock guard(lock_); 130 base::AutoLock guard(lock_);
129 can_copy_to_video_frame_ = value; 131 can_copy_to_video_frame_ = value;
130 } 132 }
131 133
132 bool CanCopyToVideoFrame() { 134 bool CanCopyToVideoFrame() {
133 base::AutoLock guard(lock_); 135 base::AutoLock guard(lock_);
134 return can_copy_to_video_frame_; 136 return can_copy_to_video_frame_;
135 } 137 }
136 138
139 void SetUseFrameSubscriber(bool value) {
140 base::AutoLock guard(lock_);
141 use_frame_subscriber_ = value;
142 }
143
144 bool CanUseFrameSubscriber() {
145 base::AutoLock guard(lock_);
146 return use_frame_subscriber_;
147 }
148
137 void WaitForNextCopy() { 149 void WaitForNextCopy() {
138 { 150 {
139 base::AutoLock guard(lock_); 151 base::AutoLock guard(lock_);
140 copy_done_ = base::MessageLoop::current()->QuitWhenIdleClosure(); 152 copy_done_ = base::MessageLoop::current()->QuitWhenIdleClosure();
141 } 153 }
142 154
143 RunCurrentLoopWithDeadline(); 155 RunCurrentLoopWithDeadline();
144 } 156 }
145 157
146 private: 158 private:
147 base::Lock lock_; // Guards changes to all members. 159 base::Lock lock_; // Guards changes to all members.
148 SkColor color_; 160 SkColor color_;
149 gfx::Size copy_result_size_; 161 gfx::Size copy_result_size_;
150 bool can_copy_to_video_frame_; 162 bool can_copy_to_video_frame_;
163 bool use_frame_subscriber_;
151 base::Closure copy_done_; 164 base::Closure copy_done_;
152 165
153 DISALLOW_COPY_AND_ASSIGN(CaptureTestSourceController); 166 DISALLOW_COPY_AND_ASSIGN(CaptureTestSourceController);
154 }; 167 };
155 168
156 // A stub implementation which returns solid-color bitmaps in calls to 169 // A stub implementation which returns solid-color bitmaps in calls to
157 // CopyFromCompositingSurfaceToVideoFrame(), and which allows the video-frame 170 // CopyFromCompositingSurfaceToVideoFrame(), and which allows the video-frame
158 // readback path to be switched on and off. The behavior is controlled by a 171 // readback path to be switched on and off. The behavior is controlled by a
159 // CaptureTestSourceController. 172 // CaptureTestSourceController.
160 class CaptureTestView : public TestRenderWidgetHostView { 173 class CaptureTestView : public TestRenderWidgetHostView {
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 base::Callback<void(SkColor, const gfx::Size&)> report_callback_; 480 base::Callback<void(SkColor, const gfx::Size&)> report_callback_;
468 base::Closure error_callback_; 481 base::Closure error_callback_;
469 482
470 DISALLOW_COPY_AND_ASSIGN(StubClient); 483 DISALLOW_COPY_AND_ASSIGN(StubClient);
471 }; 484 };
472 485
473 class StubClientObserver { 486 class StubClientObserver {
474 public: 487 public:
475 StubClientObserver() 488 StubClientObserver()
476 : error_encountered_(false), 489 : error_encountered_(false),
477 wait_color_yuv_(0xcafe1950) { 490 wait_color_yuv_(0xcafe1950),
491 wait_size_(kTestWidth, kTestHeight) {
478 client_.reset(new StubClient( 492 client_.reset(new StubClient(
479 base::Bind(&StubClientObserver::DidDeliverFrame, 493 base::Bind(&StubClientObserver::DidDeliverFrame,
480 base::Unretained(this)), 494 base::Unretained(this)),
481 base::Bind(&StubClientObserver::OnError, base::Unretained(this)))); 495 base::Bind(&StubClientObserver::OnError, base::Unretained(this))));
482 } 496 }
483 497
484 virtual ~StubClientObserver() {} 498 virtual ~StubClientObserver() {}
485 499
486 scoped_ptr<media::VideoCaptureDevice::Client> PassClient() { 500 scoped_ptr<media::VideoCaptureDevice::Client> PassClient() {
487 return std::move(client_); 501 return std::move(client_);
488 } 502 }
489 503
490 void QuitIfConditionsMet(SkColor color, const gfx::Size& size) { 504 void QuitIfConditionsMet(SkColor color, const gfx::Size& size) {
491 base::AutoLock guard(lock_); 505 base::AutoLock guard(lock_);
492 if (error_encountered_ || wait_color_yuv_ == kNotInterested || 506 if (error_encountered_)
493 wait_color_yuv_ == color) {
494 last_frame_color_yuv_ = color;
495 last_frame_size_ = size;
496 base::MessageLoop::current()->QuitWhenIdle(); 507 base::MessageLoop::current()->QuitWhenIdle();
497 } 508 else if (wait_color_yuv_ == color && wait_size_.IsEmpty())
509 base::MessageLoop::current()->QuitWhenIdle();
510 else if (wait_color_yuv_ == color && wait_size_ == size)
511 base::MessageLoop::current()->QuitWhenIdle();
498 } 512 }
499 513
500 // Run the current loop until the next frame is delivered. Returns the YUV 514 // Run the current loop until a frame is delivered with the |expected_color|
501 // color and frame size. 515 // and any non-empty frame size.
502 std::pair<SkColor, gfx::Size> WaitForNextFrame() { 516 void WaitForNextColor(SkColor expected_color) {
517 WaitForNextColorAndFrameSize(expected_color, gfx::Size());
518 }
519
520 // Run the current loop until a frame is delivered with the |expected_color|
521 // and is of the |expected_size|.
522 void WaitForNextColorAndFrameSize(SkColor expected_color,
523 const gfx::Size& expected_size) {
503 { 524 {
504 base::AutoLock guard(lock_); 525 base::AutoLock guard(lock_);
505 wait_color_yuv_ = kNotInterested; 526 wait_color_yuv_ = ConvertRgbToYuv(expected_color);
527 wait_size_ = expected_size;
506 error_encountered_ = false; 528 error_encountered_ = false;
507 } 529 }
508 RunCurrentLoopWithDeadline(); 530 RunCurrentLoopWithDeadline();
509 {
510 base::AutoLock guard(lock_);
511 CHECK(!error_encountered_);
512 return std::make_pair(last_frame_color_yuv_, last_frame_size_);
513 }
514 }
515
516 // Run the current loop until a frame is delivered with the |expected_color|.
517 void WaitForNextColor(SkColor expected_color) {
518 {
519 base::AutoLock guard(lock_);
520 wait_color_yuv_ = ConvertRgbToYuv(expected_color);
521 error_encountered_ = false;
522 }
523 RunCurrentLoopWithDeadline();
524 { 531 {
525 base::AutoLock guard(lock_); 532 base::AutoLock guard(lock_);
526 ASSERT_FALSE(error_encountered_); 533 ASSERT_FALSE(error_encountered_);
527 } 534 }
528 } 535 }
529 536
530 void WaitForError() { 537 void WaitForError() {
531 { 538 {
532 base::AutoLock guard(lock_); 539 base::AutoLock guard(lock_);
533 wait_color_yuv_ = kNotInterested; 540 wait_color_yuv_ = kNotInterested;
541 wait_size_ = gfx::Size();
534 error_encountered_ = false; 542 error_encountered_ = false;
535 } 543 }
536 RunCurrentLoopWithDeadline(); 544 RunCurrentLoopWithDeadline();
537 { 545 {
538 base::AutoLock guard(lock_); 546 base::AutoLock guard(lock_);
539 ASSERT_TRUE(error_encountered_); 547 ASSERT_TRUE(error_encountered_);
540 } 548 }
541 } 549 }
542 550
543 bool HasError() { 551 bool HasError() {
(...skipping 18 matching lines...) Expand all
562 &StubClientObserver::QuitIfConditionsMet, 570 &StubClientObserver::QuitIfConditionsMet,
563 base::Unretained(this), 571 base::Unretained(this),
564 color, 572 color,
565 size)); 573 size));
566 } 574 }
567 575
568 private: 576 private:
569 base::Lock lock_; 577 base::Lock lock_;
570 bool error_encountered_; 578 bool error_encountered_;
571 SkColor wait_color_yuv_; 579 SkColor wait_color_yuv_;
572 SkColor last_frame_color_yuv_; 580 gfx::Size wait_size_;
573 gfx::Size last_frame_size_;
574 scoped_ptr<StubClient> client_; 581 scoped_ptr<StubClient> client_;
575 582
576 DISALLOW_COPY_AND_ASSIGN(StubClientObserver); 583 DISALLOW_COPY_AND_ASSIGN(StubClientObserver);
577 }; 584 };
578 585
579 // crbug.com/159234 586 // crbug.com/159234
580 #if defined(OS_ANDROID) 587 #if defined(OS_ANDROID)
581 #define MAYBE_WebContentsVideoCaptureDeviceTest \ 588 #define MAYBE_WebContentsVideoCaptureDeviceTest \
582 DISABLED_WebContentsVideoCaptureDeviceTest 589 DISABLED_WebContentsVideoCaptureDeviceTest
583 #else 590 #else
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 // ignored on Mac platforms (when determining the device scale factor for a 679 // ignored on Mac platforms (when determining the device scale factor for a
673 // particular window). 680 // particular window).
674 float GetDeviceScaleFactor() const { 681 float GetDeviceScaleFactor() const {
675 RenderWidgetHostView* const view = 682 RenderWidgetHostView* const view =
676 web_contents_->GetRenderViewHost()->GetWidget()->GetView(); 683 web_contents_->GetRenderViewHost()->GetWidget()->GetView();
677 CHECK(view); 684 CHECK(view);
678 return ui::GetScaleFactorForNativeView(view->GetNativeView()); 685 return ui::GetScaleFactorForNativeView(view->GetNativeView());
679 } 686 }
680 687
681 void SimulateDrawEvent() { 688 void SimulateDrawEvent() {
682 DCHECK_CURRENTLY_ON(BrowserThread::UI); 689 if (source()->CanUseFrameSubscriber()) {
683 690 // Print
684 // Force at least one frame period's worth of time to pass. Otherwise, 691 CaptureTestView* test_view = static_cast<CaptureTestView*>(
685 // internal logic may decide not to capture a frame because the draw events 692 web_contents_->GetRenderViewHost()->GetWidget()->GetView());
686 // are more frequent that kTestFramesPerSecond. 693 test_view->SimulateUpdate();
687 // 694 } else {
688 // TODO(miu): Instead of physically waiting, we should inject simulated 695 // Simulate a non-accelerated paint.
689 // clocks for testing. 696 NotificationService::current()->Notify(
690 base::RunLoop run_loop; 697 NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE,
691 BrowserThread::PostDelayedTask( 698 Source<RenderWidgetHost>(
692 BrowserThread::UI, FROM_HERE, 699 web_contents_->GetRenderViewHost()->GetWidget()),
693 run_loop.QuitClosure(), 700 NotificationService::NoDetails());
694 base::TimeDelta::FromMicroseconds( 701 }
695 base::Time::kMicrosecondsPerSecond / kTestFramesPerSecond));
696 run_loop.Run();
697
698 // Schedule the update to occur when the test runs the event loop (and not
699 // before expectations have been set).
700 CaptureTestView* test_view = static_cast<CaptureTestView*>(
701 web_contents_->GetRenderViewHost()->GetWidget()->GetView());
702 BrowserThread::PostTask(
703 BrowserThread::UI, FROM_HERE,
704 base::Bind(&CaptureTestView::SimulateUpdate,
705 base::Unretained(test_view)));
706 } 702 }
707 703
708 void SimulateSourceSizeChange(const gfx::Size& size) { 704 void SimulateSourceSizeChange(const gfx::Size& size) {
709 DCHECK_CURRENTLY_ON(BrowserThread::UI); 705 DCHECK_CURRENTLY_ON(BrowserThread::UI);
710 CaptureTestView* test_view = static_cast<CaptureTestView*>( 706 CaptureTestView* test_view = static_cast<CaptureTestView*>(
711 web_contents_->GetRenderViewHost()->GetWidget()->GetView()); 707 web_contents_->GetRenderViewHost()->GetWidget()->GetView());
712 test_view->SetSize(size); 708 test_view->SetSize(size);
713 // Normally, RenderWidgetHostImpl would notify WebContentsImpl that the size 709 // Normally, RenderWidgetHostImpl would notify WebContentsImpl that the size
714 // has changed. However, in this test setup where there is no render 710 // has changed. However, in this test setup where there is no render
715 // process, we must notify WebContentsImpl directly. 711 // process, we must notify WebContentsImpl directly.
716 WebContentsImpl* const as_web_contents_impl = 712 WebContentsImpl* const as_web_contents_impl =
717 static_cast<WebContentsImpl*>(web_contents_.get()); 713 static_cast<WebContentsImpl*>(web_contents_.get());
718 RenderWidgetHostDelegate* const as_rwh_delegate = 714 RenderWidgetHostDelegate* const as_rwh_delegate =
719 static_cast<RenderWidgetHostDelegate*>(as_web_contents_impl); 715 static_cast<RenderWidgetHostDelegate*>(as_web_contents_impl);
720 as_rwh_delegate->RenderWidgetWasResized( 716 as_rwh_delegate->RenderWidgetWasResized(
721 as_web_contents_impl->GetMainFrame()->GetRenderWidgetHost(), true); 717 as_web_contents_impl->GetMainFrame()->GetRenderWidgetHost(), true);
722 } 718 }
723 719
724 // Repeatedly schedules draw events and scans for frames until the output from
725 // the capture device matches the given RGB |color| and frame |size|.
726 void SimulateDrawsUntilNewFrameSizeArrives(SkColor color,
727 const gfx::Size& size) {
728 const base::TimeTicks start_time = base::TimeTicks::Now();
729 while ((base::TimeTicks::Now() - start_time) <
730 TestTimeouts::action_max_timeout()) {
731 SimulateDrawEvent();
732 const auto color_and_size = client_observer()->WaitForNextFrame();
733 if (color_and_size.first == ConvertRgbToYuv(color) &&
734 color_and_size.second == size) {
735 return;
736 }
737 }
738 DeadlineExceeded(base::Closure());
739 }
740
741 void SimulateRefreshFrameRequest() {
742 // Force at least three frame period's worth of time to pass. The wait is
743 // needed because refresh frame requests are only honored when drawing
744 // events, which trigger frame captures, are not occurring frequently
745 // enough.
746 //
747 // TODO(miu): Instead of physically waiting, we should inject simulated
748 // clocks for testing.
749 base::RunLoop run_loop;
750 BrowserThread::PostDelayedTask(
751 BrowserThread::UI, FROM_HERE,
752 run_loop.QuitClosure(),
753 base::TimeDelta::FromMicroseconds(
754 3 * base::Time::kMicrosecondsPerSecond / kTestFramesPerSecond));
755 run_loop.Run();
756
757 BrowserThread::PostTask(
758 BrowserThread::UI, FROM_HERE,
759 base::Bind(&media::VideoCaptureDevice::RequestRefreshFrame,
760 base::Unretained(device_.get())));
761 }
762
763 void DestroyVideoCaptureDevice() { device_.reset(); } 720 void DestroyVideoCaptureDevice() { device_.reset(); }
764 721
765 StubClientObserver* client_observer() { 722 StubClientObserver* client_observer() {
766 return &client_observer_; 723 return &client_observer_;
767 } 724 }
768 725
769 private: 726 private:
770 gfx::test::TestScreen test_screen_; 727 gfx::test::TestScreen test_screen_;
771 728
772 StubClientObserver client_observer_; 729 StubClientObserver client_observer_;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 static_cast<int>(kTestHeight / device_scale_factor)); 774 static_cast<int>(kTestHeight / device_scale_factor));
818 ASSERT_NE(capture_preferred_size, web_contents()->GetPreferredSize()); 775 ASSERT_NE(capture_preferred_size, web_contents()->GetPreferredSize());
819 776
820 // We'll simulate the tab being closed after the capture pipeline is up and 777 // We'll simulate the tab being closed after the capture pipeline is up and
821 // running. 778 // running.
822 media::VideoCaptureParams capture_params; 779 media::VideoCaptureParams capture_params;
823 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); 780 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight);
824 capture_params.requested_format.frame_rate = kTestFramesPerSecond; 781 capture_params.requested_format.frame_rate = kTestFramesPerSecond;
825 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 782 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
826 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); 783 device()->AllocateAndStart(capture_params, client_observer()->PassClient());
827 784 // Do one capture to prove
828 // Do one capture to prove the tab is initially open and being captured
829 // normally.
830 source()->SetSolidColor(SK_ColorRED); 785 source()->SetSolidColor(SK_ColorRED);
831 SimulateDrawEvent(); 786 SimulateDrawEvent();
832 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); 787 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED));
833 788
834 base::RunLoop().RunUntilIdle(); 789 base::RunLoop().RunUntilIdle();
835 790
836 // Check that the preferred size of the WebContents matches the one provided 791 // Check that the preferred size of the WebContents matches the one provided
837 // by WebContentsVideoCaptureDevice. 792 // by WebContentsVideoCaptureDevice.
838 EXPECT_EQ(capture_preferred_size, web_contents()->GetPreferredSize()); 793 EXPECT_EQ(capture_preferred_size, web_contents()->GetPreferredSize());
839 794
(...skipping 19 matching lines...) Expand all
859 DestroyVideoCaptureDevice(); 814 DestroyVideoCaptureDevice();
860 815
861 // Currently, there should be CreateCaptureMachineOnUIThread() and 816 // Currently, there should be CreateCaptureMachineOnUIThread() and
862 // DestroyCaptureMachineOnUIThread() tasks pending on the current (UI) message 817 // DestroyCaptureMachineOnUIThread() tasks pending on the current (UI) message
863 // loop. These should both succeed without crashing, and the machine should 818 // loop. These should both succeed without crashing, and the machine should
864 // wind up in the idle state. 819 // wind up in the idle state.
865 base::RunLoop().RunUntilIdle(); 820 base::RunLoop().RunUntilIdle();
866 } 821 }
867 822
868 TEST_F(MAYBE_WebContentsVideoCaptureDeviceTest, StopWithRendererWorkToDo) { 823 TEST_F(MAYBE_WebContentsVideoCaptureDeviceTest, StopWithRendererWorkToDo) {
869 // Set up the test to use RGB captures into SkBitmaps instead of YUV captures 824 // Set up the test to use RGB copies and an normal
870 // into VideoFrames.
871 source()->SetCanCopyToVideoFrame(false); 825 source()->SetCanCopyToVideoFrame(false);
826 source()->SetUseFrameSubscriber(false);
872 media::VideoCaptureParams capture_params; 827 media::VideoCaptureParams capture_params;
873 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); 828 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight);
874 capture_params.requested_format.frame_rate = kTestFramesPerSecond; 829 capture_params.requested_format.frame_rate = kTestFramesPerSecond;
875 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 830 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
876 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); 831 device()->AllocateAndStart(capture_params, client_observer()->PassClient());
877 832
878 base::RunLoop().RunUntilIdle(); 833 base::RunLoop().RunUntilIdle();
879 834
880 for (int i = 0; i < 3; ++i) 835 for (int i = 0; i < 10; ++i)
881 SimulateDrawEvent(); 836 SimulateDrawEvent();
882 837
883 ASSERT_FALSE(client_observer()->HasError()); 838 ASSERT_FALSE(client_observer()->HasError());
884 device()->StopAndDeAllocate(); 839 device()->StopAndDeAllocate();
885 ASSERT_FALSE(client_observer()->HasError()); 840 ASSERT_FALSE(client_observer()->HasError());
886 base::RunLoop().RunUntilIdle(); 841 base::RunLoop().RunUntilIdle();
887 ASSERT_FALSE(client_observer()->HasError()); 842 ASSERT_FALSE(client_observer()->HasError());
888 } 843 }
889 844
890 TEST_F(MAYBE_WebContentsVideoCaptureDeviceTest, DeviceRestart) { 845 TEST_F(MAYBE_WebContentsVideoCaptureDeviceTest, DeviceRestart) {
(...skipping 25 matching lines...) Expand all
916 SimulateDrawEvent(); 871 SimulateDrawEvent();
917 ASSERT_NO_FATAL_FAILURE(observer2.WaitForNextColor(SK_ColorBLUE)); 872 ASSERT_NO_FATAL_FAILURE(observer2.WaitForNextColor(SK_ColorBLUE));
918 source()->SetSolidColor(SK_ColorYELLOW); 873 source()->SetSolidColor(SK_ColorYELLOW);
919 SimulateDrawEvent(); 874 SimulateDrawEvent();
920 ASSERT_NO_FATAL_FAILURE(observer2.WaitForNextColor(SK_ColorYELLOW)); 875 ASSERT_NO_FATAL_FAILURE(observer2.WaitForNextColor(SK_ColorYELLOW));
921 device()->StopAndDeAllocate(); 876 device()->StopAndDeAllocate();
922 } 877 }
923 878
924 // The "happy case" test. No scaling is needed, so we should be able to change 879 // The "happy case" test. No scaling is needed, so we should be able to change
925 // the picture emitted from the source and expect to see each delivered to the 880 // the picture emitted from the source and expect to see each delivered to the
926 // consumer. The test will alternate between the RGB/SkBitmap and YUV/VideoFrame 881 // consumer. The test will alternate between the three capture paths, simulating
927 // capture paths. 882 // falling in and out of accelerated compositing.
928 TEST_F(MAYBE_WebContentsVideoCaptureDeviceTest, GoesThroughAllTheMotions) { 883 TEST_F(MAYBE_WebContentsVideoCaptureDeviceTest, GoesThroughAllTheMotions) {
929 media::VideoCaptureParams capture_params; 884 media::VideoCaptureParams capture_params;
930 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); 885 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight);
931 capture_params.requested_format.frame_rate = kTestFramesPerSecond; 886 capture_params.requested_format.frame_rate = kTestFramesPerSecond;
932 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 887 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
933 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); 888 device()->AllocateAndStart(capture_params, client_observer()->PassClient());
934 889
935 for (int i = 0; i < 4; i++) { 890 for (int i = 0; i < 6; i++) {
936 const char* name = NULL; 891 const char* name = NULL;
937 if (i % 2) { 892 switch (i % 3) {
938 source()->SetCanCopyToVideoFrame(false); 893 case 0:
939 name = "SkBitmap"; 894 source()->SetCanCopyToVideoFrame(true);
940 } else { 895 source()->SetUseFrameSubscriber(false);
941 source()->SetCanCopyToVideoFrame(true); 896 name = "VideoFrame";
942 name = "VideoFrame"; 897 break;
898 case 1:
899 source()->SetCanCopyToVideoFrame(false);
900 source()->SetUseFrameSubscriber(true);
901 name = "Subscriber";
902 break;
903 case 2:
904 source()->SetCanCopyToVideoFrame(false);
905 source()->SetUseFrameSubscriber(false);
906 name = "SkBitmap";
907 break;
908 default:
909 FAIL();
943 } 910 }
944 911
945 SCOPED_TRACE(base::StringPrintf("Using %s path, iteration #%d", name, i)); 912 SCOPED_TRACE(base::StringPrintf("Using %s path, iteration #%d", name, i));
946 913
947 source()->SetSolidColor(SK_ColorRED); 914 source()->SetSolidColor(SK_ColorRED);
948 SimulateDrawEvent(); 915 SimulateDrawEvent();
949 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); 916 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED));
950 917
951 source()->SetSolidColor(SK_ColorGREEN); 918 source()->SetSolidColor(SK_ColorGREEN);
952 SimulateDrawEvent(); 919 SimulateDrawEvent();
(...skipping 15 matching lines...) Expand all
968 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); 935 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight);
969 capture_params.requested_format.frame_rate = kTestFramesPerSecond; 936 capture_params.requested_format.frame_rate = kTestFramesPerSecond;
970 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 937 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
971 // 1x1 is too small to process; we intend for this to result in an error. 938 // 1x1 is too small to process; we intend for this to result in an error.
972 source()->SetCopyResultSize(1, 1); 939 source()->SetCopyResultSize(1, 1);
973 source()->SetSolidColor(SK_ColorRED); 940 source()->SetSolidColor(SK_ColorRED);
974 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); 941 device()->AllocateAndStart(capture_params, client_observer()->PassClient());
975 942
976 // These frames ought to be dropped during the Render stage. Let 943 // These frames ought to be dropped during the Render stage. Let
977 // several captures to happen. 944 // several captures to happen.
978 for (int i = 0; i < 3; ++i) { 945 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy());
979 SimulateDrawEvent(); 946 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy());
980 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy()); 947 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy());
981 } 948 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy());
949 ASSERT_NO_FATAL_FAILURE(source()->WaitForNextCopy());
982 950
983 // Now push some good frames through; they should be processed normally. 951 // Now push some good frames through; they should be processed normally.
984 source()->SetCopyResultSize(kTestWidth, kTestHeight); 952 source()->SetCopyResultSize(kTestWidth, kTestHeight);
985 source()->SetSolidColor(SK_ColorGREEN); 953 source()->SetSolidColor(SK_ColorGREEN);
986 SimulateDrawEvent();
987 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); 954 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN));
988 source()->SetSolidColor(SK_ColorRED); 955 source()->SetSolidColor(SK_ColorRED);
989 SimulateDrawEvent();
990 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED)); 956 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED));
991 957
992 device()->StopAndDeAllocate(); 958 device()->StopAndDeAllocate();
993 } 959 }
994 960
995 // Tests that, when configured with the FIXED_ASPECT_RATIO resolution change 961 // Tests that, when configured with the FIXED_ASPECT_RATIO resolution change
996 // policy, the source size changes result in video frames of possibly varying 962 // policy, the source size changes result in video frames of possibly varying
997 // resolutions, but all with the same aspect ratio. 963 // resolutions, but all with the same aspect ratio.
998 TEST_F(MAYBE_WebContentsVideoCaptureDeviceTest, 964 TEST_F(MAYBE_WebContentsVideoCaptureDeviceTest,
999 VariableResolution_FixedAspectRatio) { 965 VariableResolution_FixedAspectRatio) {
1000 media::VideoCaptureParams capture_params; 966 media::VideoCaptureParams capture_params;
1001 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); 967 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight);
1002 capture_params.requested_format.frame_rate = kTestFramesPerSecond; 968 capture_params.requested_format.frame_rate = kTestFramesPerSecond;
1003 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 969 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
1004 capture_params.resolution_change_policy = 970 capture_params.resolution_change_policy =
1005 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO; 971 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO;
1006 972
1007 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); 973 device()->AllocateAndStart(capture_params, client_observer()->PassClient());
1008 974
975 source()->SetUseFrameSubscriber(true);
976
1009 // Source size equals maximum size. Expect delivered frames to be 977 // Source size equals maximum size. Expect delivered frames to be
1010 // kTestWidth by kTestHeight. 978 // kTestWidth by kTestHeight.
1011 source()->SetSolidColor(SK_ColorRED); 979 source()->SetSolidColor(SK_ColorRED);
1012 const float device_scale_factor = GetDeviceScaleFactor(); 980 const float device_scale_factor = GetDeviceScaleFactor();
1013 SimulateSourceSizeChange(gfx::ConvertSizeToDIP( 981 SimulateSourceSizeChange(gfx::ConvertSizeToDIP(
1014 device_scale_factor, gfx::Size(kTestWidth, kTestHeight))); 982 device_scale_factor, gfx::Size(kTestWidth, kTestHeight)));
1015 SimulateDrawsUntilNewFrameSizeArrives( 983 SimulateDrawEvent();
1016 SK_ColorRED, gfx::Size(kTestWidth, kTestHeight)); 984 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColorAndFrameSize(
985 SK_ColorRED, gfx::Size(kTestWidth, kTestHeight)));
1017 986
1018 // Source size is half in both dimensions. Expect delivered frames to be of 987 // Source size is half in both dimensions. Expect delivered frames to be of
1019 // the same aspect ratio as kTestWidth by kTestHeight, but larger than the 988 // the same aspect ratio as kTestWidth by kTestHeight, but larger than the
1020 // half size because the minimum height is 180 lines. 989 // half size because the minimum height is 180 lines.
1021 source()->SetSolidColor(SK_ColorGREEN); 990 source()->SetSolidColor(SK_ColorGREEN);
1022 SimulateSourceSizeChange(gfx::ConvertSizeToDIP( 991 SimulateSourceSizeChange(gfx::ConvertSizeToDIP(
1023 device_scale_factor, gfx::Size(kTestWidth / 2, kTestHeight / 2))); 992 device_scale_factor, gfx::Size(kTestWidth / 2, kTestHeight / 2)));
1024 SimulateDrawsUntilNewFrameSizeArrives( 993 SimulateDrawEvent();
1025 SK_ColorGREEN, gfx::Size(180 * kTestWidth / kTestHeight, 180)); 994 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColorAndFrameSize(
995 SK_ColorGREEN, gfx::Size(180 * kTestWidth / kTestHeight, 180)));
1026 996
1027 // Source size changes aspect ratio. Expect delivered frames to be padded 997 // Source size changes aspect ratio. Expect delivered frames to be padded
1028 // in the horizontal dimension to preserve aspect ratio. 998 // in the horizontal dimension to preserve aspect ratio.
1029 source()->SetSolidColor(SK_ColorBLUE); 999 source()->SetSolidColor(SK_ColorBLUE);
1030 SimulateSourceSizeChange(gfx::ConvertSizeToDIP( 1000 SimulateSourceSizeChange(gfx::ConvertSizeToDIP(
1031 device_scale_factor, gfx::Size(kTestWidth / 2, kTestHeight))); 1001 device_scale_factor, gfx::Size(kTestWidth / 2, kTestHeight)));
1032 SimulateDrawsUntilNewFrameSizeArrives( 1002 SimulateDrawEvent();
1033 SK_ColorBLUE, gfx::Size(kTestWidth, kTestHeight)); 1003 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColorAndFrameSize(
1004 SK_ColorBLUE, gfx::Size(kTestWidth, kTestHeight)));
1034 1005
1035 // Source size changes aspect ratio again. Expect delivered frames to be 1006 // Source size changes aspect ratio again. Expect delivered frames to be
1036 // padded in the vertical dimension to preserve aspect ratio. 1007 // padded in the vertical dimension to preserve aspect ratio.
1037 source()->SetSolidColor(SK_ColorBLACK); 1008 source()->SetSolidColor(SK_ColorBLACK);
1038 SimulateSourceSizeChange(gfx::ConvertSizeToDIP( 1009 SimulateSourceSizeChange(gfx::ConvertSizeToDIP(
1039 device_scale_factor, gfx::Size(kTestWidth, kTestHeight / 2))); 1010 device_scale_factor, gfx::Size(kTestWidth, kTestHeight / 2)));
1040 SimulateDrawsUntilNewFrameSizeArrives( 1011 SimulateDrawEvent();
1041 SK_ColorBLACK, gfx::Size(kTestWidth, kTestHeight)); 1012 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColorAndFrameSize(
1013 SK_ColorBLACK, gfx::Size(kTestWidth, kTestHeight)));
1042 1014
1043 device()->StopAndDeAllocate(); 1015 device()->StopAndDeAllocate();
1044 } 1016 }
1045 1017
1046 // Tests that, when configured with the ANY_WITHIN_LIMIT resolution change 1018 // Tests that, when configured with the ANY_WITHIN_LIMIT resolution change
1047 // policy, the source size changes result in video frames of possibly varying 1019 // policy, the source size changes result in video frames of possibly varying
1048 // resolutions. 1020 // resolutions.
1049 TEST_F(MAYBE_WebContentsVideoCaptureDeviceTest, 1021 TEST_F(MAYBE_WebContentsVideoCaptureDeviceTest,
1050 VariableResolution_AnyWithinLimits) { 1022 VariableResolution_AnyWithinLimits) {
1051 media::VideoCaptureParams capture_params; 1023 media::VideoCaptureParams capture_params;
1052 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); 1024 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight);
1053 capture_params.requested_format.frame_rate = kTestFramesPerSecond; 1025 capture_params.requested_format.frame_rate = kTestFramesPerSecond;
1054 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 1026 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
1055 capture_params.resolution_change_policy = 1027 capture_params.resolution_change_policy =
1056 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT; 1028 media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT;
1057 1029
1058 device()->AllocateAndStart(capture_params, client_observer()->PassClient()); 1030 device()->AllocateAndStart(capture_params, client_observer()->PassClient());
1059 1031
1032 source()->SetUseFrameSubscriber(true);
1033
1060 // Source size equals maximum size. Expect delivered frames to be 1034 // Source size equals maximum size. Expect delivered frames to be
1061 // kTestWidth by kTestHeight. 1035 // kTestWidth by kTestHeight.
1062 source()->SetSolidColor(SK_ColorRED); 1036 source()->SetSolidColor(SK_ColorRED);
1063 const float device_scale_factor = GetDeviceScaleFactor(); 1037 const float device_scale_factor = GetDeviceScaleFactor();
1064 SimulateSourceSizeChange(gfx::ConvertSizeToDIP( 1038 SimulateSourceSizeChange(gfx::ConvertSizeToDIP(
1065 device_scale_factor, gfx::Size(kTestWidth, kTestHeight))); 1039 device_scale_factor, gfx::Size(kTestWidth, kTestHeight)));
1066 SimulateDrawsUntilNewFrameSizeArrives( 1040 SimulateDrawEvent();
1067 SK_ColorRED, gfx::Size(kTestWidth, kTestHeight)); 1041 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColorAndFrameSize(
1042 SK_ColorRED, gfx::Size(kTestWidth, kTestHeight)));
1068 1043
1069 // Source size is half in both dimensions. Expect delivered frames to also 1044 // Source size is half in both dimensions. Expect delivered frames to also
1070 // be half in both dimensions. 1045 // be half in both dimensions.
1071 source()->SetSolidColor(SK_ColorGREEN); 1046 source()->SetSolidColor(SK_ColorGREEN);
1072 SimulateSourceSizeChange(gfx::ConvertSizeToDIP( 1047 SimulateSourceSizeChange(gfx::ConvertSizeToDIP(
1073 device_scale_factor, gfx::Size(kTestWidth / 2, kTestHeight / 2))); 1048 device_scale_factor, gfx::Size(kTestWidth / 2, kTestHeight / 2)));
1074 SimulateDrawsUntilNewFrameSizeArrives( 1049 SimulateDrawEvent();
1075 SK_ColorGREEN, gfx::Size(kTestWidth / 2, kTestHeight / 2)); 1050 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColorAndFrameSize(
1051 SK_ColorGREEN, gfx::Size(kTestWidth / 2, kTestHeight / 2)));
1076 1052
1077 // Source size changes to something arbitrary. Since the source size is 1053 // Source size changes to something arbitrary. Since the source size is
1078 // less than the maximum size, expect delivered frames to be the same size 1054 // less than the maximum size, expect delivered frames to be the same size
1079 // as the source size. 1055 // as the source size.
1080 source()->SetSolidColor(SK_ColorBLUE); 1056 source()->SetSolidColor(SK_ColorBLUE);
1081 gfx::Size arbitrary_source_size(kTestWidth / 2 + 42, kTestHeight - 10); 1057 gfx::Size arbitrary_source_size(kTestWidth / 2 + 42, kTestHeight - 10);
1082 SimulateSourceSizeChange(gfx::ConvertSizeToDIP(device_scale_factor, 1058 SimulateSourceSizeChange(gfx::ConvertSizeToDIP(device_scale_factor,
1083 arbitrary_source_size)); 1059 arbitrary_source_size));
1084 SimulateDrawsUntilNewFrameSizeArrives(SK_ColorBLUE, arbitrary_source_size); 1060 SimulateDrawEvent();
1061 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColorAndFrameSize(
1062 SK_ColorBLUE, arbitrary_source_size));
1085 1063
1086 // Source size changes to something arbitrary that exceeds the maximum frame 1064 // Source size changes to something arbitrary that exceeds the maximum frame
1087 // size. Since the source size exceeds the maximum size, expect delivered 1065 // size. Since the source size exceeds the maximum size, expect delivered
1088 // frames to be downscaled. 1066 // frames to be downscaled.
1089 source()->SetSolidColor(SK_ColorBLACK); 1067 source()->SetSolidColor(SK_ColorBLACK);
1090 arbitrary_source_size = gfx::Size(kTestWidth * 2, kTestHeight / 2); 1068 arbitrary_source_size = gfx::Size(kTestWidth * 2, kTestHeight / 2);
1091 SimulateSourceSizeChange(gfx::ConvertSizeToDIP(device_scale_factor, 1069 SimulateSourceSizeChange(gfx::ConvertSizeToDIP(device_scale_factor,
1092 arbitrary_source_size)); 1070 arbitrary_source_size));
1093 SimulateDrawsUntilNewFrameSizeArrives( 1071 SimulateDrawEvent();
1072 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColorAndFrameSize(
1094 SK_ColorBLACK, gfx::Size(kTestWidth, 1073 SK_ColorBLACK, gfx::Size(kTestWidth,
1095 kTestWidth * arbitrary_source_size.height() / 1074 kTestWidth * arbitrary_source_size.height() /
1096 arbitrary_source_size.width())); 1075 arbitrary_source_size.width())));
1097 1076
1098 device()->StopAndDeAllocate(); 1077 device()->StopAndDeAllocate();
1099 } 1078 }
1100 1079
1101 TEST_F(MAYBE_WebContentsVideoCaptureDeviceTest, 1080 TEST_F(MAYBE_WebContentsVideoCaptureDeviceTest,
1102 ComputesStandardResolutionsForPreferredSize) { 1081 ComputesStandardResolutionsForPreferredSize) {
1103 // Helper function to run the same testing procedure for multiple combinations 1082 // Helper function to run the same testing procedure for multiple combinations
1104 // of |policy|, |standard_size| and |oddball_size|. 1083 // of |policy|, |standard_size| and |oddball_size|.
1105 const auto RunTestForPreferredSize = 1084 const auto RunTestForPreferredSize =
1106 [=](media::ResolutionChangePolicy policy, 1085 [=](media::ResolutionChangePolicy policy,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 // adjustment made. 1164 // adjustment made.
1186 RunTestForPreferredSize( 1165 RunTestForPreferredSize(
1187 policies[i], gfx::Size(1000, 1000), gfx::Size(1000, 1000)); 1166 policies[i], gfx::Size(1000, 1000), gfx::Size(1000, 1000));
1188 RunTestForPreferredSize( 1167 RunTestForPreferredSize(
1189 policies[i], gfx::Size(1600, 1000), gfx::Size(1600, 1000)); 1168 policies[i], gfx::Size(1600, 1000), gfx::Size(1600, 1000));
1190 RunTestForPreferredSize( 1169 RunTestForPreferredSize(
1191 policies[i], gfx::Size(837, 999), gfx::Size(837, 999)); 1170 policies[i], gfx::Size(837, 999), gfx::Size(837, 999));
1192 } 1171 }
1193 } 1172 }
1194 1173
1195 // Tests the RequestRefreshFrame() functionality.
1196 TEST_F(MAYBE_WebContentsVideoCaptureDeviceTest, ProvidesRefreshFrames) {
1197 media::VideoCaptureParams capture_params;
1198 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight);
1199 capture_params.requested_format.frame_rate = kTestFramesPerSecond;
1200 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
1201 device()->AllocateAndStart(capture_params, client_observer()->PassClient());
1202
1203 // Request a refresh frame before the first frame has been drawn. This forces
1204 // a capture.
1205 source()->SetSolidColor(SK_ColorRED);
1206 SimulateRefreshFrameRequest();
1207 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorRED));
1208
1209 // Now, draw a frame and wait for a normal frame capture to occur.
1210 source()->SetSolidColor(SK_ColorGREEN);
1211 SimulateDrawEvent();
1212 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN));
1213
1214 // Now, make three more refresh frame requests. Although the source has
1215 // changed to BLUE, no draw event has occurred. Therefore, expect the refresh
1216 // frames to contain the content from the last drawn frame, which is GREEN.
1217 source()->SetSolidColor(SK_ColorBLUE);
1218 for (int i = 0; i < 3; ++i) {
1219 SimulateRefreshFrameRequest();
1220 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN));
1221 }
1222
1223 device()->StopAndDeAllocate();
1224 }
1225
1226 } // namespace 1174 } // namespace
1227 } // namespace content 1175 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698