Files
tubestation/docshell/test/browser/browser_loadDisallowInherit.js
Dorel Luca 81b4b85d01 Backed out 8 changesets (bug 1412456) for ESlint failure on browser_urlbarKeepStateAcrossTabSwitches.js:13:49 r=backout on a CLOSED TREE
Backed out changeset 0e88de036c55 (bug 1412456)
Backed out changeset 49b93f807db0 (bug 1412456)
Backed out changeset 039e980b7dc6 (bug 1412456)
Backed out changeset c7698410ddbd (bug 1412456)
Backed out changeset e56a1ba26b7c (bug 1412456)
Backed out changeset 0c4506e124ac (bug 1412456)
Backed out changeset a7aec2ce903b (bug 1412456)
Backed out changeset 3e9fb71f1e8e (bug 1412456)
2017-12-07 07:09:33 +02:00

75 lines
2.2 KiB
JavaScript

/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
function test() {
waitForExplicitFinish();
// data: URI will only inherit principal only when the pref is false.
Services.prefs.setBoolPref("security.data_uri.unique_opaque_origin", false);
registerCleanupFunction(function () {
Services.prefs.clearUserPref("security.data_uri.unique_opaque_origin");
});
executeSoon(startTest);
}
function startTest() {
let tab = gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
let browser = gBrowser.getBrowserForTab(tab);
function loadURL(url, flags, func) {
browser.addEventListener("load", function loadListener(e) {
if (browser.currentURI.spec != url)
return;
browser.removeEventListener(e.type, loadListener, true);
func();
}, true);
browser.loadURIWithFlags(url, flags, null, null, null);
}
// Load a normal http URL
function testURL(url, func) {
loadURL("http://example.com/", 0, function () {
let pagePrincipal = browser.contentPrincipal;
ok(pagePrincipal, "got principal for http:// page");
// Now load the URL normally
loadURL(url, 0, function () {
ok(browser.contentPrincipal.equals(pagePrincipal), url + " should inherit principal");
// Now load the URL and disallow inheriting the principal
let webNav = Components.interfaces.nsIWebNavigation;
loadURL(url, webNav.LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL, function () {
let newPrincipal = browser.contentPrincipal;
ok(newPrincipal, "got inner principal");
ok(!newPrincipal.equals(pagePrincipal),
url + " should not inherit principal when loaded with DISALLOW_INHERIT_OWNER");
func();
});
});
});
}
let urls = [
"data:text/html,<body>hi",
// We used to test javascript: here as well, but now that we no longer run
// javascript: in a sandbox, we end up not running it at all in the
// DISALLOW_INHERIT_OWNER case, so never actually do a load for it at all.
];
function nextTest() {
let url = urls.shift();
if (url) {
testURL(url, nextTest);
} else {
gBrowser.removeTab(tab);
finish();
}
}
nextTest();
}