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 --- .../sessionstore/test/browser_closedId.js | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 browser/components/sessionstore/test/browser_closedId.js (limited to 'browser/components/sessionstore/test/browser_closedId.js') diff --git a/browser/components/sessionstore/test/browser_closedId.js b/browser/components/sessionstore/test/browser_closedId.js new file mode 100644 index 0000000000..6e5c9d7543 --- /dev/null +++ b/browser/components/sessionstore/test/browser_closedId.js @@ -0,0 +1,109 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const BACKUP_STATE = SessionStore.getBrowserState(); + +async function add_new_tab(URL) { + let tab = BrowserTestUtils.addTab(gBrowser, URL); + await BrowserTestUtils.browserLoaded(tab.linkedBrowser); + return tab; +} + +add_task(async function test_closedId_order() { + await SpecialPowers.pushPrefEnv({ + set: [ + ["browser.sessionstore.restore_on_demand", true], + ["browser.sessionstore.restore_tabs_lazily", true], + ], + }); + // reset to 0 + SessionStore.resetNextClosedId(); + await promiseBrowserState({ + windows: [ + { + selected: 1, // SessionStore uses 1-based indexing. + tabs: [ + { + entries: [], + }, + ], + _closedTabs: [ + { + state: { + entries: [ + { + url: "https://www.example.com/", + triggeringPrincipal_base64, + }, + ], + selected: 1, + }, + closedId: 0, + closedAt: Date.now() - 100, + title: "Example", + }, + { + state: { + entries: [ + { + url: "about:mozilla", + triggeringPrincipal_base64, + }, + ], + }, + closedId: 1, + closedAt: Date.now() - 50, + title: "about:mozilla", + }, + { + state: { + entries: [ + { + url: "https://www.example.net/", + triggeringPrincipal_base64, + }, + ], + }, + closedId: 2, + closedAt: Date.now(), + title: "Example", + }, + ], + }, + ], + }); + + let tab = await add_new_tab("about:firefoxview"); + + is( + SessionStore.getClosedTabCountForWindow(window), + 3, + "Closed tab count after restored session is 3" + ); + + let initialClosedId = + SessionStore.getClosedTabDataForWindow(window)[0].closedId; + + // If this fails, that means one of the closedId's in the stubbed data in this test needs to be updated + // to reflect what the initial closedId is when a new tab is open and closed (which may change as more tests + // for session store are added here). You can manually verify a change to stubbed data by commenting out + // this._resetClosedIds in SessionStore.sys.mjs temporarily and then the "Each tab has a unique closedId" case should fail. + is(initialClosedId, 0, "Initial closedId is 0"); + + await openAndCloseTab(window, "about:robots"); // closedId should be higher than the ones we just restored. + + let closedData = SessionStore.getClosedTabDataForWindow(window); + is(closedData.length, 4, "Should have data for 4 closed tabs."); + is( + new Set(closedData.map(t => t.closedId)).size, + 4, + "Each tab has a unique closedId" + ); + + BrowserTestUtils.removeTab(tab); + + // Clean up for the next task. + await promiseBrowserState(BACKUP_STATE); +}); -- cgit v1.2.3