| Index: net/quic/quic_spdy_stream_test.cc
|
| diff --git a/net/quic/quic_spdy_stream_test.cc b/net/quic/quic_spdy_stream_test.cc
|
| index 2a7583c1f9e679650afaea187245ff30e1841117..a2fac3fa6d18372bb3e962d54a7a1eae2bf4d8b1 100644
|
| --- a/net/quic/quic_spdy_stream_test.cc
|
| +++ b/net/quic/quic_spdy_stream_test.cc
|
| @@ -604,6 +604,79 @@ TEST_P(QuicSpdyStreamTest, StreamFlowControlFinNotBlocked) {
|
| stream_->WriteOrBufferData(body, fin, nullptr);
|
| }
|
|
|
| +TEST_P(QuicSpdyStreamTest, ReceivingTrailers) {
|
| + // Test that receiving trailing headers from the peer works, and can be read
|
| + // from the stream and consumed.
|
| + ValueRestore<bool> old_flag(&FLAGS_quic_supports_trailers, true);
|
| + Initialize(kShouldProcessData);
|
| +
|
| + // Receive initial headers.
|
| + string headers = SpdyUtils::SerializeUncompressedHeaders(headers_);
|
| + stream_->OnStreamHeaders(headers);
|
| + stream_->OnStreamHeadersComplete(false, headers.size());
|
| + stream_->MarkHeadersConsumed(stream_->decompressed_headers().size());
|
| +
|
| + // Receive trailing headers.
|
| + SpdyHeaderBlock trailers_block;
|
| + trailers_block["key1"] = "value1";
|
| + trailers_block["key2"] = "value2";
|
| + trailers_block["key3"] = "value3";
|
| + string trailers = SpdyUtils::SerializeUncompressedHeaders(trailers_block);
|
| + stream_->OnStreamHeaders(trailers);
|
| + stream_->OnStreamHeadersComplete(/*fin=*/true, trailers.size());
|
| +
|
| + // The trailers should be decompressed, and readable from the stream.
|
| + EXPECT_TRUE(stream_->trailers_decompressed());
|
| + const string decompressed_trailers = stream_->decompressed_trailers();
|
| + EXPECT_EQ(trailers, decompressed_trailers);
|
| +
|
| + // Consuming the trailers erases them from the stream.
|
| + stream_->MarkTrailersConsumed(decompressed_trailers.size());
|
| + EXPECT_EQ("", stream_->decompressed_trailers());
|
| +}
|
| +
|
| +TEST_P(QuicSpdyStreamTest, ReceivingTrailersWithoutFin) {
|
| + // Test that received Trailers must always have the FIN set.
|
| + ValueRestore<bool> old_flag(&FLAGS_quic_supports_trailers, true);
|
| + Initialize(kShouldProcessData);
|
| +
|
| + // Receive initial headers.
|
| + string headers = SpdyUtils::SerializeUncompressedHeaders(headers_);
|
| + stream_->OnStreamHeaders(headers);
|
| + stream_->OnStreamHeadersComplete(false, headers.size());
|
| +
|
| + // Receive trailing headers with FIN deliberately set to false.
|
| + SpdyHeaderBlock trailers_block;
|
| + string trailers = SpdyUtils::SerializeUncompressedHeaders(trailers_block);
|
| + stream_->OnStreamHeaders(trailers);
|
| +
|
| + EXPECT_CALL(*connection_,
|
| + SendConnectionClose(QUIC_INVALID_HEADERS_STREAM_DATA))
|
| + .Times(1);
|
| + stream_->OnStreamHeadersComplete(/*fin=*/false, trailers.size());
|
| +}
|
| +
|
| +TEST_P(QuicSpdyStreamTest, ReceivingTrailersAfterFin) {
|
| + // If Trailers are sent, neither Headers nor Body should contain a FIN.
|
| + ValueRestore<bool> old_flag(&FLAGS_quic_supports_trailers, true);
|
| + Initialize(kShouldProcessData);
|
| +
|
| + // Receive initial headers with FIN set.
|
| + string headers = SpdyUtils::SerializeUncompressedHeaders(headers_);
|
| + stream_->OnStreamHeaders(headers);
|
| + stream_->OnStreamHeadersComplete(/*fin=*/true, headers.size());
|
| +
|
| + // Receive trailing headers after FIN already received.
|
| + SpdyHeaderBlock trailers_block;
|
| + string trailers = SpdyUtils::SerializeUncompressedHeaders(trailers_block);
|
| + stream_->OnStreamHeaders(trailers);
|
| +
|
| + EXPECT_CALL(*connection_,
|
| + SendConnectionClose(QUIC_INVALID_HEADERS_STREAM_DATA))
|
| + .Times(1);
|
| + stream_->OnStreamHeadersComplete(/*fin=*/true, trailers.size());
|
| +}
|
| +
|
| } // namespace
|
| } // namespace test
|
| } // namespace net
|
|
|