Thu, 15 Jan 2015 15:59:08 +0100
Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | // Opening a second listening socket on the same address as an extant |
michael@0 | 2 | // socket should elicit NS_ERROR_SOCKET_ADDRESS_IN_USE on non-Windows |
michael@0 | 3 | // machines. |
michael@0 | 4 | |
michael@0 | 5 | const CC = Components.Constructor; |
michael@0 | 6 | |
michael@0 | 7 | const ServerSocket = CC("@mozilla.org/network/server-socket;1", |
michael@0 | 8 | "nsIServerSocket", |
michael@0 | 9 | "init"); |
michael@0 | 10 | |
michael@0 | 11 | function testAddrInUse() |
michael@0 | 12 | { |
michael@0 | 13 | // Windows lets us have as many sockets listening on the same address as |
michael@0 | 14 | // we like, evidently. |
michael@0 | 15 | if ("@mozilla.org/windows-registry-key;1" in Cc) { |
michael@0 | 16 | return; |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | // Create listening socket: |
michael@0 | 20 | // any port (-1), loopback only (true), default backlog (-1) |
michael@0 | 21 | let listener = ServerSocket(-1, true, -1); |
michael@0 | 22 | do_check_true(listener instanceof Ci.nsIServerSocket); |
michael@0 | 23 | |
michael@0 | 24 | // Try to create another listening socket on the same port, whatever that was. |
michael@0 | 25 | do_check_throws_nsIException(() => ServerSocket(listener.port, true, -1), |
michael@0 | 26 | "NS_ERROR_SOCKET_ADDRESS_IN_USE"); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function run_test() |
michael@0 | 30 | { |
michael@0 | 31 | testAddrInUse(); |
michael@0 | 32 | } |