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

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

Issue 1002013003: Unit Test for WebView animating in and out of screen (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 5 years, 9 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 "android_webview/browser/browser_view_renderer.h" 5 #include "android_webview/browser/browser_view_renderer.h"
6 #include "android_webview/browser/child_frame.h"
6 #include "android_webview/browser/test/rendering_test.h" 7 #include "android_webview/browser/test/rendering_test.h"
7 8
8 namespace android_webview { 9 namespace android_webview {
9 10
10 class SmokeTest : public RenderingTest { 11 class SmokeTest : public RenderingTest {
11 void StartTest() override { 12 void StartTest() override {
12 browser_view_renderer_->SetContinuousInvalidate(true); 13 browser_view_renderer_->SetContinuousInvalidate(true);
13 } 14 }
14 15
15 void WillOnDraw() override { 16 void WillOnDraw() override {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 53
53 void DidDrawOnRT(SharedRendererState* functor) override { 54 void DidDrawOnRT(SharedRendererState* functor) override {
54 EndTest(); 55 EndTest();
55 } 56 }
56 private: 57 private:
57 size_t on_draw_count_; 58 size_t on_draw_count_;
58 }; 59 };
59 60
60 RENDERING_TEST_F(ClearViewTest); 61 RENDERING_TEST_F(ClearViewTest);
61 62
63 class TestAnimateInAndOutOfScreen : public RenderingTest {
64 public:
65 TestAnimateInAndOutOfScreen()
66 : on_draw_count_(0u), draw_gl_count_on_rt_(0u) {}
67
68 void StartTest() override {
69 new_constraints_ = ParentCompositorDrawConstraints(
70 false, gfx::Transform(), gfx::Rect(window_->surface_size()));
71 new_constraints_.transform.Scale(2.0, 2.0);
72 browser_view_renderer_->SetContinuousInvalidate(true);
73 }
74
75 void WillOnDraw() override {
76 browser_view_renderer_->SetContinuousInvalidate(false);
77 // Step 0: A single onDraw on screen. The parent draw constraints
78 // of the BVR will updated to be the initial constraints.
79 // Step 1: A single onDrraw off screen. The parent draw constraints of the
80 // BVR will be updated to the new constraints.
81 // Step 2: This onDraw is to introduce the DrawGL that animates the
82 // webview onto the screen on render thread. End the test when the parent
83 // draw constraints of BVR is updated to initial constraints.
84 if (on_draw_count_ == 1u || on_draw_count_ == 2u)
85 browser_view_renderer_->PrepareToDraw(gfx::Vector2d(), gfx::Rect());
86 }
87
88 void DidOnDraw(bool success) override {
89 EXPECT_TRUE(success);
90 on_draw_count_++;
91 }
92
93 bool WillDrawOnRT(SharedRendererState* functor,
94 AwDrawGLInfo* draw_info) override {
95 if (draw_gl_count_on_rt_ == 1u) {
96 draw_gl_count_on_rt_++;
97 ui_proxy_->PostTask(FROM_HERE, base::Bind(&RenderingTest::PostInvalidate,
98 base::Unretained(this)));
boliu 2015/03/20 01:01:44 Put it in DidDrawOnRT?
hush (inactive) 2015/03/20 01:09:41 There is no DidDrawOnRT for this particular case,
boliu 2015/03/20 01:10:22 Ohh, right
99 return false;
100 }
101
102 draw_info->width = window_->surface_size().width();
103 draw_info->height = window_->surface_size().height();
104 draw_info->is_layer = false;
105
106 gfx::Transform transform;
107 if (draw_gl_count_on_rt_ == 0u)
108 transform = new_constraints_.transform;
109
110 transform.matrix().asColMajorf(draw_info->transform);
111 return true;
112 }
113
114 void DidDrawOnRT(SharedRendererState* functor) override {
115 draw_gl_count_on_rt_++;
116 }
117
118 bool DrawConstraintsEquals(
119 const ParentCompositorDrawConstraints& constraints1,
120 const ParentCompositorDrawConstraints& constraints2) {
121 if (constraints1.is_layer != constraints2.is_layer ||
122 constraints1.transform != constraints2.transform)
123 return false;
124
125 return !constraints1.is_layer ||
126 constraints1.surface_rect == constraints2.surface_rect;
127 }
128
129 void ParentDrawConstraintsUpdated(
130 const ParentCompositorDrawConstraints& constraints) override {
131 switch (on_draw_count_) {
132 case 1u:
133 EXPECT_TRUE(DrawConstraintsEquals(constraints, new_constraints_));
134 break;
135 case 3u:
136 EXPECT_TRUE(DrawConstraintsEquals(constraints, initial_constraints_));
137 EndTest();
138 break;
139 // There will be a following 4th onDraw. But the hardware renderer won't
140 // post back the draw constraints in DrawGL because the constraints
141 // don't change.
142 default:
143 FAIL();
144 }
145 }
146
147 private:
148 size_t on_draw_count_;
149 size_t draw_gl_count_on_rt_;
150 ParentCompositorDrawConstraints initial_constraints_;
151 ParentCompositorDrawConstraints new_constraints_;
152 };
153
154 RENDERING_TEST_F(TestAnimateInAndOutOfScreen);
155
62 } // namespace android_webview 156 } // namespace android_webview
OLDNEW
« no previous file with comments | « android_webview/browser/browser_view_renderer_client.h ('k') | android_webview/browser/hardware_renderer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698