|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 Components.utils.import("resource://gre/modules/NetUtil.jsm"); |
|
6 |
|
7 // Checks that permissions set in preferences are correctly imported but can |
|
8 // be removed by the user. |
|
9 |
|
10 const XPI_MIMETYPE = "application/x-xpinstall"; |
|
11 |
|
12 function run_test() { |
|
13 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2"); |
|
14 |
|
15 Services.prefs.setCharPref("xpinstall.whitelist.add", "test1.com,test2.com"); |
|
16 Services.prefs.setCharPref("xpinstall.whitelist.add.36", "test3.com,www.test4.com"); |
|
17 Services.prefs.setCharPref("xpinstall.whitelist.add.test5", "test5.com"); |
|
18 |
|
19 Services.perms.add(NetUtil.newURI("http://www.test9.com"), "install", |
|
20 AM_Ci.nsIPermissionManager.ALLOW_ACTION); |
|
21 |
|
22 startupManager(); |
|
23 |
|
24 do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
25 NetUtil.newURI("http://test1.com"))); |
|
26 do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
27 NetUtil.newURI("https://www.test2.com"))); |
|
28 do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
29 NetUtil.newURI("https://test3.com"))); |
|
30 do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
31 NetUtil.newURI("https://test4.com"))); |
|
32 do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
33 NetUtil.newURI("https://www.test4.com"))); |
|
34 do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
35 NetUtil.newURI("http://www.test5.com"))); |
|
36 |
|
37 do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
38 NetUtil.newURI("http://www.test6.com"))); |
|
39 do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
40 NetUtil.newURI("http://test7.com"))); |
|
41 do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
42 NetUtil.newURI("http://www.test8.com"))); |
|
43 |
|
44 // This should remain unaffected |
|
45 do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
46 NetUtil.newURI("http://www.test9.com"))); |
|
47 do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
48 NetUtil.newURI("https://www.test9.com"))); |
|
49 |
|
50 Services.perms.removeAll(); |
|
51 |
|
52 do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
53 NetUtil.newURI("http://test1.com"))); |
|
54 do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
55 NetUtil.newURI("https://www.test2.com"))); |
|
56 do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
57 NetUtil.newURI("https://test3.com"))); |
|
58 do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
59 NetUtil.newURI("https://www.test4.com"))); |
|
60 do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
61 NetUtil.newURI("http://www.test5.com"))); |
|
62 |
|
63 // Upgrade the application and verify that the permissions are still not there |
|
64 restartManager("2"); |
|
65 |
|
66 do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
67 NetUtil.newURI("http://test1.com"))); |
|
68 do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
69 NetUtil.newURI("https://www.test2.com"))); |
|
70 do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
71 NetUtil.newURI("https://test3.com"))); |
|
72 do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
73 NetUtil.newURI("https://www.test4.com"))); |
|
74 do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, |
|
75 NetUtil.newURI("http://www.test5.com"))); |
|
76 } |