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

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

Issue 1777423002: Remove max_packet_length from QuicPacketGenerator, because it is no longer necessary with FEC gone.… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@116277228
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_packet_generator.cc ('k') | 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_generator.h" 5 #include "net/quic/quic_packet_generator.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "net/quic/crypto/crypto_protocol.h" 10 #include "net/quic/crypto/crypto_protocol.h"
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 QuicConsumedData consumed = generator_.ConsumeData( 383 QuicConsumedData consumed = generator_.ConsumeData(
384 kCryptoStreamId, MakeIOVector("foo"), 0, false, nullptr); 384 kCryptoStreamId, MakeIOVector("foo"), 0, false, nullptr);
385 EXPECT_EQ(3u, consumed.bytes_consumed); 385 EXPECT_EQ(3u, consumed.bytes_consumed);
386 EXPECT_FALSE(generator_.HasQueuedFrames()); 386 EXPECT_FALSE(generator_.HasQueuedFrames());
387 387
388 PacketContents contents; 388 PacketContents contents;
389 contents.num_stream_frames = 1; 389 contents.num_stream_frames = 1;
390 CheckPacketContains(contents, 0); 390 CheckPacketContains(contents, 0);
391 391
392 ASSERT_EQ(1u, packets_.size()); 392 ASSERT_EQ(1u, packets_.size());
393 ASSERT_EQ(kDefaultMaxPacketSize, generator_.GetMaxPacketLength()); 393 ASSERT_EQ(kDefaultMaxPacketSize, generator_.GetCurrentMaxPacketLength());
394 EXPECT_EQ(kDefaultMaxPacketSize, packets_[0].encrypted_length); 394 EXPECT_EQ(kDefaultMaxPacketSize, packets_[0].encrypted_length);
395 } 395 }
396 396
397 TEST_F(QuicPacketGeneratorTest, ConsumeData_EmptyData) { 397 TEST_F(QuicPacketGeneratorTest, ConsumeData_EmptyData) {
398 EXPECT_DFATAL(generator_.ConsumeData(kHeadersStreamId, MakeIOVector(""), 0, 398 EXPECT_DFATAL(generator_.ConsumeData(kHeadersStreamId, MakeIOVector(""), 0,
399 false, nullptr), 399 false, nullptr),
400 "Attempt to consume empty data without FIN."); 400 "Attempt to consume empty data without FIN.");
401 } 401 }
402 402
403 TEST_F(QuicPacketGeneratorTest, 403 TEST_F(QuicPacketGeneratorTest,
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 EXPECT_FALSE(generator_.HasQueuedFrames()); 661 EXPECT_FALSE(generator_.HasQueuedFrames());
662 662
663 // We expect first data chunk to get fragmented, but the second one to fit 663 // We expect first data chunk to get fragmented, but the second one to fit
664 // into a single packet. 664 // into a single packet.
665 ASSERT_EQ(3u, packets_.size()); 665 ASSERT_EQ(3u, packets_.size());
666 EXPECT_EQ(kDefaultMaxPacketSize, packets_[0].encrypted_length); 666 EXPECT_EQ(kDefaultMaxPacketSize, packets_[0].encrypted_length);
667 EXPECT_LE(kDefaultMaxPacketSize, packets_[2].encrypted_length); 667 EXPECT_LE(kDefaultMaxPacketSize, packets_[2].encrypted_length);
668 CheckAllPacketsHaveSingleStreamFrame(); 668 CheckAllPacketsHaveSingleStreamFrame();
669 } 669 }
670 670
671 // Test whether SetMaxPacketLength() works correctly when we change the packet
672 // size in the middle of the batched packet.
673 TEST_F(QuicPacketGeneratorTest, SetMaxPacketLength_Midpacket) {
674 delegate_.SetCanWriteAnything();
675 generator_.StartBatchOperations();
676
677 size_t first_write_len = kDefaultMaxPacketSize / 2;
678 size_t second_write_len = kDefaultMaxPacketSize;
679 size_t packet_len = kDefaultMaxPacketSize + 100;
680 ASSERT_LE(packet_len, kMaxPacketSize);
681
682 // First send half of the packet worth of data. We are in the batch mode, so
683 // should not cause packet serialization.
684 QuicConsumedData consumed =
685 generator_.ConsumeData(kHeadersStreamId, CreateData(first_write_len),
686 /*offset=*/2,
687 /*fin=*/false, nullptr);
688 EXPECT_EQ(first_write_len, consumed.bytes_consumed);
689 EXPECT_FALSE(consumed.fin_consumed);
690 EXPECT_TRUE(generator_.HasQueuedFrames());
691
692 // Make sure we have no packets so far.
693 ASSERT_EQ(0u, packets_.size());
694
695 // Increase packet size. Ensure it's not immediately enacted.
696 generator_.SetMaxPacketLength(packet_len);
697 EXPECT_EQ(packet_len, generator_.GetMaxPacketLength());
698 EXPECT_EQ(kDefaultMaxPacketSize, generator_.GetCurrentMaxPacketLength());
699
700 // We expect to see exactly one packet serialized after that, since we are in
701 // batch mode and we have sent approximately 3/2 of our MTU.
702 EXPECT_CALL(delegate_, OnSerializedPacket(_))
703 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket));
704
705 // Send a packet worth of data to the same stream. This should trigger
706 // serialization of other packet.
707 consumed =
708 generator_.ConsumeData(kHeadersStreamId, CreateData(second_write_len),
709 /*offset=*/2 + first_write_len,
710 /*fin=*/true, nullptr);
711 EXPECT_EQ(second_write_len, consumed.bytes_consumed);
712 EXPECT_TRUE(consumed.fin_consumed);
713 EXPECT_TRUE(generator_.HasQueuedFrames());
714
715 // We expect the first packet to contain two frames, and to not reflect the
716 // packet size change.
717 ASSERT_EQ(1u, packets_.size());
718 EXPECT_EQ(kDefaultMaxPacketSize, packets_[0].encrypted_length);
719
720 PacketContents contents;
721 contents.num_stream_frames = 2;
722 CheckPacketContains(contents, 0);
723 }
724
725 // Test whether SetMaxPacketLength() works correctly when we force the change of 671 // Test whether SetMaxPacketLength() works correctly when we force the change of
726 // the packet size in the middle of the batched packet. 672 // the packet size in the middle of the batched packet.
727 TEST_F(QuicPacketGeneratorTest, SetMaxPacketLength_MidpacketFlush) { 673 TEST_F(QuicPacketGeneratorTest, SetMaxPacketLength_MidpacketFlush) {
728 delegate_.SetCanWriteAnything(); 674 delegate_.SetCanWriteAnything();
729 generator_.StartBatchOperations(); 675 generator_.StartBatchOperations();
730 676
731 size_t first_write_len = kDefaultMaxPacketSize / 2; 677 size_t first_write_len = kDefaultMaxPacketSize / 2;
732 size_t packet_len = kDefaultMaxPacketSize + 100; 678 size_t packet_len = kDefaultMaxPacketSize + 100;
733 size_t second_write_len = packet_len + 1; 679 size_t second_write_len = packet_len + 1;
734 ASSERT_LE(packet_len, kMaxPacketSize); 680 ASSERT_LE(packet_len, kMaxPacketSize);
(...skipping 12 matching lines...) Expand all
747 ASSERT_EQ(0u, packets_.size()); 693 ASSERT_EQ(0u, packets_.size());
748 694
749 // Expect a packet to be flushed. 695 // Expect a packet to be flushed.
750 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 696 EXPECT_CALL(delegate_, OnSerializedPacket(_))
751 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); 697 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket));
752 698
753 // Increase packet size after flushing all frames. 699 // Increase packet size after flushing all frames.
754 // Ensure it's immediately enacted. 700 // Ensure it's immediately enacted.
755 generator_.FlushAllQueuedFrames(); 701 generator_.FlushAllQueuedFrames();
756 generator_.SetMaxPacketLength(packet_len); 702 generator_.SetMaxPacketLength(packet_len);
757 EXPECT_EQ(packet_len, generator_.GetMaxPacketLength());
758 EXPECT_EQ(packet_len, generator_.GetCurrentMaxPacketLength()); 703 EXPECT_EQ(packet_len, generator_.GetCurrentMaxPacketLength());
759 EXPECT_FALSE(generator_.HasQueuedFrames()); 704 EXPECT_FALSE(generator_.HasQueuedFrames());
760 705
761 // We expect to see exactly one packet serialized after that, because we send 706 // We expect to see exactly one packet serialized after that, because we send
762 // a value somewhat exceeding new max packet size, and the tail data does not 707 // a value somewhat exceeding new max packet size, and the tail data does not
763 // get serialized because we are still in the batch mode. 708 // get serialized because we are still in the batch mode.
764 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 709 EXPECT_CALL(delegate_, OnSerializedPacket(_))
765 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); 710 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket));
766 711
767 // Send a more than a packet worth of data to the same stream. This should 712 // Send a more than a packet worth of data to the same stream. This should
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 EXPECT_CALL(delegate_, OnSerializedPacket(_)) 856 EXPECT_CALL(delegate_, OnSerializedPacket(_))
912 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); 857 .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket));
913 generator_.FlushAllQueuedFrames(); 858 generator_.FlushAllQueuedFrames();
914 EXPECT_FALSE(generator_.HasQueuedFrames()); 859 EXPECT_FALSE(generator_.HasQueuedFrames());
915 generator_.SetCurrentPath(kTestPathId1, 1, 0); 860 generator_.SetCurrentPath(kTestPathId1, 1, 0);
916 EXPECT_EQ(kTestPathId1, QuicPacketCreatorPeer::GetCurrentPath(creator_)); 861 EXPECT_EQ(kTestPathId1, QuicPacketCreatorPeer::GetCurrentPath(creator_));
917 } 862 }
918 863
919 } // namespace test 864 } // namespace test
920 } // namespace net 865 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_packet_generator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698