Bug 1269486: tests to verify new ICE controller setting restriction. r=mjf

MozReview-Commit-ID: EaJ2yE0Vwcr

--HG--
extra : rebase_source : 3d696984a16a7ada6da57b90424f1b351f1e589f
This commit is contained in:
Nils Ohlmeier [:drno] 2016-05-04 10:53:29 -07:00
Родитель cd54d864ed
Коммит a4d7ea2e6b
1 изменённых файлов: 73 добавлений и 1 удалений

Просмотреть файл

@ -1355,6 +1355,10 @@ class IceTestPeer : public sigslot::has_slots<> {
ASSERT_TRUE(NS_SUCCEEDED(res)); ASSERT_TRUE(NS_SUCCEEDED(res));
} }
NrIceCtx::Controlling GetControlling() {
return ice_ctx_->ctx()->GetControlling();
}
void SetTiebreaker(uint64_t tiebreaker) { void SetTiebreaker(uint64_t tiebreaker) {
test_utils_->sts_target()->Dispatch( test_utils_->sts_target()->Dispatch(
WrapRunnable(this, WrapRunnable(this,
@ -2489,6 +2493,28 @@ TEST_F(WebRtcIceGatherTest, TestStunTcpAndUdpServerTrickle) {
ASSERT_TRUE(StreamHasMatchingCandidate(0, " 192.0.3.1 ", " tcptype ")); 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) { TEST_F(WebRtcIceConnectTest, TestGather) {
AddStream(1); AddStream(1);
ASSERT_TRUE(Gather()); ASSERT_TRUE(Gather());
@ -2547,7 +2573,6 @@ TEST_F(WebRtcIceConnectTest, TestConnectRestartIce) {
p3_ = nullptr; p3_ = nullptr;
} }
TEST_F(WebRtcIceConnectTest, TestConnectRestartIceThenAbort) { TEST_F(WebRtcIceConnectTest, TestConnectRestartIceThenAbort) {
AddStream(1); AddStream(1);
ASSERT_TRUE(Gather()); ASSERT_TRUE(Gather());
@ -2581,6 +2606,53 @@ TEST_F(WebRtcIceConnectTest, TestConnectRestartIceThenAbort) {
p3_ = nullptr; 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) { TEST_F(WebRtcIceConnectTest, TestConnectTcp) {
Init(false, true); Init(false, true);