[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 1 | // 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 | |
| 9 | #include "net/base/net_errors.h" |
| 10 | #include "net/base/test_completion_callback.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 11 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 12 | #include "net/base/upload_data_stream.h" |
| 13 | #include "net/http/http_response_headers.h" |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 14 | #include "net/quic/congestion_control/receive_algorithm_interface.h" |
| 15 | #include "net/quic/congestion_control/send_algorithm_interface.h" |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 16 | #include "net/quic/crypto/crypto_protocol.h" |
[email protected] | 4df6984 | 2013-02-27 06:32:16 | [diff] [blame] | 17 | #include "net/quic/crypto/quic_decrypter.h" |
| 18 | #include "net/quic/crypto/quic_encrypter.h" |
[email protected] | 17bf15c | 2014-03-14 10:08:04 | [diff] [blame] | 19 | #include "net/quic/crypto/quic_server_info.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 20 | #include "net/quic/quic_client_session.h" |
| 21 | #include "net/quic/quic_connection.h" |
| 22 | #include "net/quic/quic_connection_helper.h" |
[email protected] | cbd731e | 2013-10-24 00:20:39 | [diff] [blame] | 23 | #include "net/quic/quic_default_packet_writer.h" |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 24 | #include "net/quic/quic_http_utils.h" |
| 25 | #include "net/quic/quic_reliable_client_stream.h" |
[email protected] | 9f0dcd4e | 2014-01-16 15:58:14 | [diff] [blame] | 26 | #include "net/quic/quic_write_blocked_list.h" |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 27 | #include "net/quic/spdy_utils.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 28 | #include "net/quic/test_tools/mock_clock.h" |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 29 | #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 30 | #include "net/quic/test_tools/mock_random.h" |
[email protected] | b1f287d | 2012-12-22 17:25:39 | [diff] [blame] | 31 | #include "net/quic/test_tools/quic_connection_peer.h" |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 32 | #include "net/quic/test_tools/quic_test_packet_maker.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 33 | #include "net/quic/test_tools/quic_test_utils.h" |
| 34 | #include "net/quic/test_tools/test_task_runner.h" |
| 35 | #include "net/socket/socket_test_util.h" |
[email protected] | 6cca996b | 2013-01-25 07:43:36 | [diff] [blame] | 36 | #include "net/spdy/spdy_frame_builder.h" |
| 37 | #include "net/spdy/spdy_framer.h" |
| 38 | #include "net/spdy/spdy_http_utils.h" |
| 39 | #include "net/spdy/spdy_protocol.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 40 | #include "testing/gmock/include/gmock/gmock.h" |
| 41 | #include "testing/gtest/include/gtest/gtest.h" |
| 42 | |
| 43 | using testing::_; |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 44 | using testing::AnyNumber; |
| 45 | using testing::Return; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 46 | |
| 47 | namespace net { |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 48 | namespace test { |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 49 | namespace { |
| 50 | |
| 51 | const char kUploadData[] = "hello world!"; |
[email protected] | e4c3ea6 | 2014-03-15 00:45:14 | [diff] [blame] | 52 | const char kServerHostname[] = "www.google.com"; |
| 53 | const uint16 kServerPort = 80; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 54 | |
| 55 | class TestQuicConnection : public QuicConnection { |
| 56 | public: |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 57 | TestQuicConnection(const QuicVersionVector& versions, |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 58 | QuicConnectionId connection_id, |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 59 | IPEndPoint address, |
[email protected] | cbd731e | 2013-10-24 00:20:39 | [diff] [blame] | 60 | QuicConnectionHelper* helper, |
| 61 | QuicPacketWriter* writer) |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 62 | : QuicConnection(connection_id, address, helper, writer, false, |
[email protected] | 9bb57c7 | 2014-03-31 20:36:04 | [diff] [blame] | 63 | versions, kInitialFlowControlWindowForTest) { |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 64 | } |
| 65 | |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 66 | void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { |
| 67 | QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 68 | } |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 69 | |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 70 | void SetReceiveAlgorithm(ReceiveAlgorithmInterface* receive_algorithm) { |
| 71 | QuicConnectionPeer::SetReceiveAlgorithm(this, receive_algorithm); |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 72 | } |
| 73 | }; |
| 74 | |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 75 | class TestReceiveAlgorithm : public ReceiveAlgorithmInterface { |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 76 | public: |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 77 | virtual bool GenerateCongestionFeedback( |
| 78 | QuicCongestionFeedbackFrame* /*congestion_feedback*/) { |
| 79 | return false; |
[email protected] | 26f3f8e | 2012-12-13 21:07:19 | [diff] [blame] | 80 | } |
| 81 | |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 82 | MOCK_METHOD3(RecordIncomingPacket, |
| 83 | void(QuicByteCount, QuicPacketSequenceNumber, QuicTime)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 84 | }; |
| 85 | |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 86 | // Subclass of QuicHttpStream that closes itself when the first piece of data |
| 87 | // is received. |
| 88 | class AutoClosingStream : public QuicHttpStream { |
| 89 | public: |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 90 | explicit AutoClosingStream(const base::WeakPtr<QuicClientSession>& session) |
| 91 | : QuicHttpStream(session) { |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 92 | } |
| 93 | |
[email protected] | 46fadfd | 2013-02-06 09:40:16 | [diff] [blame] | 94 | virtual int OnDataReceived(const char* data, int length) OVERRIDE { |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 95 | Close(false); |
| 96 | return OK; |
| 97 | } |
| 98 | }; |
| 99 | |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 100 | } // namespace |
| 101 | |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 102 | class QuicHttpStreamPeer { |
| 103 | public: |
| 104 | static QuicReliableClientStream* GetQuicReliableClientStream( |
| 105 | QuicHttpStream* stream) { |
| 106 | return stream->stream_; |
| 107 | } |
| 108 | }; |
| 109 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 110 | class QuicHttpStreamTest : public ::testing::TestWithParam<QuicVersion> { |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 111 | protected: |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 112 | static const bool kFin = true; |
| 113 | static const bool kIncludeVersion = true; |
| 114 | static const bool kIncludeCongestionFeedback = true; |
| 115 | |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 116 | // Holds a packet to be written to the wire, and the IO mode that should |
| 117 | // be used by the mock socket when performing the write. |
| 118 | struct PacketToWrite { |
| 119 | PacketToWrite(IoMode mode, QuicEncryptedPacket* packet) |
| 120 | : mode(mode), |
| 121 | packet(packet) { |
| 122 | } |
| 123 | IoMode mode; |
| 124 | QuicEncryptedPacket* packet; |
| 125 | }; |
| 126 | |
| 127 | QuicHttpStreamTest() |
| 128 | : net_log_(BoundNetLog()), |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 129 | use_closing_stream_(false), |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 130 | read_buffer_(new IOBufferWithSize(4096)), |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 131 | connection_id_(2), |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 132 | stream_id_(5), |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 133 | maker_(GetParam(), connection_id_), |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 134 | random_generator_(0) { |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 135 | IPAddressNumber ip; |
| 136 | CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); |
| 137 | peer_addr_ = IPEndPoint(ip, 443); |
| 138 | self_addr_ = IPEndPoint(ip, 8435); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | ~QuicHttpStreamTest() { |
[email protected] | 4d283b3 | 2013-10-17 12:57:27 | [diff] [blame] | 142 | session_->CloseSessionOnError(ERR_ABORTED); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 143 | for (size_t i = 0; i < writes_.size(); i++) { |
| 144 | delete writes_[i].packet; |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | // Adds a packet to the list of expected writes. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 149 | void AddWrite(scoped_ptr<QuicEncryptedPacket> packet) { |
| 150 | writes_.push_back(PacketToWrite(SYNCHRONOUS, packet.release())); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | // Returns the packet to be written at position |pos|. |
| 154 | QuicEncryptedPacket* GetWrite(size_t pos) { |
| 155 | return writes_[pos].packet; |
| 156 | } |
| 157 | |
| 158 | bool AtEof() { |
| 159 | return socket_data_->at_read_eof() && socket_data_->at_write_eof(); |
| 160 | } |
| 161 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 162 | void ProcessPacket(scoped_ptr<QuicEncryptedPacket> packet) { |
| 163 | connection_->ProcessUdpPacket(self_addr_, peer_addr_, *packet); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | // Configures the test fixture to use the list of expected writes. |
| 167 | void Initialize() { |
| 168 | mock_writes_.reset(new MockWrite[writes_.size()]); |
| 169 | for (size_t i = 0; i < writes_.size(); i++) { |
| 170 | mock_writes_[i] = MockWrite(writes_[i].mode, |
| 171 | writes_[i].packet->data(), |
| 172 | writes_[i].packet->length()); |
| 173 | }; |
| 174 | |
| 175 | socket_data_.reset(new StaticSocketDataProvider(NULL, 0, mock_writes_.get(), |
| 176 | writes_.size())); |
| 177 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 178 | MockUDPClientSocket* socket = new MockUDPClientSocket(socket_data_.get(), |
| 179 | net_log_.net_log()); |
| 180 | socket->Connect(peer_addr_); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 181 | runner_ = new TestTaskRunner(&clock_); |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 182 | send_algorithm_ = new MockSendAlgorithm(); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 183 | receive_algorithm_ = new TestReceiveAlgorithm(); |
[email protected] | 6ae6e34 | 2014-02-06 02:21:42 | [diff] [blame] | 184 | EXPECT_CALL(*receive_algorithm_, RecordIncomingPacket(_, _, _)). |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 185 | Times(AnyNumber()); |
[email protected] | efecff9 | 2013-09-24 07:49:23 | [diff] [blame] | 186 | EXPECT_CALL(*send_algorithm_, |
[email protected] | 9bb57c7 | 2014-03-31 20:36:04 | [diff] [blame] | 187 | OnPacketSent(_, _, _, _)).WillRepeatedly(Return(true)); |
[email protected] | 4887809 | 2013-07-26 14:51:56 | [diff] [blame] | 188 | EXPECT_CALL(*send_algorithm_, RetransmissionDelay()).WillRepeatedly( |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 189 | Return(QuicTime::Delta::Zero())); |
[email protected] | 08da9adb | 2014-04-24 08:33:31 | [diff] [blame^] | 190 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( |
| 191 | Return(kMaxPacketSize)); |
[email protected] | 9bb57c7 | 2014-03-31 20:36:04 | [diff] [blame] | 192 | EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)). |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 193 | WillRepeatedly(Return(QuicTime::Delta::Zero())); |
[email protected] | ea825e0 | 2013-08-21 18:12:45 | [diff] [blame] | 194 | EXPECT_CALL(*send_algorithm_, BandwidthEstimate()).WillRepeatedly( |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 195 | Return(QuicBandwidth::Zero())); |
[email protected] | 62f9063 | 2013-11-01 13:07:11 | [diff] [blame] | 196 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber()); |
[email protected] | 2cfc6bb8 | 2013-10-27 03:40:44 | [diff] [blame] | 197 | helper_.reset(new QuicConnectionHelper(runner_.get(), &clock_, |
| 198 | &random_generator_)); |
[email protected] | cbd731e | 2013-10-24 00:20:39 | [diff] [blame] | 199 | writer_.reset(new QuicDefaultPacketWriter(socket)); |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 200 | connection_ = new TestQuicConnection(SupportedVersions(GetParam()), |
| 201 | connection_id_, peer_addr_, |
| 202 | helper_.get(), writer_.get()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 203 | connection_->set_visitor(&visitor_); |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 204 | connection_->SetSendAlgorithm(send_algorithm_); |
| 205 | connection_->SetReceiveAlgorithm(receive_algorithm_); |
[email protected] | ef95114d | 2013-04-17 17:57:01 | [diff] [blame] | 206 | crypto_config_.SetDefaults(); |
[email protected] | 18ccfdb | 2013-08-15 00:13:44 | [diff] [blame] | 207 | session_.reset( |
| 208 | new QuicClientSession(connection_, |
[email protected] | cbd731e | 2013-10-24 00:20:39 | [diff] [blame] | 209 | scoped_ptr<DatagramClientSocket>(socket), |
| 210 | writer_.Pass(), NULL, |
[email protected] | 18ccfdb | 2013-08-15 00:13:44 | [diff] [blame] | 211 | &crypto_client_stream_factory_, |
[email protected] | 89f79a4 | 2014-03-19 11:30:01 | [diff] [blame] | 212 | make_scoped_ptr((QuicServerInfo*)NULL), |
[email protected] | 257f24f | 2014-04-01 09:15:37 | [diff] [blame] | 213 | QuicServerId(kServerHostname, kServerPort, |
| 214 | false, PRIVACY_MODE_DISABLED), |
[email protected] | e4c3ea6 | 2014-03-15 00:45:14 | [diff] [blame] | 215 | DefaultQuicConfig(), &crypto_config_, NULL)); |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 216 | session_->GetCryptoStream()->CryptoConnect(); |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 217 | EXPECT_TRUE(session_->IsCryptoHandshakeConfirmed()); |
[email protected] | 6cca996b | 2013-01-25 07:43:36 | [diff] [blame] | 218 | stream_.reset(use_closing_stream_ ? |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 219 | new AutoClosingStream(session_->GetWeakPtr()) : |
| 220 | new QuicHttpStream(session_->GetWeakPtr())); |
[email protected] | 98a9d125 | 2014-04-04 00:43:59 | [diff] [blame] | 221 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(20)); |
[email protected] | 6cca996b | 2013-01-25 07:43:36 | [diff] [blame] | 222 | } |
| 223 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 224 | void SetRequest(const std::string& method, |
| 225 | const std::string& path, |
| 226 | RequestPriority priority) { |
| 227 | request_headers_ = maker_.GetRequestHeaders(method, "http", path); |
[email protected] | 6cca996b | 2013-01-25 07:43:36 | [diff] [blame] | 228 | } |
| 229 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 230 | void SetResponse(const std::string& status, const std::string& body) { |
| 231 | response_headers_ = maker_.GetResponseHeaders(status); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 232 | response_data_ = body; |
[email protected] | 6cca996b | 2013-01-25 07:43:36 | [diff] [blame] | 233 | } |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 234 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 235 | scoped_ptr<QuicEncryptedPacket> ConstructDataPacket( |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 236 | QuicPacketSequenceNumber sequence_number, |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 237 | bool should_include_version, |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 238 | bool fin, |
| 239 | QuicStreamOffset offset, |
| 240 | base::StringPiece data) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 241 | return maker_.MakeDataPacket( |
| 242 | sequence_number, stream_id_, should_include_version, fin, offset, data); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 243 | } |
| 244 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 245 | scoped_ptr<QuicEncryptedPacket> ConstructRequestHeadersPacket( |
| 246 | QuicPacketSequenceNumber sequence_number, |
| 247 | bool fin) { |
| 248 | return maker_.MakeRequestHeadersPacket( |
| 249 | sequence_number, stream_id_, kIncludeVersion, fin, request_headers_); |
| 250 | } |
| 251 | |
| 252 | scoped_ptr<QuicEncryptedPacket> ConstructResponseHeadersPacket( |
| 253 | QuicPacketSequenceNumber sequence_number, |
| 254 | bool fin) { |
| 255 | return maker_.MakeResponseHeadersPacket( |
| 256 | sequence_number, stream_id_, !kIncludeVersion, fin, response_headers_); |
| 257 | } |
| 258 | |
| 259 | scoped_ptr<QuicEncryptedPacket> ConstructRstStreamPacket( |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 260 | QuicPacketSequenceNumber sequence_number) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 261 | return maker_.MakeRstPacket( |
[email protected] | 51cc134 | 2014-04-18 23:44:37 | [diff] [blame] | 262 | sequence_number, true, stream_id_, |
| 263 | AdjustErrorForVersion(QUIC_RST_FLOW_CONTROL_ACCOUNTING, GetParam())); |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 264 | } |
| 265 | |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 266 | scoped_ptr<QuicEncryptedPacket> ConstructAckAndRstStreamPacket( |
| 267 | QuicPacketSequenceNumber sequence_number) { |
| 268 | return maker_.MakeAckAndRstPacket( |
| 269 | sequence_number, !kIncludeVersion, stream_id_, QUIC_STREAM_CANCELLED, |
[email protected] | 08da9adb | 2014-04-24 08:33:31 | [diff] [blame^] | 270 | 2, 1, !kIncludeCongestionFeedback); |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 271 | } |
| 272 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 273 | scoped_ptr<QuicEncryptedPacket> ConstructAckPacket( |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 274 | QuicPacketSequenceNumber sequence_number, |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 275 | QuicPacketSequenceNumber largest_received, |
| 276 | QuicPacketSequenceNumber least_unacked) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 277 | return maker_.MakeAckPacket(sequence_number, largest_received, |
| 278 | least_unacked, !kIncludeCongestionFeedback); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 279 | } |
| 280 | |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 281 | BoundNetLog net_log_; |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 282 | bool use_closing_stream_; |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 283 | MockSendAlgorithm* send_algorithm_; |
| 284 | TestReceiveAlgorithm* receive_algorithm_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 285 | scoped_refptr<TestTaskRunner> runner_; |
[email protected] | 4356f0f | 2013-04-07 00:58:17 | [diff] [blame] | 286 | scoped_ptr<MockWrite[]> mock_writes_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 287 | MockClock clock_; |
| 288 | TestQuicConnection* connection_; |
[email protected] | 2cfc6bb8 | 2013-10-27 03:40:44 | [diff] [blame] | 289 | scoped_ptr<QuicConnectionHelper> helper_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 290 | testing::StrictMock<MockConnectionVisitor> visitor_; |
| 291 | scoped_ptr<QuicHttpStream> stream_; |
[email protected] | cbd731e | 2013-10-24 00:20:39 | [diff] [blame] | 292 | scoped_ptr<QuicDefaultPacketWriter> writer_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 293 | scoped_ptr<QuicClientSession> session_; |
[email protected] | ef95114d | 2013-04-17 17:57:01 | [diff] [blame] | 294 | QuicCryptoClientConfig crypto_config_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 295 | TestCompletionCallback callback_; |
| 296 | HttpRequestInfo request_; |
| 297 | HttpRequestHeaders headers_; |
| 298 | HttpResponseInfo response_; |
| 299 | scoped_refptr<IOBufferWithSize> read_buffer_; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 300 | SpdyHeaderBlock request_headers_; |
| 301 | SpdyHeaderBlock response_headers_; |
[email protected] | 6cca996b | 2013-01-25 07:43:36 | [diff] [blame] | 302 | std::string request_data_; |
| 303 | std::string response_data_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 304 | |
| 305 | private: |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 306 | const QuicConnectionId connection_id_; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 307 | const QuicStreamId stream_id_; |
| 308 | QuicTestPacketMaker maker_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 309 | IPEndPoint self_addr_; |
| 310 | IPEndPoint peer_addr_; |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame] | 311 | MockRandom random_generator_; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 312 | MockCryptoClientStreamFactory crypto_client_stream_factory_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 313 | scoped_ptr<StaticSocketDataProvider> socket_data_; |
| 314 | std::vector<PacketToWrite> writes_; |
| 315 | }; |
| 316 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 317 | INSTANTIATE_TEST_CASE_P(Version, QuicHttpStreamTest, |
| 318 | ::testing::ValuesIn(QuicSupportedVersions())); |
| 319 | |
| 320 | TEST_P(QuicHttpStreamTest, RenewStreamForAuth) { |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 321 | Initialize(); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 322 | EXPECT_EQ(NULL, stream_->RenewStreamForAuth()); |
| 323 | } |
| 324 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 325 | TEST_P(QuicHttpStreamTest, CanFindEndOfResponse) { |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 326 | Initialize(); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 327 | EXPECT_TRUE(stream_->CanFindEndOfResponse()); |
| 328 | } |
| 329 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 330 | TEST_P(QuicHttpStreamTest, IsConnectionReusable) { |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 331 | Initialize(); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 332 | EXPECT_FALSE(stream_->IsConnectionReusable()); |
| 333 | } |
| 334 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 335 | TEST_P(QuicHttpStreamTest, GetRequest) { |
| 336 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 337 | AddWrite(ConstructRequestHeadersPacket(1, kFin)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 338 | Initialize(); |
| 339 | |
| 340 | request_.method = "GET"; |
| 341 | request_.url = GURL("http://www.google.com/"); |
| 342 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 343 | EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 344 | net_log_, callback_.callback())); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 345 | EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, |
| 346 | callback_.callback())); |
| 347 | EXPECT_EQ(&response_, stream_->GetResponseInfo()); |
| 348 | |
| 349 | // Ack the request. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 350 | ProcessPacket(ConstructAckPacket(1, 0, 0)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 351 | |
| 352 | EXPECT_EQ(ERR_IO_PENDING, |
| 353 | stream_->ReadResponseHeaders(callback_.callback())); |
| 354 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 355 | SetResponse("404 Not Found", std::string()); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 356 | ProcessPacket(ConstructResponseHeadersPacket(2, kFin)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 357 | |
| 358 | // Now that the headers have been processed, the callback will return. |
| 359 | EXPECT_EQ(OK, callback_.WaitForResult()); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 360 | ASSERT_TRUE(response_.headers.get()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 361 | EXPECT_EQ(404, response_.headers->response_code()); |
| 362 | EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 363 | |
| 364 | // There is no body, so this should return immediately. |
| 365 | EXPECT_EQ(0, stream_->ReadResponseBody(read_buffer_.get(), |
| 366 | read_buffer_->size(), |
| 367 | callback_.callback())); |
| 368 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 369 | EXPECT_TRUE(AtEof()); |
| 370 | } |
| 371 | |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 372 | // Regression test for http://crbug.com/288128 |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 373 | TEST_P(QuicHttpStreamTest, GetRequestLargeResponse) { |
| 374 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 375 | AddWrite(ConstructRequestHeadersPacket(1, kFin)); |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 376 | Initialize(); |
| 377 | |
| 378 | request_.method = "GET"; |
| 379 | request_.url = GURL("http://www.google.com/"); |
| 380 | |
| 381 | EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 382 | net_log_, callback_.callback())); |
| 383 | EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, |
| 384 | callback_.callback())); |
| 385 | EXPECT_EQ(&response_, stream_->GetResponseInfo()); |
| 386 | |
| 387 | // Ack the request. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 388 | ProcessPacket(ConstructAckPacket(1, 0, 0)); |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 389 | |
| 390 | EXPECT_EQ(ERR_IO_PENDING, |
| 391 | stream_->ReadResponseHeaders(callback_.callback())); |
| 392 | |
| 393 | SpdyHeaderBlock headers; |
| 394 | headers[":status"] = "200 OK"; |
| 395 | headers[":version"] = "HTTP/1.1"; |
| 396 | headers["content-type"] = "text/plain"; |
| 397 | headers["big6"] = std::string(10000, 'x'); // Lots of x's. |
| 398 | |
| 399 | std::string response = SpdyUtils::SerializeUncompressedHeaders(headers); |
| 400 | EXPECT_LT(4096u, response.length()); |
| 401 | stream_->OnDataReceived(response.data(), response.length()); |
| 402 | stream_->OnClose(QUIC_NO_ERROR); |
| 403 | |
| 404 | // Now that the headers have been processed, the callback will return. |
| 405 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 406 | ASSERT_TRUE(response_.headers.get()); |
| 407 | EXPECT_EQ(200, response_.headers->response_code()); |
| 408 | EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 409 | |
| 410 | // There is no body, so this should return immediately. |
| 411 | EXPECT_EQ(0, stream_->ReadResponseBody(read_buffer_.get(), |
| 412 | read_buffer_->size(), |
| 413 | callback_.callback())); |
| 414 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 415 | EXPECT_TRUE(AtEof()); |
| 416 | } |
| 417 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 418 | TEST_P(QuicHttpStreamTest, SendPostRequest) { |
| 419 | SetRequest("POST", "/", DEFAULT_PRIORITY); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 420 | AddWrite(ConstructRequestHeadersPacket(1, !kFin)); |
| 421 | AddWrite(ConstructDataPacket(2, kIncludeVersion, kFin, 0, kUploadData)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 422 | AddWrite(ConstructAckPacket(3, 3, 1)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 423 | |
| 424 | Initialize(); |
| 425 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 426 | ScopedVector<UploadElementReader> element_readers; |
| 427 | element_readers.push_back( |
| 428 | new UploadBytesElementReader(kUploadData, strlen(kUploadData))); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 429 | UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 430 | request_.method = "POST"; |
| 431 | request_.url = GURL("http://www.google.com/"); |
| 432 | request_.upload_data_stream = &upload_data_stream; |
[email protected] | 4db27d8 | 2012-12-20 11:50:24 | [diff] [blame] | 433 | ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback())); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 434 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 435 | EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 436 | net_log_, callback_.callback())); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 437 | EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, |
| 438 | callback_.callback())); |
| 439 | EXPECT_EQ(&response_, stream_->GetResponseInfo()); |
| 440 | |
| 441 | // Ack both packets in the request. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 442 | ProcessPacket(ConstructAckPacket(1, 0, 0)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 443 | |
| 444 | // Send the response headers (but not the body). |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 445 | SetResponse("200 OK", std::string()); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 446 | ProcessPacket(ConstructResponseHeadersPacket(2, !kFin)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 447 | |
| 448 | // Since the headers have already arrived, this should return immediately. |
| 449 | EXPECT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 450 | ASSERT_TRUE(response_.headers.get()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 451 | EXPECT_EQ(200, response_.headers->response_code()); |
| 452 | EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 453 | |
| 454 | // Send the response body. |
| 455 | const char kResponseBody[] = "Hello world!"; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 456 | ProcessPacket(ConstructDataPacket(3, false, kFin, 0, kResponseBody)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 457 | // Since the body has already arrived, this should return immediately. |
| 458 | EXPECT_EQ(static_cast<int>(strlen(kResponseBody)), |
| 459 | stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 460 | callback_.callback())); |
| 461 | |
| 462 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 463 | EXPECT_TRUE(AtEof()); |
| 464 | } |
| 465 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 466 | TEST_P(QuicHttpStreamTest, SendChunkedPostRequest) { |
| 467 | SetRequest("POST", "/", DEFAULT_PRIORITY); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 468 | size_t chunk_size = strlen(kUploadData); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 469 | AddWrite(ConstructRequestHeadersPacket(1, !kFin)); |
| 470 | AddWrite(ConstructDataPacket(2, kIncludeVersion, !kFin, 0, kUploadData)); |
| 471 | AddWrite(ConstructDataPacket(3, kIncludeVersion, kFin, chunk_size, |
| 472 | kUploadData)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 473 | AddWrite(ConstructAckPacket(4, 3, 1)); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 474 | Initialize(); |
| 475 | |
| 476 | UploadDataStream upload_data_stream(UploadDataStream::CHUNKED, 0); |
| 477 | upload_data_stream.AppendChunk(kUploadData, chunk_size, false); |
| 478 | |
| 479 | request_.method = "POST"; |
| 480 | request_.url = GURL("http://www.google.com/"); |
| 481 | request_.upload_data_stream = &upload_data_stream; |
| 482 | ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback())); |
| 483 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 484 | ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 485 | net_log_, callback_.callback())); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 486 | ASSERT_EQ(ERR_IO_PENDING, stream_->SendRequest(headers_, &response_, |
| 487 | callback_.callback())); |
| 488 | EXPECT_EQ(&response_, stream_->GetResponseInfo()); |
| 489 | |
| 490 | upload_data_stream.AppendChunk(kUploadData, chunk_size, true); |
| 491 | |
| 492 | // Ack both packets in the request. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 493 | ProcessPacket(ConstructAckPacket(1, 0, 0)); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 494 | |
| 495 | // Send the response headers (but not the body). |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 496 | SetResponse("200 OK", std::string()); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 497 | ProcessPacket(ConstructResponseHeadersPacket(2, !kFin)); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 498 | |
| 499 | // Since the headers have already arrived, this should return immediately. |
| 500 | ASSERT_EQ(OK, stream_->ReadResponseHeaders(callback_.callback())); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 501 | ASSERT_TRUE(response_.headers.get()); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 502 | EXPECT_EQ(200, response_.headers->response_code()); |
| 503 | EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 504 | |
| 505 | // Send the response body. |
| 506 | const char kResponseBody[] = "Hello world!"; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 507 | ProcessPacket(ConstructDataPacket(3, false, kFin, response_data_.length(), |
| 508 | kResponseBody)); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 509 | |
| 510 | // Since the body has already arrived, this should return immediately. |
| 511 | ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), |
| 512 | stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 513 | callback_.callback())); |
| 514 | |
| 515 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 516 | EXPECT_TRUE(AtEof()); |
| 517 | } |
| 518 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 519 | TEST_P(QuicHttpStreamTest, DestroyedEarly) { |
| 520 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 521 | AddWrite(ConstructRequestHeadersPacket(1, kFin)); |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 522 | AddWrite(ConstructAckAndRstStreamPacket(2)); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 523 | use_closing_stream_ = true; |
| 524 | Initialize(); |
| 525 | |
| 526 | request_.method = "GET"; |
| 527 | request_.url = GURL("http://www.google.com/"); |
| 528 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 529 | EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 530 | net_log_, callback_.callback())); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 531 | EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 532 | callback_.callback())); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 533 | EXPECT_EQ(&response_, stream_->GetResponseInfo()); |
| 534 | |
| 535 | // Ack the request. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 536 | ProcessPacket(ConstructAckPacket(1, 0, 0)); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 537 | EXPECT_EQ(ERR_IO_PENDING, |
| 538 | stream_->ReadResponseHeaders(callback_.callback())); |
| 539 | |
| 540 | // Send the response with a body. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 541 | SetResponse("404 OK", "hello world!"); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 542 | // In the course of processing this packet, the QuicHttpStream close itself. |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 543 | ProcessPacket(ConstructResponseHeadersPacket(2, kFin)); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 544 | |
| 545 | EXPECT_TRUE(AtEof()); |
| 546 | } |
| 547 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 548 | TEST_P(QuicHttpStreamTest, Priority) { |
| 549 | SetRequest("GET", "/", MEDIUM); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 550 | AddWrite(ConstructRequestHeadersPacket(1, kFin)); |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 551 | AddWrite(ConstructAckAndRstStreamPacket(2)); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 552 | use_closing_stream_ = true; |
| 553 | Initialize(); |
| 554 | |
| 555 | request_.method = "GET"; |
| 556 | request_.url = GURL("http://www.google.com/"); |
| 557 | |
| 558 | EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, |
| 559 | net_log_, callback_.callback())); |
| 560 | |
| 561 | // Check that priority is highest. |
| 562 | QuicReliableClientStream* reliable_stream = |
| 563 | QuicHttpStreamPeer::GetQuicReliableClientStream(stream_.get()); |
| 564 | DCHECK(reliable_stream); |
[email protected] | 9f0dcd4e | 2014-01-16 15:58:14 | [diff] [blame] | 565 | DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 566 | reliable_stream->EffectivePriority()); |
| 567 | |
| 568 | EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, |
| 569 | callback_.callback())); |
| 570 | EXPECT_EQ(&response_, stream_->GetResponseInfo()); |
| 571 | |
| 572 | // Check that priority has now dropped back to MEDIUM. |
| 573 | DCHECK_EQ(MEDIUM, ConvertQuicPriorityToRequestPriority( |
| 574 | reliable_stream->EffectivePriority())); |
| 575 | |
| 576 | // Ack the request. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 577 | ProcessPacket(ConstructAckPacket(1, 0, 0)); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 578 | EXPECT_EQ(ERR_IO_PENDING, |
| 579 | stream_->ReadResponseHeaders(callback_.callback())); |
| 580 | |
| 581 | // Send the response with a body. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 582 | SetResponse("404 OK", "hello world!"); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 583 | // In the course of processing this packet, the QuicHttpStream close itself. |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 584 | ProcessPacket(ConstructResponseHeadersPacket(2, kFin)); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 585 | |
| 586 | EXPECT_TRUE(AtEof()); |
| 587 | } |
| 588 | |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 589 | // Regression test for http://crbug.com/294870 |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 590 | TEST_P(QuicHttpStreamTest, CheckPriorityWithNoDelegate) { |
| 591 | SetRequest("GET", "/", MEDIUM); |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 592 | use_closing_stream_ = true; |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 593 | |
[email protected] | 08da9adb | 2014-04-24 08:33:31 | [diff] [blame^] | 594 | AddWrite(ConstructRstStreamPacket(1)); |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 595 | |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 596 | Initialize(); |
| 597 | |
| 598 | request_.method = "GET"; |
| 599 | request_.url = GURL("http://www.google.com/"); |
| 600 | |
| 601 | EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, |
| 602 | net_log_, callback_.callback())); |
| 603 | |
| 604 | // Check that priority is highest. |
| 605 | QuicReliableClientStream* reliable_stream = |
| 606 | QuicHttpStreamPeer::GetQuicReliableClientStream(stream_.get()); |
| 607 | DCHECK(reliable_stream); |
| 608 | QuicReliableClientStream::Delegate* delegate = reliable_stream->GetDelegate(); |
| 609 | DCHECK(delegate); |
[email protected] | 9f0dcd4e | 2014-01-16 15:58:14 | [diff] [blame] | 610 | DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 611 | reliable_stream->EffectivePriority()); |
| 612 | |
| 613 | // Set Delegate to NULL and make sure EffectivePriority returns highest |
| 614 | // priority. |
| 615 | reliable_stream->SetDelegate(NULL); |
[email protected] | 9f0dcd4e | 2014-01-16 15:58:14 | [diff] [blame] | 616 | DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 617 | reliable_stream->EffectivePriority()); |
| 618 | reliable_stream->SetDelegate(delegate); |
| 619 | } |
| 620 | |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 621 | } // namespace test |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 622 | } // namespace net |