1 // Test nsIThrottledInputChannel interface.
4 const { HttpServer } = ChromeUtils.import("resource://testing-common/httpd.js");
6 function test_handler(metadata, response) {
7 const originalBody = "the response";
8 response.setHeader("Content-Type", "text/html", false);
9 response.setStatusLine(metadata.httpVersion, 200, "OK");
10 response.bodyOutputStream.write(originalBody, originalBody.length);
13 function make_channel(url) {
14 return NetUtil.newChannel({
16 loadUsingSystemPrincipal: true,
17 }).QueryInterface(Ci.nsIHttpChannel);
21 let httpserver = new HttpServer();
23 const PORT = httpserver.identity.primaryPort;
25 httpserver.registerPathHandler("/testdir", test_handler);
27 let channel = make_channel("http://localhost:" + PORT + "/testdir");
29 let tq = Cc["@mozilla.org/network/throttlequeue;1"].createInstance(
30 Ci.nsIInputChannelThrottleQueue
34 let tic = channel.QueryInterface(Ci.nsIThrottledInputChannel);
35 tic.throttleQueue = tq;
38 new ChannelListener(() => {
39 ok(tq.bytesProcessed() > 0, "throttled queue processed some bytes");
41 httpserver.stop(do_test_finished);