blob: fbcfcb7161ec2a6bd641ec21577c0afba637ff39 [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
Patrik Höglunde2d6a062017-10-05 14:53:33 +020014#include "api/candidate.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "api/jsepicecandidate.h"
16#include "api/jsepsessiondescription.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "p2p/base/p2pconstants.h"
Steve Antona3a92c22017-12-07 10:27:41 -080018#include "p2p/base/port.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020019#include "pc/mediasession.h"
Steve Anton4ab68ee2017-12-19 14:26:11 -080020#include "pc/sessiondescription.h"
Mirko Bonadei88bc9d52017-12-18 16:00:13 +010021#include "pc/webrtcsdp.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020022#include "rtc_base/gunit.h"
Steve Antona3a92c22017-12-07 10:27:41 -080023#include "rtc_base/ptr_util.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;
84 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000085 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086 const std::string session_version =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000087 rtc::ToString(rtc::CreateRandomId());
Steve Antona3a92c22017-12-07 10:27:41 -080088 jsep_desc_ = rtc::MakeUnique<JsepSessionDescription>(SdpType::kOffer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089 ASSERT_TRUE(jsep_desc_->Initialize(CreateCricketSessionDescription(),
90 session_id, session_version));
91 }
92
93 std::string Serialize(const SessionDescriptionInterface* desc) {
94 std::string sdp;
95 EXPECT_TRUE(desc->ToString(&sdp));
96 EXPECT_FALSE(sdp.empty());
97 return sdp;
98 }
99
Steve Antona3a92c22017-12-07 10:27:41 -0800100 std::unique_ptr<SessionDescriptionInterface> DeSerialize(
101 const std::string& sdp) {
102 auto jsep_desc = rtc::MakeUnique<JsepSessionDescription>(SdpType::kOffer);
103 EXPECT_TRUE(webrtc::SdpDeserialize(sdp, jsep_desc.get(), nullptr));
104 return std::move(jsep_desc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105 }
106
107 cricket::Candidate candidate_;
kwibergd1fe2812016-04-27 06:47:29 -0700108 std::unique_ptr<JsepSessionDescription> jsep_desc_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109};
110
111// Test that number_of_mediasections() returns the number of media contents in
112// a session description.
113TEST_F(JsepSessionDescriptionTest, CheckSessionDescription) {
114 EXPECT_EQ(2u, jsep_desc_->number_of_mediasections());
115}
116
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700117// Test that we can add a candidate to a session description without MID.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118TEST_F(JsepSessionDescriptionTest, AddCandidateWithoutMid) {
119 JsepIceCandidate jsep_candidate("", 0, candidate_);
120 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
121 const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(0);
122 ASSERT_TRUE(ice_candidates != NULL);
123 EXPECT_EQ(1u, ice_candidates->count());
124 const IceCandidateInterface* ice_candidate = ice_candidates->at(0);
125 ASSERT_TRUE(ice_candidate != NULL);
126 candidate_.set_username(kCandidateUfragVoice);
127 candidate_.set_password(kCandidatePwdVoice);
128 EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_));
129 EXPECT_EQ(0, ice_candidate->sdp_mline_index());
130 EXPECT_EQ(0u, jsep_desc_->candidates(1)->count());
131}
132
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700133// Test that we can add and remove candidates to a session description with
134// MID. Removing candidates requires MID (transport_name).
135TEST_F(JsepSessionDescriptionTest, AddAndRemoveCandidatesWithMid) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136 // mid and m-line index don't match, in this case mid is preferred.
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700137 std::string mid = "video";
138 JsepIceCandidate jsep_candidate(mid, 0, candidate_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000139 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
140 EXPECT_EQ(0u, jsep_desc_->candidates(0)->count());
141 const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(1);
142 ASSERT_TRUE(ice_candidates != NULL);
143 EXPECT_EQ(1u, ice_candidates->count());
144 const IceCandidateInterface* ice_candidate = ice_candidates->at(0);
145 ASSERT_TRUE(ice_candidate != NULL);
146 candidate_.set_username(kCandidateUfragVideo);
147 candidate_.set_password(kCandidatePwdVideo);
148 EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_));
149 // The mline index should have been updated according to mid.
150 EXPECT_EQ(1, ice_candidate->sdp_mline_index());
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700151
152 std::vector<cricket::Candidate> candidates(1, candidate_);
153 candidates[0].set_transport_name(mid);
154 EXPECT_EQ(1u, jsep_desc_->RemoveCandidates(candidates));
155 EXPECT_EQ(0u, jsep_desc_->candidates(0)->count());
156 EXPECT_EQ(0u, jsep_desc_->candidates(1)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157}
158
159TEST_F(JsepSessionDescriptionTest, AddCandidateAlreadyHasUfrag) {
160 candidate_.set_username(kCandidateUfrag);
161 candidate_.set_password(kCandidatePwd);
162 JsepIceCandidate jsep_candidate("audio", 0, candidate_);
163 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
164 const IceCandidateCollection* ice_candidates = jsep_desc_->candidates(0);
165 ASSERT_TRUE(ice_candidates != NULL);
166 EXPECT_EQ(1u, ice_candidates->count());
167 const IceCandidateInterface* ice_candidate = ice_candidates->at(0);
168 ASSERT_TRUE(ice_candidate != NULL);
169 candidate_.set_username(kCandidateUfrag);
170 candidate_.set_password(kCandidatePwd);
171 EXPECT_TRUE(ice_candidate->candidate().IsEquivalent(candidate_));
172
173 EXPECT_EQ(0u, jsep_desc_->candidates(1)->count());
174}
175
176// Test that we can not add a candidate if there is no corresponding media
177// content in the session description.
178TEST_F(JsepSessionDescriptionTest, AddBadCandidate) {
179 JsepIceCandidate bad_candidate1("", 55, candidate_);
180 EXPECT_FALSE(jsep_desc_->AddCandidate(&bad_candidate1));
181
182 JsepIceCandidate bad_candidate2("some weird mid", 0, candidate_);
183 EXPECT_FALSE(jsep_desc_->AddCandidate(&bad_candidate2));
184}
185
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +0000186// Tests that repeatedly adding the same candidate, with or without credentials,
187// does not increase the number of candidates in the description.
188TEST_F(JsepSessionDescriptionTest, AddCandidateDuplicates) {
189 JsepIceCandidate jsep_candidate("", 0, candidate_);
190 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
191 EXPECT_EQ(1u, jsep_desc_->candidates(0)->count());
192
193 // Add the same candidate again. It should be ignored.
194 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
195 EXPECT_EQ(1u, jsep_desc_->candidates(0)->count());
196
197 // Create a new candidate, identical except that the ufrag and pwd are now
198 // populated.
199 candidate_.set_username(kCandidateUfragVoice);
200 candidate_.set_password(kCandidatePwdVoice);
201 JsepIceCandidate jsep_candidate_with_credentials("", 0, candidate_);
202
203 // This should also be identified as redundant and ignored.
204 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate_with_credentials));
205 EXPECT_EQ(1u, jsep_desc_->candidates(0)->count());
206}
207
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208// Test that we can serialize a JsepSessionDescription and deserialize it again.
209TEST_F(JsepSessionDescriptionTest, SerializeDeserialize) {
210 std::string sdp = Serialize(jsep_desc_.get());
211
Steve Antona3a92c22017-12-07 10:27:41 -0800212 auto parsed_jsep_desc = DeSerialize(sdp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 EXPECT_EQ(2u, parsed_jsep_desc->number_of_mediasections());
214
215 std::string parsed_sdp = Serialize(parsed_jsep_desc.get());
216 EXPECT_EQ(sdp, parsed_sdp);
217}
218
219// Tests that we can serialize and deserialize a JsepSesssionDescription
220// with candidates.
221TEST_F(JsepSessionDescriptionTest, SerializeDeserializeWithCandidates) {
222 std::string sdp = Serialize(jsep_desc_.get());
223
224 // Add a candidate and check that the serialized result is different.
225 JsepIceCandidate jsep_candidate("audio", 0, candidate_);
226 EXPECT_TRUE(jsep_desc_->AddCandidate(&jsep_candidate));
227 std::string sdp_with_candidate = Serialize(jsep_desc_.get());
228 EXPECT_NE(sdp, sdp_with_candidate);
229
Steve Antona3a92c22017-12-07 10:27:41 -0800230 auto parsed_jsep_desc = DeSerialize(sdp_with_candidate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 std::string parsed_sdp_with_candidate = Serialize(parsed_jsep_desc.get());
232
233 EXPECT_EQ(sdp_with_candidate, parsed_sdp_with_candidate);
234}
zhihuang38989e52017-03-21 11:04:53 -0700235
236// TODO(zhihuang): Modify these tests. These are used to verify that after
237// adding the candidates, the connection_address field is set correctly. Modify
238// those so that the "connection address" is tested directly.
239// Tests serialization of SDP with only IPv6 candidates and verifies that IPv6
240// is used as default address in c line according to preference.
241TEST_F(JsepSessionDescriptionTest, SerializeSessionDescriptionWithIPv6Only) {
242 // Stun has a high preference than local host.
243 cricket::Candidate candidate1(
244 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
245 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
246 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
247 cricket::Candidate candidate2(
248 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
249 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
250 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
251
252 JsepIceCandidate jice1("audio", 0, candidate1);
253 JsepIceCandidate jice2("audio", 0, candidate2);
254 JsepIceCandidate jice3("video", 0, candidate1);
255 JsepIceCandidate jice4("video", 0, candidate2);
256 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1));
257 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2));
258 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3));
259 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice4));
260 std::string message = Serialize(jsep_desc_.get());
261
262 // Should have a c line like this one.
263 EXPECT_NE(message.find("c=IN IP6 ::1"), std::string::npos);
264 // Shouldn't have a IP4 c line.
265 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
266}
267
268// Tests serialization of SDP with both IPv4 and IPv6 candidates and
269// verifies that IPv4 is used as default address in c line even if the
270// preference of IPv4 is lower.
271TEST_F(JsepSessionDescriptionTest,
272 SerializeSessionDescriptionWithBothIPFamilies) {
273 cricket::Candidate candidate_v4(
274 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
275 rtc::SocketAddress("192.168.1.5", 1234), kCandidatePriority, "", "",
276 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
277 cricket::Candidate candidate_v6(
278 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
279 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
280 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
281
282 JsepIceCandidate jice_v4("audio", 0, candidate_v4);
283 JsepIceCandidate jice_v6("audio", 0, candidate_v6);
284 JsepIceCandidate jice_v4_video("video", 0, candidate_v4);
285 JsepIceCandidate jice_v6_video("video", 0, candidate_v6);
286 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v4));
287 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v6));
288 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v4_video));
289 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice_v6_video));
290 std::string message = Serialize(jsep_desc_.get());
291
292 // Should have a c line like this one.
293 EXPECT_NE(message.find("c=IN IP4 192.168.1.5"), std::string::npos);
294 // Shouldn't have a IP6 c line.
295 EXPECT_EQ(message.find("c=IN IP6"), std::string::npos);
296}
297
298// Tests serialization of SDP with both UDP and TCP candidates and
299// verifies that UDP is used as default address in c line even if the
300// preference of UDP is lower.
301TEST_F(JsepSessionDescriptionTest,
302 SerializeSessionDescriptionWithBothProtocols) {
303 // Stun has a high preference than local host.
304 cricket::Candidate candidate1(
305 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
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("fe80::1234:5678:abcd:ef12", 1235), kCandidatePriority,
311 "", "", cricket::LOCAL_PORT_TYPE, kCandidateGeneration,
312 kCandidateFoundation);
313
314 JsepIceCandidate jice1("audio", 0, candidate1);
315 JsepIceCandidate jice2("audio", 0, candidate2);
316 JsepIceCandidate jice3("video", 0, candidate1);
317 JsepIceCandidate jice4("video", 0, candidate2);
318 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1));
319 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2));
320 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3));
321 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice4));
322 std::string message = Serialize(jsep_desc_.get());
323
324 // Should have a c line like this one.
325 EXPECT_NE(message.find("c=IN IP6 fe80::1234:5678:abcd:ef12"),
326 std::string::npos);
327 // Shouldn't have a IP4 c line.
328 EXPECT_EQ(message.find("c=IN IP4"), std::string::npos);
329}
330
331// Tests serialization of SDP with only TCP candidates and verifies that
332// null IPv4 is used as default address in c line.
333TEST_F(JsepSessionDescriptionTest, SerializeSessionDescriptionWithTCPOnly) {
334 // Stun has a high preference than local host.
335 cricket::Candidate candidate1(
336 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
337 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
338 cricket::STUN_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
339 cricket::Candidate candidate2(
340 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
341 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
342 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
343
344 JsepIceCandidate jice1("audio", 0, candidate1);
345 JsepIceCandidate jice2("audio", 0, candidate2);
346 JsepIceCandidate jice3("video", 0, candidate1);
347 JsepIceCandidate jice4("video", 0, candidate2);
348 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1));
349 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2));
350 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3));
351 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice4));
352
353 std::string message = Serialize(jsep_desc_.get());
354 EXPECT_EQ(message.find("c=IN IP6 ::3"), std::string::npos);
355 // Should have a c line like this one when no any default exists.
356 EXPECT_NE(message.find("c=IN IP4 0.0.0.0"), std::string::npos);
357}
358
359// Tests that the connection address will be correctly set when the Candidate is
360// removed.
361TEST_F(JsepSessionDescriptionTest, RemoveCandidateAndSetConnectionAddress) {
362 cricket::Candidate candidate1(
363 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
364 rtc::SocketAddress("::1", 1234), kCandidatePriority, "", "",
365 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
366 candidate1.set_transport_name("audio");
367
368 cricket::Candidate candidate2(
369 cricket::ICE_CANDIDATE_COMPONENT_RTP, "tcp",
370 rtc::SocketAddress("::2", 1235), kCandidatePriority, "", "",
371 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
372 candidate2.set_transport_name("audio");
373
374 cricket::Candidate candidate3(
375 cricket::ICE_CANDIDATE_COMPONENT_RTP, "udp",
376 rtc::SocketAddress("192.168.1.1", 1236), kCandidatePriority, "", "",
377 cricket::LOCAL_PORT_TYPE, kCandidateGeneration, kCandidateFoundation);
378 candidate3.set_transport_name("audio");
379
380 JsepIceCandidate jice1("audio", 0, candidate1);
381 JsepIceCandidate jice2("audio", 0, candidate2);
382 JsepIceCandidate jice3("audio", 0, candidate3);
383
384 size_t audio_index = 0;
Steve Antonb1c1de12017-12-21 15:14:30 -0800385 auto media_desc =
386 jsep_desc_->description()->contents()[audio_index].media_description();
zhihuang38989e52017-03-21 11:04:53 -0700387
388 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice1));
389 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice2));
390 ASSERT_TRUE(jsep_desc_->AddCandidate(&jice3));
391
392 std::vector<cricket::Candidate> candidates;
393 EXPECT_EQ("192.168.1.1:1236", media_desc->connection_address().ToString());
394
395 candidates.push_back(candidate3);
396 ASSERT_TRUE(jsep_desc_->RemoveCandidates(candidates));
397 EXPECT_EQ("[::1]:1234", media_desc->connection_address().ToString());
398
399 candidates.clear();
400 candidates.push_back(candidate2);
401 ASSERT_TRUE(jsep_desc_->RemoveCandidates(candidates));
402 EXPECT_EQ("[::1]:1234", media_desc->connection_address().ToString());
403
404 candidates.clear();
405 candidates.push_back(candidate1);
406 ASSERT_TRUE(jsep_desc_->RemoveCandidates(candidates));
407 EXPECT_EQ("0.0.0.0:9", media_desc->connection_address().ToString());
408}
Steve Anton88f2cb92017-12-05 12:47:32 -0800409
410class EnumerateAllSdpTypesTest : public ::testing::Test,
411 public ::testing::WithParamInterface<SdpType> {
412};
413
414TEST_P(EnumerateAllSdpTypesTest, TestIdentity) {
415 SdpType type = GetParam();
416
417 const char* str = webrtc::SdpTypeToString(type);
418 EXPECT_EQ(type, webrtc::SdpTypeFromString(str));
419}
420
421INSTANTIATE_TEST_CASE_P(JsepSessionDescriptionTest,
422 EnumerateAllSdpTypesTest,
423 Values(SdpType::kOffer,
424 SdpType::kPrAnswer,
425 SdpType::kAnswer));