blob: 745237abc1da3fd14cb0fd16457dbc0b745204e4 [file] [log] [blame]
[email protected]8b37a092012-10-18 21:53:491// 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
3// found in the LICENSE file.
4
5#include "net/quic/test_tools/quic_test_utils.h"
[email protected]9c0b1352012-11-04 00:03:276
[email protected]701bc892013-01-17 04:51:547#include "base/stl_util.h"
[email protected]b12764d2013-12-02 22:28:308#include "base/strings/string_number_conversions.h"
[email protected]8b37a092012-10-18 21:53:499#include "net/quic/crypto/crypto_framer.h"
[email protected]6f54ab32013-03-02 17:43:3510#include "net/quic/crypto/crypto_handshake.h"
[email protected]872edd9e2013-01-16 08:51:1511#include "net/quic/crypto/crypto_utils.h"
[email protected]5351cc4b2013-03-03 07:22:4112#include "net/quic/crypto/null_encrypter.h"
[email protected]4df69842013-02-27 06:32:1613#include "net/quic/crypto/quic_decrypter.h"
14#include "net/quic/crypto/quic_encrypter.h"
[email protected]a57e0272013-04-26 07:31:4715#include "net/quic/quic_framer.h"
[email protected]5351cc4b2013-03-03 07:22:4116#include "net/quic/quic_packet_creator.h"
[email protected]79d13dcb2014-02-05 07:23:1317#include "net/quic/quic_utils.h"
[email protected]cbd731e2013-10-24 00:20:3918#include "net/quic/test_tools/quic_connection_peer.h"
[email protected]c244c5a12013-05-07 20:55:0419#include "net/spdy/spdy_frame_builder.h"
[email protected]8b37a092012-10-18 21:53:4920
[email protected]c244c5a12013-05-07 20:55:0421using base::StringPiece;
[email protected]8b37a092012-10-18 21:53:4922using std::max;
23using std::min;
24using std::string;
[email protected]cff7b7b2013-01-11 08:49:0725using testing::_;
[email protected]8b37a092012-10-18 21:53:4926
27namespace net {
28namespace test {
[email protected]965dbe62013-08-09 21:34:3129namespace {
30
31// No-op alarm implementation used by MockHelper.
32class TestAlarm : public QuicAlarm {
33 public:
34 explicit TestAlarm(QuicAlarm::Delegate* delegate)
35 : QuicAlarm(delegate) {
36 }
37
38 virtual void SetImpl() OVERRIDE {}
39 virtual void CancelImpl() OVERRIDE {}
40};
41
42} // namespace
[email protected]8b37a092012-10-18 21:53:4943
44MockFramerVisitor::MockFramerVisitor() {
45 // By default, we want to accept packets.
[email protected]14e8106c2013-03-14 16:25:3346 ON_CALL(*this, OnProtocolVersionMismatch(_))
47 .WillByDefault(testing::Return(false));
48
49 // By default, we want to accept packets.
[email protected]ec86d5462013-11-17 16:04:4950 ON_CALL(*this, OnUnauthenticatedHeader(_))
51 .WillByDefault(testing::Return(true));
52
[email protected]066d8182014-01-04 02:02:4553 ON_CALL(*this, OnUnauthenticatedPublicHeader(_))
54 .WillByDefault(testing::Return(true));
55
[email protected]cff7b7b2013-01-11 08:49:0756 ON_CALL(*this, OnPacketHeader(_))
[email protected]8b37a092012-10-18 21:53:4957 .WillByDefault(testing::Return(true));
[email protected]a57e0272013-04-26 07:31:4758
59 ON_CALL(*this, OnStreamFrame(_))
60 .WillByDefault(testing::Return(true));
61
62 ON_CALL(*this, OnAckFrame(_))
63 .WillByDefault(testing::Return(true));
64
65 ON_CALL(*this, OnCongestionFeedbackFrame(_))
66 .WillByDefault(testing::Return(true));
67
68 ON_CALL(*this, OnRstStreamFrame(_))
69 .WillByDefault(testing::Return(true));
70
71 ON_CALL(*this, OnConnectionCloseFrame(_))
72 .WillByDefault(testing::Return(true));
73
74 ON_CALL(*this, OnGoAwayFrame(_))
75 .WillByDefault(testing::Return(true));
[email protected]8b37a092012-10-18 21:53:4976}
77
[email protected]044ac2b2012-11-13 21:41:0678MockFramerVisitor::~MockFramerVisitor() {
79}
[email protected]8b37a092012-10-18 21:53:4980
[email protected]48878092013-07-26 14:51:5681bool NoOpFramerVisitor::OnProtocolVersionMismatch(QuicVersion version) {
[email protected]14e8106c2013-03-14 16:25:3382 return false;
83}
84
[email protected]066d8182014-01-04 02:02:4585bool NoOpFramerVisitor::OnUnauthenticatedPublicHeader(
86 const QuicPacketPublicHeader& header) {
87 return true;
88}
89
[email protected]ec86d5462013-11-17 16:04:4990bool NoOpFramerVisitor::OnUnauthenticatedHeader(
91 const QuicPacketHeader& header) {
92 return true;
93}
94
[email protected]8b37a092012-10-18 21:53:4995bool NoOpFramerVisitor::OnPacketHeader(const QuicPacketHeader& header) {
96 return true;
97}
98
[email protected]a57e0272013-04-26 07:31:4799bool NoOpFramerVisitor::OnStreamFrame(const QuicStreamFrame& frame) {
100 return true;
101}
102
103bool NoOpFramerVisitor::OnAckFrame(const QuicAckFrame& frame) {
104 return true;
105}
106
107bool NoOpFramerVisitor::OnCongestionFeedbackFrame(
108 const QuicCongestionFeedbackFrame& frame) {
109 return true;
110}
111
112bool NoOpFramerVisitor::OnRstStreamFrame(
113 const QuicRstStreamFrame& frame) {
114 return true;
115}
116
117bool NoOpFramerVisitor::OnConnectionCloseFrame(
118 const QuicConnectionCloseFrame& frame) {
119 return true;
120}
121
122bool NoOpFramerVisitor::OnGoAwayFrame(const QuicGoAwayFrame& frame) {
123 return true;
124}
125
[email protected]cb23a922014-02-20 17:42:38126bool NoOpFramerVisitor::OnWindowUpdateFrame(
127 const QuicWindowUpdateFrame& frame) {
128 return true;
129}
130
131bool NoOpFramerVisitor::OnBlockedFrame(const QuicBlockedFrame& frame) {
132 return true;
133}
134
[email protected]9db443912013-02-25 05:27:03135FramerVisitorCapturingFrames::FramerVisitorCapturingFrames() : frame_count_(0) {
[email protected]134e5c32012-12-12 19:20:36136}
137
[email protected]9db443912013-02-25 05:27:03138FramerVisitorCapturingFrames::~FramerVisitorCapturingFrames() {
[email protected]0ac0c5b2013-11-20 05:55:58139 Reset();
140}
141
142void FramerVisitorCapturingFrames::Reset() {
[email protected]583bcbcf2013-10-28 01:51:15143 STLDeleteElements(&stream_data_);
[email protected]0ac0c5b2013-11-20 05:55:58144 stream_frames_.clear();
145 frame_count_ = 0;
146 ack_.reset();
147 feedback_.reset();
148 rst_.reset();
149 close_.reset();
150 goaway_.reset();
151 version_negotiation_packet_.reset();
[email protected]26f3f8e2012-12-13 21:07:19152}
153
[email protected]9db443912013-02-25 05:27:03154bool FramerVisitorCapturingFrames::OnPacketHeader(
[email protected]4e6f0ed2012-11-02 22:15:38155 const QuicPacketHeader& header) {
156 header_ = header;
[email protected]9db443912013-02-25 05:27:03157 frame_count_ = 0;
[email protected]4e6f0ed2012-11-02 22:15:38158 return true;
159}
160
[email protected]a57e0272013-04-26 07:31:47161bool FramerVisitorCapturingFrames::OnStreamFrame(const QuicStreamFrame& frame) {
[email protected]583bcbcf2013-10-28 01:51:15162 // Make a copy of the frame and store a copy of underlying string, since
163 // frame.data may not exist outside this callback.
[email protected]5dafdb62013-11-14 01:24:26164 stream_data_.push_back(frame.GetDataAsString());
[email protected]583bcbcf2013-10-28 01:51:15165 QuicStreamFrame frame_copy = frame;
[email protected]5dafdb62013-11-14 01:24:26166 frame_copy.data.Clear();
167 frame_copy.data.Append(const_cast<char*>(stream_data_.back()->data()),
168 stream_data_.back()->size());
[email protected]583bcbcf2013-10-28 01:51:15169 stream_frames_.push_back(frame_copy);
[email protected]9db443912013-02-25 05:27:03170 ++frame_count_;
[email protected]a57e0272013-04-26 07:31:47171 return true;
[email protected]26f3f8e2012-12-13 21:07:19172}
173
[email protected]a57e0272013-04-26 07:31:47174bool FramerVisitorCapturingFrames::OnAckFrame(const QuicAckFrame& frame) {
[email protected]9db443912013-02-25 05:27:03175 ack_.reset(new QuicAckFrame(frame));
176 ++frame_count_;
[email protected]a57e0272013-04-26 07:31:47177 return true;
[email protected]9db443912013-02-25 05:27:03178}
179
[email protected]a57e0272013-04-26 07:31:47180bool FramerVisitorCapturingFrames::OnCongestionFeedbackFrame(
[email protected]26f3f8e2012-12-13 21:07:19181 const QuicCongestionFeedbackFrame& frame) {
182 feedback_.reset(new QuicCongestionFeedbackFrame(frame));
[email protected]9db443912013-02-25 05:27:03183 ++frame_count_;
[email protected]a57e0272013-04-26 07:31:47184 return true;
[email protected]9db443912013-02-25 05:27:03185}
186
[email protected]a57e0272013-04-26 07:31:47187bool FramerVisitorCapturingFrames::OnRstStreamFrame(
[email protected]9db443912013-02-25 05:27:03188 const QuicRstStreamFrame& frame) {
189 rst_.reset(new QuicRstStreamFrame(frame));
190 ++frame_count_;
[email protected]a57e0272013-04-26 07:31:47191 return true;
[email protected]9db443912013-02-25 05:27:03192}
193
[email protected]a57e0272013-04-26 07:31:47194bool FramerVisitorCapturingFrames::OnConnectionCloseFrame(
[email protected]9db443912013-02-25 05:27:03195 const QuicConnectionCloseFrame& frame) {
196 close_.reset(new QuicConnectionCloseFrame(frame));
197 ++frame_count_;
[email protected]a57e0272013-04-26 07:31:47198 return true;
[email protected]9db443912013-02-25 05:27:03199}
200
[email protected]a57e0272013-04-26 07:31:47201bool FramerVisitorCapturingFrames::OnGoAwayFrame(const QuicGoAwayFrame& frame) {
[email protected]9db443912013-02-25 05:27:03202 goaway_.reset(new QuicGoAwayFrame(frame));
203 ++frame_count_;
[email protected]a57e0272013-04-26 07:31:47204 return true;
[email protected]4e6f0ed2012-11-02 22:15:38205}
206
[email protected]14e8106c2013-03-14 16:25:33207void FramerVisitorCapturingFrames::OnVersionNegotiationPacket(
208 const QuicVersionNegotiationPacket& packet) {
209 version_negotiation_packet_.reset(new QuicVersionNegotiationPacket(packet));
210 frame_count_ = 0;
211}
212
[email protected]fee17f72013-02-03 07:47:41213FramerVisitorCapturingPublicReset::FramerVisitorCapturingPublicReset() {
214}
215
216FramerVisitorCapturingPublicReset::~FramerVisitorCapturingPublicReset() {
217}
218
219void FramerVisitorCapturingPublicReset::OnPublicResetPacket(
220 const QuicPublicResetPacket& public_reset) {
221 public_reset_packet_ = public_reset;
222}
223
[email protected]8d659e22013-01-19 04:26:10224MockConnectionVisitor::MockConnectionVisitor() {
225}
226
227MockConnectionVisitor::~MockConnectionVisitor() {
228}
229
[email protected]9c0b1352012-11-04 00:03:27230MockHelper::MockHelper() {
231}
232
233MockHelper::~MockHelper() {
234}
235
[email protected]97693d12012-11-16 16:05:00236const QuicClock* MockHelper::GetClock() const {
[email protected]9c0b1352012-11-04 00:03:27237 return &clock_;
238}
239
[email protected]9558c5d32012-12-22 00:08:14240QuicRandom* MockHelper::GetRandomGenerator() {
241 return &random_generator_;
242}
243
[email protected]965dbe62013-08-09 21:34:31244QuicAlarm* MockHelper::CreateAlarm(QuicAlarm::Delegate* delegate) {
245 return new TestAlarm(delegate);
246}
247
[email protected]fe053f92013-04-23 20:18:55248void MockHelper::AdvanceTime(QuicTime::Delta delta) {
249 clock_.AdvanceTime(delta);
250}
251
[email protected]c05a6d222013-12-16 19:42:03252MockConnection::MockConnection(bool is_server)
253 : QuicConnection(kTestGuid,
[email protected]300ccd52014-01-25 08:00:19254 IPEndPoint(TestPeerIPAddress(), kTestPort),
[email protected]c05a6d222013-12-16 19:42:03255 new testing::NiceMock<MockHelper>(),
[email protected]cbd731e2013-10-24 00:20:39256 new testing::NiceMock<MockPacketWriter>(),
[email protected]b007e632013-10-28 08:39:25257 is_server, QuicSupportedVersions()),
[email protected]c05a6d222013-12-16 19:42:03258 writer_(QuicConnectionPeer::GetWriter(this)),
259 helper_(helper()) {
260}
261
262MockConnection::MockConnection(IPEndPoint address,
263 bool is_server)
264 : QuicConnection(kTestGuid, address,
265 new testing::NiceMock<MockHelper>(),
266 new testing::NiceMock<MockPacketWriter>(),
267 is_server, QuicSupportedVersions()),
[email protected]2cfc6bb82013-10-27 03:40:44268 writer_(QuicConnectionPeer::GetWriter(this)),
269 helper_(helper()) {
[email protected]044ac2b2012-11-13 21:41:06270}
271
[email protected]872edd9e2013-01-16 08:51:15272MockConnection::MockConnection(QuicGuid guid,
[email protected]14e8106c2013-03-14 16:25:33273 bool is_server)
[email protected]300ccd52014-01-25 08:00:19274 : QuicConnection(guid, IPEndPoint(TestPeerIPAddress(), kTestPort),
[email protected]c05a6d222013-12-16 19:42:03275 new testing::NiceMock<MockHelper>(),
276 new testing::NiceMock<MockPacketWriter>(),
277 is_server, QuicSupportedVersions()),
278 writer_(QuicConnectionPeer::GetWriter(this)),
279 helper_(helper()) {
[email protected]872edd9e2013-01-16 08:51:15280}
281
[email protected]4d640792013-12-18 22:21:08282MockConnection::MockConnection(bool is_server,
283 const QuicVersionVector& supported_versions)
284 : QuicConnection(kTestGuid,
[email protected]300ccd52014-01-25 08:00:19285 IPEndPoint(TestPeerIPAddress(), kTestPort),
[email protected]4d640792013-12-18 22:21:08286 new testing::NiceMock<MockHelper>(),
287 new testing::NiceMock<MockPacketWriter>(),
288 is_server, supported_versions),
289 writer_(QuicConnectionPeer::GetWriter(this)),
290 helper_(helper()) {
291}
292
[email protected]044ac2b2012-11-13 21:41:06293MockConnection::~MockConnection() {
294}
295
[email protected]fe053f92013-04-23 20:18:55296void MockConnection::AdvanceTime(QuicTime::Delta delta) {
[email protected]fe053f92013-04-23 20:18:55297 static_cast<MockHelper*>(helper())->AdvanceTime(delta);
298}
299
[email protected]c05a6d222013-12-16 19:42:03300PacketSavingConnection::PacketSavingConnection(bool is_server)
301 : MockConnection(is_server) {
[email protected]044ac2b2012-11-13 21:41:06302}
303
[email protected]4d640792013-12-18 22:21:08304PacketSavingConnection::PacketSavingConnection(
305 bool is_server,
306 const QuicVersionVector& supported_versions)
307 : MockConnection(is_server, supported_versions) {
308}
309
[email protected]044ac2b2012-11-13 21:41:06310PacketSavingConnection::~PacketSavingConnection() {
[email protected]701bc892013-01-17 04:51:54311 STLDeleteElements(&packets_);
[email protected]2532de12013-05-09 12:29:33312 STLDeleteElements(&encrypted_packets_);
[email protected]044ac2b2012-11-13 21:41:06313}
314
[email protected]fee17f72013-02-03 07:47:41315bool PacketSavingConnection::SendOrQueuePacket(
[email protected]8ba81212013-05-03 13:11:48316 EncryptionLevel level,
[email protected]ec86d5462013-11-17 16:04:49317 const SerializedPacket& packet,
318 TransmissionType transmission_type) {
319 packets_.push_back(packet.packet);
[email protected]c5e1aca2014-01-30 04:03:04320 QuicEncryptedPacket* encrypted = QuicConnectionPeer::GetFramer(this)->
321 EncryptPacket(level, packet.sequence_number, *packet.packet);
[email protected]2532de12013-05-09 12:29:33322 encrypted_packets_.push_back(encrypted);
[email protected]044ac2b2012-11-13 21:41:06323 return true;
324}
325
[email protected]c05a6d222013-12-16 19:42:03326MockSession::MockSession(QuicConnection* connection)
327 : QuicSession(connection, DefaultQuicConfig()) {
[email protected]0ac0c5b2013-11-20 05:55:58328 ON_CALL(*this, WritevData(_, _, _, _, _, _))
[email protected]cff7b7b2013-01-11 08:49:07329 .WillByDefault(testing::Return(QuicConsumedData(0, false)));
[email protected]044ac2b2012-11-13 21:41:06330}
331
332MockSession::~MockSession() {
333}
334
[email protected]899951652013-05-16 12:52:39335TestSession::TestSession(QuicConnection* connection,
[email protected]c05a6d222013-12-16 19:42:03336 const QuicConfig& config)
337 : QuicSession(connection, config),
[email protected]2532de12013-05-09 12:29:33338 crypto_stream_(NULL) {
339}
340
[email protected]b064310782013-05-30 21:12:17341TestSession::~TestSession() {}
[email protected]2532de12013-05-09 12:29:33342
343void TestSession::SetCryptoStream(QuicCryptoStream* stream) {
344 crypto_stream_ = stream;
345}
346
347QuicCryptoStream* TestSession::GetCryptoStream() {
348 return crypto_stream_;
349}
350
[email protected]cbd731e2013-10-24 00:20:39351MockPacketWriter::MockPacketWriter() {
352}
353
354MockPacketWriter::~MockPacketWriter() {
355}
356
[email protected]fee17f72013-02-03 07:47:41357MockSendAlgorithm::MockSendAlgorithm() {
[email protected]8d659e22013-01-19 04:26:10358}
359
[email protected]fee17f72013-02-03 07:47:41360MockSendAlgorithm::~MockSendAlgorithm() {
[email protected]8d659e22013-01-19 04:26:10361}
362
[email protected]97cf3022013-09-05 14:30:16363MockAckNotifierDelegate::MockAckNotifierDelegate() {
364}
365
366MockAckNotifierDelegate::~MockAckNotifierDelegate() {
367}
368
[email protected]8b37a092012-10-18 21:53:49369namespace {
370
371string HexDumpWithMarks(const char* data, int length,
372 const bool* marks, int mark_length) {
373 static const char kHexChars[] = "0123456789abcdef";
374 static const int kColumns = 4;
375
376 const int kSizeLimit = 1024;
377 if (length > kSizeLimit || mark_length > kSizeLimit) {
378 LOG(ERROR) << "Only dumping first " << kSizeLimit << " bytes.";
379 length = min(length, kSizeLimit);
380 mark_length = min(mark_length, kSizeLimit);
381 }
382
383 string hex;
384 for (const char* row = data; length > 0;
385 row += kColumns, length -= kColumns) {
386 for (const char *p = row; p < row + 4; ++p) {
387 if (p < row + length) {
388 const bool mark =
389 (marks && (p - data) < mark_length && marks[p - data]);
390 hex += mark ? '*' : ' ';
391 hex += kHexChars[(*p & 0xf0) >> 4];
392 hex += kHexChars[*p & 0x0f];
393 hex += mark ? '*' : ' ';
394 } else {
395 hex += " ";
396 }
397 }
398 hex = hex + " ";
399
400 for (const char *p = row; p < row + 4 && p < row + length; ++p)
401 hex += (*p >= 0x20 && *p <= 0x7f) ? (*p) : '.';
402
403 hex = hex + '\n';
404 }
405 return hex;
406}
407
408} // namespace
409
[email protected]300ccd52014-01-25 08:00:19410IPAddressNumber TestPeerIPAddress() { return Loopback4(); }
411
[email protected]b007e632013-10-28 08:39:25412QuicVersion QuicVersionMax() { return QuicSupportedVersions().front(); }
413
414QuicVersion QuicVersionMin() { return QuicSupportedVersions().back(); }
415
[email protected]c05a6d222013-12-16 19:42:03416IPAddressNumber Loopback4() {
[email protected]300ccd52014-01-25 08:00:19417 IPAddressNumber addr;
418 CHECK(ParseIPLiteralToNumber("127.0.0.1", &addr));
[email protected]c05a6d222013-12-16 19:42:03419 return addr;
420}
421
[email protected]8b37a092012-10-18 21:53:49422void CompareCharArraysWithHexError(
423 const string& description,
424 const char* actual,
425 const int actual_len,
426 const char* expected,
427 const int expected_len) {
[email protected]b007e632013-10-28 08:39:25428 EXPECT_EQ(actual_len, expected_len);
[email protected]8b37a092012-10-18 21:53:49429 const int min_len = min(actual_len, expected_len);
430 const int max_len = max(actual_len, expected_len);
[email protected]4356f0f2013-04-07 00:58:17431 scoped_ptr<bool[]> marks(new bool[max_len]);
[email protected]8b37a092012-10-18 21:53:49432 bool identical = (actual_len == expected_len);
433 for (int i = 0; i < min_len; ++i) {
434 if (actual[i] != expected[i]) {
435 marks[i] = true;
436 identical = false;
437 } else {
438 marks[i] = false;
439 }
440 }
441 for (int i = min_len; i < max_len; ++i) {
442 marks[i] = true;
443 }
444 if (identical) return;
445 ADD_FAILURE()
446 << "Description:\n"
447 << description
448 << "\n\nExpected:\n"
449 << HexDumpWithMarks(expected, expected_len, marks.get(), max_len)
450 << "\nActual:\n"
451 << HexDumpWithMarks(actual, actual_len, marks.get(), max_len);
452}
453
[email protected]b12764d2013-12-02 22:28:30454bool DecodeHexString(const base::StringPiece& hex, std::string* bytes) {
455 bytes->clear();
456 if (hex.empty())
457 return true;
458 std::vector<uint8> v;
459 if (!base::HexStringToBytes(hex.as_string(), &v))
460 return false;
461 if (!v.empty())
462 bytes->assign(reinterpret_cast<const char*>(&v[0]), v.size());
463 return true;
464}
465
[email protected]d3d15bf2013-01-30 02:51:54466static QuicPacket* ConstructPacketFromHandshakeMessage(
467 QuicGuid guid,
[email protected]14e8106c2013-03-14 16:25:33468 const CryptoHandshakeMessage& message,
469 bool should_include_version) {
[email protected]8b37a092012-10-18 21:53:49470 CryptoFramer crypto_framer;
[email protected]dc2cc742012-10-21 13:56:13471 scoped_ptr<QuicData> data(crypto_framer.ConstructHandshakeMessage(message));
[email protected]b007e632013-10-28 08:39:25472 QuicFramer quic_framer(QuicSupportedVersions(), QuicTime::Zero(), false);
[email protected]8b37a092012-10-18 21:53:49473
474 QuicPacketHeader header;
[email protected]c995c572013-01-18 05:43:20475 header.public_header.guid = guid;
[email protected]9db443912013-02-25 05:27:03476 header.public_header.reset_flag = false;
[email protected]14e8106c2013-03-14 16:25:33477 header.public_header.version_flag = should_include_version;
[email protected]8b37a092012-10-18 21:53:49478 header.packet_sequence_number = 1;
[email protected]9db443912013-02-25 05:27:03479 header.entropy_flag = false;
480 header.entropy_hash = 0;
481 header.fec_flag = false;
[email protected]8b37a092012-10-18 21:53:49482 header.fec_group = 0;
483
[email protected]be24ab22012-10-22 03:01:52484 QuicStreamFrame stream_frame(kCryptoStreamId, false, 0,
[email protected]5dafdb62013-11-14 01:24:26485 MakeIOVector(data->AsStringPiece()));
[email protected]8b37a092012-10-18 21:53:49486
[email protected]be24ab22012-10-22 03:01:52487 QuicFrame frame(&stream_frame);
488 QuicFrames frames;
489 frames.push_back(frame);
[email protected]3e60db82013-08-05 19:43:06490 return quic_framer.BuildUnsizedDataPacket(header, frames).packet;
[email protected]8b37a092012-10-18 21:53:49491}
492
[email protected]2532de12013-05-09 12:29:33493QuicPacket* ConstructHandshakePacket(QuicGuid guid, QuicTag tag) {
[email protected]d3d15bf2013-01-30 02:51:54494 CryptoHandshakeMessage message;
[email protected]ccc66e8a2013-03-26 08:26:14495 message.set_tag(tag);
[email protected]14e8106c2013-03-14 16:25:33496 return ConstructPacketFromHandshakeMessage(guid, message, false);
[email protected]d3d15bf2013-01-30 02:51:54497}
498
[email protected]ea825e02013-08-21 18:12:45499size_t GetPacketLengthForOneStream(
500 QuicVersion version,
501 bool include_version,
502 QuicSequenceNumberLength sequence_number_length,
503 InFecGroup is_in_fec_group,
504 size_t* payload_length) {
[email protected]f62262b2013-07-05 20:57:30505 *payload_length = 1;
506 const size_t stream_length =
[email protected]5dafdb62013-11-14 01:24:26507 NullEncrypter().GetCiphertextSize(*payload_length) +
[email protected]b064310782013-05-30 21:12:17508 QuicPacketCreator::StreamFramePacketOverhead(
[email protected]3e60db82013-08-05 19:43:06509 version, PACKET_8BYTE_GUID, include_version,
[email protected]ea825e02013-08-21 18:12:45510 sequence_number_length, is_in_fec_group);
[email protected]5dafdb62013-11-14 01:24:26511 const size_t ack_length = NullEncrypter().GetCiphertextSize(
[email protected]8e01c062013-10-31 07:35:31512 QuicFramer::GetMinAckFrameSize(
513 version, sequence_number_length, PACKET_1BYTE_SEQUENCE_NUMBER)) +
[email protected]25c31dc2013-06-05 17:56:04514 GetPacketHeaderSize(PACKET_8BYTE_GUID, include_version,
[email protected]ea825e02013-08-21 18:12:45515 sequence_number_length, is_in_fec_group);
[email protected]f62262b2013-07-05 20:57:30516 if (stream_length < ack_length) {
517 *payload_length = 1 + ack_length - stream_length;
518 }
519
[email protected]5dafdb62013-11-14 01:24:26520 return NullEncrypter().GetCiphertextSize(*payload_length) +
[email protected]f62262b2013-07-05 20:57:30521 QuicPacketCreator::StreamFramePacketOverhead(
[email protected]3e60db82013-08-05 19:43:06522 version, PACKET_8BYTE_GUID, include_version,
[email protected]ea825e02013-08-21 18:12:45523 sequence_number_length, is_in_fec_group);
[email protected]5351cc4b2013-03-03 07:22:41524}
525
[email protected]8e01c062013-10-31 07:35:31526TestEntropyCalculator::TestEntropyCalculator() { }
527
528TestEntropyCalculator::~TestEntropyCalculator() { }
529
[email protected]48878092013-07-26 14:51:56530QuicPacketEntropyHash TestEntropyCalculator::EntropyHash(
[email protected]9db443912013-02-25 05:27:03531 QuicPacketSequenceNumber sequence_number) const {
532 return 1u;
533}
534
[email protected]8e01c062013-10-31 07:35:31535MockEntropyCalculator::MockEntropyCalculator() { }
536
537MockEntropyCalculator::~MockEntropyCalculator() { }
538
[email protected]b064310782013-05-30 21:12:17539QuicConfig DefaultQuicConfig() {
540 QuicConfig config;
541 config.SetDefaults();
542 return config;
543}
544
[email protected]4d640792013-12-18 22:21:08545QuicVersionVector SupportedVersions(QuicVersion version) {
546 QuicVersionVector versions;
547 versions.push_back(version);
548 return versions;
549}
550
[email protected]c244c5a12013-05-07 20:55:04551bool TestDecompressorVisitor::OnDecompressedData(StringPiece data) {
552 data.AppendToString(&data_);
553 return true;
554}
555
[email protected]899951652013-05-16 12:52:39556void TestDecompressorVisitor::OnDecompressionError() {
557 error_ = true;
558}
559
[email protected]8b37a092012-10-18 21:53:49560} // namespace test
[email protected]8b37a092012-10-18 21:53:49561} // namespace net