1 // This test is checking the `network.socket.forcePort` preference has an effect.
2 // We remap an ilusional port `8765` to go to the port the server actually binds to.
6 const { HttpServer } = ChromeUtils.importESModule(
7 "resource://testing-common/httpd.sys.mjs"
10 function make_channel(url) {
11 return NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
14 const REMAPPED_PORT = 8765;
16 add_task(async function check_protocols() {
17 function contentHandler(metadata, response) {
18 let responseBody = "The server should never return this!";
19 response.setHeader("Content-Type", "text/plain");
20 response.bodyOutputStream.write(responseBody, responseBody.length);
23 const httpserv = new HttpServer();
24 httpserv.registerPathHandler("/content", contentHandler);
28 Services.prefs.setCharPref(
29 "network.socket.forcePort",
30 `${REMAPPED_PORT}=${httpserv.identity.primaryPort}`
33 function get_response() {
34 return new Promise(resolve => {
35 const URL = `http://localhost:${REMAPPED_PORT}/content`;
36 const channel = make_channel(URL);
38 new ChannelListener((request, data) => {
45 // We expect "Bad request" from the test server because the server doesn't
46 // have identity for the remapped port. We don't want to add it too, because
47 // that would not prove we actualy remap the port number.
48 Assert.equal(await get_response(), "Bad request\n");
49 await new Promise(resolve => httpserv.stop(resolve));