Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / netwerk / test / unit / test_bug667907.js
blobb407a4777b301949d1302d01ac09df8dfbe0a717
1 "use strict";
3 const { HttpServer } = ChromeUtils.importESModule(
4 "resource://testing-common/httpd.sys.mjs"
5 );
7 var httpserver = null;
8 var simplePath = "/simple";
9 var normalPath = "/normal";
10 var httpbody = "<html></html>";
12 ChromeUtils.defineLazyGetter(this, "uri1", function () {
13 return "http://localhost:" + httpserver.identity.primaryPort + simplePath;
14 });
16 ChromeUtils.defineLazyGetter(this, "uri2", function () {
17 return "http://localhost:" + httpserver.identity.primaryPort + normalPath;
18 });
20 function make_channel(url) {
21 return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
24 var listener_proto = {
25 QueryInterface: ChromeUtils.generateQI([
26 "nsIStreamListener",
27 "nsIRequestObserver",
28 ]),
30 onStartRequest(request) {
31 Assert.equal(
32 request.QueryInterface(Ci.nsIChannel).contentType,
33 this.contentType
35 request.cancel(Cr.NS_BINDING_ABORTED);
38 onDataAvailable() {
39 do_throw("Unexpected onDataAvailable");
42 onStopRequest(request, status) {
43 Assert.equal(status, Cr.NS_BINDING_ABORTED);
44 this.termination_func();
48 function listener(contentType, termination_func) {
49 this.contentType = contentType;
50 this.termination_func = termination_func;
52 listener.prototype = listener_proto;
54 function run_test() {
55 httpserver = new HttpServer();
56 httpserver.registerPathHandler(simplePath, simpleHandler);
57 httpserver.registerPathHandler(normalPath, normalHandler);
58 httpserver.start(-1);
60 var channel = make_channel(uri1);
61 channel.asyncOpen(
62 new listener("text/plain", function () {
63 run_test2();
67 do_test_pending();
70 function run_test2() {
71 var channel = make_channel(uri2);
72 channel.asyncOpen(
73 new listener("text/html", function () {
74 httpserver.stop(do_test_finished);
79 function simpleHandler(metadata, response) {
80 response.seizePower();
81 response.bodyOutputStream.write(httpbody, httpbody.length);
82 response.finish();
85 function normalHandler(metadata, response) {
86 response.bodyOutputStream.write(httpbody, httpbody.length);
87 response.finish();