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 don't migrate data from SQLITE if michael@0: // the "extensions.databaseSchema" preference shows we've michael@0: // already upgraded to JSON 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: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); michael@0: const profileDir = gProfD.clone(); michael@0: profileDir.append("extensions"); michael@0: michael@0: function run_test() { michael@0: writeInstallRDFForExtension(addon1, profileDir); 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: let a = ["addon1@tests.mozilla.org", "app-profile", "1.0", "0", "1", "0"]; 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: stmt.finalize(); michael@0: michael@0: db.schemaVersion = 14; michael@0: Services.prefs.setIntPref("extensions.databaseSchema", 14); michael@0: db.close(); michael@0: michael@0: startupManager(); michael@0: run_next_test(); michael@0: } michael@0: michael@0: add_test(function before_rebuild() { michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", michael@0: function check_before_rebuild (a1) { michael@0: // First check that it migrated OK once michael@0: // addon1 was disabled in the database michael@0: do_check_neq(a1, null); michael@0: do_check_true(a1.userDisabled); michael@0: do_check_false(a1.appDisabled); michael@0: do_check_false(a1.isActive); michael@0: do_check_false(a1.strictCompatibility); michael@0: do_check_false(a1.foreignInstall); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: michael@0: // now shut down, remove the JSON database, michael@0: // start up again, and make sure the data didn't migrate this time michael@0: add_test(function rebuild_again() { michael@0: shutdownManager(); michael@0: gExtensionsJSON.remove(true); michael@0: startupManager(); michael@0: michael@0: AddonManager.getAddonByID("addon1@tests.mozilla.org", michael@0: function check_after_rebuild(a1) { michael@0: // addon1 was rebuilt from extensions directory, michael@0: // so it appears enabled as a foreign install 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_true(a1.foreignInstall); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: });