Bug 1691622 - part 10: Make `synthesizeNativeMouseEvent` take a button argument r=smaug

Now, it should take `button` argument whose default value is 0 (primary
button).

Differential Revision: https://phabricator.services.mozilla.com/D105764
This commit is contained in:
Masayuki Nakano 2021-02-24 01:27:10 +00:00
Родитель ef2253b4a1
Коммит b77b790e20
3 изменённых файлов: 47 добавлений и 14 удалений

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

@ -702,6 +702,7 @@ function synthesizeNativeMouseEventWithAPZ(aParams, aObserver = null) {
atCenter, // Instead of offsetX/Y, synthesize the event at center of `target`
screenX, // X offset in screen, offsetX/Y nor atCenter must not be set if this is set
screenY, // Y offset in screen, offsetX/Y nor atCenter must not be set if this is set
button = 0, // if "click", "mousedown", "mouseup", set same value as DOM MouseEvent.button
modifiers = {}, // Active modifiers, see `parseNativeModifiers`
} = aParams;
if (atCenter) {
@ -747,7 +748,7 @@ function synthesizeNativeMouseEventWithAPZ(aParams, aObserver = null) {
pt.x,
pt.y,
utils.NATIVE_MOUSE_MESSAGE_BUTTON_DOWN,
0,
button,
modifierFlags,
element,
function() {
@ -755,7 +756,7 @@ function synthesizeNativeMouseEventWithAPZ(aParams, aObserver = null) {
pt.x,
pt.y,
utils.NATIVE_MOUSE_MESSAGE_BUTTON_UP,
0,
button,
modifierFlags,
element,
aObserver
@ -780,7 +781,7 @@ function synthesizeNativeMouseEventWithAPZ(aParams, aObserver = null) {
throw Error(`Invalid type is specified: ${type}`);
}
})(),
0,
button,
modifierFlags,
element,
aObserver

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

@ -53,10 +53,10 @@ function starttest() {
sendMouseEvent({type:'click'}, "testMouseEvent");
is(check, true, 'sendMouseEvent should dispatch click event');
await (async function testSynthesizeNativeMouseClick() {
await (async function testSynthesizeNativeMouseEvent() {
if (navigator.appVersion.includes("Android")) {
todo(false,
`testSynthesizeNativeMouseClick: does nothing on Android because its nsIWidget::SynthesizeNativeMouseEvent won't fire "mouseup"`);
`testSynthesizeNativeMouseEvent: does nothing on Android because its nsIWidget::SynthesizeNativeMouseEvent won't fire "mouseup"`);
return;
}
let events = [];
@ -145,7 +145,7 @@ function starttest() {
continue;
}
events = [];
info(`testSynthesizeNativeMouseClick: sending native mouse click (${test.description})`);
info(`testSynthesizeNativeMouseEvent: sending native mouse click (${test.description})`);
await promiseNativeMouseEventAndWaitForEvent({
type: "click",
target: $("testMouseEvent"),
@ -154,11 +154,11 @@ function starttest() {
eventTypeToWait: "mouseup",
});
is(events.length, 2,
`testSynthesizeNativeMouseClick: a pair of "mousedown" and "mouseup" events should be fired (${test.description})`);
`testSynthesizeNativeMouseEvent: a pair of "mousedown" and "mouseup" events should be fired (${test.description})`);
is(events[0]?.type, "mousedown",
`testSynthesizeNativeMouseClick: "mousedown" should be fired (${test.description})`);
`testSynthesizeNativeMouseEvent: "mousedown" should be fired (${test.description})`);
is(events[1]?.type, "mouseup",
`testSynthesizeNativeMouseClick: "mouseup" should be fired (${test.description})`);
`testSynthesizeNativeMouseEvent: "mouseup" should be fired (${test.description})`);
if (events.length !== 2) {
continue;
}
@ -183,11 +183,42 @@ function starttest() {
// In Headless mode, modifiers are not supported by this kind of APIs.
kIsHeadless) ? todo_is : is;
checkFn(events[0]?.getModifierState(mod.keyName), activeExpected,
`testSynthesizeNativeMouseCheck: "mousedown".getModifierState("${mod.keyName}") should return ${activeExpected} (${test.description}`);
`testSynthesizeNativeMouseEvent: "mousedown".getModifierState("${mod.keyName}") should return ${activeExpected} (${test.description}`);
checkFn(events[1]?.getModifierState(mod.keyName), activeExpected,
`testSynthesizeNativeMouseCheck: "mouseup".getModifierState("${mod.keyName}") should return ${activeExpected} (${test.description}`);
`testSynthesizeNativeMouseEvent: "mouseup".getModifierState("${mod.keyName}") should return ${activeExpected} (${test.description}`);
}
}
const supportsX1AndX2Buttons =
// On Windows, it triggers APP_COMMAND. Therefore, this test is unloaded.
!navigator.platform.includes("Win") &&
// On macOS, it seems that no API to specify X1 and X2 button at creating an NSEvent.
!navigator.platform.includes("Mac") &&
// On Linux, it seems that X1 button and X2 button events are not synthesized correctly.
!navigator.platform.includes("Linux");
for (let i = 0; i < (supportsX1AndX2Buttons ? 5 : 3); i++) {
events = [];
info(`testSynthesizeNativeMouseEvent: sending native mouse click (button=${i})`);
await promiseNativeMouseEventAndWaitForEvent({
type: "click",
target: $("testMouseEvent"),
atCenter: true,
button: i,
eventTypeToWait: "mouseup",
});
is(events.length, 2,
`testSynthesizeNativeMouseEvent: a pair of "mousedown" and "mouseup" events should be fired (button=${i})`);
is(events[0]?.type, "mousedown",
`testSynthesizeNativeMouseEvent: "mousedown" should be fired (button=${i})`);
is(events[1]?.type, "mouseup",
`testSynthesizeNativeMouseEvent: "mouseup" should be fired (button=${i})`);
if (events.length !== 2) {
continue;
}
is(events[0].button, i,
`testSynthesizeNativeMouseEvent: button of "mousedown" event should be ${i}`);
is(events[1].button, i,
`testSynthesizeNativeMouseEvent: button of "mouseup" event should be ${i}`);
}
$("testMouseEvent").removeEventListener("mousedown", listener);
$("testMouseEvent").removeEventListener("mouseup", listener);
window.removeEventListener("contextmenu", preventDefault, { capture: true });

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

