summaryrefslogtreecommitdiffstats
path: root/net/socket
diff options
context:
space:
mode:
authormbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-25 05:33:02 +0000
committermbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-25 05:33:02 +0000
commit8b114dd781075604530544cf60e665fa4306903c (patch)
treecaa2d8ef403d08ffab8dac31a126d84947990b1c /net/socket
parentbd0875ed222d58f51816ebb08e6203ef94053276 (diff)
downloadchromium_src-8b114dd781075604530544cf60e665fa4306903c.zip
chromium_src-8b114dd781075604530544cf60e665fa4306903c.tar.gz
chromium_src-8b114dd781075604530544cf60e665fa4306903c.tar.bz2
Enable IP pooling for SPDY.
Added a command-line switch: --enable-ip-pooling BUG=42669 TEST=SpdySessionTest.IPPool* Review URL: http://codereview.chromium.org/6594116 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79372 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket')
-rw-r--r--net/socket/ssl_client_socket_pool_unittest.cc82
1 files changed, 80 insertions, 2 deletions
diff --git a/net/socket/ssl_client_socket_pool_unittest.cc b/net/socket/ssl_client_socket_pool_unittest.cc
index 091a94ae..4c1585d 100644
--- a/net/socket/ssl_client_socket_pool_unittest.cc
+++ b/net/socket/ssl_client_socket_pool_unittest.cc
@@ -13,8 +13,9 @@
#include "net/base/cert_verifier.h"
#include "net/base/mock_host_resolver.h"
#include "net/base/net_errors.h"
-#include "net/base/test_completion_callback.h"
#include "net/base/ssl_config_service_defaults.h"
+#include "net/base/test_certificate_data.h"
+#include "net/base/test_completion_callback.h"
#include "net/http/http_auth_handler_factory.h"
#include "net/http/http_network_session.h"
#include "net/http/http_request_headers.h"
@@ -23,6 +24,7 @@
#include "net/socket/client_socket_handle.h"
#include "net/socket/client_socket_pool_histograms.h"
#include "net/socket/socket_test_util.h"
+#include "net/spdy/spdy_session.h"
#include "net/spdy/spdy_session_pool.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -138,7 +140,7 @@ class SSLClientSocketPoolTest : public testing::Test {
}
MockClientSocketFactory socket_factory_;
- MockHostResolver host_resolver_;
+ MockCachingHostResolver host_resolver_;
CertVerifier cert_verifier_;
const scoped_refptr<ProxyService> proxy_service_;
const scoped_refptr<SSLConfigService> ssl_config_service_;
@@ -646,6 +648,82 @@ TEST_F(SSLClientSocketPoolTest, NeedProxyAuth) {
EXPECT_FALSE(tunnel_handle->socket()->IsConnected());
}
+TEST_F(SSLClientSocketPoolTest, IPPooling) {
+ const int kTestPort = 80;
+ struct TestHosts {
+ std::string name;
+ std::string iplist;
+ HostPortProxyPair pair;
+ } test_hosts[] = {
+ { "www.webkit.org", "192.168.0.1,192.168.0.5" },
+ { "code.google.com", "192.168.0.2,192.168.0.3,192.168.0.5" },
+ { "js.webkit.org", "192.168.0.4,192.168.0.5" },
+ };
+
+ host_resolver_.set_synchronous_mode(true);
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) {
+ host_resolver_.rules()->AddIPLiteralRule(test_hosts[i].name,
+ test_hosts[i].iplist, "");
+
+ // This test requires that the HostResolver cache be populated. Normal
+ // code would have done this already, but we do it manually.
+ HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort));
+ AddressList result;
+ host_resolver_.Resolve(info, &result, NULL, NULL, BoundNetLog());
+
+ // Setup a HostPortProxyPair
+ test_hosts[i].pair = HostPortProxyPair(
+ HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct());
+ }
+
+ MockRead reads[] = {
+ MockRead(true, ERR_IO_PENDING),
+ };
+ StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0);
+ socket_factory_.AddSocketDataProvider(&data);
+ SSLSocketDataProvider ssl(true, OK);
+ ssl.cert_ = X509Certificate::CreateFromBytes(
+ reinterpret_cast<const char*>(webkit_der), sizeof(webkit_der));
+ ssl.next_proto_status = SSLClientSocket::kNextProtoNegotiated;
+ ssl.next_proto = "spdy/2";
+ socket_factory_.AddSSLSocketDataProvider(&ssl);
+
+ CreatePool(true /* tcp pool */, false, false);
+ scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT,
+ true);
+
+ scoped_ptr<ClientSocketHandle> handle(new ClientSocketHandle());
+ TestCompletionCallback callback;
+ int rv = handle->Init(
+ "a", params, MEDIUM, &callback, pool_.get(), 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());
+
+ SSLClientSocket* ssl_socket = static_cast<SSLClientSocket*>(handle->socket());
+ EXPECT_TRUE(ssl_socket->was_npn_negotiated());
+ std::string proto;
+ ssl_socket->GetNextProto(&proto);
+ EXPECT_EQ(SSLClientSocket::NextProtoFromString(proto),
+ SSLClientSocket::kProtoSPDY2);
+
+ scoped_refptr<SpdySession> spdy_session;
+ rv = session_->spdy_session_pool()->GetSpdySessionFromSocket(
+ test_hosts[0].pair, handle.release(), BoundNetLog(), 0,
+ &spdy_session, true);
+ EXPECT_EQ(0, rv);
+
+ EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[0].pair));
+ EXPECT_FALSE(session_->spdy_session_pool()->HasSession(test_hosts[1].pair));
+ EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[2].pair));
+
+ session_->spdy_session_pool()->CloseAllSessions();
+}
+
// It would be nice to also test the timeouts in SSLClientSocketPool.
} // namespace