dom/tests/mochitest/localstorage/test_appIsolation.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <html xmlns="http://www.w3.org/1999/xhtml">
     2 <head>
     3 <title>localStorage app isolation</title>
     5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     8 <script type="application/javascript;version=1.7">
    10 SimpleTest.waitForExplicitFinish();
    12 var fileTestOnCurrentOrigin = (location.protocol + "//" + location.host + location.pathname)
    13                               .replace("test_a", "frameA");
    15 var previousPrefs = {
    16   mozBrowserFramesEnabled: undefined,
    17 };
    19 try {
    20   previousPrefs.mozBrowserFramesEnabled = SpecialPowers.getBoolPref('dom.mozBrowserFramesEnabled');
    21 } catch(e)
    22 {
    23 }
    25 SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true);
    27 SpecialPowers.addPermission("browser", true, window.document);
    28 SpecialPowers.addPermission("embed-apps", true, window.document);
    30 var gData = [
    31   // APP 1
    32   {
    33     app: 'http://example.org/manifest.webapp',
    34     action: 'read-no',
    35   },
    36   {
    37     app: 'http://example.org/manifest.webapp',
    38     action: 'write',
    39   },
    40   {
    41     app: 'http://example.org/manifest.webapp',
    42     action: 'read-yes',
    43   },
    44   // APP 2
    45   {
    46     app: 'https://example.com/manifest.webapp',
    47     action: 'read-no',
    48   },
    49   {
    50     app: 'https://example.com/manifest.webapp',
    51     action: 'write',
    52   },
    53   {
    54     app: 'https://example.com/manifest.webapp',
    55     action: 'read-yes',
    56   },
    57   // Browser
    58   {
    59     browser: true,
    60     action: 'read-no',
    61   },
    62   {
    63     browser: true,
    64     action: 'write',
    65   },
    66   {
    67     browser: true,
    68     action: 'read-yes',
    69   },
    70   // Clear APP 1
    71   {
    72     app: 'http://example.org/manifest.webapp',
    73     action: 'clear',
    74   },
    75   // Clear APP 2
    76   {
    77     app: 'https://example.com/manifest.webapp',
    78     action: 'clear',
    79   },
    80   // Clear Browser
    81   {
    82     browser: true,
    83     action: 'clear',
    84   },
    85 ];
    87 function runTest()
    88 {
    89   for (var i in gData) {
    90     var iframe = document.createElement('iframe');
    91     var data = gData[i];
    93     if (data.app) {
    94       iframe.setAttribute('mozbrowser', '');
    95       iframe.setAttribute('mozapp', data.app);
    96     } else if (data.browser) {
    97       iframe.setAttribute('mozbrowser', '');
    98     }
   100     if (data.app || data.browser) {
   101       iframe.addEventListener('mozbrowsershowmodalprompt', function(e) {
   102         is(e.detail.message, "success", "test number " + i);
   104         document.body.removeChild(iframe);
   106         i++;
   107         if (i >= gData.length) {
   108           localStorage.clear();
   110           SpecialPowers.removePermission("browser", window.document);
   111           SpecialPowers.removePermission("embed-apps", window.document);
   113           if (previousPrefs.mozBrowserFramesEnabled !== undefined) {
   114             SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', previousPrefs.mozBrowserFramesEnabled);
   115           }
   117           SimpleTest.finish();
   118         } else {
   119           gTestRunner.next();
   120         }
   121       });
   122     }
   124     iframe.src = fileTestOnCurrentOrigin + "?" + data.action;
   126     document.body.appendChild(iframe);
   128     yield undefined;
   129   }
   130 }
   132 var gTestRunner = runTest();
   134 function startTest()
   135 {
   136   is(localStorage.getItem("0"), null, "no data");
   137   localStorage.setItem("0", "foo");
   138   is(localStorage.getItem("0"), "foo", "data have been written");
   140   gTestRunner.next();
   141 }
   143 addLoadEvent(startTest);
   145 </script>
   147 </head>
   149 <body>
   150 </body>
   151 </html>

mercurial