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 migrate data from SQLITE databases michael@0: // Note that since the database doesn't contain the foreignInstall field we michael@0: // should just assume that no add-ons in the user profile were foreignInstalls michael@0: michael@0: // Enable loading extensions from the user and system scopes michael@0: Services.prefs.setIntPref("extensions.enabledScopes", michael@0: AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_USER + michael@0: AddonManager.SCOPE_SYSTEM); 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 2", 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 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: strictCompatibility: true, 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 addon5 = { michael@0: id: "addon5@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 addon6 = { michael@0: id: "addon6@tests.mozilla.org", michael@0: version: "2.0", michael@0: name: "Test 6", 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 addon7 = { michael@0: id: "addon7@tests.mozilla.org", michael@0: version: "2.0", michael@0: name: "Test 7", 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 addon8 = { michael@0: id: "addon8@tests.mozilla.org", michael@0: version: "2.0", michael@0: name: "Test 8", 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: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); michael@0: const profileDir = gProfD.clone(); michael@0: profileDir.append("extensions"); michael@0: const globalDir = gProfD.clone(); michael@0: globalDir.append("extensions2"); michael@0: globalDir.append(gAppInfo.ID); michael@0: registerDirectory("XRESysSExtPD", globalDir.parent); michael@0: const userDir = gProfD.clone(); michael@0: userDir.append("extensions3"); michael@0: userDir.append(gAppInfo.ID); michael@0: registerDirectory("XREUSysExt", userDir.parent); michael@0: michael@0: function run_test() { michael@0: do_test_pending(); michael@0: michael@0: writeInstallRDFForExtension(addon1, profileDir); michael@0: writeInstallRDFForExtension(addon2, profileDir); michael@0: writeInstallRDFForExtension(addon3, profileDir); michael@0: writeInstallRDFForExtension(addon4, profileDir); michael@0: writeInstallRDFForExtension(addon5, profileDir); michael@0: writeInstallRDFForExtension(addon6, profileDir); michael@0: writeInstallRDFForExtension(addon7, globalDir); michael@0: writeInstallRDFForExtension(addon8, userDir); michael@0: michael@0: // Write out a minimal database 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: "userDisabled INTEGER, 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, :userDisabled, :installDate)"); michael@0: michael@0: let internal_ids = {}; michael@0: michael@0: [["addon1@tests.mozilla.org", "app-profile", "1.0", "1", "0", "0"], michael@0: ["addon2@tests.mozilla.org", "app-profile", "2.0", "0", "1", "0"], michael@0: ["addon3@tests.mozilla.org", "app-profile", "2.0", "1", "1", "0"], michael@0: ["addon4@tests.mozilla.org", "app-profile", "2.0", "0", "0", "0"], michael@0: ["addon5@tests.mozilla.org", "app-profile", "2.0", "1", "0", "0"], michael@0: ["addon6@tests.mozilla.org", "app-profile", "1.0", "0", "1", "0"], michael@0: ["addon7@tests.mozilla.org", "app-system-share", "1.0", "1", "0", "0"], michael@0: ["addon8@tests.mozilla.org", "app-system-user", "1.0", "1", "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.userDisabled = a[4]; michael@0: stmt.params.installDate = a[5]; michael@0: stmt.execute(); michael@0: internal_ids[a[0]] = db.lastInsertRowID; michael@0: }); michael@0: stmt.finalize(); michael@0: michael@0: // Add updated target application into for addon5 michael@0: stmt = db.createStatement("INSERT INTO targetApplication VALUES " + michael@0: "(:internal_id, :id, :minVersion, :maxVersion)"); michael@0: stmt.params.internal_id = internal_ids["addon5@tests.mozilla.org"]; michael@0: stmt.params.id = "xpcshell@tests.mozilla.org"; michael@0: stmt.params.minVersion = "0"; michael@0: stmt.params.maxVersion = "1"; michael@0: stmt.execute(); michael@0: michael@0: // Add updated target application into for addon6 michael@0: stmt.params.internal_id = internal_ids["addon6@tests.mozilla.org"]; michael@0: stmt.params.id = "xpcshell@tests.mozilla.org"; michael@0: stmt.params.minVersion = "0"; michael@0: stmt.params.maxVersion = "1"; michael@0: stmt.execute(); michael@0: stmt.finalize(); michael@0: michael@0: db.schemaVersion = 10000; michael@0: Services.prefs.setIntPref("extensions.databaseSchema", 14); 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: "addon3@tests.mozilla.org", michael@0: "addon4@tests.mozilla.org", michael@0: "addon5@tests.mozilla.org", michael@0: "addon6@tests.mozilla.org", michael@0: "addon7@tests.mozilla.org", michael@0: "addon8@tests.mozilla.org"], michael@0: function([a1, a2, a3, a4, a5, a6, a7, a8]) { michael@0: // addon1 was enabled in the database 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: do_check_false(a1.strictCompatibility); michael@0: do_check_false(a1.foreignInstall); michael@0: // addon2 was disabled in the database michael@0: do_check_neq(a2, null); michael@0: do_check_true(a2.userDisabled); michael@0: do_check_false(a2.appDisabled); michael@0: do_check_false(a2.isActive); michael@0: do_check_false(a2.strictCompatibility); michael@0: do_check_false(a2.foreignInstall); michael@0: // addon3 was pending-disable in the database michael@0: do_check_neq(a3, null); michael@0: do_check_true(a3.userDisabled); michael@0: do_check_false(a3.appDisabled); michael@0: do_check_false(a3.isActive); michael@0: do_check_false(a3.strictCompatibility); michael@0: do_check_false(a3.foreignInstall); michael@0: // addon4 was pending-enable in the database michael@0: do_check_neq(a4, null); michael@0: do_check_false(a4.userDisabled); michael@0: do_check_false(a4.appDisabled); michael@0: do_check_true(a4.isActive); michael@0: do_check_true(a4.strictCompatibility); michael@0: do_check_false(a4.foreignInstall); michael@0: // addon5 was enabled in the database but needed a compatibility update michael@0: do_check_neq(a5, null); michael@0: do_check_false(a5.userDisabled); michael@0: do_check_false(a5.appDisabled); michael@0: do_check_true(a5.isActive); michael@0: do_check_false(a5.strictCompatibility); michael@0: do_check_false(a5.foreignInstall); michael@0: // addon6 was disabled and compatible but a new version has been installed michael@0: // since, it should still be disabled but should be incompatible michael@0: do_check_neq(a6, null); michael@0: do_check_true(a6.userDisabled); michael@0: do_check_true(a6.appDisabled); michael@0: do_check_false(a6.isActive); michael@0: do_check_false(a6.strictCompatibility); michael@0: do_check_false(a6.foreignInstall); michael@0: // addon7 is in the global install location so should be a foreignInstall michael@0: do_check_neq(a7, null); michael@0: do_check_false(a7.userDisabled); michael@0: do_check_false(a7.appDisabled); michael@0: do_check_true(a7.isActive); michael@0: do_check_false(a7.strictCompatibility); michael@0: do_check_true(a7.foreignInstall); michael@0: // addon8 is in the user install location so should be a foreignInstall michael@0: do_check_neq(a8, null); michael@0: do_check_false(a8.userDisabled); michael@0: do_check_false(a8.appDisabled); michael@0: do_check_true(a8.isActive); michael@0: do_check_false(a8.strictCompatibility); michael@0: do_check_true(a8.foreignInstall); michael@0: michael@0: do_execute_soon(do_test_finished); michael@0: }); michael@0: }