• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2012 The WebRTC project authors. All Rights Reserved.
3  *
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
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include "api/jsep_session_description.h"
12 
13 #include <stddef.h>
14 #include <stdint.h>
15 
16 #include <memory>
17 #include <string>
18 #include <utility>
19 #include <vector>
20 
21 #include "api/candidate.h"
22 #include "api/jsep.h"
23 #include "api/jsep_ice_candidate.h"
24 #include "media/base/codec.h"
25 #include "p2p/base/p2p_constants.h"
26 #include "p2p/base/port.h"
27 #include "p2p/base/transport_description.h"
28 #include "p2p/base/transport_info.h"
29 #include "pc/session_description.h"
30 #include "pc/webrtc_sdp.h"
31 #include "rtc_base/helpers.h"
32 #include "rtc_base/socket_address.h"
33 #include "rtc_base/string_encode.h"
34 #include "test/gtest.h"
35 
36 using cricket::MediaProtocolType;
37 using ::testing::Values;
38 using webrtc::IceCandidateCollection;
39 using webrtc::IceCandidateInterface;
40 using webrtc::JsepIceCandidate;
41 using webrtc::JsepSessionDescription;
42 using webrtc::SdpType;
43 using webrtc::SessionDescriptionInterface;
44 
45 static const char kCandidateUfrag[] = "ufrag";
46 static const char kCandidatePwd[] = "pwd";
47 static const char kCandidateUfragVoice[] = "ufrag_voice";
48 static const char kCandidatePwdVoice[] = "pwd_voice";
49 static const char kCandidateUfragVideo[] = "ufrag_video";
50 static const char kCandidatePwdVideo[] = "pwd_video";
51 static const char kCandidateFoundation[] = "a0+B/1";
52 static const uint32_t kCandidatePriority = 2130706432U;  // pref = 1.0
53 static const uint32_t kCandidateGeneration = 2;
54 
55 // This creates a session description with both audio and video media contents.
56 // In SDP this is described by two m lines, one audio and one video.
57 static std::unique_ptr<cricket::SessionDescription>
CreateCricketSessionDescription()58 CreateCricketSessionDescription() {
59   auto desc = std::make_unique<cricket::SessionDescription>();
60 
61   // AudioContentDescription
62   auto audio = std::make_unique<cricket::AudioContentDescription>();
63   // VideoContentDescription
64   auto video = std::make_unique<cricket::VideoContentDescription>();
65 
66   audio->AddCodec(cricket::AudioCodec(103, "ISAC", 16000, 0, 0));
67   desc->AddContent(cricket::CN_AUDIO, MediaProtocolType::kRtp,
68                    std::move(audio));
69 
70   video->AddCodec(cricket::VideoCodec(120, "VP8"));
71   desc->AddContent(cricket::CN_VIDEO, MediaProtocolType::kRtp,
72                    std::move(video));
73 
74   desc->AddTransportInfo(cricket::TransportInfo(
75       cricket::CN_AUDIO,
76       cricket::TransportDescription(
77           std::vector<std::string>(), kCandidateUfragVoice, kCandidatePwdVoice,
78           cricket::ICEMODE_FULL, cricket::CONNECTIONROLE_NONE, NULL)));
79   desc->AddTransportInfo(cricket::TransportInfo(
80       cricket::CN_VIDEO,
81       cricket::TransportDescription(
82           std::vector<std::string>(), kCandidateUfragVideo, kCandidatePwdVideo,
83           cricket::ICEMODE_FULL, cricket::CONNECTIONROLE_NONE, NULL)));
84   return desc;
85 }
86 
87 class JsepSessionDescriptionTest : public ::testing::Test {
88  protected:
SetUp()89   virtual void SetUp() {
90     int port = 1234;
91     rtc::SocketAddress address("127.0.0.1", port++);
92     cricket::Candidate candidate(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
93                                  address, 1, "", "", "local", 0, "1");
94     candidate_ = candidate;
95     const std::string session_id = rtc::ToString(rtc::CreateRandomId64());
96     const std::string session_version = rtc::ToString(rtc::CreateRandomId());
97     jsep_desc_ = std::make_unique<JsepSessionDescription>(SdpType::kOffer);
98     ASSERT_TRUE(jsep_desc_->Initialize(CreateCricketSessionDescription(),
99                                        session_id, session_version));
100   }
101 
Serialize(const SessionDescriptionInterface * desc)102   std::string Serialize(const SessionDescriptionInterface* desc) {
103     std::string sdp;
104     EXPECT_TRUE(desc->ToString(&sdp));
105     EXPECT_FALSE(sdp.empty());
106     return sdp;
107   }
108 
DeSerialize(const std::string & sdp)109   std::unique_ptr<SessionDescriptionInterface> DeSerialize(
110       const std::string& sdp) {
111     auto jsep_desc = std::make_unique<JsepSessionDescription>(SdpType::kOffer);
112     EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jsep_desc.get(), nullptr));
113     return std::move(jsep_desc);
114   }
115 
116   cricket::Candidate candidate_;
117   std::unique_ptr<JsepSessionDescription> jsep_desc_;
118 };
119 
120 // Test that number_of_mediasections() returns the number of media contents in
121 // a session description.
TEST_F(JsepSessionDescriptionTest,CheckSessionDescription)122 TEST_F(JsepSessionDescriptionTest, CheckSessionDescription) {
123   EXPECT_EQ(2u, jsep_desc_->number_of_mediasections());
124 }
125 
126 // Test that we can add a candidate to a session description without MID.
TEST_F(JsepSessionDescriptionTest,AddCandidateWithoutMid)127 TEST_F(JsepSessionDescriptionTest, AddCandidateWithoutMid) {
128   JsepIceCandidate jsep_candidate("", 0, candidate_);
129   EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
130   const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(0);
131   ASSERT_TRUE(ice_candidates != NULL);
132   EXPECT_EQ(1u, ice_candidates->count());
133   const IceCandidateInterface* ice_candidate = ice_candidates->at(0);
134   ASSERT_TRUE(ice_candidate != NULL);
135   candidate_.set_username(kCandidateUfragVoice);
136   candidate_.set_password(kCandidatePwdVoice);
137   EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_));
138   EXPECT_EQ(0, ice_candidate->sdp_mline_index());
139   EXPECT_EQ(0u, jsep_desc_->candidates(1)->count());
140 }
141 
142 // Test that we can add and remove candidates to a session description with
143 // MID. Removing candidates requires MID (transport_name).
TEST_F(JsepSessionDescriptionTest,AddAndRemoveCandidatesWithMid)144 TEST_F(JsepSessionDescriptionTest, AddAndRemoveCandidatesWithMid) {
145   // mid and m-line index don't match, in this case mid is preferred.
146   std::string mid = "video";
147   JsepIceCandidate jsep_candidate(mid, 0, candidate_);
148   EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
149   EXPECT_EQ(0u, jsep_desc_->candidates(0)->count());
150   const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(1);
151   ASSERT_TRUE(ice_candidates != NULL);
152   EXPECT_EQ(1u, ice_candidates->count());
153   const IceCandidateInterface* ice_candidate = ice_candidates->at(0);
154   ASSERT_TRUE(ice_candidate != NULL);
155   candidate_.set_username(kCandidateUfragVideo);
156   candidate_.set_password(kCandidatePwdVideo);
157   EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_));
158   // The mline index should have been updated according to mid.
159   EXPECT_EQ(1, ice_candidate->sdp_mline_index());
160 
161   std::vector<cricket::Candidate> candidates(1, candidate_);
162   candidates[0].set_transport_name(mid);
163   EXPECT_EQ(1u, jsep_desc_->RemoveCandidates(candidates));
164   EXPECT_EQ(0u, jsep_desc_->candidates(0)->count());
165   EXPECT_EQ(0u, jsep_desc_->candidates(1)->count());
166 }
167 
TEST_F(JsepSessionDescriptionTest,AddCandidateAlreadyHasUfrag)168 TEST_F(JsepSessionDescriptionTest, AddCandidateAlreadyHasUfrag) {
169   candidate_.set_username(kCandidateUfrag);
170   candidate_.set_password(kCandidatePwd);
171   JsepIceCandidate jsep_candidate("audio", 0, candidate_);
172   EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
173   const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(0);
174   ASSERT_TRUE(ice_candidates != NULL);
175   EXPECT_EQ(1u, ice_candidates->count());
176   const IceCandidateInterface* ice_candidate = ice_candidates->at(0);
177   ASSERT_TRUE(ice_candidate != NULL);
178   candidate_.set_username(kCandidateUfrag);
179   candidate_.set_password(kCandidatePwd);
180   EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_));
181 
182   EXPECT_EQ(0u, jsep_desc_->candidates(1)->count());
183 }
184 
185 // Test that we can not add a candidate if there is no corresponding media
186 // content in the session description.
TEST_F(JsepSessionDescriptionTest,AddBadCandidate)187 TEST_F(JsepSessionDescriptionTest, AddBadCandidate) {
188   JsepIceCandidate bad_candidate1("", 55, candidate_);
189   EXPECT_FALSE(jsep_desc_->AddCandidate(&bad_candidate1));
190 
191   JsepIceCandidate bad_candidate2("some weird mid", 0, candidate_);
192   EXPECT_FALSE(jsep_desc_->AddCandidate(&bad_candidate2));
193 }
194 
195 // Tests that repeatedly adding the same candidate, with or without credentials,
196 // does not increase the number of candidates in the description.
TEST_F(JsepSessionDescriptionTest,AddCandidateDuplicates)197 TEST_F(JsepSessionDescriptionTest, AddCandidateDuplicates) {
198   JsepIceCandidate jsep_candidate("", 0, candidate_);
199   EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
200   EXPECT_EQ(1u, jsep_desc_->candidates(0)->count());
201 
202   // Add the same candidate again.  It should be ignored.
203   EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
204   EXPECT_EQ(1u, jsep_desc_->candidates(0)->count());
205 
206   // Create a new candidate, identical except that the ufrag and pwd are now
207   // populated.
208   candidate_.set_username(kCandidateUfragVoice);
209   candidate_.set_password(kCandidatePwdVoice);
210   JsepIceCandidate jsep_candidate_with_credentials("", 0, candidate_);
211 
212   // This should also be identified as redundant and ignored.
213   EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate_with_credentials));
214   EXPECT_EQ(1u, jsep_desc_->candidates(0)->count());
215 }
216 
217 // Test that the connection address is set to a hostname address after adding a
218 // hostname candidate.
TEST_F(JsepSessionDescriptionTest,AddHostnameCandidate)219 TEST_F(JsepSessionDescriptionTest, AddHostnameCandidate) {
220   cricket::Candidate c;
221   c.set_component(cricket::ICE_CANDIDATE_COMPONENT_RTP);
222   c.set_protocol(cricket::UDP_PROTOCOL_NAME);
223   c.set_address(rtc::SocketAddress("example.local", 1234));
224   c.set_type(cricket::LOCAL_PORT_TYPE);
225   const size_t audio_index = 0;
226   JsepIceCandidate hostname_candidate("audio", audio_index, c);
227   EXPECT_TRUE(jsep_desc_->AddCandidate(&hostname_candidate));
228 
229   ASSERT_NE(nullptr, jsep_desc_->description());
230   ASSERT_EQ(2u, jsep_desc_->description()->contents().size());
231   const auto& content = jsep_desc_->description()->contents()[audio_index];
232   EXPECT_EQ("0.0.0.0:9",
233             content.media_description()->connection_address().ToString());
234 }
235 
236 // Test that we can serialize a JsepSessionDescription and deserialize it again.
TEST_F(JsepSessionDescriptionTest,SerializeDeserialize)237 TEST_F(JsepSessionDescriptionTest, SerializeDeserialize) {
238   std::string sdp = Serialize(jsep_desc_.get());
239 
240   auto parsed_jsep_desc = DeSerialize(sdp);
241   EXPECT_EQ(2u, parsed_jsep_desc->number_of_mediasections());
242 
243   std::string parsed_sdp = Serialize(parsed_jsep_desc.get());
244   EXPECT_EQ(sdp, parsed_sdp);
245 }
246 
247 // Test that we can serialize a JsepSessionDescription when a hostname candidate
248 // is the default destination and deserialize it again. The connection address
249 // in the deserialized description should be the dummy address 0.0.0.0:9.
TEST_F(JsepSessionDescriptionTest,SerializeDeserializeWithHostnameCandidate)250 TEST_F(JsepSessionDescriptionTest, SerializeDeserializeWithHostnameCandidate) {
251   cricket::Candidate c;
252   c.set_component(cricket::ICE_CANDIDATE_COMPONENT_RTP);
253   c.set_protocol(cricket::UDP_PROTOCOL_NAME);
254   c.set_address(rtc::SocketAddress("example.local", 1234));
255   c.set_type(cricket::LOCAL_PORT_TYPE);
256   const size_t audio_index = 0;
257   const size_t video_index = 1;
258   JsepIceCandidate hostname_candidate_audio("audio", audio_index, c);
259   JsepIceCandidate hostname_candidate_video("video", video_index, c);
260   EXPECT_TRUE(jsep_desc_->AddCandidate(&hostname_candidate_audio));
261   EXPECT_TRUE(jsep_desc_->AddCandidate(&hostname_candidate_video));
262 
263   std::string sdp = Serialize(jsep_desc_.get());
264 
265   auto parsed_jsep_desc = DeSerialize(sdp);
266   EXPECT_EQ(2u, parsed_jsep_desc->number_of_mediasections());
267 
268   ASSERT_NE(nullptr, parsed_jsep_desc->description());
269   ASSERT_EQ(2u, parsed_jsep_desc->description()->contents().size());
270   const auto& audio_content =
271       parsed_jsep_desc->description()->contents()[audio_index];
272   const auto& video_content =
273       parsed_jsep_desc->description()->contents()[video_index];
274   EXPECT_EQ("0.0.0.0:9",
275             audio_content.media_description()->connection_address().ToString());
276   EXPECT_EQ("0.0.0.0:9",
277             video_content.media_description()->connection_address().ToString());
278 }
279 
280 // Tests that we can serialize and deserialize a JsepSesssionDescription
281 // with candidates.
TEST_F(JsepSessionDescriptionTest,SerializeDeserializeWithCandidates)282 TEST_F(JsepSessionDescriptionTest, SerializeDeserializeWithCandidates) {
283   std::string sdp = Serialize(jsep_desc_.get());
284 
285   // Add a candidate and check that the serialized result is different.
286   JsepIceCandidate jsep_candidate("audio", 0, candidate_);
287   EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
288   std::string sdp_with_candidate = Serialize(jsep_desc_.get());
289   EXPECT_NE(sdp, sdp_with_candidate);
290 
291   auto parsed_jsep_desc = DeSerialize(sdp_with_candidate);
292   std::string parsed_sdp_with_candidate = Serialize(parsed_jsep_desc.get());
293 
294   EXPECT_EQ(sdp_with_candidate, parsed_sdp_with_candidate);
295 }
296 
297 // TODO(zhihuang): Modify these tests. These are used to verify that after
298 // adding the candidates, the connection_address field is set correctly. Modify
299 // those so that the "connection address" is tested directly.
300 // Tests serialization of SDP with only IPv6 candidates and verifies that IPv6
301 // is used as default address in c line according to preference.
TEST_F(JsepSessionDescriptionTest,SerializeSessionDescriptionWithIPv6Only)302 TEST_F(JsepSessionDescriptionTest, SerializeSessionDescriptionWithIPv6Only) {
303   // Stun has a high preference than local host.
304   cricket::Candidate candidate1(
305       cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
306       rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
307       cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
308   cricket::Candidate candidate2(
309       cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
310       rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
311       cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
312 
313   JsepIceCandidate jice1("audio", 0, candidate1);
314   JsepIceCandidate jice2("audio", 0, candidate2);
315   JsepIceCandidate jice3("video", 0, candidate1);
316   JsepIceCandidate jice4("video", 0, candidate2);
317   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1));
318   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2));
319   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3));
320   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice4));
321   std::string message = Serialize(jsep_desc_.get());
322 
323   // Should have a c line like this one.
324   EXPECT_NE(message.find("c=IN IP6 ::1"), 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 both IPv4 and IPv6 candidates and
330 // verifies that IPv4 is used as default address in c line even if the
331 // preference of IPv4 is lower.
TEST_F(JsepSessionDescriptionTest,SerializeSessionDescriptionWithBothIPFamilies)332 TEST_F(JsepSessionDescriptionTest,
333        SerializeSessionDescriptionWithBothIPFamilies) {
334   cricket::Candidate candidate_v4(
335       cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
336       rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
337       cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
338   cricket::Candidate candidate_v6(
339       cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
340       rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
341       cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
342 
343   JsepIceCandidate jice_v4("audio", 0, candidate_v4);
344   JsepIceCandidate jice_v6("audio", 0, candidate_v6);
345   JsepIceCandidate jice_v4_video("video", 0, candidate_v4);
346   JsepIceCandidate jice_v6_video("video", 0, candidate_v6);
347   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v4));
348   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v6));
349   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v4_video));
350   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v6_video));
351   std::string message = Serialize(jsep_desc_.get());
352 
353   // Should have a c line like this one.
354   EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos);
355   // Shouldn't have a IP6 c line.
356   EXPECT_EQ(message.find("c=IN IP6"), std::string::npos);
357 }
358 
359 // Tests serialization of SDP with both UDP and TCP candidates and
360 // verifies that UDP is used as default address in c line even if the
361 // preference of UDP is lower.
TEST_F(JsepSessionDescriptionTest,SerializeSessionDescriptionWithBothProtocols)362 TEST_F(JsepSessionDescriptionTest,
363        SerializeSessionDescriptionWithBothProtocols) {
364   // Stun has a high preference than local host.
365   cricket::Candidate candidate1(
366       cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
367       rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
368       cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
369   cricket::Candidate candidate2(
370       cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
371       rtc::SocketAddress("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority,
372       "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration,
373       kCandidateFoundation);
374 
375   JsepIceCandidate jice1("audio", 0, candidate1);
376   JsepIceCandidate jice2("audio", 0, candidate2);
377   JsepIceCandidate jice3("video", 0, candidate1);
378   JsepIceCandidate jice4("video", 0, candidate2);
379   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1));
380   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2));
381   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3));
382   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice4));
383   std::string message = Serialize(jsep_desc_.get());
384 
385   // Should have a c line like this one.
386   EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"),
387             std::string::npos);
388   // Shouldn't have a IP4 c line.
389   EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
390 }
391 
392 // Tests serialization of SDP with only TCP candidates and verifies that
393 // null IPv4 is used as default address in c line.
TEST_F(JsepSessionDescriptionTest,SerializeSessionDescriptionWithTCPOnly)394 TEST_F(JsepSessionDescriptionTest, SerializeSessionDescriptionWithTCPOnly) {
395   // Stun has a high preference than local host.
396   cricket::Candidate candidate1(
397       cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
398       rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
399       cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
400   cricket::Candidate candidate2(
401       cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
402       rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
403       cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
404 
405   JsepIceCandidate jice1("audio", 0, candidate1);
406   JsepIceCandidate jice2("audio", 0, candidate2);
407   JsepIceCandidate jice3("video", 0, candidate1);
408   JsepIceCandidate jice4("video", 0, candidate2);
409   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1));
410   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2));
411   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3));
412   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice4));
413 
414   std::string message = Serialize(jsep_desc_.get());
415   EXPECT_EQ(message.find("c=IN IP6 ::3"), std::string::npos);
416   // Should have a c line like this one when no any default exists.
417   EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos);
418 }
419 
420 // Tests that the connection address will be correctly set when the Candidate is
421 // removed.
TEST_F(JsepSessionDescriptionTest,RemoveCandidateAndSetConnectionAddress)422 TEST_F(JsepSessionDescriptionTest, RemoveCandidateAndSetConnectionAddress) {
423   cricket::Candidate candidate1(
424       cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
425       rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
426       cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
427   candidate1.set_transport_name("audio");
428 
429   cricket::Candidate candidate2(
430       cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
431       rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
432       cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
433   candidate2.set_transport_name("audio");
434 
435   cricket::Candidate candidate3(
436       cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
437       rtc::SocketAddress("192.168.1.1", 1236), kCandidatePriority, "", "",
438       cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
439   candidate3.set_transport_name("audio");
440 
441   JsepIceCandidate jice1("audio", 0, candidate1);
442   JsepIceCandidate jice2("audio", 0, candidate2);
443   JsepIceCandidate jice3("audio", 0, candidate3);
444 
445   size_t audio_index = 0;
446   auto media_desc =
447       jsep_desc_->description()->contents()[audio_index].media_description();
448 
449   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1));
450   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2));
451   ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3));
452 
453   std::vector<cricket::Candidate> candidates;
454   EXPECT_EQ("192.168.1.1:1236", media_desc->connection_address().ToString());
455 
456   candidates.push_back(candidate3);
457   ASSERT_TRUE(jsep_desc_->RemoveCandidates(candidates));
458   EXPECT_EQ("[::1]:1234", media_desc->connection_address().ToString());
459 
460   candidates.clear();
461   candidates.push_back(candidate2);
462   ASSERT_TRUE(jsep_desc_->RemoveCandidates(candidates));
463   EXPECT_EQ("[::1]:1234", media_desc->connection_address().ToString());
464 
465   candidates.clear();
466   candidates.push_back(candidate1);
467   ASSERT_TRUE(jsep_desc_->RemoveCandidates(candidates));
468   EXPECT_EQ("0.0.0.0:9", media_desc->connection_address().ToString());
469 }
470 
471 class EnumerateAllSdpTypesTest : public ::testing::Test,
472                                  public ::testing::WithParamInterface<SdpType> {
473 };
474 
TEST_P(EnumerateAllSdpTypesTest,TestIdentity)475 TEST_P(EnumerateAllSdpTypesTest, TestIdentity) {
476   SdpType type = GetParam();
477 
478   const char* str = webrtc::SdpTypeToString(type);
479   EXPECT_EQ(type, webrtc::SdpTypeFromString(str));
480 }
481 
482 INSTANTIATE_TEST_SUITE_P(JsepSessionDescriptionTest,
483                          EnumerateAllSdpTypesTest,
484                          Values(SdpType::kOffer,
485                                 SdpType::kPrAnswer,
486                                 SdpType::kAnswer));
487