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

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

Issue 12806002: Land Recent QUIC Changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor comment fix Created 7 years, 9 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_packet_creator.h" 14 #include "net/quic/quic_packet_creator.h"
15 15
16 using std::max; 16 using std::max;
17 using std::min; 17 using std::min;
18 using std::string; 18 using std::string;
19 using testing::_; 19 using testing::_;
20 20
21 namespace net { 21 namespace net {
22 namespace test { 22 namespace test {
23 23
24 MockFramerVisitor::MockFramerVisitor() { 24 MockFramerVisitor::MockFramerVisitor() {
25 // By default, we want to accept packets. 25 // By default, we want to accept packets.
26 ON_CALL(*this, OnProtocolVersionMismatch(_))
27 .WillByDefault(testing::Return(false));
28
29 // By default, we want to accept packets.
26 ON_CALL(*this, OnPacketHeader(_)) 30 ON_CALL(*this, OnPacketHeader(_))
27 .WillByDefault(testing::Return(true)); 31 .WillByDefault(testing::Return(true));
28 } 32 }
29 33
30 MockFramerVisitor::~MockFramerVisitor() { 34 MockFramerVisitor::~MockFramerVisitor() {
31 } 35 }
32 36
37 bool NoOpFramerVisitor::OnProtocolVersionMismatch(QuicVersionTag version) {
38 return false;
39 }
40
33 bool NoOpFramerVisitor::OnPacketHeader(const QuicPacketHeader& header) { 41 bool NoOpFramerVisitor::OnPacketHeader(const QuicPacketHeader& header) {
34 return true; 42 return true;
35 } 43 }
36 44
37 FramerVisitorCapturingFrames::FramerVisitorCapturingFrames() : frame_count_(0) { 45 FramerVisitorCapturingFrames::FramerVisitorCapturingFrames() : frame_count_(0) {
38 } 46 }
39 47
40 FramerVisitorCapturingFrames::~FramerVisitorCapturingFrames() { 48 FramerVisitorCapturingFrames::~FramerVisitorCapturingFrames() {
41 } 49 }
42 50
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 const QuicConnectionCloseFrame& frame) { 83 const QuicConnectionCloseFrame& frame) {
76 close_.reset(new QuicConnectionCloseFrame(frame)); 84 close_.reset(new QuicConnectionCloseFrame(frame));
77 ++frame_count_; 85 ++frame_count_;
78 } 86 }
79 87
80 void FramerVisitorCapturingFrames::OnGoAwayFrame(const QuicGoAwayFrame& frame) { 88 void FramerVisitorCapturingFrames::OnGoAwayFrame(const QuicGoAwayFrame& frame) {
81 goaway_.reset(new QuicGoAwayFrame(frame)); 89 goaway_.reset(new QuicGoAwayFrame(frame));
82 ++frame_count_; 90 ++frame_count_;
83 } 91 }
84 92
93 void FramerVisitorCapturingFrames::OnVersionNegotiationPacket(
94 const QuicVersionNegotiationPacket& packet) {
95 version_negotiation_packet_.reset(new QuicVersionNegotiationPacket(packet));
96 frame_count_ = 0;
97 }
98
85 FramerVisitorCapturingPublicReset::FramerVisitorCapturingPublicReset() { 99 FramerVisitorCapturingPublicReset::FramerVisitorCapturingPublicReset() {
86 } 100 }
87 101
88 FramerVisitorCapturingPublicReset::~FramerVisitorCapturingPublicReset() { 102 FramerVisitorCapturingPublicReset::~FramerVisitorCapturingPublicReset() {
89 } 103 }
90 104
91 void FramerVisitorCapturingPublicReset::OnPublicResetPacket( 105 void FramerVisitorCapturingPublicReset::OnPublicResetPacket(
92 const QuicPublicResetPacket& public_reset) { 106 const QuicPublicResetPacket& public_reset) {
93 public_reset_packet_ = public_reset; 107 public_reset_packet_ = public_reset;
94 } 108 }
(...skipping 11 matching lines...) Expand all
106 } 120 }
107 121
108 const QuicClock* MockHelper::GetClock() const { 122 const QuicClock* MockHelper::GetClock() const {
109 return &clock_; 123 return &clock_;
110 } 124 }
111 125
112 QuicRandom* MockHelper::GetRandomGenerator() { 126 QuicRandom* MockHelper::GetRandomGenerator() {
113 return &random_generator_; 127 return &random_generator_;
114 } 128 }
115 129
116 MockConnection::MockConnection(QuicGuid guid, IPEndPoint address) 130 MockConnection::MockConnection(QuicGuid guid,
117 : QuicConnection(guid, address, new MockHelper()), 131 IPEndPoint address,
132 bool is_server)
133 : QuicConnection(guid, address, new MockHelper(), is_server),
118 helper_(helper()) { 134 helper_(helper()) {
119 } 135 }
120 136
121 MockConnection::MockConnection(QuicGuid guid, 137 MockConnection::MockConnection(QuicGuid guid,
122 IPEndPoint address, 138 IPEndPoint address,
123 QuicConnectionHelperInterface* helper) 139 QuicConnectionHelperInterface* helper,
124 : QuicConnection(guid, address, helper), 140 bool is_server)
141 : QuicConnection(guid, address, helper, is_server),
125 helper_(helper) { 142 helper_(helper) {
126 } 143 }
127 144
128 MockConnection::~MockConnection() { 145 MockConnection::~MockConnection() {
129 } 146 }
130 147
131 PacketSavingConnection::PacketSavingConnection(QuicGuid guid, 148 PacketSavingConnection::PacketSavingConnection(QuicGuid guid,
132 IPEndPoint address) 149 IPEndPoint address,
133 : MockConnection(guid, address) { 150 bool is_server)
151 : MockConnection(guid, address, is_server) {
134 } 152 }
135 153
136 PacketSavingConnection::~PacketSavingConnection() { 154 PacketSavingConnection::~PacketSavingConnection() {
137 STLDeleteElements(&packets_); 155 STLDeleteElements(&packets_);
138 } 156 }
139 157
140 bool PacketSavingConnection::SendOrQueuePacket( 158 bool PacketSavingConnection::SendOrQueuePacket(
141 QuicPacketSequenceNumber sequence_number, 159 QuicPacketSequenceNumber sequence_number,
142 QuicPacket* packet, 160 QuicPacket* packet,
143 QuicPacketEntropyHash entropy_hash, 161 QuicPacketEntropyHash entropy_hash,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 QuicData* actual, 256 QuicData* actual,
239 QuicData* expected) { 257 QuicData* expected) {
240 CompareCharArraysWithHexError( 258 CompareCharArraysWithHexError(
241 description, 259 description,
242 actual->data(), actual->length(), 260 actual->data(), actual->length(),
243 expected->data(), expected->length()); 261 expected->data(), expected->length());
244 } 262 }
245 263
246 static QuicPacket* ConstructPacketFromHandshakeMessage( 264 static QuicPacket* ConstructPacketFromHandshakeMessage(
247 QuicGuid guid, 265 QuicGuid guid,
248 const CryptoHandshakeMessage& message) { 266 const CryptoHandshakeMessage& message,
267 bool should_include_version) {
249 CryptoFramer crypto_framer; 268 CryptoFramer crypto_framer;
250 scoped_ptr<QuicData> data(crypto_framer.ConstructHandshakeMessage(message)); 269 scoped_ptr<QuicData> data(crypto_framer.ConstructHandshakeMessage(message));
251 QuicFramer quic_framer(kQuicVersion1, 270 QuicFramer quic_framer(kQuicVersion1,
252 QuicDecrypter::Create(kNULL), 271 QuicDecrypter::Create(kNULL),
253 QuicEncrypter::Create(kNULL)); 272 QuicEncrypter::Create(kNULL),
273 false);
254 274
255 QuicPacketHeader header; 275 QuicPacketHeader header;
256 header.public_header.guid = guid; 276 header.public_header.guid = guid;
257 header.public_header.reset_flag = false; 277 header.public_header.reset_flag = false;
258 header.public_header.version_flag = false; 278 header.public_header.version_flag = should_include_version;
259 header.packet_sequence_number = 1; 279 header.packet_sequence_number = 1;
260 header.entropy_flag = false; 280 header.entropy_flag = false;
261 header.entropy_hash = 0; 281 header.entropy_hash = 0;
262 header.fec_flag = false; 282 header.fec_flag = false;
263 header.fec_entropy_flag = false; 283 header.fec_entropy_flag = false;
264 header.fec_group = 0; 284 header.fec_group = 0;
265 285
266 QuicStreamFrame stream_frame(kCryptoStreamId, false, 0, 286 QuicStreamFrame stream_frame(kCryptoStreamId, false, 0,
267 data->AsStringPiece()); 287 data->AsStringPiece());
268 288
269 QuicFrame frame(&stream_frame); 289 QuicFrame frame(&stream_frame);
270 QuicFrames frames; 290 QuicFrames frames;
271 frames.push_back(frame); 291 frames.push_back(frame);
272 return quic_framer.ConstructFrameDataPacket(header, frames).packet; 292 return quic_framer.ConstructFrameDataPacket(header, frames).packet;
273 } 293 }
274 294
275 QuicPacket* ConstructHandshakePacket(QuicGuid guid, CryptoTag tag) { 295 QuicPacket* ConstructHandshakePacket(QuicGuid guid, CryptoTag tag) {
276 CryptoHandshakeMessage message; 296 CryptoHandshakeMessage message;
277 message.tag = tag; 297 message.tag = tag;
278 return ConstructPacketFromHandshakeMessage(guid, message); 298 return ConstructPacketFromHandshakeMessage(guid, message, false);
279 } 299 }
280 300
281 CryptoHandshakeMessage CreateChloMessage(const QuicClock* clock, 301 CryptoHandshakeMessage CreateChloMessage(const QuicClock* clock,
282 QuicRandom* random_generator, 302 QuicRandom* random_generator,
283 const string& server_hostname) { 303 const string& server_hostname) {
284 QuicCryptoClientConfig client_config; 304 QuicCryptoClientConfig client_config;
285 client_config.SetDefaults(random_generator); 305 client_config.SetDefaults(random_generator);
286 string nonce; 306 string nonce;
287 CryptoUtils::GenerateNonce(clock, random_generator, &nonce); 307 CryptoUtils::GenerateNonce(clock, random_generator, &nonce);
288 308
289 QuicConfig config; 309 QuicConfig config;
290 config.SetDefaults(); 310 config.SetDefaults();
291 311
292 CryptoHandshakeMessage message; 312 CryptoHandshakeMessage message;
293 client_config.FillClientHello(nonce, server_hostname, &message); 313 client_config.FillClientHello(nonce, server_hostname, &message);
294 config.ToHandshakeMessage(&message); 314 config.ToHandshakeMessage(&message);
295 return message; 315 return message;
296 } 316 }
297 317
298 QuicPacket* ConstructClientHelloPacket(QuicGuid guid, 318 QuicPacket* ConstructClientHelloPacket(QuicGuid guid,
299 const QuicClock* clock, 319 const QuicClock* clock,
300 QuicRandom* random_generator, 320 QuicRandom* random_generator,
301 const string& server_hostname) { 321 const string& server_hostname,
322 bool should_include_version) {
302 CryptoHandshakeMessage chlo = CreateChloMessage(clock, random_generator, 323 CryptoHandshakeMessage chlo = CreateChloMessage(clock, random_generator,
303 server_hostname); 324 server_hostname);
304 return ConstructPacketFromHandshakeMessage(guid, chlo); 325 return ConstructPacketFromHandshakeMessage(
326 guid, chlo, should_include_version);
305 } 327 }
306 328
307 CryptoHandshakeMessage CreateShloMessage(const QuicClock* clock, 329 CryptoHandshakeMessage CreateShloMessage(const QuicClock* clock,
308 QuicRandom* random_generator, 330 QuicRandom* random_generator,
309 const string& server_hostname) { 331 const string& server_hostname) {
310 // Expected CHLO 332 // Expected CHLO
311 CryptoHandshakeMessage chlo = CreateChloMessage(clock, random_generator, 333 CryptoHandshakeMessage chlo = CreateChloMessage(clock, random_generator,
312 server_hostname); 334 server_hostname);
313 335
314 QuicConfig config; 336 QuicConfig config;
(...skipping 22 matching lines...) Expand all
337 359
338 return shlo; 360 return shlo;
339 } 361 }
340 362
341 QuicPacket* ConstructServerHelloPacket(QuicGuid guid, 363 QuicPacket* ConstructServerHelloPacket(QuicGuid guid,
342 const QuicClock* clock, 364 const QuicClock* clock,
343 QuicRandom* random_generator, 365 QuicRandom* random_generator,
344 const string& server_hostname) { 366 const string& server_hostname) {
345 CryptoHandshakeMessage shlo = 367 CryptoHandshakeMessage shlo =
346 CreateShloMessage(clock, random_generator, server_hostname); 368 CreateShloMessage(clock, random_generator, server_hostname);
347 return ConstructPacketFromHandshakeMessage(guid, shlo); 369 return ConstructPacketFromHandshakeMessage(guid, shlo, false);
348 } 370 }
349 371
350 size_t GetPacketLengthForOneStream(bool include_version, size_t payload) { 372 size_t GetPacketLengthForOneStream(bool include_version, size_t payload) {
373 // TODO(wtc): the hardcoded use of NullEncrypter here seems wrong.
351 return NullEncrypter().GetCiphertextSize(payload) + 374 return NullEncrypter().GetCiphertextSize(payload) +
352 QuicPacketCreator::StreamFramePacketOverhead(1, include_version); 375 QuicPacketCreator::StreamFramePacketOverhead(1, include_version);
353 } 376 }
354 377
355 QuicPacketEntropyHash TestEntropyCalculator::ReceivedEntropyHash( 378 QuicPacketEntropyHash TestEntropyCalculator::ReceivedEntropyHash(
356 QuicPacketSequenceNumber sequence_number) const { 379 QuicPacketSequenceNumber sequence_number) const {
357 return 1u; 380 return 1u;
358 } 381 }
359 382
360 } // namespace test 383 } // namespace test
361 } // namespace net 384 } // 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