toolkit/mozapps/extensions/test/xpcshell/test_disable.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 // This verifies that add-ons can be disabled and enabled.
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
michael@0 33 startupManager();
michael@0 34
michael@0 35 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) {
michael@0 36 do_check_eq(a1, null);
michael@0 37 do_check_not_in_crash_annotation(addon1.id, addon1.version);
michael@0 38
michael@0 39 writeInstallRDFForExtension(addon1, profileDir, addon1.id, "icon.png");
michael@0 40 gIconURL = do_get_addon_root_uri(profileDir.clone(), addon1.id) + "icon.png";
michael@0 41
michael@0 42 restartManager();
michael@0 43
michael@0 44 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(newa1) {
michael@0 45 do_check_neq(newa1, null);
michael@0 46 do_check_true(newa1.isActive);
michael@0 47 do_check_false(newa1.userDisabled);
michael@0 48 do_check_eq(newa1.aboutURL, "chrome://foo/content/about.xul");
michael@0 49 do_check_eq(newa1.optionsURL, "chrome://foo/content/options.xul");
michael@0 50 do_check_eq(newa1.iconURL, "chrome://foo/content/icon.png");
michael@0 51 do_check_true(isExtensionInAddonsList(profileDir, newa1.id));
michael@0 52 do_check_true(hasFlag(newa1.permissions, AddonManager.PERM_CAN_DISABLE));
michael@0 53 do_check_false(hasFlag(newa1.permissions, AddonManager.PERM_CAN_ENABLE));
michael@0 54 do_check_eq(newa1.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_DISABLE |
michael@0 55 AddonManager.OP_NEEDS_RESTART_UNINSTALL);
michael@0 56 do_check_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"
michael@0 68 ]
michael@0 69 });
michael@0 70
michael@0 71 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
michael@0 72 do_check_neq(a1.operationsRequiringRestart &
michael@0 73 AddonManager.OP_NEEDS_RESTART_DISABLE, 0);
michael@0 74 a1.userDisabled = true;
michael@0 75 do_check_eq(a1.aboutURL, "chrome://foo/content/about.xul");
michael@0 76 do_check_eq(a1.optionsURL, "chrome://foo/content/options.xul");
michael@0 77 do_check_eq(a1.iconURL, "chrome://foo/content/icon.png");
michael@0 78 do_check_false(hasFlag(a1.permissions, AddonManager.PERM_CAN_DISABLE));
michael@0 79 do_check_true(hasFlag(a1.permissions, AddonManager.PERM_CAN_ENABLE));
michael@0 80 do_check_eq(a1.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_DISABLE |
michael@0 81 AddonManager.OP_NEEDS_RESTART_UNINSTALL);
michael@0 82 do_check_in_crash_annotation(addon1.id, addon1.version);
michael@0 83
michael@0 84 ensure_test_completed();
michael@0 85
michael@0 86 AddonManager.getAddonsWithOperationsByTypes(null, callback_soon(function(list) {
michael@0 87 do_check_eq(list.length, 1);
michael@0 88 do_check_eq(list[0].id, "addon1@tests.mozilla.org");
michael@0 89
michael@0 90 restartManager();
michael@0 91
michael@0 92 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(newa1) {
michael@0 93 do_check_neq(newa1, null);
michael@0 94 do_check_false(newa1.isActive);
michael@0 95 do_check_true(newa1.userDisabled);
michael@0 96 do_check_eq(newa1.aboutURL, null);
michael@0 97 do_check_eq(newa1.optionsURL, null);
michael@0 98 do_check_eq(newa1.iconURL, gIconURL);
michael@0 99 do_check_false(isExtensionInAddonsList(profileDir, newa1.id));
michael@0 100 do_check_false(hasFlag(newa1.permissions, AddonManager.PERM_CAN_DISABLE));
michael@0 101 do_check_true(hasFlag(newa1.permissions, AddonManager.PERM_CAN_ENABLE));
michael@0 102 do_check_eq(newa1.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_ENABLE);
michael@0 103 do_check_not_in_crash_annotation(addon1.id, addon1.version);
michael@0 104
michael@0 105 run_test_2();
michael@0 106 });
michael@0 107 }));
michael@0 108 });
michael@0 109 }
michael@0 110
michael@0 111 // Enabling an add-on should work.
michael@0 112 function run_test_2() {
michael@0 113 prepare_test({
michael@0 114 "addon1@tests.mozilla.org": [
michael@0 115 "onEnabling"
michael@0 116 ]
michael@0 117 });
michael@0 118
michael@0 119 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) {
michael@0 120 a1.userDisabled = false;
michael@0 121 do_check_eq(a1.aboutURL, null);
michael@0 122 do_check_eq(a1.optionsURL, null);
michael@0 123 do_check_eq(a1.iconURL, gIconURL);
michael@0 124 do_check_true(hasFlag(a1.permissions, AddonManager.PERM_CAN_DISABLE));
michael@0 125 do_check_false(hasFlag(a1.permissions, AddonManager.PERM_CAN_ENABLE));
michael@0 126 do_check_eq(a1.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_ENABLE);
michael@0 127
michael@0 128 ensure_test_completed();
michael@0 129
michael@0 130 AddonManager.getAddonsWithOperationsByTypes(null, callback_soon(function(list) {
michael@0 131 do_check_eq(list.length, 1);
michael@0 132 do_check_eq(list[0].id, "addon1@tests.mozilla.org");
michael@0 133
michael@0 134 restartManager();
michael@0 135
michael@0 136 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(newa1) {
michael@0 137 do_check_neq(newa1, null);
michael@0 138 do_check_true(newa1.isActive);
michael@0 139 do_check_false(newa1.userDisabled);
michael@0 140 do_check_eq(newa1.aboutURL, "chrome://foo/content/about.xul");
michael@0 141 do_check_eq(newa1.optionsURL, "chrome://foo/content/options.xul");
michael@0 142 do_check_eq(newa1.iconURL, "chrome://foo/content/icon.png");
michael@0 143 do_check_true(isExtensionInAddonsList(profileDir, newa1.id));
michael@0 144 do_check_true(hasFlag(newa1.permissions, AddonManager.PERM_CAN_DISABLE));
michael@0 145 do_check_false(hasFlag(newa1.permissions, AddonManager.PERM_CAN_ENABLE));
michael@0 146 do_check_eq(newa1.operationsRequiringRestart, AddonManager.OP_NEEDS_RESTART_DISABLE |
michael@0 147 AddonManager.OP_NEEDS_RESTART_UNINSTALL);
michael@0 148 do_check_in_crash_annotation(addon1.id, addon1.version);
michael@0 149
michael@0 150 run_test_3();
michael@0 151 });
michael@0 152 }));
michael@0 153 });
michael@0 154 }
michael@0 155
michael@0 156 // Disabling then enabling without restart should fire onOperationCancelled.
michael@0 157 function run_test_3() {
michael@0 158 prepare_test({
michael@0 159 "addon1@tests.mozilla.org": [
michael@0 160 "onDisabling"
michael@0 161 ]
michael@0 162 });
michael@0 163
michael@0 164 AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(a1) {
michael@0 165 a1.userDisabled = true;
michael@0 166 ensure_test_completed();
michael@0 167 prepare_test({
michael@0 168 "addon1@tests.mozilla.org": [
michael@0 169 "onOperationCancelled"
michael@0 170 ]
michael@0 171 });
michael@0 172 a1.userDisabled = false;
michael@0 173 do_check_true(hasFlag(a1.permissions, AddonManager.PERM_CAN_DISABLE));
michael@0 174 do_check_false(hasFlag(a1.permissions, AddonManager.PERM_CAN_ENABLE));
michael@0 175
michael@0 176 ensure_test_completed();
michael@0 177
michael@0 178 restartManager();
michael@0 179
michael@0 180 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(newa1) {
michael@0 181 do_check_neq(newa1, null);
michael@0 182 do_check_true(newa1.isActive);
michael@0 183 do_check_false(newa1.userDisabled);
michael@0 184 do_check_eq(newa1.aboutURL, "chrome://foo/content/about.xul");
michael@0 185 do_check_eq(newa1.optionsURL, "chrome://foo/content/options.xul");
michael@0 186 do_check_eq(newa1.iconURL, "chrome://foo/content/icon.png");
michael@0 187 do_check_true(isExtensionInAddonsList(profileDir, newa1.id));
michael@0 188 do_check_true(hasFlag(newa1.permissions, AddonManager.PERM_CAN_DISABLE));
michael@0 189 do_check_false(hasFlag(newa1.permissions, AddonManager.PERM_CAN_ENABLE));
michael@0 190
michael@0 191 do_execute_soon(do_test_finished);
michael@0 192 });
michael@0 193 }));
michael@0 194 }

mercurial