Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: net/socket/ssl_client_socket_pool_unittest.cc

Issue 7349023: Changed SPDY's ip connection pooling logic to only add the used IP, (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_proxy_client_socket_pool.h" 5 #include "net/http/http_proxy_client_socket_pool.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/time.h" 10 #include "base/time.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "net/base/auth.h" 12 #include "net/base/auth.h"
13 #include "net/base/cert_verifier.h" 13 #include "net/base/cert_verifier.h"
14 #include "net/base/mock_host_resolver.h" 14 #include "net/base/mock_host_resolver.h"
15 #include "net/base/net_errors.h" 15 #include "net/base/net_errors.h"
16 #include "net/base/ssl_config_service_defaults.h" 16 #include "net/base/ssl_config_service_defaults.h"
17 #include "net/base/test_certificate_data.h" 17 #include "net/base/test_certificate_data.h"
18 #include "net/base/test_completion_callback.h" 18 #include "net/base/test_completion_callback.h"
19 #include "net/http/http_auth_handler_factory.h" 19 #include "net/http/http_auth_handler_factory.h"
20 #include "net/http/http_network_session.h" 20 #include "net/http/http_network_session.h"
21 #include "net/http/http_request_headers.h" 21 #include "net/http/http_request_headers.h"
22 #include "net/http/http_response_headers.h" 22 #include "net/http/http_response_headers.h"
23 #include "net/proxy/proxy_service.h" 23 #include "net/proxy/proxy_service.h"
24 #include "net/socket/client_socket_handle.h" 24 #include "net/socket/client_socket_handle.h"
25 #include "net/socket/client_socket_pool_histograms.h" 25 #include "net/socket/client_socket_pool_histograms.h"
26 #include "net/socket/socket_test_util.h" 26 #include "net/socket/socket_test_util.h"
27 #include "net/spdy/spdy_session.h" 27 #include "net/spdy/spdy_session.h"
28 #include "net/spdy/spdy_session_pool.h" 28 #include "net/spdy/spdy_session_pool.h"
29 #include "net/spdy/spdy_test_util.h"
29 #include "testing/gtest/include/gtest/gtest.h" 30 #include "testing/gtest/include/gtest/gtest.h"
30 31
31 namespace net { 32 namespace net {
32 33
33 namespace { 34 namespace {
34 35
35 const int kMaxSockets = 32; 36 const int kMaxSockets = 32;
36 const int kMaxSocketsPerGroup = 6; 37 const int kMaxSocketsPerGroup = 6;
37 38
38 class SSLClientSocketPoolTest : public testing::Test { 39 class SSLClientSocketPoolTest : public testing::Test {
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 EXPECT_FALSE(tunnel_handle->socket()->IsConnected()); 650 EXPECT_FALSE(tunnel_handle->socket()->IsConnected());
650 } 651 }
651 652
652 TEST_F(SSLClientSocketPoolTest, IPPooling) { 653 TEST_F(SSLClientSocketPoolTest, IPPooling) {
653 const int kTestPort = 80; 654 const int kTestPort = 80;
654 struct TestHosts { 655 struct TestHosts {
655 std::string name; 656 std::string name;
656 std::string iplist; 657 std::string iplist;
657 HostPortProxyPair pair; 658 HostPortProxyPair pair;
658 } test_hosts[] = { 659 } test_hosts[] = {
659 { "www.webkit.org", "192.168.0.1,192.168.0.5" }, 660 { "www.webkit.org", "192.0.2.33,192.168.0.1,192.168.0.5" },
660 { "code.google.com", "192.168.0.2,192.168.0.3,192.168.0.5" }, 661 { "code.google.com", "192.168.0.2,192.168.0.3,192.168.0.5" },
661 { "js.webkit.org", "192.168.0.4,192.168.0.5" }, 662 { "js.webkit.org", "192.0.2.33,192.168.0.4,192.168.0.1" },
662 }; 663 };
663 664
664 host_resolver_.set_synchronous_mode(true); 665 host_resolver_.set_synchronous_mode(true);
665 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) { 666 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) {
666 host_resolver_.rules()->AddIPLiteralRule(test_hosts[i].name, 667 host_resolver_.rules()->AddIPLiteralRule(test_hosts[i].name,
667 test_hosts[i].iplist, ""); 668 test_hosts[i].iplist, "");
668 669
669 // This test requires that the HostResolver cache be populated. Normal 670 // This test requires that the HostResolver cache be populated. Normal
670 // code would have done this already, but we do it manually. 671 // code would have done this already, but we do it manually.
671 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); 672 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 EXPECT_TRUE(handle->is_initialized()); 706 EXPECT_TRUE(handle->is_initialized());
706 EXPECT_TRUE(handle->socket()); 707 EXPECT_TRUE(handle->socket());
707 708
708 SSLClientSocket* ssl_socket = static_cast<SSLClientSocket*>(handle->socket()); 709 SSLClientSocket* ssl_socket = static_cast<SSLClientSocket*>(handle->socket());
709 EXPECT_TRUE(ssl_socket->was_npn_negotiated()); 710 EXPECT_TRUE(ssl_socket->was_npn_negotiated());
710 std::string proto; 711 std::string proto;
711 ssl_socket->GetNextProto(&proto); 712 ssl_socket->GetNextProto(&proto);
712 EXPECT_EQ(SSLClientSocket::NextProtoFromString(proto), 713 EXPECT_EQ(SSLClientSocket::NextProtoFromString(proto),
713 SSLClientSocket::kProtoSPDY2); 714 SSLClientSocket::kProtoSPDY2);
714 715
716 // MockClientSocket::GetPeerAddress return's 0 as the port number and when we
717 // search for HasSession, we lookup with port 80. AddAliases adds addresses
718 // with port 80.
719 SpdySessionPoolPeer pool_peer(session_->spdy_session_pool());
720 pool_peer.AddAliases(test_hosts[0].pair);
721
715 scoped_refptr<SpdySession> spdy_session; 722 scoped_refptr<SpdySession> spdy_session;
716 rv = session_->spdy_session_pool()->GetSpdySessionFromSocket( 723 rv = session_->spdy_session_pool()->GetSpdySessionFromSocket(
717 test_hosts[0].pair, handle.release(), BoundNetLog(), 0, 724 test_hosts[0].pair, handle.release(), BoundNetLog(), 0,
718 &spdy_session, true); 725 &spdy_session, true);
719 EXPECT_EQ(0, rv); 726 EXPECT_EQ(0, rv);
720 727
721 EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[0].pair)); 728 EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[0].pair));
722 EXPECT_FALSE(session_->spdy_session_pool()->HasSession(test_hosts[1].pair)); 729 EXPECT_FALSE(session_->spdy_session_pool()->HasSession(test_hosts[1].pair));
723 EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[2].pair)); 730 EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[2].pair));
724 731
725 session_->spdy_session_pool()->CloseAllSessions(); 732 session_->spdy_session_pool()->CloseAllSessions();
726 } 733 }
727 734
728 // It would be nice to also test the timeouts in SSLClientSocketPool. 735 // It would be nice to also test the timeouts in SSLClientSocketPool.
729 736
730 } // namespace 737 } // namespace
731 738
732 } // namespace net 739 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698