| 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 "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
| 8 | 8 |
| 9 #include "net/quic/quic_connection.h" | 9 #include "net/quic/quic_connection.h" |
| 10 #include "net/quic/quic_utils.h" | 10 #include "net/quic/quic_utils.h" |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 kWindow); | 529 kWindow); |
| 530 | 530 |
| 531 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); | 531 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 532 stream_->OnStreamHeaders(headers); | 532 stream_->OnStreamHeaders(headers); |
| 533 stream_->OnStreamHeadersComplete(false, headers.size()); | 533 stream_->OnStreamHeadersComplete(false, headers.size()); |
| 534 | 534 |
| 535 // Receive data to overflow the window, violating flow control. | 535 // Receive data to overflow the window, violating flow control. |
| 536 string body; | 536 string body; |
| 537 GenerateBody(&body, kWindow + 1); | 537 GenerateBody(&body, kWindow + 1); |
| 538 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body)); | 538 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body)); |
| 539 EXPECT_CALL(*connection_, | 539 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( |
| 540 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)); | 540 QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _)); |
| 541 stream_->OnStreamFrame(frame); | 541 stream_->OnStreamFrame(frame); |
| 542 } | 542 } |
| 543 | 543 |
| 544 TEST_P(QuicSpdyStreamTest, TestHandlingQuicRstStreamNoError) { | 544 TEST_P(QuicSpdyStreamTest, TestHandlingQuicRstStreamNoError) { |
| 545 Initialize(kShouldProcessData); | 545 Initialize(kShouldProcessData); |
| 546 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); | 546 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 547 stream_->OnStreamHeaders(headers); | 547 stream_->OnStreamHeaders(headers); |
| 548 stream_->OnStreamHeadersComplete(false, headers.size()); | 548 stream_->OnStreamHeadersComplete(false, headers.size()); |
| 549 | 549 |
| 550 if (GetParam() <= QUIC_VERSION_28) { | 550 if (GetParam() <= QUIC_VERSION_28) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 580 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); | 580 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 581 stream_->OnStreamHeaders(headers); | 581 stream_->OnStreamHeaders(headers); |
| 582 stream_->OnStreamHeadersComplete(false, headers.size()); | 582 stream_->OnStreamHeadersComplete(false, headers.size()); |
| 583 | 583 |
| 584 // Send enough data to overflow the connection level flow control window. | 584 // Send enough data to overflow the connection level flow control window. |
| 585 string body; | 585 string body; |
| 586 GenerateBody(&body, kConnectionWindow + 1); | 586 GenerateBody(&body, kConnectionWindow + 1); |
| 587 EXPECT_LT(body.size(), kStreamWindow); | 587 EXPECT_LT(body.size(), kStreamWindow); |
| 588 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body)); | 588 QuicStreamFrame frame(kClientDataStreamId1, false, 0, StringPiece(body)); |
| 589 | 589 |
| 590 EXPECT_CALL(*connection_, | 590 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( |
| 591 SendConnectionClose(QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA)); | 591 QUIC_FLOW_CONTROL_RECEIVED_TOO_MUCH_DATA, _)); |
| 592 stream_->OnStreamFrame(frame); | 592 stream_->OnStreamFrame(frame); |
| 593 } | 593 } |
| 594 | 594 |
| 595 TEST_P(QuicSpdyStreamTest, StreamFlowControlFinNotBlocked) { | 595 TEST_P(QuicSpdyStreamTest, StreamFlowControlFinNotBlocked) { |
| 596 // An attempt to write a FIN with no data should not be flow control blocked, | 596 // An attempt to write a FIN with no data should not be flow control blocked, |
| 597 // even if the send window is 0. | 597 // even if the send window is 0. |
| 598 | 598 |
| 599 Initialize(kShouldProcessData); | 599 Initialize(kShouldProcessData); |
| 600 | 600 |
| 601 // Set a flow control limit of zero. | 601 // Set a flow control limit of zero. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 // Receive initial headers. | 653 // Receive initial headers. |
| 654 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); | 654 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 655 stream_->OnStreamHeaders(headers); | 655 stream_->OnStreamHeaders(headers); |
| 656 stream_->OnStreamHeadersComplete(false, headers.size()); | 656 stream_->OnStreamHeadersComplete(false, headers.size()); |
| 657 | 657 |
| 658 // Receive trailing headers with FIN deliberately set to false. | 658 // Receive trailing headers with FIN deliberately set to false. |
| 659 SpdyHeaderBlock trailers_block; | 659 SpdyHeaderBlock trailers_block; |
| 660 string trailers = SpdyUtils::SerializeUncompressedHeaders(trailers_block); | 660 string trailers = SpdyUtils::SerializeUncompressedHeaders(trailers_block); |
| 661 stream_->OnStreamHeaders(trailers); | 661 stream_->OnStreamHeaders(trailers); |
| 662 | 662 |
| 663 EXPECT_CALL(*connection_, | 663 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( |
| 664 SendConnectionClose(QUIC_INVALID_HEADERS_STREAM_DATA)) | 664 QUIC_INVALID_HEADERS_STREAM_DATA, _)) |
| 665 .Times(1); | 665 .Times(1); |
| 666 stream_->OnStreamHeadersComplete(/*fin=*/false, trailers.size()); | 666 stream_->OnStreamHeadersComplete(/*fin=*/false, trailers.size()); |
| 667 } | 667 } |
| 668 | 668 |
| 669 TEST_P(QuicSpdyStreamTest, ReceivingTrailersAfterFin) { | 669 TEST_P(QuicSpdyStreamTest, ReceivingTrailersAfterFin) { |
| 670 // If Trailers are sent, neither Headers nor Body should contain a FIN. | 670 // If Trailers are sent, neither Headers nor Body should contain a FIN. |
| 671 ValueRestore<bool> old_flag(&FLAGS_quic_supports_trailers, true); | 671 ValueRestore<bool> old_flag(&FLAGS_quic_supports_trailers, true); |
| 672 Initialize(kShouldProcessData); | 672 Initialize(kShouldProcessData); |
| 673 | 673 |
| 674 // Receive initial headers with FIN set. | 674 // Receive initial headers with FIN set. |
| 675 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); | 675 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 676 stream_->OnStreamHeaders(headers); | 676 stream_->OnStreamHeaders(headers); |
| 677 stream_->OnStreamHeadersComplete(/*fin=*/true, headers.size()); | 677 stream_->OnStreamHeadersComplete(/*fin=*/true, headers.size()); |
| 678 | 678 |
| 679 // Receive trailing headers after FIN already received. | 679 // Receive trailing headers after FIN already received. |
| 680 SpdyHeaderBlock trailers_block; | 680 SpdyHeaderBlock trailers_block; |
| 681 string trailers = SpdyUtils::SerializeUncompressedHeaders(trailers_block); | 681 string trailers = SpdyUtils::SerializeUncompressedHeaders(trailers_block); |
| 682 stream_->OnStreamHeaders(trailers); | 682 stream_->OnStreamHeaders(trailers); |
| 683 | 683 |
| 684 EXPECT_CALL(*connection_, | 684 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( |
| 685 SendConnectionClose(QUIC_INVALID_HEADERS_STREAM_DATA)) | 685 QUIC_INVALID_HEADERS_STREAM_DATA, _)) |
| 686 .Times(1); | 686 .Times(1); |
| 687 stream_->OnStreamHeadersComplete(/*fin=*/true, trailers.size()); | 687 stream_->OnStreamHeadersComplete(/*fin=*/true, trailers.size()); |
| 688 } | 688 } |
| 689 | 689 |
| 690 TEST_P(QuicSpdyStreamTest, ReceivingTrailersAfterBodyWithFin) { | 690 TEST_P(QuicSpdyStreamTest, ReceivingTrailersAfterBodyWithFin) { |
| 691 // If body data are received with a FIN, no trailers should then arrive. | 691 // If body data are received with a FIN, no trailers should then arrive. |
| 692 ValueRestore<bool> old_flag(&FLAGS_quic_supports_trailers, true); | 692 ValueRestore<bool> old_flag(&FLAGS_quic_supports_trailers, true); |
| 693 Initialize(kShouldProcessData); | 693 Initialize(kShouldProcessData); |
| 694 | 694 |
| 695 // Receive initial headers without FIN set. | 695 // Receive initial headers without FIN set. |
| 696 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); | 696 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 697 stream_->OnStreamHeaders(headers); | 697 stream_->OnStreamHeaders(headers); |
| 698 stream_->OnStreamHeadersComplete(/*fin=*/false, headers.size()); | 698 stream_->OnStreamHeadersComplete(/*fin=*/false, headers.size()); |
| 699 | 699 |
| 700 // Receive body data, with FIN. | 700 // Receive body data, with FIN. |
| 701 QuicStreamFrame frame(kClientDataStreamId1, /*fin=*/true, 0, "body"); | 701 QuicStreamFrame frame(kClientDataStreamId1, /*fin=*/true, 0, "body"); |
| 702 stream_->OnStreamFrame(frame); | 702 stream_->OnStreamFrame(frame); |
| 703 | 703 |
| 704 // Receive trailing headers after FIN already received. | 704 // Receive trailing headers after FIN already received. |
| 705 SpdyHeaderBlock trailers_block; | 705 SpdyHeaderBlock trailers_block; |
| 706 string trailers = SpdyUtils::SerializeUncompressedHeaders(trailers_block); | 706 string trailers = SpdyUtils::SerializeUncompressedHeaders(trailers_block); |
| 707 stream_->OnStreamHeaders(trailers); | 707 stream_->OnStreamHeaders(trailers); |
| 708 | 708 |
| 709 EXPECT_CALL(*connection_, | 709 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( |
| 710 SendConnectionClose(QUIC_INVALID_HEADERS_STREAM_DATA)) | 710 QUIC_INVALID_HEADERS_STREAM_DATA, _)) |
| 711 .Times(1); | 711 .Times(1); |
| 712 stream_->OnStreamHeadersComplete(/*fin=*/true, trailers.size()); | 712 stream_->OnStreamHeadersComplete(/*fin=*/true, trailers.size()); |
| 713 } | 713 } |
| 714 | 714 |
| 715 TEST_P(QuicSpdyStreamTest, ClosingStreamWithNoTrailers) { | 715 TEST_P(QuicSpdyStreamTest, ClosingStreamWithNoTrailers) { |
| 716 // Verify that a stream receiving headers, body, and no trailers is correctly | 716 // Verify that a stream receiving headers, body, and no trailers is correctly |
| 717 // marked as done reading on consumption of headers and body. | 717 // marked as done reading on consumption of headers and body. |
| 718 ValueRestore<bool> old_flag(&FLAGS_quic_supports_trailers, true); | 718 ValueRestore<bool> old_flag(&FLAGS_quic_supports_trailers, true); |
| 719 Initialize(kShouldProcessData); | 719 Initialize(kShouldProcessData); |
| 720 | 720 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 | 852 |
| 853 // Writing Trailers should fail, as the FIN has already been sent. | 853 // Writing Trailers should fail, as the FIN has already been sent. |
| 854 // populated with the number of body bytes written. | 854 // populated with the number of body bytes written. |
| 855 EXPECT_DFATAL(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), | 855 EXPECT_DFATAL(stream_->WriteTrailers(SpdyHeaderBlock(), nullptr), |
| 856 "Trailers cannot be sent after a FIN"); | 856 "Trailers cannot be sent after a FIN"); |
| 857 } | 857 } |
| 858 | 858 |
| 859 } // namespace | 859 } // namespace |
| 860 } // namespace test | 860 } // namespace test |
| 861 } // namespace net | 861 } // namespace net |
| OLD | NEW |