Follow-on fix for bug 457825. Use sheet principal for agent and user sheets. r=dbaron...
[wine-gecko.git] / netwerk / test / unit / test_httpcancel.js
blobecf73ed79ac7676809dc11461da5f697041c110a
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;
8 var observer = {
9   QueryInterface: function eventsink_qi(iid) {
10     if (iid.equals(Components.interfaces.nsISupports) ||
11         iid.equals(Components.interfaces.nsIObserver))
12       return this;
13     throw Components.results.NS_ERROR_NO_INTERFACE;
14   },
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");
23   }
26 var listener = {
27   onStartRequest: function test_onStartR(request, ctx) {
28     do_check_eq(request.status, NS_BINDING_ABORTED);
29   },
31   onDataAvailable: function test_ODA() {
32     do_throw("Should not get any data!");
33   },
35   onStopRequest: function test_onStopR(request, ctx, status) {
36     httpserv.stop();
37     do_test_finished();
38   }
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);
47   return chan;
50 var httpserv = null;
52 function run_test() {
53   httpserv = new nsHttpServer();
54   httpserv.registerPathHandler("/failtest", failtest);
55   httpserv.start(4444);
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);
65   do_test_pending();
68 // PATHS
70 // /failtest
71 function failtest(metadata, response) {
72   do_throw("This should not be reached");