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

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

Issue 2606123002: Remove the dependency of TransportChannel and TransportChannelImpl. (Closed)
Patch Set: Fix the format. 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::FakeIceTransport* fake_ice_channel = 91 cricket::FakeIceTransport* fake_ice_channel =
92 new cricket::FakeIceTransport(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::DtlsTransport* channel =
100 new cricket::DtlsTransportChannelWrapper(fake_ice_channel); 100 new cricket::DtlsTransport(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(std::unique_ptr<cricket::DtlsTransport>(channel));
112 std::unique_ptr<cricket::DtlsTransportChannelWrapper>(channel));
113 fake_channels_.push_back( 113 fake_channels_.push_back(
114 std::unique_ptr<cricket::FakeIceTransport>(fake_ice_channel)); 114 std::unique_ptr<cricket::FakeIceTransport>(fake_ice_channel));
115 transport_->AddChannel(channel, i); 115 transport_->AddChannel(channel, i);
116 } 116 }
117 } 117 }
118 118
119 cricket::JsepTransport* transport() { return transport_.get(); } 119 cricket::JsepTransport* transport() { return transport_.get(); }
120 120
121 cricket::FakeIceTransport* GetFakeChannel(int component) { 121 cricket::FakeIceTransport* GetFakeChannel(int component) {
122 for (const auto& ch : fake_channels_) { 122 for (const auto& ch : fake_channels_) {
123 if (ch->component() == component) { 123 if (ch->component() == component) {
124 return ch.get(); 124 return ch.get();
125 } 125 }
126 } 126 }
127 return nullptr; 127 return nullptr;
128 } 128 }
129 129
130 cricket::DtlsTransportChannelWrapper* GetDtlsChannel(int component) { 130 cricket::DtlsTransport* GetDtlsChannel(int component) {
131 for (const auto& ch : channels_) { 131 for (const auto& ch : channels_) {
132 if (ch->component() == component) { 132 if (ch->component() == component) {
133 return ch.get(); 133 return ch.get();
134 } 134 }
135 } 135 }
136 return nullptr; 136 return nullptr;
137 } 137 }
138 138
139 // Offer DTLS if we have an identity; pass in a remote fingerprint only if 139 // Offer DTLS if we have an identity; pass in a remote fingerprint only if
140 // both sides support DTLS. 140 // both sides support DTLS.
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 return false; 224 return false;
225 } 225 }
226 for (const auto& channel : channels_) { 226 for (const auto& channel : channels_) {
227 if (!channel->writable()) { 227 if (!channel->writable()) {
228 return false; 228 return false;
229 } 229 }
230 } 230 }
231 return true; 231 return true;
232 } 232 }
233 233
234 bool all_raw_channels_writable() const { 234 bool all_ice_transport_writable() const {
pthatcher1 2017/01/17 20:16:48 all_ice_transports_writable()
235 if (channels_.empty()) { 235 if (channels_.empty()) {
236 return false; 236 return false;
237 } 237 }
238 for (const auto& channel : channels_) { 238 for (const auto& channel : channels_) {
pthatcher1 2017/01/17 20:16:48 transport : transports_
239 if (!channel->channel()->writable()) { 239 if (!channel->ice_transport()->writable()) {
240 return false; 240 return false;
241 } 241 }
242 } 242 }
243 return true; 243 return true;
244 } 244 }
245 245
246 int received_dtls_client_hellos() const { 246 int received_dtls_client_hellos() const {
247 return received_dtls_client_hellos_; 247 return received_dtls_client_hellos_;
248 } 248 }
249 249
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 } else if (IsRtpLeadByte(data[0])) { 428 } else if (IsRtpLeadByte(data[0])) {
429 ASSERT_TRUE(VerifyPacket(data, size, NULL)); 429 ASSERT_TRUE(VerifyPacket(data, size, NULL));
430 } 430 }
431 } 431 }
432 } 432 }
433 433
434 private: 434 private:
435 std::string name_; 435 std::string name_;
436 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; 436 rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
437 std::vector<std::unique_ptr<cricket::FakeIceTransport>> fake_channels_; 437 std::vector<std::unique_ptr<cricket::FakeIceTransport>> fake_channels_;
438 std::vector<std::unique_ptr<cricket::DtlsTransportChannelWrapper>> channels_; 438 std::vector<std::unique_ptr<cricket::DtlsTransport>> channels_;
439 std::unique_ptr<cricket::JsepTransport> transport_; 439 std::unique_ptr<cricket::JsepTransport> transport_;
440 size_t packet_size_ = 0u; 440 size_t packet_size_ = 0u;
441 std::set<int> received_; 441 std::set<int> received_;
442 bool use_dtls_srtp_ = false; 442 bool use_dtls_srtp_ = false;
443 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12; 443 rtc::SSLProtocolVersion ssl_max_version_ = rtc::SSL_PROTOCOL_DTLS_12;
444 int received_dtls_client_hellos_ = 0; 444 int received_dtls_client_hellos_ = 0;
445 int received_dtls_server_hellos_ = 0; 445 int received_dtls_server_hellos_ = 0;
446 rtc::SentPacket sent_packet_; 446 rtc::SentPacket sent_packet_;
447 }; 447 };
448 448
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 // BoringSSL API. Skip the test if not built with BoringSSL. 986 // BoringSSL API. Skip the test if not built with BoringSSL.
987 MAYBE_SKIP_TEST(IsBoringSsl); 987 MAYBE_SKIP_TEST(IsBoringSsl);
988 988
989 PrepareDtls(true, true, rtc::KT_DEFAULT); 989 PrepareDtls(true, true, rtc::KT_DEFAULT);
990 // Exchange transport descriptions. 990 // Exchange transport descriptions.
991 Negotiate(cricket::CONNECTIONROLE_ACTPASS, cricket::CONNECTIONROLE_ACTIVE); 991 Negotiate(cricket::CONNECTIONROLE_ACTPASS, cricket::CONNECTIONROLE_ACTIVE);
992 992
993 // Make client2_ writable, but not client1_. 993 // Make client2_ writable, but not client1_.
994 // This means client1_ will send DTLS client hellos but get no response. 994 // This means client1_ will send DTLS client hellos but get no response.
995 EXPECT_TRUE(client2_.Connect(&client1_, true)); 995 EXPECT_TRUE(client2_.Connect(&client1_, true));
996 EXPECT_TRUE_SIMULATED_WAIT(client2_.all_raw_channels_writable(), kTimeout, 996 EXPECT_TRUE_SIMULATED_WAIT(client2_.all_ice_transport_writable(), kTimeout,
997 fake_clock_); 997 fake_clock_);
998 998
999 // Wait for the first client hello to be sent. 999 // Wait for the first client hello to be sent.
1000 EXPECT_EQ_WAIT(1, client1_.received_dtls_client_hellos(), kTimeout); 1000 EXPECT_EQ_WAIT(1, client1_.received_dtls_client_hellos(), kTimeout);
1001 EXPECT_FALSE(client1_.all_raw_channels_writable()); 1001 EXPECT_FALSE(client1_.all_ice_transport_writable());
1002 1002
1003 static int timeout_schedule_ms[] = {50, 100, 200, 400, 800, 1600, 1003 static int timeout_schedule_ms[] = {50, 100, 200, 400, 800, 1600,
1004 3200, 6400, 12800, 25600, 51200, 60000}; 1004 3200, 6400, 12800, 25600, 51200, 60000};
1005 1005
1006 int expected_hellos = 1; 1006 int expected_hellos = 1;
1007 for (size_t i = 0; 1007 for (size_t i = 0;
1008 i < (sizeof(timeout_schedule_ms) / sizeof(timeout_schedule_ms[0])); 1008 i < (sizeof(timeout_schedule_ms) / sizeof(timeout_schedule_ms[0]));
1009 ++i) { 1009 ++i) {
1010 // For each expected retransmission time, advance the fake clock a 1010 // For each expected retransmission time, advance the fake clock a
1011 // millisecond before the expected time and verify that no unexpected 1011 // 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]); 1096 ++(remote_desc.identity_fingerprint->digest[0]);
1097 // Even if certificate verification fails inside this method, 1097 // Even if certificate verification fails inside this method,
1098 // it should return true as long as the fingerprint was formatted 1098 // it should return true as long as the fingerprint was formatted
1099 // correctly. 1099 // correctly.
1100 EXPECT_TRUE(client1_.transport()->SetRemoteTransportDescription( 1100 EXPECT_TRUE(client1_.transport()->SetRemoteTransportDescription(
1101 remote_desc, cricket::CA_ANSWER, nullptr)); 1101 remote_desc, cricket::CA_ANSWER, nullptr));
1102 } 1102 }
1103 break; 1103 break;
1104 case CALLER_WRITABLE: 1104 case CALLER_WRITABLE:
1105 EXPECT_TRUE(client1_.Connect(&client2_, true)); 1105 EXPECT_TRUE(client1_.Connect(&client2_, true));
1106 EXPECT_TRUE_SIMULATED_WAIT(client1_.all_raw_channels_writable(), 1106 EXPECT_TRUE_SIMULATED_WAIT(client1_.all_ice_transport_writable(),
1107 kTimeout, fake_clock_); 1107 kTimeout, fake_clock_);
1108 break; 1108 break;
1109 case CALLER_RECEIVES_CLIENTHELLO: 1109 case CALLER_RECEIVES_CLIENTHELLO:
1110 // Sanity check that a ClientHello hasn't already been received. 1110 // Sanity check that a ClientHello hasn't already been received.
1111 EXPECT_EQ(0, client1_.received_dtls_client_hellos()); 1111 EXPECT_EQ(0, client1_.received_dtls_client_hellos());
1112 // Making client2_ writable will cause it to send the ClientHello. 1112 // Making client2_ writable will cause it to send the ClientHello.
1113 EXPECT_TRUE(client2_.Connect(&client1_, true)); 1113 EXPECT_TRUE(client2_.Connect(&client1_, true));
1114 EXPECT_TRUE_SIMULATED_WAIT(client2_.all_raw_channels_writable(), 1114 EXPECT_TRUE_SIMULATED_WAIT(client2_.all_ice_transport_writable(),
1115 kTimeout, fake_clock_); 1115 kTimeout, fake_clock_);
1116 EXPECT_EQ_SIMULATED_WAIT(1, client1_.received_dtls_client_hellos(), 1116 EXPECT_EQ_SIMULATED_WAIT(1, client1_.received_dtls_client_hellos(),
1117 kTimeout, fake_clock_); 1117 kTimeout, fake_clock_);
1118 break; 1118 break;
1119 case HANDSHAKE_FINISHES: 1119 case HANDSHAKE_FINISHES:
1120 // Sanity check that the handshake hasn't already finished. 1120 // Sanity check that the handshake hasn't already finished.
1121 EXPECT_FALSE(client1_.GetDtlsChannel(0)->IsDtlsConnected() || 1121 EXPECT_FALSE(client1_.GetDtlsChannel(0)->IsDtlsConnected() ||
1122 client1_.GetDtlsChannel(0)->dtls_state() == 1122 client1_.GetDtlsChannel(0)->dtls_state() ==
1123 cricket::DTLS_TRANSPORT_FAILED); 1123 cricket::DTLS_TRANSPORT_FAILED);
1124 EXPECT_TRUE_SIMULATED_WAIT( 1124 EXPECT_TRUE_SIMULATED_WAIT(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 std::vector<DtlsTransportEvent>{ 1183 std::vector<DtlsTransportEvent>{
1184 CALLER_RECEIVES_CLIENTHELLO, CALLER_RECEIVES_FINGERPRINT, 1184 CALLER_RECEIVES_CLIENTHELLO, CALLER_RECEIVES_FINGERPRINT,
1185 CALLER_WRITABLE, HANDSHAKE_FINISHES}, 1185 CALLER_WRITABLE, HANDSHAKE_FINISHES},
1186 std::vector<DtlsTransportEvent>{ 1186 std::vector<DtlsTransportEvent>{
1187 CALLER_RECEIVES_CLIENTHELLO, CALLER_WRITABLE, 1187 CALLER_RECEIVES_CLIENTHELLO, CALLER_WRITABLE,
1188 CALLER_RECEIVES_FINGERPRINT, HANDSHAKE_FINISHES}, 1188 CALLER_RECEIVES_FINGERPRINT, HANDSHAKE_FINISHES},
1189 std::vector<DtlsTransportEvent>{CALLER_RECEIVES_CLIENTHELLO, 1189 std::vector<DtlsTransportEvent>{CALLER_RECEIVES_CLIENTHELLO,
1190 CALLER_WRITABLE, HANDSHAKE_FINISHES, 1190 CALLER_WRITABLE, HANDSHAKE_FINISHES,
1191 CALLER_RECEIVES_FINGERPRINT}), 1191 CALLER_RECEIVES_FINGERPRINT}),
1192 ::testing::Bool())); 1192 ::testing::Bool()));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698