Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 1 | /* |
| 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 Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 11 | #include <memory> |
| 12 | #include <string> |
| 13 | #include <type_traits> |
| 14 | #include <utility> |
| 15 | #include <vector> |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 16 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 17 | #include "absl/types/optional.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 18 | #include "api/call/call_factory_interface.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 19 | #include "api/jsep.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 20 | #include "api/media_types.h" |
| 21 | #include "api/peer_connection_interface.h" |
Mirko Bonadei | d970807 | 2019-01-25 19:26:48 | [diff] [blame] | 22 | #include "api/scoped_refptr.h" |
Danil Chapovalov | 53d45ba | 2019-07-03 12:56:33 | [diff] [blame] | 23 | #include "api/task_queue/default_task_queue_factory.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 24 | #include "media/base/codec.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 25 | #include "media/base/fake_media_engine.h" |
| 26 | #include "media/base/media_constants.h" |
| 27 | #include "media/base/media_engine.h" |
| 28 | #include "media/sctp/sctp_transport_internal.h" |
| 29 | #include "p2p/base/p2p_constants.h" |
| 30 | #include "p2p/base/port_allocator.h" |
| 31 | #include "pc/media_session.h" |
| 32 | #include "pc/peer_connection.h" |
| 33 | #include "pc/peer_connection_factory.h" |
Markus Handell | a1b8201 | 2021-05-26 16:56:30 | [diff] [blame] | 34 | #include "pc/peer_connection_proxy.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 35 | #include "pc/peer_connection_wrapper.h" |
| 36 | #include "pc/sdp_utils.h" |
| 37 | #include "pc/session_description.h" |
| 38 | #include "pc/test/mock_peer_connection_observers.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 39 | #include "rtc_base/checks.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 40 | #include "rtc_base/ref_counted_object.h" |
| 41 | #include "rtc_base/rtc_certificate_generator.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 42 | #include "rtc_base/thread.h" |
Harald Alvestrand | 4aa1192 | 2019-05-14 20:00:01 | [diff] [blame] | 43 | #include "test/gmock.h" |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 44 | #include "test/gtest.h" |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 45 | #ifdef WEBRTC_ANDROID |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 46 | #include "pc/test/android_test_initializer.h" |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 47 | #endif |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 48 | #include "rtc_base/virtual_socket_server.h" |
Per Kjellander | 2bca008 | 2020-08-28 07:15:15 | [diff] [blame] | 49 | #include "test/pc/sctp/fake_sctp_transport.h" |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 50 | |
| 51 | namespace webrtc { |
| 52 | |
| 53 | using RTCConfiguration = PeerConnectionInterface::RTCConfiguration; |
| 54 | using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions; |
Harald Alvestrand | 4aa1192 | 2019-05-14 20:00:01 | [diff] [blame] | 55 | using ::testing::HasSubstr; |
| 56 | using ::testing::Not; |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 57 | using ::testing::Values; |
| 58 | |
Bjorn Mellem | 175aa2e | 2018-11-08 19:23:22 | [diff] [blame] | 59 | namespace { |
| 60 | |
Per Kjellander | 2bca008 | 2020-08-28 07:15:15 | [diff] [blame] | 61 | PeerConnectionFactoryDependencies CreatePeerConnectionFactoryDependencies() { |
Bjorn Mellem | 175aa2e | 2018-11-08 19:23:22 | [diff] [blame] | 62 | PeerConnectionFactoryDependencies deps; |
Per Kjellander | 2bca008 | 2020-08-28 07:15:15 | [diff] [blame] | 63 | deps.network_thread = rtc::Thread::Current(); |
| 64 | deps.worker_thread = rtc::Thread::Current(); |
| 65 | deps.signaling_thread = rtc::Thread::Current(); |
Danil Chapovalov | 53d45ba | 2019-07-03 12:56:33 | [diff] [blame] | 66 | deps.task_queue_factory = CreateDefaultTaskQueueFactory(); |
Per Kjellander | 2bca008 | 2020-08-28 07:15:15 | [diff] [blame] | 67 | deps.media_engine = std::make_unique<cricket::FakeMediaEngine>(); |
| 68 | deps.call_factory = CreateCallFactory(); |
| 69 | deps.sctp_factory = std::make_unique<FakeSctpTransportFactory>(); |
Bjorn Mellem | 175aa2e | 2018-11-08 19:23:22 | [diff] [blame] | 70 | return deps; |
| 71 | } |
| 72 | |
| 73 | } // namespace |
| 74 | |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 75 | class PeerConnectionWrapperForDataChannelTest : public PeerConnectionWrapper { |
| 76 | public: |
| 77 | using PeerConnectionWrapper::PeerConnectionWrapper; |
| 78 | |
| 79 | FakeSctpTransportFactory* sctp_transport_factory() { |
| 80 | return sctp_transport_factory_; |
| 81 | } |
| 82 | |
| 83 | void set_sctp_transport_factory( |
| 84 | FakeSctpTransportFactory* sctp_transport_factory) { |
| 85 | sctp_transport_factory_ = sctp_transport_factory; |
| 86 | } |
| 87 | |
Harald Alvestrand | 1cb929f | 2020-02-05 11:07:33 | [diff] [blame] | 88 | absl::optional<std::string> sctp_mid() { |
| 89 | return GetInternalPeerConnection()->sctp_mid(); |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 90 | } |
| 91 | |
Danil Chapovalov | 66cadcc | 2018-06-19 14:47:43 | [diff] [blame] | 92 | absl::optional<std::string> sctp_transport_name() { |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 93 | return GetInternalPeerConnection()->sctp_transport_name(); |
| 94 | } |
| 95 | |
| 96 | PeerConnection* GetInternalPeerConnection() { |
Mirko Bonadei | e97de91 | 2017-12-13 10:29:34 | [diff] [blame] | 97 | auto* pci = |
| 98 | static_cast<PeerConnectionProxyWithInternal<PeerConnectionInterface>*>( |
| 99 | pc()); |
| 100 | return static_cast<PeerConnection*>(pci->internal()); |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | private: |
| 104 | FakeSctpTransportFactory* sctp_transport_factory_ = nullptr; |
| 105 | }; |
| 106 | |
Steve Anton | dbf9d03 | 2018-01-19 23:23:40 | [diff] [blame] | 107 | class PeerConnectionDataChannelBaseTest : public ::testing::Test { |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 108 | protected: |
| 109 | typedef std::unique_ptr<PeerConnectionWrapperForDataChannelTest> WrapperPtr; |
| 110 | |
Steve Anton | dbf9d03 | 2018-01-19 23:23:40 | [diff] [blame] | 111 | explicit PeerConnectionDataChannelBaseTest(SdpSemantics sdp_semantics) |
| 112 | : vss_(new rtc::VirtualSocketServer()), |
| 113 | main_(vss_.get()), |
| 114 | sdp_semantics_(sdp_semantics) { |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 115 | #ifdef WEBRTC_ANDROID |
| 116 | InitializeAndroidObjects(); |
| 117 | #endif |
| 118 | } |
| 119 | |
| 120 | WrapperPtr CreatePeerConnection() { |
| 121 | return CreatePeerConnection(RTCConfiguration()); |
| 122 | } |
| 123 | |
| 124 | WrapperPtr CreatePeerConnection(const RTCConfiguration& config) { |
| 125 | return CreatePeerConnection(config, |
| 126 | PeerConnectionFactoryInterface::Options()); |
| 127 | } |
| 128 | |
| 129 | WrapperPtr CreatePeerConnection( |
| 130 | const RTCConfiguration& config, |
| 131 | const PeerConnectionFactoryInterface::Options factory_options) { |
Per Kjellander | 2bca008 | 2020-08-28 07:15:15 | [diff] [blame] | 132 | auto factory_deps = CreatePeerConnectionFactoryDependencies(); |
| 133 | FakeSctpTransportFactory* fake_sctp_transport_factory = |
| 134 | static_cast<FakeSctpTransportFactory*>(factory_deps.sctp_factory.get()); |
| 135 | rtc::scoped_refptr<PeerConnectionFactoryInterface> pc_factory = |
| 136 | CreateModularPeerConnectionFactory(std::move(factory_deps)); |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 137 | pc_factory->SetOptions(factory_options); |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 138 | auto observer = std::make_unique<MockPeerConnectionObserver>(); |
Steve Anton | dbf9d03 | 2018-01-19 23:23:40 | [diff] [blame] | 139 | RTCConfiguration modified_config = config; |
| 140 | modified_config.sdp_semantics = sdp_semantics_; |
| 141 | auto pc = pc_factory->CreatePeerConnection(modified_config, nullptr, |
| 142 | nullptr, observer.get()); |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 143 | if (!pc) { |
| 144 | return nullptr; |
| 145 | } |
| 146 | |
Yves Gerey | 4e93329 | 2018-10-31 14:36:05 | [diff] [blame] | 147 | observer->SetPeerConnectionInterface(pc.get()); |
Mirko Bonadei | 317a1f0 | 2019-09-17 15:06:18 | [diff] [blame] | 148 | auto wrapper = std::make_unique<PeerConnectionWrapperForDataChannelTest>( |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 149 | pc_factory, pc, std::move(observer)); |
Per Kjellander | 2bca008 | 2020-08-28 07:15:15 | [diff] [blame] | 150 | wrapper->set_sctp_transport_factory(fake_sctp_transport_factory); |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 151 | return wrapper; |
| 152 | } |
| 153 | |
| 154 | // Accepts the same arguments as CreatePeerConnection and adds a default data |
| 155 | // channel. |
| 156 | template <typename... Args> |
| 157 | WrapperPtr CreatePeerConnectionWithDataChannel(Args&&... args) { |
| 158 | auto wrapper = CreatePeerConnection(std::forward<Args>(args)...); |
| 159 | if (!wrapper) { |
| 160 | return nullptr; |
| 161 | } |
| 162 | EXPECT_TRUE(wrapper->pc()->CreateDataChannel("dc", nullptr)); |
| 163 | return wrapper; |
| 164 | } |
| 165 | |
| 166 | // Changes the SCTP data channel port on the given session description. |
| 167 | void ChangeSctpPortOnDescription(cricket::SessionDescription* desc, |
| 168 | int port) { |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 169 | auto* data_content = cricket::GetFirstDataContent(desc); |
| 170 | RTC_DCHECK(data_content); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 11:36:16 | [diff] [blame] | 171 | auto* data_desc = data_content->media_description()->as_sctp(); |
| 172 | RTC_DCHECK(data_desc); |
| 173 | data_desc->set_port(port); |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 177 | rtc::AutoSocketServerThread main_; |
Steve Anton | dbf9d03 | 2018-01-19 23:23:40 | [diff] [blame] | 178 | const SdpSemantics sdp_semantics_; |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 179 | }; |
| 180 | |
Steve Anton | dbf9d03 | 2018-01-19 23:23:40 | [diff] [blame] | 181 | class PeerConnectionDataChannelTest |
| 182 | : public PeerConnectionDataChannelBaseTest, |
| 183 | public ::testing::WithParamInterface<SdpSemantics> { |
| 184 | protected: |
| 185 | PeerConnectionDataChannelTest() |
| 186 | : PeerConnectionDataChannelBaseTest(GetParam()) {} |
| 187 | }; |
| 188 | |
Steve Anton | c8ff160 | 2020-02-05 21:53:38 | [diff] [blame] | 189 | class PeerConnectionDataChannelUnifiedPlanTest |
| 190 | : public PeerConnectionDataChannelBaseTest { |
| 191 | protected: |
| 192 | PeerConnectionDataChannelUnifiedPlanTest() |
| 193 | : PeerConnectionDataChannelBaseTest(SdpSemantics::kUnifiedPlan) {} |
| 194 | }; |
| 195 | |
Bjorn A Mellem | bc3eebc | 2019-09-23 21:53:54 | [diff] [blame] | 196 | TEST_P(PeerConnectionDataChannelTest, InternalSctpTransportDeletedOnTeardown) { |
| 197 | auto caller = CreatePeerConnectionWithDataChannel(); |
| 198 | |
| 199 | ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer())); |
| 200 | EXPECT_TRUE(caller->sctp_transport_factory()->last_fake_sctp_transport()); |
| 201 | |
| 202 | rtc::scoped_refptr<SctpTransportInterface> sctp_transport = |
| 203 | caller->GetInternalPeerConnection()->GetSctpTransport(); |
| 204 | |
| 205 | caller.reset(); |
| 206 | EXPECT_EQ(static_cast<SctpTransport*>(sctp_transport.get())->internal(), |
| 207 | nullptr); |
| 208 | } |
| 209 | |
Harald Alvestrand | 1cb929f | 2020-02-05 11:07:33 | [diff] [blame] | 210 | // Test that sctp_mid/sctp_transport_name (used for stats) are correct |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 211 | // before and after BUNDLE is negotiated. |
Steve Anton | dbf9d03 | 2018-01-19 23:23:40 | [diff] [blame] | 212 | TEST_P(PeerConnectionDataChannelTest, SctpContentAndTransportNameSetCorrectly) { |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 213 | auto caller = CreatePeerConnection(); |
| 214 | auto callee = CreatePeerConnection(); |
| 215 | |
| 216 | // Initially these fields should be empty. |
Harald Alvestrand | 1cb929f | 2020-02-05 11:07:33 | [diff] [blame] | 217 | EXPECT_FALSE(caller->sctp_mid()); |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 218 | EXPECT_FALSE(caller->sctp_transport_name()); |
| 219 | |
| 220 | // Create offer with audio/video/data. |
| 221 | // Default bundle policy is "balanced", so data should be using its own |
| 222 | // transport. |
| 223 | caller->AddAudioTrack("a"); |
| 224 | caller->AddVideoTrack("v"); |
| 225 | caller->pc()->CreateDataChannel("dc", nullptr); |
Steve Anton | dbf9d03 | 2018-01-19 23:23:40 | [diff] [blame] | 226 | |
| 227 | auto offer = caller->CreateOffer(); |
| 228 | const auto& offer_contents = offer->description()->contents(); |
| 229 | ASSERT_EQ(cricket::MEDIA_TYPE_AUDIO, |
| 230 | offer_contents[0].media_description()->type()); |
| 231 | std::string audio_mid = offer_contents[0].name; |
| 232 | ASSERT_EQ(cricket::MEDIA_TYPE_DATA, |
| 233 | offer_contents[2].media_description()->type()); |
| 234 | std::string data_mid = offer_contents[2].name; |
| 235 | |
| 236 | ASSERT_TRUE( |
| 237 | caller->SetLocalDescription(CloneSessionDescription(offer.get()))); |
| 238 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 239 | |
Harald Alvestrand | 1cb929f | 2020-02-05 11:07:33 | [diff] [blame] | 240 | ASSERT_TRUE(caller->sctp_mid()); |
| 241 | EXPECT_EQ(data_mid, *caller->sctp_mid()); |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 242 | ASSERT_TRUE(caller->sctp_transport_name()); |
Steve Anton | dbf9d03 | 2018-01-19 23:23:40 | [diff] [blame] | 243 | EXPECT_EQ(data_mid, *caller->sctp_transport_name()); |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 244 | |
| 245 | // Create answer that finishes BUNDLE negotiation, which means everything |
| 246 | // should be bundled on the first transport (audio). |
| 247 | RTCOfferAnswerOptions options; |
| 248 | options.use_rtp_mux = true; |
| 249 | ASSERT_TRUE( |
| 250 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 251 | |
Harald Alvestrand | 1cb929f | 2020-02-05 11:07:33 | [diff] [blame] | 252 | ASSERT_TRUE(caller->sctp_mid()); |
| 253 | EXPECT_EQ(data_mid, *caller->sctp_mid()); |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 254 | ASSERT_TRUE(caller->sctp_transport_name()); |
Steve Anton | dbf9d03 | 2018-01-19 23:23:40 | [diff] [blame] | 255 | EXPECT_EQ(audio_mid, *caller->sctp_transport_name()); |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 256 | } |
| 257 | |
Steve Anton | dbf9d03 | 2018-01-19 23:23:40 | [diff] [blame] | 258 | TEST_P(PeerConnectionDataChannelTest, |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 259 | CreateOfferWithNoDataChannelsGivesNoDataSection) { |
| 260 | auto caller = CreatePeerConnection(); |
| 261 | auto offer = caller->CreateOffer(); |
| 262 | |
| 263 | EXPECT_FALSE(offer->description()->GetContentByName(cricket::CN_DATA)); |
| 264 | EXPECT_FALSE(offer->description()->GetTransportInfoByName(cricket::CN_DATA)); |
| 265 | } |
| 266 | |
Steve Anton | dbf9d03 | 2018-01-19 23:23:40 | [diff] [blame] | 267 | TEST_P(PeerConnectionDataChannelTest, |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 268 | CreateAnswerWithRemoteSctpDataChannelIncludesDataSection) { |
| 269 | auto caller = CreatePeerConnectionWithDataChannel(); |
| 270 | auto callee = CreatePeerConnection(); |
| 271 | |
| 272 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 273 | |
| 274 | auto answer = callee->CreateAnswer(); |
| 275 | ASSERT_TRUE(answer); |
Steve Anton | dbf9d03 | 2018-01-19 23:23:40 | [diff] [blame] | 276 | auto* data_content = cricket::GetFirstDataContent(answer->description()); |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 277 | ASSERT_TRUE(data_content); |
| 278 | EXPECT_FALSE(data_content->rejected); |
Steve Anton | dbf9d03 | 2018-01-19 23:23:40 | [diff] [blame] | 279 | EXPECT_TRUE( |
| 280 | answer->description()->GetTransportInfoByName(data_content->name)); |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 281 | } |
| 282 | |
Steve Anton | dbf9d03 | 2018-01-19 23:23:40 | [diff] [blame] | 283 | TEST_P(PeerConnectionDataChannelTest, |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 284 | CreateDataChannelWithDtlsDisabledSucceeds) { |
| 285 | RTCConfiguration config; |
| 286 | config.enable_dtls_srtp.emplace(false); |
| 287 | auto caller = CreatePeerConnection(); |
| 288 | |
| 289 | EXPECT_TRUE(caller->pc()->CreateDataChannel("dc", nullptr)); |
| 290 | } |
| 291 | |
Steve Anton | dbf9d03 | 2018-01-19 23:23:40 | [diff] [blame] | 292 | TEST_P(PeerConnectionDataChannelTest, SctpPortPropagatedFromSdpToTransport) { |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 293 | constexpr int kNewSendPort = 9998; |
| 294 | constexpr int kNewRecvPort = 7775; |
| 295 | |
| 296 | auto caller = CreatePeerConnectionWithDataChannel(); |
| 297 | auto callee = CreatePeerConnectionWithDataChannel(); |
| 298 | |
| 299 | auto offer = caller->CreateOffer(); |
| 300 | ChangeSctpPortOnDescription(offer->description(), kNewSendPort); |
| 301 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 302 | |
| 303 | auto answer = callee->CreateAnswer(); |
| 304 | ChangeSctpPortOnDescription(answer->description(), kNewRecvPort); |
Harald Alvestrand | 7af57c6 | 2021-04-16 11:12:14 | [diff] [blame] | 305 | std::string sdp; |
| 306 | answer->ToString(&sdp); |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 307 | ASSERT_TRUE(callee->SetLocalDescription(std::move(answer))); |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 308 | auto* callee_transport = |
| 309 | callee->sctp_transport_factory()->last_fake_sctp_transport(); |
| 310 | ASSERT_TRUE(callee_transport); |
| 311 | EXPECT_EQ(kNewSendPort, callee_transport->remote_port()); |
| 312 | EXPECT_EQ(kNewRecvPort, callee_transport->local_port()); |
| 313 | } |
| 314 | |
Guido Urdaneta | cecf87f | 2019-05-31 10:17:38 | [diff] [blame] | 315 | TEST_P(PeerConnectionDataChannelTest, ModernSdpSyntaxByDefault) { |
Harald Alvestrand | 4aa1192 | 2019-05-14 20:00:01 | [diff] [blame] | 316 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 317 | auto caller = CreatePeerConnectionWithDataChannel(); |
| 318 | auto offer = caller->CreateOffer(options); |
| 319 | EXPECT_FALSE(cricket::GetFirstSctpDataContentDescription(offer->description()) |
| 320 | ->use_sctpmap()); |
| 321 | std::string sdp; |
| 322 | offer->ToString(&sdp); |
| 323 | RTC_LOG(LS_ERROR) << sdp; |
| 324 | EXPECT_THAT(sdp, HasSubstr(" UDP/DTLS/SCTP webrtc-datachannel")); |
| 325 | EXPECT_THAT(sdp, Not(HasSubstr("a=sctpmap:"))); |
| 326 | } |
| 327 | |
| 328 | TEST_P(PeerConnectionDataChannelTest, ObsoleteSdpSyntaxIfSet) { |
| 329 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 330 | options.use_obsolete_sctp_sdp = true; |
| 331 | auto caller = CreatePeerConnectionWithDataChannel(); |
| 332 | auto offer = caller->CreateOffer(options); |
| 333 | EXPECT_TRUE(cricket::GetFirstSctpDataContentDescription(offer->description()) |
| 334 | ->use_sctpmap()); |
| 335 | std::string sdp; |
| 336 | offer->ToString(&sdp); |
| 337 | EXPECT_THAT(sdp, Not(HasSubstr(" UDP/DTLS/SCTP webrtc-datachannel"))); |
| 338 | EXPECT_THAT(sdp, HasSubstr("a=sctpmap:")); |
| 339 | } |
| 340 | |
Mirko Bonadei | c84f661 | 2019-01-31 11:20:57 | [diff] [blame] | 341 | INSTANTIATE_TEST_SUITE_P(PeerConnectionDataChannelTest, |
| 342 | PeerConnectionDataChannelTest, |
| 343 | Values(SdpSemantics::kPlanB, |
| 344 | SdpSemantics::kUnifiedPlan)); |
Steve Anton | dbf9d03 | 2018-01-19 23:23:40 | [diff] [blame] | 345 | |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 346 | } // namespace webrtc |