| |
1 const Cu = Components.utils; |
| |
2 const READWRITE = "readwrite"; |
| |
3 const UNKNOWN = "foobar"; |
| |
4 |
| |
5 var gData = [ |
| |
6 // test normal expansion |
| |
7 { |
| |
8 permission: "contacts", |
| |
9 access: READWRITE, |
| |
10 expected: ["contacts-read", "contacts-create", |
| |
11 "contacts-write"] |
| |
12 }, |
| |
13 // test additional expansion and access not having read+create+write |
| |
14 { |
| |
15 permission: "settings", |
| |
16 access: READWRITE, |
| |
17 expected: ["settings-read", "settings-write", |
| |
18 "indexedDB-chrome-settings-read", |
| |
19 "indexedDB-chrome-settings-write"] |
| |
20 }, |
| |
21 // test substitute |
| |
22 { |
| |
23 permission: "storage", |
| |
24 expected: ["indexedDB-unlimited", |
| |
25 "default-persistent-storage"] |
| |
26 }, |
| |
27 // test unknown access |
| |
28 { |
| |
29 permission: "contacts", |
| |
30 access: UNKNOWN, |
| |
31 expected: [] |
| |
32 }, |
| |
33 // test unknown permission |
| |
34 { |
| |
35 permission: UNKNOWN, |
| |
36 access: READWRITE, |
| |
37 expected: [] |
| |
38 } |
| |
39 ]; |
| |
40 |
| |
41 // check if 2 arrays contain the same elements |
| |
42 function do_check_set_eq(a1, a2) { |
| |
43 do_check_eq(a1.length, a2.length) |
| |
44 |
| |
45 Array.sort(a1); |
| |
46 Array.sort(a2); |
| |
47 |
| |
48 for (let i = 0; i < a1.length; ++i) { |
| |
49 do_check_eq(a1[i], a2[i]) |
| |
50 } |
| |
51 } |
| |
52 |
| |
53 function run_test() { |
| |
54 var scope = {}; |
| |
55 Cu.import("resource://gre/modules/PermissionsTable.jsm", scope); |
| |
56 |
| |
57 for (var i = 0; i < gData.length; i++) { |
| |
58 var perms = scope.expandPermissions(gData[i].permission, |
| |
59 gData[i].access); |
| |
60 do_check_set_eq(perms, gData[i].expected); |
| |
61 } |
| |
62 } |