| 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/test_completion_callback.h" | 12 #include "net/base/test_completion_callback.h" |
| 13 #include "net/http/http_network_session.h" | 13 #include "net/http/http_network_session.h" |
| 14 #include "net/http/http_proxy_client_socket.h" | 14 #include "net/http/http_proxy_client_socket.h" |
| 15 #include "net/http/http_proxy_tunnel_delegate.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" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 24 |
| 24 namespace net { | 25 namespace net { |
| (...skipping 27 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::HttpProxyTunnelDelegate { |
| 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_proxy_tunnel_request_called_(false), |
| 94 on_before_proxy_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 virtual void OnBeforeRequest( |
| 218 const net::HostPortPair& proxy_server, |
| 219 net::HttpRequestHeaders* extra_headers) OVERRIDE { |
| 220 on_before_proxy_tunnel_request_called_ = true; |
| 221 } |
| 222 |
| 223 virtual void OnHeadersReceived( |
| 224 const net::HostPortPair& origin, |
| 225 const net::HostPortPair& proxy_server, |
| 226 const net::HttpResponseHeaders& response_headers) OVERRIDE { |
| 227 on_before_proxy_tunnel_headers_received_called_ = true; |
| 228 } |
| 229 |
| 230 bool on_before_proxy_tunnel_request_called() { |
| 231 return on_before_proxy_tunnel_request_called_; |
| 232 } |
| 233 |
| 234 bool on_before_proxy_tunnel_headers_received_called() { |
| 235 return on_before_proxy_tunnel_headers_received_called_; |
| 236 } |
| 237 |
| 211 private: | 238 private: |
| 212 SpdySessionDependencies session_deps_; | 239 SpdySessionDependencies session_deps_; |
| 213 | 240 |
| 214 ClientSocketPoolHistograms tcp_histograms_; | 241 ClientSocketPoolHistograms tcp_histograms_; |
| 215 MockTransportClientSocketPool transport_socket_pool_; | 242 MockTransportClientSocketPool transport_socket_pool_; |
| 216 ClientSocketPoolHistograms ssl_histograms_; | 243 ClientSocketPoolHistograms ssl_histograms_; |
| 217 MockHostResolver host_resolver_; | 244 MockHostResolver host_resolver_; |
| 218 scoped_ptr<CertVerifier> cert_verifier_; | 245 scoped_ptr<CertVerifier> cert_verifier_; |
| 219 SSLClientSocketPool ssl_socket_pool_; | 246 SSLClientSocketPool ssl_socket_pool_; |
| 220 | 247 |
| 221 const scoped_refptr<HttpNetworkSession> session_; | 248 const scoped_refptr<HttpNetworkSession> session_; |
| 222 ClientSocketPoolHistograms http_proxy_histograms_; | 249 ClientSocketPoolHistograms http_proxy_histograms_; |
| 250 bool on_before_proxy_tunnel_request_called_; |
| 251 bool on_before_proxy_tunnel_headers_received_called_; |
| 223 | 252 |
| 224 protected: | 253 protected: |
| 225 SpdyTestUtil spdy_util_; | 254 SpdyTestUtil spdy_util_; |
| 226 scoped_ptr<SSLSocketDataProvider> ssl_data_; | 255 scoped_ptr<SSLSocketDataProvider> ssl_data_; |
| 227 scoped_ptr<DeterministicSocketData> data_; | 256 scoped_ptr<DeterministicSocketData> data_; |
| 228 HttpProxyClientSocketPool pool_; | 257 HttpProxyClientSocketPool pool_; |
| 229 ClientSocketHandle handle_; | 258 ClientSocketHandle handle_; |
| 230 TestCompletionCallback callback_; | 259 TestCompletionCallback callback_; |
| 231 }; | 260 }; |
| 232 | 261 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 257 Initialize(NULL, 0, NULL, 0, NULL, 0, NULL, 0); | 286 Initialize(NULL, 0, NULL, 0, NULL, 0, NULL, 0); |
| 258 | 287 |
| 259 int rv = handle_.Init("a", CreateNoTunnelParams(), LOW, CompletionCallback(), | 288 int rv = handle_.Init("a", CreateNoTunnelParams(), LOW, CompletionCallback(), |
| 260 &pool_, BoundNetLog()); | 289 &pool_, BoundNetLog()); |
| 261 EXPECT_EQ(OK, rv); | 290 EXPECT_EQ(OK, rv); |
| 262 EXPECT_TRUE(handle_.is_initialized()); | 291 EXPECT_TRUE(handle_.is_initialized()); |
| 263 ASSERT_TRUE(handle_.socket()); | 292 ASSERT_TRUE(handle_.socket()); |
| 264 HttpProxyClientSocket* tunnel_socket = | 293 HttpProxyClientSocket* tunnel_socket = |
| 265 static_cast<HttpProxyClientSocket*>(handle_.socket()); | 294 static_cast<HttpProxyClientSocket*>(handle_.socket()); |
| 266 EXPECT_TRUE(tunnel_socket->IsConnected()); | 295 EXPECT_TRUE(tunnel_socket->IsConnected()); |
| 296 EXPECT_FALSE(on_before_proxy_tunnel_request_called()); |
| 297 EXPECT_FALSE(on_before_proxy_tunnel_headers_received_called()); |
| 267 } | 298 } |
| 268 | 299 |
| 269 // Make sure that HttpProxyConnectJob passes on its priority to its | 300 // Make sure that HttpProxyConnectJob passes on its priority to its |
| 270 // (non-SSL) socket request on Init. | 301 // (non-SSL) socket request on Init. |
| 271 TEST_P(HttpProxyClientSocketPoolTest, SetSocketRequestPriorityOnInit) { | 302 TEST_P(HttpProxyClientSocketPoolTest, SetSocketRequestPriorityOnInit) { |
| 272 Initialize(NULL, 0, NULL, 0, NULL, 0, NULL, 0); | 303 Initialize(NULL, 0, NULL, 0, NULL, 0, NULL, 0); |
| 273 EXPECT_EQ(OK, | 304 EXPECT_EQ(OK, |
| 274 handle_.Init("a", CreateNoTunnelParams(), HIGHEST, | 305 handle_.Init("a", CreateNoTunnelParams(), HIGHEST, |
| 275 CompletionCallback(), &pool_, BoundNetLog())); | 306 CompletionCallback(), &pool_, BoundNetLog())); |
| 276 EXPECT_EQ(HIGHEST, GetLastTransportRequestPriority()); | 307 EXPECT_EQ(HIGHEST, GetLastTransportRequestPriority()); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 AddAuthToCache(); | 387 AddAuthToCache(); |
| 357 | 388 |
| 358 int rv = handle_.Init("a", CreateTunnelParams(), LOW, callback_.callback(), | 389 int rv = handle_.Init("a", CreateTunnelParams(), LOW, callback_.callback(), |
| 359 &pool_, BoundNetLog()); | 390 &pool_, BoundNetLog()); |
| 360 EXPECT_EQ(OK, rv); | 391 EXPECT_EQ(OK, rv); |
| 361 EXPECT_TRUE(handle_.is_initialized()); | 392 EXPECT_TRUE(handle_.is_initialized()); |
| 362 ASSERT_TRUE(handle_.socket()); | 393 ASSERT_TRUE(handle_.socket()); |
| 363 HttpProxyClientSocket* tunnel_socket = | 394 HttpProxyClientSocket* tunnel_socket = |
| 364 static_cast<HttpProxyClientSocket*>(handle_.socket()); | 395 static_cast<HttpProxyClientSocket*>(handle_.socket()); |
| 365 EXPECT_TRUE(tunnel_socket->IsConnected()); | 396 EXPECT_TRUE(tunnel_socket->IsConnected()); |
| 397 EXPECT_TRUE(on_before_proxy_tunnel_request_called()); |
| 398 EXPECT_TRUE(on_before_proxy_tunnel_headers_received_called()); |
| 366 } | 399 } |
| 367 | 400 |
| 368 TEST_P(HttpProxyClientSocketPoolTest, AsyncHaveAuth) { | 401 TEST_P(HttpProxyClientSocketPoolTest, AsyncHaveAuth) { |
| 369 MockWrite writes[] = { | 402 MockWrite writes[] = { |
| 370 MockWrite(ASYNC, 0, "CONNECT www.google.com:443 HTTP/1.1\r\n" | 403 MockWrite(ASYNC, 0, "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 371 "Host: www.google.com\r\n" | 404 "Host: www.google.com\r\n" |
| 372 "Proxy-Connection: keep-alive\r\n" | 405 "Proxy-Connection: keep-alive\r\n" |
| 373 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | 406 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 374 }; | 407 }; |
| 375 MockRead reads[] = { | 408 MockRead reads[] = { |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 EXPECT_TRUE(headers->IsRedirect(&location)); | 746 EXPECT_TRUE(headers->IsRedirect(&location)); |
| 714 EXPECT_EQ(location, redirectTarget); | 747 EXPECT_EQ(location, redirectTarget); |
| 715 } | 748 } |
| 716 } | 749 } |
| 717 | 750 |
| 718 // It would be nice to also test the timeouts in HttpProxyClientSocketPool. | 751 // It would be nice to also test the timeouts in HttpProxyClientSocketPool. |
| 719 | 752 |
| 720 } // namespace | 753 } // namespace |
| 721 | 754 |
| 722 } // namespace net | 755 } // namespace net |
| OLD | NEW |