dom/permission/tests/test_permission_basics.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/permission/tests/test_permission_basics.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,109 @@
     1.4 +<!DOCTYPE html>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=770731
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug {770731} Permissions</title>
    1.11 +  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
    1.12 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.13 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.14 +</head>
    1.15 +<body>
    1.16 +
    1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=770731">Mozilla Bug 770731</a>
    1.18 +<p id="display"></p>
    1.19 +<div id="content" style="display: none">
    1.20 +
    1.21 +</div>
    1.22 +<pre id="test">
    1.23 +<script class="testbody" type="text/javascript">
    1.24 +
    1.25 +"use strict";
    1.26 +
    1.27 +SimpleTest.waitForExplicitFinish();
    1.28 +
    1.29 +var testPrivApp = {
    1.30 +  'manifestURL' : 'https://aprivileged.com/manifest.webapp'
    1.31 +};
    1.32 +
    1.33 +var testCertApp = {
    1.34 +  'manifestURL' : 'https://acertified.com/manifest.webapp'
    1.35 +};
    1.36 +
    1.37 +// Any permission explicit for privileged and implicit for certified serves
    1.38 +var testPerm = "contacts-read";
    1.39 +// Any permission explicit for privileged and certified apps
    1.40 +var explicitPerm = "geolocation";
    1.41 +
    1.42 +// Simulate that the app requested the permissions
    1.43 +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() {
    1.44 +  SpecialPowers.pushPrefEnv({ "set": [["dom.mozPermissionSettings.enabled", true]] }, permissionTest);
    1.45 +});
    1.46 +
    1.47 +function permissionTest() {
    1.48 +  if (SpecialPowers.isMainProcess()) {
    1.49 +    SpecialPowers.Cu.import("resource://gre/modules/PermissionSettings.jsm");
    1.50 +  }
    1.51 +
    1.52 +  var mozPermissions = window.navigator.mozPermissionSettings;
    1.53 +  isnot(mozPermissions, null, "mozPermissionSettings is null when not enabled.");
    1.54 +
    1.55 +  var certAppManifest = testCertApp.manifestURL;
    1.56 +  var privAppManifest = testPrivApp.manifestURL;
    1.57 +  var originPriv = "https://aprivileged.com";
    1.58 +  var originCert = "https://acertified.com";
    1.59 +  var originOther = "http://test";
    1.60 +
    1.61 +  // Trying to make any change to implicit permissions should fail
    1.62 +  try {
    1.63 +    mozPermissions.set(testPerm, "allow", certAppManifest, originCert, false);
    1.64 +    ok(false, "Change implicit permission");
    1.65 +  } catch (e) {
    1.66 +    ok(true, "Change implicit permission");
    1.67 +  }
    1.68 +
    1.69 +  var result=mozPermissions.get(testPerm, certAppManifest, originCert, false);
    1.70 +  is(result, "allow", "same result");
    1.71 +
    1.72 +  // Removing a permission from the same origin, even an explicit one, should fail
    1.73 +  try {
    1.74 +    mozPermissions.set(testPerm, "unknown", privAppManifest, originPriv);
    1.75 +    ok(false, "Setting a permission to unknown");
    1.76 +  } catch (e) {
    1.77 +    ok(true, "Setting a permission to unknown");
    1.78 +  }
    1.79 +
    1.80 +  // Removing an explicit permission from a different origin should work
    1.81 +  var testRemove = function(aPerm, aManifest, aOrigin, aTestMsg) {
    1.82 +    try {
    1.83 +      mozPermissions.remove(aPerm, aManifest, aOrigin);
    1.84 +      var status = mozPermissions.get(aPerm, aManifest, aOrigin, false);
    1.85 +      is(status, "unknown", aTestMsg);
    1.86 +    } catch (e) {
    1.87 +      ok(false, aTestMsg);
    1.88 +    }
    1.89 +  }
    1.90 +
    1.91 +  testRemove(explicitPerm, privAppManifest, originOther,
    1.92 +               "Remove explicit permission of privileged app");
    1.93 +  testRemove(explicitPerm, certAppManifest, originOther,
    1.94 +               "Remove explicit permission of certified app");
    1.95 +
    1.96 +  mozPermissions.set(testPerm, "allow", privAppManifest, originPriv, false);
    1.97 +  result = mozPermissions.get(testPerm, privAppManifest, originPriv, false);
    1.98 +  is(result, "allow", "Set to allow");
    1.99 +  mozPermissions.set(testPerm, "deny", privAppManifest, originPriv, false);
   1.100 +  result = mozPermissions.get(testPerm, privAppManifest, originPriv, false);
   1.101 +  is(result, "deny", "Set to deny");
   1.102 +  mozPermissions.set(testPerm, "prompt", privAppManifest, originPriv, false);
   1.103 +  result = mozPermissions.get(testPerm, privAppManifest, originPriv, false);
   1.104 +  is(result, "prompt", "Set to prompt");
   1.105 +  SimpleTest.finish();
   1.106 +}
   1.107 +
   1.108 +ok(true, "test passed");
   1.109 +</script>
   1.110 +</pre>
   1.111 +</body>
   1.112 +</html>
   1.113 \ No newline at end of file

mercurial