Wed, 31 Dec 2014 06:09:35 +0100
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 | // This verifies that add-ons can be uninstalled. |
michael@0 | 6 | |
michael@0 | 7 | var addon1 = { |
michael@0 | 8 | id: "addon1@tests.mozilla.org", |
michael@0 | 9 | version: "1.0", |
michael@0 | 10 | name: "Test 1", |
michael@0 | 11 | targetApplications: [{ |
michael@0 | 12 | id: "xpcshell@tests.mozilla.org", |
michael@0 | 13 | minVersion: "1", |
michael@0 | 14 | maxVersion: "1" |
michael@0 | 15 | }] |
michael@0 | 16 | }; |
michael@0 | 17 | |
michael@0 | 18 | const profileDir = gProfD.clone(); |
michael@0 | 19 | profileDir.append("extensions"); |
michael@0 | 20 | |
michael@0 | 21 | // Sets up the profile by installing an add-on. |
michael@0 | 22 | function run_test() { |
michael@0 | 23 | createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
michael@0 | 24 | |
michael@0 | 25 | do_test_pending(); |
michael@0 | 26 | startupManager(); |
michael@0 | 27 | |
michael@0 | 28 | AddonManager.getAddonByID("addon1@tests.mozilla.org", callback_soon(function(olda1) { |
michael@0 | 29 | do_check_eq(olda1, null); |
michael@0 | 30 | |
michael@0 | 31 | writeInstallRDFForExtension(addon1, profileDir); |
michael@0 | 32 | |
michael@0 | 33 | restartManager(); |
michael@0 | 34 | |
michael@0 | 35 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
michael@0 | 36 | do_check_neq(a1, null); |
michael@0 | 37 | do_check_true(a1.isActive); |
michael@0 | 38 | do_check_false(a1.userDisabled); |
michael@0 | 39 | do_check_true(isExtensionInAddonsList(profileDir, a1.id)); |
michael@0 | 40 | do_check_eq(a1.pendingOperations, 0); |
michael@0 | 41 | do_check_in_crash_annotation(addon1.id, addon1.version); |
michael@0 | 42 | |
michael@0 | 43 | do_execute_soon(run_test_1); |
michael@0 | 44 | }); |
michael@0 | 45 | })); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | function end_test() { |
michael@0 | 49 | do_execute_soon(do_test_finished); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | // Uninstalling an add-on should work. |
michael@0 | 53 | function run_test_1() { |
michael@0 | 54 | prepare_test({ |
michael@0 | 55 | "addon1@tests.mozilla.org": [ |
michael@0 | 56 | "onUninstalling" |
michael@0 | 57 | ] |
michael@0 | 58 | }); |
michael@0 | 59 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
michael@0 | 60 | do_check_eq(a1.pendingOperations, 0); |
michael@0 | 61 | do_check_neq(a1.operationsRequiringRestart & |
michael@0 | 62 | AddonManager.OP_NEEDS_RESTART_UNINSTALL, 0); |
michael@0 | 63 | a1.uninstall(); |
michael@0 | 64 | do_check_true(hasFlag(a1.pendingOperations, AddonManager.PENDING_UNINSTALL)); |
michael@0 | 65 | do_check_in_crash_annotation(addon1.id, addon1.version); |
michael@0 | 66 | |
michael@0 | 67 | ensure_test_completed(); |
michael@0 | 68 | |
michael@0 | 69 | AddonManager.getAddonsWithOperationsByTypes(null, function(list) { |
michael@0 | 70 | do_check_eq(list.length, 1); |
michael@0 | 71 | do_check_eq(list[0].id, "addon1@tests.mozilla.org"); |
michael@0 | 72 | |
michael@0 | 73 | do_execute_soon(check_test_1); |
michael@0 | 74 | }); |
michael@0 | 75 | }); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | function check_test_1() { |
michael@0 | 79 | restartManager(); |
michael@0 | 80 | |
michael@0 | 81 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
michael@0 | 82 | do_check_eq(a1, null); |
michael@0 | 83 | do_check_false(isExtensionInAddonsList(profileDir, "addon1@tests.mozilla.org")); |
michael@0 | 84 | do_check_not_in_crash_annotation(addon1.id, addon1.version); |
michael@0 | 85 | |
michael@0 | 86 | var dest = profileDir.clone(); |
michael@0 | 87 | dest.append(do_get_expected_addon_name("addon1@tests.mozilla.org")); |
michael@0 | 88 | do_check_false(dest.exists()); |
michael@0 | 89 | writeInstallRDFForExtension(addon1, profileDir); |
michael@0 | 90 | do_execute_soon(run_test_2); |
michael@0 | 91 | }); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | // Cancelling the uninstall should send onOperationCancelled |
michael@0 | 95 | function run_test_2() { |
michael@0 | 96 | restartManager(); |
michael@0 | 97 | |
michael@0 | 98 | prepare_test({ |
michael@0 | 99 | "addon1@tests.mozilla.org": [ |
michael@0 | 100 | "onUninstalling" |
michael@0 | 101 | ] |
michael@0 | 102 | }); |
michael@0 | 103 | |
michael@0 | 104 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
michael@0 | 105 | do_check_neq(a1, null); |
michael@0 | 106 | do_check_true(a1.isActive); |
michael@0 | 107 | do_check_false(a1.userDisabled); |
michael@0 | 108 | do_check_true(isExtensionInAddonsList(profileDir, a1.id)); |
michael@0 | 109 | do_check_eq(a1.pendingOperations, 0); |
michael@0 | 110 | a1.uninstall(); |
michael@0 | 111 | do_check_true(hasFlag(a1.pendingOperations, AddonManager.PENDING_UNINSTALL)); |
michael@0 | 112 | |
michael@0 | 113 | ensure_test_completed(); |
michael@0 | 114 | |
michael@0 | 115 | prepare_test({ |
michael@0 | 116 | "addon1@tests.mozilla.org": [ |
michael@0 | 117 | "onOperationCancelled" |
michael@0 | 118 | ] |
michael@0 | 119 | }); |
michael@0 | 120 | a1.cancelUninstall(); |
michael@0 | 121 | do_check_eq(a1.pendingOperations, 0); |
michael@0 | 122 | |
michael@0 | 123 | ensure_test_completed(); |
michael@0 | 124 | |
michael@0 | 125 | do_execute_soon(check_test_2); |
michael@0 | 126 | }); |
michael@0 | 127 | } |
michael@0 | 128 | |
michael@0 | 129 | function check_test_2() { |
michael@0 | 130 | restartManager(); |
michael@0 | 131 | |
michael@0 | 132 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
michael@0 | 133 | do_check_neq(a1, null); |
michael@0 | 134 | do_check_true(a1.isActive); |
michael@0 | 135 | do_check_false(a1.userDisabled); |
michael@0 | 136 | do_check_true(isExtensionInAddonsList(profileDir, a1.id)); |
michael@0 | 137 | |
michael@0 | 138 | run_test_3(); |
michael@0 | 139 | }); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | // Uninstalling an item pending disable should still require a restart |
michael@0 | 143 | function run_test_3() { |
michael@0 | 144 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
michael@0 | 145 | prepare_test({ |
michael@0 | 146 | "addon1@tests.mozilla.org": [ |
michael@0 | 147 | "onDisabling" |
michael@0 | 148 | ] |
michael@0 | 149 | }); |
michael@0 | 150 | a1.userDisabled = true; |
michael@0 | 151 | ensure_test_completed(); |
michael@0 | 152 | |
michael@0 | 153 | do_check_true(hasFlag(AddonManager.PENDING_DISABLE, a1.pendingOperations)); |
michael@0 | 154 | do_check_true(a1.isActive); |
michael@0 | 155 | |
michael@0 | 156 | prepare_test({ |
michael@0 | 157 | "addon1@tests.mozilla.org": [ |
michael@0 | 158 | "onUninstalling" |
michael@0 | 159 | ] |
michael@0 | 160 | }); |
michael@0 | 161 | a1.uninstall(); |
michael@0 | 162 | |
michael@0 | 163 | check_test_3(); |
michael@0 | 164 | }); |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | function check_test_3() { |
michael@0 | 168 | ensure_test_completed(); |
michael@0 | 169 | |
michael@0 | 170 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
michael@0 | 171 | do_check_neq(a1, null); |
michael@0 | 172 | do_check_true(hasFlag(AddonManager.PENDING_UNINSTALL, a1.pendingOperations)); |
michael@0 | 173 | |
michael@0 | 174 | prepare_test({ |
michael@0 | 175 | "addon1@tests.mozilla.org": [ |
michael@0 | 176 | "onOperationCancelled" |
michael@0 | 177 | ] |
michael@0 | 178 | }); |
michael@0 | 179 | a1.cancelUninstall(); |
michael@0 | 180 | ensure_test_completed(); |
michael@0 | 181 | do_check_true(hasFlag(AddonManager.PENDING_DISABLE, a1.pendingOperations)); |
michael@0 | 182 | |
michael@0 | 183 | do_execute_soon(run_test_4); |
michael@0 | 184 | }); |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | // Test that uninstalling an inactive item should happen without a restart |
michael@0 | 188 | function run_test_4() { |
michael@0 | 189 | restartManager(); |
michael@0 | 190 | |
michael@0 | 191 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
michael@0 | 192 | do_check_neq(a1, null); |
michael@0 | 193 | do_check_false(a1.isActive); |
michael@0 | 194 | do_check_true(a1.userDisabled); |
michael@0 | 195 | do_check_false(isExtensionInAddonsList(profileDir, a1.id)); |
michael@0 | 196 | |
michael@0 | 197 | prepare_test({ |
michael@0 | 198 | "addon1@tests.mozilla.org": [ |
michael@0 | 199 | ["onUninstalling", false], |
michael@0 | 200 | "onUninstalled" |
michael@0 | 201 | ] |
michael@0 | 202 | }); |
michael@0 | 203 | a1.uninstall(); |
michael@0 | 204 | |
michael@0 | 205 | check_test_4(); |
michael@0 | 206 | }); |
michael@0 | 207 | } |
michael@0 | 208 | |
michael@0 | 209 | function check_test_4() { |
michael@0 | 210 | AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
michael@0 | 211 | do_check_eq(a1, null); |
michael@0 | 212 | |
michael@0 | 213 | end_test(); |
michael@0 | 214 | }); |
michael@0 | 215 | } |