3 const TOPIC = "browsing-context-discarded";
5 async function observeDiscarded(browsingContexts, callback) {
8 let promise = BrowserUtils.promiseObserved(TOPIC, subject => {
9 ok(subject instanceof BrowsingContext, "subject to be a BrowsingContext");
10 discarded.push(subject);
12 return browsingContexts.every(item => discarded.includes(item));
20 add_task(async function toplevelForNewWindow() {
21 let win = await BrowserTestUtils.openNewBrowserWindow();
22 let browsingContext = win.gBrowser.selectedBrowser.browsingContext;
24 await observeDiscarded([win.browsingContext, browsingContext], async () => {
25 await BrowserTestUtils.closeWindow(win);
29 add_task(async function toplevelForNewTab() {
30 let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
31 let browsingContext = tab.linkedBrowser.browsingContext;
33 let discarded = await observeDiscarded([browsingContext], () => {
34 BrowserTestUtils.removeTab(tab);
38 !discarded.includes(window.browsingContext),
39 "no notification for the current window's chrome browsing context"
43 add_task(async function subframe() {
44 let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
45 let browsingContext = await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
46 let iframe = content.document.createElement("iframe");
47 content.document.body.appendChild(iframe);
48 iframe.contentWindow.location = "https://example.com/";
49 return iframe.browsingContext;
52 let discarded = await observeDiscarded([browsingContext], async () => {
53 await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
54 let iframe = content.document.querySelector("iframe");
60 !discarded.includes(tab.browsingContext),
61 "no notification for toplevel browsing context"
64 BrowserTestUtils.removeTab(tab);