toolkit/mozapps/extensions/test/xpcshell/test_bug659772.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 // Tests that a pending upgrade during a schema update doesn't break things
michael@0 6
michael@0 7 var addon1 = {
michael@0 8 id: "addon1@tests.mozilla.org",
michael@0 9 version: "2.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 var addon2 = {
michael@0 19 id: "addon2@tests.mozilla.org",
michael@0 20 version: "2.0",
michael@0 21 name: "Test 2",
michael@0 22 targetApplications: [{
michael@0 23 id: "xpcshell@tests.mozilla.org",
michael@0 24 minVersion: "1",
michael@0 25 maxVersion: "2"
michael@0 26 }]
michael@0 27 };
michael@0 28
michael@0 29 var addon3 = {
michael@0 30 id: "addon3@tests.mozilla.org",
michael@0 31 version: "2.0",
michael@0 32 name: "Test 3",
michael@0 33 targetApplications: [{
michael@0 34 id: "xpcshell@tests.mozilla.org",
michael@0 35 minVersion: "1",
michael@0 36 maxVersion: "1"
michael@0 37 }]
michael@0 38 };
michael@0 39
michael@0 40 var addon4 = {
michael@0 41 id: "addon4@tests.mozilla.org",
michael@0 42 version: "2.0",
michael@0 43 name: "Test 4",
michael@0 44 targetApplications: [{
michael@0 45 id: "xpcshell@tests.mozilla.org",
michael@0 46 minVersion: "2",
michael@0 47 maxVersion: "2"
michael@0 48 }]
michael@0 49 };
michael@0 50
michael@0 51 const profileDir = gProfD.clone();
michael@0 52 profileDir.append("extensions");
michael@0 53
michael@0 54 function run_test() {
michael@0 55 do_test_pending();
michael@0 56 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
michael@0 57
michael@0 58 run_test_1();
michael@0 59 }
michael@0 60
michael@0 61 // Tests whether a schema migration without app version change works
michael@0 62 function run_test_1() {
michael@0 63 writeInstallRDFForExtension(addon1, profileDir);
michael@0 64 writeInstallRDFForExtension(addon2, profileDir);
michael@0 65 writeInstallRDFForExtension(addon3, profileDir);
michael@0 66 writeInstallRDFForExtension(addon4, profileDir);
michael@0 67
michael@0 68 startupManager();
michael@0 69
michael@0 70 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
michael@0 71 "addon2@tests.mozilla.org",
michael@0 72 "addon3@tests.mozilla.org",
michael@0 73 "addon4@tests.mozilla.org"],
michael@0 74 function([a1, a2, a3, a4]) {
michael@0 75 do_check_neq(a1, null);
michael@0 76 do_check_eq(a1.version, "2.0");
michael@0 77 do_check_false(a1.appDisabled);
michael@0 78 do_check_false(a1.userDisabled);
michael@0 79 do_check_true(a1.isActive);
michael@0 80 do_check_true(isExtensionInAddonsList(profileDir, addon1.id));
michael@0 81
michael@0 82 do_check_neq(a2, null);
michael@0 83 do_check_eq(a2.version, "2.0");
michael@0 84 do_check_false(a2.appDisabled);
michael@0 85 do_check_false(a2.userDisabled);
michael@0 86 do_check_true(a2.isActive);
michael@0 87 do_check_true(isExtensionInAddonsList(profileDir, addon2.id));
michael@0 88
michael@0 89 do_check_neq(a3, null);
michael@0 90 do_check_eq(a3.version, "2.0");
michael@0 91 do_check_false(a3.appDisabled);
michael@0 92 do_check_false(a3.userDisabled);
michael@0 93 do_check_true(a3.isActive);
michael@0 94 do_check_true(isExtensionInAddonsList(profileDir, addon3.id));
michael@0 95
michael@0 96 do_check_neq(a4, null);
michael@0 97 do_check_eq(a4.version, "2.0");
michael@0 98 do_check_true(a4.appDisabled);
michael@0 99 do_check_false(a4.userDisabled);
michael@0 100 do_check_false(a4.isActive);
michael@0 101 do_check_false(isExtensionInAddonsList(profileDir, addon4.id));
michael@0 102
michael@0 103 // Prepare the add-on update, and a bootstrapped addon (bug 693714)
michael@0 104 installAllFiles([
michael@0 105 do_get_addon("test_bug659772"),
michael@0 106 do_get_addon("test_bootstrap1_1")
michael@0 107 ], function() {
michael@0 108 shutdownManager();
michael@0 109
michael@0 110 // Make it look like the next time the app is started it has a new DB schema
michael@0 111 changeXPIDBVersion(1);
michael@0 112 Services.prefs.setIntPref("extensions.databaseSchema", 1);
michael@0 113
michael@0 114 let jsonfile = gProfD.clone();
michael@0 115 jsonfile.append("extensions");
michael@0 116 jsonfile.append("staged");
michael@0 117 jsonfile.append("addon3@tests.mozilla.org.json");
michael@0 118 do_check_true(jsonfile.exists());
michael@0 119
michael@0 120 // Remove an unnecessary property from the cached manifest
michael@0 121 let fis = AM_Cc["@mozilla.org/network/file-input-stream;1"].
michael@0 122 createInstance(AM_Ci.nsIFileInputStream);
michael@0 123 let json = AM_Cc["@mozilla.org/dom/json;1"].
michael@0 124 createInstance(AM_Ci.nsIJSON);
michael@0 125 fis.init(jsonfile, -1, 0, 0);
michael@0 126 let addonObj = json.decodeFromStream(fis, jsonfile.fileSize);
michael@0 127 fis.close();
michael@0 128 delete addonObj.optionsType;
michael@0 129
michael@0 130 let stream = AM_Cc["@mozilla.org/network/file-output-stream;1"].
michael@0 131 createInstance(AM_Ci.nsIFileOutputStream);
michael@0 132 let converter = AM_Cc["@mozilla.org/intl/converter-output-stream;1"].
michael@0 133 createInstance(AM_Ci.nsIConverterOutputStream);
michael@0 134 stream.init(jsonfile, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE |
michael@0 135 FileUtils.MODE_TRUNCATE, FileUtils.PERMS_FILE,
michael@0 136 0);
michael@0 137 converter.init(stream, "UTF-8", 0, 0x0000);
michael@0 138 converter.writeString(JSON.stringify(addonObj));
michael@0 139 converter.close();
michael@0 140 stream.close();
michael@0 141
michael@0 142 Services.prefs.clearUserPref("bootstraptest.install_reason");
michael@0 143 Services.prefs.clearUserPref("bootstraptest.uninstall_reason");
michael@0 144
michael@0 145 startupManager(false);
michael@0 146
michael@0 147 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
michael@0 148 "addon2@tests.mozilla.org",
michael@0 149 "addon3@tests.mozilla.org",
michael@0 150 "addon4@tests.mozilla.org"],
michael@0 151 function([a1, a2, a3, a4]) {
michael@0 152 do_check_neq(a1, null);
michael@0 153 do_check_eq(a1.version, "2.0");
michael@0 154 do_check_false(a1.appDisabled);
michael@0 155 do_check_false(a1.userDisabled);
michael@0 156 do_check_true(a1.isActive);
michael@0 157 do_check_true(isExtensionInAddonsList(profileDir, addon1.id));
michael@0 158
michael@0 159 do_check_neq(a2, null);
michael@0 160 do_check_eq(a2.version, "2.0");
michael@0 161 do_check_false(a2.appDisabled);
michael@0 162 do_check_false(a2.userDisabled);
michael@0 163 do_check_true(a2.isActive);
michael@0 164 do_check_true(isExtensionInAddonsList(profileDir, addon2.id));
michael@0 165
michael@0 166 // Should stay enabled because we migrate the compat info from
michael@0 167 // the previous version of the DB
michael@0 168 do_check_neq(a3, null);
michael@0 169 do_check_eq(a3.version, "2.0");
michael@0 170 todo_check_false(a3.appDisabled); // XXX unresolved issue
michael@0 171 do_check_false(a3.userDisabled);
michael@0 172 todo_check_true(a3.isActive); // XXX same
michael@0 173 todo_check_true(isExtensionInAddonsList(profileDir, addon3.id)); // XXX same
michael@0 174
michael@0 175 do_check_neq(a4, null);
michael@0 176 do_check_eq(a4.version, "2.0");
michael@0 177 do_check_true(a4.appDisabled);
michael@0 178 do_check_false(a4.userDisabled);
michael@0 179 do_check_false(a4.isActive);
michael@0 180 do_check_false(isExtensionInAddonsList(profileDir, addon4.id));
michael@0 181
michael@0 182 // Check that install and uninstall haven't been called on the bootstrapped addon
michael@0 183 do_check_false(Services.prefs.prefHasUserValue("bootstraptest.install_reason"));
michael@0 184 do_check_false(Services.prefs.prefHasUserValue("bootstraptest.uninstall_reason"));
michael@0 185
michael@0 186 a1.uninstall();
michael@0 187 a2.uninstall();
michael@0 188 a3.uninstall();
michael@0 189 a4.uninstall();
michael@0 190 do_execute_soon(run_test_2);
michael@0 191 });
michael@0 192 });
michael@0 193 });
michael@0 194 }
michael@0 195
michael@0 196 // Tests whether a schema migration with app version change works
michael@0 197 function run_test_2() {
michael@0 198 restartManager();
michael@0 199
michael@0 200 shutdownManager();
michael@0 201
michael@0 202 writeInstallRDFForExtension(addon1, profileDir);
michael@0 203 writeInstallRDFForExtension(addon2, profileDir);
michael@0 204 writeInstallRDFForExtension(addon3, profileDir);
michael@0 205 writeInstallRDFForExtension(addon4, profileDir);
michael@0 206
michael@0 207 startupManager();
michael@0 208
michael@0 209 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
michael@0 210 "addon2@tests.mozilla.org",
michael@0 211 "addon3@tests.mozilla.org",
michael@0 212 "addon4@tests.mozilla.org"],
michael@0 213 function([a1, a2, a3, a4]) {
michael@0 214 do_check_neq(a1, null);
michael@0 215 do_check_eq(a1.version, "2.0");
michael@0 216 do_check_false(a1.appDisabled);
michael@0 217 do_check_false(a1.userDisabled);
michael@0 218 do_check_true(a1.isActive);
michael@0 219 do_check_true(isExtensionInAddonsList(profileDir, addon1.id));
michael@0 220
michael@0 221 do_check_neq(a2, null);
michael@0 222 do_check_eq(a2.version, "2.0");
michael@0 223 do_check_false(a2.appDisabled);
michael@0 224 do_check_false(a2.userDisabled);
michael@0 225 do_check_true(a2.isActive);
michael@0 226 do_check_true(isExtensionInAddonsList(profileDir, addon2.id));
michael@0 227
michael@0 228 do_check_neq(a3, null);
michael@0 229 do_check_eq(a3.version, "2.0");
michael@0 230 do_check_false(a3.appDisabled);
michael@0 231 do_check_false(a3.userDisabled);
michael@0 232 do_check_true(a3.isActive);
michael@0 233 do_check_true(isExtensionInAddonsList(profileDir, addon3.id));
michael@0 234
michael@0 235 do_check_neq(a4, null);
michael@0 236 do_check_eq(a4.version, "2.0");
michael@0 237 do_check_true(a4.appDisabled);
michael@0 238 do_check_false(a4.userDisabled);
michael@0 239 do_check_false(a4.isActive);
michael@0 240 do_check_false(isExtensionInAddonsList(profileDir, addon4.id));
michael@0 241
michael@0 242 // Prepare the add-on update, and a bootstrapped addon (bug 693714)
michael@0 243 installAllFiles([
michael@0 244 do_get_addon("test_bug659772"),
michael@0 245 do_get_addon("test_bootstrap1_1")
michael@0 246 ], function() { do_execute_soon(prepare_schema_migrate); });
michael@0 247
michael@0 248 function prepare_schema_migrate() {
michael@0 249 shutdownManager();
michael@0 250
michael@0 251 // Make it look like the next time the app is started it has a new DB schema
michael@0 252 changeXPIDBVersion(1);
michael@0 253 Services.prefs.setIntPref("extensions.databaseSchema", 1);
michael@0 254
michael@0 255 let jsonfile = gProfD.clone();
michael@0 256 jsonfile.append("extensions");
michael@0 257 jsonfile.append("staged");
michael@0 258 jsonfile.append("addon3@tests.mozilla.org.json");
michael@0 259 do_check_true(jsonfile.exists());
michael@0 260
michael@0 261 // Remove an unnecessary property from the cached manifest
michael@0 262 let fis = AM_Cc["@mozilla.org/network/file-input-stream;1"].
michael@0 263 createInstance(AM_Ci.nsIFileInputStream);
michael@0 264 let json = AM_Cc["@mozilla.org/dom/json;1"].
michael@0 265 createInstance(AM_Ci.nsIJSON);
michael@0 266 fis.init(jsonfile, -1, 0, 0);
michael@0 267 let addonObj = json.decodeFromStream(fis, jsonfile.fileSize);
michael@0 268 fis.close();
michael@0 269 delete addonObj.optionsType;
michael@0 270
michael@0 271 let stream = AM_Cc["@mozilla.org/network/file-output-stream;1"].
michael@0 272 createInstance(AM_Ci.nsIFileOutputStream);
michael@0 273 let converter = AM_Cc["@mozilla.org/intl/converter-output-stream;1"].
michael@0 274 createInstance(AM_Ci.nsIConverterOutputStream);
michael@0 275 stream.init(jsonfile, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE |
michael@0 276 FileUtils.MODE_TRUNCATE, FileUtils.PERMS_FILE,
michael@0 277 0);
michael@0 278 converter.init(stream, "UTF-8", 0, 0x0000);
michael@0 279 converter.writeString(JSON.stringify(addonObj));
michael@0 280 converter.close();
michael@0 281 stream.close();
michael@0 282
michael@0 283 Services.prefs.clearUserPref("bootstraptest.install_reason");
michael@0 284 Services.prefs.clearUserPref("bootstraptest.uninstall_reason");
michael@0 285
michael@0 286 gAppInfo.version = "2";
michael@0 287 startupManager(true);
michael@0 288
michael@0 289 AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org",
michael@0 290 "addon2@tests.mozilla.org",
michael@0 291 "addon3@tests.mozilla.org",
michael@0 292 "addon4@tests.mozilla.org"],
michael@0 293 callback_soon(function([a1, a2, a3, a4]) {
michael@0 294 do_check_neq(a1, null);
michael@0 295 do_check_eq(a1.version, "2.0");
michael@0 296 do_check_true(a1.appDisabled);
michael@0 297 do_check_false(a1.userDisabled);
michael@0 298 do_check_false(a1.isActive);
michael@0 299 do_check_false(isExtensionInAddonsList(profileDir, addon1.id));
michael@0 300
michael@0 301 do_check_neq(a2, null);
michael@0 302 do_check_eq(a2.version, "2.0");
michael@0 303 do_check_false(a2.appDisabled);
michael@0 304 do_check_false(a2.userDisabled);
michael@0 305 do_check_true(a2.isActive);
michael@0 306 do_check_true(isExtensionInAddonsList(profileDir, addon2.id));
michael@0 307
michael@0 308 // Should become appDisabled because we migrate the compat info from
michael@0 309 // the previous version of the DB
michael@0 310 do_check_neq(a3, null);
michael@0 311 do_check_eq(a3.version, "2.0");
michael@0 312 todo_check_true(a3.appDisabled);
michael@0 313 do_check_false(a3.userDisabled);
michael@0 314 todo_check_false(a3.isActive);
michael@0 315 todo_check_false(isExtensionInAddonsList(profileDir, addon3.id));
michael@0 316
michael@0 317 do_check_neq(a4, null);
michael@0 318 do_check_eq(a4.version, "2.0");
michael@0 319 do_check_false(a4.appDisabled);
michael@0 320 do_check_false(a4.userDisabled);
michael@0 321 do_check_true(a4.isActive);
michael@0 322 do_check_true(isExtensionInAddonsList(profileDir, addon4.id));
michael@0 323
michael@0 324 // Check that install and uninstall haven't been called on the bootstrapped addon
michael@0 325 do_check_false(Services.prefs.prefHasUserValue("bootstraptest.install_reason"));
michael@0 326 do_check_false(Services.prefs.prefHasUserValue("bootstraptest.uninstall_reason"));
michael@0 327
michael@0 328 a1.uninstall();
michael@0 329 a2.uninstall();
michael@0 330 a3.uninstall();
michael@0 331 a4.uninstall();
michael@0 332 restartManager();
michael@0 333
michael@0 334 shutdownManager();
michael@0 335
michael@0 336 do_test_finished();
michael@0 337 }));
michael@0 338 };
michael@0 339 });
michael@0 340 }

mercurial