OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "webrtc/api/peerconnection.h" | 24 #include "webrtc/api/peerconnection.h" |
25 #include "webrtc/api/peerconnectionfactory.h" | 25 #include "webrtc/api/peerconnectionfactory.h" |
26 #include "webrtc/api/peerconnectioninterface.h" | 26 #include "webrtc/api/peerconnectioninterface.h" |
27 #include "webrtc/api/test/fakeaudiocapturemodule.h" | 27 #include "webrtc/api/test/fakeaudiocapturemodule.h" |
28 #include "webrtc/api/test/fakeconstraints.h" | 28 #include "webrtc/api/test/fakeconstraints.h" |
29 #include "webrtc/api/test/fakeperiodicvideocapturer.h" | 29 #include "webrtc/api/test/fakeperiodicvideocapturer.h" |
30 #include "webrtc/api/test/fakertccertificategenerator.h" | 30 #include "webrtc/api/test/fakertccertificategenerator.h" |
31 #include "webrtc/api/test/fakevideotrackrenderer.h" | 31 #include "webrtc/api/test/fakevideotrackrenderer.h" |
32 #include "webrtc/api/test/mockpeerconnectionobservers.h" | 32 #include "webrtc/api/test/mockpeerconnectionobservers.h" |
33 #include "webrtc/base/gunit.h" | 33 #include "webrtc/base/gunit.h" |
| 34 #include "webrtc/base/helpers.h" |
34 #include "webrtc/base/physicalsocketserver.h" | 35 #include "webrtc/base/physicalsocketserver.h" |
35 #include "webrtc/base/ssladapter.h" | 36 #include "webrtc/base/ssladapter.h" |
36 #include "webrtc/base/sslstreamadapter.h" | 37 #include "webrtc/base/sslstreamadapter.h" |
37 #include "webrtc/base/thread.h" | 38 #include "webrtc/base/thread.h" |
38 #include "webrtc/base/virtualsocketserver.h" | 39 #include "webrtc/base/virtualsocketserver.h" |
39 #include "webrtc/media/engine/fakewebrtcvideoengine.h" | 40 #include "webrtc/media/engine/fakewebrtcvideoengine.h" |
40 #include "webrtc/p2p/base/fakeportallocator.h" | 41 #include "webrtc/p2p/base/fakeportallocator.h" |
41 #include "webrtc/p2p/base/p2pconstants.h" | 42 #include "webrtc/p2p/base/p2pconstants.h" |
42 #include "webrtc/p2p/base/sessiondescription.h" | 43 #include "webrtc/p2p/base/sessiondescription.h" |
43 #include "webrtc/pc/mediasession.h" | 44 #include "webrtc/pc/mediasession.h" |
(...skipping 1286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1330 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { | 1331 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { |
1331 // Messages may get lost on the unreliable DataChannel, so we send multiple | 1332 // Messages may get lost on the unreliable DataChannel, so we send multiple |
1332 // times to avoid test flakiness. | 1333 // times to avoid test flakiness. |
1333 static const size_t kSendAttempts = 5; | 1334 static const size_t kSendAttempts = 5; |
1334 | 1335 |
1335 for (size_t i = 0; i < kSendAttempts; ++i) { | 1336 for (size_t i = 0; i < kSendAttempts; ++i) { |
1336 dc->Send(DataBuffer(data)); | 1337 dc->Send(DataBuffer(data)); |
1337 } | 1338 } |
1338 } | 1339 } |
1339 | 1340 |
| 1341 rtc::VirtualSocketServer* virtual_socket_server() { return ss_.get(); } |
| 1342 |
1340 PeerConnectionTestClient* initializing_client() { | 1343 PeerConnectionTestClient* initializing_client() { |
1341 return initiating_client_.get(); | 1344 return initiating_client_.get(); |
1342 } | 1345 } |
1343 | 1346 |
1344 // Set the |initiating_client_| to the |client| passed in and return the | 1347 // Set the |initiating_client_| to the |client| passed in and return the |
1345 // original |initiating_client_|. | 1348 // original |initiating_client_|. |
1346 PeerConnectionTestClient* set_initializing_client( | 1349 PeerConnectionTestClient* set_initializing_client( |
1347 PeerConnectionTestClient* client) { | 1350 PeerConnectionTestClient* client) { |
1348 PeerConnectionTestClient* old = initiating_client_.release(); | 1351 PeerConnectionTestClient* old = initiating_client_.release(); |
1349 initiating_client_.reset(client); | 1352 initiating_client_.reset(client); |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1922 receiving_client()->data_channel()->Send(DataBuffer(data)); | 1925 receiving_client()->data_channel()->Send(DataBuffer(data)); |
1923 EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(), | 1926 EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(), |
1924 kMaxWaitMs); | 1927 kMaxWaitMs); |
1925 | 1928 |
1926 receiving_client()->data_channel()->Close(); | 1929 receiving_client()->data_channel()->Close(); |
1927 EXPECT_TRUE_WAIT(!initializing_client()->data_observer()->IsOpen(), | 1930 EXPECT_TRUE_WAIT(!initializing_client()->data_observer()->IsOpen(), |
1928 kMaxWaitMs); | 1931 kMaxWaitMs); |
1929 EXPECT_TRUE_WAIT(!receiving_client()->data_observer()->IsOpen(), kMaxWaitMs); | 1932 EXPECT_TRUE_WAIT(!receiving_client()->data_observer()->IsOpen(), kMaxWaitMs); |
1930 } | 1933 } |
1931 | 1934 |
| 1935 TEST_F(P2PTestConductor, UnorderedSctpDataChannel) { |
| 1936 ASSERT_TRUE(CreateTestClients()); |
| 1937 webrtc::DataChannelInit init; |
| 1938 init.ordered = false; |
| 1939 initializing_client()->CreateDataChannel(&init); |
| 1940 |
| 1941 // Introduce random network delays. |
| 1942 // Otherwise it's not a true "unordered" test. |
| 1943 virtual_socket_server()->set_delay_mean(20); |
| 1944 virtual_socket_server()->set_delay_stddev(5); |
| 1945 virtual_socket_server()->UpdateDelayDistribution(); |
| 1946 |
| 1947 initializing_client()->Negotiate(); |
| 1948 ASSERT_TRUE(initializing_client()->data_channel() != nullptr); |
| 1949 EXPECT_TRUE_WAIT(receiving_client()->data_channel() != nullptr, kMaxWaitMs); |
| 1950 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), |
| 1951 kMaxWaitMs); |
| 1952 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), kMaxWaitMs); |
| 1953 |
| 1954 static constexpr int kNumMessages = 100; |
| 1955 // Deliberately chosen to be larger than the MTU so messages get fragmented. |
| 1956 static constexpr size_t kMaxMessageSize = 4096; |
| 1957 // Create and send random messages. |
| 1958 std::vector<std::string> sent_messages; |
| 1959 for (int i = 0; i < kNumMessages; ++i) { |
| 1960 size_t length = (rand() % kMaxMessageSize) + 1; |
| 1961 std::string message; |
| 1962 ASSERT_TRUE(rtc::CreateRandomString(length, &message)); |
| 1963 initializing_client()->data_channel()->Send(DataBuffer(message)); |
| 1964 receiving_client()->data_channel()->Send(DataBuffer(message)); |
| 1965 sent_messages.push_back(message); |
| 1966 } |
| 1967 |
| 1968 EXPECT_EQ_WAIT( |
| 1969 kNumMessages, |
| 1970 initializing_client()->data_observer()->received_message_count(), |
| 1971 kMaxWaitMs); |
| 1972 EXPECT_EQ_WAIT(kNumMessages, |
| 1973 receiving_client()->data_observer()->received_message_count(), |
| 1974 kMaxWaitMs); |
| 1975 |
| 1976 // Sort and compare to make sure none of the messages were corrupted. |
| 1977 std::vector<std::string> initializing_client_received_messages = |
| 1978 initializing_client()->data_observer()->messages(); |
| 1979 std::vector<std::string> receiving_client_received_messages = |
| 1980 receiving_client()->data_observer()->messages(); |
| 1981 std::sort(sent_messages.begin(), sent_messages.end()); |
| 1982 std::sort(initializing_client_received_messages.begin(), |
| 1983 initializing_client_received_messages.end()); |
| 1984 std::sort(receiving_client_received_messages.begin(), |
| 1985 receiving_client_received_messages.end()); |
| 1986 EXPECT_EQ(sent_messages, initializing_client_received_messages); |
| 1987 EXPECT_EQ(sent_messages, receiving_client_received_messages); |
| 1988 |
| 1989 receiving_client()->data_channel()->Close(); |
| 1990 EXPECT_TRUE_WAIT(!initializing_client()->data_observer()->IsOpen(), |
| 1991 kMaxWaitMs); |
| 1992 EXPECT_TRUE_WAIT(!receiving_client()->data_observer()->IsOpen(), kMaxWaitMs); |
| 1993 } |
| 1994 |
1932 // This test sets up a call between two parties and creates a data channel. | 1995 // This test sets up a call between two parties and creates a data channel. |
1933 // The test tests that received data is buffered unless an observer has been | 1996 // The test tests that received data is buffered unless an observer has been |
1934 // registered. | 1997 // registered. |
1935 // Rtp data channels can receive data before the underlying | 1998 // Rtp data channels can receive data before the underlying |
1936 // transport has detected that a channel is writable and thus data can be | 1999 // transport has detected that a channel is writable and thus data can be |
1937 // received before the data channel state changes to open. That is hard to test | 2000 // received before the data channel state changes to open. That is hard to test |
1938 // but the same buffering is used in that case. | 2001 // but the same buffering is used in that case. |
1939 TEST_F(P2PTestConductor, RegisterDataChannelObserver) { | 2002 TEST_F(P2PTestConductor, RegisterDataChannelObserver) { |
1940 FakeConstraints setup_constraints; | 2003 FakeConstraints setup_constraints; |
1941 setup_constraints.SetAllowRtpDataChannels(); | 2004 setup_constraints.SetAllowRtpDataChannels(); |
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2417 server.urls.push_back("turn:hostname2"); | 2480 server.urls.push_back("turn:hostname2"); |
2418 servers.push_back(server); | 2481 servers.push_back(server); |
2419 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); | 2482 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); |
2420 EXPECT_EQ(2U, turn_servers_.size()); | 2483 EXPECT_EQ(2U, turn_servers_.size()); |
2421 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); | 2484 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); |
2422 } | 2485 } |
2423 | 2486 |
2424 #endif // if !defined(THREAD_SANITIZER) | 2487 #endif // if !defined(THREAD_SANITIZER) |
2425 | 2488 |
2426 } // namespace | 2489 } // namespace |
OLD | NEW |