Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: net/socket/transport_client_socket_pool_unittest.cc

Issue 1565303002: Change IPEndpoint::address() to return a net::IPAddress (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Android Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/socket/transport_client_socket_pool.h" 5 #include "net/socket/transport_client_socket_pool.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 ClientSocketHandle handle; 211 ClientSocketHandle handle;
212 HostPortPair host_port_pair("unresolvable.host.name", 80); 212 HostPortPair host_port_pair("unresolvable.host.name", 80);
213 scoped_refptr<TransportSocketParams> dest(new TransportSocketParams( 213 scoped_refptr<TransportSocketParams> dest(new TransportSocketParams(
214 host_port_pair, false, false, OnHostResolutionCallback(), 214 host_port_pair, false, false, OnHostResolutionCallback(),
215 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); 215 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT));
216 EXPECT_EQ(ERR_IO_PENDING, 216 EXPECT_EQ(ERR_IO_PENDING,
217 handle.Init("a", dest, kDefaultPriority, callback.callback(), 217 handle.Init("a", dest, kDefaultPriority, callback.callback(),
218 &pool_, BoundNetLog())); 218 &pool_, BoundNetLog()));
219 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback.WaitForResult()); 219 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, callback.WaitForResult());
220 ASSERT_EQ(1u, handle.connection_attempts().size()); 220 ASSERT_EQ(1u, handle.connection_attempts().size());
221 EXPECT_TRUE(handle.connection_attempts()[0].endpoint.address().empty()); 221 EXPECT_TRUE(
222 handle.connection_attempts()[0].endpoint.address_number().empty());
222 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, handle.connection_attempts()[0].result); 223 EXPECT_EQ(ERR_NAME_NOT_RESOLVED, handle.connection_attempts()[0].result);
223 } 224 }
224 225
225 TEST_F(TransportClientSocketPoolTest, InitConnectionFailure) { 226 TEST_F(TransportClientSocketPoolTest, InitConnectionFailure) {
226 client_socket_factory_.set_default_client_socket_type( 227 client_socket_factory_.set_default_client_socket_type(
227 MockTransportClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET); 228 MockTransportClientSocketFactory::MOCK_FAILING_CLIENT_SOCKET);
228 TestCompletionCallback callback; 229 TestCompletionCallback callback;
229 ClientSocketHandle handle; 230 ClientSocketHandle handle;
230 EXPECT_EQ(ERR_IO_PENDING, 231 EXPECT_EQ(ERR_IO_PENDING,
231 handle.Init("a", params_, kDefaultPriority, callback.callback(), 232 handle.Init("a", params_, kDefaultPriority, callback.callback(),
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 BoundNetLog()); 868 BoundNetLog());
868 EXPECT_EQ(ERR_IO_PENDING, rv); 869 EXPECT_EQ(ERR_IO_PENDING, rv);
869 EXPECT_FALSE(handle.is_initialized()); 870 EXPECT_FALSE(handle.is_initialized());
870 EXPECT_FALSE(handle.socket()); 871 EXPECT_FALSE(handle.socket());
871 872
872 EXPECT_EQ(OK, callback.WaitForResult()); 873 EXPECT_EQ(OK, callback.WaitForResult());
873 EXPECT_TRUE(handle.is_initialized()); 874 EXPECT_TRUE(handle.is_initialized());
874 EXPECT_TRUE(handle.socket()); 875 EXPECT_TRUE(handle.socket());
875 IPEndPoint endpoint; 876 IPEndPoint endpoint;
876 handle.socket()->GetLocalAddress(&endpoint); 877 handle.socket()->GetLocalAddress(&endpoint);
877 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size()); 878 EXPECT_EQ(kIPv4AddressSize, endpoint.address_number().size());
878 879
879 // Check that the failed connection attempt on the main socket is collected. 880 // Check that the failed connection attempt on the main socket is collected.
880 ConnectionAttempts attempts; 881 ConnectionAttempts attempts;
881 handle.socket()->GetConnectionAttempts(&attempts); 882 handle.socket()->GetConnectionAttempts(&attempts);
882 ASSERT_EQ(1u, attempts.size()); 883 ASSERT_EQ(1u, attempts.size());
883 EXPECT_EQ(ERR_CONNECTION_FAILED, attempts[0].result); 884 EXPECT_EQ(ERR_CONNECTION_FAILED, attempts[0].result);
884 EXPECT_EQ(kIPv6AddressSize, attempts[0].endpoint.address().size()); 885 EXPECT_EQ(kIPv6AddressSize, attempts[0].endpoint.address_number().size());
885 886
886 EXPECT_EQ(2, client_socket_factory_.allocation_count()); 887 EXPECT_EQ(2, client_socket_factory_.allocation_count());
887 } 888 }
888 889
889 // Test the case of the IPv6 address being slow, thus falling back to trying to 890 // Test the case of the IPv6 address being slow, thus falling back to trying to
890 // connect to the IPv4 address, but having the connect to the IPv6 address 891 // connect to the IPv4 address, but having the connect to the IPv6 address
891 // finish first. 892 // finish first.
892 TEST_F(TransportClientSocketPoolTest, IPv6FallbackSocketIPv6FinishesFirst) { 893 TEST_F(TransportClientSocketPoolTest, IPv6FallbackSocketIPv6FinishesFirst) {
893 // Create a pool without backup jobs. 894 // Create a pool without backup jobs.
894 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); 895 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
(...skipping 24 matching lines...) Expand all
919 BoundNetLog()); 920 BoundNetLog());
920 EXPECT_EQ(ERR_IO_PENDING, rv); 921 EXPECT_EQ(ERR_IO_PENDING, rv);
921 EXPECT_FALSE(handle.is_initialized()); 922 EXPECT_FALSE(handle.is_initialized());
922 EXPECT_FALSE(handle.socket()); 923 EXPECT_FALSE(handle.socket());
923 924
924 EXPECT_EQ(OK, callback.WaitForResult()); 925 EXPECT_EQ(OK, callback.WaitForResult());
925 EXPECT_TRUE(handle.is_initialized()); 926 EXPECT_TRUE(handle.is_initialized());
926 EXPECT_TRUE(handle.socket()); 927 EXPECT_TRUE(handle.socket());
927 IPEndPoint endpoint; 928 IPEndPoint endpoint;
928 handle.socket()->GetLocalAddress(&endpoint); 929 handle.socket()->GetLocalAddress(&endpoint);
929 EXPECT_EQ(kIPv6AddressSize, endpoint.address().size()); 930 EXPECT_EQ(kIPv6AddressSize, endpoint.address_number().size());
930 931
931 // Check that the failed connection attempt on the fallback socket is 932 // Check that the failed connection attempt on the fallback socket is
932 // collected. 933 // collected.
933 ConnectionAttempts attempts; 934 ConnectionAttempts attempts;
934 handle.socket()->GetConnectionAttempts(&attempts); 935 handle.socket()->GetConnectionAttempts(&attempts);
935 ASSERT_EQ(1u, attempts.size()); 936 ASSERT_EQ(1u, attempts.size());
936 EXPECT_EQ(ERR_CONNECTION_FAILED, attempts[0].result); 937 EXPECT_EQ(ERR_CONNECTION_FAILED, attempts[0].result);
937 EXPECT_EQ(kIPv4AddressSize, attempts[0].endpoint.address().size()); 938 EXPECT_EQ(kIPv4AddressSize, attempts[0].endpoint.address_number().size());
938 939
939 EXPECT_EQ(2, client_socket_factory_.allocation_count()); 940 EXPECT_EQ(2, client_socket_factory_.allocation_count());
940 } 941 }
941 942
942 TEST_F(TransportClientSocketPoolTest, IPv6NoIPv4AddressesToFallbackTo) { 943 TEST_F(TransportClientSocketPoolTest, IPv6NoIPv4AddressesToFallbackTo) {
943 // Create a pool without backup jobs. 944 // Create a pool without backup jobs.
944 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); 945 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
945 TransportClientSocketPool pool(kMaxSockets, 946 TransportClientSocketPool pool(kMaxSockets,
946 kMaxSocketsPerGroup, 947 kMaxSocketsPerGroup,
947 host_resolver_.get(), 948 host_resolver_.get(),
(...skipping 13 matching lines...) Expand all
961 BoundNetLog()); 962 BoundNetLog());
962 EXPECT_EQ(ERR_IO_PENDING, rv); 963 EXPECT_EQ(ERR_IO_PENDING, rv);
963 EXPECT_FALSE(handle.is_initialized()); 964 EXPECT_FALSE(handle.is_initialized());
964 EXPECT_FALSE(handle.socket()); 965 EXPECT_FALSE(handle.socket());
965 966
966 EXPECT_EQ(OK, callback.WaitForResult()); 967 EXPECT_EQ(OK, callback.WaitForResult());
967 EXPECT_TRUE(handle.is_initialized()); 968 EXPECT_TRUE(handle.is_initialized());
968 EXPECT_TRUE(handle.socket()); 969 EXPECT_TRUE(handle.socket());
969 IPEndPoint endpoint; 970 IPEndPoint endpoint;
970 handle.socket()->GetLocalAddress(&endpoint); 971 handle.socket()->GetLocalAddress(&endpoint);
971 EXPECT_EQ(kIPv6AddressSize, endpoint.address().size()); 972 EXPECT_EQ(kIPv6AddressSize, endpoint.address_number().size());
972 EXPECT_EQ(0u, handle.connection_attempts().size()); 973 EXPECT_EQ(0u, handle.connection_attempts().size());
973 EXPECT_EQ(1, client_socket_factory_.allocation_count()); 974 EXPECT_EQ(1, client_socket_factory_.allocation_count());
974 } 975 }
975 976
976 TEST_F(TransportClientSocketPoolTest, IPv4HasNoFallback) { 977 TEST_F(TransportClientSocketPoolTest, IPv4HasNoFallback) {
977 // Create a pool without backup jobs. 978 // Create a pool without backup jobs.
978 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); 979 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
979 TransportClientSocketPool pool(kMaxSockets, 980 TransportClientSocketPool pool(kMaxSockets,
980 kMaxSocketsPerGroup, 981 kMaxSocketsPerGroup,
981 host_resolver_.get(), 982 host_resolver_.get(),
(...skipping 12 matching lines...) Expand all
994 BoundNetLog()); 995 BoundNetLog());
995 EXPECT_EQ(ERR_IO_PENDING, rv); 996 EXPECT_EQ(ERR_IO_PENDING, rv);
996 EXPECT_FALSE(handle.is_initialized()); 997 EXPECT_FALSE(handle.is_initialized());
997 EXPECT_FALSE(handle.socket()); 998 EXPECT_FALSE(handle.socket());
998 999
999 EXPECT_EQ(OK, callback.WaitForResult()); 1000 EXPECT_EQ(OK, callback.WaitForResult());
1000 EXPECT_TRUE(handle.is_initialized()); 1001 EXPECT_TRUE(handle.is_initialized());
1001 EXPECT_TRUE(handle.socket()); 1002 EXPECT_TRUE(handle.socket());
1002 IPEndPoint endpoint; 1003 IPEndPoint endpoint;
1003 handle.socket()->GetLocalAddress(&endpoint); 1004 handle.socket()->GetLocalAddress(&endpoint);
1004 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size()); 1005 EXPECT_EQ(kIPv4AddressSize, endpoint.address_number().size());
1005 EXPECT_EQ(0u, handle.connection_attempts().size()); 1006 EXPECT_EQ(0u, handle.connection_attempts().size());
1006 EXPECT_EQ(1, client_socket_factory_.allocation_count()); 1007 EXPECT_EQ(1, client_socket_factory_.allocation_count());
1007 } 1008 }
1008 1009
1009 // Test that if TCP FastOpen is enabled, it is set on the socket 1010 // Test that if TCP FastOpen is enabled, it is set on the socket
1010 // when we have only an IPv4 address. 1011 // when we have only an IPv4 address.
1011 TEST_F(TransportClientSocketPoolTest, TCPFastOpenOnIPv4WithNoFallback) { 1012 TEST_F(TransportClientSocketPoolTest, TCPFastOpenOnIPv4WithNoFallback) {
1012 // Create a pool without backup jobs. 1013 // Create a pool without backup jobs.
1013 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); 1014 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
1014 TransportClientSocketPool pool(kMaxSockets, 1015 TransportClientSocketPool pool(kMaxSockets,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 1082
1082 TestCompletionCallback callback; 1083 TestCompletionCallback callback;
1083 ClientSocketHandle handle; 1084 ClientSocketHandle handle;
1084 // Enable TCP FastOpen in TransportSocketParams. 1085 // Enable TCP FastOpen in TransportSocketParams.
1085 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen(); 1086 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen();
1086 handle.Init("a", params, LOW, callback.callback(), &pool, BoundNetLog()); 1087 handle.Init("a", params, LOW, callback.callback(), &pool, BoundNetLog());
1087 EXPECT_EQ(OK, callback.WaitForResult()); 1088 EXPECT_EQ(OK, callback.WaitForResult());
1088 // Verify that the socket used is connected to the fallback IPv4 address. 1089 // Verify that the socket used is connected to the fallback IPv4 address.
1089 IPEndPoint endpoint; 1090 IPEndPoint endpoint;
1090 handle.socket()->GetLocalAddress(&endpoint); 1091 handle.socket()->GetLocalAddress(&endpoint);
1091 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size()); 1092 EXPECT_EQ(kIPv4AddressSize, endpoint.address_number().size());
1092 EXPECT_EQ(2, client_socket_factory_.allocation_count()); 1093 EXPECT_EQ(2, client_socket_factory_.allocation_count());
1093 // Verify that TCP FastOpen was not turned on for the socket. 1094 // Verify that TCP FastOpen was not turned on for the socket.
1094 EXPECT_FALSE(handle.socket()->UsingTCPFastOpen()); 1095 EXPECT_FALSE(handle.socket()->UsingTCPFastOpen());
1095 } 1096 }
1096 1097
1097 // Test that if TCP FastOpen is enabled, it does not do anything when there 1098 // Test that if TCP FastOpen is enabled, it does not do anything when there
1098 // is a IPv6 address with fallback to an IPv4 address. This test tests the case 1099 // is a IPv6 address with fallback to an IPv4 address. This test tests the case
1099 // when the IPv6 connect succeeds. 1100 // when the IPv6 connect succeeds.
1100 TEST_F(TransportClientSocketPoolTest, 1101 TEST_F(TransportClientSocketPoolTest,
1101 NoTCPFastOpenOnIPv6SuccessWithIPv4Fallback) { 1102 NoTCPFastOpenOnIPv6SuccessWithIPv4Fallback) {
(...skipping 18 matching lines...) Expand all
1120 1121
1121 TestCompletionCallback callback; 1122 TestCompletionCallback callback;
1122 ClientSocketHandle handle; 1123 ClientSocketHandle handle;
1123 // Enable TCP FastOpen in TransportSocketParams. 1124 // Enable TCP FastOpen in TransportSocketParams.
1124 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen(); 1125 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen();
1125 handle.Init("a", params, LOW, callback.callback(), &pool, BoundNetLog()); 1126 handle.Init("a", params, LOW, callback.callback(), &pool, BoundNetLog());
1126 EXPECT_EQ(OK, callback.WaitForResult()); 1127 EXPECT_EQ(OK, callback.WaitForResult());
1127 // Verify that the socket used is connected to the IPv6 address. 1128 // Verify that the socket used is connected to the IPv6 address.
1128 IPEndPoint endpoint; 1129 IPEndPoint endpoint;
1129 handle.socket()->GetLocalAddress(&endpoint); 1130 handle.socket()->GetLocalAddress(&endpoint);
1130 EXPECT_EQ(kIPv6AddressSize, endpoint.address().size()); 1131 EXPECT_EQ(kIPv6AddressSize, endpoint.address_number().size());
1131 EXPECT_EQ(1, client_socket_factory_.allocation_count()); 1132 EXPECT_EQ(1, client_socket_factory_.allocation_count());
1132 // Verify that TCP FastOpen was not turned on for the socket. 1133 // Verify that TCP FastOpen was not turned on for the socket.
1133 EXPECT_FALSE(handle.socket()->UsingTCPFastOpen()); 1134 EXPECT_FALSE(handle.socket()->UsingTCPFastOpen());
1134 } 1135 }
1135 1136
1136 } // namespace 1137 } // namespace
1137 1138
1138 } // namespace net 1139 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698