netwerk/test/unit/test_channel_close.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 Cu.import("resource://testing-common/httpd.js");
michael@0 2
michael@0 3 XPCOMUtils.defineLazyGetter(this, "URL", function() {
michael@0 4 return "http://localhost:" + httpserver.identity.primaryPort;
michael@0 5 });
michael@0 6
michael@0 7 var httpserver = new HttpServer();
michael@0 8 var testpath = "/simple";
michael@0 9 var httpbody = "0123456789";
michael@0 10
michael@0 11 var live_channels = [];
michael@0 12
michael@0 13 function run_test() {
michael@0 14 httpserver.registerPathHandler(testpath, serverHandler);
michael@0 15 httpserver.start(-1);
michael@0 16
michael@0 17 var local_channel;
michael@0 18
michael@0 19 // Opened channel that has no remaining references on shutdown
michael@0 20 local_channel = setupChannel(testpath);
michael@0 21 local_channel.asyncOpen(
michael@0 22 new ChannelListener(checkRequest, local_channel), null);
michael@0 23
michael@0 24 // Opened channel that has no remaining references after being opened
michael@0 25 setupChannel(testpath).asyncOpen(
michael@0 26 new ChannelListener(function() {}, null), null);
michael@0 27
michael@0 28 // Unopened channel that has remaining references on shutdown
michael@0 29 live_channels.push(setupChannel(testpath));
michael@0 30
michael@0 31 // Opened channel that has remaining references on shutdown
michael@0 32 live_channels.push(setupChannel(testpath));
michael@0 33 live_channels[1].asyncOpen(
michael@0 34 new ChannelListener(checkRequestFinish, live_channels[1]), null);
michael@0 35
michael@0 36 do_test_pending();
michael@0 37 }
michael@0 38
michael@0 39 function setupChannel(path) {
michael@0 40 var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
michael@0 41 var chan = ios.newChannel(URL + path, "", null);
michael@0 42 chan.QueryInterface(Ci.nsIHttpChannel);
michael@0 43 chan.requestMethod = "GET";
michael@0 44 return chan;
michael@0 45 }
michael@0 46
michael@0 47 function serverHandler(metadata, response) {
michael@0 48 response.setHeader("Content-Type", "text/plain", false);
michael@0 49 response.bodyOutputStream.write(httpbody, httpbody.length);
michael@0 50 }
michael@0 51
michael@0 52 function checkRequest(request, data, context) {
michael@0 53 do_check_eq(data, httpbody);
michael@0 54 }
michael@0 55
michael@0 56 function checkRequestFinish(request, data, context) {
michael@0 57 checkRequest(request, data, context);
michael@0 58 httpserver.stop(do_test_finished);
michael@0 59 }

mercurial