Bug 1337990 - Introduce a PanOptions enumeration for passing options to APZCTesterBase::Pan(). r=kats draft
authorBotond Ballo <botond@mozilla.com>
Fri, 10 Feb 2017 16:08:12 -0500
changeset 484101 83ef27a26c36f3b7bf72e92ca64a4628a2d6eb9f
parent 479455 12c02bf624c48903b155428f7c8a419ba7a333a6
child 484102 d758db722edb6bcbfc17824f0ce4aefa5a7c66ff
push id45398
push userbballo@mozilla.com
push dateTue, 14 Feb 2017 21:04:50 +0000
reviewerskats
bugs1337990
milestone54.0a1
Bug 1337990 - Introduce a PanOptions enumeration for passing options to APZCTesterBase::Pan(). r=kats MozReview-Commit-ID: 54UZV54IyfD
gfx/layers/apz/test/gtest/APZTestCommon.h
gfx/layers/apz/test/gtest/TestBasic.cpp
gfx/layers/apz/test/gtest/TestGestureDetector.cpp
gfx/layers/apz/test/gtest/TestScrollHandoff.cpp
--- a/gfx/layers/apz/test/gtest/APZTestCommon.h
+++ b/gfx/layers/apz/test/gtest/APZTestCommon.h
@@ -17,16 +17,17 @@
 
 #include "mozilla/Attributes.h"
 #include "mozilla/layers/AsyncCompositionManager.h" // for ViewTransform
 #include "mozilla/layers/GeckoContentController.h"
 #include "mozilla/layers/CompositorBridgeParent.h"
 #include "mozilla/layers/APZCTreeManager.h"
 #include "mozilla/layers/LayerMetricsWrapper.h"
 #include "mozilla/layers/APZThreadUtils.h"
+#include "mozilla/TypedEnumBits.h"
 #include "mozilla/UniquePtr.h"
 #include "apz/src/AsyncPanZoomController.h"
 #include "apz/src/HitTestingTreeNode.h"
 #include "base/task.h"
 #include "Layers.h"
 #include "TestLayers.h"
 #include "UnitTransforms.h"
 #include "gfxPrefs.h"
@@ -283,43 +284,48 @@ private:
 };
 
 class APZCTesterBase : public ::testing::Test {
 public:
   APZCTesterBase() {
     mcc = new NiceMock<MockContentControllerDelayed>();
   }
 
+  enum class PanOptions {
+    None = 0,
+    KeepFingerDown = 0x1,
+  };
+
   template<class InputReceiver>
   void Tap(const RefPtr<InputReceiver>& aTarget, const ScreenIntPoint& aPoint,
            TimeDuration aTapLength,
            nsEventStatus (*aOutEventStatuses)[2] = nullptr,
            uint64_t* aOutInputBlockId = nullptr);
 
   template<class InputReceiver>
   void TapAndCheckStatus(const RefPtr<InputReceiver>& aTarget,
                          const ScreenIntPoint& aPoint, TimeDuration aTapLength);
 
   template<class InputReceiver>
   void Pan(const RefPtr<InputReceiver>& aTarget,
            const ScreenIntPoint& aTouchStart,
            const ScreenIntPoint& aTouchEnd,
-           bool aKeepFingerDown = false,
+           PanOptions aOptions = PanOptions::None,
            nsTArray<uint32_t>* aAllowedTouchBehaviors = nullptr,
            nsEventStatus (*aOutEventStatuses)[4] = nullptr,
            uint64_t* aOutInputBlockId = nullptr);
 
   /*
    * A version of Pan() that only takes y coordinates rather than (x, y) points
    * for the touch start and end points, and uses 10 for the x coordinates.
    * This is for convenience, as most tests only need to pan in one direction.
   */
   template<class InputReceiver>
   void Pan(const RefPtr<InputReceiver>& aTarget, int aTouchStartY,
-           int aTouchEndY, bool aKeepFingerDown = false,
+           int aTouchEndY, PanOptions aOptions = PanOptions::None,
            nsTArray<uint32_t>* aAllowedTouchBehaviors = nullptr,
            nsEventStatus (*aOutEventStatuses)[4] = nullptr,
            uint64_t* aOutInputBlockId = nullptr);
 
   /*
    * Dispatches mock touch events to the apzc and checks whether apzc properly
    * consumed them and triggered scrolling behavior.
   */
@@ -345,16 +351,18 @@ public:
   void DoubleTapAndCheckStatus(const RefPtr<InputReceiver>& aTarget,
                                const ScreenIntPoint& aPoint,
                                uint64_t (*aOutInputBlockIds)[2] = nullptr);
 
 protected:
   RefPtr<MockContentControllerDelayed> mcc;
 };
 
+MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(APZCTesterBase::PanOptions)
+
 template<class InputReceiver>
 void
 APZCTesterBase::Tap(const RefPtr<InputReceiver>& aTarget,
                     const ScreenIntPoint& aPoint, TimeDuration aTapLength,
                     nsEventStatus (*aOutEventStatuses)[2],
                     uint64_t* aOutInputBlockId)
 {
   // Even if the caller doesn't care about the block id, we need it to set the
@@ -394,17 +402,17 @@ APZCTesterBase::TapAndCheckStatus(const 
   EXPECT_EQ(nsEventStatus_eConsumeDoDefault, statuses[1]);
 }
 
 template<class InputReceiver>
 void
 APZCTesterBase::Pan(const RefPtr<InputReceiver>& aTarget,
                     const ScreenIntPoint& aTouchStart,
                     const ScreenIntPoint& aTouchEnd,
-                    bool aKeepFingerDown,
+                    PanOptions aOptions,
                     nsTArray<uint32_t>* aAllowedTouchBehaviors,
                     nsEventStatus (*aOutEventStatuses)[4],
                     uint64_t* aOutInputBlockId)
 {
   // Reduce the touch start and move tolerance to a tiny value.
   // We can't use a scoped pref because this value might be read at some later
   // time when the events are actually processed, rather than when we deliver
   // them.
@@ -450,53 +458,53 @@ APZCTesterBase::Pan(const RefPtr<InputRe
 
   status = TouchMove(aTarget, aTouchEnd, mcc->Time());
   if (aOutEventStatuses) {
     (*aOutEventStatuses)[2] = status;
   }
 
   mcc->AdvanceBy(TIME_BETWEEN_TOUCH_EVENT);
 
-  if (!aKeepFingerDown) {
+  if (!(aOptions & PanOptions::KeepFingerDown)) {
     status = TouchUp(aTarget, aTouchEnd, mcc->Time());
   } else {
     status = nsEventStatus_eIgnore;
   }
   if (aOutEventStatuses) {
     (*aOutEventStatuses)[3] = status;
   }
 
   // Don't increment the time here. Animations started on touch-up, such as
   // flings, are affected by elapsed time, and we want to be able to sample
   // them immediately after they start, without time having elapsed.
 }
 
 template<class InputReceiver>
 void
 APZCTesterBase::Pan(const RefPtr<InputReceiver>& aTarget,
-                    int aTouchStartY, int aTouchEndY, bool aKeepFingerDown,
+                    int aTouchStartY, int aTouchEndY, PanOptions aOptions,
                     nsTArray<uint32_t>* aAllowedTouchBehaviors,
                     nsEventStatus (*aOutEventStatuses)[4],
                     uint64_t* aOutInputBlockId)
 {
   Pan(aTarget, ScreenIntPoint(10, aTouchStartY), ScreenIntPoint(10, aTouchEndY),
-      aKeepFingerDown, aAllowedTouchBehaviors, aOutEventStatuses, aOutInputBlockId);
+      aOptions, aAllowedTouchBehaviors, aOutEventStatuses, aOutInputBlockId);
 }
 
 template<class InputReceiver>
 void
 APZCTesterBase::PanAndCheckStatus(const RefPtr<InputReceiver>& aTarget,
                                   int aTouchStartY,
                                   int aTouchEndY,
                                   bool aExpectConsumed,
                                   nsTArray<uint32_t>* aAllowedTouchBehaviors,
                                   uint64_t* aOutInputBlockId)
 {
   nsEventStatus statuses[4]; // down, move, move, up
-  Pan(aTarget, aTouchStartY, aTouchEndY, false, aAllowedTouchBehaviors, &statuses, aOutInputBlockId);
+  Pan(aTarget, aTouchStartY, aTouchEndY, PanOptions::None, aAllowedTouchBehaviors, &statuses, aOutInputBlockId);
 
   EXPECT_EQ(nsEventStatus_eConsumeDoDefault, statuses[0]);
 
   nsEventStatus touchMoveStatus;
   if (aExpectConsumed) {
     touchMoveStatus = nsEventStatus_eConsumeDoDefault;
   } else {
     touchMoveStatus = nsEventStatus_eIgnore;
@@ -505,17 +513,17 @@ APZCTesterBase::PanAndCheckStatus(const 
   EXPECT_EQ(touchMoveStatus, statuses[2]);
 }
 
 void
 APZCTesterBase::ApzcPanNoFling(const RefPtr<TestAsyncPanZoomController>& aApzc,
                                int aTouchStartY, int aTouchEndY,
                                uint64_t* aOutInputBlockId)
 {
-  Pan(aApzc, aTouchStartY, aTouchEndY, false, nullptr, nullptr, aOutInputBlockId);
+  Pan(aApzc, aTouchStartY, aTouchEndY, PanOptions::None, nullptr, nullptr, aOutInputBlockId);
   aApzc->CancelAnimation();
 }
 
 template<class InputReceiver>
 void
 APZCTesterBase::DoubleTap(const RefPtr<InputReceiver>& aTarget,
                           const ScreenIntPoint& aPoint,
                           nsEventStatus (*aOutEventStatuses)[4],
--- a/gfx/layers/apz/test/gtest/TestBasic.cpp
+++ b/gfx/layers/apz/test/gtest/TestBasic.cpp
@@ -339,17 +339,17 @@ TEST_F(APZCBasicTester, OverScrollAbort)
 
 TEST_F(APZCBasicTester, OverScrollPanningAbort) {
   SCOPED_GFX_PREF(APZOverscrollEnabled, bool, true);
 
   // Pan sufficiently to hit overscroll behaviour. Keep the finger down so
   // the pan does not end.
   int touchStart = 500;
   int touchEnd = 10;
-  Pan(apzc, touchStart, touchEnd, true); // keep finger down
+  Pan(apzc, touchStart, touchEnd, PanOptions::KeepFingerDown);
   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());
   apzc->AssertStateIsReset();
--- a/gfx/layers/apz/test/gtest/TestGestureDetector.cpp
+++ b/gfx/layers/apz/test/gtest/TestGestureDetector.cpp
@@ -230,17 +230,17 @@ protected:
   void DoFlingStopWithSlowListener(bool aPreventDefault) {
     MakeApzcWaitForMainThread();
 
     int touchStart = 50;
     int touchEnd = 10;
     uint64_t blockId = 0;
 
     // Start the fling down.
-    Pan(apzc, touchStart, touchEnd, false, nullptr, nullptr, &blockId);
+    Pan(apzc, touchStart, touchEnd, PanOptions::None, nullptr, nullptr, &blockId);
     apzc->ConfirmTarget(blockId);
     apzc->ContentReceivedInputBlock(blockId, false);
 
     // Sample the fling a couple of times to ensure it's going.
     ParentLayerPoint point, finalPoint;
     AsyncTransform viewTransform;
     apzc->SampleContentTransformForFrame(&viewTransform, point, TimeDuration::FromMilliseconds(10));
     apzc->SampleContentTransformForFrame(&viewTransform, finalPoint, TimeDuration::FromMilliseconds(10));
--- a/gfx/layers/apz/test/gtest/TestScrollHandoff.cpp
+++ b/gfx/layers/apz/test/gtest/TestScrollHandoff.cpp
@@ -212,17 +212,17 @@ TEST_F(APZScrollHandoffTester, StuckInOv
   SCOPED_GFX_PREF(APZOverscrollEnabled, bool, true);
   SCOPED_GFX_PREF(APZFlingMinVelocityThreshold, float, 0.0f);
 
   CreateScrollHandoffLayerTree1();
 
   TestAsyncPanZoomController* child = ApzcOf(layers[1]);
 
   // Pan, causing the parent APZC to overscroll.
-  Pan(manager, 10, 40, true /* keep finger down */);
+  Pan(manager, 10, 40, PanOptions::KeepFingerDown);
   EXPECT_FALSE(child->IsOverscrolled());
   EXPECT_TRUE(rootApzc->IsOverscrolled());
 
   // Put a second finger down.
   MultiTouchInput secondFingerDown(MultiTouchInput::MULTITOUCH_START, 0, TimeStamp(), 0);
   // Use the same touch identifier for the first touch (0) as Pan(). (A bit hacky.)
   secondFingerDown.mTouches.AppendElement(SingleTouchData(0, ScreenIntPoint(10, 40), ScreenSize(0, 0), 0, 0));
   secondFingerDown.mTouches.AppendElement(SingleTouchData(1, ScreenIntPoint(30, 20), ScreenSize(0, 0), 0, 0));
@@ -250,17 +250,17 @@ TEST_F(APZScrollHandoffTester, StuckInOv
   SCOPED_GFX_PREF(APZOverscrollEnabled, bool, true);
   SCOPED_GFX_PREF(APZFlingMinVelocityThreshold, float, 0.0f);
 
   CreateScrollHandoffLayerTree1();
 
   TestAsyncPanZoomController* child = ApzcOf(layers[1]);
 
   // Pan, causing the parent APZC to overscroll.
-  Pan(manager, 60, 90, true /* keep finger down */);
+  Pan(manager, 60, 90, PanOptions::KeepFingerDown);
   EXPECT_FALSE(child->IsOverscrolled());
   EXPECT_TRUE(rootApzc->IsOverscrolled());
 
   // Put a second finger down.
   MultiTouchInput secondFingerDown(MultiTouchInput::MULTITOUCH_START, 0, TimeStamp(), 0);
   // Use the same touch identifier for the first touch (0) as Pan(). (A bit hacky.)
   secondFingerDown.mTouches.AppendElement(SingleTouchData(0, ScreenIntPoint(10, 40), ScreenSize(0, 0), 0, 0));
   secondFingerDown.mTouches.AppendElement(SingleTouchData(1, ScreenIntPoint(30, 20), ScreenSize(0, 0), 0, 0));
@@ -284,17 +284,17 @@ TEST_F(APZScrollHandoffTester, StuckInOv
   // Enable overscrolling.
   SCOPED_GFX_PREF(APZOverscrollEnabled, bool, true);
 
   CreateScrollHandoffLayerTree1();
 
   TestAsyncPanZoomController* child = ApzcOf(layers[1]);
 
   // Pan, causing the parent APZC to overscroll.
-  Pan(manager, 60, 90, true /* keep finger down */);
+  Pan(manager, 60, 90, PanOptions::KeepFingerDown);
   EXPECT_FALSE(child->IsOverscrolled());
   EXPECT_TRUE(rootApzc->IsOverscrolled());
 
   // Lift the finger, triggering an overscroll animation
   // (but don't allow it to run).
   TouchUp(manager, ScreenIntPoint(10, 90), mcc->Time());
 
   // Put the finger down again, interrupting the animation
@@ -317,17 +317,17 @@ TEST_F(APZScrollHandoffTester, StuckInOv
   // Enable overscrolling.
   SCOPED_GFX_PREF(APZOverscrollEnabled, bool, true);
 
   CreateScrollHandoffLayerTree1();
 
   TestAsyncPanZoomController* child = ApzcOf(layers[1]);
 
   // Pan, causing the parent APZC to overscroll.
-  Pan(manager, 60, 90, true /* keep finger down */);
+  Pan(manager, 60, 90, PanOptions::KeepFingerDown);
   EXPECT_FALSE(child->IsOverscrolled());
   EXPECT_TRUE(rootApzc->IsOverscrolled());
 
   // Lift the finger, triggering an overscroll animation
   // (but don't allow it to run).
   TouchUp(manager, ScreenIntPoint(10, 90), mcc->Time());
 
   // Put the finger down again, interrupting the animation