Bug 1329032 - Test privileged about page to use SystemPrincipal as TriggeringPrincipal when loading about page in child. r=gijs

This commit is contained in:
Christoph Kerschbaumer 2017-01-17 21:52:37 +01:00
parent 05287d4fa8
commit 8c97c0cf8b
5 changed files with 149 additions and 0 deletions

View File

@ -135,6 +135,9 @@ support-files =
!/toolkit/mozapps/extensions/test/xpinstall/restartless.xpi
!/toolkit/mozapps/extensions/test/xpinstall/theme.xpi
!/toolkit/mozapps/extensions/test/xpinstall/slowinstall.sjs
file_about_child.html
file_about_parent.html
file_register_about_page.js
[browser_aboutAccounts.js]
skip-if = os == "linux" # Bug 958026
@ -481,6 +484,7 @@ tags = mcb
[browser_addCertException.js]
[browser_bug1045809.js]
tags = mcb
[browser_e10s_about_page_triggeringprincipal.js]
[browser_e10s_switchbrowser.js]
[browser_e10s_about_process.js]
[browser_e10s_chrome_process.js]

View File

@ -0,0 +1,44 @@
"use strict";
Cu.import("resource://gre/modules/Services.jsm");
registerCleanupFunction(function() {
Services.ppmm.broadcastAsyncMessage("AboutPrincipalTest:Unregister");
yield BrowserTestUtils.waitForMessage(Services.ppmm, "AboutPrincipalTest:Unregistered");
Services.ppmm.removeDelayedProcessScript(
"chrome://mochitests/content/browser/browser/base/content/test/general/file_register_about_page.js"
);
});
add_task(function* test_principal() {
Services.ppmm.loadProcessScript(
"chrome://mochitests/content/browser/browser/base/content/test/general/file_register_about_page.js",
true
);
yield BrowserTestUtils.withNewTab("about:test-about-principal-parent", function*(browser) {
let loadPromise = BrowserTestUtils.browserLoaded(browser, false, "about:test-about-principal-child");
let myLink = browser.contentDocument.getElementById("aboutchildprincipal");
myLink.click();
yield loadPromise;
yield ContentTask.spawn(gBrowser.selectedBrowser, {}, function*() {
let channel = content.document.docShell.currentDocumentChannel;
is(channel.originalURI.asciiSpec,
"about:test-about-principal-child",
"sanity check - make sure we test the principal for the correct URI");
let triggeringPrincipal = channel.loadInfo.triggeringPrincipal;
ok(Services.scriptSecurityManager.isSystemPrincipal(triggeringPrincipal),
"loading about: from privileged page must have a triggering of System");
let contentPolicyType = channel.loadInfo.externalContentPolicyType;
is(contentPolicyType, Ci.nsIContentPolicy.TYPE_DOCUMENT,
"sanity check - loading a top level document");
let loadingPrincipal = channel.loadInfo.loadingPrincipal;
is(loadingPrincipal, null,
"sanity check - load of TYPE_DOCUMENT must have a null loadingPrincipal");
});
});
});

View File

@ -0,0 +1,10 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test for Bug 1329032</title>
</head>
<body>
Just an about page that only loads in the child!
</body>
</html>

View File

@ -0,0 +1,10 @@
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Test for Bug 1329032</title>
</head>
<body>
<a href="about:test-about-principal-child" id="aboutchildprincipal">about:test-about-principal-child</a>
</body>
</html>

View File

@ -0,0 +1,81 @@
const { interfaces: Ci, results: Cr, manager: Cm, utils: Cu } = Components;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
function AboutPage(chromeURL, aboutHost, classID, description, uriFlags) {
this.chromeURL = chromeURL;
this.aboutHost = aboutHost;
this.classID = Components.ID(classID);
this.description = description;
this.uriFlags = uriFlags;
}
AboutPage.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule]),
getURIFlags(aURI) { // eslint-disable-line no-unused-vars
return this.uriFlags;
},
newChannel(aURI, aLoadInfo) {
let newURI = Services.io.newURI(this.chromeURL);
let channel = Services.io.newChannelFromURIWithLoadInfo(newURI,
aLoadInfo);
channel.originalURI = aURI;
if (this.uriFlags & Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT) {
channel.owner = null;
}
return channel;
},
createInstance(outer, iid) {
if (outer !== null) {
throw Cr.NS_ERROR_NO_AGGREGATION;
}
return this.QueryInterface(iid);
},
register() {
Cm.QueryInterface(Ci.nsIComponentRegistrar).registerFactory(
this.classID, this.description,
"@mozilla.org/network/protocol/about;1?what=" + this.aboutHost, this);
},
unregister() {
Cm.QueryInterface(Ci.nsIComponentRegistrar).unregisterFactory(
this.classID, this);
}
};
/* exported AboutPrincipalTest */
var AboutPrincipalTest = {};
XPCOMUtils.defineLazyGetter(AboutPrincipalTest, "aboutChild", () =>
new AboutPage("chrome://mochitests/content/browser/browser/base/content/test/general/file_about_child.html",
"test-about-principal-child",
"{df6cbd19-c95b-4011-874b-315347c0832c}",
"About Principal Child Test",
Ci.nsIAboutModule.URI_MUST_LOAD_IN_CHILD |
Ci.nsIAboutModule.ALLOW_SCRIPT)
);
XPCOMUtils.defineLazyGetter(AboutPrincipalTest, "aboutParent", () =>
new AboutPage("chrome://mochitests/content/browser/browser/base/content/test/general/file_about_parent.html",
"test-about-principal-parent",
"{15e1a03d-9f94-4352-bfb8-94216140d3ab}",
"About Principal Parent Test",
Ci.nsIAboutModule.ALLOW_SCRIPT)
);
AboutPrincipalTest.aboutParent.register();
AboutPrincipalTest.aboutChild.register();
function onUnregisterMessage() {
removeMessageListener("AboutPrincipalTest:Unregister", onUnregisterMessage);
AboutPrincipalTest.aboutParent.unregister();
AboutPrincipalTest.aboutChild.unregister();
sendAsyncMessage("AboutPrincipalTest:Unregistered");
}
addMessageListener("AboutPrincipalTest:Unregister", onUnregisterMessage);