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/run_loop.h" |
9 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
12 #include "net/base/auth.h" | 13 #include "net/base/auth.h" |
13 #include "net/base/load_timing_info.h" | 14 #include "net/base/load_timing_info.h" |
14 #include "net/base/load_timing_info_test_util.h" | 15 #include "net/base/load_timing_info_test_util.h" |
15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
16 #include "net/base/test_completion_callback.h" | 17 #include "net/base/test_completion_callback.h" |
17 #include "net/cert/cert_verifier.h" | 18 #include "net/cert/cert_verifier.h" |
18 #include "net/dns/mock_host_resolver.h" | 19 #include "net/dns/mock_host_resolver.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 scoped_ptr<ClientSocketPoolHistograms> ssl_histograms_; | 223 scoped_ptr<ClientSocketPoolHistograms> ssl_histograms_; |
223 scoped_ptr<SSLClientSocketPool> pool_; | 224 scoped_ptr<SSLClientSocketPool> pool_; |
224 }; | 225 }; |
225 | 226 |
226 INSTANTIATE_TEST_CASE_P( | 227 INSTANTIATE_TEST_CASE_P( |
227 NextProto, | 228 NextProto, |
228 SSLClientSocketPoolTest, | 229 SSLClientSocketPoolTest, |
229 testing::Values(kProtoDeprecatedSPDY2, | 230 testing::Values(kProtoDeprecatedSPDY2, |
230 kProtoSPDY3, kProtoSPDY31, kProtoSPDY4)); | 231 kProtoSPDY3, kProtoSPDY31, kProtoSPDY4)); |
231 | 232 |
| 233 // Make sure that sockets still connect after the leader socket's |
| 234 // connection fails. |
| 235 TEST_P(SSLClientSocketPoolTest, SimultaneousConnectJobsFail) { |
| 236 SSLClientSocketPool::set_enable_connect_job_waiting(true); |
| 237 |
| 238 StaticSocketDataProvider data1; |
| 239 StaticSocketDataProvider data2; |
| 240 StaticSocketDataProvider data3; |
| 241 StaticSocketDataProvider data4; |
| 242 StaticSocketDataProvider data5; |
| 243 socket_factory_.AddSocketDataProvider(&data1); |
| 244 socket_factory_.AddSocketDataProvider(&data2); |
| 245 socket_factory_.AddSocketDataProvider(&data3); |
| 246 socket_factory_.AddSocketDataProvider(&data4); |
| 247 socket_factory_.AddSocketDataProvider(&data5); |
| 248 SSLSocketDataProvider ssl(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
| 249 ssl.is_in_session_cache = false; |
| 250 ssl.should_block_in_connect = true; |
| 251 SSLSocketDataProvider ssl2(ASYNC, OK); |
| 252 ssl2.is_in_session_cache = false; |
| 253 ssl2.should_block_in_connect = true; |
| 254 SSLSocketDataProvider ssl3(ASYNC, OK); |
| 255 ssl3.is_in_session_cache = false; |
| 256 SSLSocketDataProvider ssl4(ASYNC, OK); |
| 257 ssl4.is_in_session_cache = false; |
| 258 SSLSocketDataProvider ssl5(ASYNC, OK); |
| 259 ssl5.is_in_session_cache = false; |
| 260 |
| 261 socket_factory_.AddSSLSocketDataProvider(&ssl); |
| 262 socket_factory_.AddSSLSocketDataProvider(&ssl2); |
| 263 socket_factory_.AddSSLSocketDataProvider(&ssl3); |
| 264 socket_factory_.AddSSLSocketDataProvider(&ssl4); |
| 265 socket_factory_.AddSSLSocketDataProvider(&ssl5); |
| 266 |
| 267 CreatePool(true, false, false); |
| 268 scoped_refptr<SSLSocketParams> params1 = |
| 269 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 270 scoped_refptr<SSLSocketParams> params2 = |
| 271 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 272 scoped_refptr<SSLSocketParams> params3 = |
| 273 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 274 scoped_refptr<SSLSocketParams> params4 = |
| 275 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 276 ClientSocketHandle handle1; |
| 277 ClientSocketHandle handle2; |
| 278 ClientSocketHandle handle3; |
| 279 ClientSocketHandle handle4; |
| 280 TestCompletionCallback callback1; |
| 281 TestCompletionCallback callback2; |
| 282 TestCompletionCallback callback3; |
| 283 TestCompletionCallback callback4; |
| 284 handle1.Init( |
| 285 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); |
| 286 handle2.Init( |
| 287 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); |
| 288 handle3.Init( |
| 289 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); |
| 290 handle4.Init( |
| 291 "b", params4, MEDIUM, callback4.callback(), pool_.get(), BoundNetLog()); |
| 292 |
| 293 base::RunLoop().RunUntilIdle(); |
| 294 |
| 295 std::vector<MockSSLClientSocket*> sockets = |
| 296 socket_factory_.ssl_client_sockets(); |
| 297 |
| 298 // The first socket's connection should have failed, and no other sockets |
| 299 // should have connected yet. |
| 300 for (std::vector<MockSSLClientSocket*>::iterator it = sockets.begin(); |
| 301 it != sockets.end(); |
| 302 ++it) { |
| 303 EXPECT_FALSE((*it)->IsConnected()); |
| 304 } |
| 305 |
| 306 // Allow the first socket to resume it's connection process. |
| 307 sockets[0]->RestartPausedConnect(); |
| 308 |
| 309 base::RunLoop().RunUntilIdle(); |
| 310 |
| 311 // The second socket should have connected. |
| 312 EXPECT_TRUE(sockets[1]->IsConnected()); |
| 313 |
| 314 // Allow the second socket to continue its connection. |
| 315 sockets[1]->RestartPausedConnect(); |
| 316 |
| 317 callback4.WaitForResult(); |
| 318 |
| 319 // Pending connections should ultimately succeed. |
| 320 for (std::vector<MockSSLClientSocket*>::iterator it = ++sockets.begin(); |
| 321 it != sockets.end(); |
| 322 ++it) { |
| 323 EXPECT_TRUE((*it)->IsConnected()); |
| 324 } |
| 325 } |
| 326 |
| 327 // Make sure that no sockets connect before the "leader" socket, |
| 328 // given that the leader has a successful connection. |
| 329 TEST_P(SSLClientSocketPoolTest, SimultaneousConnectJobsSuccess) { |
| 330 SSLClientSocketPool::set_enable_connect_job_waiting(true); |
| 331 |
| 332 StaticSocketDataProvider data1; |
| 333 StaticSocketDataProvider data2; |
| 334 StaticSocketDataProvider data3; |
| 335 socket_factory_.AddSocketDataProvider(&data1); |
| 336 socket_factory_.AddSocketDataProvider(&data2); |
| 337 socket_factory_.AddSocketDataProvider(&data3); |
| 338 |
| 339 SSLSocketDataProvider ssl(ASYNC, OK); |
| 340 ssl.is_in_session_cache = false; |
| 341 ssl.should_block_in_connect = true; |
| 342 SSLSocketDataProvider ssl2(ASYNC, OK); |
| 343 ssl2.is_in_session_cache = false; |
| 344 SSLSocketDataProvider ssl3(ASYNC, OK); |
| 345 ssl3.is_in_session_cache = false; |
| 346 socket_factory_.AddSSLSocketDataProvider(&ssl); |
| 347 socket_factory_.AddSSLSocketDataProvider(&ssl2); |
| 348 socket_factory_.AddSSLSocketDataProvider(&ssl3); |
| 349 |
| 350 CreatePool(true, false, false); |
| 351 |
| 352 scoped_refptr<SSLSocketParams> params1 = |
| 353 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 354 scoped_refptr<SSLSocketParams> params2 = |
| 355 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 356 scoped_refptr<SSLSocketParams> params3 = |
| 357 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 358 ClientSocketHandle handle1; |
| 359 ClientSocketHandle handle2; |
| 360 ClientSocketHandle handle3; |
| 361 TestCompletionCallback callback1; |
| 362 TestCompletionCallback callback2; |
| 363 TestCompletionCallback callback3; |
| 364 |
| 365 handle1.Init( |
| 366 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); |
| 367 handle2.Init( |
| 368 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); |
| 369 handle3.Init( |
| 370 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); |
| 371 |
| 372 // Allow the connections to proceed until the first socket has finished |
| 373 // connecting. |
| 374 base::RunLoop().RunUntilIdle(); |
| 375 |
| 376 std::vector<MockSSLClientSocket*> sockets = |
| 377 socket_factory_.ssl_client_sockets(); |
| 378 |
| 379 EXPECT_TRUE(sockets[0]->IsConnected()); |
| 380 for (std::vector<MockSSLClientSocket*>::iterator it = ++sockets.begin(); |
| 381 it != sockets.end(); |
| 382 ++it) { |
| 383 EXPECT_FALSE((*it)->IsConnected()); |
| 384 } |
| 385 |
| 386 sockets[0]->RestartPausedConnect(); |
| 387 |
| 388 callback3.WaitForResult(); |
| 389 |
| 390 EXPECT_TRUE(handle1.socket()->IsConnected()); |
| 391 EXPECT_TRUE(handle2.socket()->IsConnected()); |
| 392 EXPECT_TRUE(handle3.socket()->IsConnected()); |
| 393 } |
| 394 |
232 TEST_P(SSLClientSocketPoolTest, TCPFail) { | 395 TEST_P(SSLClientSocketPoolTest, TCPFail) { |
233 StaticSocketDataProvider data; | 396 StaticSocketDataProvider data; |
234 data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_CONNECTION_FAILED)); | 397 data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_CONNECTION_FAILED)); |
235 socket_factory_.AddSocketDataProvider(&data); | 398 socket_factory_.AddSocketDataProvider(&data); |
236 | 399 |
237 CreatePool(true /* tcp pool */, false, false); | 400 CreatePool(true /* tcp pool */, false, false); |
238 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, | 401 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, |
239 false); | 402 false); |
240 | 403 |
241 ClientSocketHandle handle; | 404 ClientSocketHandle handle; |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 ssl.channel_id_sent = true; | 1092 ssl.channel_id_sent = true; |
930 ssl.SetNextProto(GetParam()); | 1093 ssl.SetNextProto(GetParam()); |
931 TestIPPoolingDisabled(&ssl); | 1094 TestIPPoolingDisabled(&ssl); |
932 } | 1095 } |
933 | 1096 |
934 // It would be nice to also test the timeouts in SSLClientSocketPool. | 1097 // It would be nice to also test the timeouts in SSLClientSocketPool. |
935 | 1098 |
936 } // namespace | 1099 } // namespace |
937 | 1100 |
938 } // namespace net | 1101 } // namespace net |
OLD | NEW |