dom/tests/mochitest/localstorage/test_appIsolation.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/tests/mochitest/localstorage/test_appIsolation.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,151 @@
     1.4 +<html xmlns="http://www.w3.org/1999/xhtml">
     1.5 +<head>
     1.6 +<title>localStorage app isolation</title>
     1.7 +
     1.8 +<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.10 +
    1.11 +<script type="application/javascript;version=1.7">
    1.12 +
    1.13 +SimpleTest.waitForExplicitFinish();
    1.14 +
    1.15 +var fileTestOnCurrentOrigin = (location.protocol + "//" + location.host + location.pathname)
    1.16 +                              .replace("test_a", "frameA");
    1.17 +
    1.18 +var previousPrefs = {
    1.19 +  mozBrowserFramesEnabled: undefined,
    1.20 +};
    1.21 +
    1.22 +try {
    1.23 +  previousPrefs.mozBrowserFramesEnabled = SpecialPowers.getBoolPref('dom.mozBrowserFramesEnabled');
    1.24 +} catch(e)
    1.25 +{
    1.26 +}
    1.27 +
    1.28 +SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true);
    1.29 +
    1.30 +SpecialPowers.addPermission("browser", true, window.document);
    1.31 +SpecialPowers.addPermission("embed-apps", true, window.document);
    1.32 +
    1.33 +var gData = [
    1.34 +  // APP 1
    1.35 +  {
    1.36 +    app: 'http://example.org/manifest.webapp',
    1.37 +    action: 'read-no',
    1.38 +  },
    1.39 +  {
    1.40 +    app: 'http://example.org/manifest.webapp',
    1.41 +    action: 'write',
    1.42 +  },
    1.43 +  {
    1.44 +    app: 'http://example.org/manifest.webapp',
    1.45 +    action: 'read-yes',
    1.46 +  },
    1.47 +  // APP 2
    1.48 +  {
    1.49 +    app: 'https://example.com/manifest.webapp',
    1.50 +    action: 'read-no',
    1.51 +  },
    1.52 +  {
    1.53 +    app: 'https://example.com/manifest.webapp',
    1.54 +    action: 'write',
    1.55 +  },
    1.56 +  {
    1.57 +    app: 'https://example.com/manifest.webapp',
    1.58 +    action: 'read-yes',
    1.59 +  },
    1.60 +  // Browser
    1.61 +  {
    1.62 +    browser: true,
    1.63 +    action: 'read-no',
    1.64 +  },
    1.65 +  {
    1.66 +    browser: true,
    1.67 +    action: 'write',
    1.68 +  },
    1.69 +  {
    1.70 +    browser: true,
    1.71 +    action: 'read-yes',
    1.72 +  },
    1.73 +  // Clear APP 1
    1.74 +  {
    1.75 +    app: 'http://example.org/manifest.webapp',
    1.76 +    action: 'clear',
    1.77 +  },
    1.78 +  // Clear APP 2
    1.79 +  {
    1.80 +    app: 'https://example.com/manifest.webapp',
    1.81 +    action: 'clear',
    1.82 +  },
    1.83 +  // Clear Browser
    1.84 +  {
    1.85 +    browser: true,
    1.86 +    action: 'clear',
    1.87 +  },
    1.88 +];
    1.89 +
    1.90 +function runTest()
    1.91 +{
    1.92 +  for (var i in gData) {
    1.93 +    var iframe = document.createElement('iframe');
    1.94 +    var data = gData[i];
    1.95 +
    1.96 +    if (data.app) {
    1.97 +      iframe.setAttribute('mozbrowser', '');
    1.98 +      iframe.setAttribute('mozapp', data.app);
    1.99 +    } else if (data.browser) {
   1.100 +      iframe.setAttribute('mozbrowser', '');
   1.101 +    }
   1.102 +
   1.103 +    if (data.app || data.browser) {
   1.104 +      iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
   1.105 +        is(e.detail.message, "success", "test number " + i);
   1.106 +
   1.107 +        document.body.removeChild(iframe);
   1.108 +
   1.109 +        i++;
   1.110 +        if (i >= gData.length) {
   1.111 +          localStorage.clear();
   1.112 +
   1.113 +          SpecialPowers.removePermission("browser", window.document);
   1.114 +          SpecialPowers.removePermission("embed-apps", window.document);
   1.115 +
   1.116 +          if (previousPrefs.mozBrowserFramesEnabled !== undefined) {
   1.117 +            SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', previousPrefs.mozBrowserFramesEnabled);
   1.118 +          }
   1.119 +
   1.120 +          SimpleTest.finish();
   1.121 +        } else {
   1.122 +          gTestRunner.next();
   1.123 +        }
   1.124 +      });
   1.125 +    }
   1.126 +
   1.127 +    iframe.src = fileTestOnCurrentOrigin + "?" + data.action;
   1.128 +
   1.129 +    document.body.appendChild(iframe);
   1.130 +
   1.131 +    yield undefined;
   1.132 +  }
   1.133 +}
   1.134 +
   1.135 +var gTestRunner = runTest();
   1.136 +
   1.137 +function startTest()
   1.138 +{
   1.139 +  is(localStorage.getItem("0"), null, "no data");
   1.140 +  localStorage.setItem("0", "foo");
   1.141 +  is(localStorage.getItem("0"), "foo", "data have been written");
   1.142 +
   1.143 +  gTestRunner.next();
   1.144 +}
   1.145 +
   1.146 +addLoadEvent(startTest);
   1.147 +
   1.148 +</script>
   1.149 +
   1.150 +</head>
   1.151 +
   1.152 +<body>
   1.153 +</body>
   1.154 +</html>

mercurial