toolkit/mozapps/extensions/test/xpcshell/test_safemode.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 // Tests that extensions behave correctly in safe mode
michael@0 8
michael@0 9 var addon1 = {
michael@0 10 id: "addon1@tests.mozilla.org",
michael@0 11 version: "1.0",
michael@0 12 name: "Test 1",
michael@0 13 optionsURL: "chrome://foo/content/options.xul",
michael@0 14 aboutURL: "chrome://foo/content/about.xul",
michael@0 15 iconURL: "chrome://foo/content/icon.png",
michael@0 16 targetApplications: [{
michael@0 17 id: "xpcshell@tests.mozilla.org",
michael@0 18 minVersion: "1",
michael@0 19 maxVersion: "1"
michael@0 20 }]
michael@0 21 };
michael@0 22
michael@0 23 const profileDir = gProfD.clone();
michael@0 24 profileDir.append("extensions");
michael@0 25
michael@0 26 var gIconURL = null;
michael@0 27
michael@0 28 // Sets up the profile by installing an add-on.
michael@0 29 function run_test() {
michael@0 30 do_test_pending();
michael@0 31 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
michael@0 32 gAppInfo.inSafeMode = true;
michael@0 33
michael@0 34 startupManager();
michael@0 35
michael@0 36 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) {
michael@0 37 do_check_eq(a1, null);
michael@0 38 do_check_not_in_crash_annotation(addon1.id, addon1.version);
michael@0 39
michael@0 40 writeInstallRDFForExtension(addon1, profileDir, addon1.id, "icon.png");
michael@0 41 gIconURL = do_get_addon_root_uri(profileDir.clone(), addon1.id) + "icon.png";
michael@0 42
michael@0 43 restartManager();
michael@0 44
michael@0 45 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(newa1) {
michael@0 46 do_check_neq(newa1, null);
michael@0 47 do_check_false(newa1.isActive);
michael@0 48 do_check_false(newa1.userDisabled);
michael@0 49 do_check_eq(newa1.aboutURL, null);
michael@0 50 do_check_eq(newa1.optionsURL, null);
michael@0 51 do_check_eq(newa1.iconURL, gIconURL);
michael@0 52 do_check_true(isExtensionInAddonsList(profileDir, newa1.id));
michael@0 53 do_check_true(hasFlag(newa1.permissions, AddonManager.PERM_CAN_DISABLE));
michael@0 54 do_check_false(hasFlag(newa1.permissions, AddonManager.PERM_CAN_ENABLE));
michael@0 55 do_check_eq(newa1.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_NONE);
michael@0 56 do_check_not_in_crash_annotation(addon1.id, addon1.version);
michael@0 57
michael@0 58 run_test_1();
michael@0 59 });
michael@0 60 }));
michael@0 61 }
michael@0 62
michael@0 63 // Disabling an add-on should work
michael@0 64 function run_test_1() {
michael@0 65 prepare_test({
michael@0 66 "addon1@tests.mozilla.org": [
michael@0 67 ["onDisabling", false],
michael@0 68 "onDisabled"
michael@0 69 ]
michael@0 70 });
michael@0 71
michael@0 72 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
michael@0 73 do_check_false(hasFlag(a1.operationsRequiringRestart,
michael@0 74 AddonManager.OP_NEEDS_RESTART_DISABLE));
michael@0 75 a1.userDisabled = true;
michael@0 76 do_check_false(a1.isActive);
michael@0 77 do_check_eq(a1.aboutURL, null);
michael@0 78 do_check_eq(a1.optionsURL, null);
michael@0 79 do_check_eq(a1.iconURL, gIconURL);
michael@0 80 do_check_false(hasFlag(a1.permissions, AddonManager.PERM_CAN_DISABLE));
michael@0 81 do_check_true(hasFlag(a1.permissions, AddonManager.PERM_CAN_ENABLE));
michael@0 82 do_check_eq(a1.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_NONE);
michael@0 83 do_check_not_in_crash_annotation(addon1.id, addon1.version);
michael@0 84
michael@0 85 ensure_test_completed();
michael@0 86
michael@0 87 run_test_2();
michael@0 88 });
michael@0 89 }
michael@0 90
michael@0 91 // Enabling an add-on should happen without restart but not become active.
michael@0 92 function run_test_2() {
michael@0 93 prepare_test({
michael@0 94 "addon1@tests.mozilla.org": [
michael@0 95 ["onEnabling", false],
michael@0 96 "onEnabled"
michael@0 97 ]
michael@0 98 });
michael@0 99
michael@0 100 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
michael@0 101 a1.userDisabled = false;
michael@0 102 do_check_false(a1.isActive);
michael@0 103 do_check_eq(a1.aboutURL, null);
michael@0 104 do_check_eq(a1.optionsURL, null);
michael@0 105 do_check_eq(a1.iconURL, gIconURL);
michael@0 106 do_check_true(hasFlag(a1.permissions, AddonManager.PERM_CAN_DISABLE));
michael@0 107 do_check_false(hasFlag(a1.permissions, AddonManager.PERM_CAN_ENABLE));
michael@0 108 do_check_eq(a1.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_NONE);
michael@0 109 do_check_not_in_crash_annotation(addon1.id, addon1.version);
michael@0 110
michael@0 111 ensure_test_completed();
michael@0 112
michael@0 113 do_execute_soon(do_test_finished);
michael@0 114 });
michael@0 115 }

mercurial