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" |
(...skipping 12 matching lines...) Expand all Loading... | |
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 "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
30 | 30 |
31 namespace net { | 31 namespace net { |
32 | 32 |
33 namespace { | |
willchan no longer on Chromium
2011/07/17 01:23:45
If you use the SpdySessionPoolPeer, then you can r
ramant (doing other things)
2011/07/17 08:12:30
Done.
| |
34 | |
35 const int kMaxSockets = 32; | 33 const int kMaxSockets = 32; |
36 const int kMaxSocketsPerGroup = 6; | 34 const int kMaxSocketsPerGroup = 6; |
37 | 35 |
38 class SSLClientSocketPoolTest : public testing::Test { | 36 class SSLClientSocketPoolTest : public testing::Test { |
39 protected: | 37 protected: |
40 SSLClientSocketPoolTest() | 38 SSLClientSocketPoolTest() |
41 : proxy_service_(ProxyService::CreateDirect()), | 39 : proxy_service_(ProxyService::CreateDirect()), |
42 ssl_config_service_(new SSLConfigServiceDefaults), | 40 ssl_config_service_(new SSLConfigServiceDefaults), |
43 http_auth_handler_factory_(HttpAuthHandlerFactory::CreateDefault( | 41 http_auth_handler_factory_(HttpAuthHandlerFactory::CreateDefault( |
44 &host_resolver_)), | 42 &host_resolver_)), |
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
650 } | 648 } |
651 | 649 |
652 TEST_F(SSLClientSocketPoolTest, IPPooling) { | 650 TEST_F(SSLClientSocketPoolTest, IPPooling) { |
653 const int kTestPort = 80; | 651 const int kTestPort = 80; |
654 struct TestHosts { | 652 struct TestHosts { |
655 std::string name; | 653 std::string name; |
656 std::string iplist; | 654 std::string iplist; |
657 HostPortProxyPair pair; | 655 HostPortProxyPair pair; |
658 } test_hosts[] = { | 656 } test_hosts[] = { |
659 { "www.webkit.org", "192.168.0.1,192.168.0.5" }, | 657 { "www.webkit.org", "192.168.0.1,192.168.0.5" }, |
660 { "code.google.com", "192.168.0.2,192.168.0.3,192.168.0.5" }, | 658 { "code.google.com", "192.168.0.2,192.168.0.3,192.168.0.1" }, |
661 { "js.webkit.org", "192.168.0.4,192.168.0.5" }, | 659 { "js.webkit.org", "192.168.0.4,192.168.0.1" }, |
662 }; | 660 }; |
663 | 661 |
664 host_resolver_.set_synchronous_mode(true); | 662 host_resolver_.set_synchronous_mode(true); |
665 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) { | 663 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) { |
666 host_resolver_.rules()->AddIPLiteralRule(test_hosts[i].name, | 664 host_resolver_.rules()->AddIPLiteralRule(test_hosts[i].name, |
667 test_hosts[i].iplist, ""); | 665 test_hosts[i].iplist, ""); |
668 | 666 |
669 // This test requires that the HostResolver cache be populated. Normal | 667 // This test requires that the HostResolver cache be populated. Normal |
670 // code would have done this already, but we do it manually. | 668 // code would have done this already, but we do it manually. |
671 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); | 669 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
705 EXPECT_TRUE(handle->is_initialized()); | 703 EXPECT_TRUE(handle->is_initialized()); |
706 EXPECT_TRUE(handle->socket()); | 704 EXPECT_TRUE(handle->socket()); |
707 | 705 |
708 SSLClientSocket* ssl_socket = static_cast<SSLClientSocket*>(handle->socket()); | 706 SSLClientSocket* ssl_socket = static_cast<SSLClientSocket*>(handle->socket()); |
709 EXPECT_TRUE(ssl_socket->was_npn_negotiated()); | 707 EXPECT_TRUE(ssl_socket->was_npn_negotiated()); |
710 std::string proto; | 708 std::string proto; |
711 ssl_socket->GetNextProto(&proto); | 709 ssl_socket->GetNextProto(&proto); |
712 EXPECT_EQ(SSLClientSocket::NextProtoFromString(proto), | 710 EXPECT_EQ(SSLClientSocket::NextProtoFromString(proto), |
713 SSLClientSocket::kProtoSPDY2); | 711 SSLClientSocket::kProtoSPDY2); |
714 | 712 |
713 session_->spdy_session_pool()->AddAliases(test_hosts[0].pair); | |
willchan no longer on Chromium
2011/07/17 01:23:45
Rather than doing this, you should probably just u
ramant (doing other things)
2011/07/17 08:12:30
Done.
| |
714 | |
715 scoped_refptr<SpdySession> spdy_session; | 715 scoped_refptr<SpdySession> spdy_session; |
716 rv = session_->spdy_session_pool()->GetSpdySessionFromSocket( | 716 rv = session_->spdy_session_pool()->GetSpdySessionFromSocket( |
717 test_hosts[0].pair, handle.release(), BoundNetLog(), 0, | 717 test_hosts[0].pair, handle.release(), BoundNetLog(), 0, |
718 &spdy_session, true); | 718 &spdy_session, true); |
719 EXPECT_EQ(0, rv); | 719 EXPECT_EQ(0, rv); |
720 | 720 |
721 EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[0].pair)); | 721 EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[0].pair)); |
722 EXPECT_FALSE(session_->spdy_session_pool()->HasSession(test_hosts[1].pair)); | 722 EXPECT_FALSE(session_->spdy_session_pool()->HasSession(test_hosts[1].pair)); |
723 EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[2].pair)); | 723 EXPECT_TRUE(session_->spdy_session_pool()->HasSession(test_hosts[2].pair)); |
724 | 724 |
725 session_->spdy_session_pool()->CloseAllSessions(); | 725 session_->spdy_session_pool()->CloseAllSessions(); |
726 } | 726 } |
727 | 727 |
728 // It would be nice to also test the timeouts in SSLClientSocketPool. | 728 // It would be nice to also test the timeouts in SSLClientSocketPool. |
729 | 729 |
730 } // namespace | |
731 | |
732 } // namespace net | 730 } // namespace net |
OLD | NEW |