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

Side by Side Diff: webrtc/p2p/quic/quicsession_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/quicsession.cc ('k') | webrtc/p2p/quic/quictransportchannel.h » ('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/quicsession.h" 11 #include "webrtc/p2p/quic/quicsession.h"
12 12
13 #include <memory>
13 #include <string> 14 #include <string>
14 #include <vector> 15 #include <vector>
15 16
16 #include "net/base/ip_endpoint.h" 17 #include "net/base/ip_endpoint.h"
17 #include "net/quic/crypto/crypto_server_config_protobuf.h" 18 #include "net/quic/crypto/crypto_server_config_protobuf.h"
18 #include "net/quic/crypto/quic_random.h" 19 #include "net/quic/crypto/quic_random.h"
19 #include "net/quic/crypto/proof_source.h" 20 #include "net/quic/crypto/proof_source.h"
20 #include "net/quic/crypto/proof_verifier.h" 21 #include "net/quic/crypto/proof_verifier.h"
21 #include "net/quic/crypto/quic_crypto_client_config.h" 22 #include "net/quic/crypto/quic_crypto_client_config.h"
22 #include "net/quic/crypto/quic_crypto_server_config.h" 23 #include "net/quic/crypto/quic_crypto_server_config.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 111
111 // ProofVerifier override 112 // ProofVerifier override
112 net::QuicAsyncStatus VerifyProof( 113 net::QuicAsyncStatus VerifyProof(
113 const std::string& hostname, 114 const std::string& hostname,
114 const std::string& server_config, 115 const std::string& server_config,
115 const std::vector<std::string>& certs, 116 const std::vector<std::string>& certs,
116 const std::string& cert_sct, 117 const std::string& cert_sct,
117 const std::string& signature, 118 const std::string& signature,
118 const net::ProofVerifyContext* verify_context, 119 const net::ProofVerifyContext* verify_context,
119 std::string* error_details, 120 std::string* error_details,
120 scoped_ptr<net::ProofVerifyDetails>* verify_details, 121 std::unique_ptr<net::ProofVerifyDetails>* verify_details,
121 net::ProofVerifierCallback* callback) override { 122 net::ProofVerifierCallback* callback) override {
122 return success_ ? net::QUIC_SUCCESS : net::QUIC_FAILURE; 123 return success_ ? net::QUIC_SUCCESS : net::QUIC_FAILURE;
123 } 124 }
124 125
125 private: 126 private:
126 // Whether or not proof verification succeeds. 127 // Whether or not proof verification succeeds.
127 bool success_; 128 bool success_;
128 }; 129 };
129 130
130 // Writes QUIC packets to a fake transport channel that simulates a network. 131 // Writes QUIC packets to a fake transport channel that simulates a network.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 return net::kMaxPacketSize; 173 return net::kMaxPacketSize;
173 } 174 }
174 175
175 private: 176 private:
176 FakeTransportChannel* fake_channel_; 177 FakeTransportChannel* fake_channel_;
177 }; 178 };
178 179
179 // Wrapper for QuicSession and transport channel that stores incoming data. 180 // Wrapper for QuicSession and transport channel that stores incoming data.
180 class QuicSessionForTest : public QuicSession { 181 class QuicSessionForTest : public QuicSession {
181 public: 182 public:
182 QuicSessionForTest(rtc::scoped_ptr<net::QuicConnection> connection, 183 QuicSessionForTest(std::unique_ptr<net::QuicConnection> connection,
183 const net::QuicConfig& config, 184 const net::QuicConfig& config,
184 rtc::scoped_ptr<FakeTransportChannel> channel) 185 std::unique_ptr<FakeTransportChannel> channel)
185 : QuicSession(std::move(connection), config), 186 : QuicSession(std::move(connection), config),
186 channel_(std::move(channel)) { 187 channel_(std::move(channel)) {
187 channel_->SignalReadPacket.connect( 188 channel_->SignalReadPacket.connect(
188 this, &QuicSessionForTest::OnChannelReadPacket); 189 this, &QuicSessionForTest::OnChannelReadPacket);
189 } 190 }
190 191
191 // Called when channel has packets to read. 192 // Called when channel has packets to read.
192 void OnChannelReadPacket(TransportChannel* channel, 193 void OnChannelReadPacket(TransportChannel* channel,
193 const char* data, 194 const char* data,
194 size_t size, 195 size_t size,
(...skipping 17 matching lines...) Expand all
212 std::string data() { return last_received_data_; } 213 std::string data() { return last_received_data_; }
213 214
214 bool has_data() { return data().size() > 0; } 215 bool has_data() { return data().size() > 0; }
215 216
216 FakeTransportChannel* channel() { return channel_.get(); } 217 FakeTransportChannel* channel() { return channel_.get(); }
217 218
218 ReliableQuicStream* incoming_stream() { return last_incoming_stream_; } 219 ReliableQuicStream* incoming_stream() { return last_incoming_stream_; }
219 220
220 private: 221 private:
221 // Transports QUIC packets to/from peer. 222 // Transports QUIC packets to/from peer.
222 rtc::scoped_ptr<FakeTransportChannel> channel_; 223 std::unique_ptr<FakeTransportChannel> channel_;
223 // Stores data received by peer once it is sent from the other peer. 224 // Stores data received by peer once it is sent from the other peer.
224 std::string last_received_data_; 225 std::string last_received_data_;
225 // Handles incoming streams from sender. 226 // Handles incoming streams from sender.
226 ReliableQuicStream* last_incoming_stream_ = nullptr; 227 ReliableQuicStream* last_incoming_stream_ = nullptr;
227 }; 228 };
228 229
229 // Simulates data transfer between two peers using QUIC. 230 // Simulates data transfer between two peers using QUIC.
230 class QuicSessionTest : public ::testing::Test, 231 class QuicSessionTest : public ::testing::Test,
231 public QuicCryptoClientStream::ProofHandler { 232 public QuicCryptoClientStream::ProofHandler {
232 public: 233 public:
233 QuicSessionTest() : quic_helper_(rtc::Thread::Current()) {} 234 QuicSessionTest() : quic_helper_(rtc::Thread::Current()) {}
234 235
235 // Instantiates |client_peer_| and |server_peer_|. 236 // Instantiates |client_peer_| and |server_peer_|.
236 void CreateClientAndServerSessions(); 237 void CreateClientAndServerSessions();
237 238
238 rtc::scoped_ptr<QuicSessionForTest> CreateSession( 239 std::unique_ptr<QuicSessionForTest> CreateSession(
239 rtc::scoped_ptr<FakeTransportChannel> channel, 240 std::unique_ptr<FakeTransportChannel> channel,
240 Perspective perspective); 241 Perspective perspective);
241 242
242 QuicCryptoClientStream* CreateCryptoClientStream(QuicSessionForTest* session, 243 QuicCryptoClientStream* CreateCryptoClientStream(QuicSessionForTest* session,
243 bool handshake_success); 244 bool handshake_success);
244 QuicCryptoServerStream* CreateCryptoServerStream(QuicSessionForTest* session, 245 QuicCryptoServerStream* CreateCryptoServerStream(QuicSessionForTest* session,
245 bool handshake_success); 246 bool handshake_success);
246 247
247 rtc::scoped_ptr<QuicConnection> CreateConnection( 248 std::unique_ptr<QuicConnection> CreateConnection(
248 FakeTransportChannel* channel, 249 FakeTransportChannel* channel,
249 Perspective perspective); 250 Perspective perspective);
250 251
251 void StartHandshake(bool client_handshake_success, 252 void StartHandshake(bool client_handshake_success,
252 bool server_handshake_success); 253 bool server_handshake_success);
253 254
254 // Test handshake establishment and sending/receiving of data. 255 // Test handshake establishment and sending/receiving of data.
255 void TestStreamConnection(QuicSessionForTest* from_session, 256 void TestStreamConnection(QuicSessionForTest* from_session,
256 QuicSessionForTest* to_session); 257 QuicSessionForTest* to_session);
257 // Test that client and server are not connected after handshake failure. 258 // Test that client and server are not connected after handshake failure.
258 void TestDisconnectAfterFailedHandshake(); 259 void TestDisconnectAfterFailedHandshake();
259 260
260 // QuicCryptoClientStream::ProofHelper overrides. 261 // QuicCryptoClientStream::ProofHelper overrides.
261 void OnProofValid( 262 void OnProofValid(
262 const QuicCryptoClientConfig::CachedState& cached) override {} 263 const QuicCryptoClientConfig::CachedState& cached) override {}
263 void OnProofVerifyDetailsAvailable( 264 void OnProofVerifyDetailsAvailable(
264 const ProofVerifyDetails& verify_details) override {} 265 const ProofVerifyDetails& verify_details) override {}
265 266
266 protected: 267 protected:
267 QuicConnectionHelper quic_helper_; 268 QuicConnectionHelper quic_helper_;
268 QuicConfig config_; 269 QuicConfig config_;
269 QuicClock clock_; 270 QuicClock clock_;
270 271
271 rtc::scoped_ptr<QuicSessionForTest> client_peer_; 272 std::unique_ptr<QuicSessionForTest> client_peer_;
272 rtc::scoped_ptr<QuicSessionForTest> server_peer_; 273 std::unique_ptr<QuicSessionForTest> server_peer_;
273 }; 274 };
274 275
275 // Initializes "client peer" who begins crypto handshake and "server peer" who 276 // Initializes "client peer" who begins crypto handshake and "server peer" who
276 // establishes encryption with client. 277 // establishes encryption with client.
277 void QuicSessionTest::CreateClientAndServerSessions() { 278 void QuicSessionTest::CreateClientAndServerSessions() {
278 rtc::scoped_ptr<FakeTransportChannel> channel1( 279 std::unique_ptr<FakeTransportChannel> channel1(
279 new FakeTransportChannel("channel1", 0)); 280 new FakeTransportChannel("channel1", 0));
280 rtc::scoped_ptr<FakeTransportChannel> channel2( 281 std::unique_ptr<FakeTransportChannel> channel2(
281 new FakeTransportChannel("channel2", 0)); 282 new FakeTransportChannel("channel2", 0));
282 283
283 // Prevent channel1->OnReadPacket and channel2->OnReadPacket from calling 284 // Prevent channel1->OnReadPacket and channel2->OnReadPacket from calling
284 // themselves in a loop, which causes to future packets to be recursively 285 // themselves in a loop, which causes to future packets to be recursively
285 // consumed while the current thread blocks consumption of current ones. 286 // consumed while the current thread blocks consumption of current ones.
286 channel2->SetAsync(true); 287 channel2->SetAsync(true);
287 288
288 // Configure peers to send packets to each other. 289 // Configure peers to send packets to each other.
289 channel1->Connect(); 290 channel1->Connect();
290 channel2->Connect(); 291 channel2->Connect();
291 channel1->SetDestination(channel2.get()); 292 channel1->SetDestination(channel2.get());
292 293
293 client_peer_ = CreateSession(std::move(channel1), Perspective::IS_CLIENT); 294 client_peer_ = CreateSession(std::move(channel1), Perspective::IS_CLIENT);
294 server_peer_ = CreateSession(std::move(channel2), Perspective::IS_SERVER); 295 server_peer_ = CreateSession(std::move(channel2), Perspective::IS_SERVER);
295 } 296 }
296 297
297 rtc::scoped_ptr<QuicSessionForTest> QuicSessionTest::CreateSession( 298 std::unique_ptr<QuicSessionForTest> QuicSessionTest::CreateSession(
298 rtc::scoped_ptr<FakeTransportChannel> channel, 299 std::unique_ptr<FakeTransportChannel> channel,
299 Perspective perspective) { 300 Perspective perspective) {
300 rtc::scoped_ptr<QuicConnection> quic_connection = 301 std::unique_ptr<QuicConnection> quic_connection =
301 CreateConnection(channel.get(), perspective); 302 CreateConnection(channel.get(), perspective);
302 return rtc::scoped_ptr<QuicSessionForTest>(new QuicSessionForTest( 303 return std::unique_ptr<QuicSessionForTest>(new QuicSessionForTest(
303 std::move(quic_connection), config_, std::move(channel))); 304 std::move(quic_connection), config_, std::move(channel)));
304 } 305 }
305 306
306 QuicCryptoClientStream* QuicSessionTest::CreateCryptoClientStream( 307 QuicCryptoClientStream* QuicSessionTest::CreateCryptoClientStream(
307 QuicSessionForTest* session, 308 QuicSessionForTest* session,
308 bool handshake_success) { 309 bool handshake_success) {
309 QuicCryptoClientConfig* client_config = 310 QuicCryptoClientConfig* client_config =
310 new QuicCryptoClientConfig(new FakeProofVerifier(handshake_success)); 311 new QuicCryptoClientConfig(new FakeProofVerifier(handshake_success));
311 return new QuicCryptoClientStream( 312 return new QuicCryptoClientStream(
312 kServerId, session, new ProofVerifyContext(), client_config, this); 313 kServerId, session, new ProofVerifyContext(), client_config, this);
313 } 314 }
314 315
315 QuicCryptoServerStream* QuicSessionTest::CreateCryptoServerStream( 316 QuicCryptoServerStream* QuicSessionTest::CreateCryptoServerStream(
316 QuicSessionForTest* session, 317 QuicSessionForTest* session,
317 bool handshake_success) { 318 bool handshake_success) {
318 QuicCryptoServerConfig* server_config = 319 QuicCryptoServerConfig* server_config =
319 new QuicCryptoServerConfig("TESTING", QuicRandom::GetInstance(), 320 new QuicCryptoServerConfig("TESTING", QuicRandom::GetInstance(),
320 new FakeProofSource(handshake_success)); 321 new FakeProofSource(handshake_success));
321 // Provide server with serialized config string to prove ownership. 322 // Provide server with serialized config string to prove ownership.
322 QuicCryptoServerConfig::ConfigOptions options; 323 QuicCryptoServerConfig::ConfigOptions options;
323 QuicServerConfigProtobuf* primary_config = server_config->GenerateConfig( 324 QuicServerConfigProtobuf* primary_config = server_config->GenerateConfig(
324 QuicRandom::GetInstance(), &clock_, options); 325 QuicRandom::GetInstance(), &clock_, options);
325 server_config->AddConfig(primary_config, clock_.WallNow()); 326 server_config->AddConfig(primary_config, clock_.WallNow());
326 return new QuicCryptoServerStream(server_config, session); 327 return new QuicCryptoServerStream(server_config, session);
327 } 328 }
328 329
329 rtc::scoped_ptr<QuicConnection> QuicSessionTest::CreateConnection( 330 std::unique_ptr<QuicConnection> QuicSessionTest::CreateConnection(
330 FakeTransportChannel* channel, 331 FakeTransportChannel* channel,
331 Perspective perspective) { 332 Perspective perspective) {
332 FakeQuicPacketWriter* writer = new FakeQuicPacketWriter(channel); 333 FakeQuicPacketWriter* writer = new FakeQuicPacketWriter(channel);
333 334
334 IPAddress ip(0, 0, 0, 0); 335 IPAddress ip(0, 0, 0, 0);
335 bool owns_writer = true; 336 bool owns_writer = true;
336 337
337 return rtc::scoped_ptr<QuicConnection>(new QuicConnection( 338 return std::unique_ptr<QuicConnection>(new QuicConnection(
338 0, net::IPEndPoint(ip, 0), &quic_helper_, writer, owns_writer, 339 0, net::IPEndPoint(ip, 0), &quic_helper_, writer, owns_writer,
339 perspective, net::QuicSupportedVersions())); 340 perspective, net::QuicSupportedVersions()));
340 } 341 }
341 342
342 void QuicSessionTest::StartHandshake(bool client_handshake_success, 343 void QuicSessionTest::StartHandshake(bool client_handshake_success,
343 bool server_handshake_success) { 344 bool server_handshake_success) {
344 server_peer_->StartServerHandshake( 345 server_peer_->StartServerHandshake(
345 CreateCryptoServerStream(server_peer_.get(), server_handshake_success)); 346 CreateCryptoServerStream(server_peer_.get(), server_handshake_success));
346 client_peer_->StartClientHandshake( 347 client_peer_->StartClientHandshake(
347 CreateCryptoClientStream(client_peer_.get(), client_handshake_success)); 348 CreateCryptoClientStream(client_peer_.get(), client_handshake_success));
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 StartHandshake(true, true); 458 StartHandshake(true, true);
458 ASSERT_TRUE_WAIT(client_peer_->IsCryptoHandshakeConfirmed() && 459 ASSERT_TRUE_WAIT(client_peer_->IsCryptoHandshakeConfirmed() &&
459 server_peer_->IsCryptoHandshakeConfirmed(), 460 server_peer_->IsCryptoHandshakeConfirmed(),
460 kTimeoutMs); 461 kTimeoutMs);
461 ReliableQuicStream* stream = client_peer_->CreateOutgoingDynamicStream(5); 462 ReliableQuicStream* stream = client_peer_->CreateOutgoingDynamicStream(5);
462 ASSERT_NE(nullptr, stream); 463 ASSERT_NE(nullptr, stream);
463 EXPECT_FALSE(client_peer_->IsClosedStream(stream->id())); 464 EXPECT_FALSE(client_peer_->IsClosedStream(stream->id()));
464 stream->Close(); 465 stream->Close();
465 EXPECT_TRUE(client_peer_->IsClosedStream(stream->id())); 466 EXPECT_TRUE(client_peer_->IsClosedStream(stream->id()));
466 } 467 }
OLDNEW
« no previous file with comments | « webrtc/p2p/quic/quicsession.cc ('k') | webrtc/p2p/quic/quictransportchannel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698