toolkit/mozapps/update/tests/unit_aus_update/urlConstruction.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

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

mercurial