blob: d9e2588a55179f42a650c3c4d9031523e338e228 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
kwibergd1fe2812016-04-27 06:47:29 -070011#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012#include <string>
13
Karl Wiberg918f50c2018-07-05 11:40:33 +020014#include "absl/memory/memory.h"
Patrik Höglunde2d6a062017-10-05 14:53:33 +020015#include "api/candidate.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/jsepicecandidate.h"
17#include "api/jsepsessiondescription.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "p2p/base/p2pconstants.h"
Steve Antona3a92c22017-12-07 10:27:41 -080019#include "p2p/base/port.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "pc/mediasession.h"
Steve Anton4ab68ee2017-12-19 14:26:11 -080021#include "pc/sessiondescription.h"
Mirko Bonadei88bc9d52017-12-18 16:00:13 +010022#include "pc/webrtcsdp.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020023#include "rtc_base/gunit.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "rtc_base/stringencode.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000025
Steve Anton5adfafd2017-12-20 16:34:00 -080026using cricket::MediaProtocolType;
Steve Anton88f2cb92017-12-05 12:47:32 -080027using ::testing::Values;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028using webrtc::IceCandidateCollection;
29using webrtc::IceCandidateInterface;
30using webrtc::JsepIceCandidate;
31using webrtc::JsepSessionDescription;
Steve Anton88f2cb92017-12-05 12:47:32 -080032using webrtc::SdpType;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033using webrtc::SessionDescriptionInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034
35static const char kCandidateUfrag[] = "ufrag";
36static const char kCandidatePwd[] = "pwd";
37static const char kCandidateUfragVoice[] = "ufrag_voice";
38static const char kCandidatePwdVoice[] = "pwd_voice";
39static const char kCandidateUfragVideo[] = "ufrag_video";
40static const char kCandidatePwdVideo[] = "pwd_video";
zhihuang38989e52017-03-21 11:04:53 -070041static const char kCandidateFoundation[] = "a0+B/1";
42static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0
43static const uint32_t kCandidateGeneration = 2;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044
45// This creates a session description with both audio and video media contents.
46// In SDP this is described by two m lines, one audio and one video.
47static cricket::SessionDescription* CreateCricketSessionDescription() {
48 cricket::SessionDescription* desc(new cricket::SessionDescription());
49 // AudioContentDescription
kwibergd1fe2812016-04-27 06:47:29 -070050 std::unique_ptr<cricket::AudioContentDescription> audio(
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051 new cricket::AudioContentDescription());
52
53 // VideoContentDescription
kwibergd1fe2812016-04-27 06:47:29 -070054 std::unique_ptr<cricket::VideoContentDescription> video(
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055 new cricket::VideoContentDescription());
56
deadbeef67cf2c12016-04-13 10:07:16 -070057 audio->AddCodec(cricket::AudioCodec(103, "ISAC", 16000, 0, 0));
Steve Anton5adfafd2017-12-20 16:34:00 -080058 desc->AddContent(cricket::CN_AUDIO, MediaProtocolType::kRtp, audio.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059
perkj26752742016-10-24 01:21:16 -070060 video->AddCodec(cricket::VideoCodec(120, "VP8"));
Steve Anton5adfafd2017-12-20 16:34:00 -080061 desc->AddContent(cricket::CN_VIDEO, MediaProtocolType::kRtp, video.release());
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062
deadbeef46eed762016-01-28 13:24:37 -080063 EXPECT_TRUE(desc->AddTransportInfo(cricket::TransportInfo(
64 cricket::CN_AUDIO,
65 cricket::TransportDescription(
66 std::vector<std::string>(), kCandidateUfragVoice, kCandidatePwdVoice,
67 cricket::ICEMODE_FULL, cricket::CONNECTIONROLE_NONE, NULL))));
68 EXPECT_TRUE(desc->AddTransportInfo(cricket::TransportInfo(
69 cricket::CN_VIDEO,
70 cricket::TransportDescription(
71 std::vector<std::string>(), kCandidateUfragVideo, kCandidatePwdVideo,
72 cricket::ICEMODE_FULL, cricket::CONNECTIONROLE_NONE, NULL))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073 return desc;
74}
75
76class JsepSessionDescriptionTest : public testing::Test {
77 protected:
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078 virtual void SetUp() {
79 int port = 1234;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000080 rtc::SocketAddress address("127.0.0.1", port++);
guoweis@webrtc.org61c12472015-01-15 06:53:07 +000081 cricket::Candidate candidate(cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
82 address, 1, "", "", "local", 0, "1");
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083 candidate_ = candidate;
Yves Gerey665174f2018-06-19 15:03:05 +020084 const std::string session_id = rtc::ToString(rtc::CreateRandomId64());
85 const std::string session_version = rtc::ToString(rtc::CreateRandomId());
Karl Wiberg918f50c2018-07-05 11:40:33 +020086 jsep_desc_ = absl::make_unique<JsepSessionDescription>(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087 ASSERT_TRUE(jsep_desc_->Initialize(CreateCricketSessionDescription(),
Yves Gerey665174f2018-06-19 15:03:05 +020088 session_id, session_version));
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089 }
90
91 std::string Serialize(const SessionDescriptionInterface* desc) {
92 std::string sdp;
93 EXPECT_TRUE(desc->ToString(&sdp));
94 EXPECT_FALSE(sdp.empty());
95 return sdp;
96 }
97
Steve Antona3a92c22017-12-07 10:27:41 -080098 std::unique_ptr<SessionDescriptionInterface> DeSerialize(
99 const std::string& sdp) {
Karl Wiberg918f50c2018-07-05 11:40:33 +0200100 auto jsep_desc = absl::make_unique<JsepSessionDescription>(SdpType::kOffer);
Steve Antona3a92c22017-12-07 10:27:41 -0800101 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jsep_desc.get(), nullptr));
102 return std::move(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103 }
104
105 cricket::Candidate candidate_;
kwibergd1fe2812016-04-27 06:47:29 -0700106 std::unique_ptr<JsepSessionDescription> jsep_desc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107};
108
109// Test that number_of_mediasections() returns the number of media contents in
110// a session description.
111TEST_F(JsepSessionDescriptionTest, CheckSessionDescription) {
112 EXPECT_EQ(2u, jsep_desc_->number_of_mediasections());
113}
114
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700115// Test that we can add a candidate to a session description without MID.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116TEST_F(JsepSessionDescriptionTest, AddCandidateWithoutMid) {
117 JsepIceCandidate jsep_candidate("", 0, candidate_);
118 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
119 const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(0);
120 ASSERT_TRUE(ice_candidates != NULL);
121 EXPECT_EQ(1u, ice_candidates->count());
122 const IceCandidateInterface* ice_candidate = ice_candidates->at(0);
123 ASSERT_TRUE(ice_candidate != NULL);
124 candidate_.set_username(kCandidateUfragVoice);
125 candidate_.set_password(kCandidatePwdVoice);
126 EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_));
127 EXPECT_EQ(0, ice_candidate->sdp_mline_index());
128 EXPECT_EQ(0u, jsep_desc_->candidates(1)->count());
129}
130
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700131// Test that we can add and remove candidates to a session description with
132// MID. Removing candidates requires MID (transport_name).
133TEST_F(JsepSessionDescriptionTest, AddAndRemoveCandidatesWithMid) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000134 // mid and m-line index don't match, in this case mid is preferred.
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700135 std::string mid = "video";
136 JsepIceCandidate jsep_candidate(mid, 0, candidate_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
138 EXPECT_EQ(0u, jsep_desc_->candidates(0)->count());
139 const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(1);
140 ASSERT_TRUE(ice_candidates != NULL);
141 EXPECT_EQ(1u, ice_candidates->count());
142 const IceCandidateInterface* ice_candidate = ice_candidates->at(0);
143 ASSERT_TRUE(ice_candidate != NULL);
144 candidate_.set_username(kCandidateUfragVideo);
145 candidate_.set_password(kCandidatePwdVideo);
146 EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_));
147 // The mline index should have been updated according to mid.
148 EXPECT_EQ(1, ice_candidate->sdp_mline_index());
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700149
150 std::vector<cricket::Candidate> candidates(1, candidate_);
151 candidates[0].set_transport_name(mid);
152 EXPECT_EQ(1u, jsep_desc_->RemoveCandidates(candidates));
153 EXPECT_EQ(0u, jsep_desc_->candidates(0)->count());
154 EXPECT_EQ(0u, jsep_desc_->candidates(1)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155}
156
157TEST_F(JsepSessionDescriptionTest, AddCandidateAlreadyHasUfrag) {
158 candidate_.set_username(kCandidateUfrag);
159 candidate_.set_password(kCandidatePwd);
160 JsepIceCandidate jsep_candidate("audio", 0, candidate_);
161 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
162 const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(0);
163 ASSERT_TRUE(ice_candidates != NULL);
164 EXPECT_EQ(1u, ice_candidates->count());
165 const IceCandidateInterface* ice_candidate = ice_candidates->at(0);
166 ASSERT_TRUE(ice_candidate != NULL);
167 candidate_.set_username(kCandidateUfrag);
168 candidate_.set_password(kCandidatePwd);
169 EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_));
170
171 EXPECT_EQ(0u, jsep_desc_->candidates(1)->count());
172}
173
174// Test that we can not add a candidate if there is no corresponding media
175// content in the session description.
176TEST_F(JsepSessionDescriptionTest, AddBadCandidate) {
177 JsepIceCandidate bad_candidate1("", 55, candidate_);
178 EXPECT_FALSE(jsep_desc_->AddCandidate(&bad_candidate1));
179
180 JsepIceCandidate bad_candidate2("some weird mid", 0, candidate_);
181 EXPECT_FALSE(jsep_desc_->AddCandidate(&bad_candidate2));
182}
183
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +0000184// Tests that repeatedly adding the same candidate, with or without credentials,
185// does not increase the number of candidates in the description.
186TEST_F(JsepSessionDescriptionTest, AddCandidateDuplicates) {
187 JsepIceCandidate jsep_candidate("", 0, candidate_);
188 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
189 EXPECT_EQ(1u, jsep_desc_->candidates(0)->count());
190
191 // Add the same candidate again. It should be ignored.
192 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
193 EXPECT_EQ(1u, jsep_desc_->candidates(0)->count());
194
195 // Create a new candidate, identical except that the ufrag and pwd are now
196 // populated.
197 candidate_.set_username(kCandidateUfragVoice);
198 candidate_.set_password(kCandidatePwdVoice);
199 JsepIceCandidate jsep_candidate_with_credentials("", 0, candidate_);
200
201 // This should also be identified as redundant and ignored.
202 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate_with_credentials));
203 EXPECT_EQ(1u, jsep_desc_->candidates(0)->count());
204}
205
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206// Test that we can serialize a JsepSessionDescription and deserialize it again.
207TEST_F(JsepSessionDescriptionTest, SerializeDeserialize) {
208 std::string sdp = Serialize(jsep_desc_.get());
209
Steve Antona3a92c22017-12-07 10:27:41 -0800210 auto parsed_jsep_desc = DeSerialize(sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 EXPECT_EQ(2u, parsed_jsep_desc->number_of_mediasections());
212
213 std::string parsed_sdp = Serialize(parsed_jsep_desc.get());
214 EXPECT_EQ(sdp, parsed_sdp);
215}
216
217// Tests that we can serialize and deserialize a JsepSesssionDescription
218// with candidates.
219TEST_F(JsepSessionDescriptionTest, SerializeDeserializeWithCandidates) {
220 std::string sdp = Serialize(jsep_desc_.get());
221
222 // Add a candidate and check that the serialized result is different.
223 JsepIceCandidate jsep_candidate("audio", 0, candidate_);
224 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
225 std::string sdp_with_candidate = Serialize(jsep_desc_.get());
226 EXPECT_NE(sdp, sdp_with_candidate);
227
Steve Antona3a92c22017-12-07 10:27:41 -0800228 auto parsed_jsep_desc = DeSerialize(sdp_with_candidate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229 std::string parsed_sdp_with_candidate = Serialize(parsed_jsep_desc.get());
230
231 EXPECT_EQ(sdp_with_candidate, parsed_sdp_with_candidate);
232}
zhihuang38989e52017-03-21 11:04:53 -0700233
234// TODO(zhihuang): Modify these tests. These are used to verify that after
235// adding the candidates, the connection_address field is set correctly. Modify
236// those so that the "connection address" is tested directly.
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.
239TEST_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.
269TEST_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.
299TEST_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.
331TEST_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
342 JsepIceCandidate jice1("audio", 0, candidate1);
343 JsepIceCandidate jice2("audio", 0, candidate2);
344 JsepIceCandidate jice3("video", 0, candidate1);
345 JsepIceCandidate jice4("video", 0, candidate2);
346 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1));
347 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2));
348 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3));
349 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice4));
350
351 std::string message = Serialize(jsep_desc_.get());
352 EXPECT_EQ(message.find("c=IN IP6 ::3"), std::string::npos);
353 // Should have a c line like this one when no any default exists.
354 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos);
355}
356
357// Tests that the connection address will be correctly set when the Candidate is
358// removed.
359TEST_F(JsepSessionDescriptionTest, RemoveCandidateAndSetConnectionAddress) {
360 cricket::Candidate candidate1(
361 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
362 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
363 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
364 candidate1.set_transport_name("audio");
365
366 cricket::Candidate candidate2(
367 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
368 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
369 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
370 candidate2.set_transport_name("audio");
371
372 cricket::Candidate candidate3(
373 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
374 rtc::SocketAddress("192.168.1.1", 1236), kCandidatePriority, "", "",
375 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
376 candidate3.set_transport_name("audio");
377
378 JsepIceCandidate jice1("audio", 0, candidate1);
379 JsepIceCandidate jice2("audio", 0, candidate2);
380 JsepIceCandidate jice3("audio", 0, candidate3);
381
382 size_t audio_index = 0;
Steve Antonb1c1de12017-12-21 15:14:30 -0800383 auto media_desc =
384 jsep_desc_->description()->contents()[audio_index].media_description();
zhihuang38989e52017-03-21 11:04:53 -0700385
386 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1));
387 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2));
388 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3));
389
390 std::vector<cricket::Candidate> candidates;
391 EXPECT_EQ("192.168.1.1:1236", media_desc->connection_address().ToString());
392
393 candidates.push_back(candidate3);
394 ASSERT_TRUE(jsep_desc_->RemoveCandidates(candidates));
395 EXPECT_EQ("[::1]:1234", media_desc->connection_address().ToString());
396
397 candidates.clear();
398 candidates.push_back(candidate2);
399 ASSERT_TRUE(jsep_desc_->RemoveCandidates(candidates));
400 EXPECT_EQ("[::1]:1234", media_desc->connection_address().ToString());
401
402 candidates.clear();
403 candidates.push_back(candidate1);
404 ASSERT_TRUE(jsep_desc_->RemoveCandidates(candidates));
405 EXPECT_EQ("0.0.0.0:9", media_desc->connection_address().ToString());
406}
Steve Anton88f2cb92017-12-05 12:47:32 -0800407
408class EnumerateAllSdpTypesTest : public ::testing::Test,
409 public ::testing::WithParamInterface<SdpType> {
410};
411
412TEST_P(EnumerateAllSdpTypesTest, TestIdentity) {
413 SdpType type = GetParam();
414
415 const char* str = webrtc::SdpTypeToString(type);
416 EXPECT_EQ(type, webrtc::SdpTypeFromString(str));
417}
418
419INSTANTIATE_TEST_CASE_P(JsepSessionDescriptionTest,
420 EnumerateAllSdpTypesTest,
421 Values(SdpType::kOffer,
422 SdpType::kPrAnswer,
423 SdpType::kAnswer));