@ -1002,6 +1002,7 @@ function synthesizeNativeMouseEvent(aParams, aCallback = null) {
atCenter, // Instead of offsetX/Y, synthesize the event at center of `target`
screenX, // X offset in screen, offsetX/Y nor atCenter must not be set if this is set
screenY, // Y offset in screen, offsetX/Y nor atCenter must not be set if this is set
button = 0, // if "click", "mousedown", "mouseup", set same value as DOM MouseEvent.button
modifiers = {}, // Active modifiers, see `_parseNativeModifiers`
win = window, // The window to use its utils
} = aParams;
@ -1073,7 +1074,7 @@ function synthesizeNativeMouseEvent(aParams, aCallback = null) {
x,
y,
utils.NATIVE_MOUSE_MESSAGE_BUTTON_DOWN,
0,
button,
modifierFlags,
null,
function() {
@ -1081,7 +1082,7 @@ function synthesizeNativeMouseEvent(aParams, aCallback = null) {
x,
y,
utils.NATIVE_MOUSE_MESSAGE_BUTTON_UP,
0,
button,
modifierFlags,
null,
observer
@ -1105,7 +1106,7 @@ function synthesizeNativeMouseEvent(aParams, aCallback = null) {
throw Error(`Invalid type is specified: ${type}`);
}
})(),
0,
button,
modifierFlags,
null,
observer