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
66
|
// Enable HTTPS-Only Mode
add_setup(async function () {
await SpecialPowers.pushPrefEnv({
set: [["dom.security.https_only_mode", true]],
});
});
// Copied from: https://searchfox.org/mozilla-central/rev/9f074fab9bf905fad62e7cc32faf121195f4ba46/browser/base/content/test/about/head.js
async function injectErrorPageFrame(tab, src, sandboxed) {
let loadedPromise = BrowserTestUtils.browserLoaded(
tab.linkedBrowser,
true,
null,
true
);
await SpecialPowers.spawn(
tab.linkedBrowser,
[src, sandboxed],
async function (frameSrc, frameSandboxed) {
let iframe = content.document.createElement("iframe");
iframe.src = frameSrc;
if (frameSandboxed) {
iframe.setAttribute("sandbox", "allow-scripts");
}
content.document.body.appendChild(iframe);
}
);
await loadedPromise;
}
async function openErrorPage(src, useFrame, privateWindow, sandboxed) {
let gb = gBrowser;
if (privateWindow) {
gb = privateWindow.gBrowser;
}
let dummyPage =
getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"https://example.com"
) + "dummy_page.html";
let tab;
if (useFrame) {
info("Loading error page in an iframe");
tab = await BrowserTestUtils.openNewForegroundTab(gb, dummyPage);
await injectErrorPageFrame(tab, src, sandboxed);
} else {
let ErrorPageLoaded;
tab = await BrowserTestUtils.openNewForegroundTab(
gb,
() => {
gb.selectedTab = BrowserTestUtils.addTab(gb, src);
let browser = gb.selectedBrowser;
ErrorPageLoaded = BrowserTestUtils.waitForErrorPage(browser);
},
false
);
info("Loading and waiting for the error page");
await ErrorPageLoaded;
}
return tab;
}
|