| 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 "net/quic/quic_connection.h" | 7 #include "net/quic/quic_connection.h" |
| 8 #include "net/quic/quic_utils.h" | 8 #include "net/quic/quic_utils.h" |
| 9 #include "net/quic/quic_write_blocked_list.h" | 9 #include "net/quic/quic_write_blocked_list.h" |
| 10 #include "net/quic/spdy_utils.h" | 10 #include "net/quic/spdy_utils.h" |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 string body = ""; | 597 string body = ""; |
| 598 bool fin = true; | 598 bool fin = true; |
| 599 | 599 |
| 600 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)).Times(0); | 600 EXPECT_CALL(*connection_, SendBlocked(kClientDataStreamId1)).Times(0); |
| 601 EXPECT_CALL(*session_, WritevData(kClientDataStreamId1, _, _, _, _, _)) | 601 EXPECT_CALL(*session_, WritevData(kClientDataStreamId1, _, _, _, _, _)) |
| 602 .WillOnce(Return(QuicConsumedData(0, fin))); | 602 .WillOnce(Return(QuicConsumedData(0, fin))); |
| 603 | 603 |
| 604 stream_->WriteOrBufferData(body, fin, nullptr); | 604 stream_->WriteOrBufferData(body, fin, nullptr); |
| 605 } | 605 } |
| 606 | 606 |
| 607 TEST_P(QuicSpdyStreamTest, ReceivingTrailers) { |
| 608 // Test that receiving trailing headers from the peer works, and can be read |
| 609 // from the stream and consumed. |
| 610 ValueRestore<bool> old_flag(&FLAGS_quic_supports_trailers, true); |
| 611 Initialize(kShouldProcessData); |
| 612 |
| 613 // Receive initial headers. |
| 614 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 615 stream_->OnStreamHeaders(headers); |
| 616 stream_->OnStreamHeadersComplete(false, headers.size()); |
| 617 stream_->MarkHeadersConsumed(stream_->decompressed_headers().size()); |
| 618 |
| 619 // Receive trailing headers. |
| 620 SpdyHeaderBlock trailers_block; |
| 621 trailers_block["key1"] = "value1"; |
| 622 trailers_block["key2"] = "value2"; |
| 623 trailers_block["key3"] = "value3"; |
| 624 string trailers = SpdyUtils::SerializeUncompressedHeaders(trailers_block); |
| 625 stream_->OnStreamHeaders(trailers); |
| 626 stream_->OnStreamHeadersComplete(/*fin=*/true, trailers.size()); |
| 627 |
| 628 // The trailers should be decompressed, and readable from the stream. |
| 629 EXPECT_TRUE(stream_->trailers_decompressed()); |
| 630 const string decompressed_trailers = stream_->decompressed_trailers(); |
| 631 EXPECT_EQ(trailers, decompressed_trailers); |
| 632 |
| 633 // Consuming the trailers erases them from the stream. |
| 634 stream_->MarkTrailersConsumed(decompressed_trailers.size()); |
| 635 EXPECT_EQ("", stream_->decompressed_trailers()); |
| 636 } |
| 637 |
| 638 TEST_P(QuicSpdyStreamTest, ReceivingTrailersWithoutFin) { |
| 639 // Test that received Trailers must always have the FIN set. |
| 640 ValueRestore<bool> old_flag(&FLAGS_quic_supports_trailers, true); |
| 641 Initialize(kShouldProcessData); |
| 642 |
| 643 // Receive initial headers. |
| 644 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 645 stream_->OnStreamHeaders(headers); |
| 646 stream_->OnStreamHeadersComplete(false, headers.size()); |
| 647 |
| 648 // Receive trailing headers with FIN deliberately set to false. |
| 649 SpdyHeaderBlock trailers_block; |
| 650 string trailers = SpdyUtils::SerializeUncompressedHeaders(trailers_block); |
| 651 stream_->OnStreamHeaders(trailers); |
| 652 |
| 653 EXPECT_CALL(*connection_, |
| 654 SendConnectionClose(QUIC_INVALID_HEADERS_STREAM_DATA)) |
| 655 .Times(1); |
| 656 stream_->OnStreamHeadersComplete(/*fin=*/false, trailers.size()); |
| 657 } |
| 658 |
| 659 TEST_P(QuicSpdyStreamTest, ReceivingTrailersAfterFin) { |
| 660 // If Trailers are sent, neither Headers nor Body should contain a FIN. |
| 661 ValueRestore<bool> old_flag(&FLAGS_quic_supports_trailers, true); |
| 662 Initialize(kShouldProcessData); |
| 663 |
| 664 // Receive initial headers with FIN set. |
| 665 string headers = SpdyUtils::SerializeUncompressedHeaders(headers_); |
| 666 stream_->OnStreamHeaders(headers); |
| 667 stream_->OnStreamHeadersComplete(/*fin=*/true, headers.size()); |
| 668 |
| 669 // Receive trailing headers after FIN already received. |
| 670 SpdyHeaderBlock trailers_block; |
| 671 string trailers = SpdyUtils::SerializeUncompressedHeaders(trailers_block); |
| 672 stream_->OnStreamHeaders(trailers); |
| 673 |
| 674 EXPECT_CALL(*connection_, |
| 675 SendConnectionClose(QUIC_INVALID_HEADERS_STREAM_DATA)) |
| 676 .Times(1); |
| 677 stream_->OnStreamHeadersComplete(/*fin=*/true, trailers.size()); |
| 678 } |
| 679 |
| 607 } // namespace | 680 } // namespace |
| 608 } // namespace test | 681 } // namespace test |
| 609 } // namespace net | 682 } // namespace net |
| OLD | NEW |