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

Side by Side Diff: p2p/client/basicportallocator_unittest.cc

Issue 3018493002: Making BasicPortAllocator tests slightly less fragile. (Closed)
Patch Set: Rebase onto master Created 3 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2009 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2009 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 864 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
865 kDefaultAllocationTimeout, fake_clock); 865 kDefaultAllocationTimeout, fake_clock);
866 EXPECT_EQ(1U, candidates_.size()); 866 EXPECT_EQ(1U, candidates_.size());
867 } 867 }
868 868
869 // Tests that we can get all the desired addresses successfully. 869 // Tests that we can get all the desired addresses successfully.
870 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithMinimumStepDelay) { 870 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithMinimumStepDelay) {
871 AddInterface(kClientAddr); 871 AddInterface(kClientAddr);
872 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 872 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
873 session_->StartGettingPorts(); 873 session_->StartGettingPorts();
874 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, 874 ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
875 fake_clock); 875 kDefaultAllocationTimeout, fake_clock);
876 EXPECT_EQ(7U, candidates_.size());
876 EXPECT_EQ(4U, ports_.size()); 877 EXPECT_EQ(4U, ports_.size());
877 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 878 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
878 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", kClientAddr); 879 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", kClientAddr);
879 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); 880 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr);
880 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); 881 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr);
881 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); 882 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr);
882 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); 883 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr);
883 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", 884 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp",
884 kRelaySslTcpIntAddr); 885 kRelaySslTcpIntAddr);
885 EXPECT_TRUE(candidate_allocation_done_);
886 } 886 }
887 887
888 // Test that when the same network interface is brought down and up, the 888 // Test that when the same network interface is brought down and up, the
889 // port allocator session will restart a new allocation sequence if 889 // port allocator session will restart a new allocation sequence if
890 // it is not stopped. 890 // it is not stopped.
891 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) { 891 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionNotStopped) {
892 std::string if_name("test_net0"); 892 std::string if_name("test_net0");
893 AddInterface(kClientAddr, if_name); 893 AddInterface(kClientAddr, if_name);
894 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 894 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
895 session_->StartGettingPorts(); 895 session_->StartGettingPorts();
896 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, 896 ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
897 fake_clock); 897 kDefaultAllocationTimeout, fake_clock);
898 EXPECT_EQ(7U, candidates_.size());
898 EXPECT_EQ(4U, ports_.size()); 899 EXPECT_EQ(4U, ports_.size());
899 EXPECT_TRUE(candidate_allocation_done_);
900 candidate_allocation_done_ = false; 900 candidate_allocation_done_ = false;
901 candidates_.clear(); 901 candidates_.clear();
902 ports_.clear(); 902 ports_.clear();
903 903
904 // Disable socket creation to simulate the network interface being down. When
905 // no network interfaces are available, BasicPortAllocator will fall back to
906 // binding to the "ANY" address, so we need to make sure that fails too.
907 fss_->set_tcp_sockets_enabled(false);
908 fss_->set_udp_sockets_enabled(false);
904 RemoveInterface(kClientAddr); 909 RemoveInterface(kClientAddr);
905 ASSERT_EQ_SIMULATED_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout, 910 SIMULATED_WAIT(false, 1000, fake_clock);
906 fake_clock); 911 EXPECT_EQ(0U, candidates_.size());
907 EXPECT_EQ(0U, ports_.size()); 912 ports_.clear();
908 EXPECT_FALSE(candidate_allocation_done_);
909 913
910 // When the same interfaces are added again, new candidates/ports should be 914 // When the same interfaces are added again, new candidates/ports should be
911 // generated. 915 // generated.
916 fss_->set_tcp_sockets_enabled(true);
917 fss_->set_udp_sockets_enabled(true);
912 AddInterface(kClientAddr, if_name); 918 AddInterface(kClientAddr, if_name);
913 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, 919 ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
914 fake_clock); 920 kDefaultAllocationTimeout, fake_clock);
921 EXPECT_EQ(7U, candidates_.size());
915 EXPECT_EQ(4U, ports_.size()); 922 EXPECT_EQ(4U, ports_.size());
916 EXPECT_TRUE(candidate_allocation_done_);
917 } 923 }
918 924
919 // Test that when the same network interface is brought down and up, the 925 // Test that when the same network interface is brought down and up, the
920 // port allocator session will not restart a new allocation sequence if 926 // port allocator session will not restart a new allocation sequence if
921 // it is stopped. 927 // it is stopped.
922 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionStopped) { 928 TEST_F(BasicPortAllocatorTest, TestSameNetworkDownAndUpWhenSessionStopped) {
923 std::string if_name("test_net0"); 929 std::string if_name("test_net0");
924 AddInterface(kClientAddr, if_name); 930 AddInterface(kClientAddr, if_name);
925 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 931 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
926 session_->StartGettingPorts(); 932 session_->StartGettingPorts();
927 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, 933 ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
928 fake_clock); 934 kDefaultAllocationTimeout, fake_clock);
935 EXPECT_EQ(7U, candidates_.size());
929 EXPECT_EQ(4U, ports_.size()); 936 EXPECT_EQ(4U, ports_.size());
930 EXPECT_TRUE(candidate_allocation_done_);
931 session_->StopGettingPorts(); 937 session_->StopGettingPorts();
932 candidates_.clear(); 938 candidates_.clear();
933 ports_.clear(); 939 ports_.clear();
934 940
935 RemoveInterface(kClientAddr); 941 RemoveInterface(kClientAddr);
936 ASSERT_EQ_SIMULATED_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout, 942 // Wait one (simulated) second and then verify no new candidates have
937 fake_clock); 943 // appeared.
944 SIMULATED_WAIT(false, 1000, fake_clock);
945 EXPECT_EQ(0U, candidates_.size());
938 EXPECT_EQ(0U, ports_.size()); 946 EXPECT_EQ(0U, ports_.size());
939 947
940 // When the same interfaces are added again, new candidates/ports should not 948 // When the same interfaces are added again, new candidates/ports should not
941 // be generated because the session has stopped. 949 // be generated because the session has stopped.
942 AddInterface(kClientAddr, if_name); 950 AddInterface(kClientAddr, if_name);
943 ASSERT_EQ_SIMULATED_WAIT(0U, candidates_.size(), kDefaultAllocationTimeout, 951 SIMULATED_WAIT(false, 1000, fake_clock);
944 fake_clock); 952 EXPECT_EQ(0U, candidates_.size());
945 EXPECT_EQ(0U, ports_.size()); 953 EXPECT_EQ(0U, ports_.size());
946 EXPECT_TRUE(candidate_allocation_done_);
947 } 954 }
948 955
949 // Verify candidates with default step delay of 1sec. 956 // Verify candidates with default step delay of 1sec.
950 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) { 957 TEST_F(BasicPortAllocatorTest, TestGetAllPortsWithOneSecondStepDelay) {
951 AddInterface(kClientAddr); 958 AddInterface(kClientAddr);
952 allocator_->set_step_delay(kDefaultStepDelay); 959 allocator_->set_step_delay(kDefaultStepDelay);
953 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 960 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
954 session_->StartGettingPorts(); 961 session_->StartGettingPorts();
955 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock); 962 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock);
956 EXPECT_EQ(2U, ports_.size()); 963 EXPECT_EQ(2U, ports_.size());
(...skipping 11 matching lines...) Expand all
968 EXPECT_EQ(4U, ports_.size()); 975 EXPECT_EQ(4U, ports_.size());
969 EXPECT_TRUE(candidate_allocation_done_); 976 EXPECT_TRUE(candidate_allocation_done_);
970 // If we Stop gathering now, we shouldn't get a second "done" callback. 977 // If we Stop gathering now, we shouldn't get a second "done" callback.
971 session_->StopGettingPorts(); 978 session_->StopGettingPorts();
972 } 979 }
973 980
974 TEST_F(BasicPortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) { 981 TEST_F(BasicPortAllocatorTest, TestSetupVideoRtpPortsWithNormalSendBuffers) {
975 AddInterface(kClientAddr); 982 AddInterface(kClientAddr);
976 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP, CN_VIDEO)); 983 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP, CN_VIDEO));
977 session_->StartGettingPorts(); 984 session_->StartGettingPorts();
978 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, 985 ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
979 fake_clock); 986 kDefaultAllocationTimeout, fake_clock);
980 EXPECT_TRUE(candidate_allocation_done_); 987 EXPECT_EQ(7U, candidates_.size());
981 // If we Stop gathering now, we shouldn't get a second "done" callback. 988 // If we Stop gathering now, we shouldn't get a second "done" callback.
982 session_->StopGettingPorts(); 989 session_->StopGettingPorts();
983 990
984 // All ports should have unset send-buffer sizes. 991 // All ports should have unset send-buffer sizes.
985 CheckSendBufferSizesOfAllPorts(-1); 992 CheckSendBufferSizesOfAllPorts(-1);
986 } 993 }
987 994
988 // Tests that we can get callback after StopGetAllPorts. 995 // Tests that we can get callback after StopGetAllPorts when called in the
996 // middle of gathering.
989 TEST_F(BasicPortAllocatorTest, TestStopGetAllPorts) { 997 TEST_F(BasicPortAllocatorTest, TestStopGetAllPorts) {
990 AddInterface(kClientAddr); 998 AddInterface(kClientAddr);
991 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 999 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
992 session_->StartGettingPorts(); 1000 session_->StartGettingPorts();
993 ASSERT_EQ_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout); 1001 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout,
1002 fake_clock);
994 EXPECT_EQ(2U, ports_.size()); 1003 EXPECT_EQ(2U, ports_.size());
995 session_->StopGettingPorts(); 1004 session_->StopGettingPorts();
996 EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); 1005 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1006 kDefaultAllocationTimeout, fake_clock);
997 } 1007 }
998 1008
999 // Test that we restrict client ports appropriately when a port range is set. 1009 // Test that we restrict client ports appropriately when a port range is set.
1000 // We check the candidates for udp/stun/tcp ports, and the from address 1010 // We check the candidates for udp/stun/tcp ports, and the from address
1001 // for relay ports. 1011 // for relay ports.
1002 TEST_F(BasicPortAllocatorTest, TestGetAllPortsPortRange) { 1012 TEST_F(BasicPortAllocatorTest, TestGetAllPortsPortRange) {
1003 AddInterface(kClientAddr); 1013 AddInterface(kClientAddr);
1004 // Check that an invalid port range fails. 1014 // Check that an invalid port range fails.
1005 EXPECT_FALSE(SetPortRange(kMaxPort, kMinPort)); 1015 EXPECT_FALSE(SetPortRange(kMaxPort, kMinPort));
1006 // Check that a null port range succeeds. 1016 // Check that a null port range succeeds.
1007 EXPECT_TRUE(SetPortRange(0, 0)); 1017 EXPECT_TRUE(SetPortRange(0, 0));
1008 // Check that a valid port range succeeds. 1018 // Check that a valid port range succeeds.
1009 EXPECT_TRUE(SetPortRange(kMinPort, kMaxPort)); 1019 EXPECT_TRUE(SetPortRange(kMinPort, kMaxPort));
1010 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1020 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1011 session_->StartGettingPorts(); 1021 session_->StartGettingPorts();
1012 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, 1022 ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1013 fake_clock); 1023 kDefaultAllocationTimeout, fake_clock);
1024 EXPECT_EQ(7U, candidates_.size());
1014 EXPECT_EQ(4U, ports_.size()); 1025 EXPECT_EQ(4U, ports_.size());
1015 1026
1016 int num_nonrelay_candidates = 0; 1027 int num_nonrelay_candidates = 0;
1017 for (const Candidate& candidate : candidates_) { 1028 for (const Candidate& candidate : candidates_) {
1018 // Check the port number for the UDP/STUN/TCP port objects. 1029 // Check the port number for the UDP/STUN/TCP port objects.
1019 if (candidate.type() != RELAY_PORT_TYPE) { 1030 if (candidate.type() != RELAY_PORT_TYPE) {
1020 EXPECT_PRED3(CheckPort, candidate.address(), kMinPort, kMaxPort); 1031 EXPECT_PRED3(CheckPort, candidate.address(), kMinPort, kMaxPort);
1021 ++num_nonrelay_candidates; 1032 ++num_nonrelay_candidates;
1022 } 1033 }
1023 } 1034 }
1024 EXPECT_EQ(3, num_nonrelay_candidates); 1035 EXPECT_EQ(3, num_nonrelay_candidates);
1025 // Check the port number used to connect to the relay server. 1036 // Check the port number used to connect to the relay server.
1026 EXPECT_PRED3(CheckPort, relay_server_.GetConnection(0).source(), kMinPort, 1037 EXPECT_PRED3(CheckPort, relay_server_.GetConnection(0).source(), kMinPort,
1027 kMaxPort); 1038 kMaxPort);
1028 EXPECT_TRUE(candidate_allocation_done_);
1029 } 1039 }
1030 1040
1031 // Test that if we have no network adapters, we bind to the ANY address and 1041 // Test that if we have no network adapters, we bind to the ANY address and
1032 // still get non-host candidates. 1042 // still get non-host candidates.
1033 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoAdapters) { 1043 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoAdapters) {
1034 // Default config uses GTURN and no NAT, so replace that with the 1044 // Default config uses GTURN and no NAT, so replace that with the
1035 // desired setup (NAT, STUN server, TURN server, UDP/TCP). 1045 // desired setup (NAT, STUN server, TURN server, UDP/TCP).
1036 ResetWithStunServerAndNat(kStunAddr); 1046 ResetWithStunServerAndNat(kStunAddr);
1037 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); 1047 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
1038 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); 1048 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 1000, fake_clock); 1221 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 1000, fake_clock);
1212 EXPECT_EQ(0U, candidates_.size()); 1222 EXPECT_EQ(0U, candidates_.size());
1213 } 1223 }
1214 1224
1215 // Test that we don't crash or malfunction if we can't create UDP sockets. 1225 // Test that we don't crash or malfunction if we can't create UDP sockets.
1216 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSockets) { 1226 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSockets) {
1217 AddInterface(kClientAddr); 1227 AddInterface(kClientAddr);
1218 fss_->set_udp_sockets_enabled(false); 1228 fss_->set_udp_sockets_enabled(false);
1219 EXPECT_TRUE(CreateSession(1)); 1229 EXPECT_TRUE(CreateSession(1));
1220 session_->StartGettingPorts(); 1230 session_->StartGettingPorts();
1221 ASSERT_EQ_SIMULATED_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout, 1231 ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1222 fake_clock); 1232 kDefaultAllocationTimeout, fake_clock);
1233 EXPECT_EQ(5U, candidates_.size());
1223 EXPECT_EQ(2U, ports_.size()); 1234 EXPECT_EQ(2U, ports_.size());
1224 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); 1235 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr);
1225 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); 1236 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr);
1226 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); 1237 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr);
1227 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); 1238 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr);
1228 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", 1239 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp",
1229 kRelaySslTcpIntAddr); 1240 kRelaySslTcpIntAddr);
1230 EXPECT_TRUE(candidate_allocation_done_);
1231 } 1241 }
1232 1242
1233 #endif // if !defined(ADDRESS_SANITIZER) 1243 #endif // if !defined(ADDRESS_SANITIZER)
1234 1244
1235 // Test that we don't crash or malfunction if we can't create UDP sockets or 1245 // Test that we don't crash or malfunction if we can't create UDP sockets or
1236 // listen on TCP sockets. We still give out a local TCP address, since 1246 // listen on TCP sockets. We still give out a local TCP address, since
1237 // apparently this is needed for the remote side to accept our connection. 1247 // apparently this is needed for the remote side to accept our connection.
1238 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSocketsNoTcpListen) { 1248 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpSocketsNoTcpListen) {
1239 AddInterface(kClientAddr); 1249 AddInterface(kClientAddr);
1240 fss_->set_udp_sockets_enabled(false); 1250 fss_->set_udp_sockets_enabled(false);
1241 fss_->set_tcp_listen_enabled(false); 1251 fss_->set_tcp_listen_enabled(false);
1242 EXPECT_TRUE(CreateSession(1)); 1252 EXPECT_TRUE(CreateSession(1));
1243 session_->StartGettingPorts(); 1253 session_->StartGettingPorts();
1244 ASSERT_EQ_SIMULATED_WAIT(5U, candidates_.size(), kDefaultAllocationTimeout, 1254 ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1245 fake_clock); 1255 kDefaultAllocationTimeout, fake_clock);
1256 EXPECT_EQ(5U, candidates_.size());
1246 EXPECT_EQ(2U, ports_.size()); 1257 EXPECT_EQ(2U, ports_.size());
1247 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr); 1258 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpIntAddr);
1248 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr); 1259 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", kRelayUdpExtAddr);
1249 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr); 1260 EXPECT_PRED4(HasCandidate, candidates_, "relay", "tcp", kRelayTcpIntAddr);
1250 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); 1261 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr);
1251 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp", 1262 EXPECT_PRED4(HasCandidate, candidates_, "relay", "ssltcp",
1252 kRelaySslTcpIntAddr); 1263 kRelaySslTcpIntAddr);
1253 EXPECT_TRUE(candidate_allocation_done_);
1254 } 1264 }
1255 1265
1256 // Test that we don't crash or malfunction if we can't create any sockets. 1266 // Test that we don't crash or malfunction if we can't create any sockets.
1257 // TODO(deadbeef): Find a way to exit early here. 1267 // TODO(deadbeef): Find a way to exit early here.
1258 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoSockets) { 1268 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoSockets) {
1259 AddInterface(kClientAddr); 1269 AddInterface(kClientAddr);
1260 fss_->set_tcp_sockets_enabled(false); 1270 fss_->set_tcp_sockets_enabled(false);
1261 fss_->set_udp_sockets_enabled(false); 1271 fss_->set_udp_sockets_enabled(false);
1262 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1272 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1263 session_->StartGettingPorts(); 1273 session_->StartGettingPorts();
1264 WAIT(candidates_.size() > 0, 2000); 1274 SIMULATED_WAIT(candidates_.size() > 0, 2000, fake_clock);
1265 // TODO(deadbeef): Check candidate_allocation_done signal. 1275 // TODO(deadbeef): Check candidate_allocation_done signal.
1266 // In case of Relay, ports creation will succeed but sockets will fail. 1276 // In case of Relay, ports creation will succeed but sockets will fail.
1267 // There is no error reporting from RelayEntry to handle this failure. 1277 // There is no error reporting from RelayEntry to handle this failure.
1268 } 1278 }
1269 1279
1270 // Testing STUN timeout. 1280 // Testing STUN timeout.
1271 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpAllowed) { 1281 TEST_F(BasicPortAllocatorTest, TestGetAllPortsNoUdpAllowed) {
1272 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr); 1282 fss_->AddRule(false, rtc::FP_UDP, rtc::FD_ANY, kClientAddr);
1273 AddInterface(kClientAddr); 1283 AddInterface(kClientAddr);
1274 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1284 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1309 EXPECT_EQ(2U, ports_.size()); 1319 EXPECT_EQ(2U, ports_.size());
1310 // Candidates priorities should be different. 1320 // Candidates priorities should be different.
1311 EXPECT_NE(candidates_[0].priority(), candidates_[1].priority()); 1321 EXPECT_NE(candidates_[0].priority(), candidates_[1].priority());
1312 } 1322 }
1313 1323
1314 // Test to verify ICE restart process. 1324 // Test to verify ICE restart process.
1315 TEST_F(BasicPortAllocatorTest, TestGetAllPortsRestarts) { 1325 TEST_F(BasicPortAllocatorTest, TestGetAllPortsRestarts) {
1316 AddInterface(kClientAddr); 1326 AddInterface(kClientAddr);
1317 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1327 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1318 session_->StartGettingPorts(); 1328 session_->StartGettingPorts();
1319 EXPECT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, 1329 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1320 fake_clock); 1330 kDefaultAllocationTimeout, fake_clock);
1331 EXPECT_EQ(7U, candidates_.size());
1321 EXPECT_EQ(4U, ports_.size()); 1332 EXPECT_EQ(4U, ports_.size());
1322 EXPECT_TRUE(candidate_allocation_done_);
1323 // TODO(deadbeef): Extend this to verify ICE restart. 1333 // TODO(deadbeef): Extend this to verify ICE restart.
1324 } 1334 }
1325 1335
1326 // Test that the allocator session uses the candidate filter it's created with, 1336 // Test that the allocator session uses the candidate filter it's created with,
1327 // rather than the filter of its parent allocator. 1337 // rather than the filter of its parent allocator.
1328 // The filter of the allocator should only affect the next gathering phase, 1338 // The filter of the allocator should only affect the next gathering phase,
1329 // according to JSEP, which means the *next* allocator session returned. 1339 // according to JSEP, which means the *next* allocator session returned.
1330 TEST_F(BasicPortAllocatorTest, TestSessionUsesOwnCandidateFilter) { 1340 TEST_F(BasicPortAllocatorTest, TestSessionUsesOwnCandidateFilter) {
1331 AddInterface(kClientAddr); 1341 AddInterface(kClientAddr);
1332 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1342 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1333 // Set candidate filter *after* creating the session. Should have no effect. 1343 // Set candidate filter *after* creating the session. Should have no effect.
1334 allocator().set_candidate_filter(CF_RELAY); 1344 allocator().set_candidate_filter(CF_RELAY);
1335 session_->StartGettingPorts(); 1345 session_->StartGettingPorts();
1336 // 7 candidates and 4 ports is what we would normally get (see the 1346 // 7 candidates and 4 ports is what we would normally get (see the
1337 // TestGetAllPorts* tests). 1347 // TestGetAllPorts* tests).
1338 EXPECT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, 1348 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1339 fake_clock); 1349 kDefaultAllocationTimeout, fake_clock);
1350 EXPECT_EQ(7U, candidates_.size());
1340 EXPECT_EQ(4U, ports_.size()); 1351 EXPECT_EQ(4U, ports_.size());
1341 EXPECT_TRUE(candidate_allocation_done_);
1342 } 1352 }
1343 1353
1344 // Test ICE candidate filter mechanism with options Relay/Host/Reflexive. 1354 // Test ICE candidate filter mechanism with options Relay/Host/Reflexive.
1345 // This test also verifies that when the allocator is only allowed to use 1355 // This test also verifies that when the allocator is only allowed to use
1346 // relay (i.e. IceTransportsType is relay), the raddr is an empty 1356 // relay (i.e. IceTransportsType is relay), the raddr is an empty
1347 // address with the correct family. This is to prevent any local 1357 // address with the correct family. This is to prevent any local
1348 // reflective address leakage in the sdp line. 1358 // reflective address leakage in the sdp line.
1349 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithRelayOnly) { 1359 TEST_F(BasicPortAllocatorTest, TestCandidateFilterWithRelayOnly) {
1350 AddInterface(kClientAddr); 1360 AddInterface(kClientAddr);
1351 // GTURN is not configured here. 1361 // GTURN is not configured here.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1417 for (const Candidate& candidate : candidates_) { 1427 for (const Candidate& candidate : candidates_) {
1418 EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidate.type()); 1428 EXPECT_EQ(std::string(LOCAL_PORT_TYPE), candidate.type());
1419 } 1429 }
1420 } 1430 }
1421 1431
1422 // Test that we get the same ufrag and pwd for all candidates. 1432 // Test that we get the same ufrag and pwd for all candidates.
1423 TEST_F(BasicPortAllocatorTest, TestEnableSharedUfrag) { 1433 TEST_F(BasicPortAllocatorTest, TestEnableSharedUfrag) {
1424 AddInterface(kClientAddr); 1434 AddInterface(kClientAddr);
1425 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1435 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1426 session_->StartGettingPorts(); 1436 session_->StartGettingPorts();
1427 ASSERT_EQ_SIMULATED_WAIT(7U, candidates_.size(), kDefaultAllocationTimeout, 1437 ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1428 fake_clock); 1438 kDefaultAllocationTimeout, fake_clock);
1439 EXPECT_EQ(7U, candidates_.size());
1429 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1440 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1430 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", kClientAddr); 1441 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", kClientAddr);
1431 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); 1442 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr);
1432 EXPECT_EQ(4U, ports_.size()); 1443 EXPECT_EQ(4U, ports_.size());
1433 for (const Candidate& candidate : candidates_) { 1444 for (const Candidate& candidate : candidates_) {
1434 EXPECT_EQ(kIceUfrag0, candidate.username()); 1445 EXPECT_EQ(kIceUfrag0, candidate.username());
1435 EXPECT_EQ(kIcePwd0, candidate.password()); 1446 EXPECT_EQ(kIcePwd0, candidate.password());
1436 } 1447 }
1437 EXPECT_TRUE(candidate_allocation_done_);
1438 } 1448 }
1439 1449
1440 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port 1450 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled only one port
1441 // is allocated for udp and stun. Also verify there is only one candidate 1451 // is allocated for udp and stun. Also verify there is only one candidate
1442 // (local) if stun candidate is same as local candidate, which will be the case 1452 // (local) if stun candidate is same as local candidate, which will be the case
1443 // in a public network like the below test. 1453 // in a public network like the below test.
1444 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNat) { 1454 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithoutNat) {
1445 AddInterface(kClientAddr); 1455 AddInterface(kClientAddr);
1446 allocator_->set_flags(allocator().flags() | 1456 allocator_->set_flags(allocator().flags() |
1447 PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1457 PORTALLOCATOR_ENABLE_SHARED_SOCKET);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); 1496 AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr);
1487 1497
1488 allocator_->set_step_delay(kMinimumStepDelay); 1498 allocator_->set_step_delay(kMinimumStepDelay);
1489 allocator_->set_flags(allocator().flags() | 1499 allocator_->set_flags(allocator().flags() |
1490 PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1500 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1491 PORTALLOCATOR_DISABLE_TCP); 1501 PORTALLOCATOR_DISABLE_TCP);
1492 1502
1493 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1503 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1494 session_->StartGettingPorts(); 1504 session_->StartGettingPorts();
1495 1505
1496 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout, 1506 ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1497 fake_clock); 1507 kDefaultAllocationTimeout, fake_clock);
1508 ASSERT_EQ(3U, candidates_.size());
1498 ASSERT_EQ(3U, ports_.size()); 1509 ASSERT_EQ(3U, ports_.size());
1499 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1510 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1500 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", 1511 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp",
1501 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1512 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1502 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", 1513 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp",
1503 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1514 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1504 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1505 kDefaultAllocationTimeout, fake_clock);
1506 EXPECT_EQ(3U, candidates_.size());
1507 } 1515 }
1508 1516
1509 // Test that if prune_turn_ports is set, TCP TURN port will not be used 1517 // Test that if prune_turn_ports is set, TCP TURN port will not be used
1510 // if UDP TurnPort is used, given that TCP TURN port becomes ready first. 1518 // if UDP TurnPort is used, given that TCP TURN port becomes ready first.
1511 TEST_F(BasicPortAllocatorTest, 1519 TEST_F(BasicPortAllocatorTest,
1512 TestUdpTurnPortPrunesTcpTurnPortWithTcpPortReadyFirst) { 1520 TestUdpTurnPortPrunesTcpTurnPortWithTcpPortReadyFirst) {
1513 // UDP has longer delay than TCP so that TCP TURN port becomes ready first. 1521 // UDP has longer delay than TCP so that TCP TURN port becomes ready first.
1514 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntAddr, 200); 1522 virtual_socket_server()->SetDelayOnAddress(kTurnUdpIntAddr, 200);
1515 virtual_socket_server()->SetDelayOnAddress(kTurnTcpIntAddr, 100); 1523 virtual_socket_server()->SetDelayOnAddress(kTurnTcpIntAddr, 100);
1516 1524
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 1623
1616 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 1624 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
1617 1625
1618 allocator_->set_flags(allocator().flags() | 1626 allocator_->set_flags(allocator().flags() |
1619 PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1627 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1620 PORTALLOCATOR_DISABLE_TCP); 1628 PORTALLOCATOR_DISABLE_TCP);
1621 1629
1622 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1630 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1623 session_->StartGettingPorts(); 1631 session_->StartGettingPorts();
1624 1632
1625 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout, 1633 ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1626 fake_clock); 1634 kDefaultAllocationTimeout, fake_clock);
1635 EXPECT_EQ(3U, candidates_.size());
1627 ASSERT_EQ(2U, ports_.size()); 1636 ASSERT_EQ(2U, ports_.size());
1628 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1637 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1629 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp", 1638 EXPECT_PRED4(HasCandidate, candidates_, "stun", "udp",
1630 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0)); 1639 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0));
1631 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", 1640 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp",
1632 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1641 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1633 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_, 1642 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1634 kDefaultAllocationTimeout, fake_clock); 1643 kDefaultAllocationTimeout, fake_clock);
1635 EXPECT_EQ(3U, candidates_.size());
1636 // Local port will be created first and then TURN port. 1644 // Local port will be created first and then TURN port.
1645 // TODO(deadbeef): This isn't something the BasicPortAllocator API contract
1646 // guarantees...
1637 EXPECT_EQ(2U, ports_[0]->Candidates().size()); 1647 EXPECT_EQ(2U, ports_[0]->Candidates().size());
1638 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 1648 EXPECT_EQ(1U, ports_[1]->Candidates().size());
1639 } 1649 }
1640 1650
1641 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled and the TURN 1651 // Test that when PORTALLOCATOR_ENABLE_SHARED_SOCKET is enabled and the TURN
1642 // server is also used as the STUN server, we should get 'local', 'stun', and 1652 // server is also used as the STUN server, we should get 'local', 'stun', and
1643 // 'relay' candidates. 1653 // 'relay' candidates.
1644 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) { 1654 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAsStun) {
1645 AddInterface(kClientAddr); 1655 AddInterface(kClientAddr);
1646 // Use an empty SocketAddress to add a NAT without STUN server. 1656 // Use an empty SocketAddress to add a NAT without STUN server.
1647 ResetWithStunServerAndNat(SocketAddress()); 1657 ResetWithStunServerAndNat(SocketAddress());
1648 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 1658 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
1649 1659
1650 // Must set the step delay to 0 to make sure the relay allocation phase is 1660 // Must set the step delay to 0 to make sure the relay allocation phase is
1651 // started before the STUN candidates are obtained, so that the STUN binding 1661 // started before the STUN candidates are obtained, so that the STUN binding
1652 // response is processed when both StunPort and TurnPort exist to reproduce 1662 // response is processed when both StunPort and TurnPort exist to reproduce
1653 // webrtc issue 3537. 1663 // webrtc issue 3537.
1654 allocator_->set_step_delay(0); 1664 allocator_->set_step_delay(0);
1655 allocator_->set_flags(allocator().flags() | 1665 allocator_->set_flags(allocator().flags() |
1656 PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1666 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1657 PORTALLOCATOR_DISABLE_TCP); 1667 PORTALLOCATOR_DISABLE_TCP);
1658 1668
1659 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1669 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1660 session_->StartGettingPorts(); 1670 session_->StartGettingPorts();
1661 1671
1662 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout, 1672 ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1663 fake_clock); 1673 kDefaultAllocationTimeout, fake_clock);
1674 EXPECT_EQ(3U, candidates_.size());
1664 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1675 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1665 Candidate stun_candidate; 1676 Candidate stun_candidate;
1666 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp", 1677 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp",
1667 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate); 1678 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate);
1668 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp", 1679 EXPECT_PRED5(HasCandidateWithRelatedAddr, candidates_, "relay", "udp",
1669 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0), 1680 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0),
1670 stun_candidate.address()); 1681 stun_candidate.address());
1671 1682
1672 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1673 kDefaultAllocationTimeout, fake_clock);
1674 EXPECT_EQ(3U, candidates_.size());
1675 // Local port will be created first and then TURN port. 1683 // Local port will be created first and then TURN port.
1684 // TODO(deadbeef): This isn't something the BasicPortAllocator API contract
1685 // guarantees...
1676 EXPECT_EQ(2U, ports_[0]->Candidates().size()); 1686 EXPECT_EQ(2U, ports_[0]->Candidates().size());
1677 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 1687 EXPECT_EQ(1U, ports_[1]->Candidates().size());
1678 } 1688 }
1679 1689
1680 // Test that when only a TCP TURN server is available, we do NOT use it as 1690 // Test that when only a TCP TURN server is available, we do NOT use it as
1681 // a UDP STUN server, as this could leak our IP address. Thus we should only 1691 // a UDP STUN server, as this could leak our IP address. Thus we should only
1682 // expect two ports, a UDPPort and TurnPort. 1692 // expect two ports, a UDPPort and TurnPort.
1683 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) { 1693 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnTcpOnly) {
1684 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP); 1694 turn_server_.AddInternalSocket(kTurnTcpIntAddr, PROTO_TCP);
1685 AddInterface(kClientAddr); 1695 AddInterface(kClientAddr);
1686 ResetWithStunServerAndNat(rtc::SocketAddress()); 1696 ResetWithStunServerAndNat(rtc::SocketAddress());
1687 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr); 1697 AddTurnServers(rtc::SocketAddress(), kTurnTcpIntAddr);
1688 1698
1689 allocator_->set_flags(allocator().flags() | 1699 allocator_->set_flags(allocator().flags() |
1690 PORTALLOCATOR_ENABLE_SHARED_SOCKET | 1700 PORTALLOCATOR_ENABLE_SHARED_SOCKET |
1691 PORTALLOCATOR_DISABLE_TCP); 1701 PORTALLOCATOR_DISABLE_TCP);
1692 1702
1693 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1703 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1694 session_->StartGettingPorts(); 1704 session_->StartGettingPorts();
1695 1705
1696 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), kDefaultAllocationTimeout, 1706 ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1697 fake_clock); 1707 kDefaultAllocationTimeout, fake_clock);
1708 EXPECT_EQ(2U, candidates_.size());
1698 ASSERT_EQ(2U, ports_.size()); 1709 ASSERT_EQ(2U, ports_.size());
1699 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1710 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1700 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp", 1711 EXPECT_PRED4(HasCandidate, candidates_, "relay", "udp",
1701 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0)); 1712 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0));
1702 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1703 kDefaultAllocationTimeout, fake_clock);
1704 EXPECT_EQ(2U, candidates_.size());
1705 EXPECT_EQ(1U, ports_[0]->Candidates().size()); 1713 EXPECT_EQ(1U, ports_[0]->Candidates().size());
1706 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 1714 EXPECT_EQ(1U, ports_[1]->Candidates().size());
1707 } 1715 }
1708 1716
1709 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the 1717 // Test that even when PORTALLOCATOR_ENABLE_SHARED_SOCKET is NOT enabled, the
1710 // TURN server is used as the STUN server and we get 'local', 'stun', and 1718 // TURN server is used as the STUN server and we get 'local', 'stun', and
1711 // 'relay' candidates. 1719 // 'relay' candidates.
1712 // TODO(deadbeef): Remove this test when support for non-shared socket mode 1720 // TODO(deadbeef): Remove this test when support for non-shared socket mode
1713 // is removed. 1721 // is removed.
1714 TEST_F(BasicPortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) { 1722 TEST_F(BasicPortAllocatorTest, TestNonSharedSocketWithNatUsingTurnAsStun) {
1715 AddInterface(kClientAddr); 1723 AddInterface(kClientAddr);
1716 // Use an empty SocketAddress to add a NAT without STUN server. 1724 // Use an empty SocketAddress to add a NAT without STUN server.
1717 ResetWithStunServerAndNat(SocketAddress()); 1725 ResetWithStunServerAndNat(SocketAddress());
1718 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); 1726 AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress());
1719 1727
1720 allocator_->set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_TCP); 1728 allocator_->set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_TCP);
1721 1729
1722 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1730 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1723 session_->StartGettingPorts(); 1731 session_->StartGettingPorts();
1724 1732
1725 ASSERT_EQ_SIMULATED_WAIT(3U, candidates_.size(), kDefaultAllocationTimeout, 1733 ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1726 fake_clock); 1734 kDefaultAllocationTimeout, fake_clock);
1735 EXPECT_EQ(3U, candidates_.size());
1727 ASSERT_EQ(3U, ports_.size()); 1736 ASSERT_EQ(3U, ports_.size());
1728 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1737 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1729 Candidate stun_candidate; 1738 Candidate stun_candidate;
1730 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp", 1739 EXPECT_PRED5(FindCandidate, candidates_, "stun", "udp",
1731 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate); 1740 rtc::SocketAddress(kNatUdpAddr.ipaddr(), 0), &stun_candidate);
1732 Candidate turn_candidate; 1741 Candidate turn_candidate;
1733 EXPECT_PRED5(FindCandidate, candidates_, "relay", "udp", 1742 EXPECT_PRED5(FindCandidate, candidates_, "relay", "udp",
1734 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0), 1743 rtc::SocketAddress(kTurnUdpExtAddr.ipaddr(), 0),
1735 &turn_candidate); 1744 &turn_candidate);
1736 // Not using shared socket, so the STUN request's server reflexive address 1745 // Not using shared socket, so the STUN request's server reflexive address
1737 // should be different than the TURN request's server reflexive address. 1746 // should be different than the TURN request's server reflexive address.
1738 EXPECT_NE(turn_candidate.related_address(), stun_candidate.address()); 1747 EXPECT_NE(turn_candidate.related_address(), stun_candidate.address());
1739 1748
1740 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1741 kDefaultAllocationTimeout, fake_clock);
1742 EXPECT_EQ(3U, candidates_.size());
1743 EXPECT_EQ(1U, ports_[0]->Candidates().size()); 1749 EXPECT_EQ(1U, ports_[0]->Candidates().size());
1744 EXPECT_EQ(1U, ports_[1]->Candidates().size()); 1750 EXPECT_EQ(1U, ports_[1]->Candidates().size());
1745 EXPECT_EQ(1U, ports_[2]->Candidates().size()); 1751 EXPECT_EQ(1U, ports_[2]->Candidates().size());
1746 } 1752 }
1747 1753
1748 // Test that even when both a STUN and TURN server are configured, the TURN 1754 // Test that even when both a STUN and TURN server are configured, the TURN
1749 // server is used as a STUN server and we get a 'stun' candidate. 1755 // server is used as a STUN server and we get a 'stun' candidate.
1750 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) { 1756 TEST_F(BasicPortAllocatorTest, TestSharedSocketWithNatUsingTurnAndStun) {
1751 AddInterface(kClientAddr); 1757 AddInterface(kClientAddr);
1752 // Configure with STUN server but destroy it, so we can ensure that it's 1758 // Configure with STUN server but destroy it, so we can ensure that it's
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1823 // This test verifies allocator can use IPv6 addresses along with IPv4. 1829 // This test verifies allocator can use IPv6 addresses along with IPv4.
1824 TEST_F(BasicPortAllocatorTest, TestEnableIPv6Addresses) { 1830 TEST_F(BasicPortAllocatorTest, TestEnableIPv6Addresses) {
1825 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY | 1831 allocator().set_flags(allocator().flags() | PORTALLOCATOR_DISABLE_RELAY |
1826 PORTALLOCATOR_ENABLE_IPV6 | 1832 PORTALLOCATOR_ENABLE_IPV6 |
1827 PORTALLOCATOR_ENABLE_SHARED_SOCKET); 1833 PORTALLOCATOR_ENABLE_SHARED_SOCKET);
1828 AddInterface(kClientIPv6Addr); 1834 AddInterface(kClientIPv6Addr);
1829 AddInterface(kClientAddr); 1835 AddInterface(kClientAddr);
1830 allocator_->set_step_delay(kMinimumStepDelay); 1836 allocator_->set_step_delay(kMinimumStepDelay);
1831 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1837 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1832 session_->StartGettingPorts(); 1838 session_->StartGettingPorts();
1833 ASSERT_EQ_SIMULATED_WAIT(4U, ports_.size(), kDefaultAllocationTimeout, 1839 ASSERT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1834 fake_clock); 1840 kDefaultAllocationTimeout, fake_clock);
1841 EXPECT_EQ(4U, ports_.size());
1835 EXPECT_EQ(4U, candidates_.size()); 1842 EXPECT_EQ(4U, candidates_.size());
1836 EXPECT_TRUE_SIMULATED_WAIT(candidate_allocation_done_,
1837 kDefaultAllocationTimeout, fake_clock);
1838 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientIPv6Addr); 1843 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientIPv6Addr);
1839 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr); 1844 EXPECT_PRED4(HasCandidate, candidates_, "local", "udp", kClientAddr);
1840 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientIPv6Addr); 1845 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientIPv6Addr);
1841 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr); 1846 EXPECT_PRED4(HasCandidate, candidates_, "local", "tcp", kClientAddr);
1842 EXPECT_EQ(4U, candidates_.size());
1843 } 1847 }
1844 1848
1845 TEST_F(BasicPortAllocatorTest, TestStopGettingPorts) { 1849 TEST_F(BasicPortAllocatorTest, TestStopGettingPorts) {
1846 AddInterface(kClientAddr); 1850 AddInterface(kClientAddr);
1847 allocator_->set_step_delay(kDefaultStepDelay); 1851 allocator_->set_step_delay(kDefaultStepDelay);
1848 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP)); 1852 EXPECT_TRUE(CreateSession(ICE_CANDIDATE_COMPONENT_RTP));
1849 session_->StartGettingPorts(); 1853 session_->StartGettingPorts();
1850 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock); 1854 ASSERT_EQ_SIMULATED_WAIT(2U, candidates_.size(), 1000, fake_clock);
1851 EXPECT_EQ(2U, ports_.size()); 1855 EXPECT_EQ(2U, ports_.size());
1852 session_->StopGettingPorts(); 1856 session_->StopGettingPorts();
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1954 for (const Candidate& candidate : candidates) { 1958 for (const Candidate& candidate : candidates) {
1955 // Expect only relay candidates now that the filter is applied. 1959 // Expect only relay candidates now that the filter is applied.
1956 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type()); 1960 EXPECT_EQ(std::string(RELAY_PORT_TYPE), candidate.type());
1957 // Expect that the raddr is emptied due to the CF_RELAY filter. 1961 // Expect that the raddr is emptied due to the CF_RELAY filter.
1958 EXPECT_EQ(candidate.related_address(), 1962 EXPECT_EQ(candidate.related_address(),
1959 rtc::EmptySocketAddressWithFamily(candidate.address().family())); 1963 rtc::EmptySocketAddressWithFamily(candidate.address().family()));
1960 } 1964 }
1961 } 1965 }
1962 1966
1963 } // namespace cricket 1967 } // namespace cricket
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698