 Chromium Code Reviews
 Chromium Code Reviews Issue 1002013003:
  Unit Test for WebView animating in and out of screen  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1002013003:
  Unit Test for WebView animating in and out of screen  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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..77ad855798b4c218ea2a51a6ab547c6ad8d88264 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,103 @@ 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 { | 
| + 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: 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. | 
| + browser_view_renderer_->PrepareToDraw(gfx::Vector2d(), gfx::Rect()); | 
| + } | 
| + } | 
| + | 
| + void DidOnDraw(bool success) override { | 
| + EXPECT_TRUE(success); | 
| + on_draw_count_++; | 
| + if (on_draw_count_ == 2u) { | 
| + PostInvalidate(); | 
| 
boliu
2015/03/19 22:48:39
Can this be done in DidDrawOnRT (obviously post it
 
hush (inactive)
2015/03/19 23:29:00
Sorry... What is the race condition? 
At this poin
 
boliu
2015/03/20 00:41:10
That's the race.
It's not strictly needed now, bu
 
hush (inactive)
2015/03/20 00:58:38
Okay. Done
 | 
| + } | 
| + } | 
| + | 
| + bool WillDrawOnRT(SharedRendererState* functor, | 
| + AwDrawGLInfo* draw_info) override { | 
| + if (draw_gl_count_on_rt_ == 1u) { | 
| + draw_gl_count_on_rt_++; | 
| + 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_)); | 
| + browser_view_renderer_->SetContinuousInvalidate(false); | 
| + break; | 
| + case 3u: | 
| + EXPECT_TRUE(DrawConstraintsEquals(constraints, initial_constraints_)); | 
| + browser_view_renderer_->SetContinuousInvalidate(false); | 
| 
boliu
2015/03/19 22:48:39
move this to WillOnDraw.
Actually, shouldn't SetC
 
hush (inactive)
2015/03/19 23:29:00
In SetContinuousInvalidate(true) is called in Brow
 
boliu
2015/03/20 00:41:10
Wait, isn't that EnsureContinuousInvalidation, not
 
hush (inactive)
2015/03/20 00:58:38
yeah......
okay. I moved all SetContinuousInvalida
 | 
| + EndTest(); | 
| + break; | 
| + default: | 
| + FAIL(); | 
| 
boliu
2015/03/19 22:48:39
4 can happen, because ParentDrawConstraintsUpdated
 
hush (inactive)
2015/03/19 23:29:00
We will have the next onDraw, that's for sure. But
 
boliu
2015/03/20 00:41:10
Can you put that in a comment?
 
hush (inactive)
2015/03/20 00:58:38
Done.
 | 
| + } | 
| + } | 
| + | 
| + 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 |