tor-browser

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

test_proxy-replace_canceled.js (1727B)


      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({
     11    uri: url,
     12    loadUsingSystemPrincipal: true,
     13  });
     14 }
     15 
     16 const responseBody = "response body";
     17 
     18 function contentHandler(metadata, response) {
     19  response.setHeader("Content-Type", "text/plain");
     20  response.bodyOutputStream.write(responseBody, responseBody.length);
     21 }
     22 
     23 function finish_test(request, buffer) {
     24  Assert.equal(buffer, "");
     25  httpServer.stop(do_test_finished);
     26 }
     27 
     28 function run_test() {
     29  httpServer = new HttpServer();
     30  httpServer.registerPathHandler("/content", contentHandler);
     31  httpServer.start(-1);
     32 
     33  var prefs = Services.prefs.getBranch("network.proxy.");
     34  prefs.setIntPref("type", 2);
     35  prefs.setCharPref(
     36    "autoconfig_url",
     37    "data:text/plain," +
     38      "function FindProxyForURL(url, host) {return 'PROXY localhost:" +
     39      httpServer.identity.primaryPort +
     40      "';}"
     41  );
     42 
     43  // this test assumed that a AsyncOnChannelRedirect query is made for
     44  // each proxy failover or on the inital proxy only when PAC mode is used.
     45  // Neither of those are documented anywhere that I can find and the latter
     46  // hasn't been a useful property because it is PAC dependent and the type
     47  // is generally unknown and OS driven. 769764 changed that to remove the
     48  // internal redirect used to setup the initial proxy/channel as that isn't
     49  // a redirect in any sense.
     50 
     51  var chan = make_channel(
     52    "http://localhost:" + httpServer.identity.primaryPort + "/content"
     53  );
     54  chan.asyncOpen(new ChannelListener(finish_test, null, CL_EXPECT_FAILURE));
     55  chan.cancel(Cr.NS_BINDING_ABORTED);
     56  do_test_pending();
     57 }