browser_prompt_closed_window.js (1267B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * Check that if we loop prompts from a closed tab, they don't 8 * start showing up as window prompts. 9 */ 10 add_task(async function test_closed_tab_doesnt_show_prompt() { 11 let newWin = await BrowserTestUtils.openNewBrowserWindow(); 12 13 // Get a promise for the initial, in-tab prompt: 14 let promptPromise = BrowserTestUtils.promiseAlertDialogOpen(); 15 await ContentTask.spawn(newWin.gBrowser.selectedBrowser, [], function () { 16 // Don't want to block, so use setTimeout with 0 timeout: 17 content.setTimeout( 18 () => 19 content.eval( 20 'let i = 0; while (!prompt("Prompts a lot!") && i++ < 10);' 21 ), 22 0 23 ); 24 }); 25 // wait for the first prompt to have appeared: 26 await promptPromise; 27 28 // Now close the containing tab, and check for windowed prompts appearing. 29 let opened = false; 30 let obs = () => { 31 opened = true; 32 }; 33 Services.obs.addObserver(obs, "domwindowopened"); 34 registerCleanupFunction(() => 35 Services.obs.removeObserver(obs, "domwindowopened") 36 ); 37 await BrowserTestUtils.closeWindow(newWin); 38 39 ok(!opened, "Should not have opened a prompt when closing the main window."); 40 });