OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_proxy_client_socket_pool.h" | 5 #include "net/http/http_proxy_client_socket_pool.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/run_loop.h" | |
9 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
12 #include "net/base/auth.h" | 13 #include "net/base/auth.h" |
13 #include "net/base/load_timing_info.h" | 14 #include "net/base/load_timing_info.h" |
14 #include "net/base/load_timing_info_test_util.h" | 15 #include "net/base/load_timing_info_test_util.h" |
15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
16 #include "net/base/test_completion_callback.h" | 17 #include "net/base/test_completion_callback.h" |
17 #include "net/cert/cert_verifier.h" | 18 #include "net/cert/cert_verifier.h" |
18 #include "net/dns/mock_host_resolver.h" | 19 #include "net/dns/mock_host_resolver.h" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 session_->http_auth_handler_factory(), | 118 session_->http_auth_handler_factory(), |
118 session_->spdy_session_pool(), | 119 session_->spdy_session_pool(), |
119 true)), | 120 true)), |
120 http_proxy_histograms_("MockHttpProxy"), | 121 http_proxy_histograms_("MockHttpProxy"), |
121 http_proxy_socket_pool_(kMaxSockets, | 122 http_proxy_socket_pool_(kMaxSockets, |
122 kMaxSocketsPerGroup, | 123 kMaxSocketsPerGroup, |
123 &http_proxy_histograms_, | 124 &http_proxy_histograms_, |
124 &host_resolver_, | 125 &host_resolver_, |
125 &transport_socket_pool_, | 126 &transport_socket_pool_, |
126 NULL, | 127 NULL, |
127 NULL) { | 128 NULL), |
129 enable_ssl_connect_job_waiting_(false) { | |
128 scoped_refptr<SSLConfigService> ssl_config_service( | 130 scoped_refptr<SSLConfigService> ssl_config_service( |
129 new SSLConfigServiceDefaults); | 131 new SSLConfigServiceDefaults); |
130 ssl_config_service->GetSSLConfig(&ssl_config_); | 132 ssl_config_service->GetSSLConfig(&ssl_config_); |
131 } | 133 } |
132 | 134 |
133 void CreatePool(bool transport_pool, bool http_proxy_pool, bool socks_pool) { | 135 void CreatePool(bool transport_pool, bool http_proxy_pool, bool socks_pool) { |
134 ssl_histograms_.reset(new ClientSocketPoolHistograms("SSLUnitTest")); | 136 ssl_histograms_.reset(new ClientSocketPoolHistograms("SSLUnitTest")); |
135 pool_.reset(new SSLClientSocketPool( | 137 pool_.reset(new SSLClientSocketPool( |
136 kMaxSockets, | 138 kMaxSockets, |
137 kMaxSocketsPerGroup, | 139 kMaxSocketsPerGroup, |
138 ssl_histograms_.get(), | 140 ssl_histograms_.get(), |
139 NULL /* host_resolver */, | 141 NULL /* host_resolver */, |
140 NULL /* cert_verifier */, | 142 NULL /* cert_verifier */, |
141 NULL /* server_bound_cert_service */, | 143 NULL /* server_bound_cert_service */, |
142 NULL /* transport_security_state */, | 144 NULL /* transport_security_state */, |
143 NULL /* cert_transparency_verifier */, | 145 NULL /* cert_transparency_verifier */, |
144 std::string() /* ssl_session_cache_shard */, | 146 std::string() /* ssl_session_cache_shard */, |
145 &socket_factory_, | 147 &socket_factory_, |
146 transport_pool ? &transport_socket_pool_ : NULL, | 148 transport_pool ? &transport_socket_pool_ : NULL, |
147 socks_pool ? &socks_socket_pool_ : NULL, | 149 socks_pool ? &socks_socket_pool_ : NULL, |
148 http_proxy_pool ? &http_proxy_socket_pool_ : NULL, | 150 http_proxy_pool ? &http_proxy_socket_pool_ : NULL, |
149 NULL, | 151 NULL, |
152 enable_ssl_connect_job_waiting_, | |
150 NULL)); | 153 NULL)); |
151 } | 154 } |
152 | 155 |
153 scoped_refptr<SSLSocketParams> SSLParams(ProxyServer::Scheme proxy, | 156 scoped_refptr<SSLSocketParams> SSLParams(ProxyServer::Scheme proxy, |
154 bool want_spdy_over_npn) { | 157 bool want_spdy_over_npn) { |
155 return make_scoped_refptr(new SSLSocketParams( | 158 return make_scoped_refptr(new SSLSocketParams( |
156 proxy == ProxyServer::SCHEME_DIRECT ? direct_transport_socket_params_ | 159 proxy == ProxyServer::SCHEME_DIRECT ? direct_transport_socket_params_ |
157 : NULL, | 160 : NULL, |
158 proxy == ProxyServer::SCHEME_SOCKS5 ? socks_socket_params_ : NULL, | 161 proxy == ProxyServer::SCHEME_SOCKS5 ? socks_socket_params_ : NULL, |
159 proxy == ProxyServer::SCHEME_HTTP ? http_proxy_socket_params_ : NULL, | 162 proxy == ProxyServer::SCHEME_HTTP ? http_proxy_socket_params_ : NULL, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 ClientSocketPoolHistograms socks_histograms_; | 217 ClientSocketPoolHistograms socks_histograms_; |
215 MockSOCKSClientSocketPool socks_socket_pool_; | 218 MockSOCKSClientSocketPool socks_socket_pool_; |
216 | 219 |
217 scoped_refptr<HttpProxySocketParams> http_proxy_socket_params_; | 220 scoped_refptr<HttpProxySocketParams> http_proxy_socket_params_; |
218 ClientSocketPoolHistograms http_proxy_histograms_; | 221 ClientSocketPoolHistograms http_proxy_histograms_; |
219 HttpProxyClientSocketPool http_proxy_socket_pool_; | 222 HttpProxyClientSocketPool http_proxy_socket_pool_; |
220 | 223 |
221 SSLConfig ssl_config_; | 224 SSLConfig ssl_config_; |
222 scoped_ptr<ClientSocketPoolHistograms> ssl_histograms_; | 225 scoped_ptr<ClientSocketPoolHistograms> ssl_histograms_; |
223 scoped_ptr<SSLClientSocketPool> pool_; | 226 scoped_ptr<SSLClientSocketPool> pool_; |
227 | |
228 bool enable_ssl_connect_job_waiting_; | |
224 }; | 229 }; |
225 | 230 |
226 INSTANTIATE_TEST_CASE_P( | 231 INSTANTIATE_TEST_CASE_P( |
227 NextProto, | 232 NextProto, |
228 SSLClientSocketPoolTest, | 233 SSLClientSocketPoolTest, |
229 testing::Values(kProtoDeprecatedSPDY2, | 234 testing::Values(kProtoDeprecatedSPDY2, |
230 kProtoSPDY3, kProtoSPDY31, kProtoSPDY4)); | 235 kProtoSPDY3, kProtoSPDY31, kProtoSPDY4)); |
231 | 236 |
237 // Tests that the final socket will connect even if all sockets | |
238 // prior to it fail. | |
239 // | |
240 // All sockets should wait for the first socket to attempt to | |
241 // connect. Once it fails to connect, all other sockets should | |
242 // attempt to connect. All should fail, except the final socket. | |
243 TEST_P(SSLClientSocketPoolTest, AllSocketsFailButLast) { | |
244 // 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)->DidReachConnect()); | |
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]->DidReachConnect()); | |
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*>::iterator it = sockets.begin(); | |
wtc
2014/07/31 02:02:25
Use const_iterator.
mshelley
2014/07/31 20:11:37
Done.
| |
595 | |
596 // The first socket should have had connect called on it. | |
wtc
2014/07/31 02:02:24
connect => Connect
mshelley
2014/07/31 20:11:37
Done.
| |
597 EXPECT_TRUE((*it)->DidReachConnect()); | |
598 ++it; | |
599 | |
600 // No other socket should have reached connected yet. | |
wtc
2014/07/31 02:02:24
connected => connect
mshelley
2014/07/31 20:11:37
Done.
| |
601 for (; it != sockets.end(); ++it) { | |
602 EXPECT_FALSE((*it)->DidReachConnect()); | |
603 } | |
wtc
2014/07/31 02:02:25
Omit curly braces.
mshelley
2014/07/31 20:11:37
Done.
| |
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. | |
wtc
2014/07/31 02:02:25
Update this comment -- "should have reached connec
mshelley
2014/07/31 20:11:37
Done.
| |
611 EXPECT_TRUE(sockets[1]->DidReachConnect()); | |
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 std::vector<MockSSLClientSocket*>::iterator it = sockets.begin(); | |
wtc
2014/07/31 02:02:24
Use const_iterator.
mshelley
2014/07/31 20:11:37
Done.
| |
676 // The first socket should have reached connect. | |
677 EXPECT_TRUE((*it)->DidReachConnect()); | |
678 ++it; | |
679 // All other sockets should not be connected. | |
wtc
2014/07/31 02:02:25
Change to: No other socket should have reached con
mshelley
2014/07/31 20:11:37
Done.
| |
680 for (; it != sockets.end(); ++it) { | |
681 EXPECT_FALSE((*it)->DidReachConnect()); | |
682 } | |
wtc
2014/07/31 02:02:25
Omit curly braces.
mshelley
2014/07/31 20:11:37
Done.
| |
683 | |
684 sockets[0]->RestartPausedConnect(); | |
685 | |
686 callback1.WaitForResult(); | |
687 callback2.WaitForResult(); | |
688 callback3.WaitForResult(); | |
689 | |
690 EXPECT_TRUE(handle1.socket()->IsConnected()); | |
691 EXPECT_TRUE(handle2.socket()->IsConnected()); | |
692 EXPECT_TRUE(handle3.socket()->IsConnected()); | |
693 } | |
694 | |
232 TEST_P(SSLClientSocketPoolTest, TCPFail) { | 695 TEST_P(SSLClientSocketPoolTest, TCPFail) { |
233 StaticSocketDataProvider data; | 696 StaticSocketDataProvider data; |
234 data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_CONNECTION_FAILED)); | 697 data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_CONNECTION_FAILED)); |
235 socket_factory_.AddSocketDataProvider(&data); | 698 socket_factory_.AddSocketDataProvider(&data); |
236 | 699 |
237 CreatePool(true /* tcp pool */, false, false); | 700 CreatePool(true /* tcp pool */, false, false); |
238 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, | 701 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, |
239 false); | 702 false); |
240 | 703 |
241 ClientSocketHandle handle; | 704 ClientSocketHandle handle; |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
929 ssl.channel_id_sent = true; | 1392 ssl.channel_id_sent = true; |
930 ssl.SetNextProto(GetParam()); | 1393 ssl.SetNextProto(GetParam()); |
931 TestIPPoolingDisabled(&ssl); | 1394 TestIPPoolingDisabled(&ssl); |
932 } | 1395 } |
933 | 1396 |
934 // It would be nice to also test the timeouts in SSLClientSocketPool. | 1397 // It would be nice to also test the timeouts in SSLClientSocketPool. |
935 | 1398 |
936 } // namespace | 1399 } // namespace |
937 | 1400 |
938 } // namespace net | 1401 } // namespace net |
OLD | NEW |