| OLD | NEW |
| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "net/quic/crypto/null_encrypter.h" | 10 #include "net/quic/crypto/null_encrypter.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 using testing::_; | 31 using testing::_; |
| 32 | 32 |
| 33 namespace net { | 33 namespace net { |
| 34 namespace test { | 34 namespace test { |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 // Run tests with combinations of {QuicVersion, ToggleVersionSerialization}. | 37 // Run tests with combinations of {QuicVersion, ToggleVersionSerialization}. |
| 38 struct TestParams { | 38 struct TestParams { |
| 39 TestParams(QuicVersion version, | 39 TestParams(QuicVersion version, |
| 40 bool version_serialization, | 40 bool version_serialization, |
| 41 QuicConnectionIdLength length, | 41 QuicConnectionIdLength length) |
| 42 bool copy_use_prefetch) | |
| 43 : version(version), | 42 : version(version), |
| 44 connection_id_length(length), | 43 connection_id_length(length), |
| 45 version_serialization(version_serialization), | 44 version_serialization(version_serialization) {} |
| 46 copy_use_prefetch(copy_use_prefetch) {} | |
| 47 | 45 |
| 48 friend ostream& operator<<(ostream& os, const TestParams& p) { | 46 friend ostream& operator<<(ostream& os, const TestParams& p) { |
| 49 os << "{ client_version: " << QuicVersionToString(p.version) | 47 os << "{ client_version: " << QuicVersionToString(p.version) |
| 50 << " connection id length: " << p.connection_id_length | 48 << " connection id length: " << p.connection_id_length |
| 51 << " include version: " << p.version_serialization | 49 << " include version: " << p.version_serialization << " }"; |
| 52 << " copy use prefetch: " << p.copy_use_prefetch << " }"; | |
| 53 return os; | 50 return os; |
| 54 } | 51 } |
| 55 | 52 |
| 56 QuicVersion version; | 53 QuicVersion version; |
| 57 QuicConnectionIdLength connection_id_length; | 54 QuicConnectionIdLength connection_id_length; |
| 58 bool version_serialization; | 55 bool version_serialization; |
| 59 bool copy_use_prefetch; | |
| 60 }; | 56 }; |
| 61 | 57 |
| 62 // Constructs various test permutations. | 58 // Constructs various test permutations. |
| 63 vector<TestParams> GetTestParams() { | 59 vector<TestParams> GetTestParams() { |
| 64 vector<TestParams> params; | 60 vector<TestParams> params; |
| 65 QuicConnectionIdLength max = PACKET_8BYTE_CONNECTION_ID; | 61 QuicConnectionIdLength max = PACKET_8BYTE_CONNECTION_ID; |
| 66 QuicVersionVector all_supported_versions = QuicSupportedVersions(); | 62 QuicVersionVector all_supported_versions = QuicSupportedVersions(); |
| 67 for (size_t i = 0; i < all_supported_versions.size(); ++i) { | 63 for (size_t i = 0; i < all_supported_versions.size(); ++i) { |
| 68 params.push_back(TestParams(all_supported_versions[i], true, max, false)); | 64 params.push_back(TestParams(all_supported_versions[i], true, max)); |
| 69 params.push_back(TestParams(all_supported_versions[i], false, max, false)); | 65 params.push_back(TestParams(all_supported_versions[i], false, max)); |
| 70 } | 66 } |
| 71 params.push_back(TestParams(all_supported_versions[0], true, | 67 params.push_back( |
| 72 PACKET_0BYTE_CONNECTION_ID, false)); | 68 TestParams(all_supported_versions[0], true, PACKET_0BYTE_CONNECTION_ID)); |
| 73 params.push_back(TestParams(all_supported_versions[0], true, | 69 params.push_back( |
| 74 PACKET_1BYTE_CONNECTION_ID, false)); | 70 TestParams(all_supported_versions[0], true, PACKET_1BYTE_CONNECTION_ID)); |
| 75 params.push_back(TestParams(all_supported_versions[0], true, | 71 params.push_back( |
| 76 PACKET_4BYTE_CONNECTION_ID, false)); | 72 TestParams(all_supported_versions[0], true, PACKET_4BYTE_CONNECTION_ID)); |
| 77 params.push_back(TestParams(all_supported_versions[0], true, max, true)); | 73 params.push_back(TestParams(all_supported_versions[0], true, max)); |
| 78 return params; | 74 return params; |
| 79 } | 75 } |
| 80 | 76 |
| 81 class MockDelegate : public QuicPacketCreator::DelegateInterface { | 77 class MockDelegate : public QuicPacketCreator::DelegateInterface { |
| 82 public: | 78 public: |
| 83 MockDelegate() {} | 79 MockDelegate() {} |
| 84 ~MockDelegate() override {} | 80 ~MockDelegate() override {} |
| 85 | 81 |
| 86 MOCK_METHOD1(OnSerializedPacket, void(SerializedPacket* packet)); | 82 MOCK_METHOD1(OnSerializedPacket, void(SerializedPacket* packet)); |
| 87 MOCK_METHOD0(OnResetFecGroup, void()); | 83 MOCK_METHOD0(OnResetFecGroup, void()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 data_("foo"), | 119 data_("foo"), |
| 124 creator_(connection_id_, &client_framer_, &mock_random_, &delegate_), | 120 creator_(connection_id_, &client_framer_, &mock_random_, &delegate_), |
| 125 serialized_packet_(creator_.NoPacket()) { | 121 serialized_packet_(creator_.NoPacket()) { |
| 126 creator_.set_connection_id_length(GetParam().connection_id_length); | 122 creator_.set_connection_id_length(GetParam().connection_id_length); |
| 127 | 123 |
| 128 creator_.SetEncrypter(ENCRYPTION_INITIAL, new NullEncrypter()); | 124 creator_.SetEncrypter(ENCRYPTION_INITIAL, new NullEncrypter()); |
| 129 creator_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, new NullEncrypter()); | 125 creator_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, new NullEncrypter()); |
| 130 client_framer_.set_visitor(&framer_visitor_); | 126 client_framer_.set_visitor(&framer_visitor_); |
| 131 client_framer_.set_received_entropy_calculator(&entropy_calculator_); | 127 client_framer_.set_received_entropy_calculator(&entropy_calculator_); |
| 132 server_framer_.set_visitor(&framer_visitor_); | 128 server_framer_.set_visitor(&framer_visitor_); |
| 133 FLAGS_quic_packet_creator_prefetch = GetParam().copy_use_prefetch; | |
| 134 } | 129 } |
| 135 | 130 |
| 136 ~QuicPacketCreatorTest() override {} | 131 ~QuicPacketCreatorTest() override {} |
| 137 | 132 |
| 138 SerializedPacket SerializeAllFrames(const QuicFrames& frames) { | 133 SerializedPacket SerializeAllFrames(const QuicFrames& frames) { |
| 139 SerializedPacket packet = | 134 SerializedPacket packet = |
| 140 creator_.SerializeAllFrames(frames, buffer_, kMaxPacketSize); | 135 creator_.SerializeAllFrames(frames, buffer_, kMaxPacketSize); |
| 141 EXPECT_EQ(QuicPacketCreatorPeer::GetEncryptionLevel(&creator_), | 136 EXPECT_EQ(QuicPacketCreatorPeer::GetEncryptionLevel(&creator_), |
| 142 packet.encryption_level); | 137 packet.encryption_level); |
| 143 return packet; | 138 return packet; |
| (...skipping 1373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1517 creator_.SetCurrentPath(kDefaultPathId, 2, 10000 / kDefaultMaxPacketSize); | 1512 creator_.SetCurrentPath(kDefaultPathId, 2, 10000 / kDefaultMaxPacketSize); |
| 1518 // FEC packet consumes a packet number. | 1513 // FEC packet consumes a packet number. |
| 1519 EXPECT_EQ(64 * 256 - max_packets_per_fec_group, creator_.packet_number()); | 1514 EXPECT_EQ(64 * 256 - max_packets_per_fec_group, creator_.packet_number()); |
| 1520 EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, | 1515 EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, |
| 1521 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); | 1516 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); |
| 1522 } | 1517 } |
| 1523 | 1518 |
| 1524 } // namespace | 1519 } // namespace |
| 1525 } // namespace test | 1520 } // namespace test |
| 1526 } // namespace net | 1521 } // namespace net |
| OLD | NEW |