michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: Components.utils.import("resource://gre/modules/NetUtil.jsm"); michael@0: michael@0: // Checks that permissions set in preferences are correctly imported but can michael@0: // be removed by the user. michael@0: michael@0: const XPI_MIMETYPE = "application/x-xpinstall"; michael@0: michael@0: function run_test() { michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2"); michael@0: michael@0: Services.prefs.setCharPref("xpinstall.whitelist.add", "test1.com,test2.com"); michael@0: Services.prefs.setCharPref("xpinstall.whitelist.add.36", "test3.com,www.test4.com"); michael@0: Services.prefs.setCharPref("xpinstall.whitelist.add.test5", "test5.com"); michael@0: michael@0: Services.perms.add(NetUtil.newURI("http://www.test9.com"), "install", michael@0: AM_Ci.nsIPermissionManager.ALLOW_ACTION); michael@0: michael@0: startupManager(); michael@0: michael@0: do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("http://test1.com"))); michael@0: do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("https://www.test2.com"))); michael@0: do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("https://test3.com"))); michael@0: do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("https://test4.com"))); michael@0: do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("https://www.test4.com"))); michael@0: do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("http://www.test5.com"))); michael@0: michael@0: do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("http://www.test6.com"))); michael@0: do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("http://test7.com"))); michael@0: do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("http://www.test8.com"))); michael@0: michael@0: // This should remain unaffected michael@0: do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("http://www.test9.com"))); michael@0: do_check_true(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("https://www.test9.com"))); michael@0: michael@0: Services.perms.removeAll(); michael@0: michael@0: do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("http://test1.com"))); michael@0: do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("https://www.test2.com"))); michael@0: do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("https://test3.com"))); michael@0: do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("https://www.test4.com"))); michael@0: do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("http://www.test5.com"))); michael@0: michael@0: // Upgrade the application and verify that the permissions are still not there michael@0: restartManager("2"); michael@0: michael@0: do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("http://test1.com"))); michael@0: do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("https://www.test2.com"))); michael@0: do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("https://test3.com"))); michael@0: do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("https://www.test4.com"))); michael@0: do_check_false(AddonManager.isInstallAllowed(XPI_MIMETYPE, michael@0: NetUtil.newURI("http://www.test5.com"))); michael@0: }