Bug 1698698 - Ensure event listener is registered on remote iframe before synthesizing mouse event; r=masayuki

It is not guaranteed that the task scheduled by SepcialPowers.spawn would be run
before the asynchronous synthesized mouse event. So rewrite the test to ensure
the event listener is ready on remote iframe before starting test.

Differential Revision: https://phabricator.services.mozilla.com/D120196
This commit is contained in:
Edgar Chen 2021-07-19 09:38:28 +00:00
Родитель 28ced48ac1
Коммит f965cadcb4
3 изменённых файлов: 20 добавлений и 11 удалений

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

@ -66,13 +66,25 @@ async function exitPointerLock(aWin) {
});
}
function waitForEvent(aWin, aEvent) {
function addEventListenerOnRemote(aWin, aEvent) {
return SpecialPowers.spawn(aWin, [aEvent], async (aEvent) => {
info(`wait for ${aEvent} event`);
return new Promise((aResolve) => {
content.document.addEventListener(aEvent, function(e) {
info(`wait for ${aEvent} event on remote`);
content.document.addEventListener(aEvent, function(e) {
info(`get ${aEvent} event on remote`);
content.parent.postMessage(aEvent, "*");
});
});
}
function waitForMessage(aWin, aMessage) {
return new Promise((aResolve) => {
info(`wait for ${aMessage} message`);
window.addEventListener("message", function handler(e) {
info(`get ${e.data} message`);
if (e.data === aMessage) {
window.removeEventListener("message", handler);
aResolve();
}, { once: true });
}
});
});
}
@ -84,8 +96,9 @@ async function start() {
let iframe = document.querySelector("iframe");
let win = iframe.contentWindow;
await requestPointerLock(win);
await addEventListenerOnRemote(win, "mousemove");
let promise = waitForEvent(win, "mousemove");
let promise = waitForMessage(win, "mousemove");
let div = document.querySelector("div");
synthesizeMouseAtCenter(div, { type: "mousemove" });
await promise;

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

@ -31,11 +31,6 @@ support-files =
file_changeLockElement.html
[test_pointerlock_focus.html]
[test_pointerlock_xorigin_iframe.html]
skip-if =
os == "linux" && !(webrender && !debug) # Bug 1698698 - only passes on webrender opt
os == "win" #Bug 1698698
os == "android" && bits == 64 #Bug 1698698
os == "mac" && bits == 64 && webrender # Bug 1698698
support-files =
file_pointerlock_xorigin_iframe.html
file_pointerlock_xorigin_iframe_no_user_gesture.html

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

@ -48,6 +48,7 @@ function runNextTest() {
info(`Testing ${file}`);
gTestWindow = window.open(file, "", "width=500,height=500");
info(`Test finish`);
} else {
SimpleTest.finish();
}