|
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 checks work correctly when compatibility |
|
6 // check is disabled. |
|
7 |
|
8 const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled"; |
|
9 |
|
10 // The test extension uses an insecure update url. |
|
11 Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false); |
|
12 |
|
13 Components.utils.import("resource://testing-common/httpd.js"); |
|
14 var testserver = new HttpServer(); |
|
15 testserver.start(-1); |
|
16 gPort = testserver.identity.primaryPort; |
|
17 mapFile("/data/test_update.rdf", testserver); |
|
18 mapFile("/data/test_update.xml", testserver); |
|
19 testserver.registerDirectory("/addons/", do_get_file("addons")); |
|
20 |
|
21 const profileDir = gProfD.clone(); |
|
22 profileDir.append("extensions"); |
|
23 |
|
24 |
|
25 function run_test() { |
|
26 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); |
|
27 |
|
28 run_test_1(); |
|
29 } |
|
30 |
|
31 // Test that the update check correctly observes the |
|
32 // extensions.strictCompatibility pref and compatibility overrides. |
|
33 function run_test_1() { |
|
34 writeInstallRDFForExtension({ |
|
35 id: "addon9@tests.mozilla.org", |
|
36 version: "1.0", |
|
37 updateURL: "http://localhost:" + gPort + "/data/test_update.rdf", |
|
38 targetApplications: [{ |
|
39 id: "xpcshell@tests.mozilla.org", |
|
40 minVersion: "0.1", |
|
41 maxVersion: "0.2" |
|
42 }], |
|
43 name: "Test Addon 9", |
|
44 }, profileDir); |
|
45 restartManager(); |
|
46 |
|
47 AddonManager.addInstallListener({ |
|
48 onNewInstall: function(aInstall) { |
|
49 if (aInstall.existingAddon.id != "addon9@tests.mozilla.org") |
|
50 do_throw("Saw unexpected onNewInstall for " + aInstall.existingAddon.id); |
|
51 do_check_eq(aInstall.version, "4.0"); |
|
52 }, |
|
53 onDownloadFailed: function(aInstall) { |
|
54 do_execute_soon(run_test_2); |
|
55 } |
|
56 }); |
|
57 |
|
58 Services.prefs.setCharPref(PREF_GETADDONS_BYIDS_PERFORMANCE, |
|
59 "http://localhost:" + gPort + "/data/test_update.xml"); |
|
60 Services.prefs.setBoolPref(PREF_GETADDONS_CACHE_ENABLED, true); |
|
61 // Fake a timer event |
|
62 gInternalManager.notify(null); |
|
63 } |
|
64 |
|
65 // Test that the update check correctly observes when an addon opts-in to |
|
66 // strict compatibility checking. |
|
67 function run_test_2() { |
|
68 writeInstallRDFForExtension({ |
|
69 id: "addon11@tests.mozilla.org", |
|
70 version: "1.0", |
|
71 updateURL: "http://localhost:" + gPort + "/data/test_update.rdf", |
|
72 targetApplications: [{ |
|
73 id: "xpcshell@tests.mozilla.org", |
|
74 minVersion: "0.1", |
|
75 maxVersion: "0.2" |
|
76 }], |
|
77 name: "Test Addon 11", |
|
78 }, profileDir); |
|
79 restartManager(); |
|
80 |
|
81 AddonManager.getAddonByID("addon11@tests.mozilla.org", function(a11) { |
|
82 do_check_neq(a11, null); |
|
83 |
|
84 a11.findUpdates({ |
|
85 onCompatibilityUpdateAvailable: function() { |
|
86 do_throw("Should have not have seen compatibility information"); |
|
87 }, |
|
88 |
|
89 onNoUpdateAvailable: function() { |
|
90 do_throw("Should have seen an available update"); |
|
91 }, |
|
92 |
|
93 onUpdateFinished: function() { |
|
94 end_test(); |
|
95 } |
|
96 }, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
|
97 }); |
|
98 } |