3 var CC
= Components
.Constructor
;
5 const ServerSocket
= CC(
6 "@mozilla.org/network/server-socket;1",
11 var obs
= Services
.obs
;
13 // A server that waits for a connect. If a channel is suspended it should not
14 // try to connect to the server until it is is resumed or not try at all if it
15 // is cancelled as in this test.
16 function TestServer() {
17 this.listener
= ServerSocket(-1, true, -1);
18 this.port
= this.listener
.port
;
19 this.listener
.asyncListen(this);
22 TestServer
.prototype = {
24 Assert
.ok(false, "Socket should not have tried to connect!");
31 this.listener
.close();
36 var requestListenerObserver
= {
37 QueryInterface
: ChromeUtils
.generateQI(["nsIObserver"]),
39 observe(subject
, topic
) {
41 topic
=== "http-on-modify-request" &&
42 subject
instanceof Ci
.nsIHttpChannel
44 var chan
= subject
.QueryInterface(Ci
.nsIHttpChannel
);
46 obs
.removeObserver(this, "http-on-modify-request");
48 // Timers are bad, but we need to wait to see that we are not trying to
49 // connect to the server. There are no other event since nothing should
50 // happen until we resume the channel.
51 let timer
= Cc
["@mozilla.org/timer;1"].createInstance(Ci
.nsITimer
);
52 timer
.initWithCallback(
54 chan
.cancel(Cr
.NS_BINDING_ABORTED
);
58 Ci
.nsITimer
.TYPE_ONE_SHOT
65 onStartRequest
: function test_onStartR() {},
67 onDataAvailable
: function test_ODA() {
68 do_throw("Should not get any data!");
71 onStopRequest
: function test_onStopR() {
72 executeSoon(run_next_test
);
76 // Add observer and start a channel. Observer is going to suspend the channel on
77 // "http-on-modify-request" even. If a channel is suspended so early it should
78 // not try to connect at all until it is resumed. In this case we are going to
79 // wait for some time and cancel the channel before resuming it.
80 add_test(function testNoConnectChannelCanceledEarly() {
81 let serv
= new TestServer();
83 obs
.addObserver(requestListenerObserver
, "http-on-modify-request");
84 var chan
= NetUtil
.newChannel({
85 uri
: "http://localhost:" + serv
.port
,
86 loadUsingSystemPrincipal
: true,
88 chan
.asyncOpen(listener
);
90 registerCleanupFunction(function () {