Bug 1246290 - Add a simple gtest to exercise the force-disabled-APZ codepaths. r=botond
authorKartikaya Gupta <kgupta@mozilla.com>
Sun, 03 Apr 2016 13:13:59 -0400
changeset 291519 b0ebc66fa9bb
parent 291518 e76831655536
child 291520 57cc6679cc66
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1246290
milestone48.0a1
Bug 1246290 - Add a simple gtest to exercise the force-disabled-APZ codepaths. r=botond MozReview-Commit-ID: AN5HOPgj1Tr
gfx/layers/apz/test/gtest/TestHitTesting.cpp
--- a/gfx/layers/apz/test/gtest/TestHitTesting.cpp
+++ b/gfx/layers/apz/test/gtest/TestHitTesting.cpp
@@ -53,16 +53,22 @@ protected:
     };
     root = CreateLayerTree(layerTreeSyntax, layerVisibleRegion, transforms, lm, layers);
 
     SetScrollableFrameMetrics(root, FrameMetrics::START_SCROLL_ID, CSSRect(0, 0, 200, 200));
     SetScrollableFrameMetrics(layers[1], FrameMetrics::START_SCROLL_ID + 1, CSSRect(0, 0, 80, 80));
     SetScrollableFrameMetrics(layers[3], FrameMetrics::START_SCROLL_ID + 2, CSSRect(0, 0, 80, 80));
   }
 
+  void DisableApzOn(Layer* aLayer) {
+    ScrollMetadata m = aLayer->GetScrollMetadata(0);
+    m.GetMetrics().SetForceDisableApz(true);
+    aLayer->SetScrollMetadata(m);
+  }
+
   void CreateComplexMultiLayerTree() {
     const char* layerTreeSyntax = "c(tc(t)tc(c(t)tt))";
     // LayerID                     0 12 3 45 6 7 89
     nsIntRegion layerVisibleRegion[] = {
       nsIntRegion(IntRect(0,0,300,400)),      // root(0)
       nsIntRegion(IntRect(0,0,100,100)),      // thebes(1) in top-left
       nsIntRegion(IntRect(50,50,200,300)),    // container(2) centered in root(0)
       nsIntRegion(IntRect(50,50,200,300)),    // thebes(3) fully occupying parent container(2)
@@ -448,16 +454,58 @@ TEST_F(APZHitTestingTester, TestRepaintF
     EXPECT_EQ((i + 1) * 10, point.y);
     EXPECT_EQ(0, viewTransform.mTranslation.x);
     EXPECT_EQ((i + 1) * -10, viewTransform.mTranslation.y);
 
     mcc->AdvanceByMillis(5);
   }
 }
 
+TEST_F(APZHitTestingTester, TestForceDisableApz) {
+  CreateSimpleScrollingLayer();
+  DisableApzOn(root);
+  ScopedLayerTreeRegistration registration(manager, 0, root, mcc);
+  manager->UpdateHitTestingTree(nullptr, root, false, 0, 0);
+  TestAsyncPanZoomController* apzcroot = ApzcOf(root);
+
+  ScreenPoint origin(100, 50);
+  ScrollWheelInput swi(MillisecondsSinceStartup(mcc->Time()), mcc->Time(), 0,
+    ScrollWheelInput::SCROLLMODE_INSTANT, ScrollWheelInput::SCROLLDELTA_PIXEL,
+    origin, 0, 10, false);
+  EXPECT_EQ(nsEventStatus_eConsumeDoDefault, manager->ReceiveInputEvent(swi, nullptr, nullptr));
+  EXPECT_EQ(origin, swi.mOrigin);
+
+  AsyncTransform viewTransform;
+  ParentLayerPoint point;
+  apzcroot->SampleContentTransformForFrame(&viewTransform, point);
+  // Since APZ is force-disabled, we expect to see the async transform via
+  // the NORMAL AsyncMode, but not via the RESPECT_FORCE_DISABLE AsyncMode.
+  EXPECT_EQ(0, point.x);
+  EXPECT_EQ(10, point.y);
+  EXPECT_EQ(0, viewTransform.mTranslation.x);
+  EXPECT_EQ(-10, viewTransform.mTranslation.y);
+  viewTransform = apzcroot->GetCurrentAsyncTransform(AsyncPanZoomController::RESPECT_FORCE_DISABLE);
+  point = apzcroot->GetCurrentAsyncScrollOffset(AsyncPanZoomController::RESPECT_FORCE_DISABLE);
+  EXPECT_EQ(0, point.x);
+  EXPECT_EQ(0, point.y);
+  EXPECT_EQ(0, viewTransform.mTranslation.x);
+  EXPECT_EQ(0, viewTransform.mTranslation.y);
+
+  mcc->AdvanceByMillis(10);
+
+  // With untransforming events we should get normal behaviour (in this case,
+  // no noticeable untransform, because the repaint request already got
+  // flushed).
+  swi = ScrollWheelInput(MillisecondsSinceStartup(mcc->Time()), mcc->Time(), 0,
+    ScrollWheelInput::SCROLLMODE_INSTANT, ScrollWheelInput::SCROLLDELTA_PIXEL,
+    origin, 0, 0, false);
+  EXPECT_EQ(nsEventStatus_eConsumeDoDefault, manager->ReceiveInputEvent(swi, nullptr, nullptr));
+  EXPECT_EQ(origin, swi.mOrigin);
+}
+
 TEST_F(APZHitTestingTester, Bug1148350) {
   CreateBug1148350LayerTree();
   ScopedLayerTreeRegistration registration(manager, 0, root, mcc);
   manager->UpdateHitTestingTree(nullptr, root, false, 0, 0);
 
   MockFunction<void(std::string checkPointName)> check;
   {
     InSequence s;