toolkit/mozapps/extensions/test/xpcshell/test_permissions.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial