toolkit/mozapps/extensions/test/xpcshell/test_permissions_prefs.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/
     3  */
     5 // Tests that xpinstall.[whitelist|blacklist].add preferences are emptied when
     6 // converted into permissions.
     8 const PREF_XPI_WHITELIST_PERMISSIONS  = "xpinstall.whitelist.add";
     9 const PREF_XPI_BLACKLIST_PERMISSIONS  = "xpinstall.blacklist.add";
    11 function do_check_permission_prefs(preferences) {
    12   // Check preferences were emptied
    13   for (let pref of preferences) {
    14     try {
    15       do_check_eq(Services.prefs.getCharPref(pref), "");
    16     }
    17     catch (e) {
    18       // Successfully emptied
    19     }
    20   }
    21 }
    23 function clear_imported_preferences_cache() {
    24   let scope = Components.utils.import("resource://gre/modules/PermissionsUtils.jsm", {});
    25   scope.gImportedPrefBranches.clear();
    26 }
    28 function run_test() {
    29   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
    31   // Create own preferences to test
    32   Services.prefs.setCharPref("xpinstall.whitelist.add.EMPTY", "");
    33   Services.prefs.setCharPref("xpinstall.whitelist.add.TEST", "whitelist.example.com");
    34   Services.prefs.setCharPref("xpinstall.blacklist.add.EMPTY", "");
    35   Services.prefs.setCharPref("xpinstall.blacklist.add.TEST", "blacklist.example.com");
    37   // Get list of preferences to check
    38   var whitelistPreferences = Services.prefs.getChildList(PREF_XPI_WHITELIST_PERMISSIONS, {});
    39   var blacklistPreferences = Services.prefs.getChildList(PREF_XPI_BLACKLIST_PERMISSIONS, {});
    40   var preferences = whitelistPreferences.concat(blacklistPreferences);
    42   startupManager();
    44   // Permissions are imported lazily - act as thought we're checking an install,
    45   // to trigger on-deman importing of the permissions.
    46   let url = Services.io.newURI("http://example.com/file.xpi", null, null);
    47   AddonManager.isInstallAllowed("application/x-xpinstall", url);
    48   do_check_permission_prefs(preferences);
    51   // Import can also be triggerred by an observer notification by any other area
    52   // of code, such as a permissions management UI.
    54   // First, request to flush all permissions
    55   clear_imported_preferences_cache();
    56   Services.prefs.setCharPref("xpinstall.whitelist.add.TEST2", "whitelist2.example.com");
    57   Services.obs.notifyObservers(null, "flush-pending-permissions", "install");
    58   do_check_permission_prefs(preferences);
    60   // Then, request to flush just install permissions
    61   clear_imported_preferences_cache();
    62   Services.prefs.setCharPref("xpinstall.whitelist.add.TEST3", "whitelist3.example.com");
    63   Services.obs.notifyObservers(null, "flush-pending-permissions", "");
    64   do_check_permission_prefs(preferences);
    66   // And a request to flush some other permissions sholdn't flush install permissions
    67   clear_imported_preferences_cache();
    68   Services.prefs.setCharPref("xpinstall.whitelist.add.TEST4", "whitelist4.example.com");
    69   Services.obs.notifyObservers(null, "flush-pending-permissions", "lolcats");
    70   do_check_eq(Services.prefs.getCharPref("xpinstall.whitelist.add.TEST4"), "whitelist4.example.com");
    71 }

mercurial