--- a/media/mtransport/test/ice_unittest.cpp
+++ b/media/mtransport/test/ice_unittest.cpp
@@ -180,17 +180,16 @@ public:
enum TrickleMode { TRICKLE_NONE, TRICKLE_SIMULATE, TRICKLE_REAL };
enum ConsentStatus { CONSENT_FRESH, CONSENT_STALE, CONSENT_EXPIRED};
const unsigned int ICE_TEST_PEER_OFFERER = (1 << 0);
const unsigned int ICE_TEST_PEER_ALLOW_LOOPBACK = (1 << 1);
const unsigned int ICE_TEST_PEER_ENABLED_TCP = (1 << 2);
const unsigned int ICE_TEST_PEER_ALLOW_LINK_LOCAL = (1 << 3);
-const unsigned int ICE_TEST_PEER_HIDE_NON_DEFAULT = (1 << 4);
typedef std::string (*CandidateFilter)(const std::string& candidate);
std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) {
@@ -379,21 +378,22 @@ class SchedulableTrickleCandidate {
class IceTestPeer : public sigslot::has_slots<> {
public:
// TODO(ekr@rtfm.com): Convert to flags when NrIceCtx::Create() does.
// Bug 1193437.
IceTestPeer(const std::string& name, MtransportTestUtils* utils,
bool offerer,
bool allow_loopback = false, bool enable_tcp = true,
- bool allow_link_local = false, bool hide_non_default = false) :
+ bool allow_link_local = false,
+ NrIceCtx::Policy ice_policy = NrIceCtx::ICE_POLICY_ALL) :
name_(name),
ice_ctx_(NrIceCtxHandler::Create(name, offerer, allow_loopback,
enable_tcp, allow_link_local,
- hide_non_default)),
+ ice_policy)),
candidates_(),
shutting_down_(false),
gathering_complete_(false),
ready_ct_(0),
ice_complete_(false),
ice_reached_checking_(false),
received_(0),
sent_(0),
@@ -528,21 +528,24 @@ class IceTestPeer : public sigslot::has_
}
void SetDNSResolver() {
ASSERT_TRUE(NS_SUCCEEDED(dns_resolver_->Init()));
ASSERT_TRUE(NS_SUCCEEDED(ice_ctx_->ctx()->SetResolver(
dns_resolver_->AllocateResolver())));
}
- void Gather() {
+ void Gather(bool default_route_only = false) {
nsresult res;
test_utils_->sts_target()->Dispatch(
- WrapRunnableRet(&res, ice_ctx_->ctx(), &NrIceCtx::StartGathering),
+ WrapRunnableRet(&res,
+ ice_ctx_->ctx(),
+ &NrIceCtx::StartGathering,
+ default_route_only),
NS_DISPATCH_SYNC);
ASSERT_TRUE(NS_SUCCEEDED(res));
}
void UseNat() {
nat_->enabled_ = true;
}
@@ -1457,18 +1460,17 @@ class WebRtcIceGatherTest : public StunT
}
void EnsurePeer(const unsigned int flags = ICE_TEST_PEER_OFFERER) {
if (!peer_) {
peer_ = MakeUnique<IceTestPeer>("P1", test_utils_,
flags & ICE_TEST_PEER_OFFERER,
flags & ICE_TEST_PEER_ALLOW_LOOPBACK,
flags & ICE_TEST_PEER_ENABLED_TCP,
- flags & ICE_TEST_PEER_ALLOW_LINK_LOCAL,
- flags & ICE_TEST_PEER_HIDE_NON_DEFAULT);
+ flags & ICE_TEST_PEER_ALLOW_LINK_LOCAL);
peer_->AddStream(1);
}
}
void Gather(unsigned int waitTime = kDefaultTimeout) {
EnsurePeer();
peer_->Gather();
@@ -1632,26 +1634,26 @@ class WebRtcIceConnectTest : public Stun
void RemoveStream(size_t index) {
p1_->RemoveStream(index);
p2_->RemoveStream(index);
}
void Init(bool allow_loopback,
bool enable_tcp,
- bool default_only = false,
- bool setup_stun_servers = true) {
+ bool setup_stun_servers = true,
+ NrIceCtx::Policy ice_policy = NrIceCtx::ICE_POLICY_ALL) {
if (initted_) {
return;
}
p1_ = MakeUnique<IceTestPeer>("P1", test_utils_, true, allow_loopback,
- enable_tcp, false, default_only);
+ enable_tcp, false, ice_policy);
p2_ = MakeUnique<IceTestPeer>("P2", test_utils_, false, allow_loopback,
- enable_tcp, false, default_only);
+ enable_tcp, false, ice_policy);
InitPeer(p1_.get(), setup_stun_servers);
InitPeer(p2_.get(), setup_stun_servers);
initted_ = true;
}
void InitPeer(IceTestPeer* peer, bool setup_stun_servers = true) {
if (use_nat_) {
@@ -1674,27 +1676,32 @@ class WebRtcIceConnectTest : public Stun
kDefaultStunServerPort, kNrIceTransportUdp));
stun_servers.push_back(*NrIceStunServer::Create(stun_server_address_,
kDefaultStunServerPort, kNrIceTransportTcp));
peer->SetStunServers(stun_servers);
}
}
- bool Gather(unsigned int waitTime = kDefaultTimeout) {
+ bool Gather(unsigned int waitTime = kDefaultTimeout,
+ bool default_route_only = false) {
Init(false, false);
- return GatherCallerAndCallee(p1_.get(), p2_.get(), waitTime);
+ return GatherCallerAndCallee(p1_.get(),
+ p2_.get(),
+ waitTime,
+ default_route_only);
}
bool GatherCallerAndCallee(IceTestPeer* caller,
IceTestPeer* callee,
- unsigned int waitTime = kDefaultTimeout) {
- caller->Gather();
- callee->Gather();
+ unsigned int waitTime = kDefaultTimeout,
+ bool default_route_only = false) {
+ caller->Gather(default_route_only);
+ callee->Gather(default_route_only);
if (waitTime) {
EXPECT_TRUE_WAIT(caller->gathering_complete(), waitTime);
if (!caller->gathering_complete())
return false;
EXPECT_TRUE_WAIT(callee->gathering_complete(), waitTime);
if (!callee->gathering_complete())
return false;
@@ -2139,22 +2146,22 @@ TEST_F(WebRtcIceGatherTest, TestGatherFa
}
EnsurePeer();
peer_->SetStunServer(stun_server_address_, kDefaultStunServerPort);
peer_->SetFakeResolver(stun_server_address_, stun_server_hostname_);
Gather();
}
-TEST_F(WebRtcIceGatherTest, TestGatherStunServerIpAddressDefaultRouteOnly) {
+TEST_F(WebRtcIceGatherTest, TestGatherStunServerIpAddressNoHost) {
if (stun_server_address_.empty()) {
return;
}
- peer_ = MakeUnique<IceTestPeer>("P1", test_utils_, true, false, false, false, true);
+ peer_ = MakeUnique<IceTestPeer>("P1", test_utils_, true, false, false, false, NrIceCtx::ICE_POLICY_NO_HOST);
peer_->AddStream(1);
peer_->SetStunServer(stun_server_address_, kDefaultStunServerPort);
peer_->SetFakeResolver(stun_server_address_, stun_server_hostname_);
Gather();
ASSERT_FALSE(StreamHasMatchingCandidate(0, " host "));
}
TEST_F(WebRtcIceGatherTest, TestGatherFakeStunServerHostname) {
@@ -2441,38 +2448,36 @@ TEST_F(WebRtcIceGatherTest, TestStunServ
UseFakeStunUdpServerWithResponse("192.0.2.1", 3333);
TestStunServer::GetInstance(AF_INET)->SetDropInitialPackets(3);
Gather(0);
ASSERT_FALSE(StreamHasMatchingCandidate(0, "192.0.2.1"));
WaitForGather();
ASSERT_TRUE(StreamHasMatchingCandidate(0, "192.0.2.1"));
}
-// Test default route only with our fake STUN server and
-// apparently NATted.
-TEST_F(WebRtcIceGatherTest, TestFakeStunServerNatedDefaultRouteOnly) {
- peer_ = MakeUnique<IceTestPeer>("P1", test_utils_, true, false, false, false, true);
+// Test no host with our fake STUN server and apparently NATted.
+TEST_F(WebRtcIceGatherTest, TestFakeStunServerNatedNoHost) {
+ peer_ = MakeUnique<IceTestPeer>("P1", test_utils_, true, false, false, false, NrIceCtx::ICE_POLICY_NO_HOST);
peer_->AddStream(1);
UseFakeStunUdpServerWithResponse("192.0.2.1", 3333);
Gather(0);
WaitForGather();
DumpCandidates(0);
ASSERT_FALSE(StreamHasMatchingCandidate(0, "host"));
ASSERT_TRUE(StreamHasMatchingCandidate(0, "srflx"));
NrIceCandidate default_candidate;
nsresult rv = peer_->GetDefaultCandidate(0, &default_candidate);
if (NS_SUCCEEDED(rv)) {
ASSERT_NE(NrIceCandidate::ICE_HOST, default_candidate.type);
}
}
-// Test default route only with our fake STUN server and
-// apparently non-NATted.
-TEST_F(WebRtcIceGatherTest, TestFakeStunServerNoNatDefaultRouteOnly) {
- peer_ = MakeUnique<IceTestPeer>("P1", test_utils_, true, false, false, false, true);
+// Test no host with our fake STUN server and apparently non-NATted.
+TEST_F(WebRtcIceGatherTest, TestFakeStunServerNoNatNoHost) {
+ peer_ = MakeUnique<IceTestPeer>("P1", test_utils_, true, false, false, false, NrIceCtx::ICE_POLICY_NO_HOST);
peer_->AddStream(1);
UseTestStunServer();
Gather(0);
WaitForGather();
DumpCandidates(0);
ASSERT_FALSE(StreamHasMatchingCandidate(0, "host"));
ASSERT_TRUE(StreamHasMatchingCandidate(0, "srflx"));
}
@@ -2553,18 +2558,17 @@ TEST_F(WebRtcIceConnectTest, TestConnect
p2_->RestartIce();
ASSERT_FALSE(p2_->gathering_complete());
// verify p1 and p2 streams are still connected after restarting ice on p2
SendReceive(p1_.get(), p2_.get());
mozilla::UniquePtr<IceTestPeer> p3_;
- p3_ = MakeUnique<IceTestPeer>("P3", test_utils_, true, false,
- false, false, false);
+ p3_ = MakeUnique<IceTestPeer>("P3", test_utils_, true, false, false, false);
InitPeer(p3_.get());
p3_->AddStream(1);
p2_->AddStream(1);
ASSERT_TRUE(GatherCallerAndCallee(p2_.get(), p3_.get()));
std::cout << "-------------------------------------------------" << std::endl;
ConnectCallerAndCallee(p3_.get(), p2_.get());
SendReceive(p1_.get(), p2_.get()); // p1 and p2 still connected
@@ -2586,18 +2590,17 @@ TEST_F(WebRtcIceConnectTest, TestConnect
p2_->RestartIce();
ASSERT_FALSE(p2_->gathering_complete());
// verify p1 and p2 streams are still connected after restarting ice on p2
SendReceive(p1_.get(), p2_.get());
mozilla::UniquePtr<IceTestPeer> p3_;
- p3_ = MakeUnique<IceTestPeer>("P3", test_utils_, true, false,
- false, false, false);
+ p3_ = MakeUnique<IceTestPeer>("P3", test_utils_, true, false, false, false);
InitPeer(p3_.get());
p3_->AddStream(1);
p2_->AddStream(1);
ASSERT_TRUE(GatherCallerAndCallee(p2_.get(), p3_.get()));
std::cout << "-------------------------------------------------" << std::endl;
ConnectCallerAndCallee(p3_.get(), p2_.get());
SendReceive(p1_.get(), p2_.get()); // p1 and p2 still connected
@@ -2628,18 +2631,17 @@ TEST_F(WebRtcIceConnectTest, TestConnect
// ICE restart should allow us to set control role again
p2_->SetControlling(NrIceCtx::ICE_CONTROLLED);
ASSERT_EQ(NrIceCtx::ICE_CONTROLLED, p2_->GetControlling());
// But still only allowed to set control role once
p2_->SetControlling(NrIceCtx::ICE_CONTROLLING);
ASSERT_EQ(NrIceCtx::ICE_CONTROLLED, p2_->GetControlling());
mozilla::UniquePtr<IceTestPeer> p3_;
- p3_ = MakeUnique<IceTestPeer>("P3", test_utils_, true, false,
- false, false, false);
+ p3_ = MakeUnique<IceTestPeer>("P3", test_utils_, true, false, false, false);
InitPeer(p3_.get());
p3_->AddStream(1);
// Set control role for p3 accordingly (w/o role conflict)
p3_->SetControlling(NrIceCtx::ICE_CONTROLLING);
ASSERT_EQ(NrIceCtx::ICE_CONTROLLING, p3_->GetControlling());
p2_->AddStream(1);
ASSERT_TRUE(GatherCallerAndCallee(p2_.get(), p3_.get()));
@@ -2677,27 +2679,27 @@ TEST_F(WebRtcIceConnectTest, DISABLED_Te
ASSERT_TRUE(Gather());
SetCandidateFilter(IsTcpSoCandidate);
SetExpectedTypes(NrIceCandidate::Type::ICE_HOST,
NrIceCandidate::Type::ICE_HOST, kNrIceTransportTcp);
Connect();
}
// Disabled because this breaks with hairpinning.
-TEST_F(WebRtcIceConnectTest, DISABLED_TestConnectDefaultRouteOnly) {
- Init(false, false, true);
+TEST_F(WebRtcIceConnectTest, DISABLED_TestConnectNoHost) {
+ Init(false, false, false, NrIceCtx::ICE_POLICY_NO_HOST);
AddStream(1);
ASSERT_TRUE(Gather());
SetExpectedTypes(NrIceCandidate::Type::ICE_SERVER_REFLEXIVE,
NrIceCandidate::Type::ICE_SERVER_REFLEXIVE, kNrIceTransportTcp);
Connect();
}
TEST_F(WebRtcIceConnectTest, TestLoopbackOnlySortOf) {
- Init(true, false, false, false);
+ Init(true, false, false);
AddStream(1);
SetCandidateFilter(IsLoopbackCandidate);
ASSERT_TRUE(Gather());
SetExpectedRemoteCandidateAddr("127.0.0.1");
Connect();
}
TEST_F(WebRtcIceConnectTest, TestConnectBothControllingP1Wins) {
@@ -2784,33 +2786,34 @@ TEST_F(WebRtcIceConnectTest, TestConnect
UseNat();
AddStream(1);
SetExpectedTypes(NrIceCandidate::Type::ICE_SERVER_REFLEXIVE,
NrIceCandidate::Type::ICE_SERVER_REFLEXIVE);
ASSERT_TRUE(Gather());
Connect();
}
-TEST_F(WebRtcIceConnectTest, TestConnectNoNatRouteOnly) {
- Init(false, false, true, false);
+TEST_F(WebRtcIceConnectTest, TestConnectNoNatNoHost) {
+ Init(false, false, false, NrIceCtx::ICE_POLICY_NO_HOST);
AddStream(1);
UseTestStunServer();
// Because we are connecting from our host candidate to the
// other side's apparent srflx (which is also their host)
// we see a host/srflx pair.
SetExpectedTypes(NrIceCandidate::Type::ICE_HOST,
NrIceCandidate::Type::ICE_SERVER_REFLEXIVE);
ASSERT_TRUE(Gather());
Connect();
}
-TEST_F(WebRtcIceConnectTest, TestConnectFullConeDefaultRouteOnly) {
+TEST_F(WebRtcIceConnectTest, TestConnectFullConeNoHost) {
UseNat();
- Init(false, false, true);
+ Init(false, false, false, NrIceCtx::ICE_POLICY_NO_HOST);
AddStream(1);
+ UseTestStunServer();
SetExpectedTypes(NrIceCandidate::Type::ICE_SERVER_REFLEXIVE,
NrIceCandidate::Type::ICE_SERVER_REFLEXIVE);
ASSERT_TRUE(Gather());
Connect();
}
TEST_F(WebRtcIceConnectTest, TestGatherAddressRestrictedCone) {
UseNat();
@@ -3522,17 +3525,17 @@ TEST_F(WebRtcIceConnectTest, TestPollCan
ASSERT_NE(0U, pairs.size());
ASSERT_TRUE(p2_->CandidatePairsPriorityDescending(pairs));
ASSERT_TRUE(ContainsSucceededPair(pairs));
}
// TODO Bug 1259842 - disabled until we find a better way to handle two
// candidates from different RFC1918 ranges
TEST_F(WebRtcIceConnectTest, DISABLED_TestHostCandPairingFilter) {
- Init(false, false, false, false);
+ Init(false, false, false);
AddStream(1);
ASSERT_TRUE(Gather());
SetCandidateFilter(IsIpv4Candidate);
int host_net = p1_->GetCandidatesPrivateIpv4Range(0);
if (host_net <= 0) {
// TODO bug 1226838: make this work with multiple private IPs
FAIL() << "This test needs exactly one private IPv4 host candidate to work" << std::endl;
@@ -3556,17 +3559,17 @@ TEST_F(WebRtcIceConnectTest, DISABLED_Te
}
// TODO Bug 1226838 - See Comment 2 - this test can't work as written
TEST_F(WebRtcIceConnectTest, DISABLED_TestSrflxCandPairingFilter) {
if (stun_server_address_.empty()) {
return;
}
- Init(false, false, false, false);
+ Init(false, false, false);
AddStream(1);
ASSERT_TRUE(Gather());
SetCandidateFilter(IsSrflxCandidate);
if (p1_->GetCandidatesPrivateIpv4Range(0) <= 0) {
// TODO bug 1226838: make this work with public IP addresses
std::cerr << "Don't run this test at IETF meetings!" << std::endl;
FAIL() << "This test needs one private IPv4 host candidate to work" << std::endl;