2012-11-06 15:52:13 -08:00
|
|
|
const Cu = Components.utils;
|
|
|
|
const READWRITE = "readwrite";
|
|
|
|
const UNKNOWN = "foobar";
|
|
|
|
|
|
|
|
var gData = [
|
|
|
|
// test normal expansion
|
|
|
|
{
|
|
|
|
permission: "contacts",
|
|
|
|
access: READWRITE,
|
2012-11-19 12:31:15 -08:00
|
|
|
expected: ["contacts-read", "contacts-create",
|
2012-11-06 15:52:13 -08:00
|
|
|
"contacts-write"]
|
|
|
|
},
|
|
|
|
// test additional expansion and access not having read+create+write
|
|
|
|
{
|
|
|
|
permission: "settings",
|
|
|
|
access: READWRITE,
|
2012-11-19 12:31:15 -08:00
|
|
|
expected: ["settings-read", "settings-write",
|
|
|
|
"indexedDB-chrome-settings-read",
|
2012-11-06 15:52:13 -08:00
|
|
|
"indexedDB-chrome-settings-write"]
|
|
|
|
},
|
|
|
|
// test substitute
|
|
|
|
{
|
|
|
|
permission: "storage",
|
|
|
|
expected: ["indexedDB-unlimited", "offline-app", "pin-app"]
|
|
|
|
},
|
|
|
|
// 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 run_test() {
|
|
|
|
var scope = {};
|
2012-12-17 08:38:40 -08:00
|
|
|
Cu.import("resource://gre/modules/PermissionsTable.jsm", scope);
|
2012-11-06 15:52:13 -08:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|