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 // Tests serialization of SDP with only IPv6 candidates and verifies that | |
236 // IPv6 is used as default address in c line according to preference. | |
237 TEST_F(JsepSessionDescriptionTest, SerializeSessionDescriptionWithIPv6Only) { | |
Taylor Brandstetter
2017/03/17 00:20:42
nit: These tests don't need to even call "Serializ
Zhi Huang
2017/03/17 23:42:06
Done.
| |
238 // Stun has a high preference than local host. | |
239 cricket::Candidate candidate1( | |
240 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", | |
241 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", | |
242 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); | |
243 cricket::Candidate candidate2( | |
244 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", | |
245 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "", | |
246 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); | |
247 | |
248 JsepIceCandidate jice1("audio", 0, candidate1); | |
249 JsepIceCandidate jice2("audio", 0, candidate2); | |
250 JsepIceCandidate jice3("video", 0, candidate1); | |
251 JsepIceCandidate jice4("video", 0, candidate2); | |
252 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1)); | |
253 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2)); | |
254 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3)); | |
255 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice4)); | |
256 std::string message = Serialize(jsep_desc_.get()); | |
257 | |
258 // Should have a c line like this one. | |
259 EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos); | |
260 // Shouldn't have a IP4 c line. | |
261 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos); | |
262 } | |
263 | |
264 // Tests serialization of SDP with both IPv4 and IPv6 candidates and | |
265 // verifies that IPv4 is used as default address in c line even if the | |
266 // preference of IPv4 is lower. | |
267 TEST_F(JsepSessionDescriptionTest, | |
268 SerializeSessionDescriptionWithBothIPFamilies) { | |
269 cricket::Candidate candidate_v4( | |
270 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", | |
271 rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "", | |
272 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); | |
273 cricket::Candidate candidate_v6( | |
274 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", | |
275 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", | |
276 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); | |
277 | |
278 JsepIceCandidate jice_v4("audio", 0, candidate_v4); | |
279 JsepIceCandidate jice_v6("audio", 0, candidate_v6); | |
280 JsepIceCandidate jice_v4_video("video", 0, candidate_v4); | |
281 JsepIceCandidate jice_v6_video("video", 0, candidate_v6); | |
282 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v4)); | |
283 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v6)); | |
284 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v4_video)); | |
285 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v6_video)); | |
286 std::string message = Serialize(jsep_desc_.get()); | |
287 | |
288 // Should have a c line like this one. | |
289 EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos); | |
290 // Shouldn't have a IP6 c line. | |
291 EXPECT_EQ(message.find("c=IN IP6"), std::string::npos); | |
292 } | |
293 | |
294 // Tests serialization of SDP with both UDP and TCP candidates and | |
295 // verifies that UDP is used as default address in c line even if the | |
296 // preference of UDP is lower. | |
297 TEST_F(JsepSessionDescriptionTest, | |
298 SerializeSessionDescriptionWithBothProtocols) { | |
299 // Stun has a high preference than local host. | |
300 cricket::Candidate candidate1( | |
301 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp", | |
302 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", | |
303 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); | |
304 cricket::Candidate candidate2( | |
305 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", | |
306 rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority, | |
307 "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration, | |
308 kCandidateFoundation); | |
309 | |
310 JsepIceCandidate jice1("audio", 0, candidate1); | |
311 JsepIceCandidate jice2("audio", 0, candidate2); | |
312 JsepIceCandidate jice3("video", 0, candidate1); | |
313 JsepIceCandidate jice4("video", 0, candidate2); | |
314 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1)); | |
315 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2)); | |
316 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3)); | |
317 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice4)); | |
318 std::string message = Serialize(jsep_desc_.get()); | |
319 | |
320 // Should have a c line like this one. | |
321 EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"), | |
322 std::string::npos); | |
323 // Shouldn't have a IP4 c line. | |
324 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos); | |
325 } | |
326 | |
327 // Tests serialization of SDP with only TCP candidates and verifies that | |
328 // null IPv4 is used as default address in c line. | |
329 TEST_F(JsepSessionDescriptionTest, SerializeSessionDescriptionWithTCPOnly) { | |
330 // Stun has a high preference than local host. | |
331 cricket::Candidate candidate1( | |
332 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp", | |
333 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", | |
334 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); | |
335 cricket::Candidate candidate2( | |
336 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp", | |
337 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "", | |
338 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); | |
339 // Used to test the candidate removal. | |
340 cricket::Candidate candidate3( | |
341 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", | |
342 rtc::SocketAddress("::3", 1236), kCandidatePriority, "", "", | |
343 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); | |
344 candidate3.set_transport_name("audio"); | |
345 | |
346 JsepIceCandidate jice1("audio", 0, candidate1); | |
347 JsepIceCandidate jice2("audio", 0, candidate2); | |
348 JsepIceCandidate jice3("video", 0, candidate1); | |
349 JsepIceCandidate jice4("video", 0, candidate2); | |
350 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1)); | |
351 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2)); | |
352 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3)); | |
353 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice4)); | |
354 | |
355 // Tests the candidate removal. | |
356 JsepIceCandidate jice5("audio", 0, candidate3); | |
357 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice5)); | |
358 std::string message = Serialize(jsep_desc_.get()); | |
359 // Should have a c line like this one. | |
360 EXPECT_NE(message.find("c=IN IP6 ::3"), std::string::npos); | |
361 // Remove the udp candidate. | |
362 std::vector<cricket::Candidate> candidates; | |
363 candidates.push_back(candidate3); | |
364 ASSERT_TRUE(jsep_desc_->RemoveCandidates(candidates)); | |
365 message = Serialize(jsep_desc_.get()); | |
366 EXPECT_EQ(message.find("c=IN IP6 ::3"), std::string::npos); | |
367 // Should have a c line like this one when no any default exists. | |
368 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos); | |
369 } | |
OLD | NEW |