1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_dictionary.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,801 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +// This verifies that bootstrappable add-ons can be used without restarts. 1.9 +Components.utils.import("resource://gre/modules/Services.jsm"); 1.10 + 1.11 +// Enable loading extensions from the user scopes 1.12 +Services.prefs.setIntPref("extensions.enabledScopes", 1.13 + AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER); 1.14 + 1.15 +// The test extension uses an insecure update url. 1.16 +Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false); 1.17 + 1.18 +createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); 1.19 + 1.20 +const profileDir = gProfD.clone(); 1.21 +profileDir.append("extensions"); 1.22 +const userExtDir = gProfD.clone(); 1.23 +userExtDir.append("extensions2"); 1.24 +userExtDir.append(gAppInfo.ID); 1.25 +registerDirectory("XREUSysExt", userExtDir.parent); 1.26 + 1.27 +Components.utils.import("resource://testing-common/httpd.js"); 1.28 +// Create and configure the HTTP server. 1.29 +var testserver = new HttpServer(); 1.30 +testserver.start(-1); 1.31 +gPort = testserver.identity.primaryPort; 1.32 + 1.33 +// register files with server 1.34 +testserver.registerDirectory("/addons/", do_get_file("addons")); 1.35 +mapFile("/data/test_dictionary.rdf", testserver); 1.36 + 1.37 +/** 1.38 + * This object is both a factory and an mozISpellCheckingEngine implementation (so, it 1.39 + * is de-facto a service). It's also an interface requestor that gives out 1.40 + * itself when asked for mozISpellCheckingEngine. 1.41 + */ 1.42 +var HunspellEngine = { 1.43 + dictionaryDirs: [], 1.44 + listener: null, 1.45 + 1.46 + QueryInterface: function hunspell_qi(iid) { 1.47 + if (iid.equals(Components.interfaces.nsISupports) || 1.48 + iid.equals(Components.interfaces.nsIFactory) || 1.49 + iid.equals(Components.interfaces.mozISpellCheckingEngine)) 1.50 + return this; 1.51 + throw Components.results.NS_ERROR_NO_INTERFACE; 1.52 + }, 1.53 + createInstance: function hunspell_ci(outer, iid) { 1.54 + if (outer) 1.55 + throw Components.results.NS_ERROR_NO_AGGREGATION; 1.56 + return this.QueryInterface(iid); 1.57 + }, 1.58 + lockFactory: function hunspell_lockf(lock) { 1.59 + throw Components.results.NS_ERROR_NOT_IMPLEMENTED; 1.60 + }, 1.61 + 1.62 + addDirectory: function hunspell_addDirectory(dir) { 1.63 + this.dictionaryDirs.push(dir); 1.64 + if (this.listener) 1.65 + this.listener("addDirectory"); 1.66 + }, 1.67 + 1.68 + removeDirectory: function hunspell_addDirectory(dir) { 1.69 + this.dictionaryDirs.splice(this.dictionaryDirs.indexOf(dir), 1); 1.70 + if (this.listener) 1.71 + this.listener("removeDirectory"); 1.72 + }, 1.73 + 1.74 + getInterface: function hunspell_gi(iid) { 1.75 + if (iid.equals(Components.interfaces.mozISpellCheckingEngine)) 1.76 + return this; 1.77 + throw Components.results.NS_ERROR_NO_INTERFACE; 1.78 + }, 1.79 + 1.80 + contractID: "@mozilla.org/spellchecker/engine;1", 1.81 + classID: Components.ID("{6f3c63bc-a4fd-449b-9a58-a2d9bd972cce}"), 1.82 + 1.83 + activate: function hunspell_activate() { 1.84 + this.origClassID = Components.manager.nsIComponentRegistrar 1.85 + .contractIDToCID(this.contractID); 1.86 + this.origFactory = Components.manager 1.87 + .getClassObject(Components.classes[this.contractID], 1.88 + Components.interfaces.nsIFactory); 1.89 + 1.90 + Components.manager.nsIComponentRegistrar 1.91 + .unregisterFactory(this.origClassID, this.origFactory); 1.92 + Components.manager.nsIComponentRegistrar.registerFactory(this.classID, 1.93 + "Test hunspell", this.contractID, this); 1.94 + }, 1.95 + 1.96 + deactivate: function hunspell_deactivate() { 1.97 + Components.manager.nsIComponentRegistrar.unregisterFactory(this.classID, this); 1.98 + Components.manager.nsIComponentRegistrar.registerFactory(this.origClassID, 1.99 + "Hunspell", this.contractID, this.origFactory); 1.100 + }, 1.101 + 1.102 + isDictionaryEnabled: function hunspell_isDictionaryEnabled(name) { 1.103 + return this.dictionaryDirs.some(function(dir) { 1.104 + var dic = dir.clone(); 1.105 + dic.append(name); 1.106 + return dic.exists(); 1.107 + }); 1.108 + } 1.109 +}; 1.110 + 1.111 +function run_test() { 1.112 + do_test_pending(); 1.113 + 1.114 + startupManager(); 1.115 + 1.116 + run_test_1(); 1.117 +} 1.118 + 1.119 +// Tests that installing doesn't require a restart 1.120 +function run_test_1() { 1.121 + prepare_test({ }, [ 1.122 + "onNewInstall" 1.123 + ]); 1.124 + 1.125 + HunspellEngine.activate(); 1.126 + 1.127 + AddonManager.getInstallForFile(do_get_addon("test_dictionary"), function(install) { 1.128 + ensure_test_completed(); 1.129 + 1.130 + do_check_neq(install, null); 1.131 + do_check_eq(install.type, "dictionary"); 1.132 + do_check_eq(install.version, "1.0"); 1.133 + do_check_eq(install.name, "Test Dictionary"); 1.134 + do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); 1.135 + do_check_true(install.addon.hasResource("install.rdf")); 1.136 + do_check_false(install.addon.hasResource("bootstrap.js")); 1.137 + do_check_eq(install.addon.operationsRequiringRestart & 1.138 + AddonManager.OP_NEEDS_RESTART_INSTALL, 0); 1.139 + do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); 1.140 + 1.141 + let addon = install.addon; 1.142 + prepare_test({ 1.143 + "ab-CD@dictionaries.addons.mozilla.org": [ 1.144 + ["onInstalling", false], 1.145 + "onInstalled" 1.146 + ] 1.147 + }, [ 1.148 + "onInstallStarted", 1.149 + "onInstallEnded", 1.150 + ], function() { 1.151 + do_check_true(addon.hasResource("install.rdf")); 1.152 + HunspellEngine.listener = function(aEvent) { 1.153 + HunspellEngine.listener = null; 1.154 + do_check_eq(aEvent, "addDirectory"); 1.155 + do_execute_soon(check_test_1); 1.156 + }; 1.157 + }); 1.158 + install.install(); 1.159 + }); 1.160 +} 1.161 + 1.162 +function check_test_1() { 1.163 + AddonManager.getAllInstalls(function(installs) { 1.164 + // There should be no active installs now since the install completed and 1.165 + // doesn't require a restart. 1.166 + do_check_eq(installs.length, 0); 1.167 + 1.168 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { 1.169 + do_check_neq(b1, null); 1.170 + do_check_eq(b1.version, "1.0"); 1.171 + do_check_false(b1.appDisabled); 1.172 + do_check_false(b1.userDisabled); 1.173 + do_check_true(b1.isActive); 1.174 + do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.175 + do_check_true(b1.hasResource("install.rdf")); 1.176 + do_check_false(b1.hasResource("bootstrap.js")); 1.177 + do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); 1.178 + 1.179 + let dir = do_get_addon_root_uri(profileDir, "ab-CD@dictionaries.addons.mozilla.org"); 1.180 + 1.181 + AddonManager.getAddonsWithOperationsByTypes(null, function(list) { 1.182 + do_check_eq(list.length, 0); 1.183 + 1.184 + run_test_2(); 1.185 + }); 1.186 + }); 1.187 + }); 1.188 +} 1.189 + 1.190 +// Tests that disabling doesn't require a restart 1.191 +function run_test_2() { 1.192 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { 1.193 + prepare_test({ 1.194 + "ab-CD@dictionaries.addons.mozilla.org": [ 1.195 + ["onDisabling", false], 1.196 + "onDisabled" 1.197 + ] 1.198 + }); 1.199 + 1.200 + do_check_eq(b1.operationsRequiringRestart & 1.201 + AddonManager.OP_NEEDS_RESTART_DISABLE, 0); 1.202 + b1.userDisabled = true; 1.203 + ensure_test_completed(); 1.204 + 1.205 + do_check_neq(b1, null); 1.206 + do_check_eq(b1.version, "1.0"); 1.207 + do_check_false(b1.appDisabled); 1.208 + do_check_true(b1.userDisabled); 1.209 + do_check_false(b1.isActive); 1.210 + do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.211 + do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); 1.212 + 1.213 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(newb1) { 1.214 + do_check_neq(newb1, null); 1.215 + do_check_eq(newb1.version, "1.0"); 1.216 + do_check_false(newb1.appDisabled); 1.217 + do_check_true(newb1.userDisabled); 1.218 + do_check_false(newb1.isActive); 1.219 + 1.220 + do_execute_soon(run_test_3); 1.221 + }); 1.222 + }); 1.223 +} 1.224 + 1.225 +// Test that restarting doesn't accidentally re-enable 1.226 +function run_test_3() { 1.227 + shutdownManager(); 1.228 + do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.229 + startupManager(false); 1.230 + do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.231 + do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); 1.232 + 1.233 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { 1.234 + do_check_neq(b1, null); 1.235 + do_check_eq(b1.version, "1.0"); 1.236 + do_check_false(b1.appDisabled); 1.237 + do_check_true(b1.userDisabled); 1.238 + do_check_false(b1.isActive); 1.239 + 1.240 + run_test_4(); 1.241 + }); 1.242 +} 1.243 + 1.244 +// Tests that enabling doesn't require a restart 1.245 +function run_test_4() { 1.246 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { 1.247 + prepare_test({ 1.248 + "ab-CD@dictionaries.addons.mozilla.org": [ 1.249 + ["onEnabling", false], 1.250 + "onEnabled" 1.251 + ] 1.252 + }); 1.253 + 1.254 + do_check_eq(b1.operationsRequiringRestart & 1.255 + AddonManager.OP_NEEDS_RESTART_ENABLE, 0); 1.256 + b1.userDisabled = false; 1.257 + ensure_test_completed(); 1.258 + 1.259 + do_check_neq(b1, null); 1.260 + do_check_eq(b1.version, "1.0"); 1.261 + do_check_false(b1.appDisabled); 1.262 + do_check_false(b1.userDisabled); 1.263 + do_check_true(b1.isActive); 1.264 + do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.265 + do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); 1.266 + 1.267 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(newb1) { 1.268 + do_check_neq(newb1, null); 1.269 + do_check_eq(newb1.version, "1.0"); 1.270 + do_check_false(newb1.appDisabled); 1.271 + do_check_false(newb1.userDisabled); 1.272 + do_check_true(newb1.isActive); 1.273 + 1.274 + do_execute_soon(run_test_5); 1.275 + }); 1.276 + }); 1.277 +} 1.278 + 1.279 +// Tests that a restart shuts down and restarts the add-on 1.280 +function run_test_5() { 1.281 + shutdownManager(); 1.282 + do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.283 + do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); 1.284 + startupManager(false); 1.285 + do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.286 + do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); 1.287 + 1.288 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { 1.289 + do_check_neq(b1, null); 1.290 + do_check_eq(b1.version, "1.0"); 1.291 + do_check_false(b1.appDisabled); 1.292 + do_check_false(b1.userDisabled); 1.293 + do_check_true(b1.isActive); 1.294 + do_check_false(isExtensionInAddonsList(profileDir, b1.id)); 1.295 + 1.296 + run_test_7(); 1.297 + }); 1.298 +} 1.299 + 1.300 +// Tests that uninstalling doesn't require a restart 1.301 +function run_test_7() { 1.302 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { 1.303 + prepare_test({ 1.304 + "ab-CD@dictionaries.addons.mozilla.org": [ 1.305 + ["onUninstalling", false], 1.306 + "onUninstalled" 1.307 + ] 1.308 + }); 1.309 + 1.310 + do_check_eq(b1.operationsRequiringRestart & 1.311 + AddonManager.OP_NEEDS_RESTART_UNINSTALL, 0); 1.312 + b1.uninstall(); 1.313 + 1.314 + check_test_7(); 1.315 + }); 1.316 +} 1.317 + 1.318 +function check_test_7() { 1.319 + ensure_test_completed(); 1.320 + do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.321 + do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); 1.322 + 1.323 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", 1.324 + callback_soon(function(b1) { 1.325 + do_check_eq(b1, null); 1.326 + 1.327 + restartManager(); 1.328 + 1.329 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(newb1) { 1.330 + do_check_eq(newb1, null); 1.331 + 1.332 + do_execute_soon(run_test_8); 1.333 + }); 1.334 + })); 1.335 +} 1.336 + 1.337 +// Test that a bootstrapped extension dropped into the profile loads properly 1.338 +// on startup and doesn't cause an EM restart 1.339 +function run_test_8() { 1.340 + shutdownManager(); 1.341 + 1.342 + let dir = profileDir.clone(); 1.343 + dir.append("ab-CD@dictionaries.addons.mozilla.org"); 1.344 + dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); 1.345 + let zip = AM_Cc["@mozilla.org/libjar/zip-reader;1"]. 1.346 + createInstance(AM_Ci.nsIZipReader); 1.347 + zip.open(do_get_addon("test_dictionary")); 1.348 + dir.append("install.rdf"); 1.349 + zip.extract("install.rdf", dir); 1.350 + dir = dir.parent; 1.351 + dir.append("dictionaries"); 1.352 + dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); 1.353 + dir.append("ab-CD.dic"); 1.354 + zip.extract("dictionaries/ab-CD.dic", dir); 1.355 + zip.close(); 1.356 + 1.357 + startupManager(false); 1.358 + 1.359 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { 1.360 + do_check_neq(b1, null); 1.361 + do_check_eq(b1.version, "1.0"); 1.362 + do_check_false(b1.appDisabled); 1.363 + do_check_false(b1.userDisabled); 1.364 + do_check_true(b1.isActive); 1.365 + do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.366 + do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); 1.367 + 1.368 + do_execute_soon(run_test_9); 1.369 + }); 1.370 +} 1.371 + 1.372 +// Test that items detected as removed during startup get removed properly 1.373 +function run_test_9() { 1.374 + shutdownManager(); 1.375 + 1.376 + let dir = profileDir.clone(); 1.377 + dir.append("ab-CD@dictionaries.addons.mozilla.org"); 1.378 + dir.remove(true); 1.379 + startupManager(false); 1.380 + 1.381 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { 1.382 + do_check_eq(b1, null); 1.383 + do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); 1.384 + 1.385 + do_execute_soon(run_test_12); 1.386 + }); 1.387 +} 1.388 + 1.389 + 1.390 +// Tests that bootstrapped extensions are correctly loaded even if the app is 1.391 +// upgraded at the same time 1.392 +function run_test_12() { 1.393 + shutdownManager(); 1.394 + 1.395 + let dir = profileDir.clone(); 1.396 + dir.append("ab-CD@dictionaries.addons.mozilla.org"); 1.397 + dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); 1.398 + let zip = AM_Cc["@mozilla.org/libjar/zip-reader;1"]. 1.399 + createInstance(AM_Ci.nsIZipReader); 1.400 + zip.open(do_get_addon("test_dictionary")); 1.401 + dir.append("install.rdf"); 1.402 + zip.extract("install.rdf", dir); 1.403 + dir = dir.parent; 1.404 + dir.append("dictionaries"); 1.405 + dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); 1.406 + dir.append("ab-CD.dic"); 1.407 + zip.extract("dictionaries/ab-CD.dic", dir); 1.408 + zip.close(); 1.409 + 1.410 + startupManager(true); 1.411 + 1.412 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { 1.413 + do_check_neq(b1, null); 1.414 + do_check_eq(b1.version, "1.0"); 1.415 + do_check_false(b1.appDisabled); 1.416 + do_check_false(b1.userDisabled); 1.417 + do_check_true(b1.isActive); 1.418 + do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.419 + do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); 1.420 + 1.421 + b1.uninstall(); 1.422 + do_execute_soon(run_test_16); 1.423 + }); 1.424 +} 1.425 + 1.426 + 1.427 +// Tests that bootstrapped extensions don't get loaded when in safe mode 1.428 +function run_test_16() { 1.429 + restartManager(); 1.430 + 1.431 + installAllFiles([do_get_addon("test_dictionary")], function() { 1.432 + // spin the event loop to let the addon finish starting 1.433 + do_execute_soon(function check_installed_dictionary() { 1.434 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", 1.435 + callback_soon(function(b1) { 1.436 + // Should have installed and started 1.437 + do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.438 + 1.439 + shutdownManager(); 1.440 + 1.441 + // Should have stopped 1.442 + do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.443 + 1.444 + gAppInfo.inSafeMode = true; 1.445 + startupManager(false); 1.446 + 1.447 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", 1.448 + callback_soon(function(b1) { 1.449 + // Should still be stopped 1.450 + do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.451 + do_check_false(b1.isActive); 1.452 + 1.453 + shutdownManager(); 1.454 + gAppInfo.inSafeMode = false; 1.455 + startupManager(false); 1.456 + 1.457 + // Should have started 1.458 + do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.459 + 1.460 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { 1.461 + b1.uninstall(); 1.462 + 1.463 + do_execute_soon(run_test_17); 1.464 + }); 1.465 + })); 1.466 + })); 1.467 + }); 1.468 + }); 1.469 +} 1.470 + 1.471 +// Check that a bootstrapped extension in a non-profile location is loaded 1.472 +function run_test_17() { 1.473 + shutdownManager(); 1.474 + 1.475 + let dir = userExtDir.clone(); 1.476 + dir.append("ab-CD@dictionaries.addons.mozilla.org"); 1.477 + dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); 1.478 + let zip = AM_Cc["@mozilla.org/libjar/zip-reader;1"]. 1.479 + createInstance(AM_Ci.nsIZipReader); 1.480 + zip.open(do_get_addon("test_dictionary")); 1.481 + dir.append("install.rdf"); 1.482 + zip.extract("install.rdf", dir); 1.483 + dir = dir.parent; 1.484 + dir.append("dictionaries"); 1.485 + dir.create(AM_Ci.nsIFile.DIRECTORY_TYPE, 0755); 1.486 + dir.append("ab-CD.dic"); 1.487 + zip.extract("dictionaries/ab-CD.dic", dir); 1.488 + zip.close(); 1.489 + 1.490 + startupManager(); 1.491 + 1.492 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", 1.493 + callback_soon(function(b1) { 1.494 + // Should have installed and started 1.495 + do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.496 + do_check_neq(b1, null); 1.497 + do_check_eq(b1.version, "1.0"); 1.498 + do_check_true(b1.isActive); 1.499 + 1.500 + // From run_test_21 1.501 + dir = userExtDir.clone(); 1.502 + dir.append("ab-CD@dictionaries.addons.mozilla.org"); 1.503 + dir.remove(true); 1.504 + 1.505 + restartManager(); 1.506 + 1.507 + run_test_23(); 1.508 + })); 1.509 +} 1.510 + 1.511 +// Tests that installing from a URL doesn't require a restart 1.512 +function run_test_23() { 1.513 + prepare_test({ }, [ 1.514 + "onNewInstall" 1.515 + ]); 1.516 + 1.517 + let url = "http://localhost:" + gPort + "/addons/test_dictionary.xpi"; 1.518 + AddonManager.getInstallForURL(url, function(install) { 1.519 + ensure_test_completed(); 1.520 + 1.521 + do_check_neq(install, null); 1.522 + 1.523 + prepare_test({ }, [ 1.524 + "onDownloadStarted", 1.525 + "onDownloadEnded" 1.526 + ], function() { 1.527 + do_check_eq(install.type, "dictionary"); 1.528 + do_check_eq(install.version, "1.0"); 1.529 + do_check_eq(install.name, "Test Dictionary"); 1.530 + do_check_eq(install.state, AddonManager.STATE_DOWNLOADED); 1.531 + do_check_true(install.addon.hasResource("install.rdf")); 1.532 + do_check_false(install.addon.hasResource("bootstrap.js")); 1.533 + do_check_eq(install.addon.operationsRequiringRestart & 1.534 + AddonManager.OP_NEEDS_RESTART_INSTALL, 0); 1.535 + do_check_not_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); 1.536 + 1.537 + let addon = install.addon; 1.538 + prepare_test({ 1.539 + "ab-CD@dictionaries.addons.mozilla.org": [ 1.540 + ["onInstalling", false], 1.541 + "onInstalled" 1.542 + ] 1.543 + }, [ 1.544 + "onInstallStarted", 1.545 + "onInstallEnded", 1.546 + ], function() { 1.547 + do_check_true(addon.hasResource("install.rdf")); 1.548 + // spin to let the addon startup finish 1.549 + do_execute_soon(check_test_23); 1.550 + }); 1.551 + }); 1.552 + install.install(); 1.553 + }, "application/x-xpinstall"); 1.554 +} 1.555 + 1.556 +function check_test_23() { 1.557 + AddonManager.getAllInstalls(function(installs) { 1.558 + // There should be no active installs now since the install completed and 1.559 + // doesn't require a restart. 1.560 + do_check_eq(installs.length, 0); 1.561 + 1.562 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { 1.563 + do_check_neq(b1, null); 1.564 + do_check_eq(b1.version, "1.0"); 1.565 + do_check_false(b1.appDisabled); 1.566 + do_check_false(b1.userDisabled); 1.567 + do_check_true(b1.isActive); 1.568 + do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.569 + do_check_true(b1.hasResource("install.rdf")); 1.570 + do_check_false(b1.hasResource("bootstrap.js")); 1.571 + do_check_in_crash_annotation("ab-CD@dictionaries.addons.mozilla.org", "1.0"); 1.572 + 1.573 + let dir = do_get_addon_root_uri(profileDir, "ab-CD@dictionaries.addons.mozilla.org"); 1.574 + 1.575 + AddonManager.getAddonsWithOperationsByTypes(null, callback_soon(function(list) { 1.576 + do_check_eq(list.length, 0); 1.577 + 1.578 + restartManager(); 1.579 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { 1.580 + b1.uninstall(); 1.581 + do_execute_soon(run_test_25); 1.582 + }); 1.583 + })); 1.584 + }); 1.585 + }); 1.586 +} 1.587 + 1.588 +// Tests that updating from a bootstrappable add-on to a normal add-on calls 1.589 +// the uninstall method 1.590 +function run_test_25() { 1.591 + restartManager(); 1.592 + 1.593 + HunspellEngine.listener = function(aEvent) { 1.594 + HunspellEngine.listener = null; 1.595 + do_check_eq(aEvent, "addDirectory"); 1.596 + do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.597 + 1.598 + installAllFiles([do_get_addon("test_dictionary_2")], function test_25_installed2() { 1.599 + // Needs a restart to complete this so the old version stays running 1.600 + do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.601 + 1.602 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", 1.603 + callback_soon(function(b1) { 1.604 + do_check_neq(b1, null); 1.605 + do_check_eq(b1.version, "1.0"); 1.606 + do_check_true(b1.isActive); 1.607 + do_check_true(hasFlag(b1.pendingOperations, AddonManager.PENDING_UPGRADE)); 1.608 + 1.609 + restartManager(); 1.610 + 1.611 + do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.612 + 1.613 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { 1.614 + do_check_neq(b1, null); 1.615 + do_check_eq(b1.version, "2.0"); 1.616 + do_check_true(b1.isActive); 1.617 + do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE); 1.618 + 1.619 + do_execute_soon(run_test_26); 1.620 + }); 1.621 + })); 1.622 + }); 1.623 + }; 1.624 + 1.625 + installAllFiles([do_get_addon("test_dictionary")], function test_25_installed() { }); 1.626 +} 1.627 + 1.628 +// Tests that updating from a normal add-on to a bootstrappable add-on calls 1.629 +// the install method 1.630 +function run_test_26() { 1.631 + installAllFiles([do_get_addon("test_dictionary")], function test_26_install() { 1.632 + // Needs a restart to complete this 1.633 + do_check_false(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.634 + 1.635 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", 1.636 + callback_soon(function(b1) { 1.637 + do_check_neq(b1, null); 1.638 + do_check_eq(b1.version, "2.0"); 1.639 + do_check_true(b1.isActive); 1.640 + do_check_true(hasFlag(b1.pendingOperations, AddonManager.PENDING_UPGRADE)); 1.641 + 1.642 + restartManager(); 1.643 + 1.644 + do_check_true(HunspellEngine.isDictionaryEnabled("ab-CD.dic")); 1.645 + 1.646 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { 1.647 + do_check_neq(b1, null); 1.648 + do_check_eq(b1.version, "1.0"); 1.649 + do_check_true(b1.isActive); 1.650 + do_check_eq(b1.pendingOperations, AddonManager.PENDING_NONE); 1.651 + 1.652 + HunspellEngine.deactivate(); 1.653 + b1.uninstall(); 1.654 + do_execute_soon(run_test_27); 1.655 + }); 1.656 + })); 1.657 + }); 1.658 +} 1.659 + 1.660 +// Tests that an update check from a normal add-on to a bootstrappable add-on works 1.661 +function run_test_27() { 1.662 + restartManager(); 1.663 + writeInstallRDFForExtension({ 1.664 + id: "ab-CD@dictionaries.addons.mozilla.org", 1.665 + version: "1.0", 1.666 + updateURL: "http://localhost:" + gPort + "/data/test_dictionary.rdf", 1.667 + targetApplications: [{ 1.668 + id: "xpcshell@tests.mozilla.org", 1.669 + minVersion: "1", 1.670 + maxVersion: "1" 1.671 + }], 1.672 + name: "Test Dictionary", 1.673 + }, profileDir); 1.674 + restartManager(); 1.675 + 1.676 + prepare_test({ 1.677 + "ab-CD@dictionaries.addons.mozilla.org": [ 1.678 + "onInstalling" 1.679 + ] 1.680 + }, [ 1.681 + "onNewInstall", 1.682 + "onDownloadStarted", 1.683 + "onDownloadEnded", 1.684 + "onInstallStarted", 1.685 + "onInstallEnded" 1.686 + ], callback_soon(check_test_27)); 1.687 + 1.688 + AddonManagerPrivate.backgroundUpdateCheck(); 1.689 +} 1.690 + 1.691 +function check_test_27(install) { 1.692 + do_check_eq(install.existingAddon.pendingUpgrade.install, install); 1.693 + 1.694 + restartManager(); 1.695 + AddonManager.getAddonByID("ab-CD@dictionaries.addons.mozilla.org", function(b1) { 1.696 + do_check_neq(b1, null); 1.697 + do_check_eq(b1.version, "2.0"); 1.698 + do_check_eq(b1.type, "dictionary"); 1.699 + b1.uninstall(); 1.700 + do_execute_soon(run_test_28); 1.701 + }); 1.702 +} 1.703 + 1.704 +// Tests that an update check from a bootstrappable add-on to a normal add-on works 1.705 +function run_test_28() { 1.706 + restartManager(); 1.707 + 1.708 + writeInstallRDFForExtension({ 1.709 + id: "ef@dictionaries.addons.mozilla.org", 1.710 + version: "1.0", 1.711 + type: "64", 1.712 + updateURL: "http://localhost:" + gPort + "/data/test_dictionary.rdf", 1.713 + targetApplications: [{ 1.714 + id: "xpcshell@tests.mozilla.org", 1.715 + minVersion: "1", 1.716 + maxVersion: "1" 1.717 + }], 1.718 + name: "Test Dictionary ef", 1.719 + }, profileDir); 1.720 + restartManager(); 1.721 + 1.722 + prepare_test({ 1.723 + "ef@dictionaries.addons.mozilla.org": [ 1.724 + "onInstalling" 1.725 + ] 1.726 + }, [ 1.727 + "onNewInstall", 1.728 + "onDownloadStarted", 1.729 + "onDownloadEnded", 1.730 + "onInstallStarted", 1.731 + "onInstallEnded" 1.732 + ], callback_soon(check_test_28)); 1.733 + 1.734 + AddonManagerPrivate.backgroundUpdateCheck(); 1.735 +} 1.736 + 1.737 +function check_test_28(install) { 1.738 + do_check_eq(install.existingAddon.pendingUpgrade.install, install); 1.739 + 1.740 + restartManager(); 1.741 + AddonManager.getAddonByID("ef@dictionaries.addons.mozilla.org", function(b2) { 1.742 + do_check_neq(b2, null); 1.743 + do_check_eq(b2.version, "2.0"); 1.744 + do_check_eq(b2.type, "extension"); 1.745 + b2.uninstall(); 1.746 + do_execute_soon(run_test_29); 1.747 + }); 1.748 +} 1.749 + 1.750 +// Tests that an update check from a bootstrappable add-on to a bootstrappable add-on works 1.751 +function run_test_29() { 1.752 + restartManager(); 1.753 + 1.754 + writeInstallRDFForExtension({ 1.755 + id: "gh@dictionaries.addons.mozilla.org", 1.756 + version: "1.0", 1.757 + type: "64", 1.758 + updateURL: "http://localhost:" + gPort + "/data/test_dictionary.rdf", 1.759 + targetApplications: [{ 1.760 + id: "xpcshell@tests.mozilla.org", 1.761 + minVersion: "1", 1.762 + maxVersion: "1" 1.763 + }], 1.764 + name: "Test Dictionary gh", 1.765 + }, profileDir); 1.766 + restartManager(); 1.767 + 1.768 + prepare_test({ 1.769 + "gh@dictionaries.addons.mozilla.org": [ 1.770 + ["onInstalling", false /* = no restart */], 1.771 + ["onInstalled", false] 1.772 + ] 1.773 + }, [ 1.774 + "onNewInstall", 1.775 + "onDownloadStarted", 1.776 + "onDownloadEnded", 1.777 + "onInstallStarted", 1.778 + "onInstallEnded" 1.779 + ], check_test_29); 1.780 + 1.781 + AddonManagerPrivate.backgroundUpdateCheck(); 1.782 +} 1.783 + 1.784 +function check_test_29(install) { 1.785 + AddonManager.getAddonByID("gh@dictionaries.addons.mozilla.org", function(b2) { 1.786 + do_check_neq(b2, null); 1.787 + do_check_eq(b2.version, "2.0"); 1.788 + do_check_eq(b2.type, "dictionary"); 1.789 + 1.790 + prepare_test({ 1.791 + "gh@dictionaries.addons.mozilla.org": [ 1.792 + ["onUninstalling", false], 1.793 + ["onUninstalled", false], 1.794 + ] 1.795 + }, [ 1.796 + ], callback_soon(finish_test_29)); 1.797 + 1.798 + b2.uninstall(); 1.799 + }); 1.800 +} 1.801 + 1.802 +function finish_test_29() { 1.803 + testserver.stop(do_test_finished); 1.804 +}