OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/socket/tcp_client_socket_pool.h" | 5 #include "net/socket/tcp_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/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "net/base/mock_host_resolver.h" | 10 #include "net/base/mock_host_resolver.h" |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 scoped_refptr<MockHostResolver> host_resolver_; | 275 scoped_refptr<MockHostResolver> host_resolver_; |
276 MockClientSocketFactory client_socket_factory_; | 276 MockClientSocketFactory client_socket_factory_; |
277 MockNetworkChangeNotifier notifier_; | 277 MockNetworkChangeNotifier notifier_; |
278 scoped_refptr<TCPClientSocketPool> pool_; | 278 scoped_refptr<TCPClientSocketPool> pool_; |
279 }; | 279 }; |
280 | 280 |
281 TEST_F(TCPClientSocketPoolTest, Basic) { | 281 TEST_F(TCPClientSocketPoolTest, Basic) { |
282 TestCompletionCallback callback; | 282 TestCompletionCallback callback; |
283 ClientSocketHandle handle; | 283 ClientSocketHandle handle; |
284 TCPSocketParams dest("www.google.com", 80, LOW, GURL(), false); | 284 TCPSocketParams dest("www.google.com", 80, LOW, GURL(), false); |
285 int rv = handle.Init("a", dest, LOW, &callback, pool_, NULL); | 285 int rv = handle.Init("a", dest, LOW, &callback, pool_, BoundNetLog()); |
286 EXPECT_EQ(ERR_IO_PENDING, rv); | 286 EXPECT_EQ(ERR_IO_PENDING, rv); |
287 EXPECT_FALSE(handle.is_initialized()); | 287 EXPECT_FALSE(handle.is_initialized()); |
288 EXPECT_FALSE(handle.socket()); | 288 EXPECT_FALSE(handle.socket()); |
289 | 289 |
290 EXPECT_EQ(OK, callback.WaitForResult()); | 290 EXPECT_EQ(OK, callback.WaitForResult()); |
291 EXPECT_TRUE(handle.is_initialized()); | 291 EXPECT_TRUE(handle.is_initialized()); |
292 EXPECT_TRUE(handle.socket()); | 292 EXPECT_TRUE(handle.socket()); |
293 | 293 |
294 handle.Reset(); | 294 handle.Reset(); |
295 } | 295 } |
296 | 296 |
297 TEST_F(TCPClientSocketPoolTest, InitHostResolutionFailure) { | 297 TEST_F(TCPClientSocketPoolTest, InitHostResolutionFailure) { |
298 host_resolver_->rules()->AddSimulatedFailure("unresolvable.host.name"); | 298 host_resolver_->rules()->AddSimulatedFailure("unresolvable.host.name"); |
299 TestSocketRequest req(&request_order_, &completion_count_); | 299 TestSocketRequest req(&request_order_, &completion_count_); |
300 TCPSocketParams dest("unresolvable.host.name", 80, kDefaultPriority, GURL(), | 300 TCPSocketParams dest("unresolvable.host.name", 80, kDefaultPriority, GURL(), |
301 false); | 301 false); |
302 EXPECT_EQ(ERR_IO_PENDING, | 302 EXPECT_EQ(ERR_IO_PENDING, |
303 req.handle()->Init("a", dest, kDefaultPriority, &req, pool_, NULL)); | 303 req.handle()->Init("a", dest, kDefaultPriority, &req, pool_, |
| 304 BoundNetLog())); |
304 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req.WaitForResult()); | 305 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, req.WaitForResult()); |
305 } | 306 } |
306 | 307 |
307 TEST_F(TCPClientSocketPoolTest, InitConnectionFailure) { | 308 TEST_F(TCPClientSocketPoolTest, InitConnectionFailure) { |
308 client_socket_factory_.set_client_socket_type( | 309 client_socket_factory_.set_client_socket_type( |
309 MockClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET); | 310 MockClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET); |
310 TestSocketRequest req(&request_order_, &completion_count_); | 311 TestSocketRequest req(&request_order_, &completion_count_); |
311 TCPSocketParams dest("a", 80, kDefaultPriority, GURL(), false); | 312 TCPSocketParams dest("a", 80, kDefaultPriority, GURL(), false); |
312 EXPECT_EQ(ERR_IO_PENDING, | 313 EXPECT_EQ(ERR_IO_PENDING, |
313 req.handle()->Init("a", dest, kDefaultPriority, &req, pool_, NULL)); | 314 req.handle()->Init("a", dest, kDefaultPriority, &req, pool_, |
| 315 BoundNetLog())); |
314 EXPECT_EQ(ERR_CONNECTION_FAILED, req.WaitForResult()); | 316 EXPECT_EQ(ERR_CONNECTION_FAILED, req.WaitForResult()); |
315 | 317 |
316 // Make the host resolutions complete synchronously this time. | 318 // Make the host resolutions complete synchronously this time. |
317 host_resolver_->set_synchronous_mode(true); | 319 host_resolver_->set_synchronous_mode(true); |
318 EXPECT_EQ(ERR_CONNECTION_FAILED, | 320 EXPECT_EQ(ERR_CONNECTION_FAILED, |
319 req.handle()->Init("a", dest, kDefaultPriority, &req, pool_, NULL)); | 321 req.handle()->Init("a", dest, kDefaultPriority, &req, pool_, |
| 322 BoundNetLog())); |
320 } | 323 } |
321 | 324 |
322 TEST_F(TCPClientSocketPoolTest, PendingRequests) { | 325 TEST_F(TCPClientSocketPoolTest, PendingRequests) { |
323 // First request finishes asynchronously. | 326 // First request finishes asynchronously. |
324 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 327 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
325 EXPECT_EQ(OK, requests_[0]->WaitForResult()); | 328 EXPECT_EQ(OK, requests_[0]->WaitForResult()); |
326 | 329 |
327 // Make all subsequent host resolutions complete synchronously. | 330 // Make all subsequent host resolutions complete synchronously. |
328 host_resolver_->set_synchronous_mode(true); | 331 host_resolver_->set_synchronous_mode(true); |
329 | 332 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 EXPECT_EQ(6U, completion_count_); | 418 EXPECT_EQ(6U, completion_count_); |
416 } | 419 } |
417 | 420 |
418 // This test will start up a RequestSocket() and then immediately Cancel() it. | 421 // This test will start up a RequestSocket() and then immediately Cancel() it. |
419 // The pending host resolution will eventually complete, and destroy the | 422 // The pending host resolution will eventually complete, and destroy the |
420 // ClientSocketPool which will crash if the group was not cleared properly. | 423 // ClientSocketPool which will crash if the group was not cleared properly. |
421 TEST_F(TCPClientSocketPoolTest, CancelRequestClearGroup) { | 424 TEST_F(TCPClientSocketPoolTest, CancelRequestClearGroup) { |
422 TestSocketRequest req(&request_order_, &completion_count_); | 425 TestSocketRequest req(&request_order_, &completion_count_); |
423 TCPSocketParams dest("www.google.com", 80, kDefaultPriority, GURL(), false); | 426 TCPSocketParams dest("www.google.com", 80, kDefaultPriority, GURL(), false); |
424 EXPECT_EQ(ERR_IO_PENDING, | 427 EXPECT_EQ(ERR_IO_PENDING, |
425 req.handle()->Init("a", dest, kDefaultPriority, &req, pool_, NULL)); | 428 req.handle()->Init("a", dest, kDefaultPriority, &req, pool_, |
| 429 BoundNetLog())); |
426 req.handle()->Reset(); | 430 req.handle()->Reset(); |
427 | 431 |
428 // There is a race condition here. If the worker pool doesn't post the task | 432 // There is a race condition here. If the worker pool doesn't post the task |
429 // before we get here, then this might not run ConnectingSocket::OnIOComplete | 433 // before we get here, then this might not run ConnectingSocket::OnIOComplete |
430 // and therefore leak the canceled ConnectingSocket. However, other tests | 434 // and therefore leak the canceled ConnectingSocket. However, other tests |
431 // after this will call MessageLoop::RunAllPending() which should prevent a | 435 // after this will call MessageLoop::RunAllPending() which should prevent a |
432 // leak, unless the worker thread takes longer than all of them. | 436 // leak, unless the worker thread takes longer than all of them. |
433 PlatformThread::Sleep(10); | 437 PlatformThread::Sleep(10); |
434 MessageLoop::current()->RunAllPending(); | 438 MessageLoop::current()->RunAllPending(); |
435 } | 439 } |
436 | 440 |
437 TEST_F(TCPClientSocketPoolTest, TwoRequestsCancelOne) { | 441 TEST_F(TCPClientSocketPoolTest, TwoRequestsCancelOne) { |
438 TestSocketRequest req(&request_order_, &completion_count_); | 442 TestSocketRequest req(&request_order_, &completion_count_); |
439 TestSocketRequest req2(&request_order_, &completion_count_); | 443 TestSocketRequest req2(&request_order_, &completion_count_); |
440 | 444 |
441 TCPSocketParams dest("www.google.com", 80, kDefaultPriority, GURL(), false); | 445 TCPSocketParams dest("www.google.com", 80, kDefaultPriority, GURL(), false); |
442 EXPECT_EQ(ERR_IO_PENDING, | 446 EXPECT_EQ(ERR_IO_PENDING, |
443 req.handle()->Init("a", dest, kDefaultPriority, &req, pool_, NULL)); | 447 req.handle()->Init("a", dest, kDefaultPriority, &req, pool_, |
| 448 BoundNetLog())); |
444 EXPECT_EQ(ERR_IO_PENDING, | 449 EXPECT_EQ(ERR_IO_PENDING, |
445 req2.handle()->Init("a", dest, kDefaultPriority, &req2, pool_, NULL)
); | 450 req2.handle()->Init("a", dest, kDefaultPriority, &req2, pool_, |
| 451 BoundNetLog())); |
446 | 452 |
447 req.handle()->Reset(); | 453 req.handle()->Reset(); |
448 | 454 |
449 EXPECT_EQ(OK, req2.WaitForResult()); | 455 EXPECT_EQ(OK, req2.WaitForResult()); |
450 req2.handle()->Reset(); | 456 req2.handle()->Reset(); |
451 } | 457 } |
452 | 458 |
453 TEST_F(TCPClientSocketPoolTest, ConnectCancelConnect) { | 459 TEST_F(TCPClientSocketPoolTest, ConnectCancelConnect) { |
454 client_socket_factory_.set_client_socket_type( | 460 client_socket_factory_.set_client_socket_type( |
455 MockClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET); | 461 MockClientSocketFactory::MOCK_PENDING_CLIENT_SOCKET); |
456 ClientSocketHandle handle; | 462 ClientSocketHandle handle; |
457 TestCompletionCallback callback; | 463 TestCompletionCallback callback; |
458 TestSocketRequest req(&request_order_, &completion_count_); | 464 TestSocketRequest req(&request_order_, &completion_count_); |
459 | 465 |
460 TCPSocketParams dest("www.google.com", 80, kDefaultPriority, GURL(), false); | 466 TCPSocketParams dest("www.google.com", 80, kDefaultPriority, GURL(), false); |
461 EXPECT_EQ(ERR_IO_PENDING, | 467 EXPECT_EQ(ERR_IO_PENDING, |
462 handle.Init("a", dest, kDefaultPriority, &callback, pool_, NULL)); | 468 handle.Init("a", dest, kDefaultPriority, &callback, pool_, |
| 469 BoundNetLog())); |
463 | 470 |
464 handle.Reset(); | 471 handle.Reset(); |
465 | 472 |
466 TestCompletionCallback callback2; | 473 TestCompletionCallback callback2; |
467 EXPECT_EQ(ERR_IO_PENDING, | 474 EXPECT_EQ(ERR_IO_PENDING, |
468 handle.Init("a", dest, kDefaultPriority, &callback2, pool_, NULL)); | 475 handle.Init("a", dest, kDefaultPriority, &callback2, pool_, |
| 476 BoundNetLog())); |
469 | 477 |
470 host_resolver_->set_synchronous_mode(true); | 478 host_resolver_->set_synchronous_mode(true); |
471 // At this point, handle has two ConnectingSockets out for it. Due to the | 479 // At this point, handle has two ConnectingSockets out for it. Due to the |
472 // setting the mock resolver into synchronous mode, the host resolution for | 480 // setting the mock resolver into synchronous mode, the host resolution for |
473 // both will return in the same loop of the MessageLoop. The client socket | 481 // both will return in the same loop of the MessageLoop. The client socket |
474 // is a pending socket, so the Connect() will asynchronously complete on the | 482 // is a pending socket, so the Connect() will asynchronously complete on the |
475 // next loop of the MessageLoop. That means that the first | 483 // next loop of the MessageLoop. That means that the first |
476 // ConnectingSocket will enter OnIOComplete, and then the second one will. | 484 // ConnectingSocket will enter OnIOComplete, and then the second one will. |
477 // If the first one is not cancelled, it will advance the load state, and | 485 // If the first one is not cancelled, it will advance the load state, and |
478 // then the second one will crash. | 486 // then the second one will crash. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 // run through the MessageLoop once to get it completely released. | 565 // run through the MessageLoop once to get it completely released. |
558 handle_->socket()->Disconnect(); | 566 handle_->socket()->Disconnect(); |
559 handle_->Reset(); | 567 handle_->Reset(); |
560 { | 568 { |
561 MessageLoop::ScopedNestableTaskAllower nestable( | 569 MessageLoop::ScopedNestableTaskAllower nestable( |
562 MessageLoop::current()); | 570 MessageLoop::current()); |
563 MessageLoop::current()->RunAllPending(); | 571 MessageLoop::current()->RunAllPending(); |
564 } | 572 } |
565 within_callback_ = true; | 573 within_callback_ = true; |
566 TCPSocketParams dest("www.google.com", 80, LOWEST, GURL(), false); | 574 TCPSocketParams dest("www.google.com", 80, LOWEST, GURL(), false); |
567 int rv = handle_->Init("a", dest, LOWEST, this, pool_, NULL); | 575 int rv = handle_->Init("a", dest, LOWEST, this, pool_, BoundNetLog()); |
568 EXPECT_EQ(OK, rv); | 576 EXPECT_EQ(OK, rv); |
569 } | 577 } |
570 } | 578 } |
571 | 579 |
572 int WaitForResult() { | 580 int WaitForResult() { |
573 return callback_.WaitForResult(); | 581 return callback_.WaitForResult(); |
574 } | 582 } |
575 | 583 |
576 private: | 584 private: |
577 ClientSocketHandle* const handle_; | 585 ClientSocketHandle* const handle_; |
578 const scoped_refptr<TCPClientSocketPool> pool_; | 586 const scoped_refptr<TCPClientSocketPool> pool_; |
579 bool within_callback_; | 587 bool within_callback_; |
580 TestCompletionCallback callback_; | 588 TestCompletionCallback callback_; |
581 }; | 589 }; |
582 | 590 |
583 TEST_F(TCPClientSocketPoolTest, RequestTwice) { | 591 TEST_F(TCPClientSocketPoolTest, RequestTwice) { |
584 ClientSocketHandle handle; | 592 ClientSocketHandle handle; |
585 RequestSocketCallback callback(&handle, pool_.get()); | 593 RequestSocketCallback callback(&handle, pool_.get()); |
586 TCPSocketParams dest("www.google.com", 80, LOWEST, GURL(), false); | 594 TCPSocketParams dest("www.google.com", 80, LOWEST, GURL(), false); |
587 int rv = handle.Init("a", dest, LOWEST, &callback, pool_, NULL); | 595 int rv = handle.Init("a", dest, LOWEST, &callback, pool_, BoundNetLog()); |
588 ASSERT_EQ(ERR_IO_PENDING, rv); | 596 ASSERT_EQ(ERR_IO_PENDING, rv); |
589 | 597 |
590 // The callback is going to request "www.google.com". We want it to complete | 598 // The callback is going to request "www.google.com". We want it to complete |
591 // synchronously this time. | 599 // synchronously this time. |
592 host_resolver_->set_synchronous_mode(true); | 600 host_resolver_->set_synchronous_mode(true); |
593 | 601 |
594 EXPECT_EQ(OK, callback.WaitForResult()); | 602 EXPECT_EQ(OK, callback.WaitForResult()); |
595 | 603 |
596 handle.Reset(); | 604 handle.Reset(); |
597 } | 605 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); | 648 EXPECT_EQ(ERR_IO_PENDING, StartRequest("a", kDefaultPriority)); |
641 | 649 |
642 for (int i = 0; i < kNumRequests; i++) | 650 for (int i = 0; i < kNumRequests; i++) |
643 EXPECT_EQ(ERR_CONNECTION_FAILED, requests_[i]->WaitForResult()); | 651 EXPECT_EQ(ERR_CONNECTION_FAILED, requests_[i]->WaitForResult()); |
644 } | 652 } |
645 | 653 |
646 TEST_F(TCPClientSocketPoolTest, ResetIdleSocketsOnIPAddressChange) { | 654 TEST_F(TCPClientSocketPoolTest, ResetIdleSocketsOnIPAddressChange) { |
647 TestCompletionCallback callback; | 655 TestCompletionCallback callback; |
648 ClientSocketHandle handle; | 656 ClientSocketHandle handle; |
649 TCPSocketParams dest("www.google.com", 80, LOW, GURL(), false); | 657 TCPSocketParams dest("www.google.com", 80, LOW, GURL(), false); |
650 int rv = handle.Init("a", dest, LOW, &callback, pool_, NULL); | 658 int rv = handle.Init("a", dest, LOW, &callback, pool_, BoundNetLog()); |
651 EXPECT_EQ(ERR_IO_PENDING, rv); | 659 EXPECT_EQ(ERR_IO_PENDING, rv); |
652 EXPECT_FALSE(handle.is_initialized()); | 660 EXPECT_FALSE(handle.is_initialized()); |
653 EXPECT_FALSE(handle.socket()); | 661 EXPECT_FALSE(handle.socket()); |
654 | 662 |
655 EXPECT_EQ(OK, callback.WaitForResult()); | 663 EXPECT_EQ(OK, callback.WaitForResult()); |
656 EXPECT_TRUE(handle.is_initialized()); | 664 EXPECT_TRUE(handle.is_initialized()); |
657 EXPECT_TRUE(handle.socket()); | 665 EXPECT_TRUE(handle.socket()); |
658 | 666 |
659 handle.Reset(); | 667 handle.Reset(); |
660 | 668 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 }; | 702 }; |
695 | 703 |
696 for (size_t index = 0; index < arraysize(cases); ++index) { | 704 for (size_t index = 0; index < arraysize(cases); ++index) { |
697 client_socket_factory_.set_client_socket_types(cases[index]); | 705 client_socket_factory_.set_client_socket_types(cases[index]); |
698 | 706 |
699 EXPECT_EQ(0, pool_->IdleSocketCount()); | 707 EXPECT_EQ(0, pool_->IdleSocketCount()); |
700 | 708 |
701 TestCompletionCallback callback; | 709 TestCompletionCallback callback; |
702 ClientSocketHandle handle; | 710 ClientSocketHandle handle; |
703 TCPSocketParams dest("www.google.com", 80, LOW, GURL(), false); | 711 TCPSocketParams dest("www.google.com", 80, LOW, GURL(), false); |
704 int rv = handle.Init("b", dest, LOW, &callback, pool_, NULL); | 712 int rv = handle.Init("b", dest, LOW, &callback, pool_, BoundNetLog()); |
705 EXPECT_EQ(ERR_IO_PENDING, rv); | 713 EXPECT_EQ(ERR_IO_PENDING, rv); |
706 EXPECT_FALSE(handle.is_initialized()); | 714 EXPECT_FALSE(handle.is_initialized()); |
707 EXPECT_FALSE(handle.socket()); | 715 EXPECT_FALSE(handle.socket()); |
708 | 716 |
709 // Create the first socket, set the timer. | 717 // Create the first socket, set the timer. |
710 MessageLoop::current()->RunAllPending(); | 718 MessageLoop::current()->RunAllPending(); |
711 | 719 |
712 // Wait for the backup socket timer to fire. | 720 // Wait for the backup socket timer to fire. |
713 PlatformThread::Sleep(ClientSocketPool::kMaxConnectRetryIntervalMs); | 721 PlatformThread::Sleep(ClientSocketPool::kMaxConnectRetryIntervalMs); |
714 | 722 |
(...skipping 17 matching lines...) Expand all Loading... |
732 MockClientSocketFactory::MOCK_STALLED_CLIENT_SOCKET); | 740 MockClientSocketFactory::MOCK_STALLED_CLIENT_SOCKET); |
733 | 741 |
734 enum { CANCEL_BEFORE_WAIT, CANCEL_AFTER_WAIT }; | 742 enum { CANCEL_BEFORE_WAIT, CANCEL_AFTER_WAIT }; |
735 | 743 |
736 for (int index = CANCEL_BEFORE_WAIT; index < CANCEL_AFTER_WAIT; ++index) { | 744 for (int index = CANCEL_BEFORE_WAIT; index < CANCEL_AFTER_WAIT; ++index) { |
737 EXPECT_EQ(0, pool_->IdleSocketCount()); | 745 EXPECT_EQ(0, pool_->IdleSocketCount()); |
738 | 746 |
739 TestCompletionCallback callback; | 747 TestCompletionCallback callback; |
740 ClientSocketHandle handle; | 748 ClientSocketHandle handle; |
741 TCPSocketParams dest("www.google.com", 80, LOW, GURL(), false); | 749 TCPSocketParams dest("www.google.com", 80, LOW, GURL(), false); |
742 int rv = handle.Init("c", dest, LOW, &callback, pool_, NULL); | 750 int rv = handle.Init("c", dest, LOW, &callback, pool_, BoundNetLog()); |
743 EXPECT_EQ(ERR_IO_PENDING, rv); | 751 EXPECT_EQ(ERR_IO_PENDING, rv); |
744 EXPECT_FALSE(handle.is_initialized()); | 752 EXPECT_FALSE(handle.is_initialized()); |
745 EXPECT_FALSE(handle.socket()); | 753 EXPECT_FALSE(handle.socket()); |
746 | 754 |
747 // Create the first socket, set the timer. | 755 // Create the first socket, set the timer. |
748 MessageLoop::current()->RunAllPending(); | 756 MessageLoop::current()->RunAllPending(); |
749 | 757 |
750 if (index == CANCEL_AFTER_WAIT) { | 758 if (index == CANCEL_AFTER_WAIT) { |
751 // Wait for the backup socket timer to fire. | 759 // Wait for the backup socket timer to fire. |
752 PlatformThread::Sleep(ClientSocketPool::kMaxConnectRetryIntervalMs); | 760 PlatformThread::Sleep(ClientSocketPool::kMaxConnectRetryIntervalMs); |
(...skipping 24 matching lines...) Expand all Loading... |
777 MockClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET | 785 MockClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET |
778 }; | 786 }; |
779 | 787 |
780 client_socket_factory_.set_client_socket_types(case_types); | 788 client_socket_factory_.set_client_socket_types(case_types); |
781 | 789 |
782 EXPECT_EQ(0, pool_->IdleSocketCount()); | 790 EXPECT_EQ(0, pool_->IdleSocketCount()); |
783 | 791 |
784 TestCompletionCallback callback; | 792 TestCompletionCallback callback; |
785 ClientSocketHandle handle; | 793 ClientSocketHandle handle; |
786 TCPSocketParams dest("www.google.com", 80, LOW, GURL(), false); | 794 TCPSocketParams dest("www.google.com", 80, LOW, GURL(), false); |
787 int rv = handle.Init("b", dest, LOW, &callback, pool_, NULL); | 795 int rv = handle.Init("b", dest, LOW, &callback, pool_, BoundNetLog()); |
788 EXPECT_EQ(ERR_IO_PENDING, rv); | 796 EXPECT_EQ(ERR_IO_PENDING, rv); |
789 EXPECT_FALSE(handle.is_initialized()); | 797 EXPECT_FALSE(handle.is_initialized()); |
790 EXPECT_FALSE(handle.socket()); | 798 EXPECT_FALSE(handle.socket()); |
791 | 799 |
792 // Create the first socket, set the timer. | 800 // Create the first socket, set the timer. |
793 MessageLoop::current()->RunAllPending(); | 801 MessageLoop::current()->RunAllPending(); |
794 | 802 |
795 // Wait for the backup socket timer to fire. | 803 // Wait for the backup socket timer to fire. |
796 PlatformThread::Sleep(ClientSocketPool::kMaxConnectRetryIntervalMs); | 804 PlatformThread::Sleep(ClientSocketPool::kMaxConnectRetryIntervalMs); |
797 | 805 |
(...skipping 25 matching lines...) Expand all Loading... |
823 MockClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET | 831 MockClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET |
824 }; | 832 }; |
825 | 833 |
826 client_socket_factory_.set_client_socket_types(case_types); | 834 client_socket_factory_.set_client_socket_types(case_types); |
827 | 835 |
828 EXPECT_EQ(0, pool_->IdleSocketCount()); | 836 EXPECT_EQ(0, pool_->IdleSocketCount()); |
829 | 837 |
830 TestCompletionCallback callback; | 838 TestCompletionCallback callback; |
831 ClientSocketHandle handle; | 839 ClientSocketHandle handle; |
832 TCPSocketParams dest("www.google.com", 80, LOW, GURL(), false); | 840 TCPSocketParams dest("www.google.com", 80, LOW, GURL(), false); |
833 int rv = handle.Init("b", dest, LOW, &callback, pool_, NULL); | 841 int rv = handle.Init("b", dest, LOW, &callback, pool_, BoundNetLog()); |
834 EXPECT_EQ(ERR_IO_PENDING, rv); | 842 EXPECT_EQ(ERR_IO_PENDING, rv); |
835 EXPECT_FALSE(handle.is_initialized()); | 843 EXPECT_FALSE(handle.is_initialized()); |
836 EXPECT_FALSE(handle.socket()); | 844 EXPECT_FALSE(handle.socket()); |
837 | 845 |
838 // Create the first socket, set the timer. | 846 // Create the first socket, set the timer. |
839 MessageLoop::current()->RunAllPending(); | 847 MessageLoop::current()->RunAllPending(); |
840 | 848 |
841 // Wait for the backup socket timer to fire. | 849 // Wait for the backup socket timer to fire. |
842 PlatformThread::Sleep(ClientSocketPool::kMaxConnectRetryIntervalMs); | 850 PlatformThread::Sleep(ClientSocketPool::kMaxConnectRetryIntervalMs); |
843 | 851 |
844 // Let the second connect be synchronous. Otherwise, the emulated | 852 // Let the second connect be synchronous. Otherwise, the emulated |
845 // host resolution takes an extra trip through the message loop. | 853 // host resolution takes an extra trip through the message loop. |
846 host_resolver_->set_synchronous_mode(true); | 854 host_resolver_->set_synchronous_mode(true); |
847 | 855 |
848 // Let the appropriate socket connect. | 856 // Let the appropriate socket connect. |
849 MessageLoop::current()->RunAllPending(); | 857 MessageLoop::current()->RunAllPending(); |
850 | 858 |
851 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); | 859 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); |
852 EXPECT_FALSE(handle.is_initialized()); | 860 EXPECT_FALSE(handle.is_initialized()); |
853 EXPECT_FALSE(handle.socket()); | 861 EXPECT_FALSE(handle.socket()); |
854 handle.Reset(); | 862 handle.Reset(); |
855 | 863 |
856 // Reset for the next case. | 864 // Reset for the next case. |
857 host_resolver_->set_synchronous_mode(false); | 865 host_resolver_->set_synchronous_mode(false); |
858 } | 866 } |
859 | 867 |
860 } // namespace | 868 } // namespace |
861 | 869 |
862 } // namespace net | 870 } // namespace net |
OLD | NEW |