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

Side by Side Diff: android_webview/browser/browser_view_renderer_unittest.cc

Issue 2078383004: Add a BrowserViewRenderer unittest for compositor switch logic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <map> 5 #include <map>
6 #include <queue> 6 #include <queue>
7 #include <utility> 7 #include <utility>
8 8
9 #include "android_webview/browser/browser_view_renderer.h" 9 #include "android_webview/browser/browser_view_renderer.h"
10 #include "android_webview/browser/child_frame.h" 10 #include "android_webview/browser/child_frame.h"
11 #include "android_webview/browser/compositor_frame_consumer.h" 11 #include "android_webview/browser/compositor_frame_consumer.h"
12 #include "android_webview/browser/render_thread_manager.h" 12 #include "android_webview/browser/render_thread_manager.h"
13 #include "android_webview/browser/test/rendering_test.h" 13 #include "android_webview/browser/test/rendering_test.h"
14 #include "base/location.h" 14 #include "base/location.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/threading/thread_task_runner_handle.h" 16 #include "base/threading/thread_task_runner_handle.h"
17 #include "cc/output/compositor_frame.h" 17 #include "cc/output/compositor_frame.h"
18 #include "content/public/test/test_synchronous_compositor_android.h" 18 #include "content/public/test/test_synchronous_compositor_android.h"
19 19
20 namespace android_webview { 20 namespace android_webview {
21 21
22 class SmokeTest : public RenderingTest { 22 class SmokeTest : public RenderingTest {
23 void StartTest() override { 23 void StartTest() override {
24 browser_view_renderer_->PostInvalidate(compositor_.get()); 24 browser_view_renderer_->PostInvalidate(compositor());
25 } 25 }
26 26
27 void DidDrawOnRT() override { EndTest(); } 27 void DidDrawOnRT() override { EndTest(); }
28 }; 28 };
29 29
30 RENDERING_TEST_F(SmokeTest); 30 RENDERING_TEST_F(SmokeTest);
31 31
32 // Test the case where SynchronousCompositor is constructed after the RVH that
33 // owns it is switched to be active.
34 class ActiveCompositorSwitchBeforeConstructionTest : public RenderingTest {
35 public:
36 ActiveCompositorSwitchBeforeConstructionTest() : on_draw_count_(0) {}
37 void StartTest() override {
38 browser_view_renderer_->PostInvalidate(compositor());
39 }
40
41 void DidOnDraw(bool success) override {
42 on_draw_count_++;
43 switch (on_draw_count_) {
44 case 1:
45 EXPECT_TRUE(success);
46 // Change compositor here. And do another ondraw.
47 // The previous active compositor id is 0, 0, now change it to 0, 1.
48 browser_view_renderer_->SetActiveCompositorID(CompositorID(0, 1));
49 browser_view_renderer_->PostInvalidate(compositor());
50 break;
51 case 2:
52 // The 2nd ondraw is skipped because there is no active compositor at
53 // the moment.
54 EXPECT_FALSE(success);
55 compositor_.reset(new content::TestSynchronousCompositor(0, 1));
boliu 2016/06/21 17:29:47 this also destroyes the old one, can we have exerc
hush (inactive) 2016/06/21 21:27:25 Done.
56 compositor_->SetClient(browser_view_renderer_.get());
57
58 EXPECT_EQ(compositor(), compositor_.get());
59 browser_view_renderer_->PostInvalidate(compositor());
60 break;
61 case 3:
62 EXPECT_TRUE(success);
63 EXPECT_EQ(compositor(), compositor_.get());
64 EndTest();
65 }
66 }
67
68 private:
69 int on_draw_count_;
70 };
71
72 RENDERING_TEST_F(ActiveCompositorSwitchBeforeConstructionTest);
73
74 // Test the case where SynchronousCompositor is constructed before the RVH that
75 // owns it is switched to be active.
76 class ActiveCompositorSwitchAfterConstructionTest : public RenderingTest {
77 public:
78 ActiveCompositorSwitchAfterConstructionTest() : on_draw_count_(0) {}
79 void StartTest() override {
80 browser_view_renderer_->PostInvalidate(compositor());
81 }
82
83 void DidOnDraw(bool success) override {
84 on_draw_count_++;
85 switch (on_draw_count_) {
86 case 1:
87 EXPECT_TRUE(success);
88 // Create a new compositor here. And switch it to be active. And then
89 // do another ondraw.
90 compositor_.reset(new content::TestSynchronousCompositor(0, 1));
boliu 2016/06/21 17:29:47 ditto
hush (inactive) 2016/06/21 21:27:25 Done.
91 compositor_->SetClient(browser_view_renderer_.get());
92 browser_view_renderer_->SetActiveCompositorID(CompositorID(0, 1));
93
94 EXPECT_EQ(compositor(), compositor_.get());
95 browser_view_renderer_->PostInvalidate(compositor());
96 break;
97 case 2:
98 EXPECT_TRUE(success);
99 EXPECT_EQ(compositor(), compositor_.get());
100 EndTest();
101 }
102 }
103
104 private:
105 int on_draw_count_;
106 };
107
108 RENDERING_TEST_F(ActiveCompositorSwitchAfterConstructionTest);
109
32 class ClearViewTest : public RenderingTest { 110 class ClearViewTest : public RenderingTest {
33 public: 111 public:
34 ClearViewTest() : on_draw_count_(0) {} 112 ClearViewTest() : on_draw_count_(0) {}
35 113
36 void StartTest() override { 114 void StartTest() override {
37 browser_view_renderer_->PostInvalidate(compositor_.get()); 115 browser_view_renderer_->PostInvalidate(compositor());
38 browser_view_renderer_->ClearView(); 116 browser_view_renderer_->ClearView();
39 } 117 }
40 118
41 void DidOnDraw(bool success) override { 119 void DidOnDraw(bool success) override {
42 on_draw_count_++; 120 on_draw_count_++;
43 if (on_draw_count_ == 1) { 121 if (on_draw_count_ == 1) {
44 // First OnDraw should be skipped due to ClearView. 122 // First OnDraw should be skipped due to ClearView.
45 EXPECT_FALSE(success); 123 EXPECT_FALSE(success);
46 browser_view_renderer_->DidUpdateContent( 124 browser_view_renderer_->DidUpdateContent(
47 compositor_.get()); // Unset ClearView. 125 compositor()); // Unset ClearView.
48 browser_view_renderer_->PostInvalidate(compositor_.get()); 126 browser_view_renderer_->PostInvalidate(compositor());
49 } else { 127 } else {
50 // Following OnDraws should succeed. 128 // Following OnDraws should succeed.
51 EXPECT_TRUE(success); 129 EXPECT_TRUE(success);
52 } 130 }
53 } 131 }
54 132
55 void DidDrawOnRT() override { EndTest(); } 133 void DidDrawOnRT() override { EndTest(); }
56 134
57 private: 135 private:
58 int on_draw_count_; 136 int on_draw_count_;
59 }; 137 };
60 138
61 RENDERING_TEST_F(ClearViewTest); 139 RENDERING_TEST_F(ClearViewTest);
62 140
63 class TestAnimateInAndOutOfScreen : public RenderingTest { 141 class TestAnimateInAndOutOfScreen : public RenderingTest {
64 public: 142 public:
65 TestAnimateInAndOutOfScreen() : on_draw_count_(0), draw_gl_count_on_rt_(0) {} 143 TestAnimateInAndOutOfScreen() : on_draw_count_(0), draw_gl_count_on_rt_(0) {}
66 144
67 void StartTest() override { 145 void StartTest() override {
68 new_constraints_ = ParentCompositorDrawConstraints( 146 new_constraints_ = ParentCompositorDrawConstraints(
69 false, gfx::Transform(), window_->surface_size().IsEmpty()); 147 false, gfx::Transform(), window_->surface_size().IsEmpty());
70 new_constraints_.transform.Scale(2.0, 2.0); 148 new_constraints_.transform.Scale(2.0, 2.0);
71 browser_view_renderer_->PostInvalidate(compositor_.get()); 149 browser_view_renderer_->PostInvalidate(compositor());
72 } 150 }
73 151
74 void WillOnDraw() override { 152 void WillOnDraw() override {
75 RenderingTest::WillOnDraw(); 153 RenderingTest::WillOnDraw();
76 // Step 0: A single onDraw on screen. The parent draw constraints 154 // Step 0: A single onDraw on screen. The parent draw constraints
77 // of the BVR will updated to be the initial constraints. 155 // of the BVR will updated to be the initial constraints.
78 // Step 1: A single onDrraw off screen. The parent draw constraints of the 156 // Step 1: A single onDrraw off screen. The parent draw constraints of the
79 // BVR will be updated to the new constraints. 157 // BVR will be updated to the new constraints.
80 // Step 2: This onDraw is to introduce the DrawGL that animates the 158 // Step 2: This onDraw is to introduce the DrawGL that animates the
81 // webview onto the screen on render thread. End the test when the parent 159 // webview onto the screen on render thread. End the test when the parent
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 ParentCompositorDrawConstraints new_constraints_; 231 ParentCompositorDrawConstraints new_constraints_;
154 }; 232 };
155 233
156 RENDERING_TEST_F(TestAnimateInAndOutOfScreen); 234 RENDERING_TEST_F(TestAnimateInAndOutOfScreen);
157 235
158 class CompositorNoFrameTest : public RenderingTest { 236 class CompositorNoFrameTest : public RenderingTest {
159 public: 237 public:
160 CompositorNoFrameTest() : on_draw_count_(0) {} 238 CompositorNoFrameTest() : on_draw_count_(0) {}
161 239
162 void StartTest() override { 240 void StartTest() override {
163 browser_view_renderer_->PostInvalidate(compositor_.get()); 241 browser_view_renderer_->PostInvalidate(compositor());
164 } 242 }
165 243
166 void WillOnDraw() override { 244 void WillOnDraw() override {
167 if (0 == on_draw_count_) { 245 if (0 == on_draw_count_) {
168 // No frame from compositor. 246 // No frame from compositor.
169 } else if (1 == on_draw_count_) { 247 } else if (1 == on_draw_count_) {
170 compositor_->SetHardwareFrame(0u, ConstructEmptyFrame()); 248 compositor_->SetHardwareFrame(0u, ConstructEmptyFrame());
171 } else if (2 == on_draw_count_) { 249 } else if (2 == on_draw_count_) {
172 // No frame from compositor. 250 // No frame from compositor.
173 } 251 }
174 // There may be trailing invalidates. 252 // There may be trailing invalidates.
175 } 253 }
176 254
177 void DidOnDraw(bool success) override { 255 void DidOnDraw(bool success) override {
178 if (0 == on_draw_count_) { 256 if (0 == on_draw_count_) {
179 // Should fail as there has been no frames from compositor. 257 // Should fail as there has been no frames from compositor.
180 EXPECT_FALSE(success); 258 EXPECT_FALSE(success);
181 browser_view_renderer_->PostInvalidate(compositor_.get()); 259 browser_view_renderer_->PostInvalidate(compositor());
182 } else if (1 == on_draw_count_) { 260 } else if (1 == on_draw_count_) {
183 // Should succeed with frame from compositor. 261 // Should succeed with frame from compositor.
184 EXPECT_TRUE(success); 262 EXPECT_TRUE(success);
185 browser_view_renderer_->PostInvalidate(compositor_.get()); 263 browser_view_renderer_->PostInvalidate(compositor());
186 } else if (2 == on_draw_count_) { 264 } else if (2 == on_draw_count_) {
187 // Should still succeed with last frame, even if no frame from compositor. 265 // Should still succeed with last frame, even if no frame from compositor.
188 EXPECT_TRUE(success); 266 EXPECT_TRUE(success);
189 EndTest(); 267 EndTest();
190 } 268 }
191 on_draw_count_++; 269 on_draw_count_++;
192 } 270 }
193 271
194 private: 272 private:
195 int on_draw_count_; 273 int on_draw_count_;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 316 }
239 return counts; 317 return counts;
240 } 318 }
241 319
242 virtual void CheckResults() = 0; 320 virtual void CheckResults() = 0;
243 321
244 private: 322 private:
245 bool AdvanceFrame() { 323 bool AdvanceFrame() {
246 next_frame_ = GetFrame(frame_number_++); 324 next_frame_ = GetFrame(frame_number_++);
247 if (next_frame_) { 325 if (next_frame_) {
248 browser_view_renderer_->PostInvalidate(compositor_.get()); 326 browser_view_renderer_->PostInvalidate(compositor());
249 return true; 327 return true;
250 } 328 }
251 return false; 329 return false;
252 } 330 }
253 331
254 std::unique_ptr<content::SynchronousCompositor::Frame> next_frame_; 332 std::unique_ptr<content::SynchronousCompositor::Frame> next_frame_;
255 int frame_number_; 333 int frame_number_;
256 }; 334 };
257 335
258 class SwitchOutputSurfaceIdTest : public ResourceRenderingTest { 336 class SwitchOutputSurfaceIdTest : public ResourceRenderingTest {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 } 477 }
400 478
401 private: 479 private:
402 std::unique_ptr<FakeFunctor> saved_functor_; 480 std::unique_ptr<FakeFunctor> saved_functor_;
403 OutputSurfaceResourceCountMap expected_return_count_; 481 OutputSurfaceResourceCountMap expected_return_count_;
404 }; 482 };
405 483
406 RENDERING_TEST_F(RenderThreadManagerSwitchTest); 484 RENDERING_TEST_F(RenderThreadManagerSwitchTest);
407 485
408 } // namespace android_webview 486 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698