зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1691622 - part 1: Make `synthesizeNativeMouseClick` take an `Object` instead of multiple arguments for synthesizing events r=smaug
In these days, API should take an `Object` instead of multiple arguments since the callers look like using "named" arguments and this allows to add new optional arguments with changing not all callers. This patch also changes similar API for APZ aware tests for keeping consistent style for their users. Differential Revision: https://phabricator.services.mozilla.com/D105755
This commit is contained in:
Родитель
97e19087ff
Коммит
7242445ca1
|
@ -74,7 +74,7 @@ function runTests() {
|
|||
synthesizeNativeMouseMove(target0, 10, 10, () => {
|
||||
synthesizeNativeMouseMove(target0, 15, 15, () => {
|
||||
synthesizeNativeMouseMove(target0, 20, 20, () => {
|
||||
synthesizeNativeMouseClick(target0, 20, 20);
|
||||
synthesizeNativeMouseClick({ target: target0, offsetX: 20, offsetY: 20 });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -678,24 +678,34 @@ function promiseNativeMouseEvent(aTarget, aX, aY, aType) {
|
|||
});
|
||||
}
|
||||
|
||||
function synthesizeNativeClick(aElement, aX, aY, aObserver = null) {
|
||||
var pt = coordinatesRelativeToScreen(aX, aY, aElement);
|
||||
var utils = SpecialPowers.getDOMWindowUtils(
|
||||
aElement.ownerDocument.defaultView
|
||||
function synthesizeNativeMouseClickWithAPZ(aParams, aObserver = null) {
|
||||
if (aParams.win !== undefined) {
|
||||
throw Error(
|
||||
"Are you trying to use EventUtils' API? `win` won't be used with synthesizeNativeMouseClickWithAPZ."
|
||||
);
|
||||
}
|
||||
const {
|
||||
target, // Origin of offsetX and offsetY, must be an element
|
||||
offsetX, // X offset in `target`
|
||||
offsetY, // Y offset in `target`
|
||||
} = aParams;
|
||||
const pt = coordinatesRelativeToScreen(offsetX, offsetY, target);
|
||||
const utils = SpecialPowers.getDOMWindowUtils(
|
||||
target.ownerDocument.defaultView
|
||||
);
|
||||
utils.sendNativeMouseEvent(
|
||||
pt.x,
|
||||
pt.y,
|
||||
nativeMouseDownEventMsg(),
|
||||
0,
|
||||
aElement,
|
||||
target,
|
||||
function() {
|
||||
utils.sendNativeMouseEvent(
|
||||
pt.x,
|
||||
pt.y,
|
||||
nativeMouseUpEventMsg(),
|
||||
0,
|
||||
aElement,
|
||||
target,
|
||||
aObserver
|
||||
);
|
||||
}
|
||||
|
@ -703,20 +713,19 @@ function synthesizeNativeClick(aElement, aX, aY, aObserver = null) {
|
|||
return true;
|
||||
}
|
||||
|
||||
// Promise-returning variant of synthesizeNativeClick.
|
||||
function promiseNativeClick(aElement, aX, aY) {
|
||||
// Promise-returning variant of synthesizeNativeMouseClickWithAPZ.
|
||||
function promiseNativeMouseClickWithAPZ(aParams) {
|
||||
return new Promise(resolve => {
|
||||
synthesizeNativeClick(aElement, aX, aY, resolve);
|
||||
synthesizeNativeMouseClickWithAPZ(aParams, resolve);
|
||||
});
|
||||
}
|
||||
|
||||
function synthesizeNativeClickAndWaitForClickEvent(
|
||||
aElement,
|
||||
aX,
|
||||
aY,
|
||||
aCallback
|
||||
// See synthesizeNativeMouseClickWithAPZ for the detail of aParams.
|
||||
function synthesizeNativeMouseClickWithAPZAndWaitForClickEvent(
|
||||
aParams,
|
||||
aCallback = null
|
||||
) {
|
||||
var targetWindow = windowForTarget(aElement);
|
||||
const targetWindow = windowForTarget(aParams.target);
|
||||
targetWindow.addEventListener(
|
||||
"click",
|
||||
function(e) {
|
||||
|
@ -724,13 +733,13 @@ function synthesizeNativeClickAndWaitForClickEvent(
|
|||
},
|
||||
{ capture: true, once: true }
|
||||
);
|
||||
return synthesizeNativeClick(aElement, aX, aY);
|
||||
return synthesizeNativeMouseClickWithAPZ(aParams);
|
||||
}
|
||||
|
||||
// Promise-returning variant of synthesizeNativeClickAndWaitForClickEvent
|
||||
function promiseNativeClickAndClickEvent(aElement, aX, aY) {
|
||||
// Promise-returning variant of synthesizeNativeMouseClickWithAPZAndWaitForClickEvent
|
||||
function promiseNativeMouseClickWithAPZAndClickEvent(aParams) {
|
||||
return new Promise(resolve => {
|
||||
synthesizeNativeClickAndWaitForClickEvent(aElement, aX, aY, resolve);
|
||||
synthesizeNativeMouseClickWithAPZAndWaitForClickEvent(aParams, resolve);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ async function test() {
|
|||
var subframe = document.getElementById('subframe');
|
||||
|
||||
// layerize subframe
|
||||
await promiseNativeClickAndClickEvent(subframe, 10, 10);
|
||||
await promiseNativeMouseClickWithAPZAndClickEvent({ target: subframe, offsetX: 10, offsetY: 10 });
|
||||
|
||||
// verify layerization
|
||||
await promiseAllPaintsDone();
|
||||
|
|
|
@ -20,7 +20,7 @@ async function test() {
|
|||
var subframe = document.getElementById('bugzilla-body');
|
||||
|
||||
// layerize subframe
|
||||
await promiseNativeClickAndClickEvent(subframe, 10, 10);
|
||||
await promiseNativeMouseClickWithAPZAndClickEvent({ target: subframe, offsetX: 10, offsetY: 10 });
|
||||
|
||||
// verify layerization
|
||||
await promiseAllPaintsDone();
|
||||
|
|
|
@ -21,9 +21,10 @@ async function clickButton() {
|
|||
await promiseApzRepaintsFlushed();
|
||||
}
|
||||
|
||||
synthesizeNativeClick(document.getElementById("b"), 5, 5, function() {
|
||||
dump("Finished synthesizing click, waiting for button to be clicked...\n");
|
||||
});
|
||||
synthesizeNativeMouseClickWithAPZ(
|
||||
{ target: document.getElementById("b"), offsetX: 5, offsetY: 5 },
|
||||
() => dump("Finished synthesizing click, waiting for button to be clicked...\n")
|
||||
);
|
||||
|
||||
let e = await clickPromise;
|
||||
is(e.target, document.getElementById("b"), "Clicked on button, yay! (at " + e.clientX + "," + e.clientY + ")");
|
||||
|
|
|
@ -40,7 +40,7 @@ async function test() {
|
|||
// Click at the bottom of the scrollbar track to trigger a page-down kind of
|
||||
// scroll. This should use "desktop zooming" scrollbar code which should
|
||||
// trigger an APZ scroll animation.
|
||||
await promiseNativeClick(anchor, xoffset, yoffset);
|
||||
await promiseNativeMouseClickWithAPZ({ target: anchor, offsetX: xoffset, offsetY: yoffset });
|
||||
|
||||
// Run a few frames, that should be enough to let the scroll animation
|
||||
// start. We check to make sure the scroll position has changed.
|
||||
|
@ -55,7 +55,7 @@ async function test() {
|
|||
|
||||
// Now we click on the content, which should cancel the animation. Run
|
||||
// everything to reach a stable state.
|
||||
await promiseNativeClick(anchor, -5, -5);
|
||||
await promiseNativeMouseClickWithAPZ({ target: anchor, offsetX: -5, offsetY: -5 });
|
||||
for (let i = 0; i < 1000; i++) {
|
||||
utils.advanceTimeAndRefresh(16);
|
||||
}
|
||||
|
|
|
@ -32,9 +32,10 @@ let code_for_oopif_to_run = function() {
|
|||
|
||||
async function clickOnIframe(x, y) {
|
||||
let iframePromise = promiseOneEvent(window, "OOPIF:ClickData", null);
|
||||
synthesizeNativeClick(document.body, x, y, function() {
|
||||
dump("Finished synthesizing click, waiting for OOPIF message...\n");
|
||||
});
|
||||
synthesizeNativeMouseClickWithAPZ(
|
||||
{ target: document.body, offsetX: x, offsetY: y },
|
||||
() => dump("Finished synthesizing click, waiting for OOPIF message...\n")
|
||||
);
|
||||
let iframeResponse = await iframePromise;
|
||||
dump("OOPIF response: " + JSON.stringify(iframeResponse.data) + "\n");
|
||||
return iframeResponse.data;
|
||||
|
|
|
@ -49,9 +49,10 @@ async function test() {
|
|||
ok(iframeResponse, "code_for_oopif_to_run successfully installed");
|
||||
|
||||
iframePromise = promiseOneEvent(window, "OOPIF:ClickData", null);
|
||||
synthesizeNativeClick(document.body, 400, 400, function() {
|
||||
dump("Finished synthesizing click, waiting for OOPIF message...\n");
|
||||
});
|
||||
synthesizeNativeMouseClickWithAPZ(
|
||||
{ target: document.body, offsetX: 400, offsetY: 400 },
|
||||
() => dump("Finished synthesizing click, waiting for OOPIF message...\n")
|
||||
);
|
||||
iframeResponse = await iframePromise;
|
||||
dump("OOPIF response: " + JSON.stringify(iframeResponse.data) + "\n");
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
window.addEventListener("click", resolve);
|
||||
});
|
||||
let input = document.querySelector("input");
|
||||
synthesizeNativeClick(input, 10, 10);
|
||||
synthesizeNativeMouseClickWithAPZ({ target: input, offsetX: 10, offsetY: 10 });
|
||||
let e = await clickPromise;
|
||||
is(e.target, input, "got click");
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ async function test() {
|
|||
// Click at the bottom of the scrollbar track to trigger a page-down kind of
|
||||
// scroll. This should use "desktop zooming" scrollbar code which should
|
||||
// trigger an APZ scroll animation.
|
||||
await promiseNativeClick(anchor, xoffset, yoffset);
|
||||
await promiseNativeMouseClickWithAPZ({ target: anchor, offsetX: xoffset, offsetY: yoffset });
|
||||
|
||||
// Run 1000 frames, that should be enough to let the scroll animation start
|
||||
// and run to completion. We check that it scrolled at least half the visible
|
||||
|
@ -57,7 +57,7 @@ async function test() {
|
|||
// Now we do two clicks in quick succession, but with a few frames in between
|
||||
// to verify the scroll animation from the first click is active before the
|
||||
// second click happens.
|
||||
await promiseNativeClick(anchor, xoffset, yoffset);
|
||||
await promiseNativeMouseClickWithAPZ({ target: anchor, offsetX: xoffset, offsetY: yoffset });
|
||||
for (let i = 0; i < 5; i++) {
|
||||
utils.advanceTimeAndRefresh(16);
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ async function test() {
|
|||
let curPos = scroller.scrollTop;
|
||||
ok(curPos > pageScrollAmount, `Scroll offset has increased to ${curPos}`);
|
||||
ok(curPos < pageScrollAmount * 2, "Second page-scroll is not yet complete");
|
||||
await promiseNativeClick(anchor, xoffset, yoffset);
|
||||
await promiseNativeMouseClickWithAPZ({ target: anchor, offsetX: xoffset, offsetY: yoffset });
|
||||
|
||||
// Run to completion and check that we are around 3x pageScrollAmount, with
|
||||
// some allowance for fractional rounding.
|
||||
|
|
|
@ -81,7 +81,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=987230
|
|||
let popupHasShown = false;
|
||||
function onMyPopupShown(e) {
|
||||
popupHasShown = true;
|
||||
synthesizeNativeMouseClick(outerAnchor, 5, 5);
|
||||
synthesizeNativeMouseClick({ target: outerAnchor, offsetX: 5, offsetY: 5 });
|
||||
}
|
||||
|
||||
function onAnchorClick(e) {
|
||||
|
|
|
@ -1054,24 +1054,24 @@ function synthesizeNativeMouseMove(
|
|||
utils.sendNativeMouseMove(x * scale, y * scale, null, observer);
|
||||
}
|
||||
|
||||
function synthesizeNativeMouseClick(
|
||||
aTarget,
|
||||
aOffsetX,
|
||||
aOffsetY,
|
||||
aCallback,
|
||||
aWindow = window
|
||||
) {
|
||||
var utils = _getDOMWindowUtils(aWindow);
|
||||
function synthesizeNativeMouseClick(aParams, aCallback = null) {
|
||||
const {
|
||||
target, // Origin of offsetX and offsetY, must be an element
|
||||
offsetX, // X offset in `target`
|
||||
offsetY, // Y offset in `target`
|
||||
win = window, // The window to use its utils
|
||||
} = aParams;
|
||||
const utils = _getDOMWindowUtils(win);
|
||||
if (!utils) {
|
||||
return;
|
||||
}
|
||||
|
||||
var rect = aTarget.getBoundingClientRect();
|
||||
var x = aOffsetX + window.mozInnerScreenX + rect.left;
|
||||
var y = aOffsetY + window.mozInnerScreenY + rect.top;
|
||||
var scale = utils.screenPixelsPerCSSPixel;
|
||||
const rect = target.getBoundingClientRect();
|
||||
const x = offsetX + win.mozInnerScreenX + rect.left;
|
||||
const y = offsetY + win.mozInnerScreenY + rect.top;
|
||||
const scale = utils.screenPixelsPerCSSPixel;
|
||||
|
||||
var observer = {
|
||||
const observer = {
|
||||
observe: (subject, topic, data) => {
|
||||
if (aCallback && topic == "mouseevent") {
|
||||
aCallback(data);
|
||||
|
@ -1097,6 +1097,10 @@ function synthesizeNativeMouseClick(
|
|||
);
|
||||
}
|
||||
|
||||
function promiseNativeMouseClick(aParams) {
|
||||
return new Promise(resolve => synthesizeNativeMouseClick(aParams, resolve));
|
||||
}
|
||||
|
||||
function synthesizeNativeMouseClickAtCenter(
|
||||
aTarget,
|
||||
aCallback,
|
||||
|
@ -1104,11 +1108,13 @@ function synthesizeNativeMouseClickAtCenter(
|
|||
) {
|
||||
let rect = aTarget.getBoundingClientRect();
|
||||
return synthesizeNativeMouseClick(
|
||||
aTarget,
|
||||
rect.width / 2,
|
||||
rect.height / 2,
|
||||
aCallback,
|
||||
aWindow
|
||||
{
|
||||
target: aTarget,
|
||||
offsetX: rect.width / 2,
|
||||
offsetY: rect.height / 2,
|
||||
win: aWindow,
|
||||
},
|
||||
aCallback
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче