browser_restore_tabless_window.js (1802B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 /** 7 * It's possible for us to restore windows without tabs, 8 * when on Windows/Linux the user closes the last tab as 9 * a means of closing the last window. That last tab 10 * would appear as a closed tab in session state for the 11 * window, with no open tabs (so the state would be resumed 12 * as showing the homepage). See bug 490136 for context. 13 * This test checks that in this case, the resulting window 14 * is functional and indeed has the required previously 15 * closed tabs available. 16 */ 17 add_task(async function test_restoring_tabless_window() { 18 let newWin = await BrowserTestUtils.openNewBrowserWindow(); 19 let newState = { 20 windows: [ 21 { 22 tabs: [], 23 _closedTabs: [ 24 { 25 state: { entries: [{ url: "about:" }] }, 26 title: "About:", 27 }, 28 ], 29 }, 30 ], 31 }; 32 33 await setWindowState(newWin, newState, true); 34 let tab = await BrowserTestUtils.openNewForegroundTab( 35 newWin.gBrowser, 36 "https://example.com" 37 ); 38 await TabStateFlusher.flush(tab.linkedBrowser); 39 let receivedState = SessionStore.getWindowState(newWin); 40 let { tabs, selected } = receivedState.windows[0]; 41 is(tabs.length, 2, "Should have two tabs"); 42 is(selected, 2, "Should have selected the new tab"); 43 ok( 44 tabs[1]?.entries.some(e => e.url == "https://example.com/"), 45 "Should have found the new URL" 46 ); 47 48 let closedTabData = SessionStore.getClosedTabDataForWindow(newWin); 49 is(closedTabData.length, 1, "Should have found 1 closed tab"); 50 is( 51 closedTabData[0]?.state.entries[0].url, 52 "about:", 53 "Should have found the right URL for the closed tab" 54 ); 55 await BrowserTestUtils.closeWindow(newWin); 56 });