Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: webrtc/p2p/base/dtlstransportchannel_unittest.cc

Issue 2606123002: Remove the dependency of TransportChannel and TransportChannelImpl. (Closed)
Patch Set: Revert the change of stun_unittests Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2011 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 ASSERT(certificate_); 81 ASSERT(certificate_);
82 use_dtls_srtp_ = true; 82 use_dtls_srtp_ = true;
83 } 83 }
84 void SetupMaxProtocolVersion(rtc::SSLProtocolVersion version) { 84 void SetupMaxProtocolVersion(rtc::SSLProtocolVersion version) {
85 ssl_max_version_ = version; 85 ssl_max_version_ = version;
86 } 86 }
87 void SetupChannels(int count, cricket::IceRole role, int async_delay_ms = 0) { 87 void SetupChannels(int count, cricket::IceRole role, int async_delay_ms = 0) {
88 transport_.reset( 88 transport_.reset(
89 new cricket::JsepTransport("dtls content name", certificate_)); 89 new cricket::JsepTransport("dtls content name", certificate_));
90 for (int i = 0; i < count; ++i) { 90 for (int i = 0; i < count; ++i) {
91 cricket::FakeTransportChannel* fake_ice_channel = 91 cricket::FakeIceTransport* fake_ice_channel =
92 new cricket::FakeTransportChannel(transport_->mid(), i); 92 new cricket::FakeIceTransport(transport_->mid(), i);
93 fake_ice_channel->SetAsync(true); 93 fake_ice_channel->SetAsync(true);
94 fake_ice_channel->SetAsyncDelay(async_delay_ms); 94 fake_ice_channel->SetAsyncDelay(async_delay_ms);
95 // Hook the raw packets so that we can verify they are encrypted. 95 // Hook the raw packets so that we can verify they are encrypted.
96 fake_ice_channel->SignalReadPacket.connect( 96 fake_ice_channel->SignalReadPacket.connect(
97 this, &DtlsTestClient::OnFakeTransportChannelReadPacket); 97 this, &DtlsTestClient::OnFakeTransportChannelReadPacket);
98 98
99 cricket::DtlsTransportChannelWrapper* channel = 99 cricket::DtlsTransportChannelWrapper* channel =
100 new cricket::DtlsTransportChannelWrapper(fake_ice_channel); 100 new cricket::DtlsTransportChannelWrapper(fake_ice_channel);
101 channel->SetLocalCertificate(certificate_); 101 channel->SetLocalCertificate(certificate_);
102 channel->SetIceRole(role); 102 channel->ice_transport()->SetIceRole(role);
103 channel->SetIceTiebreaker((role == cricket::ICEROLE_CONTROLLING) ? 1 : 2); 103 channel->ice_transport()->SetIceTiebreaker(
104 (role == cricket::ICEROLE_CONTROLLING) ? 1 : 2);
104 channel->SetSslMaxProtocolVersion(ssl_max_version_); 105 channel->SetSslMaxProtocolVersion(ssl_max_version_);
105 channel->SignalWritableState.connect(this, 106 channel->SignalWritableState.connect(this,
106 &DtlsTestClient::OnTransportChannelWritableState); 107 &DtlsTestClient::OnTransportChannelWritableState);
107 channel->SignalReadPacket.connect(this, 108 channel->SignalReadPacket.connect(this,
108 &DtlsTestClient::OnTransportChannelReadPacket); 109 &DtlsTestClient::OnTransportChannelReadPacket);
109 channel->SignalSentPacket.connect( 110 channel->SignalSentPacket.connect(
110 this, &DtlsTestClient::OnTransportChannelSentPacket); 111 this, &DtlsTestClient::OnTransportChannelSentPacket);
111 channels_.push_back( 112 channels_.push_back(
112 std::unique_ptr<cricket::DtlsTransportChannelWrapper>(channel)); 113 std::unique_ptr<cricket::DtlsTransportChannelWrapper>(channel));
113 fake_channels_.push_back( 114 fake_channels_.push_back(
114 std::unique_ptr<cricket::FakeTransportChannel>(fake_ice_channel)); 115 std::unique_ptr<cricket::FakeIceTransport>(fake_ice_channel));
115 transport_->AddChannel(channel, i); 116 transport_->AddChannel(channel, i);
116 } 117 }
117 } 118 }
118 119
119 cricket::JsepTransport* transport() { return transport_.get(); } 120 cricket::JsepTransport* transport() { return transport_.get(); }
120 121
121 cricket::FakeTransportChannel* GetFakeChannel(int component) { 122 cricket::FakeIceTransport* GetFakeChannel(int component) {
122 for (const auto& ch : fake_channels_) { 123 for (const auto& ch : fake_channels_) {
123 if (ch->component() == component) { 124 if (ch->component() == component) {
124 return ch.get(); 125 return ch.get();
125 } 126 }
126 } 127 }
127 return nullptr; 128 return nullptr;
128 } 129 }
129 130
130 cricket::DtlsTransportChannelWrapper* GetDtlsChannel(int component) { 131 cricket::DtlsTransportChannelWrapper* GetDtlsChannel(int component) {
131 for (const auto& ch : channels_) { 132 for (const auto& ch : channels_) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 return false; 225 return false;
225 } 226 }
226 for (const auto& channel : channels_) { 227 for (const auto& channel : channels_) {
227 if (!channel->writable()) { 228 if (!channel->writable()) {
228 return false; 229 return false;
229 } 230 }
230 } 231 }
231 return true; 232 return true;
232 } 233 }
233 234
234 bool all_raw_channels_writable() const { 235 bool all_ice_transport_writable() const {
235 if (channels_.empty()) { 236 if (channels_.empty()) {
236 return false; 237 return false;
237 } 238 }
238 for (const auto& channel : channels_) { 239 for (const auto& channel : channels_) {
239 if (!channel->channel()->writable()) { 240 if (!channel->ice_transport()->writable()) {
240 return false; 241 return false;
241 } 242 }
242 } 243 }
243 return true; 244 return true;
244 } 245 }
245 246
246 int received_dtls_client_hellos() const { 247 int received_dtls_client_hellos() const {
247 return received_dtls_client_hellos_; 248 return received_dtls_client_hellos_;
248 } 249 }
249 250
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 ASSERT_TRUE(VerifyEncryptedPacket(data, size)); 428 ASSERT_TRUE(VerifyEncryptedPacket(data, size));
428 } else if (IsRtpLeadByte(data[0])) { 429 } else if (IsRtpLeadByte(data[0])) {
429 ASSERT_TRUE(VerifyPacket(data, size, NULL)); 430 ASSERT_TRUE(VerifyPacket(data, size, NULL));
430 } 431 }
431 } 432 }
432 } 433 }
433 434
434 private: 435 private:
435 std::string name_; 436 std::string name_;
436 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; 437 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
437 std::vector<std::unique_ptr<cricket::FakeTransportChannel>> fake_channels_; 438 std::vector<std::unique_ptr<cricket::FakeIceTransport>> fake_channels_;
438 std::vector<std::unique_ptr<cricket::DtlsTransportChannelWrapper>> channels_; 439 std::vector<std::unique_ptr<cricket::DtlsTransportChannelWrapper>> channels_;
439 std::unique_ptr<cricket::JsepTransport> transport_; 440 std::unique_ptr<cricket::JsepTransport> transport_;
440 size_t packet_size_ = 0u; 441 size_t packet_size_ = 0u;
441 std::set<int> received_; 442 std::set<int> received_;
442 bool use_dtls_srtp_ = false; 443 bool use_dtls_srtp_ = false;
443 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; 444 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12;
444 int received_dtls_client_hellos_ = 0; 445 int received_dtls_client_hellos_ = 0;
445 int received_dtls_server_hellos_ = 0; 446 int received_dtls_server_hellos_ = 0;
446 rtc::SentPacket sent_packet_; 447 rtc::SentPacket sent_packet_;
447 }; 448 };
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 bool use_dtls_srtp_; 633 bool use_dtls_srtp_;
633 rtc::SSLProtocolVersion ssl_expected_version_; 634 rtc::SSLProtocolVersion ssl_expected_version_;
634 }; 635 };
635 636
636 class DtlsTransportChannelTest : public DtlsTransportChannelTestBase, 637 class DtlsTransportChannelTest : public DtlsTransportChannelTestBase,
637 public ::testing::Test {}; 638 public ::testing::Test {};
638 639
639 // Test that transport negotiation of ICE, no DTLS works properly. 640 // Test that transport negotiation of ICE, no DTLS works properly.
640 TEST_F(DtlsTransportChannelTest, TestChannelSetupIce) { 641 TEST_F(DtlsTransportChannelTest, TestChannelSetupIce) {
641 Negotiate(); 642 Negotiate();
642 cricket::FakeTransportChannel* channel1 = client1_.GetFakeChannel(0); 643 cricket::FakeIceTransport* channel1 = client1_.GetFakeChannel(0);
643 cricket::FakeTransportChannel* channel2 = client2_.GetFakeChannel(0); 644 cricket::FakeIceTransport* channel2 = client2_.GetFakeChannel(0);
644 ASSERT_TRUE(channel1 != NULL); 645 ASSERT_TRUE(channel1 != NULL);
645 ASSERT_TRUE(channel2 != NULL); 646 ASSERT_TRUE(channel2 != NULL);
646 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole()); 647 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole());
647 EXPECT_EQ(1U, channel1->IceTiebreaker()); 648 EXPECT_EQ(1U, channel1->IceTiebreaker());
648 EXPECT_EQ(kIceUfrag1, channel1->ice_ufrag()); 649 EXPECT_EQ(kIceUfrag1, channel1->ice_ufrag());
649 EXPECT_EQ(kIcePwd1, channel1->ice_pwd()); 650 EXPECT_EQ(kIcePwd1, channel1->ice_pwd());
650 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel2->GetIceRole()); 651 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel2->GetIceRole());
651 EXPECT_EQ(2U, channel2->IceTiebreaker()); 652 EXPECT_EQ(2U, channel2->IceTiebreaker());
652 } 653 }
653 654
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 // BoringSSL API. Skip the test if not built with BoringSSL. 987 // BoringSSL API. Skip the test if not built with BoringSSL.
987 MAYBE_SKIP_TEST(IsBoringSsl); 988 MAYBE_SKIP_TEST(IsBoringSsl);
988 989
989 PrepareDtls(true, true, rtc::KT_DEFAULT); 990 PrepareDtls(true, true, rtc::KT_DEFAULT);
990 // Exchange transport descriptions. 991 // Exchange transport descriptions.
991 Negotiate(cricket::CONNECTIONROLE_ACTPASS, cricket::CONNECTIONROLE_ACTIVE); 992 Negotiate(cricket::CONNECTIONROLE_ACTPASS, cricket::CONNECTIONROLE_ACTIVE);
992 993
993 // Make client2_ writable, but not client1_. 994 // Make client2_ writable, but not client1_.
994 // This means client1_ will send DTLS client hellos but get no response. 995 // This means client1_ will send DTLS client hellos but get no response.
995 EXPECT_TRUE(client2_.Connect(&client1_, true)); 996 EXPECT_TRUE(client2_.Connect(&client1_, true));
996 EXPECT_TRUE_SIMULATED_WAIT(client2_.all_raw_channels_writable(), kTimeout, 997 EXPECT_TRUE_SIMULATED_WAIT(client2_.all_ice_transport_writable(), kTimeout,
997 fake_clock_); 998 fake_clock_);
998 999
999 // Wait for the first client hello to be sent. 1000 // Wait for the first client hello to be sent.
1000 EXPECT_EQ_WAIT(1, client1_.received_dtls_client_hellos(), kTimeout); 1001 EXPECT_EQ_WAIT(1, client1_.received_dtls_client_hellos(), kTimeout);
1001 EXPECT_FALSE(client1_.all_raw_channels_writable()); 1002 EXPECT_FALSE(client1_.all_ice_transport_writable());
1002 1003
1003 static int timeout_schedule_ms[] = {50, 100, 200, 400, 800, 1600, 1004 static int timeout_schedule_ms[] = {50, 100, 200, 400, 800, 1600,
1004 3200, 6400, 12800, 25600, 51200, 60000}; 1005 3200, 6400, 12800, 25600, 51200, 60000};
1005 1006
1006 int expected_hellos = 1; 1007 int expected_hellos = 1;
1007 for (size_t i = 0; 1008 for (size_t i = 0;
1008 i < (sizeof(timeout_schedule_ms) / sizeof(timeout_schedule_ms[0])); 1009 i < (sizeof(timeout_schedule_ms) / sizeof(timeout_schedule_ms[0]));
1009 ++i) { 1010 ++i) {
1010 // For each expected retransmission time, advance the fake clock a 1011 // For each expected retransmission time, advance the fake clock a
1011 // millisecond before the expected time and verify that no unexpected 1012 // millisecond before the expected time and verify that no unexpected
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 ++(remote_desc.identity_fingerprint->digest[0]); 1097 ++(remote_desc.identity_fingerprint->digest[0]);
1097 // Even if certificate verification fails inside this method, 1098 // Even if certificate verification fails inside this method,
1098 // it should return true as long as the fingerprint was formatted 1099 // it should return true as long as the fingerprint was formatted
1099 // correctly. 1100 // correctly.
1100 EXPECT_TRUE(client1_.transport()->SetRemoteTransportDescription( 1101 EXPECT_TRUE(client1_.transport()->SetRemoteTransportDescription(
1101 remote_desc, cricket::CA_ANSWER, nullptr)); 1102 remote_desc, cricket::CA_ANSWER, nullptr));
1102 } 1103 }
1103 break; 1104 break;
1104 case CALLER_WRITABLE: 1105 case CALLER_WRITABLE:
1105 EXPECT_TRUE(client1_.Connect(&client2_, true)); 1106 EXPECT_TRUE(client1_.Connect(&client2_, true));
1106 EXPECT_TRUE_SIMULATED_WAIT(client1_.all_raw_channels_writable(), 1107 EXPECT_TRUE_SIMULATED_WAIT(client1_.all_ice_transport_writable(),
1107 kTimeout, fake_clock_); 1108 kTimeout, fake_clock_);
1108 break; 1109 break;
1109 case CALLER_RECEIVES_CLIENTHELLO: 1110 case CALLER_RECEIVES_CLIENTHELLO:
1110 // Sanity check that a ClientHello hasn't already been received. 1111 // Sanity check that a ClientHello hasn't already been received.
1111 EXPECT_EQ(0, client1_.received_dtls_client_hellos()); 1112 EXPECT_EQ(0, client1_.received_dtls_client_hellos());
1112 // Making client2_ writable will cause it to send the ClientHello. 1113 // Making client2_ writable will cause it to send the ClientHello.
1113 EXPECT_TRUE(client2_.Connect(&client1_, true)); 1114 EXPECT_TRUE(client2_.Connect(&client1_, true));
1114 EXPECT_TRUE_SIMULATED_WAIT(client2_.all_raw_channels_writable(), 1115 EXPECT_TRUE_SIMULATED_WAIT(client2_.all_ice_transport_writable(),
1115 kTimeout, fake_clock_); 1116 kTimeout, fake_clock_);
1116 EXPECT_EQ_SIMULATED_WAIT(1, client1_.received_dtls_client_hellos(), 1117 EXPECT_EQ_SIMULATED_WAIT(1, client1_.received_dtls_client_hellos(),
1117 kTimeout, fake_clock_); 1118 kTimeout, fake_clock_);
1118 break; 1119 break;
1119 case HANDSHAKE_FINISHES: 1120 case HANDSHAKE_FINISHES:
1120 // Sanity check that the handshake hasn't already finished. 1121 // Sanity check that the handshake hasn't already finished.
1121 EXPECT_FALSE(client1_.GetDtlsChannel(0)->IsDtlsConnected() || 1122 EXPECT_FALSE(client1_.GetDtlsChannel(0)->IsDtlsConnected() ||
1122 client1_.GetDtlsChannel(0)->dtls_state() == 1123 client1_.GetDtlsChannel(0)->dtls_state() ==
1123 cricket::DTLS_TRANSPORT_FAILED); 1124 cricket::DTLS_TRANSPORT_FAILED);
1124 EXPECT_TRUE_SIMULATED_WAIT( 1125 EXPECT_TRUE_SIMULATED_WAIT(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 std::vector<DtlsTransportEvent>{ 1184 std::vector<DtlsTransportEvent>{
1184 CALLER_RECEIVES_CLIENTHELLO, CALLER_RECEIVES_FINGERPRINT, 1185 CALLER_RECEIVES_CLIENTHELLO, CALLER_RECEIVES_FINGERPRINT,
1185 CALLER_WRITABLE, HANDSHAKE_FINISHES}, 1186 CALLER_WRITABLE, HANDSHAKE_FINISHES},
1186 std::vector<DtlsTransportEvent>{ 1187 std::vector<DtlsTransportEvent>{
1187 CALLER_RECEIVES_CLIENTHELLO, CALLER_WRITABLE, 1188 CALLER_RECEIVES_CLIENTHELLO, CALLER_WRITABLE,
1188 CALLER_RECEIVES_FINGERPRINT, HANDSHAKE_FINISHES}, 1189 CALLER_RECEIVES_FINGERPRINT, HANDSHAKE_FINISHES},
1189 std::vector<DtlsTransportEvent>{CALLER_RECEIVES_CLIENTHELLO, 1190 std::vector<DtlsTransportEvent>{CALLER_RECEIVES_CLIENTHELLO,
1190 CALLER_WRITABLE, HANDSHAKE_FINISHES, 1191 CALLER_WRITABLE, HANDSHAKE_FINISHES,
1191 CALLER_RECEIVES_FINGERPRINT}), 1192 CALLER_RECEIVES_FINGERPRINT}),
1192 ::testing::Bool())); 1193 ::testing::Bool()));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698