| 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 "net/http/http_stream_factory.h" | 5 #include "net/http/http_stream_factory.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "net/base/cert_verifier.h" |
| 10 #include "net/base/mock_host_resolver.h" | 11 #include "net/base/mock_host_resolver.h" |
| 11 #include "net/base/net_log.h" | 12 #include "net/base/net_log.h" |
| 12 #include "net/base/ssl_config_service_defaults.h" | 13 #include "net/base/ssl_config_service_defaults.h" |
| 13 #include "net/base/test_completion_callback.h" | 14 #include "net/base/test_completion_callback.h" |
| 14 #include "net/http/http_auth_handler_factory.h" | 15 #include "net/http/http_auth_handler_factory.h" |
| 15 #include "net/http/http_network_session.h" | 16 #include "net/http/http_network_session.h" |
| 16 #include "net/http/http_network_session_peer.h" | 17 #include "net/http/http_network_session_peer.h" |
| 17 #include "net/http/http_request_info.h" | 18 #include "net/http/http_request_info.h" |
| 18 #include "net/socket/socket_test_util.h" | 19 #include "net/socket/socket_test_util.h" |
| 19 #include "net/spdy/spdy_session_pool.h" | 20 #include "net/spdy/spdy_session_pool.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 namespace net { | 23 namespace net { |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 | 26 |
| 26 struct SessionDependencies { | 27 struct SessionDependencies { |
| 27 // Custom proxy service dependency. | 28 // Custom proxy service dependency. |
| 28 explicit SessionDependencies(ProxyService* proxy_service) | 29 explicit SessionDependencies(ProxyService* proxy_service) |
| 29 : host_resolver(new MockHostResolver), | 30 : host_resolver(new MockHostResolver), |
| 31 cert_verifier(new CertVerifier), |
| 30 proxy_service(proxy_service), | 32 proxy_service(proxy_service), |
| 31 ssl_config_service(new SSLConfigServiceDefaults), | 33 ssl_config_service(new SSLConfigServiceDefaults), |
| 32 http_auth_handler_factory( | 34 http_auth_handler_factory( |
| 33 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), | 35 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), |
| 34 net_log(NULL) {} | 36 net_log(NULL) {} |
| 35 | 37 |
| 36 scoped_ptr<MockHostResolverBase> host_resolver; | 38 scoped_ptr<MockHostResolverBase> host_resolver; |
| 39 scoped_ptr<CertVerifier> cert_verifier; |
| 37 scoped_refptr<ProxyService> proxy_service; | 40 scoped_refptr<ProxyService> proxy_service; |
| 38 scoped_refptr<SSLConfigService> ssl_config_service; | 41 scoped_refptr<SSLConfigService> ssl_config_service; |
| 39 MockClientSocketFactory socket_factory; | 42 MockClientSocketFactory socket_factory; |
| 40 scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; | 43 scoped_ptr<HttpAuthHandlerFactory> http_auth_handler_factory; |
| 41 NetLog* net_log; | 44 NetLog* net_log; |
| 42 }; | 45 }; |
| 43 | 46 |
| 44 HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { | 47 HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { |
| 45 return new HttpNetworkSession(session_deps->host_resolver.get(), | 48 return new HttpNetworkSession(session_deps->host_resolver.get(), |
| 49 session_deps->cert_verifier.get(), |
| 46 NULL /* dnsrr_resolver */, | 50 NULL /* dnsrr_resolver */, |
| 47 NULL /* dns_cert_checker */, | 51 NULL /* dns_cert_checker */, |
| 48 NULL /* ssl_host_info_factory */, | 52 NULL /* ssl_host_info_factory */, |
| 49 session_deps->proxy_service, | 53 session_deps->proxy_service, |
| 50 &session_deps->socket_factory, | 54 &session_deps->socket_factory, |
| 51 session_deps->ssl_config_service, | 55 session_deps->ssl_config_service, |
| 52 new SpdySessionPool(NULL), | 56 new SpdySessionPool(NULL), |
| 53 session_deps->http_auth_handler_factory.get(), | 57 session_deps->http_auth_handler_factory.get(), |
| 54 NULL, | 58 NULL, |
| 55 session_deps->net_log); | 59 session_deps->net_log); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 167 |
| 164 template<> | 168 template<> |
| 165 CapturePreconnectsHttpProxySocketPool::CapturePreconnectsSocketPool( | 169 CapturePreconnectsHttpProxySocketPool::CapturePreconnectsSocketPool( |
| 166 HttpNetworkSession* session) | 170 HttpNetworkSession* session) |
| 167 : HttpProxyClientSocketPool(0, 0, NULL, session->host_resolver(), NULL, | 171 : HttpProxyClientSocketPool(0, 0, NULL, session->host_resolver(), NULL, |
| 168 NULL, NULL) {} | 172 NULL, NULL) {} |
| 169 | 173 |
| 170 template<> | 174 template<> |
| 171 CapturePreconnectsSSLSocketPool::CapturePreconnectsSocketPool( | 175 CapturePreconnectsSSLSocketPool::CapturePreconnectsSocketPool( |
| 172 HttpNetworkSession* session) | 176 HttpNetworkSession* session) |
| 173 : SSLClientSocketPool(0, 0, NULL, session->host_resolver(), NULL, NULL, | 177 : SSLClientSocketPool(0, 0, NULL, session->host_resolver(), |
| 178 session->cert_verifier(), NULL, NULL, |
| 174 NULL, NULL, NULL, NULL, NULL, NULL, NULL) {} | 179 NULL, NULL, NULL, NULL, NULL, NULL, NULL) {} |
| 175 | 180 |
| 176 TEST(HttpStreamFactoryTest, PreconnectDirect) { | 181 TEST(HttpStreamFactoryTest, PreconnectDirect) { |
| 177 for (size_t i = 0; i < arraysize(kTests); ++i) { | 182 for (size_t i = 0; i < arraysize(kTests); ++i) { |
| 178 SessionDependencies session_deps(ProxyService::CreateDirect()); | 183 SessionDependencies session_deps(ProxyService::CreateDirect()); |
| 179 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 184 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 180 HttpNetworkSessionPeer peer(session); | 185 HttpNetworkSessionPeer peer(session); |
| 181 CapturePreconnectsTCPSocketPool* tcp_conn_pool = | 186 CapturePreconnectsTCPSocketPool* tcp_conn_pool = |
| 182 new CapturePreconnectsTCPSocketPool(session); | 187 new CapturePreconnectsTCPSocketPool(session); |
| 183 peer.SetTCPSocketPool(tcp_conn_pool); | 188 peer.SetTCPSocketPool(tcp_conn_pool); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 if (kTests[i].ssl) | 234 if (kTests[i].ssl) |
| 230 EXPECT_EQ(kTests[i].num_streams, ssl_conn_pool->last_num_streams()); | 235 EXPECT_EQ(kTests[i].num_streams, ssl_conn_pool->last_num_streams()); |
| 231 else | 236 else |
| 232 EXPECT_EQ(kTests[i].num_streams, socks_proxy_pool->last_num_streams()); | 237 EXPECT_EQ(kTests[i].num_streams, socks_proxy_pool->last_num_streams()); |
| 233 } | 238 } |
| 234 } | 239 } |
| 235 | 240 |
| 236 } // namespace | 241 } // namespace |
| 237 | 242 |
| 238 } // namespace net | 243 } // namespace net |
| OLD | NEW |