зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1485305 - docshell/ Ensure loadURI always passes a triggeringPrincipal() r=bgrins
Differential Revision: https://phabricator.services.mozilla.com/D4556 --HG-- extra : source : 980570093e18dfa77b28173dc18beb27f663bc1e extra : intermediate-source : 14fe80bbe0838259e36edc24e6a99c431388a123
This commit is contained in:
Родитель
45825d47d3
Коммит
d8c962ddb9
|
@ -14,14 +14,14 @@ add_task(async function runTests() {
|
|||
let browser = tab.linkedBrowser;
|
||||
|
||||
let loaded = BrowserTestUtils.browserLoaded(browser);
|
||||
browser.loadURI("about:config");
|
||||
BrowserTestUtils.loadURI(browser, "about:config");
|
||||
let href = await loaded;
|
||||
is(href, "about:config", "Check about:config loaded");
|
||||
|
||||
// Using a dummy onunload listener to disable the bfcache as that can prevent
|
||||
// the test browser load detection mechanism from working.
|
||||
loaded = BrowserTestUtils.browserLoaded(browser);
|
||||
browser.loadURI("data:text/html,<body%20onunload=''><iframe></iframe></body>");
|
||||
BrowserTestUtils.loadURI(browser, "data:text/html,<body%20onunload=''><iframe></iframe></body>");
|
||||
href = await loaded;
|
||||
is(href, "data:text/html,<body%20onunload=''><iframe></iframe></body>",
|
||||
"Check data URL loaded");
|
||||
|
|
|
@ -104,7 +104,7 @@ add_task(async function test() {
|
|||
|
||||
buttonId = "button0";
|
||||
url = TEST_PATH + "file_bug1415918_beforeunload_2.html";
|
||||
browser.loadURI(url);
|
||||
BrowserTestUtils.loadURI(browser, url);
|
||||
await BrowserTestUtils.browserLoaded(browser, false, url);
|
||||
buttonId = "";
|
||||
|
||||
|
@ -158,7 +158,7 @@ add_task(async function test() {
|
|||
|
||||
buttonId = "button0";
|
||||
url = TEST_PATH + "file_bug1415918_beforeunload_3.html";
|
||||
browser.loadURI(url);
|
||||
BrowserTestUtils.loadURI(browser, url);
|
||||
await BrowserTestUtils.browserLoaded(browser, false, url);
|
||||
|
||||
// Prompt is shown, user clicks OK.
|
||||
|
|
|
@ -113,5 +113,5 @@ function test() {
|
|||
// Now open the test page in a new tab.
|
||||
gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser);
|
||||
BrowserTestUtils.waitForContentEvent(gBrowser.selectedBrowser, "DOMContentLoaded", true).then(onPageLoad);
|
||||
gBrowser.selectedBrowser.loadURI(pageurl);
|
||||
BrowserTestUtils.loadURI(gBrowser.selectedBrowser, pageurl);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ add_task(async function runTests() {
|
|||
|
||||
// Check if all history listeners are always notified.
|
||||
info("# part 1");
|
||||
await whenPageShown(browser, () => browser.loadURI("http://www.example.com/"));
|
||||
await whenPageShown(browser, () => BrowserTestUtils.loadURI(browser, "http://www.example.com/"));
|
||||
await checkListeners("newentry", "shistory has a new entry");
|
||||
ok(browser.canGoBack, "we can go back");
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ add_task(async function test_dataURI_unique_opaque_origin() {
|
|||
let pagePrincipal = browser.contentPrincipal;
|
||||
info("pagePrincial " + pagePrincipal.origin);
|
||||
|
||||
browser.loadURI("data:text/html,hi");
|
||||
BrowserTestUtils.loadURI(browser, "data:text/html,hi");
|
||||
await BrowserTestUtils.browserLoaded(browser);
|
||||
|
||||
await ContentTask.spawn(browser, { principal: pagePrincipal }, async function(args) {
|
||||
|
|
|
@ -6,8 +6,12 @@ function test() {
|
|||
|
||||
// data: URI will only inherit principal only when the pref is false.
|
||||
Services.prefs.setBoolPref("security.data_uri.unique_opaque_origin", false);
|
||||
// data: URIs will only open at the top level when the pref is false
|
||||
// or the use of system principal but we can't use that to test here.
|
||||
Services.prefs.setBoolPref("security.data_uri.block_toplevel_data_uri_navigations", false);
|
||||
registerCleanupFunction(function () {
|
||||
Services.prefs.clearUserPref("security.data_uri.unique_opaque_origin");
|
||||
Services.prefs.clearUserPref("security.data_uri.block_toplevel_data_uri_navigations");
|
||||
});
|
||||
|
||||
executeSoon(startTest);
|
||||
|
@ -18,26 +22,31 @@ function startTest() {
|
|||
|
||||
let browser = gBrowser.getBrowserForTab(tab);
|
||||
|
||||
function loadURL(url, flags, func) {
|
||||
function loadURL(url, flags, triggeringPrincipal, func) {
|
||||
BrowserTestUtils.browserLoaded(browser, false, url).then(() => {
|
||||
func();
|
||||
});
|
||||
browser.loadURI(url, { flags });
|
||||
browser.loadURI(url, { flags, triggeringPrincipal });
|
||||
}
|
||||
|
||||
// Load a normal http URL
|
||||
function testURL(url, func) {
|
||||
loadURL("http://example.com/", 0, function () {
|
||||
let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].
|
||||
getService(Ci.nsIScriptSecurityManager);
|
||||
let ios = Cc["@mozilla.org/network/io-service;1"].
|
||||
getService(Ci.nsIIOService);
|
||||
let artificialPrincipal = secMan.createCodebasePrincipal(ios.newURI("http://example.com/"), {});
|
||||
loadURL("http://example.com/", 0, artificialPrincipal, function () {
|
||||
let pagePrincipal = browser.contentPrincipal;
|
||||
ok(pagePrincipal, "got principal for http:// page");
|
||||
|
||||
// Now load the URL normally
|
||||
loadURL(url, 0, function () {
|
||||
loadURL(url, 0, artificialPrincipal, function () {
|
||||
ok(browser.contentPrincipal.equals(pagePrincipal), url + " should inherit principal");
|
||||
|
||||
// Now load the URL and disallow inheriting the principal
|
||||
let webNav = Ci.nsIWebNavigation;
|
||||
loadURL(url, webNav.LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL, function () {
|
||||
loadURL(url, webNav.LOAD_FLAGS_DISALLOW_INHERIT_PRINCIPAL, artificialPrincipal, function () {
|
||||
let newPrincipal = browser.contentPrincipal;
|
||||
ok(newPrincipal, "got inner principal");
|
||||
ok(!newPrincipal.equals(pagePrincipal),
|
||||
|
|
|
@ -19,8 +19,11 @@ function test() {
|
|||
createInstance(Ci.nsIMIMEInputStream);
|
||||
postStream.addHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
postStream.setData(dataStream);
|
||||
var systemPrincipal = Cc["@mozilla.org/systemprincipal;1"]
|
||||
.getService(Ci.nsIPrincipal);
|
||||
|
||||
tab.linkedBrowser.loadURI("http://mochi.test:8888/browser/docshell/test/browser/print_postdata.sjs", {
|
||||
triggeringPrincipal: systemPrincipal,
|
||||
postData: postStream,
|
||||
});
|
||||
BrowserTestUtils.browserLoaded(tab.linkedBrowser).then(() => {
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
title="112564 test">
|
||||
|
||||
<script type="application/javascript"><![CDATA[
|
||||
ChromeUtils.import("resource://testing-common/BrowserTestUtils.jsm");
|
||||
const LISTEN_EVENTS = ["load", "unload", "pageshow", "pagehide"];
|
||||
|
||||
var gBrowser;
|
||||
|
@ -88,7 +89,7 @@
|
|||
gExpected = [{type: "pagehide", persisted: true},
|
||||
{type: "load", title: "test1"},
|
||||
{type: "pageshow", title: "test1", persisted: false}];
|
||||
gBrowser.loadURI(test1DocURI);
|
||||
BrowserTestUtils.loadURI(gBrowser, test1DocURI);
|
||||
yield undefined;
|
||||
|
||||
var test2Doc = "data:text/html,<html><head><title>test2</title></head>" +
|
||||
|
@ -97,7 +98,7 @@
|
|||
gExpected = [{type: "pagehide", title: "test1", persisted: true},
|
||||
{type: "load", title: "test2"},
|
||||
{type: "pageshow", title: "test2", persisted: false}];
|
||||
gBrowser.loadURI(test2Doc);
|
||||
BrowserTestUtils.loadURI(gBrowser, test2Doc);
|
||||
yield undefined;
|
||||
|
||||
// Now go back in history. First page has been cached.
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
title="215405 test">
|
||||
|
||||
<script type="application/javascript"><![CDATA[
|
||||
ChromeUtils.import("resource://testing-common/BrowserTestUtils.jsm");
|
||||
var imports = [ "SimpleTest", "is", "isnot", "ok"];
|
||||
for (var name of imports) {
|
||||
window[name] = window.opener.wrappedJSObject[name];
|
||||
|
@ -61,7 +62,7 @@
|
|||
var testName = "[nostore]";
|
||||
|
||||
// Load a page with a no-store header
|
||||
gBrowser.loadURI(nostoreURI);
|
||||
BrowserTestUtils.loadURI(gBrowser, nostoreURI);
|
||||
yield undefined;
|
||||
|
||||
|
||||
|
@ -87,7 +88,7 @@
|
|||
// Load a new document into the browser
|
||||
var simple = "data:text/html,<html><head><title>test2</title></head>" +
|
||||
"<body>test2</body></html>";
|
||||
gBrowser.loadURI(simple);
|
||||
BrowserTestUtils.loadURI(gBrowser, simple);
|
||||
yield undefined;
|
||||
|
||||
|
||||
|
@ -111,7 +112,7 @@
|
|||
|
||||
// Load a page with a no-cache header. This should not be
|
||||
// restricted like no-store (bug 567365)
|
||||
gBrowser.loadURI(nocacheURI);
|
||||
BrowserTestUtils.loadURI(gBrowser, nocacheURI);
|
||||
yield undefined;
|
||||
|
||||
|
||||
|
@ -134,7 +135,7 @@
|
|||
isnot(scrollY, originalYPosition,
|
||||
testName + " failed to scroll window vertically");
|
||||
|
||||
gBrowser.loadURI(simple);
|
||||
BrowserTestUtils.loadURI(gBrowser, simple);
|
||||
yield undefined;
|
||||
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
title="364461 test">
|
||||
|
||||
<script type="application/javascript"><![CDATA[
|
||||
|
||||
ChromeUtils.import("resource://testing-common/BrowserTestUtils.jsm");
|
||||
const LISTEN_EVENTS = ["load", "unload", "pageshow", "pagehide"];
|
||||
|
||||
var gBrowser;
|
||||
|
@ -76,7 +76,6 @@
|
|||
}
|
||||
|
||||
function* testsIterator() {
|
||||
|
||||
// Tests 1 + 2:
|
||||
// Back/forward between two simple documents. Bfcache will be used.
|
||||
|
||||
|
@ -87,7 +86,7 @@
|
|||
|
||||
{type: "load", title: "test1"},
|
||||
{type: "pageshow", title: "test1", persisted: false}];
|
||||
gBrowser.loadURI(test1Doc);
|
||||
BrowserTestUtils.loadURI(gBrowser, test1Doc);
|
||||
yield undefined;
|
||||
|
||||
var test2Doc = "data:text/html,<html><head><title>test2</title></head>" +
|
||||
|
@ -96,7 +95,7 @@
|
|||
gExpected = [{type: "pagehide", title: "test1", persisted: true},
|
||||
{type: "load", title: "test2"},
|
||||
{type: "pageshow", title: "test2", persisted: false}];
|
||||
gBrowser.loadURI(test2Doc);
|
||||
BrowserTestUtils.loadURI(gBrowser, test2Doc);
|
||||
yield undefined;
|
||||
|
||||
gExpected = [{type: "pagehide", title: "test2", persisted: true},
|
||||
|
@ -134,7 +133,7 @@
|
|||
{type: "pageshow", title: "test3-nested1", persisted: false},
|
||||
{type: "load", title: "test3"},
|
||||
{type: "pageshow", title: "test3", persisted: false}];
|
||||
gBrowser.loadURI(test3Doc);
|
||||
BrowserTestUtils.loadURI(gBrowser, test3Doc);
|
||||
yield undefined;
|
||||
|
||||
var test4Doc = "data:text/html,<html><head><title>test4</title></head>" +
|
||||
|
@ -145,7 +144,7 @@
|
|||
{type: "pagehide", title: "test3-nested2", persisted: true},
|
||||
{type: "load", title: "test4"},
|
||||
{type: "pageshow", title: "test4", persisted: false}];
|
||||
gBrowser.loadURI(test4Doc);
|
||||
BrowserTestUtils.loadURI(gBrowser, test4Doc);
|
||||
yield undefined;
|
||||
|
||||
gExpected = [{type: "pagehide", title: "test4", persisted: true},
|
||||
|
@ -175,7 +174,7 @@
|
|||
gExpected = [{type: "pagehide", title: "test4", persisted: true},
|
||||
{type: "load", title: "test5"},
|
||||
{type: "pageshow", title: "test5", persisted: false}];
|
||||
gBrowser.loadURI(test5Doc);
|
||||
BrowserTestUtils.loadURI(gBrowser, test5Doc);
|
||||
yield undefined;
|
||||
|
||||
var test6Doc = "data:text/html,<html><head><title>test6</title></head>" +
|
||||
|
@ -185,7 +184,7 @@
|
|||
{type: "unload", title: "test5"},
|
||||
{type: "load", title: "test6"},
|
||||
{type: "pageshow", title: "test6", persisted: false}];
|
||||
gBrowser.loadURI(test6Doc);
|
||||
BrowserTestUtils.loadURI(gBrowser, test6Doc);
|
||||
yield undefined;
|
||||
|
||||
gExpected = [{type: "pagehide", title: "test6", persisted: true},
|
||||
|
@ -221,7 +220,7 @@
|
|||
{type: "pageshow", title: "test7-nested1", persisted: false},
|
||||
{type: "load", title: "test7"},
|
||||
{type: "pageshow", title: "test7", persisted: false}];
|
||||
gBrowser.loadURI(test7Doc);
|
||||
BrowserTestUtils.loadURI(gBrowser, test7Doc);
|
||||
yield undefined;
|
||||
|
||||
// Simulates a click on the link inside the iframe
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
title="396519 test">
|
||||
|
||||
<script type="application/javascript"><![CDATA[
|
||||
|
||||
ChromeUtils.import("resource://testing-common/BrowserTestUtils.jsm");
|
||||
const LISTEN_EVENTS = ["pageshow"];
|
||||
|
||||
var gBrowser;
|
||||
|
@ -93,7 +93,6 @@
|
|||
}
|
||||
|
||||
function* testsIterator() {
|
||||
|
||||
// Tests 1 + 2:
|
||||
// Back/forward between two simple documents. Bfcache will be used.
|
||||
|
||||
|
@ -102,33 +101,33 @@
|
|||
|
||||
gTestCount++;
|
||||
gExpected = [false];
|
||||
gBrowser.loadURI(test1Doc);
|
||||
BrowserTestUtils.loadURI(gBrowser, test1Doc);
|
||||
yield undefined;
|
||||
|
||||
gTestCount++;
|
||||
gExpected = [true, false];
|
||||
var test2Doc = test1Doc.replace(/1/,"2");
|
||||
gBrowser.loadURI(test2Doc);
|
||||
BrowserTestUtils.loadURI(gBrowser, test2Doc);
|
||||
yield undefined;
|
||||
|
||||
gTestCount++;
|
||||
gExpected = [true, true, false];
|
||||
gBrowser.loadURI(test1Doc);
|
||||
BrowserTestUtils.loadURI(gBrowser, test1Doc);
|
||||
yield undefined;
|
||||
|
||||
gTestCount++;
|
||||
gExpected = [true, true, true, false];
|
||||
gBrowser.loadURI(test2Doc);
|
||||
BrowserTestUtils.loadURI(gBrowser, test2Doc);
|
||||
yield undefined;
|
||||
|
||||
gTestCount++;
|
||||
gExpected = [false, true, true, true, false];
|
||||
gBrowser.loadURI(test1Doc);
|
||||
BrowserTestUtils.loadURI(gBrowser, test1Doc);
|
||||
yield undefined;
|
||||
|
||||
gTestCount++;
|
||||
gExpected = [false, false, true, true, true, false];
|
||||
gBrowser.loadURI(test2Doc);
|
||||
BrowserTestUtils.loadURI(gBrowser, test2Doc);
|
||||
yield undefined;
|
||||
|
||||
gTestCount++;
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
<script type="application/javascript" src= "chrome://mochikit/content/chrome-harness.js" />
|
||||
<script type="application/javascript" src="docshell_helpers.js" />
|
||||
<script type="application/javascript"><![CDATA[
|
||||
|
||||
|
||||
ChromeUtils.import("resource://testing-common/BrowserTestUtils.jsm");
|
||||
// Define the generator-iterator for the tests.
|
||||
var tests = testIterator();
|
||||
|
||||
|
@ -50,14 +51,14 @@
|
|||
getService(Ci.nsIObserverService);
|
||||
os.addObserver(observer, "content-document-global-created");
|
||||
|
||||
browser.loadURI("http://mochi.test:8888/tests/docshell/test/chrome/582176_dummy.html");
|
||||
BrowserTestUtils.loadURI(browser, "http://mochi.test:8888/tests/docshell/test/chrome/582176_dummy.html");
|
||||
yield undefined;
|
||||
is(browser.contentWindow.testVar, undefined,
|
||||
"variable unexpectedly there already");
|
||||
browser.contentWindow.wrappedJSObject.testVar = 1;
|
||||
is(notificationCount, 1, "Should notify on first navigation");
|
||||
|
||||
browser.loadURI("http://mochi.test:8888/tests/docshell/test/chrome/582176_dummy.html?2");
|
||||
BrowserTestUtils.loadURI(browser, "http://mochi.test:8888/tests/docshell/test/chrome/582176_dummy.html?2");
|
||||
yield undefined;
|
||||
is(browser.contentWindow.wrappedJSObject.testVar, undefined,
|
||||
"variable should no longer be there");
|
||||
|
@ -69,7 +70,7 @@
|
|||
"variable should still be there");
|
||||
is(notificationCount, 2, "Should not notify on back navigation");
|
||||
|
||||
browser.loadURI("http://mochi.test:8888/tests/docshell/test/chrome/582176_xml.xml");
|
||||
BrowserTestUtils.loadURI(browser, "http://mochi.test:8888/tests/docshell/test/chrome/582176_xml.xml");
|
||||
yield undefined;
|
||||
is(browser.contentDocument.body.textContent, "xslt result",
|
||||
"Transform performed successfully");
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
title="92598 test">
|
||||
|
||||
<script type="application/javascript"><![CDATA[
|
||||
ChromeUtils.import("resource://testing-common/BrowserTestUtils.jsm");
|
||||
const LISTEN_EVENTS = ["load", "unload", "pageshow", "pagehide"];
|
||||
|
||||
var gBrowser;
|
||||
|
@ -87,7 +88,7 @@
|
|||
gExpected = [{type: "pagehide", persisted: true},
|
||||
{type: "load", title: "test1"},
|
||||
{type: "pageshow", title: "test1", persisted: false}];
|
||||
gBrowser.loadURI(test1DocURI);
|
||||
BrowserTestUtils.loadURI(gBrowser, test1DocURI);
|
||||
yield undefined;
|
||||
|
||||
var test2Doc = "data:text/html,<html><head><title>test2</title></head>" +
|
||||
|
@ -97,7 +98,7 @@
|
|||
{type: "unload", title: "test1"},
|
||||
{type: "load", title: "test2"},
|
||||
{type: "pageshow", title: "test2", persisted: false}];
|
||||
gBrowser.loadURI(test2Doc);
|
||||
BrowserTestUtils.loadURI(gBrowser, test2Doc);
|
||||
yield undefined;
|
||||
|
||||
// Now go back in history. First page should not have been cached.
|
||||
|
|
|
@ -6,6 +6,7 @@ var imports = [ "SimpleTest", "is", "isnot", "ok", "onerror", "todo",
|
|||
for (var name of imports) {
|
||||
window[name] = window.opener.wrappedJSObject[name];
|
||||
}
|
||||
ChromeUtils.import("resource://testing-common/BrowserTestUtils.jsm");
|
||||
|
||||
/**
|
||||
* Define global constants and variables.
|
||||
|
@ -169,7 +170,7 @@ function doPageNavigation(params) {
|
|||
}
|
||||
else if (uri) {
|
||||
gNavType = NAV_URI;
|
||||
TestWindow.getBrowser().loadURI(uri);
|
||||
BrowserTestUtils.loadURI(TestWindow.getBrowser(), uri);
|
||||
}
|
||||
else if (reload) {
|
||||
gNavType = NAV_RELOAD;
|
||||
|
|
|
@ -101,7 +101,7 @@ function step3() {
|
|||
}
|
||||
}).then(() => {
|
||||
// Navigate tab 2 to a different page
|
||||
ctx.tab2Browser.loadURI(testPath + "bug343515_pg3.html");
|
||||
BrowserTestUtils.loadURI(ctx.tab2Browser, testPath + "bug343515_pg3.html");
|
||||
|
||||
// bug343515_pg3.html consists of a page with two iframes, one of which
|
||||
// contains another iframe, so there'll be a total of 4 load events
|
||||
|
@ -170,7 +170,7 @@ function step5() {
|
|||
return BrowserTestUtils.switchTab(gBrowser, ctx.tab1);
|
||||
}).then(() => {
|
||||
// Navigate to page 3
|
||||
ctx.tab1Browser.loadURI(testPath + "bug343515_pg3.html");
|
||||
BrowserTestUtils.loadURI(ctx.tab1Browser, testPath + "bug343515_pg3.html");
|
||||
|
||||
// bug343515_pg3.html consists of a page with two iframes, one of which
|
||||
// contains another iframe, so there'll be a total of 4 load events
|
||||
|
|
Загрузка…
Ссылка в новой задаче