Bug 1037591 - Split ApzcPan into two so that the status checks are separated. r=botond
authorKartikaya Gupta <kgupta@mozilla.com>
Mon, 14 Jul 2014 19:07:53 -0400
changeset 215872 8a9415c1889a20cbe88728bf5dff371ef63d775d
parent 215871 239a8346e2bbd2bcf67278df0c411af301522142
child 215873 1cfd6719e04a1bb9922a923e7262d2b39134a132
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1037591
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1037591 - Split ApzcPan into two so that the status checks are separated. r=botond
gfx/tests/gtest/TestAsyncPanZoomController.cpp
--- a/gfx/tests/gtest/TestAsyncPanZoomController.cpp
+++ b/gfx/tests/gtest/TestAsyncPanZoomController.cpp
@@ -210,96 +210,124 @@ ApzcTap(AsyncPanZoomController* apzc, in
     mcc->CheckHasDelayedTask();
     mcc->ClearDelayedTask();
   }
   EXPECT_EQ(nsEventStatus_eConsumeNoDefault, status);
   aTime += aTapLength;
   return ApzcUp(apzc, aX, aY, aTime);
 }
 
+static void
+ApzcPan(AsyncPanZoomController* aApzc,
+        TestAPZCTreeManager* aTreeManager,
+        int& aTime,
+        int aTouchStartY,
+        int aTouchEndY,
+        bool aKeepFingerDown = false,
+        nsTArray<uint32_t>* aAllowedTouchBehaviors = nullptr,
+        nsEventStatus (*aOutEventStatuses)[4] = nullptr)
+{
+  const int TIME_BETWEEN_TOUCH_EVENT = 100;
+  const int OVERCOME_TOUCH_TOLERANCE = 100;
+
+  // Since we're passing inputs directly to the APZC instead of going through
+  // the tree manager, we need to build the overscroll handoff chain explicitly
+  // for panning to work correctly.
+  aTreeManager->BuildOverscrollHandoffChain(aApzc);
+
+  // Make sure the move is large enough to not be handled as a tap
+  nsEventStatus status = ApzcDown(aApzc, 10, aTouchStartY + OVERCOME_TOUCH_TOLERANCE, aTime);
+  if (aOutEventStatuses) {
+    (*aOutEventStatuses)[0] = status;
+  }
+
+  aTime += TIME_BETWEEN_TOUCH_EVENT;
+
+  // Allowed touch behaviours must be set after sending touch-start.
+  if (gfxPrefs::TouchActionEnabled() && aAllowedTouchBehaviors) {
+    aApzc->SetAllowedTouchBehavior(*aAllowedTouchBehaviors);
+  }
+
+  MultiTouchInput mti = MultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, aTime, TimeStamp(), 0);
+  mti.mTouches.AppendElement(SingleTouchData(0, ScreenIntPoint(10, aTouchStartY), ScreenSize(0, 0), 0, 0));
+  status = aApzc->ReceiveInputEvent(mti);
+  if (aOutEventStatuses) {
+    (*aOutEventStatuses)[1] = status;
+  }
+
+  aTime += TIME_BETWEEN_TOUCH_EVENT;
+
+  mti = MultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, aTime, TimeStamp(), 0);
+  mti.mTouches.AppendElement(SingleTouchData(0, ScreenIntPoint(10, aTouchEndY), ScreenSize(0, 0), 0, 0));
+  status = aApzc->ReceiveInputEvent(mti);
+  if (aOutEventStatuses) {
+    (*aOutEventStatuses)[2] = status;
+  }
+
+  aTime += TIME_BETWEEN_TOUCH_EVENT;
+
+  if (!aKeepFingerDown) {
+    status = ApzcUp(aApzc, 10, aTouchEndY, aTime);
+  } else {
+    status = -1;
+  }
+  if (aOutEventStatuses) {
+    (*aOutEventStatuses)[3] = status;
+  }
+
+  aTime += TIME_BETWEEN_TOUCH_EVENT;
+
+  // Since we've explicitly built the overscroll handoff chain before
+  // touch-start, we need to explicitly clear it after touch-end.
+  aTreeManager->ClearOverscrollHandoffChain();
+}
+
 /*
  * Dispatches mock touch events to the apzc and checks whether apzc properly
  * consumed them and triggered scrolling behavior.
  */
 static void
