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

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

Issue 180723003: Land Recent QUIC Changes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unintialized memory error Created 6 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 | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_packet_generator.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 "net/quic/crypto/crypto_protocol.h" 9 #include "net/quic/crypto/crypto_protocol.h"
10 #include "net/quic/crypto/null_encrypter.h" 10 #include "net/quic/crypto/null_encrypter.h"
(...skipping 21 matching lines...) Expand all
32 public: 32 public:
33 MockDelegate() {} 33 MockDelegate() {}
34 virtual ~MockDelegate() {} 34 virtual ~MockDelegate() {}
35 35
36 MOCK_METHOD3(ShouldGeneratePacket, 36 MOCK_METHOD3(ShouldGeneratePacket,
37 bool(TransmissionType transmission_type, 37 bool(TransmissionType transmission_type,
38 HasRetransmittableData retransmittable, 38 HasRetransmittableData retransmittable,
39 IsHandshake handshake)); 39 IsHandshake handshake));
40 MOCK_METHOD0(CreateAckFrame, QuicAckFrame*()); 40 MOCK_METHOD0(CreateAckFrame, QuicAckFrame*());
41 MOCK_METHOD0(CreateFeedbackFrame, QuicCongestionFeedbackFrame*()); 41 MOCK_METHOD0(CreateFeedbackFrame, QuicCongestionFeedbackFrame*());
42 MOCK_METHOD0(CreateStopWaitingFrame, QuicStopWaitingFrame*());
42 MOCK_METHOD1(OnSerializedPacket, bool(const SerializedPacket& packet)); 43 MOCK_METHOD1(OnSerializedPacket, bool(const SerializedPacket& packet));
43 MOCK_METHOD2(CloseConnection, void(QuicErrorCode, bool)); 44 MOCK_METHOD2(CloseConnection, void(QuicErrorCode, bool));
44 45
45 void SetCanWriteAnything() { 46 void SetCanWriteAnything() {
46 EXPECT_CALL(*this, ShouldGeneratePacket(NOT_RETRANSMISSION, _, _)) 47 EXPECT_CALL(*this, ShouldGeneratePacket(NOT_RETRANSMISSION, _, _))
47 .WillRepeatedly(Return(true)); 48 .WillRepeatedly(Return(true));
48 EXPECT_CALL(*this, ShouldGeneratePacket(NOT_RETRANSMISSION, 49 EXPECT_CALL(*this, ShouldGeneratePacket(NOT_RETRANSMISSION,
49 NO_RETRANSMITTABLE_DATA, _)) 50 NO_RETRANSMITTABLE_DATA, _))
50 .WillRepeatedly(Return(true)); 51 .WillRepeatedly(Return(true));
51 } 52 }
(...skipping 22 matching lines...) Expand all
74 // Simple struct for describing the contents of a packet. 75 // Simple struct for describing the contents of a packet.
75 // Useful in conjunction with a SimpleQuicFrame for validating 76 // Useful in conjunction with a SimpleQuicFrame for validating
76 // that a packet contains the expected frames. 77 // that a packet contains the expected frames.
77 struct PacketContents { 78 struct PacketContents {
78 PacketContents() 79 PacketContents()
79 : num_ack_frames(0), 80 : num_ack_frames(0),
80 num_connection_close_frames(0), 81 num_connection_close_frames(0),
81 num_feedback_frames(0), 82 num_feedback_frames(0),
82 num_goaway_frames(0), 83 num_goaway_frames(0),
83 num_rst_stream_frames(0), 84 num_rst_stream_frames(0),
85 num_stop_waiting_frames(0),
84 num_stream_frames(0), 86 num_stream_frames(0),
85 fec_group(0) { 87 fec_group(0) {
86 } 88 }
87 89
88 size_t num_ack_frames; 90 size_t num_ack_frames;
89 size_t num_connection_close_frames; 91 size_t num_connection_close_frames;
90 size_t num_feedback_frames; 92 size_t num_feedback_frames;
91 size_t num_goaway_frames; 93 size_t num_goaway_frames;
92 size_t num_rst_stream_frames; 94 size_t num_rst_stream_frames;
95 size_t num_stop_waiting_frames;
93 size_t num_stream_frames; 96 size_t num_stream_frames;
94 97
95 QuicFecGroupNumber fec_group; 98 QuicFecGroupNumber fec_group;
96 }; 99 };
97 100
98 } // namespace 101 } // namespace
99 102
100 class QuicPacketGeneratorTest : public ::testing::Test { 103 class QuicPacketGeneratorTest : public ::testing::Test {
101 protected: 104 protected:
102 QuicPacketGeneratorTest() 105 QuicPacketGeneratorTest()
(...skipping 25 matching lines...) Expand all
128 return new QuicAckFrame(0, QuicTime::Zero(), 0); 131 return new QuicAckFrame(0, QuicTime::Zero(), 0);
129 } 132 }
130 133
131 QuicCongestionFeedbackFrame* CreateFeedbackFrame() { 134 QuicCongestionFeedbackFrame* CreateFeedbackFrame() {
132 QuicCongestionFeedbackFrame* frame = new QuicCongestionFeedbackFrame; 135 QuicCongestionFeedbackFrame* frame = new QuicCongestionFeedbackFrame;
133 frame->type = kFixRate; 136 frame->type = kFixRate;
134 frame->fix_rate.bitrate = QuicBandwidth::FromBytesPerSecond(42); 137 frame->fix_rate.bitrate = QuicBandwidth::FromBytesPerSecond(42);
135 return frame; 138 return frame;
136 } 139 }
137 140
141 QuicStopWaitingFrame* CreateStopWaitingFrame() {
142 QuicStopWaitingFrame* frame = new QuicStopWaitingFrame();
143 frame->entropy_hash = 0;
144 frame->least_unacked = 0;
145 return frame;
146 }
147
138 QuicRstStreamFrame* CreateRstStreamFrame() { 148 QuicRstStreamFrame* CreateRstStreamFrame() {
139 return new QuicRstStreamFrame(1, QUIC_STREAM_NO_ERROR, 0); 149 return new QuicRstStreamFrame(1, QUIC_STREAM_NO_ERROR, 0);
140 } 150 }
141 151
142 QuicGoAwayFrame* CreateGoAwayFrame() { 152 QuicGoAwayFrame* CreateGoAwayFrame() {
143 return new QuicGoAwayFrame(QUIC_NO_ERROR, 1, string()); 153 return new QuicGoAwayFrame(QUIC_NO_ERROR, 1, string());
144 } 154 }
145 155
146 void CheckPacketContains(const PacketContents& contents, 156 void CheckPacketContains(const PacketContents& contents,
147 const SerializedPacket& packet) { 157 const SerializedPacket& packet) {
148 size_t num_retransmittable_frames = contents.num_connection_close_frames + 158 size_t num_retransmittable_frames = contents.num_connection_close_frames +
149 contents.num_goaway_frames + contents.num_rst_stream_frames + 159 contents.num_goaway_frames + contents.num_rst_stream_frames +
150 contents.num_stream_frames; 160 contents.num_stream_frames;
151 size_t num_frames = contents.num_feedback_frames + contents.num_ack_frames + 161 size_t num_frames = contents.num_feedback_frames + contents.num_ack_frames +
152 num_retransmittable_frames; 162 contents.num_stop_waiting_frames + num_retransmittable_frames;
153 163
154 if (num_retransmittable_frames == 0) { 164 if (num_retransmittable_frames == 0) {
155 ASSERT_TRUE(packet.retransmittable_frames == NULL); 165 ASSERT_TRUE(packet.retransmittable_frames == NULL);
156 } else { 166 } else {
157 ASSERT_TRUE(packet.retransmittable_frames != NULL); 167 ASSERT_TRUE(packet.retransmittable_frames != NULL);
158 EXPECT_EQ(num_retransmittable_frames, 168 EXPECT_EQ(num_retransmittable_frames,
159 packet.retransmittable_frames->frames().size()); 169 packet.retransmittable_frames->frames().size());
160 } 170 }
161 171
162 ASSERT_TRUE(packet.packet != NULL); 172 ASSERT_TRUE(packet.packet != NULL);
163 ASSERT_TRUE(simple_framer_.ProcessPacket(*packet.packet)); 173 ASSERT_TRUE(simple_framer_.ProcessPacket(*packet.packet));
164 EXPECT_EQ(num_frames, simple_framer_.num_frames()); 174 EXPECT_EQ(num_frames, simple_framer_.num_frames());
165 EXPECT_EQ(contents.num_ack_frames, simple_framer_.ack_frames().size()); 175 EXPECT_EQ(contents.num_ack_frames, simple_framer_.ack_frames().size());
166 EXPECT_EQ(contents.num_connection_close_frames, 176 EXPECT_EQ(contents.num_connection_close_frames,
167 simple_framer_.connection_close_frames().size()); 177 simple_framer_.connection_close_frames().size());
168 EXPECT_EQ(contents.num_feedback_frames, 178 EXPECT_EQ(contents.num_feedback_frames,
169 simple_framer_.feedback_frames().size()); 179 simple_framer_.feedback_frames().size());
170 EXPECT_EQ(contents.num_goaway_frames, 180 EXPECT_EQ(contents.num_goaway_frames,
171 simple_framer_.goaway_frames().size()); 181 simple_framer_.goaway_frames().size());
172 EXPECT_EQ(contents.num_rst_stream_frames, 182 EXPECT_EQ(contents.num_rst_stream_frames,
173 simple_framer_.rst_stream_frames().size()); 183 simple_framer_.rst_stream_frames().size());
174 EXPECT_EQ(contents.num_stream_frames, 184 EXPECT_EQ(contents.num_stream_frames,
175 simple_framer_.stream_frames().size()); 185 simple_framer_.stream_frames().size());
186 EXPECT_EQ(contents.num_stop_waiting_frames,
187 simple_framer_.stop_waiting_frames().size());
176 EXPECT_EQ(contents.fec_group, simple_framer_.header().fec_group); 188 EXPECT_EQ(contents.fec_group, simple_framer_.header().fec_group);
177 } 189 }
178 190
179 void CheckPacketHasSingleStreamFrame(const SerializedPacket& packet) { 191 void CheckPacketHasSingleStreamFrame(const SerializedPacket& packet) {
180 ASSERT_TRUE(packet.retransmittable_frames != NULL); 192 ASSERT_TRUE(packet.retransmittable_frames != NULL);
181 EXPECT_EQ(1u, packet.retransmittable_frames->frames().size()); 193 EXPECT_EQ(1u, packet.retransmittable_frames->frames().size());
182 ASSERT_TRUE(packet.packet != NULL); 194 ASSERT_TRUE(packet.packet != NULL);
183 ASSERT_TRUE(simple_framer_.ProcessPacket(*packet.packet)); 195 ASSERT_TRUE(simple_framer_.ProcessPacket(*packet.packet));
184 EXPECT_EQ(1u, simple_framer_.num_frames()); 196 EXPECT_EQ(1u, simple_framer_.num_frames());
185 EXPECT_EQ(1u, simple_framer_.stream_frames().size()); 197 EXPECT_EQ(1u, simple_framer_.stream_frames().size());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 232
221 class MockDebugDelegate : public QuicPacketGenerator::DebugDelegateInterface { 233 class MockDebugDelegate : public QuicPacketGenerator::DebugDelegateInterface {
222 public: 234 public:
223 MOCK_METHOD1(OnFrameAddedToPacket, 235 MOCK_METHOD1(OnFrameAddedToPacket,
224 void(const QuicFrame&)); 236 void(const QuicFrame&));
225 }; 237 };
226 238
227 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_NotWritable) { 239 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_NotWritable) {
228 delegate_.SetCanNotWrite(); 240 delegate_.SetCanNotWrite();
229 241
230 generator_.SetShouldSendAck(false); 242 generator_.SetShouldSendAck(false, false);
231 EXPECT_TRUE(generator_.HasQueuedFrames()); 243 EXPECT_TRUE(generator_.HasQueuedFrames());
232 } 244 }
233 245
234 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_WritableAndShouldNotFlush) { 246 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_WritableAndShouldNotFlush) {
235 StrictMock<MockDebugDelegate> debug_delegate; 247 StrictMock<MockDebugDelegate> debug_delegate;
236 248
237 generator_.set_debug_delegate(&debug_delegate); 249 generator_.set_debug_delegate(&debug_delegate);
238 delegate_.SetCanWriteOnlyNonRetransmittable(); 250 delegate_.SetCanWriteOnlyNonRetransmittable();
239 generator_.StartBatchOperations(); 251 generator_.StartBatchOperations();
240 252
241 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame())); 253 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame()));
242 EXPECT_CALL(debug_delegate, OnFrameAddedToPacket(_)).Times(1); 254 EXPECT_CALL(debug_delegate, OnFrameAddedToPacket(_)).Times(1);
243 255
244 generator_.SetShouldSendAck(false); 256 generator_.SetShouldSendAck(false, false);
245 EXPECT_TRUE(generator_.HasQueuedFrames()); 257 EXPECT_TRUE(generator_.HasQueuedFrames());
246 } 258 }
247 259
248 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_WritableAndShouldFlush) { 260 TEST_F(QuicPacketGeneratorTest, ShouldSendAck_WritableAndShouldFlush) {
249 delegate_.SetCanWriteOnlyNonRetransmittable(); 261 delegate_.SetCanWriteOnlyNonRetransmittable();
250 262
251 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame())); 263 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame()));
252 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( 264 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(
253 DoAll(SaveArg<0>(&packet_), Return(true))); 265 DoAll(SaveArg<0>(&packet_), Return(true)));
254 266
255 generator_.SetShouldSendAck(false); 267 generator_.SetShouldSendAck(false, false);
256 EXPECT_FALSE(generator_.HasQueuedFrames()); 268 EXPECT_FALSE(generator_.HasQueuedFrames());
257 269
258 PacketContents contents; 270 PacketContents contents;
259 contents.num_ack_frames = 1; 271 contents.num_ack_frames = 1;
260 CheckPacketContains(contents, packet_); 272 CheckPacketContains(contents, packet_);
261 } 273 }
262 274
263 TEST_F(QuicPacketGeneratorTest, 275 TEST_F(QuicPacketGeneratorTest,
264 ShouldSendAckWithFeedback_WritableAndShouldNotFlush) { 276 ShouldSendAckWithFeedback_WritableAndShouldNotFlush) {
265 delegate_.SetCanWriteOnlyNonRetransmittable(); 277 delegate_.SetCanWriteOnlyNonRetransmittable();
266 generator_.StartBatchOperations(); 278 generator_.StartBatchOperations();
267 279
268 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame())); 280 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame()));
269 EXPECT_CALL(delegate_, CreateFeedbackFrame()).WillOnce( 281 EXPECT_CALL(delegate_, CreateFeedbackFrame()).WillOnce(
270 Return(CreateFeedbackFrame())); 282 Return(CreateFeedbackFrame()));
271 283
272 generator_.SetShouldSendAck(true); 284 generator_.SetShouldSendAck(true, false);
273 EXPECT_TRUE(generator_.HasQueuedFrames()); 285 EXPECT_TRUE(generator_.HasQueuedFrames());
274 } 286 }
275 287
276 TEST_F(QuicPacketGeneratorTest, 288 TEST_F(QuicPacketGeneratorTest,
277 ShouldSendAckWithFeedback_WritableAndShouldFlush) { 289 ShouldSendAckWithFeedback_WritableAndShouldFlush) {
278 delegate_.SetCanWriteOnlyNonRetransmittable(); 290 delegate_.SetCanWriteOnlyNonRetransmittable();
279 291
280 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame())); 292 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame()));
281 EXPECT_CALL(delegate_, CreateFeedbackFrame()).WillOnce( 293 EXPECT_CALL(delegate_, CreateFeedbackFrame()).WillOnce(
282 Return(CreateFeedbackFrame())); 294 Return(CreateFeedbackFrame()));
295 EXPECT_CALL(delegate_, CreateStopWaitingFrame()).WillOnce(
296 Return(CreateStopWaitingFrame()));
283 297
284 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( 298 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(
285 DoAll(SaveArg<0>(&packet_), Return(true))); 299 DoAll(SaveArg<0>(&packet_), Return(true)));
286 300
287 generator_.SetShouldSendAck(true); 301 generator_.SetShouldSendAck(true, true);
288 EXPECT_FALSE(generator_.HasQueuedFrames()); 302 EXPECT_FALSE(generator_.HasQueuedFrames());
289 303
290 PacketContents contents; 304 PacketContents contents;
291 contents.num_ack_frames = 1; 305 contents.num_ack_frames = 1;
292 contents.num_feedback_frames = 1; 306 contents.num_feedback_frames = 1;
307 contents.num_stop_waiting_frames = 1;
293 CheckPacketContains(contents, packet_); 308 CheckPacketContains(contents, packet_);
294 } 309 }
295 310
296 TEST_F(QuicPacketGeneratorTest, AddControlFrame_NotWritable) { 311 TEST_F(QuicPacketGeneratorTest, AddControlFrame_NotWritable) {
297 delegate_.SetCanNotWrite(); 312 delegate_.SetCanNotWrite();
298 313
299 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame())); 314 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame()));
300 EXPECT_TRUE(generator_.HasQueuedFrames()); 315 EXPECT_TRUE(generator_.HasQueuedFrames());
301 } 316 }
302 317
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 540
526 PacketContents contents; 541 PacketContents contents;
527 contents.num_stream_frames = 1; 542 contents.num_stream_frames = 1;
528 CheckPacketContains(contents, packet_); 543 CheckPacketContains(contents, packet_);
529 CheckPacketContains(contents, packet2_); 544 CheckPacketContains(contents, packet2_);
530 } 545 }
531 546
532 TEST_F(QuicPacketGeneratorTest, NotWritableThenBatchOperations) { 547 TEST_F(QuicPacketGeneratorTest, NotWritableThenBatchOperations) {
533 delegate_.SetCanNotWrite(); 548 delegate_.SetCanNotWrite();
534 549
535 generator_.SetShouldSendAck(true); 550 generator_.SetShouldSendAck(true, false);
536 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame())); 551 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame()));
537 EXPECT_TRUE(generator_.HasQueuedFrames()); 552 EXPECT_TRUE(generator_.HasQueuedFrames());
538 553
539 delegate_.SetCanWriteAnything(); 554 delegate_.SetCanWriteAnything();
540 555
541 generator_.StartBatchOperations(); 556 generator_.StartBatchOperations();
542 557
543 // When the first write operation is invoked, the ack and feedback 558 // When the first write operation is invoked, the ack and feedback
544 // frames will be returned. 559 // frames will be returned.
545 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame())); 560 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame()));
(...skipping 15 matching lines...) Expand all
561 contents.num_goaway_frames = 1; 576 contents.num_goaway_frames = 1;
562 contents.num_feedback_frames = 1; 577 contents.num_feedback_frames = 1;
563 contents.num_rst_stream_frames = 1; 578 contents.num_rst_stream_frames = 1;
564 contents.num_stream_frames = 1; 579 contents.num_stream_frames = 1;
565 CheckPacketContains(contents, packet_); 580 CheckPacketContains(contents, packet_);
566 } 581 }
567 582
568 TEST_F(QuicPacketGeneratorTest, NotWritableThenBatchOperations2) { 583 TEST_F(QuicPacketGeneratorTest, NotWritableThenBatchOperations2) {
569 delegate_.SetCanNotWrite(); 584 delegate_.SetCanNotWrite();
570 585
571 generator_.SetShouldSendAck(true); 586 generator_.SetShouldSendAck(true, false);
572 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame())); 587 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame()));
573 EXPECT_TRUE(generator_.HasQueuedFrames()); 588 EXPECT_TRUE(generator_.HasQueuedFrames());
574 589
575 delegate_.SetCanWriteAnything(); 590 delegate_.SetCanWriteAnything();
576 591
577 generator_.StartBatchOperations(); 592 generator_.StartBatchOperations();
578 593
579 // When the first write operation is invoked, the ack and feedback 594 // When the first write operation is invoked, the ack and feedback
580 // frames will be returned. 595 // frames will be returned.
581 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame())); 596 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame()));
(...skipping 30 matching lines...) Expand all
612 627
613 // The second should have the remainder of the stream data. 628 // The second should have the remainder of the stream data.
614 PacketContents contents2; 629 PacketContents contents2;
615 contents2.num_goaway_frames = 1; 630 contents2.num_goaway_frames = 1;
616 contents2.num_stream_frames = 1; 631 contents2.num_stream_frames = 1;
617 CheckPacketContains(contents2, packet2_); 632 CheckPacketContains(contents2, packet2_);
618 } 633 }
619 634
620 } // namespace test 635 } // namespace test
621 } // namespace net 636 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_packet_generator.cc ('k') | net/quic/quic_protocol.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698