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: // This verifies that add-on update checks work correctly when compatibility michael@0: // check is disabled. michael@0: michael@0: const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled"; 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: michael@0: Components.utils.import("resource://testing-common/httpd.js"); michael@0: var testserver = new HttpServer(); michael@0: testserver.start(-1); michael@0: gPort = testserver.identity.primaryPort; michael@0: mapFile("/data/test_update.rdf", testserver); michael@0: mapFile("/data/test_update.xml", testserver); michael@0: testserver.registerDirectory("/addons/", do_get_file("addons")); michael@0: michael@0: const profileDir = gProfD.clone(); michael@0: profileDir.append("extensions"); michael@0: michael@0: michael@0: function run_test() { michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); michael@0: michael@0: run_test_1(); michael@0: } michael@0: michael@0: // Test that the update check correctly observes the michael@0: // extensions.strictCompatibility pref and compatibility overrides. michael@0: function run_test_1() { michael@0: writeInstallRDFForExtension({ michael@0: id: "addon9@tests.mozilla.org", michael@0: version: "1.0", michael@0: updateURL: "http://localhost:" + gPort + "/data/test_update.rdf", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "0.1", michael@0: maxVersion: "0.2" michael@0: }], michael@0: name: "Test Addon 9", michael@0: }, profileDir); michael@0: restartManager(); michael@0: michael@0: AddonManager.addInstallListener({ michael@0: onNewInstall: function(aInstall) { michael@0: if (aInstall.existingAddon.id != "addon9@tests.mozilla.org") michael@0: do_throw("Saw unexpected onNewInstall for " + aInstall.existingAddon.id); michael@0: do_check_eq(aInstall.version, "4.0"); michael@0: }, michael@0: onDownloadFailed: function(aInstall) { michael@0: do_execute_soon(run_test_2); michael@0: } michael@0: }); michael@0: michael@0: Services.prefs.setCharPref(PREF_GETADDONS_BYIDS_PERFORMANCE, michael@0: "http://localhost:" + gPort + "/data/test_update.xml"); michael@0: Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true); michael@0: // Fake a timer event michael@0: gInternalManager.notify(null); michael@0: } michael@0: michael@0: // Test that the update check correctly observes when an addon opts-in to michael@0: // strict compatibility checking. michael@0: function run_test_2() { michael@0: writeInstallRDFForExtension({ michael@0: id: "addon11@tests.mozilla.org", michael@0: version: "1.0", michael@0: updateURL: "http://localhost:" + gPort + "/data/test_update.rdf", michael@0: targetApplications: [{ michael@0: id: "xpcshell@tests.mozilla.org", michael@0: minVersion: "0.1", michael@0: maxVersion: "0.2" michael@0: }], michael@0: name: "Test Addon 11", michael@0: }, profileDir); michael@0: restartManager(); michael@0: michael@0: AddonManager.getAddonByID("addon11@tests.mozilla.org", function(a11) { michael@0: do_check_neq(a11, null); michael@0: michael@0: a11.findUpdates({ michael@0: onCompatibilityUpdateAvailable: function() { michael@0: do_throw("Should have not have seen compatibility information"); michael@0: }, michael@0: michael@0: onNoUpdateAvailable: function() { michael@0: do_throw("Should have seen an available update"); michael@0: }, michael@0: michael@0: onUpdateFinished: function() { michael@0: end_test(); michael@0: } michael@0: }, AddonManager.UPDATE_WHEN_USER_REQUESTED); michael@0: }); michael@0: }