Bug 1642788 - Ensure APZ gtests set mTimeStamp correctly on events where needed. r=kats
authorBotond Ballo <botond@mozilla.com>
Wed, 03 Jun 2020 16:39:01 +0000
changeset 533723 702cb5d63666fc667d12265e0fb1028230bfdc1c
parent 533722 67ce8c8ddafef497d0599d7bb353219ff176103d
child 533724 430ea4182cefb1b2365d00c8423c9c3390cd9a62
push id37477
push userdluca@mozilla.com
push dateThu, 04 Jun 2020 04:19:27 +0000
treeherdermozilla-central@6fd265574f27 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1642788
milestone79.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 1642788 - Ensure APZ gtests set mTimeStamp correctly on events where needed. r=kats Differential Revision: https://phabricator.services.mozilla.com/D77981
gfx/layers/apz/test/gtest/APZTestCommon.h
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
@@ -40,16 +40,25 @@ using namespace mozilla::layers;
 using ::testing::_;
 using ::testing::AtLeast;
 using ::testing::AtMost;
 using ::testing::InSequence;
 using ::testing::MockFunction;
 using ::testing::NiceMock;
 typedef mozilla::layers::GeckoContentController::TapType TapType;
 
+static TimeStamp GetStartupTime() {
+  static TimeStamp sStartupTime = TimeStamp::Now();
+  return sStartupTime;
+}
+
+inline uint32_t MillisecondsSinceStartup(TimeStamp aTime) {
+  return (aTime - GetStartupTime()).ToMilliseconds();
+}
+
 // Some helper functions for constructing input event objects suitable to be
 // passed either to an APZC (which expects an transformed point), or to an APZTM
 // (which expects an untransformed point). We handle both cases by setting both
 // the transformed and untransformed fields to the same value.
 inline SingleTouchData CreateSingleTouchData(int32_t aIdentifier,
                                              const ScreenIntPoint& aPoint) {
   SingleTouchData touch(aIdentifier, aPoint, ScreenSize(0, 0), 0, 0);
   touch.mLocalScreenPoint = ParentLayerPoint(aPoint.x, aPoint.y);
@@ -62,18 +71,19 @@ inline SingleTouchData CreateSingleTouch
                                              ScreenIntCoord aY) {
   return CreateSingleTouchData(aIdentifier, ScreenIntPoint(aX, aY));
 }
 
 inline PinchGestureInput CreatePinchGestureInput(
     PinchGestureInput::PinchGestureType aType, const ScreenPoint& aFocus,
     float aCurrentSpan, float aPreviousSpan, TimeStamp timestamp) {
   ParentLayerPoint localFocus(aFocus.x, aFocus.y);
-  PinchGestureInput result(aType, 0, timestamp, ExternalPoint(0, 0), aFocus,
-                           aCurrentSpan, aPreviousSpan, 0);
+  PinchGestureInput result(aType, MillisecondsSinceStartup(timestamp),
+                           timestamp, ExternalPoint(0, 0), aFocus, aCurrentSpan,
+                           aPreviousSpan, 0);
   return result;
 }
 
 template <class SetArg, class Storage>
 class ScopedGfxSetting {
  public:
   ScopedGfxSetting(const std::function<SetArg(void)>& aGetPrefFunc,
                    const std::function<void(SetArg)>& aSetPrefFunc, SetArg aVal)
@@ -110,21 +120,16 @@ class ScopedGfxSetting {
       [=]() { return Preferences::GetFloat(prefName); },                      \
       [=](float aPrefValue) { Preferences::SetFloat(prefName, aPrefValue); }, \
       prefValue)
 
 #define SCOPED_GFX_VAR(varBase, varType, varValue)         \
   ScopedGfxSetting<const varType&, varType> var_##varBase( \
       &(gfxVars::varBase), &(gfxVars::Set##varBase), varValue)
 
-static TimeStamp GetStartupTime() {
-  static TimeStamp sStartupTime = TimeStamp::Now();
-  return sStartupTime;
-}
-
 class MockContentController : public GeckoContentController {
  public:
   MOCK_METHOD1(NotifyLayerTransforms, void(const nsTArray<MatrixMessage>&));
   MOCK_METHOD1(RequestContentRepaint, void(const RepaintRequest&));
   MOCK_METHOD2(RequestFlingSnap,
                void(const ScrollableLayerGuid::ViewID& aScrollId,
                     const mozilla::CSSPoint& aDestination));
   MOCK_METHOD2(AcknowledgeScrollUpdate,
@@ -905,13 +910,9 @@ inline FrameMetrics TestFrameMetrics() {
   fm.SetDisplayPort(CSSRect(0, 0, 10, 10));
   fm.SetCompositionBounds(ParentLayerRect(0, 0, 10, 10));
   fm.SetCriticalDisplayPort(CSSRect(0, 0, 10, 10));
   fm.SetScrollableRect(CSSRect(0, 0, 100, 100));
 
   return fm;
 }
 
-inline uint32_t MillisecondsSinceStartup(TimeStamp aTime) {
-  return (aTime - GetStartupTime()).ToMilliseconds();
-}
-
 #endif  // mozilla_layers_APZTestCommon_h
--- a/gfx/layers/apz/test/gtest/TestGestureDetector.cpp
+++ b/gfx/layers/apz/test/gtest/TestGestureDetector.cpp
@@ -148,65 +148,65 @@ TEST_F(APZCGestureDetectorTester, Pan_Wi
   int touchY = 300;
   int panDistance = 20;
 
   int firstFingerId = 0;
   int secondFingerId = firstFingerId + 1;
 
   // Put finger down
   MultiTouchInput mti =
-      MultiTouchInput(MultiTouchInput::MULTITOUCH_START, 0, TimeStamp(), 0);
+      CreateMultiTouchInput(MultiTouchInput::MULTITOUCH_START, mcc->Time());
   mti.mTouches.AppendElement(
       CreateSingleTouchData(firstFingerId, touchX, touchY));
   apzc->ReceiveInputEvent(mti, nullptr);
 
   // Start a pan, break through the threshold
   touchY += 40;
-  mti = MultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, 0, TimeStamp(), 0);
+  mti = CreateMultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, mcc->Time());
   mti.mTouches.AppendElement(
       CreateSingleTouchData(firstFingerId, touchX, touchY));
   apzc->ReceiveInputEvent(mti, nullptr);
 
   // Do an actual pan for a bit
   touchY += panDistance;
-  mti = MultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, 0, TimeStamp(), 0);
+  mti = CreateMultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, mcc->Time());
   mti.mTouches.AppendElement(
       CreateSingleTouchData(firstFingerId, touchX, touchY));
   apzc->ReceiveInputEvent(mti, nullptr);
 
   // Put a second finger down
-  mti = MultiTouchInput(MultiTouchInput::MULTITOUCH_START, 0, TimeStamp(), 0);
+  mti = CreateMultiTouchInput(MultiTouchInput::MULTITOUCH_START, mcc->Time());
   mti.mTouches.AppendElement(
       CreateSingleTouchData(firstFingerId, touchX, touchY));
   mti.mTouches.AppendElement(
       CreateSingleTouchData(secondFingerId, touchX + 10, touchY));
   apzc->ReceiveInputEvent(mti, nullptr);
 
   // Lift the second finger
-  mti = MultiTouchInput(MultiTouchInput::MULTITOUCH_END, 0, TimeStamp(), 0);
+  mti = CreateMultiTouchInput(MultiTouchInput::MULTITOUCH_END, mcc->Time());
   mti.mTouches.AppendElement(
       CreateSingleTouchData(secondFingerId, touchX + 10, touchY));
   apzc->ReceiveInputEvent(mti, nullptr);
 
   // Bust through the threshold again
   touchY += 40;
-  mti = MultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, 0, TimeStamp(), 0);
+  mti = CreateMultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, mcc->Time());
   mti.mTouches.AppendElement(
       CreateSingleTouchData(firstFingerId, touchX, touchY));
   apzc->ReceiveInputEvent(mti, nullptr);
 
   // Do some more actual panning
   touchY += panDistance;
