toolkit/mozapps/extensions/test/xpcshell/test_dictionary.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 // This verifies that bootstrappable add-ons can be used without restarts.
michael@0 6 Components.utils.import("resource://gre/modules/Services.jsm");
michael@0 7
michael@0 8 // Enable loading extensions from the user scopes
michael@0 9 Services.prefs.setIntPref("extensions.enabledScopes",
michael@0 10 AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER);
michael@0 11
michael@0 12 // The test extension uses an insecure update url.
michael@0 13 Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false);
michael@0 14
michael@0 15 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
michael@0 16
michael@0 17 const profileDir = gProfD.clone();
michael@0 18 profileDir.append("extensions");
michael@0 19 const userExtDir = gProfD.clone();
michael@0 20 userExtDir.append("extensions2");
michael@0 21 userExtDir.append(gAppInfo.ID);
michael@0 22 registerDirectory("XREUSysExt", userExtDir.parent);
michael@0 23
michael@0 24 Components.utils.import("resource://testing-common/httpd.js");
michael@0 25 // Create and configure the HTTP server.
michael@0 26 var testserver = new HttpServer();
michael@0 27 testserver.start(-1);
michael@0 28 gPort = testserver.identity.primaryPort;
michael@0 29
michael@0 30 // register files with server
michael@0 31 testserver.registerDirectory("/addons/", do_get_file("addons"));
michael@0 32 mapFile("/data/test_dictionary.rdf", testserver);
michael@0 33
michael@0 34 /**
michael@0 35 * This object is both a factory and an mozISpellCheckingEngine implementation (so, it
michael@0 36 * is de-facto a service). It's also an interface requestor that gives out
michael@0 37 * itself when asked for mozISpellCheckingEngine.
michael@0 38 */
michael@0 39 var HunspellEngine = {
michael@0 40 dictionaryDirs: [],
michael@0 41 listener: null,
michael@0 42
michael@0 43 QueryInterface: function hunspell_qi(iid) {
michael@0 44 if (iid.equals(Components.interfaces.nsISupports) ||
michael@0 45 iid.equals(Components.interfaces.nsIFactory) ||
michael@0 46 iid.equals(Components.interfaces.mozISpellCheckingEngine))
michael@0 47 return this;
michael@0 48 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 49 },
michael@0 50 createInstance: function hunspell_ci(outer, iid) {
michael@0 51 if (outer)
michael@0 52 throw Components.results.NS_ERROR_NO_AGGREGATION;
michael@0 53 return this.QueryInterface(iid);
michael@0 54 },
michael@0 55 lockFactory: function hunspell_lockf(lock) {
michael@0 56 throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
michael@0 57 },
michael@0 58
michael@0 59 addDirectory: function hunspell_addDirectory(dir) {
michael@0 60 this.dictionaryDirs.push(dir);
michael@0 61 if (this.listener)
michael@0 62 this.listener("addDirectory");
michael@0 63 },
michael@0 64
michael@0 65 removeDirectory: function hunspell_addDirectory(dir) {
michael@0 66 this.dictionaryDirs.splice(this.dictionaryDirs.indexOf(dir), 1);
michael@0 67 if (this.listener)
michael@0 68 this.listener("removeDirectory");
michael@0 69 },
michael@0 70
michael@0 71 getInterface: function hunspell_gi(iid) {
michael@0 72 if (iid.equals(Components.interfaces.mozISpellCheckingEngine))
michael@0 73 return this;
michael@0 74 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 75 },
michael@0 76
michael@0 77 contractID: "@mozilla.org/spellchecker/engine;1",
michael@0 78 classID: Components.ID("{6f3c63bc-a4fd-449b-9a58-a2d9bd972cce}"),
michael@0 79
michael@0 80 activate: function hunspell_activate() {
michael@0 81 this.origClassID = Components.manager.nsIComponentRegistrar
michael@0 82 .contractIDToCID(this.contractID);
michael@0 83 this.origFactory = Components.manager
michael@0 84 .getClassObject(Components.classes[this.contractID],
michael@0 85 Components.interfaces.nsIFactory);
michael@0 86
michael@0 87 Components.manager.nsIComponentRegistrar
michael@0 88 .unregisterFactory(this.origClassID, this.origFactory);
michael@0 89 Components.manager.nsIComponentRegistrar.registerFactory(this.classID,
michael@0 90 "Test hunspell", this.contractID, this);
michael@0 91 },
michael@0 92
michael@0 93 deactivate: function hunspell_deactivate() {
michael@0 94 Components.manager.nsIComponentRegistrar.unregisterFactory(this.classID, this);
michael@0 95 Components.manager.nsIComponentRegistrar.registerFactory(this.origClassID,
michael@0 96 "Hunspell", this.contractID, this.origFactory);
michael@0 97 },
michael@0 98
michael@0 99 isDictionaryEnabled: function hunspell_isDictionaryEnabled(name) {
michael@0 100 return this.dictionaryDirs.some(function(dir) {
michael@0 101 var dic = dir.clone();
michael@0 102 dic.append(name);
michael@0 103 return dic.exists();
michael@0 104 });
michael@0 105 }
michael@0 106 };
michael@0 107
michael@0 108 function run_test() {
michael@0 109 do_test_pending();
michael@0 110
michael@0 111 startupManager();
michael@0 112
michael@0 113 run_test_1();
michael@0 114 }
michael@0 115
michael@0 116 // Tests that installing doesn't require a restart
michael@0 117 function run_test_1() {
michael@0 118 prepare_test({ }, [
michael@0 119 "onNewInstall"
michael@0 120 ]);
michael@0 121
michael@0 122 HunspellEngine.activate();
michael@0 123
michael@0 124 AddonManager.getInstallForFile(do_get_addon("test_dictionary"), function(install) {
michael@0 125 ensure_test_completed();
michael@0 126
michael@0 127 do_check_neq(install, null);
michael@0 128 do_check_eq(install.type, "dictionary");
michael@0 129 do_check_eq(install.version, "1.0");
michael@0 130 do_check_eq(install.name, "Test Dictionary");
michael@0 131 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);
michael@0 132 do_check_true(install.addon.hasResource("install.rdf"));
michael@0 133 do_check_false(install.addon.hasResource("bootstrap.js"));
michael@0 134 do_check_eq(install.addon.operationsRequiringRestart &
michael@0 135 AddonManager.OP_NEEDS_RESTART_INSTALL, 0);
michael@0 136 do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
michael@0 137
michael@0 138 let addon = install.addon;
michael@0 139 prepare_test({
michael@0 140 "ab-CD@dictionaries.addons.mozilla.org": [
michael@0 141 ["onInstalling", false],
michael@0 142 "onInstalled"
michael@0 143 ]
michael@0 144 }, [
michael@0 145 "onInstallStarted",
michael@0 146 "onInstallEnded",
michael@0 147 ], function() {
michael@0 148 do_check_true(addon.hasResource("install.rdf"));
michael@0 149 HunspellEngine.listener = function(aEvent) {
michael@0 150 HunspellEngine.listener = null;
michael@0 151 do_check_eq(aEvent, "addDirectory");
michael@0 152 do_execute_soon(check_test_1);
michael@0 153 };
michael@0 154 });
michael@0 155 install.install();
michael@0 156 });
michael@0 157 }
michael@0 158
michael@0 159 function check_test_1() {
michael@0 160 AddonManager.getAllInstalls(function(installs) {
michael@0 161 // There should be no active installs now since the install completed and
michael@0 162 // doesn't require a restart.
michael@0 163 do_check_eq(installs.length, 0);
michael@0 164
michael@0 165 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
michael@0 166 do_check_neq(b1, null);
michael@0 167 do_check_eq(b1.version, "1.0");
michael@0 168 do_check_false(b1.appDisabled);
michael@0 169 do_check_false(b1.userDisabled);
michael@0 170 do_check_true(b1.isActive);
michael@0 171 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 172 do_check_true(b1.hasResource("install.rdf"));
michael@0 173 do_check_false(b1.hasResource("bootstrap.js"));
michael@0 174 do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
michael@0 175
michael@0 176 let dir = do_get_addon_root_uri(profileDir, "ab-CD@dictionaries.addons.mozilla.org");
michael@0 177
michael@0 178 AddonManager.getAddonsWithOperationsByTypes(null, function(list) {
michael@0 179 do_check_eq(list.length, 0);
michael@0 180
michael@0 181 run_test_2();
michael@0 182 });
michael@0 183 });
michael@0 184 });
michael@0 185 }
michael@0 186
michael@0 187 // Tests that disabling doesn't require a restart
michael@0 188 function run_test_2() {
michael@0 189 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
michael@0 190 prepare_test({
michael@0 191 "ab-CD@dictionaries.addons.mozilla.org": [
michael@0 192 ["onDisabling", false],
michael@0 193 "onDisabled"
michael@0 194 ]
michael@0 195 });
michael@0 196
michael@0 197 do_check_eq(b1.operationsRequiringRestart &
michael@0 198 AddonManager.OP_NEEDS_RESTART_DISABLE, 0);
michael@0 199 b1.userDisabled = true;
michael@0 200 ensure_test_completed();
michael@0 201
michael@0 202 do_check_neq(b1, null);
michael@0 203 do_check_eq(b1.version, "1.0");
michael@0 204 do_check_false(b1.appDisabled);
michael@0 205 do_check_true(b1.userDisabled);
michael@0 206 do_check_false(b1.isActive);
michael@0 207 do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 208 do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
michael@0 209
michael@0 210 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(newb1) {
michael@0 211 do_check_neq(newb1, null);
michael@0 212 do_check_eq(newb1.version, "1.0");
michael@0 213 do_check_false(newb1.appDisabled);
michael@0 214 do_check_true(newb1.userDisabled);
michael@0 215 do_check_false(newb1.isActive);
michael@0 216
michael@0 217 do_execute_soon(run_test_3);
michael@0 218 });
michael@0 219 });
michael@0 220 }
michael@0 221
michael@0 222 // Test that restarting doesn't accidentally re-enable
michael@0 223 function run_test_3() {
michael@0 224 shutdownManager();
michael@0 225 do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 226 startupManager(false);
michael@0 227 do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 228 do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
michael@0 229
michael@0 230 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
michael@0 231 do_check_neq(b1, null);
michael@0 232 do_check_eq(b1.version, "1.0");
michael@0 233 do_check_false(b1.appDisabled);
michael@0 234 do_check_true(b1.userDisabled);
michael@0 235 do_check_false(b1.isActive);
michael@0 236
michael@0 237 run_test_4();
michael@0 238 });
michael@0 239 }
michael@0 240
michael@0 241 // Tests that enabling doesn't require a restart
michael@0 242 function run_test_4() {
michael@0 243 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
michael@0 244 prepare_test({
michael@0 245 "ab-CD@dictionaries.addons.mozilla.org": [
michael@0 246 ["onEnabling", false],
michael@0 247 "onEnabled"
michael@0 248 ]
michael@0 249 });
michael@0 250
michael@0 251 do_check_eq(b1.operationsRequiringRestart &
michael@0 252 AddonManager.OP_NEEDS_RESTART_ENABLE, 0);
michael@0 253 b1.userDisabled = false;
michael@0 254 ensure_test_completed();
michael@0 255
michael@0 256 do_check_neq(b1, null);
michael@0 257 do_check_eq(b1.version, "1.0");
michael@0 258 do_check_false(b1.appDisabled);
michael@0 259 do_check_false(b1.userDisabled);
michael@0 260 do_check_true(b1.isActive);
michael@0 261 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 262 do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
michael@0 263
michael@0 264 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(newb1) {
michael@0 265 do_check_neq(newb1, null);
michael@0 266 do_check_eq(newb1.version, "1.0");
michael@0 267 do_check_false(newb1.appDisabled);
michael@0 268 do_check_false(newb1.userDisabled);
michael@0 269 do_check_true(newb1.isActive);
michael@0 270
michael@0 271 do_execute_soon(run_test_5);
michael@0 272 });
michael@0 273 });
michael@0 274 }
michael@0 275
michael@0 276 // Tests that a restart shuts down and restarts the add-on
michael@0 277 function run_test_5() {
michael@0 278 shutdownManager();
michael@0 279 do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 280 do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
michael@0 281 startupManager(false);
michael@0 282 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 283 do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
michael@0 284
michael@0 285 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
michael@0 286 do_check_neq(b1, null);
michael@0 287 do_check_eq(b1.version, "1.0");
michael@0 288 do_check_false(b1.appDisabled);
michael@0 289 do_check_false(b1.userDisabled);
michael@0 290 do_check_true(b1.isActive);
michael@0 291 do_check_false(isExtensionInAddonsList(profileDir, b1.id));
michael@0 292
michael@0 293 run_test_7();
michael@0 294 });
michael@0 295 }
michael@0 296
michael@0 297 // Tests that uninstalling doesn't require a restart
michael@0 298 function run_test_7() {
michael@0 299 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
michael@0 300 prepare_test({
michael@0 301 "ab-CD@dictionaries.addons.mozilla.org": [
michael@0 302 ["onUninstalling", false],
michael@0 303 "onUninstalled"
michael@0 304 ]
michael@0 305 });
michael@0 306
michael@0 307 do_check_eq(b1.operationsRequiringRestart &
michael@0 308 AddonManager.OP_NEEDS_RESTART_UNINSTALL, 0);
michael@0 309 b1.uninstall();
michael@0 310
michael@0 311 check_test_7();
michael@0 312 });
michael@0 313 }
michael@0 314
michael@0 315 function check_test_7() {
michael@0 316 ensure_test_completed();
michael@0 317 do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 318 do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
michael@0 319
michael@0 320 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org",
michael@0 321 callback_soon(function(b1) {
michael@0 322 do_check_eq(b1, null);
michael@0 323
michael@0 324 restartManager();
michael@0 325
michael@0 326 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(newb1) {
michael@0 327 do_check_eq(newb1, null);
michael@0 328
michael@0 329 do_execute_soon(run_test_8);
michael@0 330 });
michael@0 331 }));
michael@0 332 }
michael@0 333
michael@0 334 // Test that a bootstrapped extension dropped into the profile loads properly
michael@0 335 // on startup and doesn't cause an EM restart
michael@0 336 function run_test_8() {
michael@0 337 shutdownManager();
michael@0 338
michael@0 339 let dir = profileDir.clone();
michael@0 340 dir.append("ab-CD@dictionaries.addons.mozilla.org");
michael@0 341 dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755);
michael@0 342 let zip = AM_Cc["@mozilla.org/libjar/zip-reader;1"].
michael@0 343 createInstance(AM_Ci.nsIZipReader);
michael@0 344 zip.open(do_get_addon("test_dictionary"));
michael@0 345 dir.append("install.rdf");
michael@0 346 zip.extract("install.rdf", dir);
michael@0 347 dir = dir.parent;
michael@0 348 dir.append("dictionaries");
michael@0 349 dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755);
michael@0 350 dir.append("ab-CD.dic");
michael@0 351 zip.extract("dictionaries/ab-CD.dic", dir);
michael@0 352 zip.close();
michael@0 353
michael@0 354 startupManager(false);
michael@0 355
michael@0 356 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
michael@0 357 do_check_neq(b1, null);
michael@0 358 do_check_eq(b1.version, "1.0");
michael@0 359 do_check_false(b1.appDisabled);
michael@0 360 do_check_false(b1.userDisabled);
michael@0 361 do_check_true(b1.isActive);
michael@0 362 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 363 do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
michael@0 364
michael@0 365 do_execute_soon(run_test_9);
michael@0 366 });
michael@0 367 }
michael@0 368
michael@0 369 // Test that items detected as removed during startup get removed properly
michael@0 370 function run_test_9() {
michael@0 371 shutdownManager();
michael@0 372
michael@0 373 let dir = profileDir.clone();
michael@0 374 dir.append("ab-CD@dictionaries.addons.mozilla.org");
michael@0 375 dir.remove(true);
michael@0 376 startupManager(false);
michael@0 377
michael@0 378 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
michael@0 379 do_check_eq(b1, null);
michael@0 380 do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
michael@0 381
michael@0 382 do_execute_soon(run_test_12);
michael@0 383 });
michael@0 384 }
michael@0 385
michael@0 386
michael@0 387 // Tests that bootstrapped extensions are correctly loaded even if the app is
michael@0 388 // upgraded at the same time
michael@0 389 function run_test_12() {
michael@0 390 shutdownManager();
michael@0 391
michael@0 392 let dir = profileDir.clone();
michael@0 393 dir.append("ab-CD@dictionaries.addons.mozilla.org");
michael@0 394 dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755);
michael@0 395 let zip = AM_Cc["@mozilla.org/libjar/zip-reader;1"].
michael@0 396 createInstance(AM_Ci.nsIZipReader);
michael@0 397 zip.open(do_get_addon("test_dictionary"));
michael@0 398 dir.append("install.rdf");
michael@0 399 zip.extract("install.rdf", dir);
michael@0 400 dir = dir.parent;
michael@0 401 dir.append("dictionaries");
michael@0 402 dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755);
michael@0 403 dir.append("ab-CD.dic");
michael@0 404 zip.extract("dictionaries/ab-CD.dic", dir);
michael@0 405 zip.close();
michael@0 406
michael@0 407 startupManager(true);
michael@0 408
michael@0 409 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
michael@0 410 do_check_neq(b1, null);
michael@0 411 do_check_eq(b1.version, "1.0");
michael@0 412 do_check_false(b1.appDisabled);
michael@0 413 do_check_false(b1.userDisabled);
michael@0 414 do_check_true(b1.isActive);
michael@0 415 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 416 do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
michael@0 417
michael@0 418 b1.uninstall();
michael@0 419 do_execute_soon(run_test_16);
michael@0 420 });
michael@0 421 }
michael@0 422
michael@0 423
michael@0 424 // Tests that bootstrapped extensions don't get loaded when in safe mode
michael@0 425 function run_test_16() {
michael@0 426 restartManager();
michael@0 427
michael@0 428 installAllFiles([do_get_addon("test_dictionary")], function() {
michael@0 429 // spin the event loop to let the addon finish starting
michael@0 430 do_execute_soon(function check_installed_dictionary() {
michael@0 431 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org",
michael@0 432 callback_soon(function(b1) {
michael@0 433 // Should have installed and started
michael@0 434 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 435
michael@0 436 shutdownManager();
michael@0 437
michael@0 438 // Should have stopped
michael@0 439 do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 440
michael@0 441 gAppInfo.inSafeMode = true;
michael@0 442 startupManager(false);
michael@0 443
michael@0 444 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org",
michael@0 445 callback_soon(function(b1) {
michael@0 446 // Should still be stopped
michael@0 447 do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 448 do_check_false(b1.isActive);
michael@0 449
michael@0 450 shutdownManager();
michael@0 451 gAppInfo.inSafeMode = false;
michael@0 452 startupManager(false);
michael@0 453
michael@0 454 // Should have started
michael@0 455 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 456
michael@0 457 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
michael@0 458 b1.uninstall();
michael@0 459
michael@0 460 do_execute_soon(run_test_17);
michael@0 461 });
michael@0 462 }));
michael@0 463 }));
michael@0 464 });
michael@0 465 });
michael@0 466 }
michael@0 467
michael@0 468 // Check that a bootstrapped extension in a non-profile location is loaded
michael@0 469 function run_test_17() {
michael@0 470 shutdownManager();
michael@0 471
michael@0 472 let dir = userExtDir.clone();
michael@0 473 dir.append("ab-CD@dictionaries.addons.mozilla.org");
michael@0 474 dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755);
michael@0 475 let zip = AM_Cc["@mozilla.org/libjar/zip-reader;1"].
michael@0 476 createInstance(AM_Ci.nsIZipReader);
michael@0 477 zip.open(do_get_addon("test_dictionary"));
michael@0 478 dir.append("install.rdf");
michael@0 479 zip.extract("install.rdf", dir);
michael@0 480 dir = dir.parent;
michael@0 481 dir.append("dictionaries");
michael@0 482 dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755);
michael@0 483 dir.append("ab-CD.dic");
michael@0 484 zip.extract("dictionaries/ab-CD.dic", dir);
michael@0 485 zip.close();
michael@0 486
michael@0 487 startupManager();
michael@0 488
michael@0 489 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org",
michael@0 490 callback_soon(function(b1) {
michael@0 491 // Should have installed and started
michael@0 492 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 493 do_check_neq(b1, null);
michael@0 494 do_check_eq(b1.version, "1.0");
michael@0 495 do_check_true(b1.isActive);
michael@0 496
michael@0 497 // From run_test_21
michael@0 498 dir = userExtDir.clone();
michael@0 499 dir.append("ab-CD@dictionaries.addons.mozilla.org");
michael@0 500 dir.remove(true);
michael@0 501
michael@0 502 restartManager();
michael@0 503
michael@0 504 run_test_23();
michael@0 505 }));
michael@0 506 }
michael@0 507
michael@0 508 // Tests that installing from a URL doesn't require a restart
michael@0 509 function run_test_23() {
michael@0 510 prepare_test({ }, [
michael@0 511 "onNewInstall"
michael@0 512 ]);
michael@0 513
michael@0 514 let url = "http://localhost:" + gPort + "/addons/test_dictionary.xpi";
michael@0 515 AddonManager.getInstallForURL(url, function(install) {
michael@0 516 ensure_test_completed();
michael@0 517
michael@0 518 do_check_neq(install, null);
michael@0 519
michael@0 520 prepare_test({ }, [
michael@0 521 "onDownloadStarted",
michael@0 522 "onDownloadEnded"
michael@0 523 ], function() {
michael@0 524 do_check_eq(install.type, "dictionary");
michael@0 525 do_check_eq(install.version, "1.0");
michael@0 526 do_check_eq(install.name, "Test Dictionary");
michael@0 527 do_check_eq(install.state, AddonManager.STATE_DOWNLOADED);
michael@0 528 do_check_true(install.addon.hasResource("install.rdf"));
michael@0 529 do_check_false(install.addon.hasResource("bootstrap.js"));
michael@0 530 do_check_eq(install.addon.operationsRequiringRestart &
michael@0 531 AddonManager.OP_NEEDS_RESTART_INSTALL, 0);
michael@0 532 do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
michael@0 533
michael@0 534 let addon = install.addon;
michael@0 535 prepare_test({
michael@0 536 "ab-CD@dictionaries.addons.mozilla.org": [
michael@0 537 ["onInstalling", false],
michael@0 538 "onInstalled"
michael@0 539 ]
michael@0 540 }, [
michael@0 541 "onInstallStarted",
michael@0 542 "onInstallEnded",
michael@0 543 ], function() {
michael@0 544 do_check_true(addon.hasResource("install.rdf"));
michael@0 545 // spin to let the addon startup finish
michael@0 546 do_execute_soon(check_test_23);
michael@0 547 });
michael@0 548 });
michael@0 549 install.install();
michael@0 550 }, "application/x-xpinstall");
michael@0 551 }
michael@0 552
michael@0 553 function check_test_23() {
michael@0 554 AddonManager.getAllInstalls(function(installs) {
michael@0 555 // There should be no active installs now since the install completed and
michael@0 556 // doesn't require a restart.
michael@0 557 do_check_eq(installs.length, 0);
michael@0 558
michael@0 559 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
michael@0 560 do_check_neq(b1, null);
michael@0 561 do_check_eq(b1.version, "1.0");
michael@0 562 do_check_false(b1.appDisabled);
michael@0 563 do_check_false(b1.userDisabled);
michael@0 564 do_check_true(b1.isActive);
michael@0 565 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 566 do_check_true(b1.hasResource("install.rdf"));
michael@0 567 do_check_false(b1.hasResource("bootstrap.js"));
michael@0 568 do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0");
michael@0 569
michael@0 570 let dir = do_get_addon_root_uri(profileDir, "ab-CD@dictionaries.addons.mozilla.org");
michael@0 571
michael@0 572 AddonManager.getAddonsWithOperationsByTypes(null, callback_soon(function(list) {
michael@0 573 do_check_eq(list.length, 0);
michael@0 574
michael@0 575 restartManager();
michael@0 576 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
michael@0 577 b1.uninstall();
michael@0 578 do_execute_soon(run_test_25);
michael@0 579 });
michael@0 580 }));
michael@0 581 });
michael@0 582 });
michael@0 583 }
michael@0 584
michael@0 585 // Tests that updating from a bootstrappable add-on to a normal add-on calls
michael@0 586 // the uninstall method
michael@0 587 function run_test_25() {
michael@0 588 restartManager();
michael@0 589
michael@0 590 HunspellEngine.listener = function(aEvent) {
michael@0 591 HunspellEngine.listener = null;
michael@0 592 do_check_eq(aEvent, "addDirectory");
michael@0 593 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 594
michael@0 595 installAllFiles([do_get_addon("test_dictionary_2")], function test_25_installed2() {
michael@0 596 // Needs a restart to complete this so the old version stays running
michael@0 597 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 598
michael@0 599 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org",
michael@0 600 callback_soon(function(b1) {
michael@0 601 do_check_neq(b1, null);
michael@0 602 do_check_eq(b1.version, "1.0");
michael@0 603 do_check_true(b1.isActive);
michael@0 604 do_check_true(hasFlag(b1.pendingOperations, AddonManager.PENDING_UPGRADE));
michael@0 605
michael@0 606 restartManager();
michael@0 607
michael@0 608 do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 609
michael@0 610 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
michael@0 611 do_check_neq(b1, null);
michael@0 612 do_check_eq(b1.version, "2.0");
michael@0 613 do_check_true(b1.isActive);
michael@0 614 do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE);
michael@0 615
michael@0 616 do_execute_soon(run_test_26);
michael@0 617 });
michael@0 618 }));
michael@0 619 });
michael@0 620 };
michael@0 621
michael@0 622 installAllFiles([do_get_addon("test_dictionary")], function test_25_installed() { });
michael@0 623 }
michael@0 624
michael@0 625 // Tests that updating from a normal add-on to a bootstrappable add-on calls
michael@0 626 // the install method
michael@0 627 function run_test_26() {
michael@0 628 installAllFiles([do_get_addon("test_dictionary")], function test_26_install() {
michael@0 629 // Needs a restart to complete this
michael@0 630 do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 631
michael@0 632 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org",
michael@0 633 callback_soon(function(b1) {
michael@0 634 do_check_neq(b1, null);
michael@0 635 do_check_eq(b1.version, "2.0");
michael@0 636 do_check_true(b1.isActive);
michael@0 637 do_check_true(hasFlag(b1.pendingOperations, AddonManager.PENDING_UPGRADE));
michael@0 638
michael@0 639 restartManager();
michael@0 640
michael@0 641 do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic"));
michael@0 642
michael@0 643 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
michael@0 644 do_check_neq(b1, null);
michael@0 645 do_check_eq(b1.version, "1.0");
michael@0 646 do_check_true(b1.isActive);
michael@0 647 do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE);
michael@0 648
michael@0 649 HunspellEngine.deactivate();
michael@0 650 b1.uninstall();
michael@0 651 do_execute_soon(run_test_27);
michael@0 652 });
michael@0 653 }));
michael@0 654 });
michael@0 655 }
michael@0 656
michael@0 657 // Tests that an update check from a normal add-on to a bootstrappable add-on works
michael@0 658 function run_test_27() {
michael@0 659 restartManager();
michael@0 660 writeInstallRDFForExtension({
michael@0 661 id: "ab-CD@dictionaries.addons.mozilla.org",
michael@0 662 version: "1.0",
michael@0 663 updateURL: "http://localhost:" + gPort + "/data/test_dictionary.rdf",
michael@0 664 targetApplications: [{
michael@0 665 id: "xpcshell@tests.mozilla.org",
michael@0 666 minVersion: "1",
michael@0 667 maxVersion: "1"
michael@0 668 }],
michael@0 669 name: "Test Dictionary",
michael@0 670 }, profileDir);
michael@0 671 restartManager();
michael@0 672
michael@0 673 prepare_test({
michael@0 674 "ab-CD@dictionaries.addons.mozilla.org": [
michael@0 675 "onInstalling"
michael@0 676 ]
michael@0 677 }, [
michael@0 678 "onNewInstall",
michael@0 679 "onDownloadStarted",
michael@0 680 "onDownloadEnded",
michael@0 681 "onInstallStarted",
michael@0 682 "onInstallEnded"
michael@0 683 ], callback_soon(check_test_27));
michael@0 684
michael@0 685 AddonManagerPrivate.backgroundUpdateCheck();
michael@0 686 }
michael@0 687
michael@0 688 function check_test_27(install) {
michael@0 689 do_check_eq(install.existingAddon.pendingUpgrade.install, install);
michael@0 690
michael@0 691 restartManager();
michael@0 692 AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) {
michael@0 693 do_check_neq(b1, null);
michael@0 694 do_check_eq(b1.version, "2.0");
michael@0 695 do_check_eq(b1.type, "dictionary");
michael@0 696 b1.uninstall();
michael@0 697 do_execute_soon(run_test_28);
michael@0 698 });
michael@0 699 }
michael@0 700
michael@0 701 // Tests that an update check from a bootstrappable add-on to a normal add-on works
michael@0 702 function run_test_28() {
michael@0 703 restartManager();
michael@0 704
michael@0 705 writeInstallRDFForExtension({
michael@0 706 id: "ef@dictionaries.addons.mozilla.org",
michael@0 707 version: "1.0",
michael@0 708 type: "64",
michael@0 709 updateURL: "http://localhost:" + gPort + "/data/test_dictionary.rdf",
michael@0 710 targetApplications: [{
michael@0 711 id: "xpcshell@tests.mozilla.org",
michael@0 712 minVersion: "1",
michael@0 713 maxVersion: "1"
michael@0 714 }],
michael@0 715 name: "Test Dictionary ef",
michael@0 716 }, profileDir);
michael@0 717 restartManager();
michael@0 718
michael@0 719 prepare_test({
michael@0 720 "ef@dictionaries.addons.mozilla.org": [
michael@0 721 "onInstalling"
michael@0 722 ]
michael@0 723 }, [
michael@0 724 "onNewInstall",
michael@0 725 "onDownloadStarted",
michael@0 726 "onDownloadEnded",
michael@0 727 "onInstallStarted",
michael@0 728 "onInstallEnded"
michael@0 729 ], callback_soon(check_test_28));
michael@0 730
michael@0 731 AddonManagerPrivate.backgroundUpdateCheck();
michael@0 732 }
michael@0 733
michael@0 734 function check_test_28(install) {
michael@0 735 do_check_eq(install.existingAddon.pendingUpgrade.install, install);
michael@0 736
michael@0 737 restartManager();
michael@0 738 AddonManager.getAddonByID("ef@dictionaries.addons.mozilla.org", function(b2) {
michael@0 739 do_check_neq(b2, null);
michael@0 740 do_check_eq(b2.version, "2.0");
michael@0 741 do_check_eq(b2.type, "extension");
michael@0 742 b2.uninstall();
michael@0 743 do_execute_soon(run_test_29);
michael@0 744 });
michael@0 745 }
michael@0 746
michael@0 747 // Tests that an update check from a bootstrappable add-on to a bootstrappable add-on works
michael@0 748 function run_test_29() {
michael@0 749 restartManager();
michael@0 750
michael@0 751 writeInstallRDFForExtension({
michael@0 752 id: "gh@dictionaries.addons.mozilla.org",
michael@0 753 version: "1.0",
michael@0 754 type: "64",
michael@0 755 updateURL: "http://localhost:" + gPort + "/data/test_dictionary.rdf",
michael@0 756 targetApplications: [{
michael@0 757 id: "xpcshell@tests.mozilla.org",
michael@0 758 minVersion: "1",
michael@0 759 maxVersion: "1"
michael@0 760 }],
michael@0 761 name: "Test Dictionary gh",
michael@0 762 }, profileDir);
michael@0 763 restartManager();
michael@0 764
michael@0 765 prepare_test({
michael@0 766 "gh@dictionaries.addons.mozilla.org": [
michael@0 767 ["onInstalling", false /* = no restart */],
michael@0 768 ["onInstalled", false]
michael@0 769 ]
michael@0 770 }, [
michael@0 771 "onNewInstall",
michael@0 772 "onDownloadStarted",
michael@0 773 "onDownloadEnded",
michael@0 774 "onInstallStarted",
michael@0 775 "onInstallEnded"
michael@0 776 ], check_test_29);
michael@0 777
michael@0 778 AddonManagerPrivate.backgroundUpdateCheck();
michael@0 779 }
michael@0 780
michael@0 781 function check_test_29(install) {
michael@0 782 AddonManager.getAddonByID("gh@dictionaries.addons.mozilla.org", function(b2) {
michael@0 783 do_check_neq(b2, null);
michael@0 784 do_check_eq(b2.version, "2.0");
michael@0 785 do_check_eq(b2.type, "dictionary");
michael@0 786
michael@0 787 prepare_test({
michael@0 788 "gh@dictionaries.addons.mozilla.org": [
michael@0 789 ["onUninstalling", false],
michael@0 790 ["onUninstalled", false],
michael@0 791 ]
michael@0 792 }, [
michael@0 793 ], callback_soon(finish_test_29));
michael@0 794
michael@0 795 b2.uninstall();
michael@0 796 });
michael@0 797 }
michael@0 798
michael@0 799 function finish_test_29() {
michael@0 800 testserver.stop(do_test_finished);
michael@0 801 }

mercurial