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/. */
5 var { setTimeout } = ChromeUtils.importESModule(
6 "resource://gre/modules/Timer.sys.mjs"
9 registerCleanupFunction(async () => {
13 add_task(async function setup() {
14 await http3_setup_tests("h3-29");
17 let Http3Listener = function () {};
19 Http3Listener.prototype = {
22 onStartRequest: function testOnStartRequest(request) {
23 Assert.equal(request.status, Cr.NS_OK);
24 Assert.equal(request.responseStatus, 200);
26 let secinfo = request.securityInfo;
27 Assert.equal(secinfo.resumed, this.resumed);
28 Assert.ok(secinfo.serverCert != null);
31 onDataAvailable: function testOnDataAvailable(request, stream, off, cnt) {
32 read_stream(stream, cnt);
35 onStopRequest: function testOnStopRequest(request, status) {
38 httpVersion = request.protocolVersion;
40 Assert.equal(httpVersion, "h3-29");
46 function chanPromise(chan, listener) {
47 return new Promise(resolve => {
48 function finish(result) {
51 listener.finish = finish;
52 chan.asyncOpen(listener);
56 function makeChan(uri) {
57 let chan = NetUtil.newChannel({
59 loadUsingSystemPrincipal: true,
60 }).QueryInterface(Ci.nsIHttpChannel);
61 chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
65 async function test_first_conn_no_resumed() {
66 let listener = new Http3Listener();
67 listener.resumed = false;
68 let chan = makeChan("https://foo.example.com/30");
69 await chanPromise(chan, listener);
72 async function test_0RTT(enable_0rtt, resumed) {
73 info(`enable_0rtt=${enable_0rtt} resumed=${resumed}`);
74 Services.prefs.setBoolPref("network.http.http3.enable_0rtt", enable_0rtt);
76 // Make sure the h3 connection created by the previous test is cleared.
77 Services.obs.notifyObservers(null, "net:cancel-all-connections");
78 // eslint-disable-next-line mozilla/no-arbitrary-setTimeout
79 await new Promise(resolve => setTimeout(resolve, 1000));
81 // This connecion should be resumed.
82 let listener = new Http3Listener();
83 listener.resumed = resumed;
84 let chan = makeChan("https://foo.example.com/30");
85 await chanPromise(chan, listener);
88 add_task(async function test_0RTT_setups() {
89 await test_first_conn_no_resumed();
92 await test_0RTT(true, true);
94 // http3.0RTT disabled
95 await test_0RTT(false, false);