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
|
add_setup(async function () {
Services.prefs.setBoolPref("privacy.firstparty.isolate", true);
registerCleanupFunction(function () {
Services.prefs.clearUserPref("privacy.firstparty.isolate");
});
});
add_task(async function test_remote_window_open_js_uri() {
let win = await BrowserTestUtils.openNewBrowserWindow({ remote: true });
let browser = win.gBrowser.selectedBrowser;
Assert.ok(browser.isRemoteBrowser, "should be a remote browser");
BrowserTestUtils.loadURIString(browser, `javascript:1;`);
await BrowserTestUtils.browserLoaded(browser);
await SpecialPowers.spawn(browser, [], async function () {
Assert.ok(true, "origin " + content.document.nodePrincipal.origin);
Assert.ok(
content.document.nodePrincipal.isNullPrincipal,
"The principal of remote javascript: should be a NullPrincipal."
);
let str = content.document.nodePrincipal.originNoSuffix;
let expectDomain =
str.substring("moz-nullprincipal:{".length, str.length - 1) + ".mozilla";
Assert.equal(
content.document.nodePrincipal.originAttributes.firstPartyDomain,
expectDomain,
"remote javascript: should have firstPartyDomain set to " + expectDomain
);
});
win.close();
});
add_task(async function test_remote_window_open_js_uri2() {
let win = await BrowserTestUtils.openNewBrowserWindow({ remote: true });
let browser = win.gBrowser.selectedBrowser;
Assert.ok(browser.isRemoteBrowser, "should be a remote browser");
BrowserTestUtils.loadURIString(
browser,
`javascript:
let iframe = document.createElement("iframe");
iframe.src = "http://example.com";
iframe.id = "iframe1";
document.body.appendChild(iframe);
void(0);
`
);
await BrowserTestUtils.browserLoaded(browser, true, function (url) {
info("URL:" + url);
return url == "http://example.com/";
});
await SpecialPowers.spawn(browser, [], async function () {
Assert.ok(true, "origin " + content.document.nodePrincipal.origin);
Assert.ok(
content.document.nodePrincipal.isNullPrincipal,
"The principal of remote javascript: should be a NullPrincipal."
);
let str = content.document.nodePrincipal.originNoSuffix;
let expectDomain =
str.substring("moz-nullprincipal:{".length, str.length - 1) + ".mozilla";
Assert.equal(
content.document.nodePrincipal.originAttributes.firstPartyDomain,
expectDomain,
"remote javascript: should have firstPartyDomain set to " + expectDomain
);
let iframe = content.document.getElementById("iframe1");
await SpecialPowers.spawn(iframe, [expectDomain], function (domain) {
Assert.equal(
content.document.nodePrincipal.originAttributes.firstPartyDomain,
domain,
"iframe should have firstPartyDomain set to " + domain
);
});
});
win.close();
});
|