1 // tests nsIPermissionManager
6 // format: [host, type, permission]
7 ["http://mozilla.org", "cookie", 1],
8 ["http://mozilla.org", "image", 2],
9 ["http://mozilla.org", "popup", 3],
10 ["http://mozilla.com", "cookie", 1],
11 ["http://www.mozilla.com", "cookie", 2],
12 ["http://dev.mozilla.com", "cookie", 3],
16 // format: [host, type, testPermission result, testExactPermission result]
18 ["http://localhost", "cookie", 0, 0],
19 ["http://spreadfirefox.com", "cookie", 0, 0],
20 // test different types
21 ["http://mozilla.org", "cookie", 1, 1],
22 ["http://mozilla.org", "image", 2, 2],
23 ["http://mozilla.org", "popup", 3, 3],
25 ["http://www.mozilla.org", "cookie", 1, 0],
26 ["http://www.dev.mozilla.org", "cookie", 1, 0],
27 // test different permissions on subdomains
28 ["http://mozilla.com", "cookie", 1, 1],
29 ["http://www.mozilla.com", "cookie", 2, 2],
30 ["http://dev.mozilla.com", "cookie", 3, 3],
31 ["http://www.dev.mozilla.com", "cookie", 3, 0],
35 Services.prefs.setCharPref("permissions.manager.defaultsUrl", "");
36 var pm = Services.perms;
38 var ioService = Services.io;
40 var secMan = Services.scriptSecurityManager;
42 // nsIPermissionManager implementation is an extension; don't fail if it's not there
48 for (let i = 0; i < hosts.length; ++i) {
49 let uri = ioService.newURI(hosts[i][0]);
50 let principal = secMan.createContentPrincipal(uri, {});
52 pm.addFromPrincipal(principal, hosts[i][1], hosts[i][2]);
56 for (let i = 0; i < results.length; ++i) {
57 let uri = ioService.newURI(results[i][0]);
58 let principal = secMan.createContentPrincipal(uri, {});
61 pm.testPermissionFromPrincipal(principal, results[i][1]),
65 pm.testExactPermissionFromPrincipal(principal, results[i][1]),
70 // test the all property ...
72 Assert.equal(perms.length, hosts.length);
74 // ... remove all the hosts ...
75 for (let j = 0; j < perms.length; ++j) {
76 pm.removePermission(perms[j]);
79 // ... ensure each and every element is equal ...
80 for (let i = 0; i < hosts.length; ++i) {
81 for (let j = 0; j < perms.length; ++j) {
83 perms[j].matchesURI(ioService.newURI(hosts[i][0]), true) &&
84 hosts[i][1] == perms[j].type &&
85 hosts[i][2] == perms[j].capability
92 Assert.equal(perms.length, 0);
94 // ... and check the permmgr's empty
95 Assert.equal(pm.all.length, 0);
97 // test UTF8 normalization behavior: expect ASCII/ACE host encodings
98 var utf8 = "b\u00FCcher.dolske.org"; // "bücher.dolske.org"
99 var aceref = "xn--bcher-kva.dolske.org";
100 var principal = secMan.createContentPrincipal(
101 ioService.newURI("http://" + utf8),
104 pm.addFromPrincipal(principal, "utf8", 1);
105 Assert.notEqual(Services.perms.all.length, 0);
106 var ace = Services.perms.all[0];
107 Assert.equal(ace.principal.asciiHost, aceref);
108 Assert.equal(Services.perms.all.length > 1, false);
112 Assert.equal(Services.perms.all.length, 0);
114 principal = secMan.createContentPrincipalFromOrigin(
115 "https://www.example.com"
117 pm.addFromPrincipal(principal, "offline-app", pm.ALLOW_ACTION);
118 // Remove existing entry.
119 let perm = pm.getPermissionObject(principal, "offline-app", true);
120 pm.removePermission(perm);
121 // Try to remove already deleted entry.
122 perm = pm.getPermissionObject(principal, "offline-app", true);
123 pm.removePermission(perm);
124 Assert.equal(Services.perms.all.length, 0);