Bug 758258 - Tests. r=sicking
authorMounir Lamouri <mounir.lamouri@gmail.com>
Sat, 21 Jul 2012 17:14:25 -0700
changeset 100043 b3db4a4b400358dcb6dab69fb8319e185acf2ef3
parent 100042 52471266a6575a98576ee154bf406c9434e7a80c
child 100044 3dfc809486f5189a8473d8926cc81cb601687af1
push id12309
push usermlamouri@mozilla.com
push dateSun, 22 Jul 2012 00:40:39 +0000
treeherdermozilla-inbound@a2c2baca43d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs758258
milestone17.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 758258 - Tests. r=sicking
caps/tests/mochitest/Makefile.in
caps/tests/mochitest/test_principal_extendedorigin_appid_appstatus.html
--- a/caps/tests/mochitest/Makefile.in
+++ b/caps/tests/mochitest/Makefile.in
@@ -13,19 +13,21 @@ include $(DEPTH)/config/autoconf.mk
 
 MOCHITEST_FILES = 	test_bug423375.html \
                 test_bug246699.html \
                 test_bug292789.html \
                 test_bug470804.html \
                 test_disallowInheritPrincipal.html \
                 $(NULL)
 
-# Temporarily disabled for orange
-# MOCHITEST_CHROME_FILES = test_principal_extendedorigin_appid_appstatus.html \
-#                          $(NULL)
+# extendedOrigin test doesn't work on Windows, see bug 776296.
+ifneq ($(OS_ARCH),WINNT)
+MOCHITEST_CHROME_FILES = test_principal_extendedorigin_appid_appstatus.html \
+                         $(NULL)
+endif
 
 test_bug292789.html : % : %.in
 	$(PYTHON) $(topsrcdir)/config/Preprocessor.py \
 	     $(AUTOMATION_PPARGS) $(DEFINES) $(ACDEFINES) $< > $@
 
 GARBAGE += test_bug292789.html
 
 include $(topsrcdir)/config/rules.mk
--- a/caps/tests/mochitest/test_principal_extendedorigin_appid_appstatus.html
+++ b/caps/tests/mochitest/test_principal_extendedorigin_appid_appstatus.html
@@ -11,17 +11,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 </head>
 <body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=758258">Mozilla Bug 758258</a>
 <p id="display"></p>
 <div id="content">
   
 </div>
 <pre id="test">
-<script type="application/javascript">
+<script type="application/javascript;version=1.7">
 
 /** Test for Bug 758258 **/
 
 var Ci = Components.interfaces;
 
 SimpleTest.waitForExplicitFinish();
 
 /*
@@ -100,69 +100,189 @@ var gData = [
     src: "http://example.org/",
     isapp: false,
     // TODO: this is a browser because we need apps to be browser and it's not
     // an app because the manifest is invalid. Ideally, it should not be a
     // browser.
     browser: true,
     test: [ "eo-as-last" ],
   },
-/*
 //  {
 //    app: "http://example.org/manifest.webapp",
 //    src: "data:text/html,foobar",
 //    test: [ "todo-src" ],
 //  },
 //  {
 //    app: "http://example.org/manifest.webapp",
 //    src: "data:text/html,foobar2",
 //    test: [ "todo-src" ],
 //  },
-*/
   {
     src: "file:///",
     isapp: false,
     test: [ "eo-unique" ],
   },
   {
-    src: "file:///tmp",
+    src: "file:///tmp/",
     isapp: false,
     test: [ "eo-unique" ],
   },
   {
     app: "http://example.org/manifest.webapp",
     src: "file:///",
     isapp: true,
     test: [ "eo-unique" ],
   },
   {
     app: "http://example.org/manifest.webapp",
-    src: "file:///tmp",
+    src: "file:///tmp/",
     isapp: true,
     test: [ "eo-unique" ],
   },
