| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 uint32_t ProcessRawData(const char* data, uint32_t data_len) { | 55 uint32_t ProcessRawData(const char* data, uint32_t data_len) { |
| 56 EXPECT_NE(0u, data_len); | 56 EXPECT_NE(0u, data_len); |
| 57 QUIC_DVLOG(1) << "ProcessData data_len: " << data_len; | 57 QUIC_DVLOG(1) << "ProcessData data_len: " << data_len; |
| 58 data_ += string(data, data_len); | 58 data_ += string(data, data_len); |
| 59 return should_process_data_ ? data_len : 0; | 59 return should_process_data_ ? data_len : 0; |
| 60 } | 60 } |
| 61 | 61 |
| 62 using QuicStream::WriteOrBufferData; | 62 using QuicStream::WriteOrBufferData; |
| 63 using QuicStream::CloseWriteSide; | 63 using QuicStream::CloseWriteSide; |
| 64 using QuicStream::OnClose; | 64 using QuicStream::OnClose; |
| 65 using QuicStream::SetIsDeletable; | |
| 66 | 65 |
| 67 private: | 66 private: |
| 68 bool should_process_data_; | 67 bool should_process_data_; |
| 69 string data_; | 68 string data_; |
| 70 }; | 69 }; |
| 71 | 70 |
| 72 class QuicStreamTest : public QuicTestWithParam<bool> { | 71 class QuicStreamTest : public QuicTestWithParam<bool> { |
| 73 public: | 72 public: |
| 74 QuicStreamTest() | 73 QuicStreamTest() |
| 75 : initial_flow_control_window_bytes_(kMaxPacketSize), | 74 : initial_flow_control_window_bytes_(kMaxPacketSize), |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 // Send data and FIN for the response. | 707 // Send data and FIN for the response. |
| 709 stream_->WriteOrBufferData(kData1, false, nullptr); | 708 stream_->WriteOrBufferData(kData1, false, nullptr); |
| 710 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_)); | 709 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_)); |
| 711 // Receive remaining data and FIN for the request. | 710 // Receive remaining data and FIN for the request. |
| 712 QuicStreamFrame frame2(stream_->id(), true, 0, QuicStringPiece("End")); | 711 QuicStreamFrame frame2(stream_->id(), true, 0, QuicStringPiece("End")); |
| 713 stream_->OnStreamFrame(frame2); | 712 stream_->OnStreamFrame(frame2); |
| 714 EXPECT_TRUE(stream_->fin_received()); | 713 EXPECT_TRUE(stream_->fin_received()); |
| 715 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); | 714 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); |
| 716 } | 715 } |
| 717 | 716 |
| 718 TEST_F(QuicStreamTest, StreamIsDeletable) { | 717 TEST_F(QuicStreamTest, StreamWaitsForAcks) { |
| 719 Initialize(kShouldProcessData); | 718 Initialize(kShouldProcessData); |
| 720 if (!session_->use_stream_notifier()) { | 719 if (!session_->use_stream_notifier()) { |
| 721 return; | 720 return; |
| 722 } | 721 } |
| 723 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) | 722 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| 724 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); | 723 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); |
| 725 // Stream is deletable initially. | 724 // Stream is not waiting for acks initially. |
| 726 EXPECT_TRUE(stream_->is_deletable()); | 725 EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 727 | 726 |
| 728 // Send kData1. | 727 // Send kData1. |
| 729 stream_->WriteOrBufferData(kData1, false, nullptr); | 728 stream_->WriteOrBufferData(kData1, false, nullptr); |
| 730 EXPECT_FALSE(stream_->is_deletable()); | 729 EXPECT_TRUE(stream_->IsWaitingForAcks()); |
| 731 QuicStreamFrame frame1(stream_->id(), false, 0, kData1); | 730 QuicStreamFrame frame1(stream_->id(), false, 0, kData1); |
| 732 stream_->OnStreamFrameAcked(frame1, QuicTime::Delta::Zero()); | 731 stream_->OnStreamFrameAcked(frame1, QuicTime::Delta::Zero()); |
| 733 // Stream is deletable as all sent data is acked. | 732 // Stream is not waiting for acks as all sent data is acked. |
| 734 EXPECT_TRUE(stream_->is_deletable()); | 733 EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 735 | 734 |
| 736 // Send kData2. | 735 // Send kData2. |
| 737 stream_->WriteOrBufferData(kData2, false, nullptr); | 736 stream_->WriteOrBufferData(kData2, false, nullptr); |
| 738 EXPECT_FALSE(stream_->is_deletable()); | 737 EXPECT_TRUE(stream_->IsWaitingForAcks()); |
| 739 // Send FIN. | 738 // Send FIN. |
| 740 stream_->WriteOrBufferData("", true, nullptr); | 739 stream_->WriteOrBufferData("", true, nullptr); |
| 741 | 740 |
| 742 // kData2 is acked. | 741 // kData2 is acked. |
| 743 QuicStreamFrame frame2(stream_->id(), false, 9, kData2); | 742 QuicStreamFrame frame2(stream_->id(), false, 9, kData2); |
| 744 stream_->OnStreamFrameAcked(frame2, QuicTime::Delta::Zero()); | 743 stream_->OnStreamFrameAcked(frame2, QuicTime::Delta::Zero()); |
| 745 // Stream is not deletable as FIN is not acked. | 744 // Stream is waiting for acks as FIN is not acked. |
| 746 EXPECT_FALSE(stream_->is_deletable()); | 745 EXPECT_TRUE(stream_->IsWaitingForAcks()); |
| 747 | 746 |
| 748 // FIN is acked. | 747 // FIN is acked. |
| 749 QuicStreamFrame frame3(stream_->id(), true, 18, ""); | 748 QuicStreamFrame frame3(stream_->id(), true, 18, ""); |
| 750 stream_->OnStreamFrameAcked(frame3, QuicTime::Delta::Zero()); | 749 stream_->OnStreamFrameAcked(frame3, QuicTime::Delta::Zero()); |
| 751 EXPECT_TRUE(stream_->is_deletable()); | 750 EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 752 } | 751 } |
| 753 | 752 |
| 754 TEST_F(QuicStreamTest, CancelStream) { | 753 TEST_F(QuicStreamTest, CancelStream) { |
| 755 Initialize(kShouldProcessData); | 754 Initialize(kShouldProcessData); |
| 756 if (!session_->use_stream_notifier()) { | 755 if (!session_->use_stream_notifier()) { |
| 757 return; | 756 return; |
| 758 } | 757 } |
| 759 | 758 |
| 760 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) | 759 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| 761 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); | 760 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); |
| 762 EXPECT_TRUE(stream_->is_deletable()); | 761 EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 763 | 762 |
| 764 stream_->WriteOrBufferData(kData1, false, nullptr); | 763 stream_->WriteOrBufferData(kData1, false, nullptr); |
| 765 EXPECT_FALSE(stream_->is_deletable()); | 764 EXPECT_TRUE(stream_->IsWaitingForAcks()); |
| 766 // Cancel stream. | 765 // Cancel stream. |
| 767 stream_->Reset(QUIC_STREAM_NO_ERROR); | 766 stream_->Reset(QUIC_STREAM_NO_ERROR); |
| 768 // stream is not deletable as the error code is QUIC_STREAM_NO_ERROR, and data | 767 // stream still waits for acks as the error code is QUIC_STREAM_NO_ERROR, and |
| 769 // is going to be retransmitted. | 768 // data is going to be retransmitted. |
| 770 EXPECT_FALSE(stream_->is_deletable()); | 769 EXPECT_TRUE(stream_->IsWaitingForAcks()); |
| 771 stream_->Reset(QUIC_STREAM_CANCELLED); | 770 stream_->Reset(QUIC_STREAM_CANCELLED); |
| 772 // Stream is deletable as data is not going to be retransmitted. | 771 // Stream stops waiting for acks as data is not going to be retransmitted. |
| 773 EXPECT_TRUE(stream_->is_deletable()); | 772 EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 774 } | 773 } |
| 775 | 774 |
| 776 TEST_F(QuicStreamTest, RstFrameReceived) { | 775 TEST_F(QuicStreamTest, RstFrameReceivedStreamNotFinishSending) { |
| 777 Initialize(kShouldProcessData); | 776 Initialize(kShouldProcessData); |
| 778 if (!session_->use_stream_notifier()) { | 777 if (!session_->use_stream_notifier()) { |
| 779 return; | 778 return; |
| 780 } | 779 } |
| 781 | 780 |
| 782 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) | 781 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| 783 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); | 782 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); |
| 784 EXPECT_TRUE(stream_->is_deletable()); | 783 EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 785 | 784 |
| 786 stream_->WriteOrBufferData(kData1, false, nullptr); | 785 stream_->WriteOrBufferData(kData1, false, nullptr); |
| 787 EXPECT_FALSE(stream_->is_deletable()); | 786 EXPECT_TRUE(stream_->IsWaitingForAcks()); |
| 788 | 787 |
| 789 // RST_STREAM received. | 788 // RST_STREAM received. |
| 790 QuicRstStreamFrame rst_frame(stream_->id(), QUIC_STREAM_CANCELLED, 1234); | 789 QuicRstStreamFrame rst_frame(stream_->id(), QUIC_STREAM_CANCELLED, 1234); |
| 791 stream_->OnStreamReset(rst_frame); | 790 stream_->OnStreamReset(rst_frame); |
| 792 // Stream is not deletable as it has outstanding data. | 791 // Stream stops waiting for acks as it does not finish sending and rst is |
| 793 EXPECT_FALSE(stream_->is_deletable()); | 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()); |
| 794 } | 814 } |
| 795 | 815 |
| 796 TEST_F(QuicStreamTest, ConnectionClosed) { | 816 TEST_F(QuicStreamTest, ConnectionClosed) { |
| 797 Initialize(kShouldProcessData); | 817 Initialize(kShouldProcessData); |
| 798 if (!session_->use_stream_notifier()) { | 818 if (!session_->use_stream_notifier()) { |
| 799 return; | 819 return; |
| 800 } | 820 } |
| 801 | 821 |
| 802 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) | 822 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| 803 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); | 823 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); |
| 804 EXPECT_TRUE(stream_->is_deletable()); | 824 EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 805 | 825 |
| 806 stream_->WriteOrBufferData(kData1, false, nullptr); | 826 stream_->WriteOrBufferData(kData1, false, nullptr); |
| 807 EXPECT_FALSE(stream_->is_deletable()); | 827 EXPECT_TRUE(stream_->IsWaitingForAcks()); |
| 808 | 828 |
| 809 stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR, | 829 stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR, |
| 810 ConnectionCloseSource::FROM_SELF); | 830 ConnectionCloseSource::FROM_SELF); |
| 811 // Stream is deletable as connection is closed. | 831 // Stream stops waiting for acks as connection is going to close. |
| 812 EXPECT_TRUE(stream_->is_deletable()); | 832 EXPECT_FALSE(stream_->IsWaitingForAcks()); |
| 813 } | 833 } |
| 814 | 834 |
| 815 } // namespace | 835 } // namespace |
| 816 } // namespace test | 836 } // namespace test |
| 817 } // namespace net | 837 } // namespace net |
| OLD | NEW |