-ApzcPan(AsyncPanZoomController* apzc,
-        TestAPZCTreeManager* aTreeManager,
-        int& aTime,
-        int aTouchStartY,
-        int aTouchEndY,
-        bool expectIgnoredPan = false,
-        bool hasTouchListeners = false,
-        nsTArray<uint32_t>* aAllowedTouchBehaviors = nullptr,
-        bool aKeepFingerDown = false)
+ApzcPanAndCheckStatus(AsyncPanZoomController* aApzc,
+                      TestAPZCTreeManager* aTreeManager,
+                      int& aTime,
+                      int aTouchStartY,
+                      int aTouchEndY,
+                      bool expectIgnoredPan,
+                      bool hasTouchListeners,
+                      nsTArray<uint32_t>* aAllowedTouchBehaviors)
 {
-  const int TIME_BETWEEN_TOUCH_EVENT = 100;
-  const int OVERCOME_TOUCH_TOLERANCE = 100;
-  MultiTouchInput mti;
-  nsEventStatus status;
-
-  // Since we're passing inputs directly to the APZC instead of going through
-  // the tree manager, we need to build the overscroll handoff chain explicitly
-  // for panning to work correctly.
-  aTreeManager->BuildOverscrollHandoffChain(apzc);
+  nsEventStatus statuses[4]; // down, move, move, up
+  ApzcPan(aApzc, aTreeManager, aTime, aTouchStartY, aTouchEndY, false, aAllowedTouchBehaviors, &statuses);
 
   nsEventStatus touchStartStatus;
   if (hasTouchListeners) {
     // APZC shouldn't consume the start event now, instead queueing it up
     // waiting for content's response.
     touchStartStatus = nsEventStatus_eIgnore;
   } else {
     // APZC should go into the touching state and therefore consume the event.
     touchStartStatus = nsEventStatus_eConsumeNoDefault;
   }
-
-  // Make sure the move is large enough to not be handled as a tap
-  status = ApzcDown(apzc, 10, aTouchStartY + OVERCOME_TOUCH_TOLERANCE, aTime);
-  aTime += TIME_BETWEEN_TOUCH_EVENT;
-  EXPECT_EQ(touchStartStatus, status);
-  // APZC should be in TOUCHING state
-
-  // Allowed touch behaviours must be set after sending touch-start.
-  if (gfxPrefs::TouchActionEnabled() && aAllowedTouchBehaviors) {
-    apzc->SetAllowedTouchBehavior(*aAllowedTouchBehaviors);
-  }
+  EXPECT_EQ(touchStartStatus, statuses[0]);
 
   nsEventStatus touchMoveStatus;
   if (expectIgnoredPan) {
     // APZC should ignore panning, be in TOUCHING state and therefore return eIgnore.
     // The same applies to all consequent touch move events.
     touchMoveStatus = nsEventStatus_eIgnore;
   } else {
     // APZC should go into the panning state and therefore consume the event.
     touchMoveStatus = nsEventStatus_eConsumeNoDefault;
   }
-
-  mti = MultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, aTime, TimeStamp(), 0);
-  aTime += TIME_BETWEEN_TOUCH_EVENT;
-  mti.mTouches.AppendElement(SingleTouchData(0, ScreenIntPoint(10, aTouchStartY), ScreenSize(0, 0), 0, 0));
-  status = apzc->ReceiveInputEvent(mti);
-  EXPECT_EQ(touchMoveStatus, status);
-
-  mti = MultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, aTime, TimeStamp(), 0);
-  aTime += TIME_BETWEEN_TOUCH_EVENT;
-  mti.mTouches.AppendElement(SingleTouchData(0, ScreenIntPoint(10, aTouchEndY), ScreenSize(0, 0), 0, 0));
-  status = apzc->ReceiveInputEvent(mti);
-  EXPECT_EQ(touchMoveStatus, status);
-
-  if (!aKeepFingerDown) {
-    status = ApzcUp(apzc, 10, aTouchEndY, aTime);
-  }
-  aTime += TIME_BETWEEN_TOUCH_EVENT;
-
-  // Since we've explicitly built the overscroll handoff chain before
-  // touch-start, we need to explicitly clear it after touch-end.
-  aTreeManager->ClearOverscrollHandoffChain();
+  EXPECT_EQ(touchMoveStatus, statuses[1]);
+  EXPECT_EQ(touchMoveStatus, statuses[2]);
 }
 
