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

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

Issue 1665973003: Refactor the QuicPacketCreatorTest to make it easier to flatten (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@113372125
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 | « no previous file | no next file » | 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 if (serialized_packet == nullptr) { 102 if (serialized_packet == nullptr) {
103 return; 103 return;
104 } 104 }
105 105
106 serialized_packet_ = *serialized_packet; 106 serialized_packet_ = *serialized_packet;
107 serialized_packet_.packet = serialized_packet->packet->Clone(); 107 serialized_packet_.packet = serialized_packet->packet->Clone();
108 delete serialized_packet->packet; 108 delete serialized_packet->packet;
109 serialized_packet->retransmittable_frames.clear(); 109 serialized_packet->retransmittable_frames.clear();
110 } 110 }
111 111
112 void DeleteSerializedPacket() { ClearSerializedPacket(&serialized_packet_); }
113
112 protected: 114 protected:
113 QuicPacketCreatorTest() 115 QuicPacketCreatorTest()
114 : server_framer_(SupportedVersions(GetParam().version), 116 : server_framer_(SupportedVersions(GetParam().version),
115 QuicTime::Zero(), 117 QuicTime::Zero(),
116 Perspective::IS_SERVER), 118 Perspective::IS_SERVER),
117 client_framer_(SupportedVersions(GetParam().version), 119 client_framer_(SupportedVersions(GetParam().version),
118 QuicTime::Zero(), 120 QuicTime::Zero(),
119 Perspective::IS_CLIENT), 121 Perspective::IS_CLIENT),
120 connection_id_(2), 122 connection_id_(2),
121 data_("foo"), 123 data_("foo"),
(...skipping 19 matching lines...) Expand all
141 ~QuicPacketCreatorTest() override {} 143 ~QuicPacketCreatorTest() override {}
142 144
143 SerializedPacket SerializeAllFrames(const QuicFrames& frames) { 145 SerializedPacket SerializeAllFrames(const QuicFrames& frames) {
144 SerializedPacket packet = QuicPacketCreatorPeer::SerializeAllFrames( 146 SerializedPacket packet = QuicPacketCreatorPeer::SerializeAllFrames(
145 &creator_, frames, buffer_, kMaxPacketSize); 147 &creator_, frames, buffer_, kMaxPacketSize);
146 EXPECT_EQ(QuicPacketCreatorPeer::GetEncryptionLevel(&creator_), 148 EXPECT_EQ(QuicPacketCreatorPeer::GetEncryptionLevel(&creator_),
147 packet.encryption_level); 149 packet.encryption_level);
148 return packet; 150 return packet;
149 } 151 }
150 152
151 void ProcessPacket(QuicEncryptedPacket* encrypted) { 153 void ProcessPacket(const SerializedPacket& packet) {
152 server_framer_.ProcessPacket(*encrypted); 154 server_framer_.ProcessPacket(*packet.packet);
153 } 155 }
154 156
155 void CheckStreamFrame(const QuicFrame& frame, 157 void CheckStreamFrame(const QuicFrame& frame,
156 QuicStreamId stream_id, 158 QuicStreamId stream_id,
157 const string& data, 159 const string& data,
158 QuicStreamOffset offset, 160 QuicStreamOffset offset,
159 bool fin) { 161 bool fin) {
160 EXPECT_EQ(STREAM_FRAME, frame.type); 162 EXPECT_EQ(STREAM_FRAME, frame.type);
161 ASSERT_TRUE(frame.stream_frame); 163 ASSERT_TRUE(frame.stream_frame);
162 EXPECT_EQ(stream_id, frame.stream_frame->stream_id); 164 EXPECT_EQ(stream_id, frame.stream_frame->stream_id);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 EXPECT_CALL(framer_visitor_, OnPacket()); 253 EXPECT_CALL(framer_visitor_, OnPacket());
252 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); 254 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
253 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); 255 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
254 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 256 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
255 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); 257 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
256 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); 258 EXPECT_CALL(framer_visitor_, OnAckFrame(_));
257 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); 259 EXPECT_CALL(framer_visitor_, OnStreamFrame(_));
258 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); 260 EXPECT_CALL(framer_visitor_, OnStreamFrame(_));
259 EXPECT_CALL(framer_visitor_, OnPacketComplete()); 261 EXPECT_CALL(framer_visitor_, OnPacketComplete());
260 } 262 }
261 ProcessPacket(serialized.packet); 263 ProcessPacket(serialized);
262 delete serialized.packet; 264 delete serialized.packet;
263 } 265 }
264 } 266 }
265 267
266 TEST_P(QuicPacketCreatorTest, SerializeWithFEC) { 268 TEST_P(QuicPacketCreatorTest, SerializeWithFEC) {
267 // Send FEC packet every 6 packets. 269 // Send FEC packet every 6 packets.
268 creator_.set_max_packets_per_fec_group(6); 270 creator_.set_max_packets_per_fec_group(6);
269 // Should return false since we do not have enough packets in the FEC group to 271 // Should return false since we do not have enough packets in the FEC group to
270 // trigger an FEC packet. 272 // trigger an FEC packet.
271 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); 273 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false));
(...skipping 12 matching lines...) Expand all
284 InSequence s; 286 InSequence s;
285 EXPECT_CALL(framer_visitor_, OnPacket()); 287 EXPECT_CALL(framer_visitor_, OnPacket());
286 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); 288 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
287 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); 289 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
288 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 290 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
289 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); 291 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
290 EXPECT_CALL(framer_visitor_, OnFecProtectedPayload(_)); 292 EXPECT_CALL(framer_visitor_, OnFecProtectedPayload(_));
291 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); 293 EXPECT_CALL(framer_visitor_, OnStreamFrame(_));
292 EXPECT_CALL(framer_visitor_, OnPacketComplete()); 294 EXPECT_CALL(framer_visitor_, OnPacketComplete());
293 } 295 }
294 ProcessPacket(serialized_packet_.packet); 296 ProcessPacket(serialized_packet_);
295 ClearSerializedPacket(&serialized_packet_); 297 DeleteSerializedPacket();
296 298
297 // Should return false since we do not have enough packets in the FEC group to 299 // Should return false since we do not have enough packets in the FEC group to
298 // trigger an FEC packet. 300 // trigger an FEC packet.
299 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); 301 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false));
300 // Should return true since there are packets in the FEC group. 302 // Should return true since there are packets in the FEC group.
301 ASSERT_TRUE(creator_.ShouldSendFec(/*force_close=*/true)); 303 ASSERT_TRUE(creator_.ShouldSendFec(/*force_close=*/true));
302 304
303 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 305 EXPECT_CALL(delegate_, OnSerializedPacket(_))
304 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); 306 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
305 creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true, 307 creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true,
306 /*is_fec_timeout=*/false); 308 /*is_fec_timeout=*/false);
307 ASSERT_EQ(2u, serialized_packet_.packet_number); 309 ASSERT_EQ(2u, serialized_packet_.packet_number);
308 { 310 {
309 InSequence s; 311 InSequence s;
310 EXPECT_CALL(framer_visitor_, OnPacket()); 312 EXPECT_CALL(framer_visitor_, OnPacket());
311 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); 313 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
312 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); 314 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
313 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 315 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
314 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); 316 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
315 EXPECT_CALL(framer_visitor_, OnFecData(_)); 317 EXPECT_CALL(framer_visitor_, OnFecData(_));
316 EXPECT_CALL(framer_visitor_, OnPacketComplete()); 318 EXPECT_CALL(framer_visitor_, OnPacketComplete());
317 } 319 }
318 ProcessPacket(serialized_packet_.packet); 320 ProcessPacket(serialized_packet_);
319 ClearSerializedPacket(&serialized_packet_); 321 DeleteSerializedPacket();
320 } 322 }
321 323
322 TEST_P(QuicPacketCreatorTest, SerializeChangingSequenceNumberLength) { 324 TEST_P(QuicPacketCreatorTest, SerializeChangingSequenceNumberLength) {
323 frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u)))); 325 frames_.push_back(QuicFrame(new QuicAckFrame(MakeAckFrame(0u))));
324 creator_.AddSavedFrame(frames_[0]); 326 creator_.AddSavedFrame(frames_[0]);
325 QuicPacketCreatorPeer::SetNextPacketNumberLength(&creator_, 327 QuicPacketCreatorPeer::SetNextPacketNumberLength(&creator_,
326 PACKET_4BYTE_PACKET_NUMBER); 328 PACKET_4BYTE_PACKET_NUMBER);
327 329
328 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 330 EXPECT_CALL(delegate_, OnSerializedPacket(_))
329 .WillRepeatedly( 331 .WillRepeatedly(
330 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); 332 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
331 creator_.Flush(); 333 creator_.Flush();
332 // The packet number length will not change mid-packet. 334 // The packet number length will not change mid-packet.
333 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, 335 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER,
334 serialized_packet_.packet_number_length); 336 serialized_packet_.packet_number_length);
335 337
336 { 338 {
337 InSequence s; 339 InSequence s;
338 EXPECT_CALL(framer_visitor_, OnPacket()); 340 EXPECT_CALL(framer_visitor_, OnPacket());
339 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); 341 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
340 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); 342 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
341 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 343 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
342 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); 344 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
343 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); 345 EXPECT_CALL(framer_visitor_, OnAckFrame(_));
344 EXPECT_CALL(framer_visitor_, OnPacketComplete()); 346 EXPECT_CALL(framer_visitor_, OnPacketComplete());
345 } 347 }
346 ProcessPacket(serialized_packet_.packet); 348 ProcessPacket(serialized_packet_);
347 ClearSerializedPacket(&serialized_packet_); 349 DeleteSerializedPacket();
348 350
349 creator_.AddSavedFrame(frames_[0]); 351 creator_.AddSavedFrame(frames_[0]);
350 creator_.Flush(); 352 creator_.Flush();
351 // Now the actual packet number length should have changed. 353 // Now the actual packet number length should have changed.
352 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, 354 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER,
353 serialized_packet_.packet_number_length); 355 serialized_packet_.packet_number_length);
354 delete frames_[0].ack_frame; 356 delete frames_[0].ack_frame;
355 357
356 { 358 {
357 InSequence s; 359 InSequence s;
358 EXPECT_CALL(framer_visitor_, OnPacket()); 360 EXPECT_CALL(framer_visitor_, OnPacket());
359 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); 361 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
360 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); 362 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
361 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 363 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
362 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); 364 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
363 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); 365 EXPECT_CALL(framer_visitor_, OnAckFrame(_));
364 EXPECT_CALL(framer_visitor_, OnPacketComplete()); 366 EXPECT_CALL(framer_visitor_, OnPacketComplete());
365 } 367 }
366 ProcessPacket(serialized_packet_.packet); 368 ProcessPacket(serialized_packet_);
367 ClearSerializedPacket(&serialized_packet_); 369 DeleteSerializedPacket();
368 } 370 }
369 371
370 TEST_P(QuicPacketCreatorTest, ChangeSequenceNumberLengthMidPacket) { 372 TEST_P(QuicPacketCreatorTest, ChangeSequenceNumberLengthMidPacket) {
371 // Changing the packet number length with queued frames in the creator 373 // Changing the packet number length with queued frames in the creator
372 // should hold the change until after any currently queued frames are 374 // should hold the change until after any currently queued frames are
373 // serialized. 375 // serialized.
374 376
375 // Packet 1. 377 // Packet 1.
376 // Queue a frame in the creator. 378 // Queue a frame in the creator.
377 EXPECT_FALSE(creator_.HasPendingFrames()); 379 EXPECT_FALSE(creator_.HasPendingFrames());
(...skipping 26 matching lines...) Expand all
404 EXPECT_CALL(framer_visitor_, OnPacket()); 406 EXPECT_CALL(framer_visitor_, OnPacket());
405 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); 407 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
406 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); 408 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
407 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 409 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
408 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)) 410 EXPECT_CALL(framer_visitor_, OnPacketHeader(_))
409 .WillOnce(DoAll(SaveArg<0>(&header), Return(true))); 411 .WillOnce(DoAll(SaveArg<0>(&header), Return(true)));
410 EXPECT_CALL(framer_visitor_, OnAckFrame(_)); 412 EXPECT_CALL(framer_visitor_, OnAckFrame(_));
411 EXPECT_CALL(framer_visitor_, OnStopWaitingFrame(_)); 413 EXPECT_CALL(framer_visitor_, OnStopWaitingFrame(_));
412 EXPECT_CALL(framer_visitor_, OnPacketComplete()); 414 EXPECT_CALL(framer_visitor_, OnPacketComplete());
413 } 415 }
414 ProcessPacket(serialized_packet_.packet); 416 ProcessPacket(serialized_packet_);
415 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, 417 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER,
416 header.public_header.packet_number_length); 418 header.public_header.packet_number_length);
417 ClearSerializedPacket(&serialized_packet_); 419 DeleteSerializedPacket();
418 420
419 // Packet 2. 421 // Packet 2.
420 EXPECT_FALSE(creator_.HasPendingFrames()); 422 EXPECT_FALSE(creator_.HasPendingFrames());
421 // Generate Packet 2 with one frame -- packet number length should now 423 // Generate Packet 2 with one frame -- packet number length should now
422 // change to 4 bytes. 424 // change to 4 bytes.
423 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&stop_waiting_frame))); 425 EXPECT_TRUE(creator_.AddSavedFrame(QuicFrame(&stop_waiting_frame)));
424 EXPECT_TRUE(creator_.HasPendingFrames()); 426 EXPECT_TRUE(creator_.HasPendingFrames());
425 427
426 // Ensure the packet is successfully created. 428 // Ensure the packet is successfully created.
427 creator_.Flush(); 429 creator_.Flush();
428 ASSERT_TRUE(serialized_packet_.packet); 430 ASSERT_TRUE(serialized_packet_.packet);
429 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, 431 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER,
430 serialized_packet_.packet_number_length); 432 serialized_packet_.packet_number_length);
431 433
432 // Verify that header in transmitted packet has 4 byte sequence length. 434 // Verify that header in transmitted packet has 4 byte sequence length.
433 { 435 {
434 InSequence s; 436 InSequence s;
435 EXPECT_CALL(framer_visitor_, OnPacket()); 437 EXPECT_CALL(framer_visitor_, OnPacket());
436 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); 438 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
437 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); 439 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
438 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 440 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
439 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)) 441 EXPECT_CALL(framer_visitor_, OnPacketHeader(_))
440 .WillOnce(DoAll(SaveArg<0>(&header), Return(true))); 442 .WillOnce(DoAll(SaveArg<0>(&header), Return(true)));
441 EXPECT_CALL(framer_visitor_, OnStopWaitingFrame(_)); 443 EXPECT_CALL(framer_visitor_, OnStopWaitingFrame(_));
442 EXPECT_CALL(framer_visitor_, OnPacketComplete()); 444 EXPECT_CALL(framer_visitor_, OnPacketComplete());
443 } 445 }
444 ProcessPacket(serialized_packet_.packet); 446 ProcessPacket(serialized_packet_);
445 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, 447 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER,
446 header.public_header.packet_number_length); 448 header.public_header.packet_number_length);
447 449
448 ClearSerializedPacket(&serialized_packet_); 450 DeleteSerializedPacket();
449 delete ack_frame.ack_frame; 451 delete ack_frame.ack_frame;
450 } 452 }
451 453
452 TEST_P(QuicPacketCreatorTest, SerializeWithFECChangingSequenceNumberLength) { 454 TEST_P(QuicPacketCreatorTest, SerializeWithFECChangingSequenceNumberLength) {
453 // Test goal is to test the following sequence (P1 => generate Packet 1): 455 // Test goal is to test the following sequence (P1 => generate Packet 1):
454 // P1 <change seq num length> P2 FEC, 456 // P1 <change seq num length> P2 FEC,
455 // and we expect that packet number length should not change until the end 457 // and we expect that packet number length should not change until the end
456 // of the open FEC group. 458 // of the open FEC group.
457 459
458 // Send FEC packet every 6 packets. 460 // Send FEC packet every 6 packets.
(...skipping 21 matching lines...) Expand all
480 InSequence s; 482 InSequence s;
481 EXPECT_CALL(framer_visitor_, OnPacket()); 483 EXPECT_CALL(framer_visitor_, OnPacket());
482 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); 484 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
483 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); 485 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
484 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 486 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
485 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); 487 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
486 EXPECT_CALL(framer_visitor_, OnFecProtectedPayload(_)); 488 EXPECT_CALL(framer_visitor_, OnFecProtectedPayload(_));
487 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); 489 EXPECT_CALL(framer_visitor_, OnStreamFrame(_));
488 EXPECT_CALL(framer_visitor_, OnPacketComplete()); 490 EXPECT_CALL(framer_visitor_, OnPacketComplete());
489 } 491 }
490 ProcessPacket(serialized_packet_.packet); 492 ProcessPacket(serialized_packet_);
491 ClearSerializedPacket(&serialized_packet_); 493 DeleteSerializedPacket();
492 494
493 // Generate Packet 2. 495 // Generate Packet 2.
494 ASSERT_TRUE(creator_.ConsumeData(2u, io_vector, 0u, 0u, false, false, &frame, 496 ASSERT_TRUE(creator_.ConsumeData(2u, io_vector, 0u, 0u, false, false, &frame,
495 MUST_FEC_PROTECT)); 497 MUST_FEC_PROTECT));
496 creator_.Flush(); 498 creator_.Flush();
497 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, 499 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER,
498 serialized_packet_.packet_number_length); 500 serialized_packet_.packet_number_length);
499 501
500 { 502 {
501 InSequence s; 503 InSequence s;
502 EXPECT_CALL(framer_visitor_, OnPacket()); 504 EXPECT_CALL(framer_visitor_, OnPacket());
503 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); 505 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
504 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); 506 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
505 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 507 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
506 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); 508 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
507 EXPECT_CALL(framer_visitor_, OnFecProtectedPayload(_)); 509 EXPECT_CALL(framer_visitor_, OnFecProtectedPayload(_));
508 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); 510 EXPECT_CALL(framer_visitor_, OnStreamFrame(_));
509 EXPECT_CALL(framer_visitor_, OnPacketComplete()); 511 EXPECT_CALL(framer_visitor_, OnPacketComplete());
510 } 512 }
511 ProcessPacket(serialized_packet_.packet); 513 ProcessPacket(serialized_packet_);
512 ClearSerializedPacket(&serialized_packet_); 514 DeleteSerializedPacket();
513 515
514 // Should return false since we do not have enough packets in the FEC group to 516 // Should return false since we do not have enough packets in the FEC group to
515 // trigger an FEC packet. 517 // trigger an FEC packet.
516 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false)); 518 ASSERT_FALSE(creator_.ShouldSendFec(/*force_close=*/false));
517 // Should return true since there are packets in the FEC group. 519 // Should return true since there are packets in the FEC group.
518 ASSERT_TRUE(creator_.ShouldSendFec(/*force_close=*/true)); 520 ASSERT_TRUE(creator_.ShouldSendFec(/*force_close=*/true));
519 521
520 // Force generation of FEC packet. 522 // Force generation of FEC packet.
521 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 523 EXPECT_CALL(delegate_, OnSerializedPacket(_))
522 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); 524 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
523 // Turn off FEC protection. 525 // Turn off FEC protection.
524 creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true, 526 creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true,
525 /*is_fec_timeout=*/false); 527 /*is_fec_timeout=*/false);
526 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, 528 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER,
527 serialized_packet_.packet_number_length); 529 serialized_packet_.packet_number_length);
528 ASSERT_EQ(3u, serialized_packet_.packet_number); 530 ASSERT_EQ(3u, serialized_packet_.packet_number);
529 531
530 { 532 {
531 InSequence s; 533 InSequence s;
532 EXPECT_CALL(framer_visitor_, OnPacket()); 534 EXPECT_CALL(framer_visitor_, OnPacket());
533 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); 535 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
534 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); 536 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
535 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 537 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
536 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); 538 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
537 EXPECT_CALL(framer_visitor_, OnFecData(_)); 539 EXPECT_CALL(framer_visitor_, OnFecData(_));
538 EXPECT_CALL(framer_visitor_, OnPacketComplete()); 540 EXPECT_CALL(framer_visitor_, OnPacketComplete());
539 } 541 }
540 ProcessPacket(serialized_packet_.packet); 542 ProcessPacket(serialized_packet_);
541 ClearSerializedPacket(&serialized_packet_); 543 DeleteSerializedPacket();
542 544
543 // Ensure the next FEC group starts using the new packet number length. 545 // Ensure the next FEC group starts using the new packet number length.
544 ASSERT_TRUE(creator_.ConsumeData(3u, io_vector, 0u, 0u, false, false, &frame, 546 ASSERT_TRUE(creator_.ConsumeData(3u, io_vector, 0u, 0u, false, false, &frame,
545 MUST_FEC_PROTECT)); 547 MUST_FEC_PROTECT));
546 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecProtected(&creator_)); 548 EXPECT_TRUE(QuicPacketCreatorPeer::IsFecProtected(&creator_));
547 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 549 EXPECT_CALL(delegate_, OnSerializedPacket(_))
548 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); 550 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
549 creator_.Flush(); 551 creator_.Flush();
550 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, 552 EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER,
551 serialized_packet_.packet_number_length); 553 serialized_packet_.packet_number_length);
552 ClearSerializedPacket(&serialized_packet_); 554 DeleteSerializedPacket();
553 } 555 }
554 556
555 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithSequenceNumberLength) { 557 TEST_P(QuicPacketCreatorTest, ReserializeFramesWithSequenceNumberLength) {
556 // If the original packet number length, the current packet number 558 // If the original packet number length, the current packet number
557 // length, and the configured send packet number length are different, the 559 // length, and the configured send packet number length are different, the
558 // retransmit must sent with the original length and the others do not change. 560 // retransmit must sent with the original length and the others do not change.
559 QuicPacketCreatorPeer::SetNextPacketNumberLength(&creator_, 561 QuicPacketCreatorPeer::SetNextPacketNumberLength(&creator_,
560 PACKET_4BYTE_PACKET_NUMBER); 562 PACKET_4BYTE_PACKET_NUMBER);
561 QuicPacketCreatorPeer::SetPacketNumberLength(&creator_, 563 QuicPacketCreatorPeer::SetPacketNumberLength(&creator_,
562 PACKET_2BYTE_PACKET_NUMBER); 564 PACKET_2BYTE_PACKET_NUMBER);
(...skipping 23 matching lines...) Expand all
586 { 588 {
587 InSequence s; 589 InSequence s;
588 EXPECT_CALL(framer_visitor_, OnPacket()); 590 EXPECT_CALL(framer_visitor_, OnPacket());
589 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); 591 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
590 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); 592 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
591 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 593 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
592 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); 594 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
593 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); 595 EXPECT_CALL(framer_visitor_, OnStreamFrame(_));
594 EXPECT_CALL(framer_visitor_, OnPacketComplete()); 596 EXPECT_CALL(framer_visitor_, OnPacketComplete());
595 } 597 }
596 ProcessPacket(serialized.packet); 598 ProcessPacket(serialized);
597 delete serialized.packet; 599 delete serialized.packet;
598 delete stream_frame; 600 delete stream_frame;
599 } 601 }
600 602
601 TEST_P(QuicPacketCreatorTest, ReserializeCryptoFrameWithForwardSecurity) { 603 TEST_P(QuicPacketCreatorTest, ReserializeCryptoFrameWithForwardSecurity) {
602 QuicStreamFrame* stream_frame = 604 QuicStreamFrame* stream_frame =
603 new QuicStreamFrame(kCryptoStreamId, /*fin=*/false, 0u, StringPiece()); 605 new QuicStreamFrame(kCryptoStreamId, /*fin=*/false, 0u, StringPiece());
604 QuicFrames frames; 606 QuicFrames frames;
605 frames.push_back(QuicFrame(stream_frame)); 607 frames.push_back(QuicFrame(stream_frame));
606 creator_.set_encryption_level(ENCRYPTION_FORWARD_SECURE); 608 creator_.set_encryption_level(ENCRYPTION_FORWARD_SECURE);
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 737
736 InSequence s; 738 InSequence s;
737 EXPECT_CALL(framer_visitor_, OnPacket()); 739 EXPECT_CALL(framer_visitor_, OnPacket());
738 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); 740 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
739 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); 741 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
740 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 742 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
741 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)); 743 EXPECT_CALL(framer_visitor_, OnPacketHeader(_));
742 EXPECT_CALL(framer_visitor_, OnConnectionCloseFrame(_)); 744 EXPECT_CALL(framer_visitor_, OnConnectionCloseFrame(_));
743 EXPECT_CALL(framer_visitor_, OnPacketComplete()); 745 EXPECT_CALL(framer_visitor_, OnPacketComplete());
744 746
745 ProcessPacket(serialized.packet); 747 ProcessPacket(serialized);
746 delete serialized.packet; 748 delete serialized.packet;
747 } 749 }
748 750
749 TEST_P(QuicPacketCreatorTest, SwitchFecOnOffWithGroupInProgress) { 751 TEST_P(QuicPacketCreatorTest, SwitchFecOnOffWithGroupInProgress) {
750 // Send FEC packet every 6 packets. 752 // Send FEC packet every 6 packets.
751 creator_.set_max_packets_per_fec_group(6); 753 creator_.set_max_packets_per_fec_group(6);
752 // Turn on FEC protection. 754 // Turn on FEC protection.
753 QuicFrame frame; 755 QuicFrame frame;
754 QuicIOVector io_vector(MakeIOVector("test")); 756 QuicIOVector io_vector(MakeIOVector("test"));
755 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame, 757 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame,
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 908
907 // BytesFree() returns bytes available for the next frame, which will 909 // BytesFree() returns bytes available for the next frame, which will
908 // be two bytes smaller since the stream frame would need to be grown. 910 // be two bytes smaller since the stream frame would need to be grown.
909 EXPECT_EQ(2u, creator_.ExpansionOnNewFrame()); 911 EXPECT_EQ(2u, creator_.ExpansionOnNewFrame());
910 size_t expected_bytes_free = bytes_free < 3 ? 0 : bytes_free - 2; 912 size_t expected_bytes_free = bytes_free < 3 ? 0 : bytes_free - 2;
911 EXPECT_EQ(expected_bytes_free, creator_.BytesFree()) << "delta: " << delta; 913 EXPECT_EQ(expected_bytes_free, creator_.BytesFree()) << "delta: " << delta;
912 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 914 EXPECT_CALL(delegate_, OnSerializedPacket(_))
913 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); 915 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
914 creator_.Flush(); 916 creator_.Flush();
915 ASSERT_TRUE(serialized_packet_.packet); 917 ASSERT_TRUE(serialized_packet_.packet);
916 ClearSerializedPacket(&serialized_packet_); 918 DeleteSerializedPacket();
917 } 919 }
918 } 920 }
919 921
920 TEST_P(QuicPacketCreatorTest, StreamFrameConsumptionWithFec) { 922 TEST_P(QuicPacketCreatorTest, StreamFrameConsumptionWithFec) {
921 // Send FEC packet every 6 packets. 923 // Send FEC packet every 6 packets.
922 creator_.set_max_packets_per_fec_group(6); 924 creator_.set_max_packets_per_fec_group(6);
923 // Turn on FEC protection. 925 // Turn on FEC protection.
924 QuicFrame frame; 926 QuicFrame frame;
925 QuicIOVector io_vector(MakeIOVector("test")); 927 QuicIOVector io_vector(MakeIOVector("test"));
926 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame, 928 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); 960 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
959 // Every 6th packet will generate an extra FEC packet. 961 // Every 6th packet will generate an extra FEC packet.
960 if (delta == -1 || delta == 5) { 962 if (delta == -1 || delta == 5) {
961 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 963 EXPECT_CALL(delegate_, OnSerializedPacket(_))
962 .WillOnce( 964 .WillOnce(
963 Invoke(this, &QuicPacketCreatorTest::ClearSerializedPacket)); 965 Invoke(this, &QuicPacketCreatorTest::ClearSerializedPacket));
964 } 966 }
965 } 967 }
966 creator_.Flush(); 968 creator_.Flush();
967 ASSERT_TRUE(serialized_packet_.packet); 969 ASSERT_TRUE(serialized_packet_.packet);
968 ClearSerializedPacket(&serialized_packet_); 970 DeleteSerializedPacket();
969 } 971 }
970 } 972 }
971 973
972 TEST_P(QuicPacketCreatorTest, CryptoStreamFramePacketPadding) { 974 TEST_P(QuicPacketCreatorTest, CryptoStreamFramePacketPadding) {
973 // Compute the total overhead for a single frame in packet. 975 // Compute the total overhead for a single frame in packet.
974 const size_t overhead = GetPacketHeaderOverhead(NOT_IN_FEC_GROUP) + 976 const size_t overhead = GetPacketHeaderOverhead(NOT_IN_FEC_GROUP) +
975 GetEncryptionOverhead() + 977 GetEncryptionOverhead() +
976 GetStreamFrameOverhead(NOT_IN_FEC_GROUP); 978 GetStreamFrameOverhead(NOT_IN_FEC_GROUP);
977 ASSERT_GT(kMaxPacketSize, overhead); 979 ASSERT_GT(kMaxPacketSize, overhead);
978 size_t capacity = kDefaultMaxPacketSize - overhead; 980 size_t capacity = kDefaultMaxPacketSize - overhead;
(...skipping 16 matching lines...) Expand all
995 ASSERT_TRUE(serialized_packet_.packet); 997 ASSERT_TRUE(serialized_packet_.packet);
996 // If there is not enough space in the packet to fit a padding frame 998 // If there is not enough space in the packet to fit a padding frame
997 // (1 byte) and to expand the stream frame (another 2 bytes) the packet 999 // (1 byte) and to expand the stream frame (another 2 bytes) the packet
998 // will not be padded. 1000 // will not be padded.
999 if (bytes_free < 3) { 1001 if (bytes_free < 3) {
1000 EXPECT_EQ(kDefaultMaxPacketSize - bytes_free, 1002 EXPECT_EQ(kDefaultMaxPacketSize - bytes_free,
1001 serialized_packet_.packet->length()); 1003 serialized_packet_.packet->length());
1002 } else { 1004 } else {
1003 EXPECT_EQ(kDefaultMaxPacketSize, serialized_packet_.packet->length()); 1005 EXPECT_EQ(kDefaultMaxPacketSize, serialized_packet_.packet->length());
1004 } 1006 }
1005 ClearSerializedPacket(&serialized_packet_); 1007 DeleteSerializedPacket();
1006 } 1008 }
1007 } 1009 }
1008 1010
1009 TEST_P(QuicPacketCreatorTest, NonCryptoStreamFramePacketNonPadding) { 1011 TEST_P(QuicPacketCreatorTest, NonCryptoStreamFramePacketNonPadding) {
1010 // Compute the total overhead for a single frame in packet. 1012 // Compute the total overhead for a single frame in packet.
1011 const size_t overhead = GetPacketHeaderOverhead(NOT_IN_FEC_GROUP) + 1013 const size_t overhead = GetPacketHeaderOverhead(NOT_IN_FEC_GROUP) +
1012 GetEncryptionOverhead() + 1014 GetEncryptionOverhead() +
1013 GetStreamFrameOverhead(NOT_IN_FEC_GROUP); 1015 GetStreamFrameOverhead(NOT_IN_FEC_GROUP);
1014 ASSERT_GT(kDefaultMaxPacketSize, overhead); 1016 ASSERT_GT(kDefaultMaxPacketSize, overhead);
1015 size_t capacity = kDefaultMaxPacketSize - overhead; 1017 size_t capacity = kDefaultMaxPacketSize - overhead;
(...skipping 13 matching lines...) Expand all
1029 size_t bytes_consumed = frame.stream_frame->frame_length; 1031 size_t bytes_consumed = frame.stream_frame->frame_length;
1030 EXPECT_LT(0u, bytes_consumed); 1032 EXPECT_LT(0u, bytes_consumed);
1031 creator_.Flush(); 1033 creator_.Flush();
1032 ASSERT_TRUE(serialized_packet_.packet); 1034 ASSERT_TRUE(serialized_packet_.packet);
1033 if (bytes_free > 0) { 1035 if (bytes_free > 0) {
1034 EXPECT_EQ(kDefaultMaxPacketSize - bytes_free, 1036 EXPECT_EQ(kDefaultMaxPacketSize - bytes_free,
1035 serialized_packet_.packet->length()); 1037 serialized_packet_.packet->length());
1036 } else { 1038 } else {
1037 EXPECT_EQ(kDefaultMaxPacketSize, serialized_packet_.packet->length()); 1039 EXPECT_EQ(kDefaultMaxPacketSize, serialized_packet_.packet->length());
1038 } 1040 }
1039 ClearSerializedPacket(&serialized_packet_); 1041 DeleteSerializedPacket();
1040 } 1042 }
1041 } 1043 }
1042 1044
1043 TEST_P(QuicPacketCreatorTest, SerializeVersionNegotiationPacket) { 1045 TEST_P(QuicPacketCreatorTest, SerializeVersionNegotiationPacket) {
1044 QuicFramerPeer::SetPerspective(&client_framer_, Perspective::IS_SERVER); 1046 QuicFramerPeer::SetPerspective(&client_framer_, Perspective::IS_SERVER);
1045 QuicVersionVector versions; 1047 QuicVersionVector versions;
1046 versions.push_back(test::QuicVersionMax()); 1048 versions.push_back(test::QuicVersionMax());
1047 scoped_ptr<QuicEncryptedPacket> encrypted( 1049 scoped_ptr<QuicEncryptedPacket> encrypted(
1048 creator_.SerializeVersionNegotiationPacket(versions)); 1050 creator_.SerializeVersionNegotiationPacket(versions));
1049 1051
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 InSequence s; 1128 InSequence s;
1127 EXPECT_CALL(framer_visitor_, OnPacket()); 1129 EXPECT_CALL(framer_visitor_, OnPacket());
1128 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_)); 1130 EXPECT_CALL(framer_visitor_, OnUnauthenticatedPublicHeader(_));
1129 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_)); 1131 EXPECT_CALL(framer_visitor_, OnUnauthenticatedHeader(_));
1130 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_)); 1132 EXPECT_CALL(framer_visitor_, OnDecryptedPacket(_));
1131 EXPECT_CALL(framer_visitor_, OnPacketHeader(_)) 1133 EXPECT_CALL(framer_visitor_, OnPacketHeader(_))
1132 .WillOnce(DoAll(SaveArg<0>(&header), Return(true))); 1134 .WillOnce(DoAll(SaveArg<0>(&header), Return(true)));
1133 EXPECT_CALL(framer_visitor_, OnStreamFrame(_)); 1135 EXPECT_CALL(framer_visitor_, OnStreamFrame(_));
1134 EXPECT_CALL(framer_visitor_, OnPacketComplete()); 1136 EXPECT_CALL(framer_visitor_, OnPacketComplete());
1135 } 1137 }
1136 ProcessPacket(serialized.packet); 1138 ProcessPacket(serialized);
1137 EXPECT_EQ(GetParam().version_serialization, 1139 EXPECT_EQ(GetParam().version_serialization,
1138 header.public_header.version_flag); 1140 header.public_header.version_flag);
1139 delete serialized.packet; 1141 delete serialized.packet;
1140 } 1142 }
1141 1143
1142 TEST_P(QuicPacketCreatorTest, ConsumeDataLargerThanOneStreamFrame) { 1144 TEST_P(QuicPacketCreatorTest, ConsumeDataLargerThanOneStreamFrame) {
1143 if (!GetParam().version_serialization) { 1145 if (!GetParam().version_serialization) {
1144 creator_.StopSendingVersion(); 1146 creator_.StopSendingVersion();
1145 } 1147 }
1146 // A string larger than fits into a frame. 1148 // A string larger than fits into a frame.
(...skipping 10 matching lines...) Expand all
1157 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 1159 EXPECT_CALL(delegate_, OnSerializedPacket(_))
1158 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); 1160 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
1159 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, true, false, &frame, 1161 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, true, false, &frame,
1160 MAY_FEC_PROTECT)); 1162 MAY_FEC_PROTECT));
1161 ASSERT_TRUE(frame.stream_frame); 1163 ASSERT_TRUE(frame.stream_frame);
1162 size_t consumed = frame.stream_frame->frame_length; 1164 size_t consumed = frame.stream_frame->frame_length;
1163 EXPECT_EQ(payload_length, consumed); 1165 EXPECT_EQ(payload_length, consumed);
1164 const string payload(payload_length, 'a'); 1166 const string payload(payload_length, 'a');
1165 CheckStreamFrame(frame, 1u, payload, 0u, false); 1167 CheckStreamFrame(frame, 1u, payload, 0u, false);
1166 creator_.Flush(); 1168 creator_.Flush();
1167 ClearSerializedPacket(&serialized_packet_); 1169 DeleteSerializedPacket();
1168 } 1170 }
1169 1171
1170 TEST_P(QuicPacketCreatorTest, AddFrameAndFlush) { 1172 TEST_P(QuicPacketCreatorTest, AddFrameAndFlush) {
1171 if (!GetParam().version_serialization) { 1173 if (!GetParam().version_serialization) {
1172 creator_.StopSendingVersion(); 1174 creator_.StopSendingVersion();
1173 } 1175 }
1174 const size_t max_plaintext_size = 1176 const size_t max_plaintext_size =
1175 client_framer_.GetMaxPlaintextSize(creator_.max_packet_length()); 1177 client_framer_.GetMaxPlaintextSize(creator_.max_packet_length());
1176 EXPECT_FALSE(creator_.HasPendingFrames()); 1178 EXPECT_FALSE(creator_.HasPendingFrames());
1177 EXPECT_EQ(max_plaintext_size - 1179 EXPECT_EQ(max_plaintext_size -
(...skipping 28 matching lines...) Expand all
1206 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); 1208 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
1207 EXPECT_FALSE(creator_.AddSavedFrame(QuicFrame(&ack_frame))); 1209 EXPECT_FALSE(creator_.AddSavedFrame(QuicFrame(&ack_frame)));
1208 1210
1209 // Ensure the packet is successfully created. 1211 // Ensure the packet is successfully created.
1210 ASSERT_TRUE(serialized_packet_.packet); 1212 ASSERT_TRUE(serialized_packet_.packet);
1211 ASSERT_FALSE(serialized_packet_.retransmittable_frames.empty()); 1213 ASSERT_FALSE(serialized_packet_.retransmittable_frames.empty());
1212 const QuicFrames& retransmittable = serialized_packet_.retransmittable_frames; 1214 const QuicFrames& retransmittable = serialized_packet_.retransmittable_frames;
1213 ASSERT_EQ(1u, retransmittable.size()); 1215 ASSERT_EQ(1u, retransmittable.size());
1214 EXPECT_EQ(STREAM_FRAME, retransmittable[0].type); 1216 EXPECT_EQ(STREAM_FRAME, retransmittable[0].type);
1215 ASSERT_TRUE(retransmittable[0].stream_frame); 1217 ASSERT_TRUE(retransmittable[0].stream_frame);
1216 ClearSerializedPacket(&serialized_packet_); 1218 DeleteSerializedPacket();
1217 1219
1218 EXPECT_FALSE(creator_.HasPendingFrames()); 1220 EXPECT_FALSE(creator_.HasPendingFrames());
1219 EXPECT_EQ(max_plaintext_size - 1221 EXPECT_EQ(max_plaintext_size -
1220 GetPacketHeaderSize( 1222 GetPacketHeaderSize(
1221 creator_.connection_id_length(), 1223 creator_.connection_id_length(),
1222 QuicPacketCreatorPeer::SendVersionInPacket(&creator_), 1224 QuicPacketCreatorPeer::SendVersionInPacket(&creator_),
1223 /*include_path_id=*/false, PACKET_1BYTE_PACKET_NUMBER, 1225 /*include_path_id=*/false, PACKET_1BYTE_PACKET_NUMBER,
1224 NOT_IN_FEC_GROUP), 1226 NOT_IN_FEC_GROUP),
1225 creator_.BytesFree()); 1227 creator_.BytesFree());
1226 } 1228 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 // Ensure the packet is successfully created, and the packet size estimate 1261 // Ensure the packet is successfully created, and the packet size estimate
1260 // matches the serialized packet length. 1262 // matches the serialized packet length.
1261 EXPECT_CALL(entropy_calculator_, EntropyHash(_)).WillOnce(testing::Return(0)); 1263 EXPECT_CALL(entropy_calculator_, EntropyHash(_)).WillOnce(testing::Return(0));
1262 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 1264 EXPECT_CALL(delegate_, OnSerializedPacket(_))
1263 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); 1265 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
1264 size_t est_packet_size = creator_.PacketSize(); 1266 size_t est_packet_size = creator_.PacketSize();
1265 creator_.Flush(); 1267 creator_.Flush();
1266 ASSERT_TRUE(serialized_packet_.packet); 1268 ASSERT_TRUE(serialized_packet_.packet);
1267 EXPECT_EQ(est_packet_size, client_framer_.GetMaxPlaintextSize( 1269 EXPECT_EQ(est_packet_size, client_framer_.GetMaxPlaintextSize(
1268 serialized_packet_.packet->length())); 1270 serialized_packet_.packet->length()));
1269 ClearSerializedPacket(&serialized_packet_); 1271 DeleteSerializedPacket();
1270 } 1272 }
1271 1273
1272 TEST_P(QuicPacketCreatorTest, SerializeTruncatedAckFrameWithSmallPacketSize) { 1274 TEST_P(QuicPacketCreatorTest, SerializeTruncatedAckFrameWithSmallPacketSize) {
1273 if (!GetParam().version_serialization) { 1275 if (!GetParam().version_serialization) {
1274 creator_.StopSendingVersion(); 1276 creator_.StopSendingVersion();
1275 } 1277 }
1276 creator_.SetMaxPacketLength(500u); 1278 creator_.SetMaxPacketLength(500u);
1277 1279
1278 const size_t max_plaintext_size = 1280 const size_t max_plaintext_size =
1279 client_framer_.GetMaxPlaintextSize(creator_.max_packet_length()); 1281 client_framer_.GetMaxPlaintextSize(creator_.max_packet_length());
(...skipping 17 matching lines...) Expand all
1297 // Ensure the packet is successfully created, and the packet size estimate 1299 // Ensure the packet is successfully created, and the packet size estimate
1298 // may not match the serialized packet length. 1300 // may not match the serialized packet length.
1299 EXPECT_CALL(entropy_calculator_, EntropyHash(_)).WillOnce(Return(0)); 1301 EXPECT_CALL(entropy_calculator_, EntropyHash(_)).WillOnce(Return(0));
1300 size_t est_packet_size = creator_.PacketSize(); 1302 size_t est_packet_size = creator_.PacketSize();
1301 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 1303 EXPECT_CALL(delegate_, OnSerializedPacket(_))
1302 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); 1304 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
1303 creator_.Flush(); 1305 creator_.Flush();
1304 ASSERT_TRUE(serialized_packet_.packet); 1306 ASSERT_TRUE(serialized_packet_.packet);
1305 EXPECT_GE(est_packet_size, client_framer_.GetMaxPlaintextSize( 1307 EXPECT_GE(est_packet_size, client_framer_.GetMaxPlaintextSize(
1306 serialized_packet_.packet->length())); 1308 serialized_packet_.packet->length()));
1307 ClearSerializedPacket(&serialized_packet_); 1309 DeleteSerializedPacket();
1308 } 1310 }
1309 1311
1310 TEST_P(QuicPacketCreatorTest, EntropyFlag) { 1312 TEST_P(QuicPacketCreatorTest, EntropyFlag) {
1311 frames_.push_back( 1313 frames_.push_back(
1312 QuicFrame(new QuicStreamFrame(0u, false, 0u, StringPiece()))); 1314 QuicFrame(new QuicStreamFrame(0u, false, 0u, StringPiece())));
1313 1315
1314 for (int i = 0; i < 2; ++i) { 1316 for (int i = 0; i < 2; ++i) {
1315 for (int j = 0; j < 64; ++j) { 1317 for (int j = 0; j < 64; ++j) {
1316 SerializedPacket serialized = SerializeAllFrames(frames_); 1318 SerializedPacket serialized = SerializeAllFrames(frames_);
1317 // Verify both BoolSource and hash algorithm. 1319 // Verify both BoolSource and hash algorithm.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 // Should return true since there are packets in the FEC group. 1391 // Should return true since there are packets in the FEC group.
1390 ASSERT_TRUE(creator_.ShouldSendFec(/*force_close=*/true)); 1392 ASSERT_TRUE(creator_.ShouldSendFec(/*force_close=*/true));
1391 1393
1392 // Change FEC policy, send FEC packet and close FEC group. 1394 // Change FEC policy, send FEC packet and close FEC group.
1393 creator_.set_fec_send_policy(FEC_ANY_TRIGGER); 1395 creator_.set_fec_send_policy(FEC_ANY_TRIGGER);
1394 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 1396 EXPECT_CALL(delegate_, OnSerializedPacket(_))
1395 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); 1397 .WillOnce(Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
1396 creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true, 1398 creator_.MaybeSendFecPacketAndCloseGroup(/*force_send_fec=*/true,
1397 /*is_fec_timeout=*/false); 1399 /*is_fec_timeout=*/false);
1398 ASSERT_EQ(3u, serialized_packet_.packet_number); 1400 ASSERT_EQ(3u, serialized_packet_.packet_number);
1399 ClearSerializedPacket(&serialized_packet_); 1401 DeleteSerializedPacket();
1400 } 1402 }
1401 1403
1402 TEST_P(QuicPacketCreatorTest, ResetFecGroupWithQueuedFrames) { 1404 TEST_P(QuicPacketCreatorTest, ResetFecGroupWithQueuedFrames) {
1403 // Send FEC packet every 6 packets. 1405 // Send FEC packet every 6 packets.
1404 creator_.set_max_packets_per_fec_group(6); 1406 creator_.set_max_packets_per_fec_group(6);
1405 // Add a stream frame to the creator and turn on FEC protection. 1407 // Add a stream frame to the creator and turn on FEC protection.
1406 QuicFrame frame; 1408 QuicFrame frame;
1407 QuicIOVector io_vector(MakeIOVector("test")); 1409 QuicIOVector io_vector(MakeIOVector("test"));
1408 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame, 1410 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame,
1409 MUST_FEC_PROTECT)); 1411 MUST_FEC_PROTECT));
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 EXPECT_TRUE(creator_.HasPendingFrames()); 1610 EXPECT_TRUE(creator_.HasPendingFrames());
1609 EXPECT_EQ(0u, creator_.packet_number()); 1611 EXPECT_EQ(0u, creator_.packet_number());
1610 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 1612 EXPECT_CALL(delegate_, OnSerializedPacket(_))
1611 .WillRepeatedly( 1613 .WillRepeatedly(
1612 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket)); 1614 Invoke(this, &QuicPacketCreatorTest::SaveSerializedPacket));
1613 creator_.Flush(); 1615 creator_.Flush();
1614 EXPECT_FALSE(creator_.HasPendingFrames()); 1616 EXPECT_FALSE(creator_.HasPendingFrames());
1615 EXPECT_EQ(1u, creator_.packet_number()); 1617 EXPECT_EQ(1u, creator_.packet_number());
1616 // Verify serialized data packet's path id. 1618 // Verify serialized data packet's path id.
1617 EXPECT_EQ(kDefaultPathId, serialized_packet_.path_id); 1619 EXPECT_EQ(kDefaultPathId, serialized_packet_.path_id);
1618 ClearSerializedPacket(&serialized_packet_); 1620 DeleteSerializedPacket();
1619 1621
1620 // Change to path 1. 1622 // Change to path 1.
1621 QuicPathId kPathId1 = 1; 1623 QuicPathId kPathId1 = 1;
1622 creator_.SetCurrentPath(kPathId1, 1, 0); 1624 creator_.SetCurrentPath(kPathId1, 1, 0);
1623 EXPECT_EQ(kPathId1, QuicPacketCreatorPeer::GetCurrentPath(&creator_)); 1625 EXPECT_EQ(kPathId1, QuicPacketCreatorPeer::GetCurrentPath(&creator_));
1624 EXPECT_FALSE(creator_.HasPendingFrames()); 1626 EXPECT_FALSE(creator_.HasPendingFrames());
1625 EXPECT_EQ(0u, creator_.packet_number()); 1627 EXPECT_EQ(0u, creator_.packet_number());
1626 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, 1628 EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER,
1627 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_)); 1629 QuicPacketCreatorPeer::NextPacketNumberLength(&creator_));
1628 1630
1629 // Add a stream frame to the creator and flush the packet. 1631 // Add a stream frame to the creator and flush the packet.
1630 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame, 1632 ASSERT_TRUE(creator_.ConsumeData(1u, io_vector, 0u, 0u, false, false, &frame,
1631 MAY_FEC_PROTECT)); 1633 MAY_FEC_PROTECT));
1632 ASSERT_TRUE(frame.stream_frame); 1634 ASSERT_TRUE(frame.stream_frame);
1633 consumed = frame.stream_frame->frame_length; 1635 consumed = frame.stream_frame->frame_length;
1634 EXPECT_EQ(4u, consumed); 1636 EXPECT_EQ(4u, consumed);
1635 EXPECT_TRUE(creator_.HasPendingFrames()); 1637 EXPECT_TRUE(creator_.HasPendingFrames());
1636 creator_.Flush(); 1638 creator_.Flush();
1637 // Verify serialized data packet's path id. 1639 // Verify serialized data packet's path id.
1638 EXPECT_EQ(kPathId1, serialized_packet_.path_id); 1640 EXPECT_EQ(kPathId1, serialized_packet_.path_id);
1639 ClearSerializedPacket(&serialized_packet_); 1641 DeleteSerializedPacket();
1640 } 1642 }
1641 1643
1642 TEST_P(QuicPacketCreatorTest, AddUnencryptedStreamDataClosesConnection) { 1644 TEST_P(QuicPacketCreatorTest, AddUnencryptedStreamDataClosesConnection) {
1643 FLAGS_quic_never_write_unencrypted_data = true; 1645 FLAGS_quic_never_write_unencrypted_data = true;
1644 EXPECT_CALL(delegate_, CloseConnection(_, _)); 1646 EXPECT_CALL(delegate_, CloseConnection(_, _));
1645 QuicStreamFrame stream_frame(kHeadersStreamId, /*fin=*/false, 0u, 1647 QuicStreamFrame stream_frame(kHeadersStreamId, /*fin=*/false, 0u,
1646 StringPiece()); 1648 StringPiece());
1647 EXPECT_DFATAL(creator_.AddSavedFrame(QuicFrame(&stream_frame)), 1649 EXPECT_DFATAL(creator_.AddSavedFrame(QuicFrame(&stream_frame)),
1648 "Cannot send stream data without encryption."); 1650 "Cannot send stream data without encryption.");
1649 } 1651 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1694 EXPECT_CALL(delegate_, CloseConnection(QUIC_UNENCRYPTED_FEC_DATA, _)); 1696 EXPECT_CALL(delegate_, CloseConnection(QUIC_UNENCRYPTED_FEC_DATA, _));
1695 char seralized_fec_buffer[kMaxPacketSize]; 1697 char seralized_fec_buffer[kMaxPacketSize];
1696 EXPECT_DFATAL(QuicPacketCreatorPeer::SerializeFec( 1698 EXPECT_DFATAL(QuicPacketCreatorPeer::SerializeFec(
1697 &creator_, seralized_fec_buffer, kMaxPacketSize), 1699 &creator_, seralized_fec_buffer, kMaxPacketSize),
1698 "SerializeFEC must be called with encryption."); 1700 "SerializeFEC must be called with encryption.");
1699 } 1701 }
1700 1702
1701 } // namespace 1703 } // namespace
1702 } // namespace test 1704 } // namespace test
1703 } // namespace net 1705 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698