Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1923)

Unified Diff: android_webview/browser/browser_view_renderer_unittest.cc

Issue 1002013003: Unit Test for WebView animating in and out of screen (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: new test Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a65aedb910a076312cfbe62b12012106d6385f99 100644
--- a/android_webview/browser/browser_view_renderer_unittest.cc
+++ b/android_webview/browser/browser_view_renderer_unittest.cc
@@ -59,4 +59,80 @@ class ClearViewTest : public RenderingTest {
RENDERING_TEST_F(ClearViewTest);
+// - The first ondraw is onscreen. It reads the default draw constraints. The
+// first DrawGL will post the new constraints to UI thread.
+// - The second onDraw is offscreen with an empty global visible rect. It reads
+// the new draw constraints. The second DrawGL will be skipped because the
+// WebView is offscreen.
+// - The third onDraw is the result of force invalidate from the second onDraw.
+// It reads the same draw constraints as the second onDraw does.
+class TestAnimateInAndOutOfScreen : public RenderingTest {
+ public:
+ TestAnimateInAndOutOfScreen() : on_draw_count_(0u) {
+ new_transform_.Scale(2.0, 2.0);
+ }
+
+ void StartTest() override {
+ browser_view_renderer_->SetContinuousInvalidate(true);
+ }
+
+ void WillOnDraw() override {
+ on_draw_count_++;
+ if (on_draw_count_ == 2u) {
+ browser_view_renderer_->PrepareToDraw(gfx::Vector2d(), gfx::Rect());
+ browser_view_renderer_->SetContinuousInvalidate(false);
boliu 2015/03/13 23:51:55 Hmm, doesn't posting of the next OnDrawHardware st
hush (inactive) 2015/03/16 18:19:21 It does not race I think. Both are post tasks to U
boliu 2015/03/16 20:25:08 PostInvalidate happen at end of BVR::OnDrawHardwar
hush (inactive) 2015/03/17 18:26:45 Okay. I added a callback in browser view renderer
+ }
+ }
+
+ void DidOnDraw(bool success) override {
+ ParentCompositorDrawConstraints initial_constraints;
+ ParentCompositorDrawConstraints new_constraints(
+ false, new_transform_, gfx::Rect(window_->surface_size()));
+ EXPECT_TRUE(success);
+ if (on_draw_count_ == 1u) {
+ EXPECT_TRUE(initial_constraints.Equals(
+ browser_view_renderer_->parent_draw_constraints_for_testing()));
+ }
+
+ if (on_draw_count_ == 2u) {
+ EXPECT_TRUE(new_constraints.Equals(
+ browser_view_renderer_->parent_draw_constraints_for_testing()));
+ }
+
+ if (on_draw_count_ == 3u) {
+ EXPECT_TRUE(new_constraints.Equals(
+ browser_view_renderer_->parent_draw_constraints_for_testing()));
boliu 2015/03/13 23:51:55 DrawGL for on_draw_count_ == 3 uses the identity m
hush (inactive) 2015/03/16 18:19:21 Well.. the 4th onDraw will early out in "Previous
boliu 2015/03/16 20:25:08 Hmm. Let's not change production code just to make
hush (inactive) 2015/03/17 18:26:45 Done.
+ EndTest();
+ }
+ }
+
+ void SetParentDrawConstraints(AwDrawGLInfo& draw_info) override {
+ 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_transform_;
+
+ transform.matrix().asColMajorf(draw_info.transform);
+ }
+
+ bool WillDrawOnRT(SharedRendererState* functor) override {
+ // The 2nd onDraw gets skipped because the WebView is offscreen.
+ if (on_draw_count_ == 2u)
+ return false;
+
+ return true;
+ }
+
+ bool WillWaitForModeDrawToFinish() override { return true; }
+
+ private:
+ size_t on_draw_count_;
+ gfx::Transform new_transform_;
+};
+
+RENDERING_TEST_F(TestAnimateInAndOutOfScreen);
+
} // namespace android_webview

Powered by Google App Engine
This is Rietveld 408576698