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/cert_verifier.h" |
11 #include "net/base/mock_host_resolver.h" | 11 #include "net/base/mock_host_resolver.h" |
12 #include "net/base/net_log.h" | 12 #include "net/base/net_log.h" |
13 #include "net/base/ssl_config_service_defaults.h" | 13 #include "net/base/ssl_config_service_defaults.h" |
14 #include "net/base/test_completion_callback.h" | 14 #include "net/base/test_completion_callback.h" |
15 #include "net/http/http_auth_handler_factory.h" | 15 #include "net/http/http_auth_handler_factory.h" |
16 #include "net/http/http_network_session.h" | 16 #include "net/http/http_network_session.h" |
17 #include "net/http/http_network_session_peer.h" | 17 #include "net/http/http_network_session_peer.h" |
18 #include "net/http/http_request_info.h" | 18 #include "net/http/http_request_info.h" |
19 #include "net/socket/socket_test_util.h" | 19 #include "net/socket/socket_test_util.h" |
| 20 #include "net/spdy/spdy_session.h" |
20 #include "net/spdy/spdy_session_pool.h" | 21 #include "net/spdy/spdy_session_pool.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
22 | 23 |
23 namespace net { | 24 namespace net { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
27 struct SessionDependencies { | 28 struct SessionDependencies { |
28 // Custom proxy service dependency. | 29 // Custom proxy service dependency. |
29 explicit SessionDependencies(ProxyService* proxy_service) | 30 explicit SessionDependencies(ProxyService* proxy_service) |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 typedef CapturePreconnectsSocketPool<HttpProxyClientSocketPool> | 157 typedef CapturePreconnectsSocketPool<HttpProxyClientSocketPool> |
157 CapturePreconnectsHttpProxySocketPool; | 158 CapturePreconnectsHttpProxySocketPool; |
158 typedef CapturePreconnectsSocketPool<SOCKSClientSocketPool> | 159 typedef CapturePreconnectsSocketPool<SOCKSClientSocketPool> |
159 CapturePreconnectsSOCKSSocketPool; | 160 CapturePreconnectsSOCKSSocketPool; |
160 typedef CapturePreconnectsSocketPool<SSLClientSocketPool> | 161 typedef CapturePreconnectsSocketPool<SSLClientSocketPool> |
161 CapturePreconnectsSSLSocketPool; | 162 CapturePreconnectsSSLSocketPool; |
162 | 163 |
163 template<typename ParentPool> | 164 template<typename ParentPool> |
164 CapturePreconnectsSocketPool<ParentPool>::CapturePreconnectsSocketPool( | 165 CapturePreconnectsSocketPool<ParentPool>::CapturePreconnectsSocketPool( |
165 HttpNetworkSession* session) | 166 HttpNetworkSession* session) |
166 : ParentPool(0, 0, NULL, session->host_resolver(), NULL, NULL) {} | 167 : ParentPool(0, 0, NULL, session->host_resolver(), NULL, NULL), |
| 168 last_num_streams_(-1) {} |
167 | 169 |
168 template<> | 170 template<> |
169 CapturePreconnectsHttpProxySocketPool::CapturePreconnectsSocketPool( | 171 CapturePreconnectsHttpProxySocketPool::CapturePreconnectsSocketPool( |
170 HttpNetworkSession* session) | 172 HttpNetworkSession* session) |
171 : HttpProxyClientSocketPool(0, 0, NULL, session->host_resolver(), NULL, | 173 : HttpProxyClientSocketPool(0, 0, NULL, session->host_resolver(), NULL, |
172 NULL, NULL) {} | 174 NULL, NULL), |
| 175 last_num_streams_(-1) {} |
173 | 176 |
174 template<> | 177 template<> |
175 CapturePreconnectsSSLSocketPool::CapturePreconnectsSocketPool( | 178 CapturePreconnectsSSLSocketPool::CapturePreconnectsSocketPool( |
176 HttpNetworkSession* session) | 179 HttpNetworkSession* session) |
177 : SSLClientSocketPool(0, 0, NULL, session->host_resolver(), | 180 : SSLClientSocketPool(0, 0, NULL, session->host_resolver(), |
178 session->cert_verifier(), NULL, NULL, | 181 session->cert_verifier(), NULL, NULL, |
179 NULL, NULL, NULL, NULL, NULL, NULL, NULL) {} | 182 NULL, NULL, NULL, NULL, NULL, NULL, NULL), |
| 183 last_num_streams_(-1) {} |
180 | 184 |
181 TEST(HttpStreamFactoryTest, PreconnectDirect) { | 185 TEST(HttpStreamFactoryTest, PreconnectDirect) { |
182 for (size_t i = 0; i < arraysize(kTests); ++i) { | 186 for (size_t i = 0; i < arraysize(kTests); ++i) { |
183 SessionDependencies session_deps(ProxyService::CreateDirect()); | 187 SessionDependencies session_deps(ProxyService::CreateDirect()); |
184 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 188 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
185 HttpNetworkSessionPeer peer(session); | 189 HttpNetworkSessionPeer peer(session); |
186 CapturePreconnectsTCPSocketPool* tcp_conn_pool = | 190 CapturePreconnectsTCPSocketPool* tcp_conn_pool = |
187 new CapturePreconnectsTCPSocketPool(session); | 191 new CapturePreconnectsTCPSocketPool(session); |
188 peer.SetTCPSocketPool(tcp_conn_pool); | 192 peer.SetTCPSocketPool(tcp_conn_pool); |
189 CapturePreconnectsSSLSocketPool* ssl_conn_pool = | 193 CapturePreconnectsSSLSocketPool* ssl_conn_pool = |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 new CapturePreconnectsSSLSocketPool(session); | 235 new CapturePreconnectsSSLSocketPool(session); |
232 peer.SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); | 236 peer.SetSocketPoolForSSLWithProxy(proxy_host, ssl_conn_pool); |
233 EXPECT_EQ(OK, PreconnectHelper(kTests[i], session)); | 237 EXPECT_EQ(OK, PreconnectHelper(kTests[i], session)); |
234 if (kTests[i].ssl) | 238 if (kTests[i].ssl) |
235 EXPECT_EQ(kTests[i].num_streams, ssl_conn_pool->last_num_streams()); | 239 EXPECT_EQ(kTests[i].num_streams, ssl_conn_pool->last_num_streams()); |
236 else | 240 else |
237 EXPECT_EQ(kTests[i].num_streams, socks_proxy_pool->last_num_streams()); | 241 EXPECT_EQ(kTests[i].num_streams, socks_proxy_pool->last_num_streams()); |
238 } | 242 } |
239 } | 243 } |
240 | 244 |
| 245 TEST(HttpStreamFactoryTest, PreconnectDirectWithExistingSpdySession) { |
| 246 for (size_t i = 0; i < arraysize(kTests); ++i) { |
| 247 SessionDependencies session_deps(ProxyService::CreateDirect()); |
| 248 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
| 249 HttpNetworkSessionPeer peer(session); |
| 250 |
| 251 // Set an existing SpdySession in the pool. |
| 252 HostPortPair host_port_pair("www.google.com", 443); |
| 253 HostPortProxyPair pair(host_port_pair, ProxyServer::Direct()); |
| 254 scoped_refptr<SpdySession> spdy_session = |
| 255 session->spdy_session_pool()->Get( |
| 256 pair, session->mutable_spdy_settings(), BoundNetLog()); |
| 257 |
| 258 CapturePreconnectsTCPSocketPool* tcp_conn_pool = |
| 259 new CapturePreconnectsTCPSocketPool(session); |
| 260 peer.SetTCPSocketPool(tcp_conn_pool); |
| 261 CapturePreconnectsSSLSocketPool* ssl_conn_pool = |
| 262 new CapturePreconnectsSSLSocketPool(session.get()); |
| 263 peer.SetSSLSocketPool(ssl_conn_pool); |
| 264 EXPECT_EQ(OK, PreconnectHelper(kTests[i], session)); |
| 265 // We shouldn't be preconnecting if we have an existing session, which is |
| 266 // the case for https://www.google.com. |
| 267 if (kTests[i].ssl) |
| 268 EXPECT_EQ(-1, ssl_conn_pool->last_num_streams()); |
| 269 else |
| 270 EXPECT_EQ(kTests[i].num_streams, tcp_conn_pool->last_num_streams()); |
| 271 } |
| 272 } |
| 273 |
241 } // namespace | 274 } // namespace |
242 | 275 |
243 } // namespace net | 276 } // namespace net |
OLD | NEW |