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..1839a0ddaf6d309a237ebc1522880ff7e5c0497e 100644 |
| --- a/android_webview/browser/browser_view_renderer_unittest.cc |
| +++ b/android_webview/browser/browser_view_renderer_unittest.cc |
| @@ -59,4 +59,93 @@ class ClearViewTest : public RenderingTest { |
| RENDERING_TEST_F(ClearViewTest); |
| +class TestAnimateInAndOutOfScreen : public RenderingTest { |
| + public: |
| + TestAnimateInAndOutOfScreen() : on_draw_count_(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 { |
| + if (on_draw_count_ == 0u) { |
| + // Step 0: A single onDraw on screen. The parent draw constraints |
| + // of the BVR will updated to be the initial constraints. |
| + browser_view_renderer_->SetContinuousInvalidate(false); |
| + } |
| + if (on_draw_count_ == 1u) { |
| + // Step 1: A single onDrraw off screen. The parent draw constraints of the |
| + // BVR will be updated to the new constraints. |
| + browser_view_renderer_->PrepareToDraw(gfx::Vector2d(), gfx::Rect()); |
| + } |
| + if (on_draw_count_ == 2u) { |
| + // Step 2: A single onDraw onscreen. End the test when the parent |
| + // draw constraints of BVR is updated to initial constraints. |
| + } |
| + } |
| + |
| + void DidOnDraw(bool success) override { |
| + EXPECT_TRUE(success); |
| + on_draw_count_++; |
| + if (on_draw_count_ == 2u) { |
| + PostInvalidate(); |
| + } |
| + } |
| + |
| + bool WillDrawOnRT(SharedRendererState* functor, |
| + AwDrawGLInfo& draw_info) override { |
| + if (browser_view_renderer_->global_visible_rect_for_testing().IsEmpty()) |
|
boliu
2015/03/19 20:24:27
This is not thread safe in general.
I guess you c
hush (inactive)
2015/03/19 21:27:57
Done.
|
| + 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 (on_draw_count_ == 1u) |
| + transform = new_constraints_.transform; |
| + |
| + transform.matrix().asColMajorf(draw_info.transform); |
| + return true; |
| + } |
| + |
| + 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 { |
| + if (on_draw_count_ == 1u) { |
|
boliu
2015/03/19 20:24:27
nit, use a switch?
then case 2: and default: can
hush (inactive)
2015/03/19 21:27:57
Okay for case 2.
However, there is a race conditio
|
| + EXPECT_TRUE(DrawConstraintsEquals(constraints, new_constraints_)); |
| + return; |
| + } |
| + |
| + EXPECT_NE(on_draw_count_, 2u); |
| + |
| + if (on_draw_count_ == 3u) { |
| + EXPECT_TRUE(DrawConstraintsEquals(constraints, initial_constraints_)); |
| + browser_view_renderer_->SetContinuousInvalidate(false); |
| + EndTest(); |
| + return; |
| + } |
| + } |
| + |
| + private: |
| + size_t on_draw_count_; |
| + ParentCompositorDrawConstraints initial_constraints_; |
| + ParentCompositorDrawConstraints new_constraints_; |
| +}; |
| + |
| +RENDERING_TEST_F(TestAnimateInAndOutOfScreen); |
| + |
| } // namespace android_webview |