tor-browser

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

test_bug369787.js (1571B)


      1 "use strict";
      2 
      3 const { HttpServer } = ChromeUtils.importESModule(
      4  "resource://testing-common/httpd.sys.mjs"
      5 );
      6 
      7 const BUGID = "369787";
      8 var server = null;
      9 var channel = null;
     10 
     11 function change_content_type() {
     12  var origType = channel.contentType;
     13  const newType = "x-foo/x-bar";
     14  channel.contentType = newType;
     15  Assert.equal(channel.contentType, newType);
     16  channel.contentType = origType;
     17  Assert.equal(channel.contentType, origType);
     18 }
     19 
     20 function TestListener() {}
     21 TestListener.prototype.onStartRequest = function (request) {
     22  try {
     23    // request might be different from channel
     24    channel = request.QueryInterface(Ci.nsIChannel);
     25 
     26    change_content_type();
     27  } catch (ex) {
     28    print(ex);
     29    throw ex;
     30  }
     31 };
     32 TestListener.prototype.onStopRequest = function () {
     33  try {
     34    change_content_type();
     35  } catch (ex) {
     36    print(ex);
     37    // don't re-throw ex to avoid hanging the test
     38  }
     39 
     40  do_timeout(0, after_channel_closed);
     41 };
     42 
     43 function after_channel_closed() {
     44  try {
     45    change_content_type();
     46  } finally {
     47    server.stop(do_test_finished);
     48  }
     49 }
     50 
     51 function run_test() {
     52  // start server
     53  server = new HttpServer();
     54 
     55  server.registerPathHandler("/bug" + BUGID, bug369787);
     56 
     57  server.start(-1);
     58 
     59  // make request
     60  channel = NetUtil.newChannel({
     61    uri: "http://localhost:" + server.identity.primaryPort + "/bug" + BUGID,
     62    loadUsingSystemPrincipal: true,
     63  });
     64  channel.QueryInterface(Ci.nsIHttpChannel);
     65  channel.asyncOpen(new TestListener());
     66 
     67  do_test_pending();
     68 }
     69 
     70 // PATH HANDLER FOR /bug369787
     71 function bug369787() {
     72  /* do nothing */
     73 }