tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_addr_in_use_error.js (919B)


      1 // Opening a second listening socket on the same address as an extant
      2 // socket should elicit NS_ERROR_SOCKET_ADDRESS_IN_USE on non-Windows
      3 // machines.
      4 
      5 "use strict";
      6 
      7 var CC = Components.Constructor;
      8 
      9 const ServerSocket = CC(
     10  "@mozilla.org/network/server-socket;1",
     11  "nsIServerSocket",
     12  "init"
     13 );
     14 
     15 function testAddrInUse() {
     16  // Windows lets us have as many sockets listening on the same address as
     17  // we like, evidently.
     18  if (mozinfo.os == "win") {
     19    return;
     20  }
     21 
     22  // Create listening socket:
     23  // any port (-1), loopback only (true), default backlog (-1)
     24  let listener = ServerSocket(-1, true, -1);
     25  Assert.ok(listener instanceof Ci.nsIServerSocket);
     26 
     27  // Try to create another listening socket on the same port, whatever that was.
     28  do_check_throws_nsIException(
     29    () => ServerSocket(listener.port, true, -1),
     30    "NS_ERROR_SOCKET_ADDRESS_IN_USE"
     31  );
     32 }
     33 
     34 function run_test() {
     35  testAddrInUse();
     36 }