-  mti = MultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, 0, TimeStamp(), 0);
+  mti = CreateMultiTouchInput(MultiTouchInput::MULTITOUCH_MOVE, mcc->Time());
   mti.mTouches.AppendElement(
       CreateSingleTouchData(firstFingerId, touchX, touchY));
   apzc->ReceiveInputEvent(mti, nullptr);
 
   // Lift the first finger
-  mti = MultiTouchInput(MultiTouchInput::MULTITOUCH_END, 0, TimeStamp(), 0);
+  mti = CreateMultiTouchInput(MultiTouchInput::MULTITOUCH_END, mcc->Time());
   mti.mTouches.AppendElement(
       CreateSingleTouchData(firstFingerId, touchX, touchY));
   apzc->ReceiveInputEvent(mti, nullptr);
 
   // Verify that we scrolled
   FrameMetrics finalMetrics = apzc->GetFrameMetrics();
   float zoom = finalMetrics.GetZoom().ToScaleFactor().scale;
   EXPECT_EQ(originalMetrics.GetScrollOffset().y - (panDistance * 2 / zoom),
--- a/gfx/layers/apz/test/gtest/TestScrollHandoff.cpp
+++ b/gfx/layers/apz/test/gtest/TestScrollHandoff.cpp
@@ -283,18 +283,18 @@ TEST_F(APZScrollHandoffTester, StuckInOv
   TestAsyncPanZoomController* child = ApzcOf(layers[1]);
 
   // Pan, causing the parent APZC to overscroll.
   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);
+  MultiTouchInput secondFingerDown =
+      CreateMultiTouchInput(MultiTouchInput::MULTITOUCH_START, mcc->Time());
   // 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));
   manager->ReceiveInputEvent(secondFingerDown);
 
@@ -328,18 +328,18 @@ TEST_F(APZScrollHandoffTester, StuckInOv
   TestAsyncPanZoomController* child = ApzcOf(layers[1]);
 
   // Pan, causing the parent APZC to overscroll.
   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);
+  MultiTouchInput secondFingerDown =
+      CreateMultiTouchInput(MultiTouchInput::MULTITOUCH_START, mcc->Time());
   // 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));
   manager->ReceiveInputEvent(secondFingerDown);