Roll src/third_party/skia dd4e568:8c9b6f1
[chromium-blink-merge.git] / android_webview / browser / browser_view_renderer_unittest.cc
blob39b83a98e1b425c90a1ef1318c8adfc16ddb8507
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
3 // found in the LICENSE file.
5 #include "android_webview/browser/browser_view_renderer.h"
6 #include "android_webview/browser/child_frame.h"
7 #include "android_webview/browser/test/rendering_test.h"
8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h"
11 namespace android_webview {
13 class SmokeTest : public RenderingTest {
14 void StartTest() override { browser_view_renderer_->PostInvalidate(); }
16 void DidDrawOnRT(SharedRendererState* functor) override {
17 EndTest();
21 RENDERING_TEST_F(SmokeTest);
23 class ClearViewTest : public RenderingTest {
24 public:
25 ClearViewTest() : on_draw_count_(0) {}
27 void StartTest() override {
28 browser_view_renderer_->PostInvalidate();
29 browser_view_renderer_->ClearView();
32 void DidOnDraw(bool success) override {
33 on_draw_count_++;
34 if (on_draw_count_ == 1) {
35 // First OnDraw should be skipped due to ClearView.
36 EXPECT_FALSE(success);
37 browser_view_renderer_->DidUpdateContent(); // Unset ClearView.
38 browser_view_renderer_->PostInvalidate();
39 } else {
40 // Following OnDraws should succeed.
41 EXPECT_TRUE(success);
45 void DidDrawOnRT(SharedRendererState* functor) override {
46 EndTest();
48 private:
49 int on_draw_count_;
52 RENDERING_TEST_F(ClearViewTest);
54 class TestAnimateInAndOutOfScreen : public RenderingTest {
55 public:
56 TestAnimateInAndOutOfScreen() : on_draw_count_(0), draw_gl_count_on_rt_(0) {}
58 void StartTest() override {
59 new_constraints_ = ParentCompositorDrawConstraints(
60 false, gfx::Transform(), gfx::Rect(window_->surface_size()));
61 new_constraints_.transform.Scale(2.0, 2.0);
62 browser_view_renderer_->PostInvalidate();
65 void WillOnDraw() override {
66 // Step 0: A single onDraw on screen. The parent draw constraints
67 // of the BVR will updated to be the initial constraints.
68 // Step 1: A single onDrraw off screen. The parent draw constraints of the
69 // BVR will be updated to the new constraints.
70 // Step 2: This onDraw is to introduce the DrawGL that animates the
71 // webview onto the screen on render thread. End the test when the parent
72 // draw constraints of BVR is updated to initial constraints.
73 if (on_draw_count_ == 1 || on_draw_count_ == 2)
74 browser_view_renderer_->PrepareToDraw(gfx::Vector2d(), gfx::Rect());
77 void DidOnDraw(bool success) override {
78 EXPECT_TRUE(success);
79 on_draw_count_++;
82 bool WillDrawOnRT(SharedRendererState* functor,
83 AwDrawGLInfo* draw_info) override {
84 if (draw_gl_count_on_rt_ == 1) {
85 draw_gl_count_on_rt_++;
86 ui_task_runner_->PostTask(
87 FROM_HERE,
88 base::Bind(&RenderingTest::PostInvalidate, base::Unretained(this)));
89 return false;
92 draw_info->width = window_->surface_size().width();
93 draw_info->height = window_->surface_size().height();
94 draw_info->is_layer = false;
96 gfx::Transform transform;
97 if (draw_gl_count_on_rt_ == 0)
98 transform = new_constraints_.transform;
100 transform.matrix().asColMajorf(draw_info->transform);
101 return true;
104 void DidDrawOnRT(SharedRendererState* functor) override {
105 draw_gl_count_on_rt_++;
108 bool DrawConstraintsEquals(
109 const ParentCompositorDrawConstraints& constraints1,
110 const ParentCompositorDrawConstraints& constraints2) {
111 if (constraints1.is_layer != constraints2.is_layer ||
112 constraints1.transform != constraints2.transform)
113 return false;
115 return !constraints1.is_layer ||
116 constraints1.surface_rect == constraints2.surface_rect;
119 void ParentDrawConstraintsUpdated(
120 const ParentCompositorDrawConstraints& constraints) override {
121 switch (on_draw_count_) {
122 case 1u:
123 EXPECT_TRUE(DrawConstraintsEquals(constraints, new_constraints_));
124 break;
125 case 3u:
126 EXPECT_TRUE(DrawConstraintsEquals(constraints, initial_constraints_));
127 EndTest();
128 break;
129 // There will be a following 4th onDraw. But the hardware renderer won't
130 // post back the draw constraints in DrawGL because the constraints
131 // don't change.
132 default:
133 FAIL();
137 private:
138 int on_draw_count_;
139 int draw_gl_count_on_rt_;
140 ParentCompositorDrawConstraints initial_constraints_;
141 ParentCompositorDrawConstraints new_constraints_;
144 RENDERING_TEST_F(TestAnimateInAndOutOfScreen);
146 } // namespace android_webview