2010-08-10 20:07:09 -07:00
|
|
|
// This file ensures that suspending a channel directly after opening it
|
|
|
|
// suspends future notifications correctly.
|
|
|
|
|
2012-08-14 07:06:04 -07:00
|
|
|
Cu.import("resource://testing-common/httpd.js");
|
2010-08-10 20:07:09 -07:00
|
|
|
|
2013-07-19 10:19:28 -07:00
|
|
|
XPCOMUtils.defineLazyGetter(this, "URL", function() {
|
|
|
|
return "http://localhost:" + httpserv.identity.primaryPort;
|
|
|
|
});
|
|
|
|
|
2010-08-10 20:07:09 -07:00
|
|
|
const MIN_TIME_DIFFERENCE = 3000;
|
|
|
|
const RESUME_DELAY = 5000;
|
|
|
|
|
|
|
|
var listener = {
|
|
|
|
_lastEvent: 0,
|
|
|
|
_gotData: false,
|
|
|
|
|
|
|
|
QueryInterface: function(iid) {
|
|
|
|
if (iid.equals(Components.interfaces.nsIStreamListener) ||
|
|
|
|
iid.equals(Components.interfaces.nsIRequestObserver) ||
|
|
|
|
iid.equals(Components.interfaces.nsISupports))
|
|
|
|
return this;
|
|
|
|
throw Components.results.NS_ERROR_NO_INTERFACE;
|
|
|
|
},
|
|
|
|
|
|
|
|
onStartRequest: function(request, ctx) {
|
|
|
|
this._lastEvent = Date.now();
|
|
|
|
request.QueryInterface(Ci.nsIRequest);
|
|
|
|
|
|
|
|
// Insert a delay between this and the next callback to ensure message buffering
|
|
|
|
// works correctly
|
|
|
|
request.suspend();
|
2011-06-11 18:37:09 -07:00
|
|
|
request.suspend();
|
2010-08-10 20:07:09 -07:00
|
|
|
do_timeout(RESUME_DELAY, function() request.resume());
|
2011-06-11 18:37:09 -07:00
|
|
|
do_timeout(RESUME_DELAY + 1000, function() request.resume());
|
2010-08-10 20:07:09 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
onDataAvailable: function(request, context, stream, offset, count) {
|
|
|
|
do_check_true(Date.now() - this._lastEvent >= MIN_TIME_DIFFERENCE);
|
|
|
|
read_stream(stream, count);
|
|
|
|
|
|
|
|
// Ensure that suspending and resuming inside a callback works correctly
|
|
|
|
request.suspend();
|
2011-06-11 18:37:09 -07:00
|
|
|
request.suspend();
|
|
|
|
request.resume();
|
2010-08-10 20:07:09 -07:00
|
|
|
request.resume();
|
|
|
|
|
|
|
|
this._gotData = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
onStopRequest: function(request, ctx, status) {
|
|
|
|
do_check_true(this._gotData);
|
|
|
|
httpserv.stop(do_test_finished);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function makeChan(url) {
|
|
|
|
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
|
|
|
var chan = ios.newChannel(url, null, null).QueryInterface(Ci.nsIHttpChannel);
|
|
|
|
return chan;
|
|
|
|
}
|
|
|
|
|
|
|
|
var httpserv = null;
|
|
|
|
|
|
|
|
function run_test() {
|
2012-08-14 07:06:04 -07:00
|
|
|
httpserv = new HttpServer();
|
2010-08-10 20:07:09 -07:00
|
|
|
httpserv.registerPathHandler("/woo", data);
|
2013-07-19 10:19:28 -07:00
|
|
|
httpserv.start(-1);
|
2010-08-10 20:07:09 -07:00
|
|
|
|
2013-07-19 10:19:28 -07:00
|
|
|
var chan = makeChan(URL + "/woo");
|
2010-08-10 20:07:09 -07:00
|
|
|
chan.QueryInterface(Ci.nsIRequest);
|
|
|
|
chan.asyncOpen(listener, null);
|
|
|
|
|
|
|
|
do_test_pending();
|
|
|
|
}
|
|
|
|
|
|
|
|
function data(metadata, response) {
|
|
|
|
let httpbody = "0123456789";
|
|
|
|
response.setHeader("Content-Type", "text/plain", false);
|
|
|
|
response.bodyOutputStream.write(httpbody, httpbody.length);
|
|
|
|
}
|