 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| OLD | NEW | 
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "android_webview/browser/browser_view_renderer.h" | 5 #include "android_webview/browser/browser_view_renderer.h" | 
| 6 #include "android_webview/browser/child_frame.h" | |
| 6 #include "android_webview/browser/test/rendering_test.h" | 7 #include "android_webview/browser/test/rendering_test.h" | 
| 7 | 8 | 
| 8 namespace android_webview { | 9 namespace android_webview { | 
| 9 | 10 | 
| 10 class SmokeTest : public RenderingTest { | 11 class SmokeTest : public RenderingTest { | 
| 11 void StartTest() override { | 12 void StartTest() override { | 
| 12 browser_view_renderer_->SetContinuousInvalidate(true); | 13 browser_view_renderer_->SetContinuousInvalidate(true); | 
| 13 } | 14 } | 
| 14 | 15 | 
| 15 void WillOnDraw() override { | 16 void WillOnDraw() override { | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 | 53 | 
| 53 void DidDrawOnRT(SharedRendererState* functor) override { | 54 void DidDrawOnRT(SharedRendererState* functor) override { | 
| 54 EndTest(); | 55 EndTest(); | 
| 55 } | 56 } | 
| 56 private: | 57 private: | 
| 57 size_t on_draw_count_; | 58 size_t on_draw_count_; | 
| 58 }; | 59 }; | 
| 59 | 60 | 
| 60 RENDERING_TEST_F(ClearViewTest); | 61 RENDERING_TEST_F(ClearViewTest); | 
| 61 | 62 | 
| 63 class TestAnimateInAndOutOfScreen : public RenderingTest { | |
| 64 public: | |
| 65 TestAnimateInAndOutOfScreen() | |
| 66 : on_draw_count_(0u), draw_gl_count_on_rt_(0u) {} | |
| 67 | |
| 68 void StartTest() override { | |
| 69 new_constraints_ = ParentCompositorDrawConstraints( | |
| 70 false, gfx::Transform(), gfx::Rect(window_->surface_size())); | |
| 71 new_constraints_.transform.Scale(2.0, 2.0); | |
| 72 browser_view_renderer_->SetContinuousInvalidate(true); | |
| 73 } | |
| 74 | |
| 75 void WillOnDraw() override { | |
| 76 if (on_draw_count_ == 0u) { | |
| 77 // Step 0: A single onDraw on screen. The parent draw constraints | |
| 78 // of the BVR will updated to be the initial constraints. | |
| 79 browser_view_renderer_->SetContinuousInvalidate(false); | |
| 80 } | |
| 81 if (on_draw_count_ == 1u) { | |
| 82 // Step 1: A single onDrraw off screen. The parent draw constraints of the | |
| 83 // BVR will be updated to the new constraints. | |
| 84 browser_view_renderer_->PrepareToDraw(gfx::Vector2d(), gfx::Rect()); | |
| 85 } | |
| 86 if (on_draw_count_ == 2u) { | |
| 87 // Step 2: This onDraw is to introduce the DrawGL that animates the | |
| 88 // webview onto the screen on render thread. End the test when the parent | |
| 89 // draw constraints of BVR is updated to initial constraints. | |
| 90 browser_view_renderer_->PrepareToDraw(gfx::Vector2d(), gfx::Rect()); | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 void DidOnDraw(bool success) override { | |
| 95 EXPECT_TRUE(success); | |
| 96 on_draw_count_++; | |
| 97 if (on_draw_count_ == 2u) { | |
| 98 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
 | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 bool WillDrawOnRT(SharedRendererState* functor, | |
| 103 AwDrawGLInfo* draw_info) override { | |
| 104 if (draw_gl_count_on_rt_ == 1u) { | |
| 105 draw_gl_count_on_rt_++; | |
| 106 return false; | |
| 107 } | |
| 108 | |
| 109 draw_info->width = window_->surface_size().width(); | |
| 110 draw_info->height = window_->surface_size().height(); | |
| 111 draw_info->is_layer = false; | |
| 112 | |
| 113 gfx::Transform transform; | |
| 114 if (draw_gl_count_on_rt_ == 0u) | |
| 115 transform = new_constraints_.transform; | |
| 116 | |
| 117 transform.matrix().asColMajorf(draw_info->transform); | |
| 118 return true; | |
| 119 } | |
| 120 | |
| 121 void DidDrawOnRT(SharedRendererState* functor) override { | |
| 122 draw_gl_count_on_rt_++; | |
| 123 } | |
| 124 | |
| 125 bool DrawConstraintsEquals( | |
| 126 const ParentCompositorDrawConstraints& constraints1, | |
| 127 const ParentCompositorDrawConstraints& constraints2) { | |
| 128 if (constraints1.is_layer != constraints2.is_layer || | |
| 129 constraints1.transform != constraints2.transform) | |
| 130 return false; | |
| 131 | |
| 132 return !constraints1.is_layer || | |
| 133 constraints1.surface_rect == constraints2.surface_rect; | |
| 134 } | |
| 135 | |
| 136 void ParentDrawConstraintsUpdated( | |
| 137 const ParentCompositorDrawConstraints& constraints) override { | |
| 138 switch (on_draw_count_) { | |
| 139 case 1u: | |
| 140 EXPECT_TRUE(DrawConstraintsEquals(constraints, new_constraints_)); | |
| 141 browser_view_renderer_->SetContinuousInvalidate(false); | |
| 142 break; | |
| 143 case 3u: | |
| 144 EXPECT_TRUE(DrawConstraintsEquals(constraints, initial_constraints_)); | |
| 145 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
 | |
| 146 EndTest(); | |
| 147 break; | |
| 148 default: | |
| 149 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.
 | |
| 150 } | |
| 151 } | |
| 152 | |
| 153 private: | |
| 154 size_t on_draw_count_; | |
| 155 size_t draw_gl_count_on_rt_; | |
| 156 ParentCompositorDrawConstraints initial_constraints_; | |
| 157 ParentCompositorDrawConstraints new_constraints_; | |
| 158 }; | |
| 159 | |
| 160 RENDERING_TEST_F(TestAnimateInAndOutOfScreen); | |
| 161 | |
| 62 } // namespace android_webview | 162 } // namespace android_webview | 
| OLD | NEW |