-static
-void DoPanTest(bool aShouldTriggerScroll, uint32_t aBehavior)
+static void
+DoPanTest(bool aShouldTriggerScroll, uint32_t aBehavior)
 {
   TimeStamp testStartTime = TimeStamp::Now();
   AsyncPanZoomController::SetFrameTime(testStartTime);
 
   nsRefPtr<MockContentController> mcc = new NiceMock<MockContentController>();
   nsRefPtr<TestAPZCTreeManager> tm = new TestAPZCTreeManager();
   nsRefPtr<TestAsyncPanZoomController> apzc = new TestAsyncPanZoomController(0, mcc, tm);
 
@@ -319,29 +347,29 @@ void DoPanTest(bool aShouldTriggerScroll
   int touchEnd = 10;
   ScreenPoint pointOut;
   ViewTransform viewTransformOut;
 
   nsTArray<uint32_t> allowedTouchBehaviors;
   allowedTouchBehaviors.AppendElement(aBehavior);
 
   // Pan down
-  ApzcPan(apzc, tm, time, touchStart, touchEnd, !aShouldTriggerScroll, false, &allowedTouchBehaviors);
+  ApzcPanAndCheckStatus(apzc, tm, time, touchStart, touchEnd, !aShouldTriggerScroll, false, &allowedTouchBehaviors);
   apzc->SampleContentTransformForFrame(testStartTime, &viewTransformOut, pointOut);
 
   if (aShouldTriggerScroll) {
     EXPECT_EQ(ScreenPoint(0, -(touchEnd-touchStart)), pointOut);
     EXPECT_NE(ViewTransform(), viewTransformOut);
   } else {
     EXPECT_EQ(ScreenPoint(), pointOut);
     EXPECT_EQ(ViewTransform(), viewTransformOut);
   }
 
   // Pan back
-  ApzcPan(apzc, tm, time, touchEnd, touchStart, !aShouldTriggerScroll, false, &allowedTouchBehaviors);
+  ApzcPanAndCheckStatus(apzc, tm, time, touchEnd, touchStart, !aShouldTriggerScroll, false, &allowedTouchBehaviors);
   apzc->SampleContentTransformForFrame(testStartTime, &viewTransformOut, pointOut);
 
   EXPECT_EQ(ScreenPoint(), pointOut);
   EXPECT_EQ(ViewTransform(), viewTransformOut);
 
   apzc->Destroy();
 }
 
@@ -750,17 +778,17 @@ TEST_F(AsyncPanZoomControllerTester, Pan
   int touchStart = 50;
   int touchEnd = 10;
   ScreenPoint pointOut;
   ViewTransform viewTransformOut;
 
   // Pan down
   nsTArray<uint32_t> allowedTouchBehaviors;
   allowedTouchBehaviors.AppendElement(mozilla::layers::AllowedTouchBehavior::VERTICAL_PAN);
-  ApzcPan(apzc, tm, time, touchStart, touchEnd, true, true, &allowedTouchBehaviors);
+  ApzcPanAndCheckStatus(apzc, tm, time, touchStart, touchEnd, true, true, &allowedTouchBehaviors);
 
   // Send the signal that content has handled and preventDefaulted the touch
   // events. This flushes the event queue.
   apzc->ContentReceivedTouch(true);
 
   apzc->SampleContentTransformForFrame(testStartTime, &viewTransformOut, pointOut);
   EXPECT_EQ(ScreenPoint(), pointOut);
   EXPECT_EQ(ViewTransform(), viewTransformOut);
@@ -963,17 +991,16 @@ TEST_F(AsyncPanZoomControllerTester, Ove
   apzc->NotifyLayersUpdated(TestFrameMetrics(), true);
 
   // Pan sufficiently to hit overscroll behaviour. Keep the finger down so
   // the pan does not end.
   int time = 0;
   int touchStart = 500;
   int touchEnd = 10;
   ApzcPan(apzc, tm, time, touchStart, touchEnd,
-          false, false, nullptr,   // filling it defaults, wish we had named arguments
           true);                   // keep finger down
   EXPECT_TRUE(apzc->IsOverscrolled());
 
   // Check that calling CancelAnimation() while the user is still panning
   // (and thus no fling or snap-back animation has had a chance to start)
   // clears the overscroll.
   apzc->CancelAnimation();
   EXPECT_FALSE(apzc->IsOverscrolled());