| 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 "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "net/quic/crypto/crypto_framer.h" | 8 #include "net/quic/crypto/crypto_framer.h" |
| 9 #include "net/quic/crypto/crypto_handshake.h" | 9 #include "net/quic/crypto/crypto_handshake.h" |
| 10 #include "net/quic/crypto/crypto_utils.h" | 10 #include "net/quic/crypto/crypto_utils.h" |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 QuicPacketEntropyHash entropy_hash, | 228 QuicPacketEntropyHash entropy_hash, |
| 229 HasRetransmittableData retransmittable) { | 229 HasRetransmittableData retransmittable) { |
| 230 packets_.push_back(packet); | 230 packets_.push_back(packet); |
| 231 QuicEncryptedPacket* encrypted = | 231 QuicEncryptedPacket* encrypted = |
| 232 framer_.EncryptPacket(level, sequence_number, *packet); | 232 framer_.EncryptPacket(level, sequence_number, *packet); |
| 233 encrypted_packets_.push_back(encrypted); | 233 encrypted_packets_.push_back(encrypted); |
| 234 return true; | 234 return true; |
| 235 } | 235 } |
| 236 | 236 |
| 237 MockSession::MockSession(QuicConnection* connection, bool is_server) | 237 MockSession::MockSession(QuicConnection* connection, bool is_server) |
| 238 : QuicSession(connection, QuicConfig(), is_server) { | 238 : QuicSession(connection, DefaultQuicConfig(), is_server) { |
| 239 ON_CALL(*this, WriteData(_, _, _, _)) | 239 ON_CALL(*this, WriteData(_, _, _, _)) |
| 240 .WillByDefault(testing::Return(QuicConsumedData(0, false))); | 240 .WillByDefault(testing::Return(QuicConsumedData(0, false))); |
| 241 } | 241 } |
| 242 | 242 |
| 243 MockSession::~MockSession() { | 243 MockSession::~MockSession() { |
| 244 } | 244 } |
| 245 | 245 |
| 246 TestSession::TestSession(QuicConnection* connection, | 246 TestSession::TestSession(QuicConnection* connection, |
| 247 const QuicConfig& config, | 247 const QuicConfig& config, |
| 248 bool is_server) | 248 bool is_server) |
| 249 : QuicSession(connection, config, is_server), | 249 : QuicSession(connection, config, is_server), |
| 250 crypto_stream_(NULL) { | 250 crypto_stream_(NULL) { |
| 251 } | 251 } |
| 252 | 252 |
| 253 TestSession::~TestSession() { | 253 TestSession::~TestSession() {} |
| 254 } | |
| 255 | 254 |
| 256 void TestSession::SetCryptoStream(QuicCryptoStream* stream) { | 255 void TestSession::SetCryptoStream(QuicCryptoStream* stream) { |
| 257 crypto_stream_ = stream; | 256 crypto_stream_ = stream; |
| 258 } | 257 } |
| 259 | 258 |
| 260 QuicCryptoStream* TestSession::GetCryptoStream() { | 259 QuicCryptoStream* TestSession::GetCryptoStream() { |
| 261 return crypto_stream_; | 260 return crypto_stream_; |
| 262 } | 261 } |
| 263 | 262 |
| 264 MockSendAlgorithm::MockSendAlgorithm() { | 263 MockSendAlgorithm::MockSendAlgorithm() { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 QuicFramer quic_framer(kQuicVersion1, QuicTime::Zero(), false); | 357 QuicFramer quic_framer(kQuicVersion1, QuicTime::Zero(), false); |
| 359 | 358 |
| 360 QuicPacketHeader header; | 359 QuicPacketHeader header; |
| 361 header.public_header.guid = guid; | 360 header.public_header.guid = guid; |
| 362 header.public_header.reset_flag = false; | 361 header.public_header.reset_flag = false; |
| 363 header.public_header.version_flag = should_include_version; | 362 header.public_header.version_flag = should_include_version; |
| 364 header.packet_sequence_number = 1; | 363 header.packet_sequence_number = 1; |
| 365 header.entropy_flag = false; | 364 header.entropy_flag = false; |
| 366 header.entropy_hash = 0; | 365 header.entropy_hash = 0; |
| 367 header.fec_flag = false; | 366 header.fec_flag = false; |
| 368 header.fec_entropy_flag = false; | |
| 369 header.fec_group = 0; | 367 header.fec_group = 0; |
| 370 | 368 |
| 371 QuicStreamFrame stream_frame(kCryptoStreamId, false, 0, | 369 QuicStreamFrame stream_frame(kCryptoStreamId, false, 0, |
| 372 data->AsStringPiece()); | 370 data->AsStringPiece()); |
| 373 | 371 |
| 374 QuicFrame frame(&stream_frame); | 372 QuicFrame frame(&stream_frame); |
| 375 QuicFrames frames; | 373 QuicFrames frames; |
| 376 frames.push_back(frame); | 374 frames.push_back(frame); |
| 377 return quic_framer.ConstructFrameDataPacket(header, frames).packet; | 375 return quic_framer.ConstructFrameDataPacket(header, frames).packet; |
| 378 } | 376 } |
| 379 | 377 |
| 380 QuicPacket* ConstructHandshakePacket(QuicGuid guid, QuicTag tag) { | 378 QuicPacket* ConstructHandshakePacket(QuicGuid guid, QuicTag tag) { |
| 381 CryptoHandshakeMessage message; | 379 CryptoHandshakeMessage message; |
| 382 message.set_tag(tag); | 380 message.set_tag(tag); |
| 383 return ConstructPacketFromHandshakeMessage(guid, message, false); | 381 return ConstructPacketFromHandshakeMessage(guid, message, false); |
| 384 } | 382 } |
| 385 | 383 |
| 386 size_t GetPacketLengthForOneStream(bool include_version, size_t payload) { | 384 size_t GetPacketLengthForOneStream( |
| 385 bool include_version, InFecGroup is_in_fec_group, size_t payload) { |
| 387 // TODO(wtc): the hardcoded use of NullEncrypter here seems wrong. | 386 // TODO(wtc): the hardcoded use of NullEncrypter here seems wrong. |
| 388 size_t packet_length = NullEncrypter().GetCiphertextSize(payload) + | 387 size_t packet_length = NullEncrypter().GetCiphertextSize(payload) + |
| 389 QuicPacketCreator::StreamFramePacketOverhead(1, include_version); | 388 QuicPacketCreator::StreamFramePacketOverhead( |
| 389 1, PACKET_8BYTE_GUID, include_version, is_in_fec_group); |
| 390 | 390 |
| 391 size_t ack_length = NullEncrypter().GetCiphertextSize( | 391 size_t ack_length = NullEncrypter().GetCiphertextSize( |
| 392 QuicFramer::GetMinAckFrameSize()) + GetPacketHeaderSize(include_version); | 392 QuicFramer::GetMinAckFrameSize()) + |
| 393 GetPacketHeaderSize(PACKET_8BYTE_GUID, include_version, is_in_fec_group); |
| 393 // Make sure that if we change the size of the packet length for one stream | 394 // Make sure that if we change the size of the packet length for one stream |
| 394 // or the ack frame; that all our test are configured correctly. | 395 // or the ack frame; that all our test are configured correctly. |
| 395 DCHECK_GE(packet_length, ack_length); | 396 DCHECK_GE(packet_length, ack_length); |
| 396 return packet_length; | 397 return packet_length; |
| 397 } | 398 } |
| 398 | 399 |
| 399 QuicPacketEntropyHash TestEntropyCalculator::ReceivedEntropyHash( | 400 QuicPacketEntropyHash TestEntropyCalculator::ReceivedEntropyHash( |
| 400 QuicPacketSequenceNumber sequence_number) const { | 401 QuicPacketSequenceNumber sequence_number) const { |
| 401 return 1u; | 402 return 1u; |
| 402 } | 403 } |
| 403 | 404 |
| 405 QuicConfig DefaultQuicConfig() { |
| 406 QuicConfig config; |
| 407 config.SetDefaults(); |
| 408 return config; |
| 409 } |
| 410 |
| 404 bool TestDecompressorVisitor::OnDecompressedData(StringPiece data) { | 411 bool TestDecompressorVisitor::OnDecompressedData(StringPiece data) { |
| 405 data.AppendToString(&data_); | 412 data.AppendToString(&data_); |
| 406 return true; | 413 return true; |
| 407 } | 414 } |
| 408 | 415 |
| 409 void TestDecompressorVisitor::OnDecompressionError() { | 416 void TestDecompressorVisitor::OnDecompressionError() { |
| 410 error_ = true; | 417 error_ = true; |
| 411 } | 418 } |
| 412 | 419 |
| 413 } // namespace test | 420 } // namespace test |
| 414 } // namespace net | 421 } // namespace net |
| OLD | NEW |