Bug 1238160 - Test frame principal when toggling isolation. r=ehsan draft
authorJ. Ryan Stinnett <jryans@gmail.com>
Thu, 11 Feb 2016 17:08:24 -0600
changeset 330487 5dc2347a69c9f419ee71b1e66bb6ffd6748cb4f3
parent 330486 9b8d61406f36e23a31711f989811be8132e6d02c
child 514186 ecbfdeabeb8515ac319acb859b4b8f8000c2cfd7
push id10770
push userbmo:jryans@gmail.com
push dateThu, 11 Feb 2016 23:23:33 +0000
reviewersehsan
bugs1238160
milestone47.0a1
Bug 1238160 - Test frame principal when toggling isolation. r=ehsan Test frame principals in different configurations to verify the new isolated attribute works as expected. MozReview-Commit-ID: CQNRo2bK9iU
caps/tests/mochitest/test_principal_jarprefix_origin_appid_appstatus.html
--- a/caps/tests/mochitest/test_principal_jarprefix_origin_appid_appstatus.html
+++ b/caps/tests/mochitest/test_principal_jarprefix_origin_appid_appstatus.html
@@ -28,16 +28,18 @@ SimpleTest.waitForExplicitFinish();
  * - app: gives the app manifest URL, will set mozapp to it on the iframe;
  * - origin: gives the origin of the iframe. This is the URL thas is going to
  *           to be passed as iframe.src but also the expected principal's
  *           origin.
  * - isapp: tells if the iframe is really a mozapp. If the manifest url isn't
  *          valid, the iframe will not be considered as a mozapp.
  * - browser: say if the iframe should be a mozbrowser. This is implicit when
  *            app is set.
+ * - isolated: if origin isolation is enabled with browser frames.  Defaults to
+ *             true if unset.
  * - test: an array of tests to run for this test case:
  *   - eo-unique: the extendedOrigin of the prinicpal must be unique in the
  *                current list.
  *   - eo-as-last: the extendedOrigin of the principal must be the same as the
  *                 last added to the list.
  */
 var gData = [
   {
@@ -225,28 +227,69 @@ var gData = [
     browser: false,
     child: {
       src: "http://example.org/chrome/",
       isapp: false,
       browser: true,
     },
     test: [ "child-has-different-eo", "child-has-same-appstatus", "child-has-same-appid" ],
   },
-  // browser containing an iframe is part of the browser
+  // browser containing an iframe that is part of the browser
   {
     src: "http://example.org/",
     isapp: false,
     browser: true,
     child: {
       src: "http://example.org/chrome/",
       isapp: false,
       inIsolatedBrowser: true,
     },
     test: [ "child-has-same-eo" ],
   },
+  // iframe containing a browser with isolation disabled
+  {
+    src: "http://example.org/",
+    isapp: false,
+    browser: false,
+    child: {
+      src: "http://example.org/",
+      isapp: false,
+      browser: true,
+      isolated: false,
+    },
+    test: [ "child-has-same-eo" ],
+  },
+  // browser with isolation disabled containing an iframe that is part of the browser
+  {
+    src: "http://example.org/",
+    isapp: false,
+    browser: true,
+    isolated: false,
+    child: {
+      src: "http://example.org/chrome/",
+      isapp: false,
+      inIsolatedBrowser: false,
+    },
+    test: [ "child-has-same-eo" ],
+  },
+  // iframe with isolation enabled containing an iframe with isolation disabled
+  // (isolated only has an effect on browsers)
+  {
+    src: "http://example.org/",
+    isapp: false,
+    browser: false,
+    isolated: true,
+    child: {
+      src: "http://example.org/chrome/",
+      isapp: false,
+      browser: false,
+      isolated: false,
+    },
+    test: [ "child-has-same-eo" ],
+  },
 ];
 
 // The list of all data ids generated by this test.
 var eoList = [];
 
 var content = document.getElementById('content');
 var checkedCount = 0;
 var checksTodo = gData.length;
@@ -275,45 +318,57 @@ function checkIFrame(aFrame, data) {
     }
   } else {
     is(principal.appStatus, Ci.nsIPrincipal.APP_STATUS_NOT_INSTALLED,
        'this should not be an installed app');
     is(principal.appId, Ci.nsIScriptSecurityManager.NO_APP_ID,
        "principals from non-installed app should have NO_APP_ID");
   }
 
