Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / netwerk / test / unit / test_throttlechannel.js
blobaf5604ff36f1b38ae80a87396a2708b1f4ba764c
1 // Test nsIThrottledInputChannel interface.
2 "use strict";
4 const { HttpServer } = ChromeUtils.importESModule(
5 "resource://testing-common/httpd.sys.mjs"
6 );
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({
17 uri: url,
18 loadUsingSystemPrincipal: true,
19 }).QueryInterface(Ci.nsIHttpChannel);
22 function run_test() {
23 let httpserver = new HttpServer();
24 httpserver.start(-1);
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
34 tq.init(1000, 1000);
36 let tic = channel.QueryInterface(Ci.nsIThrottledInputChannel);
37 tic.throttleQueue = tq;
39 channel.asyncOpen(
40 new ChannelListener(() => {
41 Assert.greater(
42 tq.bytesProcessed(),
44 "throttled queue processed some bytes"
47 httpserver.stop(do_test_finished);
51 do_test_pending();