Bug 1397365: Part 8 - Change the expected behavior for firstPartyDomain javascript: url tests. r?allstars.chh
With the change to nodefaultsrc, we now don't load the initial about:blank,
so when we test for javascript: protocol loaded into an empty window,
we will get empty firstPartyDomain.
MozReview-Commit-ID: CRWV22uCRpf
--- a/browser/components/originattributes/test/browser/browser_firstPartyIsolation_aboutPages.js
+++ b/browser/components/originattributes/test/browser/browser_firstPartyIsolation_aboutPages.js
@@ -7,43 +7,43 @@ add_task(async function setup() {
});
/**
* For loading the initial about:blank in e10s mode, it will be loaded with
* NullPrincipal, and we also test if the firstPartyDomain of the origin
* attributes is got from the origin itself.
*/
add_task(async function test_remote_window_open_aboutBlank() {
- let win = await BrowserTestUtils.openNewBrowserWindow({ remote: true });
+ let win = await BrowserTestUtils.openNewBrowserWindow({ remote: true }, "about:blank");
let browser = win.gBrowser.selectedBrowser;
Assert.ok(browser.isRemoteBrowser, "should be a remote browser");
- await ContentTask.spawn(browser, {}, async function() {
+ let attrs = { firstPartyDomain: "about.ef2a7dd5-93bc-417f-a698-142c3116864f.mozilla" };
+ await ContentTask.spawn(browser, attrs, async function(expectedAttrs) {
info("origin " + content.document.nodePrincipal.origin);
Assert.ok(content.document.nodePrincipal.isNullPrincipal,
"The principal of remote about:blank should be a NullPrincipal.");
- let str = content.document.nodePrincipal.originNoSuffix;
- let expectDomain = str.substring("moz-nullprincipal:{".length, str.length - 1) + ".mozilla";
+ let expectDomain = expectedAttrs.firstPartyDomain;
Assert.equal(content.document.nodePrincipal.originAttributes.firstPartyDomain,
expectDomain,
"remote about:blank should have firstPartyDomain set to " + expectDomain);
});
win.close();
});
/**
* For loading the initial about:blank in non-e10s mode, it will be loaded with
* a null principal. So we test if it has correct firstPartyDomain set.
*/
add_task(async function test_nonremote_window_open_aboutBlank() {
- let win = await BrowserTestUtils.openNewBrowserWindow({remote: false});
+ let win = await BrowserTestUtils.openNewBrowserWindow({remote: false}, "about:blank");
let browser = win.gBrowser.selectedBrowser;
Assert.ok(!browser.isRemoteBrowser, "shouldn't be a remote browser");
let attrs = { firstPartyDomain: "about.ef2a7dd5-93bc-417f-a698-142c3116864f.mozilla" };
await ContentTask.spawn(browser, attrs, async function(expectAttrs) {
Assert.ok(!content.document.nodePrincipal.isCodebasePrincipal,
"The principal of non-remote about:blank should not be a codebase principal.");
@@ -68,17 +68,17 @@ function frame_script() {
* Check if data: URI inherits firstPartyDomain from about:blank correctly.
*/
add_task(async function test_remote_window_open_data_uri() {
// allow top level data: URI navigations, otherwise
// <a href="data:" would fail.
await SpecialPowers.pushPrefEnv({
"set": [["security.data_uri.block_toplevel_data_uri_navigations", false]]
});
- let win = await BrowserTestUtils.openNewBrowserWindow({ remote: true });
+ let win = await BrowserTestUtils.openNewBrowserWindow({ remote: true }, "about:blank");
let browser = win.gBrowser.selectedBrowser;
let mm = browser.messageManager;
mm.loadFrameScript("data:,(" + frame_script.toString() + ")();", true);
await BrowserTestUtils.browserLoaded(browser, false, function(url) {
return url == "data:text/plain,hello";
});
@@ -95,17 +95,17 @@ add_task(async function test_remote_wind
win.close();
});
/**
* data: document contains an iframe, and we test that iframe should inherit
* origin attributes from the data: document.
*/
add_task(async function test_remote_window_open_data_uri2() {
- let win = await BrowserTestUtils.openNewBrowserWindow({ remote: true });
+ let win = await BrowserTestUtils.openNewBrowserWindow({ remote: true }, "about:blank");
let browser = win.gBrowser.selectedBrowser;
// The iframe test2.html will fetch test2.js, which will have cookies.
const DATA_URI = `data:text/html,
<iframe id="iframe1" src="http://mochi.test:8888/browser/browser/components/originattributes/test/browser/test2.html"></iframe>`;
browser.loadURI(DATA_URI);
await BrowserTestUtils.browserLoaded(browser, true);
--- a/browser/components/originattributes/test/browser/browser_firstPartyIsolation_js_uri.js
+++ b/browser/components/originattributes/test/browser/browser_firstPartyIsolation_js_uri.js
@@ -2,40 +2,42 @@ add_task(async function setup() {
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 });
+ // Load a new browser window without any document
+ let win = await BrowserTestUtils.openNewBrowserWindow({ remote: true }, "");
let browser = win.gBrowser.selectedBrowser;
Assert.ok(browser.isRemoteBrowser, "should be a remote browser");
browser.loadURI(`javascript:1;`);
await ContentTask.spawn(browser, {}, async function() {
info("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";
+ // Since there is no document loaded into the <browser>, the domain is empty
+ let expectDomain = "";
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 });
+ // Load a new browser window with a custom document
+ let win = await BrowserTestUtils.openNewBrowserWindow({ remote: true }, "data:text/html,<html><?html>");
let browser = win.gBrowser.selectedBrowser;
Assert.ok(browser.isRemoteBrowser, "should be a remote browser");
browser.loadURI(`javascript:
let iframe = document.createElement("iframe");
iframe.src = "http://example.com";
iframe.id = "iframe1";
@@ -49,18 +51,18 @@ add_task(async function test_remote_wind
});
await ContentTask.spawn(browser, {}, async function() {
info("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";
+ // Since there is no document loaded into the <browser>, the domain is empty
+ let expectDomain = "";
Assert.equal(content.document.nodePrincipal.originAttributes.firstPartyDomain,
expectDomain,
"remote javascript: should have firstPartyDomain set to " + expectDomain);
let iframe = content.document.getElementById("iframe1");
Assert.equal(iframe.contentDocument.nodePrincipal.originAttributes.firstPartyDomain,
expectDomain,
"iframe should have firstPartyDomain set to " + expectDomain);