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");
19 let Http3FailedListener = function () {};
21 Http3FailedListener.prototype = {
22 onStartRequest: function testOnStartRequest(request) {},
24 onDataAvailable: function testOnDataAvailable(request, stream, off, cnt) {
26 read_stream(stream, cnt);
29 onStopRequest: function testOnStopRequest(request, status) {
30 if (Components.isSuccessCode(status)) {
31 // This is still HTTP2 connection
34 httpVersion = request.protocolVersion;
36 Assert.equal(httpVersion, "h2");
39 Assert.equal(status, Cr.NS_ERROR_NET_PARTIAL_TRANSFER);
46 let chan = NetUtil.newChannel({
48 loadUsingSystemPrincipal: true,
49 }).QueryInterface(Ci.nsIHttpChannel);
50 chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
54 function altsvcSetupPromise(chan, listener) {
55 return new Promise(resolve => {
56 function finish(result) {
59 listener.finish = finish;
60 chan.asyncOpen(listener);
64 add_task(async function test_fatal_error() {
65 let h2Port = Services.env.get("MOZHTTP2_PORT");
66 Assert.notEqual(h2Port, null);
68 let h3Port = Services.env.get("MOZHTTP3_PORT_FAILED");
69 Assert.notEqual(h3Port, null);
70 Assert.notEqual(h3Port, "");
72 Services.prefs.setBoolPref("network.http.http3.enable", true);
73 Services.prefs.setCharPref("network.dns.localDomains", "foo.example.com");
74 Services.prefs.setBoolPref("network.dns.disableIPv6", true);
75 Services.prefs.setCharPref(
76 "network.http.http3.alt-svc-mapping-for-testing",
77 "foo.example.com;h3-29=:" + h3Port
79 Services.prefs.setIntPref("network.http.http3.backup_timer_delay", 0);
81 let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
84 addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u");
86 httpsUri = "https://foo.example.com:" + h2Port + "/";
89 add_task(async function test_fatal_stream_error() {
91 // We need to loop here because we need to wait for AltSvc storage to
94 // We need to close HTTP2 connections, otherwise our connection pooling
95 // will dispatch the request over already existing HTTP2 connection.
96 Services.obs.notifyObservers(null, "net:prune-all-connections");
97 let chan = makeChan();
98 let listener = new Http3FailedListener();
99 result = await altsvcSetupPromise(chan, listener);
100 } while (result === false);
103 let CheckOnlyHttp2Listener = function () {};
105 CheckOnlyHttp2Listener.prototype = {
106 onStartRequest: function testOnStartRequest(request) {},
108 onDataAvailable: function testOnDataAvailable(request, stream, off, cnt) {
109 read_stream(stream, cnt);
112 onStopRequest: function testOnStopRequest(request, status) {
113 Assert.equal(status, Cr.NS_OK);
114 let httpVersion = "";
116 httpVersion = request.protocolVersion;
118 Assert.equal(httpVersion, "h2");
123 add_task(async function test_no_http3_after_error() {
124 let chan = makeChan();
125 let listener = new CheckOnlyHttp2Listener();
126 await altsvcSetupPromise(chan, listener);
129 // also after all connections are closed.
130 add_task(async function test_no_http3_after_error2() {
131 Services.obs.notifyObservers(null, "net:prune-all-connections");
132 let chan = makeChan();
133 let listener = new CheckOnlyHttp2Listener();
134 await altsvcSetupPromise(chan, listener);