Index: net/quic/chromium/quic_http_stream_test.cc |
diff --git a/net/quic/chromium/quic_http_stream_test.cc b/net/quic/chromium/quic_http_stream_test.cc |
index 56ab9fd11bfc41f300bb42cbd68ab91b429dd009..f9b9a3b8ce0b26106da5dd6a09599114ffbdafda 100644 |
--- a/net/quic/chromium/quic_http_stream_test.cc |
+++ b/net/quic/chromium/quic_http_stream_test.cc |
@@ -105,11 +105,6 @@ class AutoClosingStream : public QuicHttpStream { |
std::unique_ptr<QuicChromiumClientSession::Handle> session) |
: QuicHttpStream(std::move(session)) {} |
- void OnInitialHeadersAvailable(const SpdyHeaderBlock& headers, |
- size_t frame_len) override { |
- Close(false); |
- } |
- |
void OnTrailingHeadersAvailable(const SpdyHeaderBlock& headers, |
size_t frame_len) override { |
Close(false); |
@@ -183,6 +178,9 @@ class QuicHttpStreamPeer { |
}; |
class QuicHttpStreamTest : public ::testing::TestWithParam<QuicVersion> { |
+ public: |
+ void CloseStream(QuicHttpStream* stream, int /*rv*/) { stream->Close(false); } |
+ |
protected: |
static const bool kFin = true; |
static const bool kIncludeVersion = true; |
@@ -1152,10 +1150,8 @@ TEST_P(QuicHttpStreamTest, SendPostRequest) { |
ProcessPacket(ConstructResponseHeadersPacket( |
2, !kFin, &spdy_response_headers_frame_length)); |
- // The headers have arrived, but they are delivered asynchronously. |
- EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), |
- IsError(ERR_IO_PENDING)); |
- EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
+ // The headers have already arrived. |
+ EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), IsOk()); |
ASSERT_TRUE(response_.headers.get()); |
EXPECT_EQ(200, response_.headers->response_code()); |
EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
@@ -1225,10 +1221,8 @@ TEST_P(QuicHttpStreamTest, SendChunkedPostRequest) { |
ProcessPacket(ConstructResponseHeadersPacket( |
2, !kFin, &spdy_response_headers_frame_length)); |
- // The headers have arrived, but they are delivered asynchronously |
- EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), |
- IsError(ERR_IO_PENDING)); |
- EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
+ // The headers have already arrived. |
+ EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), IsOk()); |
ASSERT_TRUE(response_.headers.get()); |
EXPECT_EQ(200, response_.headers->response_code()); |
EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
@@ -1298,10 +1292,8 @@ TEST_P(QuicHttpStreamTest, SendChunkedPostRequestWithFinalEmptyDataPacket) { |
ProcessPacket(ConstructResponseHeadersPacket( |
2, !kFin, &spdy_response_headers_frame_length)); |
- // The headers have arrived, but they are delivered asynchronously |
- EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), |
- IsError(ERR_IO_PENDING)); |
- EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
+ // The headers have already arrived. |
+ EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), IsOk()); |
ASSERT_TRUE(response_.headers.get()); |
EXPECT_EQ(200, response_.headers->response_code()); |
EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
@@ -1366,10 +1358,8 @@ TEST_P(QuicHttpStreamTest, SendChunkedPostRequestWithOneEmptyDataPacket) { |
ProcessPacket(ConstructResponseHeadersPacket( |
2, !kFin, &spdy_response_headers_frame_length)); |
- // The headers have arrived, but they are delivered asynchronously |
- EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), |
- IsError(ERR_IO_PENDING)); |
- EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
+ // The headers have already arrived. |
+ EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), IsOk()); |
ASSERT_TRUE(response_.headers.get()); |
EXPECT_EQ(200, response_.headers->response_code()); |
EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
@@ -1420,13 +1410,16 @@ TEST_P(QuicHttpStreamTest, DestroyedEarly) { |
// Ack the request. |
ProcessPacket(ConstructServerAckPacket(1, 0, 0, 0)); |
- EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), |
+ EXPECT_THAT(stream_->ReadResponseHeaders( |
+ base::Bind(&QuicHttpStreamTest::CloseStream, |
+ base::Unretained(this), stream_.get())), |
IsError(ERR_IO_PENDING)); |
// Send the response with a body. |
SetResponse("404 OK", "hello world!"); |
// In the course of processing this packet, the QuicHttpStream close itself. |
- ProcessPacket(ConstructResponseHeadersPacket(2, kFin, nullptr)); |
+ size_t response_size = 0; |
+ ProcessPacket(ConstructResponseHeadersPacket(2, kFin, &response_size)); |
base::RunLoop().RunUntilIdle(); |
@@ -1436,8 +1429,9 @@ TEST_P(QuicHttpStreamTest, DestroyedEarly) { |
// headers and payload. |
EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
stream_->GetTotalSentBytes()); |
- // Zero since the stream is closed before processing the headers. |
- EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
+ // The stream was closed after receiving the headers. |
+ EXPECT_EQ(static_cast<int64_t>(response_size), |
+ stream_->GetTotalReceivedBytes()); |
} |
TEST_P(QuicHttpStreamTest, Priority) { |
@@ -1448,7 +1442,6 @@ TEST_P(QuicHttpStreamTest, Priority) { |
AddWrite(InnerConstructRequestHeadersPacket( |
2, GetNthClientInitiatedStreamId(0), kIncludeVersion, kFin, MEDIUM, |
&spdy_request_headers_frame_length, &header_stream_offset)); |
- AddWrite(ConstructAckAndRstStreamPacket(3)); |
use_closing_stream_ = true; |
Initialize(); |
@@ -1478,10 +1471,10 @@ TEST_P(QuicHttpStreamTest, Priority) { |
// Send the response with a body. |
SetResponse("404 OK", "hello world!"); |
- // In the course of processing this packet, the QuicHttpStream close itself. |
- ProcessPacket(ConstructResponseHeadersPacket(2, kFin, nullptr)); |
+ size_t response_size = 0; |
+ ProcessPacket(ConstructResponseHeadersPacket(2, kFin, &response_size)); |
- base::RunLoop().RunUntilIdle(); |
+ EXPECT_EQ(OK, callback_.WaitForResult()); |
EXPECT_TRUE(AtEof()); |
@@ -1489,8 +1482,8 @@ TEST_P(QuicHttpStreamTest, Priority) { |
// headers and payload. |
EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
stream_->GetTotalSentBytes()); |
- // Zero since the stream is closed before processing the headers. |
- EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
+ EXPECT_EQ(static_cast<int64_t>(response_size), |
+ stream_->GetTotalReceivedBytes()); |
} |
// Regression test for http://crbug.com/294870 |