| 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 22 matching lines...) Expand all Loading... |
| 33 MockDelegate() {} | 33 MockDelegate() {} |
| 34 virtual ~MockDelegate() {} | 34 virtual ~MockDelegate() {} |
| 35 | 35 |
| 36 MOCK_METHOD3(CanWrite, bool(Retransmission retransmission, | 36 MOCK_METHOD3(CanWrite, bool(Retransmission retransmission, |
| 37 HasRetransmittableData retransmittable, | 37 HasRetransmittableData retransmittable, |
| 38 IsHandshake handshake)); | 38 IsHandshake handshake)); |
| 39 | 39 |
| 40 MOCK_METHOD0(CreateAckFrame, QuicAckFrame*()); | 40 MOCK_METHOD0(CreateAckFrame, QuicAckFrame*()); |
| 41 MOCK_METHOD0(CreateFeedbackFrame, QuicCongestionFeedbackFrame*()); | 41 MOCK_METHOD0(CreateFeedbackFrame, QuicCongestionFeedbackFrame*()); |
| 42 MOCK_METHOD1(OnSerializedPacket, bool(const SerializedPacket& packet)); | 42 MOCK_METHOD1(OnSerializedPacket, bool(const SerializedPacket& packet)); |
| 43 MOCK_METHOD2(CloseConnection, void(QuicErrorCode, bool)); |
| 43 | 44 |
| 44 void SetCanWriteAnything() { | 45 void SetCanWriteAnything() { |
| 45 EXPECT_CALL(*this, CanWrite(NOT_RETRANSMISSION, _, _)) | 46 EXPECT_CALL(*this, CanWrite(NOT_RETRANSMISSION, _, _)) |
| 46 .WillRepeatedly(Return(true)); | 47 .WillRepeatedly(Return(true)); |
| 47 EXPECT_CALL(*this, CanWrite(NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA, _)) | 48 EXPECT_CALL(*this, CanWrite(NOT_RETRANSMISSION, NO_RETRANSMITTABLE_DATA, _)) |
| 48 .WillRepeatedly(Return(true)); | 49 .WillRepeatedly(Return(true)); |
| 49 } | 50 } |
| 50 | 51 |
| 51 void SetCanNotWrite() { | 52 void SetCanNotWrite() { |
| 52 EXPECT_CALL(*this, CanWrite(NOT_RETRANSMISSION, _, _)) | 53 EXPECT_CALL(*this, CanWrite(NOT_RETRANSMISSION, _, _)) |
| (...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 generator_.ConsumeData(3, CreateData(data_len), 0, true); | 449 generator_.ConsumeData(3, CreateData(data_len), 0, true); |
| 449 EXPECT_EQ(data_len, consumed.bytes_consumed); | 450 EXPECT_EQ(data_len, consumed.bytes_consumed); |
| 450 EXPECT_TRUE(consumed.fin_consumed); | 451 EXPECT_TRUE(consumed.fin_consumed); |
| 451 EXPECT_FALSE(generator_.HasQueuedFrames()); | 452 EXPECT_FALSE(generator_.HasQueuedFrames()); |
| 452 | 453 |
| 453 CheckPacketHasSingleStreamFrame(packet_); | 454 CheckPacketHasSingleStreamFrame(packet_); |
| 454 CheckPacketHasSingleStreamFrame(packet2_); | 455 CheckPacketHasSingleStreamFrame(packet2_); |
| 455 CheckPacketIsFec(packet3_, 1); | 456 CheckPacketIsFec(packet3_, 1); |
| 456 } | 457 } |
| 457 | 458 |
| 459 TEST_F(QuicPacketGeneratorTest, ConsumeData_FramesPreviouslyQueued) { |
| 460 // Set the packet size be enough for two stream frames with 0 stream offset, |
| 461 // but not enough for a stream frame of 0 offset and one with non-zero offset. |
| 462 creator_.options()->max_packet_length = |
| 463 NullEncrypter().GetCiphertextSize(0) + |
| 464 GetPacketHeaderSize(creator_.options()->send_guid_length, |
| 465 true, |
| 466 creator_.options()->send_sequence_number_length, |
| 467 NOT_IN_FEC_GROUP) + |
| 468 // Add an extra 3 bytes for the payload and 1 byte so BytesFree is larger |
| 469 // than the GetMinStreamFrameSize. |
| 470 QuicFramer::GetMinStreamFrameSize(framer_.version(), 1, 0, false) + 3 + |
| 471 QuicFramer::GetMinStreamFrameSize(framer_.version(), 1, 0, true) + 1; |
| 472 delegate_.SetCanWriteAnything(); |
| 473 { |
| 474 InSequence dummy; |
| 475 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
| 476 DoAll(SaveArg<0>(&packet_), Return(true))); |
| 477 EXPECT_CALL(delegate_, OnSerializedPacket(_)).WillOnce( |
| 478 DoAll(SaveArg<0>(&packet2_), Return(true))); |
| 479 } |
| 480 generator_.StartBatchOperations(); |
| 481 // Queue enough data to prevent a stream frame with a non-zero offset from |
| 482 // fitting. |
| 483 QuicConsumedData consumed = generator_.ConsumeData(1, "foo", 0, false); |
| 484 EXPECT_EQ(3u, consumed.bytes_consumed); |
| 485 EXPECT_FALSE(consumed.fin_consumed); |
| 486 EXPECT_TRUE(generator_.HasQueuedFrames()); |
| 487 |
| 488 // This frame will not fit with the existing frame, causing the queued frame |
| 489 // to be serialized, and it will not fit with another frame like it, so it is |
| 490 // serialized by itself. |
| 491 consumed = generator_.ConsumeData(1, "bar", 3, true); |
| 492 EXPECT_EQ(3u, consumed.bytes_consumed); |
| 493 EXPECT_TRUE(consumed.fin_consumed); |
| 494 EXPECT_FALSE(generator_.HasQueuedFrames()); |
| 495 |
| 496 PacketContents contents; |
| 497 contents.num_stream_frames = 1; |
| 498 CheckPacketContains(contents, packet_); |
| 499 CheckPacketContains(contents, packet2_); |
| 500 } |
| 501 |
| 458 TEST_F(QuicPacketGeneratorTest, NotWritableThenBatchOperations) { | 502 TEST_F(QuicPacketGeneratorTest, NotWritableThenBatchOperations) { |
| 459 delegate_.SetCanNotWrite(); | 503 delegate_.SetCanNotWrite(); |
| 460 | 504 |
| 461 generator_.SetShouldSendAck(true); | 505 generator_.SetShouldSendAck(true); |
| 462 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame())); | 506 generator_.AddControlFrame(QuicFrame(CreateRstStreamFrame())); |
| 463 EXPECT_TRUE(generator_.HasQueuedFrames()); | 507 EXPECT_TRUE(generator_.HasQueuedFrames()); |
| 464 | 508 |
| 465 delegate_.SetCanWriteAnything(); | 509 delegate_.SetCanWriteAnything(); |
| 466 | 510 |
| 467 generator_.StartBatchOperations(); | 511 generator_.StartBatchOperations(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 | 582 |
| 539 // The second should have the remainder of the stream data. | 583 // The second should have the remainder of the stream data. |
| 540 PacketContents contents2; | 584 PacketContents contents2; |
| 541 contents2.num_goaway_frames = 1; | 585 contents2.num_goaway_frames = 1; |
| 542 contents2.num_stream_frames = 1; | 586 contents2.num_stream_frames = 1; |
| 543 CheckPacketContains(contents2, packet2_); | 587 CheckPacketContains(contents2, packet2_); |
| 544 } | 588 } |
| 545 | 589 |
| 546 } // namespace test | 590 } // namespace test |
| 547 } // namespace net | 591 } // namespace net |
| OLD | NEW |