Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 | |
| 11 | #include <stdint.h> |
| 12 | |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 13 | #include <cstdlib> |
| 14 | #include <iterator> |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 15 | #include <string> |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 16 | #include <tuple> |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 17 | #include <vector> |
| 18 | |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 19 | #include "absl/algorithm/container.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 20 | #include "absl/types/optional.h" |
| 21 | #include "api/data_channel_interface.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 22 | #include "api/dtls_transport_interface.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 23 | #include "api/peer_connection_interface.h" |
| 24 | #include "api/scoped_refptr.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 25 | #include "api/sctp_transport_interface.h" |
| 26 | #include "api/stats/rtc_stats_report.h" |
| 27 | #include "api/stats/rtcstats_objects.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 28 | #include "api/units/time_delta.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 29 | #include "p2p/base/transport_description.h" |
| 30 | #include "p2p/base/transport_info.h" |
| 31 | #include "pc/media_session.h" |
| 32 | #include "pc/session_description.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 33 | #include "pc/test/integration_test_helpers.h" |
| 34 | #include "pc/test/mock_peer_connection_observers.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 35 | #include "rtc_base/copy_on_write_buffer.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 36 | #include "rtc_base/fake_clock.h" |
| 37 | #include "rtc_base/gunit.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 38 | #include "rtc_base/helpers.h" |
| 39 | #include "rtc_base/logging.h" |
| 40 | #include "rtc_base/numerics/safe_conversions.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 41 | #include "rtc_base/virtual_socket_server.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 +0000 | [diff] [blame] | 42 | #include "test/gmock.h" |
Florent Castelli | a6983c6 | 2021-05-06 10:50:07 +0200 | [diff] [blame] | 43 | #include "test/gtest.h" |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 44 | |
| 45 | namespace webrtc { |
| 46 | |
| 47 | namespace { |
| 48 | |
Harald Alvestrand | 20f9401 | 2021-05-21 07:04:27 +0000 | [diff] [blame] | 49 | // All tests in this file require SCTP support. |
| 50 | #ifdef WEBRTC_HAVE_SCTP |
| 51 | |
Victor Boivie | fe968df | 2022-02-01 11:26:05 +0100 | [diff] [blame] | 52 | #if defined(WEBRTC_ANDROID) |
| 53 | // Disable heavy tests running on low-end Android devices. |
| 54 | #define DISABLED_ON_ANDROID(t) DISABLED_##t |
| 55 | #else |
| 56 | #define DISABLED_ON_ANDROID(t) t |
| 57 | #endif |
| 58 | |
Florent Castelli | f2599a7 | 2022-03-31 19:15:10 +0200 | [diff] [blame] | 59 | class DataChannelIntegrationTest |
| 60 | : public PeerConnectionIntegrationBaseTest, |
| 61 | public ::testing::WithParamInterface<SdpSemantics> { |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 62 | protected: |
| 63 | DataChannelIntegrationTest() |
Florent Castelli | f2599a7 | 2022-03-31 19:15:10 +0200 | [diff] [blame] | 64 | : PeerConnectionIntegrationBaseTest(GetParam()) {} |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | // Fake clock must be set before threads are started to prevent race on |
| 68 | // Set/GetClockForTesting(). |
| 69 | // To achieve that, multiple inheritance is used as a mixin pattern |
| 70 | // where order of construction is finely controlled. |
| 71 | // This also ensures peerconnection is closed before switching back to non-fake |
| 72 | // clock, avoiding other races and DCHECK failures such as in rtp_sender.cc. |
| 73 | class FakeClockForTest : public rtc::ScopedFakeClock { |
| 74 | protected: |
| 75 | FakeClockForTest() { |
| 76 | // Some things use a time of "0" as a special value, so we need to start out |
| 77 | // the fake clock at a nonzero time. |
| 78 | // TODO(deadbeef): Fix this. |
| 79 | AdvanceTime(webrtc::TimeDelta::Seconds(1)); |
| 80 | } |
| 81 | |
| 82 | // Explicit handle. |
| 83 | ScopedFakeClock& FakeClock() { return *this; } |
| 84 | }; |
| 85 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 86 | class DataChannelIntegrationTestPlanB |
| 87 | : public PeerConnectionIntegrationBaseTest { |
| 88 | protected: |
| 89 | DataChannelIntegrationTestPlanB() |
Florent Castelli | 15a38de | 2022-04-06 00:38:21 +0200 | [diff] [blame] | 90 | : PeerConnectionIntegrationBaseTest(SdpSemantics::kPlanB_DEPRECATED) {} |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 93 | class DataChannelIntegrationTestUnifiedPlan |
| 94 | : public PeerConnectionIntegrationBaseTest { |
| 95 | protected: |
| 96 | DataChannelIntegrationTestUnifiedPlan() |
| 97 | : PeerConnectionIntegrationBaseTest(SdpSemantics::kUnifiedPlan) {} |
| 98 | }; |
| 99 | |
Harald Alvestrand | 321ec3b | 2022-02-10 13:42:18 +0000 | [diff] [blame] | 100 | void MakeActiveSctpOffer(cricket::SessionDescription* desc) { |
| 101 | auto& transport_infos = desc->transport_infos(); |
| 102 | for (auto& transport_info : transport_infos) { |
| 103 | transport_info.description.connection_role = cricket::CONNECTIONROLE_ACTIVE; |
| 104 | } |
| 105 | } |
| 106 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 107 | // This test causes a PeerConnection to enter Disconnected state, and |
| 108 | // sends data on a DataChannel while disconnected. |
| 109 | // The data should be surfaced when the connection reestablishes. |
| 110 | TEST_P(DataChannelIntegrationTest, DataChannelWhileDisconnected) { |
| 111 | CreatePeerConnectionWrappers(); |
| 112 | ConnectFakeSignaling(); |
| 113 | caller()->CreateDataChannel(); |
| 114 | caller()->CreateAndSetAndSignalOffer(); |
| 115 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 116 | ASSERT_TRUE_WAIT(callee()->data_observer(), kDefaultTimeout); |
| 117 | std::string data1 = "hello first"; |
| 118 | caller()->data_channel()->Send(DataBuffer(data1)); |
| 119 | EXPECT_EQ_WAIT(data1, callee()->data_observer()->last_message(), |
| 120 | kDefaultTimeout); |
| 121 | // Cause a network outage |
| 122 | virtual_socket_server()->set_drop_probability(1.0); |
| 123 | EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 124 | caller()->standardized_ice_connection_state(), |
| 125 | kDefaultTimeout); |
| 126 | std::string data2 = "hello second"; |
| 127 | caller()->data_channel()->Send(DataBuffer(data2)); |
| 128 | // Remove the network outage. The connection should reestablish. |
| 129 | virtual_socket_server()->set_drop_probability(0.0); |
| 130 | EXPECT_EQ_WAIT(data2, callee()->data_observer()->last_message(), |
| 131 | kDefaultTimeout); |
| 132 | } |
| 133 | |
| 134 | // This test causes a PeerConnection to enter Disconnected state, |
| 135 | // sends data on a DataChannel while disconnected, and then triggers |
| 136 | // an ICE restart. |
| 137 | // The data should be surfaced when the connection reestablishes. |
| 138 | TEST_P(DataChannelIntegrationTest, DataChannelWhileDisconnectedIceRestart) { |
| 139 | CreatePeerConnectionWrappers(); |
| 140 | ConnectFakeSignaling(); |
| 141 | caller()->CreateDataChannel(); |
| 142 | caller()->CreateAndSetAndSignalOffer(); |
| 143 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 144 | ASSERT_TRUE_WAIT(callee()->data_observer(), kDefaultTimeout); |
| 145 | std::string data1 = "hello first"; |
| 146 | caller()->data_channel()->Send(DataBuffer(data1)); |
| 147 | EXPECT_EQ_WAIT(data1, callee()->data_observer()->last_message(), |
| 148 | kDefaultTimeout); |
| 149 | // Cause a network outage |
| 150 | virtual_socket_server()->set_drop_probability(1.0); |
| 151 | ASSERT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected, |
| 152 | caller()->standardized_ice_connection_state(), |
| 153 | kDefaultTimeout); |
| 154 | std::string data2 = "hello second"; |
| 155 | caller()->data_channel()->Send(DataBuffer(data2)); |
| 156 | |
| 157 | // Trigger an ICE restart. The signaling channel is not affected by |
| 158 | // the network outage. |
| 159 | caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions()); |
| 160 | caller()->CreateAndSetAndSignalOffer(); |
| 161 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 162 | // Remove the network outage. The connection should reestablish. |
| 163 | virtual_socket_server()->set_drop_probability(0.0); |
| 164 | EXPECT_EQ_WAIT(data2, callee()->data_observer()->last_message(), |
| 165 | kDefaultTimeout); |
| 166 | } |
| 167 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 168 | // This test sets up a call between two parties with audio, video and an SCTP |
| 169 | // data channel. |
| 170 | TEST_P(DataChannelIntegrationTest, EndToEndCallWithSctpDataChannel) { |
| 171 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 172 | ConnectFakeSignaling(); |
| 173 | // Expect that data channel created on caller side will show up for callee as |
| 174 | // well. |
| 175 | caller()->CreateDataChannel(); |
| 176 | caller()->AddAudioVideoTracks(); |
| 177 | callee()->AddAudioVideoTracks(); |
| 178 | caller()->CreateAndSetAndSignalOffer(); |
| 179 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 180 | // Ensure the existence of the SCTP data channel didn't impede audio/video. |
| 181 | MediaExpectations media_expectations; |
| 182 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 183 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 184 | // Caller data channel should already exist (it created one). Callee data |
| 185 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 186 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 187 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 188 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 189 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 190 | |
| 191 | // Ensure data can be sent in both directions. |
| 192 | std::string data = "hello world"; |
| 193 | caller()->data_channel()->Send(DataBuffer(data)); |
| 194 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 195 | kDefaultTimeout); |
| 196 | callee()->data_channel()->Send(DataBuffer(data)); |
| 197 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 198 | kDefaultTimeout); |
| 199 | } |
| 200 | |
Harald Alvestrand | 7087b83 | 2021-03-11 17:21:13 +0000 | [diff] [blame] | 201 | // This test sets up a call between two parties with an SCTP |
| 202 | // data channel only, and sends messages of various sizes. |
| 203 | TEST_P(DataChannelIntegrationTest, |
| 204 | EndToEndCallWithSctpDataChannelVariousSizes) { |
Harald Alvestrand | 35ba0c5 | 2022-05-05 07:37:41 +0000 | [diff] [blame] | 205 | ASSERT_TRUE(CreatePeerConnectionWrappersWithoutMediaEngine()); |
Harald Alvestrand | 7087b83 | 2021-03-11 17:21:13 +0000 | [diff] [blame] | 206 | ConnectFakeSignaling(); |
| 207 | // Expect that data channel created on caller side will show up for callee as |
| 208 | // well. |
| 209 | caller()->CreateDataChannel(); |
| 210 | caller()->CreateAndSetAndSignalOffer(); |
| 211 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 212 | // Caller data channel should already exist (it created one). Callee data |
| 213 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 214 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 215 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 216 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 217 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 218 | |
| 219 | for (int message_size = 1; message_size < 100000; message_size *= 2) { |
| 220 | std::string data(message_size, 'a'); |
| 221 | caller()->data_channel()->Send(DataBuffer(data)); |
| 222 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 223 | kDefaultTimeout); |
| 224 | callee()->data_channel()->Send(DataBuffer(data)); |
| 225 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 226 | kDefaultTimeout); |
| 227 | } |
| 228 | // Specifically probe the area around the MTU size. |
| 229 | for (int message_size = 1100; message_size < 1300; message_size += 1) { |
| 230 | std::string data(message_size, 'a'); |
| 231 | caller()->data_channel()->Send(DataBuffer(data)); |
| 232 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 233 | kDefaultTimeout); |
| 234 | callee()->data_channel()->Send(DataBuffer(data)); |
| 235 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 236 | kDefaultTimeout); |
| 237 | } |
| 238 | } |
| 239 | |
Florent Castelli | 88f4b33 | 2021-04-22 13:32:39 +0200 | [diff] [blame] | 240 | // This test sets up a call between two parties with an SCTP |
| 241 | // data channel only, and sends empty messages |
| 242 | TEST_P(DataChannelIntegrationTest, |
| 243 | EndToEndCallWithSctpDataChannelEmptyMessages) { |
Harald Alvestrand | 35ba0c5 | 2022-05-05 07:37:41 +0000 | [diff] [blame] | 244 | ASSERT_TRUE(CreatePeerConnectionWrappersWithoutMediaEngine()); |
Florent Castelli | 88f4b33 | 2021-04-22 13:32:39 +0200 | [diff] [blame] | 245 | ConnectFakeSignaling(); |
| 246 | // Expect that data channel created on caller side will show up for callee as |
| 247 | // well. |
| 248 | caller()->CreateDataChannel(); |
| 249 | caller()->CreateAndSetAndSignalOffer(); |
| 250 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 251 | // Caller data channel should already exist (it created one). Callee data |
| 252 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 253 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 254 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 255 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 256 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 257 | |
| 258 | // Ensure data can be sent in both directions. |
| 259 | // Sending empty string data |
| 260 | std::string data = ""; |
| 261 | caller()->data_channel()->Send(DataBuffer(data)); |
| 262 | EXPECT_EQ_WAIT(1u, callee()->data_observer()->received_message_count(), |
| 263 | kDefaultTimeout); |
| 264 | EXPECT_TRUE(callee()->data_observer()->last_message().empty()); |
| 265 | EXPECT_FALSE(callee()->data_observer()->messages().back().binary); |
| 266 | callee()->data_channel()->Send(DataBuffer(data)); |
| 267 | EXPECT_EQ_WAIT(1u, caller()->data_observer()->received_message_count(), |
| 268 | kDefaultTimeout); |
| 269 | EXPECT_TRUE(caller()->data_observer()->last_message().empty()); |
| 270 | EXPECT_FALSE(caller()->data_observer()->messages().back().binary); |
| 271 | |
| 272 | // Sending empty binary data |
| 273 | rtc::CopyOnWriteBuffer empty_buffer; |
| 274 | caller()->data_channel()->Send(DataBuffer(empty_buffer, true)); |
| 275 | EXPECT_EQ_WAIT(2u, callee()->data_observer()->received_message_count(), |
| 276 | kDefaultTimeout); |
| 277 | EXPECT_TRUE(callee()->data_observer()->last_message().empty()); |
| 278 | EXPECT_TRUE(callee()->data_observer()->messages().back().binary); |
| 279 | callee()->data_channel()->Send(DataBuffer(empty_buffer, true)); |
| 280 | EXPECT_EQ_WAIT(2u, caller()->data_observer()->received_message_count(), |
| 281 | kDefaultTimeout); |
| 282 | EXPECT_TRUE(caller()->data_observer()->last_message().empty()); |
| 283 | EXPECT_TRUE(caller()->data_observer()->messages().back().binary); |
| 284 | } |
| 285 | |
Harald Alvestrand | 7087b83 | 2021-03-11 17:21:13 +0000 | [diff] [blame] | 286 | TEST_P(DataChannelIntegrationTest, |
| 287 | EndToEndCallWithSctpDataChannelLowestSafeMtu) { |
| 288 | // The lowest payload size limit that's tested and found safe for this |
| 289 | // application. Note that this is not the safe limit under all conditions; |
| 290 | // in particular, the default is not the largest DTLS signature, and |
| 291 | // this test does not use TURN. |
| 292 | const size_t kLowestSafePayloadSizeLimit = 1225; |
| 293 | |
Harald Alvestrand | 35ba0c5 | 2022-05-05 07:37:41 +0000 | [diff] [blame] | 294 | ASSERT_TRUE(CreatePeerConnectionWrappersWithoutMediaEngine()); |
Harald Alvestrand | 7087b83 | 2021-03-11 17:21:13 +0000 | [diff] [blame] | 295 | ConnectFakeSignaling(); |
| 296 | // Expect that data channel created on caller side will show up for callee as |
| 297 | // well. |
| 298 | caller()->CreateDataChannel(); |
| 299 | caller()->CreateAndSetAndSignalOffer(); |
| 300 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 301 | // Caller data channel should already exist (it created one). Callee data |
| 302 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 303 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 304 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 305 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 306 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 307 | |
| 308 | virtual_socket_server()->set_max_udp_payload(kLowestSafePayloadSizeLimit); |
| 309 | for (int message_size = 1140; message_size < 1240; message_size += 1) { |
| 310 | std::string data(message_size, 'a'); |
| 311 | caller()->data_channel()->Send(DataBuffer(data)); |
| 312 | ASSERT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 313 | kDefaultTimeout); |
| 314 | callee()->data_channel()->Send(DataBuffer(data)); |
| 315 | ASSERT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 316 | kDefaultTimeout); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | // This test verifies that lowering the MTU of the connection will cause |
| 321 | // the datachannel to not transmit reliably. |
| 322 | // The purpose of this test is to ensure that we know how a too-small MTU |
| 323 | // error manifests itself. |
| 324 | TEST_P(DataChannelIntegrationTest, EndToEndCallWithSctpDataChannelHarmfulMtu) { |
| 325 | // The lowest payload size limit that's tested and found safe for this |
| 326 | // application in this configuration (see test above). |
| 327 | const size_t kLowestSafePayloadSizeLimit = 1225; |
| 328 | // The size of the smallest message that fails to be delivered. |
| 329 | const size_t kMessageSizeThatIsNotDelivered = 1157; |
| 330 | |
Harald Alvestrand | 35ba0c5 | 2022-05-05 07:37:41 +0000 | [diff] [blame] | 331 | ASSERT_TRUE(CreatePeerConnectionWrappersWithoutMediaEngine()); |
Harald Alvestrand | 7087b83 | 2021-03-11 17:21:13 +0000 | [diff] [blame] | 332 | ConnectFakeSignaling(); |
| 333 | caller()->CreateDataChannel(); |
| 334 | caller()->CreateAndSetAndSignalOffer(); |
| 335 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 336 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 337 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 338 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 339 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 340 | |
| 341 | virtual_socket_server()->set_max_udp_payload(kLowestSafePayloadSizeLimit - 1); |
| 342 | // Probe for an undelivered or slowly delivered message. The exact |
| 343 | // size limit seems to be dependent on the message history, so make the |
| 344 | // code easily able to find the current value. |
| 345 | bool failure_seen = false; |
| 346 | for (size_t message_size = 1110; message_size < 1400; message_size++) { |
| 347 | const size_t message_count = |
| 348 | callee()->data_observer()->received_message_count(); |
| 349 | const std::string data(message_size, 'a'); |
| 350 | caller()->data_channel()->Send(DataBuffer(data)); |
| 351 | // Wait a very short time for the message to be delivered. |
Harald Alvestrand | 9d1e070 | 2021-03-16 06:15:01 +0000 | [diff] [blame] | 352 | // Note: Waiting only 10 ms is too short for Windows bots; they will |
| 353 | // flakily fail at a random frame. |
Harald Alvestrand | 7087b83 | 2021-03-11 17:21:13 +0000 | [diff] [blame] | 354 | WAIT(callee()->data_observer()->received_message_count() > message_count, |
Harald Alvestrand | 9d1e070 | 2021-03-16 06:15:01 +0000 | [diff] [blame] | 355 | 100); |
Harald Alvestrand | 7087b83 | 2021-03-11 17:21:13 +0000 | [diff] [blame] | 356 | if (callee()->data_observer()->received_message_count() == message_count) { |
| 357 | ASSERT_EQ(kMessageSizeThatIsNotDelivered, message_size); |
| 358 | failure_seen = true; |
| 359 | break; |
| 360 | } |
| 361 | } |
| 362 | ASSERT_TRUE(failure_seen); |
| 363 | } |
| 364 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 365 | // Ensure that when the callee closes an SCTP data channel, the closing |
| 366 | // procedure results in the data channel being closed for the caller as well. |
| 367 | TEST_P(DataChannelIntegrationTest, CalleeClosesSctpDataChannel) { |
| 368 | // Same procedure as above test. |
| 369 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 370 | ConnectFakeSignaling(); |
| 371 | caller()->CreateDataChannel(); |
| 372 | caller()->AddAudioVideoTracks(); |
| 373 | callee()->AddAudioVideoTracks(); |
| 374 | caller()->CreateAndSetAndSignalOffer(); |
| 375 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 376 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 377 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 378 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 379 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 380 | |
| 381 | // Close the data channel on the callee side, and wait for it to reach the |
| 382 | // "closed" state on both sides. |
| 383 | callee()->data_channel()->Close(); |
Florent Castelli | 141a4de | 2021-04-29 12:49:25 +0200 | [diff] [blame] | 384 | |
| 385 | DataChannelInterface::DataState expected_states[] = { |
| 386 | DataChannelInterface::DataState::kConnecting, |
| 387 | DataChannelInterface::DataState::kOpen, |
| 388 | DataChannelInterface::DataState::kClosing, |
| 389 | DataChannelInterface::DataState::kClosed}; |
| 390 | |
| 391 | EXPECT_EQ_WAIT(DataChannelInterface::DataState::kClosed, |
| 392 | caller()->data_observer()->state(), kDefaultTimeout); |
| 393 | EXPECT_THAT(caller()->data_observer()->states(), |
| 394 | ::testing::ElementsAreArray(expected_states)); |
| 395 | |
| 396 | EXPECT_EQ_WAIT(DataChannelInterface::DataState::kClosed, |
| 397 | callee()->data_observer()->state(), kDefaultTimeout); |
| 398 | EXPECT_THAT(callee()->data_observer()->states(), |
| 399 | ::testing::ElementsAreArray(expected_states)); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | TEST_P(DataChannelIntegrationTest, SctpDataChannelConfigSentToOtherSide) { |
| 403 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 404 | ConnectFakeSignaling(); |
| 405 | webrtc::DataChannelInit init; |
| 406 | init.id = 53; |
| 407 | init.maxRetransmits = 52; |
| 408 | caller()->CreateDataChannel("data-channel", &init); |
| 409 | caller()->AddAudioVideoTracks(); |
| 410 | callee()->AddAudioVideoTracks(); |
| 411 | caller()->CreateAndSetAndSignalOffer(); |
| 412 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 413 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 414 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 415 | // Since "negotiated" is false, the "id" parameter should be ignored. |
| 416 | EXPECT_NE(init.id, callee()->data_channel()->id()); |
| 417 | EXPECT_EQ("data-channel", callee()->data_channel()->label()); |
| 418 | EXPECT_EQ(init.maxRetransmits, callee()->data_channel()->maxRetransmits()); |
| 419 | EXPECT_FALSE(callee()->data_channel()->negotiated()); |
| 420 | } |
| 421 | |
Florent Castelli | f2599a7 | 2022-03-31 19:15:10 +0200 | [diff] [blame] | 422 | // Test sctp's ability to process unordered data stream, where data actually |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 423 | // arrives out of order using simulated delays. Previously there have been some |
| 424 | // bugs in this area. |
| 425 | TEST_P(DataChannelIntegrationTest, StressTestUnorderedSctpDataChannel) { |
| 426 | // Introduce random network delays. |
| 427 | // Otherwise it's not a true "unordered" test. |
| 428 | virtual_socket_server()->set_delay_mean(20); |
| 429 | virtual_socket_server()->set_delay_stddev(5); |
| 430 | virtual_socket_server()->UpdateDelayDistribution(); |
| 431 | // Normal procedure, but with unordered data channel config. |
Harald Alvestrand | 35ba0c5 | 2022-05-05 07:37:41 +0000 | [diff] [blame] | 432 | ASSERT_TRUE(CreatePeerConnectionWrappersWithoutMediaEngine()); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 433 | ConnectFakeSignaling(); |
| 434 | webrtc::DataChannelInit init; |
| 435 | init.ordered = false; |
| 436 | caller()->CreateDataChannel(&init); |
| 437 | caller()->CreateAndSetAndSignalOffer(); |
| 438 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 439 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 440 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 441 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 442 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 443 | |
| 444 | static constexpr int kNumMessages = 100; |
| 445 | // Deliberately chosen to be larger than the MTU so messages get fragmented. |
| 446 | static constexpr size_t kMaxMessageSize = 4096; |
| 447 | // Create and send random messages. |
| 448 | std::vector<std::string> sent_messages; |
| 449 | for (int i = 0; i < kNumMessages; ++i) { |
| 450 | size_t length = |
| 451 | (rand() % kMaxMessageSize) + 1; // NOLINT (rand_r instead of rand) |
| 452 | std::string message; |
| 453 | ASSERT_TRUE(rtc::CreateRandomString(length, &message)); |
| 454 | caller()->data_channel()->Send(DataBuffer(message)); |
| 455 | callee()->data_channel()->Send(DataBuffer(message)); |
| 456 | sent_messages.push_back(message); |
| 457 | } |
| 458 | |
| 459 | // Wait for all messages to be received. |
| 460 | EXPECT_EQ_WAIT(rtc::checked_cast<size_t>(kNumMessages), |
| 461 | caller()->data_observer()->received_message_count(), |
| 462 | kDefaultTimeout); |
| 463 | EXPECT_EQ_WAIT(rtc::checked_cast<size_t>(kNumMessages), |
| 464 | callee()->data_observer()->received_message_count(), |
| 465 | kDefaultTimeout); |
| 466 | |
| 467 | // Sort and compare to make sure none of the messages were corrupted. |
Florent Castelli | 88f4b33 | 2021-04-22 13:32:39 +0200 | [diff] [blame] | 468 | std::vector<std::string> caller_received_messages; |
| 469 | absl::c_transform(caller()->data_observer()->messages(), |
| 470 | std::back_inserter(caller_received_messages), |
| 471 | [](const auto& a) { return a.data; }); |
| 472 | |
| 473 | std::vector<std::string> callee_received_messages; |
| 474 | absl::c_transform(callee()->data_observer()->messages(), |
| 475 | std::back_inserter(callee_received_messages), |
| 476 | [](const auto& a) { return a.data; }); |
| 477 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 478 | absl::c_sort(sent_messages); |
| 479 | absl::c_sort(caller_received_messages); |
| 480 | absl::c_sort(callee_received_messages); |
| 481 | EXPECT_EQ(sent_messages, caller_received_messages); |
| 482 | EXPECT_EQ(sent_messages, callee_received_messages); |
| 483 | } |
| 484 | |
Florent Castelli | d4d97eb | 2022-05-04 00:28:06 +0200 | [diff] [blame] | 485 | // Repeatedly open and close data channels on a peer connection to check that |
| 486 | // the channels are properly negotiated and SCTP stream IDs properly recycled. |
Florent Castelli | 8f04c7c | 2022-05-05 23:43:44 +0200 | [diff] [blame] | 487 | TEST_P(DataChannelIntegrationTest, StressTestOpenCloseChannelNoDelay) { |
Florent Castelli | d4d97eb | 2022-05-04 00:28:06 +0200 | [diff] [blame] | 488 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 489 | ConnectFakeSignaling(); |
| 490 | |
| 491 | int channel_id = 0; |
| 492 | const size_t kChannelCount = 8; |
| 493 | const size_t kIterations = 10; |
| 494 | bool has_negotiated = false; |
| 495 | |
| 496 | webrtc::DataChannelInit init; |
| 497 | for (size_t repeats = 0; repeats < kIterations; ++repeats) { |
| 498 | RTC_LOG(LS_INFO) << "Iteration " << (repeats + 1) << "/" << kIterations; |
| 499 | |
| 500 | for (size_t i = 0; i < kChannelCount; ++i) { |
| 501 | rtc::StringBuilder sb; |
| 502 | sb << "channel-" << channel_id++; |
| 503 | caller()->CreateDataChannel(sb.Release(), &init); |
| 504 | } |
| 505 | ASSERT_EQ(caller()->data_channels().size(), kChannelCount); |
| 506 | |
| 507 | if (!has_negotiated) { |
| 508 | caller()->CreateAndSetAndSignalOffer(); |
| 509 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 510 | has_negotiated = true; |
| 511 | } |
| 512 | |
| 513 | for (size_t i = 0; i < kChannelCount; ++i) { |
Florent Castelli | 8f04c7c | 2022-05-05 23:43:44 +0200 | [diff] [blame] | 514 | ASSERT_EQ_WAIT(caller()->data_channels()[i]->state(), |
Florent Castelli | d4d97eb | 2022-05-04 00:28:06 +0200 | [diff] [blame] | 515 | DataChannelInterface::DataState::kOpen, kDefaultTimeout); |
| 516 | RTC_LOG(LS_INFO) << "Caller Channel " |
| 517 | << caller()->data_channels()[i]->label() << " with id " |
| 518 | << caller()->data_channels()[i]->id() << " is open."; |
| 519 | } |
| 520 | ASSERT_EQ_WAIT(callee()->data_channels().size(), kChannelCount, |
| 521 | kDefaultTimeout); |
| 522 | for (size_t i = 0; i < kChannelCount; ++i) { |
Florent Castelli | 8f04c7c | 2022-05-05 23:43:44 +0200 | [diff] [blame] | 523 | ASSERT_EQ_WAIT(callee()->data_channels()[i]->state(), |
Florent Castelli | d4d97eb | 2022-05-04 00:28:06 +0200 | [diff] [blame] | 524 | DataChannelInterface::DataState::kOpen, kDefaultTimeout); |
| 525 | RTC_LOG(LS_INFO) << "Callee Channel " |
| 526 | << callee()->data_channels()[i]->label() << " with id " |
| 527 | << callee()->data_channels()[i]->id() << " is open."; |
| 528 | } |
| 529 | |
Florent Castelli | 8f04c7c | 2022-05-05 23:43:44 +0200 | [diff] [blame] | 530 | // Closing from both sides to attempt creating races. |
| 531 | // A real application would likely only close from one side. |
Florent Castelli | d4d97eb | 2022-05-04 00:28:06 +0200 | [diff] [blame] | 532 | for (size_t i = 0; i < kChannelCount; ++i) { |
Florent Castelli | 8f04c7c | 2022-05-05 23:43:44 +0200 | [diff] [blame] | 533 | if (i % 3 == 0) { |
| 534 | callee()->data_channels()[i]->Close(); |
| 535 | caller()->data_channels()[i]->Close(); |
| 536 | } else { |
| 537 | caller()->data_channels()[i]->Close(); |
| 538 | callee()->data_channels()[i]->Close(); |
| 539 | } |
Florent Castelli | d4d97eb | 2022-05-04 00:28:06 +0200 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | for (size_t i = 0; i < kChannelCount; ++i) { |
Florent Castelli | 8f04c7c | 2022-05-05 23:43:44 +0200 | [diff] [blame] | 543 | ASSERT_EQ_WAIT(caller()->data_channels()[i]->state(), |
Florent Castelli | d4d97eb | 2022-05-04 00:28:06 +0200 | [diff] [blame] | 544 | DataChannelInterface::DataState::kClosed, kDefaultTimeout); |
Florent Castelli | 8f04c7c | 2022-05-05 23:43:44 +0200 | [diff] [blame] | 545 | ASSERT_EQ_WAIT(callee()->data_channels()[i]->state(), |
| 546 | DataChannelInterface::DataState::kClosed, kDefaultTimeout); |
| 547 | } |
| 548 | |
| 549 | caller()->data_channels().clear(); |
| 550 | caller()->data_observers().clear(); |
| 551 | callee()->data_channels().clear(); |
| 552 | callee()->data_observers().clear(); |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | // Repeatedly open and close data channels on a peer connection to check that |
| 557 | // the channels are properly negotiated and SCTP stream IDs properly recycled. |
| 558 | // Some delay is added for better coverage. |
| 559 | TEST_P(DataChannelIntegrationTest, StressTestOpenCloseChannelWithDelay) { |
| 560 | // Simulate some network delay |
| 561 | virtual_socket_server()->set_delay_mean(20); |
| 562 | virtual_socket_server()->set_delay_stddev(5); |
| 563 | virtual_socket_server()->UpdateDelayDistribution(); |
| 564 | |
| 565 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 566 | ConnectFakeSignaling(); |
| 567 | |
| 568 | int channel_id = 0; |
| 569 | const size_t kChannelCount = 8; |
| 570 | const size_t kIterations = 10; |
| 571 | bool has_negotiated = false; |
| 572 | |
| 573 | webrtc::DataChannelInit init; |
| 574 | for (size_t repeats = 0; repeats < kIterations; ++repeats) { |
| 575 | RTC_LOG(LS_INFO) << "Iteration " << (repeats + 1) << "/" << kIterations; |
| 576 | |
| 577 | for (size_t i = 0; i < kChannelCount; ++i) { |
| 578 | rtc::StringBuilder sb; |
| 579 | sb << "channel-" << channel_id++; |
| 580 | caller()->CreateDataChannel(sb.Release(), &init); |
| 581 | } |
| 582 | ASSERT_EQ(caller()->data_channels().size(), kChannelCount); |
| 583 | |
| 584 | if (!has_negotiated) { |
| 585 | caller()->CreateAndSetAndSignalOffer(); |
| 586 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 587 | has_negotiated = true; |
| 588 | } |
| 589 | |
| 590 | for (size_t i = 0; i < kChannelCount; ++i) { |
| 591 | ASSERT_EQ_WAIT(caller()->data_channels()[i]->state(), |
| 592 | DataChannelInterface::DataState::kOpen, kDefaultTimeout); |
| 593 | RTC_LOG(LS_INFO) << "Caller Channel " |
| 594 | << caller()->data_channels()[i]->label() << " with id " |
| 595 | << caller()->data_channels()[i]->id() << " is open."; |
| 596 | } |
| 597 | ASSERT_EQ_WAIT(callee()->data_channels().size(), kChannelCount, |
| 598 | kDefaultTimeout); |
| 599 | for (size_t i = 0; i < kChannelCount; ++i) { |
| 600 | ASSERT_EQ_WAIT(callee()->data_channels()[i]->state(), |
| 601 | DataChannelInterface::DataState::kOpen, kDefaultTimeout); |
| 602 | RTC_LOG(LS_INFO) << "Callee Channel " |
| 603 | << callee()->data_channels()[i]->label() << " with id " |
| 604 | << callee()->data_channels()[i]->id() << " is open."; |
| 605 | } |
| 606 | |
| 607 | // Closing from both sides to attempt creating races. |
| 608 | // A real application would likely only close from one side. |
| 609 | for (size_t i = 0; i < kChannelCount; ++i) { |
| 610 | if (i % 3 == 0) { |
| 611 | callee()->data_channels()[i]->Close(); |
| 612 | caller()->data_channels()[i]->Close(); |
| 613 | } else { |
| 614 | caller()->data_channels()[i]->Close(); |
| 615 | callee()->data_channels()[i]->Close(); |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | for (size_t i = 0; i < kChannelCount; ++i) { |
| 620 | ASSERT_EQ_WAIT(caller()->data_channels()[i]->state(), |
| 621 | DataChannelInterface::DataState::kClosed, kDefaultTimeout); |
| 622 | ASSERT_EQ_WAIT(callee()->data_channels()[i]->state(), |
Florent Castelli | d4d97eb | 2022-05-04 00:28:06 +0200 | [diff] [blame] | 623 | DataChannelInterface::DataState::kClosed, kDefaultTimeout); |
| 624 | } |
| 625 | |
| 626 | caller()->data_channels().clear(); |
| 627 | caller()->data_observers().clear(); |
| 628 | callee()->data_channels().clear(); |
| 629 | callee()->data_observers().clear(); |
| 630 | } |
| 631 | } |
| 632 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 633 | // This test sets up a call between two parties with audio, and video. When |
| 634 | // audio and video are setup and flowing, an SCTP data channel is negotiated. |
| 635 | TEST_P(DataChannelIntegrationTest, AddSctpDataChannelInSubsequentOffer) { |
| 636 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 637 | ConnectFakeSignaling(); |
| 638 | // Do initial offer/answer with audio/video. |
| 639 | caller()->AddAudioVideoTracks(); |
| 640 | callee()->AddAudioVideoTracks(); |
| 641 | caller()->CreateAndSetAndSignalOffer(); |
| 642 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 643 | // Create data channel and do new offer and answer. |
| 644 | caller()->CreateDataChannel(); |
| 645 | caller()->CreateAndSetAndSignalOffer(); |
| 646 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 647 | // Caller data channel should already exist (it created one). Callee data |
| 648 | // channel may not exist yet, since negotiation happens in-band, not in SDP. |
| 649 | ASSERT_NE(nullptr, caller()->data_channel()); |
| 650 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 651 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 652 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 653 | // Ensure data can be sent in both directions. |
| 654 | std::string data = "hello world"; |
| 655 | caller()->data_channel()->Send(DataBuffer(data)); |
| 656 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 657 | kDefaultTimeout); |
| 658 | callee()->data_channel()->Send(DataBuffer(data)); |
| 659 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 660 | kDefaultTimeout); |
| 661 | } |
| 662 | |
Florent Castelli | d4d97eb | 2022-05-04 00:28:06 +0200 | [diff] [blame] | 663 | // Set up a connection initially just using SCTP data channels, later |
| 664 | // upgrading to audio/video, ensuring frames are received end-to-end. |
| 665 | // Effectively the inverse of the test above. This was broken in M57; see |
| 666 | // https://crbug.com/711243 |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 667 | TEST_P(DataChannelIntegrationTest, SctpDataChannelToAudioVideoUpgrade) { |
| 668 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 669 | ConnectFakeSignaling(); |
| 670 | // Do initial offer/answer with just data channel. |
| 671 | caller()->CreateDataChannel(); |
| 672 | caller()->CreateAndSetAndSignalOffer(); |
| 673 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 674 | // Wait until data can be sent over the data channel. |
| 675 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 676 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 677 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 678 | |
| 679 | // Do subsequent offer/answer with two-way audio and video. Audio and video |
| 680 | // should end up bundled on the DTLS/ICE transport already used for data. |
| 681 | caller()->AddAudioVideoTracks(); |
| 682 | callee()->AddAudioVideoTracks(); |
| 683 | caller()->CreateAndSetAndSignalOffer(); |
| 684 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 685 | MediaExpectations media_expectations; |
| 686 | media_expectations.ExpectBidirectionalAudioAndVideo(); |
| 687 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 688 | } |
| 689 | |
| 690 | static void MakeSpecCompliantSctpOffer(cricket::SessionDescription* desc) { |
| 691 | cricket::SctpDataContentDescription* dcd_offer = |
| 692 | GetFirstSctpDataContentDescription(desc); |
| 693 | // See https://crbug.com/webrtc/11211 - this function is a no-op |
| 694 | ASSERT_TRUE(dcd_offer); |
| 695 | dcd_offer->set_use_sctpmap(false); |
| 696 | dcd_offer->set_protocol("UDP/DTLS/SCTP"); |
| 697 | } |
| 698 | |
| 699 | // Test that the data channel works when a spec-compliant SCTP m= section is |
| 700 | // offered (using "a=sctp-port" instead of "a=sctpmap", and using |
| 701 | // "UDP/DTLS/SCTP" as the protocol). |
| 702 | TEST_P(DataChannelIntegrationTest, |
| 703 | DataChannelWorksWhenSpecCompliantSctpOfferReceived) { |
| 704 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 705 | ConnectFakeSignaling(); |
| 706 | caller()->CreateDataChannel(); |
| 707 | caller()->SetGeneratedSdpMunger(MakeSpecCompliantSctpOffer); |
| 708 | caller()->CreateAndSetAndSignalOffer(); |
| 709 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 710 | ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout); |
| 711 | EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 712 | EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 713 | |
| 714 | // Ensure data can be sent in both directions. |
| 715 | std::string data = "hello world"; |
| 716 | caller()->data_channel()->Send(DataBuffer(data)); |
| 717 | EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(), |
| 718 | kDefaultTimeout); |
| 719 | callee()->data_channel()->Send(DataBuffer(data)); |
| 720 | EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(), |
| 721 | kDefaultTimeout); |
| 722 | } |
| 723 | |
Florent Castelli | d4d97eb | 2022-05-04 00:28:06 +0200 | [diff] [blame] | 724 | // Test that after closing PeerConnections, they stop sending any packets |
| 725 | // (ICE, DTLS, RTP...). |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 726 | TEST_P(DataChannelIntegrationTest, ClosingConnectionStopsPacketFlow) { |
| 727 | // Set up audio/video/data, wait for some frames to be received. |
| 728 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 729 | ConnectFakeSignaling(); |
| 730 | caller()->AddAudioVideoTracks(); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 731 | caller()->CreateDataChannel(); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 732 | caller()->CreateAndSetAndSignalOffer(); |
| 733 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 734 | MediaExpectations media_expectations; |
| 735 | media_expectations.CalleeExpectsSomeAudioAndVideo(); |
| 736 | ASSERT_TRUE(ExpectNewFrames(media_expectations)); |
| 737 | // Close PeerConnections. |
| 738 | ClosePeerConnections(); |
| 739 | // Pump messages for a second, and ensure no new packets end up sent. |
| 740 | uint32_t sent_packets_a = virtual_socket_server()->sent_packets(); |
| 741 | WAIT(false, 1000); |
| 742 | uint32_t sent_packets_b = virtual_socket_server()->sent_packets(); |
| 743 | EXPECT_EQ(sent_packets_a, sent_packets_b); |
| 744 | } |
| 745 | |
Harald Alvestrand | 321ec3b | 2022-02-10 13:42:18 +0000 | [diff] [blame] | 746 | TEST_P(DataChannelIntegrationTest, DtlsRoleIsSetNormally) { |
| 747 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 748 | ConnectFakeSignaling(); |
| 749 | caller()->CreateDataChannel(); |
| 750 | ASSERT_FALSE(caller()->pc()->GetSctpTransport()); |
| 751 | caller()->CreateAndSetAndSignalOffer(); |
| 752 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 753 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 754 | ASSERT_TRUE(caller()->pc()->GetSctpTransport()); |
| 755 | ASSERT_TRUE( |
| 756 | caller()->pc()->GetSctpTransport()->Information().dtls_transport()); |
| 757 | EXPECT_TRUE(caller() |
| 758 | ->pc() |
| 759 | ->GetSctpTransport() |
| 760 | ->Information() |
| 761 | .dtls_transport() |
| 762 | ->Information() |
| 763 | .role()); |
| 764 | EXPECT_EQ(caller() |
| 765 | ->pc() |
| 766 | ->GetSctpTransport() |
| 767 | ->Information() |
| 768 | .dtls_transport() |
| 769 | ->Information() |
| 770 | .role(), |
| 771 | DtlsTransportTlsRole::kServer); |
| 772 | EXPECT_EQ(callee() |
| 773 | ->pc() |
| 774 | ->GetSctpTransport() |
| 775 | ->Information() |
| 776 | .dtls_transport() |
| 777 | ->Information() |
| 778 | .role(), |
| 779 | DtlsTransportTlsRole::kClient); |
Florent Castelli | d4d97eb | 2022-05-04 00:28:06 +0200 | [diff] [blame] | 780 | // ID should be assigned according to the odd/even rule based on role; |
| 781 | // client gets even numbers, server gets odd ones. RFC 8832 section 6. |
Harald Alvestrand | 321ec3b | 2022-02-10 13:42:18 +0000 | [diff] [blame] | 782 | // TODO(hta): Test multiple channels. |
| 783 | EXPECT_EQ(caller()->data_channel()->id(), 1); |
| 784 | } |
| 785 | |
| 786 | TEST_P(DataChannelIntegrationTest, DtlsRoleIsSetWhenReversed) { |
| 787 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 788 | ConnectFakeSignaling(); |
| 789 | caller()->CreateDataChannel(); |
| 790 | callee()->SetReceivedSdpMunger(MakeActiveSctpOffer); |
| 791 | caller()->CreateAndSetAndSignalOffer(); |
| 792 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 793 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 794 | EXPECT_TRUE(caller() |
| 795 | ->pc() |
| 796 | ->GetSctpTransport() |
| 797 | ->Information() |
| 798 | .dtls_transport() |
| 799 | ->Information() |
| 800 | .role()); |
| 801 | EXPECT_EQ(caller() |
| 802 | ->pc() |
| 803 | ->GetSctpTransport() |
| 804 | ->Information() |
| 805 | .dtls_transport() |
| 806 | ->Information() |
| 807 | .role(), |
| 808 | DtlsTransportTlsRole::kClient); |
| 809 | EXPECT_EQ(callee() |
| 810 | ->pc() |
| 811 | ->GetSctpTransport() |
| 812 | ->Information() |
| 813 | .dtls_transport() |
| 814 | ->Information() |
| 815 | .role(), |
| 816 | DtlsTransportTlsRole::kServer); |
Florent Castelli | d4d97eb | 2022-05-04 00:28:06 +0200 | [diff] [blame] | 817 | // ID should be assigned according to the odd/even rule based on role; |
| 818 | // client gets even numbers, server gets odd ones. RFC 8832 section 6. |
Harald Alvestrand | 321ec3b | 2022-02-10 13:42:18 +0000 | [diff] [blame] | 819 | // TODO(hta): Test multiple channels. |
| 820 | EXPECT_EQ(caller()->data_channel()->id(), 0); |
| 821 | } |
| 822 | |
Harald Alvestrand | 06c87a1 | 2022-02-11 13:12:16 +0000 | [diff] [blame] | 823 | TEST_P(DataChannelIntegrationTest, |
| 824 | DtlsRoleIsSetWhenReversedWithChannelCollision) { |
| 825 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 826 | ConnectFakeSignaling(); |
| 827 | caller()->CreateDataChannel(); |
| 828 | |
| 829 | callee()->SetReceivedSdpMunger([this](cricket::SessionDescription* desc) { |
| 830 | MakeActiveSctpOffer(desc); |
| 831 | callee()->CreateDataChannel(); |
| 832 | }); |
| 833 | caller()->CreateAndSetAndSignalOffer(); |
| 834 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 835 | ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 836 | ASSERT_EQ_WAIT(callee()->data_channels().size(), 2U, kDefaultTimeout); |
| 837 | ASSERT_EQ_WAIT(caller()->data_channels().size(), 2U, kDefaultTimeout); |
| 838 | EXPECT_TRUE(caller() |
| 839 | ->pc() |
| 840 | ->GetSctpTransport() |
| 841 | ->Information() |
| 842 | .dtls_transport() |
| 843 | ->Information() |
| 844 | .role()); |
| 845 | EXPECT_EQ(caller() |
| 846 | ->pc() |
| 847 | ->GetSctpTransport() |
| 848 | ->Information() |
| 849 | .dtls_transport() |
| 850 | ->Information() |
| 851 | .role(), |
| 852 | DtlsTransportTlsRole::kClient); |
| 853 | EXPECT_EQ(callee() |
| 854 | ->pc() |
| 855 | ->GetSctpTransport() |
| 856 | ->Information() |
| 857 | .dtls_transport() |
| 858 | ->Information() |
| 859 | .role(), |
| 860 | DtlsTransportTlsRole::kServer); |
Florent Castelli | d4d97eb | 2022-05-04 00:28:06 +0200 | [diff] [blame] | 861 | // ID should be assigned according to the odd/even rule based on role; |
| 862 | // client gets even numbers, server gets odd ones. RFC 8832 section 6. |
Harald Alvestrand | 06c87a1 | 2022-02-11 13:12:16 +0000 | [diff] [blame] | 863 | ASSERT_EQ(caller()->data_channels().size(), 2U); |
| 864 | ASSERT_EQ(callee()->data_channels().size(), 2U); |
| 865 | EXPECT_EQ(caller()->data_channels()[0]->id(), 0); |
| 866 | EXPECT_EQ(caller()->data_channels()[1]->id(), 1); |
| 867 | EXPECT_EQ(callee()->data_channels()[0]->id(), 1); |
| 868 | EXPECT_EQ(callee()->data_channels()[1]->id(), 0); |
| 869 | } |
| 870 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 871 | // Test that transport stats are generated by the RTCStatsCollector for a |
| 872 | // connection that only involves data channels. This is a regression test for |
| 873 | // crbug.com/826972. |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 874 | TEST_P(DataChannelIntegrationTest, |
| 875 | TransportStatsReportedForDataChannelOnlyConnection) { |
| 876 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 877 | ConnectFakeSignaling(); |
| 878 | caller()->CreateDataChannel(); |
| 879 | |
| 880 | caller()->CreateAndSetAndSignalOffer(); |
| 881 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 882 | ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout); |
| 883 | |
| 884 | auto caller_report = caller()->NewGetStats(); |
| 885 | EXPECT_EQ(1u, caller_report->GetStatsOfType<RTCTransportStats>().size()); |
| 886 | auto callee_report = callee()->NewGetStats(); |
| 887 | EXPECT_EQ(1u, callee_report->GetStatsOfType<RTCTransportStats>().size()); |
| 888 | } |
| 889 | |
Harald Alvestrand | feb6eb9 | 2021-04-21 18:52:32 +0000 | [diff] [blame] | 890 | TEST_P(DataChannelIntegrationTest, QueuedPacketsGetDeliveredInReliableMode) { |
| 891 | CreatePeerConnectionWrappers(); |
| 892 | ConnectFakeSignaling(); |
| 893 | caller()->CreateDataChannel(); |
| 894 | caller()->CreateAndSetAndSignalOffer(); |
| 895 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 896 | ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout); |
| 897 | |
| 898 | caller()->data_channel()->Send(DataBuffer("hello first")); |
| 899 | ASSERT_EQ_WAIT(1u, callee()->data_observer()->received_message_count(), |
| 900 | kDefaultTimeout); |
| 901 | // Cause a temporary network outage |
| 902 | virtual_socket_server()->set_drop_probability(1.0); |
| 903 | for (int i = 1; i <= 10; i++) { |
| 904 | caller()->data_channel()->Send(DataBuffer("Sent while blocked")); |
| 905 | } |
| 906 | // Nothing should be delivered during outage. Short wait. |
| 907 | EXPECT_EQ_WAIT(1u, callee()->data_observer()->received_message_count(), 10); |
| 908 | // Reverse outage |
| 909 | virtual_socket_server()->set_drop_probability(0.0); |
| 910 | // All packets should be delivered. |
| 911 | EXPECT_EQ_WAIT(11u, callee()->data_observer()->received_message_count(), |
| 912 | kDefaultTimeout); |
| 913 | } |
| 914 | |
Harald Alvestrand | 86bd92f | 2021-05-19 16:17:04 +0000 | [diff] [blame] | 915 | TEST_P(DataChannelIntegrationTest, QueuedPacketsGetDroppedInUnreliableMode) { |
Harald Alvestrand | feb6eb9 | 2021-04-21 18:52:32 +0000 | [diff] [blame] | 916 | CreatePeerConnectionWrappers(); |
| 917 | ConnectFakeSignaling(); |
| 918 | DataChannelInit init; |
| 919 | init.maxRetransmits = 0; |
| 920 | init.ordered = false; |
| 921 | caller()->CreateDataChannel(&init); |
| 922 | caller()->CreateAndSetAndSignalOffer(); |
| 923 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 924 | ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout); |
| 925 | caller()->data_channel()->Send(DataBuffer("hello first")); |
| 926 | ASSERT_EQ_WAIT(1u, callee()->data_observer()->received_message_count(), |
| 927 | kDefaultTimeout); |
| 928 | // Cause a temporary network outage |
| 929 | virtual_socket_server()->set_drop_probability(1.0); |
Harald Alvestrand | 86bd92f | 2021-05-19 16:17:04 +0000 | [diff] [blame] | 930 | // Send a few packets. Note that all get dropped only when all packets |
| 931 | // fit into the receiver receive window/congestion window, so that they |
| 932 | // actually get sent. |
Harald Alvestrand | feb6eb9 | 2021-04-21 18:52:32 +0000 | [diff] [blame] | 933 | for (int i = 1; i <= 10; i++) { |
| 934 | caller()->data_channel()->Send(DataBuffer("Sent while blocked")); |
| 935 | } |
| 936 | // Nothing should be delivered during outage. |
| 937 | // We do a short wait to verify that delivery count is still 1. |
| 938 | WAIT(false, 10); |
| 939 | EXPECT_EQ(1u, callee()->data_observer()->received_message_count()); |
| 940 | // Reverse the network outage. |
| 941 | virtual_socket_server()->set_drop_probability(0.0); |
| 942 | // Send a new packet, and wait for it to be delivered. |
| 943 | caller()->data_channel()->Send(DataBuffer("After block")); |
| 944 | EXPECT_EQ_WAIT("After block", callee()->data_observer()->last_message(), |
| 945 | kDefaultTimeout); |
| 946 | // Some messages should be lost, but first and last message should have |
| 947 | // been delivered. |
| 948 | // First, check that the protocol guarantee is preserved. |
| 949 | EXPECT_GT(11u, callee()->data_observer()->received_message_count()); |
| 950 | EXPECT_LE(2u, callee()->data_observer()->received_message_count()); |
| 951 | // Then, check that observed behavior (lose all messages) has not changed |
| 952 | EXPECT_EQ(2u, callee()->data_observer()->received_message_count()); |
| 953 | } |
| 954 | |
Harald Alvestrand | 86bd92f | 2021-05-19 16:17:04 +0000 | [diff] [blame] | 955 | TEST_P(DataChannelIntegrationTest, |
| 956 | QueuedPacketsGetDroppedInLifetimeLimitedMode) { |
| 957 | CreatePeerConnectionWrappers(); |
| 958 | ConnectFakeSignaling(); |
| 959 | DataChannelInit init; |
| 960 | init.maxRetransmitTime = 1; |
| 961 | init.ordered = false; |
| 962 | caller()->CreateDataChannel(&init); |
| 963 | caller()->CreateAndSetAndSignalOffer(); |
| 964 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 965 | ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout); |
| 966 | caller()->data_channel()->Send(DataBuffer("hello first")); |
| 967 | ASSERT_EQ_WAIT(1u, callee()->data_observer()->received_message_count(), |
| 968 | kDefaultTimeout); |
| 969 | // Cause a temporary network outage |
| 970 | virtual_socket_server()->set_drop_probability(1.0); |
| 971 | for (int i = 1; i <= 200; i++) { |
| 972 | caller()->data_channel()->Send(DataBuffer("Sent while blocked")); |
| 973 | } |
| 974 | // Nothing should be delivered during outage. |
| 975 | // We do a short wait to verify that delivery count is still 1, |
| 976 | // and to make sure max packet lifetime (which is in ms) is exceeded. |
| 977 | WAIT(false, 10); |
| 978 | EXPECT_EQ(1u, callee()->data_observer()->received_message_count()); |
| 979 | // Reverse the network outage. |
| 980 | virtual_socket_server()->set_drop_probability(0.0); |
| 981 | // Send a new packet, and wait for it to be delivered. |
| 982 | caller()->data_channel()->Send(DataBuffer("After block")); |
| 983 | EXPECT_EQ_WAIT("After block", callee()->data_observer()->last_message(), |
| 984 | kDefaultTimeout); |
| 985 | // Some messages should be lost, but first and last message should have |
| 986 | // been delivered. |
| 987 | // First, check that the protocol guarantee is preserved. |
| 988 | EXPECT_GT(202u, callee()->data_observer()->received_message_count()); |
| 989 | EXPECT_LE(2u, callee()->data_observer()->received_message_count()); |
| 990 | // Then, check that observed behavior (lose some messages) has not changed |
Florent Castelli | f2599a7 | 2022-03-31 19:15:10 +0200 | [diff] [blame] | 991 | // DcSctp loses all messages. This is correct. |
| 992 | EXPECT_EQ(2u, callee()->data_observer()->received_message_count()); |
Harald Alvestrand | 86bd92f | 2021-05-19 16:17:04 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | TEST_P(DataChannelIntegrationTest, |
Victor Boivie | fe968df | 2022-02-01 11:26:05 +0100 | [diff] [blame] | 996 | DISABLED_ON_ANDROID(SomeQueuedPacketsGetDroppedInMaxRetransmitsMode)) { |
Harald Alvestrand | 86bd92f | 2021-05-19 16:17:04 +0000 | [diff] [blame] | 997 | CreatePeerConnectionWrappers(); |
| 998 | ConnectFakeSignaling(); |
| 999 | DataChannelInit init; |
| 1000 | init.maxRetransmits = 0; |
| 1001 | init.ordered = false; |
| 1002 | caller()->CreateDataChannel(&init); |
| 1003 | caller()->CreateAndSetAndSignalOffer(); |
| 1004 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1005 | ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout); |
| 1006 | caller()->data_channel()->Send(DataBuffer("hello first")); |
| 1007 | ASSERT_EQ_WAIT(1u, callee()->data_observer()->received_message_count(), |
| 1008 | kDefaultTimeout); |
| 1009 | // Cause a temporary network outage |
| 1010 | virtual_socket_server()->set_drop_probability(1.0); |
| 1011 | // Fill the buffer until queued data starts to build |
| 1012 | size_t packet_counter = 0; |
| 1013 | while (caller()->data_channel()->buffered_amount() < 1 && |
| 1014 | packet_counter < 10000) { |
| 1015 | packet_counter++; |
| 1016 | caller()->data_channel()->Send(DataBuffer("Sent while blocked")); |
| 1017 | } |
| 1018 | if (caller()->data_channel()->buffered_amount()) { |
| 1019 | RTC_LOG(LS_INFO) << "Buffered data after " << packet_counter << " packets"; |
| 1020 | } else { |
| 1021 | RTC_LOG(LS_INFO) << "No buffered data after " << packet_counter |
| 1022 | << " packets"; |
| 1023 | } |
| 1024 | // Nothing should be delivered during outage. |
| 1025 | // We do a short wait to verify that delivery count is still 1. |
| 1026 | WAIT(false, 10); |
| 1027 | EXPECT_EQ(1u, callee()->data_observer()->received_message_count()); |
| 1028 | // Reverse the network outage. |
| 1029 | virtual_socket_server()->set_drop_probability(0.0); |
| 1030 | // Send a new packet, and wait for it to be delivered. |
| 1031 | caller()->data_channel()->Send(DataBuffer("After block")); |
| 1032 | EXPECT_EQ_WAIT("After block", callee()->data_observer()->last_message(), |
| 1033 | kDefaultTimeout); |
| 1034 | // Some messages should be lost, but first and last message should have |
| 1035 | // been delivered. |
| 1036 | // Due to the fact that retransmissions are only counted when the packet |
| 1037 | // goes on the wire, NOT when they are stalled in queue due to |
| 1038 | // congestion, we expect some of the packets to be delivered, because |
| 1039 | // congestion prevented them from being sent. |
| 1040 | // Citation: https://tools.ietf.org/html/rfc7496#section-3.1 |
| 1041 | |
| 1042 | // First, check that the protocol guarantee is preserved. |
| 1043 | EXPECT_GT(packet_counter, |
| 1044 | callee()->data_observer()->received_message_count()); |
| 1045 | EXPECT_LE(2u, callee()->data_observer()->received_message_count()); |
| 1046 | // Then, check that observed behavior (lose between 100 and 200 messages) |
| 1047 | // has not changed. |
| 1048 | // Usrsctp behavior is different on Android (177) and other platforms (122). |
| 1049 | // Dcsctp loses 432 packets. |
| 1050 | EXPECT_GT(2 + packet_counter - 100, |
| 1051 | callee()->data_observer()->received_message_count()); |
| 1052 | EXPECT_LT(2 + packet_counter - 500, |
| 1053 | callee()->data_observer()->received_message_count()); |
| 1054 | } |
| 1055 | |
Florent Castelli | f2599a7 | 2022-03-31 19:15:10 +0200 | [diff] [blame] | 1056 | INSTANTIATE_TEST_SUITE_P(DataChannelIntegrationTest, |
| 1057 | DataChannelIntegrationTest, |
Florent Castelli | 15a38de | 2022-04-06 00:38:21 +0200 | [diff] [blame] | 1058 | Values(SdpSemantics::kPlanB_DEPRECATED, |
Florent Castelli | f2599a7 | 2022-03-31 19:15:10 +0200 | [diff] [blame] | 1059 | SdpSemantics::kUnifiedPlan)); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 1060 | |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 1061 | TEST_F(DataChannelIntegrationTestUnifiedPlan, |
| 1062 | EndToEndCallWithBundledSctpDataChannel) { |
| 1063 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1064 | ConnectFakeSignaling(); |
| 1065 | caller()->CreateDataChannel(); |
| 1066 | caller()->AddAudioVideoTracks(); |
| 1067 | callee()->AddAudioVideoTracks(); |
| 1068 | caller()->CreateAndSetAndSignalOffer(); |
| 1069 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
Harald Alvestrand | 7af57c6 | 2021-04-16 11:12:14 +0000 | [diff] [blame] | 1070 | ASSERT_TRUE_WAIT(caller()->pc()->GetSctpTransport(), kDefaultTimeout); |
| 1071 | ASSERT_EQ_WAIT(SctpTransportState::kConnected, |
| 1072 | caller()->pc()->GetSctpTransport()->Information().state(), |
| 1073 | kDefaultTimeout); |
Harald Alvestrand | 3999384 | 2021-02-17 09:05:31 +0000 | [diff] [blame] | 1074 | ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout); |
| 1075 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 1076 | } |
| 1077 | |
| 1078 | TEST_F(DataChannelIntegrationTestUnifiedPlan, |
| 1079 | EndToEndCallWithDataChannelOnlyConnects) { |
| 1080 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1081 | ConnectFakeSignaling(); |
| 1082 | caller()->CreateDataChannel(); |
| 1083 | caller()->CreateAndSetAndSignalOffer(); |
| 1084 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1085 | ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout); |
| 1086 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 1087 | ASSERT_TRUE(caller()->data_observer()->IsOpen()); |
| 1088 | } |
| 1089 | |
| 1090 | TEST_F(DataChannelIntegrationTestUnifiedPlan, DataChannelClosesWhenClosed) { |
| 1091 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1092 | ConnectFakeSignaling(); |
| 1093 | caller()->CreateDataChannel(); |
| 1094 | caller()->CreateAndSetAndSignalOffer(); |
| 1095 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1096 | ASSERT_TRUE_WAIT(callee()->data_observer(), kDefaultTimeout); |
| 1097 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 1098 | caller()->data_channel()->Close(); |
| 1099 | ASSERT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 1100 | } |
| 1101 | |
| 1102 | TEST_F(DataChannelIntegrationTestUnifiedPlan, |
| 1103 | DataChannelClosesWhenClosedReverse) { |
| 1104 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1105 | ConnectFakeSignaling(); |
| 1106 | caller()->CreateDataChannel(); |
| 1107 | caller()->CreateAndSetAndSignalOffer(); |
| 1108 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1109 | ASSERT_TRUE_WAIT(callee()->data_observer(), kDefaultTimeout); |
| 1110 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 1111 | callee()->data_channel()->Close(); |
| 1112 | ASSERT_TRUE_WAIT(!caller()->data_observer()->IsOpen(), kDefaultTimeout); |
| 1113 | } |
| 1114 | |
| 1115 | TEST_F(DataChannelIntegrationTestUnifiedPlan, |
| 1116 | DataChannelClosesWhenPeerConnectionClosed) { |
| 1117 | ASSERT_TRUE(CreatePeerConnectionWrappers()); |
| 1118 | ConnectFakeSignaling(); |
| 1119 | caller()->CreateDataChannel(); |
| 1120 | caller()->CreateAndSetAndSignalOffer(); |
| 1121 | ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout); |
| 1122 | ASSERT_TRUE_WAIT(callee()->data_observer(), kDefaultTimeout); |
| 1123 | ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 1124 | caller()->pc()->Close(); |
| 1125 | ASSERT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout); |
| 1126 | } |
| 1127 | |
| 1128 | #endif // WEBRTC_HAVE_SCTP |
| 1129 | |
| 1130 | } // namespace |
| 1131 | |
| 1132 | } // namespace webrtc |