tor-browser

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

test_redirect_canceled.js (1461B)


      1 "use strict";
      2 
      3 const { HttpServer } = ChromeUtils.importESModule(
      4  "resource://testing-common/httpd.sys.mjs"
      5 );
      6 
      7 ChromeUtils.defineLazyGetter(this, "URL", function () {
      8  return "http://localhost:" + httpServer.identity.primaryPort;
      9 });
     10 
     11 var httpServer = null;
     12 // Need to randomize, because apparently no one clears our cache
     13 var randomPath = "/redirect/" + Math.random();
     14 
     15 ChromeUtils.defineLazyGetter(this, "randomURI", function () {
     16  return URL + randomPath;
     17 });
     18 
     19 function make_channel(url) {
     20  return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
     21 }
     22 
     23 const responseBody = "response body";
     24 
     25 function redirectHandler(metadata, response) {
     26  response.setStatusLine(metadata.httpVersion, 301, "Moved");
     27  response.setHeader("Location", URL + "/content", false);
     28 }
     29 
     30 function contentHandler(metadata, response) {
     31  response.setHeader("Content-Type", "text/plain");
     32  response.bodyOutputStream.write(responseBody, responseBody.length);
     33 }
     34 
     35 function finish_test(request, buffer) {
     36  Assert.equal(buffer, "");
     37  httpServer.stop(do_test_finished);
     38 }
     39 
     40 function run_test() {
     41  httpServer = new HttpServer();
     42  httpServer.registerPathHandler(randomPath, redirectHandler);
     43  httpServer.registerPathHandler("/content", contentHandler);
     44  httpServer.start(-1);
     45 
     46  var chan = make_channel(randomURI);
     47  chan.notificationCallbacks = new ChannelEventSink(ES_ABORT_REDIRECT);
     48  chan.asyncOpen(new ChannelListener(finish_test, null));
     49  do_test_pending();
     50 }