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

Side by Side Diff: net/quic/test_tools/quic_test_utils.cc

Issue 182523002: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed rch's comments in Patch set 1 of CL 181463007 Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/test_tools/quic_test_utils.h ('k') | net/tools/quic/end_to_end_test.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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/test_tools/quic_test_utils.h" 5 #include "net/quic/test_tools/quic_test_utils.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "net/quic/crypto/crypto_framer.h" 9 #include "net/quic/crypto/crypto_framer.h"
10 #include "net/quic/crypto/crypto_handshake.h" 10 #include "net/quic/crypto/crypto_handshake.h"
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 258
259 QuicAlarm* MockHelper::CreateAlarm(QuicAlarm::Delegate* delegate) { 259 QuicAlarm* MockHelper::CreateAlarm(QuicAlarm::Delegate* delegate) {
260 return new TestAlarm(delegate); 260 return new TestAlarm(delegate);
261 } 261 }
262 262
263 void MockHelper::AdvanceTime(QuicTime::Delta delta) { 263 void MockHelper::AdvanceTime(QuicTime::Delta delta) {
264 clock_.AdvanceTime(delta); 264 clock_.AdvanceTime(delta);
265 } 265 }
266 266
267 MockConnection::MockConnection(bool is_server) 267 MockConnection::MockConnection(bool is_server)
268 : QuicConnection(kTestGuid, 268 : QuicConnection(kTestConnectionId,
269 IPEndPoint(TestPeerIPAddress(), kTestPort), 269 IPEndPoint(TestPeerIPAddress(), kTestPort),
270 new testing::NiceMock<MockHelper>(), 270 new testing::NiceMock<MockHelper>(),
271 new testing::NiceMock<MockPacketWriter>(), 271 new testing::NiceMock<MockPacketWriter>(),
272 is_server, QuicSupportedVersions()), 272 is_server, QuicSupportedVersions()),
273 writer_(QuicConnectionPeer::GetWriter(this)), 273 writer_(QuicConnectionPeer::GetWriter(this)),
274 helper_(helper()) { 274 helper_(helper()) {
275 } 275 }
276 276
277 MockConnection::MockConnection(IPEndPoint address, 277 MockConnection::MockConnection(IPEndPoint address,
278 bool is_server) 278 bool is_server)
279 : QuicConnection(kTestGuid, address, 279 : QuicConnection(kTestConnectionId, address,
280 new testing::NiceMock<MockHelper>(), 280 new testing::NiceMock<MockHelper>(),
281 new testing::NiceMock<MockPacketWriter>(), 281 new testing::NiceMock<MockPacketWriter>(),
282 is_server, QuicSupportedVersions()), 282 is_server, QuicSupportedVersions()),
283 writer_(QuicConnectionPeer::GetWriter(this)), 283 writer_(QuicConnectionPeer::GetWriter(this)),
284 helper_(helper()) { 284 helper_(helper()) {
285 } 285 }
286 286
287 MockConnection::MockConnection(QuicGuid guid, 287 MockConnection::MockConnection(QuicConnectionId connection_id,
288 bool is_server) 288 bool is_server)
289 : QuicConnection(guid, IPEndPoint(TestPeerIPAddress(), kTestPort), 289 : QuicConnection(connection_id,
290 IPEndPoint(TestPeerIPAddress(), kTestPort),
290 new testing::NiceMock<MockHelper>(), 291 new testing::NiceMock<MockHelper>(),
291 new testing::NiceMock<MockPacketWriter>(), 292 new testing::NiceMock<MockPacketWriter>(),
292 is_server, QuicSupportedVersions()), 293 is_server, QuicSupportedVersions()),
293 writer_(QuicConnectionPeer::GetWriter(this)), 294 writer_(QuicConnectionPeer::GetWriter(this)),
294 helper_(helper()) { 295 helper_(helper()) {
295 } 296 }
296 297
297 MockConnection::MockConnection(bool is_server, 298 MockConnection::MockConnection(bool is_server,
298 const QuicVersionVector& supported_versions) 299 const QuicVersionVector& supported_versions)
299 : QuicConnection(kTestGuid, 300 : QuicConnection(kTestConnectionId,
300 IPEndPoint(TestPeerIPAddress(), kTestPort), 301 IPEndPoint(TestPeerIPAddress(), kTestPort),
301 new testing::NiceMock<MockHelper>(), 302 new testing::NiceMock<MockHelper>(),
302 new testing::NiceMock<MockPacketWriter>(), 303 new testing::NiceMock<MockPacketWriter>(),
303 is_server, supported_versions), 304 is_server, supported_versions),
304 writer_(QuicConnectionPeer::GetWriter(this)), 305 writer_(QuicConnectionPeer::GetWriter(this)),
305 helper_(helper()) { 306 helper_(helper()) {
306 } 307 }
307 308
308 MockConnection::~MockConnection() { 309 MockConnection::~MockConnection() {
309 } 310 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 369
369 MockPacketWriter::~MockPacketWriter() { 370 MockPacketWriter::~MockPacketWriter() {
370 } 371 }
371 372
372 MockSendAlgorithm::MockSendAlgorithm() { 373 MockSendAlgorithm::MockSendAlgorithm() {
373 } 374 }
374 375
375 MockSendAlgorithm::~MockSendAlgorithm() { 376 MockSendAlgorithm::~MockSendAlgorithm() {
376 } 377 }
377 378
379 MockLossAlgorithm::MockLossAlgorithm() {
380 }
381
382 MockLossAlgorithm::~MockLossAlgorithm() {
383 }
384
378 MockAckNotifierDelegate::MockAckNotifierDelegate() { 385 MockAckNotifierDelegate::MockAckNotifierDelegate() {
379 } 386 }
380 387
381 MockAckNotifierDelegate::~MockAckNotifierDelegate() { 388 MockAckNotifierDelegate::~MockAckNotifierDelegate() {
382 } 389 }
383 390
384 namespace { 391 namespace {
385 392
386 string HexDumpWithMarks(const char* data, int length, 393 string HexDumpWithMarks(const char* data, int length,
387 const bool* marks, int mark_length) { 394 const bool* marks, int mark_length) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 return true; 479 return true;
473 std::vector<uint8> v; 480 std::vector<uint8> v;
474 if (!base::HexStringToBytes(hex.as_string(), &v)) 481 if (!base::HexStringToBytes(hex.as_string(), &v))
475 return false; 482 return false;
476 if (!v.empty()) 483 if (!v.empty())
477 bytes->assign(reinterpret_cast<const char*>(&v[0]), v.size()); 484 bytes->assign(reinterpret_cast<const char*>(&v[0]), v.size());
478 return true; 485 return true;
479 } 486 }
480 487
481 static QuicPacket* ConstructPacketFromHandshakeMessage( 488 static QuicPacket* ConstructPacketFromHandshakeMessage(
482 QuicGuid guid, 489 QuicConnectionId connection_id,
483 const CryptoHandshakeMessage& message, 490 const CryptoHandshakeMessage& message,
484 bool should_include_version) { 491 bool should_include_version) {
485 CryptoFramer crypto_framer; 492 CryptoFramer crypto_framer;
486 scoped_ptr<QuicData> data(crypto_framer.ConstructHandshakeMessage(message)); 493 scoped_ptr<QuicData> data(crypto_framer.ConstructHandshakeMessage(message));
487 QuicFramer quic_framer(QuicSupportedVersions(), QuicTime::Zero(), false); 494 QuicFramer quic_framer(QuicSupportedVersions(), QuicTime::Zero(), false);
488 495
489 QuicPacketHeader header; 496 QuicPacketHeader header;
490 header.public_header.guid = guid; 497 header.public_header.connection_id = connection_id;
491 header.public_header.reset_flag = false; 498 header.public_header.reset_flag = false;
492 header.public_header.version_flag = should_include_version; 499 header.public_header.version_flag = should_include_version;
493 header.packet_sequence_number = 1; 500 header.packet_sequence_number = 1;
494 header.entropy_flag = false; 501 header.entropy_flag = false;
495 header.entropy_hash = 0; 502 header.entropy_hash = 0;
496 header.fec_flag = false; 503 header.fec_flag = false;
497 header.fec_group = 0; 504 header.fec_group = 0;
498 505
499 QuicStreamFrame stream_frame(kCryptoStreamId, false, 0, 506 QuicStreamFrame stream_frame(kCryptoStreamId, false, 0,
500 MakeIOVector(data->AsStringPiece())); 507 MakeIOVector(data->AsStringPiece()));
501 508
502 QuicFrame frame(&stream_frame); 509 QuicFrame frame(&stream_frame);
503 QuicFrames frames; 510 QuicFrames frames;
504 frames.push_back(frame); 511 frames.push_back(frame);
505 return quic_framer.BuildUnsizedDataPacket(header, frames).packet; 512 return quic_framer.BuildUnsizedDataPacket(header, frames).packet;
506 } 513 }
507 514
508 QuicPacket* ConstructHandshakePacket(QuicGuid guid, QuicTag tag) { 515 QuicPacket* ConstructHandshakePacket(QuicConnectionId connection_id,
516 QuicTag tag) {
509 CryptoHandshakeMessage message; 517 CryptoHandshakeMessage message;
510 message.set_tag(tag); 518 message.set_tag(tag);
511 return ConstructPacketFromHandshakeMessage(guid, message, false); 519 return ConstructPacketFromHandshakeMessage(connection_id, message, false);
512 } 520 }
513 521
514 size_t GetPacketLengthForOneStream( 522 size_t GetPacketLengthForOneStream(
515 QuicVersion version, 523 QuicVersion version,
516 bool include_version, 524 bool include_version,
517 QuicSequenceNumberLength sequence_number_length, 525 QuicSequenceNumberLength sequence_number_length,
518 InFecGroup is_in_fec_group, 526 InFecGroup is_in_fec_group,
519 size_t* payload_length) { 527 size_t* payload_length) {
520 *payload_length = 1; 528 *payload_length = 1;
521 const size_t stream_length = 529 const size_t stream_length =
522 NullEncrypter().GetCiphertextSize(*payload_length) + 530 NullEncrypter().GetCiphertextSize(*payload_length) +
523 QuicPacketCreator::StreamFramePacketOverhead( 531 QuicPacketCreator::StreamFramePacketOverhead(
524 version, PACKET_8BYTE_GUID, include_version, 532 version, PACKET_8BYTE_CONNECTION_ID, include_version,
525 sequence_number_length, is_in_fec_group); 533 sequence_number_length, is_in_fec_group);
526 const size_t ack_length = NullEncrypter().GetCiphertextSize( 534 const size_t ack_length = NullEncrypter().GetCiphertextSize(
527 QuicFramer::GetMinAckFrameSize( 535 QuicFramer::GetMinAckFrameSize(
528 version, sequence_number_length, PACKET_1BYTE_SEQUENCE_NUMBER)) + 536 version, sequence_number_length, PACKET_1BYTE_SEQUENCE_NUMBER)) +
529 GetPacketHeaderSize(PACKET_8BYTE_GUID, include_version, 537 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, include_version,
530 sequence_number_length, is_in_fec_group); 538 sequence_number_length, is_in_fec_group);
531 if (stream_length < ack_length) { 539 if (stream_length < ack_length) {
532 *payload_length = 1 + ack_length - stream_length; 540 *payload_length = 1 + ack_length - stream_length;
533 } 541 }
534 542
535 return NullEncrypter().GetCiphertextSize(*payload_length) + 543 return NullEncrypter().GetCiphertextSize(*payload_length) +
536 QuicPacketCreator::StreamFramePacketOverhead( 544 QuicPacketCreator::StreamFramePacketOverhead(
537 version, PACKET_8BYTE_GUID, include_version, 545 version, PACKET_8BYTE_CONNECTION_ID, include_version,
538 sequence_number_length, is_in_fec_group); 546 sequence_number_length, is_in_fec_group);
539 } 547 }
540 548
541 TestEntropyCalculator::TestEntropyCalculator() { } 549 TestEntropyCalculator::TestEntropyCalculator() { }
542 550
543 TestEntropyCalculator::~TestEntropyCalculator() { } 551 TestEntropyCalculator::~TestEntropyCalculator() { }
544 552
545 QuicPacketEntropyHash TestEntropyCalculator::EntropyHash( 553 QuicPacketEntropyHash TestEntropyCalculator::EntropyHash(
546 QuicPacketSequenceNumber sequence_number) const { 554 QuicPacketSequenceNumber sequence_number) const {
547 return 1u; 555 return 1u;
(...skipping 19 matching lines...) Expand all
567 data.AppendToString(&data_); 575 data.AppendToString(&data_);
568 return true; 576 return true;
569 } 577 }
570 578
571 void TestDecompressorVisitor::OnDecompressionError() { 579 void TestDecompressorVisitor::OnDecompressionError() {
572 error_ = true; 580 error_ = true;
573 } 581 }
574 582
575 } // namespace test 583 } // namespace test
576 } // namespace net 584 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/quic_test_utils.h ('k') | net/tools/quic/end_to_end_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698