Index: webrtc/p2p/client/portallocator_unittest.cc |
diff --git a/webrtc/p2p/client/portallocator_unittest.cc b/webrtc/p2p/client/portallocator_unittest.cc |
index 73bf45bd7675d595992d083f24e888e1df2e1370..7436d4cf92371e268e59d33134f41b9f77fd9abc 100644 |
--- a/webrtc/p2p/client/portallocator_unittest.cc |
+++ b/webrtc/p2p/client/portallocator_unittest.cc |
@@ -262,11 +262,15 @@ class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> { |
// it should be ignore. |
void CheckDisableAdapterEnumeration( |
uint32 total_ports, |
+ const rtc::IPAddress& host_candidate_addr, |
const rtc::IPAddress& stun_candidate_addr, |
const rtc::IPAddress& relay_candidate_udp_transport_addr, |
const rtc::IPAddress& relay_candidate_tcp_transport_addr) { |
- EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
- session_->set_flags(cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION | |
+ if (!session_) { |
+ EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
+ } |
+ session_->set_flags(session_->flags() | |
+ cricket::PORTALLOCATOR_DISABLE_ADAPTER_ENUMERATION | |
cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG | |
cricket::PORTALLOCATOR_ENABLE_SHARED_SOCKET); |
allocator().set_allow_tcp_listen(false); |
@@ -274,28 +278,36 @@ class PortAllocatorTest : public testing::Test, public sigslot::has_slots<> { |
EXPECT_TRUE_WAIT(candidate_allocation_done_, kDefaultAllocationTimeout); |
uint32 total_candidates = 0; |
- if (!IPIsUnspec(stun_candidate_addr)) { |
+ if (!IPIsUnspec(host_candidate_addr)) { |
+ EXPECT_PRED5(CheckCandidate, candidates_[total_candidates], |
+ cricket::ICE_CANDIDATE_COMPONENT_RTP, "local", "udp", |
+ rtc::SocketAddress(host_candidate_addr, 0)); |
++total_candidates; |
- EXPECT_PRED5(CheckCandidate, candidates_[0], |
+ } |
+ if (!IPIsUnspec(stun_candidate_addr)) { |
+ EXPECT_PRED5(CheckCandidate, candidates_[total_candidates], |
cricket::ICE_CANDIDATE_COMPONENT_RTP, "stun", "udp", |
rtc::SocketAddress(stun_candidate_addr, 0)); |
- EXPECT_EQ( |
- rtc::EmptySocketAddressWithFamily(candidates_[0].address().family()), |
- candidates_[0].related_address()); |
+ EXPECT_EQ(rtc::EmptySocketAddressWithFamily( |
+ candidates_[total_candidates].address().family()), |
+ candidates_[total_candidates].related_address()); |
+ ++total_candidates; |
} |
if (!IPIsUnspec(relay_candidate_udp_transport_addr)) { |
- ++total_candidates; |
- EXPECT_PRED5(CheckCandidate, candidates_[1], |
+ EXPECT_PRED5(CheckCandidate, candidates_[total_candidates], |
cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
rtc::SocketAddress(relay_candidate_udp_transport_addr, 0)); |
- EXPECT_EQ(stun_candidate_addr, candidates_[1].related_address().ipaddr()); |
+ EXPECT_EQ(stun_candidate_addr, |
+ candidates_[total_candidates].related_address().ipaddr()); |
+ ++total_candidates; |
} |
if (!IPIsUnspec(relay_candidate_tcp_transport_addr)) { |
- ++total_candidates; |
- EXPECT_PRED5(CheckCandidate, candidates_[2], |
+ EXPECT_PRED5(CheckCandidate, candidates_[total_candidates], |
cricket::ICE_CANDIDATE_COMPONENT_RTP, "relay", "udp", |
rtc::SocketAddress(relay_candidate_tcp_transport_addr, 0)); |
- EXPECT_EQ(stun_candidate_addr, candidates_[2].related_address().ipaddr()); |
+ EXPECT_EQ(stun_candidate_addr, |
+ candidates_[total_candidates].related_address().ipaddr()); |
+ ++total_candidates; |
} |
EXPECT_EQ(total_candidates, candidates_.size()); |
@@ -509,7 +521,7 @@ TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationBehindNat) { |
AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
// Expect to see 3 ports: STUN, TURN/UDP and TCP ports, and both STUN and |
// TURN/UDP candidates. |
- CheckDisableAdapterEnumeration(3U, kNatUdpAddr.ipaddr(), |
+ CheckDisableAdapterEnumeration(3U, rtc::IPAddress(), kNatUdpAddr.ipaddr(), |
kTurnUdpExtAddr.ipaddr(), rtc::IPAddress()); |
} |
@@ -523,7 +535,7 @@ TEST_F(PortAllocatorTest, |
AddTurnServers(kTurnUdpIntAddr, rtc::SocketAddress()); |
// Expect to see 3 ports: STUN, TURN/UDP and TCP ports, and both STUN and |
// TURN/UDP candidates. |
- CheckDisableAdapterEnumeration(3U, kNatUdpAddr.ipaddr(), |
+ CheckDisableAdapterEnumeration(3U, rtc::IPAddress(), kNatUdpAddr.ipaddr(), |
kTurnUdpExtAddr.ipaddr(), rtc::IPAddress()); |
} |
@@ -537,7 +549,7 @@ TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationBehindNatWithTcp) { |
AddTurnServers(kTurnUdpIntAddr, kTurnTcpIntAddr); |
// Expect to see 4 ports - STUN, TURN/UDP, TURN/TCP and TCP port. STUN, |
// TURN/UDP, and TURN/TCP candidates. |
- CheckDisableAdapterEnumeration(4U, kNatUdpAddr.ipaddr(), |
+ CheckDisableAdapterEnumeration(4U, rtc::IPAddress(), kNatUdpAddr.ipaddr(), |
kTurnUdpExtAddr.ipaddr(), |
kTurnUdpExtAddr.ipaddr()); |
} |
@@ -552,7 +564,7 @@ TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationWithoutNat) { |
// Expect to see 3 ports: STUN, TURN/UDP and TCP ports, but only both STUN and |
// TURN candidates. The STUN candidate should have kClientAddr as srflx |
// address, and TURN candidate with kClientAddr as the related address. |
- CheckDisableAdapterEnumeration(3U, kClientAddr.ipaddr(), |
+ CheckDisableAdapterEnumeration(3U, rtc::IPAddress(), kClientAddr.ipaddr(), |
kTurnUdpExtAddr.ipaddr(), rtc::IPAddress()); |
} |
@@ -563,6 +575,22 @@ TEST_F(PortAllocatorTest, TestDisableAdapterEnumerationWithoutNatOrServers) { |
ResetWithNoServers(); |
// Expect to see 2 ports: STUN and TCP ports, but no candidate. |
CheckDisableAdapterEnumeration(2U, rtc::IPAddress(), rtc::IPAddress(), |
+ rtc::IPAddress(), rtc::IPAddress()); |
+} |
+ |
+// Test that when adapter enumeration is disabled, with |
+// PORTALLOCATOR_ENABLE_LOCALHOST_CANDIDATE specified, for endpoints not behind |
+// a NAT, there are a localhost candidate in addition to a STUN candidate. |
+TEST_F(PortAllocatorTest, |
+ TestDisableAdapterEnumerationWithoutNatLocalhostCandidateRequested) { |
+ AddInterfaceAsDefaultRoute(kClientAddr); |
+ ResetWithStunServer(kStunAddr); |
+ EXPECT_TRUE(CreateSession(cricket::ICE_CANDIDATE_COMPONENT_RTP)); |
+ session_->set_flags(cricket::PORTALLOCATOR_ENABLE_LOCALHOST_CANDIDATE); |
+ // Expect to see 2 ports: STUN and TCP ports, localhost candidate and STUN |
+ // candidate. |
+ CheckDisableAdapterEnumeration(2U, rtc::GetLoopbackIP(AF_INET), |
+ kClientAddr.ipaddr(), rtc::IPAddress(), |
rtc::IPAddress()); |
} |