From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../sessionstore/test/browser_privatetabs.js | 60 ++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 browser/components/sessionstore/test/browser_privatetabs.js (limited to 'browser/components/sessionstore/test/browser_privatetabs.js') diff --git a/browser/components/sessionstore/test/browser_privatetabs.js b/browser/components/sessionstore/test/browser_privatetabs.js new file mode 100644 index 0000000000..237d9ff036 --- /dev/null +++ b/browser/components/sessionstore/test/browser_privatetabs.js @@ -0,0 +1,60 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +add_task(function cleanup() { + info("Forgetting closed tabs"); + forgetClosedTabs(window); +}); + +add_task(async function test_restore_pbm() { + // Clear the list of closed windows. + forgetClosedWindows(); + + // Create a new window to attach our frame script to. + let win = await promiseNewWindowLoaded({ private: true }); + + // Create a new tab in the new window that will load the frame script. + let tab = BrowserTestUtils.addTab(win.gBrowser, "about:mozilla"); + let browser = tab.linkedBrowser; + await promiseBrowserLoaded(browser); + + // Check that we consider the tab as private. + let state = JSON.parse(ss.getTabState(tab)); + ok(state.isPrivate, "tab considered private"); + + // Ensure that closed tabs in a private windows can be restored. + await SessionStoreTestUtils.closeTab(tab); + is(ss.getClosedTabCountForWindow(win), 1, "there is a single tab to restore"); + + // Ensure that closed private windows can never be restored. + await BrowserTestUtils.closeWindow(win); + is(ss.getClosedWindowCount(), 0, "no windows to restore"); +}); + +/** + * Tests the purgeDataForPrivateWindow SessionStore method. + */ +add_task(async function test_purge_pbm() { + info("Clear the list of closed windows."); + forgetClosedWindows(); + + info("Create a new window to attach our frame script to."); + let win = await promiseNewWindowLoaded({ private: true }); + + info("Create a new tab in the new window that will load the frame script."); + let tab = BrowserTestUtils.addTab(win.gBrowser, "about:mozilla"); + let browser = tab.linkedBrowser; + await promiseBrowserLoaded(browser); + + info("Ensure that closed tabs in a private windows can be restored."); + await SessionStoreTestUtils.closeTab(tab); + is(ss.getClosedTabCountForWindow(win), 1, "there is a single tab to restore"); + + info("Call purgeDataForPrivateWindow"); + ss.purgeDataForPrivateWindow(win); + + is(ss.getClosedTabCountForWindow(win), 0, "there is no tab to restore"); + + // Cleanup + await BrowserTestUtils.closeWindow(win); +}); -- cgit v1.2.3