netwerk/test/unit/test_bug667907.js

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 Cu.import("resource://testing-common/httpd.js");
     3 var httpserver = null;
     4 var simplePath = "/simple";
     5 var normalPath = "/normal";
     6 var httpbody = "<html></html>";
     8 XPCOMUtils.defineLazyGetter(this, "uri1", function() {
     9   return "http://localhost:" + httpserver.identity.primaryPort + simplePath;
    10 });
    12 XPCOMUtils.defineLazyGetter(this, "uri2", function() {
    13   return "http://localhost:" + httpserver.identity.primaryPort + normalPath;
    14 });
    16 function make_channel(url) {
    17   var ios = Cc["@mozilla.org/network/io-service;1"].
    18             getService(Ci.nsIIOService);
    19   return ios.newChannel(url, "", null);
    20 }
    22 var listener_proto = {
    23   QueryInterface: function(iid) {
    24     if (iid.equals(Components.interfaces.nsIStreamListener) ||
    25         iid.equals(Components.interfaces.nsIRequestObserver) ||
    26         iid.equals(Components.interfaces.nsISupports))
    27       return this;
    28     throw Components.results.NS_ERROR_NO_INTERFACE;
    29   },
    31   onStartRequest: function(request, context) {
    32     do_check_eq(request.QueryInterface(Ci.nsIChannel).contentType,
    33 		this.contentType);
    34     request.cancel(Cr.NS_BINDING_ABORTED);
    35   },
    37   onDataAvailable: function(request, context, stream, offset, count) {
    38     do_throw("Unexpected onDataAvailable");
    39   },
    41   onStopRequest: function(request, context, status) {
    42     do_check_eq(status, Cr.NS_BINDING_ABORTED);
    43     this.termination_func();
    44   }  
    45 };
    47 function listener(contentType, termination_func) {
    48   this.contentType = contentType;
    49   this.termination_func = termination_func;
    50 }
    51 listener.prototype = listener_proto;
    53 function run_test()
    54 {
    55   httpserver = new HttpServer();
    56   httpserver.registerPathHandler(simplePath, simpleHandler);
    57   httpserver.registerPathHandler(normalPath, normalHandler);
    58   httpserver.start(-1);
    60   var channel = make_channel(uri1);
    61   channel.asyncOpen(new listener("text/plain", function() {
    62 	run_test2();
    63       }), null);
    65   do_test_pending();
    66 }
    68 function run_test2()
    69 {
    70   var channel = make_channel(uri2);
    71   channel.asyncOpen(new listener("text/html", function() {
    72 	httpserver.stop(do_test_finished);
    73       }), null);
    74 }
    76 function simpleHandler(metadata, response)
    77 {
    78   response.seizePower();
    79   response.bodyOutputStream.write(httpbody, httpbody.length);
    80   response.finish();
    81 }
    83 function normalHandler(metadata, response)
    84 {
    85   response.bodyOutputStream.write(httpbody, httpbody.length);
    86   response.finish();
    87 }

mercurial