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 gExpectedStatusResult; |
michael@0 | 8 | |
michael@0 | 9 | function run_test() { |
michael@0 | 10 | // This test needs access to omni.ja to read the update.locale file so don't |
michael@0 | 11 | // use a custom directory for the application directory. |
michael@0 | 12 | gUseTestAppDir = false; |
michael@0 | 13 | setupTestCommon(); |
michael@0 | 14 | |
michael@0 | 15 | logTestInfo("testing mar download and mar hash verification"); |
michael@0 | 16 | |
michael@0 | 17 | Services.prefs.setBoolPref(PREF_APP_UPDATE_STAGING_ENABLED, false); |
michael@0 | 18 | // The HTTP server is only used for the mar file downloads since it is slow |
michael@0 | 19 | start_httpserver(); |
michael@0 | 20 | setUpdateURLOverride(gURLData + "update.xml"); |
michael@0 | 21 | // The mock XMLHttpRequest is MUCH faster |
michael@0 | 22 | overrideXHR(callHandleEvent); |
michael@0 | 23 | standardInit(); |
michael@0 | 24 | do_execute_soon(run_test_pt1); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | // The HttpServer must be stopped before calling do_test_finished |
michael@0 | 28 | function finish_test() { |
michael@0 | 29 | stop_httpserver(doTestFinish); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | // Callback function used by the custom XMLHttpRequest implementation to |
michael@0 | 33 | // call the nsIDOMEventListener's handleEvent method for onload. |
michael@0 | 34 | function callHandleEvent() { |
michael@0 | 35 | gXHR.status = 400; |
michael@0 | 36 | gXHR.responseText = gResponseBody; |
michael@0 | 37 | try { |
michael@0 | 38 | var parser = AUS_Cc["@mozilla.org/xmlextras/domparser;1"]. |
michael@0 | 39 | createInstance(AUS_Ci.nsIDOMParser); |
michael@0 | 40 | gXHR.responseXML = parser.parseFromString(gResponseBody, "application/xml"); |
michael@0 | 41 | } catch(e) { |
michael@0 | 42 | } |
michael@0 | 43 | var e = { target: gXHR }; |
michael@0 | 44 | gXHR.onload(e); |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | // Helper function for testing mar downloads that have the correct size |
michael@0 | 48 | // specified in the update xml. |
michael@0 | 49 | function run_test_helper_pt1(aMsg, aExpectedStatusResult, aNextRunFunc) { |
michael@0 | 50 | gUpdates = null; |
michael@0 | 51 | gUpdateCount = null; |
michael@0 | 52 | gStatusResult = null; |
michael@0 | 53 | gCheckFunc = check_test_helper_pt1_1; |
michael@0 | 54 | gNextRunFunc = aNextRunFunc; |
michael@0 | 55 | gExpectedStatusResult = aExpectedStatusResult; |
michael@0 | 56 | logTestInfo(aMsg, Components.stack.caller); |
michael@0 | 57 | gUpdateChecker.checkForUpdates(updateCheckListener, true); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function check_test_helper_pt1_1() { |
michael@0 | 61 | do_check_eq(gUpdateCount, 1); |
michael@0 | 62 | gCheckFunc = check_test_helper_pt1_2; |
michael@0 | 63 | var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount); |
michael@0 | 64 | var state = gAUS.downloadUpdate(bestUpdate, false); |
michael@0 | 65 | if (state == STATE_NONE || state == STATE_FAILED) |
michael@0 | 66 | do_throw("nsIApplicationUpdateService:downloadUpdate returned " + state); |
michael@0 | 67 | gAUS.addDownloadListener(downloadListener); |
michael@0 | 68 | } |
michael@0 | 69 | |
michael@0 | 70 | function check_test_helper_pt1_2() { |
michael@0 | 71 | do_check_eq(gStatusResult, gExpectedStatusResult); |
michael@0 | 72 | gAUS.removeDownloadListener(downloadListener); |
michael@0 | 73 | gNextRunFunc(); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | // The following 3 functions are a workaround for GONK due to Bug 828858 and |
michael@0 | 77 | // can be removed after it is fixed and the callers are changed to use the |
michael@0 | 78 | // regular helper functions. |
michael@0 | 79 | function run_test_helper_bug828858_pt1(aMsg, aExpectedStatusResult, aNextRunFunc) { |
michael@0 | 80 | gUpdates = null; |
michael@0 | 81 | gUpdateCount = null; |
michael@0 | 82 | gStatusResult = null; |
michael@0 | 83 | gCheckFunc = check_test_helper_bug828858_pt1_1; |
michael@0 | 84 | gNextRunFunc = aNextRunFunc; |
michael@0 | 85 | gExpectedStatusResult = aExpectedStatusResult; |
michael@0 | 86 | logTestInfo(aMsg, Components.stack.caller); |
michael@0 | 87 | gUpdateChecker.checkForUpdates(updateCheckListener, true); |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | function check_test_helper_bug828858_pt1_1() { |
michael@0 | 91 | do_check_eq(gUpdateCount, 1); |
michael@0 | 92 | gCheckFunc = check_test_helper_bug828858_pt1_2; |
michael@0 | 93 | var bestUpdate = gAUS.selectUpdate(gUpdates, gUpdateCount); |
michael@0 | 94 | var state = gAUS.downloadUpdate(bestUpdate, false); |
michael@0 | 95 | if (state == STATE_NONE || state == STATE_FAILED) |
michael@0 | 96 | do_throw("nsIApplicationUpdateService:downloadUpdate returned " + state); |
michael@0 | 97 | gAUS.addDownloadListener(downloadListener); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | function check_test_helper_bug828858_pt1_2() { |
michael@0 | 101 | if (gStatusResult == AUS_Cr.NS_ERROR_CONTENT_CORRUPTED) { |
michael@0 | 102 | do_check_eq(gStatusResult, AUS_Cr.NS_ERROR_CONTENT_CORRUPTED); |
michael@0 | 103 | } else { |
michael@0 | 104 | do_check_eq(gStatusResult, gExpectedStatusResult); |
michael@0 | 105 | } |
michael@0 | 106 | gAUS.removeDownloadListener(downloadListener); |
michael@0 | 107 | gNextRunFunc(); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | function setResponseBody(aHashFunction, aHashValue, aSize) { |
michael@0 | 111 | var patches = getRemotePatchString(null, null, |
michael@0 | 112 | aHashFunction, aHashValue, aSize); |
michael@0 | 113 | var updates = getRemoteUpdateString(patches); |
michael@0 | 114 | gResponseBody = getRemoteUpdatesXMLString(updates); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | // mar download with a valid MD5 hash |
michael@0 | 118 | function run_test_pt1() { |
michael@0 | 119 | setResponseBody("MD5", MD5_HASH_SIMPLE_MAR); |
michael@0 | 120 | run_test_helper_pt1("mar download with a valid MD5 hash", |
michael@0 | 121 | AUS_Cr.NS_OK, run_test_pt2); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | // mar download with an invalid MD5 hash |
michael@0 | 125 | function run_test_pt2() { |
michael@0 | 126 | setResponseBody("MD5", MD5_HASH_SIMPLE_MAR + "0"); |
michael@0 | 127 | run_test_helper_pt1("mar download with an invalid MD5 hash", |
michael@0 | 128 | AUS_Cr.NS_ERROR_CORRUPTED_CONTENT, run_test_pt3); |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | // mar download with a valid SHA1 hash |
michael@0 | 132 | function run_test_pt3() { |
michael@0 | 133 | setResponseBody("SHA1", SHA1_HASH_SIMPLE_MAR); |
michael@0 | 134 | run_test_helper_pt1("mar download with a valid SHA1 hash", |
michael@0 | 135 | AUS_Cr.NS_OK, run_test_pt4); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | // mar download with an invalid SHA1 hash |
michael@0 | 139 | function run_test_pt4() { |
michael@0 | 140 | setResponseBody("SHA1", SHA1_HASH_SIMPLE_MAR + "0"); |
michael@0 | 141 | run_test_helper_pt1("mar download with an invalid SHA1 hash", |
michael@0 | 142 | AUS_Cr.NS_ERROR_CORRUPTED_CONTENT, run_test_pt5); |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | // mar download with a valid SHA256 hash |
michael@0 | 146 | function run_test_pt5() { |
michael@0 | 147 | setResponseBody("SHA256", SHA256_HASH_SIMPLE_MAR); |
michael@0 | 148 | run_test_helper_pt1("mar download with a valid SHA256 hash", |
michael@0 | 149 | AUS_Cr.NS_OK, run_test_pt6); |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | // mar download with an invalid SHA256 hash |
michael@0 | 153 | function run_test_pt6() { |
michael@0 | 154 | setResponseBody("SHA256", SHA256_HASH_SIMPLE_MAR + "0"); |
michael@0 | 155 | run_test_helper_pt1("mar download with an invalid SHA256 hash", |
michael@0 | 156 | AUS_Cr.NS_ERROR_CORRUPTED_CONTENT, run_test_pt7); |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | // mar download with a valid SHA384 hash |
michael@0 | 160 | function run_test_pt7() { |
michael@0 | 161 | setResponseBody("SHA384", SHA384_HASH_SIMPLE_MAR); |
michael@0 | 162 | run_test_helper_pt1("mar download with a valid SHA384 hash", |
michael@0 | 163 | AUS_Cr.NS_OK, run_test_pt8); |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | // mar download with an invalid SHA384 hash |
michael@0 | 167 | function run_test_pt8() { |
michael@0 | 168 | setResponseBody("SHA384", SHA384_HASH_SIMPLE_MAR + "0"); |
michael@0 | 169 | run_test_helper_pt1("mar download with an invalid SHA384 hash", |
michael@0 | 170 | AUS_Cr.NS_ERROR_CORRUPTED_CONTENT, run_test_pt9); |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | // mar download with a valid SHA512 hash |
michael@0 | 174 | function run_test_pt9() { |
michael@0 | 175 | setResponseBody("SHA512", SHA512_HASH_SIMPLE_MAR); |
michael@0 | 176 | run_test_helper_pt1("mar download with a valid SHA512 hash", |
michael@0 | 177 | AUS_Cr.NS_OK, run_test_pt10); |
michael@0 | 178 | } |
michael@0 | 179 | |
michael@0 | 180 | // mar download with an invalid SHA512 hash |
michael@0 | 181 | function run_test_pt10() { |
michael@0 | 182 | setResponseBody("SHA512", SHA512_HASH_SIMPLE_MAR + "0"); |
michael@0 | 183 | run_test_helper_pt1("mar download with an invalid SHA512 hash", |
michael@0 | 184 | AUS_Cr.NS_ERROR_CORRUPTED_CONTENT, run_test_pt11); |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | // mar download with the mar not found |
michael@0 | 188 | function run_test_pt11() { |
michael@0 | 189 | var patches = getRemotePatchString(null, gURLData + "missing.mar"); |
michael@0 | 190 | var updates = getRemoteUpdateString(patches); |
michael@0 | 191 | gResponseBody = getRemoteUpdatesXMLString(updates); |
michael@0 | 192 | run_test_helper_pt1("mar download with the mar not found", |
michael@0 | 193 | AUS_Cr.NS_ERROR_UNEXPECTED, run_test_pt12); |
michael@0 | 194 | } |
michael@0 | 195 | |
michael@0 | 196 | // mar download with a valid MD5 hash but invalid file size |
michael@0 | 197 | function run_test_pt12() { |
michael@0 | 198 | const arbitraryFileSize = 1024000; |
michael@0 | 199 | setResponseBody("MD5", MD5_HASH_SIMPLE_MAR, arbitraryFileSize); |
michael@0 | 200 | if (IS_TOOLKIT_GONK) { |
michael@0 | 201 | // There seems to be a race on the web server side when the patchFile is |
michael@0 | 202 | // stored on the SDCard. Sometimes, the webserver will serve up an error |
michael@0 | 203 | // 416 and the contents of the file, and sometimes it will serve up an error |
michael@0 | 204 | // 200 and no contents. This can cause either NS_ERROR_UNEXPECTED or |
michael@0 | 205 | // NS_ERROR_CONTENT_CORRUPTED. |
michael@0 | 206 | // Bug 828858 was filed to follow up on this issue. |
michael@0 | 207 | run_test_helper_bug828858_pt1("mar download with a valid MD5 hash but invalid file size", |
michael@0 | 208 | AUS_Cr.NS_ERROR_UNEXPECTED, finish_test); |
michael@0 | 209 | } else { |
michael@0 | 210 | run_test_helper_pt1("mar download with a valid MD5 hash but invalid file size", |
michael@0 | 211 | AUS_Cr.NS_ERROR_UNEXPECTED, finish_test); |
michael@0 | 212 | } |
michael@0 | 213 | } |