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

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

Issue 14816006: Land Recent QUIC changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added missing NET_PRIVATE_EXPORT to QuicWallTime Created 7 years, 7 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.h » ('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 "base/strings/string_piece.h"
9 #include "net/quic/crypto/crypto_framer.h" 8 #include "net/quic/crypto/crypto_framer.h"
10 #include "net/quic/crypto/crypto_handshake.h" 9 #include "net/quic/crypto/crypto_handshake.h"
11 #include "net/quic/crypto/crypto_utils.h" 10 #include "net/quic/crypto/crypto_utils.h"
12 #include "net/quic/crypto/null_encrypter.h" 11 #include "net/quic/crypto/null_encrypter.h"
13 #include "net/quic/crypto/quic_decrypter.h" 12 #include "net/quic/crypto/quic_decrypter.h"
14 #include "net/quic/crypto/quic_encrypter.h" 13 #include "net/quic/crypto/quic_encrypter.h"
15 #include "net/quic/quic_framer.h" 14 #include "net/quic/quic_framer.h"
16 #include "net/quic/quic_packet_creator.h" 15 #include "net/quic/quic_packet_creator.h"
17 #include "net/spdy/spdy_frame_builder.h" 16 #include "net/spdy/spdy_frame_builder.h"
18 17
(...skipping 30 matching lines...) Expand all
49 ON_CALL(*this, OnConnectionCloseFrame(_)) 48 ON_CALL(*this, OnConnectionCloseFrame(_))
50 .WillByDefault(testing::Return(true)); 49 .WillByDefault(testing::Return(true));
51 50
52 ON_CALL(*this, OnGoAwayFrame(_)) 51 ON_CALL(*this, OnGoAwayFrame(_))
53 .WillByDefault(testing::Return(true)); 52 .WillByDefault(testing::Return(true));
54 } 53 }
55 54
56 MockFramerVisitor::~MockFramerVisitor() { 55 MockFramerVisitor::~MockFramerVisitor() {
57 } 56 }
58 57
59 bool NoOpFramerVisitor::OnProtocolVersionMismatch(QuicVersionTag version) { 58 bool NoOpFramerVisitor::OnProtocolVersionMismatch(QuicTag version) {
60 return false; 59 return false;
61 } 60 }
62 61
63 bool NoOpFramerVisitor::OnPacketHeader(const QuicPacketHeader& header) { 62 bool NoOpFramerVisitor::OnPacketHeader(const QuicPacketHeader& header) {
64 return true; 63 return true;
65 } 64 }
66 65
67 bool NoOpFramerVisitor::OnStreamFrame(const QuicStreamFrame& frame) { 66 bool NoOpFramerVisitor::OnStreamFrame(const QuicStreamFrame& frame) {
68 return true; 67 return true;
69 } 68 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 return &random_generator_; 181 return &random_generator_;
183 } 182 }
184 183
185 void MockHelper::AdvanceTime(QuicTime::Delta delta) { 184 void MockHelper::AdvanceTime(QuicTime::Delta delta) {
186 clock_.AdvanceTime(delta); 185 clock_.AdvanceTime(delta);
187 } 186 }
188 187
189 MockConnection::MockConnection(QuicGuid guid, 188 MockConnection::MockConnection(QuicGuid guid,
190 IPEndPoint address, 189 IPEndPoint address,
191 bool is_server) 190 bool is_server)
192 : QuicConnection(guid, address, new MockHelper(), is_server), 191 : QuicConnection(guid, address, new testing::NiceMock<MockHelper>(),
192 is_server),
193 has_mock_helper_(true) { 193 has_mock_helper_(true) {
194 } 194 }
195 195
196 MockConnection::MockConnection(QuicGuid guid, 196 MockConnection::MockConnection(QuicGuid guid,
197 IPEndPoint address, 197 IPEndPoint address,
198 QuicConnectionHelperInterface* helper, 198 QuicConnectionHelperInterface* helper,
199 bool is_server) 199 bool is_server)
200 : QuicConnection(guid, address, helper, is_server), 200 : QuicConnection(guid, address, helper, is_server),
201 has_mock_helper_(false) { 201 has_mock_helper_(false) {
202 } 202 }
203 203
204 MockConnection::~MockConnection() { 204 MockConnection::~MockConnection() {
205 } 205 }
206 206
207 void MockConnection::AdvanceTime(QuicTime::Delta delta) { 207 void MockConnection::AdvanceTime(QuicTime::Delta delta) {
208 CHECK(has_mock_helper_) << "Cannot advance time unless a MockClock is being" 208 CHECK(has_mock_helper_) << "Cannot advance time unless a MockClock is being"
209 " used"; 209 " used";
210 static_cast<MockHelper*>(helper())->AdvanceTime(delta); 210 static_cast<MockHelper*>(helper())->AdvanceTime(delta);
211 } 211 }
212 212
213 PacketSavingConnection::PacketSavingConnection(QuicGuid guid, 213 PacketSavingConnection::PacketSavingConnection(QuicGuid guid,
214 IPEndPoint address, 214 IPEndPoint address,
215 bool is_server) 215 bool is_server)
216 : MockConnection(guid, address, is_server) { 216 : MockConnection(guid, address, is_server) {
217 } 217 }
218 218
219 PacketSavingConnection::~PacketSavingConnection() { 219 PacketSavingConnection::~PacketSavingConnection() {
220 STLDeleteElements(&packets_); 220 STLDeleteElements(&packets_);
221 STLDeleteElements(&encrypted_packets_);
221 } 222 }
222 223
223 bool PacketSavingConnection::SendOrQueuePacket( 224 bool PacketSavingConnection::SendOrQueuePacket(
224 EncryptionLevel level, 225 EncryptionLevel level,
225 QuicPacketSequenceNumber sequence_number, 226 QuicPacketSequenceNumber sequence_number,
226 QuicPacket* packet, 227 QuicPacket* packet,
227 QuicPacketEntropyHash entropy_hash, 228 QuicPacketEntropyHash entropy_hash,
228 HasRetransmittableData retransmittable) { 229 HasRetransmittableData retransmittable) {
229 packets_.push_back(packet); 230 packets_.push_back(packet);
231 QuicEncryptedPacket* encrypted =
232 framer_.EncryptPacket(level, sequence_number, *packet);
233 encrypted_packets_.push_back(encrypted);
230 return true; 234 return true;
231 } 235 }
232 236
233 MockSession::MockSession(QuicConnection* connection, bool is_server) 237 MockSession::MockSession(QuicConnection* connection, bool is_server)
234 : QuicSession(connection, is_server) { 238 : QuicSession(connection, is_server) {
235 ON_CALL(*this, WriteData(_, _, _, _)) 239 ON_CALL(*this, WriteData(_, _, _, _))
236 .WillByDefault(testing::Return(QuicConsumedData(0, false))); 240 .WillByDefault(testing::Return(QuicConsumedData(0, false)));
237 } 241 }
238 242
239 MockSession::~MockSession() { 243 MockSession::~MockSession() {
240 } 244 }
241 245
246 TestSession::TestSession(QuicConnection* connection, bool is_server)
247 : QuicSession(connection, is_server),
248 crypto_stream_(NULL) {
249 }
250
251 TestSession::~TestSession() {
252 }
253
254 void TestSession::SetCryptoStream(QuicCryptoStream* stream) {
255 crypto_stream_ = stream;
256 }
257
258 QuicCryptoStream* TestSession::GetCryptoStream() {
259 return crypto_stream_;
260 }
261
242 MockSendAlgorithm::MockSendAlgorithm() { 262 MockSendAlgorithm::MockSendAlgorithm() {
243 } 263 }
244 264
245 MockSendAlgorithm::~MockSendAlgorithm() { 265 MockSendAlgorithm::~MockSendAlgorithm() {
246 } 266 }
247 267
248 namespace { 268 namespace {
249 269
250 string HexDumpWithMarks(const char* data, int length, 270 string HexDumpWithMarks(const char* data, int length,
251 const bool* marks, int mark_length) { 271 const bool* marks, int mark_length) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 368
349 QuicStreamFrame stream_frame(kCryptoStreamId, false, 0, 369 QuicStreamFrame stream_frame(kCryptoStreamId, false, 0,
350 data->AsStringPiece()); 370 data->AsStringPiece());
351 371
352 QuicFrame frame(&stream_frame); 372 QuicFrame frame(&stream_frame);
353 QuicFrames frames; 373 QuicFrames frames;
354 frames.push_back(frame); 374 frames.push_back(frame);
355 return quic_framer.ConstructFrameDataPacket(header, frames).packet; 375 return quic_framer.ConstructFrameDataPacket(header, frames).packet;
356 } 376 }
357 377
358 QuicPacket* ConstructHandshakePacket(QuicGuid guid, CryptoTag tag) { 378 QuicPacket* ConstructHandshakePacket(QuicGuid guid, QuicTag tag) {
359 CryptoHandshakeMessage message; 379 CryptoHandshakeMessage message;
360 message.set_tag(tag); 380 message.set_tag(tag);
361 return ConstructPacketFromHandshakeMessage(guid, message, false); 381 return ConstructPacketFromHandshakeMessage(guid, message, false);
362 } 382 }
363 383
364 size_t GetPacketLengthForOneStream(bool include_version, size_t payload) { 384 size_t GetPacketLengthForOneStream(bool include_version, size_t payload) {
365 // TODO(wtc): the hardcoded use of NullEncrypter here seems wrong. 385 // TODO(wtc): the hardcoded use of NullEncrypter here seems wrong.
366 size_t packet_length = NullEncrypter().GetCiphertextSize(payload) + 386 size_t packet_length = NullEncrypter().GetCiphertextSize(payload) +
367 QuicPacketCreator::StreamFramePacketOverhead(1, include_version); 387 QuicPacketCreator::StreamFramePacketOverhead(1, include_version);
368 388
(...skipping 10 matching lines...) Expand all
379 return 1u; 399 return 1u;
380 } 400 }
381 401
382 bool TestDecompressorVisitor::OnDecompressedData(StringPiece data) { 402 bool TestDecompressorVisitor::OnDecompressedData(StringPiece data) {
383 data.AppendToString(&data_); 403 data.AppendToString(&data_);
384 return true; 404 return true;
385 } 405 }
386 406
387 } // namespace test 407 } // namespace test
388 } // namespace net 408 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/quic_test_utils.h ('k') | net/quic/test_tools/simple_quic_framer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698