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 "base/threading/platform_thread.h" |
10 #include "net/base/mock_host_resolver.h" | 11 #include "net/base/mock_host_resolver.h" |
11 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
12 #include "net/base/test_completion_callback.h" | 13 #include "net/base/test_completion_callback.h" |
13 #include "net/socket/client_socket.h" | 14 #include "net/socket/client_socket.h" |
14 #include "net/socket/client_socket_factory.h" | 15 #include "net/socket/client_socket_factory.h" |
15 #include "net/socket/client_socket_handle.h" | 16 #include "net/socket/client_socket_handle.h" |
16 #include "net/socket/client_socket_pool_histograms.h" | 17 #include "net/socket/client_socket_pool_histograms.h" |
17 #include "net/socket/socket_test_util.h" | 18 #include "net/socket/socket_test_util.h" |
18 #include "net/socket/ssl_host_info.h" | 19 #include "net/socket/ssl_host_info.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 int rv = handle.Init("b", low_params_, LOW, &callback, &pool_, | 752 int rv = handle.Init("b", low_params_, LOW, &callback, &pool_, |
752 BoundNetLog()); | 753 BoundNetLog()); |
753 EXPECT_EQ(ERR_IO_PENDING, rv); | 754 EXPECT_EQ(ERR_IO_PENDING, rv); |
754 EXPECT_FALSE(handle.is_initialized()); | 755 EXPECT_FALSE(handle.is_initialized()); |
755 EXPECT_FALSE(handle.socket()); | 756 EXPECT_FALSE(handle.socket()); |
756 | 757 |
757 // Create the first socket, set the timer. | 758 // Create the first socket, set the timer. |
758 MessageLoop::current()->RunAllPending(); | 759 MessageLoop::current()->RunAllPending(); |
759 | 760 |
760 // Wait for the backup socket timer to fire. | 761 // Wait for the backup socket timer to fire. |
761 PlatformThread::Sleep(ClientSocketPool::kMaxConnectRetryIntervalMs * 2); | 762 base::PlatformThread::Sleep(ClientSocketPool::kMaxConnectRetryIntervalMs * 2
); |
762 | 763 |
763 // Let the appropriate socket connect. | 764 // Let the appropriate socket connect. |
764 MessageLoop::current()->RunAllPending(); | 765 MessageLoop::current()->RunAllPending(); |
765 | 766 |
766 EXPECT_EQ(OK, callback.WaitForResult()); | 767 EXPECT_EQ(OK, callback.WaitForResult()); |
767 EXPECT_TRUE(handle.is_initialized()); | 768 EXPECT_TRUE(handle.is_initialized()); |
768 EXPECT_TRUE(handle.socket()); | 769 EXPECT_TRUE(handle.socket()); |
769 | 770 |
770 // One socket is stalled, the other is active. | 771 // One socket is stalled, the other is active. |
771 EXPECT_EQ(0, pool_.IdleSocketCount()); | 772 EXPECT_EQ(0, pool_.IdleSocketCount()); |
(...skipping 21 matching lines...) Expand all Loading... |
793 BoundNetLog()); | 794 BoundNetLog()); |
794 EXPECT_EQ(ERR_IO_PENDING, rv); | 795 EXPECT_EQ(ERR_IO_PENDING, rv); |
795 EXPECT_FALSE(handle.is_initialized()); | 796 EXPECT_FALSE(handle.is_initialized()); |
796 EXPECT_FALSE(handle.socket()); | 797 EXPECT_FALSE(handle.socket()); |
797 | 798 |
798 // Create the first socket, set the timer. | 799 // Create the first socket, set the timer. |
799 MessageLoop::current()->RunAllPending(); | 800 MessageLoop::current()->RunAllPending(); |
800 | 801 |
801 if (index == CANCEL_AFTER_WAIT) { | 802 if (index == CANCEL_AFTER_WAIT) { |
802 // Wait for the backup socket timer to fire. | 803 // Wait for the backup socket timer to fire. |
803 PlatformThread::Sleep(ClientSocketPool::kMaxConnectRetryIntervalMs); | 804 base::PlatformThread::Sleep(ClientSocketPool::kMaxConnectRetryIntervalMs); |
804 } | 805 } |
805 | 806 |
806 // Let the appropriate socket connect. | 807 // Let the appropriate socket connect. |
807 MessageLoop::current()->RunAllPending(); | 808 MessageLoop::current()->RunAllPending(); |
808 | 809 |
809 handle.Reset(); | 810 handle.Reset(); |
810 | 811 |
811 EXPECT_FALSE(callback.have_result()); | 812 EXPECT_FALSE(callback.have_result()); |
812 EXPECT_FALSE(handle.is_initialized()); | 813 EXPECT_FALSE(handle.is_initialized()); |
813 EXPECT_FALSE(handle.socket()); | 814 EXPECT_FALSE(handle.socket()); |
(...skipping 22 matching lines...) Expand all Loading... |
836 ClientSocketHandle handle; | 837 ClientSocketHandle handle; |
837 int rv = handle.Init("b", low_params_, LOW, &callback, &pool_, BoundNetLog()); | 838 int rv = handle.Init("b", low_params_, LOW, &callback, &pool_, BoundNetLog()); |
838 EXPECT_EQ(ERR_IO_PENDING, rv); | 839 EXPECT_EQ(ERR_IO_PENDING, rv); |
839 EXPECT_FALSE(handle.is_initialized()); | 840 EXPECT_FALSE(handle.is_initialized()); |
840 EXPECT_FALSE(handle.socket()); | 841 EXPECT_FALSE(handle.socket()); |
841 | 842 |
842 // Create the first socket, set the timer. | 843 // Create the first socket, set the timer. |
843 MessageLoop::current()->RunAllPending(); | 844 MessageLoop::current()->RunAllPending(); |
844 | 845 |
845 // Wait for the backup socket timer to fire. | 846 // Wait for the backup socket timer to fire. |
846 PlatformThread::Sleep(ClientSocketPool::kMaxConnectRetryIntervalMs); | 847 base::PlatformThread::Sleep(ClientSocketPool::kMaxConnectRetryIntervalMs); |
847 | 848 |
848 // Let the second connect be synchronous. Otherwise, the emulated | 849 // Let the second connect be synchronous. Otherwise, the emulated |
849 // host resolution takes an extra trip through the message loop. | 850 // host resolution takes an extra trip through the message loop. |
850 host_resolver_->set_synchronous_mode(true); | 851 host_resolver_->set_synchronous_mode(true); |
851 | 852 |
852 // Let the appropriate socket connect. | 853 // Let the appropriate socket connect. |
853 MessageLoop::current()->RunAllPending(); | 854 MessageLoop::current()->RunAllPending(); |
854 | 855 |
855 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); | 856 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); |
856 EXPECT_FALSE(handle.is_initialized()); | 857 EXPECT_FALSE(handle.is_initialized()); |
(...skipping 24 matching lines...) Expand all Loading... |
881 ClientSocketHandle handle; | 882 ClientSocketHandle handle; |
882 int rv = handle.Init("b", low_params_, LOW, &callback, &pool_, BoundNetLog()); | 883 int rv = handle.Init("b", low_params_, LOW, &callback, &pool_, BoundNetLog()); |
883 EXPECT_EQ(ERR_IO_PENDING, rv); | 884 EXPECT_EQ(ERR_IO_PENDING, rv); |
884 EXPECT_FALSE(handle.is_initialized()); | 885 EXPECT_FALSE(handle.is_initialized()); |
885 EXPECT_FALSE(handle.socket()); | 886 EXPECT_FALSE(handle.socket()); |
886 | 887 |
887 // Create the first socket, set the timer. | 888 // Create the first socket, set the timer. |
888 MessageLoop::current()->RunAllPending(); | 889 MessageLoop::current()->RunAllPending(); |
889 | 890 |
890 // Wait for the backup socket timer to fire. | 891 // Wait for the backup socket timer to fire. |
891 PlatformThread::Sleep(ClientSocketPool::kMaxConnectRetryIntervalMs); | 892 base::PlatformThread::Sleep(ClientSocketPool::kMaxConnectRetryIntervalMs); |
892 | 893 |
893 // Let the second connect be synchronous. Otherwise, the emulated | 894 // Let the second connect be synchronous. Otherwise, the emulated |
894 // host resolution takes an extra trip through the message loop. | 895 // host resolution takes an extra trip through the message loop. |
895 host_resolver_->set_synchronous_mode(true); | 896 host_resolver_->set_synchronous_mode(true); |
896 | 897 |
897 // Let the appropriate socket connect. | 898 // Let the appropriate socket connect. |
898 MessageLoop::current()->RunAllPending(); | 899 MessageLoop::current()->RunAllPending(); |
899 | 900 |
900 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); | 901 EXPECT_EQ(ERR_CONNECTION_FAILED, callback.WaitForResult()); |
901 EXPECT_FALSE(handle.is_initialized()); | 902 EXPECT_FALSE(handle.is_initialized()); |
902 EXPECT_FALSE(handle.socket()); | 903 EXPECT_FALSE(handle.socket()); |
903 handle.Reset(); | 904 handle.Reset(); |
904 | 905 |
905 // Reset for the next case. | 906 // Reset for the next case. |
906 host_resolver_->set_synchronous_mode(false); | 907 host_resolver_->set_synchronous_mode(false); |
907 } | 908 } |
908 | 909 |
909 } // namespace | 910 } // namespace |
910 | 911 |
911 } // namespace net | 912 } // namespace net |
OLD | NEW |