Chromium Code Reviews| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 session_->http_auth_handler_factory(), | 118 session_->http_auth_handler_factory(), |
| 118 session_->spdy_session_pool(), | 119 session_->spdy_session_pool(), |
| 119 true)), | 120 true)), |
| 120 http_proxy_histograms_("MockHttpProxy"), | 121 http_proxy_histograms_("MockHttpProxy"), |
| 121 http_proxy_socket_pool_(kMaxSockets, | 122 http_proxy_socket_pool_(kMaxSockets, |
| 122 kMaxSocketsPerGroup, | 123 kMaxSocketsPerGroup, |
| 123 &http_proxy_histograms_, | 124 &http_proxy_histograms_, |
| 124 &host_resolver_, | 125 &host_resolver_, |
| 125 &transport_socket_pool_, | 126 &transport_socket_pool_, |
| 126 NULL, | 127 NULL, |
| 127 NULL) { | 128 NULL), |
| 129 enable_ssl_connect_job_waiting_(false) { | |
| 128 scoped_refptr<SSLConfigService> ssl_config_service( | 130 scoped_refptr<SSLConfigService> ssl_config_service( |
| 129 new SSLConfigServiceDefaults); | 131 new SSLConfigServiceDefaults); |
| 130 ssl_config_service->GetSSLConfig(&ssl_config_); | 132 ssl_config_service->GetSSLConfig(&ssl_config_); |
| 131 } | 133 } |
| 132 | 134 |
| 133 void CreatePool(bool transport_pool, bool http_proxy_pool, bool socks_pool) { | 135 void CreatePool(bool transport_pool, bool http_proxy_pool, bool socks_pool) { |
| 134 ssl_histograms_.reset(new ClientSocketPoolHistograms("SSLUnitTest")); | 136 ssl_histograms_.reset(new ClientSocketPoolHistograms("SSLUnitTest")); |
| 135 pool_.reset(new SSLClientSocketPool( | 137 pool_.reset(new SSLClientSocketPool( |
| 136 kMaxSockets, | 138 kMaxSockets, |
| 137 kMaxSocketsPerGroup, | 139 kMaxSocketsPerGroup, |
| 138 ssl_histograms_.get(), | 140 ssl_histograms_.get(), |
| 139 NULL /* host_resolver */, | 141 NULL /* host_resolver */, |
| 140 NULL /* cert_verifier */, | 142 NULL /* cert_verifier */, |
| 141 NULL /* server_bound_cert_service */, | 143 NULL /* server_bound_cert_service */, |
| 142 NULL /* transport_security_state */, | 144 NULL /* transport_security_state */, |
| 143 NULL /* cert_transparency_verifier */, | 145 NULL /* cert_transparency_verifier */, |
| 144 std::string() /* ssl_session_cache_shard */, | 146 std::string() /* ssl_session_cache_shard */, |
| 145 &socket_factory_, | 147 &socket_factory_, |
| 146 transport_pool ? &transport_socket_pool_ : NULL, | 148 transport_pool ? &transport_socket_pool_ : NULL, |
| 147 socks_pool ? &socks_socket_pool_ : NULL, | 149 socks_pool ? &socks_socket_pool_ : NULL, |
| 148 http_proxy_pool ? &http_proxy_socket_pool_ : NULL, | 150 http_proxy_pool ? &http_proxy_socket_pool_ : NULL, |
| 149 NULL, | 151 NULL, |
| 152 enable_ssl_connect_job_waiting_, | |
| 150 NULL)); | 153 NULL)); |
| 151 } | 154 } |
| 152 | 155 |
| 153 scoped_refptr<SSLSocketParams> SSLParams(ProxyServer::Scheme proxy, | 156 scoped_refptr<SSLSocketParams> SSLParams(ProxyServer::Scheme proxy, |
| 154 bool want_spdy_over_npn) { | 157 bool want_spdy_over_npn) { |
| 155 return make_scoped_refptr(new SSLSocketParams( | 158 return make_scoped_refptr(new SSLSocketParams( |
| 156 proxy == ProxyServer::SCHEME_DIRECT ? direct_transport_socket_params_ | 159 proxy == ProxyServer::SCHEME_DIRECT ? direct_transport_socket_params_ |
| 157 : NULL, | 160 : NULL, |
| 158 proxy == ProxyServer::SCHEME_SOCKS5 ? socks_socket_params_ : NULL, | 161 proxy == ProxyServer::SCHEME_SOCKS5 ? socks_socket_params_ : NULL, |
| 159 proxy == ProxyServer::SCHEME_HTTP ? http_proxy_socket_params_ : NULL, | 162 proxy == ProxyServer::SCHEME_HTTP ? http_proxy_socket_params_ : NULL, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 ClientSocketPoolHistograms socks_histograms_; | 217 ClientSocketPoolHistograms socks_histograms_; |
| 215 MockSOCKSClientSocketPool socks_socket_pool_; | 218 MockSOCKSClientSocketPool socks_socket_pool_; |
| 216 | 219 |
| 217 scoped_refptr<HttpProxySocketParams> http_proxy_socket_params_; | 220 scoped_refptr<HttpProxySocketParams> http_proxy_socket_params_; |
| 218 ClientSocketPoolHistograms http_proxy_histograms_; | 221 ClientSocketPoolHistograms http_proxy_histograms_; |
| 219 HttpProxyClientSocketPool http_proxy_socket_pool_; | 222 HttpProxyClientSocketPool http_proxy_socket_pool_; |
| 220 | 223 |
| 221 SSLConfig ssl_config_; | 224 SSLConfig ssl_config_; |
| 222 scoped_ptr<ClientSocketPoolHistograms> ssl_histograms_; | 225 scoped_ptr<ClientSocketPoolHistograms> ssl_histograms_; |
| 223 scoped_ptr<SSLClientSocketPool> pool_; | 226 scoped_ptr<SSLClientSocketPool> pool_; |
| 227 | |
| 228 bool enable_ssl_connect_job_waiting_; | |
| 224 }; | 229 }; |
| 225 | 230 |
| 226 INSTANTIATE_TEST_CASE_P( | 231 INSTANTIATE_TEST_CASE_P( |
| 227 NextProto, | 232 NextProto, |
| 228 SSLClientSocketPoolTest, | 233 SSLClientSocketPoolTest, |
| 229 testing::Values(kProtoDeprecatedSPDY2, | 234 testing::Values(kProtoDeprecatedSPDY2, |
| 230 kProtoSPDY3, kProtoSPDY31, kProtoSPDY4)); | 235 kProtoSPDY3, kProtoSPDY31, kProtoSPDY4)); |
| 231 | 236 |
| 237 // Tests that the final socket will connect even if all sockets | |
| 238 // prior to it fail. | |
| 239 // | |
| 240 // All sockets should wait for the first socket to attempt to | |
| 241 // connect. Once it fails to connect, all other sockets should | |
| 242 // attempt to connect. All should fail, except the final socket. | |
| 243 TEST_P(SSLClientSocketPoolTest, AllSocketsFailButLast) { | |
| 244 #if !defined(USE_OPENSSL) | |
|
Ryan Sleevi
2014/07/29 23:19:22
There are several ways to do this
#if defined(USE
mshelley
2014/07/30 18:33:55
As we discussed yesterday, this check isn't actual
| |
| 245 return; | |
| 246 #endif | |
| 247 // Although we request four sockets, the first three socket connect | |
| 248 // failures cause the socket pool to create three more sockets because | |
| 249 // there are pending requests. | |
| 250 StaticSocketDataProvider data1; | |
| 251 StaticSocketDataProvider data2; | |
| 252 StaticSocketDataProvider data3; | |
| 253 StaticSocketDataProvider data4; | |
| 254 StaticSocketDataProvider data5; | |
| 255 StaticSocketDataProvider data6; | |
| 256 StaticSocketDataProvider data7; | |
| 257 socket_factory_.AddSocketDataProvider(&data1); | |
| 258 socket_factory_.AddSocketDataProvider(&data2); | |
| 259 socket_factory_.AddSocketDataProvider(&data3); | |
| 260 socket_factory_.AddSocketDataProvider(&data4); | |
| 261 socket_factory_.AddSocketDataProvider(&data5); | |
| 262 socket_factory_.AddSocketDataProvider(&data6); | |
| 263 socket_factory_.AddSocketDataProvider(&data7); | |
| 264 SSLSocketDataProvider ssl(ASYNC, ERR_SSL_PROTOCOL_ERROR); | |
| 265 ssl.is_in_session_cache = false; | |
| 266 SSLSocketDataProvider ssl2(ASYNC, ERR_SSL_PROTOCOL_ERROR); | |
| 267 ssl2.is_in_session_cache = false; | |
| 268 SSLSocketDataProvider ssl3(ASYNC, ERR_SSL_PROTOCOL_ERROR); | |
| 269 ssl3.is_in_session_cache = false; | |
| 270 SSLSocketDataProvider ssl4(ASYNC, OK); | |
| 271 ssl4.is_in_session_cache = false; | |
| 272 SSLSocketDataProvider ssl5(ASYNC, OK); | |
| 273 ssl5.is_in_session_cache = false; | |
| 274 SSLSocketDataProvider ssl6(ASYNC, OK); | |
| 275 ssl6.is_in_session_cache = false; | |
| 276 SSLSocketDataProvider ssl7(ASYNC, OK); | |
| 277 ssl7.is_in_session_cache = false; | |
| 278 | |
| 279 socket_factory_.AddSSLSocketDataProvider(&ssl); | |
| 280 socket_factory_.AddSSLSocketDataProvider(&ssl2); | |
| 281 socket_factory_.AddSSLSocketDataProvider(&ssl3); | |
| 282 socket_factory_.AddSSLSocketDataProvider(&ssl4); | |
| 283 socket_factory_.AddSSLSocketDataProvider(&ssl5); | |
| 284 socket_factory_.AddSSLSocketDataProvider(&ssl6); | |
| 285 socket_factory_.AddSSLSocketDataProvider(&ssl7); | |
| 286 | |
| 287 enable_ssl_connect_job_waiting_ = true; | |
| 288 CreatePool(true, false, false); | |
| 289 | |
| 290 scoped_refptr<SSLSocketParams> params1 = | |
| 291 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 292 scoped_refptr<SSLSocketParams> params2 = | |
| 293 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 294 scoped_refptr<SSLSocketParams> params3 = | |
| 295 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 296 scoped_refptr<SSLSocketParams> params4 = | |
| 297 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 298 ClientSocketHandle handle1; | |
| 299 ClientSocketHandle handle2; | |
| 300 ClientSocketHandle handle3; | |
| 301 ClientSocketHandle handle4; | |
| 302 TestCompletionCallback callback1; | |
| 303 TestCompletionCallback callback2; | |
| 304 TestCompletionCallback callback3; | |
| 305 TestCompletionCallback callback4; | |
| 306 | |
| 307 handle1.Init( | |
| 308 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); | |
| 309 handle2.Init( | |
| 310 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); | |
| 311 handle3.Init( | |
| 312 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); | |
| 313 handle4.Init( | |
| 314 "b", params4, MEDIUM, callback4.callback(), pool_.get(), BoundNetLog()); | |
| 315 | |
| 316 base::RunLoop().RunUntilIdle(); | |
| 317 | |
| 318 // Only the last socket should have connected. | |
| 319 EXPECT_FALSE(handle1.socket()); | |
| 320 EXPECT_FALSE(handle2.socket()); | |
| 321 EXPECT_FALSE(handle3.socket()); | |
| 322 EXPECT_TRUE(handle4.socket()->IsConnected()); | |
| 323 } | |
| 324 | |
| 325 // Tests that sockets will still connect in parallel if the | |
| 326 // EnableSSLConnectJobWaiting flag is not enabled. | |
| 327 TEST_P(SSLClientSocketPoolTest, SocketsConnectWithoutFlag) { | |
| 328 StaticSocketDataProvider data1; | |
| 329 StaticSocketDataProvider data2; | |
| 330 StaticSocketDataProvider data3; | |
| 331 socket_factory_.AddSocketDataProvider(&data1); | |
| 332 socket_factory_.AddSocketDataProvider(&data2); | |
| 333 socket_factory_.AddSocketDataProvider(&data3); | |
| 334 | |
| 335 SSLSocketDataProvider ssl(ASYNC, OK); | |
| 336 ssl.is_in_session_cache = false; | |
| 337 ssl.should_block_on_connect = true; | |
| 338 SSLSocketDataProvider ssl2(ASYNC, OK); | |
| 339 ssl2.is_in_session_cache = false; | |
| 340 ssl2.should_block_on_connect = true; | |
| 341 SSLSocketDataProvider ssl3(ASYNC, OK); | |
| 342 ssl3.is_in_session_cache = false; | |
| 343 ssl3.should_block_on_connect = true; | |
| 344 socket_factory_.AddSSLSocketDataProvider(&ssl); | |
| 345 socket_factory_.AddSSLSocketDataProvider(&ssl2); | |
| 346 socket_factory_.AddSSLSocketDataProvider(&ssl3); | |
| 347 | |
| 348 CreatePool(true, false, false); | |
| 349 | |
| 350 scoped_refptr<SSLSocketParams> params1 = | |
| 351 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 352 scoped_refptr<SSLSocketParams> params2 = | |
| 353 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 354 scoped_refptr<SSLSocketParams> params3 = | |
| 355 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 356 ClientSocketHandle handle1; | |
| 357 ClientSocketHandle handle2; | |
| 358 ClientSocketHandle handle3; | |
| 359 TestCompletionCallback callback1; | |
| 360 TestCompletionCallback callback2; | |
| 361 TestCompletionCallback callback3; | |
| 362 | |
| 363 handle1.Init( | |
| 364 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); | |
| 365 handle2.Init( | |
| 366 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); | |
| 367 handle3.Init( | |
| 368 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); | |
| 369 | |
| 370 base::RunLoop().RunUntilIdle(); | |
| 371 | |
| 372 std::vector<MockSSLClientSocket*> sockets = | |
| 373 socket_factory_.ssl_client_sockets(); | |
| 374 | |
| 375 // All sockets should have started their connections. | |
| 376 for (std::vector<MockSSLClientSocket*>::iterator it = sockets.begin(); | |
| 377 it != sockets.end(); | |
| 378 ++it) { | |
| 379 EXPECT_TRUE((*it)->IsConnected()); | |
| 380 } | |
| 381 | |
| 382 // Resume connecting all of the sockets. | |
| 383 for (std::vector<MockSSLClientSocket*>::iterator it = sockets.begin(); | |
| 384 it != sockets.end(); | |
| 385 ++it) { | |
| 386 (*it)->RestartPausedConnect(); | |
| 387 } | |
| 388 | |
| 389 callback1.WaitForResult(); | |
| 390 callback2.WaitForResult(); | |
| 391 callback3.WaitForResult(); | |
| 392 | |
| 393 EXPECT_TRUE(handle1.socket()->IsConnected()); | |
| 394 EXPECT_TRUE(handle2.socket()->IsConnected()); | |
| 395 EXPECT_TRUE(handle3.socket()->IsConnected()); | |
| 396 } | |
| 397 | |
| 398 // Tests that the pool deleting an SSLConnectJob will not cause a crash, | |
| 399 // or prevent pending sockets from connecting. | |
| 400 TEST_P(SSLClientSocketPoolTest, DeletedSSLConnectJob) { | |
| 401 #if !defined(USE_OPENSSL) | |
| 402 return; | |
| 403 #endif | |
| 404 StaticSocketDataProvider data1; | |
| 405 StaticSocketDataProvider data2; | |
| 406 StaticSocketDataProvider data3; | |
| 407 socket_factory_.AddSocketDataProvider(&data1); | |
| 408 socket_factory_.AddSocketDataProvider(&data2); | |
| 409 socket_factory_.AddSocketDataProvider(&data3); | |
| 410 | |
| 411 SSLSocketDataProvider ssl(ASYNC, OK); | |
| 412 ssl.is_in_session_cache = false; | |
| 413 ssl.should_block_on_connect = true; | |
| 414 SSLSocketDataProvider ssl2(ASYNC, OK); | |
| 415 ssl2.is_in_session_cache = false; | |
| 416 SSLSocketDataProvider ssl3(ASYNC, OK); | |
| 417 ssl3.is_in_session_cache = false; | |
| 418 socket_factory_.AddSSLSocketDataProvider(&ssl); | |
| 419 socket_factory_.AddSSLSocketDataProvider(&ssl2); | |
| 420 socket_factory_.AddSSLSocketDataProvider(&ssl3); | |
| 421 | |
| 422 enable_ssl_connect_job_waiting_ = true; | |
| 423 CreatePool(true, false, false); | |
| 424 | |
| 425 scoped_refptr<SSLSocketParams> params1 = | |
| 426 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 427 scoped_refptr<SSLSocketParams> params2 = | |
| 428 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 429 scoped_refptr<SSLSocketParams> params3 = | |
| 430 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 431 ClientSocketHandle handle1; | |
| 432 ClientSocketHandle handle2; | |
| 433 ClientSocketHandle handle3; | |
| 434 TestCompletionCallback callback1; | |
| 435 TestCompletionCallback callback2; | |
| 436 TestCompletionCallback callback3; | |
| 437 | |
| 438 handle1.Init( | |
| 439 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); | |
| 440 handle2.Init( | |
| 441 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); | |
| 442 handle3.Init( | |
| 443 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); | |
| 444 | |
| 445 // Allow the connections to proceed until the first socket has started | |
| 446 // connecting. | |
| 447 base::RunLoop().RunUntilIdle(); | |
| 448 | |
| 449 std::vector<MockSSLClientSocket*> sockets = | |
| 450 socket_factory_.ssl_client_sockets(); | |
| 451 | |
| 452 pool_->CancelRequest("b", &handle2); | |
| 453 | |
| 454 sockets[0]->RestartPausedConnect(); | |
| 455 | |
| 456 callback1.WaitForResult(); | |
| 457 callback3.WaitForResult(); | |
| 458 | |
| 459 EXPECT_TRUE(handle1.socket()->IsConnected()); | |
| 460 EXPECT_FALSE(handle2.socket()); | |
| 461 EXPECT_TRUE(handle3.socket()->IsConnected()); | |
| 462 } | |
| 463 | |
| 464 // Tests that all pending sockets still connect when the pool deletes a pending | |
| 465 // SSLConnectJob which immediately followed a failed leading connection. | |
| 466 TEST_P(SSLClientSocketPoolTest, DeletedSocketAfterFail) { | |
| 467 #if !defined(USE_OPENSSL) | |
| 468 return; | |
| 469 #endif | |
| 470 StaticSocketDataProvider data1; | |
| 471 StaticSocketDataProvider data2; | |
| 472 StaticSocketDataProvider data3; | |
| 473 StaticSocketDataProvider data4; | |
| 474 socket_factory_.AddSocketDataProvider(&data1); | |
| 475 socket_factory_.AddSocketDataProvider(&data2); | |
| 476 socket_factory_.AddSocketDataProvider(&data3); | |
| 477 socket_factory_.AddSocketDataProvider(&data4); | |
| 478 | |
| 479 SSLSocketDataProvider ssl(ASYNC, ERR_SSL_PROTOCOL_ERROR); | |
| 480 ssl.is_in_session_cache = false; | |
| 481 ssl.should_block_on_connect = true; | |
| 482 SSLSocketDataProvider ssl2(ASYNC, OK); | |
| 483 ssl2.is_in_session_cache = false; | |
| 484 SSLSocketDataProvider ssl3(ASYNC, OK); | |
| 485 ssl3.is_in_session_cache = false; | |
| 486 SSLSocketDataProvider ssl4(ASYNC, OK); | |
| 487 ssl4.is_in_session_cache = false; | |
| 488 socket_factory_.AddSSLSocketDataProvider(&ssl); | |
| 489 socket_factory_.AddSSLSocketDataProvider(&ssl2); | |
| 490 socket_factory_.AddSSLSocketDataProvider(&ssl3); | |
| 491 socket_factory_.AddSSLSocketDataProvider(&ssl4); | |
| 492 | |
| 493 enable_ssl_connect_job_waiting_ = true; | |
| 494 CreatePool(true, false, false); | |
| 495 | |
| 496 scoped_refptr<SSLSocketParams> params1 = | |
| 497 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 498 scoped_refptr<SSLSocketParams> params2 = | |
| 499 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 500 scoped_refptr<SSLSocketParams> params3 = | |
| 501 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 502 ClientSocketHandle handle1; | |
| 503 ClientSocketHandle handle2; | |
| 504 ClientSocketHandle handle3; | |
| 505 TestCompletionCallback callback1; | |
| 506 TestCompletionCallback callback2; | |
| 507 TestCompletionCallback callback3; | |
| 508 | |
| 509 handle1.Init( | |
| 510 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); | |
| 511 handle2.Init( | |
| 512 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); | |
| 513 handle3.Init( | |
| 514 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); | |
| 515 | |
| 516 // Allow the connections to proceed until the first socket has started | |
| 517 // connecting. | |
| 518 base::RunLoop().RunUntilIdle(); | |
| 519 | |
| 520 std::vector<MockSSLClientSocket*> sockets = | |
| 521 socket_factory_.ssl_client_sockets(); | |
| 522 | |
| 523 EXPECT_EQ(3u, sockets.size()); | |
| 524 EXPECT_FALSE(sockets[0]->IsConnected()); | |
| 525 EXPECT_FALSE(handle1.socket()); | |
| 526 | |
| 527 pool_->CancelRequest("b", &handle2); | |
| 528 | |
| 529 sockets[0]->RestartPausedConnect(); | |
| 530 | |
| 531 callback1.WaitForResult(); | |
| 532 callback3.WaitForResult(); | |
| 533 | |
| 534 EXPECT_FALSE(handle1.socket()); | |
| 535 EXPECT_FALSE(handle2.socket()); | |
| 536 EXPECT_TRUE(handle3.socket()->IsConnected()); | |
| 537 } | |
| 538 | |
| 539 // Make sure that sockets still connect after the leader socket's | |
| 540 // connection fails. | |
| 541 TEST_P(SSLClientSocketPoolTest, SimultaneousConnectJobsFail) { | |
| 542 #if !defined(USE_OPENSSL) | |
| 543 return; | |
| 544 #endif | |
| 545 StaticSocketDataProvider data1; | |
| 546 StaticSocketDataProvider data2; | |
| 547 StaticSocketDataProvider data3; | |
| 548 StaticSocketDataProvider data4; | |
| 549 StaticSocketDataProvider data5; | |
| 550 socket_factory_.AddSocketDataProvider(&data1); | |
| 551 socket_factory_.AddSocketDataProvider(&data2); | |
| 552 socket_factory_.AddSocketDataProvider(&data3); | |
| 553 socket_factory_.AddSocketDataProvider(&data4); | |
| 554 socket_factory_.AddSocketDataProvider(&data5); | |
| 555 SSLSocketDataProvider ssl(ASYNC, ERR_SSL_PROTOCOL_ERROR); | |
| 556 ssl.is_in_session_cache = false; | |
| 557 ssl.should_block_on_connect = true; | |
| 558 SSLSocketDataProvider ssl2(ASYNC, OK); | |
| 559 ssl2.is_in_session_cache = false; | |
| 560 ssl2.should_block_on_connect = true; | |
| 561 SSLSocketDataProvider ssl3(ASYNC, OK); | |
| 562 ssl3.is_in_session_cache = false; | |
| 563 SSLSocketDataProvider ssl4(ASYNC, OK); | |
| 564 ssl4.is_in_session_cache = false; | |
| 565 SSLSocketDataProvider ssl5(ASYNC, OK); | |
| 566 ssl5.is_in_session_cache = false; | |
| 567 | |
| 568 socket_factory_.AddSSLSocketDataProvider(&ssl); | |
| 569 socket_factory_.AddSSLSocketDataProvider(&ssl2); | |
| 570 socket_factory_.AddSSLSocketDataProvider(&ssl3); | |
| 571 socket_factory_.AddSSLSocketDataProvider(&ssl4); | |
| 572 socket_factory_.AddSSLSocketDataProvider(&ssl5); | |
| 573 | |
| 574 enable_ssl_connect_job_waiting_ = true; | |
| 575 CreatePool(true, false, false); | |
| 576 scoped_refptr<SSLSocketParams> params1 = | |
| 577 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 578 scoped_refptr<SSLSocketParams> params2 = | |
| 579 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 580 scoped_refptr<SSLSocketParams> params3 = | |
| 581 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 582 scoped_refptr<SSLSocketParams> params4 = | |
| 583 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 584 ClientSocketHandle handle1; | |
| 585 ClientSocketHandle handle2; | |
| 586 ClientSocketHandle handle3; | |
| 587 ClientSocketHandle handle4; | |
| 588 TestCompletionCallback callback1; | |
| 589 TestCompletionCallback callback2; | |
| 590 TestCompletionCallback callback3; | |
| 591 TestCompletionCallback callback4; | |
| 592 handle1.Init( | |
| 593 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); | |
| 594 handle2.Init( | |
| 595 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); | |
| 596 handle3.Init( | |
| 597 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); | |
| 598 handle4.Init( | |
| 599 "b", params4, MEDIUM, callback4.callback(), pool_.get(), BoundNetLog()); | |
| 600 | |
| 601 base::RunLoop().RunUntilIdle(); | |
| 602 | |
| 603 std::vector<MockSSLClientSocket*> sockets = | |
| 604 socket_factory_.ssl_client_sockets(); | |
| 605 | |
| 606 // The first socket's connection should have failed, and no other sockets | |
| 607 // should have connected yet. | |
| 608 for (std::vector<MockSSLClientSocket*>::iterator it = sockets.begin(); | |
| 609 it != sockets.end(); | |
| 610 ++it) { | |
| 611 EXPECT_FALSE((*it)->IsConnected()); | |
| 612 } | |
| 613 | |
| 614 // Allow the first socket to resume it's connection process. | |
| 615 sockets[0]->RestartPausedConnect(); | |
| 616 | |
| 617 base::RunLoop().RunUntilIdle(); | |
| 618 | |
| 619 // The second socket should have connected. | |
| 620 EXPECT_TRUE(sockets[1]->IsConnected()); | |
| 621 | |
| 622 // Allow the second socket to continue its connection. | |
| 623 sockets[1]->RestartPausedConnect(); | |
| 624 | |
| 625 base::RunLoop().RunUntilIdle(); | |
| 626 | |
| 627 EXPECT_FALSE(handle1.socket()); | |
| 628 EXPECT_TRUE(handle2.socket()->IsConnected()); | |
| 629 EXPECT_TRUE(handle3.socket()->IsConnected()); | |
| 630 EXPECT_TRUE(handle4.socket()->IsConnected()); | |
| 631 } | |
| 632 | |
| 633 // Make sure that no sockets connect before the "leader" socket, | |
| 634 // given that the leader has a successful connection. | |
| 635 TEST_P(SSLClientSocketPoolTest, SimultaneousConnectJobsSuccess) { | |
| 636 #if !defined(USE_OPENSSL) | |
| 637 return; | |
| 638 #endif | |
| 639 StaticSocketDataProvider data1; | |
| 640 StaticSocketDataProvider data2; | |
| 641 StaticSocketDataProvider data3; | |
| 642 socket_factory_.AddSocketDataProvider(&data1); | |
| 643 socket_factory_.AddSocketDataProvider(&data2); | |
| 644 socket_factory_.AddSocketDataProvider(&data3); | |
| 645 | |
| 646 SSLSocketDataProvider ssl(ASYNC, OK); | |
| 647 ssl.is_in_session_cache = false; | |
| 648 ssl.should_block_on_connect = true; | |
| 649 SSLSocketDataProvider ssl2(ASYNC, OK); | |
| 650 ssl2.is_in_session_cache = false; | |
| 651 SSLSocketDataProvider ssl3(ASYNC, OK); | |
| 652 ssl3.is_in_session_cache = false; | |
| 653 socket_factory_.AddSSLSocketDataProvider(&ssl); | |
| 654 socket_factory_.AddSSLSocketDataProvider(&ssl2); | |
| 655 socket_factory_.AddSSLSocketDataProvider(&ssl3); | |
| 656 | |
| 657 enable_ssl_connect_job_waiting_ = true; | |
| 658 CreatePool(true, false, false); | |
| 659 | |
| 660 scoped_refptr<SSLSocketParams> params1 = | |
| 661 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 662 scoped_refptr<SSLSocketParams> params2 = | |
| 663 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 664 scoped_refptr<SSLSocketParams> params3 = | |
| 665 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
| 666 ClientSocketHandle handle1; | |
| 667 ClientSocketHandle handle2; | |
| 668 ClientSocketHandle handle3; | |
| 669 TestCompletionCallback callback1; | |
| 670 TestCompletionCallback callback2; | |
| 671 TestCompletionCallback callback3; | |
| 672 | |
| 673 handle1.Init( | |
| 674 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); | |
| 675 handle2.Init( | |
| 676 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); | |
| 677 handle3.Init( | |
| 678 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); | |
| 679 | |
| 680 // Allow the connections to proceed until the first socket has finished | |
| 681 // connecting. | |
| 682 base::RunLoop().RunUntilIdle(); | |
| 683 | |
| 684 std::vector<MockSSLClientSocket*> sockets = | |
| 685 socket_factory_.ssl_client_sockets(); | |
| 686 | |
| 687 EXPECT_TRUE(sockets[0]->IsConnected()); | |
| 688 | |
| 689 std::vector<MockSSLClientSocket*>::iterator it = sockets.begin(); | |
| 690 // The first socket should be connected. | |
| 691 EXPECT_TRUE((*it)->IsConnected()); | |
| 692 ++it; | |
| 693 // All other sockets should not be connected. | |
| 694 for (; it != sockets.end(); ++it) { | |
| 695 EXPECT_FALSE((*it)->IsConnected()); | |
| 696 } | |
| 697 | |
| 698 sockets[0]->RestartPausedConnect(); | |
| 699 | |
| 700 callback1.WaitForResult(); | |
| 701 callback2.WaitForResult(); | |
| 702 callback3.WaitForResult(); | |
| 703 | |
| 704 EXPECT_TRUE(handle1.socket()->IsConnected()); | |
| 705 EXPECT_TRUE(handle2.socket()->IsConnected()); | |
| 706 EXPECT_TRUE(handle3.socket()->IsConnected()); | |
| 707 } | |
| 708 | |
| 232 TEST_P(SSLClientSocketPoolTest, TCPFail) { | 709 TEST_P(SSLClientSocketPoolTest, TCPFail) { |
| 233 StaticSocketDataProvider data; | 710 StaticSocketDataProvider data; |
| 234 data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_CONNECTION_FAILED)); | 711 data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_CONNECTION_FAILED)); |
| 235 socket_factory_.AddSocketDataProvider(&data); | 712 socket_factory_.AddSocketDataProvider(&data); |
| 236 | 713 |
| 237 CreatePool(true /* tcp pool */, false, false); | 714 CreatePool(true /* tcp pool */, false, false); |
| 238 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, | 715 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, |
| 239 false); | 716 false); |
| 240 | 717 |
| 241 ClientSocketHandle handle; | 718 ClientSocketHandle handle; |
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 929 ssl.channel_id_sent = true; | 1406 ssl.channel_id_sent = true; |
| 930 ssl.SetNextProto(GetParam()); | 1407 ssl.SetNextProto(GetParam()); |
| 931 TestIPPoolingDisabled(&ssl); | 1408 TestIPPoolingDisabled(&ssl); |
| 932 } | 1409 } |
| 933 | 1410 |
| 934 // It would be nice to also test the timeouts in SSLClientSocketPool. | 1411 // It would be nice to also test the timeouts in SSLClientSocketPool. |
| 935 | 1412 |
| 936 } // namespace | 1413 } // namespace |
| 937 | 1414 |
| 938 } // namespace net | 1415 } // namespace net |
| OLD | NEW |