| 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" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 enum HttpProxyType { | 35 enum HttpProxyType { |
| 36 HTTP, | 36 HTTP, |
| 37 HTTPS, | 37 HTTPS, |
| 38 SPDY | 38 SPDY |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 struct HttpProxyClientSocketPoolTestParams { | 41 struct HttpProxyClientSocketPoolTestParams { |
| 42 HttpProxyClientSocketPoolTestParams() | 42 HttpProxyClientSocketPoolTestParams() |
| 43 : proxy_type(HTTP), | 43 : proxy_type(HTTP), |
| 44 protocol(kProtoSPDY31) {} | 44 protocol(kProtoSPDY31), |
| 45 priority_to_dependency(false) {} |
| 45 | 46 |
| 46 HttpProxyClientSocketPoolTestParams( | 47 HttpProxyClientSocketPoolTestParams(HttpProxyType proxy_type, |
| 47 HttpProxyType proxy_type, | 48 NextProto protocol, |
| 48 NextProto protocol) | 49 bool priority_to_dependency) |
| 49 : proxy_type(proxy_type), | 50 : proxy_type(proxy_type), |
| 50 protocol(protocol) {} | 51 protocol(protocol), |
| 52 priority_to_dependency(priority_to_dependency) {} |
| 51 | 53 |
| 52 HttpProxyType proxy_type; | 54 HttpProxyType proxy_type; |
| 53 NextProto protocol; | 55 NextProto protocol; |
| 56 bool priority_to_dependency; |
| 54 }; | 57 }; |
| 55 | 58 |
| 56 typedef ::testing::TestWithParam<HttpProxyType> TestWithHttpParam; | 59 typedef ::testing::TestWithParam<HttpProxyType> TestWithHttpParam; |
| 57 | 60 |
| 58 const char kHttpProxyHost[] = "httpproxy.example.com"; | 61 const char kHttpProxyHost[] = "httpproxy.example.com"; |
| 59 const char kHttpsProxyHost[] = "httpsproxy.example.com"; | 62 const char kHttpsProxyHost[] = "httpsproxy.example.com"; |
| 60 | 63 |
| 61 class TestProxyDelegate : public ProxyDelegate { | 64 class TestProxyDelegate : public ProxyDelegate { |
| 62 public: | 65 public: |
| 63 TestProxyDelegate() | 66 TestProxyDelegate() |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 bool on_before_tunnel_request_called_; | 145 bool on_before_tunnel_request_called_; |
| 143 bool on_tunnel_request_completed_called_; | 146 bool on_tunnel_request_completed_called_; |
| 144 bool on_tunnel_headers_received_called_; | 147 bool on_tunnel_headers_received_called_; |
| 145 HostPortPair on_tunnel_request_completed_endpoint_; | 148 HostPortPair on_tunnel_request_completed_endpoint_; |
| 146 HostPortPair on_tunnel_request_completed_proxy_server_; | 149 HostPortPair on_tunnel_request_completed_proxy_server_; |
| 147 HostPortPair on_tunnel_headers_received_origin_; | 150 HostPortPair on_tunnel_headers_received_origin_; |
| 148 HostPortPair on_tunnel_headers_received_proxy_server_; | 151 HostPortPair on_tunnel_headers_received_proxy_server_; |
| 149 std::string on_tunnel_headers_received_status_line_; | 152 std::string on_tunnel_headers_received_status_line_; |
| 150 }; | 153 }; |
| 151 | 154 |
| 155 } // namespace |
| 152 | 156 |
| 153 class HttpProxyClientSocketPoolTest | 157 class HttpProxyClientSocketPoolTest |
| 154 : public ::testing::TestWithParam<HttpProxyClientSocketPoolTestParams> { | 158 : public ::testing::TestWithParam<HttpProxyClientSocketPoolTestParams> { |
| 155 protected: | 159 protected: |
| 156 HttpProxyClientSocketPoolTest() | 160 HttpProxyClientSocketPoolTest() |
| 157 : session_deps_(GetParam().protocol), | 161 : session_deps_(GetParam().protocol), |
| 158 transport_socket_pool_(kMaxSockets, | 162 transport_socket_pool_(kMaxSockets, |
| 159 kMaxSocketsPerGroup, | 163 kMaxSocketsPerGroup, |
| 160 session_deps_.socket_factory.get()), | 164 session_deps_.socket_factory.get()), |
| 161 ssl_socket_pool_(kMaxSockets, | 165 ssl_socket_pool_(kMaxSockets, |
| 162 kMaxSocketsPerGroup, | 166 kMaxSocketsPerGroup, |
| 163 session_deps_.cert_verifier.get(), | 167 session_deps_.cert_verifier.get(), |
| 164 NULL /* channel_id_store */, | 168 NULL /* channel_id_store */, |
| 165 NULL /* transport_security_state */, | 169 NULL /* transport_security_state */, |
| 166 NULL /* cert_transparency_verifier */, | 170 NULL /* cert_transparency_verifier */, |
| 167 NULL /* cert_policy_enforcer */, | 171 NULL /* cert_policy_enforcer */, |
| 168 std::string() /* ssl_session_cache_shard */, | 172 std::string() /* ssl_session_cache_shard */, |
| 169 session_deps_.socket_factory.get(), | 173 session_deps_.socket_factory.get(), |
| 170 &transport_socket_pool_, | 174 &transport_socket_pool_, |
| 171 NULL, | 175 NULL, |
| 172 NULL, | 176 NULL, |
| 173 session_deps_.ssl_config_service.get(), | 177 session_deps_.ssl_config_service.get(), |
| 174 BoundNetLog().net_log()), | 178 BoundNetLog().net_log()), |
| 175 session_(CreateNetworkSession()), | 179 session_(CreateNetworkSession()), |
| 176 spdy_util_(GetParam().protocol), | 180 spdy_util_(GetParam().protocol, GetParam().priority_to_dependency), |
| 177 pool_(kMaxSockets, | 181 pool_(kMaxSockets, |
| 178 kMaxSocketsPerGroup, | 182 kMaxSocketsPerGroup, |
| 179 &transport_socket_pool_, | 183 &transport_socket_pool_, |
| 180 &ssl_socket_pool_, | 184 &ssl_socket_pool_, |
| 181 NULL) {} | 185 NULL) { |
| 186 SpdySession::SetPriorityDependencyDefaultForTesting( |
| 187 GetParam().priority_to_dependency); |
| 188 } |
| 182 | 189 |
| 183 virtual ~HttpProxyClientSocketPoolTest() { | 190 virtual ~HttpProxyClientSocketPoolTest() { |
| 191 SpdySession::SetPriorityDependencyDefaultForTesting(false); |
| 184 } | 192 } |
| 185 | 193 |
| 186 void AddAuthToCache() { | 194 void AddAuthToCache() { |
| 187 const base::string16 kFoo(base::ASCIIToUTF16("foo")); | 195 const base::string16 kFoo(base::ASCIIToUTF16("foo")); |
| 188 const base::string16 kBar(base::ASCIIToUTF16("bar")); | 196 const base::string16 kBar(base::ASCIIToUTF16("bar")); |
| 189 GURL proxy_url(GetParam().proxy_type == HTTP ? | 197 GURL proxy_url(GetParam().proxy_type == HTTP ? |
| 190 (std::string("http://") + kHttpProxyHost) : | 198 (std::string("http://") + kHttpProxyHost) : |
| 191 (std::string("https://") + kHttpsProxyHost)); | 199 (std::string("https://") + kHttpsProxyHost)); |
| 192 session_->http_auth_cache()->Add(proxy_url, | 200 session_->http_auth_cache()->Add(proxy_url, |
| 193 "MyRealm1", | 201 "MyRealm1", |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 | 324 |
| 317 //----------------------------------------------------------------------------- | 325 //----------------------------------------------------------------------------- |
| 318 // All tests are run with three different proxy types: HTTP, HTTPS (non-SPDY) | 326 // All tests are run with three different proxy types: HTTP, HTTPS (non-SPDY) |
| 319 // and SPDY. | 327 // and SPDY. |
| 320 // | 328 // |
| 321 // TODO(akalin): Use ::testing::Combine() when we are able to use | 329 // TODO(akalin): Use ::testing::Combine() when we are able to use |
| 322 // <tr1/tuple>. | 330 // <tr1/tuple>. |
| 323 INSTANTIATE_TEST_CASE_P( | 331 INSTANTIATE_TEST_CASE_P( |
| 324 HttpProxyClientSocketPoolTests, | 332 HttpProxyClientSocketPoolTests, |
| 325 HttpProxyClientSocketPoolTest, | 333 HttpProxyClientSocketPoolTest, |
| 326 ::testing::Values(HttpProxyClientSocketPoolTestParams(HTTP, kProtoSPDY31), | 334 ::testing::Values( |
| 327 HttpProxyClientSocketPoolTestParams(HTTPS, kProtoSPDY31), | 335 HttpProxyClientSocketPoolTestParams(HTTP, kProtoSPDY31, false), |
| 328 HttpProxyClientSocketPoolTestParams(SPDY, kProtoSPDY31), | 336 HttpProxyClientSocketPoolTestParams(HTTPS, kProtoSPDY31, false), |
| 329 HttpProxyClientSocketPoolTestParams(HTTP, kProtoHTTP2), | 337 HttpProxyClientSocketPoolTestParams(SPDY, kProtoSPDY31, false), |
| 330 HttpProxyClientSocketPoolTestParams(HTTPS, kProtoHTTP2), | 338 HttpProxyClientSocketPoolTestParams(HTTP, kProtoHTTP2, false), |
| 331 HttpProxyClientSocketPoolTestParams(SPDY, kProtoHTTP2))); | 339 HttpProxyClientSocketPoolTestParams(HTTP, kProtoHTTP2, true), |
| 340 HttpProxyClientSocketPoolTestParams(HTTPS, kProtoHTTP2, false), |
| 341 HttpProxyClientSocketPoolTestParams(HTTPS, kProtoHTTP2, true), |
| 342 HttpProxyClientSocketPoolTestParams(SPDY, kProtoHTTP2, false), |
| 343 HttpProxyClientSocketPoolTestParams(SPDY, kProtoHTTP2, true))); |
| 332 | 344 |
| 333 TEST_P(HttpProxyClientSocketPoolTest, NoTunnel) { | 345 TEST_P(HttpProxyClientSocketPoolTest, NoTunnel) { |
| 334 Initialize(NULL, 0, NULL, 0, NULL, 0, NULL, 0); | 346 Initialize(NULL, 0, NULL, 0, NULL, 0, NULL, 0); |
| 335 | 347 |
| 336 scoped_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); | 348 scoped_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
| 337 int rv = handle_.Init("a", CreateNoTunnelParams(proxy_delegate.get()), LOW, | 349 int rv = handle_.Init("a", CreateNoTunnelParams(proxy_delegate.get()), LOW, |
| 338 CompletionCallback(), &pool_, BoundNetLog()); | 350 CompletionCallback(), &pool_, BoundNetLog()); |
| 339 EXPECT_EQ(OK, rv); | 351 EXPECT_EQ(OK, rv); |
| 340 EXPECT_TRUE(handle_.is_initialized()); | 352 EXPECT_TRUE(handle_.is_initialized()); |
| 341 ASSERT_TRUE(handle_.socket()); | 353 ASSERT_TRUE(handle_.socket()); |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 805 | 817 |
| 806 // Make sure Location header was included and correct. | 818 // Make sure Location header was included and correct. |
| 807 std::string location; | 819 std::string location; |
| 808 EXPECT_TRUE(headers->IsRedirect(&location)); | 820 EXPECT_TRUE(headers->IsRedirect(&location)); |
| 809 EXPECT_EQ(location, redirectTarget); | 821 EXPECT_EQ(location, redirectTarget); |
| 810 } | 822 } |
| 811 } | 823 } |
| 812 | 824 |
| 813 // It would be nice to also test the timeouts in HttpProxyClientSocketPool. | 825 // It would be nice to also test the timeouts in HttpProxyClientSocketPool. |
| 814 | 826 |
| 815 } // namespace | |
| 816 | |
| 817 } // namespace net | 827 } // namespace net |
| OLD | NEW |