| 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 6a584f1800bd855a13464a54b7bad95daaa6c0ad..37242bf8cd0e2dcebbb4da808b99f4ae10260017 100644
|
| --- a/net/quic/quic_http_stream_test.cc
|
| +++ b/net/quic/quic_http_stream_test.cc
|
| @@ -19,6 +19,8 @@
|
| #include "net/quic/quic_client_session.h"
|
| #include "net/quic/quic_connection.h"
|
| #include "net/quic/quic_connection_helper.h"
|
| +#include "net/quic/quic_http_utils.h"
|
| +#include "net/quic/quic_reliable_client_stream.h"
|
| #include "net/quic/spdy_utils.h"
|
| #include "net/quic/test_tools/mock_clock.h"
|
| #include "net/quic/test_tools/mock_crypto_client_stream_factory.h"
|
| @@ -31,6 +33,7 @@
|
| #include "net/spdy/spdy_framer.h"
|
| #include "net/spdy/spdy_http_utils.h"
|
| #include "net/spdy/spdy_protocol.h"
|
| +#include "net/spdy/write_blocked_list.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -102,6 +105,14 @@ class AutoClosingStream : public QuicHttpStream {
|
|
|
| } // namespace
|
|
|
| +class QuicHttpStreamPeer {
|
| + public:
|
| + static QuicReliableClientStream* GetQuicReliableClientStream(
|
| + QuicHttpStream* stream) {
|
| + return stream->stream_;
|
| + }
|
| +};
|
| +
|
| class QuicHttpStreamTest : public ::testing::TestWithParam<bool> {
|
| protected:
|
| const static bool kFin = true;
|
| @@ -177,7 +188,7 @@ class QuicHttpStreamTest : public ::testing::TestWithParam<bool> {
|
| receive_algorithm_ = new TestReceiveAlgorithm(NULL);
|
| EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _, _)).
|
| Times(AnyNumber());
|
| - EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _)).Times(AnyNumber());
|
| + EXPECT_CALL(*send_algorithm_, SentPacket(_, _, _, _, _)).Times(AnyNumber());
|
| EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
|
| Return(QuicTime::Delta::Zero()));
|
| EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _, _)).
|
| @@ -206,14 +217,16 @@ class QuicHttpStreamTest : public ::testing::TestWithParam<bool> {
|
| new QuicHttpStream(session_->GetWeakPtr()));
|
| }
|
|
|
| - void SetRequestString(const std::string& method, const std::string& path) {
|
| + void SetRequestString(const std::string& method,
|
| + const std::string& path,
|
| + RequestPriority priority) {
|
| SpdyHeaderBlock headers;
|
| headers[":method"] = method;
|
| headers[":host"] = "www.google.com";
|
| headers[":path"] = path;
|
| headers[":scheme"] = "http";
|
| headers[":version"] = "HTTP/1.1";
|
| - request_data_ = SerializeHeaderBlock(headers, true);
|
| + request_data_ = SerializeHeaderBlock(headers, true, priority);
|
| }
|
|
|
| void SetResponseString(const std::string& status, const std::string& body) {
|
| @@ -221,14 +234,17 @@ class QuicHttpStreamTest : public ::testing::TestWithParam<bool> {
|
| headers[":status"] = status;
|
| headers[":version"] = "HTTP/1.1";
|
| headers["content-type"] = "text/plain";
|
| - response_data_ = SerializeHeaderBlock(headers, false) + body;
|
| + response_data_ = SerializeHeaderBlock(headers, false, DEFAULT_PRIORITY) +
|
| + body;
|
| }
|
|
|
| std::string SerializeHeaderBlock(const SpdyHeaderBlock& headers,
|
| - bool write_priority) {
|
| + bool write_priority,
|
| + RequestPriority priority) {
|
| QuicSpdyCompressor compressor;
|
| if (framer_.version() >= QUIC_VERSION_9 && write_priority) {
|
| - return compressor.CompressHeadersWithPriority(0, headers);
|
| + return compressor.CompressHeadersWithPriority(
|
| + ConvertRequestPriorityToQuicPriority(priority), headers);
|
| }
|
| return compressor.CompressHeaders(headers);
|
| }
|
| @@ -249,7 +265,7 @@ class QuicHttpStreamTest : public ::testing::TestWithParam<bool> {
|
| QuicEncryptedPacket* ConstructRstStreamPacket(
|
| QuicPacketSequenceNumber sequence_number) {
|
| InitializeHeader(sequence_number, false);
|
| - QuicRstStreamFrame frame(3, QUIC_SERVER_ERROR_PROCESSING_STREAM);
|
| + QuicRstStreamFrame frame(3, QUIC_ERROR_PROCESSING_STREAM);
|
| return ConstructPacket(header_, QuicFrame(&frame));
|
| }
|
|
|
| @@ -350,7 +366,7 @@ TEST_F(QuicHttpStreamTest, IsConnectionReusable) {
|
| }
|
|
|
| TEST_F(QuicHttpStreamTest, GetRequest) {
|
| - SetRequestString("GET", "/");
|
| + SetRequestString("GET", "/", DEFAULT_PRIORITY);
|
| AddWrite(SYNCHRONOUS, ConstructDataPacket(1, true, kFin, 0,
|
| request_data_));
|
| Initialize();
|
| @@ -393,7 +409,7 @@ TEST_F(QuicHttpStreamTest, GetRequest) {
|
|
|
| // Regression test for http://crbug.com/288128
|
| TEST_F(QuicHttpStreamTest, GetRequestLargeResponse) {
|
| - SetRequestString("GET", "/");
|
| + SetRequestString("GET", "/", DEFAULT_PRIORITY);
|
| AddWrite(SYNCHRONOUS, ConstructDataPacket(1, true, kFin, 0,
|
| request_data_));
|
| Initialize();
|
| @@ -440,7 +456,7 @@ TEST_F(QuicHttpStreamTest, GetRequestLargeResponse) {
|
| }
|
|
|
| TEST_F(QuicHttpStreamTest, GetRequestFullResponseInSinglePacket) {
|
| - SetRequestString("GET", "/");
|
| + SetRequestString("GET", "/", DEFAULT_PRIORITY);
|
| AddWrite(SYNCHRONOUS, ConstructDataPacket(1, true, kFin, 0, request_data_));
|
| Initialize();
|
|
|
| @@ -482,7 +498,7 @@ TEST_F(QuicHttpStreamTest, GetRequestFullResponseInSinglePacket) {
|
| }
|
|
|
| TEST_F(QuicHttpStreamTest, SendPostRequest) {
|
| - SetRequestString("POST", "/");
|
| + SetRequestString("POST", "/", DEFAULT_PRIORITY);
|
| AddWrite(SYNCHRONOUS, ConstructDataPacket(1, true, !kFin, 0, request_data_));
|
| AddWrite(SYNCHRONOUS, ConstructDataPacket(2, true, kFin,
|
| request_data_.length(),
|
| @@ -539,7 +555,7 @@ TEST_F(QuicHttpStreamTest, SendPostRequest) {
|
| }
|
|
|
| TEST_F(QuicHttpStreamTest, SendChunkedPostRequest) {
|
| - SetRequestString("POST", "/");
|
| + SetRequestString("POST", "/", DEFAULT_PRIORITY);
|
| size_t chunk_size = strlen(kUploadData);
|
| AddWrite(SYNCHRONOUS, ConstructDataPacket(1, true, !kFin, 0, request_data_));
|
| AddWrite(SYNCHRONOUS, ConstructDataPacket(2, true, !kFin,
|
| @@ -601,7 +617,7 @@ TEST_F(QuicHttpStreamTest, SendChunkedPostRequest) {
|
| }
|
|
|
| TEST_F(QuicHttpStreamTest, DestroyedEarly) {
|
| - SetRequestString("GET", "/");
|
| + SetRequestString("GET", "/", DEFAULT_PRIORITY);
|
| AddWrite(SYNCHRONOUS, ConstructDataPacket(1, true, kFin, 0, request_data_));
|
| AddWrite(SYNCHRONOUS, ConstructRstStreamPacket(2));
|
| use_closing_stream_ = true;
|
| @@ -613,9 +629,54 @@ TEST_F(QuicHttpStreamTest, DestroyedEarly) {
|
| EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
|
| net_log_, callback_.callback()));
|
| EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_,
|
| - callback_.callback()));
|
| + callback_.callback()));
|
| + EXPECT_EQ(&response_, stream_->GetResponseInfo());
|
| +
|
| + // Ack the request.
|
| + scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0, 0));
|
| + ProcessPacket(*ack);
|
| + EXPECT_EQ(ERR_IO_PENDING,
|
| + stream_->ReadResponseHeaders(callback_.callback()));
|
| +
|
| + // Send the response with a body.
|
| + SetResponseString("404 OK", "hello world!");
|
| + scoped_ptr<QuicEncryptedPacket> resp(
|
| + ConstructDataPacket(2, false, kFin, 0, response_data_));
|
| +
|
| + // In the course of processing this packet, the QuicHttpStream close itself.
|
| + ProcessPacket(*resp);
|
| +
|
| + EXPECT_TRUE(AtEof());
|
| +}
|
| +
|
| +TEST_F(QuicHttpStreamTest, Priority) {
|
| + SetRequestString("GET", "/", MEDIUM);
|
| + AddWrite(SYNCHRONOUS, ConstructDataPacket(1, true, kFin, 0, request_data_));
|
| + AddWrite(SYNCHRONOUS, ConstructRstStreamPacket(2));
|
| + use_closing_stream_ = true;
|
| + Initialize();
|
| +
|
| + request_.method = "GET";
|
| + request_.url = GURL("http://www.google.com/");
|
| +
|
| + EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM,
|
| + net_log_, callback_.callback()));
|
| +
|
| + // Check that priority is highest.
|
| + QuicReliableClientStream* reliable_stream =
|
| + QuicHttpStreamPeer::GetQuicReliableClientStream(stream_.get());
|
| + DCHECK(reliable_stream);
|
| + DCHECK_EQ(static_cast<QuicPriority>(kHighestPriority),
|
| + reliable_stream->EffectivePriority());
|
| +
|
| + EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_,
|
| + callback_.callback()));
|
| EXPECT_EQ(&response_, stream_->GetResponseInfo());
|
|
|
| + // Check that priority has now dropped back to MEDIUM.
|
| + DCHECK_EQ(MEDIUM, ConvertQuicPriorityToRequestPriority(
|
| + reliable_stream->EffectivePriority()));
|
| +
|
| // Ack the request.
|
| scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0, 0));
|
| ProcessPacket(*ack);
|
|
|