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 "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
12 #include "net/base/proxy_delegate.h" | |
12 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
13 #include "net/http/http_network_session.h" | 14 #include "net/http/http_network_session.h" |
14 #include "net/http/http_proxy_client_socket.h" | 15 #include "net/http/http_proxy_client_socket.h" |
15 #include "net/http/http_response_headers.h" | 16 #include "net/http/http_response_headers.h" |
16 #include "net/socket/client_socket_handle.h" | 17 #include "net/socket/client_socket_handle.h" |
17 #include "net/socket/client_socket_pool_histograms.h" | 18 #include "net/socket/client_socket_pool_histograms.h" |
18 #include "net/socket/next_proto.h" | 19 #include "net/socket/next_proto.h" |
19 #include "net/socket/socket_test_util.h" | 20 #include "net/socket/socket_test_util.h" |
20 #include "net/spdy/spdy_protocol.h" | 21 #include "net/spdy/spdy_protocol.h" |
21 #include "net/spdy/spdy_test_util_common.h" | 22 #include "net/spdy/spdy_test_util_common.h" |
(...skipping 30 matching lines...) Expand all Loading... | |
52 HttpProxyType proxy_type; | 53 HttpProxyType proxy_type; |
53 NextProto protocol; | 54 NextProto protocol; |
54 }; | 55 }; |
55 | 56 |
56 typedef ::testing::TestWithParam<HttpProxyType> TestWithHttpParam; | 57 typedef ::testing::TestWithParam<HttpProxyType> TestWithHttpParam; |
57 | 58 |
58 const char kHttpProxyHost[] = "httpproxy.example.com"; | 59 const char kHttpProxyHost[] = "httpproxy.example.com"; |
59 const char kHttpsProxyHost[] = "httpsproxy.example.com"; | 60 const char kHttpsProxyHost[] = "httpsproxy.example.com"; |
60 | 61 |
61 class HttpProxyClientSocketPoolTest | 62 class HttpProxyClientSocketPoolTest |
62 : public ::testing::TestWithParam<HttpProxyClientSocketPoolTestParams> { | 63 : public ::testing::TestWithParam<HttpProxyClientSocketPoolTestParams>, |
64 public net::ProxyDelegate { | |
63 protected: | 65 protected: |
64 HttpProxyClientSocketPoolTest() | 66 HttpProxyClientSocketPoolTest() |
65 : session_deps_(GetParam().protocol), | 67 : session_deps_(GetParam().protocol), |
66 tcp_histograms_("MockTCP"), | 68 tcp_histograms_("MockTCP"), |
67 transport_socket_pool_( | 69 transport_socket_pool_( |
68 kMaxSockets, | 70 kMaxSockets, |
69 kMaxSocketsPerGroup, | 71 kMaxSocketsPerGroup, |
70 &tcp_histograms_, | 72 &tcp_histograms_, |
71 session_deps_.deterministic_socket_factory.get()), | 73 session_deps_.deterministic_socket_factory.get()), |
72 ssl_histograms_("MockSSL"), | 74 ssl_histograms_("MockSSL"), |
73 ssl_socket_pool_(kMaxSockets, | 75 ssl_socket_pool_(kMaxSockets, |
74 kMaxSocketsPerGroup, | 76 kMaxSocketsPerGroup, |
75 &ssl_histograms_, | 77 &ssl_histograms_, |
76 session_deps_.host_resolver.get(), | 78 session_deps_.host_resolver.get(), |
77 session_deps_.cert_verifier.get(), | 79 session_deps_.cert_verifier.get(), |
78 NULL /* channel_id_store */, | 80 NULL /* channel_id_store */, |
79 NULL /* transport_security_state */, | 81 NULL /* transport_security_state */, |
80 NULL /* cert_transparency_verifier */, | 82 NULL /* cert_transparency_verifier */, |
81 std::string() /* ssl_session_cache_shard */, | 83 std::string() /* ssl_session_cache_shard */, |
82 session_deps_.deterministic_socket_factory.get(), | 84 session_deps_.deterministic_socket_factory.get(), |
83 &transport_socket_pool_, | 85 &transport_socket_pool_, |
84 NULL, | 86 NULL, |
85 NULL, | 87 NULL, |
86 session_deps_.ssl_config_service.get(), | 88 session_deps_.ssl_config_service.get(), |
87 false, | 89 false, |
88 BoundNetLog().net_log()), | 90 BoundNetLog().net_log()), |
89 session_(CreateNetworkSession()), | 91 session_(CreateNetworkSession()), |
90 http_proxy_histograms_("HttpProxyUnitTest"), | 92 http_proxy_histograms_("HttpProxyUnitTest"), |
93 on_before_tunnel_request_called_(false), | |
94 on_before_tunnel_headers_received_called_(false), | |
91 spdy_util_(GetParam().protocol), | 95 spdy_util_(GetParam().protocol), |
92 pool_(kMaxSockets, | 96 pool_(kMaxSockets, |
93 kMaxSocketsPerGroup, | 97 kMaxSocketsPerGroup, |
94 &http_proxy_histograms_, | 98 &http_proxy_histograms_, |
95 NULL, | 99 NULL, |
96 &transport_socket_pool_, | 100 &transport_socket_pool_, |
97 &ssl_socket_pool_, | 101 &ssl_socket_pool_, |
102 this, | |
98 NULL) {} | 103 NULL) {} |
99 | 104 |
100 virtual ~HttpProxyClientSocketPoolTest() { | 105 virtual ~HttpProxyClientSocketPoolTest() { |
101 } | 106 } |
102 | 107 |
103 void AddAuthToCache() { | 108 void AddAuthToCache() { |
104 const base::string16 kFoo(base::ASCIIToUTF16("foo")); | 109 const base::string16 kFoo(base::ASCIIToUTF16("foo")); |
105 const base::string16 kBar(base::ASCIIToUTF16("bar")); | 110 const base::string16 kBar(base::ASCIIToUTF16("bar")); |
106 GURL proxy_url(GetParam().proxy_type == HTTP ? | 111 GURL proxy_url(GetParam().proxy_type == HTTP ? |
107 (std::string("http://") + kHttpProxyHost) : | 112 (std::string("http://") + kHttpProxyHost) : |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 scoped_refptr<HttpProxySocketParams> CreateParams(bool tunnel) { | 152 scoped_refptr<HttpProxySocketParams> CreateParams(bool tunnel) { |
148 return scoped_refptr<HttpProxySocketParams>(new HttpProxySocketParams( | 153 return scoped_refptr<HttpProxySocketParams>(new HttpProxySocketParams( |
149 CreateHttpProxyParams(), | 154 CreateHttpProxyParams(), |
150 CreateHttpsProxyParams(), | 155 CreateHttpsProxyParams(), |
151 GURL(tunnel ? "https://www.google.com/" : "http://www.google.com"), | 156 GURL(tunnel ? "https://www.google.com/" : "http://www.google.com"), |
152 std::string(), | 157 std::string(), |
153 HostPortPair("www.google.com", tunnel ? 443 : 80), | 158 HostPortPair("www.google.com", tunnel ? 443 : 80), |
154 session_->http_auth_cache(), | 159 session_->http_auth_cache(), |
155 session_->http_auth_handler_factory(), | 160 session_->http_auth_handler_factory(), |
156 session_->spdy_session_pool(), | 161 session_->spdy_session_pool(), |
157 tunnel)); | 162 tunnel, |
163 this)); | |
158 } | 164 } |
159 | 165 |
160 scoped_refptr<HttpProxySocketParams> CreateTunnelParams() { | 166 scoped_refptr<HttpProxySocketParams> CreateTunnelParams() { |
161 return CreateParams(true); | 167 return CreateParams(true); |
162 } | 168 } |
163 | 169 |
164 scoped_refptr<HttpProxySocketParams> CreateNoTunnelParams() { | 170 scoped_refptr<HttpProxySocketParams> CreateNoTunnelParams() { |
165 return CreateParams(false); | 171 return CreateParams(false); |
166 } | 172 } |
167 | 173 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 | 207 |
202 HttpNetworkSession* CreateNetworkSession() { | 208 HttpNetworkSession* CreateNetworkSession() { |
203 return SpdySessionDependencies::SpdyCreateSessionDeterministic( | 209 return SpdySessionDependencies::SpdyCreateSessionDeterministic( |
204 &session_deps_); | 210 &session_deps_); |
205 } | 211 } |
206 | 212 |
207 RequestPriority GetLastTransportRequestPriority() const { | 213 RequestPriority GetLastTransportRequestPriority() const { |
208 return transport_socket_pool_.last_request_priority(); | 214 return transport_socket_pool_.last_request_priority(); |
209 } | 215 } |
210 | 216 |
217 // ProxyDelegate: | |
218 virtual void OnResolveProxy(const GURL& url, | |
219 int load_flags, | |
220 const ProxyService& proxy_service, | |
221 ProxyInfo* result) OVERRIDE { | |
222 } | |
223 | |
224 virtual void OnFallback(const ProxyServer& bad_proxy, | |
225 int net_error) OVERRIDE { | |
226 } | |
227 | |
228 virtual void OnBeforeSendHeaders(URLRequest* request, | |
229 const ProxyInfo& proxy_info, | |
230 HttpRequestHeaders* headers) OVERRIDE { | |
231 } | |
232 | |
233 virtual void OnBeforeTunnelRequest( | |
234 const net::HostPortPair& proxy_server, | |
235 net::HttpRequestHeaders* extra_headers) OVERRIDE { | |
236 on_before_tunnel_request_called_ = true; | |
mmenke
2014/09/08 17:38:50
Should check this actually works (Maybe add a head
bengr
2014/09/09 01:28:49
Done.
| |
237 } | |
238 | |
239 virtual void OnTunnelHeadersReceived( | |
240 const net::HostPortPair& origin, | |
241 const net::HostPortPair& proxy_server, | |
242 const net::HttpResponseHeaders& response_headers) OVERRIDE { | |
mmenke
2014/09/08 17:38:50
Again, should validate these some way.
bengr
2014/09/09 01:28:49
Done.
| |
243 on_before_tunnel_headers_received_called_ = true; | |
244 } | |
245 | |
246 bool on_before_tunnel_request_called() { | |
247 return on_before_tunnel_request_called_; | |
248 } | |
249 | |
250 bool on_before_tunnel_headers_received_called() { | |
mmenke
2014/09/08 17:38:50
These two should be const
bengr
2014/09/09 01:28:49
Done.
| |
251 return on_before_tunnel_headers_received_called_; | |
252 } | |
253 | |
211 private: | 254 private: |
212 SpdySessionDependencies session_deps_; | 255 SpdySessionDependencies session_deps_; |
213 | 256 |
214 ClientSocketPoolHistograms tcp_histograms_; | 257 ClientSocketPoolHistograms tcp_histograms_; |
215 MockTransportClientSocketPool transport_socket_pool_; | 258 MockTransportClientSocketPool transport_socket_pool_; |
216 ClientSocketPoolHistograms ssl_histograms_; | 259 ClientSocketPoolHistograms ssl_histograms_; |
217 MockHostResolver host_resolver_; | 260 MockHostResolver host_resolver_; |
218 scoped_ptr<CertVerifier> cert_verifier_; | 261 scoped_ptr<CertVerifier> cert_verifier_; |
219 SSLClientSocketPool ssl_socket_pool_; | 262 SSLClientSocketPool ssl_socket_pool_; |
220 | 263 |
221 const scoped_refptr<HttpNetworkSession> session_; | 264 const scoped_refptr<HttpNetworkSession> session_; |
222 ClientSocketPoolHistograms http_proxy_histograms_; | 265 ClientSocketPoolHistograms http_proxy_histograms_; |
266 bool on_before_tunnel_request_called_; | |
267 bool on_before_tunnel_headers_received_called_; | |
223 | 268 |
224 protected: | 269 protected: |
225 SpdyTestUtil spdy_util_; | 270 SpdyTestUtil spdy_util_; |
226 scoped_ptr<SSLSocketDataProvider> ssl_data_; | 271 scoped_ptr<SSLSocketDataProvider> ssl_data_; |
227 scoped_ptr<DeterministicSocketData> data_; | 272 scoped_ptr<DeterministicSocketData> data_; |
228 HttpProxyClientSocketPool pool_; | 273 HttpProxyClientSocketPool pool_; |
229 ClientSocketHandle handle_; | 274 ClientSocketHandle handle_; |
230 TestCompletionCallback callback_; | 275 TestCompletionCallback callback_; |
231 }; | 276 }; |
232 | 277 |
(...skipping 24 matching lines...) Expand all Loading... | |
257 Initialize(NULL, 0, NULL, 0, NULL, 0, NULL, 0); | 302 Initialize(NULL, 0, NULL, 0, NULL, 0, NULL, 0); |
258 | 303 |
259 int rv = handle_.Init("a", CreateNoTunnelParams(), LOW, CompletionCallback(), | 304 int rv = handle_.Init("a", CreateNoTunnelParams(), LOW, CompletionCallback(), |
260 &pool_, BoundNetLog()); | 305 &pool_, BoundNetLog()); |
261 EXPECT_EQ(OK, rv); | 306 EXPECT_EQ(OK, rv); |
262 EXPECT_TRUE(handle_.is_initialized()); | 307 EXPECT_TRUE(handle_.is_initialized()); |
263 ASSERT_TRUE(handle_.socket()); | 308 ASSERT_TRUE(handle_.socket()); |
264 HttpProxyClientSocket* tunnel_socket = | 309 HttpProxyClientSocket* tunnel_socket = |
265 static_cast<HttpProxyClientSocket*>(handle_.socket()); | 310 static_cast<HttpProxyClientSocket*>(handle_.socket()); |
266 EXPECT_TRUE(tunnel_socket->IsConnected()); | 311 EXPECT_TRUE(tunnel_socket->IsConnected()); |
312 EXPECT_FALSE(on_before_tunnel_request_called()); | |
313 EXPECT_FALSE(on_before_tunnel_headers_received_called()); | |
267 } | 314 } |
268 | 315 |
269 // Make sure that HttpProxyConnectJob passes on its priority to its | 316 // Make sure that HttpProxyConnectJob passes on its priority to its |
270 // (non-SSL) socket request on Init. | 317 // (non-SSL) socket request on Init. |
271 TEST_P(HttpProxyClientSocketPoolTest, SetSocketRequestPriorityOnInit) { | 318 TEST_P(HttpProxyClientSocketPoolTest, SetSocketRequestPriorityOnInit) { |
272 Initialize(NULL, 0, NULL, 0, NULL, 0, NULL, 0); | 319 Initialize(NULL, 0, NULL, 0, NULL, 0, NULL, 0); |
273 EXPECT_EQ(OK, | 320 EXPECT_EQ(OK, |
274 handle_.Init("a", CreateNoTunnelParams(), HIGHEST, | 321 handle_.Init("a", CreateNoTunnelParams(), HIGHEST, |
275 CompletionCallback(), &pool_, BoundNetLog())); | 322 CompletionCallback(), &pool_, BoundNetLog())); |
276 EXPECT_EQ(HIGHEST, GetLastTransportRequestPriority()); | 323 EXPECT_EQ(HIGHEST, GetLastTransportRequestPriority()); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
356 AddAuthToCache(); | 403 AddAuthToCache(); |
357 | 404 |
358 int rv = handle_.Init("a", CreateTunnelParams(), LOW, callback_.callback(), | 405 int rv = handle_.Init("a", CreateTunnelParams(), LOW, callback_.callback(), |
359 &pool_, BoundNetLog()); | 406 &pool_, BoundNetLog()); |
360 EXPECT_EQ(OK, rv); | 407 EXPECT_EQ(OK, rv); |
361 EXPECT_TRUE(handle_.is_initialized()); | 408 EXPECT_TRUE(handle_.is_initialized()); |
362 ASSERT_TRUE(handle_.socket()); | 409 ASSERT_TRUE(handle_.socket()); |
363 HttpProxyClientSocket* tunnel_socket = | 410 HttpProxyClientSocket* tunnel_socket = |
364 static_cast<HttpProxyClientSocket*>(handle_.socket()); | 411 static_cast<HttpProxyClientSocket*>(handle_.socket()); |
365 EXPECT_TRUE(tunnel_socket->IsConnected()); | 412 EXPECT_TRUE(tunnel_socket->IsConnected()); |
413 EXPECT_TRUE(on_before_tunnel_request_called()); | |
414 EXPECT_TRUE(on_before_tunnel_headers_received_called()); | |
366 } | 415 } |
367 | 416 |
368 TEST_P(HttpProxyClientSocketPoolTest, AsyncHaveAuth) { | 417 TEST_P(HttpProxyClientSocketPoolTest, AsyncHaveAuth) { |
369 MockWrite writes[] = { | 418 MockWrite writes[] = { |
370 MockWrite(ASYNC, 0, "CONNECT www.google.com:443 HTTP/1.1\r\n" | 419 MockWrite(ASYNC, 0, "CONNECT www.google.com:443 HTTP/1.1\r\n" |
371 "Host: www.google.com\r\n" | 420 "Host: www.google.com\r\n" |
372 "Proxy-Connection: keep-alive\r\n" | 421 "Proxy-Connection: keep-alive\r\n" |
373 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | 422 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
374 }; | 423 }; |
375 MockRead reads[] = { | 424 MockRead reads[] = { |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
713 EXPECT_TRUE(headers->IsRedirect(&location)); | 762 EXPECT_TRUE(headers->IsRedirect(&location)); |
714 EXPECT_EQ(location, redirectTarget); | 763 EXPECT_EQ(location, redirectTarget); |
715 } | 764 } |
716 } | 765 } |
717 | 766 |
718 // It would be nice to also test the timeouts in HttpProxyClientSocketPool. | 767 // It would be nice to also test the timeouts in HttpProxyClientSocketPool. |
719 | 768 |
720 } // namespace | 769 } // namespace |
721 | 770 |
722 } // namespace net | 771 } // namespace net |
OLD | NEW |