1 // This file ensures that suspending a channel directly after opening it
2 // suspends future notifications correctly.
6 const { HttpServer } = ChromeUtils.importESModule(
7 "resource://testing-common/httpd.sys.mjs"
10 ChromeUtils.defineLazyGetter(this, "URL", function () {
11 return "http://localhost:" + httpserv.identity.primaryPort;
14 const MIN_TIME_DIFFERENCE = 3000;
15 const RESUME_DELAY = 5000;
21 QueryInterface: ChromeUtils.generateQI([
26 onStartRequest(request) {
27 this._lastEvent = Date.now();
28 request.QueryInterface(Ci.nsIRequest);
30 // Insert a delay between this and the next callback to ensure message buffering
34 do_timeout(RESUME_DELAY, function () {
37 do_timeout(RESUME_DELAY + 1000, function () {
42 onDataAvailable(request, stream, offset, count) {
43 Assert.ok(Date.now() - this._lastEvent >= MIN_TIME_DIFFERENCE);
44 read_stream(stream, count);
46 // Ensure that suspending and resuming inside a callback works correctly
55 onStopRequest(request, status) {
56 Assert.ok(this._gotData);
57 httpserv.stop(do_test_finished);
61 function makeChan(url) {
62 return NetUtil.newChannel({
64 loadUsingSystemPrincipal: true,
65 }).QueryInterface(Ci.nsIHttpChannel);
71 httpserv = new HttpServer();
72 httpserv.registerPathHandler("/woo", data);
75 var chan = makeChan(URL + "/woo");
76 chan.QueryInterface(Ci.nsIRequest);
77 chan.asyncOpen(listener);
82 function data(metadata, response) {
83 let httpbody = "0123456789";
84 response.setHeader("Content-Type", "text/plain", false);
85 response.bodyOutputStream.write(httpbody, httpbody.length);