test_bug1940663.js (1426B)
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 let h2Port; 8 9 function makeChan(url) { 10 let chan = NetUtil.newChannel({ 11 uri: url, 12 loadUsingSystemPrincipal: true, 13 contentPolicyType: Ci.nsIContentPolicy.TYPE_DOCUMENT, 14 }).QueryInterface(Ci.nsIHttpChannel); 15 return chan; 16 } 17 18 function channelOpenPromise(chan, flags) { 19 return new Promise(resolve => { 20 function finish(req, buffer) { 21 resolve([req, buffer]); 22 } 23 chan.asyncOpen(new ChannelListener(finish, null, flags)); 24 }); 25 } 26 27 add_setup(async function setup() { 28 h2Port = Services.env.get("MOZHTTP2_PORT"); 29 Assert.notEqual(h2Port, null); 30 Assert.notEqual(h2Port, ""); 31 32 let certdb = Cc["@mozilla.org/security/x509certdb;1"].getService( 33 Ci.nsIX509CertDB 34 ); 35 addCertFromFile(certdb, "http2-ca.pem", "CTu,u,u"); 36 37 Services.prefs.setCharPref("network.dns.localDomains", "foo.example.com"); 38 39 registerCleanupFunction(async () => { 40 Services.prefs.clearUserPref("network.dns.localDomains"); 41 }); 42 }); 43 44 add_task(async function test_http_1_1() { 45 let chan = makeChan( 46 `https://foo.example.com:${h2Port}/h11required_with_content` 47 ); 48 let [req, resp] = await channelOpenPromise(chan); 49 Assert.equal(req.protocolVersion, "h2"); 50 Assert.equal(resp, "ok"); 51 });