|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
|
4 */ |
|
5 |
|
6 // Disables security checking our updates which haven't been signed |
|
7 Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); |
|
8 |
|
9 // Update check listener. |
|
10 const checkListener = { |
|
11 pendingCount: 0, |
|
12 |
|
13 onUpdateAvailable: function onUpdateAvailable(aAddon, aInstall) { |
|
14 for (let currentAddon of ADDONS) { |
|
15 if (currentAddon.id == aAddon.id) { |
|
16 currentAddon.newInstall = aInstall; |
|
17 return; |
|
18 } |
|
19 } |
|
20 }, |
|
21 |
|
22 onUpdateFinished: function onUpdateFinished() { |
|
23 if (--this.pendingCount == 0) |
|
24 next_test(); |
|
25 } |
|
26 } |
|
27 |
|
28 // Get the HTTP server. |
|
29 Components.utils.import("resource://testing-common/httpd.js"); |
|
30 var testserver; |
|
31 |
|
32 var ADDONS = [ |
|
33 // XPCShell |
|
34 { |
|
35 id: "bug299716-a@tests.mozilla.org", |
|
36 addon: "test_bug299716_a_1", |
|
37 installed: true, |
|
38 item: null, |
|
39 newInstall: null |
|
40 }, |
|
41 |
|
42 // Toolkit |
|
43 { |
|
44 id: "bug299716-b@tests.mozilla.org", |
|
45 addon: "test_bug299716_b_1", |
|
46 installed: true, |
|
47 item: null, |
|
48 newInstall: null |
|
49 }, |
|
50 |
|
51 // XPCShell + Toolkit |
|
52 { |
|
53 id: "bug299716-c@tests.mozilla.org", |
|
54 addon: "test_bug299716_c_1", |
|
55 installed: true, |
|
56 item: null, |
|
57 newInstall: null |
|
58 }, |
|
59 |
|
60 // XPCShell (Toolkit invalid) |
|
61 { |
|
62 id: "bug299716-d@tests.mozilla.org", |
|
63 addon: "test_bug299716_d_1", |
|
64 installed: true, |
|
65 item: null, |
|
66 newInstall: null |
|
67 }, |
|
68 |
|
69 // Toolkit (XPCShell invalid) |
|
70 { |
|
71 id: "bug299716-e@tests.mozilla.org", |
|
72 addon: "test_bug299716_e_1", |
|
73 installed: false, |
|
74 item: null, |
|
75 newInstall: null, |
|
76 failedAppName: "XPCShell" |
|
77 }, |
|
78 |
|
79 // None (XPCShell, Toolkit invalid) |
|
80 { |
|
81 id: "bug299716-f@tests.mozilla.org", |
|
82 addon: "test_bug299716_f_1", |
|
83 installed: false, |
|
84 item: null, |
|
85 newInstall: null, |
|
86 failedAppName: "XPCShell" |
|
87 }, |
|
88 |
|
89 // None (Toolkit invalid) |
|
90 { |
|
91 id: "bug299716-g@tests.mozilla.org", |
|
92 addon: "test_bug299716_g_1", |
|
93 installed: false, |
|
94 item: null, |
|
95 newInstall: null, |
|
96 failedAppName: "Toolkit" |
|
97 }, |
|
98 ]; |
|
99 |
|
100 var next_test = function() {}; |
|
101 |
|
102 function do_check_item(aItem, aVersion, aAddonsEntry) { |
|
103 if (aAddonsEntry.installed) { |
|
104 if (aItem == null) |
|
105 do_throw("Addon " + aAddonsEntry.id + " wasn't detected"); |
|
106 if (aItem.version != aVersion) |
|
107 do_throw("Addon " + aAddonsEntry.id + " was version " + aItem.version + " instead of " + aVersion); |
|
108 } else { |
|
109 if (aItem != null) |
|
110 do_throw("Addon " + aAddonsEntry.id + " was detected"); |
|
111 } |
|
112 } |
|
113 |
|
114 /** |
|
115 * Start the test by installing extensions. |
|
116 */ |
|
117 function run_test() { |
|
118 do_test_pending(); |
|
119 |
|
120 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "5", "1.9"); |
|
121 |
|
122 const dataDir = do_get_file("data"); |
|
123 const addonsDir = do_get_addon(ADDONS[0].addon).parent; |
|
124 |
|
125 // Make sure we can actually get our data files. |
|
126 const xpiFile = addonsDir.clone(); |
|
127 xpiFile.append("test_bug299716_a_2.xpi"); |
|
128 do_check_true(xpiFile.exists()); |
|
129 |
|
130 // Create and configure the HTTP server. |
|
131 testserver = new HttpServer(); |
|
132 testserver.registerDirectory("/addons/", addonsDir); |
|
133 testserver.registerDirectory("/data/", dataDir); |
|
134 testserver.start(4444); |
|
135 |
|
136 // Make sure we can fetch the files over HTTP. |
|
137 const Ci = Components.interfaces; |
|
138 const xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"] |
|
139 .createInstance(Ci.nsIXMLHttpRequest) |
|
140 xhr.open("GET", "http://localhost:4444/addons/test_bug299716_a_2.xpi", false); |
|
141 xhr.send(null); |
|
142 do_check_true(xhr.status == 200); |
|
143 |
|
144 xhr.open("GET", "http://localhost:4444/data/test_bug299716.rdf", false); |
|
145 xhr.send(null); |
|
146 do_check_true(xhr.status == 200); |
|
147 |
|
148 // Start the real test. |
|
149 startupManager(); |
|
150 dump("\n\n*** INSTALLING NEW ITEMS\n\n"); |
|
151 |
|
152 installAllFiles([do_get_addon(a.addon) for each (a in ADDONS)], run_test_pt2, |
|
153 true); |
|
154 } |
|
155 |
|
156 /** |
|
157 * Check the versions of all items, and ask the extension manager to find updates. |
|
158 */ |
|
159 function run_test_pt2() { |
|
160 dump("\n\n*** DONE INSTALLING NEW ITEMS\n\n"); |
|
161 dump("\n\n*** RESTARTING EXTENSION MANAGER\n\n"); |
|
162 restartManager(); |
|
163 |
|
164 AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(items) { |
|
165 dump("\n\n*** REQUESTING UPDATE\n\n"); |
|
166 // checkListener will call run_test_pt3(). |
|
167 next_test = run_test_pt3; |
|
168 |
|
169 // Try to update the items. |
|
170 for (var i = 0; i < ADDONS.length; i++) { |
|
171 var item = items[i]; |
|
172 do_check_item(item, "0.1", ADDONS[i]); |
|
173 |
|
174 if (item) { |
|
175 checkListener.pendingCount++; |
|
176 ADDONS[i].item = item; |
|
177 item.findUpdates(checkListener, AddonManager.UPDATE_WHEN_USER_REQUESTED); |
|
178 } |
|
179 } |
|
180 }); |
|
181 } |
|
182 |
|
183 /** |
|
184 * Install new items for each enabled extension. |
|
185 */ |
|
186 function run_test_pt3() { |
|
187 // Install the new items. |
|
188 dump("\n\n*** UPDATING ITEMS\n\n"); |
|
189 completeAllInstalls([a.newInstall for each(a in ADDONS) if (a.newInstall)], |
|
190 run_test_pt4); |
|
191 } |
|
192 |
|
193 /** |
|
194 * Check the final version of each extension. |
|
195 */ |
|
196 function run_test_pt4() { |
|
197 dump("\n\n*** RESTARTING EXTENSION MANAGER\n\n"); |
|
198 restartManager(); |
|
199 |
|
200 dump("\n\n*** FINAL CHECKS\n\n"); |
|
201 AddonManager.getAddonsByIDs([a.id for each (a in ADDONS)], function(items) { |
|
202 for (var i = 0; i < ADDONS.length; i++) { |
|
203 var item = items[i]; |
|
204 do_check_item(item, "0.2", ADDONS[i]); |
|
205 } |
|
206 |
|
207 testserver.stop(do_test_finished); |
|
208 }); |
|
209 } |