Sat, 03 Jan 2015 20:18:00 +0100
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 | var gNextRunFunc; |
michael@0 | 7 | var gExpectedCount; |
michael@0 | 8 | |
michael@0 | 9 | function run_test() { |
michael@0 | 10 | setupTestCommon(); |
michael@0 | 11 | |
michael@0 | 12 | logTestInfo("testing remote update xml attributes"); |
michael@0 | 13 | |
michael@0 | 14 | setUpdateURLOverride(); |
michael@0 | 15 | setUpdateChannel("test_channel"); |
michael@0 | 16 | // The mock XMLHttpRequest is MUCH faster |
michael@0 | 17 | overrideXHR(callHandleEvent); |
michael@0 | 18 | standardInit(); |
michael@0 | 19 | do_execute_soon(run_test_pt01); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | // Helper function for testing update counts returned from an update xml |
michael@0 | 23 | function run_test_helper_pt1(aMsg, aExpectedCount, aNextRunFunc) { |
michael@0 | 24 | gUpdates = null; |
michael@0 | 25 | gUpdateCount = null; |
michael@0 | 26 | gCheckFunc = check_test_helper_pt1; |
michael@0 | 27 | gNextRunFunc = aNextRunFunc; |
michael@0 | 28 | gExpectedCount = aExpectedCount; |
michael@0 | 29 | logTestInfo(aMsg, Components.stack.caller); |
michael@0 | 30 | gUpdateChecker.checkForUpdates(updateCheckListener, true); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | function check_test_helper_pt1() { |
michael@0 | 34 | do_check_eq(gUpdateCount, gExpectedCount); |
michael@0 | 35 | gNextRunFunc(); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | // Callback function used by the custom XMLHttpRequest implementation to |
michael@0 | 39 | // call the nsIDOMEventListener's handleEvent method for onload. |
michael@0 | 40 | function callHandleEvent() { |
michael@0 | 41 | gXHR.status = 400; |
michael@0 | 42 | gXHR.responseText = gResponseBody; |
michael@0 | 43 | try { |
michael@0 | 44 | var parser = AUS_Cc["@mozilla.org/xmlextras/domparser;1"]. |
michael@0 | 45 | createInstance(AUS_Ci.nsIDOMParser); |
michael@0 | 46 | gXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml"); |
michael@0 | 47 | } catch (e) { |
michael@0 | 48 | gXHR.responseXML = null; |
michael@0 | 49 | } |
michael@0 | 50 | var e = { target: gXHR }; |
michael@0 | 51 | gXHR.onload(e); |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | // update xml not found |
michael@0 | 55 | function run_test_pt01() { |
michael@0 | 56 | run_test_helper_pt1("testing update xml not available", |
michael@0 | 57 | null, run_test_pt02); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | // one update available and the update's property values |
michael@0 | 61 | function run_test_pt02() { |
michael@0 | 62 | logTestInfo("testing one update available and the update's property values"); |
michael@0 | 63 | gUpdates = null; |
michael@0 | 64 | gUpdateCount = null; |
michael@0 | 65 | gCheckFunc = check_test_pt02; |
michael@0 | 66 | var patches = getRemotePatchString("complete", "http://complete/", "SHA1", |
michael@0 | 67 | "98db9dad8e1d80eda7e1170d0187d6f53e477059", |
michael@0 | 68 | "9856459"); |
michael@0 | 69 | patches += getRemotePatchString("partial", "http://partial/", "SHA1", |
michael@0 | 70 | "e6678ca40ae7582316acdeddf3c133c9c8577de4", |
michael@0 | 71 | "1316138"); |
michael@0 | 72 | var updates = getRemoteUpdateString(patches, "minor", "Minor Test", |
michael@0 | 73 | "version 2.1a1pre", "2.1a1pre", |
michael@0 | 74 | "3.1a1pre", "20080811053724", |
michael@0 | 75 | "http://details/", |
michael@0 | 76 | "http://billboard/", |
michael@0 | 77 | "http://license/", "true", |
michael@0 | 78 | "true", "345600", "true", "4.1a1pre", |
michael@0 | 79 | "5.1a1pre", |
michael@0 | 80 | "custom1_attr=\"custom1 value\"", |
michael@0 | 81 | "custom2_attr=\"custom2 value\""); |
michael@0 | 82 | gResponseBody = getRemoteUpdatesXMLString(updates); |
michael@0 | 83 | gUpdateChecker.checkForUpdates(updateCheckListener, true); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | function check_test_pt02() { |
michael@0 | 87 | // XXXrstrong - not specifying a detailsURL will cause a leak due to bug 470244 |
michael@0 | 88 | // and until this is fixed this will not test the value for detailsURL when it |
michael@0 | 89 | // isn't specified in the update xml. |
michael@0 | 90 | // var defaultDetailsURL; |
michael@0 | 91 | // try { |
michael@0 | 92 | // Try using a default details URL supplied by the distribution |
michael@0 | 93 | // if the update XML does not supply one. |
michael@0 | 94 | // var formatter = AUS_Cc["@mozilla.org/toolkit/URLFormatterService;1"]. |
michael@0 | 95 | // getService(AUS_Ci.nsIURLFormatter); |
michael@0 | 96 | // defaultDetailsURL = formatter.formatURLPref(PREF_APP_UPDATE_URL_DETAILS); |
michael@0 | 97 | // } catch (e) { |
michael@0 | 98 | // defaultDetailsURL = ""; |
michael@0 | 99 | // } |
michael@0 | 100 | |
michael@0 | 101 | do_check_eq(gUpdateCount, 1); |
michael@0 | 102 | var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount).QueryInterface(AUS_Ci.nsIPropertyBag); |
michael@0 | 103 | do_check_eq(bestUpdate.type, "minor"); |
michael@0 | 104 | do_check_eq(bestUpdate.name, "Minor Test"); |
michael@0 | 105 | do_check_eq(bestUpdate.displayVersion, "version 2.1a1pre"); |
michael@0 | 106 | do_check_eq(bestUpdate.appVersion, "2.1a1pre"); |
michael@0 | 107 | do_check_eq(bestUpdate.platformVersion, "3.1a1pre"); |
michael@0 | 108 | do_check_eq(bestUpdate.buildID, "20080811053724"); |
michael@0 | 109 | do_check_eq(bestUpdate.detailsURL, "http://details/"); |
michael@0 | 110 | do_check_eq(bestUpdate.billboardURL, "http://billboard/"); |
michael@0 | 111 | do_check_eq(bestUpdate.licenseURL, "http://license/"); |
michael@0 | 112 | do_check_true(bestUpdate.showPrompt); |
michael@0 | 113 | do_check_true(bestUpdate.showNeverForVersion); |
michael@0 | 114 | do_check_eq(bestUpdate.promptWaitTime, "345600"); |
michael@0 | 115 | do_check_eq(bestUpdate.serviceURL, URL_HOST + "/update.xml?force=1"); |
michael@0 | 116 | do_check_eq(bestUpdate.channel, "test_channel"); |
michael@0 | 117 | do_check_false(bestUpdate.isCompleteUpdate); |
michael@0 | 118 | do_check_false(bestUpdate.isSecurityUpdate); |
michael@0 | 119 | // Check that installDate is within 10 seconds of the current date. |
michael@0 | 120 | do_check_true((Date.now() - bestUpdate.installDate) < 10000); |
michael@0 | 121 | do_check_eq(bestUpdate.statusText, null); |
michael@0 | 122 | // nsIUpdate:state returns an empty string when no action has been performed |
michael@0 | 123 | // on an available update |
michael@0 | 124 | do_check_eq(bestUpdate.state, ""); |
michael@0 | 125 | do_check_eq(bestUpdate.errorCode, 0); |
michael@0 | 126 | do_check_eq(bestUpdate.patchCount, 2); |
michael@0 | 127 | //XXX TODO - test nsIUpdate:serialize |
michael@0 | 128 | |
michael@0 | 129 | do_check_eq(bestUpdate.getProperty("custom1_attr"), "custom1 value"); |
michael@0 | 130 | do_check_eq(bestUpdate.getProperty("custom2_attr"), "custom2 value"); |
michael@0 | 131 | |
michael@0 | 132 | var patch = bestUpdate.getPatchAt(0); |
michael@0 | 133 | do_check_eq(patch.type, "complete"); |
michael@0 | 134 | do_check_eq(patch.URL, "http://complete/"); |
michael@0 | 135 | do_check_eq(patch.hashFunction, "SHA1"); |
michael@0 | 136 | do_check_eq(patch.hashValue, "98db9dad8e1d80eda7e1170d0187d6f53e477059"); |
michael@0 | 137 | do_check_eq(patch.size, 9856459); |
michael@0 | 138 | // The value for patch.state can be the string 'null' as a valid value. This |
michael@0 | 139 | // is confusing if it returns null which is an invalid value since the test |
michael@0 | 140 | // failure output will show a failure for null == null. To lessen the |
michael@0 | 141 | // confusion first check that the typeof for patch.state is string. |
michael@0 | 142 | do_check_eq(typeof(patch.state), "string"); |
michael@0 | 143 | do_check_eq(patch.state, STATE_NONE); |
michael@0 | 144 | do_check_false(patch.selected); |
michael@0 | 145 | //XXX TODO - test nsIUpdatePatch:serialize |
michael@0 | 146 | |
michael@0 | 147 | patch = bestUpdate.getPatchAt(1); |
michael@0 | 148 | do_check_eq(patch.type, "partial"); |
michael@0 | 149 | do_check_eq(patch.URL, "http://partial/"); |
michael@0 | 150 | do_check_eq(patch.hashFunction, "SHA1"); |
michael@0 | 151 | do_check_eq(patch.hashValue, "e6678ca40ae7582316acdeddf3c133c9c8577de4"); |
michael@0 | 152 | do_check_eq(patch.size, 1316138); |
michael@0 | 153 | do_check_eq(patch.state, STATE_NONE); |
michael@0 | 154 | do_check_false(patch.selected); |
michael@0 | 155 | //XXX TODO - test nsIUpdatePatch:serialize |
michael@0 | 156 | |
michael@0 | 157 | run_test_pt03(); |
michael@0 | 158 | } |
michael@0 | 159 | |
michael@0 | 160 | // one update available and the update's property default values |
michael@0 | 161 | function run_test_pt03() { |
michael@0 | 162 | logTestInfo("testing one update available and the update's property values " + |
michael@0 | 163 | "with the format prior to bug 530872"); |
michael@0 | 164 | gUpdates = null; |
michael@0 | 165 | gUpdateCount = null; |
michael@0 | 166 | gCheckFunc = check_test_pt03; |
michael@0 | 167 | var patches = getRemotePatchString("complete", "http://complete/", "SHA1", |
michael@0 | 168 | "98db9dad8e1d80eda7e1170d0187d6f53e477059", |
michael@0 | 169 | "9856459"); |
michael@0 | 170 | var updates = getRemoteUpdateString(patches, "major", "Major Test", |
michael@0 | 171 | null, null, |
michael@0 | 172 | "5.1a1pre", "20080811053724", |
michael@0 | 173 | "http://details/", |
michael@0 | 174 | null, null, null, null, "691200", |
michael@0 | 175 | null, "version 4.1a1pre", "4.1a1pre"); |
michael@0 | 176 | gResponseBody = getRemoteUpdatesXMLString(updates); |
michael@0 | 177 | gUpdateChecker.checkForUpdates(updateCheckListener, true); |
michael@0 | 178 | } |
michael@0 | 179 | |
michael@0 | 180 | function check_test_pt03() { |
michael@0 | 181 | do_check_eq(gUpdateCount, 1); |
michael@0 | 182 | var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount); |
michael@0 | 183 | do_check_eq(bestUpdate.type, "major"); |
michael@0 | 184 | do_check_eq(bestUpdate.name, "Major Test"); |
michael@0 | 185 | do_check_eq(bestUpdate.displayVersion, "version 4.1a1pre"); |
michael@0 | 186 | do_check_eq(bestUpdate.appVersion, "4.1a1pre"); |
michael@0 | 187 | do_check_eq(bestUpdate.platformVersion, "5.1a1pre"); |
michael@0 | 188 | do_check_eq(bestUpdate.buildID, "20080811053724"); |
michael@0 | 189 | do_check_eq(bestUpdate.detailsURL, "http://details/"); |
michael@0 | 190 | do_check_eq(bestUpdate.billboardURL, "http://details/"); |
michael@0 | 191 | do_check_eq(bestUpdate.licenseURL, null); |
michael@0 | 192 | do_check_true(bestUpdate.showPrompt); |
michael@0 | 193 | do_check_true(bestUpdate.showNeverForVersion); |
michael@0 | 194 | do_check_eq(bestUpdate.promptWaitTime, "691200"); |
michael@0 | 195 | do_check_eq(bestUpdate.serviceURL, URL_HOST + "/update.xml?force=1"); |
michael@0 | 196 | do_check_eq(bestUpdate.channel, "test_channel"); |
michael@0 | 197 | do_check_false(bestUpdate.isCompleteUpdate); |
michael@0 | 198 | do_check_false(bestUpdate.isSecurityUpdate); |
michael@0 | 199 | // Check that installDate is within 10 seconds of the current date. |
michael@0 | 200 | do_check_true((Date.now() - bestUpdate.installDate) < 10000); |
michael@0 | 201 | do_check_eq(bestUpdate.statusText, null); |
michael@0 | 202 | // nsIUpdate:state returns an empty string when no action has been performed |
michael@0 | 203 | // on an available update |
michael@0 | 204 | do_check_eq(bestUpdate.state, ""); |
michael@0 | 205 | do_check_eq(bestUpdate.errorCode, 0); |
michael@0 | 206 | do_check_eq(bestUpdate.patchCount, 1); |
michael@0 | 207 | //XXX TODO - test nsIUpdate:serialize |
michael@0 | 208 | |
michael@0 | 209 | var patch = bestUpdate.getPatchAt(0); |
michael@0 | 210 | do_check_eq(patch.type, "complete"); |
michael@0 | 211 | do_check_eq(patch.URL, "http://complete/"); |
michael@0 | 212 | do_check_eq(patch.hashFunction, "SHA1"); |
michael@0 | 213 | do_check_eq(patch.hashValue, "98db9dad8e1d80eda7e1170d0187d6f53e477059"); |
michael@0 | 214 | do_check_eq(patch.size, 9856459); |
michael@0 | 215 | // The value for patch.state can be the string 'null' as a valid value. This |
michael@0 | 216 | // is confusing if it returns null which is an invalid value since the test |
michael@0 | 217 | // failure output will show a failure for null == null. To lessen the |
michael@0 | 218 | // confusion first check that the typeof for patch.state is string. |
michael@0 | 219 | do_check_eq(typeof(patch.state), "string"); |
michael@0 | 220 | do_check_eq(patch.state, STATE_NONE); |
michael@0 | 221 | do_check_false(patch.selected); |
michael@0 | 222 | //XXX TODO - test nsIUpdatePatch:serialize |
michael@0 | 223 | |
michael@0 | 224 | run_test_pt04(); |
michael@0 | 225 | } |
michael@0 | 226 | |
michael@0 | 227 | // Empty update xml |
michael@0 | 228 | function run_test_pt04() { |
michael@0 | 229 | gResponseBody = "\n"; |
michael@0 | 230 | run_test_helper_pt1("testing empty update xml", |
michael@0 | 231 | null, run_test_pt05); |
michael@0 | 232 | } |
michael@0 | 233 | |
michael@0 | 234 | // no updates available |
michael@0 | 235 | function run_test_pt05() { |
michael@0 | 236 | gResponseBody = getRemoteUpdatesXMLString(""); |
michael@0 | 237 | run_test_helper_pt1("testing no updates available", |
michael@0 | 238 | 0, run_test_pt06); |
michael@0 | 239 | } |
michael@0 | 240 | |
michael@0 | 241 | // one update available with two patches |
michael@0 | 242 | function run_test_pt06() { |
michael@0 | 243 | var patches = getRemotePatchString("complete"); |
michael@0 | 244 | patches += getRemotePatchString("partial"); |
michael@0 | 245 | var updates = getRemoteUpdateString(patches); |
michael@0 | 246 | gResponseBody = getRemoteUpdatesXMLString(updates); |
michael@0 | 247 | run_test_helper_pt1("testing one update available", |
michael@0 | 248 | 1, run_test_pt07); |
michael@0 | 249 | } |
michael@0 | 250 | |
michael@0 | 251 | // three updates available each with two patches |
michael@0 | 252 | function run_test_pt07() { |
michael@0 | 253 | var patches = getRemotePatchString("complete"); |
michael@0 | 254 | patches += getRemotePatchString("partial"); |
michael@0 | 255 | var updates = getRemoteUpdateString(patches); |
michael@0 | 256 | updates += getRemoteUpdateString(patches); |
michael@0 | 257 | updates += getRemoteUpdateString(patches); |
michael@0 | 258 | gResponseBody = getRemoteUpdatesXMLString(updates); |
michael@0 | 259 | run_test_helper_pt1("testing three updates available", |
michael@0 | 260 | 3, run_test_pt08); |
michael@0 | 261 | } |
michael@0 | 262 | |
michael@0 | 263 | // one update with complete and partial patches with size 0 specified in the |
michael@0 | 264 | // update xml |
michael@0 | 265 | function run_test_pt08() { |
michael@0 | 266 | var patches = getRemotePatchString("complete", null, null, null, "0"); |
michael@0 | 267 | patches += getRemotePatchString("partial", null, null, null, "0"); |
michael@0 | 268 | var updates = getRemoteUpdateString(patches); |
michael@0 | 269 | gResponseBody = getRemoteUpdatesXMLString(updates); |
michael@0 | 270 | run_test_helper_pt1("testing one update with complete and partial " + |
michael@0 | 271 | "patches with size 0", 0, run_test_pt09); |
michael@0 | 272 | } |
michael@0 | 273 | |
michael@0 | 274 | // one update with complete patch with size 0 specified in the update xml |
michael@0 | 275 | function run_test_pt09() { |
michael@0 | 276 | var patches = getRemotePatchString("complete", null, null, null, "0"); |
michael@0 | 277 | var updates = getRemoteUpdateString(patches); |
michael@0 | 278 | gResponseBody = getRemoteUpdatesXMLString(updates); |
michael@0 | 279 | run_test_helper_pt1("testing one update with complete patch with size 0", |
michael@0 | 280 | 0, run_test_pt10); |
michael@0 | 281 | } |
michael@0 | 282 | |
michael@0 | 283 | // one update with partial patch with size 0 specified in the update xml |
michael@0 | 284 | function run_test_pt10() { |
michael@0 | 285 | var patches = getRemotePatchString("partial", null, null, null, "0"); |
michael@0 | 286 | var updates = getRemoteUpdateString(patches); |
michael@0 | 287 | gResponseBody = getRemoteUpdatesXMLString(updates); |
michael@0 | 288 | run_test_helper_pt1("testing one update with partial patch with size 0", |
michael@0 | 289 | 0, run_test_pt11); |
michael@0 | 290 | } |
michael@0 | 291 | |
michael@0 | 292 | // check that updates for older versions of the application aren't selected |
michael@0 | 293 | function run_test_pt11() { |
michael@0 | 294 | var patches = getRemotePatchString("complete"); |
michael@0 | 295 | patches += getRemotePatchString("partial"); |
michael@0 | 296 | var updates = getRemoteUpdateString(patches, "minor", null, null, "1.0pre"); |
michael@0 | 297 | updates += getRemoteUpdateString(patches, "minor", null, null, "1.0a"); |
michael@0 | 298 | gResponseBody = getRemoteUpdatesXMLString(updates); |
michael@0 | 299 | run_test_helper_pt1("testing two updates older than the current version", |
michael@0 | 300 | 2, check_test_pt11); |
michael@0 | 301 | } |
michael@0 | 302 | |
michael@0 | 303 | function check_test_pt11() { |
michael@0 | 304 | var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount); |
michael@0 | 305 | do_check_eq(bestUpdate, null); |
michael@0 | 306 | run_test_pt12(); |
michael@0 | 307 | } |
michael@0 | 308 | |
michael@0 | 309 | // check that updates for the current version of the application are selected |
michael@0 | 310 | function run_test_pt12() { |
michael@0 | 311 | var patches = getRemotePatchString("complete"); |
michael@0 | 312 | patches += getRemotePatchString("partial"); |
michael@0 | 313 | var updates = getRemoteUpdateString(patches, "minor", null, "version 1.0"); |
michael@0 | 314 | gResponseBody = getRemoteUpdatesXMLString(updates); |
michael@0 | 315 | run_test_helper_pt1("testing one update equal to the current version", |
michael@0 | 316 | 1, check_test_pt12); |
michael@0 | 317 | } |
michael@0 | 318 | |
michael@0 | 319 | function check_test_pt12() { |
michael@0 | 320 | var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount); |
michael@0 | 321 | do_check_neq(bestUpdate, null); |
michael@0 | 322 | do_check_eq(bestUpdate.displayVersion, "version 1.0"); |
michael@0 | 323 | |
michael@0 | 324 | doTestFinish(); |
michael@0 | 325 | } |