|
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 /* General URL Construction Tests */ |
|
7 |
|
8 Components.utils.import("resource://gre/modules/ctypes.jsm") |
|
9 |
|
10 const URL_PREFIX = URL_HOST + "/"; |
|
11 |
|
12 var gAppInfo; |
|
13 |
|
14 function run_test() { |
|
15 // This test needs access to omni.ja to read the update.locale file so don't |
|
16 // use a custom directory for the application directory. |
|
17 gUseTestAppDir = false; |
|
18 setupTestCommon(); |
|
19 |
|
20 // The mock XMLHttpRequest is MUCH faster |
|
21 overrideXHR(callHandleEvent); |
|
22 standardInit(); |
|
23 gAppInfo = AUS_Cc["@mozilla.org/xre/app-info;1"]. |
|
24 getService(AUS_Ci.nsIXULAppInfo). |
|
25 QueryInterface(AUS_Ci.nsIXULRuntime); |
|
26 do_execute_soon(run_test_pt1); |
|
27 } |
|
28 |
|
29 // Callback function used by the custom XMLHttpRequest implementation to |
|
30 // call the nsIDOMEventListener's handleEvent method for onload. |
|
31 function callHandleEvent() { |
|
32 var e = { target: gXHR }; |
|
33 gXHR.onload(e); |
|
34 } |
|
35 |
|
36 // Helper function for parsing the result from the contructed url |
|
37 function getResult(url) { |
|
38 return url.substr(URL_PREFIX.length).split("/")[0]; |
|
39 } |
|
40 |
|
41 // url constructed with %PRODUCT% |
|
42 function run_test_pt1() { |
|
43 gCheckFunc = check_test_pt1; |
|
44 var url = URL_PREFIX + "%PRODUCT%/"; |
|
45 logTestInfo("testing url constructed with %PRODUCT% - " + url); |
|
46 setUpdateURLOverride(url); |
|
47 gUpdateChecker.checkForUpdates(updateCheckListener, true); |
|
48 } |
|
49 |
|
50 function check_test_pt1() { |
|
51 do_check_eq(getResult(gRequestURL), gAppInfo.name); |
|
52 run_test_pt2(); |
|
53 } |
|
54 |
|
55 // url constructed with %VERSION% |
|
56 function run_test_pt2() { |
|
57 gCheckFunc = check_test_pt2; |
|
58 var url = URL_PREFIX + "%VERSION%/"; |
|
59 logTestInfo("testing url constructed with %VERSION% - " + url); |
|
60 setUpdateURLOverride(url); |
|
61 gUpdateChecker.checkForUpdates(updateCheckListener, true); |
|
62 } |
|
63 |
|
64 function check_test_pt2() { |
|
65 do_check_eq(getResult(gRequestURL), gAppInfo.version); |
|
66 run_test_pt3(); |
|
67 } |
|
68 |
|
69 // url constructed with %BUILD_ID% |
|
70 function run_test_pt3() { |
|
71 gCheckFunc = check_test_pt3; |
|
72 var url = URL_PREFIX + "%BUILD_ID%/"; |
|
73 logTestInfo("testing url constructed with %BUILD_ID% - " + url); |
|
74 setUpdateURLOverride(url); |
|
75 gUpdateChecker.checkForUpdates(updateCheckListener, true); |
|
76 } |
|
77 |
|
78 function check_test_pt3() { |
|
79 do_check_eq(getResult(gRequestURL), gAppInfo.appBuildID); |
|
80 run_test_pt4(); |
|
81 } |
|
82 |
|
83 // url constructed with %BUILD_TARGET% |
|
84 // XXX TODO - it might be nice if we tested the actual ABI |
|
85 function run_test_pt4() { |
|
86 gCheckFunc = check_test_pt4; |
|
87 var url = URL_PREFIX + "%BUILD_TARGET%/"; |
|
88 logTestInfo("testing url constructed with %BUILD_TARGET% - " + url); |
|
89 setUpdateURLOverride(url); |
|
90 gUpdateChecker.checkForUpdates(updateCheckListener, true); |
|
91 } |
|
92 |
|
93 function check_test_pt4() { |
|
94 var abi; |
|
95 try { |
|
96 abi = gAppInfo.XPCOMABI; |
|
97 } catch (e) { |
|
98 do_throw("nsIXULAppInfo:XPCOMABI not defined\n"); |
|
99 } |
|
100 |
|
101 if (IS_MACOSX) { |
|
102 // Mac universal build should report a different ABI than either macppc |
|
103 // or mactel. This is necessary since nsUpdateService.js will set the ABI to |
|
104 // Universal-gcc3 for Mac universal builds. |
|
105 var macutils = AUS_Cc["@mozilla.org/xpcom/mac-utils;1"]. |
|
106 getService(AUS_Ci.nsIMacUtils); |
|
107 |
|
108 if (macutils.isUniversalBinary) |
|
109 abi += "-u-" + macutils.architecturesInBinary; |
|
110 if (IS_SHARK) { |
|
111 // Disambiguate optimised and shark nightlies |
|
112 abi += "-shark" |
|
113 } |
|
114 |
|
115 } |
|
116 |
|
117 do_check_eq(getResult(gRequestURL), gAppInfo.OS + "_" + abi); |
|
118 run_test_pt5(); |
|
119 } |
|
120 |
|
121 // url constructed with %LOCALE% |
|
122 // Bug 488936 added the update.locale file that stores the update locale |
|
123 function run_test_pt5() { |
|
124 gCheckFunc = check_test_pt5; |
|
125 var url = URL_PREFIX + "%LOCALE%/"; |
|
126 logTestInfo("testing url constructed with %LOCALE% - " + url); |
|
127 setUpdateURLOverride(url); |
|
128 try { |
|
129 gUpdateChecker.checkForUpdates(updateCheckListener, true); |
|
130 } catch (e) { |
|
131 logTestInfo("The following error is most likely due to a missing " + |
|
132 "update.locale file"); |
|
133 do_throw(e); |
|
134 } |
|
135 } |
|
136 |
|
137 function check_test_pt5() { |
|
138 do_check_eq(getResult(gRequestURL), INSTALL_LOCALE); |
|
139 run_test_pt6(); |
|
140 } |
|
141 |
|
142 // url constructed with %CHANNEL% |
|
143 function run_test_pt6() { |
|
144 gCheckFunc = check_test_pt6; |
|
145 var url = URL_PREFIX + "%CHANNEL%/"; |
|
146 logTestInfo("testing url constructed with %CHANNEL% - " + url); |
|
147 setUpdateURLOverride(url); |
|
148 setUpdateChannel("test_channel"); |
|
149 gUpdateChecker.checkForUpdates(updateCheckListener, true); |
|
150 } |
|
151 |
|
152 function check_test_pt6() { |
|
153 do_check_eq(getResult(gRequestURL), "test_channel"); |
|
154 run_test_pt7(); |
|
155 } |
|
156 |
|
157 // url constructed with %CHANNEL% with distribution partners |
|
158 function run_test_pt7() { |
|
159 gCheckFunc = check_test_pt7; |
|
160 var url = URL_PREFIX + "%CHANNEL%/"; |
|
161 logTestInfo("testing url constructed with %CHANNEL% - " + url); |
|
162 setUpdateURLOverride(url); |
|
163 gDefaultPrefBranch.setCharPref(PREF_APP_PARTNER_BRANCH + "test_partner1", "test_partner1"); |
|
164 gDefaultPrefBranch.setCharPref(PREF_APP_PARTNER_BRANCH + "test_partner2", "test_partner2"); |
|
165 gUpdateChecker.checkForUpdates(updateCheckListener, true); |
|
166 } |
|
167 |
|
168 function check_test_pt7() { |
|
169 do_check_eq(getResult(gRequestURL), "test_channel-cck-test_partner1-test_partner2"); |
|
170 run_test_pt8(); |
|
171 } |
|
172 |
|
173 // url constructed with %PLATFORM_VERSION% |
|
174 function run_test_pt8() { |
|
175 gCheckFunc = check_test_pt8; |
|
176 var url = URL_PREFIX + "%PLATFORM_VERSION%/"; |
|
177 logTestInfo("testing url constructed with %PLATFORM_VERSION% - " + url); |
|
178 setUpdateURLOverride(url); |
|
179 gUpdateChecker.checkForUpdates(updateCheckListener, true); |
|
180 } |
|
181 |
|
182 function check_test_pt8() { |
|
183 do_check_eq(getResult(gRequestURL), gAppInfo.platformVersion); |
|
184 run_test_pt9(); |
|
185 } |
|
186 |
|
187 // url constructed with %OS_VERSION% |
|
188 function run_test_pt9() { |
|
189 gCheckFunc = check_test_pt9; |
|
190 var url = URL_PREFIX + "%OS_VERSION%/"; |
|
191 logTestInfo("testing url constructed with %OS_VERSION% - " + url); |
|
192 setUpdateURLOverride(url); |
|
193 gUpdateChecker.checkForUpdates(updateCheckListener, true); |
|
194 } |
|
195 |
|
196 function getServicePack() { |
|
197 // NOTE: This function is a helper function and not a test. Thus, |
|
198 // it uses throw() instead of do_throw(). Any tests that use this function |
|
199 // should catch exceptions thrown in this function and deal with them |
|
200 // appropriately (usually by calling do_throw). |
|
201 const BYTE = ctypes.uint8_t; |
|
202 const WORD = ctypes.uint16_t; |
|
203 const DWORD = ctypes.uint32_t; |
|
204 const WCHAR = ctypes.jschar; |
|
205 const BOOL = ctypes.int; |
|
206 |
|
207 // This structure is described at: |
|
208 // http://msdn.microsoft.com/en-us/library/ms724833%28v=vs.85%29.aspx |
|
209 const SZCSDVERSIONLENGTH = 128; |
|
210 const OSVERSIONINFOEXW = new ctypes.StructType('OSVERSIONINFOEXW', |
|
211 [ |
|
212 {dwOSVersionInfoSize: DWORD}, |
|
213 {dwMajorVersion: DWORD}, |
|
214 {dwMinorVersion: DWORD}, |
|
215 {dwBuildNumber: DWORD}, |
|
216 {dwPlatformId: DWORD}, |
|
217 {szCSDVersion: ctypes.ArrayType(WCHAR, SZCSDVERSIONLENGTH)}, |
|
218 {wServicePackMajor: WORD}, |
|
219 {wServicePackMinor: WORD}, |
|
220 {wSuiteMask: WORD}, |
|
221 {wProductType: BYTE}, |
|
222 {wReserved: BYTE} |
|
223 ]); |
|
224 |
|
225 let kernel32 = ctypes.open("kernel32"); |
|
226 try { |
|
227 let GetVersionEx = kernel32.declare("GetVersionExW", |
|
228 ctypes.default_abi, |
|
229 BOOL, |
|
230 OSVERSIONINFOEXW.ptr); |
|
231 let winVer = OSVERSIONINFOEXW(); |
|
232 winVer.dwOSVersionInfoSize = OSVERSIONINFOEXW.size; |
|
233 |
|
234 if(0 === GetVersionEx(winVer.address())) { |
|
235 // Using "throw" instead of "do_throw" (see NOTE above) |
|
236 throw("Failure in GetVersionEx (returned 0)"); |
|
237 } |
|
238 |
|
239 return winVer.wServicePackMajor + "." + winVer.wServicePackMinor; |
|
240 } finally { |
|
241 kernel32.close(); |
|
242 } |
|
243 } |
|
244 |
|
245 function getProcArchitecture() { |
|
246 // NOTE: This function is a helper function and not a test. Thus, |
|
247 // it uses throw() instead of do_throw(). Any tests that use this function |
|
248 // should catch exceptions thrown in this function and deal with them |
|
249 // appropriately (usually by calling do_throw). |
|
250 const WORD = ctypes.uint16_t; |
|
251 const DWORD = ctypes.uint32_t; |
|
252 |
|
253 // This structure is described at: |
|
254 // http://msdn.microsoft.com/en-us/library/ms724958%28v=vs.85%29.aspx |
|
255 const SYSTEM_INFO = new ctypes.StructType('SYSTEM_INFO', |
|
256 [ |
|
257 {wProcessorArchitecture: WORD}, |
|
258 {wReserved: WORD}, |
|
259 {dwPageSize: DWORD}, |
|
260 {lpMinimumApplicationAddress: ctypes.voidptr_t}, |
|
261 {lpMaximumApplicationAddress: ctypes.voidptr_t}, |
|
262 {dwActiveProcessorMask: DWORD.ptr}, |
|
263 {dwNumberOfProcessors: DWORD}, |
|
264 {dwProcessorType: DWORD}, |
|
265 {dwAllocationGranularity: DWORD}, |
|
266 {wProcessorLevel: WORD}, |
|
267 {wProcessorRevision: WORD} |
|
268 ]); |
|
269 |
|
270 let kernel32 = ctypes.open("kernel32"); |
|
271 try { |
|
272 let GetNativeSystemInfo = kernel32.declare("GetNativeSystemInfo", |
|
273 ctypes.default_abi, |
|
274 ctypes.void_t, |
|
275 SYSTEM_INFO.ptr); |
|
276 let sysInfo = SYSTEM_INFO(); |
|
277 // Default to unknown |
|
278 sysInfo.wProcessorArchitecture = 0xffff; |
|
279 |
|
280 GetNativeSystemInfo(sysInfo.address()); |
|
281 switch(sysInfo.wProcessorArchitecture) { |
|
282 case 9: |
|
283 return "x64"; |
|
284 case 6: |
|
285 return "IA64"; |
|
286 case 0: |
|
287 return "x86"; |
|
288 default: |
|
289 // Using "throw" instead of "do_throw" (see NOTE above) |
|
290 throw("Unknown architecture returned from GetNativeSystemInfo: " + sysInfo.wProcessorArchitecture); |
|
291 } |
|
292 } finally { |
|
293 kernel32.close(); |
|
294 } |
|
295 } |
|
296 |
|
297 function check_test_pt9() { |
|
298 var osVersion; |
|
299 var sysInfo = AUS_Cc["@mozilla.org/system-info;1"]. |
|
300 getService(AUS_Ci.nsIPropertyBag2); |
|
301 osVersion = sysInfo.getProperty("name") + " " + sysInfo.getProperty("version"); |
|
302 |
|
303 if(IS_WIN) { |
|
304 try { |
|
305 let servicePack = getServicePack(); |
|
306 osVersion += "." + servicePack; |
|
307 } catch (e) { |
|
308 do_throw("Failure obtaining service pack: " + e); |
|
309 } |
|
310 |
|
311 if("5.0" === sysInfo.getProperty("version")) { // Win2K |
|
312 osVersion += " (unknown)"; |
|
313 } else { |
|
314 try { |
|
315 osVersion += " (" + getProcArchitecture() + ")"; |
|
316 } catch (e) { |
|
317 do_throw("Failed to obtain processor architecture: " + e); |
|
318 } |
|
319 } |
|
320 } |
|
321 |
|
322 if (osVersion) { |
|
323 try { |
|
324 osVersion += " (" + sysInfo.getProperty("secondaryLibrary") + ")"; |
|
325 } catch (e) { |
|
326 // Not all platforms have a secondary widget library, so an error is |
|
327 // nothing to worry about. |
|
328 } |
|
329 osVersion = encodeURIComponent(osVersion); |
|
330 } |
|
331 |
|
332 do_check_eq(getResult(gRequestURL), osVersion); |
|
333 run_test_pt10(); |
|
334 } |
|
335 |
|
336 // url constructed with %DISTRIBUTION% |
|
337 function run_test_pt10() { |
|
338 gCheckFunc = check_test_pt10; |
|
339 var url = URL_PREFIX + "%DISTRIBUTION%/"; |
|
340 logTestInfo("testing url constructed with %DISTRIBUTION% - " + url); |
|
341 setUpdateURLOverride(url); |
|
342 gDefaultPrefBranch.setCharPref(PREF_DISTRIBUTION_ID, "test_distro"); |
|
343 gUpdateChecker.checkForUpdates(updateCheckListener, true); |
|
344 } |
|
345 |
|
346 function check_test_pt10() { |
|
347 do_check_eq(getResult(gRequestURL), "test_distro"); |
|
348 run_test_pt11(); |
|
349 } |
|
350 |
|
351 // url constructed with %DISTRIBUTION_VERSION% |
|
352 function run_test_pt11() { |
|
353 gCheckFunc = check_test_pt11; |
|
354 var url = URL_PREFIX + "%DISTRIBUTION_VERSION%/"; |
|
355 logTestInfo("testing url constructed with %DISTRIBUTION_VERSION% - " + url); |
|
356 setUpdateURLOverride(url); |
|
357 gDefaultPrefBranch.setCharPref(PREF_DISTRIBUTION_VERSION, "test_distro_version"); |
|
358 gUpdateChecker.checkForUpdates(updateCheckListener, true); |
|
359 } |
|
360 |
|
361 function check_test_pt11() { |
|
362 do_check_eq(getResult(gRequestURL), "test_distro_version"); |
|
363 run_test_pt12(); |
|
364 } |
|
365 |
|
366 // url with force param that doesn't already have a param - bug 454357 |
|
367 function run_test_pt12() { |
|
368 gCheckFunc = check_test_pt12; |
|
369 var url = URL_PREFIX; |
|
370 logTestInfo("testing url with force param that doesn't already have a " + |
|
371 "param - " + url); |
|
372 setUpdateURLOverride(url); |
|
373 gUpdateChecker.checkForUpdates(updateCheckListener, true); |
|
374 } |
|
375 |
|
376 function check_test_pt12() { |
|
377 do_check_eq(getResult(gRequestURL), "?force=1"); |
|
378 run_test_pt13(); |
|
379 } |
|
380 |
|
381 // url with force param that already has a param - bug 454357 |
|
382 function run_test_pt13() { |
|
383 gCheckFunc = check_test_pt13; |
|
384 var url = URL_PREFIX + "?extra=param"; |
|
385 logTestInfo("testing url with force param that already has a param - " + url); |
|
386 logTestInfo("testing url constructed that has a parameter - " + url); |
|
387 setUpdateURLOverride(url); |
|
388 gUpdateChecker.checkForUpdates(updateCheckListener, true); |
|
389 } |
|
390 |
|
391 function check_test_pt13() { |
|
392 do_check_eq(getResult(gRequestURL), "?extra=param&force=1"); |
|
393 run_test_pt14(); |
|
394 } |
|
395 |
|
396 function run_test_pt14() { |
|
397 Services.prefs.setCharPref("app.update.custom", "custom"); |
|
398 gCheckFunc = check_test_pt14; |
|
399 var url = URL_PREFIX + "?custom=%CUSTOM%"; |
|
400 logTestInfo("testing url constructed with %CUSTOM% - " + url); |
|
401 setUpdateURLOverride(url); |
|
402 gUpdateChecker.checkForUpdates(updateCheckListener, true); |
|
403 } |
|
404 |
|
405 function check_test_pt14() { |
|
406 do_check_eq(getResult(gRequestURL), "?custom=custom&force=1"); |
|
407 doTestFinish(); |
|
408 } |