| 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 "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/string_number_conversions.h" | |
| 12 #include "net/quic/core/quic_connection.h" | 11 #include "net/quic/core/quic_connection.h" |
| 13 #include "net/quic/core/quic_utils.h" | 12 #include "net/quic/core/quic_utils.h" |
| 14 #include "net/quic/core/quic_write_blocked_list.h" | 13 #include "net/quic/core/quic_write_blocked_list.h" |
| 15 #include "net/quic/core/spdy_utils.h" | 14 #include "net/quic/core/spdy_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" | 20 #include "net/test/gtest_util.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 21 #include "testing/gmock/include/gmock/gmock.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; |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 stream_->OnStreamFrame(frame1); | 537 stream_->OnStreamFrame(frame1); |
| 538 QuicStreamFrame frame2(kClientDataStreamId2, false, 0, StringPiece(body)); | 538 QuicStreamFrame frame2(kClientDataStreamId2, false, 0, StringPiece(body)); |
| 539 stream2_->OnStreamFrame(frame2); | 539 stream2_->OnStreamFrame(frame2); |
| 540 | 540 |
| 541 // Now receive a further single byte on one stream - again this does not | 541 // Now receive a further single byte on one stream - again this does not |
| 542 // trigger a stream WINDOW_UPDATE, but now the connection flow control window | 542 // trigger a stream WINDOW_UPDATE, but now the connection flow control window |
| 543 // is over half full and thus a connection WINDOW_UPDATE is sent. | 543 // is over half full and thus a connection WINDOW_UPDATE is sent. |
| 544 EXPECT_CALL(*connection_, SendWindowUpdate(kClientDataStreamId1, _)).Times(0); | 544 EXPECT_CALL(*connection_, SendWindowUpdate(kClientDataStreamId1, _)).Times(0); |
| 545 EXPECT_CALL(*connection_, SendWindowUpdate(kClientDataStreamId2, _)).Times(0); | 545 EXPECT_CALL(*connection_, SendWindowUpdate(kClientDataStreamId2, _)).Times(0); |
| 546 EXPECT_CALL(*connection_, | 546 EXPECT_CALL(*connection_, |
| 547 SendWindowUpdate(0, QuicFlowControllerPeer::ReceiveWindowOffset( | 547 SendWindowUpdate(0, |
| 548 session_->flow_controller()) + | 548 QuicFlowControllerPeer::ReceiveWindowOffset( |
| 549 1 + kWindow / 2)); | 549 session_->flow_controller()) + |
| 550 1 + kWindow / 2)); |
| 550 QuicStreamFrame frame3(kClientDataStreamId1, false, (kWindow / 4), | 551 QuicStreamFrame frame3(kClientDataStreamId1, false, (kWindow / 4), |
| 551 StringPiece("a")); | 552 StringPiece("a")); |
| 552 stream_->OnStreamFrame(frame3); | 553 stream_->OnStreamFrame(frame3); |
| 553 } | 554 } |
| 554 | 555 |
| 555 TEST_P(QuicSpdyStreamTest, StreamFlowControlViolation) { | 556 TEST_P(QuicSpdyStreamTest, StreamFlowControlViolation) { |
| 556 // Tests that on if the peer sends too much data (i.e. violates the flow | 557 // Tests that on if the peer sends too much data (i.e. violates the flow |
| 557 // control protocol), then we terminate the connection. | 558 // control protocol), then we terminate the connection. |
| 558 | 559 |
| 559 // Stream should not process data, so that data gets buffered in the | 560 // Stream should not process data, so that data gets buffered in the |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 // Receive initial headers. | 770 // Receive initial headers. |
| 770 QuicHeaderList headers = ProcessHeaders(false, headers_); | 771 QuicHeaderList headers = ProcessHeaders(false, headers_); |
| 771 stream_->ConsumeHeaderList(); | 772 stream_->ConsumeHeaderList(); |
| 772 | 773 |
| 773 const string body = "this is the body"; | 774 const string body = "this is the body"; |
| 774 // Receive trailing headers. | 775 // Receive trailing headers. |
| 775 SpdyHeaderBlock trailers_block; | 776 SpdyHeaderBlock trailers_block; |
| 776 trailers_block["key1"] = "value1"; | 777 trailers_block["key1"] = "value1"; |
| 777 trailers_block["key2"] = "value2"; | 778 trailers_block["key2"] = "value2"; |
| 778 trailers_block["key3"] = "value3"; | 779 trailers_block["key3"] = "value3"; |
| 779 trailers_block[kFinalOffsetHeaderKey] = base::IntToString(body.size()); | 780 trailers_block[kFinalOffsetHeaderKey] = |
| 781 QuicTextUtils::Uint64ToString(body.size()); |
| 780 | 782 |
| 781 QuicHeaderList trailers = ProcessHeaders(true, trailers_block); | 783 QuicHeaderList trailers = ProcessHeaders(true, trailers_block); |
| 782 | 784 |
| 783 // The trailers should be decompressed, and readable from the stream. | 785 // The trailers should be decompressed, and readable from the stream. |
| 784 EXPECT_TRUE(stream_->trailers_decompressed()); | 786 EXPECT_TRUE(stream_->trailers_decompressed()); |
| 785 | 787 |
| 786 // The final offset trailer will be consumed by QUIC. | 788 // The final offset trailer will be consumed by QUIC. |
| 787 trailers_block.erase(kFinalOffsetHeaderKey); | 789 trailers_block.erase(kFinalOffsetHeaderKey); |
| 788 EXPECT_EQ(trailers_block, stream_->received_trailers()); | 790 EXPECT_EQ(trailers_block, stream_->received_trailers()); |
| 789 | 791 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 | 853 |
| 852 // Write non-zero body data to force a non-zero final offset. | 854 // Write non-zero body data to force a non-zero final offset. |
| 853 const int kBodySize = 1 * 1024; // 1 MB | 855 const int kBodySize = 1 * 1024; // 1 MB |
| 854 stream_->WriteOrBufferData(string(kBodySize, 'x'), false, nullptr); | 856 stream_->WriteOrBufferData(string(kBodySize, 'x'), false, nullptr); |
| 855 | 857 |
| 856 // The final offset field in the trailing headers is populated with the | 858 // The final offset field in the trailing headers is populated with the |
| 857 // number of body bytes written (including queued bytes). | 859 // number of body bytes written (including queued bytes). |
| 858 SpdyHeaderBlock trailers; | 860 SpdyHeaderBlock trailers; |
| 859 trailers["trailer key"] = "trailer value"; | 861 trailers["trailer key"] = "trailer value"; |
| 860 SpdyHeaderBlock trailers_with_offset(trailers.Clone()); | 862 SpdyHeaderBlock trailers_with_offset(trailers.Clone()); |
| 861 trailers_with_offset[kFinalOffsetHeaderKey] = base::Uint64ToString(kBodySize); | 863 trailers_with_offset[kFinalOffsetHeaderKey] = |
| 864 QuicTextUtils::Uint64ToString(kBodySize); |
| 862 EXPECT_CALL(*session_, WriteHeadersMock(_, _, true, _, _)); | 865 EXPECT_CALL(*session_, WriteHeadersMock(_, _, true, _, _)); |
| 863 stream_->WriteTrailers(std::move(trailers), nullptr); | 866 stream_->WriteTrailers(std::move(trailers), nullptr); |
| 864 EXPECT_EQ(trailers_with_offset, session_->GetWriteHeaders()); | 867 EXPECT_EQ(trailers_with_offset, session_->GetWriteHeaders()); |
| 865 } | 868 } |
| 866 | 869 |
| 867 TEST_P(QuicSpdyStreamTest, WritingTrailersClosesWriteSide) { | 870 TEST_P(QuicSpdyStreamTest, WritingTrailersClosesWriteSide) { |
| 868 // Test that if trailers are written after all other data has been written | 871 // Test that if trailers are written after all other data has been written |
| 869 // (headers and body), that this closes the stream for writing. | 872 // (headers and body), that this closes the stream for writing. |
| 870 Initialize(kShouldProcessData); | 873 Initialize(kShouldProcessData); |
| 871 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) | 874 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 | 942 |
| 940 // Writing Trailers should fail, as the FIN has already been sent. | 943 // Writing Trailers should fail, as the FIN has already been sent. |
| 941 // populated with the number of body bytes written. | 944 // populated with the number of body bytes written. |
| 942 EXPECT_QUIC_BUG(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), | 945 EXPECT_QUIC_BUG(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), |
| 943 "Trailers cannot be sent after a FIN"); | 946 "Trailers cannot be sent after a FIN"); |
| 944 } | 947 } |
| 945 | 948 |
| 946 } // namespace | 949 } // namespace |
| 947 } // namespace test | 950 } // namespace test |
| 948 } // namespace net | 951 } // namespace net |
| OLD | NEW |