| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <math.h> // ceil | 5 #include <math.h> // ceil |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "net/base/completion_callback.h" | 8 #include "net/base/completion_callback.h" |
| 9 #include "net/base/mock_host_resolver.h" | 9 #include "net/base/mock_host_resolver.h" |
| 10 #include "net/base/ssl_info.h" | 10 #include "net/base/ssl_info.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 public: | 36 public: |
| 37 // Default set of dependencies -- "null" proxy service. | 37 // Default set of dependencies -- "null" proxy service. |
| 38 SessionDependencies() : host_resolver(new MockHostResolver), | 38 SessionDependencies() : host_resolver(new MockHostResolver), |
| 39 proxy_service(CreateNullProxyService()) {} | 39 proxy_service(CreateNullProxyService()) {} |
| 40 | 40 |
| 41 // Custom proxy service dependency. | 41 // Custom proxy service dependency. |
| 42 explicit SessionDependencies(ProxyService* proxy_service) | 42 explicit SessionDependencies(ProxyService* proxy_service) |
| 43 : host_resolver(new MockHostResolver), proxy_service(proxy_service) {} | 43 : host_resolver(new MockHostResolver), proxy_service(proxy_service) {} |
| 44 | 44 |
| 45 scoped_refptr<MockHostResolverBase> host_resolver; | 45 scoped_refptr<MockHostResolverBase> host_resolver; |
| 46 scoped_ptr<ProxyService> proxy_service; | 46 scoped_refptr<ProxyService> proxy_service; |
| 47 MockClientSocketFactory socket_factory; | 47 MockClientSocketFactory socket_factory; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 ProxyService* CreateFixedProxyService(const std::string& proxy) { | 50 ProxyService* CreateFixedProxyService(const std::string& proxy) { |
| 51 net::ProxyConfig proxy_config; | 51 net::ProxyConfig proxy_config; |
| 52 proxy_config.proxy_rules.ParseFromString(proxy); | 52 proxy_config.proxy_rules.ParseFromString(proxy); |
| 53 return ProxyService::CreateFixed(proxy_config); | 53 return ProxyService::CreateFixed(proxy_config); |
| 54 } | 54 } |
| 55 | 55 |
| 56 | 56 |
| 57 HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { | 57 HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { |
| 58 return new HttpNetworkSession(session_deps->host_resolver, | 58 return new HttpNetworkSession(session_deps->host_resolver, |
| 59 session_deps->proxy_service.get(), | 59 session_deps->proxy_service, |
| 60 &session_deps->socket_factory); | 60 &session_deps->socket_factory); |
| 61 } | 61 } |
| 62 | 62 |
| 63 class HttpNetworkTransactionTest : public PlatformTest { | 63 class HttpNetworkTransactionTest : public PlatformTest { |
| 64 public: | 64 public: |
| 65 virtual void TearDown() { | 65 virtual void TearDown() { |
| 66 // Empty the current queue. | 66 // Empty the current queue. |
| 67 MessageLoop::current()->RunAllPending(); | 67 MessageLoop::current()->RunAllPending(); |
| 68 PlatformTest::TearDown(); | 68 PlatformTest::TearDown(); |
| 69 } | 69 } |
| (...skipping 2976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3046 TestCompletionCallback callback; | 3046 TestCompletionCallback callback; |
| 3047 | 3047 |
| 3048 int rv = trans->Start(&request, &callback, NULL); | 3048 int rv = trans->Start(&request, &callback, NULL); |
| 3049 EXPECT_EQ(ERR_IO_PENDING, rv); | 3049 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3050 | 3050 |
| 3051 rv = callback.WaitForResult(); | 3051 rv = callback.WaitForResult(); |
| 3052 EXPECT_EQ(OK, rv); | 3052 EXPECT_EQ(OK, rv); |
| 3053 } | 3053 } |
| 3054 | 3054 |
| 3055 TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { | 3055 TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
| 3056 SessionDependencies session_deps; | 3056 SessionDependencies session_deps( |
| 3057 session_deps.proxy_service.reset(CreateFixedProxyService( | 3057 CreateFixedProxyService("socks4://myproxy:1080")); |
| 3058 "socks4://myproxy:1080")); | |
| 3059 | 3058 |
| 3060 scoped_ptr<HttpTransaction> trans( | 3059 scoped_ptr<HttpTransaction> trans( |
| 3061 new HttpNetworkTransaction( | 3060 new HttpNetworkTransaction( |
| 3062 CreateSession(&session_deps), | 3061 CreateSession(&session_deps), |
| 3063 &session_deps.socket_factory)); | 3062 &session_deps.socket_factory)); |
| 3064 | 3063 |
| 3065 HttpRequestInfo request; | 3064 HttpRequestInfo request; |
| 3066 request.method = "GET"; | 3065 request.method = "GET"; |
| 3067 request.url = GURL("http://www.google.com/"); | 3066 request.url = GURL("http://www.google.com/"); |
| 3068 request.load_flags = 0; | 3067 request.load_flags = 0; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3099 const HttpResponseInfo* response = trans->GetResponseInfo(); | 3098 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3100 EXPECT_FALSE(response == NULL); | 3099 EXPECT_FALSE(response == NULL); |
| 3101 | 3100 |
| 3102 std::string response_text; | 3101 std::string response_text; |
| 3103 rv = ReadTransaction(trans.get(), &response_text); | 3102 rv = ReadTransaction(trans.get(), &response_text); |
| 3104 EXPECT_EQ(OK, rv); | 3103 EXPECT_EQ(OK, rv); |
| 3105 EXPECT_EQ("Payload", response_text); | 3104 EXPECT_EQ("Payload", response_text); |
| 3106 } | 3105 } |
| 3107 | 3106 |
| 3108 TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { | 3107 TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
| 3109 SessionDependencies session_deps; | 3108 SessionDependencies session_deps( |
| 3110 session_deps.proxy_service.reset(CreateFixedProxyService( | 3109 CreateFixedProxyService("socks4://myproxy:1080")); |
| 3111 "socks4://myproxy:1080")); | |
| 3112 | 3110 |
| 3113 scoped_ptr<HttpTransaction> trans( | 3111 scoped_ptr<HttpTransaction> trans( |
| 3114 new HttpNetworkTransaction( | 3112 new HttpNetworkTransaction( |
| 3115 CreateSession(&session_deps), | 3113 CreateSession(&session_deps), |
| 3116 &session_deps.socket_factory)); | 3114 &session_deps.socket_factory)); |
| 3117 | 3115 |
| 3118 HttpRequestInfo request; | 3116 HttpRequestInfo request; |
| 3119 request.method = "GET"; | 3117 request.method = "GET"; |
| 3120 request.url = GURL("https://www.google.com/"); | 3118 request.url = GURL("https://www.google.com/"); |
| 3121 request.load_flags = 0; | 3119 request.load_flags = 0; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3157 const HttpResponseInfo* response = trans->GetResponseInfo(); | 3155 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3158 EXPECT_FALSE(response == NULL); | 3156 EXPECT_FALSE(response == NULL); |
| 3159 | 3157 |
| 3160 std::string response_text; | 3158 std::string response_text; |
| 3161 rv = ReadTransaction(trans.get(), &response_text); | 3159 rv = ReadTransaction(trans.get(), &response_text); |
| 3162 EXPECT_EQ(OK, rv); | 3160 EXPECT_EQ(OK, rv); |
| 3163 EXPECT_EQ("Payload", response_text); | 3161 EXPECT_EQ("Payload", response_text); |
| 3164 } | 3162 } |
| 3165 | 3163 |
| 3166 TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { | 3164 TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
| 3167 SessionDependencies session_deps; | 3165 SessionDependencies session_deps( |
| 3168 session_deps.proxy_service.reset(CreateFixedProxyService( | 3166 CreateFixedProxyService("socks5://myproxy:1080")); |
| 3169 "socks5://myproxy:1080")); | |
| 3170 | 3167 |
| 3171 scoped_ptr<HttpTransaction> trans( | 3168 scoped_ptr<HttpTransaction> trans( |
| 3172 new HttpNetworkTransaction( | 3169 new HttpNetworkTransaction( |
| 3173 CreateSession(&session_deps), | 3170 CreateSession(&session_deps), |
| 3174 &session_deps.socket_factory)); | 3171 &session_deps.socket_factory)); |
| 3175 | 3172 |
| 3176 HttpRequestInfo request; | 3173 HttpRequestInfo request; |
| 3177 request.method = "GET"; | 3174 request.method = "GET"; |
| 3178 request.url = GURL("http://www.google.com/"); | 3175 request.url = GURL("http://www.google.com/"); |
| 3179 request.load_flags = 0; | 3176 request.load_flags = 0; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3216 const HttpResponseInfo* response = trans->GetResponseInfo(); | 3213 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3217 EXPECT_FALSE(response == NULL); | 3214 EXPECT_FALSE(response == NULL); |
| 3218 | 3215 |
| 3219 std::string response_text; | 3216 std::string response_text; |
| 3220 rv = ReadTransaction(trans.get(), &response_text); | 3217 rv = ReadTransaction(trans.get(), &response_text); |
| 3221 EXPECT_EQ(OK, rv); | 3218 EXPECT_EQ(OK, rv); |
| 3222 EXPECT_EQ("Payload", response_text); | 3219 EXPECT_EQ("Payload", response_text); |
| 3223 } | 3220 } |
| 3224 | 3221 |
| 3225 TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { | 3222 TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
| 3226 SessionDependencies session_deps; | 3223 SessionDependencies session_deps( |
| 3227 session_deps.proxy_service.reset(CreateFixedProxyService( | 3224 CreateFixedProxyService("socks5://myproxy:1080")); |
| 3228 "socks5://myproxy:1080")); | |
| 3229 | 3225 |
| 3230 scoped_ptr<HttpTransaction> trans( | 3226 scoped_ptr<HttpTransaction> trans( |
| 3231 new HttpNetworkTransaction( | 3227 new HttpNetworkTransaction( |
| 3232 CreateSession(&session_deps), | 3228 CreateSession(&session_deps), |
| 3233 &session_deps.socket_factory)); | 3229 &session_deps.socket_factory)); |
| 3234 | 3230 |
| 3235 HttpRequestInfo request; | 3231 HttpRequestInfo request; |
| 3236 request.method = "GET"; | 3232 request.method = "GET"; |
| 3237 request.url = GURL("https://www.google.com/"); | 3233 request.url = GURL("https://www.google.com/"); |
| 3238 request.load_flags = 0; | 3234 request.load_flags = 0; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3320 "proxy/http_proxy:80/https://www.google.com/", | 3316 "proxy/http_proxy:80/https://www.google.com/", |
| 3321 }, | 3317 }, |
| 3322 { | 3318 { |
| 3323 "socks4://socks_proxy:1080", | 3319 "socks4://socks_proxy:1080", |
| 3324 "https://www.google.com/socks4_ssl", | 3320 "https://www.google.com/socks4_ssl", |
| 3325 "proxy/socks4://socks_proxy:1080/https://www.google.com/", | 3321 "proxy/socks4://socks_proxy:1080/https://www.google.com/", |
| 3326 }, | 3322 }, |
| 3327 }; | 3323 }; |
| 3328 | 3324 |
| 3329 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 3325 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
| 3330 SessionDependencies session_deps; | 3326 SessionDependencies session_deps( |
| 3331 session_deps.proxy_service.reset(CreateFixedProxyService( | 3327 CreateFixedProxyService(tests[i].proxy_server)); |
| 3332 tests[i].proxy_server)); | |
| 3333 | 3328 |
| 3334 scoped_refptr<CaptureGroupNameSocketPool> conn_pool( | 3329 scoped_refptr<CaptureGroupNameSocketPool> conn_pool( |
| 3335 new CaptureGroupNameSocketPool()); | 3330 new CaptureGroupNameSocketPool()); |
| 3336 | 3331 |
| 3337 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 3332 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 3338 session->connection_pool_ = conn_pool.get(); | 3333 session->connection_pool_ = conn_pool.get(); |
| 3339 | 3334 |
| 3340 scoped_ptr<HttpTransaction> trans( | 3335 scoped_ptr<HttpTransaction> trans( |
| 3341 new HttpNetworkTransaction( | 3336 new HttpNetworkTransaction( |
| 3342 session.get(), | 3337 session.get(), |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3574 // Extract the unescaped identity. | 3569 // Extract the unescaped identity. |
| 3575 std::wstring username, password; | 3570 std::wstring username, password; |
| 3576 HttpNetworkTransaction::GetIdentifyFromUrl(url, &username, &password); | 3571 HttpNetworkTransaction::GetIdentifyFromUrl(url, &username, &password); |
| 3577 | 3572 |
| 3578 // Verify that it was decoded as UTF8. | 3573 // Verify that it was decoded as UTF8. |
| 3579 EXPECT_EQ(L"foo", username); | 3574 EXPECT_EQ(L"foo", username); |
| 3580 EXPECT_EQ(L"\x4f60\x597d", password); | 3575 EXPECT_EQ(L"\x4f60\x597d", password); |
| 3581 } | 3576 } |
| 3582 | 3577 |
| 3583 } // namespace net | 3578 } // namespace net |
| OLD | NEW |