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