summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/xpcshell/test_permissions_prefs.js
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2018-02-10 02:51:36 -0500
committerMatt A. Tobin <email@mattatobin.com>2018-02-10 02:51:36 -0500
commit37d5300335d81cecbecc99812747a657588c63eb (patch)
tree765efa3b6a56bb715d9813a8697473e120436278 /toolkit/mozapps/extensions/test/xpcshell/test_permissions_prefs.js
parentb2bdac20c02b12f2057b9ef70b0a946113a00e00 (diff)
parent4fb11cd5966461bccc3ed1599b808237be6b0de9 (diff)
downloadUXP-37d5300335d81cecbecc99812747a657588c63eb.tar
UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.gz
UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.lz
UXP-37d5300335d81cecbecc99812747a657588c63eb.tar.xz
UXP-37d5300335d81cecbecc99812747a657588c63eb.zip
Merge branch 'ext-work'
Diffstat (limited to 'toolkit/mozapps/extensions/test/xpcshell/test_permissions_prefs.js')
-rw-r--r--toolkit/mozapps/extensions/test/xpcshell/test_permissions_prefs.js74
1 files changed, 0 insertions, 74 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_permissions_prefs.js b/toolkit/mozapps/extensions/test/xpcshell/test_permissions_prefs.js
deleted file mode 100644
index 576f04a65..000000000
--- a/toolkit/mozapps/extensions/test/xpcshell/test_permissions_prefs.js
+++ /dev/null
@@ -1,74 +0,0 @@
-/* Any copyright is dedicated to the Public Domain.
- * http://creativecommons.org/publicdomain/zero/1.0/
- */
-
-// Tests that xpinstall.[whitelist|blacklist].add preferences are emptied when
-// converted into permissions.
-
-const PREF_XPI_WHITELIST_PERMISSIONS = "xpinstall.whitelist.add";
-const PREF_XPI_BLACKLIST_PERMISSIONS = "xpinstall.blacklist.add";
-
-function newPrincipal(uri) {
- return Services.scriptSecurityManager.createCodebasePrincipal(NetUtil.newURI(uri), {});
-}
-
-function do_check_permission_prefs(preferences) {
- // Check preferences were emptied
- for (let pref of preferences) {
- try {
- do_check_eq(Services.prefs.getCharPref(pref), "");
- }
- catch (e) {
- // Successfully emptied
- }
- }
-}
-
-function clear_imported_preferences_cache() {
- let scope = Components.utils.import("resource://gre/modules/PermissionsUtils.jsm", {});
- scope.gImportedPrefBranches.clear();
-}
-
-function run_test() {
- createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
-
- // Create own preferences to test
- Services.prefs.setCharPref("xpinstall.whitelist.add.EMPTY", "");
- Services.prefs.setCharPref("xpinstall.whitelist.add.TEST", "http://whitelist.example.com");
- Services.prefs.setCharPref("xpinstall.blacklist.add.EMPTY", "");
- Services.prefs.setCharPref("xpinstall.blacklist.add.TEST", "http://blacklist.example.com");
-
- // Get list of preferences to check
- var whitelistPreferences = Services.prefs.getChildList(PREF_XPI_WHITELIST_PERMISSIONS, {});
- var blacklistPreferences = Services.prefs.getChildList(PREF_XPI_BLACKLIST_PERMISSIONS, {});
- var preferences = whitelistPreferences.concat(blacklistPreferences);
-
- startupManager();
-
- // Permissions are imported lazily - act as thought we're checking an install,
- // to trigger on-deman importing of the permissions.
- AddonManager.isInstallAllowed("application/x-xpinstall", newPrincipal("http://example.com/file.xpi"));
- do_check_permission_prefs(preferences);
-
-
- // Import can also be triggerred by an observer notification by any other area
- // of code, such as a permissions management UI.
-
- // First, request to flush all permissions
- clear_imported_preferences_cache();
- Services.prefs.setCharPref("xpinstall.whitelist.add.TEST2", "https://whitelist2.example.com");
- Services.obs.notifyObservers(null, "flush-pending-permissions", "install");
- do_check_permission_prefs(preferences);
-
- // Then, request to flush just install permissions
- clear_imported_preferences_cache();
- Services.prefs.setCharPref("xpinstall.whitelist.add.TEST3", "https://whitelist3.example.com");
- Services.obs.notifyObservers(null, "flush-pending-permissions", "");
- do_check_permission_prefs(preferences);
-
- // And a request to flush some other permissions sholdn't flush install permissions
- clear_imported_preferences_cache();
- Services.prefs.setCharPref("xpinstall.whitelist.add.TEST4", "https://whitelist4.example.com");
- Services.obs.notifyObservers(null, "flush-pending-permissions", "lolcats");
- do_check_eq(Services.prefs.getCharPref("xpinstall.whitelist.add.TEST4"), "https://whitelist4.example.com");
-}