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

Side by Side Diff: webrtc/api/webrtcsession_unittest.cc

Issue 1785613011: Revert of Remove candidates when doing continual gathering (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 break; 182 break;
183 default: 183 default:
184 ASSERT(false); 184 ASSERT(false);
185 } 185 }
186 186
187 // The ICE gathering state should always be Gathering when a candidate is 187 // The ICE gathering state should always be Gathering when a candidate is
188 // received (or possibly Completed in the case of the final candidate). 188 // received (or possibly Completed in the case of the final candidate).
189 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_); 189 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
190 } 190 }
191 191
192 // Some local candidates are removed.
193 void OnIceCandidatesRemoved(
194 const std::vector<cricket::Candidate>& candidates) {
195 num_candidates_removed_ += candidates.size();
196 }
197
198 bool oncandidatesready_; 192 bool oncandidatesready_;
199 std::vector<cricket::Candidate> mline_0_candidates_; 193 std::vector<cricket::Candidate> mline_0_candidates_;
200 std::vector<cricket::Candidate> mline_1_candidates_; 194 std::vector<cricket::Candidate> mline_1_candidates_;
201 PeerConnectionInterface::IceConnectionState ice_connection_state_; 195 PeerConnectionInterface::IceConnectionState ice_connection_state_;
202 PeerConnectionInterface::IceGatheringState ice_gathering_state_; 196 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
203 size_t num_candidates_removed_ = 0;
204 }; 197 };
205 198
206 class WebRtcSessionForTest : public webrtc::WebRtcSession { 199 class WebRtcSessionForTest : public webrtc::WebRtcSession {
207 public: 200 public:
208 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller, 201 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
209 rtc::Thread* signaling_thread, 202 rtc::Thread* signaling_thread,
210 rtc::Thread* worker_thread, 203 rtc::Thread* worker_thread,
211 cricket::PortAllocator* port_allocator, 204 cricket::PortAllocator* port_allocator,
212 webrtc::IceObserver* ice_observer) 205 webrtc::IceObserver* ice_observer)
213 : WebRtcSession(media_controller, 206 : WebRtcSession(media_controller,
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | 351 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
359 cricket::PORTALLOCATOR_DISABLE_RELAY); 352 cricket::PORTALLOCATOR_DISABLE_RELAY);
360 EXPECT_TRUE(channel_manager_->Init()); 353 EXPECT_TRUE(channel_manager_->Init());
361 desc_factory_->set_add_legacy_streams(false); 354 desc_factory_->set_add_legacy_streams(false);
362 allocator_->set_step_delay(cricket::kMinimumStepDelay); 355 allocator_->set_step_delay(cricket::kMinimumStepDelay);
363 } 356 }
364 357
365 void AddInterface(const SocketAddress& addr) { 358 void AddInterface(const SocketAddress& addr) {
366 network_manager_.AddInterface(addr); 359 network_manager_.AddInterface(addr);
367 } 360 }
368 void RemoveInterface(const SocketAddress& addr) {
369 network_manager_.RemoveInterface(addr);
370 }
371 361
372 // If |dtls_identity_store| != null or |rtc_configuration| contains 362 // If |dtls_identity_store| != null or |rtc_configuration| contains
373 // |certificates| then DTLS will be enabled unless explicitly disabled by 363 // |certificates| then DTLS will be enabled unless explicitly disabled by
374 // |rtc_configuration| options. When DTLS is enabled a certificate will be 364 // |rtc_configuration| options. When DTLS is enabled a certificate will be
375 // used if provided, otherwise one will be generated using the 365 // used if provided, otherwise one will be generated using the
376 // |dtls_identity_store|. 366 // |dtls_identity_store|.
377 void Init( 367 void Init(
378 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { 368 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) {
379 ASSERT_TRUE(session_.get() == NULL); 369 ASSERT_TRUE(session_.get() == NULL);
380 session_.reset(new WebRtcSessionForTest( 370 session_.reset(new WebRtcSessionForTest(
(...skipping 1728 matching lines...) Expand 10 before | Expand all | Expand 10 after
2109 Init(); 2099 Init();
2110 SendNothing(); 2100 SendNothing();
2111 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); 2101 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2112 2102
2113 SessionDescriptionInterface* answer = 2103 SessionDescriptionInterface* answer =
2114 CreateRemoteAnswer(offer.get()); 2104 CreateRemoteAnswer(offer.get());
2115 SetRemoteDescriptionAnswerExpectError( 2105 SetRemoteDescriptionAnswerExpectError(
2116 "Called in wrong state: STATE_INIT", answer); 2106 "Called in wrong state: STATE_INIT", answer);
2117 } 2107 }
2118 2108
2119 // Tests that the remote candidates are added and removed successfully. 2109 TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
2120 TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
2121 Init(); 2110 Init();
2122 SendAudioVideoStream1(); 2111 SendAudioVideoStream1();
2123 2112
2124 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0, 2113 cricket::Candidate candidate;
2125 "", "", "host", 0, ""); 2114 candidate.set_component(1);
2126 candidate.set_transport_name("audio");
2127 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate); 2115 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2128 2116
2129 // Fail since we have not set a remote description. 2117 // Fail since we have not set a remote description.
2130 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1)); 2118 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2131 2119
2132 SessionDescriptionInterface* offer = CreateOffer(); 2120 SessionDescriptionInterface* offer = CreateOffer();
2133 SetLocalDescriptionWithoutError(offer); 2121 SetLocalDescriptionWithoutError(offer);
2134 2122
2135 // Fail since we have not set a remote description. 2123 // Fail since we have not set a remote description.
2136 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1)); 2124 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2137 2125
2138 SessionDescriptionInterface* answer = CreateRemoteAnswer( 2126 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2139 session_->local_description()); 2127 session_->local_description());
2140 SetRemoteDescriptionWithoutError(answer); 2128 SetRemoteDescriptionWithoutError(answer);
2141 2129
2142 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1)); 2130 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2143 candidate.set_component(2); 2131 candidate.set_component(2);
2144 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
2145 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate); 2132 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2146 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); 2133 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2147 2134
2148 // Verifying the candidates are copied properly from internal vector. 2135 // Verifying the candidates are copied properly from internal vector.
2149 const SessionDescriptionInterface* remote_desc = 2136 const SessionDescriptionInterface* remote_desc =
2150 session_->remote_description(); 2137 session_->remote_description();
2151 ASSERT_TRUE(remote_desc != NULL); 2138 ASSERT_TRUE(remote_desc != NULL);
2152 ASSERT_EQ(2u, remote_desc->number_of_mediasections()); 2139 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2153 const IceCandidateCollection* candidates = 2140 const IceCandidateCollection* candidates =
2154 remote_desc->candidates(kMediaContentIndex0); 2141 remote_desc->candidates(kMediaContentIndex0);
2155 ASSERT_EQ(2u, candidates->count()); 2142 ASSERT_EQ(2u, candidates->count());
2156 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); 2143 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2157 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid()); 2144 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2158 EXPECT_EQ(1, candidates->at(0)->candidate().component()); 2145 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2159 EXPECT_EQ(2, candidates->at(1)->candidate().component()); 2146 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2160 2147
2161 // |ice_candidate3| is identical to |ice_candidate2|. It can be added 2148 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2162 // successfully, but the total count of candidates will not increase. 2149 // successfully, but the total count of candidates will not increase.
2163 candidate.set_component(2); 2150 candidate.set_component(2);
2164 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate); 2151 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2165 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3)); 2152 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
2166 ASSERT_EQ(2u, candidates->count()); 2153 ASSERT_EQ(2u, candidates->count());
2167 2154
2168 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate); 2155 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2169 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate)); 2156 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
2170
2171 // Remove candidate1 and candidate2
2172 std::vector<cricket::Candidate> remote_candidates;
2173 remote_candidates.push_back(ice_candidate1.candidate());
2174 remote_candidates.push_back(ice_candidate2.candidate());
2175 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2176 EXPECT_EQ(0u, candidates->count());
2177 } 2157 }
2178 2158
2179 // Tests that a remote candidate is added to the remote session description and 2159 // Test that a remote candidate is added to the remote session description and
2180 // that it is retained if the remote session description is changed. 2160 // that it is retained if the remote session description is changed.
2181 TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) { 2161 TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
2182 Init(); 2162 Init();
2183 cricket::Candidate candidate1; 2163 cricket::Candidate candidate1;
2184 candidate1.set_component(1); 2164 candidate1.set_component(1);
2185 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0, 2165 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2186 candidate1); 2166 candidate1);
2187 SendAudioVideoStream1(); 2167 SendAudioVideoStream1();
2188 CreateAndSetRemoteOfferAndLocalAnswer(); 2168 CreateAndSetRemoteOfferAndLocalAnswer();
2189 2169
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2222 // No need to verify the username and password. 2202 // No need to verify the username and password.
2223 candidate1.set_username(candidates->at(1)->candidate().username()); 2203 candidate1.set_username(candidates->at(1)->candidate().username());
2224 candidate1.set_password(candidates->at(1)->candidate().password()); 2204 candidate1.set_password(candidates->at(1)->candidate().password());
2225 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate())); 2205 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2226 2206
2227 // Test that the candidate is ignored if we can add the same candidate again. 2207 // Test that the candidate is ignored if we can add the same candidate again.
2228 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); 2208 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2229 } 2209 }
2230 2210
2231 // Test that local candidates are added to the local session description and 2211 // Test that local candidates are added to the local session description and
2232 // that they are retained if the local session description is changed. And if 2212 // that they are retained if the local session description is changed.
2233 // continual gathering is enabled, they are removed from the local session 2213 TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
2234 // description when the network is down.
2235 TEST_F(WebRtcSessionTest,
2236 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
2237 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); 2214 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2238 Init(); 2215 Init();
2239 SendAudioVideoStream1(); 2216 SendAudioVideoStream1();
2240 CreateAndSetRemoteOfferAndLocalAnswer(); 2217 CreateAndSetRemoteOfferAndLocalAnswer();
2241 2218
2242 const SessionDescriptionInterface* local_desc = session_->local_description(); 2219 const SessionDescriptionInterface* local_desc = session_->local_description();
2243 const IceCandidateCollection* candidates = 2220 const IceCandidateCollection* candidates =
2244 local_desc->candidates(kMediaContentIndex0); 2221 local_desc->candidates(kMediaContentIndex0);
2245 ASSERT_TRUE(candidates != NULL); 2222 ASSERT_TRUE(candidates != NULL);
2246 EXPECT_EQ(0u, candidates->count()); 2223 EXPECT_EQ(0u, candidates->count());
(...skipping 12 matching lines...) Expand all
2259 SendAudioVideoStream1(); 2236 SendAudioVideoStream1();
2260 CreateAndSetRemoteOfferAndLocalAnswer(); 2237 CreateAndSetRemoteOfferAndLocalAnswer();
2261 2238
2262 local_desc = session_->local_description(); 2239 local_desc = session_->local_description();
2263 candidates = local_desc->candidates(kMediaContentIndex0); 2240 candidates = local_desc->candidates(kMediaContentIndex0);
2264 ASSERT_TRUE(candidates != NULL); 2241 ASSERT_TRUE(candidates != NULL);
2265 EXPECT_LT(0u, candidates->count()); 2242 EXPECT_LT(0u, candidates->count());
2266 candidates = local_desc->candidates(1); 2243 candidates = local_desc->candidates(1);
2267 ASSERT_TRUE(candidates != NULL); 2244 ASSERT_TRUE(candidates != NULL);
2268 EXPECT_EQ(0u, candidates->count()); 2245 EXPECT_EQ(0u, candidates->count());
2269
2270 candidates = local_desc->candidates(kMediaContentIndex0);
2271 size_t num_local_candidates = candidates->count();
2272 // Enable Continual Gathering
2273 session_->SetIceConfig(cricket::IceConfig(-1, -1, true, false, -1));
2274 // Bring down the network interface to trigger candidate removals.
2275 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2276 // Verify that all local candidates are removed.
2277 EXPECT_EQ(0, observer_.num_candidates_removed_);
2278 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2279 kIceCandidatesTimeout);
2280 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2281 }
2282
2283 // Tests that if continual gathering is disabled, local candidates won't be
2284 // removed when the interface is turned down.
2285 TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2286 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2287 Init();
2288 SendAudioVideoStream1();
2289 CreateAndSetRemoteOfferAndLocalAnswer();
2290
2291 const SessionDescriptionInterface* local_desc = session_->local_description();
2292 const IceCandidateCollection* candidates =
2293 local_desc->candidates(kMediaContentIndex0);
2294 ASSERT_TRUE(candidates != NULL);
2295 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2296
2297 size_t num_local_candidates = candidates->count();
2298 EXPECT_LT(0u, num_local_candidates);
2299 // By default, Continual Gathering is disabled.
2300 // Bring down the network interface.
2301 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2302 // Verify that the local candidates are not removed.
2303 rtc::Thread::Current()->ProcessMessages(1000);
2304 EXPECT_EQ(0, observer_.num_candidates_removed_);
2305 EXPECT_EQ(num_local_candidates, candidates->count());
2306 } 2246 }
2307 2247
2308 // Test that we can set a remote session description with remote candidates. 2248 // Test that we can set a remote session description with remote candidates.
2309 TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) { 2249 TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
2310 Init(); 2250 Init();
2311 2251
2312 cricket::Candidate candidate1; 2252 cricket::Candidate candidate1;
2313 candidate1.set_component(1); 2253 candidate1.set_component(1);
2314 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0, 2254 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2315 candidate1); 2255 candidate1);
(...skipping 2031 matching lines...) Expand 10 before | Expand all | Expand 10 after
4347 } 4287 }
4348 4288
4349 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test 4289 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4350 // currently fails because upon disconnection and reconnection OnIceComplete is 4290 // currently fails because upon disconnection and reconnection OnIceComplete is
4351 // called more than once without returning to IceGatheringGathering. 4291 // called more than once without returning to IceGatheringGathering.
4352 4292
4353 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, 4293 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4354 WebRtcSessionTest, 4294 WebRtcSessionTest,
4355 testing::Values(ALREADY_GENERATED, 4295 testing::Values(ALREADY_GENERATED,
4356 DTLS_IDENTITY_STORE)); 4296 DTLS_IDENTITY_STORE));
OLDNEW
« 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