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 --- .../browser_privatebrowsing_lastpbcontextexited.js | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 browser/components/privatebrowsing/test/browser/browser_privatebrowsing_lastpbcontextexited.js (limited to 'browser/components/privatebrowsing/test/browser/browser_privatebrowsing_lastpbcontextexited.js') diff --git a/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_lastpbcontextexited.js b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_lastpbcontextexited.js new file mode 100644 index 0000000000..c46417933a --- /dev/null +++ b/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_lastpbcontextexited.js @@ -0,0 +1,63 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +function test() { + // We need to open a new window for this so that its docshell would get destroyed + // when clearing the PB mode flag. + function runTest(aCloseWindow, aCallback) { + let newWin = OpenBrowserWindow({ private: true }); + SimpleTest.waitForFocus(function () { + let expectedExiting = true; + let expectedExited = false; + let observerExiting = { + observe(aSubject, aTopic, aData) { + is( + aTopic, + "last-pb-context-exiting", + "Correct topic should be dispatched (exiting)" + ); + is(expectedExiting, true, "notification not expected yet (exiting)"); + expectedExited = true; + Services.obs.removeObserver( + observerExiting, + "last-pb-context-exiting" + ); + }, + }; + let observerExited = { + observe(aSubject, aTopic, aData) { + is( + aTopic, + "last-pb-context-exited", + "Correct topic should be dispatched (exited)" + ); + is(expectedExited, true, "notification not expected yet (exited)"); + Services.obs.removeObserver(observerExited, "last-pb-context-exited"); + aCallback(); + }, + }; + Services.obs.addObserver(observerExiting, "last-pb-context-exiting"); + Services.obs.addObserver(observerExited, "last-pb-context-exited"); + expectedExiting = true; + aCloseWindow(newWin); + newWin = null; + SpecialPowers.forceGC(); + }, newWin); + } + + waitForExplicitFinish(); + + runTest( + function (newWin) { + // Simulate pressing the window close button + newWin.document.getElementById("cmd_closeWindow").doCommand(); + }, + function () { + runTest(function (newWin) { + // Simulate closing the last tab + newWin.document.getElementById("cmd_close").doCommand(); + }, finish); + } + ); +} -- cgit v1.2.3