netwerk/test/unit/test_bug369787.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 Cu.import("resource://testing-common/httpd.js");
     3 const BUGID = "369787";
     4 var server = null;
     5 var channel = null;
     7 function change_content_type() {
     8   var origType = channel.contentType;
     9   const newType = "x-foo/x-bar";
    10   channel.contentType = newType;
    11   do_check_eq(channel.contentType, newType);
    12   channel.contentType = origType;
    13   do_check_eq(channel.contentType, origType);
    14 }
    16 function TestListener() {
    17 }
    18 TestListener.prototype.onStartRequest = function(request, context) {
    19   try {
    20     // request might be different from channel
    21     channel = request.QueryInterface(Components.interfaces.nsIChannel);
    23     change_content_type();
    24   } catch (ex) {
    25     print(ex);
    26     throw ex;
    27   }
    28 }
    29 TestListener.prototype.onStopRequest = function(request, context, status) {
    30   try {
    31     change_content_type();
    32   } catch (ex) {
    33     print(ex);
    34     // don't re-throw ex to avoid hanging the test
    35   }
    37   do_timeout(0, after_channel_closed);
    38 }
    40 function after_channel_closed() {
    41   try {
    42     change_content_type();
    43   } finally {
    44     server.stop(do_test_finished);
    45   }
    46 }
    48 function run_test() {
    49   // start server
    50   server = new HttpServer();
    52   server.registerPathHandler("/bug" + BUGID, bug369787);
    54   server.start(-1);
    56   // make request
    57   channel =
    58       Components.classes["@mozilla.org/network/io-service;1"].
    59       getService(Components.interfaces.nsIIOService).
    60       newChannel("http://localhost:" +
    61                  server.identity.primaryPort + "/bug" + BUGID, null, null);
    63   channel.QueryInterface(Components.interfaces.nsIHttpChannel);
    64   channel.asyncOpen(new TestListener(), null);
    66   do_test_pending();
    67 }
    69 // PATH HANDLER FOR /bug369787
    70 function bug369787(metadata, response) {
    71   /* do nothing */
    72 }

mercurial