| 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_stream.h" | 5 #include "net/quic/core/quic_stream.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "net/quic/core/quic_connection.h" | 9 #include "net/quic/core/quic_connection.h" |
| 10 #include "net/quic/core/quic_utils.h" | 10 #include "net/quic/core/quic_utils.h" |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 // Send data and FIN for the response. | 707 // Send data and FIN for the response. |
| 708 stream_->WriteOrBufferData(kData1, false, nullptr); | 708 stream_->WriteOrBufferData(kData1, false, nullptr); |
| 709 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_)); | 709 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_)); |
| 710 // Receive remaining data and FIN for the request. | 710 // Receive remaining data and FIN for the request. |
| 711 QuicStreamFrame frame2(stream_->id(), true, 0, QuicStringPiece("End")); | 711 QuicStreamFrame frame2(stream_->id(), true, 0, QuicStringPiece("End")); |
| 712 stream_->OnStreamFrame(frame2); | 712 stream_->OnStreamFrame(frame2); |
| 713 EXPECT_TRUE(stream_->fin_received()); | 713 EXPECT_TRUE(stream_->fin_received()); |
| 714 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); | 714 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); |
| 715 } | 715 } |
| 716 | 716 |
| 717 TEST_F(QuicStreamTest, StreamWaitsForAcks) { |
| 718 Initialize(kShouldProcessData); |
| 719 if (!session_->use_stream_notifier()) { |
| 720 return; |
| 721 } |
| 722 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| 723 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); |
| 724 // Stream is not waiting for acks initially. |
| 725 EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 726 |
| 727 // Send kData1. |
| 728 stream_->WriteOrBufferData(kData1, false, nullptr); |
| 729 EXPECT_TRUE(stream_->IsWaitingForAcks()); |
| 730 QuicStreamFrame frame1(stream_->id(), false, 0, kData1); |
| 731 stream_->OnStreamFrameAcked(frame1, QuicTime::Delta::Zero()); |
| 732 // Stream is not waiting for acks as all sent data is acked. |
| 733 EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 734 |
| 735 // Send kData2. |
| 736 stream_->WriteOrBufferData(kData2, false, nullptr); |
| 737 EXPECT_TRUE(stream_->IsWaitingForAcks()); |
| 738 // Send FIN. |
| 739 stream_->WriteOrBufferData("", true, nullptr); |
| 740 |
| 741 // kData2 is acked. |
| 742 QuicStreamFrame frame2(stream_->id(), false, 9, kData2); |
| 743 stream_->OnStreamFrameAcked(frame2, QuicTime::Delta::Zero()); |
| 744 // Stream is waiting for acks as FIN is not acked. |
| 745 EXPECT_TRUE(stream_->IsWaitingForAcks()); |
| 746 |
| 747 // FIN is acked. |
| 748 QuicStreamFrame frame3(stream_->id(), true, 18, ""); |
| 749 stream_->OnStreamFrameAcked(frame3, QuicTime::Delta::Zero()); |
| 750 EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 751 } |
| 752 |
| 753 TEST_F(QuicStreamTest, CancelStream) { |
| 754 Initialize(kShouldProcessData); |
| 755 if (!session_->use_stream_notifier()) { |
| 756 return; |
| 757 } |
| 758 |
| 759 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| 760 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); |
| 761 EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 762 |
| 763 stream_->WriteOrBufferData(kData1, false, nullptr); |
| 764 EXPECT_TRUE(stream_->IsWaitingForAcks()); |
| 765 // Cancel stream. |
| 766 stream_->Reset(QUIC_STREAM_NO_ERROR); |
| 767 // stream still waits for acks as the error code is QUIC_STREAM_NO_ERROR, and |
| 768 // data is going to be retransmitted. |
| 769 EXPECT_TRUE(stream_->IsWaitingForAcks()); |
| 770 stream_->Reset(QUIC_STREAM_CANCELLED); |
| 771 // Stream stops waiting for acks as data is not going to be retransmitted. |
| 772 EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 773 } |
| 774 |
| 775 TEST_F(QuicStreamTest, RstFrameReceivedStreamNotFinishSending) { |
| 776 Initialize(kShouldProcessData); |
| 777 if (!session_->use_stream_notifier()) { |
| 778 return; |
| 779 } |
| 780 |
| 781 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| 782 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); |
| 783 EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 784 |
| 785 stream_->WriteOrBufferData(kData1, false, nullptr); |
| 786 EXPECT_TRUE(stream_->IsWaitingForAcks()); |
| 787 |
| 788 // RST_STREAM received. |
| 789 QuicRstStreamFrame rst_frame(stream_->id(), QUIC_STREAM_CANCELLED, 1234); |
| 790 stream_->OnStreamReset(rst_frame); |
| 791 // Stream stops waiting for acks as it does not finish sending and rst is |
| 792 // sent. |
| 793 EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 794 } |
| 795 |
| 796 TEST_F(QuicStreamTest, RstFrameReceivedStreamFinishSending) { |
| 797 Initialize(kShouldProcessData); |
| 798 if (!session_->use_stream_notifier()) { |
| 799 return; |
| 800 } |
| 801 |
| 802 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| 803 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); |
| 804 EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 805 |
| 806 stream_->WriteOrBufferData(kData1, true, nullptr); |
| 807 EXPECT_TRUE(stream_->IsWaitingForAcks()); |
| 808 |
| 809 // RST_STREAM received. |
| 810 QuicRstStreamFrame rst_frame(stream_->id(), QUIC_STREAM_CANCELLED, 1234); |
| 811 stream_->OnStreamReset(rst_frame); |
| 812 // Stream stops waiting for acks as it has unacked data. |
| 813 EXPECT_TRUE(stream_->IsWaitingForAcks()); |
| 814 } |
| 815 |
| 816 TEST_F(QuicStreamTest, ConnectionClosed) { |
| 817 Initialize(kShouldProcessData); |
| 818 if (!session_->use_stream_notifier()) { |
| 819 return; |
| 820 } |
| 821 |
| 822 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| 823 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); |
| 824 EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 825 |
| 826 stream_->WriteOrBufferData(kData1, false, nullptr); |
| 827 EXPECT_TRUE(stream_->IsWaitingForAcks()); |
| 828 |
| 829 stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR, |
| 830 ConnectionCloseSource::FROM_SELF); |
| 831 // Stream stops waiting for acks as connection is going to close. |
| 832 EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 833 } |
| 834 |
| 717 } // namespace | 835 } // namespace |
| 718 } // namespace test | 836 } // namespace test |
| 719 } // namespace net | 837 } // namespace net |
| OLD | NEW |