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: // Checks that we fail to migrate but still start up ok when there is a SQLITE database michael@0: // with no useful data in it. michael@0: michael@0: const PREF_GENERAL_SKINS_SELECTEDSKIN = "general.skins.selectedSkin"; michael@0: michael@0: var addon1 = { michael@0: id: "addon1@tests.mozilla.org", michael@0: version: "1.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 5", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "0", michael@0: maxVersion: "0" michael@0: }] michael@0: }; michael@0: michael@0: var defaultTheme = { michael@0: id: "default@tests.mozilla.org", michael@0: version: "2.0", michael@0: name: "Default theme", michael@0: internalName: "classic/1.0", 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 theme1 = { michael@0: id: "theme1@tests.mozilla.org", michael@0: version: "2.0", michael@0: name: "Test theme", michael@0: internalName: "theme1/1.0", 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: 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: writeInstallRDFForExtension(addon1, profileDir); michael@0: writeInstallRDFForExtension(addon2, profileDir); michael@0: writeInstallRDFForExtension(defaultTheme, profileDir); michael@0: writeInstallRDFForExtension(theme1, profileDir); michael@0: michael@0: Services.prefs.setCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN, "theme1/1.0"); michael@0: michael@0: // Write out a broken database (no userDisabled field) michael@0: let dbfile = gProfD.clone(); michael@0: dbfile.append("extensions.sqlite"); michael@0: let db = AM_Cc["@mozilla.org/storage/service;1"]. michael@0: getService(AM_Ci.mozIStorageService). michael@0: openDatabase(dbfile); michael@0: db.createTable("addon", "internal_id INTEGER PRIMARY KEY AUTOINCREMENT, " + michael@0: "id TEXT, location TEXT, version TEXT, active INTEGER, " + michael@0: "installDate INTEGER"); michael@0: db.createTable("targetApplication", "addon_internal_id INTEGER, " + michael@0: "id TEXT, minVersion TEXT, maxVersion TEXT"); michael@0: let stmt = db.createStatement("INSERT INTO addon VALUES (NULL, :id, :location, " + michael@0: ":version, :active, :installDate)"); michael@0: michael@0: let internal_ids = {}; michael@0: michael@0: [["addon1@tests.mozilla.org", "app-profile", "1.0", "1", "0"], michael@0: ["addon2@tests.mozilla.org", "app-profile", "2.0", "0", "0"], michael@0: ["default@tests.mozilla.org", "app-profile", "2.0", "1", "0"], michael@0: ["theme1@tests.mozilla.org", "app-profile", "2.0", "0", "0"]].forEach(function(a) { michael@0: stmt.params.id = a[0]; michael@0: stmt.params.location = a[1]; michael@0: stmt.params.version = a[2]; michael@0: stmt.params.active = a[3]; michael@0: stmt.params.installDate = a[4]; michael@0: stmt.execute(); michael@0: internal_ids[a[0]] = db.lastInsertRowID; michael@0: }); michael@0: stmt.finalize(); michael@0: michael@0: db.schemaVersion = 100; michael@0: Services.prefs.setIntPref("extensions.databaseSchema", 100); michael@0: db.close(); michael@0: michael@0: startupManager(); michael@0: check_startup_changes("installed", []); michael@0: check_startup_changes("updated", []); michael@0: check_startup_changes("uninstalled", []); michael@0: check_startup_changes("disabled", []); michael@0: check_startup_changes("enabled", []); michael@0: michael@0: AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", michael@0: "addon2@tests.mozilla.org", michael@0: "default@tests.mozilla.org", michael@0: "theme1@tests.mozilla.org"], michael@0: function([a1, a2, d, t1]) { michael@0: do_check_neq(a1, null); michael@0: do_check_false(a1.userDisabled); michael@0: do_check_false(a1.appDisabled); michael@0: do_check_true(a1.isActive); michael@0: michael@0: do_check_neq(a2, null); michael@0: do_check_false(a2.userDisabled); michael@0: do_check_true(a2.appDisabled); michael@0: do_check_false(a2.isActive); michael@0: michael@0: // Should have enabled the selected theme michael@0: do_check_neq(t1, null); michael@0: do_check_false(t1.userDisabled); michael@0: do_check_false(t1.appDisabled); michael@0: do_check_true(t1.isActive); michael@0: michael@0: do_check_neq(d, null); michael@0: do_check_true(d.userDisabled); michael@0: do_check_false(d.appDisabled); michael@0: do_check_false(d.isActive); michael@0: michael@0: do_execute_soon(do_test_finished); michael@0: }); michael@0: }