Bug 1666755 - [marionette] Run beforeunload timer after the click event has been received. r=marionette-reviewers,jdescottes

Due to delays when the click and the appropriate event will actually
happen within the child process, the beforeunload timer with 200ms
timeout needs to be run after the click event has been received.

Differential Revision: https://phabricator.services.mozilla.com/D93194
This commit is contained in:
Henrik Skupin 2020-10-13 21:00:56 +00:00
Родитель c25b8b29fe
Коммит 3215ff5067
1 изменённых файлов: 12 добавлений и 12 удалений

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

@ -327,18 +327,6 @@ navigate.waitForNavigationCompleted = async function waitForNavigationCompleted(
checkDone({ finished: true });
};
// Certain commands like clickElement can cause a navigation. Setup a timer
// to check if a "beforeunload" event has been emitted within the given
// time frame. If not resolve the Promise.
if (!requireBeforeUnload) {
unloadTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
unloadTimer.initWithCallback(
onTimer,
TIMEOUT_BEFOREUNLOAD_EVENT,
Ci.nsITimer.TYPE_ONE_SHOT
);
}
chromeWindow.addEventListener("TabClose", onUnload);
chromeWindow.addEventListener("unload", onUnload);
driver.dialogObserver.add(onDialogOpened);
@ -347,6 +335,18 @@ navigate.waitForNavigationCompleted = async function waitForNavigationCompleted(
try {
await callback();
// Certain commands like clickElement can cause a navigation. Setup a timer
// to check if a "beforeunload" event has been emitted within the given
// time frame. If not resolve the Promise.
if (!requireBeforeUnload) {
unloadTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
unloadTimer.initWithCallback(
onTimer,
TIMEOUT_BEFOREUNLOAD_EVENT,
Ci.nsITimer.TYPE_ONE_SHOT
);
}
} catch (e) {
checkDone({ finished: true, error: e });
}