extensions/cookie/test/unit/test_permmanager_mailto.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/extensions/cookie/test/unit/test_permmanager_mailto.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,41 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +function run_test() {
     1.8 +  // initialize the permission manager service
     1.9 +  const kTestAddr = "test@example.org";
    1.10 +  const kType = "test-mailto";
    1.11 +  const kCapability = 1;
    1.12 +
    1.13 +  // make a mailto: URI with parameters
    1.14 +  let uri = Services.io.newURI("mailto:" + kTestAddr + "?subject=test", null,
    1.15 +                               null);
    1.16 +
    1.17 +  // add a permission entry for that URI
    1.18 +  Services.perms.add(uri, kType, kCapability);
    1.19 +  do_check_true(permission_exists(kTestAddr, kType, kCapability));
    1.20 +
    1.21 +  // remove the permission, and make sure it was removed
    1.22 +  Services.perms.remove(kTestAddr, kType);
    1.23 +  do_check_false(permission_exists(kTestAddr, kType, kCapability));
    1.24 +
    1.25 +  uri = Services.io.newURI("mailto:" + kTestAddr, null, null);
    1.26 +  Services.perms.add(uri, kType, kCapability);
    1.27 +  do_check_true(permission_exists(kTestAddr, kType, kCapability));
    1.28 +
    1.29 +  Services.perms.remove(kTestAddr, kType);
    1.30 +  do_check_false(permission_exists(kTestAddr, kType, kCapability));
    1.31 +}
    1.32 +
    1.33 +function permission_exists(aHost, aType, aCapability) {
    1.34 +  let e = Services.perms.enumerator;
    1.35 +  while (e.hasMoreElements()) {
    1.36 +    let perm = e.getNext().QueryInterface(Ci.nsIPermission);
    1.37 +    if (perm.host == aHost &&
    1.38 +        perm.type == aType &&
    1.39 +        perm.capability == aCapability) {
    1.40 +      return true;
    1.41 +    }
    1.42 +  }
    1.43 +  return false;
    1.44 +}

mercurial