From 9f0a9b18a27e3513c518d4e5e0c06e156cbec998 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Tue, 22 Nov 2022 06:52:50 +0000 Subject: [PATCH] Bug 1794070 - Run the test case listening "wheel" event at the last in browser_test_swipe_gesture.js. r=botond There's a bug (bug 1800022) that wheel event listeners in the browser process badly interact with overscroll even so we'd avoid the bug here. Differential Revision: https://phabricator.services.mozilla.com/D161752 --- widget/tests/browser/browser.ini | 1 + .../browser/browser_test_swipe_gesture.js | 227 +++++++++--------- 2 files changed, 116 insertions(+), 112 deletions(-) diff --git a/widget/tests/browser/browser.ini b/widget/tests/browser/browser.ini index 4767f9c2b90d..c9251a33a429 100644 --- a/widget/tests/browser/browser.ini +++ b/widget/tests/browser/browser.ini @@ -10,6 +10,7 @@ skip-if = os == 'android' run-if = (os == 'mac' || os == 'win' || os == 'linux') skip-if = os == "win" && bits == 32 && !debug # Bug 1759422 + verify # Bug 1800022 support-files = !/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js !/gfx/layers/apz/test/mochitest/apz_test_utils.js diff --git a/widget/tests/browser/browser_test_swipe_gesture.js b/widget/tests/browser/browser_test_swipe_gesture.js index 89888d0326ee..0f501c62d7a6 100644 --- a/widget/tests/browser/browser_test_swipe_gesture.js +++ b/widget/tests/browser/browser_test_swipe_gesture.js @@ -147,118 +147,6 @@ async function panLeftToRightEnd(aElement, aX, aY, aMultiplier) { requestLongerTimeout(2); -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], - ], - }); - - const firstPage = "about:about"; - const secondPage = "about:mozilla"; - const tab = await BrowserTestUtils.openNewForegroundTab( - gBrowser, - firstPage, - true /* waitForLoad */ - ); - - BrowserTestUtils.loadURI(tab.linkedBrowser, secondPage); - await BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, secondPage); - - // Make sure we can go back to the previous page. - ok(gBrowser.webNavigation.canGoBack); - // and we cannot go forward to the next page. - ok(!gBrowser.webNavigation.canGoForward); - - let wheelEventCount = 0; - tab.linkedBrowser.addEventListener("wheel", () => { - wheelEventCount++; - }); - - // Try to navigate forward. - await panRightToLeft(tab.linkedBrowser, 100, 100, 1); - // NOTE: The last endPhase shouldn't fire a wheel event since - // its delta is zero. - is(wheelEventCount, 3, "Received 3 wheel events"); - - await waitForWhile(); - // Make sure any navigation didn't happen. - is(tab.linkedBrowser.currentURI.spec, secondPage); - - // Try to navigate backward. - wheelEventCount = 0; - let startLoadingPromise = BrowserTestUtils.browserStarted( - tab.linkedBrowser, - firstPage - ); - let stoppedLoadingPromise = BrowserTestUtils.browserStopped( - tab.linkedBrowser, - firstPage - ); - await panLeftToRight(tab.linkedBrowser, 100, 100, 1); - // NOTE: We only get a wheel event for the beginPhase, rest of events have - // been captured by the swipe gesture module. - is(wheelEventCount, 1, "Received a wheel event"); - - // Make sure the gesture triggered going back to the previous page. - await Promise.all([startLoadingPromise, stoppedLoadingPromise]); - - ok(gBrowser.webNavigation.canGoForward); - - // Now try to navigate forward again. - wheelEventCount = 0; - startLoadingPromise = BrowserTestUtils.browserStarted( - tab.linkedBrowser, - secondPage - ); - stoppedLoadingPromise = BrowserTestUtils.browserStopped( - tab.linkedBrowser, - secondPage - ); - await panRightToLeft(tab.linkedBrowser, 100, 100, 1); - is(wheelEventCount, 1, "Received a wheel event"); - - await Promise.all([startLoadingPromise, stoppedLoadingPromise]); - - ok(gBrowser.webNavigation.canGoBack); - - // Now try to navigate backward again but with preventDefault-ed event - // handler. - wheelEventCount = 0; - let wheelEventListener = event => { - event.preventDefault(); - }; - tab.linkedBrowser.addEventListener("wheel", wheelEventListener); - await panLeftToRight(tab.linkedBrowser, 100, 100, 1); - is(wheelEventCount, 3, "Received all wheel events"); - - await waitForWhile(); - // Make sure any navigation didn't happen. - is(tab.linkedBrowser.currentURI.spec, secondPage); - - // Now drop the event handler and disable the swipe tracker and try to swipe - // again. - wheelEventCount = 0; - tab.linkedBrowser.removeEventListener("wheel", wheelEventListener); - await SpecialPowers.pushPrefEnv({ - set: [["widget.disable-swipe-tracker", true]], - }); - - await panLeftToRight(tab.linkedBrowser, 100, 100, 1); - is(wheelEventCount, 3, "Received all wheel events"); - - await waitForWhile(); - // Make sure any navigation didn't happen. - is(tab.linkedBrowser.currentURI.spec, secondPage); - - BrowserTestUtils.removeTab(tab); - await SpecialPowers.popPrefEnv(); -}); - add_task(async () => { // Set the default values for an OS that supports swipe to nav, except for // whole-page-pixel-size which varies by OS, we vary it in differente tests @@ -916,3 +804,118 @@ add_task(async () => { await BrowserTestUtils.closeWindow(newWin); 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. +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], + ], + }); + + const firstPage = "about:about"; + const secondPage = "about:mozilla"; + const tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, + firstPage, + true /* waitForLoad */ + ); + + BrowserTestUtils.loadURI(tab.linkedBrowser, secondPage); + await BrowserTestUtils.browserLoaded(tab.linkedBrowser, false, secondPage); + + // Make sure we can go back to the previous page. + ok(gBrowser.webNavigation.canGoBack); + // and we cannot go forward to the next page. + ok(!gBrowser.webNavigation.canGoForward); + + let wheelEventCount = 0; + tab.linkedBrowser.addEventListener("wheel", () => { + wheelEventCount++; + }); + + // Try to navigate forward. + await panRightToLeft(tab.linkedBrowser, 100, 100, 1); + // NOTE: The last endPhase shouldn't fire a wheel event since + // its delta is zero. + is(wheelEventCount, 3, "Received 3 wheel events"); + + await waitForWhile(); + // Make sure any navigation didn't happen. + is(tab.linkedBrowser.currentURI.spec, secondPage); + + // Try to navigate backward. + wheelEventCount = 0; + let startLoadingPromise = BrowserTestUtils.browserStarted( + tab.linkedBrowser, + firstPage + ); + let stoppedLoadingPromise = BrowserTestUtils.browserStopped( + tab.linkedBrowser, + firstPage + ); + await panLeftToRight(tab.linkedBrowser, 100, 100, 1); + // NOTE: We only get a wheel event for the beginPhase, rest of events have + // been captured by the swipe gesture module. + is(wheelEventCount, 1, "Received a wheel event"); + + // Make sure the gesture triggered going back to the previous page. + await Promise.all([startLoadingPromise, stoppedLoadingPromise]); + + ok(gBrowser.webNavigation.canGoForward); + + // Now try to navigate forward again. + wheelEventCount = 0; + startLoadingPromise = BrowserTestUtils.browserStarted( + tab.linkedBrowser, + secondPage + ); + stoppedLoadingPromise = BrowserTestUtils.browserStopped( + tab.linkedBrowser, + secondPage + ); + await panRightToLeft(tab.linkedBrowser, 100, 100, 1); + is(wheelEventCount, 1, "Received a wheel event"); + + await Promise.all([startLoadingPromise, stoppedLoadingPromise]); + + ok(gBrowser.webNavigation.canGoBack); + + // Now try to navigate backward again but with preventDefault-ed event + // handler. + wheelEventCount = 0; + let wheelEventListener = event => { + event.preventDefault(); + }; + tab.linkedBrowser.addEventListener("wheel", wheelEventListener); + await panLeftToRight(tab.linkedBrowser, 100, 100, 1); + is(wheelEventCount, 3, "Received all wheel events"); + + await waitForWhile(); + // Make sure any navigation didn't happen. + is(tab.linkedBrowser.currentURI.spec, secondPage); + + // Now drop the event handler and disable the swipe tracker and try to swipe + // again. + wheelEventCount = 0; + tab.linkedBrowser.removeEventListener("wheel", wheelEventListener); + await SpecialPowers.pushPrefEnv({ + set: [["widget.disable-swipe-tracker", true]], + }); + + await panLeftToRight(tab.linkedBrowser, 100, 100, 1); + is(wheelEventCount, 3, "Received all wheel events"); + + await waitForWhile(); + // Make sure any navigation didn't happen. + is(tab.linkedBrowser.currentURI.spec, secondPage); + + BrowserTestUtils.removeTab(tab); + await SpecialPowers.popPrefEnv(); +});