| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "net/quic/core/crypto/crypto_framer.h" | 10 #include "net/quic/core/crypto/crypto_framer.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 packet_size += frame_size; | 65 packet_size += frame_size; |
| 66 } | 66 } |
| 67 return BuildUnsizedDataPacket(framer, header, frames, packet_size); | 67 return BuildUnsizedDataPacket(framer, header, frames, packet_size); |
| 68 } | 68 } |
| 69 | 69 |
| 70 QuicPacket* BuildUnsizedDataPacket(QuicFramer* framer, | 70 QuicPacket* BuildUnsizedDataPacket(QuicFramer* framer, |
| 71 const QuicPacketHeader& header, | 71 const QuicPacketHeader& header, |
| 72 const QuicFrames& frames, | 72 const QuicFrames& frames, |
| 73 size_t packet_size) { | 73 size_t packet_size) { |
| 74 char* buffer = new char[packet_size]; | 74 char* buffer = new char[packet_size]; |
| 75 size_t length = framer->BuildDataPacket(header, frames, buffer, packet_size); | 75 size_t length = |
| 76 framer->BuildDataPacket(header, frames, buffer, packet_size, nullptr); |
| 76 DCHECK_NE(0u, length); | 77 DCHECK_NE(0u, length); |
| 77 // Re-construct the data packet with data ownership. | 78 // Re-construct the data packet with data ownership. |
| 78 return new QuicPacket(buffer, length, /* owns_buffer */ true, | 79 return new QuicPacket(buffer, length, /* owns_buffer */ true, |
| 79 header.public_header.connection_id_length, | 80 header.public_header.connection_id_length, |
| 80 header.public_header.version_flag, | 81 header.public_header.version_flag, |
| 81 header.public_header.nonce != nullptr, | 82 header.public_header.nonce != nullptr, |
| 82 header.public_header.packet_number_length); | 83 header.public_header.packet_number_length); |
| 83 } | 84 } |
| 84 | 85 |
| 85 string Sha1Hash(QuicStringPiece data) { | 86 string Sha1Hash(QuicStringPiece data) { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 205 } |
| 205 | 206 |
| 206 bool NoOpFramerVisitor::OnBlockedFrame(const QuicBlockedFrame& frame) { | 207 bool NoOpFramerVisitor::OnBlockedFrame(const QuicBlockedFrame& frame) { |
| 207 return true; | 208 return true; |
| 208 } | 209 } |
| 209 | 210 |
| 210 MockQuicConnectionVisitor::MockQuicConnectionVisitor() {} | 211 MockQuicConnectionVisitor::MockQuicConnectionVisitor() {} |
| 211 | 212 |
| 212 MockQuicConnectionVisitor::~MockQuicConnectionVisitor() {} | 213 MockQuicConnectionVisitor::~MockQuicConnectionVisitor() {} |
| 213 | 214 |
| 215 void MockQuicConnectionVisitor::SaveStreamData(QuicStreamId id, |
| 216 QuicIOVector iov, |
| 217 size_t iov_offset, |
| 218 QuicStreamOffset offset, |
| 219 QuicByteCount data_length) { |
| 220 producer_.SaveStreamData(id, iov, iov_offset, offset, data_length); |
| 221 } |
| 222 bool MockQuicConnectionVisitor::WriteStreamData(QuicStreamId id, |
| 223 QuicStreamOffset offset, |
| 224 QuicByteCount data_length, |
| 225 QuicDataWriter* writer) { |
| 226 return producer_.WriteStreamData(id, offset, data_length, writer); |
| 227 } |
| 228 |
| 214 MockQuicConnectionHelper::MockQuicConnectionHelper() {} | 229 MockQuicConnectionHelper::MockQuicConnectionHelper() {} |
| 215 | 230 |
| 216 MockQuicConnectionHelper::~MockQuicConnectionHelper() {} | 231 MockQuicConnectionHelper::~MockQuicConnectionHelper() {} |
| 217 | 232 |
| 218 const QuicClock* MockQuicConnectionHelper::GetClock() const { | 233 const QuicClock* MockQuicConnectionHelper::GetClock() const { |
| 219 return &clock_; | 234 return &clock_; |
| 220 } | 235 } |
| 221 | 236 |
| 222 QuicRandom* MockQuicConnectionHelper::GetRandomGenerator() { | 237 QuicRandom* MockQuicConnectionHelper::GetRandomGenerator() { |
| 223 return &random_generator_; | 238 return &random_generator_; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 QuicStream* /*stream*/, | 387 QuicStream* /*stream*/, |
| 373 QuicStreamId /*id*/, | 388 QuicStreamId /*id*/, |
| 374 const QuicIOVector& data, | 389 const QuicIOVector& data, |
| 375 QuicStreamOffset /*offset*/, | 390 QuicStreamOffset /*offset*/, |
| 376 StreamSendingState state, | 391 StreamSendingState state, |
| 377 const QuicReferenceCountedPointer< | 392 const QuicReferenceCountedPointer< |
| 378 QuicAckListenerInterface>& /*ack_listener*/) { | 393 QuicAckListenerInterface>& /*ack_listener*/) { |
| 379 return QuicConsumedData(data.total_length, state != NO_FIN); | 394 return QuicConsumedData(data.total_length, state != NO_FIN); |
| 380 } | 395 } |
| 381 | 396 |
| 397 QuicConsumedData MockQuicSession::ConsumeAndSaveAllData( |
| 398 QuicStream* stream, |
| 399 QuicStreamId id, |
| 400 const QuicIOVector& data, |
| 401 QuicStreamOffset offset, |
| 402 StreamSendingState state, |
| 403 const QuicReferenceCountedPointer<QuicAckListenerInterface>& ack_listener) { |
| 404 QuicConsumedData consumed = |
| 405 QuicConsumedData(data.total_length, state != NO_FIN); |
| 406 if (streams_own_data() && data.total_length > 0) { |
| 407 SaveStreamData(id, data, 0, offset, data.total_length); |
| 408 } |
| 409 return consumed; |
| 410 } |
| 411 |
| 382 MockQuicSpdySession::MockQuicSpdySession(QuicConnection* connection) | 412 MockQuicSpdySession::MockQuicSpdySession(QuicConnection* connection) |
| 383 : QuicSpdySession(connection, nullptr, DefaultQuicConfig()) { | 413 : QuicSpdySession(connection, nullptr, DefaultQuicConfig()) { |
| 384 crypto_stream_.reset(new QuicCryptoStream(this)); | 414 crypto_stream_.reset(new QuicCryptoStream(this)); |
| 385 Initialize(); | 415 Initialize(); |
| 386 ON_CALL(*this, WritevData(_, _, _, _, _, _)) | 416 ON_CALL(*this, WritevData(_, _, _, _, _, _)) |
| 387 .WillByDefault(testing::Return(QuicConsumedData(0, false))); | 417 .WillByDefault(testing::Return(QuicConsumedData(0, false))); |
| 388 } | 418 } |
| 389 | 419 |
| 390 MockQuicSpdySession::~MockQuicSpdySession() { | 420 MockQuicSpdySession::~MockQuicSpdySession() { |
| 391 delete connection(); | 421 delete connection(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 402 size_t MockQuicSpdySession::WriteHeaders( | 432 size_t MockQuicSpdySession::WriteHeaders( |
| 403 QuicStreamId id, | 433 QuicStreamId id, |
| 404 SpdyHeaderBlock headers, | 434 SpdyHeaderBlock headers, |
| 405 bool fin, | 435 bool fin, |
| 406 SpdyPriority priority, | 436 SpdyPriority priority, |
| 407 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { | 437 QuicReferenceCountedPointer<QuicAckListenerInterface> ack_listener) { |
| 408 write_headers_ = std::move(headers); | 438 write_headers_ = std::move(headers); |
| 409 return WriteHeadersMock(id, write_headers_, fin, priority, ack_listener); | 439 return WriteHeadersMock(id, write_headers_, fin, priority, ack_listener); |
| 410 } | 440 } |
| 411 | 441 |
| 442 QuicConsumedData MockQuicSpdySession::ConsumeAndSaveAllData( |
| 443 QuicStream* stream, |
| 444 QuicStreamId id, |
| 445 const QuicIOVector& data, |
| 446 QuicStreamOffset offset, |
| 447 StreamSendingState state, |
| 448 const QuicReferenceCountedPointer<QuicAckListenerInterface>& ack_listener) { |
| 449 QuicConsumedData consumed = |
| 450 QuicConsumedData(data.total_length, state != NO_FIN); |
| 451 if (streams_own_data() && data.total_length > 0) { |
| 452 SaveStreamData(id, data, 0, offset, data.total_length); |
| 453 } |
| 454 return consumed; |
| 455 } |
| 456 |
| 412 TestQuicSpdyServerSession::TestQuicSpdyServerSession( | 457 TestQuicSpdyServerSession::TestQuicSpdyServerSession( |
| 413 QuicConnection* connection, | 458 QuicConnection* connection, |
| 414 const QuicConfig& config, | 459 const QuicConfig& config, |
| 415 const QuicCryptoServerConfig* crypto_config, | 460 const QuicCryptoServerConfig* crypto_config, |
| 416 QuicCompressedCertsCache* compressed_certs_cache) | 461 QuicCompressedCertsCache* compressed_certs_cache) |
| 417 : QuicServerSessionBase(config, | 462 : QuicServerSessionBase(config, |
| 418 connection, | 463 connection, |
| 419 &visitor_, | 464 &visitor_, |
| 420 &helper_, | 465 &helper_, |
| 421 crypto_config, | 466 crypto_config, |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 | 831 |
| 787 MockReceivedPacketManager::MockReceivedPacketManager(QuicConnectionStats* stats) | 832 MockReceivedPacketManager::MockReceivedPacketManager(QuicConnectionStats* stats) |
| 788 : QuicReceivedPacketManager(stats) {} | 833 : QuicReceivedPacketManager(stats) {} |
| 789 | 834 |
| 790 MockReceivedPacketManager::~MockReceivedPacketManager() {} | 835 MockReceivedPacketManager::~MockReceivedPacketManager() {} |
| 791 | 836 |
| 792 MockConnectionCloseDelegate::MockConnectionCloseDelegate() {} | 837 MockConnectionCloseDelegate::MockConnectionCloseDelegate() {} |
| 793 | 838 |
| 794 MockConnectionCloseDelegate::~MockConnectionCloseDelegate() {} | 839 MockConnectionCloseDelegate::~MockConnectionCloseDelegate() {} |
| 795 | 840 |
| 841 MockPacketCreatorDelegate::MockPacketCreatorDelegate() {} |
| 842 MockPacketCreatorDelegate::~MockPacketCreatorDelegate() {} |
| 843 |
| 844 void MockPacketCreatorDelegate::SaveStreamData(QuicStreamId id, |
| 845 QuicIOVector iov, |
| 846 size_t iov_offset, |
| 847 QuicStreamOffset offset, |
| 848 QuicByteCount data_length) { |
| 849 producer_.SaveStreamData(id, iov, iov_offset, offset, data_length); |
| 850 } |
| 851 |
| 852 bool MockPacketCreatorDelegate::WriteStreamData(QuicStreamId id, |
| 853 QuicStreamOffset offset, |
| 854 QuicByteCount data_length, |
| 855 QuicDataWriter* writer) { |
| 856 return producer_.WriteStreamData(id, offset, data_length, writer); |
| 857 } |
| 858 |
| 796 void CreateClientSessionForTest(QuicServerId server_id, | 859 void CreateClientSessionForTest(QuicServerId server_id, |
| 797 bool supports_stateless_rejects, | 860 bool supports_stateless_rejects, |
| 798 QuicTime::Delta connection_start_time, | 861 QuicTime::Delta connection_start_time, |
| 799 QuicVersionVector supported_versions, | 862 QuicVersionVector supported_versions, |
| 800 MockQuicConnectionHelper* helper, | 863 MockQuicConnectionHelper* helper, |
| 801 MockAlarmFactory* alarm_factory, | 864 MockAlarmFactory* alarm_factory, |
| 802 QuicCryptoClientConfig* crypto_client_config, | 865 QuicCryptoClientConfig* crypto_client_config, |
| 803 PacketSavingConnection** client_connection, | 866 PacketSavingConnection** client_connection, |
| 804 TestQuicSpdyClientSession** client_session) { | 867 TestQuicSpdyClientSession** client_session) { |
| 805 CHECK(crypto_client_config); | 868 CHECK(crypto_client_config); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 QuicStreamId GetNthClientInitiatedStreamId(QuicVersion version, int n) { | 919 QuicStreamId GetNthClientInitiatedStreamId(QuicVersion version, int n) { |
| 857 return 5 + NextStreamId(version) * n; | 920 return 5 + NextStreamId(version) * n; |
| 858 } | 921 } |
| 859 | 922 |
| 860 QuicStreamId GetNthServerInitiatedStreamId(QuicVersion version, int n) { | 923 QuicStreamId GetNthServerInitiatedStreamId(QuicVersion version, int n) { |
| 861 return 2 + NextStreamId(version) * n; | 924 return 2 + NextStreamId(version) * n; |
| 862 } | 925 } |
| 863 | 926 |
| 864 } // namespace test | 927 } // namespace test |
| 865 } // namespace net | 928 } // namespace net |
| OLD | NEW |