extensions/cookie/test/test_permissionmanager_app_isolation.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

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=758258
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <meta charset="utf-8">
michael@0 8 <title>Test for nsIPrincipal extendedOrigin, appStatus and appId</title>
michael@0 9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=758258">Mozilla Bug 758258</a>
michael@0 14 <p id="display"></p>
michael@0 15 <div id="content">
michael@0 16
michael@0 17 </div>
michael@0 18 <pre id="test">
michael@0 19 <script type="application/javascript;version=1.7">
michael@0 20
michael@0 21 /** Test for Bug 758258 **/
michael@0 22
michael@0 23 var Ci = Components.interfaces;
michael@0 24 var Cc = Components.classes;
michael@0 25
michael@0 26 SimpleTest.waitForExplicitFinish();
michael@0 27
michael@0 28 var permManager = Cc["@mozilla.org/permissionmanager;1"]
michael@0 29 .getService(Ci.nsIPermissionManager);
michael@0 30
michael@0 31 const gPermName = 'foobar';
michael@0 32
michael@0 33 var previousPrefs = {
michael@0 34 mozBrowserFramesEnabled: undefined,
michael@0 35 };
michael@0 36
michael@0 37 try {
michael@0 38 previousPrefs.mozBrowserFramesEnabled = SpecialPowers.getBoolPref('dom.mozBrowserFramesEnabled');
michael@0 39 } catch(e)
michael@0 40 {
michael@0 41 }
michael@0 42
michael@0 43 SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', true);
michael@0 44
michael@0 45 // We use http://test/ as url so all apps use the same url and app isolation is
michael@0 46 // more obvious.
michael@0 47 var gData = [
michael@0 48 // APP 1
michael@0 49 {
michael@0 50 app: 'http://example.org/manifest.webapp',
michael@0 51 action: 'read-no',
michael@0 52 src: 'http://test/',
michael@0 53 },
michael@0 54 {
michael@0 55 app: 'http://example.org/manifest.webapp',
michael@0 56 action: 'write',
michael@0 57 src: 'http://test/',
michael@0 58 },
michael@0 59 {
michael@0 60 app: 'http://example.org/manifest.webapp',
michael@0 61 action: 'read-yes',
michael@0 62 src: 'http://test/',
michael@0 63 },
michael@0 64 // APP 2
michael@0 65 {
michael@0 66 app: 'https://example.com/manifest.webapp',
michael@0 67 action: 'read-no',
michael@0 68 src: 'http://test/',
michael@0 69 },
michael@0 70 {
michael@0 71 app: 'https://example.com/manifest.webapp',
michael@0 72 action: 'write',
michael@0 73 src: 'http://test/',
michael@0 74 },
michael@0 75 {
michael@0 76 app: 'https://example.com/manifest.webapp',
michael@0 77 action: 'read-yes',
michael@0 78 src: 'http://test/',
michael@0 79 },
michael@0 80 // Browser
michael@0 81 {
michael@0 82 browser: true,
michael@0 83 action: 'read-no',
michael@0 84 src: 'http://test/',
michael@0 85 },
michael@0 86 {
michael@0 87 browser: true,
michael@0 88 action: 'write',
michael@0 89 src: 'http://test/',
michael@0 90 },
michael@0 91 {
michael@0 92 browser: true,
michael@0 93 action: 'read-yes',
michael@0 94 src: 'http://test/',
michael@0 95 },
michael@0 96 ];
michael@0 97
michael@0 98 function runTest() {
michael@0 99 for (var i in gData) {
michael@0 100 var iframe = document.createElement('iframe');
michael@0 101 var data = gData[i];
michael@0 102
michael@0 103 if (data.app) {
michael@0 104 iframe.setAttribute('mozbrowser', '');
michael@0 105 iframe.setAttribute('mozapp', data.app);
michael@0 106 } else if (data.browser) {
michael@0 107 iframe.setAttribute('mozbrowser', '');
michael@0 108 }
michael@0 109
michael@0 110 if (data.app || data.browser) {
michael@0 111 iframe.addEventListener('load', function(e) {
michael@0 112 var principal = iframe.contentDocument.nodePrincipal;
michael@0 113
michael@0 114 switch (data.action) {
michael@0 115 case 'read-no':
michael@0 116 is(permManager.testPermissionFromPrincipal(principal, gPermName),
michael@0 117 Ci.nsIPermissionManager.UNKNOWN_ACTION,
michael@0 118 "Permission should not be set yet");
michael@0 119 is(permManager.testExactPermissionFromPrincipal(principal, gPermName),
michael@0 120 Ci.nsIPermissionManager.UNKNOWN_ACTION,
michael@0 121 "Permission should not be set yet");
michael@0 122 break;
michael@0 123 case 'write':
michael@0 124 permManager.addFromPrincipal(principal, gPermName, Ci.nsIPermissionManager.ALLOW_ACTION);
michael@0 125 break;
michael@0 126 case 'read-yes':
michael@0 127 is(permManager.testPermissionFromPrincipal(principal, gPermName),
michael@0 128 Ci.nsIPermissionManager.ALLOW_ACTION,
michael@0 129 "Permission should be set");
michael@0 130 is(permManager.testExactPermissionFromPrincipal(principal, gPermName),
michael@0 131 Ci.nsIPermissionManager.ALLOW_ACTION,
michael@0 132 "Permission should be set");
michael@0 133 break;
michael@0 134 default:
michael@0 135 ok(false, "shouldn't be there");
michael@0 136 }
michael@0 137
michael@0 138 // Calling removeChild() produces an error that creates failures.
michael@0 139 //document.getElementById('content').removeChild(iframe);
michael@0 140
michael@0 141 i++;
michael@0 142 if (i >= gData.length) {
michael@0 143 if (previousPrefs.mozBrowserFramesEnabled !== undefined) {
michael@0 144 SpecialPowers.setBoolPref('dom.mozBrowserFramesEnabled', previousPrefs.mozBrowserFramesEnabled);
michael@0 145 }
michael@0 146
michael@0 147 SimpleTest.finish();
michael@0 148 } else {
michael@0 149 gTestRunner.next();
michael@0 150 }
michael@0 151 });
michael@0 152 }
michael@0 153
michael@0 154 iframe.src = data.src;
michael@0 155
michael@0 156 document.getElementById('content').appendChild(iframe);
michael@0 157
michael@0 158 yield;
michael@0 159 }
michael@0 160 }
michael@0 161
michael@0 162 var gTestRunner = runTest();
michael@0 163 gTestRunner.next();
michael@0 164
michael@0 165 </script>
michael@0 166 </pre>
michael@0 167 </body>
michael@0 168 </html>

mercurial