OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 | 36 |
37 // Helper to manage the lifetimes of the dependencies for a | 37 // Helper to manage the lifetimes of the dependencies for a |
38 // HttpNetworkTransaction. | 38 // HttpNetworkTransaction. |
39 class SessionDependencies { | 39 class SessionDependencies { |
40 public: | 40 public: |
41 // Default set of dependencies -- "null" proxy service. | 41 // Default set of dependencies -- "null" proxy service. |
42 SessionDependencies() | 42 SessionDependencies() |
43 : host_resolver(new MockHostResolver), | 43 : host_resolver(new MockHostResolver), |
44 proxy_service(ProxyService::CreateNull()), | 44 proxy_service(ProxyService::CreateNull()), |
45 ssl_config_service(new SSLConfigServiceDefaults), | 45 ssl_config_service(new SSLConfigServiceDefaults), |
46 http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), | 46 http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()) {} |
47 spdy_session_pool(new SpdySessionPool) {} | |
48 | 47 |
49 // Custom proxy service dependency. | 48 // Custom proxy service dependency. |
50 explicit SessionDependencies(ProxyService* proxy_service) | 49 explicit SessionDependencies(ProxyService* proxy_service) |
51 : host_resolver(new MockHostResolver), | 50 : host_resolver(new MockHostResolver), |
52 proxy_service(proxy_service), | 51 proxy_service(proxy_service), |
53 ssl_config_service(new SSLConfigServiceDefaults), | 52 ssl_config_service(new SSLConfigServiceDefaults), |
54 http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), | 53 http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()) {} |
55 spdy_session_pool(new SpdySessionPool) {} | |
56 | 54 |
57 scoped_refptr<MockHostResolverBase> host_resolver; | 55 scoped_refptr<MockHostResolverBase> host_resolver; |
58 scoped_refptr<ProxyService> proxy_service; | 56 scoped_refptr<ProxyService> proxy_service; |
59 scoped_refptr<SSLConfigService> ssl_config_service; | 57 scoped_refptr<SSLConfigService> ssl_config_service; |
60 MockClientSocketFactory socket_factory; | 58 MockClientSocketFactory socket_factory; |
61 scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; | 59 scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; |
62 scoped_refptr<SpdySessionPool> spdy_session_pool; | |
63 }; | 60 }; |
64 | 61 |
65 ProxyService* CreateFixedProxyService(const std::string& proxy) { | 62 ProxyService* CreateFixedProxyService(const std::string& proxy) { |
66 net::ProxyConfig proxy_config; | 63 net::ProxyConfig proxy_config; |
67 proxy_config.proxy_rules().ParseFromString(proxy); | 64 proxy_config.proxy_rules().ParseFromString(proxy); |
68 return ProxyService::CreateFixed(proxy_config); | 65 return ProxyService::CreateFixed(proxy_config); |
69 } | 66 } |
70 | 67 |
71 | 68 |
72 HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { | 69 HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { |
73 return new HttpNetworkSession(NULL, | 70 return new HttpNetworkSession(NULL, |
74 session_deps->host_resolver, | 71 session_deps->host_resolver, |
75 session_deps->proxy_service, | 72 session_deps->proxy_service, |
76 &session_deps->socket_factory, | 73 &session_deps->socket_factory, |
77 session_deps->ssl_config_service, | 74 session_deps->ssl_config_service, |
78 session_deps->spdy_session_pool, | |
79 session_deps->http_auth_handler_factory.get()); | 75 session_deps->http_auth_handler_factory.get()); |
80 } | 76 } |
81 | 77 |
82 class HttpNetworkTransactionTest : public PlatformTest { | 78 class HttpNetworkTransactionTest : public PlatformTest { |
83 public: | 79 public: |
84 virtual void TearDown() { | 80 virtual void TearDown() { |
85 // Empty the current queue. | 81 // Empty the current queue. |
86 MessageLoop::current()->RunAllPending(); | 82 MessageLoop::current()->RunAllPending(); |
87 PlatformTest::TearDown(); | 83 PlatformTest::TearDown(); |
88 } | 84 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 std::string MockGetHostName() { | 178 std::string MockGetHostName() { |
183 return "WTC-WIN7"; | 179 return "WTC-WIN7"; |
184 } | 180 } |
185 | 181 |
186 template<typename EmulatedClientSocketPool, typename SocketSourceType> | 182 template<typename EmulatedClientSocketPool, typename SocketSourceType> |
187 class CaptureGroupNameSocketPool : public EmulatedClientSocketPool { | 183 class CaptureGroupNameSocketPool : public EmulatedClientSocketPool { |
188 public: | 184 public: |
189 CaptureGroupNameSocketPool(HttpNetworkSession* session, | 185 CaptureGroupNameSocketPool(HttpNetworkSession* session, |
190 SocketSourceType* socket_source) | 186 SocketSourceType* socket_source) |
191 : EmulatedClientSocketPool(0, 0, "CaptureGroupNameTestPool", | 187 : EmulatedClientSocketPool(0, 0, "CaptureGroupNameTestPool", |
192 session->host_resolver(), socket_source, | 188 session->host_resolver(), socket_source) {} |
193 NULL) {} | |
194 const std::string last_group_name_received() const { | 189 const std::string last_group_name_received() const { |
195 return last_group_name_; | 190 return last_group_name_; |
196 } | 191 } |
197 | 192 |
198 virtual int RequestSocket(const std::string& group_name, | 193 virtual int RequestSocket(const std::string& group_name, |
199 const void* socket_params, | 194 const void* socket_params, |
200 RequestPriority priority, | 195 RequestPriority priority, |
201 ClientSocketHandle* handle, | 196 ClientSocketHandle* handle, |
202 CompletionCallback* callback, | 197 CompletionCallback* callback, |
203 const BoundNetLog& net_log) { | 198 const BoundNetLog& net_log) { |
(...skipping 4474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4678 ASSERT_TRUE(response != NULL); | 4673 ASSERT_TRUE(response != NULL); |
4679 ASSERT_TRUE(response->headers != NULL); | 4674 ASSERT_TRUE(response->headers != NULL); |
4680 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 4675 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
4681 | 4676 |
4682 std::string response_data; | 4677 std::string response_data; |
4683 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 4678 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
4684 EXPECT_EQ("hello world", response_data); | 4679 EXPECT_EQ("hello world", response_data); |
4685 } | 4680 } |
4686 | 4681 |
4687 } // namespace net | 4682 } // namespace net |
OLD | NEW |