test_http3_version1.js (2670B)
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 "use strict"; 5 6 registerCleanupFunction(async () => { 7 http3_clear_prefs(); 8 }); 9 10 let httpsUri; 11 12 add_task(async function pre_setup() { 13 let h2Port = Services.env.get("MOZHTTP2_PORT"); 14 Assert.notEqual(h2Port, null); 15 Assert.notEqual(h2Port, ""); 16 httpsUri = "https://foo.example.com:" + h2Port + "/"; 17 Services.prefs.setBoolPref("network.http.http3.support_version1", true); 18 }); 19 20 add_task(async function setup() { 21 await http3_setup_tests("h3"); 22 }); 23 24 function chanPromise(chan, listener) { 25 return new Promise(resolve => { 26 function finish() { 27 resolve(); 28 } 29 listener.finish = finish; 30 chan.asyncOpen(listener); 31 }); 32 } 33 34 function makeH2Chan() { 35 let chan = NetUtil.newChannel({ 36 uri: httpsUri, 37 loadUsingSystemPrincipal: true, 38 }).QueryInterface(Ci.nsIHttpChannel); 39 chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI; 40 return chan; 41 } 42 43 let Http3Listener = function () {}; 44 45 Http3Listener.prototype = { 46 version1enabled: "", 47 48 onStartRequest: function testOnStartRequest() {}, 49 50 onDataAvailable: function testOnDataAvailable(request, stream, off, cnt) { 51 read_stream(stream, cnt); 52 }, 53 54 onStopRequest: function testOnStopRequest(request) { 55 let httpVersion = ""; 56 try { 57 httpVersion = request.protocolVersion; 58 } catch (e) {} 59 if (this.version1enabled) { 60 Assert.equal(httpVersion, "h3"); 61 } else { 62 Assert.equal(httpVersion, "h2"); 63 } 64 65 this.finish(); 66 }, 67 }; 68 69 add_task(async function test_version1_enabled_1() { 70 Services.prefs.setBoolPref("network.http.http3.support_version1", true); 71 let listener = new Http3Listener(); 72 listener.version1enabled = true; 73 let chan = makeH2Chan("https://foo.example.com/"); 74 await chanPromise(chan, listener); 75 }); 76 77 add_task(async function test_version1_disabled() { 78 Services.obs.notifyObservers(null, "net:cancel-all-connections"); 79 Services.prefs.setBoolPref("network.http.http3.support_version1", false); 80 let listener = new Http3Listener(); 81 listener.version1enabled = false; 82 let chan = makeH2Chan("https://foo.example.com/"); 83 await chanPromise(chan, listener); 84 }); 85 86 add_task(async function test_version1_enabled_2() { 87 Services.obs.notifyObservers(null, "net:cancel-all-connections"); 88 Services.prefs.setBoolPref("network.http.http3.support_version1", true); 89 let listener = new Http3Listener(); 90 listener.version1enabled = true; 91 let chan = makeH2Chan("https://foo.example.com/"); 92 await chanPromise(chan, listener); 93 });