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

mercurial