1 // This file ensures that canceling a channel early does not
2 // send the request to the server (bug 350790)
4 do_import_script("netwerk/test/httpserver/httpd.js");
6 const NS_BINDING_ABORTED = 0x804b0002;
9 QueryInterface: function eventsink_qi(iid) {
10 if (iid.equals(Components.interfaces.nsISupports) ||
11 iid.equals(Components.interfaces.nsIObserver))
13 throw Components.results.NS_ERROR_NO_INTERFACE;
16 observe: function(subject, topic, data) {
17 subject = subject.QueryInterface(Components.interfaces.nsIRequest);
18 subject.cancel(NS_BINDING_ABORTED);
20 var obs = Components.classes["@mozilla.org/observer-service;1"].getService();
21 obs = obs.QueryInterface(Components.interfaces.nsIObserverService);
22 obs.removeObserver(observer, "http-on-modify-request");
27 onStartRequest: function test_onStartR(request, ctx) {
28 do_check_eq(request.status, NS_BINDING_ABORTED);
31 onDataAvailable: function test_ODA() {
32 do_throw("Should not get any data!");
35 onStopRequest: function test_onStopR(request, ctx, status) {
41 function makeChan(url) {
42 var ios = Components.classes["@mozilla.org/network/io-service;1"]
43 .getService(Components.interfaces.nsIIOService);
44 var chan = ios.newChannel(url, null, null)
45 .QueryInterface(Components.interfaces.nsIHttpChannel);
53 httpserv = new nsHttpServer();
54 httpserv.registerPathHandler("/failtest", failtest);
57 var obs = Components.classes["@mozilla.org/observer-service;1"].getService();
58 obs = obs.QueryInterface(Components.interfaces.nsIObserverService);
59 obs.addObserver(observer, "http-on-modify-request", false);
61 var chan = makeChan("http://localhost:4444/failtest");
63 chan.asyncOpen(listener, null);
71 function failtest(metadata, response) {
72 do_throw("This should not be reached");