michael@0: Cu.import("resource://testing-common/httpd.js"); michael@0: michael@0: var httpserver = null; michael@0: var simplePath = "/simple"; michael@0: var normalPath = "/normal"; michael@0: var httpbody = ""; michael@0: michael@0: XPCOMUtils.defineLazyGetter(this, "uri1", function() { michael@0: return "http://localhost:" + httpserver.identity.primaryPort + simplePath; michael@0: }); michael@0: michael@0: XPCOMUtils.defineLazyGetter(this, "uri2", function() { michael@0: return "http://localhost:" + httpserver.identity.primaryPort + normalPath; michael@0: }); michael@0: michael@0: function make_channel(url) { michael@0: var ios = Cc["@mozilla.org/network/io-service;1"]. michael@0: getService(Ci.nsIIOService); michael@0: return ios.newChannel(url, "", null); michael@0: } michael@0: michael@0: var listener_proto = { michael@0: QueryInterface: function(iid) { michael@0: if (iid.equals(Components.interfaces.nsIStreamListener) || michael@0: iid.equals(Components.interfaces.nsIRequestObserver) || michael@0: iid.equals(Components.interfaces.nsISupports)) michael@0: return this; michael@0: throw Components.results.NS_ERROR_NO_INTERFACE; michael@0: }, michael@0: michael@0: onStartRequest: function(request, context) { michael@0: do_check_eq(request.QueryInterface(Ci.nsIChannel).contentType, michael@0: this.contentType); michael@0: request.cancel(Cr.NS_BINDING_ABORTED); michael@0: }, michael@0: michael@0: onDataAvailable: function(request, context, stream, offset, count) { michael@0: do_throw("Unexpected onDataAvailable"); michael@0: }, michael@0: michael@0: onStopRequest: function(request, context, status) { michael@0: do_check_eq(status, Cr.NS_BINDING_ABORTED); michael@0: this.termination_func(); michael@0: } michael@0: }; michael@0: michael@0: function listener(contentType, termination_func) { michael@0: this.contentType = contentType; michael@0: this.termination_func = termination_func; michael@0: } michael@0: listener.prototype = listener_proto; michael@0: michael@0: function run_test() michael@0: { michael@0: httpserver = new HttpServer(); michael@0: httpserver.registerPathHandler(simplePath, simpleHandler); michael@0: httpserver.registerPathHandler(normalPath, normalHandler); michael@0: httpserver.start(-1); michael@0: michael@0: var channel = make_channel(uri1); michael@0: channel.asyncOpen(new listener("text/plain", function() { michael@0: run_test2(); michael@0: }), null); michael@0: michael@0: do_test_pending(); michael@0: } michael@0: michael@0: function run_test2() michael@0: { michael@0: var channel = make_channel(uri2); michael@0: channel.asyncOpen(new listener("text/html", function() { michael@0: httpserver.stop(do_test_finished); michael@0: }), null); michael@0: } michael@0: michael@0: function simpleHandler(metadata, response) michael@0: { michael@0: response.seizePower(); michael@0: response.bodyOutputStream.write(httpbody, httpbody.length); michael@0: response.finish(); michael@0: } michael@0: michael@0: function normalHandler(metadata, response) michael@0: { michael@0: response.bodyOutputStream.write(httpbody, httpbody.length); michael@0: response.finish(); michael@0: }