Bug 1845311 - [Part 2] Use ChromeUtils.defineLazyGetter in more places r=arai,webcomp...
[gecko.git] / netwerk / test / unit / test_proxy-failover_passing.js
bloba6fab56690b5e92cd3158f55249e6dd37ef0696a
1 "use strict";
3 const { HttpServer } = ChromeUtils.importESModule(
4   "resource://testing-common/httpd.sys.mjs"
5 );
7 var httpServer = null;
9 function make_channel(url, callback, ctx) {
10   return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
13 const responseBody = "response body";
15 function contentHandler(metadata, response) {
16   response.setHeader("Content-Type", "text/plain");
17   response.bodyOutputStream.write(responseBody, responseBody.length);
20 function finish_test(request, buffer) {
21   Assert.equal(buffer, responseBody);
22   httpServer.stop(do_test_finished);
25 function run_test() {
26   httpServer = new HttpServer();
27   httpServer.registerPathHandler("/content", contentHandler);
28   httpServer.start(-1);
30   var prefs = Services.prefs.getBranch("network.proxy.");
31   prefs.setIntPref("type", 2);
32   prefs.setCharPref(
33     "autoconfig_url",
34     "data:text/plain," +
35       "function FindProxyForURL(url, host) {return 'PROXY a_non_existent_domain_x7x6c572v:80; PROXY localhost:" +
36       httpServer.identity.primaryPort +
37       "';}"
38   );
40   var chan = make_channel(
41     "http://localhost:" + httpServer.identity.primaryPort + "/content"
42   );
43   chan.asyncOpen(new ChannelListener(finish_test, null));
44   do_test_pending();