browser_tab_replace_while_loading.js (2557B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /* Test for bug 1578379. */ 7 8 add_task(async function test_window_open_about_blank() { 9 const URL = 10 "http://mochi.test:8888/browser/docshell/test/browser/file_open_about_blank.html"; 11 let firstTab = await BrowserTestUtils.openNewForegroundTab(gBrowser, URL); 12 let promiseTabOpened = BrowserTestUtils.waitForNewTab( 13 gBrowser, 14 "about:blank" 15 ); 16 17 info("Opening about:blank using a click"); 18 await SpecialPowers.spawn(firstTab.linkedBrowser, [""], async function () { 19 content.document.querySelector("#open").click(); 20 }); 21 22 info("Waiting for the second tab to be opened"); 23 let secondTab = await promiseTabOpened; 24 25 info("Detaching tab"); 26 let windowOpenedPromise = BrowserTestUtils.waitForNewWindow(); 27 gBrowser.replaceTabWithWindow(secondTab); 28 let win = await windowOpenedPromise; 29 30 info("Asserting document is visible"); 31 let tab = win.gBrowser.selectedTab; 32 await SpecialPowers.spawn(tab.linkedBrowser, [""], async function () { 33 is( 34 content.document.visibilityState, 35 "visible", 36 "Document should be visible" 37 ); 38 }); 39 40 await BrowserTestUtils.closeWindow(win); 41 await BrowserTestUtils.removeTab(firstTab); 42 }); 43 44 add_task(async function test_detach_loading_page() { 45 const URL = 46 "http://mochi.test:8888/browser/docshell/test/browser/file_slow_load.sjs"; 47 // Open a dummy tab so that detaching the second tab works. 48 let dummyTab = await BrowserTestUtils.openNewForegroundTab( 49 gBrowser, 50 "about:blank" 51 ); 52 let slowLoadingTab = await BrowserTestUtils.openNewForegroundTab( 53 gBrowser, 54 URL, 55 /* waitForLoad = */ false 56 ); 57 58 info("Wait for content document to be created"); 59 await BrowserTestUtils.waitForCondition(async function () { 60 return SpecialPowers.spawn( 61 slowLoadingTab.linkedBrowser, 62 [URL], 63 async function (url) { 64 return content.document.documentURI == url; 65 } 66 ); 67 }); 68 69 info("Detaching tab"); 70 let windowOpenedPromise = BrowserTestUtils.waitForNewWindow(); 71 gBrowser.replaceTabWithWindow(slowLoadingTab); 72 let win = await windowOpenedPromise; 73 74 info("Asserting document is visible"); 75 let tab = win.gBrowser.selectedTab; 76 await SpecialPowers.spawn(tab.linkedBrowser, [""], async function () { 77 is(content.document.readyState, "loading"); 78 is(content.document.visibilityState, "visible"); 79 }); 80 81 await BrowserTestUtils.closeWindow(win); 82 await BrowserTestUtils.removeTab(dummyTab); 83 });