Chromium Code Reviews| Index: android_webview/browser/browser_view_renderer_unittest.cc |
| diff --git a/android_webview/browser/browser_view_renderer_unittest.cc b/android_webview/browser/browser_view_renderer_unittest.cc |
| index b4a9d42227241cef82d61d71a47608eb57d52001..e4c6eac5e89705cc4493d1b4216aa04079fa7983 100644 |
| --- a/android_webview/browser/browser_view_renderer_unittest.cc |
| +++ b/android_webview/browser/browser_view_renderer_unittest.cc |
| @@ -3,6 +3,7 @@ |
| // found in the LICENSE file. |
| #include "android_webview/browser/browser_view_renderer.h" |
| +#include "android_webview/browser/child_frame.h" |
| #include "android_webview/browser/test/rendering_test.h" |
| namespace android_webview { |
| @@ -59,4 +60,97 @@ class ClearViewTest : public RenderingTest { |
| RENDERING_TEST_F(ClearViewTest); |
| +class TestAnimateInAndOutOfScreen : public RenderingTest { |
| + public: |
| + TestAnimateInAndOutOfScreen() |
| + : on_draw_count_(0u), draw_gl_count_on_rt_(0u) {} |
| + |
| + void StartTest() override { |
| + new_constraints_ = ParentCompositorDrawConstraints( |
| + false, gfx::Transform(), gfx::Rect(window_->surface_size())); |
| + new_constraints_.transform.Scale(2.0, 2.0); |
| + browser_view_renderer_->SetContinuousInvalidate(true); |
| + } |
| + |
| + void WillOnDraw() override { |
| + browser_view_renderer_->SetContinuousInvalidate(false); |
| + // Step 0: A single onDraw on screen. The parent draw constraints |
| + // of the BVR will updated to be the initial constraints. |
| + // Step 1: A single onDrraw off screen. The parent draw constraints of the |
| + // BVR will be updated to the new constraints. |
| + // Step 2: This onDraw is to introduce the DrawGL that animates the |
| + // webview onto the screen on render thread. End the test when the parent |
| + // draw constraints of BVR is updated to initial constraints. |
| + if (on_draw_count_ == 1u || on_draw_count_ == 2u) |
| + browser_view_renderer_->PrepareToDraw(gfx::Vector2d(), gfx::Rect()); |
| + } |
| + |
| + void DidOnDraw(bool success) override { |
| + EXPECT_TRUE(success); |
| + on_draw_count_++; |
| + } |
| + |
| + bool WillDrawOnRT(SharedRendererState* functor, |
| + AwDrawGLInfo* draw_info) override { |
| + if (draw_gl_count_on_rt_ == 1u) { |
| + draw_gl_count_on_rt_++; |
| + ui_proxy_->PostTask(FROM_HERE, base::Bind(&RenderingTest::PostInvalidate, |
| + 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
|
| + return false; |
| + } |
| + |
| + draw_info->width = window_->surface_size().width(); |
| + draw_info->height = window_->surface_size().height(); |
| + draw_info->is_layer = false; |
| + |
| + gfx::Transform transform; |
| + if (draw_gl_count_on_rt_ == 0u) |
| + transform = new_constraints_.transform; |
| + |
| + transform.matrix().asColMajorf(draw_info->transform); |
| + return true; |
| + } |
| + |
| + void DidDrawOnRT(SharedRendererState* functor) override { |
| + draw_gl_count_on_rt_++; |
| + } |
| + |
| + bool DrawConstraintsEquals( |
| + const ParentCompositorDrawConstraints& constraints1, |
| + const ParentCompositorDrawConstraints& constraints2) { |
| + if (constraints1.is_layer != constraints2.is_layer || |
| + constraints1.transform != constraints2.transform) |
| + return false; |
| + |
| + return !constraints1.is_layer || |
| + constraints1.surface_rect == constraints2.surface_rect; |
| + } |
| + |
| + void ParentDrawConstraintsUpdated( |
| + const ParentCompositorDrawConstraints& constraints) override { |
| + switch (on_draw_count_) { |
| + case 1u: |
| + EXPECT_TRUE(DrawConstraintsEquals(constraints, new_constraints_)); |
| + break; |
| + case 3u: |
| + EXPECT_TRUE(DrawConstraintsEquals(constraints, initial_constraints_)); |
| + EndTest(); |
| + break; |
| + // There will be a following 4th onDraw. But the hardware renderer won't |
| + // post back the draw constraints in DrawGL because the constraints |
| + // don't change. |
| + default: |
| + FAIL(); |
| + } |
| + } |
| + |
| + private: |
| + size_t on_draw_count_; |
| + size_t draw_gl_count_on_rt_; |
| + ParentCompositorDrawConstraints initial_constraints_; |
| + ParentCompositorDrawConstraints new_constraints_; |
| +}; |
| + |
| +RENDERING_TEST_F(TestAnimateInAndOutOfScreen); |
| + |
| } // namespace android_webview |