| OLD | NEW |
| 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 Loading... |
| 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 |
| 192 bool oncandidatesready_; | 198 bool oncandidatesready_; |
| 193 std::vector<cricket::Candidate> mline_0_candidates_; | 199 std::vector<cricket::Candidate> mline_0_candidates_; |
| 194 std::vector<cricket::Candidate> mline_1_candidates_; | 200 std::vector<cricket::Candidate> mline_1_candidates_; |
| 195 PeerConnectionInterface::IceConnectionState ice_connection_state_; | 201 PeerConnectionInterface::IceConnectionState ice_connection_state_; |
| 196 PeerConnectionInterface::IceGatheringState ice_gathering_state_; | 202 PeerConnectionInterface::IceGatheringState ice_gathering_state_; |
| 203 size_t num_candidates_removed_ = 0; |
| 197 }; | 204 }; |
| 198 | 205 |
| 199 class WebRtcSessionForTest : public webrtc::WebRtcSession { | 206 class WebRtcSessionForTest : public webrtc::WebRtcSession { |
| 200 public: | 207 public: |
| 201 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller, | 208 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller, |
| 202 rtc::Thread* signaling_thread, | 209 rtc::Thread* signaling_thread, |
| 203 rtc::Thread* worker_thread, | 210 rtc::Thread* worker_thread, |
| 204 cricket::PortAllocator* port_allocator, | 211 cricket::PortAllocator* port_allocator, |
| 205 webrtc::IceObserver* ice_observer) | 212 webrtc::IceObserver* ice_observer) |
| 206 : WebRtcSession(media_controller, | 213 : WebRtcSession(media_controller, |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | | 358 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP | |
| 352 cricket::PORTALLOCATOR_DISABLE_RELAY); | 359 cricket::PORTALLOCATOR_DISABLE_RELAY); |
| 353 EXPECT_TRUE(channel_manager_->Init()); | 360 EXPECT_TRUE(channel_manager_->Init()); |
| 354 desc_factory_->set_add_legacy_streams(false); | 361 desc_factory_->set_add_legacy_streams(false); |
| 355 allocator_->set_step_delay(cricket::kMinimumStepDelay); | 362 allocator_->set_step_delay(cricket::kMinimumStepDelay); |
| 356 } | 363 } |
| 357 | 364 |
| 358 void AddInterface(const SocketAddress& addr) { | 365 void AddInterface(const SocketAddress& addr) { |
| 359 network_manager_.AddInterface(addr); | 366 network_manager_.AddInterface(addr); |
| 360 } | 367 } |
| 368 void RemoveInterface(const SocketAddress& addr) { |
| 369 network_manager_.RemoveInterface(addr); |
| 370 } |
| 361 | 371 |
| 362 // If |dtls_identity_store| != null or |rtc_configuration| contains | 372 // If |dtls_identity_store| != null or |rtc_configuration| contains |
| 363 // |certificates| then DTLS will be enabled unless explicitly disabled by | 373 // |certificates| then DTLS will be enabled unless explicitly disabled by |
| 364 // |rtc_configuration| options. When DTLS is enabled a certificate will be | 374 // |rtc_configuration| options. When DTLS is enabled a certificate will be |
| 365 // used if provided, otherwise one will be generated using the | 375 // used if provided, otherwise one will be generated using the |
| 366 // |dtls_identity_store|. | 376 // |dtls_identity_store|. |
| 367 void Init( | 377 void Init( |
| 368 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { | 378 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store) { |
| 369 ASSERT_TRUE(session_.get() == NULL); | 379 ASSERT_TRUE(session_.get() == NULL); |
| 370 session_.reset(new WebRtcSessionForTest( | 380 session_.reset(new WebRtcSessionForTest( |
| (...skipping 1728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2099 Init(); | 2109 Init(); |
| 2100 SendNothing(); | 2110 SendNothing(); |
| 2101 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); | 2111 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer()); |
| 2102 | 2112 |
| 2103 SessionDescriptionInterface* answer = | 2113 SessionDescriptionInterface* answer = |
| 2104 CreateRemoteAnswer(offer.get()); | 2114 CreateRemoteAnswer(offer.get()); |
| 2105 SetRemoteDescriptionAnswerExpectError( | 2115 SetRemoteDescriptionAnswerExpectError( |
| 2106 "Called in wrong state: STATE_INIT", answer); | 2116 "Called in wrong state: STATE_INIT", answer); |
| 2107 } | 2117 } |
| 2108 | 2118 |
| 2109 TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) { | 2119 // Tests that the remote candidates are added and removed successfully. |
| 2120 TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) { |
| 2110 Init(); | 2121 Init(); |
| 2111 SendAudioVideoStream1(); | 2122 SendAudioVideoStream1(); |
| 2112 | 2123 |
| 2113 cricket::Candidate candidate; | 2124 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0, |
| 2114 candidate.set_component(1); | 2125 "", "", "host", 0, ""); |
| 2126 candidate.set_transport_name("audio"); |
| 2115 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate); | 2127 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate); |
| 2116 | 2128 |
| 2117 // Fail since we have not set a remote description. | 2129 // Fail since we have not set a remote description. |
| 2118 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1)); | 2130 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1)); |
| 2119 | 2131 |
| 2120 SessionDescriptionInterface* offer = CreateOffer(); | 2132 SessionDescriptionInterface* offer = CreateOffer(); |
| 2121 SetLocalDescriptionWithoutError(offer); | 2133 SetLocalDescriptionWithoutError(offer); |
| 2122 | 2134 |
| 2123 // Fail since we have not set a remote description. | 2135 // Fail since we have not set a remote description. |
| 2124 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1)); | 2136 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1)); |
| 2125 | 2137 |
| 2126 SessionDescriptionInterface* answer = CreateRemoteAnswer( | 2138 SessionDescriptionInterface* answer = CreateRemoteAnswer( |
| 2127 session_->local_description()); | 2139 session_->local_description()); |
| 2128 SetRemoteDescriptionWithoutError(answer); | 2140 SetRemoteDescriptionWithoutError(answer); |
| 2129 | 2141 |
| 2130 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1)); | 2142 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1)); |
| 2131 candidate.set_component(2); | 2143 candidate.set_component(2); |
| 2144 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000)); |
| 2132 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate); | 2145 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate); |
| 2133 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); | 2146 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); |
| 2134 | 2147 |
| 2135 // Verifying the candidates are copied properly from internal vector. | 2148 // Verifying the candidates are copied properly from internal vector. |
| 2136 const SessionDescriptionInterface* remote_desc = | 2149 const SessionDescriptionInterface* remote_desc = |
| 2137 session_->remote_description(); | 2150 session_->remote_description(); |
| 2138 ASSERT_TRUE(remote_desc != NULL); | 2151 ASSERT_TRUE(remote_desc != NULL); |
| 2139 ASSERT_EQ(2u, remote_desc->number_of_mediasections()); | 2152 ASSERT_EQ(2u, remote_desc->number_of_mediasections()); |
| 2140 const IceCandidateCollection* candidates = | 2153 const IceCandidateCollection* candidates = |
| 2141 remote_desc->candidates(kMediaContentIndex0); | 2154 remote_desc->candidates(kMediaContentIndex0); |
| 2142 ASSERT_EQ(2u, candidates->count()); | 2155 ASSERT_EQ(2u, candidates->count()); |
| 2143 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); | 2156 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index()); |
| 2144 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid()); | 2157 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid()); |
| 2145 EXPECT_EQ(1, candidates->at(0)->candidate().component()); | 2158 EXPECT_EQ(1, candidates->at(0)->candidate().component()); |
| 2146 EXPECT_EQ(2, candidates->at(1)->candidate().component()); | 2159 EXPECT_EQ(2, candidates->at(1)->candidate().component()); |
| 2147 | 2160 |
| 2148 // |ice_candidate3| is identical to |ice_candidate2|. It can be added | 2161 // |ice_candidate3| is identical to |ice_candidate2|. It can be added |
| 2149 // successfully, but the total count of candidates will not increase. | 2162 // successfully, but the total count of candidates will not increase. |
| 2150 candidate.set_component(2); | 2163 candidate.set_component(2); |
| 2151 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate); | 2164 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate); |
| 2152 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3)); | 2165 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3)); |
| 2153 ASSERT_EQ(2u, candidates->count()); | 2166 ASSERT_EQ(2u, candidates->count()); |
| 2154 | 2167 |
| 2155 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate); | 2168 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate); |
| 2156 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate)); | 2169 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()); |
| 2157 } | 2177 } |
| 2158 | 2178 |
| 2159 // Test that a remote candidate is added to the remote session description and | 2179 // Tests that a remote candidate is added to the remote session description and |
| 2160 // that it is retained if the remote session description is changed. | 2180 // that it is retained if the remote session description is changed. |
| 2161 TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) { | 2181 TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) { |
| 2162 Init(); | 2182 Init(); |
| 2163 cricket::Candidate candidate1; | 2183 cricket::Candidate candidate1; |
| 2164 candidate1.set_component(1); | 2184 candidate1.set_component(1); |
| 2165 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0, | 2185 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0, |
| 2166 candidate1); | 2186 candidate1); |
| 2167 SendAudioVideoStream1(); | 2187 SendAudioVideoStream1(); |
| 2168 CreateAndSetRemoteOfferAndLocalAnswer(); | 2188 CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2169 | 2189 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2202 // No need to verify the username and password. | 2222 // No need to verify the username and password. |
| 2203 candidate1.set_username(candidates->at(1)->candidate().username()); | 2223 candidate1.set_username(candidates->at(1)->candidate().username()); |
| 2204 candidate1.set_password(candidates->at(1)->candidate().password()); | 2224 candidate1.set_password(candidates->at(1)->candidate().password()); |
| 2205 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate())); | 2225 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate())); |
| 2206 | 2226 |
| 2207 // Test that the candidate is ignored if we can add the same candidate again. | 2227 // Test that the candidate is ignored if we can add the same candidate again. |
| 2208 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); | 2228 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2)); |
| 2209 } | 2229 } |
| 2210 | 2230 |
| 2211 // Test that local candidates are added to the local session description and | 2231 // Test that local candidates are added to the local session description and |
| 2212 // that they are retained if the local session description is changed. | 2232 // that they are retained if the local session description is changed. And if |
| 2213 TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) { | 2233 // continual gathering is enabled, they are removed from the local session |
| 2234 // description when the network is down. |
| 2235 TEST_F(WebRtcSessionTest, |
| 2236 TestLocalCandidatesAddedAndRemovedIfGatherContinually) { |
| 2214 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); | 2237 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort)); |
| 2215 Init(); | 2238 Init(); |
| 2216 SendAudioVideoStream1(); | 2239 SendAudioVideoStream1(); |
| 2217 CreateAndSetRemoteOfferAndLocalAnswer(); | 2240 CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2218 | 2241 |
| 2219 const SessionDescriptionInterface* local_desc = session_->local_description(); | 2242 const SessionDescriptionInterface* local_desc = session_->local_description(); |
| 2220 const IceCandidateCollection* candidates = | 2243 const IceCandidateCollection* candidates = |
| 2221 local_desc->candidates(kMediaContentIndex0); | 2244 local_desc->candidates(kMediaContentIndex0); |
| 2222 ASSERT_TRUE(candidates != NULL); | 2245 ASSERT_TRUE(candidates != NULL); |
| 2223 EXPECT_EQ(0u, candidates->count()); | 2246 EXPECT_EQ(0u, candidates->count()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2236 SendAudioVideoStream1(); | 2259 SendAudioVideoStream1(); |
| 2237 CreateAndSetRemoteOfferAndLocalAnswer(); | 2260 CreateAndSetRemoteOfferAndLocalAnswer(); |
| 2238 | 2261 |
| 2239 local_desc = session_->local_description(); | 2262 local_desc = session_->local_description(); |
| 2240 candidates = local_desc->candidates(kMediaContentIndex0); | 2263 candidates = local_desc->candidates(kMediaContentIndex0); |
| 2241 ASSERT_TRUE(candidates != NULL); | 2264 ASSERT_TRUE(candidates != NULL); |
| 2242 EXPECT_LT(0u, candidates->count()); | 2265 EXPECT_LT(0u, candidates->count()); |
| 2243 candidates = local_desc->candidates(1); | 2266 candidates = local_desc->candidates(1); |
| 2244 ASSERT_TRUE(candidates != NULL); | 2267 ASSERT_TRUE(candidates != NULL); |
| 2245 EXPECT_EQ(0u, candidates->count()); | 2268 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()); |
| 2246 } | 2306 } |
| 2247 | 2307 |
| 2248 // Test that we can set a remote session description with remote candidates. | 2308 // Test that we can set a remote session description with remote candidates. |
| 2249 TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) { | 2309 TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) { |
| 2250 Init(); | 2310 Init(); |
| 2251 | 2311 |
| 2252 cricket::Candidate candidate1; | 2312 cricket::Candidate candidate1; |
| 2253 candidate1.set_component(1); | 2313 candidate1.set_component(1); |
| 2254 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0, | 2314 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0, |
| 2255 candidate1); | 2315 candidate1); |
| (...skipping 2031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4287 } | 4347 } |
| 4288 | 4348 |
| 4289 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test | 4349 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test |
| 4290 // currently fails because upon disconnection and reconnection OnIceComplete is | 4350 // currently fails because upon disconnection and reconnection OnIceComplete is |
| 4291 // called more than once without returning to IceGatheringGathering. | 4351 // called more than once without returning to IceGatheringGathering. |
| 4292 | 4352 |
| 4293 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, | 4353 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, |
| 4294 WebRtcSessionTest, | 4354 WebRtcSessionTest, |
| 4295 testing::Values(ALREADY_GENERATED, | 4355 testing::Values(ALREADY_GENERATED, |
| 4296 DTLS_IDENTITY_STORE)); | 4356 DTLS_IDENTITY_STORE)); |
| OLD | NEW |