1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug659772.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,340 @@ 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 +// Tests that a pending upgrade during a schema update doesn't break things 1.9 + 1.10 +var addon1 = { 1.11 + id: "addon1@tests.mozilla.org", 1.12 + version: "2.0", 1.13 + name: "Test 1", 1.14 + targetApplications: [{ 1.15 + id: "xpcshell@tests.mozilla.org", 1.16 + minVersion: "1", 1.17 + maxVersion: "1" 1.18 + }] 1.19 +}; 1.20 + 1.21 +var addon2 = { 1.22 + id: "addon2@tests.mozilla.org", 1.23 + version: "2.0", 1.24 + name: "Test 2", 1.25 + targetApplications: [{ 1.26 + id: "xpcshell@tests.mozilla.org", 1.27 + minVersion: "1", 1.28 + maxVersion: "2" 1.29 + }] 1.30 +}; 1.31 + 1.32 +var addon3 = { 1.33 + id: "addon3@tests.mozilla.org", 1.34 + version: "2.0", 1.35 + name: "Test 3", 1.36 + targetApplications: [{ 1.37 + id: "xpcshell@tests.mozilla.org", 1.38 + minVersion: "1", 1.39 + maxVersion: "1" 1.40 + }] 1.41 +}; 1.42 + 1.43 +var addon4 = { 1.44 + id: "addon4@tests.mozilla.org", 1.45 + version: "2.0", 1.46 + name: "Test 4", 1.47 + targetApplications: [{ 1.48 + id: "xpcshell@tests.mozilla.org", 1.49 + minVersion: "2", 1.50 + maxVersion: "2" 1.51 + }] 1.52 +}; 1.53 + 1.54 +const profileDir = gProfD.clone(); 1.55 +profileDir.append("extensions"); 1.56 + 1.57 +function run_test() { 1.58 + do_test_pending(); 1.59 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); 1.60 + 1.61 + run_test_1(); 1.62 +} 1.63 + 1.64 +// Tests whether a schema migration without app version change works 1.65 +function run_test_1() { 1.66 + writeInstallRDFForExtension(addon1, profileDir); 1.67 + writeInstallRDFForExtension(addon2, profileDir); 1.68 + writeInstallRDFForExtension(addon3, profileDir); 1.69 + writeInstallRDFForExtension(addon4, profileDir); 1.70 + 1.71 + startupManager(); 1.72 + 1.73 + AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", 1.74 + "addon2@tests.mozilla.org", 1.75 + "addon3@tests.mozilla.org", 1.76 + "addon4@tests.mozilla.org"], 1.77 + function([a1, a2, a3, a4]) { 1.78 + do_check_neq(a1, null); 1.79 + do_check_eq(a1.version, "2.0"); 1.80 + do_check_false(a1.appDisabled); 1.81 + do_check_false(a1.userDisabled); 1.82 + do_check_true(a1.isActive); 1.83 + do_check_true(isExtensionInAddonsList(profileDir, addon1.id)); 1.84 + 1.85 + do_check_neq(a2, null); 1.86 + do_check_eq(a2.version, "2.0"); 1.87 + do_check_false(a2.appDisabled); 1.88 + do_check_false(a2.userDisabled); 1.89 + do_check_true(a2.isActive); 1.90 + do_check_true(isExtensionInAddonsList(profileDir, addon2.id)); 1.91 + 1.92 + do_check_neq(a3, null); 1.93 + do_check_eq(a3.version, "2.0"); 1.94 + do_check_false(a3.appDisabled); 1.95 + do_check_false(a3.userDisabled); 1.96 + do_check_true(a3.isActive); 1.97 + do_check_true(isExtensionInAddonsList(profileDir, addon3.id)); 1.98 + 1.99 + do_check_neq(a4, null); 1.100 + do_check_eq(a4.version, "2.0"); 1.101 + do_check_true(a4.appDisabled); 1.102 + do_check_false(a4.userDisabled); 1.103 + do_check_false(a4.isActive); 1.104 + do_check_false(isExtensionInAddonsList(profileDir, addon4.id)); 1.105 + 1.106 + // Prepare the add-on update, and a bootstrapped addon (bug 693714) 1.107 + installAllFiles([ 1.108 + do_get_addon("test_bug659772"), 1.109 + do_get_addon("test_bootstrap1_1") 1.110 + ], function() { 1.111 + shutdownManager(); 1.112 + 1.113 + // Make it look like the next time the app is started it has a new DB schema 1.114 + changeXPIDBVersion(1); 1.115 + Services.prefs.setIntPref("extensions.databaseSchema", 1); 1.116 + 1.117 + let jsonfile = gProfD.clone(); 1.118 + jsonfile.append("extensions"); 1.119 + jsonfile.append("staged"); 1.120 + jsonfile.append("addon3@tests.mozilla.org.json"); 1.121 + do_check_true(jsonfile.exists()); 1.122 + 1.123 + // Remove an unnecessary property from the cached manifest 1.124 + let fis = AM_Cc["@mozilla.org/network/file-input-stream;1"]. 1.125 + createInstance(AM_Ci.nsIFileInputStream); 1.126 + let json = AM_Cc["@mozilla.org/dom/json;1"]. 1.127 + createInstance(AM_Ci.nsIJSON); 1.128 + fis.init(jsonfile, -1, 0, 0); 1.129 + let addonObj = json.decodeFromStream(fis, jsonfile.fileSize); 1.130 + fis.close(); 1.131 + delete addonObj.optionsType; 1.132 + 1.133 + let stream = AM_Cc["@mozilla.org/network/file-output-stream;1"]. 1.134 + createInstance(AM_Ci.nsIFileOutputStream); 1.135 + let converter = AM_Cc["@mozilla.org/intl/converter-output-stream;1"]. 1.136 + createInstance(AM_Ci.nsIConverterOutputStream); 1.137 + stream.init(jsonfile, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | 1.138 + FileUtils.MODE_TRUNCATE, FileUtils.PERMS_FILE, 1.139 + 0); 1.140 + converter.init(stream, "UTF-8", 0, 0x0000); 1.141 + converter.writeString(JSON.stringify(addonObj)); 1.142 + converter.close(); 1.143 + stream.close(); 1.144 + 1.145 + Services.prefs.clearUserPref("bootstraptest.install_reason"); 1.146 + Services.prefs.clearUserPref("bootstraptest.uninstall_reason"); 1.147 + 1.148 + startupManager(false); 1.149 + 1.150 + AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", 1.151 + "addon2@tests.mozilla.org", 1.152 + "addon3@tests.mozilla.org", 1.153 + "addon4@tests.mozilla.org"], 1.154 + function([a1, a2, a3, a4]) { 1.155 + do_check_neq(a1, null); 1.156 + do_check_eq(a1.version, "2.0"); 1.157 + do_check_false(a1.appDisabled); 1.158 + do_check_false(a1.userDisabled); 1.159 + do_check_true(a1.isActive); 1.160 + do_check_true(isExtensionInAddonsList(profileDir, addon1.id)); 1.161 + 1.162 + do_check_neq(a2, null); 1.163 + do_check_eq(a2.version, "2.0"); 1.164 + do_check_false(a2.appDisabled); 1.165 + do_check_false(a2.userDisabled); 1.166 + do_check_true(a2.isActive); 1.167 + do_check_true(isExtensionInAddonsList(profileDir, addon2.id)); 1.168 + 1.169 + // Should stay enabled because we migrate the compat info from 1.170 + // the previous version of the DB 1.171 + do_check_neq(a3, null); 1.172 + do_check_eq(a3.version, "2.0"); 1.173 + todo_check_false(a3.appDisabled); // XXX unresolved issue 1.174 + do_check_false(a3.userDisabled); 1.175 + todo_check_true(a3.isActive); // XXX same 1.176 + todo_check_true(isExtensionInAddonsList(profileDir, addon3.id)); // XXX same 1.177 + 1.178 + do_check_neq(a4, null); 1.179 + do_check_eq(a4.version, "2.0"); 1.180 + do_check_true(a4.appDisabled); 1.181 + do_check_false(a4.userDisabled); 1.182 + do_check_false(a4.isActive); 1.183 + do_check_false(isExtensionInAddonsList(profileDir, addon4.id)); 1.184 + 1.185 + // Check that install and uninstall haven't been called on the bootstrapped addon 1.186 + do_check_false(Services.prefs.prefHasUserValue("bootstraptest.install_reason")); 1.187 + do_check_false(Services.prefs.prefHasUserValue("bootstraptest.uninstall_reason")); 1.188 + 1.189 + a1.uninstall(); 1.190 + a2.uninstall(); 1.191 + a3.uninstall(); 1.192 + a4.uninstall(); 1.193 + do_execute_soon(run_test_2); 1.194 + }); 1.195 + }); 1.196 + }); 1.197 +} 1.198 + 1.199 +// Tests whether a schema migration with app version change works 1.200 +function run_test_2() { 1.201 + restartManager(); 1.202 + 1.203 + shutdownManager(); 1.204 + 1.205 + writeInstallRDFForExtension(addon1, profileDir); 1.206 + writeInstallRDFForExtension(addon2, profileDir); 1.207 + writeInstallRDFForExtension(addon3, profileDir); 1.208 + writeInstallRDFForExtension(addon4, profileDir); 1.209 + 1.210 + startupManager(); 1.211 + 1.212 + AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", 1.213 + "addon2@tests.mozilla.org", 1.214 + "addon3@tests.mozilla.org", 1.215 + "addon4@tests.mozilla.org"], 1.216 + function([a1, a2, a3, a4]) { 1.217 + do_check_neq(a1, null); 1.218 + do_check_eq(a1.version, "2.0"); 1.219 + do_check_false(a1.appDisabled); 1.220 + do_check_false(a1.userDisabled); 1.221 + do_check_true(a1.isActive); 1.222 + do_check_true(isExtensionInAddonsList(profileDir, addon1.id)); 1.223 + 1.224 + do_check_neq(a2, null); 1.225 + do_check_eq(a2.version, "2.0"); 1.226 + do_check_false(a2.appDisabled); 1.227 + do_check_false(a2.userDisabled); 1.228 + do_check_true(a2.isActive); 1.229 + do_check_true(isExtensionInAddonsList(profileDir, addon2.id)); 1.230 + 1.231 + do_check_neq(a3, null); 1.232 + do_check_eq(a3.version, "2.0"); 1.233 + do_check_false(a3.appDisabled); 1.234 + do_check_false(a3.userDisabled); 1.235 + do_check_true(a3.isActive); 1.236 + do_check_true(isExtensionInAddonsList(profileDir, addon3.id)); 1.237 + 1.238 + do_check_neq(a4, null); 1.239 + do_check_eq(a4.version, "2.0"); 1.240 + do_check_true(a4.appDisabled); 1.241 + do_check_false(a4.userDisabled); 1.242 + do_check_false(a4.isActive); 1.243 + do_check_false(isExtensionInAddonsList(profileDir, addon4.id)); 1.244 + 1.245 + // Prepare the add-on update, and a bootstrapped addon (bug 693714) 1.246 + installAllFiles([ 1.247 + do_get_addon("test_bug659772"), 1.248 + do_get_addon("test_bootstrap1_1") 1.249 + ], function() { do_execute_soon(prepare_schema_migrate); }); 1.250 + 1.251 + function prepare_schema_migrate() { 1.252 + shutdownManager(); 1.253 + 1.254 + // Make it look like the next time the app is started it has a new DB schema 1.255 + changeXPIDBVersion(1); 1.256 + Services.prefs.setIntPref("extensions.databaseSchema", 1); 1.257 + 1.258 + let jsonfile = gProfD.clone(); 1.259 + jsonfile.append("extensions"); 1.260 + jsonfile.append("staged"); 1.261 + jsonfile.append("addon3@tests.mozilla.org.json"); 1.262 + do_check_true(jsonfile.exists()); 1.263 + 1.264 + // Remove an unnecessary property from the cached manifest 1.265 + let fis = AM_Cc["@mozilla.org/network/file-input-stream;1"]. 1.266 + createInstance(AM_Ci.nsIFileInputStream); 1.267 + let json = AM_Cc["@mozilla.org/dom/json;1"]. 1.268 + createInstance(AM_Ci.nsIJSON); 1.269 + fis.init(jsonfile, -1, 0, 0); 1.270 + let addonObj = json.decodeFromStream(fis, jsonfile.fileSize); 1.271 + fis.close(); 1.272 + delete addonObj.optionsType; 1.273 + 1.274 + let stream = AM_Cc["@mozilla.org/network/file-output-stream;1"]. 1.275 + createInstance(AM_Ci.nsIFileOutputStream); 1.276 + let converter = AM_Cc["@mozilla.org/intl/converter-output-stream;1"]. 1.277 + createInstance(AM_Ci.nsIConverterOutputStream); 1.278 + stream.init(jsonfile, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | 1.279 + FileUtils.MODE_TRUNCATE, FileUtils.PERMS_FILE, 1.280 + 0); 1.281 + converter.init(stream, "UTF-8", 0, 0x0000); 1.282 + converter.writeString(JSON.stringify(addonObj)); 1.283 + converter.close(); 1.284 + stream.close(); 1.285 + 1.286 + Services.prefs.clearUserPref("bootstraptest.install_reason"); 1.287 + Services.prefs.clearUserPref("bootstraptest.uninstall_reason"); 1.288 + 1.289 + gAppInfo.version = "2"; 1.290 + startupManager(true); 1.291 + 1.292 + AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", 1.293 + "addon2@tests.mozilla.org", 1.294 + "addon3@tests.mozilla.org", 1.295 + "addon4@tests.mozilla.org"], 1.296 + callback_soon(function([a1, a2, a3, a4]) { 1.297 + do_check_neq(a1, null); 1.298 + do_check_eq(a1.version, "2.0"); 1.299 + do_check_true(a1.appDisabled); 1.300 + do_check_false(a1.userDisabled); 1.301 + do_check_false(a1.isActive); 1.302 + do_check_false(isExtensionInAddonsList(profileDir, addon1.id)); 1.303 + 1.304 + do_check_neq(a2, null); 1.305 + do_check_eq(a2.version, "2.0"); 1.306 + do_check_false(a2.appDisabled); 1.307 + do_check_false(a2.userDisabled); 1.308 + do_check_true(a2.isActive); 1.309 + do_check_true(isExtensionInAddonsList(profileDir, addon2.id)); 1.310 + 1.311 + // Should become appDisabled because we migrate the compat info from 1.312 + // the previous version of the DB 1.313 + do_check_neq(a3, null); 1.314 + do_check_eq(a3.version, "2.0"); 1.315 + todo_check_true(a3.appDisabled); 1.316 + do_check_false(a3.userDisabled); 1.317 + todo_check_false(a3.isActive); 1.318 + todo_check_false(isExtensionInAddonsList(profileDir, addon3.id)); 1.319 + 1.320 + do_check_neq(a4, null); 1.321 + do_check_eq(a4.version, "2.0"); 1.322 + do_check_false(a4.appDisabled); 1.323 + do_check_false(a4.userDisabled); 1.324 + do_check_true(a4.isActive); 1.325 + do_check_true(isExtensionInAddonsList(profileDir, addon4.id)); 1.326 + 1.327 + // Check that install and uninstall haven't been called on the bootstrapped addon 1.328 + do_check_false(Services.prefs.prefHasUserValue("bootstraptest.install_reason")); 1.329 + do_check_false(Services.prefs.prefHasUserValue("bootstraptest.uninstall_reason")); 1.330 + 1.331 + a1.uninstall(); 1.332 + a2.uninstall(); 1.333 + a3.uninstall(); 1.334 + a4.uninstall(); 1.335 + restartManager(); 1.336 + 1.337 + shutdownManager(); 1.338 + 1.339 + do_test_finished(); 1.340 + })); 1.341 + }; 1.342 + }); 1.343 +}