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

Unified Diff: webrtc/api/webrtcsession_unittest.cc

Issue 1648813004: Remove candidates when doing continual gathering (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Address Alex's comments Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/api/webrtcsession.cc ('k') | webrtc/examples/androidapp/src/org/appspot/apprtc/AppRTCClient.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/api/webrtcsession_unittest.cc
diff --git a/webrtc/api/webrtcsession_unittest.cc b/webrtc/api/webrtcsession_unittest.cc
index 87ff927f7a990ff2ab9ba1584966181ecbab22c8..a599dc50f042d0f2d7088a7939df7e17304c85a3 100644
--- a/webrtc/api/webrtcsession_unittest.cc
+++ b/webrtc/api/webrtcsession_unittest.cc
@@ -189,11 +189,18 @@ class MockIceObserver : public webrtc::IceObserver {
EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
}
+ // Some local candidates are removed.
+ void OnIceCandidatesRemoved(
+ const std::vector<cricket::Candidate>& candidates) {
+ num_candidates_removed_ += candidates.size();
+ }
+
bool oncandidatesready_;
std::vector<cricket::Candidate> mline_0_candidates_;
std::vector<cricket::Candidate> mline_1_candidates_;
PeerConnectionInterface::IceConnectionState ice_connection_state_;
PeerConnectionInterface::IceGatheringState ice_gathering_state_;
+ size_t num_candidates_removed_ = 0;
};
class WebRtcSessionForTest : public webrtc::WebRtcSession {
@@ -358,6 +365,9 @@ class WebRtcSessionTest
void AddInterface(const SocketAddress& addr) {
network_manager_.AddInterface(addr);
}
+ void RemoveInterface(const SocketAddress& addr) {
+ network_manager_.RemoveInterface(addr);
+ }
// If |dtls_identity_store| != null or |rtc_configuration| contains
// |certificates| then DTLS will be enabled unless explicitly disabled by
@@ -2106,12 +2116,14 @@ TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
"Called in wrong state: STATE_INIT", answer);
}
-TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
+// Tests that the remote candidates are added and removed successfully.
+TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
Init();
SendAudioVideoStream1();
- cricket::Candidate candidate;
- candidate.set_component(1);
+ cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
+ "", "", "host", 0, "");
+ candidate.set_transport_name("audio");
JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
// Fail since we have not set a remote description.
@@ -2129,6 +2141,7 @@ TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
candidate.set_component(2);
+ candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
@@ -2154,9 +2167,16 @@ TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
+
+ // Remove candidate1 and candidate2
+ std::vector<cricket::Candidate> remote_candidates;
+ remote_candidates.push_back(ice_candidate1.candidate());
+ remote_candidates.push_back(ice_candidate2.candidate());
+ EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
+ EXPECT_EQ(0u, candidates->count());
}
-// Test that a remote candidate is added to the remote session description and
+// Tests that a remote candidate is added to the remote session description and
// that it is retained if the remote session description is changed.
TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
Init();
@@ -2209,8 +2229,11 @@ TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
}
// Test that local candidates are added to the local session description and
-// that they are retained if the local session description is changed.
-TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
+// that they are retained if the local session description is changed. And if
+// continual gathering is enabled, they are removed from the local session
+// description when the network is down.
+TEST_F(WebRtcSessionTest,
+ TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
Init();
SendAudioVideoStream1();
@@ -2243,6 +2266,43 @@ TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
candidates = local_desc->candidates(1);
ASSERT_TRUE(candidates != NULL);
EXPECT_EQ(0u, candidates->count());
+
+ candidates = local_desc->candidates(kMediaContentIndex0);
+ size_t num_local_candidates = candidates->count();
+ // Enable Continual Gathering
+ session_->SetIceConfig(cricket::IceConfig(-1, -1, true, false, -1));
+ // Bring down the network interface to trigger candidate removals.
+ RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
+ // Verify that all local candidates are removed.
+ EXPECT_EQ(0, observer_.num_candidates_removed_);
+ EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
+ kIceCandidatesTimeout);
+ EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
+}
+
+// Tests that if continual gathering is disabled, local candidates won't be
+// removed when the interface is turned down.
+TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
+ AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
+ Init();
+ SendAudioVideoStream1();
+ CreateAndSetRemoteOfferAndLocalAnswer();
+
+ const SessionDescriptionInterface* local_desc = session_->local_description();
+ const IceCandidateCollection* candidates =
+ local_desc->candidates(kMediaContentIndex0);
+ ASSERT_TRUE(candidates != NULL);
+ EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
+
+ size_t num_local_candidates = candidates->count();
+ EXPECT_LT(0u, num_local_candidates);
+ // By default, Continual Gathering is disabled.
+ // Bring down the network interface.
+ RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
+ // Verify that the local candidates are not removed.
+ rtc::Thread::Current()->ProcessMessages(1000);
+ EXPECT_EQ(0, observer_.num_candidates_removed_);
+ EXPECT_EQ(num_local_candidates, candidates->count());
}
// Test that we can set a remote session description with remote candidates.
« no previous file with comments | « webrtc/api/webrtcsession.cc ('k') | webrtc/examples/androidapp/src/org/appspot/apprtc/AppRTCClient.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698