1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_bug570173.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,80 @@ 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 check failures are propogated correctly 1.9 + 1.10 +// The test extension uses an insecure update url. 1.11 +Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); 1.12 + 1.13 +Components.utils.import("resource://testing-common/httpd.js"); 1.14 +var testserver; 1.15 +const profileDir = gProfD.clone(); 1.16 +profileDir.append("extensions"); 1.17 + 1.18 +function run_test() { 1.19 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); 1.20 + 1.21 + // Create and configure the HTTP server. 1.22 + testserver = new HttpServer(); 1.23 + testserver.registerDirectory("/data/", do_get_file("data")); 1.24 + testserver.registerDirectory("/addons/", do_get_file("addons")); 1.25 + testserver.start(-1); 1.26 + gPort = testserver.identity.primaryPort; 1.27 + 1.28 + writeInstallRDFForExtension({ 1.29 + id: "addon1@tests.mozilla.org", 1.30 + version: "1.0", 1.31 + updateURL: "http://localhost:" + gPort + "/data/test_missing.rdf", 1.32 + targetApplications: [{ 1.33 + id: "xpcshell@tests.mozilla.org", 1.34 + minVersion: "1", 1.35 + maxVersion: "1" 1.36 + }], 1.37 + name: "Test Addon 1", 1.38 + }, profileDir); 1.39 + 1.40 + startupManager(); 1.41 + 1.42 + do_test_pending(); 1.43 + run_test_1(); 1.44 +} 1.45 + 1.46 +function end_test() { 1.47 + testserver.stop(do_test_finished); 1.48 +} 1.49 + 1.50 +// Verify that an update check returns the correct errors. 1.51 +function run_test_1() { 1.52 + AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { 1.53 + do_check_neq(a1, null); 1.54 + do_check_eq(a1.version, "1.0"); 1.55 + 1.56 + let sawCompat = false; 1.57 + let sawUpdate = false; 1.58 + a1.findUpdates({ 1.59 + onNoCompatibilityUpdateAvailable: function(addon) { 1.60 + sawCompat = true; 1.61 + }, 1.62 + 1.63 + onCompatibilityUpdateAvailable: function(addon) { 1.64 + do_throw("Should not have seen a compatibility update"); 1.65 + }, 1.66 + 1.67 + onNoUpdateAvailable: function(addon) { 1.68 + sawUpdate = true; 1.69 + }, 1.70 + 1.71 + onUpdateAvailable: function(addon, install) { 1.72 + do_throw("Should not have seen an update"); 1.73 + }, 1.74 + 1.75 + onUpdateFinished: function(addon, error) { 1.76 + do_check_true(sawCompat); 1.77 + do_check_true(sawUpdate); 1.78 + do_check_eq(error, AddonManager.UPDATE_STATUS_DOWNLOAD_ERROR); 1.79 + end_test(); 1.80 + } 1.81 + }, AddonManager.UPDATE_WHEN_USER_REQUESTED); 1.82 + }); 1.83 +}