--- a/media/mtransport/test/ice_unittest.cpp
+++ b/media/mtransport/test/ice_unittest.cpp
@@ -1350,16 +1350,20 @@ class IceTestPeer : public sigslot::has_
test_utils_->sts_target()->Dispatch(
WrapRunnableRet(&res, ice_ctx_->ctx(),
&NrIceCtx::SetControlling,
controlling),
NS_DISPATCH_SYNC);
ASSERT_TRUE(NS_SUCCEEDED(res));
}
+ NrIceCtx::Controlling GetControlling() {
+ return ice_ctx_->ctx()->GetControlling();
+ }
+
void SetTiebreaker(uint64_t tiebreaker) {
test_utils_->sts_target()->Dispatch(
WrapRunnable(this,
&IceTestPeer::SetTiebreaker_s,
tiebreaker),
NS_DISPATCH_SYNC);
}
@@ -2484,16 +2488,38 @@ TEST_F(WebRtcIceGatherTest, TestStunTcpA
Gather(0);
ASSERT_FALSE(StreamHasMatchingCandidate(0, "192.0.2.1", "UDP"));
ASSERT_FALSE(StreamHasMatchingCandidate(0, " 192.0.3.1 ", " tcptype "));
WaitForGather();
ASSERT_TRUE(StreamHasMatchingCandidate(0, "192.0.2.1", "UDP"));
ASSERT_TRUE(StreamHasMatchingCandidate(0, " 192.0.3.1 ", " tcptype "));
}
+TEST_F(WebRtcIceGatherTest, TestSetIceControlling) {
+ EnsurePeer();
+ peer_->SetControlling(NrIceCtx::ICE_CONTROLLING);
+ NrIceCtx::Controlling controlling = peer_->GetControlling();
+ ASSERT_EQ(NrIceCtx::ICE_CONTROLLING, controlling);
+ // SetControlling should only allow setting this once
+ peer_->SetControlling(NrIceCtx::ICE_CONTROLLED);
+ controlling = peer_->GetControlling();
+ ASSERT_EQ(NrIceCtx::ICE_CONTROLLING, controlling);
+}
+
+TEST_F(WebRtcIceGatherTest, TestSetIceControlled) {
+ EnsurePeer();
+ peer_->SetControlling(NrIceCtx::ICE_CONTROLLED);
+ NrIceCtx::Controlling controlling = peer_->GetControlling();
+ ASSERT_EQ(NrIceCtx::ICE_CONTROLLED, controlling);
+ // SetControlling should only allow setting this once
+ peer_->SetControlling(NrIceCtx::ICE_CONTROLLING);
+ controlling = peer_->GetControlling();
+ ASSERT_EQ(NrIceCtx::ICE_CONTROLLED, controlling);
+}
+
TEST_F(WebRtcIceConnectTest, TestGather) {
AddStream(1);
ASSERT_TRUE(Gather());
}
TEST_F(WebRtcIceConnectTest, TestGatherTcp) {
Init(false, true);
AddStream(1);
@@ -2542,17 +2568,16 @@ TEST_F(WebRtcIceConnectTest, TestConnect
p2_->FinalizeIceRestart();
SendReceive(p3_.get(), p2_.get()); // p3 and p2 are still connected
SendReceive(p1_.get(), p2_.get(), false, true); // p1 and p2 not connected
p3_ = nullptr;
}
-
TEST_F(WebRtcIceConnectTest, TestConnectRestartIceThenAbort) {
AddStream(1);
ASSERT_TRUE(Gather());
Connect();
SendReceive(p1_.get(), p2_.get());
p2_->RestartIce();
ASSERT_FALSE(p2_->gathering_complete());
@@ -2576,16 +2601,63 @@ TEST_F(WebRtcIceConnectTest, TestConnect
p2_->RollbackIceRestart();
SendReceive(p1_.get(), p2_.get()); // p1 and p2 are still connected
SendReceive(p3_.get(), p2_.get(), false, true); // p3 and p2 not connected
p3_ = nullptr;
}
+TEST_F(WebRtcIceConnectTest, TestConnectSetControllingAfterIceRestart) {
+ AddStream(1);
+ ASSERT_TRUE(Gather());
+ // Just for fun lets do this with switched rolls
+ p1_->SetControlling(NrIceCtx::ICE_CONTROLLED);
+ p2_->SetControlling(NrIceCtx::ICE_CONTROLLING);
+ Connect();
+ SendReceive(p1_.get(), p2_.get());
+ // Set rolls should not switch by connecting
+ ASSERT_EQ(NrIceCtx::ICE_CONTROLLED, p1_->GetControlling());
+ ASSERT_EQ(NrIceCtx::ICE_CONTROLLING, p2_->GetControlling());
+
+ p2_->RestartIce();
+ ASSERT_FALSE(p2_->gathering_complete());
+ // 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);
+ 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()));
+ std::cout << "-------------------------------------------------" << std::endl;
+ ConnectCallerAndCallee(p3_.get(), p2_.get());
+ // Again connecting should not result in role switch
+ ASSERT_EQ(NrIceCtx::ICE_CONTROLLED, p2_->GetControlling());
+ ASSERT_EQ(NrIceCtx::ICE_CONTROLLING, p3_->GetControlling());
+
+ p2_->FinalizeIceRestart();
+ // And again we are not allowed to switch roles at this point any more
+ p2_->SetControlling(NrIceCtx::ICE_CONTROLLING);
+ ASSERT_EQ(NrIceCtx::ICE_CONTROLLED, p2_->GetControlling());
+ p3_->SetControlling(NrIceCtx::ICE_CONTROLLED);
+ ASSERT_EQ(NrIceCtx::ICE_CONTROLLING, p3_->GetControlling());
+
+ p3_ = nullptr;
+}
TEST_F(WebRtcIceConnectTest, TestConnectTcp) {
Init(false, true);
AddStream(1);
ASSERT_TRUE(Gather());
SetCandidateFilter(IsTcpCandidate);
SetExpectedTypes(NrIceCandidate::Type::ICE_HOST,
NrIceCandidate::Type::ICE_HOST, kNrIceTransportTcp);