10 // The altSvc storage may not be up imediately, therefore run test_no_altsvc_pref
11 // for a couple times to wait for the storage.
21 function run_next_test() {
22 if (current_test < tests.length) {
23 dump("starting test number " + current_test + "\n");
24 tests[current_test]();
30 h3Port = Services.env.get("MOZHTTP3_PORT");
31 Assert.notEqual(h3Port, null);
32 Assert.notEqual(h3Port, "");
33 h3AltSvc = ":" + h3Port;
35 h3Route = "foo.example.com:" + h3Port;
37 prefs = Services.prefs;
39 prefs.setBoolPref("network.http.http3.enable", true);
40 prefs.setCharPref("network.dns.localDomains", "foo.example.com");
41 prefs.setBoolPref("network.dns.disableIPv6", true);
43 // The certificate for the http3server server is for foo.example.com and
44 // is signed by http2-ca.pem so add that cert to the trust list as a
46 let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
49 addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u");
50 httpsOrigin = "https://foo.example.com/";
55 let Http3CheckListener = function () {};
57 Http3CheckListener.prototype = {
59 expectedStatus: Cr.NS_OK,
61 onStartRequest: function testOnStartRequest(request) {
62 Assert.ok(request instanceof Ci.nsIHttpChannel);
63 Assert.equal(request.status, this.expectedStatus);
64 if (Components.isSuccessCode(this.expectedStatus)) {
65 Assert.equal(request.responseStatus, 200);
69 onDataAvailable: function testOnDataAvailable(request, stream, off, cnt) {
70 read_stream(stream, cnt);
73 onStopRequest: function testOnStopRequest(request, status) {
74 Assert.equal(status, this.expectedStatus);
75 if (Components.isSuccessCode(this.expectedStatus)) {
76 Assert.equal(request.responseStatus, 200);
79 routed = request.getRequestHeader("Alt-Used");
81 dump("routed is " + routed + "\n");
83 Assert.equal(routed, this.expectedRoute);
87 httpVersion = request.protocolVersion;
89 Assert.equal(httpVersion, "h3");
96 function makeChan(uri) {
97 let chan = NetUtil.newChannel({
99 loadUsingSystemPrincipal: true,
100 }).QueryInterface(Ci.nsIHttpChannel);
101 chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
105 function test_no_altsvc_pref() {
106 dump("test_no_altsvc_pref");
109 let chan = makeChan(httpsOrigin + "http3-test");
110 let listener = new Http3CheckListener();
111 listener.expectedStatus = Cr.NS_ERROR_CONNECTION_REFUSED;
112 chan.asyncOpen(listener);
115 function test_altsvc_pref() {
116 dump("test_altsvc_pref");
120 "network.http.http3.alt-svc-mapping-for-testing",
121 "foo.example.com;h3-29=" + h3AltSvc
124 let chan = makeChan(httpsOrigin + "http3-test");
125 let listener = new Http3CheckListener();
126 listener.expectedRoute = h3Route;
127 chan.asyncOpen(listener);
130 function testsDone() {
131 prefs.clearUserPref("network.http.http3.enable");
132 prefs.clearUserPref("network.dns.localDomains");
133 prefs.clearUserPref("network.dns.disableIPv6");
134 prefs.clearUserPref("network.http.http3.alt-svc-mapping-for-testing");