Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
| michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
| michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
| michael@0 | 3 | |
| michael@0 | 4 | function run_test() { |
| michael@0 | 5 | // initialize the permission manager service |
| michael@0 | 6 | const kTestAddr = "test@example.org"; |
| michael@0 | 7 | const kType = "test-mailto"; |
| michael@0 | 8 | const kCapability = 1; |
| michael@0 | 9 | |
| michael@0 | 10 | // make a mailto: URI with parameters |
| michael@0 | 11 | let uri = Services.io.newURI("mailto:" + kTestAddr + "?subject=test", null, |
| michael@0 | 12 | null); |
| michael@0 | 13 | |
| michael@0 | 14 | // add a permission entry for that URI |
| michael@0 | 15 | Services.perms.add(uri, kType, kCapability); |
| michael@0 | 16 | do_check_true(permission_exists(kTestAddr, kType, kCapability)); |
| michael@0 | 17 | |
| michael@0 | 18 | // remove the permission, and make sure it was removed |
| michael@0 | 19 | Services.perms.remove(kTestAddr, kType); |
| michael@0 | 20 | do_check_false(permission_exists(kTestAddr, kType, kCapability)); |
| michael@0 | 21 | |
| michael@0 | 22 | uri = Services.io.newURI("mailto:" + kTestAddr, null, null); |
| michael@0 | 23 | Services.perms.add(uri, kType, kCapability); |
| michael@0 | 24 | do_check_true(permission_exists(kTestAddr, kType, kCapability)); |
| michael@0 | 25 | |
| michael@0 | 26 | Services.perms.remove(kTestAddr, kType); |
| michael@0 | 27 | do_check_false(permission_exists(kTestAddr, kType, kCapability)); |
| michael@0 | 28 | } |
| michael@0 | 29 | |
| michael@0 | 30 | function permission_exists(aHost, aType, aCapability) { |
| michael@0 | 31 | let e = Services.perms.enumerator; |
| michael@0 | 32 | while (e.hasMoreElements()) { |
| michael@0 | 33 | let perm = e.getNext().QueryInterface(Ci.nsIPermission); |
| michael@0 | 34 | if (perm.host == aHost && |
| michael@0 | 35 | perm.type == aType && |
| michael@0 | 36 | perm.capability == aCapability) { |
| michael@0 | 37 | return true; |
| michael@0 | 38 | } |
| michael@0 | 39 | } |
| michael@0 | 40 | return false; |
| michael@0 | 41 | } |