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

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

Issue 1421853006: Landing Recent QUIC changes until: Fri Oct 30 22:23:58 2015 +0000 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix comments Created 5 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_framer.cc ('k') | net/quic/quic_headers_stream.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/quic_framer.h" 5 #include "net/quic/quic_framer.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 2168 matching lines...) Expand 10 before | Expand all | Expand 10 after
2179 2179
2180 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 2180 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
2181 ASSERT_TRUE(visitor_.header_.get()); 2181 ASSERT_TRUE(visitor_.header_.get());
2182 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion)); 2182 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion));
2183 2183
2184 EXPECT_EQ(0u, visitor_.stream_frames_.size()); 2184 EXPECT_EQ(0u, visitor_.stream_frames_.size());
2185 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 2185 ASSERT_EQ(1u, visitor_.ack_frames_.size());
2186 QuicAckFrame* frame = visitor_.ack_frames_[0]; 2186 QuicAckFrame* frame = visitor_.ack_frames_[0];
2187 EXPECT_EQ(0xBA, frame->entropy_hash); 2187 EXPECT_EQ(0xBA, frame->entropy_hash);
2188 EXPECT_EQ(UINT64_C(0x0123456789ABF), frame->largest_observed); 2188 EXPECT_EQ(UINT64_C(0x0123456789ABF), frame->largest_observed);
2189 EXPECT_EQ(0u, frame->revived_packets.size()); 2189 EXPECT_EQ(0u, frame->latest_revived_packet);
2190 ASSERT_EQ(500u, frame->missing_packets.NumPacketsSlow()); 2190 ASSERT_EQ(500u, frame->missing_packets.NumPacketsSlow());
2191 EXPECT_EQ(UINT64_C(0x0123456789ABE) - 499, frame->missing_packets.Min()); 2191 EXPECT_EQ(UINT64_C(0x0123456789ABE) - 499, frame->missing_packets.Min());
2192 EXPECT_EQ(UINT64_C(0x0123456789ABE), frame->missing_packets.Max()); 2192 EXPECT_EQ(UINT64_C(0x0123456789ABE), frame->missing_packets.Max());
2193 2193
2194 // Verify that the packet re-serializes identically. 2194 // Verify that the packet re-serializes identically.
2195 QuicFrames frames; 2195 QuicFrames frames;
2196 frames.push_back(QuicFrame(frame)); 2196 frames.push_back(QuicFrame(frame));
2197 scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames)); 2197 scoped_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames));
2198 ASSERT_TRUE(data != nullptr); 2198 ASSERT_TRUE(data != nullptr);
2199 2199
(...skipping 1816 matching lines...) Expand 10 before | Expand all | Expand 10 after
4016 'e', 'f', 'g', 'h', 4016 'e', 'f', 'g', 'h',
4017 'i', 'j', 'k', 'l', 4017 'i', 'j', 'k', 'l',
4018 'm', 'n', 'o', 'p', 4018 'm', 'n', 'o', 'p',
4019 }; 4019 };
4020 // clang-format on 4020 // clang-format on
4021 4021
4022 scoped_ptr<QuicPacket> raw(new QuicPacket( 4022 scoped_ptr<QuicPacket> raw(new QuicPacket(
4023 AsChars(packet), arraysize(packet), false, PACKET_8BYTE_CONNECTION_ID, 4023 AsChars(packet), arraysize(packet), false, PACKET_8BYTE_CONNECTION_ID,
4024 !kIncludeVersion, PACKET_6BYTE_PACKET_NUMBER)); 4024 !kIncludeVersion, PACKET_6BYTE_PACKET_NUMBER));
4025 char buffer[kMaxPacketSize]; 4025 char buffer[kMaxPacketSize];
4026 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( 4026 size_t encrypted_length = framer_.EncryptPayload(
4027 ENCRYPTION_NONE, packet_number, *raw, buffer, kMaxPacketSize)); 4027 ENCRYPTION_NONE, packet_number, *raw, buffer, kMaxPacketSize);
4028 4028
4029 ASSERT_TRUE(encrypted.get() != nullptr); 4029 ASSERT_NE(0u, encrypted_length);
4030 EXPECT_TRUE(CheckEncryption(packet_number, raw.get())); 4030 EXPECT_TRUE(CheckEncryption(packet_number, raw.get()));
4031 } 4031 }
4032 4032
4033 TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) { 4033 TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) {
4034 QuicPacketNumber packet_number = UINT64_C(0x123456789ABC); 4034 QuicPacketNumber packet_number = UINT64_C(0x123456789ABC);
4035 // clang-format off 4035 // clang-format off
4036 unsigned char packet[] = { 4036 unsigned char packet[] = {
4037 // public flags (version, 8 byte connection_id) 4037 // public flags (version, 8 byte connection_id)
4038 0x3D, 4038 0x3D,
4039 // connection_id 4039 // connection_id
(...skipping 14 matching lines...) Expand all
4054 'e', 'f', 'g', 'h', 4054 'e', 'f', 'g', 'h',
4055 'i', 'j', 'k', 'l', 4055 'i', 'j', 'k', 'l',
4056 'm', 'n', 'o', 'p', 4056 'm', 'n', 'o', 'p',
4057 }; 4057 };
4058 // clang-format on 4058 // clang-format on
4059 4059
4060 scoped_ptr<QuicPacket> raw(new QuicPacket( 4060 scoped_ptr<QuicPacket> raw(new QuicPacket(
4061 AsChars(packet), arraysize(packet), false, PACKET_8BYTE_CONNECTION_ID, 4061 AsChars(packet), arraysize(packet), false, PACKET_8BYTE_CONNECTION_ID,
4062 kIncludeVersion, PACKET_6BYTE_PACKET_NUMBER)); 4062 kIncludeVersion, PACKET_6BYTE_PACKET_NUMBER));
4063 char buffer[kMaxPacketSize]; 4063 char buffer[kMaxPacketSize];
4064 scoped_ptr<QuicEncryptedPacket> encrypted(framer_.EncryptPayload( 4064 size_t encrypted_length = framer_.EncryptPayload(
4065 ENCRYPTION_NONE, packet_number, *raw, buffer, kMaxPacketSize)); 4065 ENCRYPTION_NONE, packet_number, *raw, buffer, kMaxPacketSize);
4066 4066
4067 ASSERT_TRUE(encrypted.get() != nullptr); 4067 ASSERT_NE(0u, encrypted_length);
4068 EXPECT_TRUE(CheckEncryption(packet_number, raw.get())); 4068 EXPECT_TRUE(CheckEncryption(packet_number, raw.get()));
4069 } 4069 }
4070 4070
4071 TEST_P(QuicFramerTest, AckTruncationLargePacket) { 4071 TEST_P(QuicFramerTest, AckTruncationLargePacket) {
4072 QuicPacketHeader header; 4072 QuicPacketHeader header;
4073 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210); 4073 header.public_header.connection_id = UINT64_C(0xFEDCBA9876543210);
4074 header.public_header.reset_flag = false; 4074 header.public_header.reset_flag = false;
4075 header.public_header.version_flag = false; 4075 header.public_header.version_flag = false;
4076 header.fec_flag = false; 4076 header.fec_flag = false;
4077 header.entropy_flag = false; 4077 header.entropy_flag = false;
4078 header.packet_number = UINT64_C(0x123456789ABC); 4078 header.packet_number = UINT64_C(0x123456789ABC);
4079 header.fec_group = 0; 4079 header.fec_group = 0;
4080 4080
4081 // Create a packet with just the ack. 4081 // Create a packet with just the ack.
4082 QuicAckFrame ack_frame = MakeAckFrameWithNackRanges(300, 0u); 4082 QuicAckFrame ack_frame = MakeAckFrameWithNackRanges(300, 0u);
4083 QuicFrame frame; 4083 QuicFrame frame;
4084 frame.type = ACK_FRAME; 4084 frame.type = ACK_FRAME;
4085 frame.ack_frame = &ack_frame; 4085 frame.ack_frame = &ack_frame;
4086 QuicFrames frames; 4086 QuicFrames frames;
4087 frames.push_back(frame); 4087 frames.push_back(frame);
4088 4088
4089 // Build an ack packet with truncation due to limit in number of nack ranges. 4089 // Build an ack packet with truncation due to limit in number of nack ranges.
4090 scoped_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); 4090 scoped_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames));
4091 ASSERT_TRUE(raw_ack_packet != nullptr); 4091 ASSERT_TRUE(raw_ack_packet != nullptr);
4092 char buffer[kMaxPacketSize]; 4092 char buffer[kMaxPacketSize];
4093 scoped_ptr<QuicEncryptedPacket> ack_packet( 4093 size_t encrypted_length =
4094 framer_.EncryptPayload(ENCRYPTION_NONE, header.packet_number, 4094 framer_.EncryptPayload(ENCRYPTION_NONE, header.packet_number,
4095 *raw_ack_packet, buffer, kMaxPacketSize)); 4095 *raw_ack_packet, buffer, kMaxPacketSize);
4096 ASSERT_NE(0u, encrypted_length);
4096 // Now make sure we can turn our ack packet back into an ack frame. 4097 // Now make sure we can turn our ack packet back into an ack frame.
4097 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet)); 4098 ASSERT_TRUE(framer_.ProcessPacket(
4099 QuicEncryptedPacket(buffer, encrypted_length, false)));
4098 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 4100 ASSERT_EQ(1u, visitor_.ack_frames_.size());
4099 QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; 4101 QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0];
4100 EXPECT_TRUE(processed_ack_frame.is_truncated); 4102 EXPECT_TRUE(processed_ack_frame.is_truncated);
4101 EXPECT_EQ(510u, processed_ack_frame.largest_observed); 4103 EXPECT_EQ(510u, processed_ack_frame.largest_observed);
4102 ASSERT_EQ(255u, processed_ack_frame.missing_packets.NumPacketsSlow()); 4104 ASSERT_EQ(255u, processed_ack_frame.missing_packets.NumPacketsSlow());
4103 EXPECT_EQ(1u, processed_ack_frame.missing_packets.Min()); 4105 EXPECT_EQ(1u, processed_ack_frame.missing_packets.Min());
4104 EXPECT_EQ(509u, processed_ack_frame.missing_packets.Max()); 4106 EXPECT_EQ(509u, processed_ack_frame.missing_packets.Max());
4105 } 4107 }
4106 4108
4107 TEST_P(QuicFramerTest, AckTruncationSmallPacket) { 4109 TEST_P(QuicFramerTest, AckTruncationSmallPacket) {
(...skipping 11 matching lines...) Expand all
4119 QuicFrame frame; 4121 QuicFrame frame;
4120 frame.type = ACK_FRAME; 4122 frame.type = ACK_FRAME;
4121 frame.ack_frame = &ack_frame; 4123 frame.ack_frame = &ack_frame;
4122 QuicFrames frames; 4124 QuicFrames frames;
4123 frames.push_back(frame); 4125 frames.push_back(frame);
4124 4126
4125 // Build an ack packet with truncation due to limit in number of nack ranges. 4127 // Build an ack packet with truncation due to limit in number of nack ranges.
4126 scoped_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames, 500)); 4128 scoped_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames, 500));
4127 ASSERT_TRUE(raw_ack_packet != nullptr); 4129 ASSERT_TRUE(raw_ack_packet != nullptr);
4128 char buffer[kMaxPacketSize]; 4130 char buffer[kMaxPacketSize];
4129 scoped_ptr<QuicEncryptedPacket> ack_packet( 4131 size_t encrypted_length =
4130 framer_.EncryptPayload(ENCRYPTION_NONE, header.packet_number, 4132 framer_.EncryptPayload(ENCRYPTION_NONE, header.packet_number,
4131 *raw_ack_packet, buffer, kMaxPacketSize)); 4133 *raw_ack_packet, buffer, kMaxPacketSize);
4134 ASSERT_NE(0u, encrypted_length);
4132 // Now make sure we can turn our ack packet back into an ack frame. 4135 // Now make sure we can turn our ack packet back into an ack frame.
4133 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet)); 4136 ASSERT_TRUE(framer_.ProcessPacket(
4137 QuicEncryptedPacket(buffer, encrypted_length, false)));
4134 ASSERT_EQ(1u, visitor_.ack_frames_.size()); 4138 ASSERT_EQ(1u, visitor_.ack_frames_.size());
4135 QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; 4139 QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0];
4136 EXPECT_TRUE(processed_ack_frame.is_truncated); 4140 EXPECT_TRUE(processed_ack_frame.is_truncated);
4137 EXPECT_EQ(476u, processed_ack_frame.largest_observed); 4141 EXPECT_EQ(476u, processed_ack_frame.largest_observed);
4138 ASSERT_EQ(238u, processed_ack_frame.missing_packets.NumPacketsSlow()); 4142 ASSERT_EQ(238u, processed_ack_frame.missing_packets.NumPacketsSlow());
4139 EXPECT_EQ(1u, processed_ack_frame.missing_packets.Min()); 4143 EXPECT_EQ(1u, processed_ack_frame.missing_packets.Min());
4140 EXPECT_EQ(475u, processed_ack_frame.missing_packets.Max()); 4144 EXPECT_EQ(475u, processed_ack_frame.missing_packets.Max());
4141 } 4145 }
4142 4146
4143 TEST_P(QuicFramerTest, CleanTruncation) { 4147 TEST_P(QuicFramerTest, CleanTruncation) {
(...skipping 14 matching lines...) Expand all
4158 QuicFrame frame; 4162 QuicFrame frame;
4159 frame.type = ACK_FRAME; 4163 frame.type = ACK_FRAME;
4160 frame.ack_frame = &ack_frame; 4164 frame.ack_frame = &ack_frame;
4161 QuicFrames frames; 4165 QuicFrames frames;
4162 frames.push_back(frame); 4166 frames.push_back(frame);
4163 4167
4164 scoped_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); 4168 scoped_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames));
4165 ASSERT_TRUE(raw_ack_packet != nullptr); 4169 ASSERT_TRUE(raw_ack_packet != nullptr);
4166 4170
4167 char buffer[kMaxPacketSize]; 4171 char buffer[kMaxPacketSize];
4168 scoped_ptr<QuicEncryptedPacket> ack_packet( 4172 size_t encrypted_length =
4169 framer_.EncryptPayload(ENCRYPTION_NONE, header.packet_number, 4173 framer_.EncryptPayload(ENCRYPTION_NONE, header.packet_number,
4170 *raw_ack_packet, buffer, kMaxPacketSize)); 4174 *raw_ack_packet, buffer, kMaxPacketSize);
4175 ASSERT_NE(0u, encrypted_length);
4171 4176
4172 // Now make sure we can turn our ack packet back into an ack frame. 4177 // Now make sure we can turn our ack packet back into an ack frame.
4173 ASSERT_TRUE(framer_.ProcessPacket(*ack_packet)); 4178 ASSERT_TRUE(framer_.ProcessPacket(
4179 QuicEncryptedPacket(buffer, encrypted_length, false)));
4174 4180
4175 // Test for clean truncation of the ack by comparing the length of the 4181 // Test for clean truncation of the ack by comparing the length of the
4176 // original packets to the re-serialized packets. 4182 // original packets to the re-serialized packets.
4177 frames.clear(); 4183 frames.clear();
4178 frame.type = ACK_FRAME; 4184 frame.type = ACK_FRAME;
4179 frame.ack_frame = visitor_.ack_frames_[0]; 4185 frame.ack_frame = visitor_.ack_frames_[0];
4180 frames.push_back(frame); 4186 frames.push_back(frame);
4181 4187
4182 size_t original_raw_length = raw_ack_packet->length(); 4188 size_t original_raw_length = raw_ack_packet->length();
4183 raw_ack_packet.reset(BuildDataPacket(header, frames)); 4189 raw_ack_packet.reset(BuildDataPacket(header, frames));
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
4395 EXPECT_CALL(visitor, OnStreamFrame(_)).Times(0); 4401 EXPECT_CALL(visitor, OnStreamFrame(_)).Times(0);
4396 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0); 4402 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0);
4397 EXPECT_CALL(visitor, OnPacketComplete()).Times(0); 4403 EXPECT_CALL(visitor, OnPacketComplete()).Times(0);
4398 4404
4399 EXPECT_FALSE(framer_.ProcessPacket(*packet)); 4405 EXPECT_FALSE(framer_.ProcessPacket(*packet));
4400 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); 4406 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error());
4401 } 4407 }
4402 4408
4403 } // namespace test 4409 } // namespace test
4404 } // namespace net 4410 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_framer.cc ('k') | net/quic/quic_headers_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698