mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-26 23:23:33 +00:00
Bug 1336763 - Update browser_beforeunload_between_chrome_content.js to use ContentTask. r=jessica
By using ContentTask, we get a Promise that resolves once we've heard confirmation from the content process that the ContentTask function has completed running. This means we can be certain that browser_beforeunload_between_chrome_content.js has had the beforeunload event handlers added before attempting to unload the page. MozReview-Commit-ID: DhoTsOZ4BNk --HG-- extra : rebase_source : ee31ed4e9a8fe0b734a5961c8b0d47d75ccb6703
This commit is contained in:
parent
1a7c6049d6
commit
58788522cd
@ -8,13 +8,15 @@ function pageScript() {
|
||||
}, true);
|
||||
}
|
||||
|
||||
function frameScript() {
|
||||
content.window.addEventListener("beforeunload", function (event) {
|
||||
sendAsyncMessage("Test:OnBeforeUnloadReceived");
|
||||
var str = "Leaving?";
|
||||
event.returnValue = str;
|
||||
return str;
|
||||
}, true);
|
||||
function injectBeforeUnload(browser) {
|
||||
return ContentTask.spawn(browser, null, function*() {
|
||||
content.window.addEventListener("beforeunload", function (event) {
|
||||
sendAsyncMessage("Test:OnBeforeUnloadReceived");
|
||||
var str = "Leaving?";
|
||||
event.returnValue = str;
|
||||
return str;
|
||||
}, true);
|
||||
});
|
||||
}
|
||||
|
||||
// Wait for onbeforeunload dialog, and dismiss it immediately.
|
||||
@ -49,9 +51,8 @@ add_task(function* () {
|
||||
let browser = tab.linkedBrowser;
|
||||
|
||||
ok(browser.isRemoteBrowser, "Browser should be remote.");
|
||||
browser.messageManager.loadFrameScript(
|
||||
"data:,(" + frameScript.toString() + ")();", true);
|
||||
|
||||
yield injectBeforeUnload(browser);
|
||||
// Navigate to a chrome page.
|
||||
let dialogShown1 = awaitAndCloseBeforeUnloadDialog(false);
|
||||
yield BrowserTestUtils.loadURI(browser, "about:support");
|
||||
@ -59,6 +60,7 @@ add_task(function* () {
|
||||
dialogShown1,
|
||||
BrowserTestUtils.browserLoaded(browser)
|
||||
]);
|
||||
|
||||
is(beforeUnloadCount, 1, "Should have received one beforeunload event.");
|
||||
ok(!browser.isRemoteBrowser, "Browser should not be remote.");
|
||||
|
||||
@ -66,8 +68,7 @@ add_task(function* () {
|
||||
ok(gBrowser.webNavigation.canGoBack, "Should be able to go back.");
|
||||
gBrowser.goBack();
|
||||
yield BrowserTestUtils.browserLoaded(browser);
|
||||
browser.messageManager.loadFrameScript(
|
||||
"data:,(" + frameScript.toString() + ")();", true);
|
||||
yield injectBeforeUnload(browser);
|
||||
|
||||
// Test that going forward triggers beforeunload prompt as well.
|
||||
ok(gBrowser.webNavigation.canGoForward, "Should be able to go forward.");
|
||||
|
Loading…
x
Reference in New Issue
Block a user