Bug 773373 part 5: Automatic tests. r=mounir
authorJan Varga <Jan.Varga@gmail.com>
Tue, 25 Sep 2012 16:06:28 -0700
changeset 108193 423c12f60b5dac5ff68dfeb59643c251fd89dd14
parent 108192 3c70558b823f26962b5f3b567efd8faebacfd57a
child 108194 7e92aec1bea5249458b451d628ea8dc409559364
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersmounir
bugs773373
milestone18.0a1
Bug 773373 part 5: Automatic tests. r=mounir
dom/tests/mochitest/localstorage/Makefile.in
dom/tests/mochitest/localstorage/frameAppIsolation.html
dom/tests/mochitest/localstorage/test_appIsolation.html
--- a/dom/tests/mochitest/localstorage/Makefile.in
+++ b/dom/tests/mochitest/localstorage/Makefile.in
@@ -7,31 +7,33 @@ DEPTH		= @DEPTH@
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= @relativesrcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MOCHITEST_FILES	= \
+    frameAppIsolation.html \
     frameBug624047.html \
     frameChromeSlave.html \
     frameKeySync.html \
     frameMasterEqual.html \
     frameMasterNotEqual.html \
     frameSlaveEqual.html \
     frameSlaveNotEqual.html \
     frameReplace.html \
     frameQuota.html \
     frameQuotaSessionOnly.html \
     frameOrder.html \
     interOriginFrame.js \
     interOriginTest.js \
     interOriginTest2.js \
     pbSwitch.js \
+    test_appIsolation.html \
     test_brokenUTF-16.html \
     test_bug624047.html \
     test_bug746272-1.html \
     test_bug746272-2.html \
     test_cookieBlock.html \
     test_cookieSession-phase1.html \
     test_cookieSession-phase2.html \
     test_embededNulls.html \
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/localstorage/frameAppIsolation.html
@@ -0,0 +1,35 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+  <title>slave for app isolation test</title>
+  <script type="text/javascript">
+  var success = false;
+
+  var action = window.location.search.substring(1);
+
+  switch (action) {
+    case "read-no":
+      if (localStorage.getItem("0") == null) {
+        success = true;
+      }
+      break;
+    case "write":
+      localStorage.setItem("0", "foo");
+      success = true;
+      break;
+    case "read-yes":
+      if (localStorage.getItem("0") == "foo") {
+        success = true;
+      }
+      break;
+    case "clear":
+      localStorage.clear();
+      success = true;
+      break;
+  }
+  success ? alert("success") : alert("failure");
+  </script>
+</head>
+
+<body>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/localstorage/test_appIsolation.html
@@ -0,0 +1,149 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<title>localStorage app isolation</title>
+
+<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+
+<script type="application/javascript;version=1.7">
+
+SimpleTest.waitForExplicitFinish();
+
+var fileTestOnCurrentOrigin = (location.protocol + "//" + location.host + location.pathname)
+                              .replace("test_a", "frameA");
+
+var previousPrefs = {
+  mozBrowserFramesEnabled: undefined,
+};
+
+try {
+  previousPrefs.mozBrowserFramesEnabled = SpecialPowers.getBoolPref('dom.mozBrowserFramesEnabled');
+} catch(e)
+{
+}
+
+SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true);
+
+SpecialPowers.addPermission("browser", true, window.document);
+
+var gData = [
+  // APP 1
+  {
+    app: 'http://example.org/manifest.webapp',
+    action: 'read-no',
+  },
+  {
+    app: 'http://example.org/manifest.webapp',
+    action: 'write',
+  },
+  {
+    app: 'http://example.org/manifest.webapp',
+    action: 'read-yes',
+  },
+  // APP 2
+  {
+    app: 'https://example.com/manifest.webapp',
+    action: 'read-no',
+  },
+  {
+    app: 'https://example.com/manifest.webapp',
+    action: 'write',
+  },
+  {
+    app: 'https://example.com/manifest.webapp',
+    action: 'read-yes',
+  },
+  // Browser
+  {
+    browser: true,
+    action: 'read-no',
+  },
+  {
+    browser: true,
+    action: 'write',
+  },
+  {
+    browser: true,
+    action: 'read-yes',
+  },
+  // Clear APP 1
+  {
+    app: 'http://example.org/manifest.webapp',
+    action: 'clear',
+  },
+  // Clear APP 2
+  {
+    app: 'https://example.com/manifest.webapp',
+    action: 'clear',
+  },
+  // Clear Browser
+  {
+    browser: true,
+    action: 'clear',
+  },
+];
+
+function runTest()
+{
+  for (var i in gData) {
+    var iframe = document.createElement('iframe');
+    var data = gData[i];
+
+    if (data.app) {
+      iframe.setAttribute('mozbrowser', '');
+      iframe.setAttribute('mozapp', data.app);
+    } else if (data.browser) {
+      iframe.setAttribute('mozbrowser', '');
+    }
+
+    if (data.app || data.browser) {
+      iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
+        is(e.detail.message, "success", "test number " + i);
+
+        document.body.removeChild(iframe);
+
+        i++;
+        if (i >= gData.length) {
+          localStorage.clear();
+
+          SpecialPowers.removePermission("browser", window.document);
+
+          if (previousPrefs.mozBrowserFramesEnabled !== undefined) {
+            SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', previousPrefs.mozBrowserFramesEnabled);
+          }
+
+          SimpleTest.finish();
+        } else {
+          gTestRunner.next();
+        }
+      });
+    }
+
+    iframe.src = fileTestOnCurrentOrigin + "?" + data.action;
+
+    document.body.appendChild(iframe);
+
+    yield;
+  }
+}
+
+var gTestRunner = runTest();
+
+function startTest()
+{
+  is(localStorage.getItem("0"), null, "no data");
+  localStorage.setItem("0", "foo");
+  is(localStorage.getItem("0"), "foo", "data have been written");
+
+  gTestRunner.next();
+}
+
+addLoadEvent(startTest);
+
+</script>
+
+</head>
+
+<body>
+</body>
+</html>