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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
<!DOCTYPE HTML>
<html>
<head>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<iframe id="tls1frame" src="https://tls1.example.com/"></iframe>
<script>
"use strict";
add_task(async function test_frame() {
let win = SpecialPowers.wrap(window);
info(`id=${win.browsingContext.id}`);
let [docURI, curURI] = await SpecialPowers.spawnChrome([win.browsingContext.id], async id => {
let bc = BrowsingContext.get(id);
return [
bc.currentWindowGlobal.documentURI.spec,
bc.currentURI.spec,
];
});
info(`docURI=${docURI}, curURI=${curURI}`);
is(window.location.href, curURI, "curURI has the expected value");
is(window.location.href, docURI, "documentURI has the expected value");
});
add_task(async function test_tls1_frame() {
let expframe = SpecialPowers.wrap(document.getElementById("tls1frame"));
let [docURI, curURI] = await SpecialPowers.spawnChrome(
[expframe.browsingContext.id], async id => {
const { TestUtils } = ChromeUtils.importESModule(
"resource://testing-common/TestUtils.sys.mjs"
);
let bc = BrowsingContext.get(id);
// awkwardly wait for the current window global to update to the error page.
// would be nice to do just about anything else here...
await TestUtils.waitForCondition(
() =>
bc.currentURI && bc.currentURI.spec != "about:blank" &&
bc.currentWindowGlobal && bc.currentWindowGlobal.documentURI.spec != "about:blank",
"waiting for current window global to be non-initial");
info(`currentWindowGlobal has updated in the parent!`);
return [
bc.currentWindowGlobal.documentURI.spec,
bc.currentURI.spec,
];
});
info(`docURI=${docURI}, curURI=${curURI}`);
is(curURI, "https://tls1.example.com/", "curURI has expected value");
ok(docURI.startsWith("about:neterror"), "documentURI starts with about:neterror");
});
let BROADCAST_ONLOAD_URL =
new URL("file_broadcast_currenturi_onload.html", location.href);
async function broadcastLoadTest(baseURI, callback) {
// Bug 1746646: Make mochitests work with TCP enabled (cookieBehavior = 5)
// Acquire storage access permission here so that the BroadcastChannel used to
// communicate with the opened windows works in xorigin tests. Otherwise,
// the iframe containing this page is isolated from first-party storage access,
// which isolates BroadcastChannel communication.
if (isXOrigin) {
await SpecialPowers.pushPrefEnv({
set: [["privacy.partition.always_partition_third_party_non_cookie_storage", false]],
});
SpecialPowers.wrap(document).notifyUserGestureActivation();
await SpecialPowers.addPermission(
"storageAccessAPI",
true,
window.location.href
);
await SpecialPowers.wrap(document).requestStorageAccess();
}
let loaded = new Promise(resolve => {
let chan = new BroadcastChannel("test_broadcast_onload");
chan.onmessage = event => {
resolve(event.data);
};
});
let srcURL = new URL(BROADCAST_ONLOAD_URL.pathname, baseURI);
callback(srcURL.href);
let results = await loaded;
for (let { location, curURI, docURI } of results) {
info(`location=${location}, docURI=${docURI}, curURI=${curURI}`);
is(location, curURI, "curURI has expected value");
is(location, docURI, "documentURI has expected value");
}
}
async function normalFrameLoadTest(base) {
await broadcastLoadTest(base, src => {
let frame = document.createElement("iframe");
frame.src = src;
document.body.appendChild(frame);
});
}
async function normalPopupLoadTest(base, flags = "") {
await broadcastLoadTest(base, src => {
window.open(src, null, flags);
});
}
add_task(async function test_sameorigin_frame() {
await normalFrameLoadTest(location.href);
})
add_task(async function test_crossorigin_frame() {
await normalFrameLoadTest("https://example.com");
});
add_task(async function test_sameorigin_popup() {
await normalPopupLoadTest(location.href);
await normalPopupLoadTest(location.href, "noopener");
});
add_task(async function test_crossorigin_popup() {
await normalPopupLoadTest("https://example.com");
await normalPopupLoadTest("https://example.com", "noopener");
});
</script>
</body>
</html>
|