| 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/quic_spdy_stream.h" | 5 #include "net/quic/quic_spdy_stream.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 EXPECT_EQ(kWindow, QuicFlowControllerPeer::SendWindowOffset( | 437 EXPECT_EQ(kWindow, QuicFlowControllerPeer::SendWindowOffset( |
| 438 stream_->flow_controller())); | 438 stream_->flow_controller())); |
| 439 | 439 |
| 440 // Try to send more data than the flow control limit allows. | 440 // Try to send more data than the flow control limit allows. |
| 441 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); | 441 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 442 string body; | 442 string body; |
| 443 const uint64_t kOverflow = 15; | 443 const uint64_t kOverflow = 15; |
| 444 GenerateBody(&body, kWindow + kOverflow); | 444 GenerateBody(&body, kWindow + kOverflow); |
| 445 | 445 |
| 446 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)); | 446 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)); |
| 447 EXPECT_CALL(*session_, WritevData(stream_, kClientDataStreamId1, _, _, _, _)) | 447 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| 448 .WillOnce(Return(QuicConsumedData(kWindow, true))); | 448 .WillOnce(Return(QuicConsumedData(kWindow, true))); |
| 449 stream_->WriteOrBufferData(body, false, nullptr); | 449 stream_->WriteOrBufferData(body, false, nullptr); |
| 450 | 450 |
| 451 // Should have sent as much as possible, resulting in no send window left. | 451 // Should have sent as much as possible, resulting in no send window left. |
| 452 EXPECT_EQ(0u, | 452 EXPECT_EQ(0u, |
| 453 QuicFlowControllerPeer::SendWindowSize(stream_->flow_controller())); | 453 QuicFlowControllerPeer::SendWindowSize(stream_->flow_controller())); |
| 454 | 454 |
| 455 // And we should have queued the overflowed data. | 455 // And we should have queued the overflowed data. |
| 456 EXPECT_EQ(kOverflow, ReliableQuicStreamPeer::SizeOfQueuedData(stream_)); | 456 EXPECT_EQ(kOverflow, ReliableQuicStreamPeer::SizeOfQueuedData(stream_)); |
| 457 } | 457 } |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 // Set a flow control limit of zero. | 683 // Set a flow control limit of zero. |
| 684 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), 0); | 684 QuicFlowControllerPeer::SetReceiveWindowOffset(stream_->flow_controller(), 0); |
| 685 EXPECT_EQ(0u, QuicFlowControllerPeer::ReceiveWindowOffset( | 685 EXPECT_EQ(0u, QuicFlowControllerPeer::ReceiveWindowOffset( |
| 686 stream_->flow_controller())); | 686 stream_->flow_controller())); |
| 687 | 687 |
| 688 // Send a frame with a FIN but no data. This should not be blocked. | 688 // Send a frame with a FIN but no data. This should not be blocked. |
| 689 string body = ""; | 689 string body = ""; |
| 690 bool fin = true; | 690 bool fin = true; |
| 691 | 691 |
| 692 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)).Times(0); | 692 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)).Times(0); |
| 693 EXPECT_CALL(*session_, WritevData(stream_, kClientDataStreamId1, _, _, _, _)) | 693 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| 694 .WillOnce(Return(QuicConsumedData(0, fin))); | 694 .WillOnce(Return(QuicConsumedData(0, fin))); |
| 695 | 695 |
| 696 stream_->WriteOrBufferData(body, fin, nullptr); | 696 stream_->WriteOrBufferData(body, fin, nullptr); |
| 697 } | 697 } |
| 698 | 698 |
| 699 TEST_P(QuicSpdyStreamTest, ReceivingTrailers) { | 699 TEST_P(QuicSpdyStreamTest, ReceivingTrailers) { |
| 700 // Test that receiving trailing headers from the peer works, and can be read | 700 // Test that receiving trailing headers from the peer works, and can be read |
| 701 // from the stream and consumed. | 701 // from the stream and consumed. |
| 702 Initialize(kShouldProcessData); | 702 Initialize(kShouldProcessData); |
| 703 | 703 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 | 959 |
| 960 // Write the initial headers. | 960 // Write the initial headers. |
| 961 EXPECT_CALL(*session_, WriteHeadersMock(_, _, _, _, _)); | 961 EXPECT_CALL(*session_, WriteHeadersMock(_, _, _, _, _)); |
| 962 stream_->WriteHeaders(SpdyHeaderBlock(), /*fin=*/false, nullptr); | 962 stream_->WriteHeaders(SpdyHeaderBlock(), /*fin=*/false, nullptr); |
| 963 | 963 |
| 964 // Write non-zero body data, but only consume partially, ensuring queueing. | 964 // Write non-zero body data, but only consume partially, ensuring queueing. |
| 965 const int kBodySize = 1 * 1024; // 1 MB | 965 const int kBodySize = 1 * 1024; // 1 MB |
| 966 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) | 966 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| 967 .WillOnce(Return(QuicConsumedData(kBodySize - 1, false))); | 967 .WillOnce(Return(QuicConsumedData(kBodySize - 1, false))); |
| 968 stream_->WriteOrBufferData(string(kBodySize, 'x'), false, nullptr); | 968 stream_->WriteOrBufferData(string(kBodySize, 'x'), false, nullptr); |
| 969 EXPECT_EQ(1u, stream_->queued_data_bytes()); | 969 if (!session_->force_hol_blocking()) { |
| 970 EXPECT_EQ(1u, stream_->queued_data_bytes()); |
| 971 } |
| 970 | 972 |
| 971 // Writing trailers will send a FIN, but not close the write side of the | 973 // Writing trailers will send a FIN, but not close the write side of the |
| 972 // stream as there are queued bytes. | 974 // stream as there are queued bytes. |
| 973 EXPECT_CALL(*session_, WriteHeadersMock(_, _, true, _, _)); | 975 EXPECT_CALL(*session_, WriteHeadersMock(_, _, true, _, _)); |
| 974 stream_->WriteTrailers(SpdyHeaderBlock(), nullptr); | 976 stream_->WriteTrailers(SpdyHeaderBlock(), nullptr); |
| 975 EXPECT_TRUE(stream_->fin_sent()); | 977 EXPECT_TRUE(stream_->fin_sent()); |
| 976 EXPECT_FALSE(stream_->write_side_closed()); | 978 if (!session_->force_hol_blocking()) { |
| 979 EXPECT_FALSE(stream_->write_side_closed()); |
| 980 } |
| 977 } | 981 } |
| 978 | 982 |
| 979 TEST_P(QuicSpdyStreamTest, WritingTrailersAfterFIN) { | 983 TEST_P(QuicSpdyStreamTest, WritingTrailersAfterFIN) { |
| 980 // Test that it is not possible to write Trailers after a FIN has been sent. | 984 // Test that it is not possible to write Trailers after a FIN has been sent. |
| 981 Initialize(kShouldProcessData); | 985 Initialize(kShouldProcessData); |
| 982 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) | 986 EXPECT_CALL(*session_, WritevData(_, _, _, _, _, _)) |
| 983 .Times(AnyNumber()) | 987 .Times(AnyNumber()) |
| 984 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); | 988 .WillRepeatedly(Invoke(MockQuicSession::ConsumeAllData)); |
| 985 | 989 |
| 986 // Write the initial headers, with a FIN. | 990 // Write the initial headers, with a FIN. |
| 987 EXPECT_CALL(*session_, WriteHeadersMock(_, _, _, _, _)); | 991 EXPECT_CALL(*session_, WriteHeadersMock(_, _, _, _, _)); |
| 988 stream_->WriteHeaders(SpdyHeaderBlock(), /*fin=*/true, nullptr); | 992 stream_->WriteHeaders(SpdyHeaderBlock(), /*fin=*/true, nullptr); |
| 989 EXPECT_TRUE(stream_->fin_sent()); | 993 EXPECT_TRUE(stream_->fin_sent()); |
| 990 | 994 |
| 991 // Writing Trailers should fail, as the FIN has already been sent. | 995 // Writing Trailers should fail, as the FIN has already been sent. |
| 992 // populated with the number of body bytes written. | 996 // populated with the number of body bytes written. |
| 993 EXPECT_DFATAL(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), | 997 EXPECT_DFATAL(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), |
| 994 "Trailers cannot be sent after a FIN"); | 998 "Trailers cannot be sent after a FIN"); |
| 995 } | 999 } |
| 996 | 1000 |
| 997 } // namespace | 1001 } // namespace |
| 998 } // namespace test | 1002 } // namespace test |
| 999 } // namespace net | 1003 } // namespace net |
| OLD | NEW |