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 /* channel_id_service */, | 143 NULL /* channel_id_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 // Although we request four sockets, the first three socket connect |
| 245 // failures cause the socket pool to create three more sockets because |
| 246 // there are pending requests. |
| 247 StaticSocketDataProvider data1; |
| 248 StaticSocketDataProvider data2; |
| 249 StaticSocketDataProvider data3; |
| 250 StaticSocketDataProvider data4; |
| 251 StaticSocketDataProvider data5; |
| 252 StaticSocketDataProvider data6; |
| 253 StaticSocketDataProvider data7; |
| 254 socket_factory_.AddSocketDataProvider(&data1); |
| 255 socket_factory_.AddSocketDataProvider(&data2); |
| 256 socket_factory_.AddSocketDataProvider(&data3); |
| 257 socket_factory_.AddSocketDataProvider(&data4); |
| 258 socket_factory_.AddSocketDataProvider(&data5); |
| 259 socket_factory_.AddSocketDataProvider(&data6); |
| 260 socket_factory_.AddSocketDataProvider(&data7); |
| 261 SSLSocketDataProvider ssl(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
| 262 ssl.is_in_session_cache = false; |
| 263 SSLSocketDataProvider ssl2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
| 264 ssl2.is_in_session_cache = false; |
| 265 SSLSocketDataProvider ssl3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
| 266 ssl3.is_in_session_cache = false; |
| 267 SSLSocketDataProvider ssl4(ASYNC, OK); |
| 268 ssl4.is_in_session_cache = false; |
| 269 SSLSocketDataProvider ssl5(ASYNC, OK); |
| 270 ssl5.is_in_session_cache = false; |
| 271 SSLSocketDataProvider ssl6(ASYNC, OK); |
| 272 ssl6.is_in_session_cache = false; |
| 273 SSLSocketDataProvider ssl7(ASYNC, OK); |
| 274 ssl7.is_in_session_cache = false; |
| 275 |
| 276 socket_factory_.AddSSLSocketDataProvider(&ssl); |
| 277 socket_factory_.AddSSLSocketDataProvider(&ssl2); |
| 278 socket_factory_.AddSSLSocketDataProvider(&ssl3); |
| 279 socket_factory_.AddSSLSocketDataProvider(&ssl4); |
| 280 socket_factory_.AddSSLSocketDataProvider(&ssl5); |
| 281 socket_factory_.AddSSLSocketDataProvider(&ssl6); |
| 282 socket_factory_.AddSSLSocketDataProvider(&ssl7); |
| 283 |
| 284 enable_ssl_connect_job_waiting_ = true; |
| 285 CreatePool(true, false, false); |
| 286 |
| 287 scoped_refptr<SSLSocketParams> params1 = |
| 288 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 289 scoped_refptr<SSLSocketParams> params2 = |
| 290 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 291 scoped_refptr<SSLSocketParams> params3 = |
| 292 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 293 scoped_refptr<SSLSocketParams> params4 = |
| 294 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 295 ClientSocketHandle handle1; |
| 296 ClientSocketHandle handle2; |
| 297 ClientSocketHandle handle3; |
| 298 ClientSocketHandle handle4; |
| 299 TestCompletionCallback callback1; |
| 300 TestCompletionCallback callback2; |
| 301 TestCompletionCallback callback3; |
| 302 TestCompletionCallback callback4; |
| 303 |
| 304 handle1.Init( |
| 305 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); |
| 306 handle2.Init( |
| 307 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); |
| 308 handle3.Init( |
| 309 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); |
| 310 handle4.Init( |
| 311 "b", params4, MEDIUM, callback4.callback(), pool_.get(), BoundNetLog()); |
| 312 |
| 313 base::RunLoop().RunUntilIdle(); |
| 314 |
| 315 // Only the last socket should have connected. |
| 316 EXPECT_FALSE(handle1.socket()); |
| 317 EXPECT_FALSE(handle2.socket()); |
| 318 EXPECT_FALSE(handle3.socket()); |
| 319 EXPECT_TRUE(handle4.socket()->IsConnected()); |
| 320 } |
| 321 |
| 322 // Tests that sockets will still connect in parallel if the |
| 323 // EnableSSLConnectJobWaiting flag is not enabled. |
| 324 TEST_P(SSLClientSocketPoolTest, SocketsConnectWithoutFlag) { |
| 325 StaticSocketDataProvider data1; |
| 326 StaticSocketDataProvider data2; |
| 327 StaticSocketDataProvider data3; |
| 328 socket_factory_.AddSocketDataProvider(&data1); |
| 329 socket_factory_.AddSocketDataProvider(&data2); |
| 330 socket_factory_.AddSocketDataProvider(&data3); |
| 331 |
| 332 SSLSocketDataProvider ssl(ASYNC, OK); |
| 333 ssl.is_in_session_cache = false; |
| 334 ssl.should_block_on_connect = true; |
| 335 SSLSocketDataProvider ssl2(ASYNC, OK); |
| 336 ssl2.is_in_session_cache = false; |
| 337 ssl2.should_block_on_connect = true; |
| 338 SSLSocketDataProvider ssl3(ASYNC, OK); |
| 339 ssl3.is_in_session_cache = false; |
| 340 ssl3.should_block_on_connect = true; |
| 341 socket_factory_.AddSSLSocketDataProvider(&ssl); |
| 342 socket_factory_.AddSSLSocketDataProvider(&ssl2); |
| 343 socket_factory_.AddSSLSocketDataProvider(&ssl3); |
| 344 |
| 345 CreatePool(true, false, false); |
| 346 |
| 347 scoped_refptr<SSLSocketParams> params1 = |
| 348 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 349 scoped_refptr<SSLSocketParams> params2 = |
| 350 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 351 scoped_refptr<SSLSocketParams> params3 = |
| 352 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 353 ClientSocketHandle handle1; |
| 354 ClientSocketHandle handle2; |
| 355 ClientSocketHandle handle3; |
| 356 TestCompletionCallback callback1; |
| 357 TestCompletionCallback callback2; |
| 358 TestCompletionCallback callback3; |
| 359 |
| 360 handle1.Init( |
| 361 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); |
| 362 handle2.Init( |
| 363 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); |
| 364 handle3.Init( |
| 365 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); |
| 366 |
| 367 base::RunLoop().RunUntilIdle(); |
| 368 |
| 369 std::vector<MockSSLClientSocket*> sockets = |
| 370 socket_factory_.ssl_client_sockets(); |
| 371 |
| 372 // All sockets should have started their connections. |
| 373 for (std::vector<MockSSLClientSocket*>::iterator it = sockets.begin(); |
| 374 it != sockets.end(); |
| 375 ++it) { |
| 376 EXPECT_TRUE((*it)->reached_connect()); |
| 377 } |
| 378 |
| 379 // Resume connecting all of the sockets. |
| 380 for (std::vector<MockSSLClientSocket*>::iterator it = sockets.begin(); |
| 381 it != sockets.end(); |
| 382 ++it) { |
| 383 (*it)->RestartPausedConnect(); |
| 384 } |
| 385 |
| 386 callback1.WaitForResult(); |
| 387 callback2.WaitForResult(); |
| 388 callback3.WaitForResult(); |
| 389 |
| 390 EXPECT_TRUE(handle1.socket()->IsConnected()); |
| 391 EXPECT_TRUE(handle2.socket()->IsConnected()); |
| 392 EXPECT_TRUE(handle3.socket()->IsConnected()); |
| 393 } |
| 394 |
| 395 // Tests that the pool deleting an SSLConnectJob will not cause a crash, |
| 396 // or prevent pending sockets from connecting. |
| 397 TEST_P(SSLClientSocketPoolTest, DeletedSSLConnectJob) { |
| 398 StaticSocketDataProvider data1; |
| 399 StaticSocketDataProvider data2; |
| 400 StaticSocketDataProvider data3; |
| 401 socket_factory_.AddSocketDataProvider(&data1); |
| 402 socket_factory_.AddSocketDataProvider(&data2); |
| 403 socket_factory_.AddSocketDataProvider(&data3); |
| 404 |
| 405 SSLSocketDataProvider ssl(ASYNC, OK); |
| 406 ssl.is_in_session_cache = false; |
| 407 ssl.should_block_on_connect = true; |
| 408 SSLSocketDataProvider ssl2(ASYNC, OK); |
| 409 ssl2.is_in_session_cache = false; |
| 410 SSLSocketDataProvider ssl3(ASYNC, OK); |
| 411 ssl3.is_in_session_cache = false; |
| 412 socket_factory_.AddSSLSocketDataProvider(&ssl); |
| 413 socket_factory_.AddSSLSocketDataProvider(&ssl2); |
| 414 socket_factory_.AddSSLSocketDataProvider(&ssl3); |
| 415 |
| 416 enable_ssl_connect_job_waiting_ = true; |
| 417 CreatePool(true, false, false); |
| 418 |
| 419 scoped_refptr<SSLSocketParams> params1 = |
| 420 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 421 scoped_refptr<SSLSocketParams> params2 = |
| 422 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 423 scoped_refptr<SSLSocketParams> params3 = |
| 424 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 425 ClientSocketHandle handle1; |
| 426 ClientSocketHandle handle2; |
| 427 ClientSocketHandle handle3; |
| 428 TestCompletionCallback callback1; |
| 429 TestCompletionCallback callback2; |
| 430 TestCompletionCallback callback3; |
| 431 |
| 432 handle1.Init( |
| 433 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); |
| 434 handle2.Init( |
| 435 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); |
| 436 handle3.Init( |
| 437 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); |
| 438 |
| 439 // Allow the connections to proceed until the first socket has started |
| 440 // connecting. |
| 441 base::RunLoop().RunUntilIdle(); |
| 442 |
| 443 std::vector<MockSSLClientSocket*> sockets = |
| 444 socket_factory_.ssl_client_sockets(); |
| 445 |
| 446 pool_->CancelRequest("b", &handle2); |
| 447 |
| 448 sockets[0]->RestartPausedConnect(); |
| 449 |
| 450 callback1.WaitForResult(); |
| 451 callback3.WaitForResult(); |
| 452 |
| 453 EXPECT_TRUE(handle1.socket()->IsConnected()); |
| 454 EXPECT_FALSE(handle2.socket()); |
| 455 EXPECT_TRUE(handle3.socket()->IsConnected()); |
| 456 } |
| 457 |
| 458 // Tests that all pending sockets still connect when the pool deletes a pending |
| 459 // SSLConnectJob which immediately followed a failed leading connection. |
| 460 TEST_P(SSLClientSocketPoolTest, DeletedSocketAfterFail) { |
| 461 StaticSocketDataProvider data1; |
| 462 StaticSocketDataProvider data2; |
| 463 StaticSocketDataProvider data3; |
| 464 StaticSocketDataProvider data4; |
| 465 socket_factory_.AddSocketDataProvider(&data1); |
| 466 socket_factory_.AddSocketDataProvider(&data2); |
| 467 socket_factory_.AddSocketDataProvider(&data3); |
| 468 socket_factory_.AddSocketDataProvider(&data4); |
| 469 |
| 470 SSLSocketDataProvider ssl(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
| 471 ssl.is_in_session_cache = false; |
| 472 ssl.should_block_on_connect = true; |
| 473 SSLSocketDataProvider ssl2(ASYNC, OK); |
| 474 ssl2.is_in_session_cache = false; |
| 475 SSLSocketDataProvider ssl3(ASYNC, OK); |
| 476 ssl3.is_in_session_cache = false; |
| 477 SSLSocketDataProvider ssl4(ASYNC, OK); |
| 478 ssl4.is_in_session_cache = false; |
| 479 socket_factory_.AddSSLSocketDataProvider(&ssl); |
| 480 socket_factory_.AddSSLSocketDataProvider(&ssl2); |
| 481 socket_factory_.AddSSLSocketDataProvider(&ssl3); |
| 482 socket_factory_.AddSSLSocketDataProvider(&ssl4); |
| 483 |
| 484 enable_ssl_connect_job_waiting_ = true; |
| 485 CreatePool(true, false, false); |
| 486 |
| 487 scoped_refptr<SSLSocketParams> params1 = |
| 488 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 489 scoped_refptr<SSLSocketParams> params2 = |
| 490 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 491 scoped_refptr<SSLSocketParams> params3 = |
| 492 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 493 ClientSocketHandle handle1; |
| 494 ClientSocketHandle handle2; |
| 495 ClientSocketHandle handle3; |
| 496 TestCompletionCallback callback1; |
| 497 TestCompletionCallback callback2; |
| 498 TestCompletionCallback callback3; |
| 499 |
| 500 handle1.Init( |
| 501 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); |
| 502 handle2.Init( |
| 503 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); |
| 504 handle3.Init( |
| 505 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); |
| 506 |
| 507 // Allow the connections to proceed until the first socket has started |
| 508 // connecting. |
| 509 base::RunLoop().RunUntilIdle(); |
| 510 |
| 511 std::vector<MockSSLClientSocket*> sockets = |
| 512 socket_factory_.ssl_client_sockets(); |
| 513 |
| 514 EXPECT_EQ(3u, sockets.size()); |
| 515 EXPECT_TRUE(sockets[0]->reached_connect()); |
| 516 EXPECT_FALSE(handle1.socket()); |
| 517 |
| 518 pool_->CancelRequest("b", &handle2); |
| 519 |
| 520 sockets[0]->RestartPausedConnect(); |
| 521 |
| 522 callback1.WaitForResult(); |
| 523 callback3.WaitForResult(); |
| 524 |
| 525 EXPECT_FALSE(handle1.socket()); |
| 526 EXPECT_FALSE(handle2.socket()); |
| 527 EXPECT_TRUE(handle3.socket()->IsConnected()); |
| 528 } |
| 529 |
| 530 // Make sure that sockets still connect after the leader socket's |
| 531 // connection fails. |
| 532 TEST_P(SSLClientSocketPoolTest, SimultaneousConnectJobsFail) { |
| 533 StaticSocketDataProvider data1; |
| 534 StaticSocketDataProvider data2; |
| 535 StaticSocketDataProvider data3; |
| 536 StaticSocketDataProvider data4; |
| 537 StaticSocketDataProvider data5; |
| 538 socket_factory_.AddSocketDataProvider(&data1); |
| 539 socket_factory_.AddSocketDataProvider(&data2); |
| 540 socket_factory_.AddSocketDataProvider(&data3); |
| 541 socket_factory_.AddSocketDataProvider(&data4); |
| 542 socket_factory_.AddSocketDataProvider(&data5); |
| 543 SSLSocketDataProvider ssl(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
| 544 ssl.is_in_session_cache = false; |
| 545 ssl.should_block_on_connect = true; |
| 546 SSLSocketDataProvider ssl2(ASYNC, OK); |
| 547 ssl2.is_in_session_cache = false; |
| 548 ssl2.should_block_on_connect = true; |
| 549 SSLSocketDataProvider ssl3(ASYNC, OK); |
| 550 ssl3.is_in_session_cache = false; |
| 551 SSLSocketDataProvider ssl4(ASYNC, OK); |
| 552 ssl4.is_in_session_cache = false; |
| 553 SSLSocketDataProvider ssl5(ASYNC, OK); |
| 554 ssl5.is_in_session_cache = false; |
| 555 |
| 556 socket_factory_.AddSSLSocketDataProvider(&ssl); |
| 557 socket_factory_.AddSSLSocketDataProvider(&ssl2); |
| 558 socket_factory_.AddSSLSocketDataProvider(&ssl3); |
| 559 socket_factory_.AddSSLSocketDataProvider(&ssl4); |
| 560 socket_factory_.AddSSLSocketDataProvider(&ssl5); |
| 561 |
| 562 enable_ssl_connect_job_waiting_ = true; |
| 563 CreatePool(true, false, false); |
| 564 scoped_refptr<SSLSocketParams> params1 = |
| 565 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 566 scoped_refptr<SSLSocketParams> params2 = |
| 567 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 568 scoped_refptr<SSLSocketParams> params3 = |
| 569 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 570 scoped_refptr<SSLSocketParams> params4 = |
| 571 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 572 ClientSocketHandle handle1; |
| 573 ClientSocketHandle handle2; |
| 574 ClientSocketHandle handle3; |
| 575 ClientSocketHandle handle4; |
| 576 TestCompletionCallback callback1; |
| 577 TestCompletionCallback callback2; |
| 578 TestCompletionCallback callback3; |
| 579 TestCompletionCallback callback4; |
| 580 handle1.Init( |
| 581 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); |
| 582 handle2.Init( |
| 583 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); |
| 584 handle3.Init( |
| 585 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); |
| 586 handle4.Init( |
| 587 "b", params4, MEDIUM, callback4.callback(), pool_.get(), BoundNetLog()); |
| 588 |
| 589 base::RunLoop().RunUntilIdle(); |
| 590 |
| 591 std::vector<MockSSLClientSocket*> sockets = |
| 592 socket_factory_.ssl_client_sockets(); |
| 593 |
| 594 std::vector<MockSSLClientSocket*>::const_iterator it = sockets.begin(); |
| 595 |
| 596 // The first socket should have had Connect called on it. |
| 597 EXPECT_TRUE((*it)->reached_connect()); |
| 598 ++it; |
| 599 |
| 600 // No other socket should have reached connect yet. |
| 601 for (; it != sockets.end(); ++it) |
| 602 EXPECT_FALSE((*it)->reached_connect()); |
| 603 |
| 604 // Allow the first socket to resume it's connection process. |
| 605 sockets[0]->RestartPausedConnect(); |
| 606 |
| 607 base::RunLoop().RunUntilIdle(); |
| 608 |
| 609 // The second socket should have reached connect. |
| 610 EXPECT_TRUE(sockets[1]->reached_connect()); |
| 611 |
| 612 // Allow the second socket to continue its connection. |
| 613 sockets[1]->RestartPausedConnect(); |
| 614 |
| 615 base::RunLoop().RunUntilIdle(); |
| 616 |
| 617 EXPECT_FALSE(handle1.socket()); |
| 618 EXPECT_TRUE(handle2.socket()->IsConnected()); |
| 619 EXPECT_TRUE(handle3.socket()->IsConnected()); |
| 620 EXPECT_TRUE(handle4.socket()->IsConnected()); |
| 621 } |
| 622 |
| 623 // Make sure that no sockets connect before the "leader" socket, |
| 624 // given that the leader has a successful connection. |
| 625 TEST_P(SSLClientSocketPoolTest, SimultaneousConnectJobsSuccess) { |
| 626 StaticSocketDataProvider data1; |
| 627 StaticSocketDataProvider data2; |
| 628 StaticSocketDataProvider data3; |
| 629 socket_factory_.AddSocketDataProvider(&data1); |
| 630 socket_factory_.AddSocketDataProvider(&data2); |
| 631 socket_factory_.AddSocketDataProvider(&data3); |
| 632 |
| 633 SSLSocketDataProvider ssl(ASYNC, OK); |
| 634 ssl.is_in_session_cache = false; |
| 635 ssl.should_block_on_connect = true; |
| 636 SSLSocketDataProvider ssl2(ASYNC, OK); |
| 637 ssl2.is_in_session_cache = false; |
| 638 SSLSocketDataProvider ssl3(ASYNC, OK); |
| 639 ssl3.is_in_session_cache = false; |
| 640 socket_factory_.AddSSLSocketDataProvider(&ssl); |
| 641 socket_factory_.AddSSLSocketDataProvider(&ssl2); |
| 642 socket_factory_.AddSSLSocketDataProvider(&ssl3); |
| 643 |
| 644 enable_ssl_connect_job_waiting_ = true; |
| 645 CreatePool(true, false, false); |
| 646 |
| 647 scoped_refptr<SSLSocketParams> params1 = |
| 648 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 649 scoped_refptr<SSLSocketParams> params2 = |
| 650 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 651 scoped_refptr<SSLSocketParams> params3 = |
| 652 SSLParams(ProxyServer::SCHEME_DIRECT, false); |
| 653 ClientSocketHandle handle1; |
| 654 ClientSocketHandle handle2; |
| 655 ClientSocketHandle handle3; |
| 656 TestCompletionCallback callback1; |
| 657 TestCompletionCallback callback2; |
| 658 TestCompletionCallback callback3; |
| 659 |
| 660 handle1.Init( |
| 661 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); |
| 662 handle2.Init( |
| 663 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); |
| 664 handle3.Init( |
| 665 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); |
| 666 |
| 667 // Allow the connections to proceed until the first socket has finished |
| 668 // connecting. |
| 669 base::RunLoop().RunUntilIdle(); |
| 670 |
| 671 std::vector<MockSSLClientSocket*> sockets = |
| 672 socket_factory_.ssl_client_sockets(); |
| 673 |
| 674 std::vector<MockSSLClientSocket*>::const_iterator it = sockets.begin(); |
| 675 // The first socket should have reached connect. |
| 676 EXPECT_TRUE((*it)->reached_connect()); |
| 677 ++it; |
| 678 // No other socket should have reached connect yet. |
| 679 for (; it != sockets.end(); ++it) |
| 680 EXPECT_FALSE((*it)->reached_connect()); |
| 681 |
| 682 sockets[0]->RestartPausedConnect(); |
| 683 |
| 684 callback1.WaitForResult(); |
| 685 callback2.WaitForResult(); |
| 686 callback3.WaitForResult(); |
| 687 |
| 688 EXPECT_TRUE(handle1.socket()->IsConnected()); |
| 689 EXPECT_TRUE(handle2.socket()->IsConnected()); |
| 690 EXPECT_TRUE(handle3.socket()->IsConnected()); |
| 691 } |
| 692 |
232 TEST_P(SSLClientSocketPoolTest, TCPFail) { | 693 TEST_P(SSLClientSocketPoolTest, TCPFail) { |
233 StaticSocketDataProvider data; | 694 StaticSocketDataProvider data; |
234 data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_CONNECTION_FAILED)); | 695 data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_CONNECTION_FAILED)); |
235 socket_factory_.AddSocketDataProvider(&data); | 696 socket_factory_.AddSocketDataProvider(&data); |
236 | 697 |
237 CreatePool(true /* tcp pool */, false, false); | 698 CreatePool(true /* tcp pool */, false, false); |
238 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, | 699 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, |
239 false); | 700 false); |
240 | 701 |
241 ClientSocketHandle handle; | 702 ClientSocketHandle handle; |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 ssl.channel_id_sent = true; | 1389 ssl.channel_id_sent = true; |
929 ssl.SetNextProto(GetParam()); | 1390 ssl.SetNextProto(GetParam()); |
930 TestIPPoolingDisabled(&ssl); | 1391 TestIPPoolingDisabled(&ssl); |
931 } | 1392 } |
932 | 1393 |
933 // It would be nice to also test the timeouts in SSLClientSocketPool. | 1394 // It would be nice to also test the timeouts in SSLClientSocketPool. |
934 | 1395 |
935 } // namespace | 1396 } // namespace |
936 | 1397 |
937 } // namespace net | 1398 } // namespace net |
OLD | NEW |