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