michael@0: const Cu = Components.utils; michael@0: const READWRITE = "readwrite"; michael@0: const UNKNOWN = "foobar"; michael@0: michael@0: var gData = [ michael@0: // test normal expansion michael@0: { michael@0: permission: "contacts", michael@0: access: READWRITE, michael@0: expected: ["contacts-read", "contacts-create", michael@0: "contacts-write"] michael@0: }, michael@0: // test additional expansion and access not having read+create+write michael@0: { michael@0: permission: "settings", michael@0: access: READWRITE, michael@0: expected: ["settings-read", "settings-write", michael@0: "indexedDB-chrome-settings-read", michael@0: "indexedDB-chrome-settings-write"] michael@0: }, michael@0: // test substitute michael@0: { michael@0: permission: "storage", michael@0: expected: ["indexedDB-unlimited", michael@0: "default-persistent-storage"] michael@0: }, michael@0: // test unknown access michael@0: { michael@0: permission: "contacts", michael@0: access: UNKNOWN, michael@0: expected: [] michael@0: }, michael@0: // test unknown permission michael@0: { michael@0: permission: UNKNOWN, michael@0: access: READWRITE, michael@0: expected: [] michael@0: } michael@0: ]; michael@0: michael@0: // check if 2 arrays contain the same elements michael@0: function do_check_set_eq(a1, a2) { michael@0: do_check_eq(a1.length, a2.length) michael@0: michael@0: Array.sort(a1); michael@0: Array.sort(a2); michael@0: michael@0: for (let i = 0; i < a1.length; ++i) { michael@0: do_check_eq(a1[i], a2[i]) michael@0: } michael@0: } michael@0: michael@0: function run_test() { michael@0: var scope = {}; michael@0: Cu.import("resource://gre/modules/PermissionsTable.jsm", scope); michael@0: michael@0: for (var i = 0; i < gData.length; i++) { michael@0: var perms = scope.expandPermissions(gData[i].permission, michael@0: gData[i].access); michael@0: do_check_set_eq(perms, gData[i].expected); michael@0: } michael@0: }