michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: "use strict"; michael@0: michael@0: const TEST_URL = "http://example.com/browser/toolkit/components/startup/tests/browser/beforeunload.html"; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: ignoreAllUncaughtExceptions(); michael@0: michael@0: let win2 = window.openDialog(location, "", "chrome,all,dialog=no", "about:blank"); michael@0: win2.addEventListener("load", function onLoad() { michael@0: win2.removeEventListener("load", onLoad); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(TEST_URL); michael@0: let browser = gBrowser.selectedBrowser; michael@0: michael@0: whenBrowserLoaded(browser, function () { michael@0: let seenDialog = false; michael@0: michael@0: // Cancel the prompt the first time. michael@0: waitForOnBeforeUnloadDialog(browser, (btnLeave, btnStay) => { michael@0: seenDialog = true; michael@0: btnStay.click(); michael@0: }); michael@0: michael@0: let appStartup = Cc['@mozilla.org/toolkit/app-startup;1']. michael@0: getService(Ci.nsIAppStartup); michael@0: appStartup.quit(Ci.nsIAppStartup.eAttemptQuit); michael@0: ok(seenDialog, "Should have seen a prompt dialog"); michael@0: ok(!win2.closed, "Shouldn't have closed the additional window"); michael@0: win2.close(); michael@0: michael@0: // Leave the page the second time. michael@0: waitForOnBeforeUnloadDialog(browser, (btnLeave, btnStay) => { michael@0: btnLeave.click(); michael@0: }); michael@0: michael@0: gBrowser.removeTab(gBrowser.selectedTab); michael@0: executeSoon(finish); michael@0: }); michael@0: }); michael@0: }