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

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: comment 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(ActiveCompositor());
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()
37 : on_draw_count_(0), new_compositor_(nullptr) {}
38 void StartTest() override {
39 browser_view_renderer_->PostInvalidate(ActiveCompositor());
40 }
41
42 void DidOnDraw(bool success) override {
43 on_draw_count_++;
44 switch (on_draw_count_) {
45 case 1:
46 EXPECT_TRUE(success);
47 // Change compositor here. And do another ondraw.
48 // The previous active compositor id is 0, 0, now change it to 0, 1.
49 browser_view_renderer_->SetActiveCompositorID(CompositorID(0, 1));
50 browser_view_renderer_->PostInvalidate(ActiveCompositor());
51 break;
52 case 2:
53 // The 2nd ondraw is skipped because there is no active compositor at
54 // the moment.
55 EXPECT_FALSE(success);
56 new_compositor_.reset(new content::TestSynchronousCompositor(0, 1));
57 new_compositor_->SetClient(browser_view_renderer_.get());
58 EXPECT_EQ(ActiveCompositor(), new_compositor_.get());
59 browser_view_renderer_->PostInvalidate(ActiveCompositor());
60 break;
61 case 3:
62 EXPECT_TRUE(success);
63 compositor_ = std::move(new_compositor_);
64
65 EXPECT_EQ(ActiveCompositor(), compositor_.get());
66 browser_view_renderer_->PostInvalidate(ActiveCompositor());
67 break;
68 case 4:
69 EXPECT_TRUE(success);
70 EndTest();
71 }
72 }
73
74 private:
75 int on_draw_count_;
76 std::unique_ptr<content::TestSynchronousCompositor> new_compositor_;
77 };
78
79 RENDERING_TEST_F(ActiveCompositorSwitchBeforeConstructionTest);
80
81 // Test the case where SynchronousCompositor is constructed before the RVH that
82 // owns it is switched to be active.
83 class ActiveCompositorSwitchAfterConstructionTest : public RenderingTest {
84 public:
85 ActiveCompositorSwitchAfterConstructionTest()
86 : on_draw_count_(0), new_compositor_(nullptr) {}
87 void StartTest() override {
88 browser_view_renderer_->PostInvalidate(ActiveCompositor());
89 }
90
91 void DidOnDraw(bool success) override {
92 on_draw_count_++;
93 switch (on_draw_count_) {
94 case 1:
95 EXPECT_TRUE(success);
96 // Create a new compositor here. And switch it to be active. And then
97 // do another ondraw.
98 new_compositor_.reset(new content::TestSynchronousCompositor(0, 1));
99 new_compositor_->SetClient(browser_view_renderer_.get());
100 browser_view_renderer_->SetActiveCompositorID(CompositorID(0, 1));
101
102 EXPECT_EQ(ActiveCompositor(), new_compositor_.get());
103 browser_view_renderer_->PostInvalidate(ActiveCompositor());
104 break;
105 case 2:
106 EXPECT_TRUE(success);
107 compositor_ = std::move(new_compositor_);
108
109 EXPECT_EQ(ActiveCompositor(), compositor_.get());
110 browser_view_renderer_->PostInvalidate(ActiveCompositor());
111 break;
112 case 3:
113 EXPECT_TRUE(success);
114 EndTest();
115 }
116 }
117
118 private:
119 int on_draw_count_;
120 std::unique_ptr<content::TestSynchronousCompositor> new_compositor_;
121 };
122
123 RENDERING_TEST_F(ActiveCompositorSwitchAfterConstructionTest);
124
32 class ClearViewTest : public RenderingTest { 125 class ClearViewTest : public RenderingTest {
33 public: 126 public:
34 ClearViewTest() : on_draw_count_(0) {} 127 ClearViewTest() : on_draw_count_(0) {}
35 128
36 void StartTest() override { 129 void StartTest() override {
37 browser_view_renderer_->PostInvalidate(compositor_.get()); 130 browser_view_renderer_->PostInvalidate(ActiveCompositor());
38 browser_view_renderer_->ClearView(); 131 browser_view_renderer_->ClearView();
39 } 132 }
40 133
41 void DidOnDraw(bool success) override { 134 void DidOnDraw(bool success) override {
42 on_draw_count_++; 135 on_draw_count_++;
43 if (on_draw_count_ == 1) { 136 if (on_draw_count_ == 1) {
44 // First OnDraw should be skipped due to ClearView. 137 // First OnDraw should be skipped due to ClearView.
45 EXPECT_FALSE(success); 138 EXPECT_FALSE(success);
46 browser_view_renderer_->DidUpdateContent( 139 browser_view_renderer_->DidUpdateContent(
47 compositor_.get()); // Unset ClearView. 140 ActiveCompositor()); // Unset ClearView.
48 browser_view_renderer_->PostInvalidate(compositor_.get()); 141 browser_view_renderer_->PostInvalidate(ActiveCompositor());
49 } else { 142 } else {
50 // Following OnDraws should succeed. 143 // Following OnDraws should succeed.
51 EXPECT_TRUE(success); 144 EXPECT_TRUE(success);
52 } 145 }
53 } 146 }
54 147
55 void DidDrawOnRT() override { EndTest(); } 148 void DidDrawOnRT() override { EndTest(); }
56 149
57 private: 150 private:
58 int on_draw_count_; 151 int on_draw_count_;
59 }; 152 };
60 153
61 RENDERING_TEST_F(ClearViewTest); 154 RENDERING_TEST_F(ClearViewTest);
62 155
63 class TestAnimateInAndOutOfScreen : public RenderingTest { 156 class TestAnimateInAndOutOfScreen : public RenderingTest {
64 public: 157 public:
65 TestAnimateInAndOutOfScreen() : on_draw_count_(0), draw_gl_count_on_rt_(0) {} 158 TestAnimateInAndOutOfScreen() : on_draw_count_(0), draw_gl_count_on_rt_(0) {}
66 159
67 void StartTest() override { 160 void StartTest() override {
68 new_constraints_ = ParentCompositorDrawConstraints( 161 new_constraints_ = ParentCompositorDrawConstraints(
69 false, gfx::Transform(), window_->surface_size().IsEmpty()); 162 false, gfx::Transform(), window_->surface_size().IsEmpty());
70 new_constraints_.transform.Scale(2.0, 2.0); 163 new_constraints_.transform.Scale(2.0, 2.0);
71 browser_view_renderer_->PostInvalidate(compositor_.get()); 164 browser_view_renderer_->PostInvalidate(ActiveCompositor());
72 } 165 }
73 166
74 void WillOnDraw() override { 167 void WillOnDraw() override {
75 RenderingTest::WillOnDraw(); 168 RenderingTest::WillOnDraw();
76 // Step 0: A single onDraw on screen. The parent draw constraints 169 // Step 0: A single onDraw on screen. The parent draw constraints
77 // of the BVR will updated to be the initial constraints. 170 // of the BVR will updated to be the initial constraints.
78 // Step 1: A single onDrraw off screen. The parent draw constraints of the 171 // Step 1: A single onDrraw off screen. The parent draw constraints of the
79 // BVR will be updated to the new constraints. 172 // BVR will be updated to the new constraints.
80 // Step 2: This onDraw is to introduce the DrawGL that animates the 173 // 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 174 // 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_; 246 ParentCompositorDrawConstraints new_constraints_;
154 }; 247 };
155 248
156 RENDERING_TEST_F(TestAnimateInAndOutOfScreen); 249 RENDERING_TEST_F(TestAnimateInAndOutOfScreen);
157 250
158 class CompositorNoFrameTest : public RenderingTest { 251 class CompositorNoFrameTest : public RenderingTest {
159 public: 252 public:
160 CompositorNoFrameTest() : on_draw_count_(0) {} 253 CompositorNoFrameTest() : on_draw_count_(0) {}
161 254
162 void StartTest() override { 255 void StartTest() override {
163 browser_view_renderer_->PostInvalidate(compositor_.get()); 256 browser_view_renderer_->PostInvalidate(ActiveCompositor());
164 } 257 }
165 258
166 void WillOnDraw() override { 259 void WillOnDraw() override {
167 if (0 == on_draw_count_) { 260 if (0 == on_draw_count_) {
168 // No frame from compositor. 261 // No frame from compositor.
169 } else if (1 == on_draw_count_) { 262 } else if (1 == on_draw_count_) {
170 compositor_->SetHardwareFrame(0u, ConstructEmptyFrame()); 263 compositor_->SetHardwareFrame(0u, ConstructEmptyFrame());
171 } else if (2 == on_draw_count_) { 264 } else if (2 == on_draw_count_) {
172 // No frame from compositor. 265 // No frame from compositor.
173 } 266 }
174 // There may be trailing invalidates. 267 // There may be trailing invalidates.
175 } 268 }
176 269
177 void DidOnDraw(bool success) override { 270 void DidOnDraw(bool success) override {
178 if (0 == on_draw_count_) { 271 if (0 == on_draw_count_) {
179 // Should fail as there has been no frames from compositor. 272 // Should fail as there has been no frames from compositor.
180 EXPECT_FALSE(success); 273 EXPECT_FALSE(success);
181 browser_view_renderer_->PostInvalidate(compositor_.get()); 274 browser_view_renderer_->PostInvalidate(ActiveCompositor());
182 } else if (1 == on_draw_count_) { 275 } else if (1 == on_draw_count_) {
183 // Should succeed with frame from compositor. 276 // Should succeed with frame from compositor.
184 EXPECT_TRUE(success); 277 EXPECT_TRUE(success);
185 browser_view_renderer_->PostInvalidate(compositor_.get()); 278 browser_view_renderer_->PostInvalidate(ActiveCompositor());
186 } else if (2 == on_draw_count_) { 279 } else if (2 == on_draw_count_) {
187 // Should still succeed with last frame, even if no frame from compositor. 280 // Should still succeed with last frame, even if no frame from compositor.
188 EXPECT_TRUE(success); 281 EXPECT_TRUE(success);
189 EndTest(); 282 EndTest();
190 } 283 }
191 on_draw_count_++; 284 on_draw_count_++;
192 } 285 }
193 286
194 private: 287 private:
195 int on_draw_count_; 288 int on_draw_count_;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 331 }
239 return counts; 332 return counts;
240 } 333 }
241 334
242 virtual void CheckResults() = 0; 335 virtual void CheckResults() = 0;
243 336
244 private: 337 private:
245 bool AdvanceFrame() { 338 bool AdvanceFrame() {
246 next_frame_ = GetFrame(frame_number_++); 339 next_frame_ = GetFrame(frame_number_++);
247 if (next_frame_) { 340 if (next_frame_) {
248 browser_view_renderer_->PostInvalidate(compositor_.get()); 341 browser_view_renderer_->PostInvalidate(ActiveCompositor());
249 return true; 342 return true;
250 } 343 }
251 return false; 344 return false;
252 } 345 }
253 346
254 std::unique_ptr<content::SynchronousCompositor::Frame> next_frame_; 347 std::unique_ptr<content::SynchronousCompositor::Frame> next_frame_;
255 int frame_number_; 348 int frame_number_;
256 }; 349 };
257 350
258 class SwitchOutputSurfaceIdTest : public ResourceRenderingTest { 351 class SwitchOutputSurfaceIdTest : public ResourceRenderingTest {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 } 492 }
400 493
401 private: 494 private:
402 std::unique_ptr<FakeFunctor> saved_functor_; 495 std::unique_ptr<FakeFunctor> saved_functor_;
403 OutputSurfaceResourceCountMap expected_return_count_; 496 OutputSurfaceResourceCountMap expected_return_count_;
404 }; 497 };
405 498
406 RENDERING_TEST_F(RenderThreadManagerSwitchTest); 499 RENDERING_TEST_F(RenderThreadManagerSwitchTest);
407 500
408 } // namespace android_webview 501 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/browser_view_renderer.h ('k') | android_webview/browser/test/rendering_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698