OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 ClientSocketPoolHistograms http_proxy_histograms_; | 167 ClientSocketPoolHistograms http_proxy_histograms_; |
168 HttpProxyClientSocketPool http_proxy_socket_pool_; | 168 HttpProxyClientSocketPool http_proxy_socket_pool_; |
169 | 169 |
170 SSLConfig ssl_config_; | 170 SSLConfig ssl_config_; |
171 scoped_ptr<ClientSocketPoolHistograms> ssl_histograms_; | 171 scoped_ptr<ClientSocketPoolHistograms> ssl_histograms_; |
172 scoped_ptr<SSLClientSocketPool> pool_; | 172 scoped_ptr<SSLClientSocketPool> pool_; |
173 }; | 173 }; |
174 | 174 |
175 TEST_F(SSLClientSocketPoolTest, TCPFail) { | 175 TEST_F(SSLClientSocketPoolTest, TCPFail) { |
176 StaticSocketDataProvider data; | 176 StaticSocketDataProvider data; |
177 data.set_connect_data(MockConnect(false, ERR_CONNECTION_FAILED)); | 177 data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_CONNECTION_FAILED)); |
178 socket_factory_.AddSocketDataProvider(&data); | 178 socket_factory_.AddSocketDataProvider(&data); |
179 | 179 |
180 CreatePool(true /* tcp pool */, false, false); | 180 CreatePool(true /* tcp pool */, false, false); |
181 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, | 181 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, |
182 false); | 182 false); |
183 | 183 |
184 ClientSocketHandle handle; | 184 ClientSocketHandle handle; |
185 int rv = handle.Init("a", params, MEDIUM, CompletionCallback(), pool_.get(), | 185 int rv = handle.Init("a", params, MEDIUM, CompletionCallback(), pool_.get(), |
186 BoundNetLog()); | 186 BoundNetLog()); |
187 EXPECT_EQ(ERR_CONNECTION_FAILED, rv); | 187 EXPECT_EQ(ERR_CONNECTION_FAILED, rv); |
188 EXPECT_FALSE(handle.is_initialized()); | 188 EXPECT_FALSE(handle.is_initialized()); |
189 EXPECT_FALSE(handle.socket()); | 189 EXPECT_FALSE(handle.socket()); |
190 EXPECT_FALSE(handle.is_ssl_error()); | 190 EXPECT_FALSE(handle.is_ssl_error()); |
191 } | 191 } |
192 | 192 |
193 TEST_F(SSLClientSocketPoolTest, TCPFailAsync) { | 193 TEST_F(SSLClientSocketPoolTest, TCPFailAsync) { |
194 StaticSocketDataProvider data; | 194 StaticSocketDataProvider data; |
195 data.set_connect_data(MockConnect(true, ERR_CONNECTION_FAILED)); | 195 data.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_FAILED)); |
196 socket_factory_.AddSocketDataProvider(&data); | 196 socket_factory_.AddSocketDataProvider(&data); |
197 | 197 |
198 CreatePool(true /* tcp pool */, false, false); | 198 CreatePool(true /* tcp pool */, false, false); |
199 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, | 199 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, |
200 false); | 200 false); |
201 | 201 |
202 ClientSocketHandle handle; | 202 ClientSocketHandle handle; |
203 TestCompletionCallback callback; | 203 TestCompletionCallback callback; |
204 int rv = handle.Init( | 204 int rv = handle.Init( |
205 "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); | 205 "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); |
206 EXPECT_EQ(ERR_IO_PENDING, rv); | 206 EXPECT_EQ(ERR_IO_PENDING, rv); |
207 EXPECT_FALSE(handle.is_initialized()); | 207 EXPECT_FALSE(handle.is_initialized()); |
208 EXPECT_FALSE(handle.socket()); | 208 EXPECT_FALSE(handle.socket()); |
209 | 209 |
210 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); | 210 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); |
211 EXPECT_FALSE(handle.is_initialized()); | 211 EXPECT_FALSE(handle.is_initialized()); |
212 EXPECT_FALSE(handle.socket()); | 212 EXPECT_FALSE(handle.socket()); |
213 EXPECT_FALSE(handle.is_ssl_error()); | 213 EXPECT_FALSE(handle.is_ssl_error()); |
214 } | 214 } |
215 | 215 |
216 TEST_F(SSLClientSocketPoolTest, BasicDirect) { | 216 TEST_F(SSLClientSocketPoolTest, BasicDirect) { |
217 StaticSocketDataProvider data; | 217 StaticSocketDataProvider data; |
218 data.set_connect_data(MockConnect(false, OK)); | 218 data.set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
219 socket_factory_.AddSocketDataProvider(&data); | 219 socket_factory_.AddSocketDataProvider(&data); |
220 SSLSocketDataProvider ssl(false, OK); | 220 SSLSocketDataProvider ssl(false, OK); |
221 socket_factory_.AddSSLSocketDataProvider(&ssl); | 221 socket_factory_.AddSSLSocketDataProvider(&ssl); |
222 | 222 |
223 CreatePool(true /* tcp pool */, false, false); | 223 CreatePool(true /* tcp pool */, false, false); |
224 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, | 224 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_DIRECT, |
225 false); | 225 false); |
226 | 226 |
227 ClientSocketHandle handle; | 227 ClientSocketHandle handle; |
228 TestCompletionCallback callback; | 228 TestCompletionCallback callback; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 EXPECT_TRUE(ssl_socket->was_npn_negotiated()); | 421 EXPECT_TRUE(ssl_socket->was_npn_negotiated()); |
422 std::string proto; | 422 std::string proto; |
423 std::string server_protos; | 423 std::string server_protos; |
424 ssl_socket->GetNextProto(&proto, &server_protos); | 424 ssl_socket->GetNextProto(&proto, &server_protos); |
425 EXPECT_EQ(SSLClientSocket::NextProtoFromString(proto), | 425 EXPECT_EQ(SSLClientSocket::NextProtoFromString(proto), |
426 SSLClientSocket::kProtoSPDY21); | 426 SSLClientSocket::kProtoSPDY21); |
427 } | 427 } |
428 | 428 |
429 TEST_F(SSLClientSocketPoolTest, SOCKSFail) { | 429 TEST_F(SSLClientSocketPoolTest, SOCKSFail) { |
430 StaticSocketDataProvider data; | 430 StaticSocketDataProvider data; |
431 data.set_connect_data(MockConnect(false, ERR_CONNECTION_FAILED)); | 431 data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_CONNECTION_FAILED)); |
432 socket_factory_.AddSocketDataProvider(&data); | 432 socket_factory_.AddSocketDataProvider(&data); |
433 | 433 |
434 CreatePool(false, true /* http proxy pool */, true /* socks pool */); | 434 CreatePool(false, true /* http proxy pool */, true /* socks pool */); |
435 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_SOCKS5, | 435 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_SOCKS5, |
436 false); | 436 false); |
437 | 437 |
438 ClientSocketHandle handle; | 438 ClientSocketHandle handle; |
439 TestCompletionCallback callback; | 439 TestCompletionCallback callback; |
440 int rv = handle.Init( | 440 int rv = handle.Init( |
441 "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); | 441 "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); |
442 EXPECT_EQ(ERR_CONNECTION_FAILED, rv); | 442 EXPECT_EQ(ERR_CONNECTION_FAILED, rv); |
443 EXPECT_FALSE(handle.is_initialized()); | 443 EXPECT_FALSE(handle.is_initialized()); |
444 EXPECT_FALSE(handle.socket()); | 444 EXPECT_FALSE(handle.socket()); |
445 EXPECT_FALSE(handle.is_ssl_error()); | 445 EXPECT_FALSE(handle.is_ssl_error()); |
446 } | 446 } |
447 | 447 |
448 TEST_F(SSLClientSocketPoolTest, SOCKSFailAsync) { | 448 TEST_F(SSLClientSocketPoolTest, SOCKSFailAsync) { |
449 StaticSocketDataProvider data; | 449 StaticSocketDataProvider data; |
450 data.set_connect_data(MockConnect(true, ERR_CONNECTION_FAILED)); | 450 data.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_FAILED)); |
451 socket_factory_.AddSocketDataProvider(&data); | 451 socket_factory_.AddSocketDataProvider(&data); |
452 | 452 |
453 CreatePool(false, true /* http proxy pool */, true /* socks pool */); | 453 CreatePool(false, true /* http proxy pool */, true /* socks pool */); |
454 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_SOCKS5, | 454 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_SOCKS5, |
455 false); | 455 false); |
456 | 456 |
457 ClientSocketHandle handle; | 457 ClientSocketHandle handle; |
458 TestCompletionCallback callback; | 458 TestCompletionCallback callback; |
459 int rv = handle.Init( | 459 int rv = handle.Init( |
460 "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); | 460 "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); |
461 EXPECT_EQ(ERR_IO_PENDING, rv); | 461 EXPECT_EQ(ERR_IO_PENDING, rv); |
462 EXPECT_FALSE(handle.is_initialized()); | 462 EXPECT_FALSE(handle.is_initialized()); |
463 EXPECT_FALSE(handle.socket()); | 463 EXPECT_FALSE(handle.socket()); |
464 | 464 |
465 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); | 465 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); |
466 EXPECT_FALSE(handle.is_initialized()); | 466 EXPECT_FALSE(handle.is_initialized()); |
467 EXPECT_FALSE(handle.socket()); | 467 EXPECT_FALSE(handle.socket()); |
468 EXPECT_FALSE(handle.is_ssl_error()); | 468 EXPECT_FALSE(handle.is_ssl_error()); |
469 } | 469 } |
470 | 470 |
471 TEST_F(SSLClientSocketPoolTest, SOCKSBasic) { | 471 TEST_F(SSLClientSocketPoolTest, SOCKSBasic) { |
472 StaticSocketDataProvider data; | 472 StaticSocketDataProvider data; |
473 data.set_connect_data(MockConnect(false, OK)); | 473 data.set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
474 socket_factory_.AddSocketDataProvider(&data); | 474 socket_factory_.AddSocketDataProvider(&data); |
475 SSLSocketDataProvider ssl(false, OK); | 475 SSLSocketDataProvider ssl(false, OK); |
476 socket_factory_.AddSSLSocketDataProvider(&ssl); | 476 socket_factory_.AddSSLSocketDataProvider(&ssl); |
477 | 477 |
478 CreatePool(false, true /* http proxy pool */, true /* socks pool */); | 478 CreatePool(false, true /* http proxy pool */, true /* socks pool */); |
479 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_SOCKS5, | 479 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_SOCKS5, |
480 false); | 480 false); |
481 | 481 |
482 ClientSocketHandle handle; | 482 ClientSocketHandle handle; |
483 TestCompletionCallback callback; | 483 TestCompletionCallback callback; |
(...skipping 22 matching lines...) Expand all Loading... |
506 EXPECT_FALSE(handle.is_initialized()); | 506 EXPECT_FALSE(handle.is_initialized()); |
507 EXPECT_FALSE(handle.socket()); | 507 EXPECT_FALSE(handle.socket()); |
508 | 508 |
509 EXPECT_EQ(OK, callback.WaitForResult()); | 509 EXPECT_EQ(OK, callback.WaitForResult()); |
510 EXPECT_TRUE(handle.is_initialized()); | 510 EXPECT_TRUE(handle.is_initialized()); |
511 EXPECT_TRUE(handle.socket()); | 511 EXPECT_TRUE(handle.socket()); |
512 } | 512 } |
513 | 513 |
514 TEST_F(SSLClientSocketPoolTest, HttpProxyFail) { | 514 TEST_F(SSLClientSocketPoolTest, HttpProxyFail) { |
515 StaticSocketDataProvider data; | 515 StaticSocketDataProvider data; |
516 data.set_connect_data(MockConnect(false, ERR_CONNECTION_FAILED)); | 516 data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_CONNECTION_FAILED)); |
517 socket_factory_.AddSocketDataProvider(&data); | 517 socket_factory_.AddSocketDataProvider(&data); |
518 | 518 |
519 CreatePool(false, true /* http proxy pool */, true /* socks pool */); | 519 CreatePool(false, true /* http proxy pool */, true /* socks pool */); |
520 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_HTTP, | 520 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_HTTP, |
521 false); | 521 false); |
522 | 522 |
523 ClientSocketHandle handle; | 523 ClientSocketHandle handle; |
524 TestCompletionCallback callback; | 524 TestCompletionCallback callback; |
525 int rv = handle.Init( | 525 int rv = handle.Init( |
526 "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); | 526 "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); |
527 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); | 527 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, rv); |
528 EXPECT_FALSE(handle.is_initialized()); | 528 EXPECT_FALSE(handle.is_initialized()); |
529 EXPECT_FALSE(handle.socket()); | 529 EXPECT_FALSE(handle.socket()); |
530 EXPECT_FALSE(handle.is_ssl_error()); | 530 EXPECT_FALSE(handle.is_ssl_error()); |
531 } | 531 } |
532 | 532 |
533 TEST_F(SSLClientSocketPoolTest, HttpProxyFailAsync) { | 533 TEST_F(SSLClientSocketPoolTest, HttpProxyFailAsync) { |
534 StaticSocketDataProvider data; | 534 StaticSocketDataProvider data; |
535 data.set_connect_data(MockConnect(true, ERR_CONNECTION_FAILED)); | 535 data.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_FAILED)); |
536 socket_factory_.AddSocketDataProvider(&data); | 536 socket_factory_.AddSocketDataProvider(&data); |
537 | 537 |
538 CreatePool(false, true /* http proxy pool */, true /* socks pool */); | 538 CreatePool(false, true /* http proxy pool */, true /* socks pool */); |
539 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_HTTP, | 539 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_HTTP, |
540 false); | 540 false); |
541 | 541 |
542 ClientSocketHandle handle; | 542 ClientSocketHandle handle; |
543 TestCompletionCallback callback; | 543 TestCompletionCallback callback; |
544 int rv = handle.Init( | 544 int rv = handle.Init( |
545 "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); | 545 "a", params, MEDIUM, callback.callback(), pool_.get(), BoundNetLog()); |
(...skipping 13 matching lines...) Expand all Loading... |
559 "CONNECT host:80 HTTP/1.1\r\n" | 559 "CONNECT host:80 HTTP/1.1\r\n" |
560 "Host: host\r\n" | 560 "Host: host\r\n" |
561 "Proxy-Connection: keep-alive\r\n" | 561 "Proxy-Connection: keep-alive\r\n" |
562 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), | 562 "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
563 }; | 563 }; |
564 MockRead reads[] = { | 564 MockRead reads[] = { |
565 MockRead(false, "HTTP/1.1 200 Connection Established\r\n\r\n"), | 565 MockRead(false, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
566 }; | 566 }; |
567 StaticSocketDataProvider data(reads, arraysize(reads), writes, | 567 StaticSocketDataProvider data(reads, arraysize(reads), writes, |
568 arraysize(writes)); | 568 arraysize(writes)); |
569 data.set_connect_data(MockConnect(false, OK)); | 569 data.set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
570 socket_factory_.AddSocketDataProvider(&data); | 570 socket_factory_.AddSocketDataProvider(&data); |
571 AddAuthToCache(); | 571 AddAuthToCache(); |
572 SSLSocketDataProvider ssl(false, OK); | 572 SSLSocketDataProvider ssl(false, OK); |
573 socket_factory_.AddSSLSocketDataProvider(&ssl); | 573 socket_factory_.AddSSLSocketDataProvider(&ssl); |
574 | 574 |
575 CreatePool(false, true /* http proxy pool */, true /* socks pool */); | 575 CreatePool(false, true /* http proxy pool */, true /* socks pool */); |
576 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_HTTP, | 576 scoped_refptr<SSLSocketParams> params = SSLParams(ProxyServer::SCHEME_HTTP, |
577 false); | 577 false); |
578 | 578 |
579 ClientSocketHandle handle; | 579 ClientSocketHandle handle; |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 EXPECT_FALSE(session_->spdy_session_pool()->HasSession(test_hosts[1].pair)); | 831 EXPECT_FALSE(session_->spdy_session_pool()->HasSession(test_hosts[1].pair)); |
832 | 832 |
833 session_->spdy_session_pool()->CloseAllSessions(); | 833 session_->spdy_session_pool()->CloseAllSessions(); |
834 } | 834 } |
835 | 835 |
836 // It would be nice to also test the timeouts in SSLClientSocketPool. | 836 // It would be nice to also test the timeouts in SSLClientSocketPool. |
837 | 837 |
838 } // namespace | 838 } // namespace |
839 | 839 |
840 } // namespace net | 840 } // namespace net |
OLD | NEW |