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
{
21 RENDERING_TEST_F(SmokeTest
);
23 class ClearViewTest
: public RenderingTest
{
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
{
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();
40 // Following OnDraws should succeed.
45 void DidDrawOnRT(SharedRendererState
* functor
) override
{
52 RENDERING_TEST_F(ClearViewTest
);
54 class TestAnimateInAndOutOfScreen
: public RenderingTest
{
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
{
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(
88 base::Bind(&RenderingTest::PostInvalidate
, base::Unretained(this)));
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
);
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
)
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_
) {
123 EXPECT_TRUE(DrawConstraintsEquals(constraints
, new_constraints_
));
126 EXPECT_TRUE(DrawConstraintsEquals(constraints
, initial_constraints_
));
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
139 int draw_gl_count_on_rt_
;
140 ParentCompositorDrawConstraints initial_constraints_
;
141 ParentCompositorDrawConstraints new_constraints_
;
144 RENDERING_TEST_F(TestAnimateInAndOutOfScreen
);
146 } // namespace android_webview