Bug 758258 - Part 1 - Create skeleton for extendedOrigin tests. r=sicking
authorMounir Lamouri <mounir.lamouri@gmail.com>
Thu, 19 Jul 2012 16:14:11 -0700
changeset 99852 f907bf664d47440f1bc85035f6e0ee99c66ed534
parent 99851 c06d60a5387004b3c06b14beec5a8a20928cd967
child 99853 c1fc9ea724acb51196daaf49c74b90f6475a057c
push id23151
push useremorley@mozilla.com
push dateFri, 20 Jul 2012 13:33:35 +0000
treeherdermozilla-central@3337f0685b75 [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 - Part 1 - Create skeleton for extendedOrigin 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,15 +13,18 @@ include $(DEPTH)/config/autoconf.mk
 
 MOCHITEST_FILES = 	test_bug423375.html \
                 test_bug246699.html \
                 test_bug292789.html \
                 test_bug470804.html \
                 test_disallowInheritPrincipal.html \
                 $(NULL)
 
+MOCHITEST_CHROME_FILES = test_principal_extendedorigin_appid_appstatus.html \
+                         $(NULL)
+
 test_bug292789.html : % : %.in
 	$(PYTHON) $(topsrcdir)/config/Preprocessor.py \
 	     $(AUTOMATION_PPARGS) $(DEFINES) $(ACDEFINES) $< > $@
 
 GARBAGE += test_bug292789.html
 
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/caps/tests/mochitest/test_principal_extendedorigin_appid_appstatus.html
@@ -0,0 +1,147 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=758258
+-->
+<head>
+  <meta charset="utf-8">
+  <title>Test for nsIPrincipal extendedOrigin, appStatus and appId</title>
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
+</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">
+
+/** Test for Bug 758258 **/
+
+SimpleTest.waitForExplicitFinish();
+
+var gData = [
+  {
+    app: "http://example.org/manifest.webapp",
+    origin: "http://example.org",
+  },
+  {
+    app: "https://example.com:443/manifest.webapp",
+    origin: "https://example.com",
+  },
+  {
+    app: "http://test1.example.org/manifest.webapp",
+    origin: "http://test1.example.org",
+  },
+  {
+    app: "http://test1.example.org:8000/manifest.webapp",
+    origin: "http://test1.example.org:8000",
+  },
+  {
+    app: "http://sub1.test1.example.org/manifest.webapp",
+    origin: "http://sub1.test1.example.org",
+  },
+  {
+    app: "http://example.org/foo/manifest.webapp",
+    origin: "http://example.org",
+  },
+  {
+    app: "http://example.org/bar/manifest.webapp",
+    origin: "http://example.org",
+  },
+  {
+    browser: true,
+    origin: "http://example.org",
+  },
+  {
+    origin: "http://example.org",
+  },
+  {
+    app: "http://example.org/wedonthaveanyappinthatdirectory/manifest.webapp",
+    origin: "http://example.org",
+  },
+  {
+    app: "http://example.org/manifest.webapp",
+    origin: "data:text/html,foobar",
+    test: [ "todo-origin" ],
+  },
+  {
+    app: "http://example.org/manifest.webapp",
+    origin: "data:text/html,foobar2",
+    test: [ "todo-origin" ],
+  },
+  {
+    origin: "file:///",
+  },
+  {
+    origin: "file:///tmp",
+  },
+  {
+    app: "http://example.org/manifest.webapp",
+    origin: "file:///",
+  },
+  {
+    app: "http://example.org/manifest.webapp",
+    origin: "file:///tmp",
+  },
+];
+
+var content = document.getElementById('content');
+var checkedCount = 0;
+var checksTodo = gData.length;
+
+function checkPrincipalForIFrame(aFrame, data) {
+  var principal = aFrame.contentDocument.nodePrincipal;
+
+  // TODO: TEMP.
+  if (!data.test) {
+    data.test = [];
+  }
+
+  if (data.test.indexOf('todo-origin') == -1) {
+    var origin = data.origin;
+    if (navigator.platform.indexOf("Mac") != 1) {
+      origin = origin.replace("file:///", "file:///private/");
+    }
+    is(principal.URI.origin, origin, 'the correct URL should have been loaded');
+  }
+
+  checkedCount++;
+  if (checkedCount == checksTodo) {
+    SimpleTest.finish();
+  }
+}
+
+is('appStatus' in document.nodePrincipal, false,
+   'appStatus should not be present in nsIPrincipal');
+is('extendedOrigin' in document.nodePrincipal, false,
+   'extendedOrigin should not be present in nsIPrincipal');
+is('appId' in document.nodePrincipal, false,
+   'appId should not be present in nsIPrincipal');
+
+gData.forEach(function(data) {
+  var iframe = document.createElement('iframe');
+  iframe.checkPrincipal = function() {
+    checkPrincipalForIFrame(this, data);
+  };
+
+  if (data.app) {
+    iframe.setAttribute('mozapp', data.app);
+    iframe.setAttribute('mozbrowser', '');
+  } else if (data.browser) {
+    iframe.setAttribute('mozbrowser', '');
+  }
+
+  iframe.src = data.origin;
+
+  iframe.addEventListener('load', iframe.checkPrincipal.bind(iframe));
+
+  content.appendChild(iframe);
+});
+
+</script>
+</pre>
+</body>
+</html>