Chromium Code Reviews| Index: net/quic/quic_http_stream_test.cc |
| diff --git a/net/quic/quic_http_stream_test.cc b/net/quic/quic_http_stream_test.cc |
| index 932f566d4a525c7efbc299e83188c6fc7177028a..c99fa83d22ee160ad9c085a8f954ba0b270ccf65 100644 |
| --- a/net/quic/quic_http_stream_test.cc |
| +++ b/net/quic/quic_http_stream_test.cc |
| @@ -49,7 +49,7 @@ namespace net { |
| namespace test { |
| namespace { |
| -const char kUploadData[] = "hello world!"; |
| +const char kUploadData[] = "Really nifty data!"; |
|
mmenke
2014/08/21 20:52:35
Sending upload data of "hello world!" to get a res
Ryan Hamilton
2014/08/21 21:06:44
Good point.
|
| const char kServerHostname[] = "www.google.com"; |
| const uint16 kServerPort = 80; |
| @@ -526,6 +526,105 @@ TEST_P(QuicHttpStreamTest, SendChunkedPostRequest) { |
| EXPECT_TRUE(AtEof()); |
| } |
| +TEST_P(QuicHttpStreamTest, SendChunkedPostRequestWithFinalEmptyDataPacket) { |
| + SetRequest("POST", "/", DEFAULT_PRIORITY); |
| + size_t chunk_size = strlen(kUploadData); |
| + AddWrite(ConstructRequestHeadersPacket(1, !kFin)); |
| + AddWrite(ConstructDataPacket(2, kIncludeVersion, !kFin, 0, kUploadData)); |
| + AddWrite(ConstructDataPacket(3, kIncludeVersion, kFin, chunk_size, "")); |
| + AddWrite(ConstructAckPacket(4, 3, 1)); |
| + Initialize(); |
| + |
| + UploadDataStream upload_data_stream(UploadDataStream::CHUNKED, 0); |
| + upload_data_stream.AppendChunk(kUploadData, chunk_size, false); |
| + |
| + request_.method = "POST"; |
| + request_.url = GURL("http://www.google.com/"); |
| + request_.upload_data_stream = &upload_data_stream; |
| + ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback())); |
| + |
| + ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| + net_log_, callback_.callback())); |
| + ASSERT_EQ(ERR_IO_PENDING, stream_->SendRequest(headers_, &response_, |
| + callback_.callback())); |
| + |
| + upload_data_stream.AppendChunk(NULL, 0, true); |
| + |
| + // Ack all packets in the request. |
| + ProcessPacket(ConstructAckPacket(1, 0, 0)); |
| + |
| + // Send the response headers (but not the body). |
| + SetResponse("200 OK", std::string()); |
| + ProcessPacket(ConstructResponseHeadersPacket(2, !kFin)); |
| + |
| + // Since the headers have already arrived, this should return immediately. |
| + ASSERT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); |
| + ASSERT_TRUE(response_.headers.get()); |
| + EXPECT_EQ(200, response_.headers->response_code()); |
| + EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| + |
| + // Send the response body. |
| + const char kResponseBody[] = "Hello world!"; |
| + ProcessPacket(ConstructDataPacket(3, false, kFin, response_data_.length(), |
| + kResponseBody)); |
| + |
| + // Since the body has already arrived, this should return immediately. |
| + ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), |
| + stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| + callback_.callback())); |
| + |
| + EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| + EXPECT_TRUE(AtEof()); |
| +} |
| + |
| +TEST_P(QuicHttpStreamTest, SendChunkedPostRequestWithOneEmptyDataPacket) { |
| + SetRequest("POST", "/", DEFAULT_PRIORITY); |
| + AddWrite(ConstructRequestHeadersPacket(1, !kFin)); |
| + AddWrite(ConstructDataPacket(2, kIncludeVersion, kFin, 0, "")); |
| + AddWrite(ConstructAckPacket(3, 3, 1)); |
| + Initialize(); |
| + |
| + UploadDataStream upload_data_stream(UploadDataStream::CHUNKED, 0); |
| + |
| + request_.method = "POST"; |
| + request_.url = GURL("http://www.google.com/"); |
| + request_.upload_data_stream = &upload_data_stream; |
| + ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback())); |
| + |
| + ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| + net_log_, callback_.callback())); |
| + ASSERT_EQ(ERR_IO_PENDING, stream_->SendRequest(headers_, &response_, |
| + callback_.callback())); |
| + |
| + upload_data_stream.AppendChunk(NULL, 0, true); |
| + |
| + // Ack both packets in the request. |
| + ProcessPacket(ConstructAckPacket(1, 0, 0)); |
|
mmenke
2014/08/21 20:52:36
I really can't make sense of ConstructAckPacket's
Ryan Hamilton
2014/08/21 21:06:44
The second argument should be the sequence number
mmenke
2014/08/21 21:20:47
I tried that, but it results in a GMOCK warning, a
|
| + |
| + // Send the response headers (but not the body). |
| + SetResponse("200 OK", std::string()); |
| + ProcessPacket(ConstructResponseHeadersPacket(2, !kFin)); |
| + |
| + // Since the headers have already arrived, this should return immediately. |
| + ASSERT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); |
| + ASSERT_TRUE(response_.headers.get()); |
| + EXPECT_EQ(200, response_.headers->response_code()); |
| + EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| + |
| + // Send the response body. |
| + const char kResponseBody[] = "Hello world!"; |
| + ProcessPacket(ConstructDataPacket(3, false, kFin, response_data_.length(), |
| + kResponseBody)); |
| + |
| + // Since the body has already arrived, this should return immediately. |
| + ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), |
| + stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| + callback_.callback())); |
| + |
| + EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| + EXPECT_TRUE(AtEof()); |
| +} |
| + |
| TEST_P(QuicHttpStreamTest, DestroyedEarly) { |
| SetRequest("GET", "/", DEFAULT_PRIORITY); |
| AddWrite(ConstructRequestHeadersPacket(1, kFin)); |