| OLD | NEW |
| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/sha1.h" | 9 #include "base/sha1.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 244 } |
| 245 | 245 |
| 246 MockQuicConnection::MockQuicConnection(MockQuicConnectionHelper* helper, | 246 MockQuicConnection::MockQuicConnection(MockQuicConnectionHelper* helper, |
| 247 MockAlarmFactory* alarm_factory, | 247 MockAlarmFactory* alarm_factory, |
| 248 Perspective perspective) | 248 Perspective perspective) |
| 249 : MockQuicConnection(kTestConnectionId, | 249 : MockQuicConnection(kTestConnectionId, |
| 250 IPEndPoint(TestPeerIPAddress(), kTestPort), | 250 IPEndPoint(TestPeerIPAddress(), kTestPort), |
| 251 helper, | 251 helper, |
| 252 alarm_factory, | 252 alarm_factory, |
| 253 perspective, | 253 perspective, |
| 254 QuicSupportedVersions()) {} | 254 AllSupportedVersions()) {} |
| 255 | 255 |
| 256 MockQuicConnection::MockQuicConnection(IPEndPoint address, | 256 MockQuicConnection::MockQuicConnection(IPEndPoint address, |
| 257 MockQuicConnectionHelper* helper, | 257 MockQuicConnectionHelper* helper, |
| 258 MockAlarmFactory* alarm_factory, | 258 MockAlarmFactory* alarm_factory, |
| 259 Perspective perspective) | 259 Perspective perspective) |
| 260 : MockQuicConnection(kTestConnectionId, | 260 : MockQuicConnection(kTestConnectionId, |
| 261 address, | 261 address, |
| 262 helper, | 262 helper, |
| 263 alarm_factory, | 263 alarm_factory, |
| 264 perspective, | 264 perspective, |
| 265 QuicSupportedVersions()) {} | 265 AllSupportedVersions()) {} |
| 266 | 266 |
| 267 MockQuicConnection::MockQuicConnection(QuicConnectionId connection_id, | 267 MockQuicConnection::MockQuicConnection(QuicConnectionId connection_id, |
| 268 MockQuicConnectionHelper* helper, | 268 MockQuicConnectionHelper* helper, |
| 269 MockAlarmFactory* alarm_factory, | 269 MockAlarmFactory* alarm_factory, |
| 270 Perspective perspective) | 270 Perspective perspective) |
| 271 : MockQuicConnection(connection_id, | 271 : MockQuicConnection(connection_id, |
| 272 IPEndPoint(TestPeerIPAddress(), kTestPort), | 272 IPEndPoint(TestPeerIPAddress(), kTestPort), |
| 273 helper, | 273 helper, |
| 274 alarm_factory, | 274 alarm_factory, |
| 275 perspective, | 275 perspective, |
| 276 QuicSupportedVersions()) {} | 276 CurrentSupportedVersions()) {} |
| 277 | 277 |
| 278 MockQuicConnection::MockQuicConnection( | 278 MockQuicConnection::MockQuicConnection( |
| 279 MockQuicConnectionHelper* helper, | 279 MockQuicConnectionHelper* helper, |
| 280 MockAlarmFactory* alarm_factory, | 280 MockAlarmFactory* alarm_factory, |
| 281 Perspective perspective, | 281 Perspective perspective, |
| 282 const QuicVersionVector& supported_versions) | 282 const QuicVersionVector& supported_versions) |
| 283 : MockQuicConnection(kTestConnectionId, | 283 : MockQuicConnection(kTestConnectionId, |
| 284 IPEndPoint(TestPeerIPAddress(), kTestPort), | 284 IPEndPoint(TestPeerIPAddress(), kTestPort), |
| 285 helper, | 285 helper, |
| 286 alarm_factory, | 286 alarm_factory, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 } | 343 } |
| 344 | 344 |
| 345 MockQuicSession::MockQuicSession(QuicConnection* connection) | 345 MockQuicSession::MockQuicSession(QuicConnection* connection) |
| 346 : QuicSession(connection, DefaultQuicConfig()) { | 346 : QuicSession(connection, DefaultQuicConfig()) { |
| 347 crypto_stream_.reset(new QuicCryptoStream(this)); | 347 crypto_stream_.reset(new QuicCryptoStream(this)); |
| 348 Initialize(); | 348 Initialize(); |
| 349 ON_CALL(*this, WritevData(_, _, _, _, _, _)) | 349 ON_CALL(*this, WritevData(_, _, _, _, _, _)) |
| 350 .WillByDefault(testing::Return(QuicConsumedData(0, false))); | 350 .WillByDefault(testing::Return(QuicConsumedData(0, false))); |
| 351 } | 351 } |
| 352 | 352 |
| 353 MockQuicSession::~MockQuicSession() {} | 353 MockQuicSession::~MockQuicSession() { |
| 354 delete connection(); |
| 355 } |
| 354 | 356 |
| 355 // static | 357 // static |
| 356 QuicConsumedData MockQuicSession::ConsumeAllData( | 358 QuicConsumedData MockQuicSession::ConsumeAllData( |
| 357 ReliableQuicStream* /*stream*/, | 359 ReliableQuicStream* /*stream*/, |
| 358 QuicStreamId /*id*/, | 360 QuicStreamId /*id*/, |
| 359 const QuicIOVector& data, | 361 const QuicIOVector& data, |
| 360 QuicStreamOffset /*offset*/, | 362 QuicStreamOffset /*offset*/, |
| 361 bool fin, | 363 bool fin, |
| 362 QuicAckListenerInterface* /*ack_notifier_delegate*/) { | 364 QuicAckListenerInterface* /*ack_notifier_delegate*/) { |
| 363 return QuicConsumedData(data.total_length, fin); | 365 return QuicConsumedData(data.total_length, fin); |
| 364 } | 366 } |
| 365 | 367 |
| 366 MockQuicSpdySession::MockQuicSpdySession(QuicConnection* connection) | 368 MockQuicSpdySession::MockQuicSpdySession(QuicConnection* connection) |
| 367 : QuicSpdySession(connection, DefaultQuicConfig()) { | 369 : QuicSpdySession(connection, DefaultQuicConfig()) { |
| 368 crypto_stream_.reset(new QuicCryptoStream(this)); | 370 crypto_stream_.reset(new QuicCryptoStream(this)); |
| 369 Initialize(); | 371 Initialize(); |
| 370 ON_CALL(*this, WritevData(_, _, _, _, _, _)) | 372 ON_CALL(*this, WritevData(_, _, _, _, _, _)) |
| 371 .WillByDefault(testing::Return(QuicConsumedData(0, false))); | 373 .WillByDefault(testing::Return(QuicConsumedData(0, false))); |
| 372 } | 374 } |
| 373 | 375 |
| 374 MockQuicSpdySession::~MockQuicSpdySession() {} | 376 MockQuicSpdySession::~MockQuicSpdySession() { |
| 377 delete connection(); |
| 378 } |
| 375 | 379 |
| 376 TestQuicSpdyServerSession::TestQuicSpdyServerSession( | 380 TestQuicSpdyServerSession::TestQuicSpdyServerSession( |
| 377 QuicConnection* connection, | 381 QuicConnection* connection, |
| 378 const QuicConfig& config, | 382 const QuicConfig& config, |
| 379 const QuicCryptoServerConfig* crypto_config, | 383 const QuicCryptoServerConfig* crypto_config, |
| 380 QuicCompressedCertsCache* compressed_certs_cache) | 384 QuicCompressedCertsCache* compressed_certs_cache) |
| 381 : QuicServerSessionBase(config, | 385 : QuicServerSessionBase(config, |
| 382 connection, | 386 connection, |
| 383 &visitor_, | 387 &visitor_, |
| 384 &helper_, | 388 &helper_, |
| 385 crypto_config, | 389 crypto_config, |
| 386 compressed_certs_cache) { | 390 compressed_certs_cache) { |
| 387 Initialize(); | 391 Initialize(); |
| 388 ON_CALL(helper_, GenerateConnectionIdForReject(_)) | 392 ON_CALL(helper_, GenerateConnectionIdForReject(_)) |
| 389 .WillByDefault( | 393 .WillByDefault( |
| 390 testing::Return(connection->random_generator()->RandUint64())); | 394 testing::Return(connection->random_generator()->RandUint64())); |
| 391 ON_CALL(helper_, CanAcceptClientHello(_, _, _)) | 395 ON_CALL(helper_, CanAcceptClientHello(_, _, _)) |
| 392 .WillByDefault(testing::Return(true)); | 396 .WillByDefault(testing::Return(true)); |
| 393 } | 397 } |
| 394 | 398 |
| 395 TestQuicSpdyServerSession::~TestQuicSpdyServerSession() {} | 399 TestQuicSpdyServerSession::~TestQuicSpdyServerSession() { |
| 400 delete connection(); |
| 401 } |
| 396 | 402 |
| 397 QuicCryptoServerStreamBase* | 403 QuicCryptoServerStreamBase* |
| 398 TestQuicSpdyServerSession::CreateQuicCryptoServerStream( | 404 TestQuicSpdyServerSession::CreateQuicCryptoServerStream( |
| 399 const QuicCryptoServerConfig* crypto_config, | 405 const QuicCryptoServerConfig* crypto_config, |
| 400 QuicCompressedCertsCache* compressed_certs_cache) { | 406 QuicCompressedCertsCache* compressed_certs_cache) { |
| 401 return new QuicCryptoServerStream(crypto_config, compressed_certs_cache, | 407 return new QuicCryptoServerStream(crypto_config, compressed_certs_cache, |
| 402 FLAGS_enable_quic_stateless_reject_support, | 408 FLAGS_enable_quic_stateless_reject_support, |
| 403 this); | 409 this); |
| 404 } | 410 } |
| 405 | 411 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 return hex; | 501 return hex; |
| 496 } | 502 } |
| 497 | 503 |
| 498 } // namespace | 504 } // namespace |
| 499 | 505 |
| 500 IPAddress TestPeerIPAddress() { | 506 IPAddress TestPeerIPAddress() { |
| 501 return Loopback4(); | 507 return Loopback4(); |
| 502 } | 508 } |
| 503 | 509 |
| 504 QuicVersion QuicVersionMax() { | 510 QuicVersion QuicVersionMax() { |
| 505 return QuicSupportedVersions().front(); | 511 return AllSupportedVersions().front(); |
| 506 } | 512 } |
| 507 | 513 |
| 508 QuicVersion QuicVersionMin() { | 514 QuicVersion QuicVersionMin() { |
| 509 return QuicSupportedVersions().back(); | 515 return AllSupportedVersions().back(); |
| 510 } | 516 } |
| 511 | 517 |
| 512 IPAddress Loopback4() { | 518 IPAddress Loopback4() { |
| 513 return IPAddress::IPv4Localhost(); | 519 return IPAddress::IPv4Localhost(); |
| 514 } | 520 } |
| 515 | 521 |
| 516 IPAddress Loopback6() { | 522 IPAddress Loopback6() { |
| 517 return IPAddress::IPv6Localhost(); | 523 return IPAddress::IPv6Localhost(); |
| 518 } | 524 } |
| 519 | 525 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 header.public_header.packet_number_length = packet_number_length; | 600 header.public_header.packet_number_length = packet_number_length; |
| 595 header.path_id = path_id; | 601 header.path_id = path_id; |
| 596 header.packet_number = packet_number; | 602 header.packet_number = packet_number; |
| 597 header.entropy_flag = false; | 603 header.entropy_flag = false; |
| 598 header.entropy_hash = 0; | 604 header.entropy_hash = 0; |
| 599 header.fec_flag = false; | 605 header.fec_flag = false; |
| 600 QuicStreamFrame stream_frame(1, false, 0, StringPiece(data)); | 606 QuicStreamFrame stream_frame(1, false, 0, StringPiece(data)); |
| 601 QuicFrame frame(&stream_frame); | 607 QuicFrame frame(&stream_frame); |
| 602 QuicFrames frames; | 608 QuicFrames frames; |
| 603 frames.push_back(frame); | 609 frames.push_back(frame); |
| 604 QuicFramer framer(versions != nullptr ? *versions : QuicSupportedVersions(), | 610 QuicFramer framer( |
| 605 QuicTime::Zero(), perspective); | 611 versions != nullptr ? *versions : CurrentSupportedVersions(), |
| 612 QuicTime::Zero(), perspective); |
| 606 | 613 |
| 607 std::unique_ptr<QuicPacket> packet( | 614 std::unique_ptr<QuicPacket> packet( |
| 608 BuildUnsizedDataPacket(&framer, header, frames)); | 615 BuildUnsizedDataPacket(&framer, header, frames)); |
| 609 EXPECT_TRUE(packet != nullptr); | 616 EXPECT_TRUE(packet != nullptr); |
| 610 char* buffer = new char[kMaxPacketSize]; | 617 char* buffer = new char[kMaxPacketSize]; |
| 611 size_t encrypted_length = framer.EncryptPayload( | 618 size_t encrypted_length = framer.EncryptPayload( |
| 612 ENCRYPTION_NONE, path_id, packet_number, *packet, buffer, kMaxPacketSize); | 619 ENCRYPTION_NONE, path_id, packet_number, *packet, buffer, kMaxPacketSize); |
| 613 EXPECT_NE(0u, encrypted_length); | 620 EXPECT_NE(0u, encrypted_length); |
| 614 return new QuicEncryptedPacket(buffer, encrypted_length, true); | 621 return new QuicEncryptedPacket(buffer, encrypted_length, true); |
| 615 } | 622 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 644 header.public_header.packet_number_length = packet_number_length; | 651 header.public_header.packet_number_length = packet_number_length; |
| 645 header.path_id = path_id; | 652 header.path_id = path_id; |
| 646 header.packet_number = packet_number; | 653 header.packet_number = packet_number; |
| 647 header.entropy_flag = false; | 654 header.entropy_flag = false; |
| 648 header.entropy_hash = 0; | 655 header.entropy_hash = 0; |
| 649 header.fec_flag = false; | 656 header.fec_flag = false; |
| 650 QuicStreamFrame stream_frame(1, false, 0, StringPiece(data)); | 657 QuicStreamFrame stream_frame(1, false, 0, StringPiece(data)); |
| 651 QuicFrame frame(&stream_frame); | 658 QuicFrame frame(&stream_frame); |
| 652 QuicFrames frames; | 659 QuicFrames frames; |
| 653 frames.push_back(frame); | 660 frames.push_back(frame); |
| 654 QuicFramer framer(versions != nullptr ? *versions : QuicSupportedVersions(), | 661 QuicFramer framer(versions != nullptr ? *versions : AllSupportedVersions(), |
| 655 QuicTime::Zero(), perspective); | 662 QuicTime::Zero(), perspective); |
| 656 | 663 |
| 657 std::unique_ptr<QuicPacket> packet( | 664 std::unique_ptr<QuicPacket> packet( |
| 658 BuildUnsizedDataPacket(&framer, header, frames)); | 665 BuildUnsizedDataPacket(&framer, header, frames)); |
| 659 EXPECT_TRUE(packet != nullptr); | 666 EXPECT_TRUE(packet != nullptr); |
| 660 | 667 |
| 661 if (framer.version() <= QUIC_VERSION_33) { | 668 if (framer.version() <= QUIC_VERSION_33) { |
| 662 // Now set the packet's private flags byte to 0xFF, which is an invalid | 669 // Now set the packet's private flags byte to 0xFF, which is an invalid |
| 663 // value. | 670 // value. |
| 664 reinterpret_cast<unsigned char*>( | 671 reinterpret_cast<unsigned char*>( |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 return true; | 730 return true; |
| 724 } | 731 } |
| 725 | 732 |
| 726 static QuicPacket* ConstructPacketFromHandshakeMessage( | 733 static QuicPacket* ConstructPacketFromHandshakeMessage( |
| 727 QuicConnectionId connection_id, | 734 QuicConnectionId connection_id, |
| 728 const CryptoHandshakeMessage& message, | 735 const CryptoHandshakeMessage& message, |
| 729 bool should_include_version) { | 736 bool should_include_version) { |
| 730 CryptoFramer crypto_framer; | 737 CryptoFramer crypto_framer; |
| 731 std::unique_ptr<QuicData> data( | 738 std::unique_ptr<QuicData> data( |
| 732 crypto_framer.ConstructHandshakeMessage(message)); | 739 crypto_framer.ConstructHandshakeMessage(message)); |
| 733 QuicFramer quic_framer(QuicSupportedVersions(), QuicTime::Zero(), | 740 QuicFramer quic_framer(AllSupportedVersions(), QuicTime::Zero(), |
| 734 Perspective::IS_CLIENT); | 741 Perspective::IS_CLIENT); |
| 735 | 742 |
| 736 QuicPacketHeader header; | 743 QuicPacketHeader header; |
| 737 header.public_header.connection_id = connection_id; | 744 header.public_header.connection_id = connection_id; |
| 738 header.public_header.reset_flag = false; | 745 header.public_header.reset_flag = false; |
| 739 header.public_header.version_flag = should_include_version; | 746 header.public_header.version_flag = should_include_version; |
| 740 header.packet_number = 1; | 747 header.packet_number = 1; |
| 741 header.entropy_flag = false; | 748 header.entropy_flag = false; |
| 742 header.entropy_hash = 0; | 749 header.entropy_hash = 0; |
| 743 header.fec_flag = false; | 750 header.fec_flag = false; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 // strike register worries that we've just overflowed a uint32_t time. | 900 // strike register worries that we've just overflowed a uint32_t time. |
| 894 (*server_connection)->AdvanceTime(connection_start_time); | 901 (*server_connection)->AdvanceTime(connection_start_time); |
| 895 } | 902 } |
| 896 | 903 |
| 897 QuicStreamId QuicClientDataStreamId(int i) { | 904 QuicStreamId QuicClientDataStreamId(int i) { |
| 898 return kClientDataStreamId1 + 2 * i; | 905 return kClientDataStreamId1 + 2 * i; |
| 899 } | 906 } |
| 900 | 907 |
| 901 } // namespace test | 908 } // namespace test |
| 902 } // namespace net | 909 } // namespace net |
| OLD | NEW |