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

Side by Side Diff: webrtc/p2p/quic/quictransportchannel_unittest.cc

Issue 1923163003: Replace scoped_ptr with unique_ptr in webrtc/p2p/ (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « webrtc/p2p/quic/quictransportchannel.cc ('k') | webrtc/p2p/quic/reliablequicstream_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2016 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
11 #include "webrtc/p2p/quic/quictransportchannel.h" 11 #include "webrtc/p2p/quic/quictransportchannel.h"
12 12
13 #include <memory>
13 #include <set> 14 #include <set>
14 #include <string> 15 #include <string>
15 #include <vector> 16 #include <vector>
16 17
17 #include "webrtc/base/common.h" 18 #include "webrtc/base/common.h"
18 #include "webrtc/base/gunit.h" 19 #include "webrtc/base/gunit.h"
19 #include "webrtc/base/scoped_ptr.h"
20 #include "webrtc/base/sslidentity.h" 20 #include "webrtc/base/sslidentity.h"
21 #include "webrtc/p2p/base/faketransportcontroller.h" 21 #include "webrtc/p2p/base/faketransportcontroller.h"
22 22
23 using cricket::ConnectionRole; 23 using cricket::ConnectionRole;
24 using cricket::IceRole; 24 using cricket::IceRole;
25 using cricket::QuicTransportChannel; 25 using cricket::QuicTransportChannel;
26 using cricket::ReliableQuicStream; 26 using cricket::ReliableQuicStream;
27 using cricket::TransportChannel; 27 using cricket::TransportChannel;
28 using cricket::TransportDescription; 28 using cricket::TransportDescription;
29 29
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 bytes_sent_(0), 96 bytes_sent_(0),
97 ice_channel_(name_, 0), 97 ice_channel_(name_, 0),
98 quic_channel_(&ice_channel_) { 98 quic_channel_(&ice_channel_) {
99 quic_channel_.SignalReadPacket.connect( 99 quic_channel_.SignalReadPacket.connect(
100 this, &QuicTestPeer::OnTransportChannelReadPacket); 100 this, &QuicTestPeer::OnTransportChannelReadPacket);
101 quic_channel_.SignalIncomingStream.connect(this, 101 quic_channel_.SignalIncomingStream.connect(this,
102 &QuicTestPeer::OnIncomingStream); 102 &QuicTestPeer::OnIncomingStream);
103 quic_channel_.SignalClosed.connect(this, &QuicTestPeer::OnClosed); 103 quic_channel_.SignalClosed.connect(this, &QuicTestPeer::OnClosed);
104 ice_channel_.SetAsync(true); 104 ice_channel_.SetAsync(true);
105 rtc::scoped_refptr<rtc::RTCCertificate> local_cert = 105 rtc::scoped_refptr<rtc::RTCCertificate> local_cert =
106 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>( 106 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
107 rtc::SSLIdentity::Generate(name_, rtc::KT_DEFAULT))); 107 rtc::SSLIdentity::Generate(name_, rtc::KT_DEFAULT)));
108 quic_channel_.SetLocalCertificate(local_cert); 108 quic_channel_.SetLocalCertificate(local_cert);
109 local_fingerprint_.reset(CreateFingerprint(local_cert.get())); 109 local_fingerprint_.reset(CreateFingerprint(local_cert.get()));
110 } 110 }
111 111
112 // Connects |ice_channel_| to that of the other peer. 112 // Connects |ice_channel_| to that of the other peer.
113 void Connect(QuicTestPeer* other_peer) { 113 void Connect(QuicTestPeer* other_peer) {
114 ice_channel_.Connect(); 114 ice_channel_.Connect();
115 other_peer->ice_channel_.Connect(); 115 other_peer->ice_channel_.Connect();
116 ice_channel_.SetDestination(&other_peer->ice_channel_); 116 ice_channel_.SetDestination(&other_peer->ice_channel_);
(...skipping 24 matching lines...) Expand all
141 } 141 }
142 142
143 // Creates fingerprint from certificate. 143 // Creates fingerprint from certificate.
144 rtc::SSLFingerprint* CreateFingerprint(rtc::RTCCertificate* cert) { 144 rtc::SSLFingerprint* CreateFingerprint(rtc::RTCCertificate* cert) {
145 std::string digest_algorithm; 145 std::string digest_algorithm;
146 bool get_digest_algorithm = 146 bool get_digest_algorithm =
147 cert->ssl_certificate().GetSignatureDigestAlgorithm(&digest_algorithm); 147 cert->ssl_certificate().GetSignatureDigestAlgorithm(&digest_algorithm);
148 if (!get_digest_algorithm || digest_algorithm.empty()) { 148 if (!get_digest_algorithm || digest_algorithm.empty()) {
149 return nullptr; 149 return nullptr;
150 } 150 }
151 rtc::scoped_ptr<rtc::SSLFingerprint> fingerprint( 151 std::unique_ptr<rtc::SSLFingerprint> fingerprint(
152 rtc::SSLFingerprint::Create(digest_algorithm, cert->identity())); 152 rtc::SSLFingerprint::Create(digest_algorithm, cert->identity()));
153 if (digest_algorithm != rtc::DIGEST_SHA_256) { 153 if (digest_algorithm != rtc::DIGEST_SHA_256) {
154 return nullptr; 154 return nullptr;
155 } 155 }
156 return fingerprint.release(); 156 return fingerprint.release();
157 } 157 }
158 158
159 // Sends SRTP packet to the other peer via |quic_channel_|. 159 // Sends SRTP packet to the other peer via |quic_channel_|.
160 int SendSrtpPacket() { 160 int SendSrtpPacket() {
161 char packet[kPacketSize]; 161 char packet[kPacketSize];
(...skipping 29 matching lines...) Expand all
191 void SetWriteError(int error) { ice_channel_.SetError(error); } 191 void SetWriteError(int error) { ice_channel_.SetError(error); }
192 192
193 size_t bytes_received() const { return bytes_received_; } 193 size_t bytes_received() const { return bytes_received_; }
194 194
195 size_t bytes_sent() const { return bytes_sent_; } 195 size_t bytes_sent() const { return bytes_sent_; }
196 196
197 FailableTransportChannel* ice_channel() { return &ice_channel_; } 197 FailableTransportChannel* ice_channel() { return &ice_channel_; }
198 198
199 QuicTransportChannel* quic_channel() { return &quic_channel_; } 199 QuicTransportChannel* quic_channel() { return &quic_channel_; }
200 200
201 rtc::scoped_ptr<rtc::SSLFingerprint>& local_fingerprint() { 201 std::unique_ptr<rtc::SSLFingerprint>& local_fingerprint() {
202 return local_fingerprint_; 202 return local_fingerprint_;
203 } 203 }
204 204
205 ReliableQuicStream* incoming_quic_stream() { return incoming_quic_stream_; } 205 ReliableQuicStream* incoming_quic_stream() { return incoming_quic_stream_; }
206 206
207 bool signal_closed_emitted() const { return signal_closed_emitted_; } 207 bool signal_closed_emitted() const { return signal_closed_emitted_; }
208 208
209 private: 209 private:
210 // QuicTransportChannel callbacks. 210 // QuicTransportChannel callbacks.
211 void OnTransportChannelReadPacket(TransportChannel* channel, 211 void OnTransportChannelReadPacket(TransportChannel* channel,
212 const char* data, 212 const char* data,
213 size_t size, 213 size_t size,
214 const rtc::PacketTime& packet_time, 214 const rtc::PacketTime& packet_time,
215 int flags) { 215 int flags) {
216 bytes_received_ += size; 216 bytes_received_ += size;
217 // Only SRTP packets should have the bypass flag set. 217 // Only SRTP packets should have the bypass flag set.
218 int expected_flags = IsRtpLeadByte(data[0]) ? cricket::PF_SRTP_BYPASS : 0; 218 int expected_flags = IsRtpLeadByte(data[0]) ? cricket::PF_SRTP_BYPASS : 0;
219 ASSERT_EQ(expected_flags, flags); 219 ASSERT_EQ(expected_flags, flags);
220 } 220 }
221 void OnIncomingStream(ReliableQuicStream* stream) { 221 void OnIncomingStream(ReliableQuicStream* stream) {
222 incoming_quic_stream_ = stream; 222 incoming_quic_stream_ = stream;
223 } 223 }
224 void OnClosed() { signal_closed_emitted_ = true; } 224 void OnClosed() { signal_closed_emitted_ = true; }
225 225
226 std::string name_; // Channel name. 226 std::string name_; // Channel name.
227 size_t bytes_sent_; // Bytes sent by QUIC channel. 227 size_t bytes_sent_; // Bytes sent by QUIC channel.
228 size_t bytes_received_; // Bytes received by QUIC channel. 228 size_t bytes_received_; // Bytes received by QUIC channel.
229 FailableTransportChannel ice_channel_; // Simulates an ICE channel. 229 FailableTransportChannel ice_channel_; // Simulates an ICE channel.
230 QuicTransportChannel quic_channel_; // QUIC channel to test. 230 QuicTransportChannel quic_channel_; // QUIC channel to test.
231 rtc::scoped_ptr<rtc::SSLFingerprint> local_fingerprint_; 231 std::unique_ptr<rtc::SSLFingerprint> local_fingerprint_;
232 ReliableQuicStream* incoming_quic_stream_ = nullptr; 232 ReliableQuicStream* incoming_quic_stream_ = nullptr;
233 bool signal_closed_emitted_ = false; 233 bool signal_closed_emitted_ = false;
234 }; 234 };
235 235
236 class QuicTransportChannelTest : public testing::Test { 236 class QuicTransportChannelTest : public testing::Test {
237 public: 237 public:
238 QuicTransportChannelTest() : peer1_("P1"), peer2_("P2") {} 238 QuicTransportChannelTest() : peer1_("P1"), peer2_("P2") {}
239 239
240 // Performs negotiation before QUIC handshake, then connects the fake 240 // Performs negotiation before QUIC handshake, then connects the fake
241 // transport channels of each peer. As a side effect, the QUIC channels 241 // transport channels of each peer. As a side effect, the QUIC channels
242 // start sending handshake messages. |peer1_| has a client role and |peer2_| 242 // start sending handshake messages. |peer1_| has a client role and |peer2_|
243 // has server role in the QUIC handshake. 243 // has server role in the QUIC handshake.
244 void Connect() { 244 void Connect() {
245 SetIceAndCryptoParameters(rtc::SSL_CLIENT, rtc::SSL_SERVER); 245 SetIceAndCryptoParameters(rtc::SSL_CLIENT, rtc::SSL_SERVER);
246 peer1_.Connect(&peer2_); 246 peer1_.Connect(&peer2_);
247 } 247 }
248 248
249 // Disconnects the fake transport channels. 249 // Disconnects the fake transport channels.
250 void Disconnect() { 250 void Disconnect() {
251 peer1_.Disconnect(); 251 peer1_.Disconnect();
252 peer2_.Disconnect(); 252 peer2_.Disconnect();
253 } 253 }
254 254
255 // Sets up ICE parameters and exchanges fingerprints before QUIC handshake. 255 // Sets up ICE parameters and exchanges fingerprints before QUIC handshake.
256 void SetIceAndCryptoParameters(rtc::SSLRole peer1_ssl_role, 256 void SetIceAndCryptoParameters(rtc::SSLRole peer1_ssl_role,
257 rtc::SSLRole peer2_ssl_role) { 257 rtc::SSLRole peer2_ssl_role) {
258 peer1_.quic_channel()->SetSslRole(peer1_ssl_role); 258 peer1_.quic_channel()->SetSslRole(peer1_ssl_role);
259 peer2_.quic_channel()->SetSslRole(peer2_ssl_role); 259 peer2_.quic_channel()->SetSslRole(peer2_ssl_role);
260 260
261 rtc::scoped_ptr<rtc::SSLFingerprint>& peer1_fingerprint = 261 std::unique_ptr<rtc::SSLFingerprint>& peer1_fingerprint =
262 peer1_.local_fingerprint(); 262 peer1_.local_fingerprint();
263 rtc::scoped_ptr<rtc::SSLFingerprint>& peer2_fingerprint = 263 std::unique_ptr<rtc::SSLFingerprint>& peer2_fingerprint =
264 peer2_.local_fingerprint(); 264 peer2_.local_fingerprint();
265 265
266 peer1_.quic_channel()->SetRemoteFingerprint( 266 peer1_.quic_channel()->SetRemoteFingerprint(
267 peer2_fingerprint->algorithm, 267 peer2_fingerprint->algorithm,
268 reinterpret_cast<const uint8_t*>(peer2_fingerprint->digest.data()), 268 reinterpret_cast<const uint8_t*>(peer2_fingerprint->digest.data()),
269 peer2_fingerprint->digest.size()); 269 peer2_fingerprint->digest.size());
270 peer2_.quic_channel()->SetRemoteFingerprint( 270 peer2_.quic_channel()->SetRemoteFingerprint(
271 peer1_fingerprint->algorithm, 271 peer1_fingerprint->algorithm,
272 reinterpret_cast<const uint8_t*>(peer1_fingerprint->digest.data()), 272 reinterpret_cast<const uint8_t*>(peer1_fingerprint->digest.data()),
273 peer1_fingerprint->digest.size()); 273 peer1_fingerprint->digest.size());
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 ASSERT_TRUE_WAIT(quic_connected(), kTimeoutMs); 457 ASSERT_TRUE_WAIT(quic_connected(), kTimeoutMs);
458 EXPECT_FALSE(peer1_.quic_channel()->SetSslRole(rtc::SSL_SERVER)); 458 EXPECT_FALSE(peer1_.quic_channel()->SetSslRole(rtc::SSL_SERVER));
459 EXPECT_TRUE(peer1_.quic_channel()->SetSslRole(rtc::SSL_CLIENT)); 459 EXPECT_TRUE(peer1_.quic_channel()->SetSslRole(rtc::SSL_CLIENT));
460 EXPECT_FALSE(peer2_.quic_channel()->SetSslRole(rtc::SSL_CLIENT)); 460 EXPECT_FALSE(peer2_.quic_channel()->SetSslRole(rtc::SSL_CLIENT));
461 EXPECT_TRUE(peer2_.quic_channel()->SetSslRole(rtc::SSL_SERVER)); 461 EXPECT_TRUE(peer2_.quic_channel()->SetSslRole(rtc::SSL_SERVER));
462 } 462 }
463 463
464 // Set the SSL role, then test that GetSslRole returns the same value. 464 // Set the SSL role, then test that GetSslRole returns the same value.
465 TEST_F(QuicTransportChannelTest, SetGetSslRole) { 465 TEST_F(QuicTransportChannelTest, SetGetSslRole) {
466 ASSERT_TRUE(peer1_.quic_channel()->SetSslRole(rtc::SSL_SERVER)); 466 ASSERT_TRUE(peer1_.quic_channel()->SetSslRole(rtc::SSL_SERVER));
467 rtc::scoped_ptr<rtc::SSLRole> role(new rtc::SSLRole()); 467 std::unique_ptr<rtc::SSLRole> role(new rtc::SSLRole());
468 ASSERT_TRUE(peer1_.quic_channel()->GetSslRole(role.get())); 468 ASSERT_TRUE(peer1_.quic_channel()->GetSslRole(role.get()));
469 EXPECT_EQ(rtc::SSL_SERVER, *role); 469 EXPECT_EQ(rtc::SSL_SERVER, *role);
470 } 470 }
471 471
472 // Test that after the QUIC handshake is complete, the QUIC handshake remains 472 // Test that after the QUIC handshake is complete, the QUIC handshake remains
473 // confirmed even if the ICE channel reconnects. 473 // confirmed even if the ICE channel reconnects.
474 TEST_F(QuicTransportChannelTest, HandshakeConfirmedAfterReconnect) { 474 TEST_F(QuicTransportChannelTest, HandshakeConfirmedAfterReconnect) {
475 Connect(); 475 Connect();
476 ASSERT_TRUE_WAIT(quic_connected(), kTimeoutMs); 476 ASSERT_TRUE_WAIT(quic_connected(), kTimeoutMs);
477 Disconnect(); 477 Disconnect();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 Connect(); 519 Connect();
520 ASSERT_TRUE_WAIT(quic_connected(), kTimeoutMs); 520 ASSERT_TRUE_WAIT(quic_connected(), kTimeoutMs);
521 ASSERT_FALSE(peer1_.signal_closed_emitted()); 521 ASSERT_FALSE(peer1_.signal_closed_emitted());
522 ReliableQuicStream* stream = peer1_.quic_channel()->CreateQuicStream(); 522 ReliableQuicStream* stream = peer1_.quic_channel()->CreateQuicStream();
523 ASSERT_NE(nullptr, stream); 523 ASSERT_NE(nullptr, stream);
524 stream->CloseConnectionWithDetails(net::QuicErrorCode::QUIC_NO_ERROR, 524 stream->CloseConnectionWithDetails(net::QuicErrorCode::QUIC_NO_ERROR,
525 "Closing QUIC for testing"); 525 "Closing QUIC for testing");
526 EXPECT_TRUE(peer1_.signal_closed_emitted()); 526 EXPECT_TRUE(peer1_.signal_closed_emitted());
527 EXPECT_TRUE_WAIT(peer2_.signal_closed_emitted(), kTimeoutMs); 527 EXPECT_TRUE_WAIT(peer2_.signal_closed_emitted(), kTimeoutMs);
528 } 528 }
OLDNEW
« no previous file with comments | « webrtc/p2p/quic/quictransportchannel.cc ('k') | webrtc/p2p/quic/reliablequicstream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698