tor-browser

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

test_is_proxy_used.js (1129B)


      1 "use strict";
      2 
      3 const { NodeHTTPServer, NodeHTTPProxyServer } = ChromeUtils.importESModule(
      4  "resource://testing-common/NodeServer.sys.mjs"
      5 );
      6 
      7 // We don't normally allow localhost channels to be proxied, but this
      8 // is easier than updating all the certs and/or domains.
      9 Services.prefs.setBoolPref("network.proxy.allow_hijacking_localhost", true);
     10 registerCleanupFunction(() => {
     11  Services.prefs.clearUserPref("network.proxy.allow_hijacking_localhost");
     12 });
     13 
     14 add_task(async function run_test() {
     15  let proxy = new NodeHTTPProxyServer();
     16  await proxy.start();
     17  registerCleanupFunction(async () => {
     18    await proxy.stop();
     19  });
     20 
     21  let server = new NodeHTTPServer();
     22 
     23  await server.start();
     24  registerCleanupFunction(async () => {
     25    await server.stop();
     26  });
     27 
     28  await server.registerPathHandler("/test", (req, resp) => {
     29    let content = "content";
     30    resp.writeHead(200);
     31    resp.end(content);
     32  });
     33 
     34  do_await_remote_message("start-test").then(() => {
     35    do_send_remote_message(
     36      "start-test-done",
     37      `http://localhost:${server.port()}/test`
     38    );
     39  });
     40 
     41  run_test_in_child("child_is_proxy_used.js");
     42 });