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 /* import-globals-from head_channels.js */
6 /* import-globals-from head_cookies.js */
8 async function http3_setup_tests(http3version) {
9 let env = Cc["@mozilla.org/process/environment;1"].getService(
13 let h3Port = env.get("MOZHTTP3_PORT");
14 Assert.notEqual(h3Port, null);
15 Assert.notEqual(h3Port, "");
16 let h3Route = "foo.example.com:" + h3Port;
19 Services.prefs.setBoolPref("network.http.http3.enable", true);
20 Services.prefs.setCharPref("network.dns.localDomains", "foo.example.com");
21 Services.prefs.setBoolPref("network.dns.disableIPv6", true);
22 Services.prefs.setCharPref(
23 "network.http.http3.alt-svc-mapping-for-testing",
24 `foo.example.com;${http3version}=:${h3Port}`
27 let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
30 // `../unit/` so that unit_ipc tests can use as well
31 addCertFromFile(certdb, "../unit/http2-ca.pem", "CTu,u,u");
33 await setup_altsvc("https://foo.example.com/", h3Route, http3version);
36 function makeChan(uri) {
37 let chan = NetUtil.newChannel({
39 loadUsingSystemPrincipal: true,
40 }).QueryInterface(Ci.nsIHttpChannel);
41 chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
45 let CheckHttp3Listener = function() {};
47 CheckHttp3Listener.prototype = {
51 onStartRequest: function testOnStartRequest(request) {},
53 onDataAvailable: function testOnDataAvailable(request, stream, off, cnt) {
54 read_stream(stream, cnt);
57 onStopRequest: function testOnStopRequest(request, status) {
60 routed = request.getRequestHeader("Alt-Used");
62 dump("routed is " + routed + "\n");
64 if (routed == this.expectedRoute) {
67 httpVersion = request.protocolVersion;
69 Assert.equal(httpVersion, this.http3version);
72 dump("try again to get alt svc mapping\n");
78 async function setup_altsvc(uri, expectedRoute, http3version) {
81 let chan = makeChan(uri);
82 let listener = new CheckHttp3Listener();
83 listener.expectedRoute = expectedRoute;
84 listener.http3version = http3version;
85 result = await altsvcSetupPromise(chan, listener);
86 dump("results=" + result);
87 } while (result === false);
90 function altsvcSetupPromise(chan, listener) {
91 return new Promise(resolve => {
92 function finish(result) {
95 listener.finish = finish;
96 chan.asyncOpen(listener);
100 function http3_clear_prefs() {
101 Services.prefs.clearUserPref("network.http.http3.enable");
102 Services.prefs.clearUserPref("network.dns.localDomains");
103 Services.prefs.clearUserPref("network.dns.disableIPv6");
104 Services.prefs.clearUserPref(
105 "network.http.http3.alt-svc-mapping-for-testing"
107 Services.prefs.clearUserPref("network.http.http3.support_version1");
108 dump("cleanup done\n");