summaryrefslogtreecommitdiffstats
path: root/dom/permission/tests/unit/test_bug808734.js
blob: 8dfbd9458b2b6bda581ff4860218c6a53f40b5aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var Cu = Components.utils;
const READWRITE = "readwrite";
const UNKNOWN = "foobar";

var gData = [
// test normal expansion
{
  permission: "contacts",
  access: READWRITE,
  expected: ["contacts-read", "contacts-create",
             "contacts-write"]
},
// test additional expansion and access not having read+create+write
{
  permission: "settings",
  access: READWRITE,
  expected: ["settings-read", "settings-write",
             "settings-api-read", "settings-api-write",
             "indexedDB-chrome-settings-read",
             "indexedDB-chrome-settings-write"]
},
// test unknown access
{
  permission: "contacts",
  access: UNKNOWN,
  expected: []
},
// test unknown permission
{
  permission: UNKNOWN,
  access: READWRITE,
  expected: []
}
];

// check if 2 arrays contain the same elements
function do_check_set_eq(a1, a2) {
  do_check_eq(a1.length, a2.length)

  Array.sort(a1);
  Array.sort(a2);

  for (let i = 0; i < a1.length; ++i) {
    do_check_eq(a1[i], a2[i])
  }
}

function test_substitute_does_not_break_substituted(scope) {
  const Ci = Components.interfaces;

  // geolocation-noprompt substitutes for geolocation ...
  do_check_eq(scope.PermissionsTable["geolocation-noprompt"].substitute[0],
              "geolocation");
  // ... and sets silent allow ...
  do_check_eq(scope.PermissionsTable["geolocation-noprompt"].certified,
              Ci.nsIPermissionManager.ALLOW_ACTION)
  // ... which works ...
  do_check_false(scope.isExplicitInPermissionsTable("geolocation-noprompt", Ci.nsIPrincipal.APP_STATUS_CERTIFIED));
  // ... but does not interfere with geolocation's PROMPT value
  do_check_true(scope.isExplicitInPermissionsTable("geolocation", Ci.nsIPrincipal.APP_STATUS_CERTIFIED));
}

function run_test() {
  var scope = {};
  Cu.import("resource://gre/modules/PermissionsTable.jsm", scope);

  for (var i = 0; i < gData.length; i++) {
    var perms = scope.expandPermissions(gData[i].permission,
                                        gData[i].access);
    do_check_set_eq(perms, gData[i].expected);
  }
  test_substitute_does_not_break_substituted(scope);
}