[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 | |
rch | 675757b | 2016-07-29 16:40:11 | [diff] [blame] | 5 | #include "net/quic/chromium/quic_http_stream.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 6 | |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 9 | #include <memory> |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 10 | #include <utility> |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 11 | |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 12 | #include "base/memory/ptr_util.h" |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13 | #include "base/run_loop.h" |
xunjieli | 188bd40 | 2016-03-12 00:17:25 | [diff] [blame] | 14 | #include "base/strings/string_number_conversions.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 15 | #include "base/threading/thread_task_runner_handle.h" |
xunjieli | 84adaab | 2016-09-20 01:12:28 | [diff] [blame^] | 16 | #include "base/time/time.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17 | #include "net/base/chunked_upload_data_stream.h" |
| 18 | #include "net/base/elements_upload_data_stream.h" |
xunjieli | 84adaab | 2016-09-20 01:12:28 | [diff] [blame^] | 19 | #include "net/base/load_timing_info.h" |
| 20 | #include "net/base/load_timing_info_test_util.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 21 | #include "net/base/net_errors.h" |
| 22 | #include "net/base/test_completion_callback.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 23 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 24 | #include "net/http/http_response_headers.h" |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 25 | #include "net/http/transport_security_state.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 26 | #include "net/log/net_log_event_type.h" |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 27 | #include "net/log/test_net_log.h" |
| 28 | #include "net/log/test_net_log_util.h" |
rch | 675757b | 2016-07-29 16:40:11 | [diff] [blame] | 29 | #include "net/quic/chromium/crypto/proof_verifier_chromium.h" |
| 30 | #include "net/quic/chromium/quic_chromium_alarm_factory.h" |
| 31 | #include "net/quic/chromium/quic_chromium_connection_helper.h" |
| 32 | #include "net/quic/chromium/quic_chromium_packet_reader.h" |
| 33 | #include "net/quic/chromium/quic_chromium_packet_writer.h" |
rch | d4db7c15 | 2016-07-29 21:58:12 | [diff] [blame] | 34 | #include "net/quic/core/congestion_control/send_algorithm_interface.h" |
| 35 | #include "net/quic/core/crypto/crypto_protocol.h" |
| 36 | #include "net/quic/core/crypto/quic_decrypter.h" |
| 37 | #include "net/quic/core/crypto/quic_encrypter.h" |
| 38 | #include "net/quic/core/crypto/quic_server_info.h" |
| 39 | #include "net/quic/core/quic_connection.h" |
| 40 | #include "net/quic/core/quic_http_utils.h" |
| 41 | #include "net/quic/core/quic_write_blocked_list.h" |
| 42 | #include "net/quic/core/spdy_utils.h" |
rch | 1fe2eeb | 2015-10-26 14:45:57 | [diff] [blame] | 43 | #include "net/quic/test_tools/crypto_test_utils.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 44 | #include "net/quic/test_tools/mock_clock.h" |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 45 | #include "net/quic/test_tools/mock_crypto_client_stream_factory.h" |
[email protected] | 9db44391 | 2013-02-25 05:27:03 | [diff] [blame] | 46 | #include "net/quic/test_tools/mock_random.h" |
[email protected] | b1f287d | 2012-12-22 17:25:39 | [diff] [blame] | 47 | #include "net/quic/test_tools/quic_connection_peer.h" |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 48 | #include "net/quic/test_tools/quic_test_packet_maker.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 49 | #include "net/quic/test_tools/quic_test_utils.h" |
| 50 | #include "net/quic/test_tools/test_task_runner.h" |
tbansal | ca83c00 | 2016-04-28 20:56:28 | [diff] [blame] | 51 | #include "net/socket/socket_performance_watcher.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 52 | #include "net/socket/socket_test_util.h" |
[email protected] | 6cca996b | 2013-01-25 07:43:36 | [diff] [blame] | 53 | #include "net/spdy/spdy_frame_builder.h" |
| 54 | #include "net/spdy/spdy_framer.h" |
| 55 | #include "net/spdy/spdy_http_utils.h" |
| 56 | #include "net/spdy/spdy_protocol.h" |
rch | 03b7a20 | 2016-02-05 00:54:20 | [diff] [blame] | 57 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 58 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 59 | #include "net/test/test_data_directory.h" |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 60 | #include "testing/gmock/include/gmock/gmock.h" |
| 61 | #include "testing/gtest/include/gtest/gtest.h" |
| 62 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 63 | using net::test::IsError; |
| 64 | using net::test::IsOk; |
| 65 | |
bnc | 614a92d3 | 2016-04-04 13:56:07 | [diff] [blame] | 66 | using std::string; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 67 | using testing::_; |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 68 | using testing::AnyNumber; |
| 69 | using testing::Return; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 70 | |
| 71 | namespace net { |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 72 | namespace test { |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 73 | namespace { |
| 74 | |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 75 | const char kUploadData[] = "Really nifty data!"; |
rch | 9ae5b3b | 2016-02-11 00:36:29 | [diff] [blame] | 76 | const char kDefaultServerHostName[] = "www.example.org"; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 77 | const uint16_t kDefaultServerPort = 80; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 78 | |
| 79 | class TestQuicConnection : public QuicConnection { |
| 80 | public: |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 81 | TestQuicConnection(const QuicVersionVector& versions, |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 82 | QuicConnectionId connection_id, |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 83 | IPEndPoint address, |
rch | 12fef55 | 2016-01-15 16:26:31 | [diff] [blame] | 84 | QuicChromiumConnectionHelper* helper, |
rch | 16c74d1d | 2016-04-22 06:14:07 | [diff] [blame] | 85 | QuicChromiumAlarmFactory* alarm_factory, |
jdorfman | 90d185f3 | 2016-01-15 13:22:47 | [diff] [blame] | 86 | QuicPacketWriter* writer) |
[email protected] | 66cd2d6 | 2014-08-01 18:42:39 | [diff] [blame] | 87 | : QuicConnection(connection_id, |
| 88 | address, |
| 89 | helper, |
rch | 16c74d1d | 2016-04-22 06:14:07 | [diff] [blame] | 90 | alarm_factory, |
jdorfman | 90d185f3 | 2016-01-15 13:22:47 | [diff] [blame] | 91 | writer, |
rtenneti | 6f48aa9 | 2015-03-16 02:18:48 | [diff] [blame] | 92 | true /* owns_writer */, |
| 93 | Perspective::IS_CLIENT, |
rtenneti | 6f48aa9 | 2015-03-16 02:18:48 | [diff] [blame] | 94 | versions) {} |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 95 | |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 96 | void SetSendAlgorithm(SendAlgorithmInterface* send_algorithm) { |
rch | daf5a85 | 2016-07-26 19:42:50 | [diff] [blame] | 97 | QuicConnectionPeer::SetSendAlgorithm(this, kDefaultPathId, send_algorithm); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 98 | } |
| 99 | }; |
| 100 | |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 101 | // Subclass of QuicHttpStream that closes itself when the first piece of data |
| 102 | // is received. |
| 103 | class AutoClosingStream : public QuicHttpStream { |
| 104 | public: |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 105 | explicit AutoClosingStream( |
| 106 | const base::WeakPtr<QuicChromiumClientSession>& session) |
| 107 | : QuicHttpStream(session) {} |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 108 | |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 109 | void OnHeadersAvailable(const SpdyHeaderBlock& headers, |
| 110 | size_t frame_len) override { |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 111 | Close(false); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 112 | } |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 113 | |
| 114 | void OnDataAvailable() override { Close(false); } |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 115 | }; |
| 116 | |
maksim.sisov | 84e20c9 | 2016-06-23 08:49:34 | [diff] [blame] | 117 | // UploadDataStream that always returns errors on data read. |
| 118 | class ReadErrorUploadDataStream : public UploadDataStream { |
| 119 | public: |
| 120 | enum class FailureMode { SYNC, ASYNC }; |
| 121 | |
| 122 | explicit ReadErrorUploadDataStream(FailureMode mode) |
| 123 | : UploadDataStream(true, 0), async_(mode), weak_factory_(this) {} |
| 124 | ~ReadErrorUploadDataStream() override {} |
| 125 | |
| 126 | private: |
| 127 | void CompleteRead() { UploadDataStream::OnReadCompleted(ERR_FAILED); } |
| 128 | |
| 129 | // UploadDataStream implementation: |
maksim.sisov | 819ba85 | 2016-08-17 08:22:52 | [diff] [blame] | 130 | int InitInternal(const BoundNetLog& net_log) override { return OK; } |
maksim.sisov | 84e20c9 | 2016-06-23 08:49:34 | [diff] [blame] | 131 | |
| 132 | int ReadInternal(IOBuffer* buf, int buf_len) override { |
| 133 | if (async_ == FailureMode::ASYNC) { |
| 134 | base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 135 | FROM_HERE, base::Bind(&ReadErrorUploadDataStream::CompleteRead, |
| 136 | weak_factory_.GetWeakPtr())); |
| 137 | return ERR_IO_PENDING; |
| 138 | } |
| 139 | return ERR_FAILED; |
| 140 | } |
| 141 | |
| 142 | void ResetInternal() override {} |
| 143 | |
| 144 | const FailureMode async_; |
| 145 | |
| 146 | base::WeakPtrFactory<ReadErrorUploadDataStream> weak_factory_; |
| 147 | |
| 148 | DISALLOW_COPY_AND_ASSIGN(ReadErrorUploadDataStream); |
| 149 | }; |
| 150 | |
xunjieli | 8dff50b | 2016-07-22 14:19:06 | [diff] [blame] | 151 | // A Callback that deletes the QuicHttpStream. |
| 152 | class DeleteStreamCallback : public TestCompletionCallbackBase { |
| 153 | public: |
| 154 | DeleteStreamCallback(std::unique_ptr<QuicHttpStream> stream) |
| 155 | : stream_(std::move(stream)), |
| 156 | callback_(base::Bind(&DeleteStreamCallback::DeleteStream, |
| 157 | base::Unretained(this))) {} |
| 158 | |
| 159 | const CompletionCallback& callback() const { return callback_; } |
| 160 | |
| 161 | private: |
| 162 | void DeleteStream(int result) { |
| 163 | stream_.reset(); |
| 164 | SetResult(result); |
| 165 | } |
| 166 | |
| 167 | std::unique_ptr<QuicHttpStream> stream_; |
| 168 | CompletionCallback callback_; |
| 169 | }; |
| 170 | |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 171 | } // namespace |
| 172 | |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 173 | class QuicHttpStreamPeer { |
| 174 | public: |
rch | 12fef55 | 2016-01-15 16:26:31 | [diff] [blame] | 175 | static QuicChromiumClientStream* GetQuicChromiumClientStream( |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 176 | QuicHttpStream* stream) { |
| 177 | return stream->stream_; |
| 178 | } |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 179 | |
| 180 | static bool WasHandshakeConfirmed(QuicHttpStream* stream) { |
| 181 | return stream->was_handshake_confirmed_; |
| 182 | } |
| 183 | |
| 184 | static void SetHandshakeConfirmed(QuicHttpStream* stream, bool confirmed) { |
| 185 | stream->was_handshake_confirmed_ = confirmed; |
| 186 | } |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 187 | }; |
| 188 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 189 | class QuicHttpStreamTest : public ::testing::TestWithParam<QuicVersion> { |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 190 | protected: |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 191 | static const bool kFin = true; |
| 192 | static const bool kIncludeVersion = true; |
| 193 | static const bool kIncludeCongestionFeedback = true; |
| 194 | |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 195 | // Holds a packet to be written to the wire, and the IO mode that should |
| 196 | // be used by the mock socket when performing the write. |
| 197 | struct PacketToWrite { |
jokulik | f2bd55c5 | 2016-03-24 22:35:30 | [diff] [blame] | 198 | PacketToWrite(IoMode mode, QuicReceivedPacket* packet) |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 199 | : mode(mode), packet(packet) {} |
rtenneti | 15656ae | 2016-01-23 03:05:03 | [diff] [blame] | 200 | PacketToWrite(IoMode mode, int rv) : mode(mode), packet(nullptr), rv(rv) {} |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 201 | IoMode mode; |
jokulik | f2bd55c5 | 2016-03-24 22:35:30 | [diff] [blame] | 202 | QuicReceivedPacket* packet; |
rtenneti | 15656ae | 2016-01-23 03:05:03 | [diff] [blame] | 203 | int rv; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 204 | }; |
| 205 | |
| 206 | QuicHttpStreamTest() |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 207 | : use_closing_stream_(false), |
rch | 1fe2eeb | 2015-10-26 14:45:57 | [diff] [blame] | 208 | crypto_config_(CryptoTestUtils::ProofVerifierForTesting()), |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 209 | read_buffer_(new IOBufferWithSize(4096)), |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 210 | promise_id_(kServerDataStreamId1), |
[email protected] | 66ae596 | 2014-05-22 11:13:05 | [diff] [blame] | 211 | stream_id_(kClientDataStreamId1), |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 212 | connection_id_(2), |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 213 | client_maker_(GetParam(), |
| 214 | connection_id_, |
| 215 | &clock_, |
| 216 | kDefaultServerHostName, |
| 217 | Perspective::IS_CLIENT), |
| 218 | server_maker_(GetParam(), |
| 219 | connection_id_, |
| 220 | &clock_, |
| 221 | kDefaultServerHostName, |
| 222 | Perspective::IS_SERVER), |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 223 | random_generator_(0), |
| 224 | response_offset_(0) { |
martijn | 21968ea | 2016-02-24 18:46:20 | [diff] [blame] | 225 | IPAddress ip(192, 0, 2, 33); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 226 | peer_addr_ = IPEndPoint(ip, 443); |
| 227 | self_addr_ = IPEndPoint(ip, 8435); |
rtenneti | 4b06ae7 | 2014-08-26 03:43:43 | [diff] [blame] | 228 | clock_.AdvanceTime(QuicTime::Delta::FromMilliseconds(20)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | ~QuicHttpStreamTest() { |
rtenneti | 85dcfac2 | 2015-03-27 20:22:19 | [diff] [blame] | 232 | session_->CloseSessionOnError(ERR_ABORTED, QUIC_INTERNAL_ERROR); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 233 | for (size_t i = 0; i < writes_.size(); i++) { |
| 234 | delete writes_[i].packet; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | // Adds a packet to the list of expected writes. |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 239 | void AddWrite(std::unique_ptr<QuicReceivedPacket> packet) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 240 | writes_.push_back(PacketToWrite(SYNCHRONOUS, packet.release())); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 241 | } |
| 242 | |
rtenneti | 15656ae | 2016-01-23 03:05:03 | [diff] [blame] | 243 | void AddWrite(IoMode mode, int rv) { |
| 244 | writes_.push_back(PacketToWrite(mode, rv)); |
| 245 | } |
| 246 | |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 247 | // Returns the packet to be written at position |pos|. |
jokulik | f2bd55c5 | 2016-03-24 22:35:30 | [diff] [blame] | 248 | QuicReceivedPacket* GetWrite(size_t pos) { return writes_[pos].packet; } |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 249 | |
| 250 | bool AtEof() { |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 251 | return socket_data_->AllReadDataConsumed() && |
| 252 | socket_data_->AllWriteDataConsumed(); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 253 | } |
| 254 | |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 255 | void ProcessPacket(std::unique_ptr<QuicReceivedPacket> packet) { |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 256 | connection_->ProcessUdpPacket(self_addr_, peer_addr_, *packet); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | // Configures the test fixture to use the list of expected writes. |
| 260 | void Initialize() { |
| 261 | mock_writes_.reset(new MockWrite[writes_.size()]); |
| 262 | for (size_t i = 0; i < writes_.size(); i++) { |
rtenneti | 15656ae | 2016-01-23 03:05:03 | [diff] [blame] | 263 | if (writes_[i].packet == nullptr) { |
| 264 | mock_writes_[i] = MockWrite(writes_[i].mode, writes_[i].rv, i); |
| 265 | } else { |
| 266 | mock_writes_[i] = MockWrite(writes_[i].mode, writes_[i].packet->data(), |
| 267 | writes_[i].packet->length()); |
| 268 | } |
bnc | 614a92d3 | 2016-04-04 13:56:07 | [diff] [blame] | 269 | } |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 270 | |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 271 | socket_data_.reset(new StaticSocketDataProvider( |
| 272 | nullptr, 0, mock_writes_.get(), writes_.size())); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 273 | |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 274 | std::unique_ptr<MockUDPClientSocket> socket(new MockUDPClientSocket( |
xunjieli | b53b38c | 2016-03-24 15:54:36 | [diff] [blame] | 275 | socket_data_.get(), net_log_.bound().net_log())); |
[email protected] | e13201d8 | 2012-12-12 05:00:32 | [diff] [blame] | 276 | socket->Connect(peer_addr_); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 277 | runner_ = new TestTaskRunner(&clock_); |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 278 | send_algorithm_ = new MockSendAlgorithm(); |
rch | 7dd1570 | 2015-07-01 18:57:57 | [diff] [blame] | 279 | EXPECT_CALL(*send_algorithm_, InRecovery()).WillRepeatedly(Return(false)); |
| 280 | EXPECT_CALL(*send_algorithm_, InSlowStart()).WillRepeatedly(Return(false)); |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 281 | EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)) |
| 282 | .WillRepeatedly(Return(true)); |
rtenneti | 44f4a2e | 2015-08-07 14:00:07 | [diff] [blame] | 283 | EXPECT_CALL(*send_algorithm_, RetransmissionDelay()) |
| 284 | .WillRepeatedly(Return(QuicTime::Delta::Zero())); |
| 285 | EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) |
| 286 | .WillRepeatedly(Return(kMaxPacketSize)); |
jokulik | 0e0a00c3 | 2016-06-13 21:51:58 | [diff] [blame] | 287 | EXPECT_CALL(*send_algorithm_, PacingRate(_)) |
rtenneti | 44f4a2e | 2015-08-07 14:00:07 | [diff] [blame] | 288 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
fnk | f57804c | 2016-03-17 20:57:07 | [diff] [blame] | 289 | EXPECT_CALL(*send_algorithm_, TimeUntilSend(_, _)) |
rtenneti | 44f4a2e | 2015-08-07 14:00:07 | [diff] [blame] | 290 | .WillRepeatedly(Return(QuicTime::Delta::Zero())); |
| 291 | EXPECT_CALL(*send_algorithm_, BandwidthEstimate()) |
| 292 | .WillRepeatedly(Return(QuicBandwidth::Zero())); |
rch | 1e543ec | 2015-03-29 07:04:40 | [diff] [blame] | 293 | EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)).Times(AnyNumber()); |
rch | 16c74d1d | 2016-04-22 06:14:07 | [diff] [blame] | 294 | helper_.reset( |
| 295 | new QuicChromiumConnectionHelper(&clock_, &random_generator_)); |
| 296 | alarm_factory_.reset(new QuicChromiumAlarmFactory(runner_.get(), &clock_)); |
| 297 | |
| 298 | connection_ = |
| 299 | new TestQuicConnection(SupportedVersions(GetParam()), connection_id_, |
| 300 | peer_addr_, helper_.get(), alarm_factory_.get(), |
| 301 | new QuicChromiumPacketWriter(socket.get())); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 302 | connection_->set_visitor(&visitor_); |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 303 | connection_->SetSendAlgorithm(send_algorithm_); |
rch | 03b7a20 | 2016-02-05 00:54:20 | [diff] [blame] | 304 | |
| 305 | // Load a certificate that is valid for *.example.org |
| 306 | scoped_refptr<X509Certificate> test_cert( |
| 307 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem")); |
| 308 | EXPECT_TRUE(test_cert.get()); |
| 309 | |
| 310 | verify_details_.cert_verify_result.verified_cert = test_cert; |
| 311 | verify_details_.cert_verify_result.is_issued_by_known_root = true; |
| 312 | crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details_); |
| 313 | |
xunjieli | 84adaab | 2016-09-20 01:12:28 | [diff] [blame^] | 314 | base::TimeTicks dns_end = base::TimeTicks::Now(); |
| 315 | base::TimeTicks dns_start = dns_end - base::TimeDelta::FromMilliseconds(1); |
ckrasic | 4f9d88d | 2015-07-22 22:23:16 | [diff] [blame] | 316 | session_.reset(new QuicChromiumClientSession( |
xunjieli | b53b38c | 2016-03-24 15:54:36 | [diff] [blame] | 317 | connection_, std::move(socket), |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 318 | /*stream_factory=*/nullptr, &crypto_client_stream_factory_, &clock_, |
bnc | 614a92d3 | 2016-04-04 13:56:07 | [diff] [blame] | 319 | &transport_security_state_, |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 320 | base::WrapUnique(static_cast<QuicServerInfo*>(nullptr)), |
bnc | b07c0553 | 2015-05-14 19:07:20 | [diff] [blame] | 321 | QuicServerId(kDefaultServerHostName, kDefaultServerPort, |
rch | 1fe2eeb | 2015-10-26 14:45:57 | [diff] [blame] | 322 | PRIVACY_MODE_DISABLED), |
rtenneti | 1cd3b16 | 2015-09-29 02:58:28 | [diff] [blame] | 323 | kQuicYieldAfterPacketsRead, |
| 324 | QuicTime::Delta::FromMilliseconds(kQuicYieldAfterDurationMilliseconds), |
rtenneti | a75df62 | 2015-06-21 23:59:50 | [diff] [blame] | 325 | /*cert_verify_flags=*/0, DefaultQuicConfig(), &crypto_config_, |
xunjieli | 84adaab | 2016-09-20 01:12:28 | [diff] [blame^] | 326 | "CONNECTION_UNKNOWN", dns_start, dns_end, &push_promise_index_, |
| 327 | base::ThreadTaskRunnerHandle::Get().get(), |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 328 | /*socket_performance_watcher=*/nullptr, net_log_.bound().net_log())); |
rtenneti | d39bd76 | 2015-06-12 01:05:52 | [diff] [blame] | 329 | session_->Initialize(); |
xunjieli | 100937eb5 | 2016-09-15 20:09:37 | [diff] [blame] | 330 | TestCompletionCallback callback; |
| 331 | session_->CryptoConnect(/*require_confirmation=*/false, |
| 332 | callback.callback()); |
[email protected] | 8ba8121 | 2013-05-03 13:11:48 | [diff] [blame] | 333 | EXPECT_TRUE(session_->IsCryptoHandshakeConfirmed()); |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 334 | stream_.reset(use_closing_stream_ |
| 335 | ? new AutoClosingStream(session_->GetWeakPtr()) |
| 336 | : new QuicHttpStream(session_->GetWeakPtr())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 337 | |
| 338 | promised_stream_.reset(use_closing_stream_ |
| 339 | ? new AutoClosingStream(session_->GetWeakPtr()) |
| 340 | : new QuicHttpStream(session_->GetWeakPtr())); |
| 341 | |
| 342 | push_promise_[":path"] = "/bar"; |
| 343 | push_promise_[":authority"] = "www.example.org"; |
| 344 | push_promise_[":version"] = "HTTP/1.1"; |
| 345 | push_promise_[":method"] = "GET"; |
| 346 | push_promise_[":scheme"] = "https"; |
| 347 | |
| 348 | promised_response_[":status"] = "200 OK"; |
| 349 | promised_response_[":version"] = "HTTP/1.1"; |
| 350 | promised_response_["content-type"] = "text/plain"; |
| 351 | |
| 352 | promise_url_ = SpdyUtils::GetUrlFromHeaderBlock(push_promise_); |
| 353 | |
| 354 | serialized_push_promise_ = |
| 355 | SpdyUtils::SerializeUncompressedHeaders(push_promise_); |
[email protected] | 6cca996b | 2013-01-25 07:43:36 | [diff] [blame] | 356 | } |
| 357 | |
bnc | 614a92d3 | 2016-04-04 13:56:07 | [diff] [blame] | 358 | void SetRequest(const string& method, |
| 359 | const string& path, |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 360 | RequestPriority priority) { |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 361 | request_headers_ = client_maker_.GetRequestHeaders(method, "http", path); |
[email protected] | 6cca996b | 2013-01-25 07:43:36 | [diff] [blame] | 362 | } |
| 363 | |
bnc | 614a92d3 | 2016-04-04 13:56:07 | [diff] [blame] | 364 | void SetResponse(const string& status, const string& body) { |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 365 | response_headers_ = server_maker_.GetResponseHeaders(status); |
[email protected] | 92bf17c | 2014-03-03 21:14:03 | [diff] [blame] | 366 | response_data_ = body; |
[email protected] | 6cca996b | 2013-01-25 07:43:36 | [diff] [blame] | 367 | } |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 368 | |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 369 | std::unique_ptr<QuicReceivedPacket> InnerConstructDataPacket( |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 370 | QuicPacketNumber packet_number, |
| 371 | QuicStreamId stream_id, |
| 372 | bool should_include_version, |
| 373 | bool fin, |
| 374 | QuicStreamOffset offset, |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 375 | base::StringPiece data, |
| 376 | QuicTestPacketMaker* maker) { |
| 377 | return maker->MakeDataPacket(packet_number, stream_id, |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 378 | should_include_version, fin, offset, data); |
| 379 | } |
| 380 | |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 381 | std::unique_ptr<QuicReceivedPacket> ConstructClientDataPacket( |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 382 | QuicPacketNumber packet_number, |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 383 | bool should_include_version, |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 384 | bool fin, |
| 385 | QuicStreamOffset offset, |
| 386 | base::StringPiece data) { |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 387 | return InnerConstructDataPacket(packet_number, stream_id_, |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 388 | should_include_version, fin, offset, data, |
| 389 | &client_maker_); |
| 390 | } |
| 391 | |
| 392 | std::unique_ptr<QuicReceivedPacket> ConstructServerDataPacket( |
| 393 | QuicPacketNumber packet_number, |
| 394 | bool should_include_version, |
| 395 | bool fin, |
| 396 | QuicStreamOffset offset, |
| 397 | base::StringPiece data) { |
| 398 | return InnerConstructDataPacket(packet_number, stream_id_, |
| 399 | should_include_version, fin, offset, data, |
| 400 | &server_maker_); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 401 | } |
| 402 | |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 403 | std::unique_ptr<QuicReceivedPacket> InnerConstructRequestHeadersPacket( |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 404 | QuicPacketNumber packet_number, |
| 405 | QuicStreamId stream_id, |
| 406 | bool should_include_version, |
| 407 | bool fin, |
| 408 | RequestPriority request_priority, |
xunjieli | 100937eb5 | 2016-09-15 20:09:37 | [diff] [blame] | 409 | size_t* spdy_headers_frame_length, |
| 410 | QuicStreamOffset* offset) { |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 411 | SpdyPriority priority = |
| 412 | ConvertRequestPriorityToQuicPriority(request_priority); |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 413 | return client_maker_.MakeRequestHeadersPacket( |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 414 | packet_number, stream_id, should_include_version, fin, priority, |
xunjieli | 100937eb5 | 2016-09-15 20:09:37 | [diff] [blame] | 415 | std::move(request_headers_), spdy_headers_frame_length, offset); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 416 | } |
| 417 | |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 418 | std::unique_ptr<QuicReceivedPacket> ConstructRequestHeadersPacket( |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 419 | QuicPacketNumber packet_number, |
rtenneti | f4bdb54 | 2015-01-21 14:33:05 | [diff] [blame] | 420 | bool fin, |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 421 | RequestPriority request_priority, |
| 422 | size_t* spdy_headers_frame_length) { |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 423 | return InnerConstructRequestHeadersPacket( |
| 424 | packet_number, stream_id_, kIncludeVersion, fin, request_priority, |
xunjieli | 100937eb5 | 2016-09-15 20:09:37 | [diff] [blame] | 425 | spdy_headers_frame_length, nullptr); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 426 | } |
| 427 | |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 428 | std::unique_ptr<QuicReceivedPacket> InnerConstructResponseHeadersPacket( |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 429 | QuicPacketNumber packet_number, |
| 430 | QuicStreamId stream_id, |
| 431 | bool fin, |
| 432 | size_t* spdy_headers_frame_length) { |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 433 | return server_maker_.MakeResponseHeadersPacket( |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 434 | packet_number, stream_id, !kIncludeVersion, fin, |
| 435 | std::move(response_headers_), spdy_headers_frame_length, |
| 436 | &response_offset_); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 437 | } |
| 438 | |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 439 | std::unique_ptr<QuicReceivedPacket> ConstructResponseHeadersPacket( |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 440 | QuicPacketNumber packet_number, |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 441 | bool fin, |
| 442 | size_t* spdy_headers_frame_length) { |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 443 | return InnerConstructResponseHeadersPacket(packet_number, stream_id_, fin, |
| 444 | spdy_headers_frame_length); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 445 | } |
| 446 | |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 447 | std::unique_ptr<QuicReceivedPacket> ConstructResponseHeadersPacketWithOffset( |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 448 | QuicPacketNumber packet_number, |
| 449 | bool fin, |
| 450 | size_t* spdy_headers_frame_length, |
| 451 | QuicStreamOffset* offset) { |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 452 | return server_maker_.MakeResponseHeadersPacket( |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 453 | packet_number, stream_id_, !kIncludeVersion, fin, |
| 454 | std::move(response_headers_), spdy_headers_frame_length, offset); |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 455 | } |
| 456 | |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 457 | std::unique_ptr<QuicReceivedPacket> ConstructResponseTrailersPacket( |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 458 | QuicPacketNumber packet_number, |
| 459 | bool fin, |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 460 | SpdyHeaderBlock trailers, |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 461 | size_t* spdy_headers_frame_length, |
| 462 | QuicStreamOffset* offset) { |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 463 | return server_maker_.MakeResponseHeadersPacket( |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 464 | packet_number, stream_id_, !kIncludeVersion, fin, std::move(trailers), |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 465 | spdy_headers_frame_length, offset); |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 466 | } |
| 467 | |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 468 | std::unique_ptr<QuicReceivedPacket> ConstructClientRstStreamPacket( |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 469 | QuicPacketNumber packet_number) { |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 470 | return client_maker_.MakeRstPacket( |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 471 | packet_number, true, stream_id_, |
rtenneti | 4a5df26 | 2014-11-07 00:43:58 | [diff] [blame] | 472 | AdjustErrorForVersion(QUIC_RST_ACKNOWLEDGEMENT, GetParam())); |
[email protected] | 06ff515 | 2013-08-29 01:03:05 | [diff] [blame] | 473 | } |
| 474 | |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 475 | std::unique_ptr<QuicReceivedPacket> ConstructClientRstStreamCancelledPacket( |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 476 | QuicPacketNumber packet_number) { |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 477 | return client_maker_.MakeRstPacket(packet_number, !kIncludeVersion, |
| 478 | stream_id_, QUIC_STREAM_CANCELLED); |
rtenneti | 6bd660b | 2015-07-18 00:19:53 | [diff] [blame] | 479 | } |
| 480 | |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 481 | std::unique_ptr<QuicReceivedPacket> |
| 482 | ConstructClientRstStreamVaryMismatchPacket(QuicPacketNumber packet_number) { |
| 483 | return client_maker_.MakeRstPacket(packet_number, !kIncludeVersion, |
| 484 | promise_id_, QUIC_PROMISE_VARY_MISMATCH); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 485 | } |
| 486 | |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 487 | std::unique_ptr<QuicReceivedPacket> ConstructAckAndRstStreamPacket( |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 488 | QuicPacketNumber packet_number, |
| 489 | QuicPacketNumber largest_received, |
| 490 | QuicPacketNumber ack_least_unacked, |
| 491 | QuicPacketNumber stop_least_unacked) { |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 492 | return client_maker_.MakeAckAndRstPacket( |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 493 | packet_number, !kIncludeVersion, stream_id_, QUIC_STREAM_CANCELLED, |
| 494 | largest_received, ack_least_unacked, stop_least_unacked, |
| 495 | !kIncludeCongestionFeedback); |
| 496 | } |
| 497 | |
maksim.sisov | 84e20c9 | 2016-06-23 08:49:34 | [diff] [blame] | 498 | std::unique_ptr<QuicReceivedPacket> ConstructClientRstStreamErrorPacket( |
| 499 | QuicPacketNumber packet_number, |
| 500 | bool include_version) { |
| 501 | return client_maker_.MakeRstPacket(packet_number, include_version, |
| 502 | stream_id_, |
| 503 | QUIC_ERROR_PROCESSING_STREAM); |
| 504 | } |
| 505 | |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 506 | std::unique_ptr<QuicReceivedPacket> ConstructAckAndRstStreamPacket( |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 507 | QuicPacketNumber packet_number) { |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 508 | return ConstructAckAndRstStreamPacket(packet_number, 2, 1, 1); |
[email protected] | c5e1aca | 2014-01-30 04:03:04 | [diff] [blame] | 509 | } |
| 510 | |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 511 | std::unique_ptr<QuicReceivedPacket> ConstructClientAckPacket( |
rtenneti | a004d33 | 2015-08-28 06:44:57 | [diff] [blame] | 512 | QuicPacketNumber packet_number, |
| 513 | QuicPacketNumber largest_received, |
| 514 | QuicPacketNumber least_unacked) { |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 515 | return client_maker_.MakeAckPacket(packet_number, largest_received, |
| 516 | least_unacked, |
| 517 | !kIncludeCongestionFeedback); |
| 518 | } |
| 519 | |
| 520 | std::unique_ptr<QuicReceivedPacket> ConstructServerAckPacket( |
| 521 | QuicPacketNumber packet_number, |
| 522 | QuicPacketNumber largest_received, |
| 523 | QuicPacketNumber least_unacked) { |
| 524 | return server_maker_.MakeAckPacket(packet_number, largest_received, |
| 525 | least_unacked, |
| 526 | !kIncludeCongestionFeedback); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 527 | } |
| 528 | |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 529 | void ReceivePromise(QuicStreamId id) { |
| 530 | QuicChromiumClientStream* stream = |
| 531 | QuicHttpStreamPeer::GetQuicChromiumClientStream(stream_.get()); |
| 532 | stream->OnStreamHeaders(serialized_push_promise_); |
| 533 | |
| 534 | stream->OnPromiseHeadersComplete(id, serialized_push_promise_.size()); |
| 535 | } |
| 536 | |
xunjieli | 84adaab | 2016-09-20 01:12:28 | [diff] [blame^] | 537 | void ExpectLoadTimingValid(const LoadTimingInfo& load_timing_info, |
xunjieli | 100937eb5 | 2016-09-15 20:09:37 | [diff] [blame] | 538 | bool session_reused) { |
| 539 | EXPECT_EQ(session_reused, load_timing_info.socket_reused); |
xunjieli | 84adaab | 2016-09-20 01:12:28 | [diff] [blame^] | 540 | if (session_reused) { |
| 541 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 542 | } else { |
| 543 | ExpectConnectTimingHasTimes( |
| 544 | load_timing_info.connect_timing, |
| 545 | CONNECT_TIMING_HAS_SSL_TIMES | CONNECT_TIMING_HAS_DNS_TIMES); |
| 546 | } |
| 547 | ExpectLoadTimingHasOnlyConnectionTimes(load_timing_info); |
xunjieli | 100937eb5 | 2016-09-15 20:09:37 | [diff] [blame] | 548 | } |
| 549 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 550 | BoundTestNetLog net_log_; |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 551 | bool use_closing_stream_; |
[email protected] | fee17f7 | 2013-02-03 07:47:41 | [diff] [blame] | 552 | MockSendAlgorithm* send_algorithm_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 553 | scoped_refptr<TestTaskRunner> runner_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 554 | std::unique_ptr<MockWrite[]> mock_writes_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 555 | MockClock clock_; |
| 556 | TestQuicConnection* connection_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 557 | std::unique_ptr<QuicChromiumConnectionHelper> helper_; |
rch | 16c74d1d | 2016-04-22 06:14:07 | [diff] [blame] | 558 | std::unique_ptr<QuicChromiumAlarmFactory> alarm_factory_; |
ckrasic | a7fd124 | 2016-05-14 20:36:01 | [diff] [blame] | 559 | testing::StrictMock<MockQuicConnectionVisitor> visitor_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 560 | std::unique_ptr<QuicHttpStream> stream_; |
[email protected] | 5db45220 | 2014-08-19 05:22:15 | [diff] [blame] | 561 | TransportSecurityState transport_security_state_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 562 | std::unique_ptr<QuicChromiumClientSession> session_; |
[email protected] | ef95114d | 2013-04-17 17:57:01 | [diff] [blame] | 563 | QuicCryptoClientConfig crypto_config_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 564 | TestCompletionCallback callback_; |
| 565 | HttpRequestInfo request_; |
| 566 | HttpRequestHeaders headers_; |
| 567 | HttpResponseInfo response_; |
| 568 | scoped_refptr<IOBufferWithSize> read_buffer_; |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 569 | SpdyHeaderBlock request_headers_; |
| 570 | SpdyHeaderBlock response_headers_; |
bnc | 614a92d3 | 2016-04-04 13:56:07 | [diff] [blame] | 571 | string request_data_; |
| 572 | string response_data_; |
ckrasic | 244375a3 | 2016-02-04 21:21:22 | [diff] [blame] | 573 | QuicClientPushPromiseIndex push_promise_index_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 574 | |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 575 | // For server push testing |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 576 | std::unique_ptr<QuicHttpStream> promised_stream_; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 577 | SpdyHeaderBlock push_promise_; |
| 578 | SpdyHeaderBlock promised_response_; |
| 579 | const QuicStreamId promise_id_; |
| 580 | string promise_url_; |
| 581 | string serialized_push_promise_; |
| 582 | const QuicStreamId stream_id_; |
| 583 | |
[email protected] | 3aa9ca7 | 2014-02-27 19:39:43 | [diff] [blame] | 584 | const QuicConnectionId connection_id_; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 585 | QuicTestPacketMaker client_maker_; |
| 586 | QuicTestPacketMaker server_maker_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 587 | IPEndPoint self_addr_; |
| 588 | IPEndPoint peer_addr_; |
[email protected] | 457d695 | 2013-12-13 09:24:58 | [diff] [blame] | 589 | MockRandom random_generator_; |
rch | 03b7a20 | 2016-02-05 00:54:20 | [diff] [blame] | 590 | ProofVerifyDetailsChromium verify_details_; |
[email protected] | e8ff2684 | 2013-03-22 21:02:05 | [diff] [blame] | 591 | MockCryptoClientStreamFactory crypto_client_stream_factory_; |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 592 | std::unique_ptr<StaticSocketDataProvider> socket_data_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 593 | std::vector<PacketToWrite> writes_; |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 594 | QuicStreamOffset response_offset_; |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 595 | }; |
| 596 | |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 597 | INSTANTIATE_TEST_CASE_P(Version, |
| 598 | QuicHttpStreamTest, |
danzh | 3134c256 | 2016-08-12 14:07:52 | [diff] [blame] | 599 | ::testing::ValuesIn(AllSupportedVersions())); |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 600 | |
| 601 | TEST_P(QuicHttpStreamTest, RenewStreamForAuth) { |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 602 | Initialize(); |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 603 | EXPECT_EQ(nullptr, stream_->RenewStreamForAuth()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 604 | } |
| 605 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 606 | TEST_P(QuicHttpStreamTest, CanReuseConnection) { |
[email protected] | ed3fc15d | 2013-03-08 18:37:44 | [diff] [blame] | 607 | Initialize(); |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 608 | EXPECT_FALSE(stream_->CanReuseConnection()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 609 | } |
| 610 | |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 611 | TEST_P(QuicHttpStreamTest, DisableConnectionMigrationForStream) { |
| 612 | request_.load_flags |= LOAD_DISABLE_CONNECTION_MIGRATION; |
| 613 | Initialize(); |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 614 | EXPECT_EQ(OK, |
| 615 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 616 | net_log_.bound(), callback_.callback())); |
jri | 231c297 | 2016-03-08 19:50:11 | [diff] [blame] | 617 | QuicChromiumClientStream* client_stream = |
| 618 | QuicHttpStreamPeer::GetQuicChromiumClientStream(stream_.get()); |
| 619 | EXPECT_FALSE(client_stream->can_migrate()); |
| 620 | } |
| 621 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 622 | TEST_P(QuicHttpStreamTest, GetRequest) { |
| 623 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 624 | size_t spdy_request_header_frame_length; |
| 625 | AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY, |
| 626 | &spdy_request_header_frame_length)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 627 | Initialize(); |
| 628 | |
| 629 | request_.method = "GET"; |
rch | 9ae5b3b | 2016-02-11 00:36:29 | [diff] [blame] | 630 | request_.url = GURL("http://www.example.org/"); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 631 | |
xunjieli | 100937eb5 | 2016-09-15 20:09:37 | [diff] [blame] | 632 | // Make sure getting load timing from the stream early does not crash. |
| 633 | LoadTimingInfo load_timing_info; |
| 634 | EXPECT_TRUE(stream_->GetLoadTimingInfo(&load_timing_info)); |
| 635 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 636 | EXPECT_EQ(OK, |
| 637 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 638 | net_log_.bound(), callback_.callback())); |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 639 | EXPECT_EQ(OK, |
| 640 | stream_->SendRequest(headers_, &response_, callback_.callback())); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 641 | |
| 642 | // Ack the request. |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 643 | ProcessPacket(ConstructServerAckPacket(1, 0, 0)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 644 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 645 | EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), |
| 646 | IsError(ERR_IO_PENDING)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 647 | |
bnc | 614a92d3 | 2016-04-04 13:56:07 | [diff] [blame] | 648 | SetResponse("404 Not Found", string()); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 649 | size_t spdy_response_header_frame_length; |
| 650 | ProcessPacket(ConstructResponseHeadersPacket( |
| 651 | 2, kFin, &spdy_response_header_frame_length)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 652 | |
| 653 | // Now that the headers have been processed, the callback will return. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 654 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 655 | ASSERT_TRUE(response_.headers.get()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 656 | EXPECT_EQ(404, response_.headers->response_code()); |
| 657 | EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
[email protected] | 6ed6743 | 2014-06-24 01:53:53 | [diff] [blame] | 658 | EXPECT_FALSE(response_.response_time.is_null()); |
| 659 | EXPECT_FALSE(response_.request_time.is_null()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 660 | |
| 661 | // There is no body, so this should return immediately. |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 662 | EXPECT_EQ(0, |
| 663 | stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 664 | callback_.callback())); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 665 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 666 | EXPECT_TRUE(AtEof()); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 667 | |
xunjieli | 100937eb5 | 2016-09-15 20:09:37 | [diff] [blame] | 668 | EXPECT_TRUE(stream_->GetLoadTimingInfo(&load_timing_info)); |
xunjieli | 84adaab | 2016-09-20 01:12:28 | [diff] [blame^] | 669 | ExpectLoadTimingValid(load_timing_info, /*session_reused=*/false); |
xunjieli | 100937eb5 | 2016-09-15 20:09:37 | [diff] [blame] | 670 | |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 671 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 672 | // headers and payload. |
| 673 | EXPECT_EQ(static_cast<int64_t>(spdy_request_header_frame_length), |
| 674 | stream_->GetTotalSentBytes()); |
| 675 | EXPECT_EQ(static_cast<int64_t>(spdy_response_header_frame_length), |
| 676 | stream_->GetTotalReceivedBytes()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 677 | } |
| 678 | |
xunjieli | 100937eb5 | 2016-09-15 20:09:37 | [diff] [blame] | 679 | TEST_P(QuicHttpStreamTest, LoadTimingTwoRequests) { |
| 680 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
| 681 | size_t spdy_request_header_frame_length; |
| 682 | |
| 683 | QuicStreamOffset offset = 0; |
| 684 | AddWrite(InnerConstructRequestHeadersPacket( |
| 685 | 1, kClientDataStreamId1, kIncludeVersion, kFin, DEFAULT_PRIORITY, |
| 686 | &spdy_request_header_frame_length, &offset)); |
| 687 | |
| 688 | // SetRequest() again for second request as |request_headers_| was moved. |
| 689 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
| 690 | AddWrite(InnerConstructRequestHeadersPacket( |
| 691 | 2, kClientDataStreamId2, kIncludeVersion, kFin, DEFAULT_PRIORITY, |
| 692 | &spdy_request_header_frame_length, &offset)); |
| 693 | AddWrite(ConstructClientAckPacket(3, 3, 1)); // Ack the responses. |
| 694 | |
| 695 | Initialize(); |
| 696 | |
| 697 | request_.method = "GET"; |
| 698 | request_.url = GURL("http://www.example.org/"); |
| 699 | // Start first request. |
| 700 | EXPECT_EQ(OK, |
| 701 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 702 | net_log_.bound(), callback_.callback())); |
| 703 | EXPECT_EQ(OK, |
| 704 | stream_->SendRequest(headers_, &response_, callback_.callback())); |
| 705 | |
| 706 | // Start a second request. |
| 707 | QuicHttpStream stream2(session_->GetWeakPtr()); |
| 708 | TestCompletionCallback callback2; |
| 709 | EXPECT_EQ(OK, |
| 710 | stream2.InitializeStream(&request_, DEFAULT_PRIORITY, |
| 711 | net_log_.bound(), callback2.callback())); |
| 712 | EXPECT_EQ(OK, |
| 713 | stream2.SendRequest(headers_, &response_, callback2.callback())); |
| 714 | |
| 715 | // Ack both requests. |
| 716 | ProcessPacket(ConstructServerAckPacket(1, 0, 0)); |
| 717 | |
| 718 | EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), |
| 719 | IsError(ERR_IO_PENDING)); |
| 720 | size_t spdy_response_header_frame_length; |
| 721 | SetResponse("200 OK", string()); |
| 722 | ProcessPacket(InnerConstructResponseHeadersPacket( |
| 723 | 2, kClientDataStreamId1, kFin, &spdy_response_header_frame_length)); |
| 724 | |
| 725 | // Now that the headers have been processed, the callback will return. |
| 726 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 727 | EXPECT_EQ(200, response_.headers->response_code()); |
| 728 | |
| 729 | // There is no body, so this should return immediately. |
| 730 | EXPECT_EQ(0, |
| 731 | stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 732 | callback_.callback())); |
| 733 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 734 | |
| 735 | LoadTimingInfo load_timing_info; |
| 736 | EXPECT_TRUE(stream_->GetLoadTimingInfo(&load_timing_info)); |
xunjieli | 84adaab | 2016-09-20 01:12:28 | [diff] [blame^] | 737 | ExpectLoadTimingValid(load_timing_info, /*session_reused=*/false); |
xunjieli | 100937eb5 | 2016-09-15 20:09:37 | [diff] [blame] | 738 | |
| 739 | // SetResponse() again for second request as |response_headers_| was moved. |
| 740 | SetResponse("200 OK", string()); |
| 741 | EXPECT_THAT(stream2.ReadResponseHeaders(callback2.callback()), |
| 742 | IsError(ERR_IO_PENDING)); |
| 743 | |
| 744 | ProcessPacket(InnerConstructResponseHeadersPacket( |
| 745 | 3, kClientDataStreamId2, kFin, &spdy_response_header_frame_length)); |
| 746 | |
| 747 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 748 | |
| 749 | // There is no body, so this should return immediately. |
| 750 | EXPECT_EQ(0, |
| 751 | stream2.ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 752 | callback2.callback())); |
| 753 | EXPECT_TRUE(stream2.IsResponseBodyComplete()); |
| 754 | |
| 755 | LoadTimingInfo load_timing_info2; |
| 756 | EXPECT_TRUE(stream2.GetLoadTimingInfo(&load_timing_info2)); |
xunjieli | 84adaab | 2016-09-20 01:12:28 | [diff] [blame^] | 757 | ExpectLoadTimingValid(load_timing_info2, /*session_reused=*/true); |
xunjieli | 100937eb5 | 2016-09-15 20:09:37 | [diff] [blame] | 758 | } |
| 759 | |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 760 | // QuicHttpStream does not currently support trailers. It should ignore |
| 761 | // trailers upon receiving them. |
| 762 | TEST_P(QuicHttpStreamTest, GetRequestWithTrailers) { |
| 763 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
| 764 | size_t spdy_request_header_frame_length; |
| 765 | AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY, |
| 766 | &spdy_request_header_frame_length)); |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 767 | AddWrite(ConstructClientAckPacket(2, 3, 1)); // Ack the data packet. |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 768 | |
| 769 | Initialize(); |
| 770 | |
| 771 | request_.method = "GET"; |
| 772 | request_.url = GURL("http://www.example.org/"); |
| 773 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 774 | EXPECT_EQ(OK, |
| 775 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 776 | net_log_.bound(), callback_.callback())); |
| 777 | |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 778 | EXPECT_EQ(OK, |
| 779 | stream_->SendRequest(headers_, &response_, callback_.callback())); |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 780 | // Ack the request. |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 781 | ProcessPacket(ConstructServerAckPacket(1, 0, 0)); |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 782 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 783 | EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), |
| 784 | IsError(ERR_IO_PENDING)); |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 785 | |
bnc | 614a92d3 | 2016-04-04 13:56:07 | [diff] [blame] | 786 | SetResponse("200 OK", string()); |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 787 | |
| 788 | // Send the response headers. |
| 789 | size_t spdy_response_header_frame_length; |
| 790 | QuicStreamOffset offset = 0; |
| 791 | ProcessPacket(ConstructResponseHeadersPacketWithOffset( |
| 792 | 2, !kFin, &spdy_response_header_frame_length, &offset)); |
| 793 | // Now that the headers have been processed, the callback will return. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 794 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 795 | ASSERT_TRUE(response_.headers.get()); |
| 796 | EXPECT_EQ(200, response_.headers->response_code()); |
| 797 | EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 798 | EXPECT_FALSE(response_.response_time.is_null()); |
| 799 | EXPECT_FALSE(response_.request_time.is_null()); |
| 800 | |
| 801 | // Send the response body. |
| 802 | const char kResponseBody[] = "Hello world!"; |
| 803 | ProcessPacket( |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 804 | ConstructServerDataPacket(3, false, !kFin, /*offset=*/0, kResponseBody)); |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 805 | SpdyHeaderBlock trailers; |
| 806 | size_t spdy_trailers_frame_length; |
| 807 | trailers["foo"] = "bar"; |
xunjieli | 188bd40 | 2016-03-12 00:17:25 | [diff] [blame] | 808 | trailers[kFinalOffsetHeaderKey] = base::IntToString(strlen(kResponseBody)); |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 809 | ProcessPacket(ConstructResponseTrailersPacket( |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 810 | 4, kFin, std::move(trailers), &spdy_trailers_frame_length, &offset)); |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 811 | |
| 812 | // Make sure trailers are processed. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 813 | base::RunLoop().RunUntilIdle(); |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 814 | |
| 815 | EXPECT_EQ(static_cast<int>(strlen(kResponseBody)), |
| 816 | stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 817 | callback_.callback())); |
| 818 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 819 | |
| 820 | EXPECT_EQ(OK, |
| 821 | stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 822 | callback_.callback())); |
| 823 | |
| 824 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 825 | EXPECT_TRUE(AtEof()); |
| 826 | |
| 827 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
| 828 | // headers and payload. |
| 829 | EXPECT_EQ(static_cast<int64_t>(spdy_request_header_frame_length), |
| 830 | stream_->GetTotalSentBytes()); |
| 831 | EXPECT_EQ( |
| 832 | static_cast<int64_t>(spdy_response_header_frame_length + |
| 833 | strlen(kResponseBody) + +spdy_trailers_frame_length), |
| 834 | stream_->GetTotalReceivedBytes()); |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 835 | // Check that NetLog was filled as expected. |
| 836 | TestNetLogEntry::List entries; |
| 837 | net_log_.GetEntries(&entries); |
| 838 | size_t pos = ExpectLogContainsSomewhere( |
| 839 | entries, /*min_offset=*/0, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 840 | NetLogEventType::QUIC_CHROMIUM_CLIENT_STREAM_SEND_REQUEST_HEADERS, |
| 841 | NetLogEventPhase::NONE); |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 842 | pos = ExpectLogContainsSomewhere( |
| 843 | entries, /*min_offset=*/pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 844 | NetLogEventType::QUIC_CHROMIUM_CLIENT_STREAM_SEND_REQUEST_HEADERS, |
| 845 | NetLogEventPhase::NONE); |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 846 | ExpectLogContainsSomewhere( |
| 847 | entries, /*min_offset=*/pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 848 | NetLogEventType::QUIC_CHROMIUM_CLIENT_STREAM_SEND_REQUEST_HEADERS, |
| 849 | NetLogEventPhase::NONE); |
xunjieli | 34291fe1 | 2016-03-02 13:58:38 | [diff] [blame] | 850 | } |
| 851 | |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 852 | // Regression test for http://crbug.com/288128 |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 853 | TEST_P(QuicHttpStreamTest, GetRequestLargeResponse) { |
| 854 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 855 | size_t spdy_request_headers_frame_length; |
| 856 | AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY, |
| 857 | &spdy_request_headers_frame_length)); |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 858 | Initialize(); |
| 859 | |
| 860 | request_.method = "GET"; |
rch | 9ae5b3b | 2016-02-11 00:36:29 | [diff] [blame] | 861 | request_.url = GURL("http://www.example.org/"); |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 862 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 863 | EXPECT_EQ(OK, |
| 864 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 865 | net_log_.bound(), callback_.callback())); |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 866 | EXPECT_EQ(OK, |
| 867 | stream_->SendRequest(headers_, &response_, callback_.callback())); |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 868 | |
| 869 | // Ack the request. |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 870 | ProcessPacket(ConstructServerAckPacket(1, 0, 0)); |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 871 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 872 | EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), |
| 873 | IsError(ERR_IO_PENDING)); |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 874 | |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 875 | response_headers_[":status"] = "200 OK"; |
| 876 | response_headers_[":version"] = "HTTP/1.1"; |
| 877 | response_headers_["content-type"] = "text/plain"; |
| 878 | response_headers_["big6"] = string(1000, 'x'); // Lots of x's. |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 879 | |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 880 | size_t spdy_response_headers_frame_length; |
| 881 | ProcessPacket(ConstructResponseHeadersPacket( |
| 882 | 2, kFin, &spdy_response_headers_frame_length)); |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 883 | |
| 884 | // Now that the headers have been processed, the callback will return. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 885 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 886 | ASSERT_TRUE(response_.headers.get()); |
| 887 | EXPECT_EQ(200, response_.headers->response_code()); |
| 888 | EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 889 | |
| 890 | // There is no body, so this should return immediately. |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 891 | EXPECT_EQ(0, |
| 892 | stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 893 | callback_.callback())); |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 894 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 895 | EXPECT_TRUE(AtEof()); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 896 | |
| 897 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 898 | // headers and payload. |
| 899 | EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
| 900 | stream_->GetTotalSentBytes()); |
| 901 | EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length), |
| 902 | stream_->GetTotalReceivedBytes()); |
[email protected] | 3e7dca6 | 2013-09-10 16:14:23 | [diff] [blame] | 903 | } |
| 904 | |
rch | f9f103cbc | 2014-08-30 05:28:04 | [diff] [blame] | 905 | // Regression test for http://crbug.com/409101 |
| 906 | TEST_P(QuicHttpStreamTest, SessionClosedBeforeSendRequest) { |
| 907 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
| 908 | Initialize(); |
| 909 | |
| 910 | request_.method = "GET"; |
rch | 9ae5b3b | 2016-02-11 00:36:29 | [diff] [blame] | 911 | request_.url = GURL("http://www.example.org/"); |
rch | f9f103cbc | 2014-08-30 05:28:04 | [diff] [blame] | 912 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 913 | EXPECT_EQ(OK, |
| 914 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 915 | net_log_.bound(), callback_.callback())); |
rch | f9f103cbc | 2014-08-30 05:28:04 | [diff] [blame] | 916 | |
jri | 78ec06a | 2016-03-31 18:19:40 | [diff] [blame] | 917 | session_->connection()->CloseConnection( |
| 918 | QUIC_NO_ERROR, "test", ConnectionCloseBehavior::SILENT_CLOSE); |
rch | f9f103cbc | 2014-08-30 05:28:04 | [diff] [blame] | 919 | |
| 920 | EXPECT_EQ(ERR_CONNECTION_CLOSED, |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 921 | stream_->SendRequest(headers_, &response_, callback_.callback())); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 922 | |
| 923 | EXPECT_EQ(0, stream_->GetTotalSentBytes()); |
| 924 | EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
rch | f9f103cbc | 2014-08-30 05:28:04 | [diff] [blame] | 925 | } |
| 926 | |
rch | 03b7a20 | 2016-02-05 00:54:20 | [diff] [blame] | 927 | // Regression test for http://crbug.com/584441 |
| 928 | TEST_P(QuicHttpStreamTest, GetSSLInfoAfterSessionClosed) { |
| 929 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
| 930 | Initialize(); |
| 931 | |
| 932 | request_.method = "GET"; |
rch | 9ae5b3b | 2016-02-11 00:36:29 | [diff] [blame] | 933 | request_.url = GURL("http://www.example.org/"); |
rch | 03b7a20 | 2016-02-05 00:54:20 | [diff] [blame] | 934 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 935 | EXPECT_EQ(OK, |
| 936 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 937 | net_log_.bound(), callback_.callback())); |
rch | 03b7a20 | 2016-02-05 00:54:20 | [diff] [blame] | 938 | |
| 939 | SSLInfo ssl_info; |
rch | 11565e0 | 2016-02-09 20:13:47 | [diff] [blame] | 940 | EXPECT_FALSE(ssl_info.is_valid()); |
rch | 03b7a20 | 2016-02-05 00:54:20 | [diff] [blame] | 941 | stream_->GetSSLInfo(&ssl_info); |
rch | 11565e0 | 2016-02-09 20:13:47 | [diff] [blame] | 942 | EXPECT_TRUE(ssl_info.is_valid()); |
rch | 03b7a20 | 2016-02-05 00:54:20 | [diff] [blame] | 943 | |
jri | 78ec06a | 2016-03-31 18:19:40 | [diff] [blame] | 944 | session_->connection()->CloseConnection( |
| 945 | QUIC_NO_ERROR, "test", ConnectionCloseBehavior::SILENT_CLOSE); |
rch | 03b7a20 | 2016-02-05 00:54:20 | [diff] [blame] | 946 | |
rch | 11565e0 | 2016-02-09 20:13:47 | [diff] [blame] | 947 | SSLInfo ssl_info2; |
| 948 | stream_->GetSSLInfo(&ssl_info2); |
| 949 | EXPECT_TRUE(ssl_info2.is_valid()); |
rch | 03b7a20 | 2016-02-05 00:54:20 | [diff] [blame] | 950 | } |
| 951 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 952 | TEST_P(QuicHttpStreamTest, LogGranularQuicConnectionError) { |
| 953 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
| 954 | size_t spdy_request_headers_frame_length; |
| 955 | AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY, |
| 956 | &spdy_request_headers_frame_length)); |
| 957 | AddWrite(ConstructAckAndRstStreamPacket(2)); |
| 958 | use_closing_stream_ = true; |
| 959 | Initialize(); |
| 960 | |
| 961 | request_.method = "GET"; |
rch | 9ae5b3b | 2016-02-11 00:36:29 | [diff] [blame] | 962 | request_.url = GURL("http://www.example.org/"); |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 963 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 964 | EXPECT_EQ(OK, |
| 965 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 966 | net_log_.bound(), callback_.callback())); |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 967 | EXPECT_EQ(OK, |
| 968 | stream_->SendRequest(headers_, &response_, callback_.callback())); |
| 969 | |
| 970 | // Ack the request. |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 971 | ProcessPacket(ConstructServerAckPacket(1, 0, 0)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 972 | EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), |
| 973 | IsError(ERR_IO_PENDING)); |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 974 | |
| 975 | EXPECT_TRUE(QuicHttpStreamPeer::WasHandshakeConfirmed(stream_.get())); |
rch | 1c5b74a | 2016-06-23 22:10:55 | [diff] [blame] | 976 | |
| 977 | QuicConnectionCloseFrame frame; |
| 978 | frame.error_code = QUIC_PEER_GOING_AWAY; |
| 979 | session_->connection()->OnConnectionCloseFrame(frame); |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 980 | |
| 981 | NetErrorDetails details; |
| 982 | EXPECT_EQ(QUIC_NO_ERROR, details.quic_connection_error); |
| 983 | stream_->PopulateNetErrorDetails(&details); |
| 984 | EXPECT_EQ(QUIC_PEER_GOING_AWAY, details.quic_connection_error); |
| 985 | } |
| 986 | |
| 987 | TEST_P(QuicHttpStreamTest, DoNotLogGranularQuicErrorIfHandshakeNotConfirmed) { |
| 988 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
| 989 | size_t spdy_request_headers_frame_length; |
| 990 | AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY, |
| 991 | &spdy_request_headers_frame_length)); |
| 992 | AddWrite(ConstructAckAndRstStreamPacket(2)); |
| 993 | use_closing_stream_ = true; |
| 994 | Initialize(); |
| 995 | |
| 996 | request_.method = "GET"; |
rch | 9ae5b3b | 2016-02-11 00:36:29 | [diff] [blame] | 997 | request_.url = GURL("http://www.example.org/"); |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 998 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 999 | EXPECT_EQ(OK, |
| 1000 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1001 | net_log_.bound(), callback_.callback())); |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 1002 | EXPECT_EQ(OK, |
| 1003 | stream_->SendRequest(headers_, &response_, callback_.callback())); |
| 1004 | |
| 1005 | // Ack the request. |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1006 | ProcessPacket(ConstructServerAckPacket(1, 0, 0)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1007 | EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), |
| 1008 | IsError(ERR_IO_PENDING)); |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 1009 | |
| 1010 | // The test setup defaults handshake to be confirmed. Manually set |
| 1011 | // it to be not confirmed. |
| 1012 | // Granular errors shouldn't be reported if handshake not confirmed. |
| 1013 | QuicHttpStreamPeer::SetHandshakeConfirmed(stream_.get(), false); |
| 1014 | |
| 1015 | EXPECT_FALSE(QuicHttpStreamPeer::WasHandshakeConfirmed(stream_.get())); |
rch | 1c5b74a | 2016-06-23 22:10:55 | [diff] [blame] | 1016 | QuicConnectionCloseFrame frame; |
| 1017 | frame.error_code = QUIC_PEER_GOING_AWAY; |
| 1018 | session_->connection()->OnConnectionCloseFrame(frame); |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 1019 | |
| 1020 | NetErrorDetails details; |
| 1021 | EXPECT_EQ(QUIC_NO_ERROR, details.quic_connection_error); |
| 1022 | stream_->PopulateNetErrorDetails(&details); |
| 1023 | EXPECT_EQ(QUIC_NO_ERROR, details.quic_connection_error); |
| 1024 | } |
| 1025 | |
rch | 11a114a | 2014-09-04 23:41:59 | [diff] [blame] | 1026 | // Regression test for http://crbug.com/409871 |
| 1027 | TEST_P(QuicHttpStreamTest, SessionClosedBeforeReadResponseHeaders) { |
| 1028 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1029 | size_t spdy_request_headers_frame_length; |
| 1030 | AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY, |
| 1031 | &spdy_request_headers_frame_length)); |
rch | 11a114a | 2014-09-04 23:41:59 | [diff] [blame] | 1032 | Initialize(); |
| 1033 | |
| 1034 | request_.method = "GET"; |
rch | 9ae5b3b | 2016-02-11 00:36:29 | [diff] [blame] | 1035 | request_.url = GURL("http://www.example.org/"); |
rch | 11a114a | 2014-09-04 23:41:59 | [diff] [blame] | 1036 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1037 | EXPECT_EQ(OK, |
| 1038 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1039 | net_log_.bound(), callback_.callback())); |
rch | 11a114a | 2014-09-04 23:41:59 | [diff] [blame] | 1040 | |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1041 | EXPECT_EQ(OK, |
| 1042 | stream_->SendRequest(headers_, &response_, callback_.callback())); |
rch | 11a114a | 2014-09-04 23:41:59 | [diff] [blame] | 1043 | |
jri | 78ec06a | 2016-03-31 18:19:40 | [diff] [blame] | 1044 | session_->connection()->CloseConnection( |
| 1045 | QUIC_NO_ERROR, "test", ConnectionCloseBehavior::SILENT_CLOSE); |
rch | 11a114a | 2014-09-04 23:41:59 | [diff] [blame] | 1046 | |
| 1047 | EXPECT_NE(OK, stream_->ReadResponseHeaders(callback_.callback())); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1048 | |
| 1049 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1050 | // headers and payload. |
| 1051 | EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
| 1052 | stream_->GetTotalSentBytes()); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1053 | EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
rch | 11a114a | 2014-09-04 23:41:59 | [diff] [blame] | 1054 | } |
| 1055 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1056 | TEST_P(QuicHttpStreamTest, SendPostRequest) { |
| 1057 | SetRequest("POST", "/", DEFAULT_PRIORITY); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1058 | size_t spdy_request_headers_frame_length; |
| 1059 | AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY, |
| 1060 | &spdy_request_headers_frame_length)); |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1061 | AddWrite(ConstructClientDataPacket(2, kIncludeVersion, kFin, 0, kUploadData)); |
| 1062 | AddWrite(ConstructClientAckPacket(3, 3, 1)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 1063 | |
| 1064 | Initialize(); |
| 1065 | |
danakj | ad1777e | 2016-04-16 00:56:42 | [diff] [blame] | 1066 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 1067 | element_readers.push_back(base::MakeUnique<UploadBytesElementReader>( |
| 1068 | kUploadData, strlen(kUploadData))); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1069 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 1070 | request_.method = "POST"; |
rch | 9ae5b3b | 2016-02-11 00:36:29 | [diff] [blame] | 1071 | request_.url = GURL("http://www.example.org/"); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 1072 | request_.upload_data_stream = &upload_data_stream; |
maksim.sisov | 819ba85 | 2016-08-17 08:22:52 | [diff] [blame] | 1073 | ASSERT_THAT( |
| 1074 | request_.upload_data_stream->Init(CompletionCallback(), BoundNetLog()), |
| 1075 | IsOk()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 1076 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1077 | EXPECT_EQ(OK, |
| 1078 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1079 | net_log_.bound(), callback_.callback())); |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1080 | EXPECT_EQ(OK, |
| 1081 | stream_->SendRequest(headers_, &response_, callback_.callback())); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 1082 | |
| 1083 | // Ack both packets in the request. |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1084 | ProcessPacket(ConstructServerAckPacket(1, 0, 0)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 1085 | |
| 1086 | // Send the response headers (but not the body). |
bnc | 614a92d3 | 2016-04-04 13:56:07 | [diff] [blame] | 1087 | SetResponse("200 OK", string()); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1088 | size_t spdy_response_headers_frame_length; |
| 1089 | ProcessPacket(ConstructResponseHeadersPacket( |
| 1090 | 2, !kFin, &spdy_response_headers_frame_length)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 1091 | |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 1092 | // The headers have arrived, but they are delivered asynchronously. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1093 | EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), |
| 1094 | IsError(ERR_IO_PENDING)); |
| 1095 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 1096 | ASSERT_TRUE(response_.headers.get()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 1097 | EXPECT_EQ(200, response_.headers->response_code()); |
| 1098 | EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 1099 | |
| 1100 | // Send the response body. |
| 1101 | const char kResponseBody[] = "Hello world!"; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1102 | ProcessPacket(ConstructServerDataPacket(3, false, kFin, 0, kResponseBody)); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 1103 | // Since the body has already arrived, this should return immediately. |
| 1104 | EXPECT_EQ(static_cast<int>(strlen(kResponseBody)), |
| 1105 | stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 1106 | callback_.callback())); |
| 1107 | |
| 1108 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 1109 | EXPECT_TRUE(AtEof()); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1110 | |
| 1111 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1112 | // headers and payload. |
| 1113 | EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length + |
| 1114 | strlen(kUploadData)), |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1115 | stream_->GetTotalSentBytes()); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1116 | EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length + |
| 1117 | strlen(kResponseBody)), |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1118 | stream_->GetTotalReceivedBytes()); |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 1119 | } |
| 1120 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1121 | TEST_P(QuicHttpStreamTest, SendChunkedPostRequest) { |
| 1122 | SetRequest("POST", "/", DEFAULT_PRIORITY); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 1123 | size_t chunk_size = strlen(kUploadData); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1124 | size_t spdy_request_headers_frame_length; |
| 1125 | AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY, |
| 1126 | &spdy_request_headers_frame_length)); |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1127 | AddWrite( |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1128 | ConstructClientDataPacket(2, kIncludeVersion, !kFin, 0, kUploadData)); |
| 1129 | AddWrite(ConstructClientDataPacket(3, kIncludeVersion, kFin, chunk_size, |
| 1130 | kUploadData)); |
| 1131 | AddWrite(ConstructClientAckPacket(4, 3, 1)); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 1132 | Initialize(); |
| 1133 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1134 | ChunkedUploadDataStream upload_data_stream(0); |
| 1135 | upload_data_stream.AppendData(kUploadData, chunk_size, false); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 1136 | |
| 1137 | request_.method = "POST"; |
rch | 9ae5b3b | 2016-02-11 00:36:29 | [diff] [blame] | 1138 | request_.url = GURL("http://www.example.org/"); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 1139 | request_.upload_data_stream = &upload_data_stream; |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1140 | ASSERT_EQ(OK, request_.upload_data_stream->Init( |
maksim.sisov | 819ba85 | 2016-08-17 08:22:52 | [diff] [blame] | 1141 | TestCompletionCallback().callback(), BoundNetLog())); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 1142 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1143 | ASSERT_EQ(OK, |
| 1144 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1145 | net_log_.bound(), callback_.callback())); |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1146 | ASSERT_EQ(ERR_IO_PENDING, |
| 1147 | stream_->SendRequest(headers_, &response_, callback_.callback())); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 1148 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1149 | upload_data_stream.AppendData(kUploadData, chunk_size, true); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1150 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 1151 | |
| 1152 | // Ack both packets in the request. |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1153 | ProcessPacket(ConstructServerAckPacket(1, 0, 0)); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 1154 | |
| 1155 | // Send the response headers (but not the body). |
bnc | 614a92d3 | 2016-04-04 13:56:07 | [diff] [blame] | 1156 | SetResponse("200 OK", string()); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1157 | size_t spdy_response_headers_frame_length; |
| 1158 | ProcessPacket(ConstructResponseHeadersPacket( |
| 1159 | 2, !kFin, &spdy_response_headers_frame_length)); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 1160 | |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 1161 | // The headers have arrived, but they are delivered asynchronously |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1162 | EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), |
| 1163 | IsError(ERR_IO_PENDING)); |
| 1164 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 1165 | ASSERT_TRUE(response_.headers.get()); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 1166 | EXPECT_EQ(200, response_.headers->response_code()); |
| 1167 | EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 1168 | |
| 1169 | // Send the response body. |
| 1170 | const char kResponseBody[] = "Hello world!"; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1171 | ProcessPacket(ConstructServerDataPacket( |
| 1172 | 3, false, kFin, response_data_.length(), kResponseBody)); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 1173 | |
| 1174 | // Since the body has already arrived, this should return immediately. |
| 1175 | ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), |
| 1176 | stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 1177 | callback_.callback())); |
| 1178 | |
| 1179 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 1180 | EXPECT_TRUE(AtEof()); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1181 | |
| 1182 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1183 | // headers and payload. |
| 1184 | EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length + |
| 1185 | strlen(kUploadData) * 2), |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1186 | stream_->GetTotalSentBytes()); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1187 | EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length + |
| 1188 | strlen(kResponseBody)), |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1189 | stream_->GetTotalReceivedBytes()); |
[email protected] | c9e49a0 | 2013-02-26 05:56:47 | [diff] [blame] | 1190 | } |
| 1191 | |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1192 | TEST_P(QuicHttpStreamTest, SendChunkedPostRequestWithFinalEmptyDataPacket) { |
| 1193 | SetRequest("POST", "/", DEFAULT_PRIORITY); |
| 1194 | size_t chunk_size = strlen(kUploadData); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1195 | size_t spdy_request_headers_frame_length; |
| 1196 | AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY, |
| 1197 | &spdy_request_headers_frame_length)); |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1198 | AddWrite( |
| 1199 | ConstructClientDataPacket(2, kIncludeVersion, !kFin, 0, kUploadData)); |
| 1200 | AddWrite(ConstructClientDataPacket(3, kIncludeVersion, kFin, chunk_size, "")); |
| 1201 | AddWrite(ConstructClientAckPacket(4, 3, 1)); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1202 | Initialize(); |
| 1203 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1204 | ChunkedUploadDataStream upload_data_stream(0); |
| 1205 | upload_data_stream.AppendData(kUploadData, chunk_size, false); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1206 | |
| 1207 | request_.method = "POST"; |
rch | 9ae5b3b | 2016-02-11 00:36:29 | [diff] [blame] | 1208 | request_.url = GURL("http://www.example.org/"); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1209 | request_.upload_data_stream = &upload_data_stream; |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1210 | ASSERT_EQ(OK, request_.upload_data_stream->Init( |
maksim.sisov | 819ba85 | 2016-08-17 08:22:52 | [diff] [blame] | 1211 | TestCompletionCallback().callback(), BoundNetLog())); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1212 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1213 | ASSERT_EQ(OK, |
| 1214 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1215 | net_log_.bound(), callback_.callback())); |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1216 | ASSERT_EQ(ERR_IO_PENDING, |
| 1217 | stream_->SendRequest(headers_, &response_, callback_.callback())); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1218 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1219 | upload_data_stream.AppendData(nullptr, 0, true); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1220 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1221 | |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1222 | ProcessPacket(ConstructServerAckPacket(1, 0, 0)); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1223 | |
| 1224 | // Send the response headers (but not the body). |
bnc | 614a92d3 | 2016-04-04 13:56:07 | [diff] [blame] | 1225 | SetResponse("200 OK", string()); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1226 | size_t spdy_response_headers_frame_length; |
| 1227 | ProcessPacket(ConstructResponseHeadersPacket( |
| 1228 | 2, !kFin, &spdy_response_headers_frame_length)); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1229 | |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 1230 | // The headers have arrived, but they are delivered asynchronously |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1231 | EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), |
| 1232 | IsError(ERR_IO_PENDING)); |
| 1233 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1234 | ASSERT_TRUE(response_.headers.get()); |
| 1235 | EXPECT_EQ(200, response_.headers->response_code()); |
| 1236 | EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 1237 | |
| 1238 | // Send the response body. |
| 1239 | const char kResponseBody[] = "Hello world!"; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1240 | ProcessPacket(ConstructServerDataPacket( |
| 1241 | 3, false, kFin, response_data_.length(), kResponseBody)); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1242 | |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 1243 | // The body has arrived, but it is delivered asynchronously |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1244 | ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), |
| 1245 | stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 1246 | callback_.callback())); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1247 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 1248 | EXPECT_TRUE(AtEof()); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1249 | |
| 1250 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1251 | // headers and payload. |
| 1252 | EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length + |
| 1253 | strlen(kUploadData)), |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1254 | stream_->GetTotalSentBytes()); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1255 | EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length + |
| 1256 | strlen(kResponseBody)), |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1257 | stream_->GetTotalReceivedBytes()); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1258 | } |
| 1259 | |
| 1260 | TEST_P(QuicHttpStreamTest, SendChunkedPostRequestWithOneEmptyDataPacket) { |
| 1261 | SetRequest("POST", "/", DEFAULT_PRIORITY); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1262 | size_t spdy_request_headers_frame_length; |
| 1263 | AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY, |
| 1264 | &spdy_request_headers_frame_length)); |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1265 | AddWrite(ConstructClientDataPacket(2, kIncludeVersion, kFin, 0, "")); |
| 1266 | AddWrite(ConstructClientAckPacket(3, 3, 1)); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1267 | Initialize(); |
| 1268 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1269 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1270 | |
| 1271 | request_.method = "POST"; |
rch | 9ae5b3b | 2016-02-11 00:36:29 | [diff] [blame] | 1272 | request_.url = GURL("http://www.example.org/"); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1273 | request_.upload_data_stream = &upload_data_stream; |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1274 | ASSERT_EQ(OK, request_.upload_data_stream->Init( |
maksim.sisov | 819ba85 | 2016-08-17 08:22:52 | [diff] [blame] | 1275 | TestCompletionCallback().callback(), BoundNetLog())); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1276 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1277 | ASSERT_EQ(OK, |
| 1278 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1279 | net_log_.bound(), callback_.callback())); |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1280 | ASSERT_EQ(ERR_IO_PENDING, |
| 1281 | stream_->SendRequest(headers_, &response_, callback_.callback())); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1282 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1283 | upload_data_stream.AppendData(nullptr, 0, true); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1284 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1285 | |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1286 | ProcessPacket(ConstructServerAckPacket(1, 0, 0)); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1287 | |
| 1288 | // Send the response headers (but not the body). |
bnc | 614a92d3 | 2016-04-04 13:56:07 | [diff] [blame] | 1289 | SetResponse("200 OK", string()); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1290 | size_t spdy_response_headers_frame_length; |
| 1291 | ProcessPacket(ConstructResponseHeadersPacket( |
| 1292 | 2, !kFin, &spdy_response_headers_frame_length)); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1293 | |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 1294 | // The headers have arrived, but they are delivered asynchronously |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1295 | EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), |
| 1296 | IsError(ERR_IO_PENDING)); |
| 1297 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1298 | ASSERT_TRUE(response_.headers.get()); |
| 1299 | EXPECT_EQ(200, response_.headers->response_code()); |
| 1300 | EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 1301 | |
| 1302 | // Send the response body. |
| 1303 | const char kResponseBody[] = "Hello world!"; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1304 | ProcessPacket(ConstructServerDataPacket( |
| 1305 | 3, false, kFin, response_data_.length(), kResponseBody)); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1306 | |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 1307 | // The body has arrived, but it is delivered asynchronously |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1308 | ASSERT_EQ(static_cast<int>(strlen(kResponseBody)), |
| 1309 | stream_->ReadResponseBody(read_buffer_.get(), read_buffer_->size(), |
| 1310 | callback_.callback())); |
| 1311 | |
| 1312 | EXPECT_TRUE(stream_->IsResponseBodyComplete()); |
| 1313 | EXPECT_TRUE(AtEof()); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1314 | |
| 1315 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1316 | // headers and payload. |
| 1317 | EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
| 1318 | stream_->GetTotalSentBytes()); |
| 1319 | EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length + |
| 1320 | strlen(kResponseBody)), |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1321 | stream_->GetTotalReceivedBytes()); |
[email protected] | 16ba774 | 2014-08-22 00:57:25 | [diff] [blame] | 1322 | } |
| 1323 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1324 | TEST_P(QuicHttpStreamTest, DestroyedEarly) { |
| 1325 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1326 | size_t spdy_request_headers_frame_length; |
| 1327 | AddWrite(ConstructRequestHeadersPacket(1, kFin, DEFAULT_PRIORITY, |
| 1328 | &spdy_request_headers_frame_length)); |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 1329 | AddWrite(ConstructAckAndRstStreamPacket(2)); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 1330 | use_closing_stream_ = true; |
| 1331 | Initialize(); |
| 1332 | |
| 1333 | request_.method = "GET"; |
rch | 9ae5b3b | 2016-02-11 00:36:29 | [diff] [blame] | 1334 | request_.url = GURL("http://www.example.org/"); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 1335 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1336 | EXPECT_EQ(OK, |
| 1337 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1338 | net_log_.bound(), callback_.callback())); |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1339 | EXPECT_EQ(OK, |
| 1340 | stream_->SendRequest(headers_, &response_, callback_.callback())); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 1341 | |
| 1342 | // Ack the request. |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1343 | ProcessPacket(ConstructServerAckPacket(1, 0, 0)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1344 | EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), |
| 1345 | IsError(ERR_IO_PENDING)); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 1346 | |
| 1347 | // Send the response with a body. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1348 | SetResponse("404 OK", "hello world!"); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 1349 | // In the course of processing this packet, the QuicHttpStream close itself. |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1350 | ProcessPacket(ConstructResponseHeadersPacket(2, kFin, nullptr)); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 1351 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1352 | base::RunLoop().RunUntilIdle(); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 1353 | |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 1354 | EXPECT_TRUE(AtEof()); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1355 | |
| 1356 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1357 | // headers and payload. |
| 1358 | EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
| 1359 | stream_->GetTotalSentBytes()); |
| 1360 | // Zero since the stream is closed before processing the headers. |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1361 | EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
[email protected] | 6353451 | 2012-12-23 18:49:00 | [diff] [blame] | 1362 | } |
| 1363 | |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1364 | TEST_P(QuicHttpStreamTest, Priority) { |
| 1365 | SetRequest("GET", "/", MEDIUM); |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1366 | size_t spdy_request_headers_frame_length; |
| 1367 | AddWrite(ConstructRequestHeadersPacket(1, kFin, MEDIUM, |
| 1368 | &spdy_request_headers_frame_length)); |
rtenneti | 4efd55dd | 2015-09-18 01:12:04 | [diff] [blame] | 1369 | AddWrite(ConstructAckAndRstStreamPacket(2)); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 1370 | use_closing_stream_ = true; |
| 1371 | Initialize(); |
| 1372 | |
| 1373 | request_.method = "GET"; |
rch | 9ae5b3b | 2016-02-11 00:36:29 | [diff] [blame] | 1374 | request_.url = GURL("http://www.example.org/"); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 1375 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1376 | EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_.bound(), |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1377 | callback_.callback())); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 1378 | |
| 1379 | // Check that priority is highest. |
rch | 12fef55 | 2016-01-15 16:26:31 | [diff] [blame] | 1380 | QuicChromiumClientStream* reliable_stream = |
| 1381 | QuicHttpStreamPeer::GetQuicChromiumClientStream(stream_.get()); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 1382 | DCHECK(reliable_stream); |
fayang | a64c1a9 | 2016-02-13 01:55:58 | [diff] [blame] | 1383 | DCHECK_EQ(kV3HighestPriority, reliable_stream->priority()); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 1384 | |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1385 | EXPECT_EQ(OK, |
| 1386 | stream_->SendRequest(headers_, &response_, callback_.callback())); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 1387 | |
| 1388 | // Check that priority has now dropped back to MEDIUM. |
ianswett | 0888cff | 2015-11-24 17:42:16 | [diff] [blame] | 1389 | DCHECK_EQ(MEDIUM, |
fayang | a64c1a9 | 2016-02-13 01:55:58 | [diff] [blame] | 1390 | ConvertQuicPriorityToRequestPriority(reliable_stream->priority())); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 1391 | |
| 1392 | // Ack the request. |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1393 | ProcessPacket(ConstructServerAckPacket(1, 0, 0)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1394 | EXPECT_THAT(stream_->ReadResponseHeaders(callback_.callback()), |
| 1395 | IsError(ERR_IO_PENDING)); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 1396 | |
| 1397 | // Send the response with a body. |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1398 | SetResponse("404 OK", "hello world!"); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 1399 | // In the course of processing this packet, the QuicHttpStream close itself. |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1400 | ProcessPacket(ConstructResponseHeadersPacket(2, kFin, nullptr)); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 1401 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1402 | base::RunLoop().RunUntilIdle(); |
rch | b27683c | 2015-07-29 23:53:50 | [diff] [blame] | 1403 | |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 1404 | EXPECT_TRUE(AtEof()); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1405 | |
| 1406 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
sclittle | c4dc1a3 | 2015-09-24 00:15:45 | [diff] [blame] | 1407 | // headers and payload. |
| 1408 | EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
| 1409 | stream_->GetTotalSentBytes()); |
| 1410 | // Zero since the stream is closed before processing the headers. |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1411 | EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
[email protected] | 24e5bc5 | 2013-09-18 15:36:58 | [diff] [blame] | 1412 | } |
| 1413 | |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 1414 | // Regression test for http://crbug.com/294870 |
[email protected] | 1e96003 | 2013-12-20 19:00:20 | [diff] [blame] | 1415 | TEST_P(QuicHttpStreamTest, CheckPriorityWithNoDelegate) { |
| 1416 | SetRequest("GET", "/", MEDIUM); |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 1417 | use_closing_stream_ = true; |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1418 | |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1419 | AddWrite(ConstructClientRstStreamPacket(1)); |
[email protected] | 459a740 | 2014-02-10 12:58:52 | [diff] [blame] | 1420 | |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 1421 | Initialize(); |
| 1422 | |
| 1423 | request_.method = "GET"; |
rch | 9ae5b3b | 2016-02-11 00:36:29 | [diff] [blame] | 1424 | request_.url = GURL("http://www.example.org/"); |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 1425 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1426 | EXPECT_EQ(OK, stream_->InitializeStream(&request_, MEDIUM, net_log_.bound(), |
rjshade | d5ced07 | 2015-12-18 19:26:02 | [diff] [blame] | 1427 | callback_.callback())); |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 1428 | |
| 1429 | // Check that priority is highest. |
rch | 12fef55 | 2016-01-15 16:26:31 | [diff] [blame] | 1430 | QuicChromiumClientStream* reliable_stream = |
| 1431 | QuicHttpStreamPeer::GetQuicChromiumClientStream(stream_.get()); |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 1432 | DCHECK(reliable_stream); |
rch | 12fef55 | 2016-01-15 16:26:31 | [diff] [blame] | 1433 | QuicChromiumClientStream::Delegate* delegate = reliable_stream->GetDelegate(); |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 1434 | DCHECK(delegate); |
fayang | a64c1a9 | 2016-02-13 01:55:58 | [diff] [blame] | 1435 | DCHECK_EQ(kV3HighestPriority, reliable_stream->priority()); |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 1436 | |
ianswett | 0888cff | 2015-11-24 17:42:16 | [diff] [blame] | 1437 | // Set Delegate to nullptr and make sure Priority returns highest |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 1438 | // priority. |
rtenneti | be63573 | 2014-10-02 22:51:42 | [diff] [blame] | 1439 | reliable_stream->SetDelegate(nullptr); |
fayang | a64c1a9 | 2016-02-13 01:55:58 | [diff] [blame] | 1440 | DCHECK_EQ(kV3HighestPriority, reliable_stream->priority()); |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 1441 | reliable_stream->SetDelegate(delegate); |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1442 | |
sclittle | 1edeeb2 | 2015-09-02 20:46:10 | [diff] [blame] | 1443 | EXPECT_EQ(0, stream_->GetTotalSentBytes()); |
| 1444 | EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
[email protected] | e1cca9a | 2013-09-20 17:14:44 | [diff] [blame] | 1445 | } |
| 1446 | |
xunjieli | 8dff50b | 2016-07-22 14:19:06 | [diff] [blame] | 1447 | TEST_P(QuicHttpStreamTest, SessionClosedDuringDoLoop) { |
| 1448 | SetRequest("POST", "/", DEFAULT_PRIORITY); |
| 1449 | size_t spdy_request_headers_frame_length; |
| 1450 | AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY, |
| 1451 | &spdy_request_headers_frame_length)); |
| 1452 | AddWrite( |
| 1453 | ConstructClientDataPacket(2, kIncludeVersion, !kFin, 0, kUploadData)); |
| 1454 | // Second data write will result in a synchronous failure which will close |
| 1455 | // the session. |
| 1456 | AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 1457 | Initialize(); |
| 1458 | |
| 1459 | ChunkedUploadDataStream upload_data_stream(0); |
| 1460 | |
| 1461 | request_.method = "POST"; |
| 1462 | request_.url = GURL("http://www.example.org/"); |
| 1463 | request_.upload_data_stream = &upload_data_stream; |
| 1464 | ASSERT_EQ(OK, request_.upload_data_stream->Init( |
maksim.sisov | 819ba85 | 2016-08-17 08:22:52 | [diff] [blame] | 1465 | TestCompletionCallback().callback(), BoundNetLog())); |
xunjieli | 8dff50b | 2016-07-22 14:19:06 | [diff] [blame] | 1466 | |
| 1467 | size_t chunk_size = strlen(kUploadData); |
| 1468 | upload_data_stream.AppendData(kUploadData, chunk_size, false); |
| 1469 | ASSERT_EQ(OK, |
| 1470 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1471 | net_log_.bound(), callback_.callback())); |
| 1472 | QuicHttpStream* stream = stream_.get(); |
| 1473 | DeleteStreamCallback delete_stream_callback(std::move(stream_)); |
| 1474 | // SendRequest() completes asynchronously after the final chunk is added. |
| 1475 | ASSERT_EQ(ERR_IO_PENDING, |
| 1476 | stream->SendRequest(headers_, &response_, callback_.callback())); |
| 1477 | upload_data_stream.AppendData(kUploadData, chunk_size, true); |
| 1478 | int rv = callback_.WaitForResult(); |
| 1479 | EXPECT_EQ(ERR_QUIC_PROTOCOL_ERROR, rv); |
| 1480 | } |
| 1481 | |
rtenneti | 15656ae | 2016-01-23 03:05:03 | [diff] [blame] | 1482 | TEST_P(QuicHttpStreamTest, SessionClosedBeforeSendHeadersComplete) { |
| 1483 | SetRequest("POST", "/", DEFAULT_PRIORITY); |
| 1484 | AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 1485 | Initialize(); |
| 1486 | |
| 1487 | ChunkedUploadDataStream upload_data_stream(0); |
| 1488 | |
| 1489 | request_.method = "POST"; |
rch | 9ae5b3b | 2016-02-11 00:36:29 | [diff] [blame] | 1490 | request_.url = GURL("http://www.example.org/"); |
rtenneti | 15656ae | 2016-01-23 03:05:03 | [diff] [blame] | 1491 | request_.upload_data_stream = &upload_data_stream; |
| 1492 | ASSERT_EQ(OK, request_.upload_data_stream->Init( |
maksim.sisov | 819ba85 | 2016-08-17 08:22:52 | [diff] [blame] | 1493 | TestCompletionCallback().callback(), BoundNetLog())); |
rtenneti | 15656ae | 2016-01-23 03:05:03 | [diff] [blame] | 1494 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1495 | ASSERT_EQ(OK, |
| 1496 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1497 | net_log_.bound(), callback_.callback())); |
rtenneti | 15656ae | 2016-01-23 03:05:03 | [diff] [blame] | 1498 | ASSERT_EQ(ERR_QUIC_PROTOCOL_ERROR, |
| 1499 | stream_->SendRequest(headers_, &response_, callback_.callback())); |
| 1500 | } |
| 1501 | |
| 1502 | TEST_P(QuicHttpStreamTest, SessionClosedBeforeSendBodyComplete) { |
| 1503 | SetRequest("POST", "/", DEFAULT_PRIORITY); |
| 1504 | size_t spdy_request_headers_frame_length; |
| 1505 | AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY, |
| 1506 | &spdy_request_headers_frame_length)); |
| 1507 | AddWrite(SYNCHRONOUS, ERR_FAILED); |
| 1508 | Initialize(); |
| 1509 | |
| 1510 | ChunkedUploadDataStream upload_data_stream(0); |
| 1511 | size_t chunk_size = strlen(kUploadData); |
| 1512 | upload_data_stream.AppendData(kUploadData, chunk_size, false); |
| 1513 | |
| 1514 | request_.method = "POST"; |
rch | 9ae5b3b | 2016-02-11 00:36:29 | [diff] [blame] | 1515 | request_.url = GURL("http://www.example.org/"); |
rtenneti | 15656ae | 2016-01-23 03:05:03 | [diff] [blame] | 1516 | request_.upload_data_stream = &upload_data_stream; |
| 1517 | ASSERT_EQ(OK, request_.upload_data_stream->Init( |
maksim.sisov | 819ba85 | 2016-08-17 08:22:52 | [diff] [blame] | 1518 | TestCompletionCallback().callback(), BoundNetLog())); |
rtenneti | 15656ae | 2016-01-23 03:05:03 | [diff] [blame] | 1519 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1520 | ASSERT_EQ(OK, |
| 1521 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1522 | net_log_.bound(), callback_.callback())); |
rtenneti | 15656ae | 2016-01-23 03:05:03 | [diff] [blame] | 1523 | ASSERT_EQ(ERR_QUIC_PROTOCOL_ERROR, |
| 1524 | stream_->SendRequest(headers_, &response_, callback_.callback())); |
| 1525 | } |
| 1526 | |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1527 | TEST_P(QuicHttpStreamTest, ServerPushGetRequest) { |
| 1528 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
| 1529 | Initialize(); |
| 1530 | |
| 1531 | // Initialize the first stream, for receiving the promise on. |
| 1532 | request_.method = "GET"; |
| 1533 | request_.url = GURL("http://www.example.org/"); |
| 1534 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1535 | EXPECT_EQ(OK, |
| 1536 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1537 | net_log_.bound(), callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1538 | |
| 1539 | // TODO(ckrasic) - could do this via constructing a PUSH_PROMISE |
| 1540 | // packet, but does it matter? |
| 1541 | ReceivePromise(promise_id_); |
| 1542 | EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); |
| 1543 | |
| 1544 | request_.url = GURL(promise_url_); |
| 1545 | |
| 1546 | // Make the second stream that will exercise the first step of the |
| 1547 | // server push rendezvous mechanism. |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1548 | EXPECT_EQ(OK, promised_stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1549 | net_log_.bound(), |
| 1550 | callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1551 | |
| 1552 | // Receive the promised response headers. |
bnc | 94893a7 | 2016-06-30 13:45:25 | [diff] [blame] | 1553 | response_headers_ = promised_response_.Clone(); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1554 | size_t spdy_response_headers_frame_length; |
| 1555 | ProcessPacket(InnerConstructResponseHeadersPacket( |
| 1556 | 1, promise_id_, false, &spdy_response_headers_frame_length)); |
| 1557 | |
| 1558 | // Receive the promised response body. |
| 1559 | const char kResponseBody[] = "Hello world!"; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1560 | ProcessPacket(InnerConstructDataPacket(2, promise_id_, false, kFin, 0, |
| 1561 | kResponseBody, &server_maker_)); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1562 | |
| 1563 | // Now sending a matching request will have successful rendezvous |
| 1564 | // with the promised stream. |
| 1565 | EXPECT_EQ(OK, promised_stream_->SendRequest(headers_, &response_, |
| 1566 | callback_.callback())); |
| 1567 | |
| 1568 | EXPECT_EQ( |
| 1569 | QuicHttpStreamPeer::GetQuicChromiumClientStream(promised_stream_.get()) |
| 1570 | ->id(), |
| 1571 | promise_id_); |
| 1572 | |
| 1573 | // The headers will be immediately available. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1574 | EXPECT_THAT(promised_stream_->ReadResponseHeaders(callback_.callback()), |
| 1575 | IsOk()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1576 | |
| 1577 | // As will be the body. |
| 1578 | EXPECT_EQ( |
| 1579 | static_cast<int>(strlen(kResponseBody)), |
| 1580 | promised_stream_->ReadResponseBody( |
| 1581 | read_buffer_.get(), read_buffer_->size(), callback_.callback())); |
| 1582 | EXPECT_TRUE(promised_stream_->IsResponseBodyComplete()); |
| 1583 | EXPECT_TRUE(AtEof()); |
| 1584 | |
| 1585 | EXPECT_EQ(0, stream_->GetTotalSentBytes()); |
| 1586 | EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
| 1587 | EXPECT_EQ(0, promised_stream_->GetTotalSentBytes()); |
| 1588 | EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length + |
| 1589 | strlen(kResponseBody)), |
| 1590 | promised_stream_->GetTotalReceivedBytes()); |
| 1591 | } |
| 1592 | |
| 1593 | TEST_P(QuicHttpStreamTest, ServerPushGetRequestSlowResponse) { |
| 1594 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
| 1595 | Initialize(); |
| 1596 | |
| 1597 | // Initialize the first stream, for receiving the promise on. |
| 1598 | request_.method = "GET"; |
| 1599 | request_.url = GURL("http://www.example.org/"); |
| 1600 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1601 | EXPECT_EQ(OK, |
| 1602 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1603 | net_log_.bound(), callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1604 | |
| 1605 | // TODO(ckrasic) - could do this via constructing a PUSH_PROMISE |
| 1606 | // packet, but does it matter? |
| 1607 | ReceivePromise(promise_id_); |
| 1608 | EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); |
| 1609 | |
| 1610 | request_.url = GURL(promise_url_); |
| 1611 | |
| 1612 | // Make the second stream that will exercise the first step of the |
| 1613 | // server push rendezvous mechanism. |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1614 | EXPECT_EQ(OK, promised_stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1615 | net_log_.bound(), |
| 1616 | callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1617 | |
| 1618 | // Now sending a matching request will rendezvous with the promised |
| 1619 | // stream, but pending secondary validation. |
| 1620 | EXPECT_EQ(ERR_IO_PENDING, promised_stream_->SendRequest( |
| 1621 | headers_, &response_, callback_.callback())); |
| 1622 | |
| 1623 | // Receive the promised response headers. |
bnc | 94893a7 | 2016-06-30 13:45:25 | [diff] [blame] | 1624 | response_headers_ = promised_response_.Clone(); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1625 | size_t spdy_response_headers_frame_length; |
| 1626 | ProcessPacket(InnerConstructResponseHeadersPacket( |
| 1627 | 1, promise_id_, false, &spdy_response_headers_frame_length)); |
| 1628 | |
| 1629 | // Receive the promised response body. |
| 1630 | const char kResponseBody[] = "Hello world!"; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1631 | ProcessPacket(InnerConstructDataPacket(2, promise_id_, false, kFin, 0, |
| 1632 | kResponseBody, &server_maker_)); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1633 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1634 | base::RunLoop().RunUntilIdle(); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1635 | |
| 1636 | // Rendezvous should have succeeded now, so the promised stream |
| 1637 | // should point at our push stream, and we should be able read |
| 1638 | // headers and data from it. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1639 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1640 | |
| 1641 | EXPECT_EQ( |
| 1642 | QuicHttpStreamPeer::GetQuicChromiumClientStream(promised_stream_.get()) |
| 1643 | ->id(), |
| 1644 | promise_id_); |
| 1645 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1646 | EXPECT_THAT(promised_stream_->ReadResponseHeaders(callback_.callback()), |
| 1647 | IsOk()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1648 | |
| 1649 | EXPECT_EQ( |
| 1650 | static_cast<int>(strlen(kResponseBody)), |
| 1651 | promised_stream_->ReadResponseBody( |
| 1652 | read_buffer_.get(), read_buffer_->size(), callback_.callback())); |
| 1653 | |
| 1654 | // Callback should return |
| 1655 | EXPECT_TRUE(promised_stream_->IsResponseBodyComplete()); |
| 1656 | EXPECT_TRUE(AtEof()); |
| 1657 | |
| 1658 | EXPECT_EQ(0, stream_->GetTotalSentBytes()); |
| 1659 | EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
| 1660 | EXPECT_EQ(0, promised_stream_->GetTotalSentBytes()); |
| 1661 | EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length + |
| 1662 | strlen(kResponseBody)), |
| 1663 | promised_stream_->GetTotalReceivedBytes()); |
| 1664 | } |
| 1665 | |
ckrasic | 2c63f9b | 2016-08-16 23:54:07 | [diff] [blame] | 1666 | // Verify fix for crbug.com/637349 |
| 1667 | TEST_P(QuicHttpStreamTest, ServerPushCancelHttpStreamBeforeResponse) { |
| 1668 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
| 1669 | Initialize(); |
| 1670 | |
| 1671 | // Initialize the first stream, for receiving the promise on. |
| 1672 | request_.method = "GET"; |
| 1673 | request_.url = GURL("http://www.example.org/"); |
| 1674 | |
| 1675 | EXPECT_EQ(OK, |
| 1676 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1677 | net_log_.bound(), callback_.callback())); |
| 1678 | |
| 1679 | // TODO(ckrasic) - could do this via constructing a PUSH_PROMISE |
| 1680 | // packet, but does it matter? |
| 1681 | ReceivePromise(promise_id_); |
| 1682 | EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); |
| 1683 | |
| 1684 | request_.url = GURL(promise_url_); |
| 1685 | |
| 1686 | // Make the second stream that will exercise the first step of the |
| 1687 | // server push rendezvous mechanism. |
| 1688 | EXPECT_EQ(OK, promised_stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1689 | net_log_.bound(), |
| 1690 | callback_.callback())); |
| 1691 | |
| 1692 | // Now sending a matching request will rendezvous with the promised |
| 1693 | // stream, but pending secondary validation. |
| 1694 | EXPECT_EQ(ERR_IO_PENDING, promised_stream_->SendRequest( |
| 1695 | headers_, &response_, callback_.callback())); |
| 1696 | |
| 1697 | base::RunLoop().RunUntilIdle(); |
| 1698 | |
| 1699 | // Cause of FinalValidation() crash as per bug. |
| 1700 | promised_stream_.reset(); |
| 1701 | |
| 1702 | // Receive the promised response headers. |
| 1703 | response_headers_ = promised_response_.Clone(); |
| 1704 | size_t spdy_response_headers_frame_length; |
| 1705 | ProcessPacket(InnerConstructResponseHeadersPacket( |
| 1706 | 1, promise_id_, false, &spdy_response_headers_frame_length)); |
| 1707 | } |
| 1708 | |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1709 | TEST_P(QuicHttpStreamTest, ServerPushCrossOriginOK) { |
| 1710 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
| 1711 | Initialize(); |
| 1712 | |
| 1713 | // Initialize the first stream, for receiving the promise on. |
| 1714 | request_.method = "GET"; |
| 1715 | request_.url = GURL("http://www.example.org/"); |
| 1716 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1717 | EXPECT_EQ(OK, |
| 1718 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1719 | net_log_.bound(), callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1720 | |
| 1721 | // TODO(ckrasic) - could do this via constructing a PUSH_PROMISE |
| 1722 | // packet, but does it matter? |
| 1723 | |
| 1724 | push_promise_[":authority"] = "mail.example.org"; |
| 1725 | promise_url_ = SpdyUtils::GetUrlFromHeaderBlock(push_promise_); |
| 1726 | serialized_push_promise_ = |
| 1727 | SpdyUtils::SerializeUncompressedHeaders(push_promise_); |
| 1728 | |
| 1729 | ReceivePromise(promise_id_); |
| 1730 | EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); |
| 1731 | |
| 1732 | request_.url = GURL(promise_url_); |
| 1733 | |
| 1734 | // Make the second stream that will exercise the first step of the |
| 1735 | // server push rendezvous mechanism. |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1736 | EXPECT_EQ(OK, promised_stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1737 | net_log_.bound(), |
| 1738 | callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1739 | |
| 1740 | // Receive the promised response headers. |
bnc | 94893a7 | 2016-06-30 13:45:25 | [diff] [blame] | 1741 | response_headers_ = promised_response_.Clone(); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1742 | size_t spdy_response_headers_frame_length; |
| 1743 | ProcessPacket(InnerConstructResponseHeadersPacket( |
| 1744 | 1, promise_id_, false, &spdy_response_headers_frame_length)); |
| 1745 | |
| 1746 | // Receive the promised response body. |
| 1747 | const char kResponseBody[] = "Hello world!"; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1748 | ProcessPacket(InnerConstructDataPacket(2, promise_id_, false, kFin, 0, |
| 1749 | kResponseBody, &server_maker_)); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1750 | |
| 1751 | // Now sending a matching request will have successful rendezvous |
| 1752 | // with the promised stream. |
| 1753 | EXPECT_EQ(OK, promised_stream_->SendRequest(headers_, &response_, |
| 1754 | callback_.callback())); |
| 1755 | |
| 1756 | EXPECT_EQ( |
| 1757 | QuicHttpStreamPeer::GetQuicChromiumClientStream(promised_stream_.get()) |
| 1758 | ->id(), |
| 1759 | promise_id_); |
| 1760 | |
| 1761 | // The headers will be immediately available. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1762 | EXPECT_THAT(promised_stream_->ReadResponseHeaders(callback_.callback()), |
| 1763 | IsOk()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1764 | |
| 1765 | // As will be the body. |
| 1766 | EXPECT_EQ( |
| 1767 | static_cast<int>(strlen(kResponseBody)), |
| 1768 | promised_stream_->ReadResponseBody( |
| 1769 | read_buffer_.get(), read_buffer_->size(), callback_.callback())); |
| 1770 | EXPECT_TRUE(promised_stream_->IsResponseBodyComplete()); |
| 1771 | EXPECT_TRUE(AtEof()); |
| 1772 | |
| 1773 | EXPECT_EQ(0, stream_->GetTotalSentBytes()); |
| 1774 | EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
| 1775 | EXPECT_EQ(0, promised_stream_->GetTotalSentBytes()); |
| 1776 | EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length + |
| 1777 | strlen(kResponseBody)), |
| 1778 | promised_stream_->GetTotalReceivedBytes()); |
| 1779 | } |
| 1780 | |
| 1781 | TEST_P(QuicHttpStreamTest, ServerPushCrossOriginFail) { |
| 1782 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
| 1783 | Initialize(); |
| 1784 | |
| 1785 | // Initialize the first stream, for receiving the promise on. |
| 1786 | request_.method = "GET"; |
| 1787 | request_.url = GURL("http://www.example.org/"); |
| 1788 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1789 | EXPECT_EQ(OK, |
| 1790 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1791 | net_log_.bound(), callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1792 | |
| 1793 | // TODO(ckrasic) - could do this via constructing a PUSH_PROMISE |
| 1794 | // packet, but does it matter? |
| 1795 | push_promise_[":authority"] = "www.notexample.org"; |
| 1796 | promise_url_ = SpdyUtils::GetUrlFromHeaderBlock(push_promise_); |
| 1797 | serialized_push_promise_ = |
| 1798 | SpdyUtils::SerializeUncompressedHeaders(push_promise_); |
| 1799 | |
| 1800 | ReceivePromise(promise_id_); |
| 1801 | // The promise will have been rejected because the cert doesn't |
| 1802 | // match. |
| 1803 | EXPECT_EQ(session_->GetPromisedByUrl(promise_url_), nullptr); |
| 1804 | } |
| 1805 | |
| 1806 | TEST_P(QuicHttpStreamTest, ServerPushVaryCheckOK) { |
| 1807 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
| 1808 | Initialize(); |
| 1809 | |
| 1810 | // Initialize the first stream, for receiving the promise on. |
| 1811 | request_.method = "GET"; |
| 1812 | request_.url = GURL("http://www.example.org/"); |
| 1813 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1814 | EXPECT_EQ(OK, |
| 1815 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1816 | net_log_.bound(), callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1817 | |
| 1818 | push_promise_["accept-encoding"] = "gzip"; |
| 1819 | serialized_push_promise_ = |
| 1820 | SpdyUtils::SerializeUncompressedHeaders(push_promise_); |
| 1821 | |
| 1822 | // TODO(ckrasic) - could do this via constructing a PUSH_PROMISE |
| 1823 | // packet, but does it matter? |
| 1824 | ReceivePromise(promise_id_); |
| 1825 | EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); |
| 1826 | |
| 1827 | request_.url = GURL(promise_url_); |
| 1828 | |
| 1829 | // Make the second stream that will exercise the first step of the |
| 1830 | // server push rendezvous mechanism. |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1831 | EXPECT_EQ(OK, promised_stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1832 | net_log_.bound(), |
| 1833 | callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1834 | |
| 1835 | headers_.SetHeader("accept-encoding", "gzip"); |
| 1836 | |
| 1837 | // Now sending a matching request will rendezvous with the promised |
| 1838 | // stream, but pending secondary validation. |
| 1839 | EXPECT_EQ(ERR_IO_PENDING, promised_stream_->SendRequest( |
| 1840 | headers_, &response_, callback_.callback())); |
| 1841 | |
| 1842 | // Receive the promised response headers. |
| 1843 | promised_response_["vary"] = "accept-encoding"; |
bnc | 94893a7 | 2016-06-30 13:45:25 | [diff] [blame] | 1844 | response_headers_ = promised_response_.Clone(); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1845 | size_t spdy_response_headers_frame_length; |
| 1846 | ProcessPacket(InnerConstructResponseHeadersPacket( |
| 1847 | 1, promise_id_, false, &spdy_response_headers_frame_length)); |
| 1848 | |
| 1849 | // Receive the promised response body. |
| 1850 | const char kResponseBody[] = "Hello world!"; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1851 | ProcessPacket(InnerConstructDataPacket(2, promise_id_, false, kFin, 0, |
| 1852 | kResponseBody, &server_maker_)); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1853 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1854 | base::RunLoop().RunUntilIdle(); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1855 | |
| 1856 | // Rendezvous should have succeeded now, so the promised stream |
| 1857 | // should point at our push stream, and we should be able read |
| 1858 | // headers and data from it. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1859 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1860 | |
| 1861 | EXPECT_EQ( |
| 1862 | QuicHttpStreamPeer::GetQuicChromiumClientStream(promised_stream_.get()) |
| 1863 | ->id(), |
| 1864 | promise_id_); |
| 1865 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1866 | EXPECT_THAT(promised_stream_->ReadResponseHeaders(callback_.callback()), |
| 1867 | IsOk()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1868 | |
| 1869 | EXPECT_EQ( |
| 1870 | static_cast<int>(strlen(kResponseBody)), |
| 1871 | promised_stream_->ReadResponseBody( |
| 1872 | read_buffer_.get(), read_buffer_->size(), callback_.callback())); |
| 1873 | |
| 1874 | // Callback should return |
| 1875 | EXPECT_TRUE(promised_stream_->IsResponseBodyComplete()); |
| 1876 | EXPECT_TRUE(AtEof()); |
| 1877 | |
| 1878 | EXPECT_EQ(0, stream_->GetTotalSentBytes()); |
| 1879 | EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
| 1880 | EXPECT_EQ(0, promised_stream_->GetTotalSentBytes()); |
| 1881 | EXPECT_EQ(static_cast<int64_t>(spdy_response_headers_frame_length + |
| 1882 | strlen(kResponseBody)), |
| 1883 | promised_stream_->GetTotalReceivedBytes()); |
| 1884 | } |
| 1885 | |
| 1886 | TEST_P(QuicHttpStreamTest, ServerPushVaryCheckFail) { |
| 1887 | SetRequest("GET", "/", DEFAULT_PRIORITY); |
| 1888 | request_headers_[":scheme"] = "https"; |
| 1889 | request_headers_[":path"] = "/bar"; |
| 1890 | request_headers_["accept-encoding"] = "sdch"; |
| 1891 | |
| 1892 | size_t spdy_request_header_frame_length; |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1893 | AddWrite(ConstructClientRstStreamVaryMismatchPacket(1)); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1894 | AddWrite(InnerConstructRequestHeadersPacket( |
| 1895 | 2, stream_id_ + 2, !kIncludeVersion, kFin, DEFAULT_PRIORITY, |
xunjieli | 100937eb5 | 2016-09-15 20:09:37 | [diff] [blame] | 1896 | &spdy_request_header_frame_length, /*offset=*/nullptr)); |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1897 | AddWrite(ConstructClientAckPacket(3, 3, 1)); |
| 1898 | AddWrite(ConstructClientRstStreamCancelledPacket(4)); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1899 | Initialize(); |
| 1900 | |
| 1901 | // Initialize the first stream, for receiving the promise on. |
| 1902 | request_.method = "GET"; |
| 1903 | request_.url = GURL("http://www.example.org/"); |
| 1904 | |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1905 | EXPECT_EQ(OK, |
| 1906 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1907 | net_log_.bound(), callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1908 | |
| 1909 | push_promise_["accept-encoding"] = "gzip"; |
| 1910 | serialized_push_promise_ = |
| 1911 | SpdyUtils::SerializeUncompressedHeaders(push_promise_); |
| 1912 | |
| 1913 | // TODO(ckrasic) - could do this via constructing a PUSH_PROMISE |
| 1914 | // packet, but does it matter? |
| 1915 | ReceivePromise(promise_id_); |
| 1916 | EXPECT_NE(session_->GetPromisedByUrl(promise_url_), nullptr); |
| 1917 | |
| 1918 | request_.url = GURL(promise_url_); |
| 1919 | |
| 1920 | // Make the second stream that will exercise the first step of the |
| 1921 | // server push rendezvous mechanism. |
xunjieli | 5fafe14 | 2016-03-23 23:32:54 | [diff] [blame] | 1922 | EXPECT_EQ(OK, promised_stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 1923 | net_log_.bound(), |
| 1924 | callback_.callback())); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1925 | |
| 1926 | headers_.SetHeader("accept-encoding", "sdch"); |
| 1927 | |
| 1928 | // Now sending a matching request will rendezvous with the promised |
| 1929 | // stream, but pending secondary validation. |
| 1930 | EXPECT_EQ(ERR_IO_PENDING, promised_stream_->SendRequest( |
| 1931 | headers_, &response_, callback_.callback())); |
| 1932 | |
| 1933 | // Receive the promised response headers. |
| 1934 | promised_response_["vary"] = "accept-encoding"; |
bnc | 94893a7 | 2016-06-30 13:45:25 | [diff] [blame] | 1935 | response_headers_ = promised_response_.Clone(); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1936 | size_t spdy_response_headers_frame_length; |
| 1937 | ProcessPacket(InnerConstructResponseHeadersPacket( |
| 1938 | 1, promise_id_, false, &spdy_response_headers_frame_length)); |
| 1939 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1940 | base::RunLoop().RunUntilIdle(); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1941 | |
| 1942 | // Rendezvous should have failed due to vary mismatch, so the |
| 1943 | // promised stream should have been aborted, and instead we have a |
| 1944 | // new, regular client initiated stream. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1945 | EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1946 | |
| 1947 | // Not a server-initiated stream. |
| 1948 | EXPECT_NE( |
| 1949 | QuicHttpStreamPeer::GetQuicChromiumClientStream(promised_stream_.get()) |
| 1950 | ->id(), |
| 1951 | promise_id_); |
| 1952 | |
| 1953 | // Instead, a new client-initiated stream. |
| 1954 | EXPECT_EQ( |
| 1955 | QuicHttpStreamPeer::GetQuicChromiumClientStream(promised_stream_.get()) |
| 1956 | ->id(), |
| 1957 | stream_id_ + 2); |
| 1958 | |
| 1959 | // After rendezvous failure, the push stream has been cancelled. |
| 1960 | EXPECT_EQ(session_->GetPromisedByUrl(promise_url_), nullptr); |
| 1961 | |
| 1962 | // The rest of the test verifies that the retried as |
| 1963 | // client-initiated version of |promised_stream_| works as intended. |
| 1964 | |
| 1965 | // Ack the request. |
alyssar | 2adf3ac | 2016-05-03 17:12:58 | [diff] [blame] | 1966 | ProcessPacket(ConstructServerAckPacket(2, 0, 0)); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1967 | |
bnc | 614a92d3 | 2016-04-04 13:56:07 | [diff] [blame] | 1968 | SetResponse("404 Not Found", string()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1969 | size_t spdy_response_header_frame_length; |
| 1970 | ProcessPacket(InnerConstructResponseHeadersPacket( |
| 1971 | 3, stream_id_ + 2, kFin, &spdy_response_header_frame_length)); |
| 1972 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1973 | base::RunLoop().RunUntilIdle(); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1974 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1975 | EXPECT_THAT(promised_stream_->ReadResponseHeaders(callback_.callback()), |
| 1976 | IsOk()); |
ckrasic | 3865ee0f | 2016-02-29 22:04:56 | [diff] [blame] | 1977 | ASSERT_TRUE(response_.headers.get()); |
| 1978 | EXPECT_EQ(404, response_.headers->response_code()); |
| 1979 | EXPECT_TRUE(response_.headers->HasHeaderValue("Content-Type", "text/plain")); |
| 1980 | EXPECT_FALSE(response_.response_time.is_null()); |
| 1981 | EXPECT_FALSE(response_.request_time.is_null()); |
| 1982 | |
| 1983 | // There is no body, so this should return immediately. |
| 1984 | EXPECT_EQ( |
| 1985 | 0, promised_stream_->ReadResponseBody( |
| 1986 | read_buffer_.get(), read_buffer_->size(), callback_.callback())); |
| 1987 | EXPECT_TRUE(promised_stream_->IsResponseBodyComplete()); |
| 1988 | |
| 1989 | stream_->Close(true); |
| 1990 | |
| 1991 | EXPECT_TRUE(AtEof()); |
| 1992 | |
| 1993 | // QuicHttpStream::GetTotalSent/ReceivedBytes currently only includes the |
| 1994 | // headers and payload. |
| 1995 | EXPECT_EQ(static_cast<int64_t>(spdy_request_header_frame_length), |
| 1996 | promised_stream_->GetTotalSentBytes()); |
| 1997 | EXPECT_EQ(static_cast<int64_t>(spdy_response_header_frame_length), |
| 1998 | promised_stream_->GetTotalReceivedBytes()); |
| 1999 | } |
| 2000 | |
maksim.sisov | 84e20c9 | 2016-06-23 08:49:34 | [diff] [blame] | 2001 | TEST_P(QuicHttpStreamTest, DataReadErrorSynchronous) { |
| 2002 | SetRequest("POST", "/", DEFAULT_PRIORITY); |
| 2003 | size_t spdy_request_headers_frame_length; |
| 2004 | AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY, |
| 2005 | &spdy_request_headers_frame_length)); |
| 2006 | AddWrite(ConstructClientRstStreamErrorPacket(2, kIncludeVersion)); |
| 2007 | |
| 2008 | Initialize(); |
| 2009 | |
| 2010 | ReadErrorUploadDataStream upload_data_stream( |
| 2011 | ReadErrorUploadDataStream::FailureMode::SYNC); |
| 2012 | request_.method = "POST"; |
| 2013 | request_.url = GURL("http://www.example.org/"); |
| 2014 | request_.upload_data_stream = &upload_data_stream; |
| 2015 | ASSERT_EQ(OK, request_.upload_data_stream->Init( |
maksim.sisov | 819ba85 | 2016-08-17 08:22:52 | [diff] [blame] | 2016 | TestCompletionCallback().callback(), BoundNetLog())); |
maksim.sisov | 84e20c9 | 2016-06-23 08:49:34 | [diff] [blame] | 2017 | |
| 2018 | EXPECT_EQ(OK, |
| 2019 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 2020 | net_log_.bound(), callback_.callback())); |
| 2021 | |
| 2022 | int result = stream_->SendRequest(headers_, &response_, callback_.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2023 | EXPECT_THAT(result, IsError(ERR_FAILED)); |
maksim.sisov | 84e20c9 | 2016-06-23 08:49:34 | [diff] [blame] | 2024 | |
| 2025 | EXPECT_TRUE(AtEof()); |
| 2026 | |
| 2027 | // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers. |
| 2028 | EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
| 2029 | stream_->GetTotalSentBytes()); |
| 2030 | EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
| 2031 | } |
| 2032 | |
| 2033 | TEST_P(QuicHttpStreamTest, DataReadErrorAsynchronous) { |
| 2034 | SetRequest("POST", "/", DEFAULT_PRIORITY); |
| 2035 | size_t spdy_request_headers_frame_length; |
| 2036 | AddWrite(ConstructRequestHeadersPacket(1, !kFin, DEFAULT_PRIORITY, |
| 2037 | &spdy_request_headers_frame_length)); |
| 2038 | AddWrite(ConstructClientRstStreamErrorPacket(2, !kIncludeVersion)); |
| 2039 | |
| 2040 | Initialize(); |
| 2041 | |
| 2042 | ReadErrorUploadDataStream upload_data_stream( |
| 2043 | ReadErrorUploadDataStream::FailureMode::ASYNC); |
| 2044 | request_.method = "POST"; |
| 2045 | request_.url = GURL("http://www.example.org/"); |
| 2046 | request_.upload_data_stream = &upload_data_stream; |
| 2047 | ASSERT_EQ(OK, request_.upload_data_stream->Init( |
maksim.sisov | 819ba85 | 2016-08-17 08:22:52 | [diff] [blame] | 2048 | TestCompletionCallback().callback(), BoundNetLog())); |
maksim.sisov | 84e20c9 | 2016-06-23 08:49:34 | [diff] [blame] | 2049 | |
| 2050 | EXPECT_EQ(OK, |
| 2051 | stream_->InitializeStream(&request_, DEFAULT_PRIORITY, |
| 2052 | net_log_.bound(), callback_.callback())); |
| 2053 | |
| 2054 | int result = stream_->SendRequest(headers_, &response_, callback_.callback()); |
| 2055 | |
| 2056 | ProcessPacket(ConstructServerAckPacket(1, 0, 0)); |
| 2057 | SetResponse("200 OK", string()); |
| 2058 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2059 | EXPECT_THAT(result, IsError(ERR_IO_PENDING)); |
| 2060 | EXPECT_THAT(callback_.GetResult(result), IsError(ERR_FAILED)); |
maksim.sisov | 84e20c9 | 2016-06-23 08:49:34 | [diff] [blame] | 2061 | |
| 2062 | EXPECT_TRUE(AtEof()); |
| 2063 | |
| 2064 | // QuicHttpStream::GetTotalSent/ReceivedBytes includes only headers. |
| 2065 | EXPECT_EQ(static_cast<int64_t>(spdy_request_headers_frame_length), |
| 2066 | stream_->GetTotalSentBytes()); |
| 2067 | EXPECT_EQ(0, stream_->GetTotalReceivedBytes()); |
| 2068 | } |
| 2069 | |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 2070 | } // namespace test |
[email protected] | f702d57 | 2012-12-04 15:56:20 | [diff] [blame] | 2071 | } // namespace net |