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/. */
8 registerCleanupFunction(async () => {
9 Services
.prefs
.clearUserPref("network.http.http3.enable");
10 Services
.prefs
.clearUserPref("network.dns.localDomains");
11 Services
.prefs
.clearUserPref("network.dns.disableIPv6");
12 Services
.prefs
.clearUserPref(
13 "network.http.http3.alt-svc-mapping-for-testing"
15 Services
.prefs
.clearUserPref("network.http.http3.backup_timer_delay");
16 dump("cleanup done\n");
20 let chan
= NetUtil
.newChannel({
22 loadUsingSystemPrincipal
: true,
23 }).QueryInterface(Ci
.nsIHttpChannel
);
24 chan
.loadFlags
= Ci
.nsIChannel
.LOAD_INITIAL_DOCUMENT_URI
;
28 function altsvcSetupPromise(chan
, listener
) {
29 return new Promise(resolve
=> {
30 function finish(result
) {
33 listener
.finish
= finish
;
34 chan
.asyncOpen(listener
);
38 add_task(async
function test_fatal_error() {
39 let h2Port
= Services
.env
.get("MOZHTTP2_PORT");
40 Assert
.notEqual(h2Port
, null);
42 Services
.prefs
.setBoolPref("network.http.http3.enable", true);
43 Services
.prefs
.setCharPref("network.dns.localDomains", "foo.example.com");
44 Services
.prefs
.setBoolPref("network.dns.disableIPv6", true);
45 // Set AltSvc to point to not existing HTTP3 server on port 443
46 Services
.prefs
.setCharPref(
47 "network.http.http3.alt-svc-mapping-for-testing",
48 "foo.example.com;h3=:443"
50 Services
.prefs
.setIntPref("network.http.http3.backup_timer_delay", 0);
52 let certdb
= Cc
["@mozilla.org/security/x509certdb;1"].getService(
55 addCertFromFile(certdb
, "http2-ca.pem", "CTu,u,u");
57 httpsUri
= "https://foo.example.com:" + h2Port
+ "/";
60 add_task(async
function test_fatal_stream_error() {
62 // We need to loop here because we need to wait for AltSvc storage to
64 // We also do not have a way to verify that HTTP3 has been tried, because
65 // the fallback is automatic, so try a couple of times.
67 // We need to close HTTP2 connections, otherwise our connection pooling
68 // will dispatch the request over already existing HTTP2 connection.
69 Services
.obs
.notifyObservers(null, "net:prune-all-connections");
70 let chan
= makeChan();
71 let listener
= new CheckOnlyHttp2Listener();
72 await
altsvcSetupPromise(chan
, listener
);
77 let CheckOnlyHttp2Listener = function () {};
79 CheckOnlyHttp2Listener
.prototype = {
80 onStartRequest
: function testOnStartRequest() {},
82 onDataAvailable
: function testOnDataAvailable(request
, stream
, off
, cnt
) {
83 read_stream(stream
, cnt
);
86 onStopRequest
: function testOnStopRequest(request
, status
) {
87 Assert
.equal(status
, Cr
.NS_OK
);
90 httpVersion
= request
.protocolVersion
;
92 Assert
.equal(httpVersion
, "h2");
97 add_task(async
function test_no_http3_after_error() {
98 let chan
= makeChan();
99 let listener
= new CheckOnlyHttp2Listener();
100 await
altsvcSetupPromise(chan
, listener
);
103 // also after all connections are closed.
104 add_task(async
function test_no_http3_after_error2() {
105 Services
.obs
.notifyObservers(null, "net:prune-all-connections");
106 let chan
= makeChan();
107 let listener
= new CheckOnlyHttp2Listener();
108 await
altsvcSetupPromise(chan
, listener
);