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

Unified Diff: webrtc/p2p/base/dtlstransportchannel_unittest.cc

Issue 2606123002: Remove the dependency of TransportChannel and TransportChannelImpl. (Closed)
Patch Set: Fix the memory leak. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/p2p/base/dtlstransportchannel.cc ('k') | webrtc/p2p/base/dtlstransportinternal.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/p2p/base/dtlstransportchannel_unittest.cc
diff --git a/webrtc/p2p/base/dtlstransportchannel_unittest.cc b/webrtc/p2p/base/dtlstransportchannel_unittest.cc
index 4eba26d241db00574070fda57bd12c53c32f90ea..2fc95d4e3b307865c5166b898e6cc7759edd56b2 100644
--- a/webrtc/p2p/base/dtlstransportchannel_unittest.cc
+++ b/webrtc/p2p/base/dtlstransportchannel_unittest.cc
@@ -97,30 +97,31 @@ class DtlsTestClient : public sigslot::has_slots<> {
fake_ice_channel->SignalReadPacket.connect(
this, &DtlsTestClient::OnFakeTransportChannelReadPacket);
- cricket::DtlsTransportChannelWrapper* channel =
- new cricket::DtlsTransportChannelWrapper(fake_ice_channel);
- channel->SetLocalCertificate(certificate_);
- channel->SetIceRole(role);
- channel->SetIceTiebreaker((role == cricket::ICEROLE_CONTROLLING) ? 1 : 2);
- channel->SetSslMaxProtocolVersion(ssl_max_version_);
- channel->SignalWritableState.connect(this,
- &DtlsTestClient::OnTransportChannelWritableState);
- channel->SignalReadPacket.connect(this,
- &DtlsTestClient::OnTransportChannelReadPacket);
- channel->SignalSentPacket.connect(
+ cricket::DtlsTransport* dtls =
+ new cricket::DtlsTransport(fake_ice_channel);
+ dtls->SetLocalCertificate(certificate_);
+ dtls->ice_transport()->SetIceRole(role);
+ dtls->ice_transport()->SetIceTiebreaker(
+ (role == cricket::ICEROLE_CONTROLLING) ? 1 : 2);
+ dtls->SetSslMaxProtocolVersion(ssl_max_version_);
+ dtls->SignalWritableState.connect(
+ this, &DtlsTestClient::OnTransportChannelWritableState);
+ dtls->SignalReadPacket.connect(
+ this, &DtlsTestClient::OnTransportChannelReadPacket);
+ dtls->SignalSentPacket.connect(
this, &DtlsTestClient::OnTransportChannelSentPacket);
- channels_.push_back(
- std::unique_ptr<cricket::DtlsTransportChannelWrapper>(channel));
- fake_channels_.push_back(
+ fake_dtls_transports_.push_back(
+ std::unique_ptr<cricket::DtlsTransport>(dtls));
+ fake_ice_transports_.push_back(
std::unique_ptr<cricket::FakeIceTransport>(fake_ice_channel));
- transport_->AddChannel(channel, i);
+ transport_->AddChannel(dtls, i);
}
}
cricket::JsepTransport* transport() { return transport_.get(); }
- cricket::FakeIceTransport* GetFakeChannel(int component) {
- for (const auto& ch : fake_channels_) {
+ cricket::FakeIceTransport* GetFakeIceTransort(int component) {
+ for (const auto& ch : fake_ice_transports_) {
if (ch->component() == component) {
return ch.get();
}
@@ -128,10 +129,10 @@ class DtlsTestClient : public sigslot::has_slots<> {
return nullptr;
}
- cricket::DtlsTransportChannelWrapper* GetDtlsChannel(int component) {
- for (const auto& ch : channels_) {
- if (ch->component() == component) {
- return ch.get();
+ cricket::DtlsTransport* GetDtlsTransport(int component) {
+ for (const auto& dtls : fake_dtls_transports_) {
+ if (dtls->component() == component) {
+ return dtls.get();
}
}
return nullptr;
@@ -153,8 +154,8 @@ class DtlsTestClient : public sigslot::has_slots<> {
std::vector<int> ciphers;
ciphers.push_back(rtc::SRTP_AES128_CM_SHA1_80);
// SRTP ciphers will be set only in the beginning.
- for (const auto& channel : channels_) {
- EXPECT_TRUE(channel->SetSrtpCryptoSuites(ciphers));
+ for (const auto& dtls : fake_dtls_transports_) {
+ EXPECT_TRUE(dtls->SetSrtpCryptoSuites(ciphers));
}
}
@@ -213,31 +214,31 @@ class DtlsTestClient : public sigslot::has_slots<> {
}
bool Connect(DtlsTestClient* peer, bool asymmetric) {
- for (auto& channel : fake_channels_) {
- channel->SetDestination(peer->GetFakeChannel(channel->component()),
- asymmetric);
+ for (auto& ice : fake_ice_transports_) {
+ ice->SetDestination(peer->GetFakeIceTransort(ice->component()),
+ asymmetric);
}
return true;
}
- bool all_channels_writable() const {
- if (channels_.empty()) {
+ bool all_dtls_transports_writable() const {
+ if (fake_dtls_transports_.empty()) {
return false;
}
- for (const auto& channel : channels_) {
- if (!channel->writable()) {
+ for (const auto& dtls : fake_dtls_transports_) {
+ if (!dtls->writable()) {
return false;
}
}
return true;
}
- bool all_raw_channels_writable() const {
- if (channels_.empty()) {
+ bool all_ice_transports_writable() const {
+ if (fake_dtls_transports_.empty()) {
return false;
}
- for (const auto& channel : channels_) {
- if (!channel->channel()->writable()) {
+ for (const auto& dtls : fake_dtls_transports_) {
+ if (!dtls->ice_transport()->writable()) {
return false;
}
}
@@ -270,10 +271,10 @@ class DtlsTestClient : public sigslot::has_slots<> {
}
void CheckSrtp(int expected_crypto_suite) {
- for (const auto& channel : channels_) {
+ for (const auto& dtls : fake_dtls_transports_) {
int crypto_suite;
- bool rv = channel->GetSrtpCryptoSuite(&crypto_suite);
+ bool rv = dtls->GetSrtpCryptoSuite(&crypto_suite);
if (negotiated_dtls() && expected_crypto_suite) {
ASSERT_TRUE(rv);
@@ -285,10 +286,10 @@ class DtlsTestClient : public sigslot::has_slots<> {
}
void CheckSsl() {
- for (const auto& channel : channels_) {
+ for (const auto& dtls : fake_dtls_transports_) {
int cipher;
- bool rv = channel->GetSslCipherSuite(&cipher);
+ bool rv = dtls->GetSslCipherSuite(&cipher);
if (negotiated_dtls()) {
ASSERT_TRUE(rv);
@@ -300,8 +301,8 @@ class DtlsTestClient : public sigslot::has_slots<> {
}
}
- void SendPackets(size_t channel, size_t size, size_t count, bool srtp) {
- RTC_CHECK(channel < channels_.size());
+ void SendPackets(size_t transport, size_t size, size_t count, bool srtp) {
+ RTC_CHECK(transport < fake_dtls_transports_.size());
std::unique_ptr<char[]> packet(new char[size]);
size_t sent = 0;
do {
@@ -316,7 +317,7 @@ class DtlsTestClient : public sigslot::has_slots<> {
int flags = (certificate_ && srtp) ? cricket::PF_SRTP_BYPASS : 0;
rtc::PacketOptions packet_options;
packet_options.packet_id = kFakePacketId;
- int rv = channels_[channel]->SendPacket(
+ int rv = fake_dtls_transports_[transport]->SendPacket(
packet.get(), size, packet_options, flags);
ASSERT_GT(rv, 0);
ASSERT_EQ(size, static_cast<size_t>(rv));
@@ -324,18 +325,18 @@ class DtlsTestClient : public sigslot::has_slots<> {
} while (sent < count);
}
- int SendInvalidSrtpPacket(size_t channel, size_t size) {
- RTC_CHECK(channel < channels_.size());
+ int SendInvalidSrtpPacket(size_t transport, size_t size) {
+ RTC_CHECK(transport < fake_dtls_transports_.size());
std::unique_ptr<char[]> packet(new char[size]);
// Fill the packet with 0 to form an invalid SRTP packet.
memset(packet.get(), 0, size);
rtc::PacketOptions packet_options;
- return channels_[channel]->SendPacket(
+ return fake_dtls_transports_[transport]->SendPacket(
packet.get(), size, packet_options, cricket::PF_SRTP_BYPASS);
}
- void ExpectPackets(size_t channel, size_t size) {
+ void ExpectPackets(size_t transport, size_t size) {
packet_size_ = size;
received_.clear();
}
@@ -435,8 +436,8 @@ class DtlsTestClient : public sigslot::has_slots<> {
private:
std::string name_;
rtc::scoped_refptr<rtc::RTCCertificate> certificate_;
- std::vector<std::unique_ptr<cricket::FakeIceTransport>> fake_channels_;
- std::vector<std::unique_ptr<cricket::DtlsTransportChannelWrapper>> channels_;
+ std::vector<std::unique_ptr<cricket::FakeIceTransport>> fake_ice_transports_;
+ std::vector<std::unique_ptr<cricket::DtlsTransport>> fake_dtls_transports_;
std::unique_ptr<cricket::JsepTransport> transport_;
size_t packet_size_ = 0u;
std::set<int> received_;
@@ -527,10 +528,11 @@ class DtlsTransportChannelTestBase {
if (!rv)
return false;
- EXPECT_TRUE_SIMULATED_WAIT(
- client1_.all_channels_writable() && client2_.all_channels_writable(),
- kTimeout, fake_clock_);
- if (!client1_.all_channels_writable() || !client2_.all_channels_writable())
+ EXPECT_TRUE_SIMULATED_WAIT(client1_.all_dtls_transports_writable() &&
+ client2_.all_dtls_transports_writable(),
+ kTimeout, fake_clock_);
+ if (!client1_.all_dtls_transports_writable() ||
+ !client2_.all_dtls_transports_writable())
return false;
// Check that we used the right roles.
@@ -616,10 +618,10 @@ class DtlsTransportChannelTestBase {
}
}
- void TestTransfer(size_t channel, size_t size, size_t count, bool srtp) {
+ void TestTransfer(size_t transport, size_t size, size_t count, bool srtp) {
LOG(LS_INFO) << "Expect packets, size=" << size;
- client2_.ExpectPackets(channel, size);
- client1_.SendPackets(channel, size, count, srtp);
+ client2_.ExpectPackets(transport, size);
+ client1_.SendPackets(transport, size, count, srtp);
EXPECT_EQ_SIMULATED_WAIT(count, client2_.NumPacketsReceived(), kTimeout,
fake_clock_);
}
@@ -640,8 +642,8 @@ class DtlsTransportChannelTest : public DtlsTransportChannelTestBase,
// Test that transport negotiation of ICE, no DTLS works properly.
TEST_F(DtlsTransportChannelTest, TestChannelSetupIce) {
Negotiate();
- cricket::FakeIceTransport* channel1 = client1_.GetFakeChannel(0);
- cricket::FakeIceTransport* channel2 = client2_.GetFakeChannel(0);
+ cricket::FakeIceTransport* channel1 = client1_.GetFakeIceTransort(0);
+ cricket::FakeIceTransport* channel2 = client2_.GetFakeIceTransort(0);
ASSERT_TRUE(channel1 != NULL);
ASSERT_TRUE(channel2 != NULL);
EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole());
@@ -920,9 +922,9 @@ TEST_F(DtlsTransportChannelTest, TestRenegotiateBeforeConnect) {
cricket::CONNECTIONROLE_ACTIVE, NF_REOFFER);
bool rv = client1_.Connect(&client2_, false);
EXPECT_TRUE(rv);
- EXPECT_TRUE_SIMULATED_WAIT(
- client1_.all_channels_writable() && client2_.all_channels_writable(),
- kTimeout, fake_clock_);
+ EXPECT_TRUE_SIMULATED_WAIT(client1_.all_dtls_transports_writable() &&
+ client2_.all_dtls_transports_writable(),
+ kTimeout, fake_clock_);
TestTransfer(0, 1000, 100, true);
TestTransfer(1, 1000, 100, true);
@@ -945,8 +947,8 @@ TEST_F(DtlsTransportChannelTest, TestCertificatesBeforeConnect) {
ASSERT_TRUE(client2_.transport()->GetLocalCertificate(&certificate2));
ASSERT_NE(certificate1->ssl_certificate().ToPEMString(),
certificate2->ssl_certificate().ToPEMString());
- ASSERT_FALSE(client1_.GetDtlsChannel(0)->GetRemoteSSLCertificate());
- ASSERT_FALSE(client2_.GetDtlsChannel(0)->GetRemoteSSLCertificate());
+ ASSERT_FALSE(client1_.GetDtlsTransport(0)->GetRemoteSSLCertificate());
+ ASSERT_FALSE(client2_.GetDtlsTransport(0)->GetRemoteSSLCertificate());
}
// Test Certificates state after connection.
@@ -966,12 +968,12 @@ TEST_F(DtlsTransportChannelTest, TestCertificatesAfterConnect) {
// Each side's remote certificate is the other side's local certificate.
std::unique_ptr<rtc::SSLCertificate> remote_cert1 =
- client1_.GetDtlsChannel(0)->GetRemoteSSLCertificate();
+ client1_.GetDtlsTransport(0)->GetRemoteSSLCertificate();
ASSERT_TRUE(remote_cert1);
ASSERT_EQ(remote_cert1->ToPEMString(),
certificate2->ssl_certificate().ToPEMString());
std::unique_ptr<rtc::SSLCertificate> remote_cert2 =
- client2_.GetDtlsChannel(0)->GetRemoteSSLCertificate();
+ client2_.GetDtlsTransport(0)->GetRemoteSSLCertificate();
ASSERT_TRUE(remote_cert2);
ASSERT_EQ(remote_cert2->ToPEMString(),
certificate1->ssl_certificate().ToPEMString());
@@ -994,12 +996,12 @@ TEST_F(DtlsTransportChannelTest, TestRetransmissionSchedule) {
// Make client2_ writable, but not client1_.
// This means client1_ will send DTLS client hellos but get no response.
EXPECT_TRUE(client2_.Connect(&client1_, true));
- EXPECT_TRUE_SIMULATED_WAIT(client2_.all_raw_channels_writable(), kTimeout,
+ EXPECT_TRUE_SIMULATED_WAIT(client2_.all_ice_transports_writable(), kTimeout,
fake_clock_);
// Wait for the first client hello to be sent.
EXPECT_EQ_WAIT(1, client1_.received_dtls_client_hellos(), kTimeout);
- EXPECT_FALSE(client1_.all_raw_channels_writable());
+ EXPECT_FALSE(client1_.all_ice_transports_writable());
static int timeout_schedule_ms[] = {50, 100, 200, 400, 800, 1600,
3200, 6400, 12800, 25600, 51200, 60000};
@@ -1104,7 +1106,7 @@ class DtlsEventOrderingTest
break;
case CALLER_WRITABLE:
EXPECT_TRUE(client1_.Connect(&client2_, true));
- EXPECT_TRUE_SIMULATED_WAIT(client1_.all_raw_channels_writable(),
+ EXPECT_TRUE_SIMULATED_WAIT(client1_.all_ice_transports_writable(),
kTimeout, fake_clock_);
break;
case CALLER_RECEIVES_CLIENTHELLO:
@@ -1112,19 +1114,19 @@ class DtlsEventOrderingTest
EXPECT_EQ(0, client1_.received_dtls_client_hellos());
// Making client2_ writable will cause it to send the ClientHello.
EXPECT_TRUE(client2_.Connect(&client1_, true));
- EXPECT_TRUE_SIMULATED_WAIT(client2_.all_raw_channels_writable(),
+ EXPECT_TRUE_SIMULATED_WAIT(client2_.all_ice_transports_writable(),
kTimeout, fake_clock_);
EXPECT_EQ_SIMULATED_WAIT(1, client1_.received_dtls_client_hellos(),
kTimeout, fake_clock_);
break;
case HANDSHAKE_FINISHES:
// Sanity check that the handshake hasn't already finished.
- EXPECT_FALSE(client1_.GetDtlsChannel(0)->IsDtlsConnected() ||
- client1_.GetDtlsChannel(0)->dtls_state() ==
+ EXPECT_FALSE(client1_.GetDtlsTransport(0)->IsDtlsConnected() ||
+ client1_.GetDtlsTransport(0)->dtls_state() ==
cricket::DTLS_TRANSPORT_FAILED);
EXPECT_TRUE_SIMULATED_WAIT(
- client1_.GetDtlsChannel(0)->IsDtlsConnected() ||
- client1_.GetDtlsChannel(0)->dtls_state() ==
+ client1_.GetDtlsTransport(0)->IsDtlsConnected() ||
+ client1_.GetDtlsTransport(0)->dtls_state() ==
cricket::DTLS_TRANSPORT_FAILED,
kTimeout, fake_clock_);
break;
@@ -1135,15 +1137,15 @@ class DtlsEventOrderingTest
valid_fingerprint ? cricket::DTLS_TRANSPORT_CONNECTED
: cricket::DTLS_TRANSPORT_FAILED;
EXPECT_EQ_SIMULATED_WAIT(expected_final_state,
- client1_.GetDtlsChannel(0)->dtls_state(), kTimeout,
- fake_clock_);
+ client1_.GetDtlsTransport(0)->dtls_state(),
+ kTimeout, fake_clock_);
EXPECT_EQ_SIMULATED_WAIT(expected_final_state,
- client2_.GetDtlsChannel(0)->dtls_state(), kTimeout,
- fake_clock_);
+ client2_.GetDtlsTransport(0)->dtls_state(),
+ kTimeout, fake_clock_);
// Channel should be writable iff there was a valid fingerprint.
- EXPECT_EQ(valid_fingerprint, client1_.GetDtlsChannel(0)->writable());
- EXPECT_EQ(valid_fingerprint, client2_.GetDtlsChannel(0)->writable());
+ EXPECT_EQ(valid_fingerprint, client1_.GetDtlsTransport(0)->writable());
+ EXPECT_EQ(valid_fingerprint, client2_.GetDtlsTransport(0)->writable());
// Check that no hello needed to be retransmitted.
EXPECT_EQ(1, client1_.received_dtls_client_hellos());
« no previous file with comments | « webrtc/p2p/base/dtlstransportchannel.cc ('k') | webrtc/p2p/base/dtlstransportinternal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698