From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../test/browser_restore_tabless_window.js | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 browser/components/sessionstore/test/browser_restore_tabless_window.js (limited to 'browser/components/sessionstore/test/browser_restore_tabless_window.js') diff --git a/browser/components/sessionstore/test/browser_restore_tabless_window.js b/browser/components/sessionstore/test/browser_restore_tabless_window.js new file mode 100644 index 0000000000..cffb2159f5 --- /dev/null +++ b/browser/components/sessionstore/test/browser_restore_tabless_window.js @@ -0,0 +1,56 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +/** + * It's possible for us to restore windows without tabs, + * when on Windows/Linux the user closes the last tab as + * a means of closing the last window. That last tab + * would appear as a closed tab in session state for the + * window, with no open tabs (so the state would be resumed + * as showing the homepage). See bug 490136 for context. + * This test checks that in this case, the resulting window + * is functional and indeed has the required previously + * closed tabs available. + */ +add_task(async function test_restoring_tabless_window() { + let newWin = await BrowserTestUtils.openNewBrowserWindow(); + let newState = { + windows: [ + { + tabs: [], + _closedTabs: [ + { + state: { entries: [{ url: "about:" }] }, + title: "About:", + }, + ], + }, + ], + }; + + await setWindowState(newWin, newState, true); + let tab = await BrowserTestUtils.openNewForegroundTab( + newWin.gBrowser, + "https://example.com" + ); + await TabStateFlusher.flush(tab.linkedBrowser); + let receivedState = SessionStore.getWindowState(newWin); + let { tabs, selected } = receivedState.windows[0]; + is(tabs.length, 2, "Should have two tabs"); + is(selected, 2, "Should have selected the new tab"); + ok( + tabs[1]?.entries.some(e => e.url == "https://example.com/"), + "Should have found the new URL" + ); + + let closedTabData = SessionStore.getClosedTabDataForWindow(newWin); + is(closedTabData.length, 1, "Should have found 1 closed tab"); + is( + closedTabData[0]?.state.entries[0].url, + "about:", + "Should have found the right URL for the closed tab" + ); + await BrowserTestUtils.closeWindow(newWin); +}); -- cgit v1.2.3