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

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

Issue 1932363003: Remove net::IPAddressNumber. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 callback.callback(), &pool, BoundNetLog()); 878 callback.callback(), &pool, BoundNetLog());
879 EXPECT_EQ(ERR_IO_PENDING, rv); 879 EXPECT_EQ(ERR_IO_PENDING, rv);
880 EXPECT_FALSE(handle.is_initialized()); 880 EXPECT_FALSE(handle.is_initialized());
881 EXPECT_FALSE(handle.socket()); 881 EXPECT_FALSE(handle.socket());
882 882
883 EXPECT_EQ(OK, callback.WaitForResult()); 883 EXPECT_EQ(OK, callback.WaitForResult());
884 EXPECT_TRUE(handle.is_initialized()); 884 EXPECT_TRUE(handle.is_initialized());
885 EXPECT_TRUE(handle.socket()); 885 EXPECT_TRUE(handle.socket());
886 IPEndPoint endpoint; 886 IPEndPoint endpoint;
887 handle.socket()->GetLocalAddress(&endpoint); 887 handle.socket()->GetLocalAddress(&endpoint);
888 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size()); 888 EXPECT_TRUE(endpoint.address().IsIPv4());
889 889
890 // Check that the failed connection attempt on the main socket is collected. 890 // Check that the failed connection attempt on the main socket is collected.
891 ConnectionAttempts attempts; 891 ConnectionAttempts attempts;
892 handle.socket()->GetConnectionAttempts(&attempts); 892 handle.socket()->GetConnectionAttempts(&attempts);
893 ASSERT_EQ(1u, attempts.size()); 893 ASSERT_EQ(1u, attempts.size());
894 EXPECT_EQ(ERR_CONNECTION_FAILED, attempts[0].result); 894 EXPECT_EQ(ERR_CONNECTION_FAILED, attempts[0].result);
895 EXPECT_EQ(kIPv6AddressSize, attempts[0].endpoint.address().size()); 895 EXPECT_TRUE(attempts[0].endpoint.address().IsIPv6());
896 896
897 EXPECT_EQ(2, client_socket_factory_.allocation_count()); 897 EXPECT_EQ(2, client_socket_factory_.allocation_count());
898 } 898 }
899 899
900 // Test the case of the IPv6 address being slow, thus falling back to trying to 900 // Test the case of the IPv6 address being slow, thus falling back to trying to
901 // connect to the IPv4 address, but having the connect to the IPv6 address 901 // connect to the IPv4 address, but having the connect to the IPv6 address
902 // finish first. 902 // finish first.
903 TEST_F(TransportClientSocketPoolTest, IPv6FallbackSocketIPv6FinishesFirst) { 903 TEST_F(TransportClientSocketPoolTest, IPv6FallbackSocketIPv6FinishesFirst) {
904 // Create a pool without backup jobs. 904 // Create a pool without backup jobs.
905 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); 905 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
(...skipping 23 matching lines...) Expand all
929 callback.callback(), &pool, BoundNetLog()); 929 callback.callback(), &pool, BoundNetLog());
930 EXPECT_EQ(ERR_IO_PENDING, rv); 930 EXPECT_EQ(ERR_IO_PENDING, rv);
931 EXPECT_FALSE(handle.is_initialized()); 931 EXPECT_FALSE(handle.is_initialized());
932 EXPECT_FALSE(handle.socket()); 932 EXPECT_FALSE(handle.socket());
933 933
934 EXPECT_EQ(OK, callback.WaitForResult()); 934 EXPECT_EQ(OK, callback.WaitForResult());
935 EXPECT_TRUE(handle.is_initialized()); 935 EXPECT_TRUE(handle.is_initialized());
936 EXPECT_TRUE(handle.socket()); 936 EXPECT_TRUE(handle.socket());
937 IPEndPoint endpoint; 937 IPEndPoint endpoint;
938 handle.socket()->GetLocalAddress(&endpoint); 938 handle.socket()->GetLocalAddress(&endpoint);
939 EXPECT_EQ(kIPv6AddressSize, endpoint.address().size()); 939 EXPECT_TRUE(endpoint.address().IsIPv6());
940 940
941 // Check that the failed connection attempt on the fallback socket is 941 // Check that the failed connection attempt on the fallback socket is
942 // collected. 942 // collected.
943 ConnectionAttempts attempts; 943 ConnectionAttempts attempts;
944 handle.socket()->GetConnectionAttempts(&attempts); 944 handle.socket()->GetConnectionAttempts(&attempts);
945 ASSERT_EQ(1u, attempts.size()); 945 ASSERT_EQ(1u, attempts.size());
946 EXPECT_EQ(ERR_CONNECTION_FAILED, attempts[0].result); 946 EXPECT_EQ(ERR_CONNECTION_FAILED, attempts[0].result);
947 EXPECT_EQ(kIPv4AddressSize, attempts[0].endpoint.address().size()); 947 EXPECT_TRUE(attempts[0].endpoint.address().IsIPv4());
948 948
949 EXPECT_EQ(2, client_socket_factory_.allocation_count()); 949 EXPECT_EQ(2, client_socket_factory_.allocation_count());
950 } 950 }
951 951
952 TEST_F(TransportClientSocketPoolTest, IPv6NoIPv4AddressesToFallbackTo) { 952 TEST_F(TransportClientSocketPoolTest, IPv6NoIPv4AddressesToFallbackTo) {
953 // Create a pool without backup jobs. 953 // Create a pool without backup jobs.
954 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); 954 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
955 TransportClientSocketPool pool(kMaxSockets, kMaxSocketsPerGroup, 955 TransportClientSocketPool pool(kMaxSockets, kMaxSocketsPerGroup,
956 host_resolver_.get(), &client_socket_factory_, 956 host_resolver_.get(), &client_socket_factory_,
957 NULL, NULL); 957 NULL, NULL);
(...skipping 12 matching lines...) Expand all
970 callback.callback(), &pool, BoundNetLog()); 970 callback.callback(), &pool, BoundNetLog());
971 EXPECT_EQ(ERR_IO_PENDING, rv); 971 EXPECT_EQ(ERR_IO_PENDING, rv);
972 EXPECT_FALSE(handle.is_initialized()); 972 EXPECT_FALSE(handle.is_initialized());
973 EXPECT_FALSE(handle.socket()); 973 EXPECT_FALSE(handle.socket());
974 974
975 EXPECT_EQ(OK, callback.WaitForResult()); 975 EXPECT_EQ(OK, callback.WaitForResult());
976 EXPECT_TRUE(handle.is_initialized()); 976 EXPECT_TRUE(handle.is_initialized());
977 EXPECT_TRUE(handle.socket()); 977 EXPECT_TRUE(handle.socket());
978 IPEndPoint endpoint; 978 IPEndPoint endpoint;
979 handle.socket()->GetLocalAddress(&endpoint); 979 handle.socket()->GetLocalAddress(&endpoint);
980 EXPECT_EQ(kIPv6AddressSize, endpoint.address().size()); 980 EXPECT_TRUE(endpoint.address().IsIPv6());
981 EXPECT_EQ(0u, handle.connection_attempts().size()); 981 EXPECT_EQ(0u, handle.connection_attempts().size());
982 EXPECT_EQ(1, client_socket_factory_.allocation_count()); 982 EXPECT_EQ(1, client_socket_factory_.allocation_count());
983 } 983 }
984 984
985 TEST_F(TransportClientSocketPoolTest, IPv4HasNoFallback) { 985 TEST_F(TransportClientSocketPoolTest, IPv4HasNoFallback) {
986 // Create a pool without backup jobs. 986 // Create a pool without backup jobs.
987 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false); 987 ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled(false);
988 TransportClientSocketPool pool(kMaxSockets, kMaxSocketsPerGroup, 988 TransportClientSocketPool pool(kMaxSockets, kMaxSocketsPerGroup,
989 host_resolver_.get(), &client_socket_factory_, 989 host_resolver_.get(), &client_socket_factory_,
990 NULL, NULL); 990 NULL, NULL);
(...skipping 11 matching lines...) Expand all
1002 callback.callback(), &pool, BoundNetLog()); 1002 callback.callback(), &pool, BoundNetLog());
1003 EXPECT_EQ(ERR_IO_PENDING, rv); 1003 EXPECT_EQ(ERR_IO_PENDING, rv);
1004 EXPECT_FALSE(handle.is_initialized()); 1004 EXPECT_FALSE(handle.is_initialized());
1005 EXPECT_FALSE(handle.socket()); 1005 EXPECT_FALSE(handle.socket());
1006 1006
1007 EXPECT_EQ(OK, callback.WaitForResult()); 1007 EXPECT_EQ(OK, callback.WaitForResult());
1008 EXPECT_TRUE(handle.is_initialized()); 1008 EXPECT_TRUE(handle.is_initialized());
1009 EXPECT_TRUE(handle.socket()); 1009 EXPECT_TRUE(handle.socket());
1010 IPEndPoint endpoint; 1010 IPEndPoint endpoint;
1011 handle.socket()->GetLocalAddress(&endpoint); 1011 handle.socket()->GetLocalAddress(&endpoint);
1012 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size()); 1012 EXPECT_TRUE(endpoint.address().IsIPv4());
1013 EXPECT_EQ(0u, handle.connection_attempts().size()); 1013 EXPECT_EQ(0u, handle.connection_attempts().size());
1014 EXPECT_EQ(1, client_socket_factory_.allocation_count()); 1014 EXPECT_EQ(1, client_socket_factory_.allocation_count());
1015 } 1015 }
1016 1016
1017 // Test that if TCP FastOpen is enabled, it is set on the socket 1017 // Test that if TCP FastOpen is enabled, it is set on the socket
1018 // when we have only an IPv4 address. 1018 // when we have only an IPv4 address.
1019 TEST_F(TransportClientSocketPoolTest, TCPFastOpenOnIPv4WithNoFallback) { 1019 TEST_F(TransportClientSocketPoolTest, TCPFastOpenOnIPv4WithNoFallback) {
1020 SequencedSocketData socket_data(nullptr, 0, nullptr, 0); 1020 SequencedSocketData socket_data(nullptr, 0, nullptr, 0);
1021 MockClientSocketFactory factory; 1021 MockClientSocketFactory factory;
1022 factory.AddSocketDataProvider(&socket_data); 1022 factory.AddSocketDataProvider(&socket_data);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 TestCompletionCallback callback; 1086 TestCompletionCallback callback;
1087 ClientSocketHandle handle; 1087 ClientSocketHandle handle;
1088 // Enable TCP FastOpen in TransportSocketParams. 1088 // Enable TCP FastOpen in TransportSocketParams.
1089 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen(); 1089 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen();
1090 handle.Init("a", params, LOW, ClientSocketPool::RespectLimits::ENABLED, 1090 handle.Init("a", params, LOW, ClientSocketPool::RespectLimits::ENABLED,
1091 callback.callback(), &pool, BoundNetLog()); 1091 callback.callback(), &pool, BoundNetLog());
1092 EXPECT_EQ(OK, callback.WaitForResult()); 1092 EXPECT_EQ(OK, callback.WaitForResult());
1093 // Verify that the socket used is connected to the fallback IPv4 address. 1093 // Verify that the socket used is connected to the fallback IPv4 address.
1094 IPEndPoint endpoint; 1094 IPEndPoint endpoint;
1095 handle.socket()->GetPeerAddress(&endpoint); 1095 handle.socket()->GetPeerAddress(&endpoint);
1096 EXPECT_EQ(kIPv4AddressSize, endpoint.address().size()); 1096 EXPECT_TRUE(endpoint.address().IsIPv4());
1097 // Verify that TCP FastOpen was not turned on for the socket. 1097 // Verify that TCP FastOpen was not turned on for the socket.
1098 EXPECT_FALSE(socket_data_1.IsUsingTCPFastOpen()); 1098 EXPECT_FALSE(socket_data_1.IsUsingTCPFastOpen());
1099 } 1099 }
1100 1100
1101 // Test that if TCP FastOpen is enabled, it does not do anything when there 1101 // Test that if TCP FastOpen is enabled, it does not do anything when there
1102 // is a IPv6 address with fallback to an IPv4 address. This test tests the case 1102 // is a IPv6 address with fallback to an IPv4 address. This test tests the case
1103 // when the IPv6 connect succeeds. 1103 // when the IPv6 connect succeeds.
1104 TEST_F(TransportClientSocketPoolTest, 1104 TEST_F(TransportClientSocketPoolTest,
1105 NoTCPFastOpenOnIPv6SuccessWithIPv4Fallback) { 1105 NoTCPFastOpenOnIPv6SuccessWithIPv4Fallback) {
1106 SequencedSocketData socket_data(nullptr, 0, nullptr, 0); 1106 SequencedSocketData socket_data(nullptr, 0, nullptr, 0);
(...skipping 11 matching lines...) Expand all
1118 TestCompletionCallback callback; 1118 TestCompletionCallback callback;
1119 ClientSocketHandle handle; 1119 ClientSocketHandle handle;
1120 // Enable TCP FastOpen in TransportSocketParams. 1120 // Enable TCP FastOpen in TransportSocketParams.
1121 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen(); 1121 scoped_refptr<TransportSocketParams> params = CreateParamsForTCPFastOpen();
1122 handle.Init("a", params, LOW, ClientSocketPool::RespectLimits::ENABLED, 1122 handle.Init("a", params, LOW, ClientSocketPool::RespectLimits::ENABLED,
1123 callback.callback(), &pool, BoundNetLog()); 1123 callback.callback(), &pool, BoundNetLog());
1124 EXPECT_EQ(OK, callback.WaitForResult()); 1124 EXPECT_EQ(OK, callback.WaitForResult());
1125 IPEndPoint endpoint; 1125 IPEndPoint endpoint;
1126 handle.socket()->GetPeerAddress(&endpoint); 1126 handle.socket()->GetPeerAddress(&endpoint);
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 EXPECT_EQ(kIPv6AddressSize, endpoint.address().size()); 1128 EXPECT_TRUE(endpoint.address().IsIPv6());
1129 // Verify that TCP FastOpen was not turned on for the socket. 1129 // Verify that TCP FastOpen was not turned on for the socket.
1130 EXPECT_FALSE(socket_data.IsUsingTCPFastOpen()); 1130 EXPECT_FALSE(socket_data.IsUsingTCPFastOpen());
1131 } 1131 }
1132 1132
1133 } // namespace 1133 } // namespace
1134 1134
1135 } // namespace net 1135 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_socket_address_coder.cc ('k') | net/socket/websocket_transport_client_socket_pool_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698