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