dom/permission/tests/unit/test_bug808734.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 const Cu = Components.utils;
michael@0 2 const READWRITE = "readwrite";
michael@0 3 const UNKNOWN = "foobar";
michael@0 4
michael@0 5 var gData = [
michael@0 6 // test normal expansion
michael@0 7 {
michael@0 8 permission: "contacts",
michael@0 9 access: READWRITE,
michael@0 10 expected: ["contacts-read", "contacts-create",
michael@0 11 "contacts-write"]
michael@0 12 },
michael@0 13 // test additional expansion and access not having read+create+write
michael@0 14 {
michael@0 15 permission: "settings",
michael@0 16 access: READWRITE,
michael@0 17 expected: ["settings-read", "settings-write",
michael@0 18 "indexedDB-chrome-settings-read",
michael@0 19 "indexedDB-chrome-settings-write"]
michael@0 20 },
michael@0 21 // test substitute
michael@0 22 {
michael@0 23 permission: "storage",
michael@0 24 expected: ["indexedDB-unlimited",
michael@0 25 "default-persistent-storage"]
michael@0 26 },
michael@0 27 // test unknown access
michael@0 28 {
michael@0 29 permission: "contacts",
michael@0 30 access: UNKNOWN,
michael@0 31 expected: []
michael@0 32 },
michael@0 33 // test unknown permission
michael@0 34 {
michael@0 35 permission: UNKNOWN,
michael@0 36 access: READWRITE,
michael@0 37 expected: []
michael@0 38 }
michael@0 39 ];
michael@0 40
michael@0 41 // check if 2 arrays contain the same elements
michael@0 42 function do_check_set_eq(a1, a2) {
michael@0 43 do_check_eq(a1.length, a2.length)
michael@0 44
michael@0 45 Array.sort(a1);
michael@0 46 Array.sort(a2);
michael@0 47
michael@0 48 for (let i = 0; i < a1.length; ++i) {
michael@0 49 do_check_eq(a1[i], a2[i])
michael@0 50 }
michael@0 51 }
michael@0 52
michael@0 53 function run_test() {
michael@0 54 var scope = {};
michael@0 55 Cu.import("resource://gre/modules/PermissionsTable.jsm", scope);
michael@0 56
michael@0 57 for (var i = 0; i < gData.length; i++) {
michael@0 58 var perms = scope.expandPermissions(gData[i].permission,
michael@0 59 gData[i].access);
michael@0 60 do_check_set_eq(perms, gData[i].expected);
michael@0 61 }
michael@0 62 }

mercurial