[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 | |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 11 | #include "base/thread_task_runner_handle.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 12 | #include "net/base/chunked_upload_data_stream.h" |
| 13 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 14 | #include "net/base/net_errors.h" |
tbansal | fdf5665b | 2015-09-21 22:46:40 | [diff] [blame] | 15 | #include "net/base/socket_performance_watcher.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 16 | #include "net/base/test_completion_callback.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 17 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 18 | #include "net/http/http_response_headers.h" |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 19 | #include "net/http/transport_security_state.h" |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 20 | #include "net/quic/congestion_control/send_algorithm_interface.h" |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 21 | #include "net/quic/crypto/crypto_protocol.h" |
[email protected] | 4df6984 | 2013-02-27 06:32:16 | [diff] [blame] | 22 | #include "net/quic/crypto/quic_decrypter.h" |
| 23 | #include "net/quic/crypto/quic_encrypter.h" |
[email protected] | 17bf15c | 2014-03-14 10:08:04 | [diff] [blame] | 24 | #include "net/quic/crypto/quic_server_info.h" |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 25 | #include "net/quic/quic_chromium_client_session.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 26 | #include "net/quic/quic_connection.h" |
| 27 | #include "net/quic/quic_connection_helper.h" |
[email protected] | cbd731e | 2013-10-24 00:20:39 | [diff] [blame] | 28 | #include "net/quic/quic_default_packet_writer.h" |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 29 | #include "net/quic/quic_http_utils.h" |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 30 | #include "net/quic/quic_packet_reader.h" |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 31 | #include "net/quic/quic_reliable_client_stream.h" |
[email protected] | 9f0dcd4e | 2014-01-16 15:58:14 | [diff] [blame] | 32 | #include "net/quic/quic_write_blocked_list.h" |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 33 | #include "net/quic/spdy_utils.h" |
rch | 1fe2eeb | 2015-10-26 14:45:57 | [diff] [blame^] | 34 | #include "net/quic/test_tools/crypto_test_utils.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 35 | #include "net/quic/test_tools/mock_clock.h" |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 36 | #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 37 | #include "net/quic/test_tools/mock_random.h" |
[email protected] | b1f287d | 2012-12-22 17:25:39 | [diff] [blame] | 38 | #include "net/quic/test_tools/quic_connection_peer.h" |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 39 | #include "net/quic/test_tools/quic_test_packet_maker.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 40 | #include "net/quic/test_tools/quic_test_utils.h" |
| 41 | #include "net/quic/test_tools/test_task_runner.h" |
| 42 | #include "net/socket/socket_test_util.h" |
[email protected] | 6cca996b | 2013-01-25 07:43:36 | [diff] [blame] | 43 | #include "net/spdy/spdy_frame_builder.h" |
| 44 | #include "net/spdy/spdy_framer.h" |
| 45 | #include "net/spdy/spdy_http_utils.h" |
| 46 | #include "net/spdy/spdy_protocol.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 47 | #include "testing/gmock/include/gmock/gmock.h" |
| 48 | #include "testing/gtest/include/gtest/gtest.h" |
| 49 | |
| 50 | using testing::_; |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 51 | using testing::AnyNumber; |
| 52 | using testing::Return; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 53 | |
| 54 | namespace net { |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 55 | namespace test { |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 56 | namespace { |
| 57 | |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 58 | const char kUploadData[] = "Really nifty data!"; |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 59 | const char kDefaultServerHostName[] = "www.google.com"; |
| 60 | const uint16 kDefaultServerPort = 80; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 61 | |
| 62 | class TestQuicConnection : public QuicConnection { |
| 63 | public: |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 64 | TestQuicConnection(const QuicVersionVector& versions, |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 65 | QuicConnectionId connection_id, |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 66 | IPEndPoint address, |
[email protected] | cbd731e | 2013-10-24 00:20:39 | [diff] [blame] | 67 | QuicConnectionHelper* helper, |
[email protected] | 6d51582 | 2014-08-22 01:58:06 | [diff] [blame] | 68 | const QuicConnection::PacketWriterFactory& writer_factory) |
[email protected] | 66cd2d6 | 2014-08-01 18:42:39 | [diff] [blame] | 69 | : QuicConnection(connection_id, |
| 70 | address, |
| 71 | helper, |
[email protected] | 6d51582 | 2014-08-22 01:58:06 | [diff] [blame] | 72 | writer_factory, |
rtenneti | 6f48aa9 | 2015-03-16 02:18:48 | [diff] [blame] | 73 | true /* owns_writer */, |
| 74 | Perspective::IS_CLIENT, |
rtenneti | 6f48aa9 | 2015-03-16 02:18:48 | [diff] [blame] | 75 | versions) {} |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 76 | |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 77 | void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { |
| 78 | QuicConnectionPeer::SetSendAlgorithm(this, send_algorithm); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 79 | } |
| 80 | }; |
| 81 | |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 82 | // Subclass of QuicHttpStream that closes itself when the first piece of data |
| 83 | // is received. |
| 84 | class AutoClosingStream : public QuicHttpStream { |
| 85 | public: |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 86 | explicit AutoClosingStream( |
| 87 | const base::WeakPtr<QuicChromiumClientSession>& session) |
| 88 | : QuicHttpStream(session) {} |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 89 | |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 90 | void OnHeadersAvailable(const SpdyHeaderBlock& headers, |
| 91 | size_t frame_len) override { |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 92 | Close(false); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 93 | } |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 94 | |
| 95 | void OnDataAvailable() override { Close(false); } |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 96 | }; |
| 97 | |
[email protected] | 6d51582 | 2014-08-22 01:58:06 | [diff] [blame] | 98 | class TestPacketWriterFactory : public QuicConnection::PacketWriterFactory { |
| 99 | public: |
| 100 | explicit TestPacketWriterFactory(DatagramClientSocket* socket) |
| 101 | : socket_(socket) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 102 | ~TestPacketWriterFactory() override {} |
[email protected] | 6d51582 | 2014-08-22 01:58:06 | [diff] [blame] | 103 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 104 | QuicPacketWriter* Create(QuicConnection* connection) const override { |
[email protected] | 6d51582 | 2014-08-22 01:58:06 | [diff] [blame] | 105 | return new QuicDefaultPacketWriter(socket_); |
| 106 | } |
| 107 | |
| 108 | private: |
| 109 | DatagramClientSocket* socket_; |
| 110 | }; |
| 111 | |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 112 | } // namespace |
| 113 | |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 114 | class QuicHttpStreamPeer { |
| 115 | public: |
| 116 | static QuicReliableClientStream* GetQuicReliableClientStream( |
| 117 | QuicHttpStream* stream) { |
| 118 | return stream->stream_; |
| 119 | } |
| 120 | }; |
| 121 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 122 | class QuicHttpStreamTest : public ::testing::TestWithParam<QuicVersion> { |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 123 | protected: |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 124 | static const bool kFin = true; |
| 125 | static const bool kIncludeVersion = true; |
| 126 | static const bool kIncludeCongestionFeedback = true; |
| 127 | |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 128 | // Holds a packet to be written to the wire, and the IO mode that should |
| 129 | // be used by the mock socket when performing the write. |
| 130 | struct PacketToWrite { |
| 131 | PacketToWrite(IoMode mode, QuicEncryptedPacket* packet) |
| 132 | : mode(mode), |
| 133 | packet(packet) { |
| 134 | } |
| 135 | IoMode mode; |
| 136 | QuicEncryptedPacket* packet; |
| 137 | }; |
| 138 | |
| 139 | QuicHttpStreamTest() |
| 140 | : net_log_(BoundNetLog()), |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 141 | use_closing_stream_(false), |
rch | 1fe2eeb | 2015-10-26 14:45:57 | [diff] [blame^] | 142 | crypto_config_(CryptoTestUtils::ProofVerifierForTesting()), |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 143 | read_buffer_(new IOBufferWithSize(4096)), |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 144 | connection_id_(2), |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 145 | stream_id_(kClientDataStreamId1), |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 146 | maker_(GetParam(), connection_id_, &clock_, kDefaultServerHostName), |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 147 | random_generator_(0) { |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 148 | IPAddressNumber ip; |
| 149 | CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); |
| 150 | peer_addr_ = IPEndPoint(ip, 443); |
| 151 | self_addr_ = IPEndPoint(ip, 8435); |
rtenneti | 4b06ae7 | 2014-08-26 03:43:43 | [diff] [blame] | 152 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(20)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | ~QuicHttpStreamTest() { |
rtenneti | 85dcfac2 | 2015-03-27 20:22:19 | [diff] [blame] | 156 | session_->CloseSessionOnError(ERR_ABORTED, QUIC_INTERNAL_ERROR); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 157 | for (size_t i = 0; i < writes_.size(); i++) { |
| 158 | delete writes_[i].packet; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | // Adds a packet to the list of expected writes. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 163 | void AddWrite(scoped_ptr<QuicEncryptedPacket> packet) { |
| 164 | writes_.push_back(PacketToWrite(SYNCHRONOUS, packet.release())); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | // Returns the packet to be written at position |pos|. |
| 168 | QuicEncryptedPacket* GetWrite(size_t pos) { |
| 169 | return writes_[pos].packet; |
| 170 | } |
| 171 | |
| 172 | bool AtEof() { |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 173 | return socket_data_->AllReadDataConsumed() && |
| 174 | socket_data_->AllWriteDataConsumed(); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 175 | } |
| 176 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 177 | void ProcessPacket(scoped_ptr<QuicEncryptedPacket> packet) { |
| 178 | connection_->ProcessUdpPacket(self_addr_, peer_addr_, *packet); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | // Configures the test fixture to use the list of expected writes. |
| 182 | void Initialize() { |
| 183 | mock_writes_.reset(new MockWrite[writes_.size()]); |
| 184 | for (size_t i = 0; i < writes_.size(); i++) { |
| 185 | mock_writes_[i] = MockWrite(writes_[i].mode, |
| 186 | writes_[i].packet->data(), |
| 187 | writes_[i].packet->length()); |
| 188 | }; |
| 189 | |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 190 | socket_data_.reset(new StaticSocketDataProvider( |
| 191 | nullptr, 0, mock_writes_.get(), writes_.size())); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 192 | |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 193 | MockUDPClientSocket* socket = new MockUDPClientSocket(socket_data_.get(), |
| 194 | net_log_.net_log()); |
| 195 | socket->Connect(peer_addr_); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 196 | runner_ = new TestTaskRunner(&clock_); |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 197 | send_algorithm_ = new MockSendAlgorithm(); |
rch | 7dd1570 | 2015-07-01 18:57:57 | [diff] [blame] | 198 | EXPECT_CALL(*send_algorithm_, InRecovery()).WillRepeatedly(Return(false)); |
| 199 | EXPECT_CALL(*send_algorithm_, InSlowStart()).WillRepeatedly(Return(false)); |
[email protected] | efecff9 | 2013-09-24 07:49:23 | [diff] [blame] | 200 | EXPECT_CALL(*send_algorithm_, |
[email protected] | ef0da58 | 2014-05-09 07:16:30 | [diff] [blame] | 201 | OnPacketSent(_, _, _, _, _)).WillRepeatedly(Return(true)); |
rtenneti | 44f4a2e | 2015-08-07 14:00:07 | [diff] [blame] | 202 | EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) |
| 203 | .WillRepeatedly(Return(QuicTime::Delta::Zero())); |
| 204 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 205 | .WillRepeatedly(Return(kMaxPacketSize)); |
| 206 | EXPECT_CALL(*send_algorithm_, PacingRate()) |
| 207 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
| 208 | EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _, _)) |
| 209 | .WillRepeatedly(Return(QuicTime::Delta::Zero())); |
| 210 | EXPECT_CALL(*send_algorithm_, BandwidthEstimate()) |
| 211 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
rch | 1e543ec | 2015-03-29 07:04:40 | [diff] [blame] | 212 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber()); |
[email protected] | 2cfc6bb8 | 2013-10-27 03:40:44 | [diff] [blame] | 213 | helper_.reset(new QuicConnectionHelper(runner_.get(), &clock_, |
| 214 | &random_generator_)); |
[email protected] | 6d51582 | 2014-08-22 01:58:06 | [diff] [blame] | 215 | TestPacketWriterFactory writer_factory(socket); |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 216 | connection_ = new TestQuicConnection(SupportedVersions(GetParam()), |
| 217 | connection_id_, peer_addr_, |
[email protected] | 6d51582 | 2014-08-22 01:58:06 | [diff] [blame] | 218 | helper_.get(), writer_factory); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 219 | connection_->set_visitor(&visitor_); |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 220 | connection_->SetSendAlgorithm(send_algorithm_); |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 221 | session_.reset(new QuicChromiumClientSession( |
rtenneti | d39bd76 | 2015-06-12 01:05:52 | [diff] [blame] | 222 | connection_, scoped_ptr<DatagramClientSocket>(socket), |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 223 | /*stream_factory=*/nullptr, &crypto_client_stream_factory_, &clock_, |
rtenneti | 041b299 | 2015-02-23 23:03:28 | [diff] [blame] | 224 | &transport_security_state_, make_scoped_ptr((QuicServerInfo*)nullptr), |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 225 | QuicServerId(kDefaultServerHostName, kDefaultServerPort, |
rch | 1fe2eeb | 2015-10-26 14:45:57 | [diff] [blame^] | 226 | PRIVACY_MODE_DISABLED), |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 227 | kQuicYieldAfterPacketsRead, |
| 228 | QuicTime::Delta::FromMilliseconds(kQuicYieldAfterDurationMilliseconds), |
rtenneti | a75df62 | 2015-06-21 23:59:50 | [diff] [blame] | 229 | /*cert_verify_flags=*/0, DefaultQuicConfig(), &crypto_config_, |
| 230 | "CONNECTION_UNKNOWN", base::TimeTicks::Now(), |
tbansal | fdf5665b | 2015-09-21 22:46:40 | [diff] [blame] | 231 | base::ThreadTaskRunnerHandle::Get().get(), |
| 232 | /*socket_performance_watcher=*/nullptr, nullptr)); |
rtenneti | d39bd76 | 2015-06-12 01:05:52 | [diff] [blame] | 233 | session_->Initialize(); |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 234 | session_->GetCryptoStream()->CryptoConnect(); |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 235 | EXPECT_TRUE(session_->IsCryptoHandshakeConfirmed()); |
[email protected] | 6cca996b | 2013-01-25 07:43:36 | [diff] [blame] | 236 | stream_.reset(use_closing_stream_ ? |
[email protected] | 0b2294d3 | 2013-08-02 00:46:36 | [diff] [blame] | 237 | new AutoClosingStream(session_->GetWeakPtr()) : |
| 238 | new QuicHttpStream(session_->GetWeakPtr())); |
[email protected] | 6cca996b | 2013-01-25 07:43:36 | [diff] [blame] | 239 | } |
| 240 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 241 | void SetRequest(const std::string& method, |
| 242 | const std::string& path, |
| 243 | RequestPriority priority) { |
| 244 | request_headers_ = maker_.GetRequestHeaders(method, "http", path); |
[email protected] | 6cca996b | 2013-01-25 07:43:36 | [diff] [blame] | 245 | } |
| 246 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 247 | void SetResponse(const std::string& status, const std::string& body) { |
| 248 | response_headers_ = maker_.GetResponseHeaders(status); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 249 | response_data_ = body; |
[email protected] | 6cca996b | 2013-01-25 07:43:36 | [diff] [blame] | 250 | } |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 251 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 252 | scoped_ptr<QuicEncryptedPacket> ConstructDataPacket( |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 253 | QuicPacketNumber packet_number, |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 254 | bool should_include_version, |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 255 | bool fin, |
| 256 | QuicStreamOffset offset, |
| 257 | base::StringPiece data) { |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 258 | return maker_.MakeDataPacket(packet_number, stream_id_, |
rtenneti | f4bdb54 | 2015-01-21 14:33:05 | [diff] [blame] | 259 | should_include_version, fin, offset, data); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 260 | } |
| 261 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 262 | scoped_ptr<QuicEncryptedPacket> ConstructRequestHeadersPacket( |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 263 | QuicPacketNumber packet_number, |
rtenneti | f4bdb54 | 2015-01-21 14:33:05 | [diff] [blame] | 264 | bool fin, |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 265 | RequestPriority request_priority, |
| 266 | size_t* spdy_headers_frame_length) { |
rtenneti | f4bdb54 | 2015-01-21 14:33:05 | [diff] [blame] | 267 | QuicPriority priority = |
| 268 | ConvertRequestPriorityToQuicPriority(request_priority); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 269 | return maker_.MakeRequestHeadersPacket( |
| 270 | packet_number, stream_id_, kIncludeVersion, fin, priority, |
| 271 | request_headers_, spdy_headers_frame_length); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | scoped_ptr<QuicEncryptedPacket> ConstructResponseHeadersPacket( |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 275 | QuicPacketNumber packet_number, |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 276 | bool fin, |
| 277 | size_t* spdy_headers_frame_length) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 278 | return maker_.MakeResponseHeadersPacket( |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 279 | packet_number, stream_id_, !kIncludeVersion, fin, response_headers_, |
| 280 | spdy_headers_frame_length); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | scoped_ptr<QuicEncryptedPacket> ConstructRstStreamPacket( |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 284 | QuicPacketNumber packet_number) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 285 | return maker_.MakeRstPacket( |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 286 | packet_number, true, stream_id_, |
rtenneti | 4a5df26 | 2014-11-07 00:43:58 | [diff] [blame] | 287 | AdjustErrorForVersion(QUIC_RST_ACKNOWLEDGEMENT, GetParam())); |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 288 | } |
| 289 | |
rtenneti | 6bd660b | 2015-07-18 00:19:53 | [diff] [blame] | 290 | scoped_ptr<QuicEncryptedPacket> ConstructRstStreamCancelledPacket( |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 291 | QuicPacketNumber packet_number) { |
| 292 | return maker_.MakeRstPacket(packet_number, !kIncludeVersion, stream_id_, |
rtenneti | 6bd660b | 2015-07-18 00:19:53 | [diff] [blame] | 293 | QUIC_STREAM_CANCELLED); |
| 294 | } |
| 295 | |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 296 | scoped_ptr<QuicEncryptedPacket> ConstructAckAndRstStreamPacket( |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 297 | QuicPacketNumber packet_number) { |
| 298 | return maker_.MakeAckAndRstPacket(packet_number, !kIncludeVersion, |
| 299 | stream_id_, QUIC_STREAM_CANCELLED, 2, 1, |
| 300 | !kIncludeCongestionFeedback); |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 301 | } |
| 302 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 303 | scoped_ptr<QuicEncryptedPacket> ConstructAckPacket( |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 304 | QuicPacketNumber packet_number, |
| 305 | QuicPacketNumber largest_received, |
| 306 | QuicPacketNumber least_unacked) { |
| 307 | return maker_.MakeAckPacket(packet_number, largest_received, least_unacked, |
| 308 | !kIncludeCongestionFeedback); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 309 | } |
| 310 | |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 311 | BoundNetLog net_log_; |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 312 | bool use_closing_stream_; |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 313 | MockSendAlgorithm* send_algorithm_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 314 | scoped_refptr<TestTaskRunner> runner_; |
[email protected] | 4356f0f | 2013-04-07 00:58:17 | [diff] [blame] | 315 | scoped_ptr<MockWrite[]> mock_writes_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 316 | MockClock clock_; |
| 317 | TestQuicConnection* connection_; |
[email protected] | 2cfc6bb8 | 2013-10-27 03:40:44 | [diff] [blame] | 318 | scoped_ptr<QuicConnectionHelper> helper_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 319 | testing::StrictMock<MockConnectionVisitor> visitor_; |
| 320 | scoped_ptr<QuicHttpStream> stream_; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 321 | TransportSecurityState transport_security_state_; |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 322 | scoped_ptr<QuicChromiumClientSession> session_; |
[email protected] | ef95114d | 2013-04-17 17:57:01 | [diff] [blame] | 323 | QuicCryptoClientConfig crypto_config_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 324 | TestCompletionCallback callback_; |
| 325 | HttpRequestInfo request_; |
| 326 | HttpRequestHeaders headers_; |
| 327 | HttpResponseInfo response_; |
| 328 | scoped_refptr<IOBufferWithSize> read_buffer_; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 329 | SpdyHeaderBlock request_headers_; |
| 330 | SpdyHeaderBlock response_headers_; |
[email protected] | 6cca996b | 2013-01-25 07:43:36 | [diff] [blame] | 331 | std::string request_data_; |
| 332 | std::string response_data_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 333 | |
| 334 | private: |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 335 | const QuicConnectionId connection_id_; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 336 | const QuicStreamId stream_id_; |
| 337 | QuicTestPacketMaker maker_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 338 | IPEndPoint self_addr_; |
| 339 | IPEndPoint peer_addr_; |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame] | 340 | MockRandom random_generator_; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 341 | MockCryptoClientStreamFactory crypto_client_stream_factory_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 342 | scoped_ptr<StaticSocketDataProvider> socket_data_; |
| 343 | std::vector<PacketToWrite> writes_; |
| 344 | }; |
| 345 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 346 | INSTANTIATE_TEST_CASE_P(Version, QuicHttpStreamTest, |
| 347 | ::testing::ValuesIn(QuicSupportedVersions())); |
| 348 | |
| 349 | TEST_P(QuicHttpStreamTest, RenewStreamForAuth) { |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 350 | Initialize(); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 351 | EXPECT_EQ(nullptr, stream_->RenewStreamForAuth()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 352 | } |
| 353 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 354 | TEST_P(QuicHttpStreamTest, CanReuseConnection) { |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 355 | Initialize(); |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 356 | EXPECT_FALSE(stream_->CanReuseConnection()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 357 | } |
| 358 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 359 | TEST_P(QuicHttpStreamTest, GetRequest) { |
| 360 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 361 | size_t spdy_request_header_frame_length; |
| 362 | AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY, |
| 363 | &spdy_request_header_frame_length)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 364 | Initialize(); |
| 365 | |
| 366 | request_.method = "GET"; |
| 367 | request_.url = GURL("http://www.google.com/"); |
| 368 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 369 | EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 370 | net_log_, callback_.callback())); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 371 | EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, |
| 372 | callback_.callback())); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 373 | |
| 374 | // Ack the request. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 375 | ProcessPacket(ConstructAckPacket(1, 0, 0)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 376 | |
| 377 | EXPECT_EQ(ERR_IO_PENDING, |
| 378 | stream_->ReadResponseHeaders(callback_.callback())); |
| 379 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 380 | SetResponse("404 Not Found", std::string()); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 381 | size_t spdy_response_header_frame_length; |
| 382 | ProcessPacket(ConstructResponseHeadersPacket( |
| 383 | 2, kFin, &spdy_response_header_frame_length)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 384 | |
| 385 | // Now that the headers have been processed, the callback will return. |
| 386 | EXPECT_EQ(OK, callback_.WaitForResult()); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 387 | ASSERT_TRUE(response_.headers.get()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 388 | EXPECT_EQ(404, response_.headers->response_code()); |
| 389 | EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
[email protected] | 6ed6743 | 2014-06-24 01:53:53 | [diff] [blame] | 390 | EXPECT_FALSE(response_.response_time.is_null()); |
| 391 | EXPECT_FALSE(response_.request_time.is_null()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 392 | |
| 393 | // There is no body, so this should return immediately. |
| 394 | EXPECT_EQ(0, stream_->ReadResponseBody(read_buffer_.get(), |
| 395 | read_buffer_->size(), |
| 396 | callback_.callback())); |
| 397 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 398 | EXPECT_TRUE(AtEof()); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 399 | |
| 400 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 401 | // headers and payload. |
| 402 | EXPECT_EQ(static_cast<int64_t>(spdy_request_header_frame_length), |
| 403 | stream_->GetTotalSentBytes()); |
| 404 | EXPECT_EQ(static_cast<int64_t>(spdy_response_header_frame_length), |
| 405 | stream_->GetTotalReceivedBytes()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 406 | } |
| 407 | |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 408 | // Regression test for http://crbug.com/288128 |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 409 | TEST_P(QuicHttpStreamTest, GetRequestLargeResponse) { |
| 410 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 411 | size_t spdy_request_headers_frame_length; |
| 412 | AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY, |
| 413 | &spdy_request_headers_frame_length)); |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 414 | Initialize(); |
| 415 | |
| 416 | request_.method = "GET"; |
| 417 | request_.url = GURL("http://www.google.com/"); |
| 418 | |
| 419 | EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 420 | net_log_, callback_.callback())); |
| 421 | EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, |
| 422 | callback_.callback())); |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 423 | |
| 424 | // Ack the request. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 425 | ProcessPacket(ConstructAckPacket(1, 0, 0)); |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 426 | |
| 427 | EXPECT_EQ(ERR_IO_PENDING, |
| 428 | stream_->ReadResponseHeaders(callback_.callback())); |
| 429 | |
| 430 | SpdyHeaderBlock headers; |
| 431 | headers[":status"] = "200 OK"; |
| 432 | headers[":version"] = "HTTP/1.1"; |
| 433 | headers["content-type"] = "text/plain"; |
rch | 7dd1570 | 2015-07-01 18:57:57 | [diff] [blame] | 434 | headers["big6"] = std::string(1000, 'x'); // Lots of x's. |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 435 | |
rch | 7dd1570 | 2015-07-01 18:57:57 | [diff] [blame] | 436 | response_headers_ = headers; |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 437 | size_t spdy_response_headers_frame_length; |
| 438 | ProcessPacket(ConstructResponseHeadersPacket( |
| 439 | 2, kFin, &spdy_response_headers_frame_length)); |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 440 | |
| 441 | // Now that the headers have been processed, the callback will return. |
| 442 | EXPECT_EQ(OK, callback_.WaitForResult()); |
| 443 | ASSERT_TRUE(response_.headers.get()); |
| 444 | EXPECT_EQ(200, response_.headers->response_code()); |
| 445 | EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 446 | |
| 447 | // There is no body, so this should return immediately. |
| 448 | EXPECT_EQ(0, stream_->ReadResponseBody(read_buffer_.get(), |
| 449 | read_buffer_->size(), |
| 450 | callback_.callback())); |
| 451 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 452 | EXPECT_TRUE(AtEof()); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 453 | |
| 454 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 455 | // headers and payload. |
| 456 | EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
| 457 | stream_->GetTotalSentBytes()); |
| 458 | EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length), |
| 459 | stream_->GetTotalReceivedBytes()); |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 460 | } |
| 461 | |
rch | f9f103cbc | 2014-08-30 05:28:04 | [diff] [blame] | 462 | // Regression test for http://crbug.com/409101 |
| 463 | TEST_P(QuicHttpStreamTest, SessionClosedBeforeSendRequest) { |
| 464 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
| 465 | Initialize(); |
| 466 | |
| 467 | request_.method = "GET"; |
| 468 | request_.url = GURL("http://www.google.com/"); |
| 469 | |
| 470 | EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 471 | net_log_, callback_.callback())); |
| 472 | |
| 473 | session_->connection()->CloseConnection(QUIC_NO_ERROR, true); |
| 474 | |
| 475 | EXPECT_EQ(ERR_CONNECTION_CLOSED, |
| 476 | stream_->SendRequest(headers_, &response_, |
| 477 | callback_.callback())); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 478 | |
| 479 | EXPECT_EQ(0, stream_->GetTotalSentBytes()); |
| 480 | EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
rch | f9f103cbc | 2014-08-30 05:28:04 | [diff] [blame] | 481 | } |
| 482 | |
rch | 11a114a | 2014-09-04 23:41:59 | [diff] [blame] | 483 | // Regression test for http://crbug.com/409871 |
| 484 | TEST_P(QuicHttpStreamTest, SessionClosedBeforeReadResponseHeaders) { |
| 485 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 486 | size_t spdy_request_headers_frame_length; |
| 487 | AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY, |
| 488 | &spdy_request_headers_frame_length)); |
rch | 11a114a | 2014-09-04 23:41:59 | [diff] [blame] | 489 | Initialize(); |
| 490 | |
| 491 | request_.method = "GET"; |
| 492 | request_.url = GURL("http://www.google.com/"); |
| 493 | |
| 494 | EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 495 | net_log_, callback_.callback())); |
| 496 | |
| 497 | EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, |
| 498 | callback_.callback())); |
| 499 | |
| 500 | session_->connection()->CloseConnection(QUIC_NO_ERROR, true); |
| 501 | |
| 502 | EXPECT_NE(OK, stream_->ReadResponseHeaders(callback_.callback())); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 503 | |
| 504 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 505 | // headers and payload. |
| 506 | EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
| 507 | stream_->GetTotalSentBytes()); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 508 | EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
rch | 11a114a | 2014-09-04 23:41:59 | [diff] [blame] | 509 | } |
| 510 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 511 | TEST_P(QuicHttpStreamTest, SendPostRequest) { |
| 512 | SetRequest("POST", "/", DEFAULT_PRIORITY); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 513 | size_t spdy_request_headers_frame_length; |
| 514 | AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY, |
| 515 | &spdy_request_headers_frame_length)); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 516 | AddWrite(ConstructDataPacket(2, kIncludeVersion, kFin, 0, kUploadData)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 517 | AddWrite(ConstructAckPacket(3, 3, 1)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 518 | |
| 519 | Initialize(); |
| 520 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 521 | ScopedVector<UploadElementReader> element_readers; |
| 522 | element_readers.push_back( |
| 523 | new UploadBytesElementReader(kUploadData, strlen(kUploadData))); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 524 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 525 | request_.method = "POST"; |
| 526 | request_.url = GURL("http://www.google.com/"); |
| 527 | request_.upload_data_stream = &upload_data_stream; |
[email protected] | 4db27d8 | 2012-12-20 11:50:24 | [diff] [blame] | 528 | ASSERT_EQ(OK, request_.upload_data_stream->Init(CompletionCallback())); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 529 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 530 | EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 531 | net_log_, callback_.callback())); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 532 | EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, |
| 533 | callback_.callback())); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 534 | |
| 535 | // Ack both packets in the request. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 536 | ProcessPacket(ConstructAckPacket(1, 0, 0)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 537 | |
| 538 | // Send the response headers (but not the body). |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 539 | SetResponse("200 OK", std::string()); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 540 | size_t spdy_response_headers_frame_length; |
| 541 | ProcessPacket(ConstructResponseHeadersPacket( |
| 542 | 2, !kFin, &spdy_response_headers_frame_length)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 543 | |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 544 | // The headers have arrived, but they are delivered asynchronously. |
| 545 | EXPECT_EQ(ERR_IO_PENDING, stream_->ReadResponseHeaders(callback_.callback())); |
| 546 | EXPECT_EQ(OK, callback_.WaitForResult()); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 547 | ASSERT_TRUE(response_.headers.get()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 548 | EXPECT_EQ(200, response_.headers->response_code()); |
| 549 | EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 550 | |
| 551 | // Send the response body. |
| 552 | const char kResponseBody[] = "Hello world!"; |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 553 | ProcessPacket(ConstructDataPacket(3, false, kFin, 0, kResponseBody)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 554 | // Since the body has already arrived, this should return immediately. |
| 555 | EXPECT_EQ(static_cast<int>(strlen(kResponseBody)), |
| 556 | stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 557 | callback_.callback())); |
| 558 | |
| 559 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 560 | EXPECT_TRUE(AtEof()); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 561 | |
| 562 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 563 | // headers and payload. |
| 564 | EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length + |
| 565 | strlen(kUploadData)), |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 566 | stream_->GetTotalSentBytes()); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 567 | EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length + |
| 568 | strlen(kResponseBody)), |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 569 | stream_->GetTotalReceivedBytes()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 570 | } |
| 571 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 572 | TEST_P(QuicHttpStreamTest, SendChunkedPostRequest) { |
| 573 | SetRequest("POST", "/", DEFAULT_PRIORITY); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 574 | size_t chunk_size = strlen(kUploadData); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 575 | size_t spdy_request_headers_frame_length; |
| 576 | AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY, |
| 577 | &spdy_request_headers_frame_length)); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 578 | AddWrite(ConstructDataPacket(2, kIncludeVersion, !kFin, 0, kUploadData)); |
| 579 | AddWrite(ConstructDataPacket(3, kIncludeVersion, kFin, chunk_size, |
| 580 | kUploadData)); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 581 | AddWrite(ConstructAckPacket(4, 3, 1)); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 582 | Initialize(); |
| 583 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 584 | ChunkedUploadDataStream upload_data_stream(0); |
| 585 | upload_data_stream.AppendData(kUploadData, chunk_size, false); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 586 | |
| 587 | request_.method = "POST"; |
| 588 | request_.url = GURL("http://www.google.com/"); |
| 589 | request_.upload_data_stream = &upload_data_stream; |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 590 | ASSERT_EQ(OK, request_.upload_data_stream->Init( |
| 591 | TestCompletionCallback().callback())); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 592 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 593 | ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 594 | net_log_, callback_.callback())); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 595 | ASSERT_EQ(ERR_IO_PENDING, stream_->SendRequest(headers_, &response_, |
| 596 | callback_.callback())); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 597 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 598 | upload_data_stream.AppendData(kUploadData, chunk_size, true); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 599 | EXPECT_EQ(OK, callback_.WaitForResult()); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 600 | |
| 601 | // Ack both packets in the request. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 602 | ProcessPacket(ConstructAckPacket(1, 0, 0)); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 603 | |
| 604 | // Send the response headers (but not the body). |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 605 | SetResponse("200 OK", std::string()); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 606 | size_t spdy_response_headers_frame_length; |
| 607 | ProcessPacket(ConstructResponseHeadersPacket( |
| 608 | 2, !kFin, &spdy_response_headers_frame_length)); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 609 | |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 610 | // The headers have arrived, but they are delivered asynchronously |
| 611 | EXPECT_EQ(ERR_IO_PENDING, stream_->ReadResponseHeaders(callback_.callback())); |
| 612 | EXPECT_EQ(OK, callback_.WaitForResult()); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 613 | ASSERT_TRUE(response_.headers.get()); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 614 | EXPECT_EQ(200, response_.headers->response_code()); |
| 615 | EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 616 | |
| 617 | // Send the response body. |
| 618 | const char kResponseBody[] = "Hello world!"; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 619 | ProcessPacket(ConstructDataPacket(3, false, kFin, response_data_.length(), |
| 620 | kResponseBody)); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 621 | |
| 622 | // Since the body has already arrived, this should return immediately. |
| 623 | ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), |
| 624 | stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 625 | callback_.callback())); |
| 626 | |
| 627 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 628 | EXPECT_TRUE(AtEof()); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 629 | |
| 630 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 631 | // headers and payload. |
| 632 | EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length + |
| 633 | strlen(kUploadData) * 2), |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 634 | stream_->GetTotalSentBytes()); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 635 | EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length + |
| 636 | strlen(kResponseBody)), |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 637 | stream_->GetTotalReceivedBytes()); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 638 | } |
| 639 | |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 640 | TEST_P(QuicHttpStreamTest, SendChunkedPostRequestWithFinalEmptyDataPacket) { |
| 641 | SetRequest("POST", "/", DEFAULT_PRIORITY); |
| 642 | size_t chunk_size = strlen(kUploadData); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 643 | size_t spdy_request_headers_frame_length; |
| 644 | AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY, |
| 645 | &spdy_request_headers_frame_length)); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 646 | AddWrite(ConstructDataPacket(2, kIncludeVersion, !kFin, 0, kUploadData)); |
| 647 | AddWrite(ConstructDataPacket(3, kIncludeVersion, kFin, chunk_size, "")); |
| 648 | AddWrite(ConstructAckPacket(4, 3, 1)); |
| 649 | Initialize(); |
| 650 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 651 | ChunkedUploadDataStream upload_data_stream(0); |
| 652 | upload_data_stream.AppendData(kUploadData, chunk_size, false); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 653 | |
| 654 | request_.method = "POST"; |
| 655 | request_.url = GURL("http://www.google.com/"); |
| 656 | request_.upload_data_stream = &upload_data_stream; |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 657 | ASSERT_EQ(OK, request_.upload_data_stream->Init( |
| 658 | TestCompletionCallback().callback())); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 659 | |
| 660 | ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 661 | net_log_, callback_.callback())); |
| 662 | ASSERT_EQ(ERR_IO_PENDING, stream_->SendRequest(headers_, &response_, |
| 663 | callback_.callback())); |
| 664 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 665 | upload_data_stream.AppendData(nullptr, 0, true); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 666 | EXPECT_EQ(OK, callback_.WaitForResult()); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 667 | |
| 668 | ProcessPacket(ConstructAckPacket(1, 0, 0)); |
| 669 | |
| 670 | // Send the response headers (but not the body). |
| 671 | SetResponse("200 OK", std::string()); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 672 | size_t spdy_response_headers_frame_length; |
| 673 | ProcessPacket(ConstructResponseHeadersPacket( |
| 674 | 2, !kFin, &spdy_response_headers_frame_length)); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 675 | |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 676 | // The headers have arrived, but they are delivered asynchronously |
| 677 | EXPECT_EQ(ERR_IO_PENDING, stream_->ReadResponseHeaders(callback_.callback())); |
| 678 | EXPECT_EQ(OK, callback_.WaitForResult()); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 679 | ASSERT_TRUE(response_.headers.get()); |
| 680 | EXPECT_EQ(200, response_.headers->response_code()); |
| 681 | EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 682 | |
| 683 | // Send the response body. |
| 684 | const char kResponseBody[] = "Hello world!"; |
| 685 | ProcessPacket(ConstructDataPacket(3, false, kFin, response_data_.length(), |
| 686 | kResponseBody)); |
| 687 | |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 688 | // The body has arrived, but it is delivered asynchronously |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 689 | ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), |
| 690 | stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 691 | callback_.callback())); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 692 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 693 | EXPECT_TRUE(AtEof()); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 694 | |
| 695 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 696 | // headers and payload. |
| 697 | EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length + |
| 698 | strlen(kUploadData)), |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 699 | stream_->GetTotalSentBytes()); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 700 | EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length + |
| 701 | strlen(kResponseBody)), |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 702 | stream_->GetTotalReceivedBytes()); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | TEST_P(QuicHttpStreamTest, SendChunkedPostRequestWithOneEmptyDataPacket) { |
| 706 | SetRequest("POST", "/", DEFAULT_PRIORITY); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 707 | size_t spdy_request_headers_frame_length; |
| 708 | AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY, |
| 709 | &spdy_request_headers_frame_length)); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 710 | AddWrite(ConstructDataPacket(2, kIncludeVersion, kFin, 0, "")); |
| 711 | AddWrite(ConstructAckPacket(3, 3, 1)); |
| 712 | Initialize(); |
| 713 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 714 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 715 | |
| 716 | request_.method = "POST"; |
| 717 | request_.url = GURL("http://www.google.com/"); |
| 718 | request_.upload_data_stream = &upload_data_stream; |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 719 | ASSERT_EQ(OK, request_.upload_data_stream->Init( |
| 720 | TestCompletionCallback().callback())); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 721 | |
| 722 | ASSERT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 723 | net_log_, callback_.callback())); |
| 724 | ASSERT_EQ(ERR_IO_PENDING, stream_->SendRequest(headers_, &response_, |
| 725 | callback_.callback())); |
| 726 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 727 | upload_data_stream.AppendData(nullptr, 0, true); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 728 | EXPECT_EQ(OK, callback_.WaitForResult()); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 729 | |
| 730 | ProcessPacket(ConstructAckPacket(1, 0, 0)); |
| 731 | |
| 732 | // Send the response headers (but not the body). |
| 733 | SetResponse("200 OK", std::string()); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 734 | size_t spdy_response_headers_frame_length; |
| 735 | ProcessPacket(ConstructResponseHeadersPacket( |
| 736 | 2, !kFin, &spdy_response_headers_frame_length)); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 737 | |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 738 | // The headers have arrived, but they are delivered asynchronously |
| 739 | EXPECT_EQ(ERR_IO_PENDING, stream_->ReadResponseHeaders(callback_.callback())); |
| 740 | EXPECT_EQ(OK, callback_.WaitForResult()); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 741 | ASSERT_TRUE(response_.headers.get()); |
| 742 | EXPECT_EQ(200, response_.headers->response_code()); |
| 743 | EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 744 | |
| 745 | // Send the response body. |
| 746 | const char kResponseBody[] = "Hello world!"; |
| 747 | ProcessPacket(ConstructDataPacket(3, false, kFin, response_data_.length(), |
| 748 | kResponseBody)); |
| 749 | |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 750 | // The body has arrived, but it is delivered asynchronously |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 751 | ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), |
| 752 | stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 753 | callback_.callback())); |
| 754 | |
| 755 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 756 | EXPECT_TRUE(AtEof()); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 757 | |
| 758 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 759 | // headers and payload. |
| 760 | EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
| 761 | stream_->GetTotalSentBytes()); |
| 762 | EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length + |
| 763 | strlen(kResponseBody)), |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 764 | stream_->GetTotalReceivedBytes()); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 765 | } |
| 766 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 767 | TEST_P(QuicHttpStreamTest, DestroyedEarly) { |
| 768 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 769 | size_t spdy_request_headers_frame_length; |
| 770 | AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY, |
| 771 | &spdy_request_headers_frame_length)); |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 772 | AddWrite(ConstructAckAndRstStreamPacket(2)); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 773 | use_closing_stream_ = true; |
| 774 | Initialize(); |
| 775 | |
| 776 | request_.method = "GET"; |
| 777 | request_.url = GURL("http://www.google.com/"); |
| 778 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 779 | EXPECT_EQ(OK, stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 780 | net_log_, callback_.callback())); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 781 | EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 782 | callback_.callback())); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 783 | |
| 784 | // Ack the request. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 785 | ProcessPacket(ConstructAckPacket(1, 0, 0)); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 786 | EXPECT_EQ(ERR_IO_PENDING, |
| 787 | stream_->ReadResponseHeaders(callback_.callback())); |
| 788 | |
| 789 | // Send the response with a body. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 790 | SetResponse("404 OK", "hello world!"); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 791 | // In the course of processing this packet, the QuicHttpStream close itself. |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 792 | ProcessPacket(ConstructResponseHeadersPacket(2, kFin, nullptr)); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 793 | |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 794 | base::MessageLoop::current()->RunUntilIdle(); |
| 795 | |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 796 | EXPECT_TRUE(AtEof()); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 797 | |
| 798 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 799 | // headers and payload. |
| 800 | EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
| 801 | stream_->GetTotalSentBytes()); |
| 802 | // Zero since the stream is closed before processing the headers. |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 803 | EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 804 | } |
| 805 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 806 | TEST_P(QuicHttpStreamTest, Priority) { |
| 807 | SetRequest("GET", "/", MEDIUM); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 808 | size_t spdy_request_headers_frame_length; |
| 809 | AddWrite(ConstructRequestHeadersPacket(1, kFin, MEDIUM, |
| 810 | &spdy_request_headers_frame_length)); |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 811 | AddWrite(ConstructAckAndRstStreamPacket(2)); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 812 | use_closing_stream_ = true; |
| 813 | Initialize(); |
| 814 | |
| 815 | request_.method = "GET"; |
| 816 | request_.url = GURL("http://www.google.com/"); |
| 817 | |
| 818 | EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, |
| 819 | net_log_, callback_.callback())); |
| 820 | |
| 821 | // Check that priority is highest. |
| 822 | QuicReliableClientStream* reliable_stream = |
| 823 | QuicHttpStreamPeer::GetQuicReliableClientStream(stream_.get()); |
| 824 | DCHECK(reliable_stream); |
[email protected] | 9f0dcd4e | 2014-01-16 15:58:14 | [diff] [blame] | 825 | DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 826 | reliable_stream->EffectivePriority()); |
| 827 | |
| 828 | EXPECT_EQ(OK, stream_->SendRequest(headers_, &response_, |
| 829 | callback_.callback())); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 830 | |
| 831 | // Check that priority has now dropped back to MEDIUM. |
| 832 | DCHECK_EQ(MEDIUM, ConvertQuicPriorityToRequestPriority( |
| 833 | reliable_stream->EffectivePriority())); |
| 834 | |
| 835 | // Ack the request. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 836 | ProcessPacket(ConstructAckPacket(1, 0, 0)); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 837 | EXPECT_EQ(ERR_IO_PENDING, |
| 838 | stream_->ReadResponseHeaders(callback_.callback())); |
| 839 | |
| 840 | // Send the response with a body. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 841 | SetResponse("404 OK", "hello world!"); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 842 | // In the course of processing this packet, the QuicHttpStream close itself. |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 843 | ProcessPacket(ConstructResponseHeadersPacket(2, kFin, nullptr)); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 844 | |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 845 | base::MessageLoop::current()->RunUntilIdle(); |
| 846 | |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 847 | EXPECT_TRUE(AtEof()); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 848 | |
| 849 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 850 | // headers and payload. |
| 851 | EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
| 852 | stream_->GetTotalSentBytes()); |
| 853 | // Zero since the stream is closed before processing the headers. |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 854 | EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 855 | } |
| 856 | |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 857 | // Regression test for http://crbug.com/294870 |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 858 | TEST_P(QuicHttpStreamTest, CheckPriorityWithNoDelegate) { |
| 859 | SetRequest("GET", "/", MEDIUM); |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 860 | use_closing_stream_ = true; |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 861 | |
[email protected] | 08da9adb | 2014-04-24 08:33:31 | [diff] [blame] | 862 | AddWrite(ConstructRstStreamPacket(1)); |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 863 | |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 864 | Initialize(); |
| 865 | |
| 866 | request_.method = "GET"; |
| 867 | request_.url = GURL("http://www.google.com/"); |
| 868 | |
| 869 | EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, |
| 870 | net_log_, callback_.callback())); |
| 871 | |
| 872 | // Check that priority is highest. |
| 873 | QuicReliableClientStream* reliable_stream = |
| 874 | QuicHttpStreamPeer::GetQuicReliableClientStream(stream_.get()); |
| 875 | DCHECK(reliable_stream); |
| 876 | QuicReliableClientStream::Delegate* delegate = reliable_stream->GetDelegate(); |
| 877 | DCHECK(delegate); |
[email protected] | 9f0dcd4e | 2014-01-16 15:58:14 | [diff] [blame] | 878 | DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 879 | reliable_stream->EffectivePriority()); |
| 880 | |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 881 | // Set Delegate to nullptr and make sure EffectivePriority returns highest |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 882 | // priority. |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 883 | reliable_stream->SetDelegate(nullptr); |
[email protected] | 9f0dcd4e | 2014-01-16 15:58:14 | [diff] [blame] | 884 | DCHECK_EQ(QuicWriteBlockedList::kHighestPriority, |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 885 | reliable_stream->EffectivePriority()); |
| 886 | reliable_stream->SetDelegate(delegate); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 887 | |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 888 | EXPECT_EQ(0, stream_->GetTotalSentBytes()); |
| 889 | EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 890 | } |
| 891 | |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 892 | } // namespace test |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 893 | } // namespace net |