tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_http3_direct_proxy.js (1619B)


      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 // Test if a HTTP3 connection can be established when a proxy info says
      6 // to use direct connection
      7 
      8 "use strict";
      9 
     10 registerCleanupFunction(async () => {
     11  http3_clear_prefs();
     12  Services.prefs.clearUserPref("network.proxy.type");
     13  Services.prefs.clearUserPref("network.proxy.autoconfig_url");
     14 });
     15 
     16 add_task(async function setup() {
     17  await http3_setup_tests("h3");
     18 });
     19 
     20 function makeChan(url) {
     21  let chan = NetUtil.newChannel({
     22    uri: url,
     23    loadUsingSystemPrincipal: true,
     24    contentPolicyType: Ci.nsIContentPolicy.TYPE_DOCUMENT,
     25  }).QueryInterface(Ci.nsIHttpChannel);
     26  chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
     27  return chan;
     28 }
     29 
     30 function channelOpenPromise(chan, flags) {
     31  return new Promise(resolve => {
     32    function finish(req, buffer) {
     33      resolve([req, buffer]);
     34    }
     35    chan.asyncOpen(new ChannelListener(finish, null, flags));
     36  });
     37 }
     38 
     39 add_task(async function testHttp3WithDirectProxy() {
     40  var pac =
     41    "data:text/plain," +
     42    "function FindProxyForURL(url, host) {" +
     43    '  return "DIRECT; PROXY foopy:8080;"' +
     44    "}";
     45 
     46  // Configure PAC
     47  Services.prefs.setIntPref("network.proxy.type", 2);
     48  Services.prefs.setCharPref("network.proxy.autoconfig_url", pac);
     49 
     50  let chan = makeChan(`https://foo.example.com`);
     51  let [req] = await channelOpenPromise(chan, CL_ALLOW_UNKNOWN_CL);
     52  req.QueryInterface(Ci.nsIHttpChannel);
     53  Assert.equal(req.protocolVersion, "h3");
     54 });