1 // Test nsIThrottledInputChannel interface.
4 const { HttpServer } = ChromeUtils.importESModule(
5 "resource://testing-common/httpd.sys.mjs"
8 function test_handler(metadata, response) {
9 const originalBody = "the response";
10 response.setHeader("Content-Type", "text/html", false);
11 response.setStatusLine(metadata.httpVersion, 200, "OK");
12 response.bodyOutputStream.write(originalBody, originalBody.length);
15 function make_channel(url) {
16 return NetUtil.newChannel({
18 loadUsingSystemPrincipal: true,
19 }).QueryInterface(Ci.nsIHttpChannel);
23 let httpserver = new HttpServer();
25 const PORT = httpserver.identity.primaryPort;
27 httpserver.registerPathHandler("/testdir", test_handler);
29 let channel = make_channel("http://localhost:" + PORT + "/testdir");
31 let tq = Cc["@mozilla.org/network/throttlequeue;1"].createInstance(
32 Ci.nsIInputChannelThrottleQueue
36 let tic = channel.QueryInterface(Ci.nsIThrottledInputChannel);
37 tic.throttleQueue = tq;
40 new ChannelListener(() => {
41 ok(tq.bytesProcessed() > 0, "throttled queue processed some bytes");
43 httpserver.stop(do_test_finished);