browser_multiple_dialog_navigation.js (2274B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 add_task(async function test_multiple_dialog_navigation() { 7 await BrowserTestUtils.withNewTab( 8 "https://example.com/gone", 9 async browser => { 10 let firstDialogPromise = BrowserTestUtils.promiseAlertDialogOpen(); 11 // We're gonna queue up some dialogs, and navigate. The tasks queueing the dialog 12 // are going to get aborted when the navigation happened, but that's OK because by 13 // that time they will have done their job. Detect and swallow that specific 14 // exception: 15 let navigationCatcher = e => { 16 if (e.name == "AbortError" && e.message.includes("destroyed before")) { 17 return; 18 } 19 throw e; 20 }; 21 // Queue up 2 dialogs 22 let firstTask = SpecialPowers.spawn(browser, [], async function () { 23 content.eval(`alert('hi');`); 24 }).catch(navigationCatcher); 25 let secondTask = SpecialPowers.spawn(browser, [], async function () { 26 content.eval(`alert('hi again');`); 27 }).catch(navigationCatcher); 28 info("Waiting for first dialog."); 29 let dialogWin = await firstDialogPromise; 30 31 let secondDialogPromise = BrowserTestUtils.promiseAlertDialogOpen(); 32 dialogWin.document 33 .getElementById("commonDialog") 34 .getButton("accept") 35 .click(); 36 dialogWin = null; 37 38 info("Wait for second dialog to appear."); 39 let secondDialogWin = await secondDialogPromise; 40 let closedPromise = BrowserTestUtils.waitForEvent( 41 secondDialogWin, 42 "unload" 43 ); 44 let loadedOtherPage = BrowserTestUtils.waitForLocationChange( 45 gBrowser, 46 "https://example.org/gone" 47 ); 48 BrowserTestUtils.startLoadingURIString( 49 browser, 50 "https://example.org/gone" 51 ); 52 info("Waiting for the next page to load."); 53 await loadedOtherPage; 54 info( 55 "Waiting for second dialog to close. If we time out here that's a bug!" 56 ); 57 await closedPromise; 58 is(secondDialogWin.closed, true, "Should have closed second dialog."); 59 info("Ensure content tasks are done"); 60 await secondTask; 61 await firstTask; 62 } 63 ); 64 });