OLD | NEW |
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/sys_addrinfo.h" |
17 #include "net/base/test_certificate_data.h" | 18 #include "net/base/test_certificate_data.h" |
18 #include "net/base/test_completion_callback.h" | 19 #include "net/base/test_completion_callback.h" |
19 #include "net/http/http_auth_handler_factory.h" | 20 #include "net/http/http_auth_handler_factory.h" |
20 #include "net/http/http_network_session.h" | 21 #include "net/http/http_network_session.h" |
21 #include "net/http/http_request_headers.h" | 22 #include "net/http/http_request_headers.h" |
22 #include "net/http/http_response_headers.h" | 23 #include "net/http/http_response_headers.h" |
23 #include "net/proxy/proxy_service.h" | 24 #include "net/proxy/proxy_service.h" |
24 #include "net/socket/client_socket_handle.h" | 25 #include "net/socket/client_socket_handle.h" |
25 #include "net/socket/client_socket_pool_histograms.h" | 26 #include "net/socket/client_socket_pool_histograms.h" |
26 #include "net/socket/socket_test_util.h" | 27 #include "net/socket/socket_test_util.h" |
27 #include "net/spdy/spdy_session.h" | 28 #include "net/spdy/spdy_session.h" |
28 #include "net/spdy/spdy_session_pool.h" | 29 #include "net/spdy/spdy_session_pool.h" |
| 30 #include "net/spdy/spdy_test_util.h" |
29 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
30 | 32 |
31 namespace net { | 33 namespace net { |
32 | 34 |
33 namespace { | 35 namespace { |
34 | 36 |
35 const int kMaxSockets = 32; | 37 const int kMaxSockets = 32; |
36 const int kMaxSocketsPerGroup = 6; | 38 const int kMaxSocketsPerGroup = 6; |
37 | 39 |
38 class SSLClientSocketPoolTest : public testing::Test { | 40 class SSLClientSocketPoolTest : public testing::Test { |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 EXPECT_TRUE(tunnel_handle->socket()); | 650 EXPECT_TRUE(tunnel_handle->socket()); |
649 EXPECT_FALSE(tunnel_handle->socket()->IsConnected()); | 651 EXPECT_FALSE(tunnel_handle->socket()->IsConnected()); |
650 } | 652 } |
651 | 653 |
652 TEST_F(SSLClientSocketPoolTest, IPPooling) { | 654 TEST_F(SSLClientSocketPoolTest, IPPooling) { |
653 const int kTestPort = 80; | 655 const int kTestPort = 80; |
654 struct TestHosts { | 656 struct TestHosts { |
655 std::string name; | 657 std::string name; |
656 std::string iplist; | 658 std::string iplist; |
657 HostPortProxyPair pair; | 659 HostPortProxyPair pair; |
| 660 AddressList addresses; |
658 } test_hosts[] = { | 661 } test_hosts[] = { |
659 { "www.webkit.org", "192.168.0.1,192.168.0.5" }, | 662 { "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" }, | 663 { "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" }, | 664 { "js.webkit.org", "192.168.0.4,192.168.0.1,192.0.2.33" }, |
662 }; | 665 }; |
663 | 666 |
664 host_resolver_.set_synchronous_mode(true); | 667 host_resolver_.set_synchronous_mode(true); |
665 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) { | 668 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) { |
666 host_resolver_.rules()->AddIPLiteralRule(test_hosts[i].name, | 669 host_resolver_.rules()->AddIPLiteralRule(test_hosts[i].name, |
667 test_hosts[i].iplist, ""); | 670 test_hosts[i].iplist, ""); |
668 | 671 |
669 // This test requires that the HostResolver cache be populated. Normal | 672 // This test requires that the HostResolver cache be populated. Normal |
670 // code would have done this already, but we do it manually. | 673 // code would have done this already, but we do it manually. |
671 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); | 674 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); |
672 AddressList result; | 675 host_resolver_.Resolve(info, &test_hosts[i].addresses, NULL, NULL, |
673 host_resolver_.Resolve(info, &result, NULL, NULL, BoundNetLog()); | 676 BoundNetLog()); |
674 | 677 |
675 // Setup a HostPortProxyPair | 678 // Setup a HostPortProxyPair |
676 test_hosts[i].pair = HostPortProxyPair( | 679 test_hosts[i].pair = HostPortProxyPair( |
677 HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct()); | 680 HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct()); |
678 } | 681 } |
679 | 682 |
680 MockRead reads[] = { | 683 MockRead reads[] = { |
681 MockRead(true, ERR_IO_PENDING), | 684 MockRead(true, ERR_IO_PENDING), |
682 }; | 685 }; |
683 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 686 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
(...skipping 21 matching lines...) Expand all Loading... |
705 EXPECT_TRUE(handle->is_initialized()); | 708 EXPECT_TRUE(handle->is_initialized()); |
706 EXPECT_TRUE(handle->socket()); | 709 EXPECT_TRUE(handle->socket()); |
707 | 710 |
708 SSLClientSocket* ssl_socket = static_cast<SSLClientSocket*>(handle->socket()); | 711 SSLClientSocket* ssl_socket = static_cast<SSLClientSocket*>(handle->socket()); |
709 EXPECT_TRUE(ssl_socket->was_npn_negotiated()); | 712 EXPECT_TRUE(ssl_socket->was_npn_negotiated()); |
710 std::string proto; | 713 std::string proto; |
711 ssl_socket->GetNextProto(&proto); | 714 ssl_socket->GetNextProto(&proto); |
712 EXPECT_EQ(SSLClientSocket::NextProtoFromString(proto), | 715 EXPECT_EQ(SSLClientSocket::NextProtoFromString(proto), |
713 SSLClientSocket::kProtoSPDY2); | 716 SSLClientSocket::kProtoSPDY2); |
714 | 717 |
| 718 // TODO(rtenneti): MockClientSocket::GetPeerAddress return's 0 as the port |
| 719 // number. Fix it to return port 80 and then use GetPeerAddress to AddAlias. |
| 720 const addrinfo* address = test_hosts[0].addresses.head(); |
| 721 SpdySessionPoolPeer pool_peer(session_->spdy_session_pool()); |
| 722 pool_peer.AddAlias(address, test_hosts[0].pair); |
| 723 |
715 scoped_refptr<SpdySession> spdy_session; | 724 scoped_refptr<SpdySession> spdy_session; |
716 rv = session_->spdy_session_pool()->GetSpdySessionFromSocket( | 725 rv = session_->spdy_session_pool()->GetSpdySessionFromSocket( |
717 test_hosts[0].pair, handle.release(), BoundNetLog(), 0, | 726 test_hosts[0].pair, handle.release(), BoundNetLog(), 0, |
718 &spdy_session, true); | 727 &spdy_session, true); |
719 EXPECT_EQ(0, rv); | 728 EXPECT_EQ(0, rv); |
720 | 729 |
721 EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[0].pair)); | 730 EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[0].pair)); |
722 EXPECT_FALSE(session_->spdy_session_pool()->HasSession(test_hosts[1].pair)); | 731 EXPECT_FALSE(session_->spdy_session_pool()->HasSession(test_hosts[1].pair)); |
723 EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[2].pair)); | 732 EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[2].pair)); |
724 | 733 |
725 session_->spdy_session_pool()->CloseAllSessions(); | 734 session_->spdy_session_pool()->CloseAllSessions(); |
726 } | 735 } |
727 | 736 |
728 // It would be nice to also test the timeouts in SSLClientSocketPool. | 737 // It would be nice to also test the timeouts in SSLClientSocketPool. |
729 | 738 |
730 } // namespace | 739 } // namespace |
731 | 740 |
732 } // namespace net | 741 } // namespace net |
OLD | NEW |