blob: 0fe4a543b34409120ddb5b5367e0297fee2cee3f [file] [log] [blame]
[email protected]f702d572012-12-04 15:56:201// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "net/quic/quic_http_stream.h"
6
7#include <vector>
8
skyostil4891b25b2015-06-11 11:43:459#include "base/thread_task_runner_handle.h"
mmenkecbc2b712014-10-09 20:29:0710#include "net/base/chunked_upload_data_stream.h"
11#include "net/base/elements_upload_data_stream.h"
[email protected]f702d572012-12-04 15:56:2012#include "net/base/net_errors.h"
13#include "net/base/test_completion_callback.h"
[email protected]b2d26cfd2012-12-11 10:36:0614#include "net/base/upload_bytes_element_reader.h"
[email protected]f702d572012-12-04 15:56:2015#include "net/http/http_response_headers.h"
[email protected]5db452202014-08-19 05:22:1516#include "net/http/transport_security_state.h"
[email protected]fee17f72013-02-03 07:47:4117#include "net/quic/congestion_control/send_algorithm_interface.h"
[email protected]e8ff26842013-03-22 21:02:0518#include "net/quic/crypto/crypto_protocol.h"
[email protected]4df69842013-02-27 06:32:1619#include "net/quic/crypto/quic_decrypter.h"
20#include "net/quic/crypto/quic_encrypter.h"
[email protected]17bf15c2014-03-14 10:08:0421#include "net/quic/crypto/quic_server_info.h"
ckrasic4f9d88d2015-07-22 22:23:1622#include "net/quic/quic_chromium_client_session.h"
[email protected]f702d572012-12-04 15:56:2023#include "net/quic/quic_connection.h"
24#include "net/quic/quic_connection_helper.h"
[email protected]cbd731e2013-10-24 00:20:3925#include "net/quic/quic_default_packet_writer.h"
rtenneti6bd660b2015-07-18 00:19:5326#include "net/quic/quic_flags.h"
[email protected]24e5bc52013-09-18 15:36:5827#include "net/quic/quic_http_utils.h"
28#include "net/quic/quic_reliable_client_stream.h"
[email protected]9f0dcd4e2014-01-16 15:58:1429#include "net/quic/quic_write_blocked_list.h"
[email protected]3e7dca62013-09-10 16:14:2330#include "net/quic/spdy_utils.h"
[email protected]f702d572012-12-04 15:56:2031#include "net/quic/test_tools/mock_clock.h"
[email protected]e8ff26842013-03-22 21:02:0532#include "net/quic/test_tools/mock_crypto_client_stream_factory.h"
[email protected]9db443912013-02-25 05:27:0333#include "net/quic/test_tools/mock_random.h"
[email protected]b1f287d2012-12-22 17:25:3934#include "net/quic/test_tools/quic_connection_peer.h"
[email protected]1e960032013-12-20 19:00:2035#include "net/quic/test_tools/quic_test_packet_maker.h"
[email protected]f702d572012-12-04 15:56:2036#include "net/quic/test_tools/quic_test_utils.h"
37#include "net/quic/test_tools/test_task_runner.h"
38#include "net/socket/socket_test_util.h"
[email protected]6cca996b2013-01-25 07:43:3639#include "net/spdy/spdy_frame_builder.h"
40#include "net/spdy/spdy_framer.h"
41#include "net/spdy/spdy_http_utils.h"
42#include "net/spdy/spdy_protocol.h"
[email protected]f702d572012-12-04 15:56:2043#include "testing/gmock/include/gmock/gmock.h"
44#include "testing/gtest/include/gtest/gtest.h"
45
46using testing::_;
[email protected]06ff5152013-08-29 01:03:0547using testing::AnyNumber;
48using testing::Return;
[email protected]f702d572012-12-04 15:56:2049
50namespace net {
[email protected]f702d572012-12-04 15:56:2051namespace test {
[email protected]f702d572012-12-04 15:56:2052namespace {
53
[email protected]16ba7742014-08-22 00:57:2554const char kUploadData[] = "Really nifty data!";
bncb07c05532015-05-14 19:07:2055const char kDefaultServerHostName[] = "www.google.com";
56const uint16 kDefaultServerPort = 80;
[email protected]f702d572012-12-04 15:56:2057
58class TestQuicConnection : public QuicConnection {
59 public:
[email protected]1e960032013-12-20 19:00:2060 TestQuicConnection(const QuicVersionVector& versions,
[email protected]3aa9ca72014-02-27 19:39:4361 QuicConnectionId connection_id,
[email protected]f702d572012-12-04 15:56:2062 IPEndPoint address,
[email protected]cbd731e2013-10-24 00:20:3963 QuicConnectionHelper* helper,
[email protected]6d515822014-08-22 01:58:0664 const QuicConnection::PacketWriterFactory& writer_factory)
[email protected]66cd2d62014-08-01 18:42:3965 : QuicConnection(connection_id,
66 address,
67 helper,
[email protected]6d515822014-08-22 01:58:0668 writer_factory,
rtenneti6f48aa92015-03-16 02:18:4869 true /* owns_writer */,
70 Perspective::IS_CLIENT,
71 false /* is_secure */,
72 versions) {}
[email protected]f702d572012-12-04 15:56:2073
[email protected]fee17f72013-02-03 07:47:4174 void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) {
75 QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm);
[email protected]f702d572012-12-04 15:56:2076 }
77};
78
[email protected]63534512012-12-23 18:49:0079// Subclass of QuicHttpStream that closes itself when the first piece of data
80// is received.
81class AutoClosingStream : public QuicHttpStream {
82 public:
ckrasic4f9d88d2015-07-22 22:23:1683 explicit AutoClosingStream(
84 const base::WeakPtr<QuicChromiumClientSession>& session)
85 : QuicHttpStream(session) {}
[email protected]63534512012-12-23 18:49:0086
rchb27683c2015-07-29 23:53:5087 void OnHeadersAvailable(const SpdyHeaderBlock& headers) override {
[email protected]63534512012-12-23 18:49:0088 Close(false);
[email protected]63534512012-12-23 18:49:0089 }
rchb27683c2015-07-29 23:53:5090
91 void OnDataAvailable() override { Close(false); }
[email protected]63534512012-12-23 18:49:0092};
93
[email protected]6d515822014-08-22 01:58:0694class TestPacketWriterFactory : public QuicConnection::PacketWriterFactory {
95 public:
96 explicit TestPacketWriterFactory(DatagramClientSocket* socket)
97 : socket_(socket) {}
dchengb03027d2014-10-21 12:00:2098 ~TestPacketWriterFactory() override {}
[email protected]6d515822014-08-22 01:58:0699
dchengb03027d2014-10-21 12:00:20100 QuicPacketWriter* Create(QuicConnection* connection) const override {
[email protected]6d515822014-08-22 01:58:06101 return new QuicDefaultPacketWriter(socket_);
102 }
103
104 private:
105 DatagramClientSocket* socket_;
106};
107
[email protected]f702d572012-12-04 15:56:20108} // namespace
109
[email protected]24e5bc52013-09-18 15:36:58110class QuicHttpStreamPeer {
111 public:
112 static QuicReliableClientStream* GetQuicReliableClientStream(
113 QuicHttpStream* stream) {
114 return stream->stream_;
115 }
116};
117
[email protected]1e960032013-12-20 19:00:20118class QuicHttpStreamTest : public ::testing::TestWithParam<QuicVersion> {
[email protected]f702d572012-12-04 15:56:20119 protected:
[email protected]1e960032013-12-20 19:00:20120 static const bool kFin = true;
121 static const bool kIncludeVersion = true;
122 static const bool kIncludeCongestionFeedback = true;
123
[email protected]f702d572012-12-04 15:56:20124 // Holds a packet to be written to the wire, and the IO mode that should
125 // be used by the mock socket when performing the write.
126 struct PacketToWrite {
127 PacketToWrite(IoMode mode, QuicEncryptedPacket* packet)
128 : mode(mode),
129 packet(packet) {
130 }
131 IoMode mode;
132 QuicEncryptedPacket* packet;
133 };
134
135 QuicHttpStreamTest()
136 : net_log_(BoundNetLog()),
[email protected]63534512012-12-23 18:49:00137 use_closing_stream_(false),
[email protected]f702d572012-12-04 15:56:20138 read_buffer_(new IOBufferWithSize(4096)),
[email protected]3aa9ca72014-02-27 19:39:43139 connection_id_(2),
[email protected]66ae5962014-05-22 11:13:05140 stream_id_(kClientDataStreamId1),
bncb07c05532015-05-14 19:07:20141 maker_(GetParam(), connection_id_, &clock_, kDefaultServerHostName),
[email protected]1e960032013-12-20 19:00:20142 random_generator_(0) {
[email protected]f702d572012-12-04 15:56:20143 IPAddressNumber ip;
144 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip));
145 peer_addr_ = IPEndPoint(ip, 443);
146 self_addr_ = IPEndPoint(ip, 8435);
rtenneti4b06ae72014-08-26 03:43:43147 clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(20));
[email protected]f702d572012-12-04 15:56:20148 }
149
150 ~QuicHttpStreamTest() {
rtenneti85dcfac22015-03-27 20:22:19151 session_->CloseSessionOnError(ERR_ABORTED, QUIC_INTERNAL_ERROR);
[email protected]f702d572012-12-04 15:56:20152 for (size_t i = 0; i < writes_.size(); i++) {
153 delete writes_[i].packet;
154 }
155 }
156
157 // Adds a packet to the list of expected writes.
[email protected]1e960032013-12-20 19:00:20158 void AddWrite(scoped_ptr<QuicEncryptedPacket> packet) {
159 writes_.push_back(PacketToWrite(SYNCHRONOUS, packet.release()));
[email protected]f702d572012-12-04 15:56:20160 }
161
162 // Returns the packet to be written at position |pos|.
163 QuicEncryptedPacket* GetWrite(size_t pos) {
164 return writes_[pos].packet;
165 }
166
167 bool AtEof() {
rch37de576c2015-05-17 20:28:17168 return socket_data_->AllReadDataConsumed() &&
169 socket_data_->AllWriteDataConsumed();
[email protected]f702d572012-12-04 15:56:20170 }
171
[email protected]1e960032013-12-20 19:00:20172 void ProcessPacket(scoped_ptr<QuicEncryptedPacket> packet) {
173 connection_->ProcessUdpPacket(self_addr_, peer_addr_, *packet);
[email protected]f702d572012-12-04 15:56:20174 }
175
176 // Configures the test fixture to use the list of expected writes.
177 void Initialize() {
178 mock_writes_.reset(new MockWrite[writes_.size()]);
179 for (size_t i = 0; i < writes_.size(); i++) {
180 mock_writes_[i] = MockWrite(writes_[i].mode,
181 writes_[i].packet->data(),
182 writes_[i].packet->length());
183 };
184
rtennetibe635732014-10-02 22:51:42185 socket_data_.reset(new StaticSocketDataProvider(
186 nullptr, 0, mock_writes_.get(), writes_.size()));
[email protected]f702d572012-12-04 15:56:20187
[email protected]e13201d82012-12-12 05:00:32188 MockUDPClientSocket* socket = new MockUDPClientSocket(socket_data_.get(),
189 net_log_.net_log());
190 socket->Connect(peer_addr_);
[email protected]f702d572012-12-04 15:56:20191 runner_ = new TestTaskRunner(&clock_);
[email protected]fee17f72013-02-03 07:47:41192 send_algorithm_ = new MockSendAlgorithm();
rch7dd15702015-07-01 18:57:57193 EXPECT_CALL(*send_algorithm_, InRecovery()).WillRepeatedly(Return(false));
194 EXPECT_CALL(*send_algorithm_, InSlowStart()).WillRepeatedly(Return(false));
[email protected]efecff92013-09-24 07:49:23195 EXPECT_CALL(*send_algorithm_,
[email protected]ef0da582014-05-09 07:16:30196 OnPacketSent(_, _, _, _, _)).WillRepeatedly(Return(true));
[email protected]48878092013-07-26 14:51:56197 EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly(
[email protected]06ff5152013-08-29 01:03:05198 Return(QuicTime::Delta::Zero()));
[email protected]08da9adb2014-04-24 08:33:31199 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly(
200 Return(kMaxPacketSize));
[email protected]77b5d50b2014-05-07 22:48:48201 EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)).
[email protected]06ff5152013-08-29 01:03:05202 WillRepeatedly(Return(QuicTime::Delta::Zero()));
[email protected]ea825e02013-08-21 18:12:45203 EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly(
[email protected]06ff5152013-08-29 01:03:05204 Return(QuicBandwidth::Zero()));
rch1e543ec2015-03-29 07:04:40205 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber());
[email protected]2cfc6bb82013-10-27 03:40:44206 helper_.reset(new QuicConnectionHelper(runner_.get(), &clock_,
207 &random_generator_));
[email protected]6d515822014-08-22 01:58:06208 TestPacketWriterFactory writer_factory(socket);
[email protected]3aa9ca72014-02-27 19:39:43209 connection_ = new TestQuicConnection(SupportedVersions(GetParam()),
210 connection_id_, peer_addr_,
[email protected]6d515822014-08-22 01:58:06211 helper_.get(), writer_factory);
[email protected]f702d572012-12-04 15:56:20212 connection_->set_visitor(&visitor_);
[email protected]fee17f72013-02-03 07:47:41213 connection_->SetSendAlgorithm(send_algorithm_);
ckrasic4f9d88d2015-07-22 22:23:16214 session_.reset(new QuicChromiumClientSession(
rtennetid39bd762015-06-12 01:05:52215 connection_, scoped_ptr<DatagramClientSocket>(socket),
216 /*stream_factory=*/nullptr, &crypto_client_stream_factory_,
rtenneti041b2992015-02-23 23:03:28217 &transport_security_state_, make_scoped_ptr((QuicServerInfo*)nullptr),
bncb07c05532015-05-14 19:07:20218 QuicServerId(kDefaultServerHostName, kDefaultServerPort,
219 /*is_secure=*/false, PRIVACY_MODE_DISABLED),
rtennetia75df622015-06-21 23:59:50220 /*cert_verify_flags=*/0, DefaultQuicConfig(), &crypto_config_,
221 "CONNECTION_UNKNOWN", base::TimeTicks::Now(),
222 base::ThreadTaskRunnerHandle::Get().get(), nullptr));
rtennetid39bd762015-06-12 01:05:52223 session_->Initialize();
[email protected]ed3fc15d2013-03-08 18:37:44224 session_->GetCryptoStream()->CryptoConnect();
[email protected]8ba81212013-05-03 13:11:48225 EXPECT_TRUE(session_->IsCryptoHandshakeConfirmed());
[email protected]6cca996b2013-01-25 07:43:36226 stream_.reset(use_closing_stream_ ?
[email protected]0b2294d32013-08-02 00:46:36227 new AutoClosingStream(session_->GetWeakPtr()) :
228 new QuicHttpStream(session_->GetWeakPtr()));
[email protected]6cca996b2013-01-25 07:43:36229 }
230
[email protected]1e960032013-12-20 19:00:20231 void SetRequest(const std::string& method,
232 const std::string& path,
233 RequestPriority priority) {
234 request_headers_ = maker_.GetRequestHeaders(method, "http", path);
[email protected]6cca996b2013-01-25 07:43:36235 }
236
[email protected]1e960032013-12-20 19:00:20237 void SetResponse(const std::string& status, const std::string& body) {
238 response_headers_ = maker_.GetResponseHeaders(status);
[email protected]92bf17c2014-03-03 21:14:03239 response_data_ = body;
[email protected]6cca996b2013-01-25 07:43:36240 }
[email protected]f702d572012-12-04 15:56:20241
[email protected]1e960032013-12-20 19:00:20242 scoped_ptr<QuicEncryptedPacket> ConstructDataPacket(
[email protected]f702d572012-12-04 15:56:20243 QuicPacketSequenceNumber sequence_number,
[email protected]e8ff26842013-03-22 21:02:05244 bool should_include_version,
[email protected]f702d572012-12-04 15:56:20245 bool fin,
246 QuicStreamOffset offset,
247 base::StringPiece data) {
rtennetif4bdb542015-01-21 14:33:05248 return maker_.MakeDataPacket(sequence_number, stream_id_,
249 should_include_version, fin, offset, data);
[email protected]f702d572012-12-04 15:56:20250 }
251
[email protected]1e960032013-12-20 19:00:20252 scoped_ptr<QuicEncryptedPacket> ConstructRequestHeadersPacket(
253 QuicPacketSequenceNumber sequence_number,
rtennetif4bdb542015-01-21 14:33:05254 bool fin,
255 RequestPriority request_priority) {
256 QuicPriority priority =
257 ConvertRequestPriorityToQuicPriority(request_priority);
258 return maker_.MakeRequestHeadersPacket(sequence_number, stream_id_,
259 kIncludeVersion, fin, priority,
260 request_headers_);
[email protected]1e960032013-12-20 19:00:20261 }
262
263 scoped_ptr<QuicEncryptedPacket> ConstructResponseHeadersPacket(
264 QuicPacketSequenceNumber sequence_number,
265 bool fin) {
266 return maker_.MakeResponseHeadersPacket(
267 sequence_number, stream_id_, !kIncludeVersion, fin, response_headers_);
268 }
269
270 scoped_ptr<QuicEncryptedPacket> ConstructRstStreamPacket(
[email protected]06ff5152013-08-29 01:03:05271 QuicPacketSequenceNumber sequence_number) {
[email protected]1e960032013-12-20 19:00:20272 return maker_.MakeRstPacket(
[email protected]51cc1342014-04-18 23:44:37273 sequence_number, true, stream_id_,
rtenneti4a5df262014-11-07 00:43:58274 AdjustErrorForVersion(QUIC_RST_ACKNOWLEDGEMENT, GetParam()));
[email protected]06ff5152013-08-29 01:03:05275 }
276
rtenneti6bd660b2015-07-18 00:19:53277 scoped_ptr<QuicEncryptedPacket> ConstructRstStreamCancelledPacket(
278 QuicPacketSequenceNumber sequence_number) {
279 return maker_.MakeRstPacket(sequence_number, !kIncludeVersion, stream_id_,
280 QUIC_STREAM_CANCELLED);
281 }
282
[email protected]c5e1aca2014-01-30 04:03:04283 scoped_ptr<QuicEncryptedPacket> ConstructAckAndRstStreamPacket(
284 QuicPacketSequenceNumber sequence_number) {
285 return maker_.MakeAckAndRstPacket(
286 sequence_number, !kIncludeVersion, stream_id_, QUIC_STREAM_CANCELLED,
[email protected]08da9adb2014-04-24 08:33:31287 2, 1, !kIncludeCongestionFeedback);
[email protected]c5e1aca2014-01-30 04:03:04288 }
289
[email protected]1e960032013-12-20 19:00:20290 scoped_ptr<QuicEncryptedPacket> ConstructAckPacket(
[email protected]f702d572012-12-04 15:56:20291 QuicPacketSequenceNumber sequence_number,
[email protected]63534512012-12-23 18:49:00292 QuicPacketSequenceNumber largest_received,
293 QuicPacketSequenceNumber least_unacked) {
[email protected]1e960032013-12-20 19:00:20294 return maker_.MakeAckPacket(sequence_number, largest_received,
295 least_unacked, !kIncludeCongestionFeedback);
[email protected]63534512012-12-23 18:49:00296 }
297
[email protected]f702d572012-12-04 15:56:20298 BoundNetLog net_log_;
[email protected]63534512012-12-23 18:49:00299 bool use_closing_stream_;
[email protected]fee17f72013-02-03 07:47:41300 MockSendAlgorithm* send_algorithm_;
[email protected]f702d572012-12-04 15:56:20301 scoped_refptr<TestTaskRunner> runner_;
[email protected]4356f0f2013-04-07 00:58:17302 scoped_ptr<MockWrite[]> mock_writes_;
[email protected]f702d572012-12-04 15:56:20303 MockClock clock_;
304 TestQuicConnection* connection_;
[email protected]2cfc6bb82013-10-27 03:40:44305 scoped_ptr<QuicConnectionHelper> helper_;
[email protected]f702d572012-12-04 15:56:20306 testing::StrictMock<MockConnectionVisitor> visitor_;
307 scoped_ptr<QuicHttpStream> stream_;
[email protected]5db452202014-08-19 05:22:15308 TransportSecurityState transport_security_state_;
ckrasic4f9d88d2015-07-22 22:23:16309 scoped_ptr<QuicChromiumClientSession> session_;
[email protected]ef95114d2013-04-17 17:57:01310 QuicCryptoClientConfig crypto_config_;
[email protected]f702d572012-12-04 15:56:20311 TestCompletionCallback callback_;
312 HttpRequestInfo request_;
313 HttpRequestHeaders headers_;
314 HttpResponseInfo response_;
315 scoped_refptr<IOBufferWithSize> read_buffer_;
[email protected]1e960032013-12-20 19:00:20316 SpdyHeaderBlock request_headers_;
317 SpdyHeaderBlock response_headers_;
[email protected]6cca996b2013-01-25 07:43:36318 std::string request_data_;
319 std::string response_data_;
[email protected]f702d572012-12-04 15:56:20320
321 private:
[email protected]3aa9ca72014-02-27 19:39:43322 const QuicConnectionId connection_id_;
[email protected]1e960032013-12-20 19:00:20323 const QuicStreamId stream_id_;
324 QuicTestPacketMaker maker_;
[email protected]f702d572012-12-04 15:56:20325 IPEndPoint self_addr_;
326 IPEndPoint peer_addr_;
[email protected]457d6952013-12-13 09:24:58327 MockRandom random_generator_;
[email protected]e8ff26842013-03-22 21:02:05328 MockCryptoClientStreamFactory crypto_client_stream_factory_;
[email protected]f702d572012-12-04 15:56:20329 scoped_ptr<StaticSocketDataProvider> socket_data_;
330 std::vector<PacketToWrite> writes_;
331};
332
[email protected]1e960032013-12-20 19:00:20333INSTANTIATE_TEST_CASE_P(Version, QuicHttpStreamTest,
334 ::testing::ValuesIn(QuicSupportedVersions()));
335
336TEST_P(QuicHttpStreamTest, RenewStreamForAuth) {
[email protected]ed3fc15d2013-03-08 18:37:44337 Initialize();
rtennetibe635732014-10-02 22:51:42338 EXPECT_EQ(nullptr, stream_->RenewStreamForAuth());
[email protected]f702d572012-12-04 15:56:20339}
340
[email protected]1e960032013-12-20 19:00:20341TEST_P(QuicHttpStreamTest, CanFindEndOfResponse) {
[email protected]ed3fc15d2013-03-08 18:37:44342 Initialize();
[email protected]f702d572012-12-04 15:56:20343 EXPECT_TRUE(stream_->CanFindEndOfResponse());
344}
345
[email protected]1e960032013-12-20 19:00:20346TEST_P(QuicHttpStreamTest, IsConnectionReusable) {
[email protected]ed3fc15d2013-03-08 18:37:44347 Initialize();
[email protected]f702d572012-12-04 15:56:20348 EXPECT_FALSE(stream_->IsConnectionReusable());
349}
350
[email protected]1e960032013-12-20 19:00:20351TEST_P(QuicHttpStreamTest, GetRequest) {
352 SetRequest("GET", "/", DEFAULT_PRIORITY);
rtennetif4bdb542015-01-21 14:33:05353 AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY));
[email protected]f702d572012-12-04 15:56:20354 Initialize();
355
356 request_.method = "GET";
357 request_.url = GURL("http://www.google.com/");
358
[email protected]262eec82013-03-19 21:01:36359 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
360 net_log_, callback_.callback()));
[email protected]f702d572012-12-04 15:56:20361 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_,
362 callback_.callback()));
[email protected]f702d572012-12-04 15:56:20363
364 // Ack the request.
[email protected]1e960032013-12-20 19:00:20365 ProcessPacket(ConstructAckPacket(1, 0, 0));
[email protected]f702d572012-12-04 15:56:20366
367 EXPECT_EQ(ERR_IO_PENDING,
368 stream_->ReadResponseHeaders(callback_.callback()));
369
[email protected]1e960032013-12-20 19:00:20370 SetResponse("404 Not Found", std::string());
[email protected]92bf17c2014-03-03 21:14:03371 ProcessPacket(ConstructResponseHeadersPacket(2, kFin));
[email protected]f702d572012-12-04 15:56:20372
373 // Now that the headers have been processed, the callback will return.
374 EXPECT_EQ(OK, callback_.WaitForResult());
[email protected]cadac622013-06-11 16:46:36375 ASSERT_TRUE(response_.headers.get());
[email protected]f702d572012-12-04 15:56:20376 EXPECT_EQ(404, response_.headers->response_code());
377 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
[email protected]6ed67432014-06-24 01:53:53378 EXPECT_FALSE(response_.response_time.is_null());
379 EXPECT_FALSE(response_.request_time.is_null());
[email protected]f702d572012-12-04 15:56:20380
381 // There is no body, so this should return immediately.
382 EXPECT_EQ(0, stream_->ReadResponseBody(read_buffer_.get(),
383 read_buffer_->size(),
384 callback_.callback()));
385 EXPECT_TRUE(stream_->IsResponseBodyComplete());
386 EXPECT_TRUE(AtEof());
387}
388
[email protected]3e7dca62013-09-10 16:14:23389// Regression test for http://crbug.com/288128
[email protected]1e960032013-12-20 19:00:20390TEST_P(QuicHttpStreamTest, GetRequestLargeResponse) {
391 SetRequest("GET", "/", DEFAULT_PRIORITY);
rtennetif4bdb542015-01-21 14:33:05392 AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY));
[email protected]3e7dca62013-09-10 16:14:23393 Initialize();
394
395 request_.method = "GET";
396 request_.url = GURL("http://www.google.com/");
397
398 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
399 net_log_, callback_.callback()));
400 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_,
401 callback_.callback()));
[email protected]3e7dca62013-09-10 16:14:23402
403 // Ack the request.
[email protected]1e960032013-12-20 19:00:20404 ProcessPacket(ConstructAckPacket(1, 0, 0));
[email protected]3e7dca62013-09-10 16:14:23405
406 EXPECT_EQ(ERR_IO_PENDING,
407 stream_->ReadResponseHeaders(callback_.callback()));
408
409 SpdyHeaderBlock headers;
410 headers[":status"] = "200 OK";
411 headers[":version"] = "HTTP/1.1";
412 headers["content-type"] = "text/plain";
rch7dd15702015-07-01 18:57:57413 headers["big6"] = std::string(1000, 'x'); // Lots of x's.
[email protected]3e7dca62013-09-10 16:14:23414
rch7dd15702015-07-01 18:57:57415 response_headers_ = headers;
416 ProcessPacket(ConstructResponseHeadersPacket(2, kFin));
[email protected]3e7dca62013-09-10 16:14:23417
418 // Now that the headers have been processed, the callback will return.
419 EXPECT_EQ(OK, callback_.WaitForResult());
420 ASSERT_TRUE(response_.headers.get());
421 EXPECT_EQ(200, response_.headers->response_code());
422 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
423
424 // There is no body, so this should return immediately.
425 EXPECT_EQ(0, stream_->ReadResponseBody(read_buffer_.get(),
426 read_buffer_->size(),
427 callback_.callback()));
428 EXPECT_TRUE(stream_->IsResponseBodyComplete());
429 EXPECT_TRUE(AtEof());
430}
431
rchf9f103cbc2014-08-30 05:28:04432// Regression test for http://crbug.com/409101
433TEST_P(QuicHttpStreamTest, SessionClosedBeforeSendRequest) {
434 SetRequest("GET", "/", DEFAULT_PRIORITY);
435 Initialize();
436
437 request_.method = "GET";
438 request_.url = GURL("http://www.google.com/");
439
440 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
441 net_log_, callback_.callback()));
442
443 session_->connection()->CloseConnection(QUIC_NO_ERROR, true);
444
445 EXPECT_EQ(ERR_CONNECTION_CLOSED,
446 stream_->SendRequest(headers_, &response_,
447 callback_.callback()));
448}
449
rch11a114a2014-09-04 23:41:59450// Regression test for http://crbug.com/409871
451TEST_P(QuicHttpStreamTest, SessionClosedBeforeReadResponseHeaders) {
452 SetRequest("GET", "/", DEFAULT_PRIORITY);
rtennetif4bdb542015-01-21 14:33:05453 AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY));
rch11a114a2014-09-04 23:41:59454 Initialize();
455
456 request_.method = "GET";
457 request_.url = GURL("http://www.google.com/");
458
459 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
460 net_log_, callback_.callback()));
461
462 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_,
463 callback_.callback()));
464
465 session_->connection()->CloseConnection(QUIC_NO_ERROR, true);
466
467 EXPECT_NE(OK, stream_->ReadResponseHeaders(callback_.callback()));
468}
469
[email protected]1e960032013-12-20 19:00:20470TEST_P(QuicHttpStreamTest, SendPostRequest) {
471 SetRequest("POST", "/", DEFAULT_PRIORITY);
rtennetif4bdb542015-01-21 14:33:05472 AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY));
[email protected]92bf17c2014-03-03 21:14:03473 AddWrite(ConstructDataPacket(2, kIncludeVersion, kFin, 0, kUploadData));
[email protected]1e960032013-12-20 19:00:20474 AddWrite(ConstructAckPacket(3, 3, 1));
[email protected]f702d572012-12-04 15:56:20475
476 Initialize();
477
[email protected]b2d26cfd2012-12-11 10:36:06478 ScopedVector<UploadElementReader> element_readers;
479 element_readers.push_back(
480 new UploadBytesElementReader(kUploadData, strlen(kUploadData)));
mmenkecbc2b712014-10-09 20:29:07481 ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0);
[email protected]f702d572012-12-04 15:56:20482 request_.method = "POST";
483 request_.url = GURL("http://www.google.com/");
484 request_.upload_data_stream = &upload_data_stream;
[email protected]4db27d82012-12-20 11:50:24485 ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback()));
[email protected]f702d572012-12-04 15:56:20486
[email protected]262eec82013-03-19 21:01:36487 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
488 net_log_, callback_.callback()));
[email protected]f702d572012-12-04 15:56:20489 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_,
490 callback_.callback()));
[email protected]f702d572012-12-04 15:56:20491
492 // Ack both packets in the request.
[email protected]1e960032013-12-20 19:00:20493 ProcessPacket(ConstructAckPacket(1, 0, 0));
[email protected]f702d572012-12-04 15:56:20494
495 // Send the response headers (but not the body).
[email protected]1e960032013-12-20 19:00:20496 SetResponse("200 OK", std::string());
[email protected]92bf17c2014-03-03 21:14:03497 ProcessPacket(ConstructResponseHeadersPacket(2, !kFin));
[email protected]f702d572012-12-04 15:56:20498
rchb27683c2015-07-29 23:53:50499 // The headers have arrived, but they are delivered asynchronously.
500 EXPECT_EQ(ERR_IO_PENDING, stream_->ReadResponseHeaders(callback_.callback()));
501 EXPECT_EQ(OK, callback_.WaitForResult());
[email protected]cadac622013-06-11 16:46:36502 ASSERT_TRUE(response_.headers.get());
[email protected]f702d572012-12-04 15:56:20503 EXPECT_EQ(200, response_.headers->response_code());
504 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
505
506 // Send the response body.
507 const char kResponseBody[] = "Hello world!";
[email protected]92bf17c2014-03-03 21:14:03508 ProcessPacket(ConstructDataPacket(3, false, kFin, 0, kResponseBody));
[email protected]f702d572012-12-04 15:56:20509 // Since the body has already arrived, this should return immediately.
510 EXPECT_EQ(static_cast<int>(strlen(kResponseBody)),
511 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(),
512 callback_.callback()));
513
514 EXPECT_TRUE(stream_->IsResponseBodyComplete());
515 EXPECT_TRUE(AtEof());
516}
517
[email protected]1e960032013-12-20 19:00:20518TEST_P(QuicHttpStreamTest, SendChunkedPostRequest) {
519 SetRequest("POST", "/", DEFAULT_PRIORITY);
[email protected]c9e49a02013-02-26 05:56:47520 size_t chunk_size = strlen(kUploadData);
rtennetif4bdb542015-01-21 14:33:05521 AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY));
[email protected]92bf17c2014-03-03 21:14:03522 AddWrite(ConstructDataPacket(2, kIncludeVersion, !kFin, 0, kUploadData));
523 AddWrite(ConstructDataPacket(3, kIncludeVersion, kFin, chunk_size,
524 kUploadData));
[email protected]1e960032013-12-20 19:00:20525 AddWrite(ConstructAckPacket(4, 3, 1));
[email protected]c9e49a02013-02-26 05:56:47526 Initialize();
527
mmenkecbc2b712014-10-09 20:29:07528 ChunkedUploadDataStream upload_data_stream(0);
529 upload_data_stream.AppendData(kUploadData, chunk_size, false);
[email protected]c9e49a02013-02-26 05:56:47530
531 request_.method = "POST";
532 request_.url = GURL("http://www.google.com/");
533 request_.upload_data_stream = &upload_data_stream;
mmenkecbc2b712014-10-09 20:29:07534 ASSERT_EQ(OK, request_.upload_data_stream->Init(
535 TestCompletionCallback().callback()));
[email protected]c9e49a02013-02-26 05:56:47536
[email protected]262eec82013-03-19 21:01:36537 ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
538 net_log_, callback_.callback()));
[email protected]c9e49a02013-02-26 05:56:47539 ASSERT_EQ(ERR_IO_PENDING, stream_->SendRequest(headers_, &response_,
540 callback_.callback()));
[email protected]c9e49a02013-02-26 05:56:47541
mmenkecbc2b712014-10-09 20:29:07542 upload_data_stream.AppendData(kUploadData, chunk_size, true);
rchb27683c2015-07-29 23:53:50543 EXPECT_EQ(OK, callback_.WaitForResult());
[email protected]c9e49a02013-02-26 05:56:47544
545 // Ack both packets in the request.
[email protected]1e960032013-12-20 19:00:20546 ProcessPacket(ConstructAckPacket(1, 0, 0));
[email protected]c9e49a02013-02-26 05:56:47547
548 // Send the response headers (but not the body).
[email protected]1e960032013-12-20 19:00:20549 SetResponse("200 OK", std::string());
[email protected]92bf17c2014-03-03 21:14:03550 ProcessPacket(ConstructResponseHeadersPacket(2, !kFin));
[email protected]c9e49a02013-02-26 05:56:47551
rchb27683c2015-07-29 23:53:50552 // The headers have arrived, but they are delivered asynchronously
553 EXPECT_EQ(ERR_IO_PENDING, stream_->ReadResponseHeaders(callback_.callback()));
554 EXPECT_EQ(OK, callback_.WaitForResult());
[email protected]cadac622013-06-11 16:46:36555 ASSERT_TRUE(response_.headers.get());
[email protected]c9e49a02013-02-26 05:56:47556 EXPECT_EQ(200, response_.headers->response_code());
557 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
558
559 // Send the response body.
560 const char kResponseBody[] = "Hello world!";
[email protected]1e960032013-12-20 19:00:20561 ProcessPacket(ConstructDataPacket(3, false, kFin, response_data_.length(),
562 kResponseBody));
[email protected]c9e49a02013-02-26 05:56:47563
564 // Since the body has already arrived, this should return immediately.
565 ASSERT_EQ(static_cast<int>(strlen(kResponseBody)),
566 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(),
567 callback_.callback()));
568
569 EXPECT_TRUE(stream_->IsResponseBodyComplete());
570 EXPECT_TRUE(AtEof());
571}
572
[email protected]16ba7742014-08-22 00:57:25573TEST_P(QuicHttpStreamTest, SendChunkedPostRequestWithFinalEmptyDataPacket) {
574 SetRequest("POST", "/", DEFAULT_PRIORITY);
575 size_t chunk_size = strlen(kUploadData);
rtennetif4bdb542015-01-21 14:33:05576 AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY));
[email protected]16ba7742014-08-22 00:57:25577 AddWrite(ConstructDataPacket(2, kIncludeVersion, !kFin, 0, kUploadData));
578 AddWrite(ConstructDataPacket(3, kIncludeVersion, kFin, chunk_size, ""));
579 AddWrite(ConstructAckPacket(4, 3, 1));
580 Initialize();
581
mmenkecbc2b712014-10-09 20:29:07582 ChunkedUploadDataStream upload_data_stream(0);
583 upload_data_stream.AppendData(kUploadData, chunk_size, false);
[email protected]16ba7742014-08-22 00:57:25584
585 request_.method = "POST";
586 request_.url = GURL("http://www.google.com/");
587 request_.upload_data_stream = &upload_data_stream;
mmenkecbc2b712014-10-09 20:29:07588 ASSERT_EQ(OK, request_.upload_data_stream->Init(
589 TestCompletionCallback().callback()));
[email protected]16ba7742014-08-22 00:57:25590
591 ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
592 net_log_, callback_.callback()));
593 ASSERT_EQ(ERR_IO_PENDING, stream_->SendRequest(headers_, &response_,
594 callback_.callback()));
595
mmenkecbc2b712014-10-09 20:29:07596 upload_data_stream.AppendData(nullptr, 0, true);
rchb27683c2015-07-29 23:53:50597 EXPECT_EQ(OK, callback_.WaitForResult());
[email protected]16ba7742014-08-22 00:57:25598
599 ProcessPacket(ConstructAckPacket(1, 0, 0));
600
601 // Send the response headers (but not the body).
602 SetResponse("200 OK", std::string());
603 ProcessPacket(ConstructResponseHeadersPacket(2, !kFin));
604
rchb27683c2015-07-29 23:53:50605 // The headers have arrived, but they are delivered asynchronously
606 EXPECT_EQ(ERR_IO_PENDING, stream_->ReadResponseHeaders(callback_.callback()));
607 EXPECT_EQ(OK, callback_.WaitForResult());
[email protected]16ba7742014-08-22 00:57:25608 ASSERT_TRUE(response_.headers.get());
609 EXPECT_EQ(200, response_.headers->response_code());
610 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
611
612 // Send the response body.
613 const char kResponseBody[] = "Hello world!";
614 ProcessPacket(ConstructDataPacket(3, false, kFin, response_data_.length(),
615 kResponseBody));
616
rchb27683c2015-07-29 23:53:50617 // The body has arrived, but it is delivered asynchronously
[email protected]16ba7742014-08-22 00:57:25618 ASSERT_EQ(static_cast<int>(strlen(kResponseBody)),
619 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(),
620 callback_.callback()));
[email protected]16ba7742014-08-22 00:57:25621 EXPECT_TRUE(stream_->IsResponseBodyComplete());
622 EXPECT_TRUE(AtEof());
623}
624
625TEST_P(QuicHttpStreamTest, SendChunkedPostRequestWithOneEmptyDataPacket) {
626 SetRequest("POST", "/", DEFAULT_PRIORITY);
rtennetif4bdb542015-01-21 14:33:05627 AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY));
[email protected]16ba7742014-08-22 00:57:25628 AddWrite(ConstructDataPacket(2, kIncludeVersion, kFin, 0, ""));
629 AddWrite(ConstructAckPacket(3, 3, 1));
630 Initialize();
631
mmenkecbc2b712014-10-09 20:29:07632 ChunkedUploadDataStream upload_data_stream(0);
[email protected]16ba7742014-08-22 00:57:25633
634 request_.method = "POST";
635 request_.url = GURL("http://www.google.com/");
636 request_.upload_data_stream = &upload_data_stream;
mmenkecbc2b712014-10-09 20:29:07637 ASSERT_EQ(OK, request_.upload_data_stream->Init(
638 TestCompletionCallback().callback()));
[email protected]16ba7742014-08-22 00:57:25639
640 ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
641 net_log_, callback_.callback()));
642 ASSERT_EQ(ERR_IO_PENDING, stream_->SendRequest(headers_, &response_,
643 callback_.callback()));
644
mmenkecbc2b712014-10-09 20:29:07645 upload_data_stream.AppendData(nullptr, 0, true);
rchb27683c2015-07-29 23:53:50646 EXPECT_EQ(OK, callback_.WaitForResult());
[email protected]16ba7742014-08-22 00:57:25647
648 ProcessPacket(ConstructAckPacket(1, 0, 0));
649
650 // Send the response headers (but not the body).
651 SetResponse("200 OK", std::string());
652 ProcessPacket(ConstructResponseHeadersPacket(2, !kFin));
653
rchb27683c2015-07-29 23:53:50654 // The headers have arrived, but they are delivered asynchronously
655 EXPECT_EQ(ERR_IO_PENDING, stream_->ReadResponseHeaders(callback_.callback()));
656 EXPECT_EQ(OK, callback_.WaitForResult());
[email protected]16ba7742014-08-22 00:57:25657 ASSERT_TRUE(response_.headers.get());
658 EXPECT_EQ(200, response_.headers->response_code());
659 EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain"));
660
661 // Send the response body.
662 const char kResponseBody[] = "Hello world!";
663 ProcessPacket(ConstructDataPacket(3, false, kFin, response_data_.length(),
664 kResponseBody));
665
rchb27683c2015-07-29 23:53:50666 // The body has arrived, but it is delivered asynchronously
[email protected]16ba7742014-08-22 00:57:25667 ASSERT_EQ(static_cast<int>(strlen(kResponseBody)),
668 stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(),
669 callback_.callback()));
670
671 EXPECT_TRUE(stream_->IsResponseBodyComplete());
672 EXPECT_TRUE(AtEof());
673}
674
[email protected]1e960032013-12-20 19:00:20675TEST_P(QuicHttpStreamTest, DestroyedEarly) {
676 SetRequest("GET", "/", DEFAULT_PRIORITY);
rtennetif4bdb542015-01-21 14:33:05677 AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY));
rchb27683c2015-07-29 23:53:50678 if (!FLAGS_quic_process_frames_inline) {
rtenneti6bd660b2015-07-18 00:19:53679 AddWrite(ConstructRstStreamCancelledPacket(2));
680 } else {
681 AddWrite(ConstructAckAndRstStreamPacket(2));
682 }
[email protected]63534512012-12-23 18:49:00683 use_closing_stream_ = true;
684 Initialize();
685
686 request_.method = "GET";
687 request_.url = GURL("http://www.google.com/");
688
[email protected]262eec82013-03-19 21:01:36689 EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY,
690 net_log_, callback_.callback()));
[email protected]63534512012-12-23 18:49:00691 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_,
[email protected]24e5bc52013-09-18 15:36:58692 callback_.callback()));
[email protected]63534512012-12-23 18:49:00693
694 // Ack the request.
[email protected]1e960032013-12-20 19:00:20695 ProcessPacket(ConstructAckPacket(1, 0, 0));
[email protected]63534512012-12-23 18:49:00696 EXPECT_EQ(ERR_IO_PENDING,
697 stream_->ReadResponseHeaders(callback_.callback()));
698
699 // Send the response with a body.
[email protected]1e960032013-12-20 19:00:20700 SetResponse("404 OK", "hello world!");
[email protected]63534512012-12-23 18:49:00701 // In the course of processing this packet, the QuicHttpStream close itself.
[email protected]92bf17c2014-03-03 21:14:03702 ProcessPacket(ConstructResponseHeadersPacket(2, kFin));
[email protected]63534512012-12-23 18:49:00703
rchb27683c2015-07-29 23:53:50704 base::MessageLoop::current()->RunUntilIdle();
705
[email protected]63534512012-12-23 18:49:00706 EXPECT_TRUE(AtEof());
707}
708
[email protected]1e960032013-12-20 19:00:20709TEST_P(QuicHttpStreamTest, Priority) {
710 SetRequest("GET", "/", MEDIUM);
rtennetif4bdb542015-01-21 14:33:05711 AddWrite(ConstructRequestHeadersPacket(1, kFin, MEDIUM));
rchb27683c2015-07-29 23:53:50712 if (!FLAGS_quic_process_frames_inline) {
rtenneti6bd660b2015-07-18 00:19:53713 AddWrite(ConstructRstStreamCancelledPacket(2));
714 } else {
715 AddWrite(ConstructAckAndRstStreamPacket(2));
716 }
[email protected]24e5bc52013-09-18 15:36:58717 use_closing_stream_ = true;
718 Initialize();
719
720 request_.method = "GET";
721 request_.url = GURL("http://www.google.com/");
722
723 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM,
724 net_log_, callback_.callback()));
725
726 // Check that priority is highest.
727 QuicReliableClientStream* reliable_stream =
728 QuicHttpStreamPeer::GetQuicReliableClientStream(stream_.get());
729 DCHECK(reliable_stream);
[email protected]9f0dcd4e2014-01-16 15:58:14730 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority,
[email protected]24e5bc52013-09-18 15:36:58731 reliable_stream->EffectivePriority());
732
733 EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_,
734 callback_.callback()));
[email protected]24e5bc52013-09-18 15:36:58735
736 // Check that priority has now dropped back to MEDIUM.
737 DCHECK_EQ(MEDIUM, ConvertQuicPriorityToRequestPriority(
738 reliable_stream->EffectivePriority()));
739
740 // Ack the request.
[email protected]1e960032013-12-20 19:00:20741 ProcessPacket(ConstructAckPacket(1, 0, 0));
[email protected]24e5bc52013-09-18 15:36:58742 EXPECT_EQ(ERR_IO_PENDING,
743 stream_->ReadResponseHeaders(callback_.callback()));
744
745 // Send the response with a body.
[email protected]1e960032013-12-20 19:00:20746 SetResponse("404 OK", "hello world!");
[email protected]24e5bc52013-09-18 15:36:58747 // In the course of processing this packet, the QuicHttpStream close itself.
[email protected]92bf17c2014-03-03 21:14:03748 ProcessPacket(ConstructResponseHeadersPacket(2, kFin));
[email protected]24e5bc52013-09-18 15:36:58749
rchb27683c2015-07-29 23:53:50750 base::MessageLoop::current()->RunUntilIdle();
751
[email protected]24e5bc52013-09-18 15:36:58752 EXPECT_TRUE(AtEof());
753}
754
[email protected]e1cca9a2013-09-20 17:14:44755// Regression test for http://crbug.com/294870
[email protected]1e960032013-12-20 19:00:20756TEST_P(QuicHttpStreamTest, CheckPriorityWithNoDelegate) {
757 SetRequest("GET", "/", MEDIUM);
[email protected]e1cca9a2013-09-20 17:14:44758 use_closing_stream_ = true;
[email protected]459a7402014-02-10 12:58:52759
[email protected]08da9adb2014-04-24 08:33:31760 AddWrite(ConstructRstStreamPacket(1));
[email protected]459a7402014-02-10 12:58:52761
[email protected]e1cca9a2013-09-20 17:14:44762 Initialize();
763
764 request_.method = "GET";
765 request_.url = GURL("http://www.google.com/");
766
767 EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM,
768 net_log_, callback_.callback()));
769
770 // Check that priority is highest.
771 QuicReliableClientStream* reliable_stream =
772 QuicHttpStreamPeer::GetQuicReliableClientStream(stream_.get());
773 DCHECK(reliable_stream);
774 QuicReliableClientStream::Delegate* delegate = reliable_stream->GetDelegate();
775 DCHECK(delegate);
[email protected]9f0dcd4e2014-01-16 15:58:14776 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority,
[email protected]e1cca9a2013-09-20 17:14:44777 reliable_stream->EffectivePriority());
778
rtennetibe635732014-10-02 22:51:42779 // Set Delegate to nullptr and make sure EffectivePriority returns highest
[email protected]e1cca9a2013-09-20 17:14:44780 // priority.
rtennetibe635732014-10-02 22:51:42781 reliable_stream->SetDelegate(nullptr);
[email protected]9f0dcd4e2014-01-16 15:58:14782 DCHECK_EQ(QuicWriteBlockedList::kHighestPriority,
[email protected]e1cca9a2013-09-20 17:14:44783 reliable_stream->EffectivePriority());
784 reliable_stream->SetDelegate(delegate);
785}
786
[email protected]f702d572012-12-04 15:56:20787} // namespace test
[email protected]f702d572012-12-04 15:56:20788} // namespace net