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 let env = Cc["@mozilla.org/process/environment;1"].getService(
33 h3Port = env.get("MOZHTTP3_PORT");
34 Assert.notEqual(h3Port, null);
35 Assert.notEqual(h3Port, "");
36 h3AltSvc = ":" + h3Port;
38 h3Route = "foo.example.com:" + h3Port;
40 prefs = Services.prefs;
42 prefs.setBoolPref("network.http.http3.enable", true);
43 prefs.setCharPref("network.dns.localDomains", "foo.example.com");
44 prefs.setBoolPref("network.dns.disableIPv6", true);
46 // The certificate for the http3server server is for foo.example.com and
47 // is signed by http2-ca.pem so add that cert to the trust list as a
49 let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService(
52 addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u");
53 httpsOrigin = "https://foo.example.com/";
58 let Http3CheckListener = function() {};
60 Http3CheckListener.prototype = {
62 expectedStatus: Cr.NS_OK,
64 onStartRequest: function testOnStartRequest(request) {
65 Assert.ok(request instanceof Ci.nsIHttpChannel);
66 Assert.equal(request.status, this.expectedStatus);
67 if (Components.isSuccessCode(this.expectedStatus)) {
68 Assert.equal(request.responseStatus, 200);
72 onDataAvailable: function testOnDataAvailable(request, stream, off, cnt) {
73 read_stream(stream, cnt);
76 onStopRequest: function testOnStopRequest(request, status) {
77 Assert.equal(status, this.expectedStatus);
78 if (Components.isSuccessCode(this.expectedStatus)) {
79 Assert.equal(request.responseStatus, 200);
82 routed = request.getRequestHeader("Alt-Used");
84 dump("routed is " + routed + "\n");
86 Assert.equal(routed, this.expectedRoute);
90 httpVersion = request.protocolVersion;
92 Assert.equal(httpVersion, "h3");
99 function makeChan(uri) {
100 let chan = NetUtil.newChannel({
102 loadUsingSystemPrincipal: true,
103 }).QueryInterface(Ci.nsIHttpChannel);
104 chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
108 function test_no_altsvc_pref() {
109 dump("test_no_altsvc_pref");
112 let chan = makeChan(httpsOrigin + "http3-test");
113 let listener = new Http3CheckListener();
114 listener.expectedStatus = Cr.NS_ERROR_CONNECTION_REFUSED;
115 chan.asyncOpen(listener);
118 function test_altsvc_pref() {
119 dump("test_altsvc_pref");
123 "network.http.http3.alt-svc-mapping-for-testing",
124 "foo.example.com;h3-29=" + h3AltSvc
127 let chan = makeChan(httpsOrigin + "http3-test");
128 let listener = new Http3CheckListener();
129 listener.expectedRoute = h3Route;
130 chan.asyncOpen(listener);
133 function testsDone() {
134 prefs.clearUserPref("network.http.http3.enable");
135 prefs.clearUserPref("network.dns.localDomains");
136 prefs.clearUserPref("network.dns.disableIPv6");
137 prefs.clearUserPref("network.http.http3.alt-svc-mapping-for-testing");