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: michael@0: Components.utils.import("resource://testing-common/httpd.js"); michael@0: // Create and configure the HTTP server. michael@0: var testserver = new HttpServer(); michael@0: testserver.start(-1); michael@0: gPort = testserver.identity.primaryPort; michael@0: michael@0: // register files with server michael@0: testserver.registerDirectory("/addons/", do_get_file("addons")); michael@0: mapFile("/data/test_corrupt.rdf", testserver); 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: function run_test() { michael@0: do_test_pending(); 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: AddonManager.getAddonsByIDs(["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"], function([a2, a3, a4, michael@0: a7, t2]) { 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: do_execute_soon(run_test_1); michael@0: } michael@0: }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE); michael@0: } michael@0: }, AddonManager.UPDATE_WHEN_PERIODIC_UPDATE); michael@0: }); michael@0: } michael@0: michael@0: function end_test() { michael@0: testserver.stop(do_test_finished); michael@0: } michael@0: michael@0: function run_test_1() { michael@0: restartManager(); 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: "theme1@tests.mozilla.org", michael@0: "theme2@tests.mozilla.org"], michael@0: callback_soon(function([a1, a2, a3, a4, a5, a6, a7, t1, t2]) { 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: 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: 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: 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: 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: 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: 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: michael@0: // Shutdown and replace the database with a corrupt file (a directory michael@0: // serves this purpose). On startup the add-ons manager won't rebuild michael@0: // because there is a file there still. michael@0: shutdownManager(); michael@0: gExtensionsJSON.remove(true); michael@0: gExtensionsJSON.create(AM_Ci.nsIFile.DIRECTORY_TYPE, FileUtils.PERMS_DIRECTORY); michael@0: startupManager(false); michael@0: michael@0: // Accessing the add-ons should open and recover the database 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: "theme1@tests.mozilla.org", michael@0: "theme2@tests.mozilla.org"], michael@0: callback_soon(function([a1, a2, a3, a4, a5, a6, a7, t1, t2]) { 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: 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: 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: 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: 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: 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: 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: michael@0: restartManager(); 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: "theme1@tests.mozilla.org", michael@0: "theme2@tests.mozilla.org"], michael@0: callback_soon(function([a1, a2, a3, a4, a5, a6, a7, t1, t2]) { 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: 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: 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: 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: 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: 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: 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: michael@0: end_test(); michael@0: })); michael@0: })); michael@0: })); michael@0: }