1 // tests nsIPermissionManager
4 // format: [host, type, permission]
5 ["mozilla.org", "cookie", 1],
6 ["mozilla.org", "image", 2],
7 ["mozilla.org", "popup", 3],
8 ["mozilla.com", "cookie", 1],
9 ["www.mozilla.com", "cookie", 2],
10 ["dev.mozilla.com", "cookie", 3]
14 // format: [host, type, testPermission result, testExactPermission result]
16 ["localhost", "cookie", 0, 0],
17 ["spreadfirefox.com", "cookie", 0, 0],
18 // test different types
19 ["mozilla.org", "cookie", 1, 1],
20 ["mozilla.org", "image", 2, 2],
21 ["mozilla.org", "popup", 3, 3],
23 ["www.mozilla.org", "cookie", 1, 0],
24 ["www.dev.mozilla.org", "cookie", 1, 0],
25 // test different permissions on subdomains
26 ["mozilla.com", "cookie", 1, 1],
27 ["www.mozilla.com", "cookie", 2, 2],
28 ["dev.mozilla.com", "cookie", 3, 3],
29 ["www.dev.mozilla.com", "cookie", 3, 0]
33 var pm = Components.classes["@mozilla.org/permissionmanager;1"]
34 .getService(Components.interfaces.nsIPermissionManager);
36 var ioService = Components.classes["@mozilla.org/network/io-service;1"]
37 .getService(Components.interfaces.nsIIOService);
39 // nsIPermissionManager implementation is an extension; don't fail if it's not there
44 for (var i = 0; i < hosts.length; ++i) {
45 var uri = ioService.newURI("http://" + hosts[i][0], null, null);
46 pm.add(uri, hosts[i][1], hosts[i][2]);
50 for (var i = 0; i < results.length; ++i) {
51 var uri = ioService.newURI("http://" + results[i][0], null, null);
52 do_check_eq(pm.testPermission(uri, results[i][1]), results[i][2]);
53 do_check_eq(pm.testExactPermission(uri, results[i][1]), results[i][3]);
56 // test the enumerator ...
58 var perms = new Array();
59 var enumerator = pm.enumerator;
60 while (enumerator.hasMoreElements()) {
61 perms[j] = enumerator.getNext().QueryInterface(Components.interfaces.nsIPermission);
64 do_check_eq(perms.length, hosts.length);
66 // ... remove all the hosts ...
67 for (var j = 0; j < perms.length; ++j) {
68 pm.remove(perms[j].host, perms[j].type);
71 // ... ensure each and every element is equal ...
72 for (var i = 0; i < hosts.length; ++i) {
73 for (var j = 0; j < perms.length; ++j) {
74 if (hosts[i][0] == perms[j].host &&
75 hosts[i][1] == perms[j].type &&
76 hosts[i][2] == perms[j].capability) {
82 do_check_eq(perms.length, 0);
84 // ... and check the permmgr's empty
85 do_check_eq(pm.enumerator.hasMoreElements(), false);
87 // test UTF8 normalization behavior: expect ASCII/ACE host encodings
88 var utf8 = "b\u00FCcher.dolske.org"; // "bücher.dolske.org"
89 var aceref = "xn--bcher-kva.dolske.org";
90 var uri = ioService.newURI("http://" + utf8, null, null);
91 pm.add(uri, "utf8", 1);
92 var enumerator = pm.enumerator;
93 do_check_eq(enumerator.hasMoreElements(), true);
94 var ace = enumerator.getNext().QueryInterface(Components.interfaces.nsIPermission);
95 do_check_eq(ace.host, aceref);
96 do_check_eq(enumerator.hasMoreElements(), false);
100 do_check_eq(pm.enumerator.hasMoreElements(), false);