blob: a902c76654fef627c311f22e9642cd6f64676477 [file] [log] [blame]
Steve Antonda6c0952017-10-23 11:41:54 -07001/*
2 * Copyright 2017 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
Yves Gerey3e707812018-11-28 16:47:49 +010011#include <memory>
12#include <string>
13#include <type_traits>
14#include <utility>
15#include <vector>
Steve Antonda6c0952017-10-23 11:41:54 -070016
Yves Gerey3e707812018-11-28 16:47:49 +010017#include "absl/types/optional.h"
Steve Anton10542f22019-01-11 09:11:00 -080018#include "api/call/call_factory_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010019#include "api/jsep.h"
Steve Anton10542f22019-01-11 09:11:00 -080020#include "api/media_types.h"
21#include "api/peer_connection_interface.h"
22#include "api/peer_connection_proxy.h"
Mirko Bonadeid9708072019-01-25 20:26:48 +010023#include "api/scoped_refptr.h"
Danil Chapovalov53d45ba2019-07-03 14:56:33 +020024#include "api/task_queue/default_task_queue_factory.h"
Bjorn Mellem175aa2e2018-11-08 11:23:22 -080025#include "api/test/fake_media_transport.h"
Niels Möller65f17ca2019-09-12 13:59:36 +020026#include "api/transport/media/media_transport_interface.h"
Yves Gerey3e707812018-11-28 16:47:49 +010027#include "media/base/codec.h"
Steve Anton10542f22019-01-11 09:11:00 -080028#include "media/base/fake_media_engine.h"
29#include "media/base/media_constants.h"
30#include "media/base/media_engine.h"
31#include "media/sctp/sctp_transport_internal.h"
32#include "p2p/base/p2p_constants.h"
33#include "p2p/base/port_allocator.h"
34#include "pc/media_session.h"
35#include "pc/peer_connection.h"
36#include "pc/peer_connection_factory.h"
37#include "pc/peer_connection_wrapper.h"
38#include "pc/sdp_utils.h"
39#include "pc/session_description.h"
40#include "pc/test/mock_peer_connection_observers.h"
Yves Gerey3e707812018-11-28 16:47:49 +010041#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 09:11:00 -080042#include "rtc_base/ref_counted_object.h"
43#include "rtc_base/rtc_certificate_generator.h"
Yves Gerey3e707812018-11-28 16:47:49 +010044#include "rtc_base/thread.h"
Harald Alvestrand4aa11922019-05-14 22:00:01 +020045#include "test/gmock.h"
Yves Gerey3e707812018-11-28 16:47:49 +010046#include "test/gtest.h"
Steve Antonda6c0952017-10-23 11:41:54 -070047#ifdef WEBRTC_ANDROID
Steve Anton10542f22019-01-11 09:11:00 -080048#include "pc/test/android_test_initializer.h"
Steve Antonda6c0952017-10-23 11:41:54 -070049#endif
Steve Anton10542f22019-01-11 09:11:00 -080050#include "pc/test/fake_sctp_transport.h"
51#include "rtc_base/virtual_socket_server.h"
Steve Antonda6c0952017-10-23 11:41:54 -070052
53namespace webrtc {
54
55using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
56using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions;
Harald Alvestrand4aa11922019-05-14 22:00:01 +020057using ::testing::HasSubstr;
58using ::testing::Not;
Steve Antonda6c0952017-10-23 11:41:54 -070059using ::testing::Values;
60
Bjorn Mellem175aa2e2018-11-08 11:23:22 -080061namespace {
62
63PeerConnectionFactoryDependencies CreatePeerConnectionFactoryDependencies(
64 rtc::Thread* network_thread,
65 rtc::Thread* worker_thread,
66 rtc::Thread* signaling_thread,
67 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
68 std::unique_ptr<CallFactoryInterface> call_factory,
69 std::unique_ptr<MediaTransportFactory> media_transport_factory) {
70 PeerConnectionFactoryDependencies deps;
71 deps.network_thread = network_thread;
72 deps.worker_thread = worker_thread;
73 deps.signaling_thread = signaling_thread;
Danil Chapovalov53d45ba2019-07-03 14:56:33 +020074 deps.task_queue_factory = CreateDefaultTaskQueueFactory();
Bjorn Mellem175aa2e2018-11-08 11:23:22 -080075 deps.media_engine = std::move(media_engine);
76 deps.call_factory = std::move(call_factory);
77 deps.media_transport_factory = std::move(media_transport_factory);
78 return deps;
79}
80
81} // namespace
82
Steve Antonda6c0952017-10-23 11:41:54 -070083class PeerConnectionFactoryForDataChannelTest
84 : public rtc::RefCountedObject<PeerConnectionFactory> {
85 public:
86 PeerConnectionFactoryForDataChannelTest()
87 : rtc::RefCountedObject<PeerConnectionFactory>(
Bjorn Mellem175aa2e2018-11-08 11:23:22 -080088 CreatePeerConnectionFactoryDependencies(
89 rtc::Thread::Current(),
90 rtc::Thread::Current(),
91 rtc::Thread::Current(),
Mirko Bonadei317a1f02019-09-17 17:06:18 +020092 std::make_unique<cricket::FakeMediaEngine>(),
Bjorn Mellem175aa2e2018-11-08 11:23:22 -080093 CreateCallFactory(),
Mirko Bonadei317a1f02019-09-17 17:06:18 +020094 std::make_unique<FakeMediaTransportFactory>())) {}
Steve Antonda6c0952017-10-23 11:41:54 -070095
96 std::unique_ptr<cricket::SctpTransportInternalFactory>
97 CreateSctpTransportInternalFactory() {
Mirko Bonadei317a1f02019-09-17 17:06:18 +020098 auto factory = std::make_unique<FakeSctpTransportFactory>();
Steve Antonda6c0952017-10-23 11:41:54 -070099 last_fake_sctp_transport_factory_ = factory.get();
100 return factory;
101 }
102
103 FakeSctpTransportFactory* last_fake_sctp_transport_factory_ = nullptr;
104};
105
106class PeerConnectionWrapperForDataChannelTest : public PeerConnectionWrapper {
107 public:
108 using PeerConnectionWrapper::PeerConnectionWrapper;
109
110 FakeSctpTransportFactory* sctp_transport_factory() {
111 return sctp_transport_factory_;
112 }
113
114 void set_sctp_transport_factory(
115 FakeSctpTransportFactory* sctp_transport_factory) {
116 sctp_transport_factory_ = sctp_transport_factory;
117 }
118
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200119 absl::optional<std::string> sctp_content_name() {
Steve Antonda6c0952017-10-23 11:41:54 -0700120 return GetInternalPeerConnection()->sctp_content_name();
121 }
122
Danil Chapovalov66cadcc2018-06-19 16:47:43 +0200123 absl::optional<std::string> sctp_transport_name() {
Steve Antonda6c0952017-10-23 11:41:54 -0700124 return GetInternalPeerConnection()->sctp_transport_name();
125 }
126
127 PeerConnection* GetInternalPeerConnection() {
Mirko Bonadeie97de912017-12-13 11:29:34 +0100128 auto* pci =
129 static_cast<PeerConnectionProxyWithInternal<PeerConnectionInterface>*>(
130 pc());
131 return static_cast<PeerConnection*>(pci->internal());
Steve Antonda6c0952017-10-23 11:41:54 -0700132 }
133
134 private:
135 FakeSctpTransportFactory* sctp_transport_factory_ = nullptr;
136};
137
Steve Antondbf9d032018-01-19 15:23:40 -0800138class PeerConnectionDataChannelBaseTest : public ::testing::Test {
Steve Antonda6c0952017-10-23 11:41:54 -0700139 protected:
140 typedef std::unique_ptr<PeerConnectionWrapperForDataChannelTest> WrapperPtr;
141
Steve Antondbf9d032018-01-19 15:23:40 -0800142 explicit PeerConnectionDataChannelBaseTest(SdpSemantics sdp_semantics)
143 : vss_(new rtc::VirtualSocketServer()),
144 main_(vss_.get()),
145 sdp_semantics_(sdp_semantics) {
Steve Antonda6c0952017-10-23 11:41:54 -0700146#ifdef WEBRTC_ANDROID
147 InitializeAndroidObjects();
148#endif
149 }
150
151 WrapperPtr CreatePeerConnection() {
152 return CreatePeerConnection(RTCConfiguration());
153 }
154
155 WrapperPtr CreatePeerConnection(const RTCConfiguration& config) {
156 return CreatePeerConnection(config,
157 PeerConnectionFactoryInterface::Options());
158 }
159
160 WrapperPtr CreatePeerConnection(
161 const RTCConfiguration& config,
162 const PeerConnectionFactoryInterface::Options factory_options) {
163 rtc::scoped_refptr<PeerConnectionFactoryForDataChannelTest> pc_factory(
164 new PeerConnectionFactoryForDataChannelTest());
165 pc_factory->SetOptions(factory_options);
166 RTC_CHECK(pc_factory->Initialize());
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200167 auto observer = std::make_unique<MockPeerConnectionObserver>();
Steve Antondbf9d032018-01-19 15:23:40 -0800168 RTCConfiguration modified_config = config;
169 modified_config.sdp_semantics = sdp_semantics_;
170 auto pc = pc_factory->CreatePeerConnection(modified_config, nullptr,
171 nullptr, observer.get());
Steve Antonda6c0952017-10-23 11:41:54 -0700172 if (!pc) {
173 return nullptr;
174 }
175
Yves Gerey4e933292018-10-31 15:36:05 +0100176 observer->SetPeerConnectionInterface(pc.get());
Mirko Bonadei317a1f02019-09-17 17:06:18 +0200177 auto wrapper = std::make_unique<PeerConnectionWrapperForDataChannelTest>(
Steve Antonda6c0952017-10-23 11:41:54 -0700178 pc_factory, pc, std::move(observer));
179 RTC_DCHECK(pc_factory->last_fake_sctp_transport_factory_);
180 wrapper->set_sctp_transport_factory(
181 pc_factory->last_fake_sctp_transport_factory_);
182 return wrapper;
183 }
184
185 // Accepts the same arguments as CreatePeerConnection and adds a default data
186 // channel.
187 template <typename... Args>
188 WrapperPtr CreatePeerConnectionWithDataChannel(Args&&... args) {
189 auto wrapper = CreatePeerConnection(std::forward<Args>(args)...);
190 if (!wrapper) {
191 return nullptr;
192 }
193 EXPECT_TRUE(wrapper->pc()->CreateDataChannel("dc", nullptr));
194 return wrapper;
195 }
196
197 // Changes the SCTP data channel port on the given session description.
198 void ChangeSctpPortOnDescription(cricket::SessionDescription* desc,
199 int port) {
Steve Antonda6c0952017-10-23 11:41:54 -0700200 auto* data_content = cricket::GetFirstDataContent(desc);
201 RTC_DCHECK(data_content);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200202 auto* data_desc = data_content->media_description()->as_sctp();
203 RTC_DCHECK(data_desc);
204 data_desc->set_port(port);
Steve Antonda6c0952017-10-23 11:41:54 -0700205 }
206
207 std::unique_ptr<rtc::VirtualSocketServer> vss_;
208 rtc::AutoSocketServerThread main_;
Steve Antondbf9d032018-01-19 15:23:40 -0800209 const SdpSemantics sdp_semantics_;
Steve Antonda6c0952017-10-23 11:41:54 -0700210};
211
Steve Antondbf9d032018-01-19 15:23:40 -0800212class PeerConnectionDataChannelTest
213 : public PeerConnectionDataChannelBaseTest,
214 public ::testing::WithParamInterface<SdpSemantics> {
215 protected:
216 PeerConnectionDataChannelTest()
217 : PeerConnectionDataChannelBaseTest(GetParam()) {}
218};
219
220TEST_P(PeerConnectionDataChannelTest,
Steve Antonda6c0952017-10-23 11:41:54 -0700221 NoSctpTransportCreatedIfRtpDataChannelEnabled) {
222 RTCConfiguration config;
223 config.enable_rtp_data_channel = true;
224 auto caller = CreatePeerConnectionWithDataChannel(config);
225
226 ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer()));
227 EXPECT_FALSE(caller->sctp_transport_factory()->last_fake_sctp_transport());
228}
229
Steve Antondbf9d032018-01-19 15:23:40 -0800230TEST_P(PeerConnectionDataChannelTest,
Steve Antonda6c0952017-10-23 11:41:54 -0700231 RtpDataChannelCreatedEvenIfSctpAvailable) {
232 RTCConfiguration config;
233 config.enable_rtp_data_channel = true;
234 PeerConnectionFactoryInterface::Options options;
235 options.disable_sctp_data_channels = false;
236 auto caller = CreatePeerConnectionWithDataChannel(config, options);
237
238 ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer()));
239 EXPECT_FALSE(caller->sctp_transport_factory()->last_fake_sctp_transport());
240}
241
Bjorn A Mellembc3eebc2019-09-23 14:53:54 -0700242TEST_P(PeerConnectionDataChannelTest, InternalSctpTransportDeletedOnTeardown) {
243 auto caller = CreatePeerConnectionWithDataChannel();
244
245 ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer()));
246 EXPECT_TRUE(caller->sctp_transport_factory()->last_fake_sctp_transport());
247
248 rtc::scoped_refptr<SctpTransportInterface> sctp_transport =
249 caller->GetInternalPeerConnection()->GetSctpTransport();
250
251 caller.reset();
252 EXPECT_EQ(static_cast<SctpTransport*>(sctp_transport.get())->internal(),
253 nullptr);
254}
255
Steve Antonda6c0952017-10-23 11:41:54 -0700256// Test that sctp_content_name/sctp_transport_name (used for stats) are correct
257// before and after BUNDLE is negotiated.
Steve Antondbf9d032018-01-19 15:23:40 -0800258TEST_P(PeerConnectionDataChannelTest, SctpContentAndTransportNameSetCorrectly) {
Steve Antonda6c0952017-10-23 11:41:54 -0700259 auto caller = CreatePeerConnection();
260 auto callee = CreatePeerConnection();
261
262 // Initially these fields should be empty.
263 EXPECT_FALSE(caller->sctp_content_name());
264 EXPECT_FALSE(caller->sctp_transport_name());
265
266 // Create offer with audio/video/data.
267 // Default bundle policy is "balanced", so data should be using its own
268 // transport.
269 caller->AddAudioTrack("a");
270 caller->AddVideoTrack("v");
271 caller->pc()->CreateDataChannel("dc", nullptr);
Steve Antondbf9d032018-01-19 15:23:40 -0800272
273 auto offer = caller->CreateOffer();
274 const auto& offer_contents = offer->description()->contents();
275 ASSERT_EQ(cricket::MEDIA_TYPE_AUDIO,
276 offer_contents[0].media_description()->type());
277 std::string audio_mid = offer_contents[0].name;
278 ASSERT_EQ(cricket::MEDIA_TYPE_DATA,
279 offer_contents[2].media_description()->type());
280 std::string data_mid = offer_contents[2].name;
281
282 ASSERT_TRUE(
283 caller->SetLocalDescription(CloneSessionDescription(offer.get())));
284 ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer)));
Steve Antonda6c0952017-10-23 11:41:54 -0700285
286 ASSERT_TRUE(caller->sctp_content_name());
Steve Antondbf9d032018-01-19 15:23:40 -0800287 EXPECT_EQ(data_mid, *caller->sctp_content_name());
Steve Antonda6c0952017-10-23 11:41:54 -0700288 ASSERT_TRUE(caller->sctp_transport_name());
Steve Antondbf9d032018-01-19 15:23:40 -0800289 EXPECT_EQ(data_mid, *caller->sctp_transport_name());
Steve Antonda6c0952017-10-23 11:41:54 -0700290
291 // Create answer that finishes BUNDLE negotiation, which means everything
292 // should be bundled on the first transport (audio).
293 RTCOfferAnswerOptions options;
294 options.use_rtp_mux = true;
295 ASSERT_TRUE(
296 caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal()));
297
298 ASSERT_TRUE(caller->sctp_content_name());
Steve Antondbf9d032018-01-19 15:23:40 -0800299 EXPECT_EQ(data_mid, *caller->sctp_content_name());
Steve Antonda6c0952017-10-23 11:41:54 -0700300 ASSERT_TRUE(caller->sctp_transport_name());
Steve Antondbf9d032018-01-19 15:23:40 -0800301 EXPECT_EQ(audio_mid, *caller->sctp_transport_name());
Steve Antonda6c0952017-10-23 11:41:54 -0700302}
303
Steve Antondbf9d032018-01-19 15:23:40 -0800304TEST_P(PeerConnectionDataChannelTest,
Steve Antonda6c0952017-10-23 11:41:54 -0700305 CreateOfferWithNoDataChannelsGivesNoDataSection) {
306 auto caller = CreatePeerConnection();
307 auto offer = caller->CreateOffer();
308
309 EXPECT_FALSE(offer->description()->GetContentByName(cricket::CN_DATA));
310 EXPECT_FALSE(offer->description()->GetTransportInfoByName(cricket::CN_DATA));
311}
312
Steve Antondbf9d032018-01-19 15:23:40 -0800313TEST_P(PeerConnectionDataChannelTest,
Steve Antonda6c0952017-10-23 11:41:54 -0700314 CreateAnswerWithRemoteSctpDataChannelIncludesDataSection) {
315 auto caller = CreatePeerConnectionWithDataChannel();
316 auto callee = CreatePeerConnection();
317
318 ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
319
320 auto answer = callee->CreateAnswer();
321 ASSERT_TRUE(answer);
Steve Antondbf9d032018-01-19 15:23:40 -0800322 auto* data_content = cricket::GetFirstDataContent(answer->description());
Steve Antonda6c0952017-10-23 11:41:54 -0700323 ASSERT_TRUE(data_content);
324 EXPECT_FALSE(data_content->rejected);
Steve Antondbf9d032018-01-19 15:23:40 -0800325 EXPECT_TRUE(
326 answer->description()->GetTransportInfoByName(data_content->name));
Steve Antonda6c0952017-10-23 11:41:54 -0700327}
328
Steve Antondbf9d032018-01-19 15:23:40 -0800329TEST_P(PeerConnectionDataChannelTest,
Steve Antonda6c0952017-10-23 11:41:54 -0700330 CreateDataChannelWithDtlsDisabledSucceeds) {
331 RTCConfiguration config;
332 config.enable_dtls_srtp.emplace(false);
333 auto caller = CreatePeerConnection();
334
335 EXPECT_TRUE(caller->pc()->CreateDataChannel("dc", nullptr));
336}
337
Steve Antondbf9d032018-01-19 15:23:40 -0800338TEST_P(PeerConnectionDataChannelTest, CreateDataChannelWithSctpDisabledFails) {
Steve Antonda6c0952017-10-23 11:41:54 -0700339 PeerConnectionFactoryInterface::Options options;
340 options.disable_sctp_data_channels = true;
341 auto caller = CreatePeerConnection(RTCConfiguration(), options);
342
343 EXPECT_FALSE(caller->pc()->CreateDataChannel("dc", nullptr));
344}
345
346// Test that if a callee has SCTP disabled and receives an offer with an SCTP
347// data channel, the data section is rejected and no SCTP transport is created
348// on the callee.
Steve Antondbf9d032018-01-19 15:23:40 -0800349TEST_P(PeerConnectionDataChannelTest,
Steve Antonda6c0952017-10-23 11:41:54 -0700350 DataSectionRejectedIfCalleeHasSctpDisabled) {
351 auto caller = CreatePeerConnectionWithDataChannel();
352 PeerConnectionFactoryInterface::Options options;
353 options.disable_sctp_data_channels = true;
354 auto callee = CreatePeerConnection(RTCConfiguration(), options);
355
356 ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal()));
357
358 EXPECT_FALSE(callee->sctp_transport_factory()->last_fake_sctp_transport());
359
360 auto answer = callee->CreateAnswer();
Steve Antondbf9d032018-01-19 15:23:40 -0800361 auto* data_content = cricket::GetFirstDataContent(answer->description());
Steve Antonda6c0952017-10-23 11:41:54 -0700362 ASSERT_TRUE(data_content);
363 EXPECT_TRUE(data_content->rejected);
364}
365
Steve Antondbf9d032018-01-19 15:23:40 -0800366TEST_P(PeerConnectionDataChannelTest, SctpPortPropagatedFromSdpToTransport) {
Steve Antonda6c0952017-10-23 11:41:54 -0700367 constexpr int kNewSendPort = 9998;
368 constexpr int kNewRecvPort = 7775;
369
370 auto caller = CreatePeerConnectionWithDataChannel();
371 auto callee = CreatePeerConnectionWithDataChannel();
372
373 auto offer = caller->CreateOffer();
374 ChangeSctpPortOnDescription(offer->description(), kNewSendPort);
375 ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer)));
376
377 auto answer = callee->CreateAnswer();
378 ChangeSctpPortOnDescription(answer->description(), kNewRecvPort);
379 ASSERT_TRUE(callee->SetLocalDescription(std::move(answer)));
380
381 auto* callee_transport =
382 callee->sctp_transport_factory()->last_fake_sctp_transport();
383 ASSERT_TRUE(callee_transport);
384 EXPECT_EQ(kNewSendPort, callee_transport->remote_port());
385 EXPECT_EQ(kNewRecvPort, callee_transport->local_port());
386}
387
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800388TEST_P(PeerConnectionDataChannelTest,
389 NoSctpTransportCreatedIfMediaTransportDataChannelsEnabled) {
390 RTCConfiguration config;
391 config.use_media_transport_for_data_channels = true;
392 config.enable_dtls_srtp = false; // SDES is required to use media transport.
393 auto caller = CreatePeerConnectionWithDataChannel(config);
394
395 ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer()));
396 EXPECT_FALSE(caller->sctp_transport_factory()->last_fake_sctp_transport());
397}
398
399TEST_P(PeerConnectionDataChannelTest,
400 MediaTransportDataChannelCreatedEvenIfSctpAvailable) {
401 RTCConfiguration config;
402 config.use_media_transport_for_data_channels = true;
403 config.enable_dtls_srtp = false; // SDES is required to use media transport.
404 PeerConnectionFactoryInterface::Options options;
405 options.disable_sctp_data_channels = false;
406 auto caller = CreatePeerConnectionWithDataChannel(config, options);
407
408 ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer()));
409 EXPECT_FALSE(caller->sctp_transport_factory()->last_fake_sctp_transport());
410}
411
412TEST_P(PeerConnectionDataChannelTest,
413 CannotEnableBothMediaTransportAndRtpDataChannels) {
414 RTCConfiguration config;
415 config.enable_rtp_data_channel = true;
416 config.use_media_transport_for_data_channels = true;
417 config.enable_dtls_srtp = false; // SDES is required to use media transport.
418 EXPECT_EQ(CreatePeerConnection(config), nullptr);
419}
420
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800421// This test now DCHECKs, instead of failing to SetLocalDescription.
422TEST_P(PeerConnectionDataChannelTest, MediaTransportWithoutSdesFails) {
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800423 RTCConfiguration config;
424 config.use_media_transport_for_data_channels = true;
425 config.enable_dtls_srtp = true; // Disables SDES for data sections.
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800426
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800427 auto caller = CreatePeerConnectionWithDataChannel(config);
428
Piotr (Peter) Slatalab1ae10b2019-03-01 11:14:05 -0800429 EXPECT_EQ(nullptr, caller);
Bjorn Mellem175aa2e2018-11-08 11:23:22 -0800430}
431
Guido Urdanetacecf87f2019-05-31 10:17:38 +0000432TEST_P(PeerConnectionDataChannelTest, ModernSdpSyntaxByDefault) {
Harald Alvestrand4aa11922019-05-14 22:00:01 +0200433 PeerConnectionInterface::RTCOfferAnswerOptions options;
434 auto caller = CreatePeerConnectionWithDataChannel();
435 auto offer = caller->CreateOffer(options);
436 EXPECT_FALSE(cricket::GetFirstSctpDataContentDescription(offer->description())
437 ->use_sctpmap());
438 std::string sdp;
439 offer->ToString(&sdp);
440 RTC_LOG(LS_ERROR) << sdp;
441 EXPECT_THAT(sdp, HasSubstr(" UDP/DTLS/SCTP webrtc-datachannel"));
442 EXPECT_THAT(sdp, Not(HasSubstr("a=sctpmap:")));
443}
444
445TEST_P(PeerConnectionDataChannelTest, ObsoleteSdpSyntaxIfSet) {
446 PeerConnectionInterface::RTCOfferAnswerOptions options;
447 options.use_obsolete_sctp_sdp = true;
448 auto caller = CreatePeerConnectionWithDataChannel();
449 auto offer = caller->CreateOffer(options);
450 EXPECT_TRUE(cricket::GetFirstSctpDataContentDescription(offer->description())
451 ->use_sctpmap());
452 std::string sdp;
453 offer->ToString(&sdp);
454 EXPECT_THAT(sdp, Not(HasSubstr(" UDP/DTLS/SCTP webrtc-datachannel")));
455 EXPECT_THAT(sdp, HasSubstr("a=sctpmap:"));
456}
457
Mirko Bonadeic84f6612019-01-31 12:20:57 +0100458INSTANTIATE_TEST_SUITE_P(PeerConnectionDataChannelTest,
459 PeerConnectionDataChannelTest,
460 Values(SdpSemantics::kPlanB,
461 SdpSemantics::kUnifiedPlan));
Steve Antondbf9d032018-01-19 15:23:40 -0800462
Steve Antonda6c0952017-10-23 11:41:54 -0700463} // namespace webrtc