Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 <!DOCTYPE html>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=770731
5 -->
6 <head>
7 <title>Test for Bug {770731} Permissions</title>
8 <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
9 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
11 </head>
12 <body>
14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=770731">Mozilla Bug 770731</a>
15 <p id="display"></p>
16 <div id="content" style="display: none">
18 </div>
19 <pre id="test">
20 <script class="testbody" type="text/javascript">
22 "use strict";
24 SimpleTest.waitForExplicitFinish();
26 var testPrivApp = {
27 'manifestURL' : 'https://aprivileged.com/manifest.webapp'
28 };
30 var testCertApp = {
31 'manifestURL' : 'https://acertified.com/manifest.webapp'
32 };
34 // Any permission explicit for privileged and implicit for certified serves
35 var testPerm = "contacts-read";
36 // Any permission explicit for privileged and certified apps
37 var explicitPerm = "geolocation";
39 // Simulate that the app requested the permissions
40 SpecialPowers.pushPermissions([{'type': 'permissions', 'allow': true, 'context': document}, {'type': testPerm, 'allow': true, 'context': testPrivApp}, {'type': testPerm, 'allow': true, 'context': testCertApp}, {'type': explicitPerm, 'allow': true, 'context': testPrivApp}, {'type': explicitPerm, 'allow': true, 'context': testCertApp}], function() {
41 SpecialPowers.pushPrefEnv({ "set": [["dom.mozPermissionSettings.enabled", true]] }, permissionTest);
42 });
44 function permissionTest() {
45 if (SpecialPowers.isMainProcess()) {
46 SpecialPowers.Cu.import("resource://gre/modules/PermissionSettings.jsm");
47 }
49 var mozPermissions = window.navigator.mozPermissionSettings;
50 isnot(mozPermissions, null, "mozPermissionSettings is null when not enabled.");
52 var certAppManifest = testCertApp.manifestURL;
53 var privAppManifest = testPrivApp.manifestURL;
54 var originPriv = "https://aprivileged.com";
55 var originCert = "https://acertified.com";
56 var originOther = "http://test";
58 // Trying to make any change to implicit permissions should fail
59 try {
60 mozPermissions.set(testPerm, "allow", certAppManifest, originCert, false);
61 ok(false, "Change implicit permission");
62 } catch (e) {
63 ok(true, "Change implicit permission");
64 }
66 var result=mozPermissions.get(testPerm, certAppManifest, originCert, false);
67 is(result, "allow", "same result");
69 // Removing a permission from the same origin, even an explicit one, should fail
70 try {
71 mozPermissions.set(testPerm, "unknown", privAppManifest, originPriv);
72 ok(false, "Setting a permission to unknown");
73 } catch (e) {
74 ok(true, "Setting a permission to unknown");
75 }
77 // Removing an explicit permission from a different origin should work
78 var testRemove = function(aPerm, aManifest, aOrigin, aTestMsg) {
79 try {
80 mozPermissions.remove(aPerm, aManifest, aOrigin);
81 var status = mozPermissions.get(aPerm, aManifest, aOrigin, false);
82 is(status, "unknown", aTestMsg);
83 } catch (e) {
84 ok(false, aTestMsg);
85 }
86 }
88 testRemove(explicitPerm, privAppManifest, originOther,
89 "Remove explicit permission of privileged app");
90 testRemove(explicitPerm, certAppManifest, originOther,
91 "Remove explicit permission of certified app");
93 mozPermissions.set(testPerm, "allow", privAppManifest, originPriv, false);
94 result = mozPermissions.get(testPerm, privAppManifest, originPriv, false);
95 is(result, "allow", "Set to allow");
96 mozPermissions.set(testPerm, "deny", privAppManifest, originPriv, false);
97 result = mozPermissions.get(testPerm, privAppManifest, originPriv, false);
98 is(result, "deny", "Set to deny");
99 mozPermissions.set(testPerm, "prompt", privAppManifest, originPriv, false);
100 result = mozPermissions.get(testPerm, privAppManifest, originPriv, false);
101 is(result, "prompt", "Set to prompt");
102 SimpleTest.finish();
103 }
105 ok(true, "test passed");
106 </script>
107 </pre>
108 </body>
109 </html>