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

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: Feedback eroman 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 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 BoundNetLog()); 867 BoundNetLog());
868 EXPECT_EQ(ERR_IO_PENDING, rv); 868 EXPECT_EQ(ERR_IO_PENDING, rv);
869 EXPECT_FALSE(handle.is_initialized()); 869 EXPECT_FALSE(handle.is_initialized());
870 EXPECT_FALSE(handle.socket()); 870 EXPECT_FALSE(handle.socket());
871 871
872 EXPECT_EQ(OK, callback.WaitForResult()); 872 EXPECT_EQ(OK, callback.WaitForResult());
873 EXPECT_TRUE(handle.is_initialized()); 873 EXPECT_TRUE(handle.is_initialized());
874 EXPECT_TRUE(handle.socket()); 874 EXPECT_TRUE(handle.socket());
875 IPEndPoint endpoint; 875 IPEndPoint endpoint;
876 handle.socket()->GetLocalAddress(&endpoint); 876 handle.socket()->GetLocalAddress(&endpoint);
877 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size()); 877 EXPECT_EQ(kIPv4AddressSize, endpoint.address().bytes().size());
878 878
879 // Check that the failed connection attempt on the main socket is collected. 879 // Check that the failed connection attempt on the main socket is collected.
880 ConnectionAttempts attempts; 880 ConnectionAttempts attempts;
881 handle.socket()->GetConnectionAttempts(&attempts); 881 handle.socket()->GetConnectionAttempts(&attempts);
882 ASSERT_EQ(1u, attempts.size()); 882 ASSERT_EQ(1u, attempts.size());
883 EXPECT_EQ(ERR_CONNECTION_FAILED, attempts[0].result); 883 EXPECT_EQ(ERR_CONNECTION_FAILED, attempts[0].result);
884 EXPECT_EQ(kIPv6AddressSize, attempts[0].endpoint.address().size()); 884 EXPECT_EQ(kIPv6AddressSize, attempts[0].endpoint.address().bytes().size());
885 885
886 EXPECT_EQ(2, client_socket_factory_.allocation_count()); 886 EXPECT_EQ(2, client_socket_factory_.allocation_count());
887 } 887 }
888 888
889 // Test the case of the IPv6 address being slow, thus falling back to trying to 889 // 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 890 // connect to the IPv4 address, but having the connect to the IPv6 address
891 // finish first. 891 // finish first.
892 TEST_F(TransportClientSocketPoolTest, IPv6FallbackSocketIPv6FinishesFirst) { 892 TEST_F(TransportClientSocketPoolTest, IPv6FallbackSocketIPv6FinishesFirst) {
893 // Create a pool without backup jobs. 893 // Create a pool without backup jobs.
894 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); 894 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
(...skipping 24 matching lines...) Expand all
919 BoundNetLog()); 919 BoundNetLog());
920 EXPECT_EQ(ERR_IO_PENDING, rv); 920 EXPECT_EQ(ERR_IO_PENDING, rv);
921 EXPECT_FALSE(handle.is_initialized()); 921 EXPECT_FALSE(handle.is_initialized());
922 EXPECT_FALSE(handle.socket()); 922 EXPECT_FALSE(handle.socket());
923 923
924 EXPECT_EQ(OK, callback.WaitForResult()); 924 EXPECT_EQ(OK, callback.WaitForResult());
925 EXPECT_TRUE(handle.is_initialized()); 925 EXPECT_TRUE(handle.is_initialized());
926 EXPECT_TRUE(handle.socket()); 926 EXPECT_TRUE(handle.socket());
927 IPEndPoint endpoint; 927 IPEndPoint endpoint;
928 handle.socket()->GetLocalAddress(&endpoint); 928 handle.socket()->GetLocalAddress(&endpoint);
929 EXPECT_EQ(kIPv6AddressSize, endpoint.address().size()); 929 EXPECT_EQ(kIPv6AddressSize, endpoint.address().bytes().size());
930 930
931 // Check that the failed connection attempt on the fallback socket is 931 // Check that the failed connection attempt on the fallback socket is
932 // collected. 932 // collected.
933 ConnectionAttempts attempts; 933 ConnectionAttempts attempts;
934 handle.socket()->GetConnectionAttempts(&attempts); 934 handle.socket()->GetConnectionAttempts(&attempts);
935 ASSERT_EQ(1u, attempts.size()); 935 ASSERT_EQ(1u, attempts.size());
936 EXPECT_EQ(ERR_CONNECTION_FAILED, attempts[0].result); 936 EXPECT_EQ(ERR_CONNECTION_FAILED, attempts[0].result);
937 EXPECT_EQ(kIPv4AddressSize, attempts[0].endpoint.address().size()); 937 EXPECT_EQ(kIPv4AddressSize, attempts[0].endpoint.address().bytes().size());
938 938
939 EXPECT_EQ(2, client_socket_factory_.allocation_count()); 939 EXPECT_EQ(2, client_socket_factory_.allocation_count());
940 } 940 }
941 941
942 TEST_F(TransportClientSocketPoolTest, IPv6NoIPv4AddressesToFallbackTo) { 942 TEST_F(TransportClientSocketPoolTest, IPv6NoIPv4AddressesToFallbackTo) {
943 // Create a pool without backup jobs. 943 // Create a pool without backup jobs.
944 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); 944 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
945 TransportClientSocketPool pool(kMaxSockets, 945 TransportClientSocketPool pool(kMaxSockets,
946 kMaxSocketsPerGroup, 946 kMaxSocketsPerGroup,
947 host_resolver_.get(), 947 host_resolver_.get(),
(...skipping 13 matching lines...) Expand all
961 BoundNetLog()); 961 BoundNetLog());
962 EXPECT_EQ(ERR_IO_PENDING, rv); 962 EXPECT_EQ(ERR_IO_PENDING, rv);
963 EXPECT_FALSE(handle.is_initialized()); 963 EXPECT_FALSE(handle.is_initialized());
964 EXPECT_FALSE(handle.socket()); 964 EXPECT_FALSE(handle.socket());
965 965
966 EXPECT_EQ(OK, callback.WaitForResult()); 966 EXPECT_EQ(OK, callback.WaitForResult());
967 EXPECT_TRUE(handle.is_initialized()); 967 EXPECT_TRUE(handle.is_initialized());
968 EXPECT_TRUE(handle.socket()); 968 EXPECT_TRUE(handle.socket());
969 IPEndPoint endpoint; 969 IPEndPoint endpoint;
970 handle.socket()->GetLocalAddress(&endpoint); 970 handle.socket()->GetLocalAddress(&endpoint);
971 EXPECT_EQ(kIPv6AddressSize, endpoint.address().size()); 971 EXPECT_EQ(kIPv6AddressSize, endpoint.address().bytes().size());
972 EXPECT_EQ(0u, handle.connection_attempts().size()); 972 EXPECT_EQ(0u, handle.connection_attempts().size());
973 EXPECT_EQ(1, client_socket_factory_.allocation_count()); 973 EXPECT_EQ(1, client_socket_factory_.allocation_count());
974 } 974 }
975 975
976 TEST_F(TransportClientSocketPoolTest, IPv4HasNoFallback) { 976 TEST_F(TransportClientSocketPoolTest, IPv4HasNoFallback) {
977 // Create a pool without backup jobs. 977 // Create a pool without backup jobs.
978 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); 978 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
979 TransportClientSocketPool pool(kMaxSockets, 979 TransportClientSocketPool pool(kMaxSockets,
980 kMaxSocketsPerGroup, 980 kMaxSocketsPerGroup,
981 host_resolver_.get(), 981 host_resolver_.get(),
(...skipping 12 matching lines...) Expand all
994 BoundNetLog()); 994 BoundNetLog());
995 EXPECT_EQ(ERR_IO_PENDING, rv); 995 EXPECT_EQ(ERR_IO_PENDING, rv);
996 EXPECT_FALSE(handle.is_initialized()); 996 EXPECT_FALSE(handle.is_initialized());
997 EXPECT_FALSE(handle.socket()); 997 EXPECT_FALSE(handle.socket());
998 998
999 EXPECT_EQ(OK, callback.WaitForResult()); 999 EXPECT_EQ(OK, callback.WaitForResult());
1000 EXPECT_TRUE(handle.is_initialized()); 1000 EXPECT_TRUE(handle.is_initialized());
1001 EXPECT_TRUE(handle.socket()); 1001 EXPECT_TRUE(handle.socket());
1002 IPEndPoint endpoint; 1002 IPEndPoint endpoint;
1003 handle.socket()->GetLocalAddress(&endpoint); 1003 handle.socket()->GetLocalAddress(&endpoint);
1004 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size()); 1004 EXPECT_EQ(kIPv4AddressSize, endpoint.address().bytes().size());
1005 EXPECT_EQ(0u, handle.connection_attempts().size()); 1005 EXPECT_EQ(0u, handle.connection_attempts().size());
1006 EXPECT_EQ(1, client_socket_factory_.allocation_count()); 1006 EXPECT_EQ(1, client_socket_factory_.allocation_count());
1007 } 1007 }
1008 1008
1009 // Test that if TCP FastOpen is enabled, it is set on the socket 1009 // Test that if TCP FastOpen is enabled, it is set on the socket
1010 // when we have only an IPv4 address. 1010 // when we have only an IPv4 address.
1011 TEST_F(TransportClientSocketPoolTest, TCPFastOpenOnIPv4WithNoFallback) { 1011 TEST_F(TransportClientSocketPoolTest, TCPFastOpenOnIPv4WithNoFallback) {
1012 // Create a pool without backup jobs. 1012 // Create a pool without backup jobs.
1013 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); 1013 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
1014 TransportClientSocketPool pool(kMaxSockets, 1014 TransportClientSocketPool pool(kMaxSockets,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 1081
1082 TestCompletionCallback callback; 1082 TestCompletionCallback callback;
1083 ClientSocketHandle handle; 1083 ClientSocketHandle handle;
1084 // Enable TCP FastOpen in TransportSocketParams. 1084 // Enable TCP FastOpen in TransportSocketParams.
1085 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen(); 1085 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen();
1086 handle.Init("a", params, LOW, callback.callback(), &pool, BoundNetLog()); 1086 handle.Init("a", params, LOW, callback.callback(), &pool, BoundNetLog());
1087 EXPECT_EQ(OK, callback.WaitForResult()); 1087 EXPECT_EQ(OK, callback.WaitForResult());
1088 // Verify that the socket used is connected to the fallback IPv4 address. 1088 // Verify that the socket used is connected to the fallback IPv4 address.
1089 IPEndPoint endpoint; 1089 IPEndPoint endpoint;
1090 handle.socket()->GetLocalAddress(&endpoint); 1090 handle.socket()->GetLocalAddress(&endpoint);
1091 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size()); 1091 EXPECT_EQ(kIPv4AddressSize, endpoint.address().bytes().size());
1092 EXPECT_EQ(2, client_socket_factory_.allocation_count()); 1092 EXPECT_EQ(2, client_socket_factory_.allocation_count());
1093 // Verify that TCP FastOpen was not turned on for the socket. 1093 // Verify that TCP FastOpen was not turned on for the socket.
1094 EXPECT_FALSE(handle.socket()->UsingTCPFastOpen()); 1094 EXPECT_FALSE(handle.socket()->UsingTCPFastOpen());
1095 } 1095 }
1096 1096
1097 // Test that if TCP FastOpen is enabled, it does not do anything when there 1097 // 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 1098 // is a IPv6 address with fallback to an IPv4 address. This test tests the case
1099 // when the IPv6 connect succeeds. 1099 // when the IPv6 connect succeeds.
1100 TEST_F(TransportClientSocketPoolTest, 1100 TEST_F(TransportClientSocketPoolTest,
1101 NoTCPFastOpenOnIPv6SuccessWithIPv4Fallback) { 1101 NoTCPFastOpenOnIPv6SuccessWithIPv4Fallback) {
(...skipping 18 matching lines...) Expand all
1120 1120
1121 TestCompletionCallback callback; 1121 TestCompletionCallback callback;
1122 ClientSocketHandle handle; 1122 ClientSocketHandle handle;
1123 // Enable TCP FastOpen in TransportSocketParams. 1123 // Enable TCP FastOpen in TransportSocketParams.
1124 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen(); 1124 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen();
1125 handle.Init("a", params, LOW, callback.callback(), &pool, BoundNetLog()); 1125 handle.Init("a", params, LOW, callback.callback(), &pool, BoundNetLog());
1126 EXPECT_EQ(OK, callback.WaitForResult()); 1126 EXPECT_EQ(OK, callback.WaitForResult());
1127 // Verify that the socket used is connected to the IPv6 address. 1127 // Verify that the socket used is connected to the IPv6 address.
1128 IPEndPoint endpoint; 1128 IPEndPoint endpoint;
1129 handle.socket()->GetLocalAddress(&endpoint); 1129 handle.socket()->GetLocalAddress(&endpoint);
1130 EXPECT_EQ(kIPv6AddressSize, endpoint.address().size()); 1130 EXPECT_EQ(kIPv6AddressSize, endpoint.address().bytes().size());
1131 EXPECT_EQ(1, client_socket_factory_.allocation_count()); 1131 EXPECT_EQ(1, client_socket_factory_.allocation_count());
1132 // Verify that TCP FastOpen was not turned on for the socket. 1132 // Verify that TCP FastOpen was not turned on for the socket.
1133 EXPECT_FALSE(handle.socket()->UsingTCPFastOpen()); 1133 EXPECT_FALSE(handle.socket()->UsingTCPFastOpen());
1134 } 1134 }
1135 1135
1136 } // namespace 1136 } // namespace
1137 1137
1138 } // namespace net 1138 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698