dom/permission/tests/unit/test_bug808734.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial