| 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; |
| 65 | 66 |
| 66 private: | 67 private: |
| 67 bool should_process_data_; | 68 bool should_process_data_; |
| 68 string data_; | 69 string data_; |
| 69 }; | 70 }; |
| 70 | 71 |
| 71 class QuicStreamTest : public QuicTestWithParam<bool> { | 72 class QuicStreamTest : public QuicTestWithParam<bool> { |
| 72 public: | 73 public: |
| 73 QuicStreamTest() | 74 QuicStreamTest() |
| 74 : initial_flow_control_window_bytes_(kMaxPacketSize), | 75 : initial_flow_control_window_bytes_(kMaxPacketSize), |
| (...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 // Send data and FIN for the response. | 708 // Send data and FIN for the response. |
| 708 stream_->WriteOrBufferData(kData1, false, nullptr); | 709 stream_->WriteOrBufferData(kData1, false, nullptr); |
| 709 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_)); | 710 EXPECT_TRUE(QuicStreamPeer::read_side_closed(stream_)); |
| 710 // Receive remaining data and FIN for the request. | 711 // Receive remaining data and FIN for the request. |
| 711 QuicStreamFrame frame2(stream_->id(), true, 0, QuicStringPiece("End")); | 712 QuicStreamFrame frame2(stream_->id(), true, 0, QuicStringPiece("End")); |
| 712 stream_->OnStreamFrame(frame2); | 713 stream_->OnStreamFrame(frame2); |
| 713 EXPECT_TRUE(stream_->fin_received()); | 714 EXPECT_TRUE(stream_->fin_received()); |
| 714 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); | 715 EXPECT_TRUE(stream_->HasFinalReceivedByteOffset()); |
| 715 } | 716 } |
| 716 | 717 |
| 718 TEST_F(QuicStreamTest, StreamIsDeletable) { |
| 719 Initialize(kShouldProcessData); |
| 720 if (!session_->use_stream_notifier()) { |
| 721 return; |
| 722 } |
| 723 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| 724 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); |
| 725 // Stream is deletable initially. |
| 726 EXPECT_TRUE(stream_->is_deletable()); |
| 727 |
| 728 // Send kData1. |
| 729 stream_->WriteOrBufferData(kData1, false, nullptr); |
| 730 EXPECT_FALSE(stream_->is_deletable()); |
| 731 QuicStreamFrame frame1(stream_->id(), false, 0, kData1); |
| 732 stream_->OnStreamFrameAcked(frame1, QuicTime::Delta::Zero()); |
| 733 // Stream is deletable as all sent data is acked. |
| 734 EXPECT_TRUE(stream_->is_deletable()); |
| 735 |
| 736 // Send kData2. |
| 737 stream_->WriteOrBufferData(kData2, false, nullptr); |
| 738 EXPECT_FALSE(stream_->is_deletable()); |
| 739 // Send FIN. |
| 740 stream_->WriteOrBufferData("", true, nullptr); |
| 741 |
| 742 // kData2 is acked. |
| 743 QuicStreamFrame frame2(stream_->id(), false, 9, kData2); |
| 744 stream_->OnStreamFrameAcked(frame2, QuicTime::Delta::Zero()); |
| 745 // Stream is not deletable as FIN is not acked. |
| 746 EXPECT_FALSE(stream_->is_deletable()); |
| 747 |
| 748 // FIN is acked. |
| 749 QuicStreamFrame frame3(stream_->id(), true, 18, ""); |
| 750 stream_->OnStreamFrameAcked(frame3, QuicTime::Delta::Zero()); |
| 751 EXPECT_TRUE(stream_->is_deletable()); |
| 752 } |
| 753 |
| 754 TEST_F(QuicStreamTest, CancelStream) { |
| 755 Initialize(kShouldProcessData); |
| 756 if (!session_->use_stream_notifier()) { |
| 757 return; |
| 758 } |
| 759 |
| 760 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| 761 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); |
| 762 EXPECT_TRUE(stream_->is_deletable()); |
| 763 |
| 764 stream_->WriteOrBufferData(kData1, false, nullptr); |
| 765 EXPECT_FALSE(stream_->is_deletable()); |
| 766 // Cancel stream. |
| 767 stream_->Reset(QUIC_STREAM_NO_ERROR); |
| 768 // stream is not deletable as the error code is QUIC_STREAM_NO_ERROR, and data |
| 769 // is going to be retransmitted. |
| 770 EXPECT_FALSE(stream_->is_deletable()); |
| 771 stream_->Reset(QUIC_STREAM_CANCELLED); |
| 772 // Stream is deletable as data is not going to be retransmitted. |
| 773 EXPECT_TRUE(stream_->is_deletable()); |
| 774 } |
| 775 |
| 776 TEST_F(QuicStreamTest, RstFrameReceived) { |
| 777 Initialize(kShouldProcessData); |
| 778 if (!session_->use_stream_notifier()) { |
| 779 return; |
| 780 } |
| 781 |
| 782 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| 783 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); |
| 784 EXPECT_TRUE(stream_->is_deletable()); |
| 785 |
| 786 stream_->WriteOrBufferData(kData1, false, nullptr); |
| 787 EXPECT_FALSE(stream_->is_deletable()); |
| 788 |
| 789 // RST_STREAM received. |
| 790 QuicRstStreamFrame rst_frame(stream_->id(), QUIC_STREAM_CANCELLED, 1234); |
| 791 stream_->OnStreamReset(rst_frame); |
| 792 // Stream is not deletable as it has outstanding data. |
| 793 EXPECT_FALSE(stream_->is_deletable()); |
| 794 } |
| 795 |
| 796 TEST_F(QuicStreamTest, ConnectionClosed) { |
| 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_TRUE(stream_->is_deletable()); |
| 805 |
| 806 stream_->WriteOrBufferData(kData1, false, nullptr); |
| 807 EXPECT_FALSE(stream_->is_deletable()); |
| 808 |
| 809 stream_->OnConnectionClosed(QUIC_INTERNAL_ERROR, |
| 810 ConnectionCloseSource::FROM_SELF); |
| 811 // Stream is deletable as connection is closed. |
| 812 EXPECT_TRUE(stream_->is_deletable()); |
| 813 } |
| 814 |
| 717 } // namespace | 815 } // namespace |
| 718 } // namespace test | 816 } // namespace test |
| 719 } // namespace net | 817 } // namespace net |
| OLD | NEW |