Bug 1331686: Test triggeringPrincipal for tabs openend through ctrl-click and open link in new tab. r=gijs
authorChristoph Kerschbaumer <ckerschb@christophkerschbaumer.com>
Sun, 22 Jan 2017 11:47:16 +0100
changeset 377855 3444d123020d204cbe94053c32987c4ee495c8f6
parent 377854 338508c5cc01f6ad368fc7672048c3153755b838
child 377856 f91b100895abbd8593169802185bb7b025c21faf
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
bugs1331686
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 1331686: Test triggeringPrincipal for tabs openend through ctrl-click and open link in new tab. r=gijs
browser/base/content/test/general/browser_e10s_about_page_triggeringprincipal.js
--- a/browser/base/content/test/general/browser_e10s_about_page_triggeringprincipal.js
+++ b/browser/base/content/test/general/browser_e10s_about_page_triggeringprincipal.js
@@ -5,17 +5,17 @@ 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() {
+add_task(function* test_principal_click() {
   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");
@@ -37,8 +37,88 @@ add_task(function* test_principal() {
         "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");
     });
   });
 });
+
+add_task(function* test_principal_ctrl_click() {
+  yield SpecialPowers.pushPrefEnv({
+    "set": [["security.sandbox.content.level", 1]],
+  });
+
+  yield BrowserTestUtils.withNewTab("about:test-about-principal-parent", function*(browser) {
+    let loadPromise = BrowserTestUtils.waitForNewTab(gBrowser, "about:test-about-principal-child");
+    // simulate ctrl+click
+    BrowserTestUtils.synthesizeMouseAtCenter("#aboutchildprincipal",
+                                             { ctrlKey: true, metaKey: true },
+                                             gBrowser.selectedBrowser);
+    let tab = yield loadPromise;
+    gBrowser.selectTabAtIndex(2);
+
+    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");
+    });
+    yield BrowserTestUtils.removeTab(tab);
+  });
+});
+
+add_task(function* test_principal_right_click_open_link_in_new_tab() {
+  yield SpecialPowers.pushPrefEnv({
+    "set": [["security.sandbox.content.level", 1]],
+  });
+  
+  yield BrowserTestUtils.withNewTab("about:test-about-principal-parent", function*(browser) {
+    let loadPromise = BrowserTestUtils.waitForNewTab(gBrowser, "about:test-about-principal-child");
+
+    // simulate right-click open link in tab
+    BrowserTestUtils.waitForEvent(document, "popupshown", false, event => {
+      // These are operations that must be executed synchronously with the event.
+      document.getElementById("context-openlinkintab").doCommand();
+      event.target.hidePopup();
+      return true;
+    });
+    BrowserTestUtils.synthesizeMouseAtCenter("#aboutchildprincipal",
+                                             { type: "contextmenu", button: 2 },
+                                             gBrowser.selectedBrowser);
+
+    let tab = yield loadPromise;
+    gBrowser.selectTabAtIndex(2);
+
+    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");
+    });
+    yield BrowserTestUtils.removeTab(tab);
+  });
+});