Bug 1211591 - Part 2: Tests for nsPermissionManager::RemovePermissionsForApp, r=jdm

This commit is contained in:
Michael Layzell 2015-10-06 12:11:37 -04:00
Родитель 4e925c38c8
Коммит 430ced132c
2 изменённых файлов: 97 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,96 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
function run_test() {
// initialize the permission manager service
let ssm = Services.scriptSecurityManager;
let pm = Services.perms;
function mkPrin(uri, appId, inBrowser) {
return ssm.createCodebasePrincipal(Services.io.newURI(uri, null, null),
{appId: appId, inBrowser: inBrowser});
}
function checkPerms(perms) {
perms.forEach((perm) => {
// Look up the expected permission
do_check_eq(pm.getPermissionObject(mkPrin(perm[0], perm[1], perm[2]),
perm[3], true).capability,
perm[4], "Permission is expected in the permission database");
});
// Count the entries
let count = 0;
let enumerator = Services.perms.enumerator;
while (enumerator.hasMoreElements()) { enumerator.getNext(); count++; }
do_check_eq(count, perms.length, "There should be the right number of permissions in the DB");
}
checkPerms([]);
let permissions = [
['http://google.com', 1001, false, 'a', 1],
['http://google.com', 1001, false, 'b', 1],
['http://mozilla.com', 1001, false, 'b', 1],
['http://mozilla.com', 1001, false, 'a', 1],
['http://google.com', 1001, true, 'a', 1],
['http://google.com', 1001, true, 'b', 1],
['http://mozilla.com', 1001, true, 'b', 1],
['http://mozilla.com', 1001, true, 'a', 1],
['http://google.com', 1011, false, 'a', 1],
['http://google.com', 1011, false, 'b', 1],
['http://mozilla.com', 1011, false, 'b', 1],
['http://mozilla.com', 1011, false, 'a', 1],
];
permissions.forEach((perm) => {
pm.addFromPrincipal(mkPrin(perm[0], perm[1], perm[2]), perm[3], perm[4]);
});
checkPerms(permissions);
let remove_false_perms = [
['http://google.com', 1011, false, 'a', 1],
['http://google.com', 1011, false, 'b', 1],
['http://mozilla.com', 1011, false, 'b', 1],
['http://mozilla.com', 1011, false, 'a', 1],
];
pm.removePermissionsForApp(1001, false);
checkPerms(remove_false_perms);
let restore = [
['http://google.com', 1001, false, 'a', 1],
['http://google.com', 1001, false, 'b', 1],
['http://mozilla.com', 1001, false, 'b', 1],
['http://mozilla.com', 1001, false, 'a', 1],
['http://google.com', 1001, true, 'a', 1],
['http://google.com', 1001, true, 'b', 1],
['http://mozilla.com', 1001, true, 'b', 1],
['http://mozilla.com', 1001, true, 'a', 1],
];
restore.forEach((perm) => {
pm.addFromPrincipal(mkPrin(perm[0], perm[1], perm[2]), perm[3], perm[4]);
});
checkPerms(permissions);
let remove_true_perms = [
['http://google.com', 1001, false, 'a', 1],
['http://google.com', 1001, false, 'b', 1],
['http://mozilla.com', 1001, false, 'b', 1],
['http://mozilla.com', 1001, false, 'a', 1],
['http://google.com', 1011, false, 'a', 1],
['http://google.com', 1011, false, 'b', 1],
['http://mozilla.com', 1011, false, 'b', 1],
['http://mozilla.com', 1011, false, 'a', 1],
];
pm.removePermissionsForApp(1001, true);
checkPerms(remove_true_perms);
}

Просмотреть файл

@ -26,6 +26,7 @@ skip-if = true # Bug 863738
[test_permmanager_notifications.js]
[test_permmanager_removeall.js]
[test_permmanager_removesince.js]
[test_permmanager_removeforapp.js]
[test_permmanager_load_invalid_entries.js]
skip-if = debug == true
[test_permmanager_idn.js]