Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 using webrtc::JsepIceCandidate; | 27 using webrtc::JsepIceCandidate; |
| 28 using webrtc::JsepSessionDescription; | 28 using webrtc::JsepSessionDescription; |
| 29 using webrtc::SessionDescriptionInterface; | 29 using webrtc::SessionDescriptionInterface; |
| 30 | 30 |
| 31 static const char kCandidateUfrag[] = "ufrag"; | 31 static const char kCandidateUfrag[] = "ufrag"; |
| 32 static const char kCandidatePwd[] = "pwd"; | 32 static const char kCandidatePwd[] = "pwd"; |
| 33 static const char kCandidateUfragVoice[] = "ufrag_voice"; | 33 static const char kCandidateUfragVoice[] = "ufrag_voice"; |
| 34 static const char kCandidatePwdVoice[] = "pwd_voice"; | 34 static const char kCandidatePwdVoice[] = "pwd_voice"; |
| 35 static const char kCandidateUfragVideo[] = "ufrag_video"; | 35 static const char kCandidateUfragVideo[] = "ufrag_video"; |
| 36 static const char kCandidatePwdVideo[] = "pwd_video"; | 36 static const char kCandidatePwdVideo[] = "pwd_video"; |
| 37 static const char kCandidateFoundation[] = "a0+B/1"; | |
| 38 static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0 | |
| 39 static const uint32_t kCandidateGeneration = 2; | |
| 37 | 40 |
| 38 // This creates a session description with both audio and video media contents. | 41 // This creates a session description with both audio and video media contents. |
| 39 // In SDP this is described by two m lines, one audio and one video. | 42 // In SDP this is described by two m lines, one audio and one video. |
| 40 static cricket::SessionDescription* CreateCricketSessionDescription() { | 43 static cricket::SessionDescription* CreateCricketSessionDescription() { |
| 41 cricket::SessionDescription* desc(new cricket::SessionDescription()); | 44 cricket::SessionDescription* desc(new cricket::SessionDescription()); |
| 42 // AudioContentDescription | 45 // AudioContentDescription |
| 43 std::unique_ptr<cricket::AudioContentDescription> audio( | 46 std::unique_ptr<cricket::AudioContentDescription> audio( |
| 44 new cricket::AudioContentDescription()); | 47 new cricket::AudioContentDescription()); |
| 45 | 48 |
| 46 // VideoContentDescription | 49 // VideoContentDescription |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate)); | 224 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate)); |
| 222 std::string sdp_with_candidate = Serialize(jsep_desc_.get()); | 225 std::string sdp_with_candidate = Serialize(jsep_desc_.get()); |
| 223 EXPECT_NE(sdp, sdp_with_candidate); | 226 EXPECT_NE(sdp, sdp_with_candidate); |
| 224 | 227 |
| 225 std::unique_ptr<SessionDescriptionInterface> parsed_jsep_desc( | 228 std::unique_ptr<SessionDescriptionInterface> parsed_jsep_desc( |
| 226 DeSerialize(sdp_with_candidate)); | 229 DeSerialize(sdp_with_candidate)); |
| 227 std::string parsed_sdp_with_candidate = Serialize(parsed_jsep_desc.get()); | 230 std::string parsed_sdp_with_candidate = Serialize(parsed_jsep_desc.get()); |
| 228 | 231 |
| 229 EXPECT_EQ(sdp_with_candidate, parsed_sdp_with_candidate); | 232 EXPECT_EQ(sdp_with_candidate, parsed_sdp_with_candidate); |
| 230 } | 233 } |
| 234 | |
| 235 // TODO(zhihuang): Rename these tests. These are used to verify that after | |
|
Taylor Brandstetter
2017/03/18 00:46:07
Not just rename, but also modify to test the "conn
Zhi Huang
2017/03/18 19:27:55
Done.
| |
| 236 // adding the candidates, the connection_address field is set correctly. | |
| 237 // Tests serialization of SDP with only IPv6 candidates and verifies that IPv6 | |
| 238 // is used as default address in c line according to preference. | |
| 239 TEST_F(JsepSessionDescriptionTest, SerializeSessionDescriptionWithIPv6Only) { | |
| 240 // Stun has a high preference than local host. | |
| 241 cricket::Candidate candidate1( | |
| 242 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", | |
| 243 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", | |
| 244 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); | |
| 245 cricket::Candidate candidate2( | |
| 246 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", | |
| 247 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "", | |
| 248 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); | |
| 249 | |
| 250 JsepIceCandidate jice1("audio", 0, candidate1); | |
| 251 JsepIceCandidate jice2("audio", 0, candidate2); | |
| 252 JsepIceCandidate jice3("video", 0, candidate1); | |
| 253 JsepIceCandidate jice4("video", 0, candidate2); | |
| 254 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1)); | |
| 255 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2)); | |
| 256 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3)); | |
| 257 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice4)); | |
| 258 std::string message = Serialize(jsep_desc_.get()); | |
| 259 | |
| 260 // Should have a c line like this one. | |
| 261 EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos); | |
| 262 // Shouldn't have a IP4 c line. | |
| 263 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos); | |
| 264 } | |
| 265 | |
| 266 // Tests serialization of SDP with both IPv4 and IPv6 candidates and | |
| 267 // verifies that IPv4 is used as default address in c line even if the | |
| 268 // preference of IPv4 is lower. | |
| 269 TEST_F(JsepSessionDescriptionTest, | |
| 270 SerializeSessionDescriptionWithBothIPFamilies) { | |
| 271 cricket::Candidate candidate_v4( | |
| 272 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", | |
| 273 rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "", | |
| 274 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); | |
| 275 cricket::Candidate candidate_v6( | |
| 276 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", | |
| 277 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", | |
| 278 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); | |
| 279 | |
| 280 JsepIceCandidate jice_v4("audio", 0, candidate_v4); | |
| 281 JsepIceCandidate jice_v6("audio", 0, candidate_v6); | |
| 282 JsepIceCandidate jice_v4_video("video", 0, candidate_v4); | |
| 283 JsepIceCandidate jice_v6_video("video", 0, candidate_v6); | |
| 284 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v4)); | |
| 285 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v6)); | |
| 286 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v4_video)); | |
| 287 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v6_video)); | |
| 288 std::string message = Serialize(jsep_desc_.get()); | |
| 289 | |
| 290 // Should have a c line like this one. | |
| 291 EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos); | |
| 292 // Shouldn't have a IP6 c line. | |
| 293 EXPECT_EQ(message.find("c=IN IP6"), std::string::npos); | |
| 294 } | |
| 295 | |
| 296 // Tests serialization of SDP with both UDP and TCP candidates and | |
| 297 // verifies that UDP is used as default address in c line even if the | |
| 298 // preference of UDP is lower. | |
| 299 TEST_F(JsepSessionDescriptionTest, | |
| 300 SerializeSessionDescriptionWithBothProtocols) { | |
| 301 // Stun has a high preference than local host. | |
| 302 cricket::Candidate candidate1( | |
| 303 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp", | |
| 304 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", | |
| 305 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); | |
| 306 cricket::Candidate candidate2( | |
| 307 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", | |
| 308 rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority, | |
| 309 "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration, | |
| 310 kCandidateFoundation); | |
| 311 | |
| 312 JsepIceCandidate jice1("audio", 0, candidate1); | |
| 313 JsepIceCandidate jice2("audio", 0, candidate2); | |
| 314 JsepIceCandidate jice3("video", 0, candidate1); | |
| 315 JsepIceCandidate jice4("video", 0, candidate2); | |
| 316 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1)); | |
| 317 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2)); | |
| 318 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3)); | |
| 319 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice4)); | |
| 320 std::string message = Serialize(jsep_desc_.get()); | |
| 321 | |
| 322 // Should have a c line like this one. | |
| 323 EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"), | |
| 324 std::string::npos); | |
| 325 // Shouldn't have a IP4 c line. | |
| 326 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos); | |
| 327 } | |
| 328 | |
| 329 // Tests serialization of SDP with only TCP candidates and verifies that | |
| 330 // null IPv4 is used as default address in c line. | |
| 331 TEST_F(JsepSessionDescriptionTest, SerializeSessionDescriptionWithTCPOnly) { | |
| 332 // Stun has a high preference than local host. | |
| 333 cricket::Candidate candidate1( | |
| 334 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp", | |
| 335 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", | |
| 336 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); | |
| 337 cricket::Candidate candidate2( | |
| 338 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp", | |
| 339 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "", | |
| 340 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); | |
| 341 // Used to test the candidate removal. | |
| 342 cricket::Candidate candidate3( | |
| 343 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", | |
| 344 rtc::SocketAddress("::3", 1236), kCandidatePriority, "", "", | |
| 345 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); | |
| 346 candidate3.set_transport_name("audio"); | |
| 347 | |
| 348 JsepIceCandidate jice1("audio", 0, candidate1); | |
| 349 JsepIceCandidate jice2("audio", 0, candidate2); | |
| 350 JsepIceCandidate jice3("video", 0, candidate1); | |
| 351 JsepIceCandidate jice4("video", 0, candidate2); | |
| 352 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1)); | |
| 353 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2)); | |
| 354 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3)); | |
| 355 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice4)); | |
| 356 | |
| 357 // Tests the candidate removal. | |
| 358 JsepIceCandidate jice5("audio", 0, candidate3); | |
| 359 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice5)); | |
| 360 std::string message = Serialize(jsep_desc_.get()); | |
| 361 // Should have a c line like this one. | |
| 362 EXPECT_NE(message.find("c=IN IP6 ::3"), std::string::npos); | |
| 363 // Remove the udp candidate. | |
| 364 std::vector<cricket::Candidate> candidates; | |
| 365 candidates.push_back(candidate3); | |
| 366 ASSERT_TRUE(jsep_desc_->RemoveCandidates(candidates)); | |
| 367 message = Serialize(jsep_desc_.get()); | |
| 368 EXPECT_EQ(message.find("c=IN IP6 ::3"), std::string::npos); | |
| 369 // Should have a c line like this one when no any default exists. | |
| 370 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos); | |
| 371 } | |
| OLD | NEW |