1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_permissions.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +Components.utils.import("resource://gre/modules/NetUtil.jsm"); 1.9 + 1.10 +// Checks that permissions set in preferences are correctly imported but can 1.11 +// be removed by the user. 1.12 + 1.13 +const XPI_MIMETYPE = "application/x-xpinstall"; 1.14 + 1.15 +function run_test() { 1.16 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2"); 1.17 + 1.18 + Services.prefs.setCharPref("xpinstall.whitelist.add", "test1.com,test2.com"); 1.19 + Services.prefs.setCharPref("xpinstall.whitelist.add.36", "test3.com,www.test4.com"); 1.20 + Services.prefs.setCharPref("xpinstall.whitelist.add.test5", "test5.com"); 1.21 + 1.22 + Services.perms.add(NetUtil.newURI("http://www.test9.com"), "install", 1.23 + AM_Ci.nsIPermissionManager.ALLOW_ACTION); 1.24 + 1.25 + startupManager(); 1.26 + 1.27 + do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.28 + NetUtil.newURI("http://test1.com"))); 1.29 + do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.30 + NetUtil.newURI("https://www.test2.com"))); 1.31 + do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.32 + NetUtil.newURI("https://test3.com"))); 1.33 + do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.34 + NetUtil.newURI("https://test4.com"))); 1.35 + do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.36 + NetUtil.newURI("https://www.test4.com"))); 1.37 + do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.38 + NetUtil.newURI("http://www.test5.com"))); 1.39 + 1.40 + do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.41 + NetUtil.newURI("http://www.test6.com"))); 1.42 + do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.43 + NetUtil.newURI("http://test7.com"))); 1.44 + do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.45 + NetUtil.newURI("http://www.test8.com"))); 1.46 + 1.47 + // This should remain unaffected 1.48 + do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.49 + NetUtil.newURI("http://www.test9.com"))); 1.50 + do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.51 + NetUtil.newURI("https://www.test9.com"))); 1.52 + 1.53 + Services.perms.removeAll(); 1.54 + 1.55 + do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.56 + NetUtil.newURI("http://test1.com"))); 1.57 + do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.58 + NetUtil.newURI("https://www.test2.com"))); 1.59 + do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.60 + NetUtil.newURI("https://test3.com"))); 1.61 + do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.62 + NetUtil.newURI("https://www.test4.com"))); 1.63 + do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.64 + NetUtil.newURI("http://www.test5.com"))); 1.65 + 1.66 + // Upgrade the application and verify that the permissions are still not there 1.67 + restartManager("2"); 1.68 + 1.69 + do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.70 + NetUtil.newURI("http://test1.com"))); 1.71 + do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.72 + NetUtil.newURI("https://www.test2.com"))); 1.73 + do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.74 + NetUtil.newURI("https://test3.com"))); 1.75 + do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.76 + NetUtil.newURI("https://www.test4.com"))); 1.77 + do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, 1.78 + NetUtil.newURI("http://www.test5.com"))); 1.79 +}