1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/unit/test_channel_close.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,59 @@ 1.4 +Cu.import("resource://testing-common/httpd.js"); 1.5 + 1.6 +XPCOMUtils.defineLazyGetter(this, "URL", function() { 1.7 + return "http://localhost:" + httpserver.identity.primaryPort; 1.8 +}); 1.9 + 1.10 +var httpserver = new HttpServer(); 1.11 +var testpath = "/simple"; 1.12 +var httpbody = "0123456789"; 1.13 + 1.14 +var live_channels = []; 1.15 + 1.16 +function run_test() { 1.17 + httpserver.registerPathHandler(testpath, serverHandler); 1.18 + httpserver.start(-1); 1.19 + 1.20 + var local_channel; 1.21 + 1.22 + // Opened channel that has no remaining references on shutdown 1.23 + local_channel = setupChannel(testpath); 1.24 + local_channel.asyncOpen( 1.25 + new ChannelListener(checkRequest, local_channel), null); 1.26 + 1.27 + // Opened channel that has no remaining references after being opened 1.28 + setupChannel(testpath).asyncOpen( 1.29 + new ChannelListener(function() {}, null), null); 1.30 + 1.31 + // Unopened channel that has remaining references on shutdown 1.32 + live_channels.push(setupChannel(testpath)); 1.33 + 1.34 + // Opened channel that has remaining references on shutdown 1.35 + live_channels.push(setupChannel(testpath)); 1.36 + live_channels[1].asyncOpen( 1.37 + new ChannelListener(checkRequestFinish, live_channels[1]), null); 1.38 + 1.39 + do_test_pending(); 1.40 +} 1.41 + 1.42 +function setupChannel(path) { 1.43 + var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); 1.44 + var chan = ios.newChannel(URL + path, "", null); 1.45 + chan.QueryInterface(Ci.nsIHttpChannel); 1.46 + chan.requestMethod = "GET"; 1.47 + return chan; 1.48 +} 1.49 + 1.50 +function serverHandler(metadata, response) { 1.51 + response.setHeader("Content-Type", "text/plain", false); 1.52 + response.bodyOutputStream.write(httpbody, httpbody.length); 1.53 +} 1.54 + 1.55 +function checkRequest(request, data, context) { 1.56 + do_check_eq(data, httpbody); 1.57 +} 1.58 + 1.59 +function checkRequestFinish(request, data, context) { 1.60 + checkRequest(request, data, context); 1.61 + httpserver.stop(do_test_finished); 1.62 +}