OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "net/base/auth.h" | 12 #include "net/base/auth.h" |
13 #include "net/base/load_timing_info.h" | 13 #include "net/base/load_timing_info.h" |
14 #include "net/base/load_timing_info_test_util.h" | 14 #include "net/base/load_timing_info_test_util.h" |
15 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
16 #include "net/base/test_completion_callback.h" | 16 #include "net/base/test_completion_callback.h" |
17 #include "net/cert/cert_verifier.h" | 17 #include "net/cert/cert_verifier.h" |
18 #include "net/dns/mock_host_resolver.h" | 18 #include "net/dns/mock_host_resolver.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/http/http_server_properties_impl.h" | 23 #include "net/http/http_server_properties_impl.h" |
24 #include "net/http/transport_security_state.h" | 24 #include "net/http/transport_security_state.h" |
25 #include "net/proxy/proxy_service.h" | 25 #include "net/proxy/proxy_service.h" |
26 #include "net/socket/client_socket_handle.h" | 26 #include "net/socket/client_socket_handle.h" |
27 #include "net/socket/client_socket_pool_histograms.h" | |
28 #include "net/socket/next_proto.h" | 27 #include "net/socket/next_proto.h" |
29 #include "net/socket/socket_test_util.h" | 28 #include "net/socket/socket_test_util.h" |
30 #include "net/spdy/spdy_session.h" | 29 #include "net/spdy/spdy_session.h" |
31 #include "net/spdy/spdy_session_pool.h" | 30 #include "net/spdy/spdy_session_pool.h" |
32 #include "net/spdy/spdy_test_util_common.h" | 31 #include "net/spdy/spdy_test_util_common.h" |
33 #include "net/ssl/ssl_config_service_defaults.h" | 32 #include "net/ssl/ssl_config_service_defaults.h" |
34 #include "net/test/test_certificate_data.h" | 33 #include "net/test/test_certificate_data.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
36 | 35 |
37 namespace net { | 36 namespace net { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 ssl_config_service_(new SSLConfigServiceDefaults), | 83 ssl_config_service_(new SSLConfigServiceDefaults), |
85 http_auth_handler_factory_( | 84 http_auth_handler_factory_( |
86 HttpAuthHandlerFactory::CreateDefault(&host_resolver_)), | 85 HttpAuthHandlerFactory::CreateDefault(&host_resolver_)), |
87 session_(CreateNetworkSession()), | 86 session_(CreateNetworkSession()), |
88 direct_transport_socket_params_(new TransportSocketParams( | 87 direct_transport_socket_params_(new TransportSocketParams( |
89 HostPortPair("host", 443), | 88 HostPortPair("host", 443), |
90 false, | 89 false, |
91 false, | 90 false, |
92 OnHostResolutionCallback(), | 91 OnHostResolutionCallback(), |
93 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)), | 92 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)), |
94 transport_histograms_("MockTCP"), | |
95 transport_socket_pool_(kMaxSockets, | 93 transport_socket_pool_(kMaxSockets, |
96 kMaxSocketsPerGroup, | 94 kMaxSocketsPerGroup, |
97 &transport_histograms_, | |
98 &socket_factory_), | 95 &socket_factory_), |
99 proxy_transport_socket_params_(new TransportSocketParams( | 96 proxy_transport_socket_params_(new TransportSocketParams( |
100 HostPortPair("proxy", 443), | 97 HostPortPair("proxy", 443), |
101 false, | 98 false, |
102 false, | 99 false, |
103 OnHostResolutionCallback(), | 100 OnHostResolutionCallback(), |
104 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)), | 101 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)), |
105 socks_socket_params_( | 102 socks_socket_params_( |
106 new SOCKSSocketParams(proxy_transport_socket_params_, | 103 new SOCKSSocketParams(proxy_transport_socket_params_, |
107 true, | 104 true, |
108 HostPortPair("sockshost", 443))), | 105 HostPortPair("sockshost", 443))), |
109 socks_histograms_("MockSOCKS"), | |
110 socks_socket_pool_(kMaxSockets, | 106 socks_socket_pool_(kMaxSockets, |
111 kMaxSocketsPerGroup, | 107 kMaxSocketsPerGroup, |
112 &socks_histograms_, | |
113 &transport_socket_pool_), | 108 &transport_socket_pool_), |
114 http_proxy_socket_params_( | 109 http_proxy_socket_params_( |
115 new HttpProxySocketParams(proxy_transport_socket_params_, | 110 new HttpProxySocketParams(proxy_transport_socket_params_, |
116 NULL, | 111 NULL, |
117 GURL("http://host"), | 112 GURL("http://host"), |
118 std::string(), | 113 std::string(), |
119 HostPortPair("host", 80), | 114 HostPortPair("host", 80), |
120 session_->http_auth_cache(), | 115 session_->http_auth_cache(), |
121 session_->http_auth_handler_factory(), | 116 session_->http_auth_handler_factory(), |
122 session_->spdy_session_pool(), | 117 session_->spdy_session_pool(), |
123 true, | 118 true, |
124 NULL)), | 119 NULL)), |
125 http_proxy_histograms_("MockHttpProxy"), | |
126 http_proxy_socket_pool_(kMaxSockets, | 120 http_proxy_socket_pool_(kMaxSockets, |
127 kMaxSocketsPerGroup, | 121 kMaxSocketsPerGroup, |
128 &http_proxy_histograms_, | |
129 &transport_socket_pool_, | 122 &transport_socket_pool_, |
130 NULL, | 123 NULL, |
131 NULL) { | 124 NULL) { |
132 scoped_refptr<SSLConfigService> ssl_config_service( | 125 scoped_refptr<SSLConfigService> ssl_config_service( |
133 new SSLConfigServiceDefaults); | 126 new SSLConfigServiceDefaults); |
134 ssl_config_service->GetSSLConfig(&ssl_config_); | 127 ssl_config_service->GetSSLConfig(&ssl_config_); |
135 } | 128 } |
136 | 129 |
137 void CreatePool(bool transport_pool, bool http_proxy_pool, bool socks_pool) { | 130 void CreatePool(bool transport_pool, bool http_proxy_pool, bool socks_pool) { |
138 ssl_histograms_.reset(new ClientSocketPoolHistograms("SSLUnitTest")); | |
139 pool_.reset(new SSLClientSocketPool( | 131 pool_.reset(new SSLClientSocketPool( |
140 kMaxSockets, kMaxSocketsPerGroup, ssl_histograms_.get(), | 132 kMaxSockets, kMaxSocketsPerGroup, NULL /* cert_verifier */, |
141 NULL /* cert_verifier */, NULL /* channel_id_service */, | 133 NULL /* channel_id_service */, NULL /* transport_security_state */, |
142 NULL /* transport_security_state */, | |
143 NULL /* cert_transparency_verifier */, NULL /* cert_policy_enforcer */, | 134 NULL /* cert_transparency_verifier */, NULL /* cert_policy_enforcer */, |
144 std::string() /* ssl_session_cache_shard */, &socket_factory_, | 135 std::string() /* ssl_session_cache_shard */, &socket_factory_, |
145 transport_pool ? &transport_socket_pool_ : NULL, | 136 transport_pool ? &transport_socket_pool_ : NULL, |
146 socks_pool ? &socks_socket_pool_ : NULL, | 137 socks_pool ? &socks_socket_pool_ : NULL, |
147 http_proxy_pool ? &http_proxy_socket_pool_ : NULL, NULL, NULL)); | 138 http_proxy_pool ? &http_proxy_socket_pool_ : NULL, NULL, NULL)); |
148 } | 139 } |
149 | 140 |
150 scoped_refptr<SSLSocketParams> SSLParams(ProxyServer::Scheme proxy, | 141 scoped_refptr<SSLSocketParams> SSLParams(ProxyServer::Scheme proxy, |
151 bool want_spdy_over_npn) { | 142 bool want_spdy_over_npn) { |
152 return make_scoped_refptr(new SSLSocketParams( | 143 return make_scoped_refptr(new SSLSocketParams( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 MockCachingHostResolver host_resolver_; | 186 MockCachingHostResolver host_resolver_; |
196 scoped_ptr<CertVerifier> cert_verifier_; | 187 scoped_ptr<CertVerifier> cert_verifier_; |
197 scoped_ptr<TransportSecurityState> transport_security_state_; | 188 scoped_ptr<TransportSecurityState> transport_security_state_; |
198 const scoped_ptr<ProxyService> proxy_service_; | 189 const scoped_ptr<ProxyService> proxy_service_; |
199 const scoped_refptr<SSLConfigService> ssl_config_service_; | 190 const scoped_refptr<SSLConfigService> ssl_config_service_; |
200 const scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory_; | 191 const scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory_; |
201 HttpServerPropertiesImpl http_server_properties_; | 192 HttpServerPropertiesImpl http_server_properties_; |
202 const scoped_refptr<HttpNetworkSession> session_; | 193 const scoped_refptr<HttpNetworkSession> session_; |
203 | 194 |
204 scoped_refptr<TransportSocketParams> direct_transport_socket_params_; | 195 scoped_refptr<TransportSocketParams> direct_transport_socket_params_; |
205 ClientSocketPoolHistograms transport_histograms_; | |
206 MockTransportClientSocketPool transport_socket_pool_; | 196 MockTransportClientSocketPool transport_socket_pool_; |
207 | 197 |
208 scoped_refptr<TransportSocketParams> proxy_transport_socket_params_; | 198 scoped_refptr<TransportSocketParams> proxy_transport_socket_params_; |
209 | 199 |
210 scoped_refptr<SOCKSSocketParams> socks_socket_params_; | 200 scoped_refptr<SOCKSSocketParams> socks_socket_params_; |
211 ClientSocketPoolHistograms socks_histograms_; | |
212 MockSOCKSClientSocketPool socks_socket_pool_; | 201 MockSOCKSClientSocketPool socks_socket_pool_; |
213 | 202 |
214 scoped_refptr<HttpProxySocketParams> http_proxy_socket_params_; | 203 scoped_refptr<HttpProxySocketParams> http_proxy_socket_params_; |
215 ClientSocketPoolHistograms http_proxy_histograms_; | |
216 HttpProxyClientSocketPool http_proxy_socket_pool_; | 204 HttpProxyClientSocketPool http_proxy_socket_pool_; |
217 | 205 |
218 SSLConfig ssl_config_; | 206 SSLConfig ssl_config_; |
219 scoped_ptr<ClientSocketPoolHistograms> ssl_histograms_; | |
220 scoped_ptr<SSLClientSocketPool> pool_; | 207 scoped_ptr<SSLClientSocketPool> pool_; |
221 }; | 208 }; |
222 | 209 |
223 INSTANTIATE_TEST_CASE_P(NextProto, | 210 INSTANTIATE_TEST_CASE_P(NextProto, |
224 SSLClientSocketPoolTest, | 211 SSLClientSocketPoolTest, |
225 testing::Values(kProtoSPDY31, | 212 testing::Values(kProtoSPDY31, |
226 kProtoSPDY4_14, | 213 kProtoSPDY4_14, |
227 kProtoSPDY4)); | 214 kProtoSPDY4)); |
228 | 215 |
229 TEST_P(SSLClientSocketPoolTest, TCPFail) { | 216 TEST_P(SSLClientSocketPoolTest, TCPFail) { |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
924 ssl.channel_id_sent = true; | 911 ssl.channel_id_sent = true; |
925 ssl.SetNextProto(GetParam()); | 912 ssl.SetNextProto(GetParam()); |
926 TestIPPoolingDisabled(&ssl); | 913 TestIPPoolingDisabled(&ssl); |
927 } | 914 } |
928 | 915 |
929 // It would be nice to also test the timeouts in SSLClientSocketPool. | 916 // It would be nice to also test the timeouts in SSLClientSocketPool. |
930 | 917 |
931 } // namespace | 918 } // namespace |
932 | 919 |
933 } // namespace net | 920 } // namespace net |
OLD | NEW |