diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/components/privatebrowsing/test/browser/browser_privatebrowsing_lastpbcontextexited.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/privatebrowsing/test/browser/browser_privatebrowsing_lastpbcontextexited.js')
-rw-r--r-- | browser/components/privatebrowsing/test/browser/browser_privatebrowsing_lastpbcontextexited.js | 63 |
1 files changed, 63 insertions, 0 deletions
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); + } + ); +} |