Bug 808734 - Fix permissions expansion and add unit test. r=ddahl, r=gwagner

This commit is contained in:
David Chan 2012-11-06 15:52:13 -08:00
parent b0aa31a99b
commit 062c862d47
5 changed files with 79 additions and 4 deletions

View File

@ -358,10 +358,8 @@ Temporarily disabled in order to add access fields to gaia: See Bug 805646
let AllPossiblePermissions = [];
for (let permName in PermissionsTable) {
if (PermissionsTable[permName].access) {
for each (let access in PermissionsTable[permName].access) {
AllPossiblePermissions =
AllPossiblePermissions.concat(expandPermissions(permName, access));
}
AllPossiblePermissions =
AllPossiblePermissions.concat(expandPermissions(permName, READWRITE));
} else {
AllPossiblePermissions =
AllPossiblePermissions.concat(expandPermissions(permName));

View File

@ -14,6 +14,9 @@ include $(DEPTH)/config/autoconf.mk
DIRS = \
$(NULL)
MODULE = test_permission
XPCSHELL_TESTS = unit
include $(topsrcdir)/config/rules.mk
_TEST_FILES = \

View File

@ -0,0 +1,68 @@
const Cu = Components.utils;
const READWRITE = "readwrite";
const UNKNOWN = "foobar";
/*
* Remove "contacts" from first test expected array and
* "settings" and "indexedDB-chrome-settings" from second
* test when this is fixed
* http://mxr.mozilla.org/mozilla-central/source/dom/apps/src/PermissionsInstaller.jsm#316
*/
var gData = [
// test normal expansion
{
permission: "contacts",
access: READWRITE,
expected: ["contacts", "contacts-read", "contacts-create",
"contacts-write"]
},
// test additional expansion and access not having read+create+write
{
permission: "settings",
access: READWRITE,
expected: ["settings", "settings-read", "settings-write",
"indexedDB-chrome-settings", "indexedDB-chrome-settings-read",
"indexedDB-chrome-settings-write"]
},
// test substitute
{
permission: "storage",
access: READWRITE,
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 = {};
Cu.import("resource://gre/modules/PermissionsInstaller.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);
}
}

View File

@ -0,0 +1,5 @@
[DEFAULT]
head =
tail =
[test_bug808734.js]

View File

@ -16,6 +16,7 @@
[include:dom/network/tests/unit/xpcshell.ini]
[include:dom/network/tests/unit_ipc/xpcshell.ini]
[include:dom/network/tests/unit_stats/xpcshell.ini]
[include:dom/permission/tests/unit/xpcshell.ini]
[include:dom/src/json/test/unit/xpcshell.ini]
[include:dom/system/gonk/tests/xpcshell.ini]
[include:dom/tests/unit/xpcshell.ini]