|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Tests that xpinstall.[whitelist|blacklist].add preferences are emptied when |
|
6 // converted into permissions. |
|
7 |
|
8 const PREF_XPI_WHITELIST_PERMISSIONS = "xpinstall.whitelist.add"; |
|
9 const PREF_XPI_BLACKLIST_PERMISSIONS = "xpinstall.blacklist.add"; |
|
10 |
|
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 } |
|
22 |
|
23 function clear_imported_preferences_cache() { |
|
24 let scope = Components.utils.import("resource://gre/modules/PermissionsUtils.jsm", {}); |
|
25 scope.gImportedPrefBranches.clear(); |
|
26 } |
|
27 |
|
28 function run_test() { |
|
29 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); |
|
30 |
|
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"); |
|
36 |
|
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); |
|
41 |
|
42 startupManager(); |
|
43 |
|
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); |
|
49 |
|
50 |
|
51 // Import can also be triggerred by an observer notification by any other area |
|
52 // of code, such as a permissions management UI. |
|
53 |
|
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); |
|
59 |
|
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); |
|
65 |
|
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 } |