From 27d6b966c4836687b7779001bce913f0fdb8a7e0 Mon Sep 17 00:00:00 2001 From: Botond Ballo Date: Mon, 12 Sep 2022 07:25:06 +0000 Subject: [PATCH] Bug 1786452 - Add a gtest. r=hiro Differential Revision: https://phabricator.services.mozilla.com/D156767 --- gfx/layers/apz/test/gtest/APZTestCommon.h | 4 +++ gfx/layers/apz/test/gtest/TestOverscroll.cpp | 36 ++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/gfx/layers/apz/test/gtest/APZTestCommon.h b/gfx/layers/apz/test/gtest/APZTestCommon.h index b5b4c1f92c7c..a05836f59c7b 100644 --- a/gfx/layers/apz/test/gtest/APZTestCommon.h +++ b/gfx/layers/apz/test/gtest/APZTestCommon.h @@ -156,6 +156,10 @@ class MockContentController : public GeckoContentController { MOCK_METHOD1(CancelAutoscroll, void(const ScrollableLayerGuid&)); MOCK_METHOD2(NotifyScaleGestureComplete, void(const ScrollableLayerGuid&, float aScale)); + MOCK_METHOD4(UpdateOverscrollVelocity, + void(const ScrollableLayerGuid&, float, float, bool)); + MOCK_METHOD4(UpdateOverscrollOffset, + void(const ScrollableLayerGuid&, float, float, bool)); }; class MockContentControllerDelayed : public MockContentController { diff --git a/gfx/layers/apz/test/gtest/TestOverscroll.cpp b/gfx/layers/apz/test/gtest/TestOverscroll.cpp index 972cfdf442c9..59df3d06d4cf 100644 --- a/gfx/layers/apz/test/gtest/TestOverscroll.cpp +++ b/gfx/layers/apz/test/gtest/TestOverscroll.cpp @@ -1599,6 +1599,42 @@ TEST_F(APZCOverscrollTester, SmallAmountOfOverscroll) { } #endif +#ifdef MOZ_WIDGET_ANDROID // Only applies to WidgetOverscrollEffect +TEST_F(APZCOverscrollTester, StuckInOverscroll_Bug1786452) { + SCOPED_GFX_PREF_BOOL("apz.overscroll.enabled", true); + + ScrollMetadata metadata; + FrameMetrics& metrics = metadata.GetMetrics(); + metrics.SetCompositionBounds(ParentLayerRect(0, 0, 100, 100)); + metrics.SetScrollableRect(CSSRect(0, 0, 100, 1000)); + + // Over the course of the test, expect one or more calls to + // UpdateOverscrollOffset(), followed by a call to UpdateOverscrollVelocity(). + // The latter ensures the widget has a chance to end its overscroll effect. + InSequence s; + EXPECT_CALL(*mcc, UpdateOverscrollOffset(_, _, _, _)).Times(AtLeast(1)); + EXPECT_CALL(*mcc, UpdateOverscrollVelocity(_, _, _, _)).Times(1); + + // Pan into overscroll, keeping the finger down + ScreenIntPoint startPoint(10, 500); + ScreenIntPoint endPoint(10, 10); + Pan(apzc, startPoint, endPoint, PanOptions::KeepFingerDown); + EXPECT_TRUE(apzc->IsOverscrolled()); + + // Linger a while to cause the velocity to drop to very low or zero + mcc->AdvanceByMillis(100); + TouchMove(apzc, endPoint, mcc->Time()); + EXPECT_LT(apzc->GetVelocityVector().Length(), + StaticPrefs::apz_fling_min_velocity_threshold()); + EXPECT_TRUE(apzc->IsOverscrolled()); + + // Lift the finger + mcc->AdvanceByMillis(20); + TouchUp(apzc, endPoint, mcc->Time()); + EXPECT_FALSE(apzc->IsOverscrolled()); +} +#endif + class APZCOverscrollTesterMock : public APZCTreeManagerTester { public: APZCOverscrollTesterMock() { CreateMockHitTester(); }