1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/unit/test_addr_in_use_error.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,32 @@ 1.4 +// Opening a second listening socket on the same address as an extant 1.5 +// socket should elicit NS_ERROR_SOCKET_ADDRESS_IN_USE on non-Windows 1.6 +// machines. 1.7 + 1.8 +const CC = Components.Constructor; 1.9 + 1.10 +const ServerSocket = CC("@mozilla.org/network/server-socket;1", 1.11 + "nsIServerSocket", 1.12 + "init"); 1.13 + 1.14 +function testAddrInUse() 1.15 +{ 1.16 + // Windows lets us have as many sockets listening on the same address as 1.17 + // we like, evidently. 1.18 + if ("@mozilla.org/windows-registry-key;1" in Cc) { 1.19 + return; 1.20 + } 1.21 + 1.22 + // Create listening socket: 1.23 + // any port (-1), loopback only (true), default backlog (-1) 1.24 + let listener = ServerSocket(-1, true, -1); 1.25 + do_check_true(listener instanceof Ci.nsIServerSocket); 1.26 + 1.27 + // Try to create another listening socket on the same port, whatever that was. 1.28 + do_check_throws_nsIException(() => ServerSocket(listener.port, true, -1), 1.29 + "NS_ERROR_SOCKET_ADDRESS_IN_USE"); 1.30 +} 1.31 + 1.32 +function run_test() 1.33 +{ 1.34 + testAddrInUse(); 1.35 +}