 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/test/rendering_test.h" | 6 #include "android_webview/browser/test/rendering_test.h" | 
| 7 | 7 | 
| 8 namespace android_webview { | 8 namespace android_webview { | 
| 9 | 9 | 
| 10 class SmokeTest : public RenderingTest { | 10 class SmokeTest : public RenderingTest { | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 | 52 | 
| 53 void DidDrawOnRT(SharedRendererState* functor) override { | 53 void DidDrawOnRT(SharedRendererState* functor) override { | 
| 54 EndTest(); | 54 EndTest(); | 
| 55 } | 55 } | 
| 56 private: | 56 private: | 
| 57 size_t on_draw_count_; | 57 size_t on_draw_count_; | 
| 58 }; | 58 }; | 
| 59 | 59 | 
| 60 RENDERING_TEST_F(ClearViewTest); | 60 RENDERING_TEST_F(ClearViewTest); | 
| 61 | 61 | 
| 62 class TestAnimateInAndOutOfScreen : public RenderingTest { | |
| 63 public: | |
| 64 TestAnimateInAndOutOfScreen() : on_draw_count_(0u) {} | |
| 65 | |
| 66 void StartTest() override { | |
| 67 new_constraints_ = ParentCompositorDrawConstraints( | |
| 68 false, gfx::Transform(), gfx::Rect(window_->surface_size())); | |
| 69 new_constraints_.transform.Scale(2.0, 2.0); | |
| 70 browser_view_renderer_->SetContinuousInvalidate(true); | |
| 71 } | |
| 72 | |
| 73 void WillOnDraw() override { | |
| 74 if (on_draw_count_ == 0u) { | |
| 75 // Step 0: A single onDraw on screen. The parent draw constraints | |
| 76 // of the BVR will updated to be the initial constraints. | |
| 77 browser_view_renderer_->SetContinuousInvalidate(false); | |
| 78 } | |
| 79 if (on_draw_count_ == 1u) { | |
| 80 // Step 1: A single onDrraw off screen. The parent draw constraints of the | |
| 81 // BVR will be updated to the new constraints. | |
| 82 browser_view_renderer_->PrepareToDraw(gfx::Vector2d(), gfx::Rect()); | |
| 83 } | |
| 84 if (on_draw_count_ == 2u) { | |
| 85 // Step 2: A single onDraw onscreen. End the test when the parent | |
| 86 // draw constraints of BVR is updated to initial constraints. | |
| 87 } | |
| 88 } | |
| 89 | |
| 90 void DidOnDraw(bool success) override { | |
| 91 EXPECT_TRUE(success); | |
| 92 on_draw_count_++; | |
| 93 if (on_draw_count_ == 2u) { | |
| 94 PostInvalidate(); | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 bool WillDrawOnRT(SharedRendererState* functor, | |
| 99 AwDrawGLInfo& draw_info) override { | |
| 100 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.
 | |
| 101 return false; | |
| 102 | |
| 103 draw_info.width = window_->surface_size().width(); | |
| 104 draw_info.height = window_->surface_size().height(); | |
| 105 draw_info.is_layer = false; | |
| 106 | |
| 107 gfx::Transform transform; | |
| 108 if (on_draw_count_ == 1u) | |
| 109 transform = new_constraints_.transform; | |
| 110 | |
| 111 transform.matrix().asColMajorf(draw_info.transform); | |
| 112 return true; | |
| 113 } | |
| 114 | |
| 115 bool DrawConstraintsEquals( | |
| 116 const ParentCompositorDrawConstraints& constraints1, | |
| 117 const ParentCompositorDrawConstraints& constraints2) { | |
| 118 if (constraints1.is_layer != constraints2.is_layer || | |
| 119 constraints1.transform != constraints2.transform) | |
| 120 return false; | |
| 121 | |
| 122 return !constraints1.is_layer || | |
| 123 constraints1.surface_rect == constraints2.surface_rect; | |
| 124 } | |
| 125 | |
| 126 void ParentDrawConstraintsUpdated( | |
| 127 const ParentCompositorDrawConstraints& constraints) override { | |
| 128 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
 | |
| 129 EXPECT_TRUE(DrawConstraintsEquals(constraints, new_constraints_)); | |
| 130 return; | |
| 131 } | |
| 132 | |
| 133 EXPECT_NE(on_draw_count_, 2u); | |
| 134 | |
| 135 if (on_draw_count_ == 3u) { | |
| 136 EXPECT_TRUE(DrawConstraintsEquals(constraints, initial_constraints_)); | |
| 137 browser_view_renderer_->SetContinuousInvalidate(false); | |
| 138 EndTest(); | |
| 139 return; | |
| 140 } | |
| 141 } | |
| 142 | |
| 143 private: | |
| 144 size_t on_draw_count_; | |
| 145 ParentCompositorDrawConstraints initial_constraints_; | |
| 146 ParentCompositorDrawConstraints new_constraints_; | |
| 147 }; | |
| 148 | |
| 149 RENDERING_TEST_F(TestAnimateInAndOutOfScreen); | |
| 150 | |
| 62 } // namespace android_webview | 151 } // namespace android_webview | 
| OLD | NEW |