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 rebuild something sensible from a corrupt database michael@0: michael@0: Components.utils.import("resource://testing-common/httpd.js"); michael@0: Components.utils.import("resource://gre/modules/osfile.jsm"); michael@0: michael@0: var testserver = new HttpServer(); michael@0: testserver.start(-1); michael@0: gPort = testserver.identity.primaryPort; michael@0: mapFile("/data/test_corrupt.rdf", testserver); michael@0: testserver.registerDirectory("/addons/", do_get_file("addons")); michael@0: michael@0: // The test extension uses an insecure update url. michael@0: Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false); michael@0: Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false); michael@0: michael@0: // Will be enabled 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: "2", michael@0: maxVersion: "2" michael@0: }] michael@0: }; michael@0: michael@0: // Will be disabled michael@0: var addon2 = { michael@0: id: "addon2@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Test 2", 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: // Will get a compatibility update and stay enabled michael@0: var addon3 = { michael@0: id: "addon3@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Test 3", michael@0: updateURL: "http://localhost:" + gPort + "/data/test_corrupt.rdf", 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: // Will get a compatibility update and be enabled michael@0: var addon4 = { michael@0: id: "addon4@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Test 4", michael@0: updateURL: "http://localhost:" + gPort + "/data/test_corrupt.rdf", 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: // Would stay incompatible with strict compat michael@0: var addon5 = { michael@0: id: "addon5@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Test 5", 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: // Enabled bootstrapped michael@0: var addon6 = { michael@0: id: "addon6@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Test 6", michael@0: bootstrap: "true", 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: // Disabled bootstrapped michael@0: var addon7 = { michael@0: id: "addon7@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Test 7", michael@0: bootstrap: "true", 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: // The default theme michael@0: var theme1 = { michael@0: id: "theme1@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Theme 1", michael@0: internalName: "classic/1.0", 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: // The selected theme michael@0: var theme2 = { michael@0: id: "theme2@tests.mozilla.org", michael@0: version: "1.0", michael@0: name: "Theme 2", michael@0: internalName: "test/1.0", 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: add_task(function* init() { michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "2", "2"); 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, profileDir); michael@0: writeInstallRDFForExtension(theme1, profileDir); michael@0: writeInstallRDFForExtension(theme2, profileDir); michael@0: michael@0: // Startup the profile and setup the initial state michael@0: startupManager(); michael@0: michael@0: // New profile so new add-ons are ignored michael@0: check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []); michael@0: michael@0: let [a2, a3, a4, a7, t2] = michael@0: yield promiseAddonsByIDs(["addon2@tests.mozilla.org", michael@0: "addon3@tests.mozilla.org", michael@0: "addon4@tests.mozilla.org", michael@0: "addon7@tests.mozilla.org", michael@0: "theme2@tests.mozilla.org"]); michael@0: let deferredUpdateFinished = Promise.defer(); michael@0: // Set up the initial state michael@0: a2.userDisabled = true; michael@0: a4.userDisabled = true; michael@0: a7.userDisabled = true; michael@0: t2.userDisabled = false; michael@0: a3.findUpdates({ michael@0: onUpdateFinished: function() { michael@0: a4.findUpdates({ michael@0: onUpdateFinished: function() { michael@0: // Let the updates finish before restarting the manager michael@0: deferredUpdateFinished.resolve(); michael@0: } michael@0: }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE); michael@0: } michael@0: }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE); michael@0: michael@0: yield deferredUpdateFinished.promise; michael@0: }); michael@0: michael@0: michael@0: add_task(function* run_test_1() { michael@0: restartManager(); michael@0: let [a1, a2, a3, a4, a5, a6, a7, t1, t2] = michael@0: yield promiseAddonsByIDs(["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: "theme1@tests.mozilla.org", michael@0: "theme2@tests.mozilla.org"]); michael@0: michael@0: do_check_neq(a1, null); michael@0: do_check_true(a1.isActive); michael@0: do_check_false(a1.userDisabled); michael@0: do_check_false(a1.appDisabled); michael@0: do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a1.id)); michael@0: michael@0: do_check_neq(a2, null); michael@0: do_check_false(a2.isActive); michael@0: do_check_true(a2.userDisabled); michael@0: do_check_false(a2.appDisabled); michael@0: do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a2.id)); michael@0: michael@0: do_check_neq(a3, null); michael@0: do_check_true(a3.isActive); michael@0: do_check_false(a3.userDisabled); michael@0: do_check_false(a3.appDisabled); michael@0: do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a3.id)); michael@0: michael@0: do_check_neq(a4, null); michael@0: do_check_false(a4.isActive); michael@0: do_check_true(a4.userDisabled); michael@0: do_check_false(a4.appDisabled); michael@0: do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a4.id)); michael@0: michael@0: do_check_neq(a5, null); michael@0: do_check_true(a5.isActive); michael@0: do_check_false(a5.userDisabled); michael@0: do_check_false(a5.appDisabled); michael@0: do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a5.id)); michael@0: michael@0: do_check_neq(a6, null); michael@0: do_check_true(a6.isActive); michael@0: do_check_false(a6.userDisabled); michael@0: do_check_false(a6.appDisabled); michael@0: do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE); michael@0: michael@0: do_check_neq(a7, null); michael@0: do_check_false(a7.isActive); michael@0: do_check_true(a7.userDisabled); michael@0: do_check_false(a7.appDisabled); michael@0: do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE); michael@0: michael@0: do_check_neq(t1, null); michael@0: do_check_false(t1.isActive); michael@0: do_check_true(t1.userDisabled); michael@0: do_check_false(t1.appDisabled); michael@0: do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_false(isThemeInAddonsList(profileDir, t1.id)); michael@0: michael@0: do_check_neq(t2, null); michael@0: do_check_true(t2.isActive); michael@0: do_check_false(t2.userDisabled); michael@0: do_check_false(t2.appDisabled); michael@0: do_check_eq(t2.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_true(isThemeInAddonsList(profileDir, t2.id)); michael@0: michael@0: // Open another handle on the JSON DB with as much Unix and Windows locking michael@0: // as we can to simulate some other process interfering with it michael@0: shutdownManager(); michael@0: do_print("Locking " + gExtensionsJSON.path); michael@0: let options = { michael@0: winShare: 0 michael@0: }; michael@0: if (OS.Constants.libc.O_EXLOCK) michael@0: options.unixFlags = OS.Constants.libc.O_EXLOCK; michael@0: michael@0: let file = yield OS.File.open(gExtensionsJSON.path, {read:true, write:true, existing:true}, options); michael@0: michael@0: let filePermissions = gExtensionsJSON.permissions; michael@0: if (!OS.Constants.Win) { michael@0: gExtensionsJSON.permissions = 0; michael@0: } michael@0: startupManager(false); michael@0: michael@0: // Shouldn't have seen any startup changes michael@0: check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []); michael@0: michael@0: // Accessing the add-ons should open and recover the database michael@0: [a1, a2, a3, a4, a5, a6, a7, t1, t2] = michael@0: yield promiseAddonsByIDs(["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: "theme1@tests.mozilla.org", michael@0: "theme2@tests.mozilla.org"]); michael@0: michael@0: // Should be correctly recovered michael@0: do_check_neq(a1, null); michael@0: do_check_true(a1.isActive); michael@0: do_check_false(a1.userDisabled); michael@0: do_check_false(a1.appDisabled); michael@0: do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a1.id)); michael@0: michael@0: // Should be correctly recovered michael@0: do_check_neq(a2, null); michael@0: do_check_false(a2.isActive); michael@0: do_check_true(a2.userDisabled); michael@0: do_check_false(a2.appDisabled); michael@0: do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a2.id)); michael@0: michael@0: // The compatibility update won't be recovered but it should still be michael@0: // active for this session michael@0: do_check_neq(a3, null); michael@0: do_check_true(a3.isActive); michael@0: do_check_false(a3.userDisabled); michael@0: do_check_false(a3.appDisabled); michael@0: do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a3.id)); michael@0: michael@0: // The compatibility update won't be recovered and with strict michael@0: // compatibility it would not have been able to tell that it was michael@0: // previously userDisabled. However, without strict compat, it wasn't michael@0: // appDisabled, so it knows it must have been userDisabled. michael@0: do_check_neq(a4, null); michael@0: do_check_false(a4.isActive); michael@0: do_check_true(a4.userDisabled); michael@0: do_check_false(a4.appDisabled); michael@0: do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a4.id)); michael@0: michael@0: do_check_neq(a5, null); michael@0: do_check_true(a5.isActive); michael@0: do_check_false(a5.userDisabled); michael@0: do_check_false(a5.appDisabled); michael@0: do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a5.id)); michael@0: michael@0: do_check_neq(a6, null); michael@0: do_check_true(a6.isActive); michael@0: do_check_false(a6.userDisabled); michael@0: do_check_false(a6.appDisabled); michael@0: do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE); michael@0: michael@0: do_check_neq(a7, null); michael@0: do_check_false(a7.isActive); michael@0: do_check_true(a7.userDisabled); michael@0: do_check_false(a7.appDisabled); michael@0: do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE); michael@0: michael@0: // Should be correctly recovered michael@0: do_check_neq(t1, null); michael@0: do_check_false(t1.isActive); michael@0: do_check_true(t1.userDisabled); michael@0: do_check_false(t1.appDisabled); michael@0: do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_false(isThemeInAddonsList(profileDir, t1.id)); michael@0: michael@0: // Should be correctly recovered michael@0: do_check_neq(t2, null); michael@0: do_check_true(t2.isActive); michael@0: do_check_false(t2.userDisabled); michael@0: do_check_false(t2.appDisabled); michael@0: do_check_eq(t2.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_true(isThemeInAddonsList(profileDir, t2.id)); michael@0: michael@0: // Restarting will actually apply changes to extensions.ini which will michael@0: // then be put into the in-memory database when we next fail to load the michael@0: // real thing michael@0: restartManager(); michael@0: michael@0: // Shouldn't have seen any startup changes michael@0: check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []); michael@0: michael@0: [a1, a2, a3, a4, a5, a6, a7, t1, t2] = michael@0: yield promiseAddonsByIDs(["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: "theme1@tests.mozilla.org", michael@0: "theme2@tests.mozilla.org"]); michael@0: michael@0: do_check_neq(a1, null); michael@0: do_check_true(a1.isActive); michael@0: do_check_false(a1.userDisabled); michael@0: do_check_false(a1.appDisabled); michael@0: do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a1.id)); michael@0: michael@0: do_check_neq(a2, null); michael@0: do_check_false(a2.isActive); michael@0: do_check_true(a2.userDisabled); michael@0: do_check_false(a2.appDisabled); michael@0: do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a2.id)); michael@0: michael@0: do_check_neq(a3, null); michael@0: do_check_true(a3.isActive); michael@0: do_check_false(a3.userDisabled); michael@0: do_check_false(a3.appDisabled); michael@0: do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a3.id)); michael@0: michael@0: do_check_neq(a4, null); michael@0: do_check_false(a4.isActive); michael@0: do_check_true(a4.userDisabled); michael@0: do_check_false(a4.appDisabled); michael@0: do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a4.id)); michael@0: michael@0: do_check_neq(a5, null); michael@0: do_check_true(a5.isActive); michael@0: do_check_false(a5.userDisabled); michael@0: do_check_false(a5.appDisabled); michael@0: do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a5.id)); michael@0: michael@0: do_check_neq(a6, null); michael@0: do_check_true(a6.isActive); michael@0: do_check_false(a6.userDisabled); michael@0: do_check_false(a6.appDisabled); michael@0: do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE); michael@0: michael@0: do_check_neq(a7, null); michael@0: do_check_false(a7.isActive); michael@0: do_check_true(a7.userDisabled); michael@0: do_check_false(a7.appDisabled); michael@0: do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE); michael@0: michael@0: do_check_neq(t1, null); michael@0: do_check_false(t1.isActive); michael@0: do_check_true(t1.userDisabled); michael@0: do_check_false(t1.appDisabled); michael@0: do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_false(isThemeInAddonsList(profileDir, t1.id)); michael@0: michael@0: do_check_neq(t2, null); michael@0: do_check_true(t2.isActive); michael@0: do_check_false(t2.userDisabled); michael@0: do_check_false(t2.appDisabled); michael@0: do_check_eq(t2.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_true(isThemeInAddonsList(profileDir, t2.id)); michael@0: michael@0: // After allowing access to the original DB things should go back to as michael@0: // they were previously michael@0: shutdownManager(); michael@0: do_print("Unlocking " + gExtensionsJSON.path); michael@0: yield file.close(); michael@0: gExtensionsJSON.permissions = filePermissions; michael@0: startupManager(); michael@0: michael@0: michael@0: // Shouldn't have seen any startup changes michael@0: check_startup_changes(AddonManager.STARTUP_CHANGE_INSTALLED, []); michael@0: michael@0: [a1, a2, a3, a4, a5, a6, a7, t1, t2] = michael@0: yield promiseAddonsByIDs(["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: "theme1@tests.mozilla.org", michael@0: "theme2@tests.mozilla.org"]); michael@0: michael@0: do_check_neq(a1, null); michael@0: do_check_true(a1.isActive); michael@0: do_check_false(a1.userDisabled); michael@0: do_check_false(a1.appDisabled); michael@0: do_check_eq(a1.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a1.id)); michael@0: michael@0: do_check_neq(a2, null); michael@0: do_check_false(a2.isActive); michael@0: do_check_true(a2.userDisabled); michael@0: do_check_false(a2.appDisabled); michael@0: do_check_eq(a2.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a2.id)); michael@0: michael@0: do_check_neq(a3, null); michael@0: do_check_true(a3.isActive); michael@0: do_check_false(a3.userDisabled); michael@0: do_check_false(a3.appDisabled); michael@0: do_check_eq(a3.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a3.id)); michael@0: michael@0: do_check_neq(a4, null); michael@0: do_check_false(a4.isActive); michael@0: do_check_true(a4.userDisabled); michael@0: do_check_false(a4.appDisabled); michael@0: do_check_eq(a4.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_false(isExtensionInAddonsList(profileDir, a4.id)); michael@0: michael@0: do_check_neq(a5, null); michael@0: do_check_true(a5.isActive); michael@0: do_check_false(a5.userDisabled); michael@0: do_check_false(a5.appDisabled); michael@0: do_check_eq(a5.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_true(isExtensionInAddonsList(profileDir, a5.id)); michael@0: michael@0: do_check_neq(a6, null); michael@0: do_check_true(a6.isActive); michael@0: do_check_false(a6.userDisabled); michael@0: do_check_false(a6.appDisabled); michael@0: do_check_eq(a6.pendingOperations, AddonManager.PENDING_NONE); michael@0: michael@0: do_check_neq(a7, null); michael@0: do_check_false(a7.isActive); michael@0: do_check_true(a7.userDisabled); michael@0: do_check_false(a7.appDisabled); michael@0: do_check_eq(a7.pendingOperations, AddonManager.PENDING_NONE); michael@0: michael@0: do_check_neq(t1, null); michael@0: do_check_false(t1.isActive); michael@0: do_check_true(t1.userDisabled); michael@0: do_check_false(t1.appDisabled); michael@0: do_check_eq(t1.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_false(isThemeInAddonsList(profileDir, t1.id)); michael@0: michael@0: do_check_neq(t2, null); michael@0: do_check_true(t2.isActive); michael@0: do_check_false(t2.userDisabled); michael@0: do_check_false(t2.appDisabled); michael@0: do_check_eq(t2.pendingOperations, AddonManager.PENDING_NONE); michael@0: do_check_true(isThemeInAddonsList(profileDir, t2.id)); michael@0: }); michael@0: michael@0: michael@0: function run_test() { michael@0: run_next_test(); michael@0: }