-  if (!data.isapp && !data.browser) {
+  if (!data.isapp && !data.browser ||
+      (data.browser && data.isolated === false)) {
     is(principal.jarPrefix, "",
-       'jarPrefix should return an empty string for non-app and non-browsers principals');
+       "jarPrefix should return an empty string for non-app, non-browsers, " +
+       "and browsers with isolation disabled");
   } else {
     isnot(principal.jarPrefix, "",
-          'jarPrefix should not return an empty string for apps or mozbrowsers');
+          "jarPrefix should not return an empty string for apps or browsers " +
+          "with isolation enabled");
   }
 
   if (data.test.indexOf("eo-unique") != -1) {
     is(eoList.indexOf(principal.jarPrefix + principal.origin), -1,
        "extended origin should be unique");
   }
   if (data.test.indexOf("eo-as-last") != -1) {
     is(principal.jarPrefix + principal.origin, eoList[eoList.length-1],
        "extended origin should be the same as the last inserted one");
   }
 
-  is(principal.isInIsolatedBrowserElement, !!data.browser,
+  let isolationExpected = false;
+  if (data.isolated !== false) {
+    isolationExpected = !!data.browser;
+  }
+  is(principal.isInIsolatedBrowserElement, isolationExpected,
      "check principal.isInIsolatedBrowserElement");
 
   if (data.child) {
     let childPrincipal = aFrame.contentWindow.frames[0].document.nodePrincipal;
 
     if (data.child.isapp) {
       is(childPrincipal.appStatus, Ci.nsIPrincipal.APP_STATUS_INSTALLED,
          "child should be an installed app");
     }
 
-    is(childPrincipal.isInIsolatedBrowserElement, !!data.child.browser || !!data.child.inIsolatedBrowser,
+    let childIsolationExpected = false;
+    if (data.child.isolated !== false) {
+      childIsolationExpected = !!data.child.browser ||
+                               !!data.child.inIsolatedBrowser;
+    }
+    is(childPrincipal.isInIsolatedBrowserElement, childIsolationExpected,
        "check childPrincipal.isInIsolatedBrowserElement");
 
     if (data.test.indexOf("child-has-same-eo") != -1) {
       is(childPrincipal.jarPrefix + childPrincipal.origin,
          principal.jarPrefix + principal.origin,
          "child should have the same extended origin as parent");
       is(childPrincipal.appStatus, principal.appStatus,
          "child should have the same appStatus if it has the same extended origin");
@@ -387,46 +442,56 @@ function runTest() {
 
       if (data.child.app) {
         childFrame.setAttribute('mozapp', data.child.app)
         childFrame.setAttribute('mozbrowser', '');
       } else if (data.child.browser) {
         childFrame.setAttribute('mozbrowser', '');
       }
 
+      if (data.child.isolated === false) {
+        childFrame.setAttribute("isolated", "false");
+      }
+
       childFrame.src = data.child.src;
 
       this.removeEventListener('load', this.addChild.bind(this));
       childFrame.addEventListener('load', this.check.bind(this));
 
       this.contentDocument.body.appendChild(childFrame);
     };
 
     if (data.app) {
       iframe.setAttribute('mozapp', data.app);
       iframe.setAttribute('mozbrowser', '');
     } else if (data.browser) {
       iframe.setAttribute('mozbrowser', '');
     }
 
+    if (data.isolated === false) {
+      iframe.setAttribute("isolated", "false");
+    }
+
     iframe.src = data.src;
 
     if (data.child) {
       iframe.addEventListener('load', iframe.addChild.bind(iframe));
     } else {
       iframe.addEventListener('load', iframe.check.bind(iframe));
     }
 
     content.appendChild(iframe);
 
     yield;
   }
 }
 
 var gTestRunner = runTest();
 
-SpecialPowers.pushPrefEnv({'set':[["dom.mozBrowserFramesEnabled", true]]},
-                           function() { gTestRunner.next(); });
+SpecialPowers.pushPrefEnv({"set": [
+  ["dom.mozBrowserFramesEnabled", true],
+  ["dom.browserFrameIsolation.disablingPossible", true],
+]}, function() { gTestRunner.next(); });
 
 </script>
 </pre>
 </body>
 </html>