OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_spdy_stream.h" | 5 #include "net/quic/core/quic_spdy_stream.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "net/quic/core/quic_connection.h" | 10 #include "net/quic/core/quic_connection.h" |
11 #include "net/quic/core/quic_utils.h" | 11 #include "net/quic/core/quic_utils.h" |
12 #include "net/quic/core/quic_write_blocked_list.h" | 12 #include "net/quic/core/quic_write_blocked_list.h" |
13 #include "net/quic/core/spdy_utils.h" | 13 #include "net/quic/core/spdy_utils.h" |
14 #include "net/quic/platform/api/quic_ptr_util.h" | 14 #include "net/quic/platform/api/quic_ptr_util.h" |
15 #include "net/quic/platform/api/quic_text_utils.h" | 15 #include "net/quic/platform/api/quic_text_utils.h" |
16 #include "net/quic/test_tools/quic_flow_controller_peer.h" | 16 #include "net/quic/test_tools/quic_flow_controller_peer.h" |
17 #include "net/quic/test_tools/quic_session_peer.h" | 17 #include "net/quic/test_tools/quic_session_peer.h" |
18 #include "net/quic/test_tools/quic_stream_peer.h" | 18 #include "net/quic/test_tools/quic_stream_peer.h" |
19 #include "net/quic/test_tools/quic_test_utils.h" | 19 #include "net/quic/test_tools/quic_test_utils.h" |
20 #include "net/test/gtest_util.h" | |
21 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" |
22 | 22 |
23 using base::StringPiece; | 23 using base::StringPiece; |
24 using std::string; | 24 using std::string; |
25 using testing::AnyNumber; | 25 using testing::AnyNumber; |
26 using testing::Invoke; | 26 using testing::Invoke; |
27 using testing::Return; | 27 using testing::Return; |
28 using testing::StrictMock; | 28 using testing::StrictMock; |
29 using testing::_; | 29 using testing::_; |
30 | 30 |
31 namespace net { | 31 namespace net { |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 } | 745 } |
746 | 746 |
747 TEST_P(QuicSpdyStreamTest, ReceivingTrailersWithoutFin) { | 747 TEST_P(QuicSpdyStreamTest, ReceivingTrailersWithoutFin) { |
748 // Test that received Trailers must always have the FIN set. | 748 // Test that received Trailers must always have the FIN set. |
749 Initialize(kShouldProcessData); | 749 Initialize(kShouldProcessData); |
750 | 750 |
751 // Receive initial headers. | 751 // Receive initial headers. |
752 auto headers = AsHeaderList(headers_); | 752 auto headers = AsHeaderList(headers_); |
753 stream_->OnStreamHeaderList(/*fin=*/false, | 753 stream_->OnStreamHeaderList(/*fin=*/false, |
754 headers.uncompressed_header_bytes(), headers); | 754 headers.uncompressed_header_bytes(), headers); |
| 755 stream_->ConsumeHeaderList(); |
755 | 756 |
756 // Receive trailing headers with FIN deliberately set to false. | 757 // Receive trailing headers with FIN deliberately set to false. |
757 SpdyHeaderBlock trailers_block; | 758 SpdyHeaderBlock trailers_block; |
| 759 trailers_block["foo"] = "bar"; |
758 auto trailers = AsHeaderList(trailers_block); | 760 auto trailers = AsHeaderList(trailers_block); |
759 | 761 |
760 EXPECT_CALL(*connection_, | 762 EXPECT_CALL(*connection_, |
761 CloseConnection(QUIC_INVALID_HEADERS_STREAM_DATA, _, _)) | 763 CloseConnection(QUIC_INVALID_HEADERS_STREAM_DATA, _, _)) |
762 .Times(1); | 764 .Times(1); |
763 stream_->OnStreamHeaderList(/*fin=*/false, | 765 stream_->OnStreamHeaderList(/*fin=*/false, |
764 trailers.uncompressed_header_bytes(), trailers); | 766 trailers.uncompressed_header_bytes(), trailers); |
765 } | 767 } |
766 | 768 |
767 TEST_P(QuicSpdyStreamTest, ReceivingTrailersAfterHeadersWithFin) { | 769 TEST_P(QuicSpdyStreamTest, ReceivingTrailersAfterHeadersWithFin) { |
768 // If headers are received with a FIN, no trailers should then arrive. | 770 // If headers are received with a FIN, no trailers should then arrive. |
769 Initialize(kShouldProcessData); | 771 Initialize(kShouldProcessData); |
770 | 772 |
771 // Receive initial headers with FIN set. | 773 // Receive initial headers with FIN set. |
772 ProcessHeaders(true, headers_); | 774 ProcessHeaders(true, headers_); |
773 stream_->ConsumeHeaderList(); | 775 stream_->ConsumeHeaderList(); |
774 | 776 |
775 // Receive trailing headers after FIN already received. | 777 // Receive trailing headers after FIN already received. |
776 SpdyHeaderBlock trailers_block; | 778 SpdyHeaderBlock trailers_block; |
| 779 trailers_block["foo"] = "bar"; |
777 EXPECT_CALL(*connection_, | 780 EXPECT_CALL(*connection_, |
778 CloseConnection(QUIC_INVALID_HEADERS_STREAM_DATA, _, _)) | 781 CloseConnection(QUIC_INVALID_HEADERS_STREAM_DATA, _, _)) |
779 .Times(1); | 782 .Times(1); |
780 ProcessHeaders(true, trailers_block); | 783 ProcessHeaders(true, trailers_block); |
781 } | 784 } |
782 | 785 |
783 TEST_P(QuicSpdyStreamTest, ReceivingTrailersAfterBodyWithFin) { | 786 TEST_P(QuicSpdyStreamTest, ReceivingTrailersAfterBodyWithFin) { |
784 // If body data are received with a FIN, no trailers should then arrive. | 787 // If body data are received with a FIN, no trailers should then arrive. |
785 Initialize(kShouldProcessData); | 788 Initialize(kShouldProcessData); |
786 | 789 |
787 // Receive initial headers without FIN set. | 790 // Receive initial headers without FIN set. |
788 ProcessHeaders(false, headers_); | 791 ProcessHeaders(false, headers_); |
789 stream_->ConsumeHeaderList(); | 792 stream_->ConsumeHeaderList(); |
790 | 793 |
791 // Receive body data, with FIN. | 794 // Receive body data, with FIN. |
792 QuicStreamFrame frame(kClientDataStreamId1, /*fin=*/true, 0, "body"); | 795 QuicStreamFrame frame(kClientDataStreamId1, /*fin=*/true, 0, "body"); |
793 stream_->OnStreamFrame(frame); | 796 stream_->OnStreamFrame(frame); |
794 | 797 |
795 // Receive trailing headers after FIN already received. | 798 // Receive trailing headers after FIN already received. |
796 SpdyHeaderBlock trailers_block; | 799 SpdyHeaderBlock trailers_block; |
| 800 trailers_block["foo"] = "bar"; |
797 EXPECT_CALL(*connection_, | 801 EXPECT_CALL(*connection_, |
798 CloseConnection(QUIC_INVALID_HEADERS_STREAM_DATA, _, _)) | 802 CloseConnection(QUIC_INVALID_HEADERS_STREAM_DATA, _, _)) |
799 .Times(1); | 803 .Times(1); |
800 ProcessHeaders(false, trailers_block); | 804 ProcessHeaders(true, trailers_block); |
801 } | 805 } |
802 | 806 |
803 TEST_P(QuicSpdyStreamTest, ClosingStreamWithNoTrailers) { | 807 TEST_P(QuicSpdyStreamTest, ClosingStreamWithNoTrailers) { |
804 // Verify that a stream receiving headers, body, and no trailers is correctly | 808 // Verify that a stream receiving headers, body, and no trailers is correctly |
805 // marked as done reading on consumption of headers and body. | 809 // marked as done reading on consumption of headers and body. |
806 Initialize(kShouldProcessData); | 810 Initialize(kShouldProcessData); |
807 | 811 |
808 // Receive and consume initial headers with FIN not set. | 812 // Receive and consume initial headers with FIN not set. |
809 auto h = AsHeaderList(headers_); | 813 auto h = AsHeaderList(headers_); |
810 stream_->OnStreamHeaderList(/*fin=*/false, h.uncompressed_header_bytes(), h); | 814 stream_->OnStreamHeaderList(/*fin=*/false, h.uncompressed_header_bytes(), h); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 | 945 |
942 // Writing Trailers should fail, as the FIN has already been sent. | 946 // Writing Trailers should fail, as the FIN has already been sent. |
943 // populated with the number of body bytes written. | 947 // populated with the number of body bytes written. |
944 EXPECT_QUIC_BUG(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), | 948 EXPECT_QUIC_BUG(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), |
945 "Trailers cannot be sent after a FIN"); | 949 "Trailers cannot be sent after a FIN"); |
946 } | 950 } |
947 | 951 |
948 } // namespace | 952 } // namespace |
949 } // namespace test | 953 } // namespace test |
950 } // namespace net | 954 } // namespace net |
OLD | NEW |