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

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

Issue 14287009: Land Recent QUIC Changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with Tot Created 7 years, 8 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/quic/test_tools/simple_quic_framer.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 "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"
11 #include "net/quic/crypto/null_encrypter.h" 11 #include "net/quic/crypto/null_encrypter.h"
12 #include "net/quic/crypto/quic_decrypter.h" 12 #include "net/quic/crypto/quic_decrypter.h"
13 #include "net/quic/crypto/quic_encrypter.h" 13 #include "net/quic/crypto/quic_encrypter.h"
14 #include "net/quic/quic_framer.h"
14 #include "net/quic/quic_packet_creator.h" 15 #include "net/quic/quic_packet_creator.h"
15 16
16 using std::max; 17 using std::max;
17 using std::min; 18 using std::min;
18 using std::string; 19 using std::string;
19 using testing::_; 20 using testing::_;
20 21
21 namespace net { 22 namespace net {
22 namespace test { 23 namespace test {
23 24
24 MockFramerVisitor::MockFramerVisitor() { 25 MockFramerVisitor::MockFramerVisitor() {
25 // By default, we want to accept packets. 26 // By default, we want to accept packets.
26 ON_CALL(*this, OnProtocolVersionMismatch(_)) 27 ON_CALL(*this, OnProtocolVersionMismatch(_))
27 .WillByDefault(testing::Return(false)); 28 .WillByDefault(testing::Return(false));
28 29
29 // By default, we want to accept packets. 30 // By default, we want to accept packets.
30 ON_CALL(*this, OnPacketHeader(_)) 31 ON_CALL(*this, OnPacketHeader(_))
31 .WillByDefault(testing::Return(true)); 32 .WillByDefault(testing::Return(true));
33
34 ON_CALL(*this, OnStreamFrame(_))
35 .WillByDefault(testing::Return(true));
36
37 ON_CALL(*this, OnAckFrame(_))
38 .WillByDefault(testing::Return(true));
39
40 ON_CALL(*this, OnCongestionFeedbackFrame(_))
41 .WillByDefault(testing::Return(true));
42
43 ON_CALL(*this, OnRstStreamFrame(_))
44 .WillByDefault(testing::Return(true));
45
46 ON_CALL(*this, OnConnectionCloseFrame(_))
47 .WillByDefault(testing::Return(true));
48
49 ON_CALL(*this, OnGoAwayFrame(_))
50 .WillByDefault(testing::Return(true));
32 } 51 }
33 52
34 MockFramerVisitor::~MockFramerVisitor() { 53 MockFramerVisitor::~MockFramerVisitor() {
35 } 54 }
36 55
37 bool NoOpFramerVisitor::OnProtocolVersionMismatch(QuicVersionTag version) { 56 bool NoOpFramerVisitor::OnProtocolVersionMismatch(QuicVersionTag version) {
38 return false; 57 return false;
39 } 58 }
40 59
41 bool NoOpFramerVisitor::OnPacketHeader(const QuicPacketHeader& header) { 60 bool NoOpFramerVisitor::OnPacketHeader(const QuicPacketHeader& header) {
42 return true; 61 return true;
43 } 62 }
44 63
64 bool NoOpFramerVisitor::OnStreamFrame(const QuicStreamFrame& frame) {
65 return true;
66 }
67
68 bool NoOpFramerVisitor::OnAckFrame(const QuicAckFrame& frame) {
69 return true;
70 }
71
72 bool NoOpFramerVisitor::OnCongestionFeedbackFrame(
73 const QuicCongestionFeedbackFrame& frame) {
74 return true;
75 }
76
77 bool NoOpFramerVisitor::OnRstStreamFrame(
78 const QuicRstStreamFrame& frame) {
79 return true;
80 }
81
82 bool NoOpFramerVisitor::OnConnectionCloseFrame(
83 const QuicConnectionCloseFrame& frame) {
84 return true;
85 }
86
87 bool NoOpFramerVisitor::OnGoAwayFrame(const QuicGoAwayFrame& frame) {
88 return true;
89 }
90
45 FramerVisitorCapturingFrames::FramerVisitorCapturingFrames() : frame_count_(0) { 91 FramerVisitorCapturingFrames::FramerVisitorCapturingFrames() : frame_count_(0) {
46 } 92 }
47 93
48 FramerVisitorCapturingFrames::~FramerVisitorCapturingFrames() { 94 FramerVisitorCapturingFrames::~FramerVisitorCapturingFrames() {
49 } 95 }
50 96
51 bool FramerVisitorCapturingFrames::OnPacketHeader( 97 bool FramerVisitorCapturingFrames::OnPacketHeader(
52 const QuicPacketHeader& header) { 98 const QuicPacketHeader& header) {
53 header_ = header; 99 header_ = header;
54 frame_count_ = 0; 100 frame_count_ = 0;
55 return true; 101 return true;
56 } 102 }
57 103
58 void FramerVisitorCapturingFrames::OnStreamFrame(const QuicStreamFrame& frame) { 104 bool FramerVisitorCapturingFrames::OnStreamFrame(const QuicStreamFrame& frame) {
59 // TODO(ianswett): Own the underlying string, so it will not exist outside 105 // TODO(ianswett): Own the underlying string, so it will not exist outside
60 // this callback. 106 // this callback.
61 stream_frames_.push_back(frame); 107 stream_frames_.push_back(frame);
62 ++frame_count_; 108 ++frame_count_;
109 return true;
63 } 110 }
64 111
65 void FramerVisitorCapturingFrames::OnAckFrame(const QuicAckFrame& frame) { 112 bool FramerVisitorCapturingFrames::OnAckFrame(const QuicAckFrame& frame) {
66 ack_.reset(new QuicAckFrame(frame)); 113 ack_.reset(new QuicAckFrame(frame));
67 ++frame_count_; 114 ++frame_count_;
115 return true;
68 } 116 }
69 117
70 void FramerVisitorCapturingFrames::OnCongestionFeedbackFrame( 118 bool FramerVisitorCapturingFrames::OnCongestionFeedbackFrame(
71 const QuicCongestionFeedbackFrame& frame) { 119 const QuicCongestionFeedbackFrame& frame) {
72 feedback_.reset(new QuicCongestionFeedbackFrame(frame)); 120 feedback_.reset(new QuicCongestionFeedbackFrame(frame));
73 ++frame_count_; 121 ++frame_count_;
122 return true;
74 } 123 }
75 124
76 void FramerVisitorCapturingFrames::OnRstStreamFrame( 125 bool FramerVisitorCapturingFrames::OnRstStreamFrame(
77 const QuicRstStreamFrame& frame) { 126 const QuicRstStreamFrame& frame) {
78 rst_.reset(new QuicRstStreamFrame(frame)); 127 rst_.reset(new QuicRstStreamFrame(frame));
79 ++frame_count_; 128 ++frame_count_;
129 return true;
80 } 130 }
81 131
82 void FramerVisitorCapturingFrames::OnConnectionCloseFrame( 132 bool FramerVisitorCapturingFrames::OnConnectionCloseFrame(
83 const QuicConnectionCloseFrame& frame) { 133 const QuicConnectionCloseFrame& frame) {
84 close_.reset(new QuicConnectionCloseFrame(frame)); 134 close_.reset(new QuicConnectionCloseFrame(frame));
85 ++frame_count_; 135 ++frame_count_;
136 return true;
86 } 137 }
87 138
88 void FramerVisitorCapturingFrames::OnGoAwayFrame(const QuicGoAwayFrame& frame) { 139 bool FramerVisitorCapturingFrames::OnGoAwayFrame(const QuicGoAwayFrame& frame) {
89 goaway_.reset(new QuicGoAwayFrame(frame)); 140 goaway_.reset(new QuicGoAwayFrame(frame));
90 ++frame_count_; 141 ++frame_count_;
142 return true;
91 } 143 }
92 144
93 void FramerVisitorCapturingFrames::OnVersionNegotiationPacket( 145 void FramerVisitorCapturingFrames::OnVersionNegotiationPacket(
94 const QuicVersionNegotiationPacket& packet) { 146 const QuicVersionNegotiationPacket& packet) {
95 version_negotiation_packet_.reset(new QuicVersionNegotiationPacket(packet)); 147 version_negotiation_packet_.reset(new QuicVersionNegotiationPacket(packet));
96 frame_count_ = 0; 148 frame_count_ = 0;
97 } 149 }
98 150
99 FramerVisitorCapturingPublicReset::FramerVisitorCapturingPublicReset() { 151 FramerVisitorCapturingPublicReset::FramerVisitorCapturingPublicReset() {
100 } 152 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 } 356 }
305 357
306 QuicPacket* ConstructHandshakePacket(QuicGuid guid, CryptoTag tag) { 358 QuicPacket* ConstructHandshakePacket(QuicGuid guid, CryptoTag tag) {
307 CryptoHandshakeMessage message; 359 CryptoHandshakeMessage message;
308 message.set_tag(tag); 360 message.set_tag(tag);
309 return ConstructPacketFromHandshakeMessage(guid, message, false); 361 return ConstructPacketFromHandshakeMessage(guid, message, false);
310 } 362 }
311 363
312 size_t GetPacketLengthForOneStream(bool include_version, size_t payload) { 364 size_t GetPacketLengthForOneStream(bool include_version, size_t payload) {
313 // TODO(wtc): the hardcoded use of NullEncrypter here seems wrong. 365 // TODO(wtc): the hardcoded use of NullEncrypter here seems wrong.
314 return NullEncrypter().GetCiphertextSize(payload) + 366 size_t packet_length = NullEncrypter().GetCiphertextSize(payload) +
315 QuicPacketCreator::StreamFramePacketOverhead(1, include_version); 367 QuicPacketCreator::StreamFramePacketOverhead(1, include_version);
368
369 size_t ack_length = NullEncrypter().GetCiphertextSize(
370 QuicFramer::GetMinAckFrameSize()) + GetPacketHeaderSize(include_version);
371 // Make sure that if we change the size of the packet length for one stream
372 // or the ack frame; that all our test are configured correctly.
373 DCHECK_GE(packet_length, ack_length);
374 return packet_length;
316 } 375 }
317 376
318 QuicPacketEntropyHash TestEntropyCalculator::ReceivedEntropyHash( 377 QuicPacketEntropyHash TestEntropyCalculator::ReceivedEntropyHash(
319 QuicPacketSequenceNumber sequence_number) const { 378 QuicPacketSequenceNumber sequence_number) const {
320 return 1u; 379 return 1u;
321 } 380 }
322 381
323 } // namespace test 382 } // namespace test
324 } // namespace net 383 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/quic_test_utils.h ('k') | net/quic/test_tools/simple_quic_framer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698