mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-01 08:48:25 +02:00
This new IPDL API allows processes to communicate to the Window that it should process a Close Watcher close request, independent of the browser controlled gestures such as the Esc key. This will allow the browser UI to provide a button that can process a close request. Differential Revision: https://phabricator.services.mozilla.com/D254530
64 lines
2 KiB
JavaScript
64 lines
2 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
"use strict";
|
|
|
|
const TEST_PAGE =
|
|
getRootDirectory(gTestPath).replace(
|
|
"chrome://mochitests/content",
|
|
"https://example.com"
|
|
) + "dummy_page.html";
|
|
const CLOSEWATCHER_PAGE =
|
|
getRootDirectory(gTestPath).replace(
|
|
"chrome://mochitests/content",
|
|
"https://example.com"
|
|
) + "page_with_closewatcher.html";
|
|
|
|
const runTest =
|
|
(bool, baseURL = TEST_PAGE) =>
|
|
async () => {
|
|
// Wait for the session data to be flushed before continuing the test
|
|
Services.prefs.setBoolPref("dom.closewatcher.enabled", true);
|
|
|
|
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, baseURL);
|
|
|
|
await new Promise(resolve =>
|
|
SessionStore.getSessionHistory(gBrowser.selectedTab, resolve)
|
|
);
|
|
|
|
// Assert the hasActiveCloseWatcher property
|
|
is(
|
|
gBrowser.selectedBrowser.hasActiveCloseWatcher,
|
|
bool,
|
|
`hasActiveCloseWatcher is ${bool}`
|
|
);
|
|
|
|
gBrowser.selectedBrowser.processCloseRequest();
|
|
|
|
// CloseWatcher may not be immediately closed as the request is over IPC, so allow some grace
|
|
// by checking every 100ms to see if hasActiveCloseWatcher flips to false.
|
|
{
|
|
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
|
|
const sleep = ms => new Promise(r => setTimeout(r, ms));
|
|
const hasActiveCloseWatcherEventuallyFalse = (async () => {
|
|
while (gBrowser.selectedBrowser.hasActiveCloseWatcher) {
|
|
await sleep(50);
|
|
}
|
|
})();
|
|
await Promise.race([hasActiveCloseWatcherEventuallyFalse, sleep(3000)]);
|
|
}
|
|
|
|
// Assert the hasActiveCloseWatcher property is false after a close request
|
|
is(
|
|
gBrowser.selectedBrowser.hasActiveCloseWatcher,
|
|
false,
|
|
`hasActiveCloseWatcher is false after processCloseRequest`
|
|
);
|
|
|
|
BrowserTestUtils.removeTab(tab);
|
|
|
|
Services.prefs.clearUserPref("dom.closewatcher.enabled");
|
|
};
|
|
|
|
add_task(runTest(false, TEST_PAGE));
|
|
add_task(runTest(true, CLOSEWATCHER_PAGE));
|