Bug 1329032 - Test privileged about page to use SystemPrincipal as TriggeringPrincipal when loading about page in child. r=gijs
authorChristoph Kerschbaumer <ckerschb@christophkerschbaumer.com>
Wed, 18 Jan 2017 08:44:42 +0100
changeset 377081 5b544b8ab06b0d75bb3abb4095cceefeeebec525
parent 377080 a385d2425a76099cf77d1dddbc24a0915dd02077
child 377160 71b2ddbe1f88123ee0b20eb17a133ce5fa8fac9b
child 377202 0a7d9f3e25ab212e5305fb936fcc4b517155a0f6
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgijs
bugs1329032
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1329032 - Test privileged about page to use SystemPrincipal as TriggeringPrincipal when loading about page in child. r=gijs
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_e10s_about_page_triggeringprincipal.js
browser/base/content/test/general/file_about_child.html
browser/base/content/test/general/file_about_parent.html
browser/base/content/test/general/file_register_about_page.js
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -130,16 +130,19 @@ support-files =
   !/toolkit/mozapps/extensions/test/xpinstall/corrupt.xpi
   !/toolkit/mozapps/extensions/test/xpinstall/incompatible.xpi
   !/toolkit/mozapps/extensions/test/xpinstall/installtrigger.html
   !/toolkit/mozapps/extensions/test/xpinstall/redirect.sjs
   !/toolkit/mozapps/extensions/test/xpinstall/restartless-unsigned.xpi
   !/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
 support-files =
   content_aboutAccounts.js
 [browser_aboutCertError.js]
 [browser_aboutNetError.js]
 [browser_aboutSupport_newtab_security_state.js]
@@ -477,16 +480,17 @@ skip-if = (os == "win" && !debug)
 [browser_zbug569342.js]
 skip-if = e10s || debug # Bug 1094240 - has findbar-related failures
 [browser_registerProtocolHandler_notification.js]
 [browser_no_mcb_on_http_site.js]
 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]
 [browser_e10s_javascript.js]
 [browser_blockHPKP.js]
 tags = psm
 [browser_mcb_redirect.js]
 tags = mcb
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/browser_e10s_about_page_triggeringprincipal.js
@@ -0,0 +1,44 @@
+"use strict";
+Cu.import("resource://gre/modules/Services.jsm");
+
+registerCleanupFunction(function() {
+  Services.ppmm.broadcastAsyncMessage("AboutPrincipalTest:Unregister");
+  BrowserTestUtils.waitForMessage(Services.ppmm, "AboutPrincipalTest:Unregistered").then(
+    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");
+    });
+  });
+});
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/file_about_child.html
@@ -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>
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/file_about_parent.html
@@ -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>
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/file_register_about_page.js
@@ -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);