test_http3_timings.js (1729B)
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 5 "use strict"; 6 7 var { setTimeout } = ChromeUtils.importESModule( 8 "resource://gre/modules/Timer.sys.mjs" 9 ); 10 11 add_setup(async function () { 12 await http3_setup_tests("h3"); 13 }); 14 15 function makeChan(url) { 16 let chan = NetUtil.newChannel({ 17 uri: url, 18 loadUsingSystemPrincipal: true, 19 contentPolicyType: Ci.nsIContentPolicy.TYPE_DOCUMENT, 20 }).QueryInterface(Ci.nsIHttpChannel); 21 return chan; 22 } 23 24 function channelOpenPromise(chan, flags) { 25 return new Promise(resolve => { 26 function finish(req, buffer) { 27 resolve([req, buffer]); 28 } 29 chan.asyncOpen(new ChannelListener(finish, null, flags)); 30 }); 31 } 32 33 async function doTestTimings() { 34 Services.obs.notifyObservers(null, "net:prune-all-connections"); 35 36 // eslint-disable-next-line mozilla/no-arbitrary-setTimeout 37 await new Promise(resolve => setTimeout(resolve, 1000)); 38 39 let chan = makeChan(`https://foo.example.com`); 40 let [req] = await channelOpenPromise(chan); 41 let httpVersion = ""; 42 try { 43 httpVersion = req.protocolVersion; 44 } catch (e) {} 45 Assert.equal(httpVersion, "h3"); 46 47 let timing = req.QueryInterface(Ci.nsITimedChannel); 48 Assert.greater(timing.connectStartTime, 0); 49 Assert.equal(timing.connectStartTime, timing.secureConnectionStartTime); 50 } 51 52 add_task(async function test_connectStart_equals_secureConnectionStart() { 53 Services.prefs.setIntPref("network.http.speculative-parallel-limit", 0); 54 await doTestTimings(); 55 56 Services.prefs.setIntPref("network.http.speculative-parallel-limit", 6); 57 await doTestTimings(); 58 });