Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [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 16:47:49 +0100 | [diff] [blame] | 11 | #include <memory> |
| 12 | #include <string> |
| 13 | #include <type_traits> |
| 14 | #include <utility> |
| 15 | #include <vector> |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 16 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 17 | #include "absl/types/optional.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 18 | #include "api/call/call_factory_interface.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 19 | #include "api/jsep.h" |
| 20 | #include "api/media_transport_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 21 | #include "api/media_types.h" |
| 22 | #include "api/peer_connection_interface.h" |
| 23 | #include "api/peer_connection_proxy.h" |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 24 | #include "api/scoped_refptr.h" |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 25 | #include "api/test/fake_media_transport.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 26 | #include "media/base/codec.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 27 | #include "media/base/fake_media_engine.h" |
| 28 | #include "media/base/media_constants.h" |
| 29 | #include "media/base/media_engine.h" |
| 30 | #include "media/sctp/sctp_transport_internal.h" |
| 31 | #include "p2p/base/p2p_constants.h" |
| 32 | #include "p2p/base/port_allocator.h" |
| 33 | #include "pc/media_session.h" |
| 34 | #include "pc/peer_connection.h" |
| 35 | #include "pc/peer_connection_factory.h" |
| 36 | #include "pc/peer_connection_wrapper.h" |
| 37 | #include "pc/sdp_utils.h" |
| 38 | #include "pc/session_description.h" |
| 39 | #include "pc/test/mock_peer_connection_observers.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 40 | #include "rtc_base/checks.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 41 | #include "rtc_base/ref_counted_object.h" |
| 42 | #include "rtc_base/rtc_certificate_generator.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 43 | #include "rtc_base/thread.h" |
Harald Alvestrand | 4aa1192 | 2019-05-14 22:00:01 +0200 | [diff] [blame] | 44 | #include "test/gmock.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 45 | #include "test/gtest.h" |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 46 | #ifdef WEBRTC_ANDROID |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 47 | #include "pc/test/android_test_initializer.h" |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 48 | #endif |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 49 | #include "absl/memory/memory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 50 | #include "pc/test/fake_sctp_transport.h" |
| 51 | #include "rtc_base/virtual_socket_server.h" |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 52 | |
| 53 | namespace webrtc { |
| 54 | |
| 55 | using RTCConfiguration = PeerConnectionInterface::RTCConfiguration; |
| 56 | using RTCOfferAnswerOptions = PeerConnectionInterface::RTCOfferAnswerOptions; |
Harald Alvestrand | 4aa1192 | 2019-05-14 22:00:01 +0200 | [diff] [blame] | 57 | using ::testing::HasSubstr; |
| 58 | using ::testing::Not; |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 59 | using ::testing::Values; |
| 60 | |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 61 | namespace { |
| 62 | |
| 63 | PeerConnectionFactoryDependencies 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; |
| 74 | deps.media_engine = std::move(media_engine); |
| 75 | deps.call_factory = std::move(call_factory); |
| 76 | deps.media_transport_factory = std::move(media_transport_factory); |
| 77 | return deps; |
| 78 | } |
| 79 | |
| 80 | } // namespace |
| 81 | |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 82 | class PeerConnectionFactoryForDataChannelTest |
| 83 | : public rtc::RefCountedObject<PeerConnectionFactory> { |
| 84 | public: |
| 85 | PeerConnectionFactoryForDataChannelTest() |
| 86 | : rtc::RefCountedObject<PeerConnectionFactory>( |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 87 | CreatePeerConnectionFactoryDependencies( |
| 88 | rtc::Thread::Current(), |
| 89 | rtc::Thread::Current(), |
| 90 | rtc::Thread::Current(), |
| 91 | absl::make_unique<cricket::FakeMediaEngine>(), |
| 92 | CreateCallFactory(), |
| 93 | absl::make_unique<FakeMediaTransportFactory>())) {} |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 94 | |
| 95 | std::unique_ptr<cricket::SctpTransportInternalFactory> |
| 96 | CreateSctpTransportInternalFactory() { |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 97 | auto factory = absl::make_unique<FakeSctpTransportFactory>(); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 98 | last_fake_sctp_transport_factory_ = factory.get(); |
| 99 | return factory; |
| 100 | } |
| 101 | |
| 102 | FakeSctpTransportFactory* last_fake_sctp_transport_factory_ = nullptr; |
| 103 | }; |
| 104 | |
| 105 | class PeerConnectionWrapperForDataChannelTest : public PeerConnectionWrapper { |
| 106 | public: |
| 107 | using PeerConnectionWrapper::PeerConnectionWrapper; |
| 108 | |
| 109 | FakeSctpTransportFactory* sctp_transport_factory() { |
| 110 | return sctp_transport_factory_; |
| 111 | } |
| 112 | |
| 113 | void set_sctp_transport_factory( |
| 114 | FakeSctpTransportFactory* sctp_transport_factory) { |
| 115 | sctp_transport_factory_ = sctp_transport_factory; |
| 116 | } |
| 117 | |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 118 | absl::optional<std::string> sctp_content_name() { |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 119 | return GetInternalPeerConnection()->sctp_content_name(); |
| 120 | } |
| 121 | |
Danil Chapovalov | 66cadcc | 2018-06-19 16:47:43 +0200 | [diff] [blame] | 122 | absl::optional<std::string> sctp_transport_name() { |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 123 | return GetInternalPeerConnection()->sctp_transport_name(); |
| 124 | } |
| 125 | |
| 126 | PeerConnection* GetInternalPeerConnection() { |
Mirko Bonadei | e97de91 | 2017-12-13 11:29:34 +0100 | [diff] [blame] | 127 | auto* pci = |
| 128 | static_cast<PeerConnectionProxyWithInternal<PeerConnectionInterface>*>( |
| 129 | pc()); |
| 130 | return static_cast<PeerConnection*>(pci->internal()); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | private: |
| 134 | FakeSctpTransportFactory* sctp_transport_factory_ = nullptr; |
| 135 | }; |
| 136 | |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 137 | class PeerConnectionDataChannelBaseTest : public ::testing::Test { |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 138 | protected: |
| 139 | typedef std::unique_ptr<PeerConnectionWrapperForDataChannelTest> WrapperPtr; |
| 140 | |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 141 | explicit PeerConnectionDataChannelBaseTest(SdpSemantics sdp_semantics) |
| 142 | : vss_(new rtc::VirtualSocketServer()), |
| 143 | main_(vss_.get()), |
| 144 | sdp_semantics_(sdp_semantics) { |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 145 | #ifdef WEBRTC_ANDROID |
| 146 | InitializeAndroidObjects(); |
| 147 | #endif |
| 148 | } |
| 149 | |
| 150 | WrapperPtr CreatePeerConnection() { |
| 151 | return CreatePeerConnection(RTCConfiguration()); |
| 152 | } |
| 153 | |
| 154 | WrapperPtr CreatePeerConnection(const RTCConfiguration& config) { |
| 155 | return CreatePeerConnection(config, |
| 156 | PeerConnectionFactoryInterface::Options()); |
| 157 | } |
| 158 | |
| 159 | WrapperPtr CreatePeerConnection( |
| 160 | const RTCConfiguration& config, |
| 161 | const PeerConnectionFactoryInterface::Options factory_options) { |
| 162 | rtc::scoped_refptr<PeerConnectionFactoryForDataChannelTest> pc_factory( |
| 163 | new PeerConnectionFactoryForDataChannelTest()); |
| 164 | pc_factory->SetOptions(factory_options); |
| 165 | RTC_CHECK(pc_factory->Initialize()); |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 166 | auto observer = absl::make_unique<MockPeerConnectionObserver>(); |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 167 | RTCConfiguration modified_config = config; |
| 168 | modified_config.sdp_semantics = sdp_semantics_; |
| 169 | auto pc = pc_factory->CreatePeerConnection(modified_config, nullptr, |
| 170 | nullptr, observer.get()); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 171 | if (!pc) { |
| 172 | return nullptr; |
| 173 | } |
| 174 | |
Yves Gerey | 4e93329 | 2018-10-31 15:36:05 +0100 | [diff] [blame] | 175 | observer->SetPeerConnectionInterface(pc.get()); |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 176 | auto wrapper = absl::make_unique<PeerConnectionWrapperForDataChannelTest>( |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 177 | pc_factory, pc, std::move(observer)); |
| 178 | RTC_DCHECK(pc_factory->last_fake_sctp_transport_factory_); |
| 179 | wrapper->set_sctp_transport_factory( |
| 180 | pc_factory->last_fake_sctp_transport_factory_); |
| 181 | return wrapper; |
| 182 | } |
| 183 | |
| 184 | // Accepts the same arguments as CreatePeerConnection and adds a default data |
| 185 | // channel. |
| 186 | template <typename... Args> |
| 187 | WrapperPtr CreatePeerConnectionWithDataChannel(Args&&... args) { |
| 188 | auto wrapper = CreatePeerConnection(std::forward<Args>(args)...); |
| 189 | if (!wrapper) { |
| 190 | return nullptr; |
| 191 | } |
| 192 | EXPECT_TRUE(wrapper->pc()->CreateDataChannel("dc", nullptr)); |
| 193 | return wrapper; |
| 194 | } |
| 195 | |
| 196 | // Changes the SCTP data channel port on the given session description. |
| 197 | void ChangeSctpPortOnDescription(cricket::SessionDescription* desc, |
| 198 | int port) { |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 199 | auto* data_content = cricket::GetFirstDataContent(desc); |
| 200 | RTC_DCHECK(data_content); |
Harald Alvestrand | 5fc28b1 | 2019-05-13 13:36:16 +0200 | [diff] [blame] | 201 | auto* data_desc = data_content->media_description()->as_sctp(); |
| 202 | RTC_DCHECK(data_desc); |
| 203 | data_desc->set_port(port); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | std::unique_ptr<rtc::VirtualSocketServer> vss_; |
| 207 | rtc::AutoSocketServerThread main_; |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 208 | const SdpSemantics sdp_semantics_; |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 209 | }; |
| 210 | |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 211 | class PeerConnectionDataChannelTest |
| 212 | : public PeerConnectionDataChannelBaseTest, |
| 213 | public ::testing::WithParamInterface<SdpSemantics> { |
| 214 | protected: |
| 215 | PeerConnectionDataChannelTest() |
| 216 | : PeerConnectionDataChannelBaseTest(GetParam()) {} |
| 217 | }; |
| 218 | |
| 219 | TEST_P(PeerConnectionDataChannelTest, |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 220 | NoSctpTransportCreatedIfRtpDataChannelEnabled) { |
| 221 | RTCConfiguration config; |
| 222 | config.enable_rtp_data_channel = true; |
| 223 | auto caller = CreatePeerConnectionWithDataChannel(config); |
| 224 | |
| 225 | ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer())); |
| 226 | EXPECT_FALSE(caller->sctp_transport_factory()->last_fake_sctp_transport()); |
| 227 | } |
| 228 | |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 229 | TEST_P(PeerConnectionDataChannelTest, |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 230 | RtpDataChannelCreatedEvenIfSctpAvailable) { |
| 231 | RTCConfiguration config; |
| 232 | config.enable_rtp_data_channel = true; |
| 233 | PeerConnectionFactoryInterface::Options options; |
| 234 | options.disable_sctp_data_channels = false; |
| 235 | auto caller = CreatePeerConnectionWithDataChannel(config, options); |
| 236 | |
| 237 | ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer())); |
| 238 | EXPECT_FALSE(caller->sctp_transport_factory()->last_fake_sctp_transport()); |
| 239 | } |
| 240 | |
| 241 | // Test that sctp_content_name/sctp_transport_name (used for stats) are correct |
| 242 | // before and after BUNDLE is negotiated. |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 243 | TEST_P(PeerConnectionDataChannelTest, SctpContentAndTransportNameSetCorrectly) { |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 244 | auto caller = CreatePeerConnection(); |
| 245 | auto callee = CreatePeerConnection(); |
| 246 | |
| 247 | // Initially these fields should be empty. |
| 248 | EXPECT_FALSE(caller->sctp_content_name()); |
| 249 | EXPECT_FALSE(caller->sctp_transport_name()); |
| 250 | |
| 251 | // Create offer with audio/video/data. |
| 252 | // Default bundle policy is "balanced", so data should be using its own |
| 253 | // transport. |
| 254 | caller->AddAudioTrack("a"); |
| 255 | caller->AddVideoTrack("v"); |
| 256 | caller->pc()->CreateDataChannel("dc", nullptr); |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 257 | |
| 258 | auto offer = caller->CreateOffer(); |
| 259 | const auto& offer_contents = offer->description()->contents(); |
| 260 | ASSERT_EQ(cricket::MEDIA_TYPE_AUDIO, |
| 261 | offer_contents[0].media_description()->type()); |
| 262 | std::string audio_mid = offer_contents[0].name; |
| 263 | ASSERT_EQ(cricket::MEDIA_TYPE_DATA, |
| 264 | offer_contents[2].media_description()->type()); |
| 265 | std::string data_mid = offer_contents[2].name; |
| 266 | |
| 267 | ASSERT_TRUE( |
| 268 | caller->SetLocalDescription(CloneSessionDescription(offer.get()))); |
| 269 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 270 | |
| 271 | ASSERT_TRUE(caller->sctp_content_name()); |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 272 | EXPECT_EQ(data_mid, *caller->sctp_content_name()); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 273 | ASSERT_TRUE(caller->sctp_transport_name()); |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 274 | EXPECT_EQ(data_mid, *caller->sctp_transport_name()); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 275 | |
| 276 | // Create answer that finishes BUNDLE negotiation, which means everything |
| 277 | // should be bundled on the first transport (audio). |
| 278 | RTCOfferAnswerOptions options; |
| 279 | options.use_rtp_mux = true; |
| 280 | ASSERT_TRUE( |
| 281 | caller->SetRemoteDescription(callee->CreateAnswerAndSetAsLocal())); |
| 282 | |
| 283 | ASSERT_TRUE(caller->sctp_content_name()); |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 284 | EXPECT_EQ(data_mid, *caller->sctp_content_name()); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 285 | ASSERT_TRUE(caller->sctp_transport_name()); |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 286 | EXPECT_EQ(audio_mid, *caller->sctp_transport_name()); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 289 | TEST_P(PeerConnectionDataChannelTest, |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 290 | CreateOfferWithNoDataChannelsGivesNoDataSection) { |
| 291 | auto caller = CreatePeerConnection(); |
| 292 | auto offer = caller->CreateOffer(); |
| 293 | |
| 294 | EXPECT_FALSE(offer->description()->GetContentByName(cricket::CN_DATA)); |
| 295 | EXPECT_FALSE(offer->description()->GetTransportInfoByName(cricket::CN_DATA)); |
| 296 | } |
| 297 | |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 298 | TEST_P(PeerConnectionDataChannelTest, |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 299 | CreateAnswerWithRemoteSctpDataChannelIncludesDataSection) { |
| 300 | auto caller = CreatePeerConnectionWithDataChannel(); |
| 301 | auto callee = CreatePeerConnection(); |
| 302 | |
| 303 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 304 | |
| 305 | auto answer = callee->CreateAnswer(); |
| 306 | ASSERT_TRUE(answer); |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 307 | auto* data_content = cricket::GetFirstDataContent(answer->description()); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 308 | ASSERT_TRUE(data_content); |
| 309 | EXPECT_FALSE(data_content->rejected); |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 310 | EXPECT_TRUE( |
| 311 | answer->description()->GetTransportInfoByName(data_content->name)); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 314 | TEST_P(PeerConnectionDataChannelTest, |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 315 | CreateDataChannelWithDtlsDisabledSucceeds) { |
| 316 | RTCConfiguration config; |
| 317 | config.enable_dtls_srtp.emplace(false); |
| 318 | auto caller = CreatePeerConnection(); |
| 319 | |
| 320 | EXPECT_TRUE(caller->pc()->CreateDataChannel("dc", nullptr)); |
| 321 | } |
| 322 | |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 323 | TEST_P(PeerConnectionDataChannelTest, CreateDataChannelWithSctpDisabledFails) { |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 324 | PeerConnectionFactoryInterface::Options options; |
| 325 | options.disable_sctp_data_channels = true; |
| 326 | auto caller = CreatePeerConnection(RTCConfiguration(), options); |
| 327 | |
| 328 | EXPECT_FALSE(caller->pc()->CreateDataChannel("dc", nullptr)); |
| 329 | } |
| 330 | |
| 331 | // Test that if a callee has SCTP disabled and receives an offer with an SCTP |
| 332 | // data channel, the data section is rejected and no SCTP transport is created |
| 333 | // on the callee. |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 334 | TEST_P(PeerConnectionDataChannelTest, |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 335 | DataSectionRejectedIfCalleeHasSctpDisabled) { |
| 336 | auto caller = CreatePeerConnectionWithDataChannel(); |
| 337 | PeerConnectionFactoryInterface::Options options; |
| 338 | options.disable_sctp_data_channels = true; |
| 339 | auto callee = CreatePeerConnection(RTCConfiguration(), options); |
| 340 | |
| 341 | ASSERT_TRUE(callee->SetRemoteDescription(caller->CreateOfferAndSetAsLocal())); |
| 342 | |
| 343 | EXPECT_FALSE(callee->sctp_transport_factory()->last_fake_sctp_transport()); |
| 344 | |
| 345 | auto answer = callee->CreateAnswer(); |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 346 | auto* data_content = cricket::GetFirstDataContent(answer->description()); |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 347 | ASSERT_TRUE(data_content); |
| 348 | EXPECT_TRUE(data_content->rejected); |
| 349 | } |
| 350 | |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 351 | TEST_P(PeerConnectionDataChannelTest, SctpPortPropagatedFromSdpToTransport) { |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 352 | constexpr int kNewSendPort = 9998; |
| 353 | constexpr int kNewRecvPort = 7775; |
| 354 | |
| 355 | auto caller = CreatePeerConnectionWithDataChannel(); |
| 356 | auto callee = CreatePeerConnectionWithDataChannel(); |
| 357 | |
| 358 | auto offer = caller->CreateOffer(); |
| 359 | ChangeSctpPortOnDescription(offer->description(), kNewSendPort); |
| 360 | ASSERT_TRUE(callee->SetRemoteDescription(std::move(offer))); |
| 361 | |
| 362 | auto answer = callee->CreateAnswer(); |
| 363 | ChangeSctpPortOnDescription(answer->description(), kNewRecvPort); |
| 364 | ASSERT_TRUE(callee->SetLocalDescription(std::move(answer))); |
| 365 | |
| 366 | auto* callee_transport = |
| 367 | callee->sctp_transport_factory()->last_fake_sctp_transport(); |
| 368 | ASSERT_TRUE(callee_transport); |
| 369 | EXPECT_EQ(kNewSendPort, callee_transport->remote_port()); |
| 370 | EXPECT_EQ(kNewRecvPort, callee_transport->local_port()); |
| 371 | } |
| 372 | |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 373 | TEST_P(PeerConnectionDataChannelTest, |
| 374 | NoSctpTransportCreatedIfMediaTransportDataChannelsEnabled) { |
| 375 | RTCConfiguration config; |
| 376 | config.use_media_transport_for_data_channels = true; |
| 377 | config.enable_dtls_srtp = false; // SDES is required to use media transport. |
| 378 | auto caller = CreatePeerConnectionWithDataChannel(config); |
| 379 | |
| 380 | ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer())); |
| 381 | EXPECT_FALSE(caller->sctp_transport_factory()->last_fake_sctp_transport()); |
| 382 | } |
| 383 | |
| 384 | TEST_P(PeerConnectionDataChannelTest, |
| 385 | MediaTransportDataChannelCreatedEvenIfSctpAvailable) { |
| 386 | RTCConfiguration config; |
| 387 | config.use_media_transport_for_data_channels = true; |
| 388 | config.enable_dtls_srtp = false; // SDES is required to use media transport. |
| 389 | PeerConnectionFactoryInterface::Options options; |
| 390 | options.disable_sctp_data_channels = false; |
| 391 | auto caller = CreatePeerConnectionWithDataChannel(config, options); |
| 392 | |
| 393 | ASSERT_TRUE(caller->SetLocalDescription(caller->CreateOffer())); |
| 394 | EXPECT_FALSE(caller->sctp_transport_factory()->last_fake_sctp_transport()); |
| 395 | } |
| 396 | |
| 397 | TEST_P(PeerConnectionDataChannelTest, |
| 398 | CannotEnableBothMediaTransportAndRtpDataChannels) { |
| 399 | RTCConfiguration config; |
| 400 | config.enable_rtp_data_channel = true; |
| 401 | config.use_media_transport_for_data_channels = true; |
| 402 | config.enable_dtls_srtp = false; // SDES is required to use media transport. |
| 403 | EXPECT_EQ(CreatePeerConnection(config), nullptr); |
| 404 | } |
| 405 | |
Piotr (Peter) Slatala | b1ae10b | 2019-03-01 11:14:05 -0800 | [diff] [blame] | 406 | // This test now DCHECKs, instead of failing to SetLocalDescription. |
| 407 | TEST_P(PeerConnectionDataChannelTest, MediaTransportWithoutSdesFails) { |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 408 | RTCConfiguration config; |
| 409 | config.use_media_transport_for_data_channels = true; |
| 410 | config.enable_dtls_srtp = true; // Disables SDES for data sections. |
Piotr (Peter) Slatala | b1ae10b | 2019-03-01 11:14:05 -0800 | [diff] [blame] | 411 | |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 412 | auto caller = CreatePeerConnectionWithDataChannel(config); |
| 413 | |
Piotr (Peter) Slatala | b1ae10b | 2019-03-01 11:14:05 -0800 | [diff] [blame] | 414 | EXPECT_EQ(nullptr, caller); |
Bjorn Mellem | 175aa2e | 2018-11-08 11:23:22 -0800 | [diff] [blame] | 415 | } |
| 416 | |
Guido Urdaneta | 4436887 | 2019-05-31 11:32:01 +0200 | [diff] [blame^] | 417 | TEST_P(PeerConnectionDataChannelTest, DISABLED_ModernSdpSyntaxByDefault) { |
Harald Alvestrand | 4aa1192 | 2019-05-14 22:00:01 +0200 | [diff] [blame] | 418 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 419 | auto caller = CreatePeerConnectionWithDataChannel(); |
| 420 | auto offer = caller->CreateOffer(options); |
| 421 | EXPECT_FALSE(cricket::GetFirstSctpDataContentDescription(offer->description()) |
| 422 | ->use_sctpmap()); |
| 423 | std::string sdp; |
| 424 | offer->ToString(&sdp); |
| 425 | RTC_LOG(LS_ERROR) << sdp; |
| 426 | EXPECT_THAT(sdp, HasSubstr(" UDP/DTLS/SCTP webrtc-datachannel")); |
| 427 | EXPECT_THAT(sdp, Not(HasSubstr("a=sctpmap:"))); |
| 428 | } |
| 429 | |
| 430 | TEST_P(PeerConnectionDataChannelTest, ObsoleteSdpSyntaxIfSet) { |
| 431 | PeerConnectionInterface::RTCOfferAnswerOptions options; |
| 432 | options.use_obsolete_sctp_sdp = true; |
| 433 | auto caller = CreatePeerConnectionWithDataChannel(); |
| 434 | auto offer = caller->CreateOffer(options); |
| 435 | EXPECT_TRUE(cricket::GetFirstSctpDataContentDescription(offer->description()) |
| 436 | ->use_sctpmap()); |
| 437 | std::string sdp; |
| 438 | offer->ToString(&sdp); |
| 439 | EXPECT_THAT(sdp, Not(HasSubstr(" UDP/DTLS/SCTP webrtc-datachannel"))); |
| 440 | EXPECT_THAT(sdp, HasSubstr("a=sctpmap:")); |
| 441 | } |
| 442 | |
Mirko Bonadei | c84f661 | 2019-01-31 12:20:57 +0100 | [diff] [blame] | 443 | INSTANTIATE_TEST_SUITE_P(PeerConnectionDataChannelTest, |
| 444 | PeerConnectionDataChannelTest, |
| 445 | Values(SdpSemantics::kPlanB, |
| 446 | SdpSemantics::kUnifiedPlan)); |
Steve Anton | dbf9d03 | 2018-01-19 15:23:40 -0800 | [diff] [blame] | 447 | |
Steve Anton | da6c095 | 2017-10-23 11:41:54 -0700 | [diff] [blame] | 448 | } // namespace webrtc |