Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / netwerk / test / unit / test_http2.js
blob9730f5b1e7ac844f9b469abe0df28f1d9f6f4493
1 /* import-globals-from http2_test_common.js */
3 const { HttpServer } = ChromeUtils.importESModule(
4 "resource://testing-common/httpd.sys.mjs"
5 );
7 var concurrent_channels = [];
8 var httpserv = null;
9 var httpserv2 = null;
11 var loadGroup;
12 var serverPort;
14 function altsvcHttp1Server(metadata, response) {
15 response.setStatusLine(metadata.httpVersion, 200, "OK");
16 response.setHeader("Content-Type", "text/plain", false);
17 response.setHeader("Connection", "close", false);
18 response.setHeader("Alt-Svc", 'h2=":' + serverPort + '"', false);
19 var body = "this is where a cool kid would write something neat.\n";
20 response.bodyOutputStream.write(body, body.length);
23 function h1ServerWK(metadata, response) {
24 response.setStatusLine(metadata.httpVersion, 200, "OK");
25 response.setHeader("Content-Type", "application/json", false);
26 response.setHeader("Connection", "close", false);
27 response.setHeader("Cache-Control", "no-cache", false);
28 response.setHeader("Access-Control-Allow-Origin", "*", false);
29 response.setHeader("Access-Control-Allow-Method", "GET", false);
31 var body = '["http://foo.example.com:' + httpserv.identity.primaryPort + '"]';
32 response.bodyOutputStream.write(body, body.length);
35 function altsvcHttp1Server2(metadata, response) {
36 // this server should never be used thanks to an alt svc frame from the
37 // h2 server.. but in case of some async lag in setting the alt svc route
38 // up we have it.
39 response.setStatusLine(metadata.httpVersion, 200, "OK");
40 response.setHeader("Content-Type", "text/plain", false);
41 response.setHeader("Connection", "close", false);
42 var body = "hanging.\n";
43 response.bodyOutputStream.write(body, body.length);
46 function h1ServerWK2(metadata, response) {
47 response.setStatusLine(metadata.httpVersion, 200, "OK");
48 response.setHeader("Content-Type", "application/json", false);
49 response.setHeader("Connection", "close", false);
50 response.setHeader("Cache-Control", "no-cache", false);
51 response.setHeader("Access-Control-Allow-Origin", "*", false);
52 response.setHeader("Access-Control-Allow-Method", "GET", false);
54 var body =
55 '["http://foo.example.com:' + httpserv2.identity.primaryPort + '"]';
56 response.bodyOutputStream.write(body, body.length);
59 add_setup(async function setup() {
60 serverPort = Services.env.get("MOZHTTP2_PORT");
61 Assert.notEqual(serverPort, null);
62 dump("using port " + serverPort + "\n");
64 // Set to allow the cert presented by our H2 server
65 do_get_profile();
67 Services.prefs.setIntPref("network.http.speculative-parallel-limit", 0);
69 // The moz-http2 cert is for foo.example.com and is signed by http2-ca.pem
70 // so add that cert to the trust list as a signing cert. Some older tests in
71 // this suite use localhost with a TOFU exception, but new ones should use
72 // foo.example.com
73 let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
74 Ci.nsIX509CertDB
76 addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u");
78 Services.prefs.setBoolPref("network.http.http2.enabled", true);
79 Services.prefs.setBoolPref("network.http.http2.allow-push", true);
80 Services.prefs.setBoolPref("network.http.altsvc.enabled", true);
81 Services.prefs.setBoolPref("network.http.altsvc.oe", true);
82 Services.prefs.setCharPref(
83 "network.dns.localDomains",
84 "foo.example.com, bar.example.com"
86 Services.prefs.setBoolPref(
87 "network.cookieJarSettings.unblocked_for_testing",
88 true
91 loadGroup = Cc["@mozilla.org/network/load-group;1"].createInstance(
92 Ci.nsILoadGroup
95 httpserv = new HttpServer();
96 httpserv.registerPathHandler("/altsvc1", altsvcHttp1Server);
97 httpserv.registerPathHandler("/.well-known/http-opportunistic", h1ServerWK);
98 httpserv.start(-1);
99 httpserv.identity.setPrimary(
100 "http",
101 "foo.example.com",
102 httpserv.identity.primaryPort
105 httpserv2 = new HttpServer();
106 httpserv2.registerPathHandler("/altsvc2", altsvcHttp1Server2);
107 httpserv2.registerPathHandler("/.well-known/http-opportunistic", h1ServerWK2);
108 httpserv2.start(-1);
109 httpserv2.identity.setPrimary(
110 "http",
111 "foo.example.com",
112 httpserv2.identity.primaryPort
116 registerCleanupFunction(async () => {
117 Services.prefs.clearUserPref("network.http.speculative-parallel-limit");
118 Services.prefs.clearUserPref("network.http.http2.enabled");
119 Services.prefs.clearUserPref("network.http.http2.allow-push");
120 Services.prefs.clearUserPref("network.http.altsvc.enabled");
121 Services.prefs.clearUserPref("network.http.altsvc.oe");
122 Services.prefs.clearUserPref("network.dns.localDomains");
123 Services.prefs.clearUserPref(
124 "network.cookieJarSettings.unblocked_for_testing"
126 await httpserv.stop();
127 await httpserv2.stop();
130 // hack - the header test resets the multiplex object on the server,
131 // so make sure header is always run before the multiplex test.
133 // make sure post_big runs first to test race condition in restarting
134 // a stalled stream when a SETTINGS frame arrives
135 add_task(async function do_test_http2_post_big() {
136 const { httpProxyConnectResponseCode } =
137 await test_http2_post_big(serverPort);
138 Assert.equal(httpProxyConnectResponseCode, -1);
141 add_task(async function do_test_http2_basic() {
142 const { httpProxyConnectResponseCode } = await test_http2_basic(serverPort);
143 Assert.equal(httpProxyConnectResponseCode, -1);
146 add_task(async function do_test_http2_concurrent() {
147 const { httpProxyConnectResponseCode } = await test_http2_concurrent(
148 concurrent_channels,
149 serverPort
151 Assert.equal(httpProxyConnectResponseCode, -1);
154 add_task(async function do_test_http2_concurrent_post() {
155 const { httpProxyConnectResponseCode } = await test_http2_concurrent_post(
156 concurrent_channels,
157 serverPort
159 Assert.equal(httpProxyConnectResponseCode, -1);
162 add_task(async function do_test_http2_basic_unblocked_dep() {
163 const { httpProxyConnectResponseCode } =
164 await test_http2_basic_unblocked_dep(serverPort);
165 Assert.equal(httpProxyConnectResponseCode, -1);
168 add_task(async function do_test_http2_nospdy() {
169 const { httpProxyConnectResponseCode } = await test_http2_nospdy(serverPort);
170 Assert.equal(httpProxyConnectResponseCode, -1);
173 add_task(async function do_test_http2_push1() {
174 const { httpProxyConnectResponseCode } = await test_http2_push1(
175 loadGroup,
176 serverPort
178 Assert.equal(httpProxyConnectResponseCode, -1);
181 add_task(async function do_test_http2_push2() {
182 const { httpProxyConnectResponseCode } = await test_http2_push2(
183 loadGroup,
184 serverPort
186 Assert.equal(httpProxyConnectResponseCode, -1);
189 add_task(async function do_test_http2_push3() {
190 const { httpProxyConnectResponseCode } = await test_http2_push3(
191 loadGroup,
192 serverPort
194 Assert.equal(httpProxyConnectResponseCode, -1);
197 add_task(async function do_test_http2_push4() {
198 const { httpProxyConnectResponseCode } = await test_http2_push4(
199 loadGroup,
200 serverPort
202 Assert.equal(httpProxyConnectResponseCode, -1);
205 add_task(async function do_test_http2_push5() {
206 const { httpProxyConnectResponseCode } = await test_http2_push5(
207 loadGroup,
208 serverPort
210 Assert.equal(httpProxyConnectResponseCode, -1);
213 add_task(async function do_test_http2_push6() {
214 const { httpProxyConnectResponseCode } = await test_http2_push6(
215 loadGroup,
216 serverPort
218 Assert.equal(httpProxyConnectResponseCode, -1);
221 add_task(async function do_test_http2_altsvc() {
222 const { httpProxyConnectResponseCode } = await test_http2_altsvc(
223 httpserv.identity.primaryPort,
224 httpserv2.identity.primaryPort,
225 false
227 Assert.equal(httpProxyConnectResponseCode, -1);
230 add_task(async function do_test_http2_doubleheader() {
231 const { httpProxyConnectResponseCode } =
232 await test_http2_doubleheader(serverPort);
233 Assert.equal(httpProxyConnectResponseCode, -1);
236 add_task(async function do_test_http2_xhr() {
237 await test_http2_xhr(serverPort);
240 add_task(async function do_test_http2_header() {
241 const { httpProxyConnectResponseCode } = await test_http2_header(serverPort);
242 Assert.equal(httpProxyConnectResponseCode, -1);
245 add_task(async function do_test_http2_invalid_response_header_name_spaces() {
246 const { httpProxyConnectResponseCode } =
247 await test_http2_invalid_response_header(serverPort, "name_spaces");
248 Assert.equal(httpProxyConnectResponseCode, -1);
251 add_task(
252 async function do_test_http2_invalid_response_header_value_line_feed() {
253 const { httpProxyConnectResponseCode } =
254 await test_http2_invalid_response_header(serverPort, "value_line_feed");
255 Assert.equal(httpProxyConnectResponseCode, -1);
259 add_task(
260 async function do_test_http2_invalid_response_header_value_carriage_return() {
261 const { httpProxyConnectResponseCode } =
262 await test_http2_invalid_response_header(
263 serverPort,
264 "value_carriage_return"
266 Assert.equal(httpProxyConnectResponseCode, -1);
270 add_task(async function do_test_http2_invalid_response_header_value_null() {
271 const { httpProxyConnectResponseCode } =
272 await test_http2_invalid_response_header(serverPort, "value_null");
273 Assert.equal(httpProxyConnectResponseCode, -1);
276 add_task(async function do_test_http2_cookie_crumbling() {
277 const { httpProxyConnectResponseCode } =
278 await test_http2_cookie_crumbling(serverPort);
279 Assert.equal(httpProxyConnectResponseCode, -1);
282 add_task(async function do_test_http2_multiplex() {
283 var values = await test_http2_multiplex(serverPort);
284 Assert.equal(values[0].httpProxyConnectResponseCode, -1);
285 Assert.equal(values[1].httpProxyConnectResponseCode, -1);
286 Assert.notEqual(values[0].streamID, values[1].streamID);
289 add_task(async function do_test_http2_big() {
290 const { httpProxyConnectResponseCode } = await test_http2_big(serverPort);
291 Assert.equal(httpProxyConnectResponseCode, -1);
294 add_task(async function do_test_http2_huge_suspended() {
295 const { httpProxyConnectResponseCode } =
296 await test_http2_huge_suspended(serverPort);
297 Assert.equal(httpProxyConnectResponseCode, -1);
300 add_task(async function do_test_http2_post() {
301 const { httpProxyConnectResponseCode } = await test_http2_post(serverPort);
302 Assert.equal(httpProxyConnectResponseCode, -1);
305 add_task(async function do_test_http2_empty_post() {
306 const { httpProxyConnectResponseCode } =
307 await test_http2_empty_post(serverPort);
308 Assert.equal(httpProxyConnectResponseCode, -1);
311 add_task(async function do_test_http2_patch() {
312 const { httpProxyConnectResponseCode } = await test_http2_patch(serverPort);
313 Assert.equal(httpProxyConnectResponseCode, -1);
316 add_task(async function do_test_http2_pushapi_1() {
317 const { httpProxyConnectResponseCode } = await test_http2_pushapi_1(
318 loadGroup,
319 serverPort
321 Assert.equal(httpProxyConnectResponseCode, -1);
324 add_task(async function do_test_http2_continuations() {
325 const { httpProxyConnectResponseCode } = await test_http2_continuations(
326 loadGroup,
327 serverPort
329 Assert.equal(httpProxyConnectResponseCode, -1);
332 add_task(async function do_test_http2_blocking_download() {
333 const { httpProxyConnectResponseCode } =
334 await test_http2_blocking_download(serverPort);
335 Assert.equal(httpProxyConnectResponseCode, -1);
338 add_task(async function do_test_http2_illegalhpacksoft() {
339 const { httpProxyConnectResponseCode } =
340 await test_http2_illegalhpacksoft(serverPort);
341 Assert.equal(httpProxyConnectResponseCode, -1);
344 add_task(async function do_test_http2_illegalhpackhard() {
345 const { httpProxyConnectResponseCode } =
346 await test_http2_illegalhpackhard(serverPort);
347 Assert.equal(httpProxyConnectResponseCode, -1);
350 add_task(async function do_test_http2_folded_header() {
351 const { httpProxyConnectResponseCode } = await test_http2_folded_header(
352 loadGroup,
353 serverPort
355 Assert.equal(httpProxyConnectResponseCode, -1);
358 add_task(async function do_test_http2_empty_data() {
359 const { httpProxyConnectResponseCode } =
360 await test_http2_empty_data(serverPort);
361 Assert.equal(httpProxyConnectResponseCode, -1);
364 add_task(async function do_test_http2_status_phrase() {
365 const { httpProxyConnectResponseCode } =
366 await test_http2_status_phrase(serverPort);
367 Assert.equal(httpProxyConnectResponseCode, -1);
370 add_task(async function do_test_http2_doublepush() {
371 const { httpProxyConnectResponseCode } = await test_http2_doublepush(
372 loadGroup,
373 serverPort
375 Assert.equal(httpProxyConnectResponseCode, -1);
378 add_task(async function do_test_http2_disk_cache_push() {
379 const { httpProxyConnectResponseCode } = await test_http2_disk_cache_push(
380 loadGroup,
381 serverPort
383 Assert.equal(httpProxyConnectResponseCode, -1);
386 add_task(async function do_test_http2_h11required_stream() {
387 // Add new tests above here - best to add new tests before h1
388 // streams get too involved
389 // These next two must always come in this order
390 const { httpProxyConnectResponseCode } =
391 await test_http2_h11required_stream(serverPort);
392 Assert.equal(httpProxyConnectResponseCode, -1);
395 add_task(async function do_test_http2_h11required_session() {
396 const { httpProxyConnectResponseCode } =
397 await test_http2_h11required_session(serverPort);
398 Assert.equal(httpProxyConnectResponseCode, -1);
401 add_task(async function do_test_http2_retry_rst() {
402 const { httpProxyConnectResponseCode } =
403 await test_http2_retry_rst(serverPort);
404 Assert.equal(httpProxyConnectResponseCode, -1);
407 add_task(async function do_test_http2_wrongsuite_tls12() {
408 const { httpProxyConnectResponseCode } =
409 await test_http2_wrongsuite_tls12(serverPort);
410 Assert.equal(httpProxyConnectResponseCode, -1);
413 add_task(async function do_test_http2_wrongsuite_tls13() {
414 const { httpProxyConnectResponseCode } =
415 await test_http2_wrongsuite_tls13(serverPort);
416 Assert.equal(httpProxyConnectResponseCode, -1);
419 add_task(async function do_test_http2_push_firstparty1() {
420 const { httpProxyConnectResponseCode } = await test_http2_push_firstparty1(
421 loadGroup,
422 serverPort
424 Assert.equal(httpProxyConnectResponseCode, -1);
427 add_task(async function do_test_http2_push_firstparty2() {
428 const { httpProxyConnectResponseCode } = await test_http2_push_firstparty2(
429 loadGroup,
430 serverPort
432 Assert.equal(httpProxyConnectResponseCode, -1);
435 add_task(async function do_test_http2_push_firstparty3() {
436 const { httpProxyConnectResponseCode } = await test_http2_push_firstparty3(
437 loadGroup,
438 serverPort
440 Assert.equal(httpProxyConnectResponseCode, -1);
443 add_task(async function do_test_http2_push_userContext1() {
444 const { httpProxyConnectResponseCode } = await test_http2_push_userContext1(
445 loadGroup,
446 serverPort
448 Assert.equal(httpProxyConnectResponseCode, -1);
451 add_task(async function do_test_http2_push_userContext2() {
452 const { httpProxyConnectResponseCode } = await test_http2_push_userContext2(
453 loadGroup,
454 serverPort
456 Assert.equal(httpProxyConnectResponseCode, -1);
459 add_task(async function do_test_http2_push_userContext3() {
460 const { httpProxyConnectResponseCode } = await test_http2_push_userContext3(
461 loadGroup,
462 serverPort
464 Assert.equal(httpProxyConnectResponseCode, -1);
467 add_task(async function do_test_http2_continuations_over_max_response_limit() {
468 const { httpProxyConnectResponseCode } =
469 await test_http2_continuations_over_max_response_limit(
470 loadGroup,
471 serverPort
473 Assert.equal(httpProxyConnectResponseCode, -1);