|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // This verifies that add-on update check failures are propogated correctly |
|
6 |
|
7 // The test extension uses an insecure update url. |
|
8 Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); |
|
9 |
|
10 Components.utils.import("resource://testing-common/httpd.js"); |
|
11 var testserver; |
|
12 const profileDir = gProfD.clone(); |
|
13 profileDir.append("extensions"); |
|
14 |
|
15 function run_test() { |
|
16 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
|
17 |
|
18 // Create and configure the HTTP server. |
|
19 testserver = new HttpServer(); |
|
20 testserver.registerDirectory("/data/", do_get_file("data")); |
|
21 testserver.registerDirectory("/addons/", do_get_file("addons")); |
|
22 testserver.start(-1); |
|
23 gPort = testserver.identity.primaryPort; |
|
24 |
|
25 writeInstallRDFForExtension({ |
|
26 id: "addon1@tests.mozilla.org", |
|
27 version: "1.0", |
|
28 updateURL: "http://localhost:" + gPort + "/data/test_missing.rdf", |
|
29 targetApplications: [{ |
|
30 id: "xpcshell@tests.mozilla.org", |
|
31 minVersion: "1", |
|
32 maxVersion: "1" |
|
33 }], |
|
34 name: "Test Addon 1", |
|
35 }, profileDir); |
|
36 |
|
37 startupManager(); |
|
38 |
|
39 do_test_pending(); |
|
40 run_test_1(); |
|
41 } |
|
42 |
|
43 function end_test() { |
|
44 testserver.stop(do_test_finished); |
|
45 } |
|
46 |
|
47 // Verify that an update check returns the correct errors. |
|
48 function run_test_1() { |
|
49 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(a1) { |
|
50 do_check_neq(a1, null); |
|
51 do_check_eq(a1.version, "1.0"); |
|
52 |
|
53 let sawCompat = false; |
|
54 let sawUpdate = false; |
|
55 a1.findUpdates({ |
|
56 onNoCompatibilityUpdateAvailable: function(addon) { |
|
57 sawCompat = true; |
|
58 }, |
|
59 |
|
60 onCompatibilityUpdateAvailable: function(addon) { |
|
61 do_throw("Should not have seen a compatibility update"); |
|
62 }, |
|
63 |
|
64 onNoUpdateAvailable: function(addon) { |
|
65 sawUpdate = true; |
|
66 }, |
|
67 |
|
68 onUpdateAvailable: function(addon, install) { |
|
69 do_throw("Should not have seen an update"); |
|
70 }, |
|
71 |
|
72 onUpdateFinished: function(addon, error) { |
|
73 do_check_true(sawCompat); |
|
74 do_check_true(sawUpdate); |
|
75 do_check_eq(error, AddonManager.UPDATE_STATUS_DOWNLOAD_ERROR); |
|
76 end_test(); |
|
77 } |
|
78 }, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
|
79 }); |
|
80 } |