3 const { HttpServer } = ChromeUtils.importESModule(
4 "resource://testing-common/httpd.sys.mjs"
8 * The test is checking async redirect code path that is loading a
9 * redirect. But creation of the target channel fails before we even try
10 * to do async open on it. We force the creation error by forbidding
11 * the port number the URI contains.
14 function inChildProcess() {
15 return Services.appinfo.processType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
18 ChromeUtils.defineLazyGetter(this, "URL", function () {
19 return "http://localhost:" + httpServer.identity.primaryPort;
22 var httpServer = null;
23 // Need to randomize, because apparently no one clears our cache
24 var randomPath = "/redirect/" + Math.random();
26 ChromeUtils.defineLazyGetter(this, "randomURI", function () {
27 return URL + randomPath;
30 function make_channel(url, callback, ctx) {
31 return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
34 function redirectHandler(metadata, response) {
35 response.setStatusLine(metadata.httpVersion, 301, "Moved");
36 response.setHeader("Location", "http://non-existent.tld:65400", false);
37 response.setHeader("Cache-Control", "no-cache", false);
40 function finish_test(request, buffer) {
41 Assert.equal(request.status, Cr.NS_ERROR_PORT_ACCESS_NOT_ALLOWED);
43 Assert.equal(buffer, "");
44 httpServer.stop(do_test_finished);
48 httpServer = new HttpServer();
49 httpServer.registerPathHandler(randomPath, redirectHandler);
52 if (!inChildProcess()) {
53 Services.prefs.setCharPref("network.security.ports.banned", "65400");
56 var chan = make_channel(randomURI);
57 chan.asyncOpen(new ChannelListener(finish_test, null, CL_EXPECT_FAILURE));