Bug 1329032 - Test privileged about page to use SystemPrincipal as TriggeringPrincipal when loading about page in child. r=gijs
☠☠ backed out by 56f0b3f7b125 ☠ ☠
authorChristoph Kerschbaumer <ckerschb@christophkerschbaumer.com>
Tue, 17 Jan 2017 21:52:37 +0100
changeset 374726 16c4f0df527dfd31aead2e20cc7fa39a07d06806
parent 374725 54f7bfe3ca1159493abdf19bb94e76e566cd021c
child 374727 ec08fbdc84b278afa68994acd2c75011d412e227
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [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]
@@ -476,16 +479,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");
+  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");
+    });
+  });
+});
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);