1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/unit/test_bug667907.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,87 @@ 1.4 +Cu.import("resource://testing-common/httpd.js"); 1.5 + 1.6 +var httpserver = null; 1.7 +var simplePath = "/simple"; 1.8 +var normalPath = "/normal"; 1.9 +var httpbody = "<html></html>"; 1.10 + 1.11 +XPCOMUtils.defineLazyGetter(this, "uri1", function() { 1.12 + return "http://localhost:" + httpserver.identity.primaryPort + simplePath; 1.13 +}); 1.14 + 1.15 +XPCOMUtils.defineLazyGetter(this, "uri2", function() { 1.16 + return "http://localhost:" + httpserver.identity.primaryPort + normalPath; 1.17 +}); 1.18 + 1.19 +function make_channel(url) { 1.20 + var ios = Cc["@mozilla.org/network/io-service;1"]. 1.21 + getService(Ci.nsIIOService); 1.22 + return ios.newChannel(url, "", null); 1.23 +} 1.24 + 1.25 +var listener_proto = { 1.26 + QueryInterface: function(iid) { 1.27 + if (iid.equals(Components.interfaces.nsIStreamListener) || 1.28 + iid.equals(Components.interfaces.nsIRequestObserver) || 1.29 + iid.equals(Components.interfaces.nsISupports)) 1.30 + return this; 1.31 + throw Components.results.NS_ERROR_NO_INTERFACE; 1.32 + }, 1.33 + 1.34 + onStartRequest: function(request, context) { 1.35 + do_check_eq(request.QueryInterface(Ci.nsIChannel).contentType, 1.36 + this.contentType); 1.37 + request.cancel(Cr.NS_BINDING_ABORTED); 1.38 + }, 1.39 + 1.40 + onDataAvailable: function(request, context, stream, offset, count) { 1.41 + do_throw("Unexpected onDataAvailable"); 1.42 + }, 1.43 + 1.44 + onStopRequest: function(request, context, status) { 1.45 + do_check_eq(status, Cr.NS_BINDING_ABORTED); 1.46 + this.termination_func(); 1.47 + } 1.48 +}; 1.49 + 1.50 +function listener(contentType, termination_func) { 1.51 + this.contentType = contentType; 1.52 + this.termination_func = termination_func; 1.53 +} 1.54 +listener.prototype = listener_proto; 1.55 + 1.56 +function run_test() 1.57 +{ 1.58 + httpserver = new HttpServer(); 1.59 + httpserver.registerPathHandler(simplePath, simpleHandler); 1.60 + httpserver.registerPathHandler(normalPath, normalHandler); 1.61 + httpserver.start(-1); 1.62 + 1.63 + var channel = make_channel(uri1); 1.64 + channel.asyncOpen(new listener("text/plain", function() { 1.65 + run_test2(); 1.66 + }), null); 1.67 + 1.68 + do_test_pending(); 1.69 +} 1.70 + 1.71 +function run_test2() 1.72 +{ 1.73 + var channel = make_channel(uri2); 1.74 + channel.asyncOpen(new listener("text/html", function() { 1.75 + httpserver.stop(do_test_finished); 1.76 + }), null); 1.77 +} 1.78 + 1.79 +function simpleHandler(metadata, response) 1.80 +{ 1.81 + response.seizePower(); 1.82 + response.bodyOutputStream.write(httpbody, httpbody.length); 1.83 + response.finish(); 1.84 +} 1.85 + 1.86 +function normalHandler(metadata, response) 1.87 +{ 1.88 + response.bodyOutputStream.write(httpbody, httpbody.length); 1.89 + response.finish(); 1.90 +}