Chromium Code Reviews| Index: webrtc/pc/jsepsessiondescription_unittest.cc |
| diff --git a/webrtc/pc/jsepsessiondescription_unittest.cc b/webrtc/pc/jsepsessiondescription_unittest.cc |
| index f692457f7ebf351cbdf9f3c7ee912f2560a8655f..095a3ce4cf7d6cfb265222b027b61dfefc990c9a 100644 |
| --- a/webrtc/pc/jsepsessiondescription_unittest.cc |
| +++ b/webrtc/pc/jsepsessiondescription_unittest.cc |
| @@ -34,6 +34,9 @@ static const char kCandidateUfragVoice[] = "ufrag_voice"; |
| static const char kCandidatePwdVoice[] = "pwd_voice"; |
| static const char kCandidateUfragVideo[] = "ufrag_video"; |
| static const char kCandidatePwdVideo[] = "pwd_video"; |
| +static const char kCandidateFoundation[] = "a0+B/1"; |
| +static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0 |
| +static const uint32_t kCandidateGeneration = 2; |
| // This creates a session description with both audio and video media contents. |
| // In SDP this is described by two m lines, one audio and one video. |
| @@ -228,3 +231,142 @@ TEST_F(JsepSessionDescriptionTest, SerializeDeserializeWithCandidates) { |
| EXPECT_EQ(sdp_with_candidate, parsed_sdp_with_candidate); |
| } |
| + |
| +// TODO(zhihuang): Modify these tests. These are used to verify that after |
| +// adding the candidates, the connection_address field is set correctly. Modify |
| +// those so that the "connection address" is tested directly. |
| +// Tests serialization of SDP with only IPv6 candidates and verifies that IPv6 |
| +// is used as default address in c line according to preference. |
| +TEST_F(JsepSessionDescriptionTest, SerializeSessionDescriptionWithIPv6Only) { |
| + // Stun has a high preference than local host. |
| + cricket::Candidate candidate1( |
| + cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| + rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", |
| + cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); |
| + cricket::Candidate candidate2( |
| + cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| + rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "", |
| + cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); |
| + |
| + JsepIceCandidate jice1("audio", 0, candidate1); |
| + JsepIceCandidate jice2("audio", 0, candidate2); |
| + JsepIceCandidate jice3("video", 0, candidate1); |
| + JsepIceCandidate jice4("video", 0, candidate2); |
| + ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1)); |
| + ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2)); |
| + ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3)); |
| + ASSERT_TRUE(jsep_desc_->AddCandidate(&jice4)); |
| + std::string message = Serialize(jsep_desc_.get()); |
| + |
| + // Should have a c line like this one. |
| + EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos); |
| + // Shouldn't have a IP4 c line. |
| + EXPECT_EQ(message.find("c=IN IP4"), std::string::npos); |
| +} |
| + |
| +// Tests serialization of SDP with both IPv4 and IPv6 candidates and |
| +// verifies that IPv4 is used as default address in c line even if the |
| +// preference of IPv4 is lower. |
| +TEST_F(JsepSessionDescriptionTest, |
| + SerializeSessionDescriptionWithBothIPFamilies) { |
| + cricket::Candidate candidate_v4( |
| + cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| + rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "", |
| + cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); |
| + cricket::Candidate candidate_v6( |
| + cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| + rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", |
| + cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); |
| + |
| + JsepIceCandidate jice_v4("audio", 0, candidate_v4); |
| + JsepIceCandidate jice_v6("audio", 0, candidate_v6); |
| + JsepIceCandidate jice_v4_video("video", 0, candidate_v4); |
| + JsepIceCandidate jice_v6_video("video", 0, candidate_v6); |
| + ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v4)); |
| + ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v6)); |
| + ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v4_video)); |
| + ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v6_video)); |
| + std::string message = Serialize(jsep_desc_.get()); |
| + |
| + // Should have a c line like this one. |
| + EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos); |
| + // Shouldn't have a IP6 c line. |
| + EXPECT_EQ(message.find("c=IN IP6"), std::string::npos); |
| +} |
| + |
| +// Tests serialization of SDP with both UDP and TCP candidates and |
| +// verifies that UDP is used as default address in c line even if the |
| +// preference of UDP is lower. |
| +TEST_F(JsepSessionDescriptionTest, |
| + SerializeSessionDescriptionWithBothProtocols) { |
| + // Stun has a high preference than local host. |
| + cricket::Candidate candidate1( |
| + cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
| + rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", |
| + cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); |
| + cricket::Candidate candidate2( |
| + cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| + rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority, |
| + "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration, |
| + kCandidateFoundation); |
| + |
| + JsepIceCandidate jice1("audio", 0, candidate1); |
| + JsepIceCandidate jice2("audio", 0, candidate2); |
| + JsepIceCandidate jice3("video", 0, candidate1); |
| + JsepIceCandidate jice4("video", 0, candidate2); |
| + ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1)); |
| + ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2)); |
| + ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3)); |
| + ASSERT_TRUE(jsep_desc_->AddCandidate(&jice4)); |
| + std::string message = Serialize(jsep_desc_.get()); |
| + |
| + // Should have a c line like this one. |
| + EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"), |
| + std::string::npos); |
| + // Shouldn't have a IP4 c line. |
| + EXPECT_EQ(message.find("c=IN IP4"), std::string::npos); |
| +} |
| + |
| +// Tests serialization of SDP with only TCP candidates and verifies that |
| +// null IPv4 is used as default address in c line. |
| +TEST_F(JsepSessionDescriptionTest, SerializeSessionDescriptionWithTCPOnly) { |
| + // Stun has a high preference than local host. |
| + cricket::Candidate candidate1( |
| + cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
| + rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "", |
| + cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); |
| + cricket::Candidate candidate2( |
| + cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp", |
| + rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "", |
| + cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); |
| + // Used to test the candidate removal. |
| + cricket::Candidate candidate3( |
| + cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp", |
| + rtc::SocketAddress("::3", 1236), kCandidatePriority, "", "", |
| + cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation); |
| + candidate3.set_transport_name("audio"); |
| + |
| + JsepIceCandidate jice1("audio", 0, candidate1); |
| + JsepIceCandidate jice2("audio", 0, candidate2); |
| + JsepIceCandidate jice3("video", 0, candidate1); |
| + JsepIceCandidate jice4("video", 0, candidate2); |
| + ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1)); |
| + ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2)); |
| + ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3)); |
| + ASSERT_TRUE(jsep_desc_->AddCandidate(&jice4)); |
| + |
| + // Tests the candidate removal. |
|
Taylor Brandstetter
2017/03/20 18:29:58
nit: The candidate removal case would be better as
Zhi Huang
2017/03/21 03:43:12
Done.
|
| + JsepIceCandidate jice5("audio", 0, candidate3); |
| + ASSERT_TRUE(jsep_desc_->AddCandidate(&jice5)); |
| + std::string message = Serialize(jsep_desc_.get()); |
| + // Should have a c line like this one. |
| + EXPECT_NE(message.find("c=IN IP6 ::3"), std::string::npos); |
| + // Remove the udp candidate. |
| + std::vector<cricket::Candidate> candidates; |
| + candidates.push_back(candidate3); |
| + ASSERT_TRUE(jsep_desc_->RemoveCandidates(candidates)); |
| + message = Serialize(jsep_desc_.get()); |
| + EXPECT_EQ(message.find("c=IN IP6 ::3"), std::string::npos); |
| + // Should have a c line like this one when no any default exists. |
| + EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos); |
| +} |