| 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/core/quic_packet_generator.h" | 5 #include "net/quic/core/quic_packet_generator.h" | 
| 6 | 6 | 
| 7 #include <cstdint> | 7 #include <cstdint> | 
| 8 #include <memory> | 8 #include <memory> | 
| 9 #include <string> | 9 #include <string> | 
| 10 | 10 | 
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 394   PacketContents contents; | 394   PacketContents contents; | 
| 395   contents.num_stream_frames = 1; | 395   contents.num_stream_frames = 1; | 
| 396   CheckPacketContains(contents, 0); | 396   CheckPacketContains(contents, 0); | 
| 397 | 397 | 
| 398   ASSERT_EQ(1u, packets_.size()); | 398   ASSERT_EQ(1u, packets_.size()); | 
| 399   ASSERT_EQ(kDefaultMaxPacketSize, generator_.GetCurrentMaxPacketLength()); | 399   ASSERT_EQ(kDefaultMaxPacketSize, generator_.GetCurrentMaxPacketLength()); | 
| 400   EXPECT_EQ(kDefaultMaxPacketSize, packets_[0].encrypted_length); | 400   EXPECT_EQ(kDefaultMaxPacketSize, packets_[0].encrypted_length); | 
| 401 } | 401 } | 
| 402 | 402 | 
| 403 TEST_F(QuicPacketGeneratorTest, ConsumeData_EmptyData) { | 403 TEST_F(QuicPacketGeneratorTest, ConsumeData_EmptyData) { | 
| 404   EXPECT_DFATAL(generator_.ConsumeData(kHeadersStreamId, MakeIOVector(""), 0, | 404   EXPECT_QUIC_BUG(generator_.ConsumeData(kHeadersStreamId, MakeIOVector(""), 0, | 
| 405                                        false, nullptr), | 405                                          false, nullptr), | 
| 406                 "Attempt to consume empty data without FIN."); | 406                   "Attempt to consume empty data without FIN."); | 
| 407 } | 407 } | 
| 408 | 408 | 
| 409 TEST_F(QuicPacketGeneratorTest, | 409 TEST_F(QuicPacketGeneratorTest, | 
| 410        ConsumeDataMultipleTimes_WritableAndShouldNotFlush) { | 410        ConsumeDataMultipleTimes_WritableAndShouldNotFlush) { | 
| 411   delegate_.SetCanWriteAnything(); | 411   delegate_.SetCanWriteAnything(); | 
| 412   generator_.StartBatchOperations(); | 412   generator_.StartBatchOperations(); | 
| 413 | 413 | 
| 414   generator_.ConsumeData(kHeadersStreamId, MakeIOVector("foo"), 2, true, | 414   generator_.ConsumeData(kHeadersStreamId, MakeIOVector("foo"), 2, true, | 
| 415                          nullptr); | 415                          nullptr); | 
| 416   QuicConsumedData consumed = | 416   QuicConsumedData consumed = | 
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 835       .WillOnce(Return(QuicFrame(&ack_frame_))); | 835       .WillOnce(Return(QuicFrame(&ack_frame_))); | 
| 836   EXPECT_CALL(delegate_, PopulateStopWaitingFrame(_)); | 836   EXPECT_CALL(delegate_, PopulateStopWaitingFrame(_)); | 
| 837   // Generator should have queued control frames, and creator should be empty. | 837   // Generator should have queued control frames, and creator should be empty. | 
| 838   EXPECT_TRUE(generator_.HasQueuedFrames()); | 838   EXPECT_TRUE(generator_.HasQueuedFrames()); | 
| 839   EXPECT_FALSE(creator_->HasPendingFrames()); | 839   EXPECT_FALSE(creator_->HasPendingFrames()); | 
| 840 | 840 | 
| 841   // This will not serialize any packets, because of the invalid frame. | 841   // This will not serialize any packets, because of the invalid frame. | 
| 842   EXPECT_CALL(delegate_, | 842   EXPECT_CALL(delegate_, | 
| 843               OnUnrecoverableError(QUIC_FAILED_TO_SERIALIZE_PACKET, _, | 843               OnUnrecoverableError(QUIC_FAILED_TO_SERIALIZE_PACKET, _, | 
| 844                                    ConnectionCloseSource::FROM_SELF)); | 844                                    ConnectionCloseSource::FROM_SELF)); | 
| 845   EXPECT_DFATAL(generator_.FinishBatchOperations(), | 845   EXPECT_QUIC_BUG(generator_.FinishBatchOperations(), | 
| 846                 "packet_number_length 1 is too small " | 846                   "packet_number_length 1 is too small " | 
| 847                 "for least_unacked_delta: 1001"); | 847                   "for least_unacked_delta: 1001"); | 
| 848 } | 848 } | 
| 849 | 849 | 
| 850 TEST_F(QuicPacketGeneratorTest, SetCurrentPath) { | 850 TEST_F(QuicPacketGeneratorTest, SetCurrentPath) { | 
| 851   delegate_.SetCanWriteAnything(); | 851   delegate_.SetCanWriteAnything(); | 
| 852   generator_.StartBatchOperations(); | 852   generator_.StartBatchOperations(); | 
| 853 | 853 | 
| 854   QuicConsumedData consumed = generator_.ConsumeData( | 854   QuicConsumedData consumed = generator_.ConsumeData( | 
| 855       kHeadersStreamId, MakeIOVector("foo"), 2, true, nullptr); | 855       kHeadersStreamId, MakeIOVector("foo"), 2, true, nullptr); | 
| 856   EXPECT_EQ(3u, consumed.bytes_consumed); | 856   EXPECT_EQ(3u, consumed.bytes_consumed); | 
| 857   EXPECT_TRUE(consumed.fin_consumed); | 857   EXPECT_TRUE(consumed.fin_consumed); | 
| 858   EXPECT_TRUE(generator_.HasQueuedFrames()); | 858   EXPECT_TRUE(generator_.HasQueuedFrames()); | 
| 859   EXPECT_EQ(kDefaultPathId, QuicPacketCreatorPeer::GetCurrentPath(creator_)); | 859   EXPECT_EQ(kDefaultPathId, QuicPacketCreatorPeer::GetCurrentPath(creator_)); | 
| 860   // Does not change current path. | 860   // Does not change current path. | 
| 861   generator_.SetCurrentPath(kDefaultPathId, 1, 0); | 861   generator_.SetCurrentPath(kDefaultPathId, 1, 0); | 
| 862   EXPECT_EQ(kDefaultPathId, QuicPacketCreatorPeer::GetCurrentPath(creator_)); | 862   EXPECT_EQ(kDefaultPathId, QuicPacketCreatorPeer::GetCurrentPath(creator_)); | 
| 863 | 863 | 
| 864   // Try to switch path when a packet is under construction. | 864   // Try to switch path when a packet is under construction. | 
| 865   QuicPathId kTestPathId1 = 1; | 865   QuicPathId kTestPathId1 = 1; | 
| 866   EXPECT_DFATAL(generator_.SetCurrentPath(kTestPathId1, 1, 0), | 866   EXPECT_QUIC_BUG(generator_.SetCurrentPath(kTestPathId1, 1, 0), | 
| 867                 "Unable to change paths when a packet is under construction"); | 867                   "Unable to change paths when a packet is under construction"); | 
| 868   EXPECT_EQ(kDefaultPathId, QuicPacketCreatorPeer::GetCurrentPath(creator_)); | 868   EXPECT_EQ(kDefaultPathId, QuicPacketCreatorPeer::GetCurrentPath(creator_)); | 
| 869 | 869 | 
| 870   // Try to switch path after current open packet gets serialized. | 870   // Try to switch path after current open packet gets serialized. | 
| 871   EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 871   EXPECT_CALL(delegate_, OnSerializedPacket(_)) | 
| 872       .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); | 872       .WillOnce(Invoke(this, &QuicPacketGeneratorTest::SavePacket)); | 
| 873   generator_.FlushAllQueuedFrames(); | 873   generator_.FlushAllQueuedFrames(); | 
| 874   EXPECT_FALSE(generator_.HasQueuedFrames()); | 874   EXPECT_FALSE(generator_.HasQueuedFrames()); | 
| 875   generator_.SetCurrentPath(kTestPathId1, 1, 0); | 875   generator_.SetCurrentPath(kTestPathId1, 1, 0); | 
| 876   EXPECT_EQ(kTestPathId1, QuicPacketCreatorPeer::GetCurrentPath(creator_)); | 876   EXPECT_EQ(kTestPathId1, QuicPacketCreatorPeer::GetCurrentPath(creator_)); | 
| 877 } | 877 } | 
| 878 | 878 | 
| 879 }  // namespace test | 879 }  // namespace test | 
| 880 }  // namespace net | 880 }  // namespace net | 
| OLD | NEW | 
|---|