summaryrefslogtreecommitdiffstats
path: root/net/socket/tcp_client_socket_pool_unittest.cc
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-19 22:45:53 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-19 22:45:53 +0000
commit61a86c4d5644817d291e7f22ffd0b0b5cef56295 (patch)
treedfd15e590bbbf44af479f702875d24aa19d1f491 /net/socket/tcp_client_socket_pool_unittest.cc
parent74d7e1d0cb8040ba0bfe15619ccb240e5c7d5c19 (diff)
downloadchromium_src-61a86c4d5644817d291e7f22ffd0b0b5cef56295.zip
chromium_src-61a86c4d5644817d291e7f22ffd0b0b5cef56295.tar.gz
chromium_src-61a86c4d5644817d291e7f22ffd0b0b5cef56295.tar.bz2
Fix crash on IP address change.
Revert r43908: "Flush socket pools and SPDY session pool properly on explicit requests and network changes." This change was reverted on the 375 branch, but not on trunk. BUG=41190 Review URL: http://codereview.chromium.org/1604045 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44973 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/tcp_client_socket_pool_unittest.cc')
-rw-r--r--net/socket/tcp_client_socket_pool_unittest.cc31
1 files changed, 30 insertions, 1 deletions
diff --git a/net/socket/tcp_client_socket_pool_unittest.cc b/net/socket/tcp_client_socket_pool_unittest.cc
index a41fb88..e7c8a9f 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"
@@ -246,7 +247,8 @@ class TCPClientSocketPoolTest : public ClientSocketPoolTest {
kMaxSocketsPerGroup,
"TCPUnitTest",
host_resolver_,
- &client_socket_factory_)) {
+ &client_socket_factory_,
+ &notifier_)) {
}
int StartRequest(const std::string& group_name, RequestPriority priority) {
@@ -257,6 +259,7 @@ class TCPClientSocketPoolTest : public ClientSocketPoolTest {
TCPSocketParams ignored_socket_params_;
scoped_refptr<MockHostResolver> host_resolver_;
MockClientSocketFactory client_socket_factory_;
+ MockNetworkChangeNotifier notifier_;
scoped_refptr<TCPClientSocketPool> pool_;
};
@@ -625,6 +628,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_, NULL);
+ 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[] = {