michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Tests that a pending upgrade during a schema update doesn't break things michael@0: michael@0: var addon1 = { michael@0: id: "addon1@tests.mozilla.org", michael@0: version: "2.0", michael@0: name: "Test 1", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }] michael@0: }; michael@0: michael@0: var addon2 = { michael@0: id: "addon2@tests.mozilla.org", michael@0: version: "2.0", michael@0: name: "Test 2", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "2" michael@0: }] michael@0: }; michael@0: michael@0: var addon3 = { michael@0: id: "addon3@tests.mozilla.org", michael@0: version: "2.0", michael@0: name: "Test 3", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "1", michael@0: maxVersion: "1" michael@0: }] michael@0: }; michael@0: michael@0: var addon4 = { michael@0: id: "addon4@tests.mozilla.org", michael@0: version: "2.0", michael@0: name: "Test 4", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "2", michael@0: maxVersion: "2" michael@0: }] michael@0: }; michael@0: michael@0: const profileDir = gProfD.clone(); michael@0: profileDir.append("extensions"); michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); michael@0: michael@0: run_test_1(); michael@0: } michael@0: michael@0: // Tests whether a schema migration without app version change works michael@0: function run_test_1() { michael@0: writeInstallRDFForExtension(addon1, profileDir); michael@0: writeInstallRDFForExtension(addon2, profileDir); michael@0: writeInstallRDFForExtension(addon3, profileDir); michael@0: writeInstallRDFForExtension(addon4, profileDir); michael@0: michael@0: startupManager(); michael@0: michael@0: AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", michael@0: "addon2@tests.mozilla.org", michael@0: "addon3@tests.mozilla.org", michael@0: "addon4@tests.mozilla.org"], michael@0: function([a1, a2, a3, a4]) { michael@0: do_check_neq(a1, null); michael@0: do_check_eq(a1.version, "2.0"); michael@0: do_check_false(a1.appDisabled); michael@0: do_check_false(a1.userDisabled); michael@0: do_check_true(a1.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, addon1.id)); michael@0: michael@0: do_check_neq(a2, null); michael@0: do_check_eq(a2.version, "2.0"); michael@0: do_check_false(a2.appDisabled); michael@0: do_check_false(a2.userDisabled); michael@0: do_check_true(a2.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, addon2.id)); michael@0: michael@0: do_check_neq(a3, null); michael@0: do_check_eq(a3.version, "2.0"); michael@0: do_check_false(a3.appDisabled); michael@0: do_check_false(a3.userDisabled); michael@0: do_check_true(a3.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, addon3.id)); michael@0: michael@0: do_check_neq(a4, null); michael@0: do_check_eq(a4.version, "2.0"); michael@0: do_check_true(a4.appDisabled); michael@0: do_check_false(a4.userDisabled); michael@0: do_check_false(a4.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, addon4.id)); michael@0: michael@0: // Prepare the add-on update, and a bootstrapped addon (bug 693714) michael@0: installAllFiles([ michael@0: do_get_addon("test_bug659772"), michael@0: do_get_addon("test_bootstrap1_1") michael@0: ], function() { michael@0: shutdownManager(); michael@0: michael@0: // Make it look like the next time the app is started it has a new DB schema michael@0: changeXPIDBVersion(1); michael@0: Services.prefs.setIntPref("extensions.databaseSchema", 1); michael@0: michael@0: let jsonfile = gProfD.clone(); michael@0: jsonfile.append("extensions"); michael@0: jsonfile.append("staged"); michael@0: jsonfile.append("addon3@tests.mozilla.org.json"); michael@0: do_check_true(jsonfile.exists()); michael@0: michael@0: // Remove an unnecessary property from the cached manifest michael@0: let fis = AM_Cc["@mozilla.org/network/file-input-stream;1"]. michael@0: createInstance(AM_Ci.nsIFileInputStream); michael@0: let json = AM_Cc["@mozilla.org/dom/json;1"]. michael@0: createInstance(AM_Ci.nsIJSON); michael@0: fis.init(jsonfile, -1, 0, 0); michael@0: let addonObj = json.decodeFromStream(fis, jsonfile.fileSize); michael@0: fis.close(); michael@0: delete addonObj.optionsType; michael@0: michael@0: let stream = AM_Cc["@mozilla.org/network/file-output-stream;1"]. michael@0: createInstance(AM_Ci.nsIFileOutputStream); michael@0: let converter = AM_Cc["@mozilla.org/intl/converter-output-stream;1"]. michael@0: createInstance(AM_Ci.nsIConverterOutputStream); michael@0: stream.init(jsonfile, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | michael@0: FileUtils.MODE_TRUNCATE, FileUtils.PERMS_FILE, michael@0: 0); michael@0: converter.init(stream, "UTF-8", 0, 0x0000); michael@0: converter.writeString(JSON.stringify(addonObj)); michael@0: converter.close(); michael@0: stream.close(); michael@0: michael@0: Services.prefs.clearUserPref("bootstraptest.install_reason"); michael@0: Services.prefs.clearUserPref("bootstraptest.uninstall_reason"); michael@0: michael@0: startupManager(false); michael@0: michael@0: AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", michael@0: "addon2@tests.mozilla.org", michael@0: "addon3@tests.mozilla.org", michael@0: "addon4@tests.mozilla.org"], michael@0: function([a1, a2, a3, a4]) { michael@0: do_check_neq(a1, null); michael@0: do_check_eq(a1.version, "2.0"); michael@0: do_check_false(a1.appDisabled); michael@0: do_check_false(a1.userDisabled); michael@0: do_check_true(a1.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, addon1.id)); michael@0: michael@0: do_check_neq(a2, null); michael@0: do_check_eq(a2.version, "2.0"); michael@0: do_check_false(a2.appDisabled); michael@0: do_check_false(a2.userDisabled); michael@0: do_check_true(a2.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, addon2.id)); michael@0: michael@0: // Should stay enabled because we migrate the compat info from michael@0: // the previous version of the DB michael@0: do_check_neq(a3, null); michael@0: do_check_eq(a3.version, "2.0"); michael@0: todo_check_false(a3.appDisabled); // XXX unresolved issue michael@0: do_check_false(a3.userDisabled); michael@0: todo_check_true(a3.isActive); // XXX same michael@0: todo_check_true(isExtensionInAddonsList(profileDir, addon3.id)); // XXX same michael@0: michael@0: do_check_neq(a4, null); michael@0: do_check_eq(a4.version, "2.0"); michael@0: do_check_true(a4.appDisabled); michael@0: do_check_false(a4.userDisabled); michael@0: do_check_false(a4.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, addon4.id)); michael@0: michael@0: // Check that install and uninstall haven't been called on the bootstrapped addon michael@0: do_check_false(Services.prefs.prefHasUserValue("bootstraptest.install_reason")); michael@0: do_check_false(Services.prefs.prefHasUserValue("bootstraptest.uninstall_reason")); michael@0: michael@0: a1.uninstall(); michael@0: a2.uninstall(); michael@0: a3.uninstall(); michael@0: a4.uninstall(); michael@0: do_execute_soon(run_test_2); michael@0: }); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: // Tests whether a schema migration with app version change works michael@0: function run_test_2() { michael@0: restartManager(); michael@0: michael@0: shutdownManager(); michael@0: michael@0: writeInstallRDFForExtension(addon1, profileDir); michael@0: writeInstallRDFForExtension(addon2, profileDir); michael@0: writeInstallRDFForExtension(addon3, profileDir); michael@0: writeInstallRDFForExtension(addon4, profileDir); michael@0: michael@0: startupManager(); michael@0: michael@0: AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", michael@0: "addon2@tests.mozilla.org", michael@0: "addon3@tests.mozilla.org", michael@0: "addon4@tests.mozilla.org"], michael@0: function([a1, a2, a3, a4]) { michael@0: do_check_neq(a1, null); michael@0: do_check_eq(a1.version, "2.0"); michael@0: do_check_false(a1.appDisabled); michael@0: do_check_false(a1.userDisabled); michael@0: do_check_true(a1.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, addon1.id)); michael@0: michael@0: do_check_neq(a2, null); michael@0: do_check_eq(a2.version, "2.0"); michael@0: do_check_false(a2.appDisabled); michael@0: do_check_false(a2.userDisabled); michael@0: do_check_true(a2.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, addon2.id)); michael@0: michael@0: do_check_neq(a3, null); michael@0: do_check_eq(a3.version, "2.0"); michael@0: do_check_false(a3.appDisabled); michael@0: do_check_false(a3.userDisabled); michael@0: do_check_true(a3.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, addon3.id)); michael@0: michael@0: do_check_neq(a4, null); michael@0: do_check_eq(a4.version, "2.0"); michael@0: do_check_true(a4.appDisabled); michael@0: do_check_false(a4.userDisabled); michael@0: do_check_false(a4.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, addon4.id)); michael@0: michael@0: // Prepare the add-on update, and a bootstrapped addon (bug 693714) michael@0: installAllFiles([ michael@0: do_get_addon("test_bug659772"), michael@0: do_get_addon("test_bootstrap1_1") michael@0: ], function() { do_execute_soon(prepare_schema_migrate); }); michael@0: michael@0: function prepare_schema_migrate() { michael@0: shutdownManager(); michael@0: michael@0: // Make it look like the next time the app is started it has a new DB schema michael@0: changeXPIDBVersion(1); michael@0: Services.prefs.setIntPref("extensions.databaseSchema", 1); michael@0: michael@0: let jsonfile = gProfD.clone(); michael@0: jsonfile.append("extensions"); michael@0: jsonfile.append("staged"); michael@0: jsonfile.append("addon3@tests.mozilla.org.json"); michael@0: do_check_true(jsonfile.exists()); michael@0: michael@0: // Remove an unnecessary property from the cached manifest michael@0: let fis = AM_Cc["@mozilla.org/network/file-input-stream;1"]. michael@0: createInstance(AM_Ci.nsIFileInputStream); michael@0: let json = AM_Cc["@mozilla.org/dom/json;1"]. michael@0: createInstance(AM_Ci.nsIJSON); michael@0: fis.init(jsonfile, -1, 0, 0); michael@0: let addonObj = json.decodeFromStream(fis, jsonfile.fileSize); michael@0: fis.close(); michael@0: delete addonObj.optionsType; michael@0: michael@0: let stream = AM_Cc["@mozilla.org/network/file-output-stream;1"]. michael@0: createInstance(AM_Ci.nsIFileOutputStream); michael@0: let converter = AM_Cc["@mozilla.org/intl/converter-output-stream;1"]. michael@0: createInstance(AM_Ci.nsIConverterOutputStream); michael@0: stream.init(jsonfile, FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | michael@0: FileUtils.MODE_TRUNCATE, FileUtils.PERMS_FILE, michael@0: 0); michael@0: converter.init(stream, "UTF-8", 0, 0x0000); michael@0: converter.writeString(JSON.stringify(addonObj)); michael@0: converter.close(); michael@0: stream.close(); michael@0: michael@0: Services.prefs.clearUserPref("bootstraptest.install_reason"); michael@0: Services.prefs.clearUserPref("bootstraptest.uninstall_reason"); michael@0: michael@0: gAppInfo.version = "2"; michael@0: startupManager(true); michael@0: michael@0: AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", michael@0: "addon2@tests.mozilla.org", michael@0: "addon3@tests.mozilla.org", michael@0: "addon4@tests.mozilla.org"], michael@0: callback_soon(function([a1, a2, a3, a4]) { michael@0: do_check_neq(a1, null); michael@0: do_check_eq(a1.version, "2.0"); michael@0: do_check_true(a1.appDisabled); michael@0: do_check_false(a1.userDisabled); michael@0: do_check_false(a1.isActive); michael@0: do_check_false(isExtensionInAddonsList(profileDir, addon1.id)); michael@0: michael@0: do_check_neq(a2, null); michael@0: do_check_eq(a2.version, "2.0"); michael@0: do_check_false(a2.appDisabled); michael@0: do_check_false(a2.userDisabled); michael@0: do_check_true(a2.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, addon2.id)); michael@0: michael@0: // Should become appDisabled because we migrate the compat info from michael@0: // the previous version of the DB michael@0: do_check_neq(a3, null); michael@0: do_check_eq(a3.version, "2.0"); michael@0: todo_check_true(a3.appDisabled); michael@0: do_check_false(a3.userDisabled); michael@0: todo_check_false(a3.isActive); michael@0: todo_check_false(isExtensionInAddonsList(profileDir, addon3.id)); michael@0: michael@0: do_check_neq(a4, null); michael@0: do_check_eq(a4.version, "2.0"); michael@0: do_check_false(a4.appDisabled); michael@0: do_check_false(a4.userDisabled); michael@0: do_check_true(a4.isActive); michael@0: do_check_true(isExtensionInAddonsList(profileDir, addon4.id)); michael@0: michael@0: // Check that install and uninstall haven't been called on the bootstrapped addon michael@0: do_check_false(Services.prefs.prefHasUserValue("bootstraptest.install_reason")); michael@0: do_check_false(Services.prefs.prefHasUserValue("bootstraptest.uninstall_reason")); michael@0: michael@0: a1.uninstall(); michael@0: a2.uninstall(); michael@0: a3.uninstall(); michael@0: a4.uninstall(); michael@0: restartManager(); michael@0: michael@0: shutdownManager(); michael@0: michael@0: do_test_finished(); michael@0: })); michael@0: }; michael@0: }); michael@0: }