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

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

Issue 1660593004: Landing Recent QUIC changes until 01/28/2016 18:41 UTC (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@Final_0202
Patch Set: Created 4 years, 10 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
« no previous file with comments | « net/quic/quic_packet_creator_test.cc ('k') | net/quic/quic_protocol.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_generator.h" 5 #include "net/quic/quic_packet_generator.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "net/quic/crypto/crypto_protocol.h" 10 #include "net/quic/crypto/crypto_protocol.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 for (SerializedPacket& packet : packets_) { 126 for (SerializedPacket& packet : packets_) {
127 QuicUtils::ClearSerializedPacket(&packet); 127 QuicUtils::ClearSerializedPacket(&packet);
128 } 128 }
129 } 129 }
130 130
131 void SavePacket(SerializedPacket* packet) { 131 void SavePacket(SerializedPacket* packet) {
132 packets_.push_back(*packet); 132 packets_.push_back(*packet);
133 ASSERT_FALSE(packet->packet->owns_buffer()); 133 ASSERT_FALSE(packet->packet->owns_buffer());
134 scoped_ptr<QuicEncryptedPacket> encrypted_deleter(packets_.back().packet); 134 scoped_ptr<QuicEncryptedPacket> encrypted_deleter(packets_.back().packet);
135 packets_.back().packet = packets_.back().packet->Clone(); 135 packets_.back().packet = packets_.back().packet->Clone();
136 packet->retransmittable_frames.clear();
136 } 137 }
137 138
138 protected: 139 protected:
139 QuicRstStreamFrame* CreateRstStreamFrame() { 140 QuicRstStreamFrame* CreateRstStreamFrame() {
140 return new QuicRstStreamFrame(1, QUIC_STREAM_NO_ERROR, 0); 141 return new QuicRstStreamFrame(1, QUIC_STREAM_NO_ERROR, 0);
141 } 142 }
142 143
143 QuicGoAwayFrame* CreateGoAwayFrame() { 144 QuicGoAwayFrame* CreateGoAwayFrame() {
144 return new QuicGoAwayFrame(QUIC_NO_ERROR, 1, string()); 145 return new QuicGoAwayFrame(QUIC_NO_ERROR, 1, string());
145 } 146 }
146 147
147 void CheckPacketContains(const PacketContents& contents, 148 void CheckPacketContains(const PacketContents& contents,
148 size_t packet_index) { 149 size_t packet_index) {
149 ASSERT_GT(packets_.size(), packet_index); 150 ASSERT_GT(packets_.size(), packet_index);
150 const SerializedPacket& packet = packets_[packet_index]; 151 const SerializedPacket& packet = packets_[packet_index];
151 size_t num_retransmittable_frames = 152 size_t num_retransmittable_frames =
152 contents.num_connection_close_frames + contents.num_goaway_frames + 153 contents.num_connection_close_frames + contents.num_goaway_frames +
153 contents.num_rst_stream_frames + contents.num_stream_frames + 154 contents.num_rst_stream_frames + contents.num_stream_frames +
154 contents.num_ping_frames; 155 contents.num_ping_frames;
155 size_t num_frames = 156 size_t num_frames =
156 contents.num_ack_frames + contents.num_stop_waiting_frames + 157 contents.num_ack_frames + contents.num_stop_waiting_frames +
157 contents.num_mtu_discovery_frames + num_retransmittable_frames; 158 contents.num_mtu_discovery_frames + num_retransmittable_frames;
158 159
159 if (num_retransmittable_frames == 0) { 160 if (num_retransmittable_frames == 0) {
160 ASSERT_TRUE(packet.retransmittable_frames == nullptr); 161 ASSERT_TRUE(packet.retransmittable_frames.empty());
161 } else { 162 } else {
162 ASSERT_TRUE(packet.retransmittable_frames != nullptr); 163 ASSERT_FALSE(packet.retransmittable_frames.empty());
163 EXPECT_EQ(num_retransmittable_frames, 164 EXPECT_EQ(num_retransmittable_frames,
164 packet.retransmittable_frames->size()); 165 packet.retransmittable_frames.size());
165 } 166 }
166 167
167 ASSERT_TRUE(packet.packet != nullptr); 168 ASSERT_TRUE(packet.packet != nullptr);
168 ASSERT_TRUE(simple_framer_.ProcessPacket(*packet.packet)); 169 ASSERT_TRUE(simple_framer_.ProcessPacket(*packet.packet));
169 EXPECT_EQ(num_frames, simple_framer_.num_frames()); 170 EXPECT_EQ(num_frames, simple_framer_.num_frames());
170 EXPECT_EQ(contents.num_ack_frames, simple_framer_.ack_frames().size()); 171 EXPECT_EQ(contents.num_ack_frames, simple_framer_.ack_frames().size());
171 EXPECT_EQ(contents.num_connection_close_frames, 172 EXPECT_EQ(contents.num_connection_close_frames,
172 simple_framer_.connection_close_frames().size()); 173 simple_framer_.connection_close_frames().size());
173 EXPECT_EQ(contents.num_goaway_frames, 174 EXPECT_EQ(contents.num_goaway_frames,
174 simple_framer_.goaway_frames().size()); 175 simple_framer_.goaway_frames().size());
175 EXPECT_EQ(contents.num_rst_stream_frames, 176 EXPECT_EQ(contents.num_rst_stream_frames,
176 simple_framer_.rst_stream_frames().size()); 177 simple_framer_.rst_stream_frames().size());
177 EXPECT_EQ(contents.num_stream_frames, 178 EXPECT_EQ(contents.num_stream_frames,
178 simple_framer_.stream_frames().size()); 179 simple_framer_.stream_frames().size());
179 EXPECT_EQ(contents.num_stop_waiting_frames, 180 EXPECT_EQ(contents.num_stop_waiting_frames,
180 simple_framer_.stop_waiting_frames().size()); 181 simple_framer_.stop_waiting_frames().size());
181 EXPECT_EQ(contents.fec_group, simple_framer_.header().fec_group); 182 EXPECT_EQ(contents.fec_group, simple_framer_.header().fec_group);
182 183
183 // From the receiver's perspective, MTU discovery frames are ping frames. 184 // From the receiver's perspective, MTU discovery frames are ping frames.
184 EXPECT_EQ(contents.num_ping_frames + contents.num_mtu_discovery_frames, 185 EXPECT_EQ(contents.num_ping_frames + contents.num_mtu_discovery_frames,
185 simple_framer_.ping_frames().size()); 186 simple_framer_.ping_frames().size());
186 } 187 }
187 188
188 void CheckPacketHasSingleStreamFrame(size_t packet_index) { 189 void CheckPacketHasSingleStreamFrame(size_t packet_index) {
189 ASSERT_GT(packets_.size(), packet_index); 190 ASSERT_GT(packets_.size(), packet_index);
190 const SerializedPacket& packet = packets_[packet_index]; 191 const SerializedPacket& packet = packets_[packet_index];
191 ASSERT_TRUE(packet.retransmittable_frames != nullptr); 192 ASSERT_FALSE(packet.retransmittable_frames.empty());
192 EXPECT_EQ(1u, packet.retransmittable_frames->size()); 193 EXPECT_EQ(1u, packet.retransmittable_frames.size());
193 ASSERT_TRUE(packet.packet != nullptr); 194 ASSERT_TRUE(packet.packet != nullptr);
194 ASSERT_TRUE(simple_framer_.ProcessPacket(*packet.packet)); 195 ASSERT_TRUE(simple_framer_.ProcessPacket(*packet.packet));
195 EXPECT_EQ(1u, simple_framer_.num_frames()); 196 EXPECT_EQ(1u, simple_framer_.num_frames());
196 EXPECT_EQ(1u, simple_framer_.stream_frames().size()); 197 EXPECT_EQ(1u, simple_framer_.stream_frames().size());
197 } 198 }
198 199
199 void CheckAllPacketsHaveSingleStreamFrame() { 200 void CheckAllPacketsHaveSingleStreamFrame() {
200 for (size_t i = 0; i < packets_.size(); i++) { 201 for (size_t i = 0; i < packets_.size(); i++) {
201 CheckPacketHasSingleStreamFrame(i); 202 CheckPacketHasSingleStreamFrame(i);
202 } 203 }
203 } 204 }
204 205
205 void CheckPacketIsFec(size_t packet_index, QuicPacketNumber fec_group) { 206 void CheckPacketIsFec(size_t packet_index, QuicPacketNumber fec_group) {
206 ASSERT_GT(packets_.size(), packet_index); 207 ASSERT_GT(packets_.size(), packet_index);
207 const SerializedPacket& packet = packets_[packet_index]; 208 const SerializedPacket& packet = packets_[packet_index];
208 ASSERT_TRUE(packet.retransmittable_frames == nullptr); 209 ASSERT_TRUE(packet.retransmittable_frames.empty());
209 ASSERT_TRUE(packet.packet != nullptr); 210 ASSERT_TRUE(packet.packet != nullptr);
210 ASSERT_TRUE(simple_framer_.ProcessPacket(*packet.packet)); 211 ASSERT_TRUE(simple_framer_.ProcessPacket(*packet.packet));
211 EXPECT_TRUE(simple_framer_.header().fec_flag); 212 EXPECT_TRUE(simple_framer_.header().fec_flag);
212 } 213 }
213 214
214 QuicIOVector CreateData(size_t len) { 215 QuicIOVector CreateData(size_t len) {
215 data_array_.reset(new char[len]); 216 data_array_.reset(new char[len]);
216 memset(data_array_.get(), '?', len); 217 memset(data_array_.get(), '?', len);
217 iov_.iov_base = data_array_.get(); 218 iov_.iov_base = data_array_.get();
218 iov_.iov_len = len; 219 iov_.iov_len = len;
(...skipping 1488 matching lines...) Expand 10 before | Expand all | Expand 10 after
1707 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 1708 EXPECT_CALL(delegate_, OnSerializedPacket(_))
1708 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); 1709 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket));
1709 generator_.FlushAllQueuedFrames(); 1710 generator_.FlushAllQueuedFrames();
1710 EXPECT_FALSE(generator_.HasQueuedFrames()); 1711 EXPECT_FALSE(generator_.HasQueuedFrames());
1711 generator_.SetCurrentPath(kTestPathId1, 1, 0); 1712 generator_.SetCurrentPath(kTestPathId1, 1, 0);
1712 EXPECT_EQ(kTestPathId1, QuicPacketCreatorPeer::GetCurrentPath(creator_)); 1713 EXPECT_EQ(kTestPathId1, QuicPacketCreatorPeer::GetCurrentPath(creator_));
1713 } 1714 }
1714 1715
1715 } // namespace test 1716 } // namespace test
1716 } // namespace net 1717 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_packet_creator_test.cc ('k') | net/quic/quic_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698