forked from mirrors/gecko-dev
For many browser-chrome (bc) tests is does not matter what the
document is, as long as it is does not cause state to bleed over
from the previous test.
For these cases this patch introduces a shorthand, setup(), which
calls setupForURL(url) with an empty document generated by toDataURL("").
Differential Revision: https://phabricator.services.mozilla.com/D40216
--HG--
extra : moz-landing-system : lando
61 lines
1.8 KiB
JavaScript
61 lines
1.8 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
"use strict";
|
|
|
|
// Test beforeunload dialog events.
|
|
add_task(async function() {
|
|
info("Allow to trigger onbeforeunload without user interaction");
|
|
await new Promise(resolve => {
|
|
const options = {
|
|
set: [["dom.require_user_interaction_for_beforeunload", false]],
|
|
};
|
|
SpecialPowers.pushPrefEnv(options, resolve);
|
|
});
|
|
|
|
const { client, tab } = await setup();
|
|
|
|
const { Page } = client;
|
|
|
|
info("Enable the page domain");
|
|
await Page.enable();
|
|
|
|
info("Attach a valid onbeforeunload handler");
|
|
await ContentTask.spawn(gBrowser.selectedBrowser, null, () => {
|
|
content.onbeforeunload = () => true;
|
|
});
|
|
|
|
info("Trigger the beforeunload again but reject the prompt");
|
|
const { type } = await triggerBeforeUnload(Page, tab, false);
|
|
is(type, "beforeunload", "dialog event contains the correct type");
|
|
|
|
info("Trigger the beforeunload again and accept the prompt");
|
|
const onTabClose = BrowserTestUtils.waitForEvent(tab, "TabClose");
|
|
await triggerBeforeUnload(Page, tab, true);
|
|
|
|
info("Wait for the TabClose event");
|
|
await onTabClose;
|
|
|
|
await client.close();
|
|
ok(true, "The client is closed");
|
|
|
|
await RemoteAgent.close();
|
|
});
|
|
|
|
function triggerBeforeUnload(Page, tab, accept) {
|
|
// We use then here because after clicking on the close button, nothing
|
|
// in the main block of the function will be executed until the prompt
|
|
// is accepted or rejected. Attaching a then to this promise still works.
|
|
|
|
const onDialogOpen = Page.javascriptDialogOpening().then(
|
|
async dialogEvent => {
|
|
await Page.handleJavaScriptDialog({ accept });
|
|
return dialogEvent;
|
|
}
|
|
);
|
|
|
|
info("Click on the tab close icon");
|
|
tab.closeButton.click();
|
|
|
|
return onDialogOpen;
|
|
}
|