1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_update_ignorecompat.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,98 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +// This verifies that add-on update checks work correctly when compatibility 1.9 +// check is disabled. 1.10 + 1.11 +const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled"; 1.12 + 1.13 +// The test extension uses an insecure update url. 1.14 +Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false); 1.15 + 1.16 +Components.utils.import("resource://testing-common/httpd.js"); 1.17 +var testserver = new HttpServer(); 1.18 +testserver.start(-1); 1.19 +gPort = testserver.identity.primaryPort; 1.20 +mapFile("/data/test_update.rdf", testserver); 1.21 +mapFile("/data/test_update.xml", testserver); 1.22 +testserver.registerDirectory("/addons/", do_get_file("addons")); 1.23 + 1.24 +const profileDir = gProfD.clone(); 1.25 +profileDir.append("extensions"); 1.26 + 1.27 + 1.28 +function run_test() { 1.29 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); 1.30 + 1.31 + run_test_1(); 1.32 +} 1.33 + 1.34 +// Test that the update check correctly observes the 1.35 +// extensions.strictCompatibility pref and compatibility overrides. 1.36 +function run_test_1() { 1.37 + writeInstallRDFForExtension({ 1.38 + id: "addon9@tests.mozilla.org", 1.39 + version: "1.0", 1.40 + updateURL: "http://localhost:" + gPort + "/data/test_update.rdf", 1.41 + targetApplications: [{ 1.42 + id: "xpcshell@tests.mozilla.org", 1.43 + minVersion: "0.1", 1.44 + maxVersion: "0.2" 1.45 + }], 1.46 + name: "Test Addon 9", 1.47 + }, profileDir); 1.48 + restartManager(); 1.49 + 1.50 + AddonManager.addInstallListener({ 1.51 + onNewInstall: function(aInstall) { 1.52 + if (aInstall.existingAddon.id != "addon9@tests.mozilla.org") 1.53 + do_throw("Saw unexpected onNewInstall for " + aInstall.existingAddon.id); 1.54 + do_check_eq(aInstall.version, "4.0"); 1.55 + }, 1.56 + onDownloadFailed: function(aInstall) { 1.57 + do_execute_soon(run_test_2); 1.58 + } 1.59 + }); 1.60 + 1.61 + Services.prefs.setCharPref(PREF_GETADDONS_BYIDS_PERFORMANCE, 1.62 + "http://localhost:" + gPort + "/data/test_update.xml"); 1.63 + Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true); 1.64 + // Fake a timer event 1.65 + gInternalManager.notify(null); 1.66 +} 1.67 + 1.68 +// Test that the update check correctly observes when an addon opts-in to 1.69 +// strict compatibility checking. 1.70 +function run_test_2() { 1.71 + writeInstallRDFForExtension({ 1.72 + id: "addon11@tests.mozilla.org", 1.73 + version: "1.0", 1.74 + updateURL: "http://localhost:" + gPort + "/data/test_update.rdf", 1.75 + targetApplications: [{ 1.76 + id: "xpcshell@tests.mozilla.org", 1.77 + minVersion: "0.1", 1.78 + maxVersion: "0.2" 1.79 + }], 1.80 + name: "Test Addon 11", 1.81 + }, profileDir); 1.82 + restartManager(); 1.83 + 1.84 + AddonManager.getAddonByID("addon11@tests.mozilla.org", function(a11) { 1.85 + do_check_neq(a11, null); 1.86 + 1.87 + a11.findUpdates({ 1.88 + onCompatibilityUpdateAvailable: function() { 1.89 + do_throw("Should have not have seen compatibility information"); 1.90 + }, 1.91 + 1.92 + onNoUpdateAvailable: function() { 1.93 + do_throw("Should have seen an available update"); 1.94 + }, 1.95 + 1.96 + onUpdateFinished: function() { 1.97 + end_test(); 1.98 + } 1.99 + }, AddonManager.UPDATE_WHEN_USER_REQUESTED); 1.100 + }); 1.101 +}