+  // iframe inside an app is part of the app.
+  {
+    app: "http://example.org/manifest.webapp",
+    src: "http://example.org/",
+    isapp: true,
+    child: {
+      src: "http://example.org/chrome/",
+      isapp: true
+    },
+    test: [ "child-has-same-eo" ],
+  },
+  // app A inside app B aren't the same app.
+  {
+    app: "http://example.org/manifest.webapp",
+    src: "http://example.org/",
+    isapp: true,
+    child: {
+      app: "https://example.com/manifest.webapp",
+      src: "https://example.com/chrome/",
+      isapp: true
+    },
+    test: [ "child-has-different-eo", "child-has-same-appstatus", "child-has-different-appid" ],
+  },
+  // app A inside app A are the same app.
+  {
+    app: "http://example.org/manifest.webapp",
+    src: "http://example.org/",
+    isapp: true,
+    child: {
+      app: "http://example.org/manifest.webapp",
+      src: "http://example.org/chrome/",
+      isapp: true
+    },
+    test: [ "child-has-same-eo" ],
+  },
+  // app inside a regular iframe is an app.
+  {
+    src: "http://example.org/",
+    isapp: false,
+    child: {
+      app: "http://example.org/manifest.webapp",
+      src: "http://example.org/chrome/",
+      isapp: true
+    },
+    test: [ "child-has-different-eo", "child-has-different-appstatus", "child-has-different-appid" ],
+  },
+  // browser inside app is a browser, has appid but isn't installed.
+  {
+    src: "http://example.org/",
+    app: "http://example.org/manifest.webapp",
+    isapp: true,
+    child: {
+      src: "http://example.org/chrome/",
+      isapp: false,
+      browser: true,
+    },
+    test: [ "child-has-different-eo", "child-has-different-appstatus", "child-has-same-appid" ],
+  },
+  // app inside a browser is an app.
+  {
+    src: "http://example.org/",
+    isapp: false,
+    browser: true,
+    child: {
+      app: "http://example.org/manifest.webapp",
+      src: "http://example.org/chrome/",
+      isapp: true,
+    },
+    test: [ "child-has-different-eo", "child-has-different-appstatus", "child-has-different-appid" ],
+  },
+  // browser inside a browser are two browsers
+  {
+    src: "http://example.org/",
+    isapp: false,
+    browser: true,
+    child: {
+      src: "http://example.org/chrome/",
+      isapp: false,
+      browser: true,
+    },
+    test: [ "child-has-same-eo" ],
+  },
+  // browser inside a browser are two browsers
+  {
+    src: "http://example.org/",
+    isapp: false,
+    browser: true,
+    child: {
+      src: "https://example.com/chrome/",
+      isapp: false,
+      browser: true,
+    },
+    test: [ "child-has-different-eo", "child-has-same-appstatus", "child-has-same-appid" ],
+  },
+  // iframe containing a browser
+  {
+    src: "http://example.org/",
+    isapp: false,
+    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
+  {
+    src: "http://example.org/",
+    isapp: false,
+    browser: true,
+    child: {
+      src: "http://example.org/chrome/",
+      isapp: 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;
 
-function checkPrincipalForIFrame(aFrame, data) {
+function checkIFrame(aFrame, data) {
   var principal = aFrame.contentDocument.nodePrincipal;
 
   if (!data.test) {
     data.test = [];
   }
 
-// Temporarily disable that check.
-//  is(principal.URI.spec, data.src,
-//     'the correct URL should have been loaded');
+  if (navigator.platform.indexOf("Mac") != -1) {
+    is(principal.URI.spec,
+       data.src.replace('file:///tmp/', 'file:///private/tmp/'),
+       'the correct URL should have been loaded');
+  } else {
+    is(principal.URI.spec, data.src,
+       'the correct URL should have been loaded');
+  }
 
   if (data.isapp) {
     is(principal.appStatus, Ci.nsIPrincipal.APP_STATUS_INSTALLED,
        'this should be an installed app');
     isnot(principal.appId, Ci.nsIScriptSecurityManager.NO_APP_ID,
           "installed app should have a valid appId");
     isnot(principal.appId, Ci.nsIScriptSecurityManager.UNKNOWN_APP_ID,
           "installed app should have a valid appId");
@@ -185,57 +305,127 @@ function checkPrincipalForIFrame(aFrame,
     is(eoList.indexOf(principal.extendedOrigin), -1,
        "extendedOrigin should be unique");
   }
   if (data.test.indexOf("eo-as-last") != -1) {
     is(principal.extendedOrigin, eoList[eoList.length-1],
        "extendedOrigin should be the same as the last inserted one");
   }
 
+  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");
+    }
+
+    if (data.test.indexOf("child-has-same-eo") != -1) {
+      is(childPrincipal.extendedOrigin, principal.extendedOrigin,
+         "child should have the same extendedOrigin as parent");
+      is(childPrincipal.appStatus, principal.appStatus,
+         "child should have the same appStatus if it has the same extendedOrigin");
+      is(childPrincipal.appId, principal.appId,
+         "child should have the same appId if it has the same extendedOrigin");
+    }
+
+    if (data.test.indexOf("child-has-different-eo") != -1) {
+      isnot(childPrincipal.extendedOrigin, principal.extendedOrigin,
+            "child should not have the same extendedOrigin as parent");
+    }
+
+    if (data.test.indexOf("child-has-same-appstatus") != -1) {
+      is(childPrincipal.appStatus, principal.appStatus,
+         "childPrincipal and parent principal should have the same appStatus");
+    }
+
+    if (data.test.indexOf("child-has-different-appstatus") != -1) {
+      isnot(childPrincipal.appStatus, principal.appStatus,
+            "childPrincipal and parent principal should not have the same appStatus");
+    }
+
+    if (data.test.indexOf("child-has-same-appid") != -1) {
+      is(childPrincipal.appId, principal.appId,
+         "childPrincipal and parent principal should have the same appId");
+    }
+
+    if (data.test.indexOf("child-has-different-appid") != -1) {
+      isnot(childPrincipal.appId, principal.appId,
+            "childPrincipal and parent principal should have different appId");
+    }
+  }
+
   eoList.push(principal.extendedOrigin);
 
   checkedCount++;
   if (checkedCount == checksTodo) {
     SimpleTest.finish();
+  } else {
+    gTestRunner.next();
   }
 }
 
 is('appStatus' in document.nodePrincipal, true,
    'appStatus should be present in nsIPrincipal');
 is('extendedOrigin' in document.nodePrincipal, true,
    'extendedOrigin should be present in nsIPrincipal');
 is('appId' in document.nodePrincipal, true,
    'appId should be present in nsIPrincipal');
 
-SpecialPowers.pushPrefEnv({'set': [["dom.mozBrowserFramesEnabled", true]]}, function() {
+function runTest() {
+  // We want to use a generator. Those only work in a one level stack so we
+  // can't use .forEach() here.
+  for (var i=0; i<gData.length; ++i) {
+    let data = gData[i];
+
+    var iframe = document.createElement('iframe');
+    iframe.check = function() {
+      checkIFrame(this, data);
+    };
+    iframe.addChild = function() {
+      var childFrame = document.createElement('iframe');
+
+      if (data.child.app) {
+        childFrame.setAttribute('mozapp', data.child.app)
+        childFrame.setAttribute('mozbrowser', '');
+      } else if (data.child.browser) {
+        childFrame.setAttribute('mozbrowser', '');
+      }
+
+      childFrame.src = data.child.src;
 
-// For some unknown reasons, this test this to always timeout on Windows.
-if (navigator.platform.indexOf("Win") != -1) {
-  SimpleTest.finish();
-  return;
+      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', '');
+    }
+
+    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;
+  }
 }
 
-gData.forEach(function(data) {
-  var iframe = document.createElement('iframe');
-  iframe.checkPrincipal = function() {
-    checkPrincipalForIFrame(this, data);
-  };
+var gTestRunner = runTest();
 
-  if (data.app) {
-    iframe.setAttribute('mozapp', data.app);
-    iframe.setAttribute('mozbrowser', '');
-  } else if (data.browser) {
-    iframe.setAttribute('mozbrowser', '');
-  }
-
-  iframe.src = data.src;
-
-  iframe.addEventListener('load', iframe.checkPrincipal.bind(iframe));
-
-  content.appendChild(iframe);
-});
-
-});
+SpecialPowers.pushPrefEnv({'set': [["dom.mozBrowserFramesEnabled", true],
+                                   ["dom.mozBrowserFramesWhitelist", "http://example.org"]]},
+                           function() { gTestRunner.next(); });
 
 </script>
 </pre>
 </body>
 </html>