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/sha1.h" |
7 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
8 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
9 #include "net/quic/crypto/crypto_framer.h" | 10 #include "net/quic/crypto/crypto_framer.h" |
10 #include "net/quic/crypto/crypto_handshake.h" | 11 #include "net/quic/crypto/crypto_handshake.h" |
11 #include "net/quic/crypto/crypto_utils.h" | 12 #include "net/quic/crypto/crypto_utils.h" |
12 #include "net/quic/crypto/null_encrypter.h" | 13 #include "net/quic/crypto/null_encrypter.h" |
13 #include "net/quic/crypto/quic_decrypter.h" | 14 #include "net/quic/crypto/quic_decrypter.h" |
14 #include "net/quic/crypto/quic_encrypter.h" | 15 #include "net/quic/crypto/quic_encrypter.h" |
15 #include "net/quic/quic_framer.h" | 16 #include "net/quic/quic_framer.h" |
16 #include "net/quic/quic_packet_creator.h" | 17 #include "net/quic/quic_packet_creator.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 const size_t frame_size = framer->GetSerializedFrameLength( | 76 const size_t frame_size = framer->GetSerializedFrameLength( |
76 frames[i], max_plaintext_size - packet_size, first_frame, last_frame, | 77 frames[i], max_plaintext_size - packet_size, first_frame, last_frame, |
77 header.is_in_fec_group, | 78 header.is_in_fec_group, |
78 header.public_header.sequence_number_length); | 79 header.public_header.sequence_number_length); |
79 DCHECK(frame_size); | 80 DCHECK(frame_size); |
80 packet_size += frame_size; | 81 packet_size += frame_size; |
81 } | 82 } |
82 return framer->BuildDataPacket(header, frames, packet_size); | 83 return framer->BuildDataPacket(header, frames, packet_size); |
83 } | 84 } |
84 | 85 |
| 86 uint64 SimpleRandom::RandUint64() { |
| 87 unsigned char hash[base::kSHA1Length]; |
| 88 base::SHA1HashBytes(reinterpret_cast<unsigned char*>(&seed_), sizeof(seed_), |
| 89 hash); |
| 90 memcpy(&seed_, hash, sizeof(seed_)); |
| 91 return seed_; |
| 92 } |
| 93 |
85 MockFramerVisitor::MockFramerVisitor() { | 94 MockFramerVisitor::MockFramerVisitor() { |
86 // By default, we want to accept packets. | 95 // By default, we want to accept packets. |
87 ON_CALL(*this, OnProtocolVersionMismatch(_)) | 96 ON_CALL(*this, OnProtocolVersionMismatch(_)) |
88 .WillByDefault(testing::Return(false)); | 97 .WillByDefault(testing::Return(false)); |
89 | 98 |
90 // By default, we want to accept packets. | 99 // By default, we want to accept packets. |
91 ON_CALL(*this, OnUnauthenticatedHeader(_)) | 100 ON_CALL(*this, OnUnauthenticatedHeader(_)) |
92 .WillByDefault(testing::Return(true)); | 101 .WillByDefault(testing::Return(true)); |
93 | 102 |
94 ON_CALL(*this, OnUnauthenticatedPublicHeader(_)) | 103 ON_CALL(*this, OnUnauthenticatedPublicHeader(_)) |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 const SerializedPacket& packet, | 294 const SerializedPacket& packet, |
286 TransmissionType transmission_type) { | 295 TransmissionType transmission_type) { |
287 packets_.push_back(packet.packet); | 296 packets_.push_back(packet.packet); |
288 QuicEncryptedPacket* encrypted = QuicConnectionPeer::GetFramer(this)-> | 297 QuicEncryptedPacket* encrypted = QuicConnectionPeer::GetFramer(this)-> |
289 EncryptPacket(level, packet.sequence_number, *packet.packet); | 298 EncryptPacket(level, packet.sequence_number, *packet.packet); |
290 encrypted_packets_.push_back(encrypted); | 299 encrypted_packets_.push_back(encrypted); |
291 return true; | 300 return true; |
292 } | 301 } |
293 | 302 |
294 MockSession::MockSession(QuicConnection* connection) | 303 MockSession::MockSession(QuicConnection* connection) |
295 : QuicSession(connection, kInitialFlowControlWindowForTest, | 304 : QuicSession(connection, DefaultQuicConfig()) { |
296 DefaultQuicConfig()) { | |
297 ON_CALL(*this, WritevData(_, _, _, _, _, _)) | 305 ON_CALL(*this, WritevData(_, _, _, _, _, _)) |
298 .WillByDefault(testing::Return(QuicConsumedData(0, false))); | 306 .WillByDefault(testing::Return(QuicConsumedData(0, false))); |
299 } | 307 } |
300 | 308 |
301 MockSession::~MockSession() { | 309 MockSession::~MockSession() { |
302 } | 310 } |
303 | 311 |
304 TestSession::TestSession(QuicConnection* connection, const QuicConfig& config) | 312 TestSession::TestSession(QuicConnection* connection, const QuicConfig& config) |
305 : QuicSession(connection, kInitialFlowControlWindowForTest, config), | 313 : QuicSession(connection, config), |
306 crypto_stream_(NULL) {} | 314 crypto_stream_(NULL) {} |
307 | 315 |
308 TestSession::~TestSession() {} | 316 TestSession::~TestSession() {} |
309 | 317 |
310 void TestSession::SetCryptoStream(QuicCryptoStream* stream) { | 318 void TestSession::SetCryptoStream(QuicCryptoStream* stream) { |
311 crypto_stream_ = stream; | 319 crypto_stream_ = stream; |
312 } | 320 } |
313 | 321 |
314 QuicCryptoStream* TestSession::GetCryptoStream() { | 322 QuicCryptoStream* TestSession::GetCryptoStream() { |
315 return crypto_stream_; | 323 return crypto_stream_; |
316 } | 324 } |
317 | 325 |
318 TestClientSession::TestClientSession(QuicConnection* connection, | 326 TestClientSession::TestClientSession(QuicConnection* connection, |
319 const QuicConfig& config) | 327 const QuicConfig& config) |
320 : QuicClientSessionBase(connection, kInitialFlowControlWindowForTest, | 328 : QuicClientSessionBase(connection, |
321 config), | 329 config), |
322 crypto_stream_(NULL) { | 330 crypto_stream_(NULL) { |
323 EXPECT_CALL(*this, OnProofValid(_)).Times(AnyNumber()); | 331 EXPECT_CALL(*this, OnProofValid(_)).Times(AnyNumber()); |
324 } | 332 } |
325 | 333 |
326 TestClientSession::~TestClientSession() {} | 334 TestClientSession::~TestClientSession() {} |
327 | 335 |
328 void TestClientSession::SetCryptoStream(QuicCryptoStream* stream) { | 336 void TestClientSession::SetCryptoStream(QuicCryptoStream* stream) { |
329 crypto_stream_ = stream; | 337 crypto_stream_ = stream; |
330 } | 338 } |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 if (stream_length < ack_length) { | 563 if (stream_length < ack_length) { |
556 *payload_length = 1 + ack_length - stream_length; | 564 *payload_length = 1 + ack_length - stream_length; |
557 } | 565 } |
558 | 566 |
559 return NullEncrypter().GetCiphertextSize(*payload_length) + | 567 return NullEncrypter().GetCiphertextSize(*payload_length) + |
560 QuicPacketCreator::StreamFramePacketOverhead( | 568 QuicPacketCreator::StreamFramePacketOverhead( |
561 version, PACKET_8BYTE_CONNECTION_ID, include_version, | 569 version, PACKET_8BYTE_CONNECTION_ID, include_version, |
562 sequence_number_length, 0u, is_in_fec_group); | 570 sequence_number_length, 0u, is_in_fec_group); |
563 } | 571 } |
564 | 572 |
565 TestEntropyCalculator::TestEntropyCalculator() { } | 573 TestEntropyCalculator::TestEntropyCalculator() {} |
566 | 574 |
567 TestEntropyCalculator::~TestEntropyCalculator() { } | 575 TestEntropyCalculator::~TestEntropyCalculator() {} |
568 | 576 |
569 QuicPacketEntropyHash TestEntropyCalculator::EntropyHash( | 577 QuicPacketEntropyHash TestEntropyCalculator::EntropyHash( |
570 QuicPacketSequenceNumber sequence_number) const { | 578 QuicPacketSequenceNumber sequence_number) const { |
571 return 1u; | 579 return 1u; |
572 } | 580 } |
573 | 581 |
574 MockEntropyCalculator::MockEntropyCalculator() { } | 582 MockEntropyCalculator::MockEntropyCalculator() {} |
575 | 583 |
576 MockEntropyCalculator::~MockEntropyCalculator() { } | 584 MockEntropyCalculator::~MockEntropyCalculator() {} |
577 | 585 |
578 QuicConfig DefaultQuicConfig() { | 586 QuicConfig DefaultQuicConfig() { |
579 QuicConfig config; | 587 QuicConfig config; |
580 config.SetDefaults(); | 588 config.SetDefaults(); |
| 589 config.SetInitialFlowControlWindowToSend(kInitialFlowControlWindowForTest); |
581 return config; | 590 return config; |
582 } | 591 } |
583 | 592 |
584 QuicVersionVector SupportedVersions(QuicVersion version) { | 593 QuicVersionVector SupportedVersions(QuicVersion version) { |
585 QuicVersionVector versions; | 594 QuicVersionVector versions; |
586 versions.push_back(version); | 595 versions.push_back(version); |
587 return versions; | 596 return versions; |
588 } | 597 } |
589 | 598 |
590 } // namespace test | 599 } // namespace test |
591 } // namespace net | 600 } // namespace net |
OLD | NEW |