From f6eeba9f7b31ca6fc07a413444dee4219b9310db Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Tue, 7 Mar 2023 03:36:07 +0000 Subject: [PATCH] Bug 1816032 - Schedule a timeout to avoid waiting for the browser gesture responce forever. r=botond The browser mochitest in this change causes a timeout without this fix since the overscroll gutter gets stuck thus we will never get "APZ:TransformEnd". Differential Revision: https://phabricator.services.mozilla.com/D171421 --- gfx/layers/apz/src/InputQueue.cpp | 6 +- .../browser/browser_test_swipe_gesture.js | 62 +++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/gfx/layers/apz/src/InputQueue.cpp b/gfx/layers/apz/src/InputQueue.cpp index 229709aece85..a5c8631d7acc 100644 --- a/gfx/layers/apz/src/InputQueue.cpp +++ b/gfx/layers/apz/src/InputQueue.cpp @@ -454,12 +454,16 @@ APZEventResult InputQueue::ReceivePanGestureInput( mActivePanGestureBlock = block; CancelAnimationsForNewBlock(block); - MaybeRequestContentResponse(aTarget, block); + const bool waitingForContentResponse = + MaybeRequestContentResponse(aTarget, block); if (event.AllowsSwipe() && !CanScrollTargetHorizontally(event, block)) { // We will ask the browser whether this pan event is going to be used for // swipe or not, so we need to wait the response. block->SetNeedsToWaitForBrowserGestureResponse(true); + if (!waitingForContentResponse) { + ScheduleMainThreadTimeout(aTarget, block); + } if (aFlags.mTargetConfirmed) { // This event may trigger a swipe gesture, depending on what our caller // wants to do it. We need to suspend handling of this block until we diff --git a/widget/tests/browser/browser_test_swipe_gesture.js b/widget/tests/browser/browser_test_swipe_gesture.js index 1680c56465a1..be9fc5c5889a 100644 --- a/widget/tests/browser/browser_test_swipe_gesture.js +++ b/widget/tests/browser/browser_test_swipe_gesture.js @@ -1053,6 +1053,68 @@ add_task(async () => { await SpecialPowers.popPrefEnv(); }); +add_task(async () => { + await SpecialPowers.pushPrefEnv({ + set: [ + ["browser.gesture.swipe.left", "Browser:BackOrBackDuplicate"], + ["browser.gesture.swipe.right", "Browser:ForwardOrForwardDuplicate"], + ["widget.disable-swipe-tracker", false], + ["widget.swipe.velocity-twitch-tolerance", 0.0000001], + ["widget.swipe.success-velocity-contribution", 0.5], + ["apz.overscroll.enabled", true], + ["apz.content_response_timeout", 0], + ], + }); + + const tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + "about:about", + true /* waitForLoad */ + ); + + const URL_ROOT = getRootDirectory(gTestPath).replace( + "chrome://mochitests/content/", + "http://mochi.test:8888/" + ); + + // Load a horizontal scrollable content. + BrowserTestUtils.loadURIString( + tab.linkedBrowser, + URL_ROOT + "helper_swipe_gesture.html" + ); + await BrowserTestUtils.browserLoaded( + tab.linkedBrowser, + false /* includeSubFrames */, + URL_ROOT + "helper_swipe_gesture.html" + ); + + // Make sure we can go back to the previous page. + ok(gBrowser.webNavigation.canGoBack); + + // Shift the horizontal scroll position slightly to make the content + // overscrollable. + await SpecialPowers.spawn(tab.linkedBrowser, [], async () => { + content.document.documentElement.scrollLeft = 1; + await content.wrappedJSObject.promiseApzFlushedRepaints(); + }); + + // Swipe horizontally to overscroll. + await panLeftToRight(tab.linkedBrowser, 1, 100, 1); + + // Swipe again over the overscroll gutter. + await panLeftToRight(tab.linkedBrowser, 1, 100, 1); + + // Wait the overscroll gutter is restored. + await SpecialPowers.spawn(tab.linkedBrowser, [], async () => { + // For some reasons promiseTransformEnd() causes "Uncaught exception in + // test bound". + await content.wrappedJSObject.promiseTopic("APZ:TransformEnd"); + }); + + BrowserTestUtils.removeTab(tab); + await SpecialPowers.popPrefEnv(); +}); + // NOTE: This test listens wheel events so that it causes an overscroll issue // (bug 1800022). To avoid the bug, we need to run this test case at the end // of this file.