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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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) { |
128 scoped_refptr<SSLConfigService> ssl_config_service( | 129 scoped_refptr<SSLConfigService> ssl_config_service( |
129 new SSLConfigServiceDefaults); | 130 new SSLConfigServiceDefaults); |
130 ssl_config_service->GetSSLConfig(&ssl_config_); | 131 ssl_config_service->GetSSLConfig(&ssl_config_); |
131 } | 132 } |
132 | 133 |
133 void CreatePool(bool transport_pool, bool http_proxy_pool, bool socks_pool) { | 134 void CreatePool(bool transport_pool, |
135 bool http_proxy_pool, | |
136 bool socks_pool, | |
137 bool enable_ssl_connect_job_waiting = false) { | |
wtc
2014/07/23 22:53:33
Don't use default arguments. In general the Style
mshelley
2014/07/24 20:37:49
Done.
| |
134 ssl_histograms_.reset(new ClientSocketPoolHistograms("SSLUnitTest")); | 138 ssl_histograms_.reset(new ClientSocketPoolHistograms("SSLUnitTest")); |
135 pool_.reset(new SSLClientSocketPool( | 139 pool_.reset(new SSLClientSocketPool( |
136 kMaxSockets, | 140 kMaxSockets, |
137 kMaxSocketsPerGroup, | 141 kMaxSocketsPerGroup, |
138 ssl_histograms_.get(), | 142 ssl_histograms_.get(), |
139 NULL /* host_resolver */, | 143 NULL /* host_resolver */, |
140 NULL /* cert_verifier */, | 144 NULL /* cert_verifier */, |
141 NULL /* server_bound_cert_service */, | 145 NULL /* server_bound_cert_service */, |
142 NULL /* transport_security_state */, | 146 NULL /* transport_security_state */, |
143 NULL /* cert_transparency_verifier */, | 147 NULL /* cert_transparency_verifier */, |
144 std::string() /* ssl_session_cache_shard */, | 148 std::string() /* ssl_session_cache_shard */, |
145 &socket_factory_, | 149 &socket_factory_, |
146 transport_pool ? &transport_socket_pool_ : NULL, | 150 transport_pool ? &transport_socket_pool_ : NULL, |
147 socks_pool ? &socks_socket_pool_ : NULL, | 151 socks_pool ? &socks_socket_pool_ : NULL, |
148 http_proxy_pool ? &http_proxy_socket_pool_ : NULL, | 152 http_proxy_pool ? &http_proxy_socket_pool_ : NULL, |
149 NULL, | 153 NULL, |
154 enable_ssl_connect_job_waiting, | |
150 NULL)); | 155 NULL)); |
151 } | 156 } |
152 | 157 |
153 scoped_refptr<SSLSocketParams> SSLParams(ProxyServer::Scheme proxy, | 158 scoped_refptr<SSLSocketParams> SSLParams(ProxyServer::Scheme proxy, |
154 bool want_spdy_over_npn) { | 159 bool want_spdy_over_npn) { |
155 return make_scoped_refptr(new SSLSocketParams( | 160 return make_scoped_refptr(new SSLSocketParams( |
156 proxy == ProxyServer::SCHEME_DIRECT ? direct_transport_socket_params_ | 161 proxy == ProxyServer::SCHEME_DIRECT ? direct_transport_socket_params_ |
157 : NULL, | 162 : NULL, |
158 proxy == ProxyServer::SCHEME_SOCKS5 ? socks_socket_params_ : NULL, | 163 proxy == ProxyServer::SCHEME_SOCKS5 ? socks_socket_params_ : NULL, |
159 proxy == ProxyServer::SCHEME_HTTP ? http_proxy_socket_params_ : NULL, | 164 proxy == ProxyServer::SCHEME_HTTP ? http_proxy_socket_params_ : NULL, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 scoped_ptr<ClientSocketPoolHistograms> ssl_histograms_; | 227 scoped_ptr<ClientSocketPoolHistograms> ssl_histograms_; |
223 scoped_ptr<SSLClientSocketPool> pool_; | 228 scoped_ptr<SSLClientSocketPool> pool_; |
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 TEST_P(SSLClientSocketPoolTest, AllSocketsFailButLast) { | |
240 StaticSocketDataProvider data1; | |
241 StaticSocketDataProvider data2; | |
242 StaticSocketDataProvider data3; | |
243 StaticSocketDataProvider data4; | |
244 socket_factory_.AddSocketDataProvider(&data1); | |
245 socket_factory_.AddSocketDataProvider(&data2); | |
246 socket_factory_.AddSocketDataProvider(&data3); | |
247 socket_factory_.AddSocketDataProvider(&data4); | |
248 socket_factory_.AddSocketDataProvider(&data4); | |
249 socket_factory_.AddSocketDataProvider(&data4); | |
250 socket_factory_.AddSocketDataProvider(&data4); | |
251 socket_factory_.AddSocketDataProvider(&data4); | |
252 SSLSocketDataProvider ssl(ASYNC, ERR_SSL_PROTOCOL_ERROR); | |
253 ssl.is_in_session_cache = false; | |
254 SSLSocketDataProvider ssl2(ASYNC, ERR_SSL_PROTOCOL_ERROR); | |
255 ssl2.is_in_session_cache = true; | |
256 SSLSocketDataProvider ssl3(ASYNC, ERR_SSL_PROTOCOL_ERROR); | |
257 ssl3.is_in_session_cache = true; | |
258 SSLSocketDataProvider ssl4(ASYNC, OK); | |
259 ssl4.is_in_session_cache = true; | |
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(&ssl4); | |
266 socket_factory_.AddSSLSocketDataProvider(&ssl4); | |
267 socket_factory_.AddSSLSocketDataProvider(&ssl4); | |
268 socket_factory_.AddSSLSocketDataProvider(&ssl4); | |
269 | |
270 CreatePool(true, false, false, true); | |
271 | |
272 scoped_refptr<SSLSocketParams> params1 = | |
273 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
274 scoped_refptr<SSLSocketParams> params2 = | |
275 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
276 scoped_refptr<SSLSocketParams> params3 = | |
277 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
278 scoped_refptr<SSLSocketParams> params4 = | |
279 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
280 ClientSocketHandle handle1; | |
281 ClientSocketHandle handle2; | |
282 ClientSocketHandle handle3; | |
283 ClientSocketHandle handle4; | |
284 TestCompletionCallback callback1; | |
285 TestCompletionCallback callback2; | |
286 TestCompletionCallback callback3; | |
287 TestCompletionCallback callback4; | |
288 | |
289 handle1.Init( | |
290 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); | |
291 handle2.Init( | |
292 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); | |
293 handle3.Init( | |
294 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); | |
295 handle4.Init( | |
296 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); | |
297 | |
298 base::RunLoop().RunUntilIdle(); | |
299 | |
300 std::vector<MockSSLClientSocket*> sockets = | |
301 socket_factory_.ssl_client_sockets(); | |
302 | |
303 // Only the last socket should have connected. | |
304 EXPECT_FALSE(handle1.socket()); | |
305 EXPECT_FALSE(handle2.socket()); | |
306 EXPECT_FALSE(handle3.socket()); | |
307 EXPECT_TRUE(handle4.socket()->IsConnected()); | |
308 } | |
309 | |
310 // Tests that sockets will still connect in parellel if the | |
311 // EnableSSLConnectJobWaiting flag is not enabled. | |
312 TEST_P(SSLClientSocketPoolTest, SocketsConnectWithoutFlag) { | |
313 StaticSocketDataProvider data1; | |
314 StaticSocketDataProvider data2; | |
315 StaticSocketDataProvider data3; | |
316 socket_factory_.AddSocketDataProvider(&data1); | |
317 socket_factory_.AddSocketDataProvider(&data2); | |
318 socket_factory_.AddSocketDataProvider(&data3); | |
319 | |
320 SSLSocketDataProvider ssl(ASYNC, OK); | |
321 ssl.is_in_session_cache = false; | |
322 ssl.should_block_on_connect = true; | |
323 SSLSocketDataProvider ssl2(ASYNC, OK); | |
324 ssl2.is_in_session_cache = true; | |
325 ssl2.should_block_on_connect = true; | |
326 SSLSocketDataProvider ssl3(ASYNC, OK); | |
327 ssl3.is_in_session_cache = true; | |
328 ssl3.should_block_on_connect = true; | |
329 socket_factory_.AddSSLSocketDataProvider(&ssl); | |
330 socket_factory_.AddSSLSocketDataProvider(&ssl2); | |
331 socket_factory_.AddSSLSocketDataProvider(&ssl3); | |
332 | |
333 CreatePool(true, false, false); | |
334 | |
335 scoped_refptr<SSLSocketParams> params1 = | |
336 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
337 scoped_refptr<SSLSocketParams> params2 = | |
338 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
339 scoped_refptr<SSLSocketParams> params3 = | |
340 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
341 ClientSocketHandle handle1; | |
342 ClientSocketHandle handle2; | |
343 ClientSocketHandle handle3; | |
344 TestCompletionCallback callback1; | |
345 TestCompletionCallback callback2; | |
346 TestCompletionCallback callback3; | |
347 | |
348 handle1.Init( | |
349 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); | |
350 handle2.Init( | |
351 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); | |
352 handle3.Init( | |
353 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); | |
354 | |
355 base::RunLoop().RunUntilIdle(); | |
356 | |
357 std::vector<MockSSLClientSocket*> sockets = | |
358 socket_factory_.ssl_client_sockets(); | |
359 | |
360 // All sockets should have started their connections. | |
361 for (std::vector<MockSSLClientSocket*>::iterator it = sockets.begin(); | |
362 it != sockets.end(); | |
363 ++it) { | |
364 EXPECT_TRUE((*it)->IsConnected()); | |
365 (*it)->RestartPausedConnect(); | |
366 } | |
367 | |
368 callback3.WaitForResult(); | |
369 | |
370 EXPECT_TRUE(handle1.socket()->IsConnected()); | |
371 EXPECT_TRUE(handle2.socket()->IsConnected()); | |
372 EXPECT_TRUE(handle3.socket()->IsConnected()); | |
373 } | |
374 | |
375 // Tests that the pool deleting an SSLConnectJob will not cause a crash, | |
376 // or prevent pending sockets from connecting. | |
377 TEST_P(SSLClientSocketPoolTest, DeletedSSLConnectJob) { | |
378 StaticSocketDataProvider data1; | |
379 StaticSocketDataProvider data2; | |
380 StaticSocketDataProvider data3; | |
381 socket_factory_.AddSocketDataProvider(&data1); | |
382 socket_factory_.AddSocketDataProvider(&data2); | |
383 socket_factory_.AddSocketDataProvider(&data3); | |
384 | |
385 SSLSocketDataProvider ssl(ASYNC, OK); | |
386 ssl.is_in_session_cache = false; | |
387 ssl.should_block_on_connect = true; | |
388 SSLSocketDataProvider ssl2(ASYNC, OK); | |
389 ssl2.is_in_session_cache = false; | |
390 SSLSocketDataProvider ssl3(ASYNC, OK); | |
391 ssl3.is_in_session_cache = false; | |
392 socket_factory_.AddSSLSocketDataProvider(&ssl); | |
393 socket_factory_.AddSSLSocketDataProvider(&ssl2); | |
394 socket_factory_.AddSSLSocketDataProvider(&ssl3); | |
395 | |
396 CreatePool(true, false, false, true); | |
397 | |
398 scoped_refptr<SSLSocketParams> params1 = | |
399 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
400 scoped_refptr<SSLSocketParams> params2 = | |
401 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
402 scoped_refptr<SSLSocketParams> params3 = | |
403 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
404 ClientSocketHandle handle1; | |
405 ClientSocketHandle handle2; | |
406 ClientSocketHandle handle3; | |
407 TestCompletionCallback callback1; | |
408 TestCompletionCallback callback2; | |
409 TestCompletionCallback callback3; | |
410 | |
411 handle1.Init( | |
412 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); | |
413 handle2.Init( | |
414 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); | |
415 handle3.Init( | |
416 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); | |
417 | |
418 // Allow the connections to proceed until the first socket has started | |
419 // connecting. | |
420 base::RunLoop().RunUntilIdle(); | |
421 | |
422 std::vector<MockSSLClientSocket*> sockets = | |
423 socket_factory_.ssl_client_sockets(); | |
424 | |
425 pool_->CancelRequest("b", &handle2); | |
426 | |
427 sockets[0]->RestartPausedConnect(); | |
428 | |
429 callback3.WaitForResult(); | |
430 | |
431 EXPECT_TRUE(handle1.socket()->IsConnected()); | |
432 EXPECT_FALSE(handle2.socket()); | |
433 EXPECT_TRUE(handle3.socket()->IsConnected()); | |
434 } | |
435 | |
436 // Tests that all pending sockets still connect when the pool deletes a pending | |
437 // SSLConnectJob which immediately followed a failed leading connection. | |
438 TEST_P(SSLClientSocketPoolTest, DeletedSocketAfterFail) { | |
439 StaticSocketDataProvider data1; | |
440 StaticSocketDataProvider data2; | |
441 StaticSocketDataProvider data3; | |
442 socket_factory_.AddSocketDataProvider(&data1); | |
443 socket_factory_.AddSocketDataProvider(&data2); | |
444 socket_factory_.AddSocketDataProvider(&data3); | |
445 | |
446 SSLSocketDataProvider ssl(ASYNC, ERR_SSL_PROTOCOL_ERROR); | |
447 ssl.is_in_session_cache = false; | |
448 ssl.should_block_on_connect = true; | |
449 SSLSocketDataProvider ssl2(ASYNC, OK); | |
450 ssl2.is_in_session_cache = false; | |
451 SSLSocketDataProvider ssl3(ASYNC, OK); | |
452 ssl3.is_in_session_cache = false; | |
453 socket_factory_.AddSSLSocketDataProvider(&ssl); | |
454 socket_factory_.AddSSLSocketDataProvider(&ssl2); | |
455 socket_factory_.AddSSLSocketDataProvider(&ssl3); | |
456 | |
457 CreatePool(true, false, false, true); | |
458 | |
459 scoped_refptr<SSLSocketParams> params1 = | |
460 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
461 scoped_refptr<SSLSocketParams> params2 = | |
462 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
463 scoped_refptr<SSLSocketParams> params3 = | |
464 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
465 ClientSocketHandle handle1; | |
466 ClientSocketHandle handle2; | |
467 ClientSocketHandle handle3; | |
468 TestCompletionCallback callback1; | |
469 TestCompletionCallback callback2; | |
470 TestCompletionCallback callback3; | |
471 | |
472 handle1.Init( | |
473 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); | |
474 handle2.Init( | |
475 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); | |
476 handle3.Init( | |
477 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); | |
478 | |
479 // Allow the connections to proceed until the first socket has started | |
480 // connecting. | |
481 base::RunLoop().RunUntilIdle(); | |
482 | |
483 std::vector<MockSSLClientSocket*> sockets = | |
484 socket_factory_.ssl_client_sockets(); | |
485 | |
486 pool_->CancelRequest("b", &handle2); | |
487 | |
488 sockets[0]->RestartPausedConnect(); | |
489 | |
490 callback3.WaitForResult(); | |
491 | |
492 EXPECT_TRUE(handle1.socket()->IsConnected()); | |
493 EXPECT_FALSE(handle2.socket()); | |
494 EXPECT_TRUE(handle3.socket()->IsConnected()); | |
495 } | |
496 | |
497 // Make sure that sockets still connect after the leader socket's | |
498 // connection fails. | |
499 TEST_P(SSLClientSocketPoolTest, SimultaneousConnectJobsFail) { | |
500 StaticSocketDataProvider data1; | |
501 StaticSocketDataProvider data2; | |
502 StaticSocketDataProvider data3; | |
503 StaticSocketDataProvider data4; | |
504 StaticSocketDataProvider data5; | |
505 socket_factory_.AddSocketDataProvider(&data1); | |
506 socket_factory_.AddSocketDataProvider(&data2); | |
507 socket_factory_.AddSocketDataProvider(&data3); | |
508 socket_factory_.AddSocketDataProvider(&data4); | |
509 socket_factory_.AddSocketDataProvider(&data5); | |
510 SSLSocketDataProvider ssl(ASYNC, ERR_SSL_PROTOCOL_ERROR); | |
511 ssl.is_in_session_cache = false; | |
512 ssl.should_block_on_connect = true; | |
513 SSLSocketDataProvider ssl2(ASYNC, OK); | |
514 ssl2.is_in_session_cache = false; | |
515 ssl2.should_block_on_connect = true; | |
516 SSLSocketDataProvider ssl3(ASYNC, OK); | |
517 ssl3.is_in_session_cache = false; | |
518 SSLSocketDataProvider ssl4(ASYNC, OK); | |
519 ssl4.is_in_session_cache = false; | |
520 SSLSocketDataProvider ssl5(ASYNC, OK); | |
521 ssl5.is_in_session_cache = false; | |
522 | |
523 socket_factory_.AddSSLSocketDataProvider(&ssl); | |
524 socket_factory_.AddSSLSocketDataProvider(&ssl2); | |
525 socket_factory_.AddSSLSocketDataProvider(&ssl3); | |
526 socket_factory_.AddSSLSocketDataProvider(&ssl4); | |
527 socket_factory_.AddSSLSocketDataProvider(&ssl5); | |
528 | |
529 CreatePool(true, false, false, true); | |
530 scoped_refptr<SSLSocketParams> params1 = | |
531 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
532 scoped_refptr<SSLSocketParams> params2 = | |
533 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
534 scoped_refptr<SSLSocketParams> params3 = | |
535 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
536 scoped_refptr<SSLSocketParams> params4 = | |
537 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
538 ClientSocketHandle handle1; | |
539 ClientSocketHandle handle2; | |
540 ClientSocketHandle handle3; | |
541 ClientSocketHandle handle4; | |
542 TestCompletionCallback callback1; | |
543 TestCompletionCallback callback2; | |
544 TestCompletionCallback callback3; | |
545 TestCompletionCallback callback4; | |
546 handle1.Init( | |
547 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); | |
548 handle2.Init( | |
549 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); | |
550 handle3.Init( | |
551 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); | |
552 handle4.Init( | |
553 "b", params4, MEDIUM, callback4.callback(), pool_.get(), BoundNetLog()); | |
554 | |
555 base::RunLoop().RunUntilIdle(); | |
556 | |
557 std::vector<MockSSLClientSocket*> sockets = | |
558 socket_factory_.ssl_client_sockets(); | |
559 | |
560 // The first socket's connection should have failed, and no other sockets | |
561 // should have connected yet. | |
562 for (std::vector<MockSSLClientSocket*>::iterator it = sockets.begin(); | |
563 it != sockets.end(); | |
564 ++it) { | |
565 EXPECT_FALSE((*it)->IsConnected()); | |
566 } | |
567 | |
568 // Allow the first socket to resume it's connection process. | |
569 sockets[0]->RestartPausedConnect(); | |
570 | |
571 base::RunLoop().RunUntilIdle(); | |
572 | |
573 // The second socket should have connected. | |
574 EXPECT_TRUE(sockets[1]->IsConnected()); | |
575 | |
576 // Allow the second socket to continue its connection. | |
577 sockets[1]->RestartPausedConnect(); | |
578 | |
579 callback4.WaitForResult(); | |
580 | |
581 // Pending connections should ultimately succeed. | |
582 for (std::vector<MockSSLClientSocket*>::iterator it = ++sockets.begin(); | |
583 it != sockets.end(); | |
584 ++it) { | |
585 EXPECT_TRUE((*it)->IsConnected()); | |
586 } | |
587 } | |
588 | |
589 // Make sure that no sockets connect before the "leader" socket, | |
590 // given that the leader has a successful connection. | |
591 TEST_P(SSLClientSocketPoolTest, SimultaneousConnectJobsSuccess) { | |
592 StaticSocketDataProvider data1; | |
593 StaticSocketDataProvider data2; | |
594 StaticSocketDataProvider data3; | |
595 socket_factory_.AddSocketDataProvider(&data1); | |
596 socket_factory_.AddSocketDataProvider(&data2); | |
597 socket_factory_.AddSocketDataProvider(&data3); | |
598 | |
599 SSLSocketDataProvider ssl(ASYNC, OK); | |
600 ssl.is_in_session_cache = false; | |
601 ssl.should_block_on_connect = true; | |
602 SSLSocketDataProvider ssl2(ASYNC, OK); | |
603 ssl2.is_in_session_cache = false; | |
604 SSLSocketDataProvider ssl3(ASYNC, OK); | |
605 ssl3.is_in_session_cache = false; | |
606 socket_factory_.AddSSLSocketDataProvider(&ssl); | |
607 socket_factory_.AddSSLSocketDataProvider(&ssl2); | |
608 socket_factory_.AddSSLSocketDataProvider(&ssl3); | |
609 | |
610 CreatePool(true, false, false, true); | |
611 | |
612 scoped_refptr<SSLSocketParams> params1 = | |
613 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
614 scoped_refptr<SSLSocketParams> params2 = | |
615 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
616 scoped_refptr<SSLSocketParams> params3 = | |
617 SSLParams(ProxyServer::SCHEME_DIRECT, false); | |
618 ClientSocketHandle handle1; | |
619 ClientSocketHandle handle2; | |
620 ClientSocketHandle handle3; | |
621 TestCompletionCallback callback1; | |
622 TestCompletionCallback callback2; | |
623 TestCompletionCallback callback3; | |
624 | |
625 handle1.Init( | |
626 "b", params1, MEDIUM, callback1.callback(), pool_.get(), BoundNetLog()); | |
627 handle2.Init( | |
628 "b", params2, MEDIUM, callback2.callback(), pool_.get(), BoundNetLog()); | |
629 handle3.Init( | |
630 "b", params3, MEDIUM, callback3.callback(), pool_.get(), BoundNetLog()); | |
631 | |
632 // Allow the connections to proceed until the first socket has finished | |
633 // connecting. | |
634 base::RunLoop().RunUntilIdle(); | |
635 | |
636 std::vector<MockSSLClientSocket*> sockets = | |
637 socket_factory_.ssl_client_sockets(); | |
638 | |
639 EXPECT_TRUE(sockets[0]->IsConnected()); | |
640 for (std::vector<MockSSLClientSocket*>::iterator it = ++sockets.begin(); | |
641 it != sockets.end(); | |
642 ++it) { | |
643 EXPECT_FALSE((*it)->IsConnected()); | |
644 } | |
645 | |
646 sockets[0]->RestartPausedConnect(); | |
647 | |
648 callback3.WaitForResult(); | |
649 | |
650 EXPECT_TRUE(handle1.socket()->IsConnected()); | |
651 EXPECT_TRUE(handle2.socket()->IsConnected()); | |
652 EXPECT_TRUE(handle3.socket()->IsConnected()); | |
653 } | |
654 | |
232 TEST_P(SSLClientSocketPoolTest, TCPFail) { | 655 TEST_P(SSLClientSocketPoolTest, TCPFail) { |
233 StaticSocketDataProvider data; | 656 StaticSocketDataProvider data; |
234 data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_CONNECTION_FAILED)); | 657 data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_CONNECTION_FAILED)); |
235 socket_factory_.AddSocketDataProvider(&data); | 658 socket_factory_.AddSocketDataProvider(&data); |
236 | 659 |
237 CreatePool(true /* tcp pool */, false, false); | 660 CreatePool(true /* tcp pool */, false, false); |
238 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, | 661 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, |
239 false); | 662 false); |
240 | 663 |
241 ClientSocketHandle handle; | 664 ClientSocketHandle handle; |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
929 ssl.channel_id_sent = true; | 1352 ssl.channel_id_sent = true; |
930 ssl.SetNextProto(GetParam()); | 1353 ssl.SetNextProto(GetParam()); |
931 TestIPPoolingDisabled(&ssl); | 1354 TestIPPoolingDisabled(&ssl); |
932 } | 1355 } |
933 | 1356 |
934 // It would be nice to also test the timeouts in SSLClientSocketPool. | 1357 // It would be nice to also test the timeouts in SSLClientSocketPool. |
935 | 1358 |
936 } // namespace | 1359 } // namespace |
937 | 1360 |
938 } // namespace net | 1361 } // namespace net |
OLD | NEW |