OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_packet_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 14 matching lines...) Expand all Loading... |
25 using testing::InSequence; | 25 using testing::InSequence; |
26 using testing::Return; | 26 using testing::Return; |
27 using testing::SaveArg; | 27 using testing::SaveArg; |
28 using testing::StrictMock; | 28 using testing::StrictMock; |
29 using testing::_; | 29 using testing::_; |
30 | 30 |
31 namespace net { | 31 namespace net { |
32 namespace test { | 32 namespace test { |
33 namespace { | 33 namespace { |
34 | 34 |
| 35 const int64 kMinFecTimeoutMs = 5u; |
| 36 |
35 class MockDelegate : public QuicPacketGenerator::DelegateInterface { | 37 class MockDelegate : public QuicPacketGenerator::DelegateInterface { |
36 public: | 38 public: |
37 MockDelegate() {} | 39 MockDelegate() {} |
38 ~MockDelegate() override {} | 40 ~MockDelegate() override {} |
39 | 41 |
40 MOCK_METHOD3(ShouldGeneratePacket, | 42 MOCK_METHOD3(ShouldGeneratePacket, |
41 bool(TransmissionType transmission_type, | 43 bool(TransmissionType transmission_type, |
42 HasRetransmittableData retransmittable, | 44 HasRetransmittableData retransmittable, |
43 IsHandshake handshake)); | 45 IsHandshake handshake)); |
44 MOCK_METHOD0(CreateAckFrame, QuicAckFrame*()); | 46 MOCK_METHOD0(CreateAckFrame, QuicAckFrame*()); |
(...skipping 25 matching lines...) Expand all Loading... |
70 EXPECT_CALL(*this, ShouldGeneratePacket(NOT_RETRANSMISSION, | 72 EXPECT_CALL(*this, ShouldGeneratePacket(NOT_RETRANSMISSION, |
71 NO_RETRANSMITTABLE_DATA, _)) | 73 NO_RETRANSMITTABLE_DATA, _)) |
72 .WillRepeatedly(Return(true)); | 74 .WillRepeatedly(Return(true)); |
73 } | 75 } |
74 | 76 |
75 private: | 77 private: |
76 DISALLOW_COPY_AND_ASSIGN(MockDelegate); | 78 DISALLOW_COPY_AND_ASSIGN(MockDelegate); |
77 }; | 79 }; |
78 | 80 |
79 // Simple struct for describing the contents of a packet. | 81 // Simple struct for describing the contents of a packet. |
80 // Useful in conjunction with a SimpleQuicFrame for validating | 82 // Useful in conjunction with a SimpleQuicFrame for validating that a packet |
81 // that a packet contains the expected frames. | 83 // contains the expected frames. |
82 struct PacketContents { | 84 struct PacketContents { |
83 PacketContents() | 85 PacketContents() |
84 : num_ack_frames(0), | 86 : num_ack_frames(0), |
85 num_connection_close_frames(0), | 87 num_connection_close_frames(0), |
86 num_feedback_frames(0), | 88 num_feedback_frames(0), |
87 num_goaway_frames(0), | 89 num_goaway_frames(0), |
88 num_rst_stream_frames(0), | 90 num_rst_stream_frames(0), |
89 num_stop_waiting_frames(0), | 91 num_stop_waiting_frames(0), |
90 num_stream_frames(0), | 92 num_stream_frames(0), |
91 fec_group(0) { | 93 fec_group(0) { |
(...skipping 17 matching lines...) Expand all Loading... |
109 QuicPacketGeneratorTest() | 111 QuicPacketGeneratorTest() |
110 : framer_(QuicSupportedVersions(), QuicTime::Zero(), false), | 112 : framer_(QuicSupportedVersions(), QuicTime::Zero(), false), |
111 generator_(42, &framer_, &random_, &delegate_), | 113 generator_(42, &framer_, &random_, &delegate_), |
112 creator_(QuicPacketGeneratorPeer::GetPacketCreator(&generator_)), | 114 creator_(QuicPacketGeneratorPeer::GetPacketCreator(&generator_)), |
113 packet_(0, PACKET_1BYTE_SEQUENCE_NUMBER, nullptr, 0, nullptr), | 115 packet_(0, PACKET_1BYTE_SEQUENCE_NUMBER, nullptr, 0, nullptr), |
114 packet2_(0, PACKET_1BYTE_SEQUENCE_NUMBER, nullptr, 0, nullptr), | 116 packet2_(0, PACKET_1BYTE_SEQUENCE_NUMBER, nullptr, 0, nullptr), |
115 packet3_(0, PACKET_1BYTE_SEQUENCE_NUMBER, nullptr, 0, nullptr), | 117 packet3_(0, PACKET_1BYTE_SEQUENCE_NUMBER, nullptr, 0, nullptr), |
116 packet4_(0, PACKET_1BYTE_SEQUENCE_NUMBER, nullptr, 0, nullptr), | 118 packet4_(0, PACKET_1BYTE_SEQUENCE_NUMBER, nullptr, 0, nullptr), |
117 packet5_(0, PACKET_1BYTE_SEQUENCE_NUMBER, nullptr, 0, nullptr), | 119 packet5_(0, PACKET_1BYTE_SEQUENCE_NUMBER, nullptr, 0, nullptr), |
118 packet6_(0, PACKET_1BYTE_SEQUENCE_NUMBER, nullptr, 0, nullptr), | 120 packet6_(0, PACKET_1BYTE_SEQUENCE_NUMBER, nullptr, 0, nullptr), |
119 packet7_(0, PACKET_1BYTE_SEQUENCE_NUMBER, nullptr, 0, nullptr) {} | 121 packet7_(0, PACKET_1BYTE_SEQUENCE_NUMBER, nullptr, 0, nullptr), |
| 122 packet8_(0, PACKET_1BYTE_SEQUENCE_NUMBER, nullptr, 0, nullptr) {} |
120 | 123 |
121 ~QuicPacketGeneratorTest() override { | 124 ~QuicPacketGeneratorTest() override { |
122 delete packet_.packet; | 125 delete packet_.packet; |
123 delete packet_.retransmittable_frames; | 126 delete packet_.retransmittable_frames; |
124 delete packet2_.packet; | 127 delete packet2_.packet; |
125 delete packet2_.retransmittable_frames; | 128 delete packet2_.retransmittable_frames; |
126 delete packet3_.packet; | 129 delete packet3_.packet; |
127 delete packet3_.retransmittable_frames; | 130 delete packet3_.retransmittable_frames; |
128 delete packet4_.packet; | 131 delete packet4_.packet; |
129 delete packet4_.retransmittable_frames; | 132 delete packet4_.retransmittable_frames; |
130 delete packet5_.packet; | 133 delete packet5_.packet; |
131 delete packet5_.retransmittable_frames; | 134 delete packet5_.retransmittable_frames; |
132 delete packet6_.packet; | 135 delete packet6_.packet; |
133 delete packet6_.retransmittable_frames; | 136 delete packet6_.retransmittable_frames; |
134 delete packet7_.packet; | 137 delete packet7_.packet; |
135 delete packet7_.retransmittable_frames; | 138 delete packet7_.retransmittable_frames; |
| 139 delete packet8_.packet; |
| 140 delete packet8_.retransmittable_frames; |
136 } | 141 } |
137 | 142 |
138 QuicAckFrame* CreateAckFrame() { | 143 QuicAckFrame* CreateAckFrame() { |
139 // TODO(rch): Initialize this so it can be verified later. | 144 // TODO(rch): Initialize this so it can be verified later. |
140 return new QuicAckFrame(MakeAckFrame(0)); | 145 return new QuicAckFrame(MakeAckFrame(0)); |
141 } | 146 } |
142 | 147 |
143 QuicCongestionFeedbackFrame* CreateFeedbackFrame() { | 148 QuicCongestionFeedbackFrame* CreateFeedbackFrame() { |
144 QuicCongestionFeedbackFrame* frame = new QuicCongestionFeedbackFrame; | 149 QuicCongestionFeedbackFrame* frame = new QuicCongestionFeedbackFrame; |
145 frame->type = kTCP; | 150 frame->type = kTCP; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 QuicPacketGenerator generator_; | 234 QuicPacketGenerator generator_; |
230 QuicPacketCreator* creator_; | 235 QuicPacketCreator* creator_; |
231 SimpleQuicFramer simple_framer_; | 236 SimpleQuicFramer simple_framer_; |
232 SerializedPacket packet_; | 237 SerializedPacket packet_; |
233 SerializedPacket packet2_; | 238 SerializedPacket packet2_; |
234 SerializedPacket packet3_; | 239 SerializedPacket packet3_; |
235 SerializedPacket packet4_; | 240 SerializedPacket packet4_; |
236 SerializedPacket packet5_; | 241 SerializedPacket packet5_; |
237 SerializedPacket packet6_; | 242 SerializedPacket packet6_; |
238 SerializedPacket packet7_; | 243 SerializedPacket packet7_; |
| 244 SerializedPacket packet8_; |
239 | 245 |
240 private: | 246 private: |
241 scoped_ptr<char[]> data_array_; | 247 scoped_ptr<char[]> data_array_; |
242 }; | 248 }; |
243 | 249 |
244 class MockDebugDelegate : public QuicPacketGenerator::DebugDelegate { | 250 class MockDebugDelegate : public QuicPacketGenerator::DebugDelegate { |
245 public: | 251 public: |
246 MOCK_METHOD1(OnFrameAddedToPacket, | 252 MOCK_METHOD1(OnFrameAddedToPacket, |
247 void(const QuicFrame&)); | 253 void(const QuicFrame&)); |
248 }; | 254 }; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 // Now both frames will be flushed out. | 472 // Now both frames will be flushed out. |
467 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet_)); | 473 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet_)); |
468 generator_.FinishBatchOperations(); | 474 generator_.FinishBatchOperations(); |
469 EXPECT_FALSE(generator_.HasQueuedFrames()); | 475 EXPECT_FALSE(generator_.HasQueuedFrames()); |
470 | 476 |
471 PacketContents contents; | 477 PacketContents contents; |
472 contents.num_stream_frames = 2; | 478 contents.num_stream_frames = 2; |
473 CheckPacketContains(contents, packet_); | 479 CheckPacketContains(contents, packet_); |
474 } | 480 } |
475 | 481 |
476 TEST_F(QuicPacketGeneratorTest, ConsumeDataFEC) { | 482 TEST_F(QuicPacketGeneratorTest, ConsumeDataSendsFecOnMaxGroupSize) { |
477 delegate_.SetCanWriteAnything(); | 483 delegate_.SetCanWriteAnything(); |
478 | 484 |
479 // Send FEC every two packets. | 485 // Send FEC every two packets. |
480 creator_->set_max_packets_per_fec_group(2); | 486 creator_->set_max_packets_per_fec_group(2); |
481 | 487 |
482 { | 488 { |
483 InSequence dummy; | 489 InSequence dummy; |
484 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 490 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
485 SaveArg<0>(&packet_)); | 491 SaveArg<0>(&packet_)); |
486 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 492 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
487 SaveArg<0>(&packet2_)); | 493 SaveArg<0>(&packet2_)); |
488 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 494 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
489 SaveArg<0>(&packet3_)); | 495 SaveArg<0>(&packet3_)); |
490 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 496 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
491 SaveArg<0>(&packet4_)); | 497 SaveArg<0>(&packet4_)); |
492 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | |
493 SaveArg<0>(&packet5_)); | |
494 } | 498 } |
495 | 499 |
496 // Send enough data to create 3 packets: two full and one partial. Send | 500 // Send enough data to create 3 packets: two full and one partial. Send with |
497 // with MUST_FEC_PROTECT flag. | 501 // MUST_FEC_PROTECT flag. |
498 size_t data_len = 2 * kDefaultMaxPacketSize + 100; | 502 size_t data_len = 2 * kDefaultMaxPacketSize + 100; |
499 QuicConsumedData consumed = generator_.ConsumeData( | 503 QuicConsumedData consumed = generator_.ConsumeData( |
500 3, CreateData(data_len), 0, true, MUST_FEC_PROTECT, nullptr); | 504 3, CreateData(data_len), 0, true, MUST_FEC_PROTECT, nullptr); |
501 EXPECT_EQ(data_len, consumed.bytes_consumed); | 505 EXPECT_EQ(data_len, consumed.bytes_consumed); |
502 EXPECT_TRUE(consumed.fin_consumed); | 506 EXPECT_TRUE(consumed.fin_consumed); |
503 EXPECT_FALSE(generator_.HasQueuedFrames()); | 507 EXPECT_FALSE(generator_.HasQueuedFrames()); |
504 | 508 |
505 CheckPacketHasSingleStreamFrame(packet_); | 509 CheckPacketHasSingleStreamFrame(packet_); |
506 CheckPacketHasSingleStreamFrame(packet2_); | 510 CheckPacketHasSingleStreamFrame(packet2_); |
507 CheckPacketIsFec(packet3_, 1); | 511 CheckPacketIsFec(packet3_, 1); |
| 512 CheckPacketHasSingleStreamFrame(packet4_); |
| 513 EXPECT_TRUE(creator_->IsFecProtected()); |
508 | 514 |
509 CheckPacketHasSingleStreamFrame(packet4_); | 515 // The FEC packet under construction will be sent when one more packet is sent |
510 CheckPacketIsFec(packet5_, 4); | 516 // (since FEC group size is 2), or when OnFecTimeout is called. Send more data |
| 517 // with MAY_FEC_PROTECT. This packet should also be protected, and FEC packet |
| 518 // is sent since FEC group size is reached. |
| 519 { |
| 520 InSequence dummy; |
| 521 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
| 522 .WillOnce(SaveArg<0>(&packet5_)); |
| 523 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
| 524 .WillOnce(SaveArg<0>(&packet6_)); |
| 525 } |
| 526 consumed = generator_.ConsumeData(5, CreateData(1u), 0, true, MAY_FEC_PROTECT, |
| 527 nullptr); |
| 528 EXPECT_EQ(1u, consumed.bytes_consumed); |
| 529 CheckPacketHasSingleStreamFrame(packet5_); |
| 530 CheckPacketIsFec(packet6_, 4); |
| 531 EXPECT_FALSE(creator_->IsFecProtected()); |
511 } | 532 } |
512 | 533 |
513 TEST_F(QuicPacketGeneratorTest, ConsumeDataSendsFecAtEnd) { | 534 TEST_F(QuicPacketGeneratorTest, ConsumeDataSendsFecOnTimeout) { |
514 delegate_.SetCanWriteAnything(); | 535 delegate_.SetCanWriteAnything(); |
| 536 creator_->set_max_packets_per_fec_group(1000); |
515 | 537 |
516 // Enable FEC. | 538 // Send data with MUST_FEC_PROTECT flag. No FEC packet is emitted, but the |
| 539 // creator FEC protects all data. |
| 540 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet_)); |
| 541 QuicConsumedData consumed = generator_.ConsumeData(3, CreateData(1u), 0, true, |
| 542 MUST_FEC_PROTECT, nullptr); |
| 543 EXPECT_EQ(1u, consumed.bytes_consumed); |
| 544 EXPECT_TRUE(consumed.fin_consumed); |
| 545 CheckPacketHasSingleStreamFrame(packet_); |
| 546 EXPECT_TRUE(creator_->IsFecProtected()); |
| 547 |
| 548 // Send more data with MAY_FEC_PROTECT. This packet should also be protected, |
| 549 // and FEC packet is not yet sent. |
| 550 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet2_)); |
| 551 consumed = generator_.ConsumeData(5, CreateData(1u), 0, true, MAY_FEC_PROTECT, |
| 552 nullptr); |
| 553 EXPECT_EQ(1u, consumed.bytes_consumed); |
| 554 CheckPacketHasSingleStreamFrame(packet2_); |
| 555 EXPECT_TRUE(creator_->IsFecProtected()); |
| 556 |
| 557 // Calling OnFecTimeout should cause the FEC packet to be emitted. |
| 558 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet3_)); |
| 559 generator_.OnFecTimeout(); |
| 560 CheckPacketIsFec(packet3_, 1); |
| 561 EXPECT_FALSE(creator_->IsFecProtected()); |
| 562 |
| 563 // Subsequent data is protected under the next FEC group. Send enough data to |
| 564 // create 2 more packets: one full and one partial. |
| 565 { |
| 566 InSequence dummy; |
| 567 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
| 568 .WillOnce(SaveArg<0>(&packet4_)); |
| 569 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
| 570 .WillOnce(SaveArg<0>(&packet5_)); |
| 571 } |
| 572 size_t data_len = kDefaultMaxPacketSize + 1; |
| 573 consumed = generator_.ConsumeData(7, CreateData(data_len), 0, true, |
| 574 MUST_FEC_PROTECT, nullptr); |
| 575 EXPECT_EQ(data_len, consumed.bytes_consumed); |
| 576 EXPECT_TRUE(consumed.fin_consumed); |
| 577 CheckPacketHasSingleStreamFrame(packet4_); |
| 578 CheckPacketHasSingleStreamFrame(packet5_); |
| 579 EXPECT_TRUE(creator_->IsFecProtected()); |
| 580 |
| 581 // Calling OnFecTimeout should cause the FEC packet to be emitted. |
| 582 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet6_)); |
| 583 generator_.OnFecTimeout(); |
| 584 CheckPacketIsFec(packet6_, 4); |
| 585 EXPECT_FALSE(creator_->IsFecProtected()); |
| 586 } |
| 587 |
| 588 TEST_F(QuicPacketGeneratorTest, GetFecTimeoutFiniteOnlyOnFirstPacketInGroup) { |
| 589 delegate_.SetCanWriteAnything(); |
517 creator_->set_max_packets_per_fec_group(6); | 590 creator_->set_max_packets_per_fec_group(6); |
| 591 |
| 592 // Send enough data to create 2 packets: one full and one partial. Send with |
| 593 // MUST_FEC_PROTECT flag. No FEC packet is emitted yet, but the creator FEC |
| 594 // protects all data. |
518 { | 595 { |
519 InSequence dummy; | 596 InSequence dummy; |
520 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 597 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
521 SaveArg<0>(&packet_)); | 598 SaveArg<0>(&packet_)); |
522 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 599 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
523 SaveArg<0>(&packet2_)); | 600 SaveArg<0>(&packet2_)); |
524 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | |
525 SaveArg<0>(&packet3_)); | |
526 } | 601 } |
527 | |
528 // Send enough data to create 2 packets: one full and one partial. Send | |
529 // with MUST_FEC_PROTECT flag. | |
530 size_t data_len = 1 * kDefaultMaxPacketSize + 100; | 602 size_t data_len = 1 * kDefaultMaxPacketSize + 100; |
531 QuicConsumedData consumed = generator_.ConsumeData( | 603 QuicConsumedData consumed = generator_.ConsumeData( |
532 3, CreateData(data_len), 0, true, MUST_FEC_PROTECT, nullptr); | 604 3, CreateData(data_len), 0, true, MUST_FEC_PROTECT, nullptr); |
533 EXPECT_EQ(data_len, consumed.bytes_consumed); | 605 EXPECT_EQ(data_len, consumed.bytes_consumed); |
534 EXPECT_TRUE(consumed.fin_consumed); | 606 EXPECT_TRUE(consumed.fin_consumed); |
535 EXPECT_FALSE(generator_.HasQueuedFrames()); | 607 EXPECT_FALSE(generator_.HasQueuedFrames()); |
536 | |
537 CheckPacketHasSingleStreamFrame(packet_); | 608 CheckPacketHasSingleStreamFrame(packet_); |
538 CheckPacketHasSingleStreamFrame(packet2_); | 609 CheckPacketHasSingleStreamFrame(packet2_); |
539 CheckPacketIsFec(packet3_, 1); | 610 EXPECT_TRUE(creator_->IsFecProtected()); |
| 611 |
| 612 // GetFecTimeout returns finite timeout only for first packet in group. |
| 613 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(kMinFecTimeoutMs), |
| 614 generator_.GetFecTimeout(/*sequence_number=*/1u)); |
| 615 EXPECT_EQ(QuicTime::Delta::Infinite(), |
| 616 generator_.GetFecTimeout(/*sequence_number=*/2u)); |
| 617 |
| 618 // Send more data with MAY_FEC_PROTECT. This packet should also be protected, |
| 619 // and FEC packet is not yet sent. |
| 620 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet3_)); |
| 621 consumed = generator_.ConsumeData(5, CreateData(1u), 0, true, MAY_FEC_PROTECT, |
| 622 nullptr); |
| 623 CheckPacketHasSingleStreamFrame(packet3_); |
| 624 EXPECT_TRUE(creator_->IsFecProtected()); |
| 625 |
| 626 // GetFecTimeout returns finite timeout only for first packet in group. |
| 627 EXPECT_EQ(QuicTime::Delta::Infinite(), |
| 628 generator_.GetFecTimeout(/*sequence_number=*/3u)); |
| 629 |
| 630 // Calling OnFecTimeout should cause the FEC packet to be emitted. |
| 631 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet4_)); |
| 632 generator_.OnFecTimeout(); |
| 633 CheckPacketIsFec(packet4_, /*fec_group=*/1u); |
| 634 EXPECT_FALSE(creator_->IsFecProtected()); |
| 635 |
| 636 // Subsequent data is protected under the next FEC group. Send enough data to |
| 637 // create 2 more packets: one full and one partial. |
| 638 { |
| 639 InSequence dummy; |
| 640 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
| 641 .WillOnce(SaveArg<0>(&packet5_)); |
| 642 EXPECT_CALL(delegate_, OnSerializedPacket(_)) |
| 643 .WillOnce(SaveArg<0>(&packet6_)); |
| 644 } |
| 645 data_len = kDefaultMaxPacketSize + 1u; |
| 646 consumed = generator_.ConsumeData(7, CreateData(data_len), 0, true, |
| 647 MUST_FEC_PROTECT, nullptr); |
| 648 EXPECT_EQ(data_len, consumed.bytes_consumed); |
| 649 EXPECT_TRUE(consumed.fin_consumed); |
| 650 CheckPacketHasSingleStreamFrame(packet5_); |
| 651 CheckPacketHasSingleStreamFrame(packet6_); |
| 652 EXPECT_TRUE(creator_->IsFecProtected()); |
| 653 |
| 654 // GetFecTimeout returns finite timeout for first packet in the new group. |
| 655 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(kMinFecTimeoutMs), |
| 656 generator_.GetFecTimeout(/*sequence_number=*/5u)); |
| 657 EXPECT_EQ(QuicTime::Delta::Infinite(), |
| 658 generator_.GetFecTimeout(/*sequence_number=*/6u)); |
| 659 |
| 660 // Calling OnFecTimeout should cause the FEC packet to be emitted. |
| 661 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet7_)); |
| 662 generator_.OnFecTimeout(); |
| 663 CheckPacketIsFec(packet7_, /*fec_group=*/5u); |
| 664 EXPECT_FALSE(creator_->IsFecProtected()); |
| 665 |
| 666 // Send more data with MAY_FEC_PROTECT. No FEC protection, so GetFecTimeout |
| 667 // returns infinite. |
| 668 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet8_)); |
| 669 consumed = generator_.ConsumeData(9, CreateData(1u), 0, true, MAY_FEC_PROTECT, |
| 670 nullptr); |
| 671 CheckPacketHasSingleStreamFrame(packet8_); |
| 672 EXPECT_FALSE(creator_->IsFecProtected()); |
| 673 EXPECT_EQ(QuicTime::Delta::Infinite(), |
| 674 generator_.GetFecTimeout(/*sequence_number=*/8u)); |
540 } | 675 } |
541 | 676 |
542 TEST_F(QuicPacketGeneratorTest, ConsumeData_FramesPreviouslyQueued) { | 677 TEST_F(QuicPacketGeneratorTest, ConsumeData_FramesPreviouslyQueued) { |
543 // Set the packet size be enough for two stream frames with 0 stream offset, | 678 // Set the packet size be enough for two stream frames with 0 stream offset, |
544 // but not enough for a stream frame of 0 offset and one with non-zero offset. | 679 // but not enough for a stream frame of 0 offset and one with non-zero offset. |
545 size_t length = | 680 size_t length = |
546 NullEncrypter().GetCiphertextSize(0) + | 681 NullEncrypter().GetCiphertextSize(0) + |
547 GetPacketHeaderSize(creator_->connection_id_length(), | 682 GetPacketHeaderSize(creator_->connection_id_length(), true, |
548 true, | |
549 creator_->next_sequence_number_length(), | 683 creator_->next_sequence_number_length(), |
550 NOT_IN_FEC_GROUP) + | 684 NOT_IN_FEC_GROUP) + |
551 // Add an extra 3 bytes for the payload and 1 byte so BytesFree is larger | 685 // Add an extra 3 bytes for the payload and 1 byte so BytesFree is larger |
552 // than the GetMinStreamFrameSize. | 686 // than the GetMinStreamFrameSize. |
553 QuicFramer::GetMinStreamFrameSize(1, 0, false, NOT_IN_FEC_GROUP) + 3 + | 687 QuicFramer::GetMinStreamFrameSize(1, 0, false, NOT_IN_FEC_GROUP) + 3 + |
554 QuicFramer::GetMinStreamFrameSize(1, 0, true, NOT_IN_FEC_GROUP) + 1; | 688 QuicFramer::GetMinStreamFrameSize(1, 0, true, NOT_IN_FEC_GROUP) + 1; |
555 creator_->set_max_packet_length(length); | 689 creator_->set_max_packet_length(length); |
556 delegate_.SetCanWriteAnything(); | 690 delegate_.SetCanWriteAnything(); |
557 { | 691 { |
558 InSequence dummy; | 692 InSequence dummy; |
(...skipping 20 matching lines...) Expand all Loading... |
579 EXPECT_EQ(3u, consumed.bytes_consumed); | 713 EXPECT_EQ(3u, consumed.bytes_consumed); |
580 EXPECT_TRUE(consumed.fin_consumed); | 714 EXPECT_TRUE(consumed.fin_consumed); |
581 EXPECT_FALSE(generator_.HasQueuedFrames()); | 715 EXPECT_FALSE(generator_.HasQueuedFrames()); |
582 | 716 |
583 PacketContents contents; | 717 PacketContents contents; |
584 contents.num_stream_frames = 1; | 718 contents.num_stream_frames = 1; |
585 CheckPacketContains(contents, packet_); | 719 CheckPacketContains(contents, packet_); |
586 CheckPacketContains(contents, packet2_); | 720 CheckPacketContains(contents, packet2_); |
587 } | 721 } |
588 | 722 |
| 723 TEST_F(QuicPacketGeneratorTest, NoFecPacketSentWhenBatchEnds) { |
| 724 delegate_.SetCanWriteAnything(); |
| 725 creator_->set_max_packets_per_fec_group(6); |
| 726 |
| 727 generator_.StartBatchOperations(); |
| 728 |
| 729 generator_.ConsumeData(3, MakeIOVector("foo"), 2, true, MUST_FEC_PROTECT, |
| 730 nullptr); |
| 731 QuicConsumedData consumed = generator_.ConsumeData( |
| 732 5, MakeIOVector("quux"), 7, false, MUST_FEC_PROTECT, nullptr); |
| 733 EXPECT_EQ(4u, consumed.bytes_consumed); |
| 734 EXPECT_FALSE(consumed.fin_consumed); |
| 735 EXPECT_TRUE(generator_.HasQueuedFrames()); |
| 736 |
| 737 // Now both frames will be flushed out, but FEC packet is not yet sent. |
| 738 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet_)); |
| 739 generator_.FinishBatchOperations(); |
| 740 EXPECT_FALSE(generator_.HasQueuedFrames()); |
| 741 |
| 742 PacketContents contents; |
| 743 contents.num_stream_frames = 2u; |
| 744 contents.fec_group = 1u; |
| 745 CheckPacketContains(contents, packet_); |
| 746 |
| 747 // Forcing FEC timeout causes FEC packet to be emitted. |
| 748 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet2_)); |
| 749 generator_.OnFecTimeout(); |
| 750 CheckPacketIsFec(packet2_, /*fec_group=*/1u); |
| 751 } |
| 752 |
589 TEST_F(QuicPacketGeneratorTest, FecTimeoutOnRttChange) { | 753 TEST_F(QuicPacketGeneratorTest, FecTimeoutOnRttChange) { |
590 EXPECT_EQ(QuicTime::Delta::Zero(), generator_.fec_timeout()); | 754 EXPECT_EQ(QuicTime::Delta::Zero(), |
| 755 QuicPacketGeneratorPeer::GetFecTimeout(&generator_)); |
591 generator_.OnRttChange(QuicTime::Delta::FromMilliseconds(300)); | 756 generator_.OnRttChange(QuicTime::Delta::FromMilliseconds(300)); |
592 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(150), generator_.fec_timeout()); | 757 EXPECT_EQ(QuicTime::Delta::FromMilliseconds(150), |
| 758 QuicPacketGeneratorPeer::GetFecTimeout(&generator_)); |
593 } | 759 } |
594 | 760 |
595 TEST_F(QuicPacketGeneratorTest, FecGroupSizeOnCongestionWindowChange) { | 761 TEST_F(QuicPacketGeneratorTest, FecGroupSizeOnCongestionWindowChange) { |
596 delegate_.SetCanWriteAnything(); | 762 delegate_.SetCanWriteAnything(); |
597 creator_->set_max_packets_per_fec_group(50); | 763 creator_->set_max_packets_per_fec_group(50); |
598 EXPECT_EQ(50u, creator_->max_packets_per_fec_group()); | 764 EXPECT_EQ(50u, creator_->max_packets_per_fec_group()); |
599 EXPECT_FALSE(creator_->IsFecGroupOpen()); | 765 EXPECT_FALSE(creator_->IsFecGroupOpen()); |
600 | 766 |
601 // On reduced cwnd. | 767 // On reduced cwnd. |
602 generator_.OnCongestionWindowChange(7); | 768 generator_.OnCongestionWindowChange(7); |
603 EXPECT_EQ(3u, creator_->max_packets_per_fec_group()); | 769 EXPECT_EQ(3u, creator_->max_packets_per_fec_group()); |
604 | 770 |
605 // On increased cwnd. | 771 // On increased cwnd. |
606 generator_.OnCongestionWindowChange(100); | 772 generator_.OnCongestionWindowChange(100); |
607 EXPECT_EQ(50u, creator_->max_packets_per_fec_group()); | 773 EXPECT_EQ(50u, creator_->max_packets_per_fec_group()); |
608 | 774 |
609 // On collapsed cwnd. | 775 // On collapsed cwnd. |
610 generator_.OnCongestionWindowChange(1); | 776 generator_.OnCongestionWindowChange(1); |
611 EXPECT_EQ(2u, creator_->max_packets_per_fec_group()); | 777 EXPECT_EQ(2u, creator_->max_packets_per_fec_group()); |
612 } | 778 } |
613 | 779 |
614 TEST_F(QuicPacketGeneratorTest, FecGroupSizeChangeWithOpenGroup) { | 780 TEST_F(QuicPacketGeneratorTest, FecGroupSizeChangeWithOpenGroup) { |
615 delegate_.SetCanWriteAnything(); | 781 delegate_.SetCanWriteAnything(); |
616 // TODO(jri): This starting of batch mode should not be required when | |
617 // FEC sending is separated from batching operations. | |
618 generator_.StartBatchOperations(); | 782 generator_.StartBatchOperations(); |
619 creator_->set_max_packets_per_fec_group(50); | 783 creator_->set_max_packets_per_fec_group(50); |
620 EXPECT_EQ(50u, creator_->max_packets_per_fec_group()); | 784 EXPECT_EQ(50u, creator_->max_packets_per_fec_group()); |
621 EXPECT_FALSE(creator_->IsFecGroupOpen()); | 785 EXPECT_FALSE(creator_->IsFecGroupOpen()); |
622 | 786 |
623 // Send enough data to create 4 packets with MUST_FEC_PROTECT flag. | 787 // Send enough data to create 4 packets with MUST_FEC_PROTECT flag. 3 packets |
624 // 3 packets are sent, one is queued in the creator. | 788 // are sent, one is queued in the creator. |
625 { | 789 { |
626 InSequence dummy; | 790 InSequence dummy; |
627 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 791 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
628 SaveArg<0>(&packet_)); | 792 SaveArg<0>(&packet_)); |
629 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 793 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
630 SaveArg<0>(&packet2_)); | 794 SaveArg<0>(&packet2_)); |
631 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 795 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
632 SaveArg<0>(&packet3_)); | 796 SaveArg<0>(&packet3_)); |
633 } | 797 } |
634 size_t data_len = 3 * kDefaultMaxPacketSize + 1; | 798 size_t data_len = 3 * kDefaultMaxPacketSize + 1; |
635 QuicConsumedData consumed = generator_.ConsumeData( | 799 QuicConsumedData consumed = generator_.ConsumeData( |
636 7, CreateData(data_len), 0, true, MUST_FEC_PROTECT, nullptr); | 800 7, CreateData(data_len), 0, true, MUST_FEC_PROTECT, nullptr); |
637 EXPECT_EQ(data_len, consumed.bytes_consumed); | 801 EXPECT_EQ(data_len, consumed.bytes_consumed); |
638 EXPECT_TRUE(creator_->IsFecGroupOpen()); | 802 EXPECT_TRUE(creator_->IsFecGroupOpen()); |
639 | 803 |
640 // Change FEC groupsize. | 804 // Change FEC groupsize. |
641 generator_.OnCongestionWindowChange(2); | 805 generator_.OnCongestionWindowChange(2); |
642 EXPECT_EQ(2u, creator_->max_packets_per_fec_group()); | 806 EXPECT_EQ(2u, creator_->max_packets_per_fec_group()); |
643 | 807 |
644 // Send enough data to trigger one unprotected data packet, | 808 // Send enough data to trigger one unprotected data packet, causing the FEC |
645 // causing the FEC packet to also be sent. | 809 // packet to also be sent. |
646 { | 810 { |
647 InSequence dummy; | 811 InSequence dummy; |
648 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 812 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
649 SaveArg<0>(&packet4_)); | 813 SaveArg<0>(&packet4_)); |
650 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 814 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
651 SaveArg<0>(&packet5_)); | 815 SaveArg<0>(&packet5_)); |
652 } | 816 } |
653 consumed = generator_.ConsumeData(7, CreateData(kDefaultMaxPacketSize), 0, | 817 consumed = generator_.ConsumeData(7, CreateData(kDefaultMaxPacketSize), 0, |
654 true, MAY_FEC_PROTECT, nullptr); | 818 true, MAY_FEC_PROTECT, nullptr); |
655 EXPECT_EQ(kDefaultMaxPacketSize, consumed.bytes_consumed); | 819 EXPECT_EQ(kDefaultMaxPacketSize, consumed.bytes_consumed); |
(...skipping 24 matching lines...) Expand all Loading... |
680 { | 844 { |
681 InSequence dummy; | 845 InSequence dummy; |
682 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 846 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
683 SaveArg<0>(&packet2_)); | 847 SaveArg<0>(&packet2_)); |
684 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 848 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
685 SaveArg<0>(&packet3_)); | 849 SaveArg<0>(&packet3_)); |
686 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 850 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
687 SaveArg<0>(&packet4_)); | 851 SaveArg<0>(&packet4_)); |
688 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 852 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
689 SaveArg<0>(&packet5_)); | 853 SaveArg<0>(&packet5_)); |
690 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | |
691 SaveArg<0>(&packet6_)); | |
692 } | 854 } |
693 // Send enough data to create 3 packets with MUST_FEC_PROTECT flag. | 855 // Send enough data to create 3 packets with MUST_FEC_PROTECT flag. |
694 size_t data_len = 2 * kDefaultMaxPacketSize + 100; | 856 size_t data_len = 2 * kDefaultMaxPacketSize + 100; |
695 consumed = generator_.ConsumeData(7, CreateData(data_len), 0, true, | 857 consumed = generator_.ConsumeData(7, CreateData(data_len), 0, true, |
696 MUST_FEC_PROTECT, nullptr); | 858 MUST_FEC_PROTECT, nullptr); |
697 EXPECT_EQ(data_len, consumed.bytes_consumed); | 859 EXPECT_EQ(data_len, consumed.bytes_consumed); |
698 EXPECT_FALSE(generator_.HasQueuedFrames()); | 860 EXPECT_FALSE(generator_.HasQueuedFrames()); |
699 | 861 |
700 // Verify that two FEC packets were sent. | 862 // Verify that packets sent were 3 data and 1 FEC. |
701 CheckPacketHasSingleStreamFrame(packet2_); | 863 CheckPacketHasSingleStreamFrame(packet2_); |
702 CheckPacketHasSingleStreamFrame(packet3_); | 864 CheckPacketHasSingleStreamFrame(packet3_); |
703 CheckPacketIsFec(packet4_, /*fec_group=*/2u); | 865 CheckPacketIsFec(packet4_, /*fec_group=*/2u); |
704 CheckPacketHasSingleStreamFrame(packet5_); | 866 CheckPacketHasSingleStreamFrame(packet5_); |
705 CheckPacketIsFec(packet6_, /*fec_group=*/5u); // Sent at the end of stream. | 867 |
| 868 // Calling OnFecTimeout should emit the pending FEC packet. |
| 869 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet6_)); |
| 870 generator_.OnFecTimeout(); |
| 871 CheckPacketIsFec(packet6_, /*fec_group=*/5u); |
706 | 872 |
707 // Send one unprotected data packet. | 873 // Send one unprotected data packet. |
708 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 874 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
709 SaveArg<0>(&packet7_)); | 875 SaveArg<0>(&packet7_)); |
710 consumed = generator_.ConsumeData(7, CreateData(1u), 0, true, MAY_FEC_PROTECT, | 876 consumed = generator_.ConsumeData(7, CreateData(1u), 0, true, MAY_FEC_PROTECT, |
711 nullptr); | 877 nullptr); |
712 EXPECT_EQ(1u, consumed.bytes_consumed); | 878 EXPECT_EQ(1u, consumed.bytes_consumed); |
713 EXPECT_FALSE(generator_.HasQueuedFrames()); | 879 EXPECT_FALSE(generator_.HasQueuedFrames()); |
714 EXPECT_FALSE(creator_->IsFecProtected()); | 880 EXPECT_FALSE(creator_->IsFecProtected()); |
715 // Verify that one unprotected data packet was sent. | 881 // Verify that one unprotected data packet was sent. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
813 EXPECT_TRUE(creator_->IsFecProtected()); | 979 EXPECT_TRUE(creator_->IsFecProtected()); |
814 } | 980 } |
815 | 981 |
816 TEST_F(QuicPacketGeneratorTest, SwitchFecOnOffWithSubsequentPacketsProtected) { | 982 TEST_F(QuicPacketGeneratorTest, SwitchFecOnOffWithSubsequentPacketsProtected) { |
817 delegate_.SetCanWriteAnything(); | 983 delegate_.SetCanWriteAnything(); |
818 | 984 |
819 // Enable FEC. | 985 // Enable FEC. |
820 creator_->set_max_packets_per_fec_group(2); | 986 creator_->set_max_packets_per_fec_group(2); |
821 EXPECT_FALSE(creator_->IsFecProtected()); | 987 EXPECT_FALSE(creator_->IsFecProtected()); |
822 | 988 |
823 generator_.StartBatchOperations(); | |
824 // Send first packet, FEC protected. | 989 // Send first packet, FEC protected. |
825 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet_)); | 990 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce(SaveArg<0>(&packet_)); |
826 // Write enough data to cause a packet to be emitted. | 991 QuicConsumedData consumed = generator_.ConsumeData(5, CreateData(1u), 0, true, |
827 size_t data_len = kDefaultMaxPacketSize; | 992 MUST_FEC_PROTECT, nullptr); |
828 QuicConsumedData consumed = generator_.ConsumeData( | 993 EXPECT_EQ(1u, consumed.bytes_consumed); |
829 5, CreateData(data_len), 0, true, MUST_FEC_PROTECT, nullptr); | |
830 EXPECT_EQ(data_len, consumed.bytes_consumed); | |
831 PacketContents contents; | 994 PacketContents contents; |
832 contents.num_stream_frames = 1u; | 995 contents.num_stream_frames = 1u; |
833 contents.fec_group = 1u; | 996 contents.fec_group = 1u; |
834 CheckPacketContains(contents, packet_); | 997 CheckPacketContains(contents, packet_); |
835 | 998 |
836 // FEC should still be on in creator. | 999 // FEC should still be on in creator. |
837 EXPECT_TRUE(creator_->IsFecProtected()); | 1000 EXPECT_TRUE(creator_->IsFecProtected()); |
838 | 1001 |
839 // Send enough unprotected data to cause second packet to be sent, which gets | 1002 // Send unprotected data to cause second packet to be sent, which gets |
840 // protected because it happens to fall within an open FEC group. Data packet | 1003 // protected because it happens to fall within an open FEC group. Data packet |
841 // will be followed by FEC packet. | 1004 // will be followed by FEC packet. |
842 { | 1005 { |
843 InSequence dummy; | 1006 InSequence dummy; |
844 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 1007 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
845 SaveArg<0>(&packet2_)); | 1008 SaveArg<0>(&packet2_)); |
846 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 1009 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
847 SaveArg<0>(&packet3_)); | 1010 SaveArg<0>(&packet3_)); |
848 } | 1011 } |
849 consumed = generator_.ConsumeData(5, CreateData(data_len), 0, true, | 1012 consumed = generator_.ConsumeData(5, CreateData(1u), 0, true, MAY_FEC_PROTECT, |
850 MAY_FEC_PROTECT, nullptr); | 1013 nullptr); |
851 EXPECT_EQ(data_len, consumed.bytes_consumed); | 1014 EXPECT_EQ(1u, consumed.bytes_consumed); |
852 contents.num_stream_frames = 2u; | 1015 contents.num_stream_frames = 1u; |
853 CheckPacketContains(contents, packet2_); | 1016 CheckPacketContains(contents, packet2_); |
854 CheckPacketIsFec(packet3_, /*fec_group=*/1u); | 1017 CheckPacketIsFec(packet3_, /*fec_group=*/1u); |
855 | 1018 |
856 // FEC protection should be off in creator. | 1019 // FEC protection should be off in creator. |
857 EXPECT_FALSE(creator_->IsFecProtected()); | 1020 EXPECT_FALSE(creator_->IsFecProtected()); |
858 } | 1021 } |
859 | 1022 |
860 TEST_F(QuicPacketGeneratorTest, SwitchFecOnOffThenOnWithCreatorProtectionOn) { | 1023 TEST_F(QuicPacketGeneratorTest, SwitchFecOnOffThenOnWithCreatorProtectionOn) { |
861 delegate_.SetCanWriteAnything(); | 1024 delegate_.SetCanWriteAnything(); |
862 generator_.StartBatchOperations(); | 1025 generator_.StartBatchOperations(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 delegate_.SetCanNotWrite(); | 1071 delegate_.SetCanNotWrite(); |
909 | 1072 |
910 generator_.SetShouldSendAck(true, false); | 1073 generator_.SetShouldSendAck(true, false); |
911 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame())); | 1074 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame())); |
912 EXPECT_TRUE(generator_.HasQueuedFrames()); | 1075 EXPECT_TRUE(generator_.HasQueuedFrames()); |
913 | 1076 |
914 delegate_.SetCanWriteAnything(); | 1077 delegate_.SetCanWriteAnything(); |
915 | 1078 |
916 generator_.StartBatchOperations(); | 1079 generator_.StartBatchOperations(); |
917 | 1080 |
918 // When the first write operation is invoked, the ack and feedback | 1081 // When the first write operation is invoked, the ack and feedback frames will |
919 // frames will be returned. | 1082 // be returned. |
920 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame())); | 1083 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame())); |
921 EXPECT_CALL(delegate_, CreateFeedbackFrame()).WillOnce( | 1084 EXPECT_CALL(delegate_, CreateFeedbackFrame()).WillOnce( |
922 Return(CreateFeedbackFrame())); | 1085 Return(CreateFeedbackFrame())); |
923 | 1086 |
924 // Send some data and a control frame | 1087 // Send some data and a control frame |
925 generator_.ConsumeData(3, MakeIOVector("quux"), 7, false, MAY_FEC_PROTECT, | 1088 generator_.ConsumeData(3, MakeIOVector("quux"), 7, false, MAY_FEC_PROTECT, |
926 nullptr); | 1089 nullptr); |
927 generator_.AddControlFrame(QuicFrame(CreateGoAwayFrame())); | 1090 generator_.AddControlFrame(QuicFrame(CreateGoAwayFrame())); |
928 | 1091 |
929 // All five frames will be flushed out in a single packet. | 1092 // All five frames will be flushed out in a single packet. |
(...skipping 14 matching lines...) Expand all Loading... |
944 delegate_.SetCanNotWrite(); | 1107 delegate_.SetCanNotWrite(); |
945 | 1108 |
946 generator_.SetShouldSendAck(true, false); | 1109 generator_.SetShouldSendAck(true, false); |
947 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame())); | 1110 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame())); |
948 EXPECT_TRUE(generator_.HasQueuedFrames()); | 1111 EXPECT_TRUE(generator_.HasQueuedFrames()); |
949 | 1112 |
950 delegate_.SetCanWriteAnything(); | 1113 delegate_.SetCanWriteAnything(); |
951 | 1114 |
952 generator_.StartBatchOperations(); | 1115 generator_.StartBatchOperations(); |
953 | 1116 |
954 // When the first write operation is invoked, the ack and feedback | 1117 // When the first write operation is invoked, the ack and feedback frames will |
955 // frames will be returned. | 1118 // be returned. |
956 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame())); | 1119 EXPECT_CALL(delegate_, CreateAckFrame()).WillOnce(Return(CreateAckFrame())); |
957 EXPECT_CALL(delegate_, CreateFeedbackFrame()).WillOnce( | 1120 EXPECT_CALL(delegate_, CreateFeedbackFrame()).WillOnce( |
958 Return(CreateFeedbackFrame())); | 1121 Return(CreateFeedbackFrame())); |
959 | 1122 |
960 { | 1123 { |
961 InSequence dummy; | 1124 InSequence dummy; |
962 // All five frames will be flushed out in a single packet | 1125 // All five frames will be flushed out in a single packet |
963 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 1126 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
964 SaveArg<0>(&packet_)); | 1127 SaveArg<0>(&packet_)); |
965 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( | 1128 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 generator_.SetConnectionIdLength(7); | 1173 generator_.SetConnectionIdLength(7); |
1011 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, creator_->connection_id_length()); | 1174 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, creator_->connection_id_length()); |
1012 generator_.SetConnectionIdLength(8); | 1175 generator_.SetConnectionIdLength(8); |
1013 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, creator_->connection_id_length()); | 1176 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, creator_->connection_id_length()); |
1014 generator_.SetConnectionIdLength(9); | 1177 generator_.SetConnectionIdLength(9); |
1015 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, creator_->connection_id_length()); | 1178 EXPECT_EQ(PACKET_8BYTE_CONNECTION_ID, creator_->connection_id_length()); |
1016 } | 1179 } |
1017 | 1180 |
1018 } // namespace test | 1181 } // namespace test |
1019 } // namespace net | 1182 } // namespace net |
OLD | NEW |