1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
"use strict";
const TOPIC = "browsing-context-discarded";
async function observeDiscarded(browsingContexts, callback) {
let discarded = [];
let promise = BrowserUtils.promiseObserved(TOPIC, subject => {
ok(BrowsingContext.isInstance(subject), "subject to be a BrowsingContext");
discarded.push(subject);
return browsingContexts.every(item => discarded.includes(item));
});
await callback();
await promise;
return discarded;
}
add_task(async function toplevelForNewWindow() {
let win = await BrowserTestUtils.openNewBrowserWindow();
let browsingContext = win.gBrowser.selectedBrowser.browsingContext;
await observeDiscarded([win.browsingContext, browsingContext], async () => {
await BrowserTestUtils.closeWindow(win);
});
});
add_task(async function toplevelForNewTab() {
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
let browsingContext = tab.linkedBrowser.browsingContext;
let discarded = await observeDiscarded([browsingContext], () => {
BrowserTestUtils.removeTab(tab);
});
ok(
!discarded.includes(window.browsingContext),
"no notification for the current window's chrome browsing context"
);
});
add_task(async function subframe() {
let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser);
let browsingContext = await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
let iframe = content.document.createElement("iframe");
content.document.body.appendChild(iframe);
iframe.contentWindow.location = "https://example.com/";
return iframe.browsingContext;
});
let discarded = await observeDiscarded([browsingContext], async () => {
await SpecialPowers.spawn(tab.linkedBrowser, [], () => {
let iframe = content.document.querySelector("iframe");
iframe.remove();
});
});
ok(
!discarded.includes(tab.browsingContext),
"no notification for toplevel browsing context"
);
BrowserTestUtils.removeTab(tab);
});
|