Index: net/socket/tcp_client_socket_pool_unittest.cc |
diff --git a/net/socket/tcp_client_socket_pool_unittest.cc b/net/socket/tcp_client_socket_pool_unittest.cc |
index 9fd1c8afc118311a8cb50b83453986cec53067fc..e6d435a05c6d92e47d305b12952ff27f3798943a 100644 |
--- a/net/socket/tcp_client_socket_pool_unittest.cc |
+++ b/net/socket/tcp_client_socket_pool_unittest.cc |
@@ -8,6 +8,7 @@ |
#include "base/compiler_specific.h" |
#include "base/message_loop.h" |
#include "net/base/mock_host_resolver.h" |
+#include "net/base/mock_network_change_notifier.h" |
#include "net/base/net_errors.h" |
#include "net/base/test_completion_callback.h" |
#include "net/socket/client_socket.h" |
@@ -268,7 +269,9 @@ class TCPClientSocketPoolTest : public ClientSocketPoolTest { |
kMaxSocketsPerGroup, |
"TCPUnitTest", |
host_resolver_, |
- &client_socket_factory_)) {} |
+ &client_socket_factory_, |
+ ¬ifier_)) { |
+ } |
int StartRequest(const std::string& group_name, RequestPriority priority) { |
return StartRequestUsingPool( |
@@ -278,6 +281,7 @@ class TCPClientSocketPoolTest : public ClientSocketPoolTest { |
TCPSocketParams ignored_socket_params_; |
scoped_refptr<MockHostResolver> host_resolver_; |
MockClientSocketFactory client_socket_factory_; |
+ MockNetworkChangeNotifier notifier_; |
scoped_refptr<TCPClientSocketPool> pool_; |
}; |
@@ -654,6 +658,32 @@ TEST_F(TCPClientSocketPoolTest, FailingActiveRequestWithPendingRequests) { |
EXPECT_EQ(ERR_CONNECTION_FAILED, requests_[i]->WaitForResult()); |
} |
+TEST_F(TCPClientSocketPoolTest, ResetIdleSocketsOnIPAddressChange) { |
+ TestCompletionCallback callback; |
+ ClientSocketHandle handle; |
+ TCPSocketParams dest("www.google.com", 80, LOW, GURL(), false); |
+ int rv = handle.Init("a", dest, LOW, &callback, pool_, BoundNetLog()); |
+ EXPECT_EQ(ERR_IO_PENDING, rv); |
+ EXPECT_FALSE(handle.is_initialized()); |
+ EXPECT_FALSE(handle.socket()); |
+ |
+ EXPECT_EQ(OK, callback.WaitForResult()); |
+ EXPECT_TRUE(handle.is_initialized()); |
+ EXPECT_TRUE(handle.socket()); |
+ |
+ handle.Reset(); |
+ |
+ // Need to run all pending to release the socket back to the pool. |
+ MessageLoop::current()->RunAllPending(); |
+ |
+ // Now we should have 1 idle socket. |
+ EXPECT_EQ(1, pool_->IdleSocketCount()); |
+ |
+ // After an IP address change, we should have 0 idle sockets. |
+ notifier_.NotifyIPAddressChange(); |
+ EXPECT_EQ(0, pool_->IdleSocketCount()); |
+} |
+ |
TEST_F(TCPClientSocketPoolTest, BackupSocketConnect) { |
// Case 1 tests the first socket stalling, and the backup connecting. |
MockClientSocketFactory::ClientSocketType case1_types[] = { |
@@ -712,7 +742,8 @@ TEST_F(TCPClientSocketPoolTest, BackupSocketConnect) { |
kMaxSocketsPerGroup, |
"TCPUnitTest", |
host_resolver_, |
- &client_socket_factory_); |
+ &client_socket_factory_, |
+ NULL); |
} |
} |