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

Side by Side Diff: net/quic/quic_packet_creator_test.cc

Issue 687033002: Adding an option for peers to negotiate the length of the QUIC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Final_1028
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « net/quic/quic_packet_creator.cc ('k') | net/quic/quic_packet_generator.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/quic_packet_creator.h" 5 #include "net/quic/quic_packet_creator.h"
6 6
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "net/quic/crypto/null_encrypter.h" 8 #include "net/quic/crypto/null_encrypter.h"
9 #include "net/quic/crypto/quic_decrypter.h" 9 #include "net/quic/crypto/quic_decrypter.h"
10 #include "net/quic/crypto/quic_encrypter.h" 10 #include "net/quic/crypto/quic_encrypter.h"
(...skipping 15 matching lines...) Expand all
26 using testing::SaveArg; 26 using testing::SaveArg;
27 using testing::_; 27 using testing::_;
28 28
29 namespace net { 29 namespace net {
30 namespace test { 30 namespace test {
31 namespace { 31 namespace {
32 32
33 // Run tests with combinations of {QuicVersion, ToggleVersionSerialization}. 33 // Run tests with combinations of {QuicVersion, ToggleVersionSerialization}.
34 struct TestParams { 34 struct TestParams {
35 TestParams(QuicVersion version, 35 TestParams(QuicVersion version,
36 bool version_serialization) 36 bool version_serialization,
37 QuicConnectionIdLength length)
37 : version(version), 38 : version(version),
39 connection_id_length(length),
38 version_serialization(version_serialization) { 40 version_serialization(version_serialization) {
39 } 41 }
40 42
41 friend ostream& operator<<(ostream& os, const TestParams& p) { 43 friend ostream& operator<<(ostream& os, const TestParams& p) {
42 os << "{ client_version: " << QuicVersionToString(p.version) 44 os << "{ client_version: " << QuicVersionToString(p.version)
45 << " connection id length: " << p.connection_id_length
43 << " include version: " << p.version_serialization << " }"; 46 << " include version: " << p.version_serialization << " }";
44 return os; 47 return os;
45 } 48 }
46 49
47 QuicVersion version; 50 QuicVersion version;
51 QuicConnectionIdLength connection_id_length;
48 bool version_serialization; 52 bool version_serialization;
49 }; 53 };
50 54
51 // Constructs various test permutations. 55 // Constructs various test permutations.
52 vector<TestParams> GetTestParams() { 56 vector<TestParams> GetTestParams() {
53 vector<TestParams> params; 57 vector<TestParams> params;
58 QuicConnectionIdLength max = PACKET_8BYTE_CONNECTION_ID;
54 QuicVersionVector all_supported_versions = QuicSupportedVersions(); 59 QuicVersionVector all_supported_versions = QuicSupportedVersions();
55 for (size_t i = 0; i < all_supported_versions.size(); ++i) { 60 for (size_t i = 0; i < all_supported_versions.size(); ++i) {
56 params.push_back(TestParams(all_supported_versions[i], true)); 61 params.push_back(TestParams(all_supported_versions[i], true, max));
57 params.push_back(TestParams(all_supported_versions[i], false)); 62 params.push_back(TestParams(all_supported_versions[i], false, max));
58 } 63 }
64 params.push_back(TestParams(
65 all_supported_versions[0], true, PACKET_0BYTE_CONNECTION_ID));
66 params.push_back(TestParams(
67 all_supported_versions[0], true, PACKET_1BYTE_CONNECTION_ID));
68 params.push_back(TestParams(
69 all_supported_versions[0], true, PACKET_4BYTE_CONNECTION_ID));
59 return params; 70 return params;
60 } 71 }
61 72
62 class QuicPacketCreatorTest : public ::testing::TestWithParam<TestParams> { 73 class QuicPacketCreatorTest : public ::testing::TestWithParam<TestParams> {
63 protected: 74 protected:
64 QuicPacketCreatorTest() 75 QuicPacketCreatorTest()
65 : server_framer_(SupportedVersions(GetParam().version), QuicTime::Zero(), 76 : server_framer_(SupportedVersions(GetParam().version), QuicTime::Zero(),
66 true), 77 true),
67 client_framer_(SupportedVersions(GetParam().version), QuicTime::Zero(), 78 client_framer_(SupportedVersions(GetParam().version), QuicTime::Zero(),
68 false), 79 false),
69 sequence_number_(0), 80 sequence_number_(0),
70 connection_id_(2), 81 connection_id_(2),
71 data_("foo"), 82 data_("foo"),
72 creator_(connection_id_, &client_framer_, &mock_random_) { 83 creator_(connection_id_, &client_framer_, &mock_random_) {
84 creator_.set_connection_id_length(GetParam().connection_id_length);
73 client_framer_.set_visitor(&framer_visitor_); 85 client_framer_.set_visitor(&framer_visitor_);
74 client_framer_.set_received_entropy_calculator(&entropy_calculator_); 86 client_framer_.set_received_entropy_calculator(&entropy_calculator_);
75 server_framer_.set_visitor(&framer_visitor_); 87 server_framer_.set_visitor(&framer_visitor_);
76 } 88 }
77 89
78 virtual ~QuicPacketCreatorTest() override { 90 virtual ~QuicPacketCreatorTest() override {
79 } 91 }
80 92
81 void ProcessPacket(QuicPacket* packet) { 93 void ProcessPacket(QuicPacket* packet) {
82 scoped_ptr<QuicEncryptedPacket> encrypted( 94 scoped_ptr<QuicEncryptedPacket> encrypted(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 testing::StrictMock<MockFramerVisitor> framer_visitor_; 149 testing::StrictMock<MockFramerVisitor> framer_visitor_;
138 QuicPacketSequenceNumber sequence_number_; 150 QuicPacketSequenceNumber sequence_number_;
139 QuicConnectionId connection_id_; 151 QuicConnectionId connection_id_;
140 string data_; 152 string data_;
141 MockRandom mock_random_; 153 MockRandom mock_random_;
142 QuicPacketCreator creator_; 154 QuicPacketCreator creator_;
143 MockEntropyCalculator entropy_calculator_; 155 MockEntropyCalculator entropy_calculator_;
144 }; 156 };
145 157
146 // Run all packet creator tests with all supported versions of QUIC, and with 158 // Run all packet creator tests with all supported versions of QUIC, and with
147 // and without version in the packet header. 159 // and without version in the packet header, as well as doing a run for each
160 // length of truncated connection id.
148 INSTANTIATE_TEST_CASE_P(QuicPacketCreatorTests, 161 INSTANTIATE_TEST_CASE_P(QuicPacketCreatorTests,
149 QuicPacketCreatorTest, 162 QuicPacketCreatorTest,
150 ::testing::ValuesIn(GetTestParams())); 163 ::testing::ValuesIn(GetTestParams()));
151 164
152 TEST_P(QuicPacketCreatorTest, SerializeFrames) { 165 TEST_P(QuicPacketCreatorTest, SerializeFrames) {
153 frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u)))); 166 frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u))));
154 frames_.push_back(QuicFrame(new QuicStreamFrame(0u, false, 0u, IOVector()))); 167 frames_.push_back(QuicFrame(new QuicStreamFrame(0u, false, 0u, IOVector())));
155 frames_.push_back(QuicFrame(new QuicStreamFrame(0u, true, 0u, IOVector()))); 168 frames_.push_back(QuicFrame(new QuicStreamFrame(0u, true, 0u, IOVector())));
156 SerializedPacket serialized = creator_.SerializeAllFrames(frames_); 169 SerializedPacket serialized = creator_.SerializeAllFrames(frames_);
157 delete frames_[0].ack_frame; 170 delete frames_[0].ack_frame;
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 847
835 TEST_P(QuicPacketCreatorTest, CreateStreamFrameTooLarge) { 848 TEST_P(QuicPacketCreatorTest, CreateStreamFrameTooLarge) {
836 if (!GetParam().version_serialization) { 849 if (!GetParam().version_serialization) {
837 creator_.StopSendingVersion(); 850 creator_.StopSendingVersion();
838 } 851 }
839 // A string larger than fits into a frame. 852 // A string larger than fits into a frame.
840 size_t payload_length; 853 size_t payload_length;
841 creator_.set_max_packet_length(GetPacketLengthForOneStream( 854 creator_.set_max_packet_length(GetPacketLengthForOneStream(
842 client_framer_.version(), 855 client_framer_.version(),
843 QuicPacketCreatorPeer::SendVersionInPacket(&creator_), 856 QuicPacketCreatorPeer::SendVersionInPacket(&creator_),
857 creator_.connection_id_length(),
844 PACKET_1BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP, &payload_length)); 858 PACKET_1BYTE_SEQUENCE_NUMBER, NOT_IN_FEC_GROUP, &payload_length));
845 QuicFrame frame; 859 QuicFrame frame;
846 const string too_long_payload(payload_length * 2, 'a'); 860 const string too_long_payload(payload_length * 2, 'a');
847 size_t consumed = creator_.CreateStreamFrame( 861 size_t consumed = creator_.CreateStreamFrame(
848 1u, MakeIOVector(too_long_payload), 0u, true, &frame); 862 1u, MakeIOVector(too_long_payload), 0u, true, &frame);
849 EXPECT_EQ(payload_length, consumed); 863 EXPECT_EQ(payload_length, consumed);
850 const string payload(payload_length, 'a'); 864 const string payload(payload_length, 'a');
851 CheckStreamFrame(frame, 1u, payload, 0u, false); 865 CheckStreamFrame(frame, 1u, payload, 0u, false);
852 delete frame.stream_frame; 866 delete frame.stream_frame;
853 } 867 }
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 // After 64 calls, BoolSource will refresh the bucket - make sure it does. 1026 // After 64 calls, BoolSource will refresh the bucket - make sure it does.
1013 mock_random_.ChangeValue(); 1027 mock_random_.ChangeValue();
1014 } 1028 }
1015 1029
1016 delete frames_[0].stream_frame; 1030 delete frames_[0].stream_frame;
1017 } 1031 }
1018 1032
1019 } // namespace 1033 } // namespace
1020 } // namespace test 1034 } // namespace test
1021 } // namespace net 1035 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_packet_creator.cc ('k') | net/quic/quic_packet_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698