Bug 1692716 - Make browser_quit_disabled.js more robust. r=Gijs

I realized that we wouldn't notice if the quit-application-requested observer wasn't called.

Differential Revision: https://phabricator.services.mozilla.com/D105121
This commit is contained in:
Tom Schuster 2021-02-23 21:23:24 +00:00
parent e6322c7b6f
commit 98018ecb9a
2 changed files with 7 additions and 1 deletions

View File

@ -8,3 +8,5 @@ reason = test depends on update channel
[browser_initial_tab_remoteType.js]
[browser_startup_homepage.js]
[browser_quit_disabled.js]
# On macOS we can't change browser.quitShortcut.disabled during runtime.
skip-if = os == 'mac'

View File

@ -25,6 +25,7 @@ add_task(async function test_quit_shortcut_disabled() {
async function testQuitShortcut(shouldQuit) {
let win = await BrowserTestUtils.openNewBrowserWindow();
let quitRequested = false;
let observer = {
observe(subject, topic, data) {
is(topic, "quit-application-requested", "Right observer topic");
@ -33,6 +34,8 @@ add_task(async function test_quit_shortcut_disabled() {
// Don't actually quit the browser when testing.
let cancelQuit = subject.QueryInterface(Ci.nsISupportsPRBool);
cancelQuit.data = true;
quitRequested = true;
},
};
Services.obs.addObserver(observer, "quit-application-requested");
@ -44,8 +47,9 @@ add_task(async function test_quit_shortcut_disabled() {
EventUtils.synthesizeKey("q", modifiers, win);
await BrowserTestUtils.closeWindow(win);
Services.obs.removeObserver(observer, "quit-application-requested");
is(quitRequested, shouldQuit, "Expected quit state");
}
// Quit shortcut should work when pref is not set.