dom/tests/mochitest/localstorage/test_appIsolation.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial