tor-browser

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

test_proxy-failover_passing.js (1228B)


      1 "use strict";
      2 
      3 const { HttpServer } = ChromeUtils.importESModule(
      4  "resource://testing-common/httpd.sys.mjs"
      5 );
      6 
      7 var httpServer = null;
      8 
      9 function make_channel(url) {
     10  return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
     11 }
     12 
     13 const responseBody = "response body";
     14 
     15 function contentHandler(metadata, response) {
     16  response.setHeader("Content-Type", "text/plain");
     17  response.bodyOutputStream.write(responseBody, responseBody.length);
     18 }
     19 
     20 function finish_test(request, buffer) {
     21  Assert.equal(buffer, responseBody);
     22  httpServer.stop(do_test_finished);
     23 }
     24 
     25 function run_test() {
     26  httpServer = new HttpServer();
     27  httpServer.registerPathHandler("/content", contentHandler);
     28  httpServer.start(-1);
     29 
     30  var prefs = Services.prefs.getBranch("network.proxy.");
     31  prefs.setIntPref("type", 2);
     32  prefs.setCharPref(
     33    "autoconfig_url",
     34    "data:text/plain," +
     35      "function FindProxyForURL(url, host) {return 'PROXY a_non_existent_domain_x7x6c572v:80; PROXY localhost:" +
     36      httpServer.identity.primaryPort +
     37      "';}"
     38  );
     39 
     40  var chan = make_channel(
     41    "http://localhost:" + httpServer.identity.primaryPort + "/content"
     42  );
     43  chan.asyncOpen(new ChannelListener(finish_test, null));
     44  do_test_pending();
     45 }