Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: net/socket/ssl_client_socket_pool_unittest.cc

Issue 353713005: Implements new, more robust design for communicating between SSLConnectJobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rewrote the MockSSLClientSocket connect state loop to use the typical Chrome structure & fixed bugs… Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 std::vector<MockSSLClientSocket*> sockets =
316 socket_factory_.ssl_client_sockets();
wtc 2014/07/29 20:59:35 Delete these two lines. |sockets| is not used.
mshelley 2014/07/29 21:40:13 Done.
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 StaticSocketDataProvider data1;
402 StaticSocketDataProvider data2;
403 StaticSocketDataProvider data3;
404 socket_factory_.AddSocketDataProvider(&data1);
405 socket_factory_.AddSocketDataProvider(&data2);
406 socket_factory_.AddSocketDataProvider(&data3);
407
408 SSLSocketDataProvider ssl(ASYNC, OK);
409 ssl.is_in_session_cache = false;
410 ssl.should_block_on_connect = true;
411 SSLSocketDataProvider ssl2(ASYNC, OK);
412 ssl2.is_in_session_cache = false;
413 SSLSocketDataProvider ssl3(ASYNC, OK);
414 ssl3.is_in_session_cache = false;
415 socket_factory_.AddSSLSocketDataProvider(&ssl);
416 socket_factory_.AddSSLSocketDataProvider(&ssl2);
417 socket_factory_.AddSSLSocketDataProvider(&ssl3);
418
419 enable_ssl_connect_job_waiting_ = true;
420 CreatePool(true, false, false);
421
422 scoped_refptr<SSLSocketParams> params1 =
423 SSLParams(ProxyServer::SCHEME_DIRECT, false);
424 scoped_refptr<SSLSocketParams> params2 =
425 SSLParams(ProxyServer::SCHEME_DIRECT, false);
426 scoped_refptr<SSLSocketParams> params3 =
427 SSLParams(ProxyServer::SCHEME_DIRECT, false);
428 ClientSocketHandle handle1;
429 ClientSocketHandle handle2;
430 ClientSocketHandle handle3;
431 TestCompletionCallback callback1;
432 TestCompletionCallback callback2;
433 TestCompletionCallback callback3;
434
435 handle1.Init(
436 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog());
437 handle2.Init(
438 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog());
439 handle3.Init(
440 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog());
441
442 // Allow the connections to proceed until the first socket has started
443 // connecting.
444 base::RunLoop().RunUntilIdle();
445
446 std::vector<MockSSLClientSocket*> sockets =
447 socket_factory_.ssl_client_sockets();
448
449 pool_->CancelRequest("b", &handle2);
450
451 sockets[0]->RestartPausedConnect();
452
453 callback1.WaitForResult();
454 callback3.WaitForResult();
455
456 EXPECT_TRUE(handle1.socket()->IsConnected());
457 EXPECT_FALSE(handle2.socket());
458 EXPECT_TRUE(handle3.socket()->IsConnected());
459 }
460
461 // Tests that all pending sockets still connect when the pool deletes a pending
462 // SSLConnectJob which immediately followed a failed leading connection.
463 TEST_P(SSLClientSocketPoolTest, DeletedSocketAfterFail) {
464 StaticSocketDataProvider data1;
465 StaticSocketDataProvider data2;
466 StaticSocketDataProvider data3;
467 StaticSocketDataProvider data4;
468 socket_factory_.AddSocketDataProvider(&data1);
469 socket_factory_.AddSocketDataProvider(&data2);
470 socket_factory_.AddSocketDataProvider(&data3);
471 socket_factory_.AddSocketDataProvider(&data4);
472
473 SSLSocketDataProvider ssl(ASYNC, ERR_SSL_PROTOCOL_ERROR);
474 ssl.is_in_session_cache = false;
475 ssl.should_block_on_connect = true;
476 SSLSocketDataProvider ssl2(ASYNC, OK);
477 ssl2.is_in_session_cache = false;
478 SSLSocketDataProvider ssl3(ASYNC, OK);
479 ssl3.is_in_session_cache = false;
480 SSLSocketDataProvider ssl4(ASYNC, OK);
481 ssl4.is_in_session_cache = false;
482 socket_factory_.AddSSLSocketDataProvider(&ssl);
483 socket_factory_.AddSSLSocketDataProvider(&ssl2);
484 socket_factory_.AddSSLSocketDataProvider(&ssl3);
485 socket_factory_.AddSSLSocketDataProvider(&ssl4);
486
487 enable_ssl_connect_job_waiting_ = true;
488 CreatePool(true, false, false);
489
490 scoped_refptr<SSLSocketParams> params1 =
491 SSLParams(ProxyServer::SCHEME_DIRECT, false);
492 scoped_refptr<SSLSocketParams> params2 =
493 SSLParams(ProxyServer::SCHEME_DIRECT, false);
494 scoped_refptr<SSLSocketParams> params3 =
495 SSLParams(ProxyServer::SCHEME_DIRECT, false);
496 ClientSocketHandle handle1;
497 ClientSocketHandle handle2;
498 ClientSocketHandle handle3;
499 TestCompletionCallback callback1;
500 TestCompletionCallback callback2;
501 TestCompletionCallback callback3;
502
503 handle1.Init(
504 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog());
505 handle2.Init(
506 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog());
507 handle3.Init(
508 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog());
509
510 // Allow the connections to proceed until the first socket has started
511 // connecting.
512 base::RunLoop().RunUntilIdle();
513
514 std::vector<MockSSLClientSocket*> sockets =
515 socket_factory_.ssl_client_sockets();
516
517 EXPECT_EQ(3u, sockets.size());
518 EXPECT_FALSE(sockets[0]->IsConnected());
519 EXPECT_FALSE(handle1.socket());
520
521 pool_->CancelRequest("b", &handle2);
522
523 sockets[0]->RestartPausedConnect();
524
525 callback1.WaitForResult();
526 callback3.WaitForResult();
527
528 EXPECT_FALSE(handle1.socket());
529 EXPECT_FALSE(handle2.socket());
530 EXPECT_TRUE(handle3.socket()->IsConnected());
531 }
532
533 // Make sure that sockets still connect after the leader socket's
534 // connection fails.
535 TEST_P(SSLClientSocketPoolTest, SimultaneousConnectJobsFail) {
536 StaticSocketDataProvider data1;
537 StaticSocketDataProvider data2;
538 StaticSocketDataProvider data3;
539 StaticSocketDataProvider data4;
540 StaticSocketDataProvider data5;
541 socket_factory_.AddSocketDataProvider(&data1);
542 socket_factory_.AddSocketDataProvider(&data2);
543 socket_factory_.AddSocketDataProvider(&data3);
544 socket_factory_.AddSocketDataProvider(&data4);
545 socket_factory_.AddSocketDataProvider(&data5);
546 SSLSocketDataProvider ssl(ASYNC, ERR_SSL_PROTOCOL_ERROR);
547 ssl.is_in_session_cache = false;
548 ssl.should_block_on_connect = true;
549 SSLSocketDataProvider ssl2(ASYNC, OK);
550 ssl2.is_in_session_cache = false;
551 ssl2.should_block_on_connect = true;
552 SSLSocketDataProvider ssl3(ASYNC, OK);
553 ssl3.is_in_session_cache = false;
554 SSLSocketDataProvider ssl4(ASYNC, OK);
555 ssl4.is_in_session_cache = false;
556 SSLSocketDataProvider ssl5(ASYNC, OK);
557 ssl5.is_in_session_cache = false;
558
559 socket_factory_.AddSSLSocketDataProvider(&ssl);
560 socket_factory_.AddSSLSocketDataProvider(&ssl2);
561 socket_factory_.AddSSLSocketDataProvider(&ssl3);
562 socket_factory_.AddSSLSocketDataProvider(&ssl4);
563 socket_factory_.AddSSLSocketDataProvider(&ssl5);
564
565 enable_ssl_connect_job_waiting_ = true;
566 CreatePool(true, false, false);
567 scoped_refptr<SSLSocketParams> params1 =
568 SSLParams(ProxyServer::SCHEME_DIRECT, false);
569 scoped_refptr<SSLSocketParams> params2 =
570 SSLParams(ProxyServer::SCHEME_DIRECT, false);
571 scoped_refptr<SSLSocketParams> params3 =
572 SSLParams(ProxyServer::SCHEME_DIRECT, false);
573 scoped_refptr<SSLSocketParams> params4 =
574 SSLParams(ProxyServer::SCHEME_DIRECT, false);
575 ClientSocketHandle handle1;
576 ClientSocketHandle handle2;
577 ClientSocketHandle handle3;
578 ClientSocketHandle handle4;
579 TestCompletionCallback callback1;
580 TestCompletionCallback callback2;
581 TestCompletionCallback callback3;
582 TestCompletionCallback callback4;
583 handle1.Init(
584 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog());
585 handle2.Init(
586 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog());
587 handle3.Init(
588 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog());
589 handle4.Init(
590 "b", params4, MEDIUM, callback4.callback(), pool_.get(), BoundNetLog());
591
592 base::RunLoop().RunUntilIdle();
593
594 std::vector<MockSSLClientSocket*> sockets =
595 socket_factory_.ssl_client_sockets();
596
597 // The first socket's connection should have failed, and no other sockets
598 // should have connected yet.
599 for (std::vector<MockSSLClientSocket*>::iterator it = sockets.begin();
600 it != sockets.end();
601 ++it) {
602 EXPECT_FALSE((*it)->IsConnected());
603 }
604
605 // Allow the first socket to resume it's connection process.
606 sockets[0]->RestartPausedConnect();
607
608 base::RunLoop().RunUntilIdle();
609
610 // The second socket should have connected.
611 EXPECT_TRUE(sockets[1]->IsConnected());
612
613 // Allow the second socket to continue its connection.
614 sockets[1]->RestartPausedConnect();
615
616 base::RunLoop().RunUntilIdle();
617
618 EXPECT_FALSE(handle1.socket());
619 EXPECT_TRUE(handle2.socket()->IsConnected());
620 EXPECT_TRUE(handle3.socket()->IsConnected());
621 EXPECT_TRUE(handle4.socket()->IsConnected());
622 }
623
624 // Make sure that no sockets connect before the "leader" socket,
625 // given that the leader has a successful connection.
626 TEST_P(SSLClientSocketPoolTest, SimultaneousConnectJobsSuccess) {
627 StaticSocketDataProvider data1;
628 StaticSocketDataProvider data2;
629 StaticSocketDataProvider data3;
630 socket_factory_.AddSocketDataProvider(&data1);
631 socket_factory_.AddSocketDataProvider(&data2);
632 socket_factory_.AddSocketDataProvider(&data3);
633
634 SSLSocketDataProvider ssl(ASYNC, OK);
635 ssl.is_in_session_cache = false;
636 ssl.should_block_on_connect = true;
637 SSLSocketDataProvider ssl2(ASYNC, OK);
638 ssl2.is_in_session_cache = false;
639 SSLSocketDataProvider ssl3(ASYNC, OK);
640 ssl3.is_in_session_cache = false;
641 socket_factory_.AddSSLSocketDataProvider(&ssl);
642 socket_factory_.AddSSLSocketDataProvider(&ssl2);
643 socket_factory_.AddSSLSocketDataProvider(&ssl3);
644
645 enable_ssl_connect_job_waiting_ = true;
646 CreatePool(true, false, false);
647
648 scoped_refptr<SSLSocketParams> params1 =
649 SSLParams(ProxyServer::SCHEME_DIRECT, false);
650 scoped_refptr<SSLSocketParams> params2 =
651 SSLParams(ProxyServer::SCHEME_DIRECT, false);
652 scoped_refptr<SSLSocketParams> params3 =
653 SSLParams(ProxyServer::SCHEME_DIRECT, false);
654 ClientSocketHandle handle1;
655 ClientSocketHandle handle2;
656 ClientSocketHandle handle3;
657 TestCompletionCallback callback1;
658 TestCompletionCallback callback2;
659 TestCompletionCallback callback3;
660
661 handle1.Init(
662 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog());
663 handle2.Init(
664 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog());
665 handle3.Init(
666 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog());
667
668 // Allow the connections to proceed until the first socket has finished
669 // connecting.
670 base::RunLoop().RunUntilIdle();
671
672 std::vector<MockSSLClientSocket*> sockets =
673 socket_factory_.ssl_client_sockets();
674
675 EXPECT_TRUE(sockets[0]->IsConnected());
676
677 std::vector<MockSSLClientSocket*>::iterator it = sockets.begin();
678 // The first socket should be connected.
679 EXPECT_TRUE((*it)->IsConnected());
680 ++it;
681 // All other sockets should not be connected.
682 for (; it != sockets.end(); ++it) {
683 EXPECT_FALSE((*it)->IsConnected());
684 }
685
686 sockets[0]->RestartPausedConnect();
687
688 callback1.WaitForResult();
689 callback2.WaitForResult();
690 callback3.WaitForResult();
691
692 EXPECT_TRUE(handle1.socket()->IsConnected());
693 EXPECT_TRUE(handle2.socket()->IsConnected());
694 EXPECT_TRUE(handle3.socket()->IsConnected());
695 }
696
232 TEST_P(SSLClientSocketPoolTest, TCPFail) { 697 TEST_P(SSLClientSocketPoolTest, TCPFail) {
233 StaticSocketDataProvider data; 698 StaticSocketDataProvider data;
234 data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_CONNECTION_FAILED)); 699 data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_CONNECTION_FAILED));
235 socket_factory_.AddSocketDataProvider(&data); 700 socket_factory_.AddSocketDataProvider(&data);
236 701
237 CreatePool(true /* tcp pool */, false, false); 702 CreatePool(true /* tcp pool */, false, false);
238 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, 703 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT,
239 false); 704 false);
240 705
241 ClientSocketHandle handle; 706 ClientSocketHandle handle;
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 ssl.channel_id_sent = true; 1394 ssl.channel_id_sent = true;
930 ssl.SetNextProto(GetParam()); 1395 ssl.SetNextProto(GetParam());
931 TestIPPoolingDisabled(&ssl); 1396 TestIPPoolingDisabled(&ssl);
932 } 1397 }
933 1398
934 // It would be nice to also test the timeouts in SSLClientSocketPool. 1399 // It would be nice to also test the timeouts in SSLClientSocketPool.
935 1400
936 } // namespace 1401 } // namespace
937 1402
938 } // namespace net 1403 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698