Bug 1691622 - part 6: Merge `synthesizeNativeMouseClick*` with `synthesizeNativeMouseEvent*` r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D105760
This commit is contained in:
Masayuki Nakano 2021-02-24 01:27:08 +00:00
Родитель 293d2541c8
Коммит 44ff291cb4
22 изменённых файлов: 99 добавлений и 68 удалений

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

@ -36,7 +36,8 @@ add_task(async function test_PanelMultiView_toggle_with_other_popup() {
// 3. Click the button to which the main menu is anchored. We need a native
// mouse event to simulate the exact platform behavior with popups.
let clickFn = () =>
EventUtils.promiseNativeMouseClickAndWaitForEvent({
EventUtils.promiseNativeMouseEventAndWaitForEvent({
type: "click",
target: document.getElementById("PanelUI-button"),
atCenter: true,
eventTypeToWait: "mouseup",

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

@ -135,7 +135,8 @@ add_task(async function open_empty() {
promise = promiseEvent(searchPopup, "popuphidden");
info("Hiding popup");
await EventUtils.promiseNativeMouseClickAndWaitForEvent({
await EventUtils.promiseNativeMouseEventAndWaitForEvent({
type: "click",
target: searchIcon,
atCenter: true,
eventTypeToWait: "mouseup",
@ -229,7 +230,8 @@ add_task(async function open_empty_hiddenOneOffs() {
promise = promiseEvent(searchPopup, "popuphidden");
info("Hiding popup");
await EventUtils.promiseNativeMouseClickAndWaitForEvent({
await EventUtils.promiseNativeMouseEventAndWaitForEvent({
type: "click",
target: searchIcon,
atCenter: true,
eventTypeToWait: "mouseup",
@ -572,7 +574,8 @@ add_task(async function dont_consume_clicks() {
is(textbox.selectionEnd, 3, "Should have selected all of the text");
promise = promiseEvent(searchPopup, "popuphidden");
await EventUtils.promiseNativeMouseClickAndWaitForEvent({
await EventUtils.promiseNativeMouseEventAndWaitForEvent({
type: "click",
target: gURLBar.inputField,
atCenter: true,
eventTypeToWait: "mouseup",

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

@ -23,7 +23,11 @@ add_task(async function() {
// Must have at least one test.
Assert.ok(!!elt, "Found a valid element: " + (elt.id || elt.localName));
await UrlbarTestUtils.promisePopupClose(window, () =>
EventUtils.synthesizeNativeMouseClick({ target: elt, atCenter: true })
EventUtils.synthesizeNativeMouseEvent({
type: "click",
target: elt,
atCenter: true,
})
);
}
});

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

@ -74,7 +74,7 @@ function runTests() {
synthesizeNativeMouseMove(target0, 10, 10, () => {
synthesizeNativeMouseMove(target0, 15, 15, () => {
synthesizeNativeMouseMove(target0, 20, 20, () => {
synthesizeNativeMouseClick({ target: target0, offsetX: 20, offsetY: 20 });
synthesizeNativeMouseEvent({ type: "click", target: target0, offsetX: 20, offsetY: 20 });
});
});
});

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

@ -59,10 +59,11 @@ add_task(async () => {
});
// NOTE: synthesizeMouseAtCenter doesn't work for OOP iframes (bug 1528935),
// so we use promiseNativeMouseClick instead.
// so we use promiseNativeMouseEvent instead.
const [expectedScreenXInSameOrigin, expectedScreenYInSameOrigin] =
getScreenPosition(iframes[0], 10, 10);
await promiseNativeMouseClick({
await promiseNativeMouseEvent({
type: "click",
target: iframes[0],
screenX: expectedScreenXInSameOrigin,
screenY: expectedScreenYInSameOrigin,
@ -76,7 +77,8 @@ add_task(async () => {
const [expectedScreenXInCrossOrigin, expectedScreenYInCrossOrigin] =
getScreenPosition(iframes[1], 10, 10);
await promiseNativeMouseClick({
await promiseNativeMouseEvent({
type: "click",
target: iframes[0],
screenX: expectedScreenXInCrossOrigin,
screenY: expectedScreenYInCrossOrigin,

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

@ -47,7 +47,7 @@ add_task(async () => {
await promiseApzFlushedRepaints();
// NOTE: synthesizeMouseAtCenter doesn't work for OOP iframes (bug 1528935),
// so we use synthesizeNativeMouseClick instead.
// so we use promiseNativeMouseEventWithAPZ instead.
const [expectedScreenX, expectedScreenY] =
getScreenPosition(iframe, 10, 10);
@ -78,7 +78,8 @@ add_task(async () => {
});
});
await promiseNativeMouseClick({
await promiseNativeMouseEventWithAPZ({
type: "click",
target: iframe,
screenX: expectedScreenX,
screenY: expectedScreenY,
@ -104,7 +105,8 @@ add_task(async () => {
});
});
await promiseNativeMouseClick({
await promiseNativeMouseEventWithAPZ({
type: "click",
target: iframe,
screenX: expectedScreenX,
screenY: expectedScreenY,

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

@ -52,7 +52,7 @@ add_task(async () => {
await promiseApzFlushedRepaints();
// NOTE: synthesizeMouseAtCenter doesn't work for OOP iframes (bug 1528935),
// so we use promiseNativeMouseClick instead.
// so we use promiseNativeMouseEventWithAPZ instead.
const [expectedScreenX, expectedScreenY] =
getScreenPosition(iframe, 10, 10);
@ -85,7 +85,8 @@ add_task(async () => {
});
});
await promiseNativeMouseClick({
await promiseNativeMouseEventWithAPZ({
type: "click",
target: iframe,
screenX: expectedScreenX,
screenY: expectedScreenY + 110,
@ -131,7 +132,8 @@ add_task(async () => {
});
});
await promiseNativeMouseClick({
await promiseNativeMouseEventWithAPZ({
type: "click",
target: iframe,
screenX: expectedScreenX,
screenY: expectedScreenY,

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

@ -36,7 +36,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1224790
synthesizeMouseAtCenter(button, { type: 'mousemove' }, window);
function click() {
// The bug is not reproducible with synthesizeMouseAtCenter.
synthesizeNativeMouseClick({ target: button, atCenter: true });
synthesizeNativeMouseEvent({ type: "click", target: button, atCenter: true });
}
click();
// On debug build, it's possible that the click event handler is not

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

@ -37,7 +37,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1224790
synthesizeMouseAtCenter(button, { type: 'mousemove' }, window);
function click() {
// The bug is not reproducible with synthesizeMouseAtCenter.
synthesizeNativeMouseClick({ target: button, atCenter: true });
synthesizeNativeMouseEvent({ type: "click", target: button, atCenter: true });
}
click();
// On debug build, it's possible that the click event handler is not

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

@ -885,36 +885,26 @@ function promiseNativeMouseEventWithAPZ(aParams) {
);
}
function synthesizeNativeMouseClickWithAPZ(aParams, aObserver = null) {
aParams.type = "click";
return synthesizeNativeMouseEventWithAPZ(aParams, aObserver);
}
function promiseNativeMouseClickWithAPZ(aParams) {
aParams.type = "click";
return promiseNativeMouseEventWithAPZ(aParams);
}
// See synthesizeNativeMouseClickWithAPZ for the detail of aParams.
function synthesizeNativeMouseClickWithAPZAndWaitForClickEvent(
// See synthesizeNativeMouseEventWithAPZ for the detail of aParams.
function synthesizeNativeMouseEventWithAPZAndWaitForWaitForEvent(
aParams,
aCallback = null
) {
const targetWindow = windowForTarget(aParams.target);
const eventType = aParams.eventTypeToWait || aParams.type;
targetWindow.addEventListener(
"click",
eventType,
function(e) {
setTimeout(aCallback, 0);
},
{ capture: true, once: true }
);
return synthesizeNativeMouseClickWithAPZ(aParams);
return synthesizeNativeMouseEventWithAPZ(aParams);
}
// Promise-returning variant of synthesizeNativeMouseClickWithAPZAndWaitForClickEvent
function promiseNativeMouseClickWithAPZAndClickEvent(aParams) {
function promiseNativeMouseEventWithAPZAndWaitForEvent(aParams) {
return new Promise(resolve => {
synthesizeNativeMouseClickWithAPZAndWaitForClickEvent(aParams, resolve);
synthesizeNativeMouseEventWithAPZAndWaitForWaitForEvent(aParams, resolve);
});
}

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

@ -15,7 +15,12 @@ async function test() {
var subframe = document.getElementById('subframe');
// layerize subframe
await promiseNativeMouseClickWithAPZAndClickEvent({ target: subframe, offsetX: 10, offsetY: 10 });
await promiseNativeMouseEventWithAPZAndWaitForEvent({
type: "click",
target: subframe,
offsetX: 10,
offsetY: 10,
});
// verify layerization
await promiseAllPaintsDone();

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

@ -20,7 +20,12 @@ async function test() {
var subframe = document.getElementById('bugzilla-body');
// layerize subframe
await promiseNativeMouseClickWithAPZAndClickEvent({ target: subframe, offsetX: 10, offsetY: 10 });
await promiseNativeMouseEventWithAPZAndWaitForEvent({
type: "click",
target: subframe,
offsetX: 10,
offsetY: 10,
});
// verify layerization
await promiseAllPaintsDone();

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

@ -21,8 +21,8 @@ async function clickButton() {
await promiseApzRepaintsFlushed();
}
synthesizeNativeMouseClickWithAPZ(
{ target: document.getElementById("b"), offsetX: 5, offsetY: 5 },
synthesizeNativeMouseEventWithAPZ(
{ type: "click", target: document.getElementById("b"), offsetX: 5, offsetY: 5 },
() => dump("Finished synthesizing click, waiting for button to be clicked...\n")
);

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

@ -40,7 +40,12 @@ 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 promiseNativeMouseClickWithAPZ({ target: anchor, offsetX: xoffset, offsetY: yoffset });
await promiseNativeMouseEventWithAPZ({
type: "click",
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 +60,12 @@ async function test() {
// Now we click on the content, which should cancel the animation. Run
// everything to reach a stable state.
await promiseNativeMouseClickWithAPZ({ target: anchor, offsetX: -5, offsetY: -5 });
await promiseNativeMouseEventWithAPZ({
type: "click",
target: anchor,
offsetX: -5,
offsetY: -5,
});
for (let i = 0; i < 1000; i++) {
utils.advanceTimeAndRefresh(16);
}

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

@ -32,8 +32,8 @@ let code_for_oopif_to_run = function() {
async function clickOnIframe(x, y) {
let iframePromise = promiseOneEvent(window, "OOPIF:ClickData", null);
synthesizeNativeMouseClickWithAPZ(
{ target: document.body, offsetX: x, offsetY: y },
synthesizeNativeMouseEventWithAPZ(
{ type: "click", target: document.body, offsetX: x, offsetY: y },
() => dump("Finished synthesizing click, waiting for OOPIF message...\n")
);
let iframeResponse = await iframePromise;

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

@ -49,8 +49,8 @@ async function test() {
ok(iframeResponse, "code_for_oopif_to_run successfully installed");
iframePromise = promiseOneEvent(window, "OOPIF:ClickData", null);
synthesizeNativeMouseClickWithAPZ(
{ target: document.body, offsetX: 400, offsetY: 400 },
synthesizeNativeMouseEventWithAPZ(
{ type: "click", target: document.body, offsetX: 400, offsetY: 400 },
() => dump("Finished synthesizing click, waiting for OOPIF message...\n")
);
iframeResponse = await iframePromise;

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

@ -39,7 +39,7 @@
window.addEventListener("click", resolve);
});
let input = document.querySelector("input");
synthesizeNativeMouseClickWithAPZ({ target: input, offsetX: 10, offsetY: 10 });
synthesizeNativeMouseEventWithAPZ({ type: "click", target: input, offsetX: 10, offsetY: 10 });
let e = await clickPromise;
is(e.target, input, "got click");
}

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

@ -40,7 +40,12 @@ 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 promiseNativeMouseClickWithAPZ({ target: anchor, offsetX: xoffset, offsetY: yoffset });
await promiseNativeMouseEventWithAPZ({
type: "click",
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 +62,12 @@ 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 promiseNativeMouseClickWithAPZ({ target: anchor, offsetX: xoffset, offsetY: yoffset });
await promiseNativeMouseEventWithAPZ({
type: "click",
target: anchor,
offsetX: xoffset,
offsetY: yoffset,
});
for (let i = 0; i < 5; i++) {
utils.advanceTimeAndRefresh(16);
}
@ -65,7 +75,12 @@ 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 promiseNativeMouseClickWithAPZ({ target: anchor, offsetX: xoffset, offsetY: yoffset });
await promiseNativeMouseEventWithAPZ({
type: "click",
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({ target: outerAnchor, offsetX: 5, offsetY: 5 });
synthesizeNativeMouseEvent({ type: "click", target: outerAnchor, offsetX: 5, offsetY: 5 });
}
function onAnchorClick(e) {

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

@ -146,7 +146,8 @@ function starttest() {
}
events = [];
info(`testSynthesizeNativeMouseClick: sending native mouse click (${test.description})`);
await promiseNativeMouseClickAndWaitForEvent({
await promiseNativeMouseEventAndWaitForEvent({
type: "click",
target: $("testMouseEvent"),
atCenter: true,
modifiers: test.modifiers,

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

@ -12,7 +12,6 @@
* synthesizeMouseAtCenter
* synthesizeNativeMouseMove
* synthesizeNativeMouseEvent
* synthesizeNativeMouseClick
* synthesizeWheel
* synthesizeWheelAtPoint
* synthesizeKey
@ -1190,29 +1189,19 @@ function promiseNativeMouseEvent(aParams) {
return new Promise(resolve => synthesizeNativeMouseEvent(aParams, resolve));
}
function synthesizeNativeMouseClick(aParams, aObserver = null) {
aParams.type = "click";
return synthesizeNativeMouseEvent(aParams, aObserver);
}
function promiseNativeMouseClick(aParams) {
aParams.type = "click";
return promiseNativeMouseEvent(aParams);
}
function synthesizeNativeMouseClickAndWaitForEvent(aParams, aCallback) {
function synthesizeNativeMouseEventAndWaitForEvent(aParams, aCallback) {
const listener = aParams.eventTargetToListen || aParams.target;
const eventType = aParams.eventTypeToWait || "click";
const eventType = aParams.eventTypeToWait || aParams.type;
listener.addEventListener(eventType, aCallback, {
capture: true,
once: true,
});
synthesizeNativeMouseClick(aParams);
synthesizeNativeMouseEvent(aParams);
}
function promiseNativeMouseClickAndWaitForEvent(aParams) {
function promiseNativeMouseEventAndWaitForEvent(aParams) {
return new Promise(resolve =>
synthesizeNativeMouseClickAndWaitForEvent(aParams, resolve)
synthesizeNativeMouseEventAndWaitForEvent(aParams, resolve)
);
}

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

@ -75,7 +75,8 @@ add_task(async function TestMouseClickWithControl() {
["contextmenu", 0, true],
["mouseup", 0, true],
["click", 0, true]]);
synthesizeNativeMouseClick({
synthesizeNativeMouseEvent({
type: "click",
target,
offsetX: 10,
offsetY: 10,
@ -94,7 +95,8 @@ add_task(async function TestOldBehavior() {
["contextmenu", 2, true],
["mouseup", 2, true],
["auxclick", 2, true]]);
synthesizeNativeMouseClick({
synthesizeNativeMouseEvent({
type: "click",
target,
offsetX: 10,
offsetY: 10,