Bug 1348786 - Make browser_test_swipe_gesture.js work on Windows. r=tnikkel

Differential Revision: https://phabricator.services.mozilla.com/D134639
This commit is contained in:
Hiroyuki Ikezoe 2022-01-05 09:08:08 +00:00
Родитель 671448031d
Коммит b7ef828313
3 изменённых файлов: 93 добавлений и 30 удалений

Просмотреть файл

@ -469,6 +469,36 @@ async function synthesizeNativePanGestureEvent(
return true;
}
// Sends a native touchpad pan event.
// NOTE: This works only on Windows.
// You can specify nsIDOMWindowUtils.PHASE_BEGIN, PHASE_UPDATE and PHASE_END
// for |aPhase|.
async function promiseNativeTouchpadPan(
aTarget,
aX,
aY,
aDeltaX,
aDeltaY,
aPhase
) {
if (getPlatform() != "windows") {
throw new Error(
`promiseNativeTouchpadPan doesn't work on ${getPlatform()}`
);
}
let pt = await coordinatesRelativeToScreen({
offsetX: aX,
offsetY: aY,
target: aTarget,
});
const utils = utilsForTarget(aTarget);
utils.sendNativeTouchpadPan(aPhase, pt.x, pt.y, aDeltaX, aDeltaY, 0);
return promiseFrame();
}
// Synthesizes a native pan gesture event and resolve the returned promise once the
// request has been successfully made to the OS.
function promiseNativePanGestureEventAndWaitForObserver(

Просмотреть файл

@ -1,6 +1,7 @@
[browser_test_clipboardcache.js]
skip-if = os == 'android' || (os == 'linux' && ccov) || tsan # Bug 1613516, the test consistently timeouts on Linux coverage builds.
[browser_test_swipe_gesture.js]
run-if = (os == 'mac')
run-if = (os == 'mac' || os == 'win')
support-files =
!/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js
!/gfx/layers/apz/test/mochitest/apz_test_utils.js

Просмотреть файл

@ -4,6 +4,11 @@
"use strict";
Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/gfx/layers/apz/test/mochitest/apz_test_utils.js",
this
);
Services.scriptloader.loadSubScript(
"chrome://mochitests/content/browser/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js",
this
@ -15,78 +20,105 @@ function waitForWhile() {
});
}
// From https://developer.apple.com/documentation/coregraphics/cgscrollphase/kcgscrollphasebegan?language=occ , etc.
const kCGScrollPhaseBegan = 1;
const kCGScrollPhaseChanged = 2;
const kCGScrollPhaseEnded = 4;
const NativePanHandlerForWindows = {
beginPhase: SpecialPowers.DOMWindowUtils.PHASE_BEGIN,
updatePhase: SpecialPowers.DOMWindowUtils.PHASE_UPDATE,
endPhase: SpecialPowers.DOMWindowUtils.PHASE_END,
promiseNativePanEvent: promiseNativeTouchpadPan,
deltaOnRTL: 50,
};
const NativePanHandlerForMac = {
// From https://developer.apple.com/documentation/coregraphics/cgscrollphase/kcgscrollphasebegan?language=occ , etc.
beginPhase: 1, // kCGScrollPhaseBegan
updatePhase: 2, // kCGScrollPhaseChanged
endPhase: 4, // kCGScrollPhaseEnded
promiseNativePanEvent: promiseNativePanGestureEventAndWaitForObserver,
deltaOnRTL: -50,
};
function getPanHandler() {
switch (getPlatform()) {
case "windows":
return NativePanHandlerForWindows;
case "mac":
return NativePanHandlerForMac;
default:
throw new Error(
"There's no native pan handler on platform " + getPlatform()
);
}
}
const NativePanHandler = getPanHandler();
async function panRightToLeft(aElement, aX, aY) {
await promiseNativePanGestureEventAndWaitForObserver(
await NativePanHandler.promiseNativePanEvent(
aElement,
aX,
aY,
-50,
NativePanHandler.deltaOnRTL,
0,
kCGScrollPhaseBegan
NativePanHandler.beginPhase
);
await promiseNativePanGestureEventAndWaitForObserver(
await NativePanHandler.promiseNativePanEvent(
aElement,
aX,
aY,
-50,
NativePanHandler.deltaOnRTL,
0,
kCGScrollPhaseChanged
NativePanHandler.updatePhase
);
await promiseNativePanGestureEventAndWaitForObserver(
await NativePanHandler.promiseNativePanEvent(
aElement,
aX,
aY,
-50,
NativePanHandler.deltaOnRTL,
0,
kCGScrollPhaseChanged
NativePanHandler.updatePhase
);
await promiseNativePanGestureEventAndWaitForObserver(
await NativePanHandler.promiseNativePanEvent(
aElement,
aX,
aY,
0,
0,
kCGScrollPhaseEnded
NativePanHandler.endPhase
);
}
async function panLeftToRight(aElement, aX, aY) {
await promiseNativePanGestureEventAndWaitForObserver(
await NativePanHandler.promiseNativePanEvent(
aElement,
aX,
aY,
50,
-NativePanHandler.deltaOnRTL,
0,
kCGScrollPhaseBegan
NativePanHandler.beginPhase
);
await promiseNativePanGestureEventAndWaitForObserver(
await NativePanHandler.promiseNativePanEvent(
aElement,
aX,
aY,
50,
-NativePanHandler.deltaOnRTL,
0,
kCGScrollPhaseChanged
NativePanHandler.updatePhase
);
await promiseNativePanGestureEventAndWaitForObserver(
await NativePanHandler.promiseNativePanEvent(
aElement,
aX,
aY,
50,
-NativePanHandler.deltaOnRTL,
0,
kCGScrollPhaseChanged
NativePanHandler.updatePhase
);
await promiseNativePanGestureEventAndWaitForObserver(
await NativePanHandler.promiseNativePanEvent(
aElement,
aX,
aY,
0,
0,
kCGScrollPhaseEnded
NativePanHandler.endPhase
);
}
@ -121,7 +153,7 @@ add_task(async () => {
// Try to navigate forward.
await panRightToLeft(tab.linkedBrowser, 100, 100);
// NOTE: The last kCGScrollPhaseEnded shouldn't fire a wheel event since
// NOTE: The last endPhase shouldn't fire a wheel event since
// its delta is zero.
is(wheelEventCount, 3, "Received 3 wheel events");
@ -140,8 +172,8 @@ add_task(async () => {
firstPage
);
await panLeftToRight(tab.linkedBrowser, 100, 100);
// NOTE: We only get a wheel event for the kCGScrollPhaseBegan, rest of events
// have been captured by the swipe gesture module.
// 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.