netwerk/test/unit/test_bug369787.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/test/unit/test_bug369787.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,72 @@
     1.4 +Cu.import("resource://testing-common/httpd.js");
     1.5 +
     1.6 +const BUGID = "369787";
     1.7 +var server = null;
     1.8 +var channel = null;
     1.9 +
    1.10 +function change_content_type() {
    1.11 +  var origType = channel.contentType;
    1.12 +  const newType = "x-foo/x-bar";
    1.13 +  channel.contentType = newType;
    1.14 +  do_check_eq(channel.contentType, newType);
    1.15 +  channel.contentType = origType;
    1.16 +  do_check_eq(channel.contentType, origType);
    1.17 +}
    1.18 +
    1.19 +function TestListener() {
    1.20 +}
    1.21 +TestListener.prototype.onStartRequest = function(request, context) {
    1.22 +  try {
    1.23 +    // request might be different from channel
    1.24 +    channel = request.QueryInterface(Components.interfaces.nsIChannel);
    1.25 +
    1.26 +    change_content_type();
    1.27 +  } catch (ex) {
    1.28 +    print(ex);
    1.29 +    throw ex;
    1.30 +  }
    1.31 +}
    1.32 +TestListener.prototype.onStopRequest = function(request, context, status) {
    1.33 +  try {
    1.34 +    change_content_type();
    1.35 +  } catch (ex) {
    1.36 +    print(ex);
    1.37 +    // don't re-throw ex to avoid hanging the test
    1.38 +  }
    1.39 +
    1.40 +  do_timeout(0, after_channel_closed);
    1.41 +}
    1.42 +
    1.43 +function after_channel_closed() {
    1.44 +  try {
    1.45 +    change_content_type();
    1.46 +  } finally {
    1.47 +    server.stop(do_test_finished);
    1.48 +  }
    1.49 +}
    1.50 +
    1.51 +function run_test() {
    1.52 +  // start server
    1.53 +  server = new HttpServer();
    1.54 +
    1.55 +  server.registerPathHandler("/bug" + BUGID, bug369787);
    1.56 +
    1.57 +  server.start(-1);
    1.58 +
    1.59 +  // make request
    1.60 +  channel =
    1.61 +      Components.classes["@mozilla.org/network/io-service;1"].
    1.62 +      getService(Components.interfaces.nsIIOService).
    1.63 +      newChannel("http://localhost:" +
    1.64 +                 server.identity.primaryPort + "/bug" + BUGID, null, null);
    1.65 +
    1.66 +  channel.QueryInterface(Components.interfaces.nsIHttpChannel);
    1.67 +  channel.asyncOpen(new TestListener(), null);
    1.68 +
    1.69 +  do_test_pending();
    1.70 +}
    1.71 +
    1.72 +// PATH HANDLER FOR /bug369787
    1.73 +function bug369787(metadata, response) {
    1.74 +  /* do nothing */
    1.75 +}

mercurial