[email protected] | a159531 | 2012-01-22 03:25:04 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 5af3c57 | 2010-07-20 14:16:27 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 3 | // found in the LICENSE file. |
| 4 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5 | #include <cmath> |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 6 | #include <memory> |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 7 | #include <string> |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 8 | #include <utility> |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11 | #include "base/bind.h" |
| 12 | #include "base/bind_helpers.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 13 | #include "base/files/file_util.h" |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 14 | #include "base/files/scoped_temp_dir.h" |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 15 | #include "base/memory/ptr_util.h" |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 16 | #include "base/run_loop.h" |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 17 | #include "base/strings/string_piece.h" |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 18 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 19 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 20 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 21 | #include "net/base/chunked_upload_data_stream.h" |
| 22 | #include "net/base/elements_upload_data_stream.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 23 | #include "net/base/proxy_delegate.h" |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 24 | #include "net/base/request_priority.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 25 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 26 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 27 | #include "net/base/upload_file_element_reader.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 28 | #include "net/http/http_auth_scheme.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 29 | #include "net/http/http_network_session_peer.h" |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 30 | #include "net/http/http_network_transaction.h" |
| 31 | #include "net/http/http_server_properties.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 32 | #include "net/http/http_transaction_test_util.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 33 | #include "net/log/net_log_event_type.h" |
mmenke | 16a7cbdd | 2015-04-24 23:00:56 | [diff] [blame] | 34 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 35 | #include "net/log/test_net_log_entry.h" |
| 36 | #include "net/log/test_net_log_util.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 37 | #include "net/proxy/proxy_server.h" |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 38 | #include "net/socket/client_socket_pool_base.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 39 | #include "net/socket/next_proto.h" |
[email protected] | f54c8579 | 2012-03-08 19:06:41 | [diff] [blame] | 40 | #include "net/spdy/buffered_spdy_framer.h" |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 41 | #include "net/spdy/spdy_http_stream.h" |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 42 | #include "net/spdy/spdy_http_utils.h" |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 43 | #include "net/spdy/spdy_session.h" |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 44 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 45 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | a4bfdf7 | 2013-02-22 04:06:16 | [diff] [blame] | 46 | #include "net/spdy/spdy_test_utils.h" |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 47 | #include "net/ssl/ssl_connection_status_flags.h" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 48 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 49 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 50 | #include "net/test/test_data_directory.h" |
[email protected] | d2db029 | 2011-01-26 20:23:44 | [diff] [blame] | 51 | #include "net/url_request/url_request_test_util.h" |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 52 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 53 | #include "testing/platform_test.h" |
| 54 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 55 | using net::test::IsError; |
| 56 | using net::test::IsOk; |
| 57 | |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 58 | //----------------------------------------------------------------------------- |
| 59 | |
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 60 | namespace net { |
[email protected] | dae22c5 | 2010-07-30 02:16:35 | [diff] [blame] | 61 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 62 | namespace { |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 63 | |
| 64 | using testing::Each; |
| 65 | using testing::Eq; |
| 66 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 67 | const int32_t kBufferSize = SpdyHttpStream::kRequestBodyBufferSize; |
| 68 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 69 | } // namespace |
| 70 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 71 | class SpdyNetworkTransactionTest : public ::testing::Test { |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 72 | protected: |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 73 | SpdyNetworkTransactionTest() |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 74 | : default_url_(kDefaultUrl), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 75 | host_port_pair_(HostPortPair::FromURL(default_url_)) {} |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 76 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 77 | ~SpdyNetworkTransactionTest() override { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 78 | // UploadDataStream may post a deletion tasks back to the message loop on |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 79 | // destruction. |
| 80 | upload_data_stream_.reset(); |
| 81 | base::RunLoop().RunUntilIdle(); |
| 82 | } |
| 83 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 84 | void SetUp() override { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 85 | get_request_initialized_ = false; |
| 86 | post_request_initialized_ = false; |
| 87 | chunked_post_request_initialized_ = false; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 88 | ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 89 | } |
| 90 | |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 91 | struct TransactionHelperResult { |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 92 | int rv; |
| 93 | std::string status_line; |
| 94 | std::string response_data; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 95 | HttpResponseInfo response_info; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 96 | }; |
| 97 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 98 | // A helper class that handles all the initial npn/ssl setup. |
| 99 | class NormalSpdyTransactionHelper { |
| 100 | public: |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 101 | NormalSpdyTransactionHelper( |
| 102 | const HttpRequestInfo& request, |
| 103 | RequestPriority priority, |
| 104 | const BoundNetLog& log, |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 105 | std::unique_ptr<SpdySessionDependencies> session_deps) |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 106 | : request_(request), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 107 | priority_(priority), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 108 | session_deps_(session_deps.get() == NULL |
| 109 | ? base::MakeUnique<SpdySessionDependencies>() |
| 110 | : std::move(session_deps)), |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 111 | session_( |
| 112 | SpdySessionDependencies::SpdyCreateSession(session_deps_.get())), |
bnc | 927c496 | 2016-07-21 14:45:59 | [diff] [blame] | 113 | log_(log) {} |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 114 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 115 | ~NormalSpdyTransactionHelper() { |
| 116 | // Any test which doesn't close the socket by sending it an EOF will |
| 117 | // have a valid session left open, which leaks the entire session pool. |
| 118 | // This is just fine - in fact, some of our tests intentionally do this |
| 119 | // so that we can check consistency of the SpdySessionPool as the test |
| 120 | // finishes. If we had put an EOF on the socket, the SpdySession would |
| 121 | // have closed and we wouldn't be able to check the consistency. |
| 122 | |
| 123 | // Forcefully close existing sessions here. |
| 124 | session()->spdy_session_pool()->CloseAllSessions(); |
| 125 | } |
| 126 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 127 | void RunPreTestSetup() { |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 128 | // We're now ready to use SSL-npn SPDY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 129 | trans_.reset(new HttpNetworkTransaction(priority_, session_.get())); |
[email protected] | cb54b3b2 | 2010-06-03 16:28:55 | [diff] [blame] | 130 | } |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 131 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 132 | // Start the transaction, read some data, finish. |
| 133 | void RunDefaultTest() { |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 134 | if (!StartDefaultTest()) |
| 135 | return; |
| 136 | FinishDefaultTest(); |
| 137 | } |
| 138 | |
| 139 | bool StartDefaultTest() { |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 140 | output_.rv = trans_->Start(&request_, callback_.callback(), log_); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 141 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 142 | // We expect an IO Pending or some sort of error. |
| 143 | EXPECT_LT(output_.rv, 0); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 144 | return output_.rv == ERR_IO_PENDING; |
| 145 | } |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 146 | |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 147 | void FinishDefaultTest() { |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 148 | output_.rv = callback_.WaitForResult(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 149 | if (output_.rv != OK) { |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 150 | session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 151 | return; |
| 152 | } |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 153 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 154 | // Verify responses. |
| 155 | const HttpResponseInfo* response = trans_->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 156 | ASSERT_TRUE(response); |
| 157 | ASSERT_TRUE(response->headers); |
bnc | 927c496 | 2016-07-21 14:45:59 | [diff] [blame] | 158 | EXPECT_EQ(HttpResponseInfo::ConnectionInfoFromNextProto(kProtoHTTP2), |
| 159 | response->connection_info); |
| 160 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 161 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 162 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 163 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 164 | EXPECT_EQ(443, response->socket_address.port()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 165 | output_.status_line = response->headers->GetStatusLine(); |
| 166 | output_.response_info = *response; // Make a copy so we can verify. |
| 167 | output_.rv = ReadTransaction(trans_.get(), &output_.response_data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 168 | } |
| 169 | |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 170 | void FinishDefaultTestWithoutVerification() { |
| 171 | output_.rv = callback_.WaitForResult(); |
| 172 | if (output_.rv != OK) |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 173 | session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 174 | } |
| 175 | |
maksim.sisov | 8d2df66d | 2016-06-20 07:07:11 | [diff] [blame] | 176 | void WaitForCallbackToComplete() { output_.rv = callback_.WaitForResult(); } |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 177 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 178 | // Most tests will want to call this function. In particular, the MockReads |
| 179 | // should end with an empty read, and that read needs to be processed to |
| 180 | // ensure proper deletion of the spdy_session_pool. |
| 181 | void VerifyDataConsumed() { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 182 | for (const SocketDataProvider* provider : data_vector_) { |
| 183 | EXPECT_TRUE(provider->AllReadDataConsumed()); |
| 184 | EXPECT_TRUE(provider->AllWriteDataConsumed()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
| 188 | // Occasionally a test will expect to error out before certain reads are |
| 189 | // processed. In that case we want to explicitly ensure that the reads were |
| 190 | // not processed. |
| 191 | void VerifyDataNotConsumed() { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 192 | for (const SocketDataProvider* provider : data_vector_) { |
| 193 | EXPECT_FALSE(provider->AllReadDataConsumed()); |
| 194 | EXPECT_FALSE(provider->AllWriteDataConsumed()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 198 | void RunToCompletion(SocketDataProvider* data) { |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 199 | RunPreTestSetup(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 200 | AddData(data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 201 | RunDefaultTest(); |
| 202 | VerifyDataConsumed(); |
| 203 | } |
[email protected] | e6b0686 | 2010-07-20 16:32:58 | [diff] [blame] | 204 | |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 205 | void RunToCompletionWithSSLData( |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 206 | SocketDataProvider* data, |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 207 | std::unique_ptr<SSLSocketDataProvider> ssl_provider) { |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 208 | RunPreTestSetup(); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 209 | AddDataWithSSLSocketDataProvider(data, std::move(ssl_provider)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 210 | RunDefaultTest(); |
| 211 | VerifyDataConsumed(); |
| 212 | } |
| 213 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 214 | void AddData(SocketDataProvider* data) { |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 215 | std::unique_ptr<SSLSocketDataProvider> ssl_provider( |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 216 | new SSLSocketDataProvider(ASYNC, OK)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 217 | ssl_provider->cert = |
| 218 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 219 | AddDataWithSSLSocketDataProvider(data, std::move(ssl_provider)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | void AddDataWithSSLSocketDataProvider( |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 223 | SocketDataProvider* data, |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 224 | std::unique_ptr<SSLSocketDataProvider> ssl_provider) { |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 225 | data_vector_.push_back(data); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 226 | if (ssl_provider->next_proto == kProtoUnknown) |
| 227 | ssl_provider->next_proto = kProtoHTTP2; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 228 | |
| 229 | session_deps_->socket_factory->AddSSLSocketDataProvider( |
| 230 | ssl_provider.get()); |
olli.raula | ae011c42 | 2015-12-10 07:38:51 | [diff] [blame] | 231 | ssl_vector_.push_back(std::move(ssl_provider)); |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 232 | |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 233 | session_deps_->socket_factory->AddSocketDataProvider(data); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 234 | } |
| 235 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 236 | HttpNetworkTransaction* trans() { return trans_.get(); } |
| 237 | void ResetTrans() { trans_.reset(); } |
bnc | 4d782f49 | 2016-08-18 13:50:00 | [diff] [blame] | 238 | const TransactionHelperResult& output() { return output_; } |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 239 | const HttpRequestInfo& request() const { return request_; } |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 240 | HttpNetworkSession* session() const { return session_.get(); } |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 241 | SpdySessionDependencies* session_deps() { return session_deps_.get(); } |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 242 | |
| 243 | private: |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 244 | typedef std::vector<SocketDataProvider*> DataVector; |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 245 | typedef std::vector<std::unique_ptr<SSLSocketDataProvider>> SSLVector; |
| 246 | typedef std::vector<std::unique_ptr<SocketDataProvider>> AlternateVector; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 247 | HttpRequestInfo request_; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 248 | RequestPriority priority_; |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 249 | std::unique_ptr<SpdySessionDependencies> session_deps_; |
| 250 | std::unique_ptr<HttpNetworkSession> session_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 251 | TransactionHelperResult output_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 252 | SSLVector ssl_vector_; |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 253 | TestCompletionCallback callback_; |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 254 | std::unique_ptr<HttpNetworkTransaction> trans_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 255 | DataVector data_vector_; |
bnc | 29b1f07 | 2015-01-14 20:37:49 | [diff] [blame] | 256 | const BoundNetLog log_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 257 | }; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 258 | |
| 259 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 260 | int expected_status); |
| 261 | |
| 262 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 263 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 264 | const HttpRequestInfo& CreateGetPushRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 265 | get_push_request_.method = "GET"; |
| 266 | get_push_request_.url = GURL(GetDefaultUrlWithPath("/foo.dat")); |
| 267 | get_push_request_.load_flags = 0; |
| 268 | return get_push_request_; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 269 | } |
| 270 | |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 271 | const HttpRequestInfo& CreateGetRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 272 | if (!get_request_initialized_) { |
| 273 | get_request_.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 274 | get_request_.url = default_url_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 275 | get_request_.load_flags = 0; |
| 276 | get_request_initialized_ = true; |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 277 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 278 | return get_request_; |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 279 | } |
| 280 | |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 281 | const HttpRequestInfo& CreateGetRequestWithUserAgent() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 282 | if (!get_request_initialized_) { |
| 283 | get_request_.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 284 | get_request_.url = default_url_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 285 | get_request_.load_flags = 0; |
| 286 | get_request_.extra_headers.SetHeader("User-Agent", "Chrome"); |
| 287 | get_request_initialized_ = true; |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 288 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 289 | return get_request_; |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 290 | } |
| 291 | |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 292 | const HttpRequestInfo& CreatePostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 293 | if (!post_request_initialized_) { |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 294 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame^] | 295 | element_readers.push_back(base::MakeUnique<UploadBytesElementReader>( |
| 296 | kUploadData, kUploadDataSize)); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 297 | upload_data_stream_.reset( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 298 | new ElementsUploadDataStream(std::move(element_readers), 0)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 299 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 300 | post_request_.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 301 | post_request_.url = default_url_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 302 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 303 | post_request_initialized_ = true; |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 304 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 305 | return post_request_; |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 306 | } |
| 307 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 308 | const HttpRequestInfo& CreateFilePostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 309 | if (!post_request_initialized_) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 310 | base::FilePath file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 311 | CHECK(base::CreateTemporaryFileInDir(temp_dir_.path(), &file_path)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 312 | CHECK_EQ(static_cast<int>(kUploadDataSize), |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 313 | base::WriteFile(file_path, kUploadData, kUploadDataSize)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 314 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 315 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame^] | 316 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 317 | base::ThreadTaskRunnerHandle::Get().get(), file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame^] | 318 | kUploadDataSize, base::Time())); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 319 | upload_data_stream_.reset( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 320 | new ElementsUploadDataStream(std::move(element_readers), 0)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 321 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 322 | post_request_.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 323 | post_request_.url = default_url_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 324 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 325 | post_request_initialized_ = true; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 326 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 327 | return post_request_; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 328 | } |
| 329 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 330 | const HttpRequestInfo& CreateUnreadableFilePostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 331 | if (post_request_initialized_) |
| 332 | return post_request_; |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 333 | |
| 334 | base::FilePath file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 335 | CHECK(base::CreateTemporaryFileInDir(temp_dir_.path(), &file_path)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 336 | CHECK_EQ(static_cast<int>(kUploadDataSize), |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 337 | base::WriteFile(file_path, kUploadData, kUploadDataSize)); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 338 | CHECK(base::MakeFileUnreadable(file_path)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 339 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 340 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame^] | 341 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 342 | base::ThreadTaskRunnerHandle::Get().get(), file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame^] | 343 | kUploadDataSize, base::Time())); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 344 | upload_data_stream_.reset( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 345 | new ElementsUploadDataStream(std::move(element_readers), 0)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 346 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 347 | post_request_.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 348 | post_request_.url = default_url_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 349 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 350 | post_request_initialized_ = true; |
| 351 | return post_request_; |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 352 | } |
| 353 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 354 | const HttpRequestInfo& CreateComplexPostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 355 | if (!post_request_initialized_) { |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 356 | const int kFileRangeOffset = 1; |
| 357 | const int kFileRangeLength = 3; |
| 358 | CHECK_LT(kFileRangeOffset + kFileRangeLength, kUploadDataSize); |
| 359 | |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 360 | base::FilePath file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 361 | CHECK(base::CreateTemporaryFileInDir(temp_dir_.path(), &file_path)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 362 | CHECK_EQ(static_cast<int>(kUploadDataSize), |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 363 | base::WriteFile(file_path, kUploadData, kUploadDataSize)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 364 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 365 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame^] | 366 | element_readers.push_back(base::MakeUnique<UploadBytesElementReader>( |
| 367 | kUploadData, kFileRangeOffset)); |
| 368 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 369 | base::ThreadTaskRunnerHandle::Get().get(), file_path, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame^] | 370 | kFileRangeOffset, kFileRangeLength, base::Time())); |
| 371 | element_readers.push_back(base::MakeUnique<UploadBytesElementReader>( |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 372 | kUploadData + kFileRangeOffset + kFileRangeLength, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame^] | 373 | kUploadDataSize - (kFileRangeOffset + kFileRangeLength))); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 374 | upload_data_stream_.reset( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 375 | new ElementsUploadDataStream(std::move(element_readers), 0)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 376 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 377 | post_request_.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 378 | post_request_.url = default_url_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 379 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 380 | post_request_initialized_ = true; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 381 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 382 | return post_request_; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 383 | } |
| 384 | |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 385 | const HttpRequestInfo& CreateChunkedPostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 386 | if (!chunked_post_request_initialized_) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 387 | upload_chunked_data_stream_.reset(new ChunkedUploadDataStream(0)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 388 | chunked_post_request_.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 389 | chunked_post_request_.url = default_url_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 390 | chunked_post_request_.upload_data_stream = |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 391 | upload_chunked_data_stream_.get(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 392 | chunked_post_request_initialized_ = true; |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 393 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 394 | return chunked_post_request_; |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 395 | } |
| 396 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 397 | // Read the result of a particular transaction, knowing that we've got |
| 398 | // multiple transactions in the read pipeline; so as we read, we may have |
| 399 | // to skip over data destined for other transactions while we consume |
| 400 | // the data for |trans|. |
| 401 | int ReadResult(HttpNetworkTransaction* trans, |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 402 | std::string* result) { |
| 403 | const int kSize = 3000; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 404 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 405 | int bytes_read = 0; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 406 | scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(kSize)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 407 | TestCompletionCallback callback; |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 408 | while (true) { |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 409 | int rv = trans->Read(buf.get(), kSize, callback.callback()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 410 | if (rv == ERR_IO_PENDING) { |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 411 | rv = callback.WaitForResult(); |
| 412 | } else if (rv <= 0) { |
| 413 | break; |
| 414 | } |
| 415 | result->append(buf->data(), rv); |
| 416 | bytes_read += rv; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 417 | } |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 418 | return bytes_read; |
| 419 | } |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 420 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 421 | void VerifyStreamsClosed(const NormalSpdyTransactionHelper& helper) { |
| 422 | // This lengthy block is reaching into the pool to dig out the active |
| 423 | // session. Once we have the session, we verify that the streams are |
| 424 | // all closed and not leaked at this point. |
| 425 | const GURL& url = helper.request().url; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 426 | SpdySessionKey key(HostPortPair::FromURL(url), ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 427 | PRIVACY_MODE_DISABLED); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 428 | BoundNetLog log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 429 | HttpNetworkSession* session = helper.session(); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 430 | base::WeakPtr<SpdySession> spdy_session = |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 431 | session->spdy_session_pool()->FindAvailableSession(key, url, log); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 432 | ASSERT_TRUE(spdy_session); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 433 | EXPECT_EQ(0u, spdy_session->num_active_streams()); |
| 434 | EXPECT_EQ(0u, spdy_session->num_unclaimed_pushed_streams()); |
| 435 | } |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 436 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 437 | void RunServerPushTest(SequencedSocketData* data, |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 438 | HttpResponseInfo* response, |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 439 | HttpResponseInfo* push_response, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 440 | const std::string& expected) { |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 441 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 442 | BoundNetLog(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 443 | helper.RunPreTestSetup(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 444 | helper.AddData(data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 445 | |
| 446 | HttpNetworkTransaction* trans = helper.trans(); |
| 447 | |
| 448 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 449 | TestCompletionCallback callback; |
| 450 | int rv = trans->Start( |
| 451 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 452 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 453 | rv = callback.WaitForResult(); |
| 454 | |
| 455 | // Request the pushed path. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 456 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
| 457 | rv = trans2.Start(&CreateGetPushRequest(), callback.callback(), |
| 458 | BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 459 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 460 | base::RunLoop().RunUntilIdle(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 461 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 462 | // The data for the pushed path may be coming in more than 1 frame. Compile |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 463 | // the results into a single string. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 464 | |
| 465 | // Read the server push body. |
| 466 | std::string result2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 467 | ReadResult(&trans2, &result2); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 468 | // Read the response body. |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 469 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 470 | ReadResult(trans, &result); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 471 | |
| 472 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 473 | EXPECT_TRUE(data->AllReadDataConsumed()); |
| 474 | EXPECT_TRUE(data->AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 475 | |
caseq | e8340bc9 | 2016-04-20 00:02:57 | [diff] [blame] | 476 | LoadTimingInfo load_timing_info; |
| 477 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 478 | EXPECT_TRUE(load_timing_info.push_start.is_null()); |
| 479 | EXPECT_TRUE(load_timing_info.push_end.is_null()); |
| 480 | |
| 481 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 482 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
caseq | e8340bc9 | 2016-04-20 00:02:57 | [diff] [blame] | 483 | EXPECT_FALSE(load_timing_info2.push_start.is_null()); |
| 484 | EXPECT_FALSE(load_timing_info2.push_end.is_null()); |
| 485 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 486 | // Verify that the received push data is same as the expected push data. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 487 | EXPECT_EQ(result2.compare(expected), 0) << "Received data: " |
| 488 | << result2 |
| 489 | << "||||| Expected data: " |
| 490 | << expected; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 491 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 492 | // Verify the response HEADERS. |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 493 | // Copy the response info, because trans goes away. |
| 494 | *response = *trans->GetResponseInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 495 | *push_response = *trans2.GetResponseInfo(); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 496 | |
| 497 | VerifyStreamsClosed(helper); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 498 | } |
| 499 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 500 | static void DeleteSessionCallback(NormalSpdyTransactionHelper* helper, |
| 501 | int result) { |
| 502 | helper->ResetTrans(); |
| 503 | } |
| 504 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 505 | static void StartTransactionCallback(HttpNetworkSession* session, |
| 506 | GURL url, |
| 507 | int result) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 508 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 509 | TestCompletionCallback callback; |
| 510 | HttpRequestInfo request; |
| 511 | request.method = "GET"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 512 | request.url = url; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 513 | request.load_flags = 0; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 514 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 515 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 516 | callback.WaitForResult(); |
| 517 | } |
| 518 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 519 | ChunkedUploadDataStream* upload_chunked_data_stream() const { |
| 520 | return upload_chunked_data_stream_.get(); |
| 521 | } |
| 522 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 523 | std::string GetDefaultUrlWithPath(const char* path) { |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 524 | return std::string(kDefaultUrl) + path; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 525 | } |
| 526 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 527 | const GURL default_url_; |
| 528 | const HostPortPair host_port_pair_; |
[email protected] | 9ec54f8 | 2013-05-10 02:53:05 | [diff] [blame] | 529 | SpdyTestUtil spdy_util_; |
| 530 | |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 531 | private: |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 532 | std::unique_ptr<ChunkedUploadDataStream> upload_chunked_data_stream_; |
| 533 | std::unique_ptr<UploadDataStream> upload_data_stream_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 534 | bool get_request_initialized_; |
| 535 | bool post_request_initialized_; |
| 536 | bool chunked_post_request_initialized_; |
| 537 | HttpRequestInfo get_request_; |
| 538 | HttpRequestInfo post_request_; |
| 539 | HttpRequestInfo chunked_post_request_; |
| 540 | HttpRequestInfo get_push_request_; |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 541 | base::ScopedTempDir temp_dir_; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 542 | }; |
| 543 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 544 | // Verify HttpNetworkTransaction constructor. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 545 | TEST_F(SpdyNetworkTransactionTest, Constructor) { |
| 546 | auto session_deps = base::MakeUnique<SpdySessionDependencies>(); |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 547 | std::unique_ptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 548 | SpdySessionDependencies::SpdyCreateSession(session_deps.get())); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 549 | auto trans = |
| 550 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 551 | } |
| 552 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 553 | TEST_F(SpdyNetworkTransactionTest, Get) { |
[email protected] | 75f30cc2 | 2010-06-28 21:41:38 | [diff] [blame] | 554 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 555 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 556 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 557 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 558 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 559 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 560 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 561 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 562 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 563 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 564 | }; |
| 565 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 566 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 567 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 568 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 569 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 570 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 571 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 572 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 573 | EXPECT_EQ("hello!", out.response_data); |
| 574 | } |
| 575 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 576 | TEST_F(SpdyNetworkTransactionTest, GetAtEachPriority) { |
[email protected] | 3d08dd38 | 2013-10-19 00:13:11 | [diff] [blame] | 577 | for (RequestPriority p = MINIMUM_PRIORITY; p <= MAXIMUM_PRIORITY; |
[email protected] | 31ae7ab | 2012-04-24 21:09:05 | [diff] [blame] | 578 | p = RequestPriority(p + 1)) { |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 579 | SpdyTestUtil spdy_test_util; |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 580 | |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 581 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 582 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 583 | spdy_test_util.ConstructSpdyGet(nullptr, 0, 1, p, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 584 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 585 | |
[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 586 | SpdyPriority spdy_prio = 0; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 587 | EXPECT_TRUE(GetSpdyPriority(req, &spdy_prio)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 588 | // this repeats the RequestPriority-->SpdyPriority mapping from |
| 589 | // SpdyFramer::ConvertRequestPriorityToSpdyPriority to make |
| 590 | // sure it's being done right. |
bnc | 05808ff4 | 2016-01-08 23:48:25 | [diff] [blame] | 591 | switch (p) { |
| 592 | case HIGHEST: |
| 593 | EXPECT_EQ(0, spdy_prio); |
| 594 | break; |
| 595 | case MEDIUM: |
| 596 | EXPECT_EQ(1, spdy_prio); |
| 597 | break; |
| 598 | case LOW: |
| 599 | EXPECT_EQ(2, spdy_prio); |
| 600 | break; |
| 601 | case LOWEST: |
| 602 | EXPECT_EQ(3, spdy_prio); |
| 603 | break; |
| 604 | case IDLE: |
| 605 | EXPECT_EQ(4, spdy_prio); |
| 606 | break; |
| 607 | default: |
| 608 | FAIL(); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 609 | } |
| 610 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 611 | SpdySerializedFrame resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 612 | spdy_test_util.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 613 | SpdySerializedFrame body(spdy_test_util.ConstructSpdyDataFrame(1, true)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 614 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 615 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 616 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 617 | }; |
| 618 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 619 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 620 | arraysize(writes)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 621 | HttpRequestInfo http_req = CreateGetRequest(); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 622 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 623 | NormalSpdyTransactionHelper helper(http_req, p, BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 624 | helper.RunToCompletion(&data); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 625 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 626 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 627 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 628 | EXPECT_EQ("hello!", out.response_data); |
| 629 | } |
| 630 | } |
| 631 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 632 | // Start three gets simultaniously; making sure that multiplexed |
| 633 | // streams work properly. |
| 634 | |
| 635 | // This can't use the TransactionHelper method, since it only |
| 636 | // handles a single transaction, and finishes them as soon |
| 637 | // as it launches them. |
| 638 | |
| 639 | // TODO(gavinp): create a working generalized TransactionHelper that |
| 640 | // can allow multiple streams in flight. |
| 641 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 642 | TEST_F(SpdyNetworkTransactionTest, ThreeGets) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 643 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 644 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 645 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 646 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 647 | SpdySerializedFrame fbody(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 648 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 649 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 650 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 651 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 652 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, false)); |
| 653 | SpdySerializedFrame fbody2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 654 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 655 | SpdySerializedFrame req3( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 656 | spdy_util_.ConstructSpdyGet(nullptr, 0, 5, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 657 | SpdySerializedFrame resp3(spdy_util_.ConstructSpdyGetReply(NULL, 0, 5)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 658 | SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame(5, false)); |
| 659 | SpdySerializedFrame fbody3(spdy_util_.ConstructSpdyDataFrame(5, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 660 | |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 661 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 662 | CreateMockWrite(req, 0), CreateMockWrite(req2, 3), |
| 663 | CreateMockWrite(req3, 6), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 664 | }; |
| 665 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 666 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
| 667 | CreateMockRead(resp2, 4), CreateMockRead(body2, 5), |
| 668 | CreateMockRead(resp3, 7), CreateMockRead(body3, 8), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 669 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 670 | CreateMockRead(fbody, 9), CreateMockRead(fbody2, 10), |
| 671 | CreateMockRead(fbody3, 11), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 672 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 673 | MockRead(ASYNC, 0, 12), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 674 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 675 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 676 | SequencedSocketData data_placeholder1(NULL, 0, NULL, 0); |
| 677 | SequencedSocketData data_placeholder2(NULL, 0, NULL, 0); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 678 | |
| 679 | BoundNetLog log; |
| 680 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 681 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 682 | BoundNetLog(), NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 683 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 684 | helper.AddData(&data); |
rch | aeb3f05 | 2015-04-14 16:02:49 | [diff] [blame] | 685 | // We require placeholder data because three get requests are sent out at |
| 686 | // the same time which results in three sockets being connected. The first |
| 687 | // on will negotiate SPDY and will be used for all requests. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 688 | helper.AddData(&data_placeholder1); |
| 689 | helper.AddData(&data_placeholder2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 690 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session()); |
| 691 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
| 692 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, helper.session()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 693 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 694 | TestCompletionCallback callback1; |
| 695 | TestCompletionCallback callback2; |
| 696 | TestCompletionCallback callback3; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 697 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 698 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 699 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 700 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 701 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 702 | out.rv = trans1.Start(&httpreq1, callback1.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 703 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 704 | out.rv = trans2.Start(&httpreq2, callback2.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 705 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 706 | out.rv = trans3.Start(&httpreq3, callback3.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 707 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 708 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 709 | out.rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 710 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 711 | out.rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 712 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 713 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 714 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 715 | EXPECT_TRUE(response1->headers); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 716 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 717 | out.status_line = response1->headers->GetStatusLine(); |
| 718 | out.response_info = *response1; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 719 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 720 | trans2.GetResponseInfo(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 721 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 722 | out.rv = ReadTransaction(&trans1, &out.response_data); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 723 | helper.VerifyDataConsumed(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 724 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 725 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 726 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 727 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 728 | EXPECT_EQ("hello!hello!", out.response_data); |
| 729 | } |
| 730 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 731 | TEST_F(SpdyNetworkTransactionTest, TwoGetsLateBinding) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 732 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 733 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 734 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 735 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 736 | SpdySerializedFrame fbody(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 737 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 738 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 739 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 740 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 741 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, false)); |
| 742 | SpdySerializedFrame fbody2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 743 | |
| 744 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 745 | CreateMockWrite(req, 0), CreateMockWrite(req2, 3), |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 746 | }; |
| 747 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 748 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
| 749 | CreateMockRead(resp2, 4), CreateMockRead(body2, 5), |
| 750 | CreateMockRead(fbody, 6), CreateMockRead(fbody2, 7), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 751 | MockRead(ASYNC, 0, 8), // EOF |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 752 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 753 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 754 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 755 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 756 | SequencedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 757 | data_placeholder.set_connect_data(never_finishing_connect); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 758 | |
| 759 | BoundNetLog log; |
| 760 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 761 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 762 | BoundNetLog(), NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 763 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 764 | helper.AddData(&data); |
rch | aeb3f05 | 2015-04-14 16:02:49 | [diff] [blame] | 765 | // We require placeholder data because two requests are sent out at |
| 766 | // the same time which results in two sockets being connected. The first |
| 767 | // on will negotiate SPDY and will be used for all requests. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 768 | helper.AddData(&data_placeholder); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 769 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session()); |
| 770 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 771 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 772 | TestCompletionCallback callback1; |
| 773 | TestCompletionCallback callback2; |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 774 | |
| 775 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 776 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 777 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 778 | out.rv = trans1.Start(&httpreq1, callback1.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 779 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 780 | out.rv = trans2.Start(&httpreq2, callback2.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 781 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 782 | |
| 783 | out.rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 784 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 785 | out.rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 786 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 787 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 788 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 789 | EXPECT_TRUE(response1->headers); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 790 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 791 | out.status_line = response1->headers->GetStatusLine(); |
| 792 | out.response_info = *response1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 793 | out.rv = ReadTransaction(&trans1, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 794 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 795 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 796 | EXPECT_EQ("hello!hello!", out.response_data); |
| 797 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 798 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 799 | EXPECT_TRUE(response2->headers); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 800 | EXPECT_TRUE(response2->was_fetched_via_spdy); |
| 801 | out.status_line = response2->headers->GetStatusLine(); |
| 802 | out.response_info = *response2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 803 | out.rv = ReadTransaction(&trans2, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 804 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 805 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 806 | EXPECT_EQ("hello!hello!", out.response_data); |
| 807 | |
| 808 | helper.VerifyDataConsumed(); |
| 809 | } |
| 810 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 811 | TEST_F(SpdyNetworkTransactionTest, TwoGetsLateBindingFromPreconnect) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 812 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 813 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 814 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 815 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 816 | SpdySerializedFrame fbody(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 817 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 818 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 819 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 820 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 821 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, false)); |
| 822 | SpdySerializedFrame fbody2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 823 | |
| 824 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 825 | CreateMockWrite(req, 0), CreateMockWrite(req2, 3), |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 826 | }; |
| 827 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 828 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
| 829 | CreateMockRead(resp2, 4), CreateMockRead(body2, 5), |
| 830 | CreateMockRead(fbody, 6), CreateMockRead(fbody2, 7), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 831 | MockRead(ASYNC, 0, 8), // EOF |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 832 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 833 | SequencedSocketData preconnect_data(reads, arraysize(reads), writes, |
| 834 | arraysize(writes)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 835 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 836 | MockConnect never_finishing_connect(ASYNC, ERR_IO_PENDING); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 837 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 838 | SequencedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 839 | data_placeholder.set_connect_data(never_finishing_connect); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 840 | |
| 841 | BoundNetLog log; |
| 842 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 843 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 844 | BoundNetLog(), NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 845 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 846 | helper.AddData(&preconnect_data); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 847 | // We require placeholder data because 3 connections are attempted (first is |
| 848 | // the preconnect, 2nd and 3rd are the never finished connections. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 849 | helper.AddData(&data_placeholder); |
| 850 | helper.AddData(&data_placeholder); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 851 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 852 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session()); |
| 853 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 854 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 855 | TestCompletionCallback callback1; |
| 856 | TestCompletionCallback callback2; |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 857 | |
| 858 | HttpRequestInfo httpreq = CreateGetRequest(); |
| 859 | |
| 860 | // Preconnect the first. |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 861 | HttpStreamFactory* http_stream_factory = |
| 862 | helper.session()->http_stream_factory(); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 863 | |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 864 | http_stream_factory->PreconnectStreams(1, httpreq); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 865 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 866 | out.rv = trans1.Start(&httpreq, callback1.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 867 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 868 | out.rv = trans2.Start(&httpreq, callback2.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 869 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 870 | |
| 871 | out.rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 872 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 873 | out.rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 874 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 875 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 876 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 877 | EXPECT_TRUE(response1->headers); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 878 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 879 | out.status_line = response1->headers->GetStatusLine(); |
| 880 | out.response_info = *response1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 881 | out.rv = ReadTransaction(&trans1, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 882 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 883 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 884 | EXPECT_EQ("hello!hello!", out.response_data); |
| 885 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 886 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 887 | EXPECT_TRUE(response2->headers); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 888 | EXPECT_TRUE(response2->was_fetched_via_spdy); |
| 889 | out.status_line = response2->headers->GetStatusLine(); |
| 890 | out.response_info = *response2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 891 | out.rv = ReadTransaction(&trans2, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 892 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 893 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 894 | EXPECT_EQ("hello!hello!", out.response_data); |
| 895 | |
| 896 | helper.VerifyDataConsumed(); |
| 897 | } |
| 898 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 899 | // Similar to ThreeGets above, however this test adds a SETTINGS |
| 900 | // frame. The SETTINGS frame is read during the IO loop waiting on |
| 901 | // the first transaction completion, and sets a maximum concurrent |
| 902 | // stream limit of 1. This means that our IO loop exists after the |
| 903 | // second transaction completes, so we can assert on read_index(). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 904 | TEST_F(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrent) { |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 905 | // Construct the request. |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 906 | // Each request fully completes before the next starts. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 907 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 908 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 909 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 910 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 911 | SpdySerializedFrame fbody(spdy_util_.ConstructSpdyDataFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 912 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 913 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 914 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 915 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 916 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 917 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, false)); |
| 918 | SpdySerializedFrame fbody2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 919 | spdy_util_.UpdateWithStreamDestruction(3); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 920 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 921 | SpdySerializedFrame req3( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 922 | spdy_util_.ConstructSpdyGet(nullptr, 0, 5, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 923 | SpdySerializedFrame resp3(spdy_util_.ConstructSpdyGetReply(NULL, 0, 5)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 924 | SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame(5, false)); |
| 925 | SpdySerializedFrame fbody3(spdy_util_.ConstructSpdyDataFrame(5, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 926 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 927 | SettingsMap settings; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 928 | const uint32_t max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 929 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 930 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 931 | SpdySerializedFrame settings_frame( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 932 | spdy_util_.ConstructSpdySettings(settings)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 933 | SpdySerializedFrame settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 934 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 935 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 936 | CreateMockWrite(req, 0), CreateMockWrite(settings_ack, 5), |
| 937 | CreateMockWrite(req2, 6), CreateMockWrite(req3, 10), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 938 | }; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 939 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 940 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 941 | CreateMockRead(settings_frame, 1), |
| 942 | CreateMockRead(resp, 2), |
| 943 | CreateMockRead(body, 3), |
| 944 | CreateMockRead(fbody, 4), |
| 945 | CreateMockRead(resp2, 7), |
| 946 | CreateMockRead(body2, 8), |
| 947 | CreateMockRead(fbody2, 9), |
| 948 | CreateMockRead(resp3, 11), |
| 949 | CreateMockRead(body3, 12), |
| 950 | CreateMockRead(fbody3, 13), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 951 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 952 | MockRead(ASYNC, 0, 14), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 953 | }; |
| 954 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 955 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 956 | |
| 957 | BoundNetLog log; |
| 958 | TransactionHelperResult out; |
| 959 | { |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 960 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 961 | BoundNetLog(), NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 962 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 963 | helper.AddData(&data); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 964 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session()); |
| 965 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
| 966 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, helper.session()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 967 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 968 | TestCompletionCallback callback1; |
| 969 | TestCompletionCallback callback2; |
| 970 | TestCompletionCallback callback3; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 971 | |
| 972 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 973 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 974 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
| 975 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 976 | out.rv = trans1.Start(&httpreq1, callback1.callback(), log); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 977 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 978 | // Run transaction 1 through quickly to force a read of our SETTINGS |
| 979 | // frame. |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 980 | out.rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 981 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 982 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 983 | out.rv = trans2.Start(&httpreq2, callback2.callback(), log); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 984 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 985 | out.rv = trans3.Start(&httpreq3, callback3.callback(), log); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 986 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
| 987 | out.rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 988 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 989 | |
| 990 | out.rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 991 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 992 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 993 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 994 | ASSERT_TRUE(response1); |
| 995 | EXPECT_TRUE(response1->headers); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 996 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 997 | out.status_line = response1->headers->GetStatusLine(); |
| 998 | out.response_info = *response1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 999 | out.rv = ReadTransaction(&trans1, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1000 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1001 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1002 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1003 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1004 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1005 | out.status_line = response2->headers->GetStatusLine(); |
| 1006 | out.response_info = *response2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1007 | out.rv = ReadTransaction(&trans2, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1008 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1009 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1010 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1011 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1012 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1013 | out.status_line = response3->headers->GetStatusLine(); |
| 1014 | out.response_info = *response3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1015 | out.rv = ReadTransaction(&trans3, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1016 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1017 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1018 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1019 | |
| 1020 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1021 | } |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1022 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | // Similar to ThreeGetsWithMaxConcurrent above, however this test adds |
| 1026 | // a fourth transaction. The third and fourth transactions have |
| 1027 | // different data ("hello!" vs "hello!hello!") and because of the |
| 1028 | // user specified priority, we expect to see them inverted in |
| 1029 | // the response from the server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1030 | TEST_F(SpdyNetworkTransactionTest, FourGetsWithMaxConcurrentPriority) { |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1031 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1032 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1033 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1034 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1035 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 1036 | SpdySerializedFrame fbody(spdy_util_.ConstructSpdyDataFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1037 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1038 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1039 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1040 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1041 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1042 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, false)); |
| 1043 | SpdySerializedFrame fbody2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1044 | spdy_util_.UpdateWithStreamDestruction(3); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1045 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1046 | SpdySerializedFrame req4( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1047 | spdy_util_.ConstructSpdyGet(nullptr, 0, 5, HIGHEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1048 | SpdySerializedFrame resp4(spdy_util_.ConstructSpdyGetReply(NULL, 0, 5)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1049 | SpdySerializedFrame fbody4(spdy_util_.ConstructSpdyDataFrame(5, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1050 | spdy_util_.UpdateWithStreamDestruction(5); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1051 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1052 | SpdySerializedFrame req3( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1053 | spdy_util_.ConstructSpdyGet(nullptr, 0, 7, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1054 | SpdySerializedFrame resp3(spdy_util_.ConstructSpdyGetReply(NULL, 0, 7)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1055 | SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame(7, false)); |
| 1056 | SpdySerializedFrame fbody3(spdy_util_.ConstructSpdyDataFrame(7, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1057 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1058 | SettingsMap settings; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 1059 | const uint32_t max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1060 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1061 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1062 | SpdySerializedFrame settings_frame( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1063 | spdy_util_.ConstructSpdySettings(settings)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1064 | SpdySerializedFrame settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1065 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1066 | CreateMockWrite(req, 0), CreateMockWrite(settings_ack, 5), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1067 | // By making these synchronous, it guarantees that they are not *started* |
| 1068 | // before their sequence number, which in turn verifies that only a single |
| 1069 | // request is in-flight at a time. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1070 | CreateMockWrite(req2, 6, SYNCHRONOUS), |
| 1071 | CreateMockWrite(req4, 10, SYNCHRONOUS), |
| 1072 | CreateMockWrite(req3, 13, SYNCHRONOUS), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1073 | }; |
| 1074 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1075 | CreateMockRead(settings_frame, 1), |
| 1076 | CreateMockRead(resp, 2), |
| 1077 | CreateMockRead(body, 3), |
| 1078 | CreateMockRead(fbody, 4), |
| 1079 | CreateMockRead(resp2, 7), |
| 1080 | CreateMockRead(body2, 8), |
| 1081 | CreateMockRead(fbody2, 9), |
| 1082 | CreateMockRead(resp4, 11), |
| 1083 | CreateMockRead(fbody4, 12), |
| 1084 | CreateMockRead(resp3, 14), |
| 1085 | CreateMockRead(body3, 15), |
| 1086 | CreateMockRead(fbody3, 16), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1087 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1088 | MockRead(ASYNC, 0, 17), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1089 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1090 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1091 | BoundNetLog log; |
| 1092 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1093 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1094 | BoundNetLog(), NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1095 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1096 | helper.AddData(&data); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1097 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1098 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session()); |
| 1099 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
| 1100 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, helper.session()); |
| 1101 | HttpNetworkTransaction trans4(HIGHEST, helper.session()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1102 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1103 | TestCompletionCallback callback1; |
| 1104 | TestCompletionCallback callback2; |
| 1105 | TestCompletionCallback callback3; |
| 1106 | TestCompletionCallback callback4; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1107 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1108 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1109 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1110 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
| 1111 | HttpRequestInfo httpreq4 = CreateGetRequest(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1112 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1113 | out.rv = trans1.Start(&httpreq1, callback1.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1114 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1115 | // Run transaction 1 through quickly to force a read of our SETTINGS frame. |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1116 | out.rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1117 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1118 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1119 | out.rv = trans2.Start(&httpreq2, callback2.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1120 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1121 | out.rv = trans3.Start(&httpreq3, callback3.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1122 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1123 | out.rv = trans4.Start(&httpreq4, callback4.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1124 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1125 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1126 | out.rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1127 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1128 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1129 | out.rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1130 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1131 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1132 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1133 | EXPECT_TRUE(response1->headers); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1134 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1135 | out.status_line = response1->headers->GetStatusLine(); |
| 1136 | out.response_info = *response1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1137 | out.rv = ReadTransaction(&trans1, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1138 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1139 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1140 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1141 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1142 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1143 | out.status_line = response2->headers->GetStatusLine(); |
| 1144 | out.response_info = *response2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1145 | out.rv = ReadTransaction(&trans2, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1146 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1147 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1148 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1149 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1150 | // notice: response3 gets two hellos, response4 gets one |
| 1151 | // hello, so we know dequeuing priority was respected. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1152 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1153 | out.status_line = response3->headers->GetStatusLine(); |
| 1154 | out.response_info = *response3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1155 | out.rv = ReadTransaction(&trans3, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1156 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1157 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1158 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1159 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1160 | out.rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1161 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1162 | const HttpResponseInfo* response4 = trans4.GetResponseInfo(); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1163 | out.status_line = response4->headers->GetStatusLine(); |
| 1164 | out.response_info = *response4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1165 | out.rv = ReadTransaction(&trans4, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1166 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1167 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1168 | EXPECT_EQ("hello!", out.response_data); |
| 1169 | helper.VerifyDataConsumed(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1170 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | // Similar to ThreeGetsMaxConcurrrent above, however, this test |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1174 | // deletes a session in the middle of the transaction to ensure |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1175 | // that we properly remove pendingcreatestream objects from |
| 1176 | // the spdy_session |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1177 | TEST_F(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentDelete) { |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1178 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1179 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1180 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1181 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1182 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 1183 | SpdySerializedFrame fbody(spdy_util_.ConstructSpdyDataFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1184 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1185 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1186 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1187 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1188 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1189 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, false)); |
| 1190 | SpdySerializedFrame fbody2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1191 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1192 | SettingsMap settings; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 1193 | const uint32_t max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1194 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1195 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1196 | SpdySerializedFrame settings_frame( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1197 | spdy_util_.ConstructSpdySettings(settings)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1198 | SpdySerializedFrame settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1199 | |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1200 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1201 | CreateMockWrite(req, 0), CreateMockWrite(settings_ack, 5), |
| 1202 | CreateMockWrite(req2, 6), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1203 | }; |
| 1204 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1205 | CreateMockRead(settings_frame, 1), CreateMockRead(resp, 2), |
| 1206 | CreateMockRead(body, 3), CreateMockRead(fbody, 4), |
| 1207 | CreateMockRead(resp2, 7), CreateMockRead(body2, 8), |
| 1208 | CreateMockRead(fbody2, 9), MockRead(ASYNC, 0, 10), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1209 | }; |
| 1210 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1211 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1212 | |
| 1213 | BoundNetLog log; |
| 1214 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1215 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1216 | BoundNetLog(), NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1217 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1218 | helper.AddData(&data); |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 1219 | std::unique_ptr<HttpNetworkTransaction> trans1( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1220 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 1221 | std::unique_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1222 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 1223 | std::unique_ptr<HttpNetworkTransaction> trans3( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1224 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1225 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1226 | TestCompletionCallback callback1; |
| 1227 | TestCompletionCallback callback2; |
| 1228 | TestCompletionCallback callback3; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1229 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1230 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1231 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1232 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1233 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1234 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1235 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1236 | // Run transaction 1 through quickly to force a read of our SETTINGS frame. |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1237 | out.rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1238 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1239 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1240 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1241 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1242 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
olli.raula | 7ca9cd1d | 2016-01-04 06:50:37 | [diff] [blame] | 1243 | trans3.reset(); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1244 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
| 1245 | out.rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1246 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1247 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1248 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1249 | ASSERT_TRUE(response1); |
| 1250 | EXPECT_TRUE(response1->headers); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1251 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1252 | out.status_line = response1->headers->GetStatusLine(); |
| 1253 | out.response_info = *response1; |
| 1254 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1255 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1256 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1257 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1258 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1259 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1260 | ASSERT_TRUE(response2); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1261 | out.status_line = response2->headers->GetStatusLine(); |
| 1262 | out.response_info = *response2; |
| 1263 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1264 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1265 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1266 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1267 | helper.VerifyDataConsumed(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1268 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1269 | } |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1270 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1271 | namespace { |
| 1272 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1273 | // The KillerCallback will delete the transaction on error as part of the |
| 1274 | // callback. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1275 | class KillerCallback : public TestCompletionCallbackBase { |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1276 | public: |
| 1277 | explicit KillerCallback(HttpNetworkTransaction* transaction) |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1278 | : transaction_(transaction), |
[email protected] | aa249b5 | 2013-04-30 01:04:32 | [diff] [blame] | 1279 | callback_(base::Bind(&KillerCallback::OnComplete, |
| 1280 | base::Unretained(this))) { |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1281 | } |
| 1282 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 1283 | ~KillerCallback() override {} |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1284 | |
| 1285 | const CompletionCallback& callback() const { return callback_; } |
| 1286 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1287 | private: |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1288 | void OnComplete(int result) { |
| 1289 | if (result < 0) |
| 1290 | delete transaction_; |
| 1291 | |
| 1292 | SetResult(result); |
| 1293 | } |
| 1294 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1295 | HttpNetworkTransaction* transaction_; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1296 | CompletionCallback callback_; |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1297 | }; |
| 1298 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1299 | } // namespace |
| 1300 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1301 | // Similar to ThreeGetsMaxConcurrrentDelete above, however, this test |
| 1302 | // closes the socket while we have a pending transaction waiting for |
| 1303 | // a pending stream creation. http://crbug.com/52901 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1304 | TEST_F(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentSocketClose) { |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1305 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1306 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1307 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1308 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1309 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 1310 | SpdySerializedFrame fin_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1311 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1312 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1313 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1314 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1315 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1316 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1317 | SettingsMap settings; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 1318 | const uint32_t max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1319 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1320 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1321 | SpdySerializedFrame settings_frame( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1322 | spdy_util_.ConstructSpdySettings(settings)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1323 | SpdySerializedFrame settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1324 | |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1325 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1326 | CreateMockWrite(req, 0), CreateMockWrite(settings_ack, 5), |
| 1327 | CreateMockWrite(req2, 6), |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1328 | }; |
| 1329 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1330 | CreateMockRead(settings_frame, 1), |
| 1331 | CreateMockRead(resp, 2), |
| 1332 | CreateMockRead(body, 3), |
| 1333 | CreateMockRead(fin_body, 4), |
| 1334 | CreateMockRead(resp2, 7), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1335 | MockRead(ASYNC, ERR_CONNECTION_RESET, 8), // Abort! |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1336 | }; |
| 1337 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1338 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 1339 | SequencedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1340 | |
| 1341 | BoundNetLog log; |
| 1342 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1343 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1344 | BoundNetLog(), NULL); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1345 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1346 | helper.AddData(&data); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1347 | // We require placeholder data because three get requests are sent out, so |
| 1348 | // there needs to be three sets of SSL connection data. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1349 | helper.AddData(&data_placeholder); |
| 1350 | helper.AddData(&data_placeholder); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1351 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session()); |
| 1352 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1353 | HttpNetworkTransaction* trans3( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1354 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1355 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1356 | TestCompletionCallback callback1; |
| 1357 | TestCompletionCallback callback2; |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1358 | KillerCallback callback3(trans3); |
| 1359 | |
| 1360 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1361 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1362 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
| 1363 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1364 | out.rv = trans1.Start(&httpreq1, callback1.callback(), log); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1365 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1366 | // Run transaction 1 through quickly to force a read of our SETTINGS frame. |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1367 | out.rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1368 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1369 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1370 | out.rv = trans2.Start(&httpreq2, callback2.callback(), log); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1371 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1372 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1373 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
| 1374 | out.rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1375 | ASSERT_THAT(out.rv, IsError(ERR_ABORTED)); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1376 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1377 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1378 | ASSERT_TRUE(response1); |
| 1379 | EXPECT_TRUE(response1->headers); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1380 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1381 | out.status_line = response1->headers->GetStatusLine(); |
| 1382 | out.response_info = *response1; |
| 1383 | out.rv = ReadTransaction(&trans1, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1384 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1385 | |
| 1386 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1387 | ASSERT_TRUE(response2); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1388 | out.status_line = response2->headers->GetStatusLine(); |
| 1389 | out.response_info = *response2; |
| 1390 | out.rv = ReadTransaction(&trans2, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1391 | EXPECT_THAT(out.rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1392 | |
| 1393 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1394 | } |
| 1395 | |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1396 | // Test that a simple PUT request works. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1397 | TEST_F(SpdyNetworkTransactionTest, Put) { |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1398 | // Setup the request |
| 1399 | HttpRequestInfo request; |
| 1400 | request.method = "PUT"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1401 | request.url = default_url_; |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1402 | |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 1403 | SpdyHeaderBlock put_headers( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1404 | spdy_util_.ConstructPutHeaderBlock(kDefaultUrl, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1405 | SpdySerializedFrame req( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1406 | spdy_util_.ConstructSpdyHeaders(1, std::move(put_headers), LOWEST, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1407 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1408 | CreateMockWrite(req, 0), |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1409 | }; |
| 1410 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1411 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1412 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1413 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1414 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1415 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1416 | }; |
| 1417 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1418 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1419 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 1420 | NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1421 | helper.RunToCompletion(&data); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1422 | TransactionHelperResult out = helper.output(); |
| 1423 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1424 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1425 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | // Test that a simple HEAD request works. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1429 | TEST_F(SpdyNetworkTransactionTest, Head) { |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1430 | // Setup the request |
| 1431 | HttpRequestInfo request; |
| 1432 | request.method = "HEAD"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1433 | request.url = default_url_; |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1434 | |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 1435 | SpdyHeaderBlock head_headers( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1436 | spdy_util_.ConstructHeadHeaderBlock(kDefaultUrl, 0)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1437 | SpdySerializedFrame req(spdy_util_.ConstructSpdyHeaders( |
| 1438 | 1, std::move(head_headers), LOWEST, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1439 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1440 | CreateMockWrite(req, 0), |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1441 | }; |
| 1442 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1443 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1444 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1445 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1446 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1447 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1448 | }; |
| 1449 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1450 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1451 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 1452 | NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1453 | helper.RunToCompletion(&data); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1454 | TransactionHelperResult out = helper.output(); |
| 1455 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1456 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1457 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1458 | } |
| 1459 | |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 1460 | // Test that a simple POST works. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1461 | TEST_F(SpdyNetworkTransactionTest, Post) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1462 | SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1463 | kDefaultUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1464 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1465 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1466 | CreateMockWrite(req, 0), CreateMockWrite(body, 1), // POST upload frame |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1467 | }; |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 1468 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1469 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1470 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1471 | CreateMockRead(resp, 2), CreateMockRead(body, 3), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1472 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 1473 | }; |
| 1474 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1475 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1476 | NormalSpdyTransactionHelper helper(CreatePostRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1477 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1478 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1479 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1480 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1481 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 1482 | EXPECT_EQ("hello!", out.response_data); |
| 1483 | } |
| 1484 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1485 | // Test that a POST with a file works. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1486 | TEST_F(SpdyNetworkTransactionTest, FilePost) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1487 | SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1488 | kDefaultUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1489 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1490 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1491 | CreateMockWrite(req, 0), CreateMockWrite(body, 1), // POST upload frame |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1492 | }; |
| 1493 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1494 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1495 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1496 | CreateMockRead(resp, 2), CreateMockRead(body, 3), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1497 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1498 | }; |
| 1499 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1500 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1501 | NormalSpdyTransactionHelper helper(CreateFilePostRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1502 | BoundNetLog(), NULL); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1503 | helper.RunToCompletion(&data); |
| 1504 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1505 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1506 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1507 | EXPECT_EQ("hello!", out.response_data); |
| 1508 | } |
| 1509 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1510 | // Test that a POST with a unreadable file fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1511 | TEST_F(SpdyNetworkTransactionTest, UnreadableFilePost) { |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1512 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1513 | MockWrite(ASYNC, 0, 0) // EOF |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1514 | }; |
| 1515 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1516 | MockRead(ASYNC, 0, 1) // EOF |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1517 | }; |
| 1518 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1519 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1520 | NormalSpdyTransactionHelper helper(CreateUnreadableFilePostRequest(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1521 | DEFAULT_PRIORITY, BoundNetLog(), NULL); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1522 | helper.RunPreTestSetup(); |
| 1523 | helper.AddData(&data); |
| 1524 | helper.RunDefaultTest(); |
| 1525 | |
| 1526 | base::RunLoop().RunUntilIdle(); |
| 1527 | helper.VerifyDataNotConsumed(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1528 | EXPECT_THAT(helper.output().rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1529 | } |
| 1530 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1531 | // Test that a complex POST works. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1532 | TEST_F(SpdyNetworkTransactionTest, ComplexPost) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1533 | SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1534 | kDefaultUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1535 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1536 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1537 | CreateMockWrite(req, 0), CreateMockWrite(body, 1), // POST upload frame |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1538 | }; |
| 1539 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1540 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1541 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1542 | CreateMockRead(resp, 2), CreateMockRead(body, 3), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1543 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1544 | }; |
| 1545 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1546 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1547 | NormalSpdyTransactionHelper helper(CreateComplexPostRequest(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1548 | DEFAULT_PRIORITY, BoundNetLog(), NULL); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1549 | helper.RunToCompletion(&data); |
| 1550 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1551 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1552 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1553 | EXPECT_EQ("hello!", out.response_data); |
| 1554 | } |
| 1555 | |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1556 | // Test that a chunked POST works. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1557 | TEST_F(SpdyNetworkTransactionTest, ChunkedPost) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1558 | SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1559 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1560 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1561 | CreateMockWrite(req, 0), CreateMockWrite(body, 1), |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1562 | }; |
| 1563 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1564 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1565 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1566 | CreateMockRead(resp, 2), CreateMockRead(body, 3), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1567 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1568 | }; |
| 1569 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1570 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1571 | NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1572 | DEFAULT_PRIORITY, BoundNetLog(), NULL); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1573 | |
| 1574 | // These chunks get merged into a single frame when being sent. |
| 1575 | const int kFirstChunkSize = kUploadDataSize/2; |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1576 | upload_chunked_data_stream()->AppendData(kUploadData, kFirstChunkSize, false); |
| 1577 | upload_chunked_data_stream()->AppendData( |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1578 | kUploadData + kFirstChunkSize, kUploadDataSize - kFirstChunkSize, true); |
| 1579 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1580 | helper.RunToCompletion(&data); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1581 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1582 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1583 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1584 | EXPECT_EQ(kUploadData, out.response_data); |
| 1585 | } |
| 1586 | |
| 1587 | // Test that a chunked POST works with chunks appended after transaction starts. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1588 | TEST_F(SpdyNetworkTransactionTest, DelayedChunkedPost) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1589 | SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1590 | SpdySerializedFrame chunk1(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 1591 | SpdySerializedFrame chunk2(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 1592 | SpdySerializedFrame chunk3(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1593 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1594 | CreateMockWrite(req, 0), CreateMockWrite(chunk1, 1), |
| 1595 | CreateMockWrite(chunk2, 2), CreateMockWrite(chunk3, 3), |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1596 | }; |
| 1597 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1598 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1599 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1600 | CreateMockRead(resp, 4), CreateMockRead(chunk1, 5), |
| 1601 | CreateMockRead(chunk2, 6), CreateMockRead(chunk3, 7), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1602 | MockRead(ASYNC, 0, 8) // EOF |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1603 | }; |
| 1604 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1605 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1606 | NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1607 | DEFAULT_PRIORITY, BoundNetLog(), NULL); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1608 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1609 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, false); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1610 | |
| 1611 | helper.RunPreTestSetup(); |
| 1612 | helper.AddData(&data); |
| 1613 | ASSERT_TRUE(helper.StartDefaultTest()); |
| 1614 | |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 1615 | base::RunLoop().RunUntilIdle(); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1616 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, false); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 1617 | base::RunLoop().RunUntilIdle(); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1618 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, true); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1619 | |
| 1620 | helper.FinishDefaultTest(); |
| 1621 | helper.VerifyDataConsumed(); |
| 1622 | |
| 1623 | std::string expected_response; |
| 1624 | expected_response += kUploadData; |
| 1625 | expected_response += kUploadData; |
| 1626 | expected_response += kUploadData; |
| 1627 | |
| 1628 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1629 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1630 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1631 | EXPECT_EQ(expected_response, out.response_data); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1632 | } |
| 1633 | |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1634 | // Test that a POST without any post data works. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1635 | TEST_F(SpdyNetworkTransactionTest, NullPost) { |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1636 | // Setup the request |
| 1637 | HttpRequestInfo request; |
| 1638 | request.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1639 | request.url = default_url_; |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1640 | // Create an empty UploadData. |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1641 | request.upload_data_stream = NULL; |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1642 | |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1643 | // When request.upload_data_stream is NULL for post, content-length is |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1644 | // expected to be 0. |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 1645 | SpdyHeaderBlock req_block( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1646 | spdy_util_.ConstructPostHeaderBlock(kDefaultUrl, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1647 | SpdySerializedFrame req( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1648 | spdy_util_.ConstructSpdyHeaders(1, std::move(req_block), LOWEST, true)); |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1649 | |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1650 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1651 | CreateMockWrite(req, 0), |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1652 | }; |
| 1653 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1654 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1655 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1656 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1657 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1658 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1659 | }; |
| 1660 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1661 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1662 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1663 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 1664 | NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1665 | helper.RunToCompletion(&data); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1666 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1667 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1668 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1669 | EXPECT_EQ("hello!", out.response_data); |
| 1670 | } |
| 1671 | |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1672 | // Test that a simple POST works. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1673 | TEST_F(SpdyNetworkTransactionTest, EmptyPost) { |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1674 | // Create an empty UploadDataStream. |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 1675 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1676 | ElementsUploadDataStream stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1677 | |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1678 | // Setup the request |
| 1679 | HttpRequestInfo request; |
| 1680 | request.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1681 | request.url = default_url_; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1682 | request.upload_data_stream = &stream; |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1683 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 1684 | const uint64_t kContentLength = 0; |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1685 | |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 1686 | SpdyHeaderBlock req_block( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1687 | spdy_util_.ConstructPostHeaderBlock(kDefaultUrl, kContentLength)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1688 | SpdySerializedFrame req( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1689 | spdy_util_.ConstructSpdyHeaders(1, std::move(req_block), LOWEST, true)); |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1690 | |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1691 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1692 | CreateMockWrite(req, 0), |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1693 | }; |
| 1694 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1695 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1696 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1697 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1698 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1699 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1700 | }; |
| 1701 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1702 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 1703 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1704 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 1705 | NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1706 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1707 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1708 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1709 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1710 | EXPECT_EQ("hello!", out.response_data); |
| 1711 | } |
| 1712 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1713 | // While we're doing a post, the server sends the reply before upload completes. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1714 | TEST_F(SpdyNetworkTransactionTest, ResponseBeforePostCompletes) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1715 | SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1716 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1717 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1718 | CreateMockWrite(req, 0), CreateMockWrite(body, 3), |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1719 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1720 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
[email protected] | a5566f970 | 2010-05-05 22:25:43 | [diff] [blame] | 1721 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1722 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
| 1723 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | a5566f970 | 2010-05-05 22:25:43 | [diff] [blame] | 1724 | }; |
| 1725 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1726 | // Write the request headers, and read the complete response |
| 1727 | // while still waiting for chunked request data. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1728 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1729 | NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1730 | DEFAULT_PRIORITY, BoundNetLog(), NULL); |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 1731 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1732 | helper.AddData(&data); |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 1733 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1734 | ASSERT_TRUE(helper.StartDefaultTest()); |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 1735 | |
maksim.sisov | 8d2df66d | 2016-06-20 07:07:11 | [diff] [blame] | 1736 | base::RunLoop().RunUntilIdle(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1737 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1738 | // Process the request headers, response headers, and response body. |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1739 | // The request body is still in flight. |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1740 | const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1741 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1742 | |
| 1743 | // Finish sending the request body. |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1744 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, true); |
maksim.sisov | 8d2df66d | 2016-06-20 07:07:11 | [diff] [blame] | 1745 | helper.WaitForCallbackToComplete(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1746 | EXPECT_THAT(helper.output().rv, IsOk()); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1747 | |
| 1748 | std::string response_body; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1749 | EXPECT_THAT(ReadTransaction(helper.trans(), &response_body), IsOk()); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1750 | EXPECT_EQ(kUploadData, response_body); |
| 1751 | helper.VerifyDataConsumed(); |
[email protected] | a5566f970 | 2010-05-05 22:25:43 | [diff] [blame] | 1752 | } |
| 1753 | |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 1754 | // The client upon cancellation tries to send a RST_STREAM frame. The mock |
| 1755 | // socket causes the TCP write to return zero. This test checks that the client |
| 1756 | // tries to queue up the RST_STREAM frame again. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1757 | TEST_F(SpdyNetworkTransactionTest, SocketWriteReturnsZero) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1758 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1759 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1760 | SpdySerializedFrame rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1761 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 1762 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1763 | CreateMockWrite(req, 0, SYNCHRONOUS), MockWrite(SYNCHRONOUS, 0, 0, 2), |
| 1764 | CreateMockWrite(rst, 3, SYNCHRONOUS), |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 1765 | }; |
| 1766 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1767 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 1768 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1769 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 0, 4) // EOF |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 1770 | }; |
| 1771 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1772 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1773 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1774 | BoundNetLog(), NULL); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 1775 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1776 | helper.AddData(&data); |
bnc | 4d782f49 | 2016-08-18 13:50:00 | [diff] [blame] | 1777 | helper.StartDefaultTest(); |
| 1778 | EXPECT_THAT(helper.output().rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 1779 | |
bnc | 4d782f49 | 2016-08-18 13:50:00 | [diff] [blame] | 1780 | helper.WaitForCallbackToComplete(); |
| 1781 | EXPECT_THAT(helper.output().rv, IsOk()); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 1782 | |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 1783 | helper.ResetTrans(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1784 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 1785 | |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 1786 | helper.VerifyDataConsumed(); |
| 1787 | } |
| 1788 | |
[email protected] | 9330067 | 2009-10-24 13:22:51 | [diff] [blame] | 1789 | // Test that the transaction doesn't crash when we don't have a reply. |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1790 | TEST_F(SpdyNetworkTransactionTest, ResponseWithoutHeaders) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1791 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1792 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1793 | CreateMockRead(body, 1), MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 9330067 | 2009-10-24 13:22:51 | [diff] [blame] | 1794 | }; |
| 1795 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1796 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1797 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1798 | SpdySerializedFrame rst( |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1799 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 1800 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1801 | CreateMockWrite(req, 0), CreateMockWrite(rst, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1802 | }; |
| 1803 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1804 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1805 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1806 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1807 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1808 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
[email protected] | 9330067 | 2009-10-24 13:22:51 | [diff] [blame] | 1809 | } |
| 1810 | |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1811 | // Test that the transaction doesn't crash when we get two replies on the same |
| 1812 | // stream ID. See http://crbug.com/45639. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1813 | TEST_F(SpdyNetworkTransactionTest, ResponseWithTwoSynReplies) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1814 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1815 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1816 | SpdySerializedFrame rst( |
[email protected] | 00b2947 | 2014-01-16 18:10:24 | [diff] [blame] | 1817 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 1818 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1819 | CreateMockWrite(req, 0), CreateMockWrite(rst, 4), |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 1820 | }; |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1821 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1822 | SpdySerializedFrame resp0(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1823 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1824 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1825 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1826 | CreateMockRead(resp0, 1), CreateMockRead(resp1, 2), |
| 1827 | CreateMockRead(body, 3), MockRead(ASYNC, 0, 5) // EOF |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1828 | }; |
| 1829 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1830 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1831 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1832 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1833 | BoundNetLog(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1834 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1835 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1836 | |
| 1837 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1838 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1839 | TestCompletionCallback callback; |
| 1840 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1841 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1842 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1843 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1844 | |
| 1845 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1846 | ASSERT_TRUE(response); |
| 1847 | EXPECT_TRUE(response->headers); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1848 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 1849 | std::string response_data; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1850 | rv = ReadTransaction(trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1851 | EXPECT_THAT(rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1852 | |
| 1853 | helper.VerifyDataConsumed(); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1854 | } |
| 1855 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1856 | TEST_F(SpdyNetworkTransactionTest, ResetReplyWithTransferEncoding) { |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1857 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1858 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1859 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1860 | SpdySerializedFrame rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1861 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1862 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1863 | CreateMockWrite(req, 0), CreateMockWrite(rst, 2), |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1864 | }; |
| 1865 | |
| 1866 | const char* const headers[] = { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1867 | "transfer-encoding", "chunked" |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1868 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1869 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(headers, 1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1870 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1871 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1872 | CreateMockRead(resp, 1), CreateMockRead(body, 3), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1873 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1874 | }; |
| 1875 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1876 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1877 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1878 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1879 | helper.RunToCompletion(&data); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1880 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1881 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1882 | |
| 1883 | helper.session()->spdy_session_pool()->CloseAllSessions(); |
| 1884 | helper.VerifyDataConsumed(); |
| 1885 | } |
| 1886 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1887 | TEST_F(SpdyNetworkTransactionTest, ResetPushWithTransferEncoding) { |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1888 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1889 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1890 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1891 | SpdySerializedFrame rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1892 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1893 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1894 | CreateMockWrite(req, 0), CreateMockWrite(rst, 4), |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1895 | }; |
| 1896 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1897 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1898 | const char* const headers[] = { |
| 1899 | "transfer-encoding", "chunked" |
| 1900 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1901 | SpdySerializedFrame push( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1902 | spdy_util_.ConstructSpdyPush(headers, arraysize(headers) / 2, 2, 1, |
| 1903 | GetDefaultUrlWithPath("/1").c_str())); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1904 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1905 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1906 | CreateMockRead(resp, 1), CreateMockRead(push, 2), CreateMockRead(body, 3), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1907 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1908 | }; |
| 1909 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1910 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1911 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1912 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1913 | helper.RunToCompletion(&data); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1914 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1915 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1916 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1917 | EXPECT_EQ("hello!", out.response_data); |
| 1918 | |
| 1919 | helper.session()->spdy_session_pool()->CloseAllSessions(); |
| 1920 | helper.VerifyDataConsumed(); |
| 1921 | } |
| 1922 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1923 | TEST_F(SpdyNetworkTransactionTest, CancelledTransaction) { |
[email protected] | 75f30cc2 | 2010-06-28 21:41:38 | [diff] [blame] | 1924 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1925 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1926 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 1927 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1928 | CreateMockWrite(req), |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 1929 | }; |
| 1930 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1931 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 1932 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1933 | CreateMockRead(resp), |
| 1934 | // This following read isn't used by the test, except during the |
| 1935 | // RunUntilIdle() call at the end since the SpdySession survives the |
| 1936 | // HttpNetworkTransaction and still tries to continue Read()'ing. Any |
| 1937 | // MockRead will do here. |
| 1938 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 1939 | }; |
| 1940 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1941 | StaticSocketDataProvider data(reads, arraysize(reads), |
| 1942 | writes, arraysize(writes)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1943 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1944 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1945 | BoundNetLog(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1946 | helper.RunPreTestSetup(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 1947 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1948 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 1949 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1950 | TestCompletionCallback callback; |
| 1951 | int rv = trans->Start( |
| 1952 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1953 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1954 | helper.ResetTrans(); // Cancel the transaction. |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 1955 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 1956 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 1957 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 1958 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1959 | helper.VerifyDataNotConsumed(); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 1960 | } |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 1961 | |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1962 | // Verify that the client sends a Rst Frame upon cancelling the stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1963 | TEST_F(SpdyNetworkTransactionTest, CancelledTransactionSendRst) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1964 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1965 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1966 | SpdySerializedFrame rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1967 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1968 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1969 | CreateMockWrite(req, 0, SYNCHRONOUS), |
| 1970 | CreateMockWrite(rst, 2, SYNCHRONOUS), |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1971 | }; |
| 1972 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1973 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1974 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1975 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 0, 3) // EOF |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1976 | }; |
| 1977 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1978 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1979 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1980 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1981 | BoundNetLog(), NULL); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1982 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1983 | helper.AddData(&data); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1984 | HttpNetworkTransaction* trans = helper.trans(); |
| 1985 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1986 | TestCompletionCallback callback; |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1987 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1988 | int rv = trans->Start( |
| 1989 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1990 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1991 | |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 1992 | helper.ResetTrans(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1993 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 1994 | |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1995 | helper.VerifyDataConsumed(); |
| 1996 | } |
| 1997 | |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 1998 | // Verify that the client can correctly deal with the user callback attempting |
| 1999 | // to start another transaction on a session that is closing down. See |
| 2000 | // http://crbug.com/47455 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2001 | TEST_F(SpdyNetworkTransactionTest, StartTransactionOnReadCallback) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2002 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2003 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2004 | MockWrite writes[] = {CreateMockWrite(req)}; |
| 2005 | MockWrite writes2[] = {CreateMockWrite(req, 0)}; |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2006 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 2007 | // The indicated length of this frame is longer than its actual length. When |
| 2008 | // the session receives an empty frame after this one, it shuts down the |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2009 | // session, and calls the read callback with the incomplete data. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 2010 | const uint8_t kGetBodyFrame2[] = { |
| 2011 | 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, |
| 2012 | 0x07, 'h', 'e', 'l', 'l', 'o', '!', |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2013 | }; |
| 2014 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2015 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2016 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2017 | CreateMockRead(resp, 1), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 2018 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause |
| 2019 | MockRead(ASYNC, reinterpret_cast<const char*>(kGetBodyFrame2), |
| 2020 | arraysize(kGetBodyFrame2), 3), |
| 2021 | MockRead(ASYNC, ERR_IO_PENDING, 4), // Force a pause |
| 2022 | MockRead(ASYNC, 0, 0, 5), // EOF |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2023 | }; |
| 2024 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2025 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 0, 2), // EOF |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2026 | }; |
| 2027 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 2028 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2029 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 2030 | arraysize(writes2)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2031 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2032 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2033 | BoundNetLog(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2034 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2035 | helper.AddData(&data); |
| 2036 | helper.AddData(&data2); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2037 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2038 | |
| 2039 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2040 | TestCompletionCallback callback; |
| 2041 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2042 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2043 | rv = callback.WaitForResult(); |
| 2044 | |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2045 | const int kSize = 3000; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 2046 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSize)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2047 | rv = trans->Read( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2048 | buf.get(), kSize, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2049 | base::Bind(&SpdyNetworkTransactionTest::StartTransactionCallback, |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 2050 | helper.session(), default_url_)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2051 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2052 | // This forces an err_IO_pending, which sets the callback. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 2053 | data.Resume(); |
| 2054 | data.RunUntilPaused(); |
| 2055 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2056 | // This finishes the read. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 2057 | data.Resume(); |
| 2058 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2059 | helper.VerifyDataConsumed(); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2060 | } |
| 2061 | |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2062 | // Verify that the client can correctly deal with the user callback deleting the |
| 2063 | // transaction. Failures will usually be valgrind errors. See |
| 2064 | // http://crbug.com/46925 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2065 | TEST_F(SpdyNetworkTransactionTest, DeleteSessionOnReadCallback) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2066 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2067 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2068 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2069 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2070 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2071 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2072 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2073 | CreateMockRead(resp, 1), |
| 2074 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause |
| 2075 | CreateMockRead(body, 3), MockRead(ASYNC, 0, 0, 4), // EOF |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2076 | }; |
| 2077 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 2078 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2079 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2080 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2081 | BoundNetLog(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2082 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2083 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2084 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2085 | |
| 2086 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2087 | TestCompletionCallback callback; |
| 2088 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2089 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2090 | rv = callback.WaitForResult(); |
| 2091 | |
| 2092 | // Setup a user callback which will delete the session, and clear out the |
| 2093 | // memory holding the stream object. Note that the callback deletes trans. |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2094 | const int kSize = 3000; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 2095 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSize)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2096 | rv = trans->Read( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2097 | buf.get(), |
| 2098 | kSize, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2099 | base::Bind(&SpdyNetworkTransactionTest::DeleteSessionCallback, |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2100 | base::Unretained(&helper))); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2101 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 2102 | data.Resume(); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2103 | |
| 2104 | // Finish running rest of tasks. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2105 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2106 | helper.VerifyDataConsumed(); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2107 | } |
| 2108 | |
allada | 71b2efb | 2016-09-09 04:57:48 | [diff] [blame] | 2109 | TEST_F(SpdyNetworkTransactionTest, TestRawHeaderSizeSuccessfullRequest) { |
| 2110 | SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
| 2111 | headers["user-agent"] = ""; |
| 2112 | headers["accept-encoding"] = "gzip, deflate"; |
| 2113 | |
| 2114 | SpdySerializedFrame req( |
| 2115 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 2116 | MockWrite writes[] = { |
| 2117 | CreateMockWrite(req, 0), |
| 2118 | }; |
| 2119 | |
| 2120 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 2121 | |
| 2122 | SpdySerializedFrame response_body_frame( |
| 2123 | spdy_util_.ConstructSpdyDataFrame(1, "should not include", 18, true)); |
| 2124 | |
| 2125 | MockRead response_headers(CreateMockRead(resp, 1)); |
| 2126 | MockRead reads[] = { |
| 2127 | response_headers, CreateMockRead(response_body_frame, 2), |
| 2128 | MockRead(ASYNC, 0, 0, 3) // EOF |
| 2129 | }; |
| 2130 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2131 | |
| 2132 | TestDelegate delegate; |
| 2133 | SpdyURLRequestContext spdy_url_request_context; |
| 2134 | TestNetworkDelegate network_delegate; |
| 2135 | spdy_url_request_context.set_network_delegate(&network_delegate); |
| 2136 | SSLSocketDataProvider ssl_data(ASYNC, OK); |
| 2137 | ssl_data.next_proto = kProtoHTTP2; |
| 2138 | |
| 2139 | std::unique_ptr<URLRequest> request(spdy_url_request_context.CreateRequest( |
| 2140 | GURL(kDefaultUrl), DEFAULT_PRIORITY, &delegate)); |
| 2141 | spdy_url_request_context.socket_factory().AddSSLSocketDataProvider(&ssl_data); |
| 2142 | spdy_url_request_context.socket_factory().AddSocketDataProvider(&data); |
| 2143 | |
| 2144 | request->Start(); |
| 2145 | base::RunLoop().Run(); |
| 2146 | |
| 2147 | EXPECT_LT(0, request->GetTotalSentBytes()); |
| 2148 | EXPECT_LT(0, request->GetTotalReceivedBytes()); |
| 2149 | EXPECT_EQ(network_delegate.total_network_bytes_sent(), |
| 2150 | request->GetTotalSentBytes()); |
| 2151 | EXPECT_EQ(network_delegate.total_network_bytes_received(), |
| 2152 | request->GetTotalReceivedBytes()); |
| 2153 | EXPECT_EQ(response_headers.data_len, request->raw_header_size()); |
| 2154 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2155 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 2156 | } |
| 2157 | |
| 2158 | TEST_F(SpdyNetworkTransactionTest, |
| 2159 | TestRawHeaderSizeSuccessfullPushHeadersFirst) { |
| 2160 | SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
| 2161 | headers["user-agent"] = ""; |
| 2162 | headers["accept-encoding"] = "gzip, deflate"; |
| 2163 | |
| 2164 | SpdySerializedFrame req( |
| 2165 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 2166 | MockWrite writes[] = { |
| 2167 | CreateMockWrite(req, 0), |
| 2168 | }; |
| 2169 | |
| 2170 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 2171 | SpdySerializedFrame response_body_frame( |
| 2172 | spdy_util_.ConstructSpdyDataFrame(1, "should not include", 18, true)); |
| 2173 | |
| 2174 | SpdyHeaderBlock push_headers; |
| 2175 | spdy_util_.AddUrlToHeaderBlock(std::string(kDefaultUrl) + "b.dat", |
| 2176 | &push_headers); |
| 2177 | |
| 2178 | SpdySerializedFrame push_init_frame( |
| 2179 | spdy_util_.ConstructInitialSpdyPushFrame(std::move(push_headers), 2, 1)); |
| 2180 | |
| 2181 | SpdySerializedFrame push_headers_frame( |
| 2182 | spdy_util_.ConstructSpdyPushHeaders(2, nullptr, 0)); |
| 2183 | |
| 2184 | SpdySerializedFrame push_body_frame(spdy_util_.ConstructSpdyDataFrame( |
| 2185 | 2, "should not include either", 25, false)); |
| 2186 | |
| 2187 | MockRead push_init_read(CreateMockRead(push_init_frame, 1)); |
| 2188 | MockRead response_headers(CreateMockRead(resp, 4)); |
| 2189 | // raw_header_size() will contain the size of the push promise frame |
| 2190 | // initialization. |
| 2191 | int expected_response_headers_size = |
| 2192 | response_headers.data_len + push_init_read.data_len; |
| 2193 | |
| 2194 | MockRead reads[] = { |
| 2195 | push_init_read, |
| 2196 | CreateMockRead(push_headers_frame, 2), |
| 2197 | CreateMockRead(push_body_frame, 3), |
| 2198 | response_headers, |
| 2199 | CreateMockRead(response_body_frame, 5), |
| 2200 | MockRead(ASYNC, 0, 6) // EOF |
| 2201 | }; |
| 2202 | |
| 2203 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2204 | |
| 2205 | TestDelegate delegate; |
| 2206 | SpdyURLRequestContext spdy_url_request_context; |
| 2207 | TestNetworkDelegate network_delegate; |
| 2208 | spdy_url_request_context.set_network_delegate(&network_delegate); |
| 2209 | SSLSocketDataProvider ssl_data(ASYNC, OK); |
| 2210 | ssl_data.next_proto = kProtoHTTP2; |
| 2211 | |
| 2212 | std::unique_ptr<URLRequest> request(spdy_url_request_context.CreateRequest( |
| 2213 | GURL(kDefaultUrl), DEFAULT_PRIORITY, &delegate)); |
| 2214 | spdy_url_request_context.socket_factory().AddSSLSocketDataProvider(&ssl_data); |
| 2215 | spdy_url_request_context.socket_factory().AddSocketDataProvider(&data); |
| 2216 | |
| 2217 | request->Start(); |
| 2218 | base::RunLoop().Run(); |
| 2219 | |
| 2220 | EXPECT_LT(0, request->GetTotalSentBytes()); |
| 2221 | EXPECT_LT(0, request->GetTotalReceivedBytes()); |
| 2222 | EXPECT_EQ(network_delegate.total_network_bytes_sent(), |
| 2223 | request->GetTotalSentBytes()); |
| 2224 | EXPECT_EQ(network_delegate.total_network_bytes_received(), |
| 2225 | request->GetTotalReceivedBytes()); |
| 2226 | EXPECT_EQ(expected_response_headers_size, request->raw_header_size()); |
| 2227 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2228 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 2229 | } |
| 2230 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2231 | // Send a spdy request to www.example.org that gets redirected to www.foo.com. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2232 | TEST_F(SpdyNetworkTransactionTest, DISABLED_RedirectGetRequest) { |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 2233 | SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2234 | headers["user-agent"] = ""; |
| 2235 | headers["accept-encoding"] = "gzip, deflate"; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2236 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2237 | // Setup writes/reads to www.example.org |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2238 | SpdySerializedFrame req( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2239 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 2240 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReplyRedirect(1)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2241 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2242 | CreateMockWrite(req, 1), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2243 | }; |
| 2244 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2245 | CreateMockRead(resp, 2), MockRead(ASYNC, 0, 0, 3) // EOF |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2246 | }; |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2247 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2248 | |
| 2249 | // Setup writes/reads to www.foo.com |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2250 | SpdyHeaderBlock headers2( |
| 2251 | spdy_util_.ConstructGetHeaderBlock("http://www.foo.com/index.php")); |
| 2252 | headers2["user-agent"] = ""; |
| 2253 | headers2["accept-encoding"] = "gzip, deflate"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2254 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2255 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers2), LOWEST, true)); |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2256 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2257 | CreateMockWrite(req2, 1), |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2258 | }; |
| 2259 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2260 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2261 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2262 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2263 | CreateMockRead(resp2, 2), CreateMockRead(body2, 3), |
| 2264 | MockRead(ASYNC, 0, 0, 4) // EOF |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2265 | }; |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2266 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2267 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 2268 | arraysize(writes2)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2269 | |
| 2270 | // TODO(erikchen): Make test support SPDYSSL, SPDYNPN |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2271 | TestDelegate d; |
| 2272 | { |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 2273 | SpdyURLRequestContext spdy_url_request_context; |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 2274 | std::unique_ptr<URLRequest> r(spdy_url_request_context.CreateRequest( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 2275 | default_url_, DEFAULT_PRIORITY, &d)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2276 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2277 | AddSocketDataProvider(&data); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2278 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2279 | AddSocketDataProvider(&data2); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2280 | |
| 2281 | d.set_quit_on_redirect(true); |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2282 | r->Start(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2283 | base::RunLoop().Run(); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2284 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2285 | EXPECT_EQ(1, d.received_redirect_count()); |
| 2286 | |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2287 | r->FollowDeferredRedirect(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2288 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2289 | EXPECT_EQ(1, d.response_started_count()); |
| 2290 | EXPECT_FALSE(d.received_data_before_response()); |
allada | 71b2efb | 2016-09-09 04:57:48 | [diff] [blame] | 2291 | EXPECT_EQ(OK, r->status().error()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2292 | std::string contents("hello!"); |
| 2293 | EXPECT_EQ(contents, d.data_received()); |
| 2294 | } |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 2295 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2296 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 2297 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 2298 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2299 | } |
| 2300 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2301 | // Send a spdy request to www.example.org. Get a pushed stream that redirects to |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2302 | // www.foo.com. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2303 | TEST_F(SpdyNetworkTransactionTest, DISABLED_RedirectServerPush) { |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 2304 | SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2305 | headers["user-agent"] = ""; |
| 2306 | headers["accept-encoding"] = "gzip, deflate"; |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2307 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2308 | // Setup writes/reads to www.example.org |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2309 | SpdySerializedFrame req( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2310 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 2311 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2312 | SpdySerializedFrame rep(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2313 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str(), |
| 2314 | "301 Moved Permanently", "http://www.foo.com/index.php")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2315 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 2316 | SpdySerializedFrame rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2317 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_CANCEL)); |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2318 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2319 | CreateMockWrite(req, 1), CreateMockWrite(rst, 6), |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2320 | }; |
| 2321 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2322 | CreateMockRead(resp, 2), CreateMockRead(rep, 3), CreateMockRead(body, 4), |
| 2323 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
| 2324 | MockRead(ASYNC, 0, 0, 7) // EOF |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2325 | }; |
| 2326 | |
| 2327 | // Setup writes/reads to www.foo.com |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2328 | SpdyHeaderBlock headers2( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2329 | spdy_util_.ConstructGetHeaderBlock("http://www.foo.com/index.php")); |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2330 | headers2["user-agent"] = ""; |
| 2331 | headers2["accept-encoding"] = "gzip, deflate"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2332 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2333 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers2), LOWEST, true)); |
| 2334 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2335 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2336 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2337 | CreateMockWrite(req2, 1), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2338 | }; |
| 2339 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2340 | CreateMockRead(resp2, 2), CreateMockRead(body2, 3), |
| 2341 | MockRead(ASYNC, 0, 0, 5) // EOF |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2342 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2343 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2344 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 2345 | arraysize(writes2)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2346 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2347 | TestDelegate d; |
| 2348 | TestDelegate d2; |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 2349 | SpdyURLRequestContext spdy_url_request_context; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2350 | { |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 2351 | std::unique_ptr<URLRequest> r(spdy_url_request_context.CreateRequest( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 2352 | default_url_, DEFAULT_PRIORITY, &d)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2353 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2354 | AddSocketDataProvider(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2355 | |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2356 | r->Start(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2357 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2358 | |
| 2359 | EXPECT_EQ(0, d.received_redirect_count()); |
| 2360 | std::string contents("hello!"); |
| 2361 | EXPECT_EQ(contents, d.data_received()); |
| 2362 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 2363 | std::unique_ptr<URLRequest> r2(spdy_url_request_context.CreateRequest( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2364 | GURL(GetDefaultUrlWithPath("/foo.dat")), DEFAULT_PRIORITY, &d2)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2365 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2366 | AddSocketDataProvider(&data2); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2367 | |
| 2368 | d2.set_quit_on_redirect(true); |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2369 | r2->Start(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2370 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2371 | EXPECT_EQ(1, d2.received_redirect_count()); |
| 2372 | |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2373 | r2->FollowDeferredRedirect(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2374 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2375 | EXPECT_EQ(1, d2.response_started_count()); |
| 2376 | EXPECT_FALSE(d2.received_data_before_response()); |
allada | 71b2efb | 2016-09-09 04:57:48 | [diff] [blame] | 2377 | EXPECT_EQ(OK, r2->status().error()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2378 | std::string contents2("hello!"); |
| 2379 | EXPECT_EQ(contents2, d2.data_received()); |
| 2380 | } |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2381 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2382 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 2383 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 2384 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2385 | } |
| 2386 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2387 | TEST_F(SpdyNetworkTransactionTest, ServerPushSingleDataFrame) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2388 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2389 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2390 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2391 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2392 | CreateMockWrite(stream1_syn, 0), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2393 | }; |
| 2394 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2395 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2396 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2397 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2398 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2399 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2400 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 2401 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2402 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2403 | CreateMockRead(stream1_reply, 1), |
| 2404 | CreateMockRead(stream2_syn, 2), |
| 2405 | CreateMockRead(stream1_body, 3, SYNCHRONOUS), |
| 2406 | CreateMockRead(stream2_body, 4), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2407 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2408 | }; |
| 2409 | |
| 2410 | HttpResponseInfo response; |
| 2411 | HttpResponseInfo response2; |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2412 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2413 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2414 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2415 | &response, |
| 2416 | &response2, |
| 2417 | expected_push_result); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2418 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2419 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2420 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2421 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2422 | |
| 2423 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2424 | EXPECT_TRUE(response2.headers); |
bnc | cdc749f | 2016-01-27 16:39:04 | [diff] [blame] | 2425 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2426 | } |
| 2427 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2428 | TEST_F(SpdyNetworkTransactionTest, ServerPushBeforeHeaders) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2429 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2430 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2431 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2432 | CreateMockWrite(stream1_syn, 0), |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2433 | }; |
| 2434 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2435 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2436 | nullptr, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2437 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2438 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2439 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2440 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2441 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 2442 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2443 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2444 | CreateMockRead(stream2_syn, 1), |
| 2445 | CreateMockRead(stream1_reply, 2), |
| 2446 | CreateMockRead(stream1_body, 3, SYNCHRONOUS), |
| 2447 | CreateMockRead(stream2_body, 4), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2448 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2449 | }; |
| 2450 | |
| 2451 | HttpResponseInfo response; |
| 2452 | HttpResponseInfo response2; |
| 2453 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2454 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2455 | RunServerPushTest(&data, |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2456 | &response, |
| 2457 | &response2, |
| 2458 | expected_push_result); |
| 2459 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2460 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2461 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2462 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2463 | |
| 2464 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2465 | EXPECT_TRUE(response2.headers); |
bnc | cdc749f | 2016-01-27 16:39:04 | [diff] [blame] | 2466 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2467 | } |
| 2468 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2469 | TEST_F(SpdyNetworkTransactionTest, ServerPushSingleDataFrame2) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2470 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2471 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2472 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2473 | CreateMockWrite(stream1_syn, 0), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2474 | }; |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2475 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2476 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2477 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2478 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2479 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2480 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2481 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 2482 | 2, kPushedData, strlen(kPushedData), true)); |
| 2483 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2484 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2485 | CreateMockRead(stream1_reply, 1), |
| 2486 | CreateMockRead(stream2_syn, 2), |
| 2487 | CreateMockRead(stream2_body, 3), |
| 2488 | CreateMockRead(stream1_body, 4, SYNCHRONOUS), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2489 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2490 | }; |
| 2491 | |
| 2492 | HttpResponseInfo response; |
| 2493 | HttpResponseInfo response2; |
| 2494 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2495 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2496 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2497 | &response, |
| 2498 | &response2, |
| 2499 | expected_push_result); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2500 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2501 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2502 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2503 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2504 | |
| 2505 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2506 | EXPECT_TRUE(response2.headers); |
bnc | cdc749f | 2016-01-27 16:39:04 | [diff] [blame] | 2507 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2508 | } |
| 2509 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2510 | TEST_F(SpdyNetworkTransactionTest, ServerPushServerAborted) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2511 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2512 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2513 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2514 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2515 | CreateMockWrite(stream1_syn, 0), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2516 | }; |
| 2517 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2518 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2519 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2520 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2521 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2522 | SpdySerializedFrame stream2_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2523 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2524 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2525 | CreateMockRead(stream1_reply, 1), |
| 2526 | CreateMockRead(stream2_syn, 2), |
| 2527 | CreateMockRead(stream2_rst, 3), |
| 2528 | CreateMockRead(stream1_body, 4, SYNCHRONOUS), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2529 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2530 | }; |
| 2531 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2532 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2533 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2534 | BoundNetLog(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2535 | |
| 2536 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2537 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2538 | |
| 2539 | HttpNetworkTransaction* trans = helper.trans(); |
| 2540 | |
| 2541 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2542 | TestCompletionCallback callback; |
| 2543 | int rv = trans->Start( |
| 2544 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2545 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2546 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2547 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2548 | |
| 2549 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2550 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2551 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2552 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2553 | // Verify the response headers. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2554 | HttpResponseInfo response = *trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2555 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2556 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2557 | } |
| 2558 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2559 | // Verify that we don't leak streams and that we properly send a reset |
| 2560 | // if the server pushes the same stream twice. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2561 | TEST_F(SpdyNetworkTransactionTest, ServerPushDuplicate) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2562 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2563 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2564 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 2565 | SpdySerializedFrame stream3_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2566 | spdy_util_.ConstructSpdyRstStream(4, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2567 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2568 | CreateMockWrite(stream1_syn, 0), CreateMockWrite(stream3_rst, 4), |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2569 | }; |
| 2570 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2571 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2572 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2573 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2574 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2575 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2576 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 2577 | 2, kPushedData, strlen(kPushedData), true)); |
| 2578 | SpdySerializedFrame stream3_syn(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2579 | NULL, 0, 4, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2580 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2581 | CreateMockRead(stream1_reply, 1), |
| 2582 | CreateMockRead(stream2_syn, 2), |
| 2583 | CreateMockRead(stream3_syn, 3), |
| 2584 | CreateMockRead(stream1_body, 5), |
| 2585 | CreateMockRead(stream2_body, 6), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2586 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 7), // Force a pause |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2587 | }; |
| 2588 | |
| 2589 | HttpResponseInfo response; |
| 2590 | HttpResponseInfo response2; |
| 2591 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2592 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2593 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2594 | &response, |
| 2595 | &response2, |
| 2596 | expected_push_result); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2597 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2598 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2599 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2600 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2601 | |
| 2602 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2603 | EXPECT_TRUE(response2.headers); |
bnc | cdc749f | 2016-01-27 16:39:04 | [diff] [blame] | 2604 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2605 | } |
| 2606 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2607 | TEST_F(SpdyNetworkTransactionTest, ServerPushMultipleDataFrame) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2608 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2609 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2610 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2611 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2612 | CreateMockWrite(stream1_syn, 0), |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2613 | }; |
| 2614 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2615 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2616 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2617 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2618 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2619 | static const char kPushedData[] = "pushed my darling hello my baby"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2620 | SpdySerializedFrame stream2_body_base(spdy_util_.ConstructSpdyDataFrame( |
| 2621 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2622 | const size_t kChunkSize = strlen(kPushedData) / 4; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2623 | SpdySerializedFrame stream2_body1(stream2_body_base.data(), kChunkSize, |
| 2624 | false); |
| 2625 | SpdySerializedFrame stream2_body2(stream2_body_base.data() + kChunkSize, |
| 2626 | kChunkSize, false); |
| 2627 | SpdySerializedFrame stream2_body3(stream2_body_base.data() + 2 * kChunkSize, |
| 2628 | kChunkSize, false); |
| 2629 | SpdySerializedFrame stream2_body4(stream2_body_base.data() + 3 * kChunkSize, |
| 2630 | stream2_body_base.size() - 3 * kChunkSize, |
| 2631 | false); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2632 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2633 | CreateMockRead(stream1_reply, 1), |
| 2634 | CreateMockRead(stream2_syn, 2), |
| 2635 | CreateMockRead(stream2_body1, 3), |
| 2636 | CreateMockRead(stream2_body2, 4), |
| 2637 | CreateMockRead(stream2_body3, 5), |
| 2638 | CreateMockRead(stream2_body4, 6), |
| 2639 | CreateMockRead(stream1_body, 7, SYNCHRONOUS), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2640 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), // Force a pause |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2641 | }; |
| 2642 | |
| 2643 | HttpResponseInfo response; |
| 2644 | HttpResponseInfo response2; |
| 2645 | std::string expected_push_result("pushed my darling hello my baby"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2646 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2647 | RunServerPushTest(&data, &response, &response2, kPushedData); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2648 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2649 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2650 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2651 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2652 | |
| 2653 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2654 | EXPECT_TRUE(response2.headers); |
bnc | cdc749f | 2016-01-27 16:39:04 | [diff] [blame] | 2655 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2656 | } |
| 2657 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2658 | TEST_F(SpdyNetworkTransactionTest, ServerPushMultipleDataFrameInterrupted) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2659 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2660 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2661 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2662 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2663 | CreateMockWrite(stream1_syn, 0), |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2664 | }; |
| 2665 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2666 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2667 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2668 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2669 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2670 | static const char kPushedData[] = "pushed my darling hello my baby"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2671 | SpdySerializedFrame stream2_body_base(spdy_util_.ConstructSpdyDataFrame( |
| 2672 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2673 | const size_t kChunkSize = strlen(kPushedData) / 4; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2674 | SpdySerializedFrame stream2_body1(stream2_body_base.data(), kChunkSize, |
| 2675 | false); |
| 2676 | SpdySerializedFrame stream2_body2(stream2_body_base.data() + kChunkSize, |
| 2677 | kChunkSize, false); |
| 2678 | SpdySerializedFrame stream2_body3(stream2_body_base.data() + 2 * kChunkSize, |
| 2679 | kChunkSize, false); |
| 2680 | SpdySerializedFrame stream2_body4(stream2_body_base.data() + 3 * kChunkSize, |
| 2681 | stream2_body_base.size() - 3 * kChunkSize, |
| 2682 | false); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2683 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2684 | CreateMockRead(stream1_reply, 1), |
| 2685 | CreateMockRead(stream2_syn, 2), |
| 2686 | CreateMockRead(stream2_body1, 3), |
| 2687 | CreateMockRead(stream2_body2, 4), |
| 2688 | CreateMockRead(stream2_body3, 5), |
| 2689 | CreateMockRead(stream2_body4, 6), |
| 2690 | CreateMockRead(stream1_body, 7, SYNCHRONOUS), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2691 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8) // Force a pause. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2692 | }; |
| 2693 | |
| 2694 | HttpResponseInfo response; |
| 2695 | HttpResponseInfo response2; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2696 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2697 | RunServerPushTest(&data, &response, &response2, kPushedData); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2698 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2699 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2700 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2701 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2702 | |
| 2703 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2704 | EXPECT_TRUE(response2.headers); |
bnc | cdc749f | 2016-01-27 16:39:04 | [diff] [blame] | 2705 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2706 | } |
| 2707 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2708 | TEST_F(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID0) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2709 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2710 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2711 | SpdySerializedFrame goaway(spdy_util_.ConstructSpdyGoAway( |
| 2712 | 0, GOAWAY_PROTOCOL_ERROR, "Framer error: 1 (INVALID_STREAM_ID).")); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2713 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2714 | CreateMockWrite(stream1_syn, 0), CreateMockWrite(goaway, 3), |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2715 | }; |
| 2716 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2717 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2718 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2719 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2720 | NULL, 0, 2, 0, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2721 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2722 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2), |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2723 | }; |
| 2724 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2725 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2726 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2727 | BoundNetLog(), NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2728 | |
| 2729 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2730 | helper.AddData(&data); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2731 | |
| 2732 | HttpNetworkTransaction* trans = helper.trans(); |
| 2733 | |
| 2734 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2735 | TestCompletionCallback callback; |
| 2736 | int rv = trans->Start( |
| 2737 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2738 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2739 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2740 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2741 | |
| 2742 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2743 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2744 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2745 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2746 | // Verify the response headers. |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2747 | HttpResponseInfo response = *trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2748 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2749 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2750 | } |
| 2751 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2752 | TEST_F(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID9) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2753 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2754 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2755 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 2756 | SpdySerializedFrame stream2_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2757 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_INVALID_STREAM)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2758 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2759 | CreateMockWrite(stream1_syn, 0), CreateMockWrite(stream2_rst, 3), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2760 | }; |
| 2761 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2762 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2763 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2764 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2765 | NULL, 0, 2, 9, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2766 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2767 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2), |
| 2768 | CreateMockRead(stream1_body, 4), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2769 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2770 | }; |
| 2771 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2772 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2773 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2774 | BoundNetLog(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2775 | |
| 2776 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2777 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2778 | |
| 2779 | HttpNetworkTransaction* trans = helper.trans(); |
| 2780 | |
| 2781 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2782 | TestCompletionCallback callback; |
| 2783 | int rv = trans->Start( |
| 2784 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2785 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2786 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2787 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2788 | |
| 2789 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2790 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2791 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2792 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2793 | // Verify the response headers. |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2794 | HttpResponseInfo response = *trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2795 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2796 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2797 | } |
| 2798 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2799 | TEST_F(SpdyNetworkTransactionTest, ServerPushNoURL) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2800 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2801 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2802 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 2803 | SpdySerializedFrame stream2_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2804 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2805 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2806 | CreateMockWrite(stream1_syn, 0), CreateMockWrite(stream2_rst, 3), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2807 | }; |
| 2808 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2809 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2810 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2811 | SpdyHeaderBlock incomplete_headers; |
| 2812 | incomplete_headers[spdy_util_.GetStatusKey()] = "200 OK"; |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2813 | incomplete_headers["hello"] = "bye"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2814 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame( |
| 2815 | std::move(incomplete_headers), 2, 1)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2816 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2817 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2), |
| 2818 | CreateMockRead(stream1_body, 4), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2819 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5) // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2820 | }; |
| 2821 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2822 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2823 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2824 | BoundNetLog(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2825 | |
| 2826 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2827 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2828 | |
| 2829 | HttpNetworkTransaction* trans = helper.trans(); |
| 2830 | |
| 2831 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2832 | TestCompletionCallback callback; |
| 2833 | int rv = trans->Start( |
| 2834 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2835 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2836 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2837 | EXPECT_THAT(rv, IsOk()); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2838 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2839 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2840 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2841 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2842 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2843 | // Verify the response headers. |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2844 | HttpResponseInfo response = *trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2845 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2846 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2847 | } |
| 2848 | |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2849 | // PUSH_PROMISE on a server-initiated stream should trigger GOAWAY. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2850 | TEST_F(SpdyNetworkTransactionTest, ServerPushOnPushedStream) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2851 | SpdySerializedFrame stream1_syn( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2852 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2853 | SpdySerializedFrame goaway(spdy_util_.ConstructSpdyGoAway( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2854 | 2, GOAWAY_PROTOCOL_ERROR, "Push on even stream id.")); |
| 2855 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2856 | CreateMockWrite(stream1_syn, 0), CreateMockWrite(goaway, 4), |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2857 | }; |
| 2858 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2859 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2860 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2861 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2862 | nullptr, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2863 | SpdySerializedFrame stream3_syn(spdy_util_.ConstructSpdyPush( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2864 | nullptr, 0, 4, 2, GetDefaultUrlWithPath("/bar.dat").c_str())); |
| 2865 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2866 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2), |
| 2867 | CreateMockRead(stream3_syn, 3), |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2868 | }; |
| 2869 | |
| 2870 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2871 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2872 | BoundNetLog(), nullptr); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2873 | helper.RunToCompletion(&data); |
| 2874 | } |
| 2875 | |
| 2876 | // PUSH_PROMISE on a closed client-initiated stream should trigger RST_STREAM. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2877 | TEST_F(SpdyNetworkTransactionTest, ServerPushOnClosedStream) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2878 | SpdySerializedFrame stream1_syn( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2879 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2880 | SpdySerializedFrame rst( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2881 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_INVALID_STREAM)); |
| 2882 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2883 | CreateMockWrite(stream1_syn, 0), CreateMockWrite(rst, 5), |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2884 | }; |
| 2885 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2886 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2887 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2888 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 2889 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2890 | nullptr, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
| 2891 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2892 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream1_body, 2), |
| 2893 | CreateMockRead(stream2_syn, 3), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 4), |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2894 | }; |
| 2895 | |
| 2896 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2897 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2898 | BoundNetLog(), nullptr); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2899 | helper.RunPreTestSetup(); |
| 2900 | helper.AddData(&data); |
| 2901 | |
| 2902 | HttpNetworkTransaction* trans = helper.trans(); |
| 2903 | |
| 2904 | TestCompletionCallback callback; |
| 2905 | int rv = |
| 2906 | trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 2907 | rv = callback.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2908 | EXPECT_THAT(rv, IsOk()); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2909 | HttpResponseInfo response = *trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2910 | EXPECT_TRUE(response.headers); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2911 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
| 2912 | |
| 2913 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2914 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 2915 | VerifyStreamsClosed(helper); |
| 2916 | } |
| 2917 | |
| 2918 | // PUSH_PROMISE on a server-initiated stream should trigger GOAWAY even if |
| 2919 | // stream is closed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2920 | TEST_F(SpdyNetworkTransactionTest, ServerPushOnClosedPushedStream) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2921 | SpdySerializedFrame stream1_syn( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2922 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2923 | SpdySerializedFrame goaway(spdy_util_.ConstructSpdyGoAway( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2924 | 2, GOAWAY_PROTOCOL_ERROR, "Push on even stream id.")); |
| 2925 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2926 | CreateMockWrite(stream1_syn, 0), CreateMockWrite(goaway, 7), |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2927 | }; |
| 2928 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2929 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2930 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2931 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2932 | nullptr, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2933 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2934 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2935 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 2936 | 2, kPushedData, strlen(kPushedData), true)); |
| 2937 | SpdySerializedFrame stream3_syn(spdy_util_.ConstructSpdyPush( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2938 | nullptr, 0, 4, 2, GetDefaultUrlWithPath("/bar.dat").c_str())); |
| 2939 | |
| 2940 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2941 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2), |
| 2942 | CreateMockRead(stream1_body, 3), CreateMockRead(stream2_body, 4), |
| 2943 | MockRead(ASYNC, ERR_IO_PENDING, 5), CreateMockRead(stream3_syn, 6), |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2944 | }; |
| 2945 | |
| 2946 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2947 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2948 | BoundNetLog(), nullptr); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2949 | helper.RunPreTestSetup(); |
| 2950 | helper.AddData(&data); |
| 2951 | |
| 2952 | HttpNetworkTransaction* trans1 = helper.trans(); |
| 2953 | TestCompletionCallback callback1; |
| 2954 | int rv = |
| 2955 | trans1->Start(&CreateGetRequest(), callback1.callback(), BoundNetLog()); |
| 2956 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2957 | EXPECT_THAT(rv, IsOk()); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2958 | HttpResponseInfo response = *trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2959 | EXPECT_TRUE(response.headers); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2960 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
| 2961 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2962 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2963 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2964 | rv = trans2.Start(&CreateGetPushRequest(), callback2.callback(), |
| 2965 | BoundNetLog()); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2966 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2967 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2968 | response = *trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2969 | EXPECT_TRUE(response.headers); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2970 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
| 2971 | std::string result; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2972 | ReadResult(&trans2, &result); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2973 | EXPECT_EQ(kPushedData, result); |
| 2974 | |
| 2975 | data.Resume(); |
| 2976 | base::RunLoop().RunUntilIdle(); |
| 2977 | |
| 2978 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2979 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 2980 | } |
| 2981 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2982 | // Verify that various response headers parse correctly through the HTTP layer. |
| 2983 | TEST_F(SpdyNetworkTransactionTest, ResponseHeaders) { |
| 2984 | struct ResponseHeadersTests { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2985 | int num_headers; |
| 2986 | const char* extra_headers[5]; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2987 | SpdyHeaderBlock expected_headers; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 2988 | } test_cases[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2989 | // This uses a multi-valued cookie header. |
| 2990 | { 2, |
| 2991 | { "cookie", "val1", |
| 2992 | "cookie", "val2", // will get appended separated by NULL |
| 2993 | NULL |
| 2994 | }, |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 2995 | }, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2996 | // This is the minimalist set of headers. |
| 2997 | { 0, |
| 2998 | { NULL }, |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 2999 | }, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3000 | // Headers with a comma separated list. |
| 3001 | { 1, |
| 3002 | { "cookie", "val1,val2", |
| 3003 | NULL |
| 3004 | }, |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3005 | } |
| 3006 | }; |
| 3007 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3008 | test_cases[0].expected_headers["status"] = "200"; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3009 | test_cases[1].expected_headers["status"] = "200"; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3010 | test_cases[2].expected_headers["status"] = "200"; |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3011 | |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3012 | test_cases[0].expected_headers["hello"] = "bye"; |
| 3013 | test_cases[1].expected_headers["hello"] = "bye"; |
| 3014 | test_cases[2].expected_headers["hello"] = "bye"; |
| 3015 | |
bnc | 2d24791 | 2016-04-21 23:34:37 | [diff] [blame] | 3016 | test_cases[0].expected_headers["cookie"] = base::StringPiece("val1\0val2", 9); |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3017 | test_cases[2].expected_headers["cookie"] = "val1,val2"; |
| 3018 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 3019 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3020 | SpdyTestUtil spdy_test_util; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3021 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3022 | spdy_test_util.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3023 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3024 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3025 | SpdySerializedFrame resp(spdy_test_util.ConstructSpdyGetReply( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3026 | test_cases[i].extra_headers, test_cases[i].num_headers, 1)); |
| 3027 | SpdySerializedFrame body(spdy_test_util.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3028 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3029 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3030 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3031 | }; |
| 3032 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3033 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 3034 | arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3035 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3036 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3037 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3038 | TransactionHelperResult out = helper.output(); |
| 3039 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3040 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3041 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3042 | EXPECT_EQ("hello!", out.response_data); |
| 3043 | |
| 3044 | scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3045 | EXPECT_TRUE(headers); |
olli.raula | 33c282f | 2016-01-21 12:12:49 | [diff] [blame] | 3046 | size_t iter = 0; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3047 | std::string name, value; |
| 3048 | SpdyHeaderBlock header_block; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3049 | while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3050 | SpdyHeaderBlock::StringPieceProxy mutable_header_block_value = |
| 3051 | header_block[name]; |
bnc | 2d24791 | 2016-04-21 23:34:37 | [diff] [blame] | 3052 | if (static_cast<base::StringPiece>(mutable_header_block_value).empty()) { |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3053 | mutable_header_block_value = value; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3054 | } else { |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3055 | std::string joint_value = mutable_header_block_value.as_string(); |
| 3056 | joint_value.append(1, '\0'); |
| 3057 | joint_value.append(value); |
| 3058 | mutable_header_block_value = joint_value; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3059 | } |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3060 | } |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3061 | EXPECT_EQ(test_cases[i].expected_headers, header_block); |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3062 | } |
| 3063 | } |
| 3064 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3065 | // Verify that various response headers parse vary fields correctly through the |
| 3066 | // HTTP layer, and the response matches the request. |
| 3067 | TEST_F(SpdyNetworkTransactionTest, ResponseHeadersVary) { |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3068 | // Modify the following data to change/add test cases: |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3069 | struct ResponseTests { |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3070 | bool vary_matches; |
| 3071 | int num_headers[2]; |
| 3072 | const char* extra_headers[2][16]; |
| 3073 | } test_cases[] = { |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3074 | // Test the case of a multi-valued cookie. When the value is delimited |
| 3075 | // with NUL characters, it needs to be unfolded into multiple headers. |
| 3076 | {true, |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 3077 | {1, 3}, |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3078 | {{"cookie", "val1,val2", NULL}, |
| 3079 | {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 3080 | "/index.php", "vary", "cookie", NULL}}}, |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3081 | {// Multiple vary fields. |
| 3082 | true, |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3083 | {2, 4}, |
| 3084 | {{"friend", "barney", "enemy", "snaggletooth", NULL}, |
| 3085 | {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 3086 | "/index.php", "vary", "friend", "vary", "enemy", NULL}}}, |
| 3087 | {// Test a '*' vary field. |
| 3088 | false, |
| 3089 | {1, 3}, |
| 3090 | {{"cookie", "val1,val2", NULL}, |
| 3091 | {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
| 3092 | "/index.php", "vary", "*", NULL}}}, |
| 3093 | {// Multiple comma-separated vary fields. |
| 3094 | true, |
| 3095 | {2, 3}, |
| 3096 | {{"friend", "barney", "enemy", "snaggletooth", NULL}, |
| 3097 | {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
| 3098 | "/index.php", "vary", "friend,enemy", NULL}}}}; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3099 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 3100 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3101 | SpdyTestUtil spdy_test_util; |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3102 | |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3103 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3104 | SpdySerializedFrame frame_req(spdy_test_util.ConstructSpdyGet( |
| 3105 | test_cases[i].extra_headers[0], test_cases[i].num_headers[0], 1, LOWEST, |
| 3106 | true)); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3107 | |
| 3108 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3109 | CreateMockWrite(frame_req, 0), |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3110 | }; |
| 3111 | |
| 3112 | // Construct the reply. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3113 | SpdyHeaderBlock reply_headers; |
| 3114 | AppendToHeaderBlock(test_cases[i].extra_headers[1], |
| 3115 | test_cases[i].num_headers[1], |
| 3116 | &reply_headers); |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 3117 | // Construct the expected header reply string before moving |reply_headers|. |
| 3118 | std::string expected_reply = |
| 3119 | spdy_test_util.ConstructSpdyReplyString(reply_headers); |
| 3120 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3121 | SpdySerializedFrame frame_reply( |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 3122 | spdy_test_util.ConstructSpdyReply(1, std::move(reply_headers))); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3123 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3124 | SpdySerializedFrame body(spdy_test_util.ConstructSpdyDataFrame(1, true)); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3125 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3126 | CreateMockRead(frame_reply, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3127 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3128 | }; |
| 3129 | |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3130 | // Attach the headers to the request. |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 3131 | int header_count = test_cases[i].num_headers[0]; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3132 | |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 3133 | HttpRequestInfo request = CreateGetRequest(); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 3134 | for (int ct = 0; ct < header_count; ct++) { |
| 3135 | const char* header_key = test_cases[i].extra_headers[0][ct * 2]; |
| 3136 | const char* header_value = test_cases[i].extra_headers[0][ct * 2 + 1]; |
| 3137 | request.extra_headers.SetHeader(header_key, header_value); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3138 | } |
| 3139 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3140 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 3141 | arraysize(writes)); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3142 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 3143 | NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3144 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3145 | TransactionHelperResult out = helper.output(); |
| 3146 | |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3147 | EXPECT_EQ(OK, out.rv) << i; |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3148 | EXPECT_EQ("HTTP/1.1 200", out.status_line) << i; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3149 | EXPECT_EQ("hello!", out.response_data) << i; |
| 3150 | |
| 3151 | // Test the response information. |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3152 | EXPECT_EQ(out.response_info.vary_data.is_valid(), |
| 3153 | test_cases[i].vary_matches) << i; |
| 3154 | |
| 3155 | // Check the headers. |
| 3156 | scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3157 | ASSERT_TRUE(headers) << i; |
olli.raula | 33c282f | 2016-01-21 12:12:49 | [diff] [blame] | 3158 | size_t iter = 0; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3159 | std::string name, value, lines; |
| 3160 | while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
| 3161 | lines.append(name); |
| 3162 | lines.append(": "); |
| 3163 | lines.append(value); |
| 3164 | lines.append("\n"); |
| 3165 | } |
| 3166 | |
[email protected] | 9aa32319 | 2013-05-31 21:38:40 | [diff] [blame] | 3167 | EXPECT_EQ(expected_reply, lines) << i; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3168 | } |
| 3169 | } |
| 3170 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3171 | // Verify that we don't crash on invalid response headers. |
| 3172 | TEST_F(SpdyNetworkTransactionTest, InvalidResponseHeaders) { |
| 3173 | struct InvalidResponseHeadersTests { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3174 | int num_headers; |
| 3175 | const char* headers[10]; |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3176 | } test_cases[] = { |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3177 | // Response headers missing status header |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3178 | { |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 3179 | 3, |
| 3180 | {spdy_util_.GetPathKey(), "/index.php", "cookie", "val1", "cookie", |
| 3181 | "val2", NULL}, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3182 | }, |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3183 | // Response headers missing version header |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3184 | { |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 3185 | 1, {spdy_util_.GetPathKey(), "/index.php", "status", "200", NULL}, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3186 | }, |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3187 | // Response headers with no headers |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3188 | { |
| 3189 | 0, {NULL}, |
| 3190 | }, |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3191 | }; |
| 3192 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 3193 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3194 | SpdyTestUtil spdy_test_util; |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3195 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3196 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3197 | spdy_test_util.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3198 | SpdySerializedFrame rst( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3199 | spdy_test_util.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3200 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3201 | CreateMockWrite(req, 0), CreateMockWrite(rst, 2), |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3202 | }; |
| 3203 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3204 | // Construct the reply. |
| 3205 | SpdyHeaderBlock reply_headers; |
| 3206 | AppendToHeaderBlock( |
| 3207 | test_cases[i].headers, test_cases[i].num_headers, &reply_headers); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3208 | SpdySerializedFrame resp( |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 3209 | spdy_test_util.ConstructSpdyReply(1, std::move(reply_headers))); |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3210 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3211 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3) // EOF |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3212 | }; |
| 3213 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3214 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 3215 | arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3216 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3217 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3218 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3219 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3220 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3221 | } |
| 3222 | } |
| 3223 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3224 | TEST_F(SpdyNetworkTransactionTest, CorruptFrameSessionError) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3225 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3226 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3227 | SpdySerializedFrame goaway(spdy_util_.ConstructSpdyGoAway( |
bnc | f501299 | 2016-04-19 16:36:26 | [diff] [blame] | 3228 | 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 6 (DECOMPRESS_FAILURE).")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3229 | MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(goaway, 2)}; |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3230 | |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3231 | // This is the length field that's too short. |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3232 | SpdySerializedFrame reply_wrong_length( |
| 3233 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
diannahu | 86e7a8ab | 2016-08-03 20:11:14 | [diff] [blame] | 3234 | size_t right_size = |
| 3235 | reply_wrong_length.size() - SpdyConstants::GetFrameHeaderSize(HTTP2); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3236 | size_t wrong_size = right_size - 4; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3237 | test::SetFrameLength(&reply_wrong_length, wrong_size, HTTP2); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3238 | |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3239 | MockRead reads[] = { |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3240 | MockRead(ASYNC, reply_wrong_length.data(), reply_wrong_length.size() - 4, |
| 3241 | 1), |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3242 | }; |
| 3243 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3244 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3245 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3246 | BoundNetLog(), NULL); |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3247 | helper.RunToCompletion(&data); |
| 3248 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3249 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_COMPRESSION_ERROR)); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3250 | } |
| 3251 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3252 | TEST_F(SpdyNetworkTransactionTest, GoAwayOnDecompressionFailure) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3253 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3254 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3255 | SpdySerializedFrame goaway(spdy_util_.ConstructSpdyGoAway( |
bnc | f501299 | 2016-04-19 16:36:26 | [diff] [blame] | 3256 | 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 6 (DECOMPRESS_FAILURE).")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3257 | MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(goaway, 2)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3258 | |
| 3259 | // Read HEADERS with corrupted payload. |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3260 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3261 | memset(resp.data() + 12, 0xcf, resp.size() - 12); |
| 3262 | MockRead reads[] = {CreateMockRead(resp, 1)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3263 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3264 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3265 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 3266 | BoundNetLog(), NULL); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3267 | helper.RunToCompletion(&data); |
| 3268 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3269 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_COMPRESSION_ERROR)); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3270 | } |
| 3271 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3272 | TEST_F(SpdyNetworkTransactionTest, GoAwayOnFrameSizeError) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3273 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3274 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3275 | SpdySerializedFrame goaway(spdy_util_.ConstructSpdyGoAway( |
bnc | 20df67c | 2016-04-07 01:36:18 | [diff] [blame] | 3276 | 0, GOAWAY_FRAME_SIZE_ERROR, |
dahollings | af379649 | 2016-05-25 19:21:35 | [diff] [blame] | 3277 | "Framer error: 15 (INVALID_CONTROL_FRAME_SIZE).")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3278 | MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(goaway, 2)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3279 | |
| 3280 | // Read WINDOW_UPDATE with incorrectly-sized payload. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3281 | SpdySerializedFrame bad_window_update( |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3282 | spdy_util_.ConstructSpdyWindowUpdate(1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3283 | test::SetFrameLength(&bad_window_update, bad_window_update.size() - 1, HTTP2); |
| 3284 | MockRead reads[] = {CreateMockRead(bad_window_update, 1)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3285 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3286 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3287 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 3288 | BoundNetLog(), NULL); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3289 | helper.RunToCompletion(&data); |
| 3290 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3291 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_FRAME_SIZE_ERROR)); |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3292 | } |
| 3293 | |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3294 | // Test that we shutdown correctly on write errors. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3295 | TEST_F(SpdyNetworkTransactionTest, WriteError) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3296 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3297 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3298 | MockWrite writes[] = { |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3299 | // We'll write 10 bytes successfully |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3300 | MockWrite(ASYNC, req.data(), 10, 1), |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3301 | // Followed by ERROR! |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3302 | MockWrite(ASYNC, ERR_FAILED, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 3303 | // Session drains and attempts to write a GOAWAY: Another ERROR! |
| 3304 | MockWrite(ASYNC, ERR_FAILED, 3), |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3305 | }; |
| 3306 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 3307 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3308 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 3309 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3310 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3311 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3312 | BoundNetLog(), NULL); |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3313 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 3314 | helper.AddData(&data); |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3315 | EXPECT_TRUE(helper.StartDefaultTest()); |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3316 | helper.FinishDefaultTest(); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 3317 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 3318 | EXPECT_TRUE(data.AllReadDataConsumed()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3319 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3320 | EXPECT_THAT(out.rv, IsError(ERR_FAILED)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3321 | } |
| 3322 | |
| 3323 | // Test that partial writes work. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3324 | TEST_F(SpdyNetworkTransactionTest, PartialWrite) { |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3325 | // Chop the HEADERS frame into 5 chunks. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3326 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3327 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3328 | const int kChunks = 5; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3329 | std::unique_ptr<MockWrite[]> writes(ChopWriteFrame(req, kChunks)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3330 | for (int i = 0; i < kChunks; ++i) { |
| 3331 | writes[i].sequence_number = i; |
| 3332 | } |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3333 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3334 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3335 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3336 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3337 | CreateMockRead(resp, kChunks), CreateMockRead(body, kChunks + 1), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3338 | MockRead(ASYNC, 0, kChunks + 2) // EOF |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3339 | }; |
| 3340 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3341 | SequencedSocketData data(reads, arraysize(reads), writes.get(), kChunks); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3342 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3343 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3344 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3345 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3346 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3347 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3348 | EXPECT_EQ("hello!", out.response_data); |
| 3349 | } |
| 3350 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 3351 | // Test that the NetLog contains good data for a simple GET request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3352 | TEST_F(SpdyNetworkTransactionTest, NetLog) { |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3353 | static const char* const kExtraHeaders[] = { |
| 3354 | "user-agent", "Chrome", |
| 3355 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3356 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3357 | spdy_util_.ConstructSpdyGet(kExtraHeaders, 1, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3358 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3359 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3360 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3361 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3362 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3363 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3364 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3365 | }; |
| 3366 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3367 | BoundTestNetLog log; |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3368 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3369 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3370 | NormalSpdyTransactionHelper helper(CreateGetRequestWithUserAgent(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3371 | DEFAULT_PRIORITY, log.bound(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3372 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3373 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3374 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3375 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3376 | EXPECT_EQ("hello!", out.response_data); |
| 3377 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 3378 | // Check that the NetLog was filled reasonably. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3379 | // This test is intentionally non-specific about the exact ordering of the |
| 3380 | // log; instead we just check to make sure that certain events exist, and that |
| 3381 | // they are in the right order. |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3382 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3383 | log.GetEntries(&entries); |
| 3384 | |
| 3385 | EXPECT_LT(0u, entries.size()); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3386 | int pos = 0; |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3387 | pos = ExpectLogContainsSomewhere( |
| 3388 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST, |
| 3389 | NetLogEventPhase::BEGIN); |
| 3390 | pos = ExpectLogContainsSomewhere( |
| 3391 | entries, pos + 1, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST, |
| 3392 | NetLogEventPhase::END); |
| 3393 | pos = ExpectLogContainsSomewhere( |
| 3394 | entries, pos + 1, NetLogEventType::HTTP_TRANSACTION_READ_HEADERS, |
| 3395 | NetLogEventPhase::BEGIN); |
| 3396 | pos = ExpectLogContainsSomewhere( |
| 3397 | entries, pos + 1, NetLogEventType::HTTP_TRANSACTION_READ_HEADERS, |
| 3398 | NetLogEventPhase::END); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3399 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3400 | NetLogEventType::HTTP_TRANSACTION_READ_BODY, |
| 3401 | NetLogEventPhase::BEGIN); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3402 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3403 | NetLogEventType::HTTP_TRANSACTION_READ_BODY, |
| 3404 | NetLogEventPhase::END); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3405 | |
| 3406 | // Check that we logged all the headers correctly |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3407 | pos = ExpectLogContainsSomewhere(entries, 0, |
| 3408 | NetLogEventType::HTTP2_SESSION_SEND_HEADERS, |
| 3409 | NetLogEventPhase::NONE); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3410 | |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 3411 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3412 | ASSERT_TRUE(entries[pos].params.get()); |
| 3413 | ASSERT_TRUE(entries[pos].params->GetList("headers", &header_list)); |
| 3414 | |
| 3415 | std::vector<std::string> expected; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3416 | expected.push_back(std::string(spdy_util_.GetHostKey()) + |
| 3417 | ": www.example.org"); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3418 | expected.push_back(std::string(spdy_util_.GetPathKey()) + ": /"); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 3419 | expected.push_back(std::string(spdy_util_.GetSchemeKey()) + ": " + |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 3420 | default_url_.scheme()); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3421 | expected.push_back(std::string(spdy_util_.GetMethodKey()) + ": GET"); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3422 | expected.push_back("user-agent: Chrome"); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3423 | EXPECT_EQ(expected.size(), header_list->GetSize()); |
| 3424 | for (std::vector<std::string>::const_iterator it = expected.begin(); |
| 3425 | it != expected.end(); |
| 3426 | ++it) { |
| 3427 | base::StringValue header(*it); |
| 3428 | EXPECT_NE(header_list->end(), header_list->Find(header)) << |
| 3429 | "Header not found: " << *it; |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3430 | } |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3431 | } |
| 3432 | |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3433 | // Since we buffer the IO from the stream to the renderer, this test verifies |
| 3434 | // that when we read out the maximum amount of data (e.g. we received 50 bytes |
| 3435 | // on the network, but issued a Read for only 5 of those bytes) that the data |
| 3436 | // flow still works correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3437 | TEST_F(SpdyNetworkTransactionTest, BufferFull) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3438 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3439 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3440 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3441 | |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3442 | // 2 data frames in a single read. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3443 | SpdySerializedFrame data_frame_1( |
| 3444 | spdy_util_.ConstructSpdyDataFrame(1, "goodby", 6, /*fin=*/false)); |
| 3445 | SpdySerializedFrame data_frame_2( |
| 3446 | spdy_util_.ConstructSpdyDataFrame(1, "e worl", 6, /*fin=*/false)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 3447 | const SpdySerializedFrame* data_frames[2] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3448 | &data_frame_1, &data_frame_2, |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3449 | }; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3450 | char combined_data_frames[100]; |
| 3451 | int combined_data_frames_len = |
| 3452 | CombineFrames(data_frames, arraysize(data_frames), |
| 3453 | combined_data_frames, arraysize(combined_data_frames)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3454 | SpdySerializedFrame last_frame( |
| 3455 | spdy_util_.ConstructSpdyDataFrame(1, "d", 1, /*fin=*/true)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3456 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3457 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3458 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3459 | CreateMockRead(resp, 1), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3460 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause |
| 3461 | MockRead(ASYNC, combined_data_frames, combined_data_frames_len, 3), |
| 3462 | MockRead(ASYNC, ERR_IO_PENDING, 4), // Force a pause |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3463 | CreateMockRead(last_frame, 5), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3464 | MockRead(ASYNC, 0, 6) // EOF |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3465 | }; |
| 3466 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3467 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3468 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3469 | TestCompletionCallback callback; |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3470 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3471 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3472 | BoundNetLog(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3473 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3474 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3475 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3476 | int rv = trans->Start( |
| 3477 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3478 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3479 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3480 | TransactionHelperResult out = helper.output(); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3481 | out.rv = callback.WaitForResult(); |
| 3482 | EXPECT_EQ(out.rv, OK); |
| 3483 | |
| 3484 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3485 | EXPECT_TRUE(response->headers); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3486 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3487 | out.status_line = response->headers->GetStatusLine(); |
| 3488 | out.response_info = *response; // Make a copy so we can verify. |
| 3489 | |
| 3490 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3491 | TestCompletionCallback read_callback; |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3492 | |
| 3493 | std::string content; |
| 3494 | do { |
| 3495 | // Read small chunks at a time. |
| 3496 | const int kSmallReadSize = 3; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3497 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3498 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3499 | if (rv == ERR_IO_PENDING) { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 3500 | data.Resume(); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3501 | rv = read_callback.WaitForResult(); |
| 3502 | } |
| 3503 | if (rv > 0) { |
| 3504 | content.append(buf->data(), rv); |
| 3505 | } else if (rv < 0) { |
| 3506 | NOTREACHED(); |
| 3507 | } |
| 3508 | } while (rv > 0); |
| 3509 | |
| 3510 | out.response_data.swap(content); |
| 3511 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3512 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3513 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3514 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3515 | |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3516 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3517 | helper.VerifyDataConsumed(); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3518 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3519 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3520 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3521 | EXPECT_EQ("goodbye world", out.response_data); |
| 3522 | } |
| 3523 | |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3524 | // Verify that basic buffering works; when multiple data frames arrive |
| 3525 | // at the same time, ensure that we don't notify a read completion for |
| 3526 | // each data frame individually. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3527 | TEST_F(SpdyNetworkTransactionTest, Buffering) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3528 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3529 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3530 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3531 | |
| 3532 | // 4 data frames in a single read. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3533 | SpdySerializedFrame data_frame( |
| 3534 | spdy_util_.ConstructSpdyDataFrame(1, "message", 7, /*fin=*/false)); |
| 3535 | SpdySerializedFrame data_frame_fin( |
| 3536 | spdy_util_.ConstructSpdyDataFrame(1, "message", 7, /*fin=*/true)); |
| 3537 | const SpdySerializedFrame* data_frames[4] = {&data_frame, &data_frame, |
| 3538 | &data_frame, &data_frame_fin}; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3539 | char combined_data_frames[100]; |
| 3540 | int combined_data_frames_len = |
| 3541 | CombineFrames(data_frames, arraysize(data_frames), |
| 3542 | combined_data_frames, arraysize(combined_data_frames)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3543 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3544 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3545 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3546 | CreateMockRead(resp, 1), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3547 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause |
| 3548 | MockRead(ASYNC, combined_data_frames, combined_data_frames_len, 3), |
| 3549 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3550 | }; |
| 3551 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3552 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3553 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3554 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3555 | BoundNetLog(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3556 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3557 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3558 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3559 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3560 | TestCompletionCallback callback; |
| 3561 | int rv = trans->Start( |
| 3562 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3563 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3564 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3565 | TransactionHelperResult out = helper.output(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3566 | out.rv = callback.WaitForResult(); |
| 3567 | EXPECT_EQ(out.rv, OK); |
| 3568 | |
| 3569 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3570 | EXPECT_TRUE(response->headers); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3571 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3572 | out.status_line = response->headers->GetStatusLine(); |
| 3573 | out.response_info = *response; // Make a copy so we can verify. |
| 3574 | |
| 3575 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3576 | TestCompletionCallback read_callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3577 | |
| 3578 | std::string content; |
| 3579 | int reads_completed = 0; |
| 3580 | do { |
| 3581 | // Read small chunks at a time. |
| 3582 | const int kSmallReadSize = 14; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3583 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3584 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3585 | if (rv == ERR_IO_PENDING) { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 3586 | data.Resume(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3587 | rv = read_callback.WaitForResult(); |
| 3588 | } |
| 3589 | if (rv > 0) { |
| 3590 | EXPECT_EQ(kSmallReadSize, rv); |
| 3591 | content.append(buf->data(), rv); |
| 3592 | } else if (rv < 0) { |
| 3593 | FAIL() << "Unexpected read error: " << rv; |
| 3594 | } |
| 3595 | reads_completed++; |
| 3596 | } while (rv > 0); |
| 3597 | |
| 3598 | EXPECT_EQ(3, reads_completed); // Reads are: 14 bytes, 14 bytes, 0 bytes. |
| 3599 | |
| 3600 | out.response_data.swap(content); |
| 3601 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3602 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3603 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3604 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3605 | |
| 3606 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3607 | helper.VerifyDataConsumed(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3608 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3609 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3610 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3611 | EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 3612 | } |
| 3613 | |
| 3614 | // Verify the case where we buffer data but read it after it has been buffered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3615 | TEST_F(SpdyNetworkTransactionTest, BufferedAll) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3616 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3617 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3618 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3619 | |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3620 | // 5 data frames in a single read. |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3621 | SpdySerializedFrame reply(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3622 | SpdySerializedFrame data_frame( |
| 3623 | spdy_util_.ConstructSpdyDataFrame(1, "message", 7, /*fin=*/false)); |
| 3624 | SpdySerializedFrame data_frame_fin( |
| 3625 | spdy_util_.ConstructSpdyDataFrame(1, "message", 7, /*fin=*/true)); |
| 3626 | const SpdySerializedFrame* frames[5] = {&reply, &data_frame, &data_frame, |
| 3627 | &data_frame, &data_frame_fin}; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3628 | char combined_frames[200]; |
| 3629 | int combined_frames_len = |
| 3630 | CombineFrames(frames, arraysize(frames), |
| 3631 | combined_frames, arraysize(combined_frames)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3632 | |
| 3633 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3634 | MockRead(ASYNC, combined_frames, combined_frames_len, 1), |
| 3635 | MockRead(ASYNC, 0, 2) // EOF |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3636 | }; |
| 3637 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3638 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3639 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3640 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3641 | BoundNetLog(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3642 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3643 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3644 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3645 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3646 | TestCompletionCallback callback; |
| 3647 | int rv = trans->Start( |
| 3648 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3649 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3650 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3651 | TransactionHelperResult out = helper.output(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3652 | out.rv = callback.WaitForResult(); |
| 3653 | EXPECT_EQ(out.rv, OK); |
| 3654 | |
| 3655 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3656 | EXPECT_TRUE(response->headers); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3657 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3658 | out.status_line = response->headers->GetStatusLine(); |
| 3659 | out.response_info = *response; // Make a copy so we can verify. |
| 3660 | |
| 3661 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3662 | TestCompletionCallback read_callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3663 | |
| 3664 | std::string content; |
| 3665 | int reads_completed = 0; |
| 3666 | do { |
| 3667 | // Read small chunks at a time. |
| 3668 | const int kSmallReadSize = 14; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3669 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3670 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3671 | if (rv > 0) { |
| 3672 | EXPECT_EQ(kSmallReadSize, rv); |
| 3673 | content.append(buf->data(), rv); |
| 3674 | } else if (rv < 0) { |
| 3675 | FAIL() << "Unexpected read error: " << rv; |
| 3676 | } |
| 3677 | reads_completed++; |
| 3678 | } while (rv > 0); |
| 3679 | |
| 3680 | EXPECT_EQ(3, reads_completed); |
| 3681 | |
| 3682 | out.response_data.swap(content); |
| 3683 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3684 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3685 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3686 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3687 | |
| 3688 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3689 | helper.VerifyDataConsumed(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3690 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3691 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3692 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3693 | EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 3694 | } |
| 3695 | |
| 3696 | // Verify the case where we buffer data and close the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3697 | TEST_F(SpdyNetworkTransactionTest, BufferedClosed) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3698 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3699 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3700 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3701 | |
| 3702 | // All data frames in a single read. |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3703 | // NOTE: We don't FIN the stream. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3704 | SpdySerializedFrame data_frame( |
| 3705 | spdy_util_.ConstructSpdyDataFrame(1, "message", 7, /*fin=*/false)); |
| 3706 | const SpdySerializedFrame* data_frames[4] = {&data_frame, &data_frame, |
| 3707 | &data_frame, &data_frame}; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3708 | char combined_data_frames[100]; |
| 3709 | int combined_data_frames_len = |
| 3710 | CombineFrames(data_frames, arraysize(data_frames), |
| 3711 | combined_data_frames, arraysize(combined_data_frames)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3712 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3713 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3714 | CreateMockRead(resp, 1), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3715 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a wait |
| 3716 | MockRead(ASYNC, combined_data_frames, combined_data_frames_len, 3), |
| 3717 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3718 | }; |
| 3719 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3720 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3721 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3722 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3723 | BoundNetLog(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3724 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3725 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3726 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3727 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3728 | TestCompletionCallback callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3729 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3730 | int rv = trans->Start( |
| 3731 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3732 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3733 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3734 | TransactionHelperResult out = helper.output(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3735 | out.rv = callback.WaitForResult(); |
| 3736 | EXPECT_EQ(out.rv, OK); |
| 3737 | |
| 3738 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3739 | EXPECT_TRUE(response->headers); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3740 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3741 | out.status_line = response->headers->GetStatusLine(); |
| 3742 | out.response_info = *response; // Make a copy so we can verify. |
| 3743 | |
| 3744 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3745 | TestCompletionCallback read_callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3746 | |
| 3747 | std::string content; |
| 3748 | int reads_completed = 0; |
| 3749 | do { |
| 3750 | // Read small chunks at a time. |
| 3751 | const int kSmallReadSize = 14; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3752 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3753 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3754 | if (rv == ERR_IO_PENDING) { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 3755 | data.Resume(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3756 | rv = read_callback.WaitForResult(); |
| 3757 | } |
| 3758 | if (rv > 0) { |
| 3759 | content.append(buf->data(), rv); |
| 3760 | } else if (rv < 0) { |
| 3761 | // This test intentionally closes the connection, and will get an error. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3762 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3763 | break; |
| 3764 | } |
| 3765 | reads_completed++; |
| 3766 | } while (rv > 0); |
| 3767 | |
| 3768 | EXPECT_EQ(0, reads_completed); |
| 3769 | |
| 3770 | out.response_data.swap(content); |
| 3771 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3772 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3773 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3774 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3775 | |
| 3776 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3777 | helper.VerifyDataConsumed(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3778 | } |
| 3779 | |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3780 | // Verify the case where we buffer data and cancel the transaction. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3781 | TEST_F(SpdyNetworkTransactionTest, BufferedCancelled) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3782 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3783 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3784 | SpdySerializedFrame rst( |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 3785 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3786 | MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(rst, 4)}; |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3787 | |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3788 | // NOTE: We don't FIN the stream. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3789 | SpdySerializedFrame data_frame( |
| 3790 | spdy_util_.ConstructSpdyDataFrame(1, "message", 7, /*fin=*/false)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3791 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3792 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3793 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3794 | CreateMockRead(resp, 1), |
| 3795 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a wait |
| 3796 | CreateMockRead(data_frame, 3), MockRead(ASYNC, 0, 5) // EOF |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3797 | }; |
| 3798 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3799 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3800 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3801 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3802 | BoundNetLog(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3803 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3804 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3805 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3806 | TestCompletionCallback callback; |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3807 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3808 | int rv = trans->Start( |
| 3809 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3810 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3811 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3812 | TransactionHelperResult out = helper.output(); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3813 | out.rv = callback.WaitForResult(); |
| 3814 | EXPECT_EQ(out.rv, OK); |
| 3815 | |
| 3816 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3817 | EXPECT_TRUE(response->headers); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3818 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3819 | out.status_line = response->headers->GetStatusLine(); |
| 3820 | out.response_info = *response; // Make a copy so we can verify. |
| 3821 | |
| 3822 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3823 | TestCompletionCallback read_callback; |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3824 | |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 3825 | const int kReadSize = 256; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3826 | scoped_refptr<IOBuffer> buf(new IOBuffer(kReadSize)); |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 3827 | rv = trans->Read(buf.get(), kReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3828 | ASSERT_EQ(ERR_IO_PENDING, rv) << "Unexpected read: " << rv; |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 3829 | |
| 3830 | // Complete the read now, which causes buffering to start. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 3831 | data.Resume(); |
| 3832 | base::RunLoop().RunUntilIdle(); |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 3833 | // Destroy the transaction, causing the stream to get cancelled |
| 3834 | // and orphaning the buffered IO task. |
| 3835 | helper.ResetTrans(); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3836 | |
| 3837 | // Flush the MessageLoop; this will cause the buffered IO task |
| 3838 | // to run for the final time. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3839 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3840 | |
| 3841 | // Verify that we consumed all test data. |
| 3842 | helper.VerifyDataConsumed(); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3843 | } |
| 3844 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3845 | TEST_F(SpdyNetworkTransactionTest, GoAwayWithActiveStream) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3846 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3847 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3848 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 69d717bd | 2010-04-21 18:43:21 | [diff] [blame] | 3849 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3850 | SpdySerializedFrame go_away(spdy_util_.ConstructSpdyGoAway()); |
[email protected] | 69d717bd | 2010-04-21 18:43:21 | [diff] [blame] | 3851 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3852 | CreateMockRead(go_away, 1), |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 3853 | }; |
| 3854 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3855 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3856 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3857 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3858 | helper.AddData(&data); |
| 3859 | helper.RunToCompletion(&data); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 3860 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3861 | EXPECT_THAT(out.rv, IsError(ERR_ABORTED)); |
[email protected] | 69d717bd | 2010-04-21 18:43:21 | [diff] [blame] | 3862 | } |
| 3863 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3864 | TEST_F(SpdyNetworkTransactionTest, CloseWithActiveStream) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3865 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3866 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3867 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 3868 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3869 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 3870 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3871 | CreateMockRead(resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 3872 | }; |
| 3873 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3874 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
bnc | 4d782f49 | 2016-08-18 13:50:00 | [diff] [blame] | 3875 | |
| 3876 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 3877 | BoundNetLog(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3878 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3879 | helper.AddData(&data); |
bnc | 4d782f49 | 2016-08-18 13:50:00 | [diff] [blame] | 3880 | helper.StartDefaultTest(); |
| 3881 | EXPECT_THAT(helper.output().rv, IsError(ERR_IO_PENDING)); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 3882 | |
bnc | 4d782f49 | 2016-08-18 13:50:00 | [diff] [blame] | 3883 | helper.WaitForCallbackToComplete(); |
| 3884 | EXPECT_THAT(helper.output().rv, IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3885 | |
bnc | 4d782f49 | 2016-08-18 13:50:00 | [diff] [blame] | 3886 | const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3887 | EXPECT_TRUE(response->headers); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 3888 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 3889 | |
| 3890 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3891 | helper.VerifyDataConsumed(); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 3892 | } |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 3893 | |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3894 | // Retry with HTTP/1.1 when receiving HTTP_1_1_REQUIRED. Note that no actual |
| 3895 | // protocol negotiation happens, instead this test forces protocols for both |
| 3896 | // sockets. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3897 | TEST_F(SpdyNetworkTransactionTest, HTTP11RequiredRetry) { |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3898 | HttpRequestInfo request; |
| 3899 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 3900 | request.url = default_url_; |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3901 | // Do not force SPDY so that second socket can negotiate HTTP/1.1. |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3902 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3903 | nullptr); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3904 | |
| 3905 | // First socket: HTTP/2 request rejected with HTTP_1_1_REQUIRED. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 3906 | SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3907 | SpdySerializedFrame req( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3908 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3909 | MockWrite writes0[] = {CreateMockWrite(req, 0)}; |
| 3910 | SpdySerializedFrame go_away(spdy_util_.ConstructSpdyGoAway( |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3911 | 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3912 | MockRead reads0[] = {CreateMockRead(go_away, 1)}; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3913 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 3914 | arraysize(writes0)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3915 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 3916 | std::unique_ptr<SSLSocketDataProvider> ssl_provider0( |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3917 | new SSLSocketDataProvider(ASYNC, OK)); |
| 3918 | // Expect HTTP/2 protocols too in SSLConfig. |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 3919 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP2); |
bnc | 3f0118e | 2016-02-02 15:42:22 | [diff] [blame] | 3920 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3921 | // Force SPDY. |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 3922 | ssl_provider0->next_proto = kProtoHTTP2; |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3923 | helper.AddDataWithSSLSocketDataProvider(&data0, std::move(ssl_provider0)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3924 | |
| 3925 | // Second socket: falling back to HTTP/1.1. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3926 | MockWrite writes1[] = {MockWrite(ASYNC, 0, |
| 3927 | "GET / HTTP/1.1\r\n" |
| 3928 | "Host: www.example.org\r\n" |
| 3929 | "Connection: keep-alive\r\n\r\n")}; |
| 3930 | MockRead reads1[] = {MockRead(ASYNC, 1, |
| 3931 | "HTTP/1.1 200 OK\r\n" |
| 3932 | "Content-Length: 5\r\n\r\n" |
| 3933 | "hello")}; |
| 3934 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 3935 | arraysize(writes1)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3936 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 3937 | std::unique_ptr<SSLSocketDataProvider> ssl_provider1( |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3938 | new SSLSocketDataProvider(ASYNC, OK)); |
| 3939 | // Expect only HTTP/1.1 protocol in SSLConfig. |
| 3940 | ssl_provider1->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 3941 | // Force HTTP/1.1. |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 3942 | ssl_provider1->next_proto = kProtoHTTP11; |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3943 | helper.AddDataWithSSLSocketDataProvider(&data1, std::move(ssl_provider1)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3944 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 3945 | HttpServerProperties* http_server_properties = |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3946 | helper.session()->spdy_session_pool()->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 3947 | EXPECT_FALSE(http_server_properties->RequiresHTTP11(host_port_pair_)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3948 | |
| 3949 | helper.RunPreTestSetup(); |
| 3950 | helper.StartDefaultTest(); |
| 3951 | helper.FinishDefaultTestWithoutVerification(); |
| 3952 | helper.VerifyDataConsumed(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 3953 | EXPECT_TRUE(http_server_properties->RequiresHTTP11(host_port_pair_)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3954 | |
| 3955 | const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3956 | ASSERT_TRUE(response); |
| 3957 | ASSERT_TRUE(response->headers); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3958 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3959 | EXPECT_FALSE(response->was_fetched_via_spdy); |
mmenke | 8210acc | 2016-07-11 16:34:52 | [diff] [blame] | 3960 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1_1, |
| 3961 | response->connection_info); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3962 | EXPECT_TRUE(response->was_npn_negotiated); |
| 3963 | EXPECT_TRUE(request.url.SchemeIs("https")); |
| 3964 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 3965 | EXPECT_EQ(443, response->socket_address.port()); |
| 3966 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3967 | ASSERT_THAT(ReadTransaction(helper.trans(), &response_data), IsOk()); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3968 | EXPECT_EQ("hello", response_data); |
| 3969 | } |
| 3970 | |
| 3971 | // Retry with HTTP/1.1 to the proxy when receiving HTTP_1_1_REQUIRED from the |
| 3972 | // proxy. Note that no actual protocol negotiation happens, instead this test |
| 3973 | // forces protocols for both sockets. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3974 | TEST_F(SpdyNetworkTransactionTest, HTTP11RequiredProxyRetry) { |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3975 | HttpRequestInfo request; |
| 3976 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 3977 | request.url = default_url_; |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3978 | auto session_deps = base::MakeUnique<SpdySessionDependencies>( |
| 3979 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3980 | // Do not force SPDY so that second socket can negotiate HTTP/1.1. |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3981 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3982 | std::move(session_deps)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3983 | |
| 3984 | // First socket: HTTP/2 CONNECT rejected with HTTP_1_1_REQUIRED. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3985 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3986 | nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3987 | MockWrite writes0[] = {CreateMockWrite(req, 0)}; |
| 3988 | SpdySerializedFrame go_away(spdy_util_.ConstructSpdyGoAway( |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3989 | 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3990 | MockRead reads0[] = {CreateMockRead(go_away, 1)}; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3991 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 3992 | arraysize(writes0)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3993 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 3994 | std::unique_ptr<SSLSocketDataProvider> ssl_provider0( |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3995 | new SSLSocketDataProvider(ASYNC, OK)); |
| 3996 | // Expect HTTP/2 protocols too in SSLConfig. |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 3997 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP2); |
bnc | 3f0118e | 2016-02-02 15:42:22 | [diff] [blame] | 3998 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3999 | // Force SPDY. |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4000 | ssl_provider0->next_proto = kProtoHTTP2; |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4001 | helper.AddDataWithSSLSocketDataProvider(&data0, std::move(ssl_provider0)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4002 | |
| 4003 | // Second socket: retry using HTTP/1.1. |
| 4004 | MockWrite writes1[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4005 | MockWrite(ASYNC, 0, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4006 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4007 | "Host: www.example.org:443\r\n" |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4008 | "Proxy-Connection: keep-alive\r\n\r\n"), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4009 | MockWrite(ASYNC, 2, |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4010 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4011 | "Host: www.example.org\r\n" |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4012 | "Connection: keep-alive\r\n\r\n"), |
| 4013 | }; |
| 4014 | |
| 4015 | MockRead reads1[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4016 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 4017 | MockRead(ASYNC, 3, |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4018 | "HTTP/1.1 200 OK\r\n" |
| 4019 | "Content-Length: 5\r\n\r\n" |
| 4020 | "hello"), |
| 4021 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4022 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 4023 | arraysize(writes1)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4024 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 4025 | std::unique_ptr<SSLSocketDataProvider> ssl_provider1( |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4026 | new SSLSocketDataProvider(ASYNC, OK)); |
| 4027 | // Expect only HTTP/1.1 protocol in SSLConfig. |
| 4028 | ssl_provider1->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4029 | // Force HTTP/1.1. |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4030 | ssl_provider1->next_proto = kProtoHTTP11; |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4031 | helper.AddDataWithSSLSocketDataProvider(&data1, std::move(ssl_provider1)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4032 | |
| 4033 | // A third socket is needed for the tunnelled connection. |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 4034 | std::unique_ptr<SSLSocketDataProvider> ssl_provider2( |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4035 | new SSLSocketDataProvider(ASYNC, OK)); |
| 4036 | helper.session_deps()->socket_factory->AddSSLSocketDataProvider( |
| 4037 | ssl_provider2.get()); |
| 4038 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 4039 | HttpServerProperties* http_server_properties = |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4040 | helper.session()->spdy_session_pool()->http_server_properties(); |
| 4041 | const HostPortPair proxy_host_port_pair = HostPortPair("myproxy", 70); |
| 4042 | EXPECT_FALSE(http_server_properties->RequiresHTTP11(proxy_host_port_pair)); |
| 4043 | |
| 4044 | helper.RunPreTestSetup(); |
| 4045 | helper.StartDefaultTest(); |
| 4046 | helper.FinishDefaultTestWithoutVerification(); |
| 4047 | helper.VerifyDataConsumed(); |
| 4048 | EXPECT_TRUE(http_server_properties->RequiresHTTP11(proxy_host_port_pair)); |
| 4049 | |
| 4050 | const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4051 | ASSERT_TRUE(response); |
| 4052 | ASSERT_TRUE(response->headers); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4053 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4054 | EXPECT_FALSE(response->was_fetched_via_spdy); |
mmenke | 8210acc | 2016-07-11 16:34:52 | [diff] [blame] | 4055 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1_1, |
| 4056 | response->connection_info); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4057 | EXPECT_FALSE(response->was_npn_negotiated); |
| 4058 | EXPECT_TRUE(request.url.SchemeIs("https")); |
| 4059 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 4060 | EXPECT_EQ(70, response->socket_address.port()); |
| 4061 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4062 | ASSERT_THAT(ReadTransaction(helper.trans(), &response_data), IsOk()); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4063 | EXPECT_EQ("hello", response_data); |
| 4064 | } |
| 4065 | |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4066 | // Test to make sure we can correctly connect through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4067 | TEST_F(SpdyNetworkTransactionTest, ProxyConnect) { |
| 4068 | auto session_deps = base::MakeUnique<SpdySessionDependencies>( |
| 4069 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4070 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4071 | BoundNetLog(), std::move(session_deps)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4072 | helper.RunPreTestSetup(); |
| 4073 | HttpNetworkTransaction* trans = helper.trans(); |
| 4074 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4075 | const char kConnect443[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4076 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4077 | "Host: www.example.org:443\r\n" |
rch | cb934f56 | 2015-04-07 16:25:12 | [diff] [blame] | 4078 | "Proxy-Connection: keep-alive\r\n\r\n"}; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4079 | const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4080 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4081 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4082 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4083 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4084 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4085 | MockWrite writes[] = { |
| 4086 | MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4087 | CreateMockWrite(req, 2), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4088 | }; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4089 | MockRead reads[] = { |
| 4090 | MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4091 | CreateMockRead(resp, 3), CreateMockRead(body, 4), |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4092 | MockRead(ASYNC, 0, 0, 5), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4093 | }; |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 4094 | std::unique_ptr<SequencedSocketData> data(new SequencedSocketData( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4095 | reads, arraysize(reads), writes, arraysize(writes))); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4096 | |
| 4097 | helper.AddData(data.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4098 | TestCompletionCallback callback; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4099 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4100 | int rv = trans->Start( |
| 4101 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4102 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4103 | |
| 4104 | rv = callback.WaitForResult(); |
| 4105 | EXPECT_EQ(0, rv); |
| 4106 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4107 | // Verify the response headers. |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4108 | HttpResponseInfo response = *trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4109 | ASSERT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4110 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4111 | |
| 4112 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4113 | ASSERT_THAT(ReadTransaction(trans, &response_data), IsOk()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4114 | EXPECT_EQ("hello!", response_data); |
| 4115 | helper.VerifyDataConsumed(); |
| 4116 | } |
| 4117 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4118 | // Test to make sure we can correctly connect through a proxy to |
| 4119 | // www.example.org, if there already exists a direct spdy connection to |
| 4120 | // www.example.org. See https://crbug.com/49874. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4121 | TEST_F(SpdyNetworkTransactionTest, DirectConnectProxyReconnect) { |
[email protected] | 733b7a6d | 2010-08-25 01:38:43 | [diff] [blame] | 4122 | // Use a proxy service which returns a proxy fallback list from DIRECT to |
| 4123 | // myproxy:70. For this test there will be no fallback, so it is equivalent |
| 4124 | // to simply DIRECT. The reason for appending the second proxy is to verify |
| 4125 | // that the session pool key used does is just "DIRECT". |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4126 | auto session_deps = base::MakeUnique<SpdySessionDependencies>( |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4127 | ProxyService::CreateFixedFromPacResult("DIRECT; PROXY myproxy:70")); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4128 | // When setting up the first transaction, we store the SpdySessionPool so that |
| 4129 | // we can use the same pool in the second transaction. |
| 4130 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 4131 | BoundNetLog(), std::move(session_deps)); |
[email protected] | 733b7a6d | 2010-08-25 01:38:43 | [diff] [blame] | 4132 | |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 4133 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4134 | helper.RunPreTestSetup(); |
| 4135 | |
| 4136 | // Construct and send a simple GET request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4137 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4138 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4139 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4140 | CreateMockWrite(req, 0), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4141 | }; |
| 4142 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4143 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4144 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4145 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4146 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4147 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), // Force a pause |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4148 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4149 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4150 | helper.AddData(&data); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4151 | HttpNetworkTransaction* trans = helper.trans(); |
| 4152 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4153 | TestCompletionCallback callback; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4154 | TransactionHelperResult out; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4155 | out.rv = trans->Start( |
| 4156 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4157 | |
| 4158 | EXPECT_EQ(out.rv, ERR_IO_PENDING); |
| 4159 | out.rv = callback.WaitForResult(); |
| 4160 | EXPECT_EQ(out.rv, OK); |
| 4161 | |
| 4162 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4163 | EXPECT_TRUE(response->headers); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4164 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4165 | out.rv = ReadTransaction(trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4166 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4167 | out.status_line = response->headers->GetStatusLine(); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4168 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4169 | EXPECT_EQ("hello!", out.response_data); |
| 4170 | |
| 4171 | // Check that the SpdySession is still in the SpdySessionPool. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4172 | SpdySessionKey session_pool_key_direct(host_port_pair_, ProxyServer::Direct(), |
| 4173 | PRIVACY_MODE_DISABLED); |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 4174 | EXPECT_TRUE(HasSpdySession(spdy_session_pool, session_pool_key_direct)); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 4175 | SpdySessionKey session_pool_key_proxy( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4176 | host_port_pair_, |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 4177 | ProxyServer::FromURI("www.foo.com", ProxyServer::SCHEME_HTTP), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 4178 | PRIVACY_MODE_DISABLED); |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 4179 | EXPECT_FALSE(HasSpdySession(spdy_session_pool, session_pool_key_proxy)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4180 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4181 | // New SpdyTestUtil instance for the session that will be used for the |
| 4182 | // proxy connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4183 | SpdyTestUtil spdy_util_2; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4184 | |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4185 | // Set up data for the proxy connection. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4186 | const char kConnect443[] = { |
| 4187 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4188 | "Host: www.example.org:443\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4189 | "Proxy-Connection: keep-alive\r\n\r\n"}; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4190 | const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4191 | SpdySerializedFrame req2(spdy_util_2.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4192 | GetDefaultUrlWithPath("/foo.dat").c_str(), 1, LOWEST)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4193 | SpdySerializedFrame resp2(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4194 | SpdySerializedFrame body2(spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4195 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4196 | MockWrite writes2[] = { |
| 4197 | MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4198 | CreateMockWrite(req2, 2), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4199 | }; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4200 | MockRead reads2[] = { |
| 4201 | MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4202 | CreateMockRead(resp2, 3), CreateMockRead(body2, 4), |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4203 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4204 | }; |
| 4205 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 4206 | std::unique_ptr<SequencedSocketData> data_proxy(new SequencedSocketData( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4207 | reads2, arraysize(reads2), writes2, arraysize(writes2))); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4208 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4209 | // Create another request to www.example.org, but this time through a proxy. |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4210 | HttpRequestInfo request_proxy; |
| 4211 | request_proxy.method = "GET"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4212 | request_proxy.url = GURL(GetDefaultUrlWithPath("/foo.dat")); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4213 | request_proxy.load_flags = 0; |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4214 | auto session_deps_proxy = base::MakeUnique<SpdySessionDependencies>( |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4215 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4216 | NormalSpdyTransactionHelper helper_proxy(request_proxy, DEFAULT_PRIORITY, |
| 4217 | BoundNetLog(), |
| 4218 | std::move(session_deps_proxy)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4219 | helper_proxy.RunPreTestSetup(); |
| 4220 | helper_proxy.AddData(data_proxy.get()); |
| 4221 | |
| 4222 | HttpNetworkTransaction* trans_proxy = helper_proxy.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4223 | TestCompletionCallback callback_proxy; |
| 4224 | int rv = trans_proxy->Start( |
| 4225 | &request_proxy, callback_proxy.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4226 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4227 | rv = callback_proxy.WaitForResult(); |
| 4228 | EXPECT_EQ(0, rv); |
| 4229 | |
| 4230 | HttpResponseInfo response_proxy = *trans_proxy->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4231 | ASSERT_TRUE(response_proxy.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4232 | EXPECT_EQ("HTTP/1.1 200", response_proxy.headers->GetStatusLine()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4233 | |
| 4234 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4235 | ASSERT_THAT(ReadTransaction(trans_proxy, &response_data), IsOk()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4236 | EXPECT_EQ("hello!", response_data); |
| 4237 | |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4238 | helper_proxy.VerifyDataConsumed(); |
| 4239 | } |
| 4240 | |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4241 | // When we get a TCP-level RST, we need to retry a HttpNetworkTransaction |
| 4242 | // on a new connection, if the connection was previously known to be good. |
| 4243 | // This can happen when a server reboots without saying goodbye, or when |
| 4244 | // we're behind a NAT that masked the RST. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4245 | TEST_F(SpdyNetworkTransactionTest, VerifyRetryOnConnectionReset) { |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4246 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4247 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4248 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4249 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4250 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 4251 | MockRead(ASYNC, ERR_CONNECTION_RESET, 4), |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4252 | }; |
| 4253 | |
| 4254 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4255 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4256 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4257 | }; |
| 4258 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4259 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4260 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4261 | // In all cases the connection will be reset before req3 can be |
| 4262 | // dispatched, destroying both streams. |
| 4263 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4264 | SpdySerializedFrame req3( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4265 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4266 | MockWrite writes1[] = {CreateMockWrite(req, 0), CreateMockWrite(req3, 5)}; |
| 4267 | MockWrite writes2[] = {CreateMockWrite(req, 0)}; |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4268 | |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4269 | // This test has a couple of variants. |
| 4270 | enum { |
| 4271 | // Induce the RST while waiting for our transaction to send. |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4272 | VARIANT_RST_DURING_SEND_COMPLETION = 0, |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4273 | // Induce the RST while waiting for our transaction to read. |
| 4274 | // In this case, the send completed - everything copied into the SNDBUF. |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4275 | VARIANT_RST_DURING_READ_COMPLETION = 1 |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4276 | }; |
| 4277 | |
| 4278 | for (int variant = VARIANT_RST_DURING_SEND_COMPLETION; |
| 4279 | variant <= VARIANT_RST_DURING_READ_COMPLETION; |
| 4280 | ++variant) { |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4281 | SequencedSocketData data1(reads, arraysize(reads), writes1, 1 + variant); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4282 | |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4283 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 4284 | arraysize(writes2)); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4285 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4286 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4287 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4288 | helper.AddData(&data1); |
| 4289 | helper.AddData(&data2); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4290 | helper.RunPreTestSetup(); |
| 4291 | |
| 4292 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4293 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, helper.session()); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4294 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4295 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4296 | int rv = |
| 4297 | trans.Start(&helper.request(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4298 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4299 | // On the second transaction, we trigger the RST. |
| 4300 | if (i == 1) { |
| 4301 | if (variant == VARIANT_RST_DURING_READ_COMPLETION) { |
| 4302 | // Writes to the socket complete asynchronously on SPDY by running |
| 4303 | // through the message loop. Complete the write here. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4304 | base::RunLoop().RunUntilIdle(); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4305 | } |
| 4306 | |
| 4307 | // Now schedule the ERR_CONNECTION_RESET. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 4308 | data1.Resume(); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4309 | } |
| 4310 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4311 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4312 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4313 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4314 | ASSERT_TRUE(response); |
| 4315 | EXPECT_TRUE(response->headers); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4316 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4317 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4318 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4319 | EXPECT_THAT(rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4320 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4321 | EXPECT_EQ("hello!", response_data); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4322 | base::RunLoop().RunUntilIdle(); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4323 | } |
| 4324 | |
| 4325 | helper.VerifyDataConsumed(); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4326 | base::RunLoop().RunUntilIdle(); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4327 | } |
| 4328 | } |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4329 | |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4330 | // Tests that Basic authentication works over SPDY |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4331 | TEST_F(SpdyNetworkTransactionTest, SpdyBasicAuth) { |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4332 | // The first request will be a bare GET, the second request will be a |
| 4333 | // GET with an Authorization header. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4334 | SpdySerializedFrame req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4335 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4336 | // Will be refused for lack of auth. |
| 4337 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4338 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4339 | "authorization", "Basic Zm9vOmJhcg==" |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4340 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4341 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 4342 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 4343 | LOWEST, true)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4344 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4345 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4346 | }; |
| 4347 | |
| 4348 | // The first response is a 401 authentication challenge, and the second |
| 4349 | // response will be a 200 response since the second request includes a valid |
| 4350 | // Authorization header. |
| 4351 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | fb9e431 | 2012-02-17 06:27:26 | [diff] [blame] | 4352 | "www-authenticate", |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4353 | "Basic realm=\"MyRealm\"" |
| 4354 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4355 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4356 | "401 Authentication Required", kExtraAuthenticationHeaders, |
| 4357 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 4358 | SpdySerializedFrame body_authentication( |
| 4359 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4360 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4361 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4362 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4363 | CreateMockRead(resp_authentication, 1), |
| 4364 | CreateMockRead(body_authentication, 2), |
| 4365 | CreateMockRead(resp_data, 4), |
| 4366 | CreateMockRead(body_data, 5), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4367 | MockRead(ASYNC, 0, 6), |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4368 | }; |
| 4369 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4370 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4371 | arraysize(spdy_writes)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4372 | HttpRequestInfo request(CreateGetRequest()); |
bnc | 4d782f49 | 2016-08-18 13:50:00 | [diff] [blame] | 4373 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 4374 | NULL); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4375 | |
| 4376 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4377 | helper.AddData(&data); |
bnc | 4d782f49 | 2016-08-18 13:50:00 | [diff] [blame] | 4378 | helper.StartDefaultTest(); |
| 4379 | EXPECT_THAT(helper.output().rv, IsError(ERR_IO_PENDING)); |
| 4380 | |
| 4381 | helper.WaitForCallbackToComplete(); |
| 4382 | EXPECT_THAT(helper.output().rv, IsOk()); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4383 | |
| 4384 | // Make sure the response has an auth challenge. |
bnc | 4d782f49 | 2016-08-18 13:50:00 | [diff] [blame] | 4385 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4386 | const HttpResponseInfo* const response_start = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4387 | ASSERT_TRUE(response_start); |
| 4388 | ASSERT_TRUE(response_start->headers); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4389 | EXPECT_EQ(401, response_start->headers->response_code()); |
| 4390 | EXPECT_TRUE(response_start->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4391 | AuthChallengeInfo* auth_challenge = response_start->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4392 | ASSERT_TRUE(auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4393 | EXPECT_FALSE(auth_challenge->is_proxy); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 4394 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4395 | EXPECT_EQ("MyRealm", auth_challenge->realm); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4396 | |
| 4397 | // Restart with a username/password. |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 4398 | AuthCredentials credentials(base::ASCIIToUTF16("foo"), |
| 4399 | base::ASCIIToUTF16("bar")); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4400 | TestCompletionCallback callback_restart; |
| 4401 | const int rv_restart = trans->RestartWithAuth( |
| 4402 | credentials, callback_restart.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4403 | EXPECT_THAT(rv_restart, IsError(ERR_IO_PENDING)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4404 | const int rv_restart_complete = callback_restart.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4405 | EXPECT_THAT(rv_restart_complete, IsOk()); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4406 | // TODO(cbentzel): This is actually the same response object as before, but |
| 4407 | // data has changed. |
| 4408 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4409 | ASSERT_TRUE(response_restart); |
| 4410 | ASSERT_TRUE(response_restart->headers); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4411 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4412 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 4413 | } |
| 4414 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4415 | TEST_F(SpdyNetworkTransactionTest, ServerPushWithHeaders) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4416 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4417 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4418 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4419 | CreateMockWrite(stream1_syn, 0), |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4420 | }; |
| 4421 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4422 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4423 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4424 | |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 4425 | SpdyHeaderBlock initial_headers; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4426 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 4427 | &initial_headers); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4428 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame( |
| 4429 | std::move(initial_headers), 2, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4430 | |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4431 | SpdyHeaderBlock late_headers; |
| 4432 | late_headers[spdy_util_.GetStatusKey()] = "200"; |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4433 | late_headers["hello"] = "bye"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4434 | SpdySerializedFrame stream2_headers(spdy_util_.ConstructSpdyResponseHeaders( |
| 4435 | 2, std::move(late_headers), false)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4436 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4437 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4438 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 4439 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4440 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 4441 | 2, kPushedData, strlen(kPushedData), true)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4442 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4443 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4444 | CreateMockRead(stream1_reply, 1), |
| 4445 | CreateMockRead(stream2_syn, 2), |
| 4446 | CreateMockRead(stream2_headers, 3), |
| 4447 | CreateMockRead(stream1_body, 4, SYNCHRONOUS), |
| 4448 | CreateMockRead(stream2_body, 5), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4449 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a pause |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4450 | }; |
| 4451 | |
| 4452 | HttpResponseInfo response; |
| 4453 | HttpResponseInfo response2; |
| 4454 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4455 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4456 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4457 | &response, |
| 4458 | &response2, |
| 4459 | expected_push_result); |
| 4460 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4461 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4462 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4463 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4464 | |
| 4465 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4466 | EXPECT_TRUE(response2.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4467 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4468 | } |
| 4469 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4470 | TEST_F(SpdyNetworkTransactionTest, ServerPushClaimBeforeHeaders) { |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4471 | // We push a stream and attempt to claim it before the headers come down. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4472 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4473 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4474 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4475 | CreateMockWrite(stream1_syn, 0, SYNCHRONOUS), |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4476 | }; |
| 4477 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4478 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4479 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 4480 | SpdyHeaderBlock initial_headers; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4481 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 4482 | &initial_headers); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4483 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame( |
| 4484 | std::move(initial_headers), 2, 1)); |
| 4485 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4486 | SpdyHeaderBlock late_headers; |
| 4487 | late_headers[spdy_util_.GetStatusKey()] = "200"; |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4488 | late_headers["hello"] = "bye"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4489 | SpdySerializedFrame stream2_headers(spdy_util_.ConstructSpdyResponseHeaders( |
| 4490 | 2, std::move(late_headers), false)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 4491 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4492 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 4493 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4494 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4495 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2), |
| 4496 | CreateMockRead(stream1_body, 3), MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 4497 | CreateMockRead(stream2_headers, 5), CreateMockRead(stream2_body, 6), |
| 4498 | MockRead(ASYNC, ERR_IO_PENDING, 7), MockRead(ASYNC, 0, 8), // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4499 | }; |
| 4500 | |
| 4501 | HttpResponseInfo response; |
| 4502 | HttpResponseInfo response2; |
| 4503 | std::string expected_push_result("pushed"); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4504 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4505 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4506 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4507 | BoundNetLog(), NULL); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4508 | helper.AddData(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4509 | helper.RunPreTestSetup(); |
| 4510 | |
| 4511 | HttpNetworkTransaction* trans = helper.trans(); |
| 4512 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4513 | // Start the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4514 | TestCompletionCallback callback; |
| 4515 | int rv = trans->Start( |
| 4516 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4517 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4518 | // Run until we've received the primary HEADERS, the pushed HEADERS, |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4519 | // and the body of the primary stream, but before we've received the HEADERS |
| 4520 | // for the pushed stream. |
| 4521 | data.RunUntilPaused(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4522 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4523 | |
| 4524 | // Request the pushed path. At this point, we've received the push, but the |
| 4525 | // headers are not yet complete. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4526 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
| 4527 | rv = |
| 4528 | trans2.Start(&CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4529 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4530 | data.Resume(); |
| 4531 | data.RunUntilPaused(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4532 | base::RunLoop().RunUntilIdle(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4533 | |
| 4534 | // Read the server push body. |
| 4535 | std::string result2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4536 | ReadResult(&trans2, &result2); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4537 | // Read the response body. |
| 4538 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 4539 | ReadResult(trans, &result); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4540 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4541 | // Verify that the received push data is same as the expected push data. |
| 4542 | EXPECT_EQ(result2.compare(expected_push_result), 0) |
| 4543 | << "Received data: " |
| 4544 | << result2 |
| 4545 | << "||||| Expected data: " |
| 4546 | << expected_push_result; |
| 4547 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4548 | // Verify the response headers. |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4549 | // Copy the response info, because trans goes away. |
| 4550 | response = *trans->GetResponseInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4551 | response2 = *trans2.GetResponseInfo(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4552 | |
| 4553 | VerifyStreamsClosed(helper); |
| 4554 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4555 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4556 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4557 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4558 | |
| 4559 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4560 | EXPECT_TRUE(response2.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4561 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 4562 | |
| 4563 | // Read the final EOF (which will close the session) |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4564 | data.Resume(); |
| 4565 | base::RunLoop().RunUntilIdle(); |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 4566 | |
| 4567 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 4568 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 4569 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4570 | } |
| 4571 | |
[email protected] | 6cd63ba | 2014-06-12 16:14:56 | [diff] [blame] | 4572 | // TODO(baranovich): HTTP 2 does not allow multiple HEADERS frames |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4573 | TEST_F(SpdyNetworkTransactionTest, ServerPushWithTwoHeaderFrames) { |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4574 | // We push a stream and attempt to claim it before the headers come down. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4575 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4576 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4577 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4578 | CreateMockWrite(stream1_syn, 0, SYNCHRONOUS), |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4579 | }; |
| 4580 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4581 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4582 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4583 | |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 4584 | SpdyHeaderBlock initial_headers; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4585 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 4586 | &initial_headers); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4587 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame( |
| 4588 | std::move(initial_headers), 2, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4589 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4590 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4591 | |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4592 | SpdyHeaderBlock middle_headers; |
| 4593 | middle_headers["hello"] = "bye"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4594 | SpdySerializedFrame stream2_headers1(spdy_util_.ConstructSpdyResponseHeaders( |
| 4595 | 2, std::move(middle_headers), false)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4596 | |
| 4597 | SpdyHeaderBlock late_headers; |
| 4598 | late_headers[spdy_util_.GetStatusKey()] = "200"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4599 | SpdySerializedFrame stream2_headers2(spdy_util_.ConstructSpdyResponseHeaders( |
| 4600 | 2, std::move(late_headers), false)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4601 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 4602 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4603 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 4604 | 2, kPushedData, strlen(kPushedData), true)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4605 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4606 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4607 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2), |
| 4608 | CreateMockRead(stream1_body, 3), MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 4609 | CreateMockRead(stream2_headers1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4610 | // This is needed to work around https://crbug.com/571102. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4611 | MockRead(ASYNC, ERR_IO_PENDING, 6), CreateMockRead(stream2_headers2, 7), |
| 4612 | CreateMockRead(stream2_body, 8), MockRead(ASYNC, ERR_IO_PENDING, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4613 | MockRead(ASYNC, 0, 10), // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4614 | }; |
| 4615 | |
| 4616 | HttpResponseInfo response; |
| 4617 | HttpResponseInfo response2; |
| 4618 | std::string expected_push_result("pushed"); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4619 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4620 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4621 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4622 | BoundNetLog(), NULL); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4623 | helper.AddData(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4624 | helper.RunPreTestSetup(); |
| 4625 | |
| 4626 | HttpNetworkTransaction* trans = helper.trans(); |
| 4627 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4628 | // Start the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4629 | TestCompletionCallback callback; |
| 4630 | int rv = trans->Start( |
| 4631 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4632 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4633 | // Run until we've received the primary HEADERS, the pushed HEADERS, |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4634 | // the first HEADERS frame, and the body of the primary stream, but before |
| 4635 | // we've received the final HEADERS for the pushed stream. |
| 4636 | data.RunUntilPaused(); |
| 4637 | EXPECT_EQ(0, callback.WaitForResult()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4638 | |
| 4639 | // Request the pushed path. At this point, we've received the push, but the |
| 4640 | // headers are not yet complete. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4641 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
| 4642 | rv = |
| 4643 | trans2.Start(&CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4644 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4645 | data.Resume(); |
| 4646 | data.RunUntilPaused(); |
| 4647 | base::RunLoop().RunUntilIdle(); |
| 4648 | // This is needed to work around https://crbug.com/571102. |
| 4649 | data.Resume(); |
| 4650 | data.RunUntilPaused(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4651 | base::RunLoop().RunUntilIdle(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4652 | |
| 4653 | // Read the server push body. |
| 4654 | std::string result2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4655 | ReadResult(&trans2, &result2); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4656 | // Read the response body. |
| 4657 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 4658 | ReadResult(trans, &result); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4659 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4660 | // Verify that the received push data is same as the expected push data. |
[email protected] | 6d116e1a | 2013-06-24 07:42:15 | [diff] [blame] | 4661 | EXPECT_EQ(expected_push_result, result2); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4662 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4663 | // Verify the response headers. |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4664 | // Copy the response info, because trans goes away. |
| 4665 | response = *trans->GetResponseInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4666 | response2 = *trans2.GetResponseInfo(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4667 | |
| 4668 | VerifyStreamsClosed(helper); |
| 4669 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4670 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4671 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4672 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4673 | |
| 4674 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4675 | EXPECT_TRUE(response2.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4676 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4677 | |
[email protected] | 6cd63ba | 2014-06-12 16:14:56 | [diff] [blame] | 4678 | // Verify we got all the headers from all header blocks. |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4679 | EXPECT_TRUE(response2.headers->HasHeaderValue("hello", "bye")); |
| 4680 | EXPECT_TRUE(response2.headers->HasHeaderValue("status", "200")); |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 4681 | |
| 4682 | // Read the final EOF (which will close the session) |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4683 | data.Resume(); |
| 4684 | base::RunLoop().RunUntilIdle(); |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 4685 | |
| 4686 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 4687 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 4688 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4689 | } |
| 4690 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4691 | TEST_F(SpdyNetworkTransactionTest, ServerPushWithNoStatusHeaderFrames) { |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4692 | // We push a stream and attempt to claim it before the headers come down. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4693 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4694 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4695 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4696 | CreateMockWrite(stream1_syn, 0, SYNCHRONOUS), |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4697 | }; |
| 4698 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4699 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4700 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4701 | |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 4702 | SpdyHeaderBlock initial_headers; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4703 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 4704 | &initial_headers); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4705 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame( |
| 4706 | std::move(initial_headers), 2, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4707 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4708 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4709 | |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4710 | SpdyHeaderBlock middle_headers; |
| 4711 | middle_headers["hello"] = "bye"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4712 | SpdySerializedFrame stream2_headers1(spdy_util_.ConstructSpdyResponseHeaders( |
| 4713 | 2, std::move(middle_headers), false)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4714 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 4715 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4716 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 4717 | 2, kPushedData, strlen(kPushedData), true)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4718 | |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4719 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4720 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2), |
| 4721 | CreateMockRead(stream1_body, 3), MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 4722 | CreateMockRead(stream2_headers1, 5), CreateMockRead(stream2_body, 6), |
| 4723 | MockRead(ASYNC, ERR_IO_PENDING, 7), MockRead(ASYNC, 0, 8), // EOF |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4724 | }; |
| 4725 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4726 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4727 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4728 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4729 | BoundNetLog(), NULL); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4730 | helper.AddData(&data); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4731 | helper.RunPreTestSetup(); |
| 4732 | |
| 4733 | HttpNetworkTransaction* trans = helper.trans(); |
| 4734 | |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4735 | // Start the transaction. |
| 4736 | TestCompletionCallback callback; |
| 4737 | int rv = trans->Start( |
| 4738 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4739 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4740 | // Run until we've received the primary HEADERS, the pushed HEADERS, |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4741 | // the first HEADERS frame, and the body of the primary stream, but before |
| 4742 | // we've received the final HEADERS for the pushed stream. |
| 4743 | data.RunUntilPaused(); |
| 4744 | EXPECT_EQ(0, callback.WaitForResult()); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4745 | |
| 4746 | // Request the pushed path. At this point, we've received the push, but the |
| 4747 | // headers are not yet complete. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4748 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
| 4749 | rv = |
| 4750 | trans2.Start(&CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4751 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4752 | data.Resume(); |
| 4753 | data.RunUntilPaused(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4754 | base::RunLoop().RunUntilIdle(); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4755 | |
| 4756 | // Read the server push body. |
| 4757 | std::string result2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4758 | ReadResult(&trans2, &result2); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4759 | // Read the response body. |
| 4760 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 4761 | ReadResult(trans, &result); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4762 | EXPECT_EQ("hello!", result); |
| 4763 | |
| 4764 | // Verify that we haven't received any push data. |
| 4765 | EXPECT_EQ("", result2); |
| 4766 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4767 | // Verify the response headers. |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4768 | // Copy the response info, because trans goes away. |
| 4769 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4770 | |
| 4771 | VerifyStreamsClosed(helper); |
| 4772 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4773 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4774 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4775 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4776 | |
| 4777 | // Read the final EOF (which will close the session). |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4778 | data.Resume(); |
| 4779 | base::RunLoop().RunUntilIdle(); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4780 | |
| 4781 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 4782 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 4783 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4784 | } |
| 4785 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4786 | TEST_F(SpdyNetworkTransactionTest, ResponseHeadersTwice) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4787 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4788 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4789 | SpdySerializedFrame rst( |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 4790 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 4791 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4792 | CreateMockWrite(req, 0), CreateMockWrite(rst, 4), |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4793 | }; |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4794 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4795 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4796 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4797 | |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4798 | SpdyHeaderBlock late_headers; |
| 4799 | late_headers["hello"] = "bye"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4800 | SpdySerializedFrame stream1_headers(spdy_util_.ConstructSpdyResponseHeaders( |
| 4801 | 1, std::move(late_headers), false)); |
| 4802 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4803 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4804 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream1_headers, 2), |
| 4805 | CreateMockRead(stream1_body, 3), MockRead(ASYNC, 0, 5) // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4806 | }; |
| 4807 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4808 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4809 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4810 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4811 | helper.RunToCompletion(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4812 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4813 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4814 | } |
| 4815 | |
xunjieli | 294da72 | 2015-08-11 19:15:02 | [diff] [blame] | 4816 | // Tests that receiving HEADERS, DATA, HEADERS, and DATA in that sequence will |
| 4817 | // trigger a ERR_SPDY_PROTOCOL_ERROR because trailing HEADERS must not be |
| 4818 | // followed by any DATA frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4819 | TEST_F(SpdyNetworkTransactionTest, SyncReplyDataAfterTrailers) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4820 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4821 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4822 | SpdySerializedFrame rst( |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 4823 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 4824 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4825 | CreateMockWrite(req, 0), CreateMockWrite(rst, 5), |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 4826 | }; |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4827 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4828 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4829 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4830 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, false)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4831 | |
| 4832 | SpdyHeaderBlock late_headers; |
| 4833 | late_headers["hello"] = "bye"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4834 | SpdySerializedFrame stream1_headers(spdy_util_.ConstructSpdyResponseHeaders( |
| 4835 | 1, std::move(late_headers), false)); |
| 4836 | SpdySerializedFrame stream1_body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4837 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4838 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream1_body, 2), |
| 4839 | CreateMockRead(stream1_headers, 3), CreateMockRead(stream1_body2, 4), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4840 | MockRead(ASYNC, 0, 6) // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4841 | }; |
| 4842 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4843 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4844 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4845 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4846 | helper.RunToCompletion(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4847 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4848 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4849 | } |
| 4850 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4851 | TEST_F(SpdyNetworkTransactionTest, ServerPushCrossOriginCorrectness) { |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4852 | // In this test we want to verify that we can't accidentally push content |
| 4853 | // which can't be pushed by this content server. |
| 4854 | // This test assumes that: |
| 4855 | // - if we're requesting http://www.foo.com/barbaz |
| 4856 | // - the browser has made a connection to "www.foo.com". |
| 4857 | |
| 4858 | // A list of the URL to fetch, followed by the URL being pushed. |
| 4859 | static const char* const kTestCases[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4860 | "https://www.example.org/foo.html", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4861 | "http://www.example.org/foo.js", // Bad protocol |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4862 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4863 | "https://www.example.org/foo.html", |
| 4864 | "ftp://www.example.org/foo.js", // Invalid Protocol |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4865 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4866 | "https://www.example.org/foo.html", |
| 4867 | "https://blat.www.example.org/foo.js", // Cross subdomain |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4868 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4869 | "https://www.example.org/foo.html", |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4870 | "https://www.foo.com/foo.js", // Cross domain |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4871 | }; |
| 4872 | |
[email protected] | b3f89933 | 2010-12-08 18:20:44 | [diff] [blame] | 4873 | for (size_t index = 0; index < arraysize(kTestCases); index += 2) { |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4874 | const char* url_to_fetch = kTestCases[index]; |
| 4875 | const char* url_to_push = kTestCases[index + 1]; |
| 4876 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4877 | SpdyTestUtil spdy_test_util; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4878 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4879 | spdy_test_util.ConstructSpdyGet(url_to_fetch, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4880 | SpdySerializedFrame stream1_body( |
| 4881 | spdy_test_util.ConstructSpdyDataFrame(1, true)); |
| 4882 | SpdySerializedFrame push_rst( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4883 | spdy_test_util.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4884 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4885 | CreateMockWrite(stream1_syn, 0), CreateMockWrite(push_rst, 3), |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4886 | }; |
| 4887 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4888 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4889 | spdy_test_util.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4890 | SpdySerializedFrame stream2_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4891 | spdy_test_util.ConstructSpdyPush(nullptr, 0, 2, 1, url_to_push)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 4892 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4893 | SpdySerializedFrame stream2_body(spdy_test_util.ConstructSpdyDataFrame( |
| 4894 | 2, kPushedData, strlen(kPushedData), true)); |
| 4895 | SpdySerializedFrame rst( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4896 | spdy_test_util.ConstructSpdyRstStream(2, RST_STREAM_CANCEL)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4897 | |
| 4898 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4899 | CreateMockRead(stream1_reply, 1), |
| 4900 | CreateMockRead(stream2_syn, 2), |
| 4901 | CreateMockRead(stream1_body, 4), |
| 4902 | CreateMockRead(stream2_body, 5), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4903 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a pause |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4904 | }; |
| 4905 | |
| 4906 | HttpResponseInfo response; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4907 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 4908 | arraysize(writes)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4909 | |
| 4910 | HttpRequestInfo request; |
| 4911 | request.method = "GET"; |
| 4912 | request.url = GURL(url_to_fetch); |
| 4913 | request.load_flags = 0; |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4914 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 4915 | // Enable cross-origin push. Since we are not using a proxy, this should |
| 4916 | // not actually enable cross-origin SPDY push. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4917 | auto session_deps = base::MakeUnique<SpdySessionDependencies>(); |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 4918 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 4919 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 4920 | "https://123.45.67.89:443", net::ProxyServer::SCHEME_HTTP)); |
| 4921 | session_deps->proxy_delegate.reset(proxy_delegate.release()); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4922 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4923 | std::move(session_deps)); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4924 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4925 | helper.AddData(&data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 4926 | |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4927 | HttpNetworkTransaction* trans = helper.trans(); |
| 4928 | |
| 4929 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4930 | TestCompletionCallback callback; |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4931 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4932 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4933 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4934 | rv = callback.WaitForResult(); |
| 4935 | |
| 4936 | // Read the response body. |
| 4937 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 4938 | ReadResult(trans, &result); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4939 | |
| 4940 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 4941 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 4942 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4943 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4944 | // Verify the response headers. |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4945 | // Copy the response info, because trans goes away. |
| 4946 | response = *trans->GetResponseInfo(); |
| 4947 | |
| 4948 | VerifyStreamsClosed(helper); |
| 4949 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4950 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4951 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4952 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4953 | } |
| 4954 | } |
| 4955 | |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4956 | // Verify that push works cross origin as long as the certificate is valid for |
| 4957 | // the pushed authority. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4958 | TEST_F(SpdyNetworkTransactionTest, ServerPushValidCrossOrigin) { |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4959 | // "spdy_pooling.pem" is valid for both www.example.org and mail.example.org. |
| 4960 | const char* url_to_fetch = "https://www.example.org"; |
| 4961 | const char* url_to_push = "https://mail.example.org"; |
| 4962 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4963 | SpdySerializedFrame headers( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4964 | spdy_util_.ConstructSpdyGet(url_to_fetch, 1, LOWEST)); |
| 4965 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4966 | CreateMockWrite(headers, 0), |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4967 | }; |
| 4968 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4969 | SpdySerializedFrame reply(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4970 | SpdySerializedFrame push( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4971 | spdy_util_.ConstructSpdyPush(nullptr, 0, 2, 1, url_to_push)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4972 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4973 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4974 | SpdySerializedFrame pushed_body(spdy_util_.ConstructSpdyDataFrame( |
| 4975 | 2, kPushedData, strlen(kPushedData), true)); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4976 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4977 | CreateMockRead(reply, 1), |
| 4978 | CreateMockRead(push, 2), |
| 4979 | CreateMockRead(body, 3), |
| 4980 | CreateMockRead(pushed_body, 4), |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4981 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
| 4982 | }; |
| 4983 | |
| 4984 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 4985 | |
| 4986 | HttpRequestInfo request; |
| 4987 | request.method = "GET"; |
| 4988 | request.url = GURL(url_to_fetch); |
| 4989 | request.load_flags = 0; |
| 4990 | |
| 4991 | BoundNetLog log; |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4992 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, log, nullptr); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4993 | helper.RunPreTestSetup(); |
| 4994 | helper.AddData(&data); |
| 4995 | |
| 4996 | HttpNetworkTransaction* trans0 = helper.trans(); |
| 4997 | TestCompletionCallback callback0; |
| 4998 | int rv = trans0->Start(&request, callback0.callback(), log); |
| 4999 | rv = callback0.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5000 | EXPECT_THAT(rv, IsOk()); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5001 | |
| 5002 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5003 | SpdySessionKey key(host_port_pair_, ProxyServer::Direct(), |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5004 | PRIVACY_MODE_DISABLED); |
| 5005 | base::WeakPtr<SpdySession> spdy_session = |
| 5006 | spdy_session_pool->FindAvailableSession(key, GURL(), log); |
| 5007 | |
| 5008 | EXPECT_FALSE(spdy_session->unclaimed_pushed_streams_.empty()); |
| 5009 | EXPECT_EQ(1u, spdy_session->unclaimed_pushed_streams_.size()); |
| 5010 | EXPECT_EQ(1u, |
| 5011 | spdy_session->unclaimed_pushed_streams_.count(GURL(url_to_push))); |
| 5012 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5013 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session()); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5014 | HttpRequestInfo push_request; |
| 5015 | push_request.method = "GET"; |
| 5016 | push_request.url = GURL(url_to_push); |
| 5017 | push_request.load_flags = 0; |
| 5018 | TestCompletionCallback callback1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5019 | rv = trans1.Start(&push_request, callback1.callback(), log); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5020 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5021 | EXPECT_THAT(rv, IsOk()); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5022 | |
| 5023 | EXPECT_TRUE(spdy_session->unclaimed_pushed_streams_.empty()); |
| 5024 | EXPECT_EQ(0u, spdy_session->unclaimed_pushed_streams_.size()); |
| 5025 | |
| 5026 | helper.VerifyDataConsumed(); |
| 5027 | VerifyStreamsClosed(helper); |
| 5028 | |
| 5029 | HttpResponseInfo response = *trans0->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5030 | EXPECT_TRUE(response.headers); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5031 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
| 5032 | |
| 5033 | std::string result0; |
| 5034 | ReadResult(trans0, &result0); |
| 5035 | EXPECT_EQ("hello!", result0); |
| 5036 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5037 | HttpResponseInfo push_response = *trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5038 | EXPECT_TRUE(push_response.headers); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5039 | EXPECT_EQ("HTTP/1.1 200", push_response.headers->GetStatusLine()); |
| 5040 | |
| 5041 | std::string result1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5042 | ReadResult(&trans1, &result1); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5043 | EXPECT_EQ(kPushedData, result1); |
| 5044 | } |
| 5045 | |
| 5046 | // Verify that push works cross origin, even if there is already a connection |
| 5047 | // open to origin of pushed resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5048 | TEST_F(SpdyNetworkTransactionTest, ServerPushValidCrossOriginWithOpenSession) { |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5049 | const char* url_to_fetch0 = "https://mail.example.org/foo"; |
| 5050 | const char* url_to_fetch1 = "https://docs.example.org"; |
| 5051 | const char* url_to_push = "https://mail.example.org/bar"; |
| 5052 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5053 | SpdyTestUtil spdy_util_0; |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5054 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5055 | SpdySerializedFrame headers0( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5056 | spdy_util_0.ConstructSpdyGet(url_to_fetch0, 1, LOWEST)); |
| 5057 | MockWrite writes0[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5058 | CreateMockWrite(headers0, 0), |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5059 | }; |
| 5060 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5061 | SpdySerializedFrame reply0(spdy_util_0.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5062 | const char kData0[] = "first"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5063 | SpdySerializedFrame body0( |
| 5064 | spdy_util_0.ConstructSpdyDataFrame(1, kData0, strlen(kData0), true)); |
| 5065 | MockRead reads0[] = {CreateMockRead(reply0, 1), CreateMockRead(body0, 2), |
| 5066 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5067 | |
| 5068 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 5069 | arraysize(writes0)); |
| 5070 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5071 | SpdyTestUtil spdy_util_1; |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5072 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5073 | SpdySerializedFrame headers1( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5074 | spdy_util_1.ConstructSpdyGet(url_to_fetch1, 1, LOWEST)); |
| 5075 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5076 | CreateMockWrite(headers1, 0), |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5077 | }; |
| 5078 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5079 | SpdySerializedFrame reply1(spdy_util_1.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5080 | SpdySerializedFrame push( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5081 | spdy_util_1.ConstructSpdyPush(nullptr, 0, 2, 1, url_to_push)); |
| 5082 | const char kData1[] = "second"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5083 | SpdySerializedFrame body1( |
| 5084 | spdy_util_1.ConstructSpdyDataFrame(1, kData1, strlen(kData1), true)); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5085 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5086 | SpdySerializedFrame pushed_body(spdy_util_1.ConstructSpdyDataFrame( |
| 5087 | 2, kPushedData, strlen(kPushedData), true)); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5088 | |
| 5089 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5090 | CreateMockRead(reply1, 1), |
| 5091 | CreateMockRead(push, 2), |
| 5092 | CreateMockRead(body1, 3), |
| 5093 | CreateMockRead(pushed_body, 4), |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5094 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
| 5095 | }; |
| 5096 | |
| 5097 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 5098 | arraysize(writes1)); |
| 5099 | |
| 5100 | // Request |url_to_fetch0| to open connection to mail.example.org. |
| 5101 | HttpRequestInfo request0; |
| 5102 | request0.method = "GET"; |
| 5103 | request0.url = GURL(url_to_fetch0); |
| 5104 | request0.load_flags = 0; |
| 5105 | |
| 5106 | BoundNetLog log; |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5107 | NormalSpdyTransactionHelper helper(request0, DEFAULT_PRIORITY, log, nullptr); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5108 | helper.RunPreTestSetup(); |
| 5109 | |
| 5110 | // "spdy_pooling.pem" is valid for www.example.org, but not for |
| 5111 | // docs.example.org. |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5112 | std::unique_ptr<SSLSocketDataProvider> ssl_provider0( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5113 | new SSLSocketDataProvider(ASYNC, OK)); |
| 5114 | ssl_provider0->cert = |
| 5115 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 5116 | helper.AddDataWithSSLSocketDataProvider(&data0, std::move(ssl_provider0)); |
| 5117 | |
| 5118 | // "wildcard.pem" is valid for both www.example.org and docs.example.org. |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5119 | std::unique_ptr<SSLSocketDataProvider> ssl_provider1( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5120 | new SSLSocketDataProvider(ASYNC, OK)); |
| 5121 | ssl_provider1->cert = |
| 5122 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 5123 | helper.AddDataWithSSLSocketDataProvider(&data1, std::move(ssl_provider1)); |
| 5124 | |
| 5125 | HttpNetworkTransaction* trans0 = helper.trans(); |
| 5126 | TestCompletionCallback callback0; |
| 5127 | int rv = trans0->Start(&request0, callback0.callback(), log); |
| 5128 | rv = callback0.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5129 | EXPECT_THAT(rv, IsOk()); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5130 | |
| 5131 | // Request |url_to_fetch1|, during which docs.example.org pushes |
| 5132 | // |url_to_push|, which happens to be for www.example.org, to which there is |
| 5133 | // already an open connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5134 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session()); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5135 | HttpRequestInfo request1; |
| 5136 | request1.method = "GET"; |
| 5137 | request1.url = GURL(url_to_fetch1); |
| 5138 | request1.load_flags = 0; |
| 5139 | TestCompletionCallback callback1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5140 | rv = trans1.Start(&request1, callback1.callback(), log); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5141 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5142 | EXPECT_THAT(rv, IsOk()); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5143 | |
| 5144 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
| 5145 | HostPortPair host_port_pair0("mail.example.org", 443); |
| 5146 | SpdySessionKey key0(host_port_pair0, ProxyServer::Direct(), |
| 5147 | PRIVACY_MODE_DISABLED); |
| 5148 | base::WeakPtr<SpdySession> spdy_session0 = |
| 5149 | spdy_session_pool->FindAvailableSession(key0, GURL(), log); |
| 5150 | |
| 5151 | EXPECT_TRUE(spdy_session0->unclaimed_pushed_streams_.empty()); |
| 5152 | EXPECT_EQ(0u, spdy_session0->unclaimed_pushed_streams_.size()); |
| 5153 | |
| 5154 | HostPortPair host_port_pair1("docs.example.org", 443); |
| 5155 | SpdySessionKey key1(host_port_pair1, ProxyServer::Direct(), |
| 5156 | PRIVACY_MODE_DISABLED); |
| 5157 | base::WeakPtr<SpdySession> spdy_session1 = |
| 5158 | spdy_session_pool->FindAvailableSession(key1, GURL(), log); |
| 5159 | |
| 5160 | EXPECT_FALSE(spdy_session1->unclaimed_pushed_streams_.empty()); |
| 5161 | EXPECT_EQ(1u, spdy_session1->unclaimed_pushed_streams_.size()); |
| 5162 | EXPECT_EQ(1u, |
| 5163 | spdy_session1->unclaimed_pushed_streams_.count(GURL(url_to_push))); |
| 5164 | |
| 5165 | // Request |url_to_push|, which should be served from the pushed resource. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5166 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5167 | HttpRequestInfo push_request; |
| 5168 | push_request.method = "GET"; |
| 5169 | push_request.url = GURL(url_to_push); |
| 5170 | push_request.load_flags = 0; |
| 5171 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5172 | rv = trans2.Start(&push_request, callback2.callback(), log); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5173 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5174 | EXPECT_THAT(rv, IsOk()); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5175 | |
| 5176 | EXPECT_TRUE(spdy_session0->unclaimed_pushed_streams_.empty()); |
| 5177 | EXPECT_EQ(0u, spdy_session0->unclaimed_pushed_streams_.size()); |
| 5178 | |
| 5179 | EXPECT_TRUE(spdy_session1->unclaimed_pushed_streams_.empty()); |
| 5180 | EXPECT_EQ(0u, spdy_session1->unclaimed_pushed_streams_.size()); |
| 5181 | |
| 5182 | helper.VerifyDataConsumed(); |
| 5183 | VerifyStreamsClosed(helper); |
| 5184 | |
| 5185 | HttpResponseInfo response0 = *trans0->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5186 | EXPECT_TRUE(response0.headers); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5187 | EXPECT_EQ("HTTP/1.1 200", response0.headers->GetStatusLine()); |
| 5188 | |
| 5189 | std::string result0; |
| 5190 | ReadResult(trans0, &result0); |
| 5191 | EXPECT_EQ(kData0, result0); |
| 5192 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5193 | HttpResponseInfo response1 = *trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5194 | EXPECT_TRUE(response1.headers); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5195 | EXPECT_EQ("HTTP/1.1 200", response1.headers->GetStatusLine()); |
| 5196 | |
| 5197 | std::string result1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5198 | ReadResult(&trans1, &result1); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5199 | EXPECT_EQ(kData1, result1); |
| 5200 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5201 | HttpResponseInfo push_response = *trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5202 | EXPECT_TRUE(push_response.headers); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5203 | EXPECT_EQ("HTTP/1.1 200", push_response.headers->GetStatusLine()); |
| 5204 | |
| 5205 | std::string result2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5206 | ReadResult(&trans2, &result2); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5207 | EXPECT_EQ(kPushedData, result2); |
| 5208 | } |
| 5209 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5210 | TEST_F(SpdyNetworkTransactionTest, ServerPushInvalidCrossOrigin) { |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5211 | // "spdy_pooling.pem" is valid for www.example.org, |
| 5212 | // but not for invalid.example.org. |
| 5213 | const char* url_to_fetch = "https://www.example.org"; |
| 5214 | const char* url_to_push = "https://invalid.example.org"; |
| 5215 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5216 | SpdySerializedFrame headers( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5217 | spdy_util_.ConstructSpdyGet(url_to_fetch, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5218 | SpdySerializedFrame rst( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5219 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
| 5220 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5221 | CreateMockWrite(headers, 0), CreateMockWrite(rst, 3), |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5222 | }; |
| 5223 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5224 | SpdySerializedFrame reply(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5225 | SpdySerializedFrame push( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5226 | spdy_util_.ConstructSpdyPush(nullptr, 0, 2, 1, url_to_push)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5227 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5228 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5229 | SpdySerializedFrame pushed_body(spdy_util_.ConstructSpdyDataFrame( |
| 5230 | 2, kPushedData, strlen(kPushedData), true)); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5231 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5232 | CreateMockRead(reply, 1), |
| 5233 | CreateMockRead(push, 2), |
| 5234 | CreateMockRead(body, 4), |
| 5235 | CreateMockRead(pushed_body, 5), |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5236 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), |
| 5237 | }; |
| 5238 | |
| 5239 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 5240 | |
| 5241 | HttpRequestInfo request; |
| 5242 | request.method = "GET"; |
| 5243 | request.url = GURL(url_to_fetch); |
| 5244 | request.load_flags = 0; |
| 5245 | |
| 5246 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5247 | nullptr); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5248 | helper.RunToCompletion(&data); |
| 5249 | TransactionHelperResult out = helper.output(); |
| 5250 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
| 5251 | EXPECT_EQ("hello!", out.response_data); |
| 5252 | } |
| 5253 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5254 | TEST_F(SpdyNetworkTransactionTest, RetryAfterRefused) { |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5255 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5256 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5257 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5258 | // Will be destroyed by the RST before stream 3 starts. |
| 5259 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5260 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5261 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5262 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5263 | CreateMockWrite(req, 0), CreateMockWrite(req2, 2), |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5264 | }; |
| 5265 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5266 | SpdySerializedFrame refused( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5267 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_REFUSED_STREAM)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5268 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5269 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5270 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5271 | CreateMockRead(refused, 1), CreateMockRead(resp, 3), |
| 5272 | CreateMockRead(body, 4), MockRead(ASYNC, 0, 5) // EOF |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5273 | }; |
| 5274 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5275 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5276 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5277 | BoundNetLog(), NULL); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5278 | |
| 5279 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5280 | helper.AddData(&data); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5281 | |
| 5282 | HttpNetworkTransaction* trans = helper.trans(); |
| 5283 | |
| 5284 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5285 | TestCompletionCallback callback; |
| 5286 | int rv = trans->Start( |
| 5287 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5288 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5289 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5290 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5291 | |
| 5292 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5293 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 5294 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5295 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5296 | // Verify the response headers. |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5297 | HttpResponseInfo response = *trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5298 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5299 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5300 | } |
| 5301 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5302 | TEST_F(SpdyNetworkTransactionTest, OutOfOrderHeaders) { |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5303 | // This first request will start to establish the SpdySession. |
| 5304 | // Then we will start the second (MEDIUM priority) and then third |
| 5305 | // (HIGHEST priority) request in such a way that the third will actually |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 5306 | // start before the second, causing the second to be numbered differently |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5307 | // than the order they were created. |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5308 | // |
| 5309 | // Note that the requests and responses created below are expectations |
| 5310 | // of what the above will produce on the wire, and hence are in the |
| 5311 | // initial->HIGHEST->LOWEST priority. |
| 5312 | // |
| 5313 | // Frames are created by SpdySession just before the write associated |
| 5314 | // with the frame is attempted, so stream dependencies will be based |
| 5315 | // on the streams alive at the point of the request write attempt. Thus |
| 5316 | // req1 is alive when req2 is attempted (during but not after the |
| 5317 | // |data.RunFor(2);| statement below) but not when req3 is attempted. |
| 5318 | // The call to spdy_util_.UpdateWithStreamDestruction() reflects this. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5319 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5320 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5321 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5322 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, HIGHEST, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5323 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5324 | SpdySerializedFrame req3( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5325 | spdy_util_.ConstructSpdyGet(nullptr, 0, 5, MEDIUM, true)); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5326 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5327 | MockWrite(ASYNC, ERR_IO_PENDING, 0), CreateMockWrite(req1, 1), |
| 5328 | CreateMockWrite(req2, 5), CreateMockWrite(req3, 6), |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5329 | }; |
| 5330 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5331 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5332 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5333 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5334 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5335 | SpdySerializedFrame resp3(spdy_util_.ConstructSpdyGetReply(NULL, 0, 5)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5336 | SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame(5, true)); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5337 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5338 | CreateMockRead(resp1, 2), MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 5339 | CreateMockRead(body1, 4), CreateMockRead(resp2, 7), |
| 5340 | CreateMockRead(body2, 8), CreateMockRead(resp3, 9), |
| 5341 | CreateMockRead(body3, 10), MockRead(ASYNC, 0, 11) // EOF |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5342 | }; |
| 5343 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5344 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5345 | NormalSpdyTransactionHelper helper(CreateGetRequest(), LOWEST, BoundNetLog(), |
| 5346 | NULL); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5347 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5348 | helper.AddData(&data); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5349 | |
| 5350 | // Start the first transaction to set up the SpdySession |
| 5351 | HttpNetworkTransaction* trans = helper.trans(); |
| 5352 | TestCompletionCallback callback; |
| 5353 | HttpRequestInfo info1 = CreateGetRequest(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5354 | int rv = trans->Start(&info1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5355 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5356 | |
| 5357 | // Run the message loop, but do not allow the write to complete. |
| 5358 | // This leaves the SpdySession with a write pending, which prevents |
| 5359 | // SpdySession from attempting subsequent writes until this write completes. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5360 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5361 | |
| 5362 | // Now, start both new transactions |
| 5363 | HttpRequestInfo info2 = CreateGetRequest(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5364 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5365 | HttpNetworkTransaction trans2(MEDIUM, helper.session()); |
| 5366 | rv = trans2.Start(&info2, callback2.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5367 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5368 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5369 | |
| 5370 | HttpRequestInfo info3 = CreateGetRequest(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5371 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5372 | HttpNetworkTransaction trans3(HIGHEST, helper.session()); |
| 5373 | rv = trans3.Start(&info3, callback3.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5374 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5375 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5376 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5377 | // We now have two HEADERS frames queued up which will be |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5378 | // dequeued only once the first write completes, which we |
| 5379 | // now allow to happen. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5380 | ASSERT_TRUE(data.IsPaused()); |
| 5381 | data.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5382 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5383 | |
| 5384 | // And now we can allow everything else to run to completion. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5385 | data.Resume(); |
| 5386 | base::RunLoop().RunUntilIdle(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5387 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 5388 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5389 | |
| 5390 | helper.VerifyDataConsumed(); |
| 5391 | } |
| 5392 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5393 | // Test that sent data frames and received WINDOW_UPDATE frames change |
| 5394 | // the send_window_size_ correctly. |
| 5395 | |
| 5396 | // WINDOW_UPDATE is different than most other frames in that it can arrive |
| 5397 | // while the client is still sending the request body. In order to enforce |
| 5398 | // this scenario, we feed a couple of dummy frames and give a delay of 0 to |
| 5399 | // socket data provider, so that initial read that is done as soon as the |
| 5400 | // stream is created, succeeds and schedules another read. This way reads |
| 5401 | // and writes are interleaved; after doing a full frame write, SpdyStream |
| 5402 | // will break out of DoLoop and will read and process a WINDOW_UPDATE. |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5403 | // Once our WINDOW_UPDATE is read, we cannot send HEADERS right away |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5404 | // since request has not been completely written, therefore we feed |
| 5405 | // enough number of WINDOW_UPDATEs to finish the first read and cause a |
| 5406 | // write, leading to a complete write of request body; after that we send |
| 5407 | // a reply with a body, to cause a graceful shutdown. |
| 5408 | |
| 5409 | // TODO(agayev): develop a socket data provider where both, reads and |
| 5410 | // writes are ordered so that writing tests like these are easy and rewrite |
| 5411 | // all these tests using it. Right now we are working around the |
| 5412 | // limitations as described above and it's not deterministic, tests may |
| 5413 | // fail under specific circumstances. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5414 | TEST_F(SpdyNetworkTransactionTest, WindowUpdateReceived) { |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5415 | static int kFrameCount = 2; |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5416 | std::unique_ptr<std::string> content( |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5417 | new std::string(kMaxSpdyFrameChunkSize, 'a')); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5418 | SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5419 | kDefaultUrl, 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5420 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 5421 | 1, content->c_str(), content->size(), false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5422 | SpdySerializedFrame body_end(spdy_util_.ConstructSpdyDataFrame( |
| 5423 | 1, content->c_str(), content->size(), true)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5424 | |
| 5425 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5426 | CreateMockWrite(req, 0), CreateMockWrite(body, 1), |
| 5427 | CreateMockWrite(body_end, 2), |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5428 | }; |
| 5429 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5430 | static const int32_t kDeltaWindowSize = 0xff; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5431 | static const int kDeltaCount = 4; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5432 | SpdySerializedFrame window_update( |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5433 | spdy_util_.ConstructSpdyWindowUpdate(1, kDeltaWindowSize)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5434 | SpdySerializedFrame window_update_dummy( |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5435 | spdy_util_.ConstructSpdyWindowUpdate(2, kDeltaWindowSize)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5436 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5437 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5438 | CreateMockRead(window_update_dummy, 3), |
| 5439 | CreateMockRead(window_update_dummy, 4), |
| 5440 | CreateMockRead(window_update_dummy, 5), |
| 5441 | CreateMockRead(window_update, 6), // Four updates, therefore window |
| 5442 | CreateMockRead(window_update, 7), // size should increase by |
| 5443 | CreateMockRead(window_update, 8), // kDeltaWindowSize * 4 |
| 5444 | CreateMockRead(window_update, 9), |
| 5445 | CreateMockRead(resp, 10), |
| 5446 | MockRead(ASYNC, ERR_IO_PENDING, 11), |
| 5447 | CreateMockRead(body_end, 12), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5448 | MockRead(ASYNC, 0, 13) // EOF |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5449 | }; |
| 5450 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5451 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5452 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5453 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5454 | for (int i = 0; i < kFrameCount; ++i) { |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5455 | element_readers.push_back(base::WrapUnique( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5456 | new UploadBytesElementReader(content->c_str(), content->size()))); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5457 | } |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5458 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5459 | |
| 5460 | // Setup the request |
| 5461 | HttpRequestInfo request; |
| 5462 | request.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5463 | request.url = default_url_; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5464 | request.upload_data_stream = &upload_data_stream; |
| 5465 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5466 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 5467 | NULL); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5468 | helper.AddData(&data); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5469 | helper.RunPreTestSetup(); |
| 5470 | |
| 5471 | HttpNetworkTransaction* trans = helper.trans(); |
| 5472 | |
| 5473 | TestCompletionCallback callback; |
| 5474 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 5475 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5476 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5477 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5478 | data.RunUntilPaused(); |
| 5479 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5480 | |
| 5481 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5482 | ASSERT_TRUE(stream); |
| 5483 | ASSERT_TRUE(stream->stream()); |
bnc | bca843ba | 2016-07-14 13:05:48 | [diff] [blame] | 5484 | EXPECT_EQ(static_cast<int>(kDefaultInitialWindowSize) + |
| 5485 | kDeltaWindowSize * kDeltaCount - |
| 5486 | kMaxSpdyFrameChunkSize * kFrameCount, |
| 5487 | stream->stream()->send_window_size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5488 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5489 | data.Resume(); |
| 5490 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5491 | |
| 5492 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5493 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5494 | |
| 5495 | helper.VerifyDataConsumed(); |
| 5496 | } |
| 5497 | |
| 5498 | // Test that received data frames and sent WINDOW_UPDATE frames change |
| 5499 | // the recv_window_size_ correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5500 | TEST_F(SpdyNetworkTransactionTest, WindowUpdateSent) { |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5501 | // Session level maximum window size that is more than twice the default |
| 5502 | // initial window size so that an initial window update is sent. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5503 | const int32_t session_max_recv_window_size = 5 * 64 * 1024; |
bnc | bca843ba | 2016-07-14 13:05:48 | [diff] [blame] | 5504 | ASSERT_LT(2 * kDefaultInitialWindowSize, session_max_recv_window_size); |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5505 | // Stream level maximum window size that is less than the session level |
| 5506 | // maximum window size so that we test for confusion between the two. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5507 | const int32_t stream_max_recv_window_size = 4 * 64 * 1024; |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5508 | ASSERT_GT(session_max_recv_window_size, stream_max_recv_window_size); |
| 5509 | // Size of body to be sent. Has to be less than or equal to both window sizes |
| 5510 | // so that we do not run out of receiving window. Also has to be greater than |
| 5511 | // half of them so that it triggers both a session level and a stream level |
| 5512 | // window update frame. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5513 | const int32_t kTargetSize = 3 * 64 * 1024; |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5514 | ASSERT_GE(session_max_recv_window_size, kTargetSize); |
| 5515 | ASSERT_GE(stream_max_recv_window_size, kTargetSize); |
| 5516 | ASSERT_LT(session_max_recv_window_size / 2, kTargetSize); |
| 5517 | ASSERT_LT(stream_max_recv_window_size / 2, kTargetSize); |
| 5518 | // Size of each DATA frame. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5519 | const int32_t kChunkSize = 4096; |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5520 | // Size of window updates. |
| 5521 | ASSERT_EQ(0, session_max_recv_window_size / 2 % kChunkSize); |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5522 | const int32_t session_window_update_delta = |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5523 | session_max_recv_window_size / 2 + kChunkSize; |
| 5524 | ASSERT_EQ(0, stream_max_recv_window_size / 2 % kChunkSize); |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5525 | const int32_t stream_window_update_delta = |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5526 | stream_max_recv_window_size / 2 + kChunkSize; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5527 | |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5528 | SettingsMap initial_settings; |
bnc | b3cafaa | 2016-09-02 16:59:56 | [diff] [blame] | 5529 | initial_settings[SETTINGS_HEADER_TABLE_SIZE] = |
| 5530 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxHeaderTableSize); |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5531 | initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 5532 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); |
| 5533 | initial_settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
| 5534 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, stream_max_recv_window_size); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5535 | SpdySerializedFrame initial_settings_frame( |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5536 | spdy_util_.ConstructSpdySettings(initial_settings)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5537 | SpdySerializedFrame initial_window_update( |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5538 | spdy_util_.ConstructSpdyWindowUpdate( |
| 5539 | kSessionFlowControlStreamId, |
bnc | bca843ba | 2016-07-14 13:05:48 | [diff] [blame] | 5540 | session_max_recv_window_size - kDefaultInitialWindowSize)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5541 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5542 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5543 | SpdySerializedFrame session_window_update( |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5544 | spdy_util_.ConstructSpdyWindowUpdate(0, session_window_update_delta)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5545 | SpdySerializedFrame stream_window_update( |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5546 | spdy_util_.ConstructSpdyWindowUpdate(1, stream_window_update_delta)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5547 | |
| 5548 | std::vector<MockWrite> writes; |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 5549 | writes.push_back(MockWrite(ASYNC, kHttp2ConnectionHeaderPrefix, |
| 5550 | kHttp2ConnectionHeaderPrefixSize, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5551 | writes.push_back(CreateMockWrite(initial_settings_frame, writes.size())); |
| 5552 | writes.push_back(CreateMockWrite(initial_window_update, writes.size())); |
| 5553 | writes.push_back(CreateMockWrite(req, writes.size())); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5554 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5555 | std::vector<MockRead> reads; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5556 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5557 | reads.push_back(CreateMockRead(resp, writes.size() + reads.size())); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5558 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5559 | std::vector<SpdySerializedFrame> body_frames; |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5560 | const std::string body_data(kChunkSize, 'x'); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5561 | for (size_t remaining = kTargetSize; remaining != 0;) { |
| 5562 | size_t frame_size = std::min(remaining, body_data.size()); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5563 | body_frames.push_back(spdy_util_.ConstructSpdyDataFrame(1, body_data.data(), |
| 5564 | frame_size, false)); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5565 | reads.push_back( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5566 | CreateMockRead(body_frames.back(), writes.size() + reads.size())); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5567 | remaining -= frame_size; |
| 5568 | } |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5569 | // Yield. |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5570 | reads.push_back( |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5571 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, writes.size() + reads.size())); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5572 | |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5573 | writes.push_back( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5574 | CreateMockWrite(session_window_update, writes.size() + reads.size())); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5575 | writes.push_back( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5576 | CreateMockWrite(stream_window_update, writes.size() + reads.size())); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5577 | |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 5578 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 5579 | writes.size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5580 | |
| 5581 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5582 | BoundNetLog(), NULL); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5583 | helper.AddData(&data); |
| 5584 | helper.RunPreTestSetup(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5585 | |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5586 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
| 5587 | SpdySessionPoolPeer pool_peer(spdy_session_pool); |
| 5588 | pool_peer.SetEnableSendingInitialData(true); |
| 5589 | pool_peer.SetSessionMaxRecvWindowSize(session_max_recv_window_size); |
| 5590 | pool_peer.SetStreamInitialRecvWindowSize(stream_max_recv_window_size); |
| 5591 | |
| 5592 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5593 | TestCompletionCallback callback; |
| 5594 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 5595 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5596 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5597 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5598 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5599 | |
| 5600 | SpdyHttpStream* stream = |
| 5601 | static_cast<SpdyHttpStream*>(trans->stream_.get()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5602 | ASSERT_TRUE(stream); |
| 5603 | ASSERT_TRUE(stream->stream()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5604 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5605 | // All data has been read, but not consumed. The window reflects this. |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5606 | EXPECT_EQ(static_cast<int>(stream_max_recv_window_size - kTargetSize), |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5607 | stream->stream()->recv_window_size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5608 | |
| 5609 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5610 | ASSERT_TRUE(response); |
| 5611 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5612 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5613 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 5614 | |
| 5615 | // Issue a read which will cause a WINDOW_UPDATE to be sent and window |
| 5616 | // size increased to default. |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 5617 | scoped_refptr<IOBuffer> buf(new IOBuffer(kTargetSize)); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5618 | EXPECT_EQ(static_cast<int>(kTargetSize), |
| 5619 | trans->Read(buf.get(), kTargetSize, CompletionCallback())); |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5620 | EXPECT_EQ(static_cast<int>(stream_max_recv_window_size), |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5621 | stream->stream()->recv_window_size()); |
| 5622 | EXPECT_THAT(base::StringPiece(buf->data(), kTargetSize), Each(Eq('x'))); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5623 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5624 | // Allow scheduled WINDOW_UPDATE frames to write. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5625 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5626 | helper.VerifyDataConsumed(); |
| 5627 | } |
| 5628 | |
| 5629 | // Test that WINDOW_UPDATE frame causing overflow is handled correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5630 | TEST_F(SpdyNetworkTransactionTest, WindowUpdateOverflow) { |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5631 | // Number of full frames we hope to write (but will not, used to |
| 5632 | // set content-length header correctly) |
| 5633 | static int kFrameCount = 3; |
| 5634 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5635 | std::unique_ptr<std::string> content( |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5636 | new std::string(kMaxSpdyFrameChunkSize, 'a')); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5637 | SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5638 | kDefaultUrl, 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5639 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 5640 | 1, content->c_str(), content->size(), false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5641 | SpdySerializedFrame rst( |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5642 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_FLOW_CONTROL_ERROR)); |
| 5643 | |
| 5644 | // We're not going to write a data frame with FIN, we'll receive a bad |
| 5645 | // WINDOW_UPDATE while sending a request and will send a RST_STREAM frame. |
| 5646 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5647 | CreateMockWrite(req, 0), CreateMockWrite(body, 2), |
| 5648 | CreateMockWrite(rst, 3), |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5649 | }; |
| 5650 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5651 | static const int32_t kDeltaWindowSize = 0x7fffffff; // cause an overflow |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5652 | SpdySerializedFrame window_update( |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5653 | spdy_util_.ConstructSpdyWindowUpdate(1, kDeltaWindowSize)); |
| 5654 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5655 | CreateMockRead(window_update, 1), MockRead(ASYNC, 0, 4) // EOF |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5656 | }; |
| 5657 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5658 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5659 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5660 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5661 | for (int i = 0; i < kFrameCount; ++i) { |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5662 | element_readers.push_back(base::WrapUnique( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5663 | new UploadBytesElementReader(content->c_str(), content->size()))); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5664 | } |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5665 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5666 | |
| 5667 | // Setup the request |
| 5668 | HttpRequestInfo request; |
| 5669 | request.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5670 | request.url = default_url_; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5671 | request.upload_data_stream = &upload_data_stream; |
| 5672 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5673 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 5674 | NULL); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5675 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5676 | helper.AddData(&data); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5677 | HttpNetworkTransaction* trans = helper.trans(); |
| 5678 | |
| 5679 | TestCompletionCallback callback; |
| 5680 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5681 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5682 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5683 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5684 | ASSERT_TRUE(callback.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5685 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_SPDY_PROTOCOL_ERROR)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5686 | helper.VerifyDataConsumed(); |
| 5687 | } |
| 5688 | |
| 5689 | // Test that after hitting a send window size of 0, the write process |
| 5690 | // stalls and upon receiving WINDOW_UPDATE frame write resumes. |
| 5691 | |
| 5692 | // This test constructs a POST request followed by enough data frames |
| 5693 | // containing 'a' that would make the window size 0, followed by another |
| 5694 | // data frame containing default content (which is "hello!") and this frame |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5695 | // also contains a FIN flag. SequencedSocketData is used to enforce all |
| 5696 | // writes, save the last, go through before a read could happen. The last frame |
| 5697 | // ("hello!") is not permitted to go through since by the time its turn |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5698 | // arrives, window size is 0. At this point MessageLoop::Run() called via |
| 5699 | // callback would block. Therefore we call MessageLoop::RunUntilIdle() |
| 5700 | // which returns after performing all possible writes. We use DCHECKS to |
| 5701 | // ensure that last data frame is still there and stream has stalled. |
| 5702 | // After that, next read is artifically enforced, which causes a |
| 5703 | // WINDOW_UPDATE to be read and I/O process resumes. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5704 | TEST_F(SpdyNetworkTransactionTest, FlowControlStallResume) { |
bnc | bca843ba | 2016-07-14 13:05:48 | [diff] [blame] | 5705 | const int32_t initial_window_size = kDefaultInitialWindowSize; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5706 | // Number of upload data buffers we need to send to zero out the window size |
| 5707 | // is the minimal number of upload buffers takes to be bigger than |
| 5708 | // |initial_window_size|. |
| 5709 | size_t num_upload_buffers = |
| 5710 | ceil(static_cast<double>(initial_window_size) / kBufferSize); |
| 5711 | // Each upload data buffer consists of |num_frames_in_one_upload_buffer| |
| 5712 | // frames, each with |kMaxSpdyFrameChunkSize| bytes except the last frame, |
| 5713 | // which has kBufferSize % kMaxSpdyChunkSize bytes. |
| 5714 | size_t num_frames_in_one_upload_buffer = |
| 5715 | ceil(static_cast<double>(kBufferSize) / kMaxSpdyFrameChunkSize); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5716 | |
| 5717 | // Construct content for a data frame of maximum size. |
| 5718 | std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 5719 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5720 | SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5721 | kDefaultUrl, 1, |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5722 | /*content_length=*/kBufferSize * num_upload_buffers + kUploadDataSize, |
| 5723 | LOWEST, NULL, 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5724 | |
| 5725 | // Full frames. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5726 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 5727 | 1, content.c_str(), content.size(), false)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5728 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5729 | // Last frame in each upload data buffer. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5730 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5731 | 1, content.c_str(), kBufferSize % kMaxSpdyFrameChunkSize, false)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5732 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5733 | // The very last frame before the stalled frames. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5734 | SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5735 | 1, content.c_str(), |
| 5736 | initial_window_size % kBufferSize % kMaxSpdyFrameChunkSize, false)); |
| 5737 | |
| 5738 | // Data frames to be sent once WINDOW_UPDATE frame is received. |
| 5739 | |
| 5740 | // If kBufferSize * num_upload_buffers > initial_window_size, |
| 5741 | // we need one additional frame to send the rest of 'a'. |
| 5742 | std::string last_body(kBufferSize * num_upload_buffers - initial_window_size, |
| 5743 | 'a'); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5744 | SpdySerializedFrame body4(spdy_util_.ConstructSpdyDataFrame( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5745 | 1, last_body.c_str(), last_body.size(), false)); |
| 5746 | |
| 5747 | // Also send a "hello!" after WINDOW_UPDATE. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5748 | SpdySerializedFrame body5(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5749 | |
| 5750 | // Fill in mock writes. |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5751 | size_t i = 0; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5752 | std::vector<MockWrite> writes; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5753 | writes.push_back(CreateMockWrite(req, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5754 | for (size_t j = 0; j < num_upload_buffers; j++) { |
| 5755 | for (size_t k = 0; k < num_frames_in_one_upload_buffer; k++) { |
| 5756 | if (k == num_frames_in_one_upload_buffer - 1 && |
| 5757 | kBufferSize % kMaxSpdyFrameChunkSize != 0) { |
| 5758 | if (j == num_upload_buffers - 1 && |
| 5759 | (initial_window_size % kBufferSize != 0)) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5760 | writes.push_back(CreateMockWrite(body3, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5761 | } else { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5762 | writes.push_back(CreateMockWrite(body2, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5763 | } |
| 5764 | } else { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5765 | writes.push_back(CreateMockWrite(body1, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5766 | } |
| 5767 | } |
| 5768 | } |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5769 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5770 | // Fill in mock reads. |
| 5771 | std::vector<MockRead> reads; |
| 5772 | // Force a pause. |
| 5773 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, i++)); |
| 5774 | // Construct read frame for window updates that gives enough space to upload |
| 5775 | // the rest of the data. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5776 | SpdySerializedFrame session_window_update( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5777 | spdy_util_.ConstructSpdyWindowUpdate(0, |
| 5778 | kUploadDataSize + last_body.size())); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5779 | SpdySerializedFrame window_update(spdy_util_.ConstructSpdyWindowUpdate( |
| 5780 | 1, kUploadDataSize + last_body.size())); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5781 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5782 | reads.push_back(CreateMockRead(session_window_update, i++)); |
| 5783 | reads.push_back(CreateMockRead(window_update, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5784 | |
| 5785 | // Stalled frames which can be sent after receiving window updates. |
| 5786 | if (last_body.size() > 0) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5787 | writes.push_back(CreateMockWrite(body4, i++)); |
| 5788 | writes.push_back(CreateMockWrite(body5, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5789 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5790 | SpdySerializedFrame reply(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5791 | reads.push_back(CreateMockRead(reply, i++)); |
| 5792 | reads.push_back(CreateMockRead(body2, i++)); |
| 5793 | reads.push_back(CreateMockRead(body5, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5794 | reads.push_back(MockRead(ASYNC, 0, i++)); // EOF |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5795 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5796 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 5797 | writes.size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5798 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5799 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5800 | std::string upload_data_string(kBufferSize * num_upload_buffers, 'a'); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5801 | upload_data_string.append(kUploadData, kUploadDataSize); |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5802 | element_readers.push_back(base::WrapUnique(new UploadBytesElementReader( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5803 | upload_data_string.c_str(), upload_data_string.size()))); |
| 5804 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5805 | |
| 5806 | HttpRequestInfo request; |
| 5807 | request.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5808 | request.url = default_url_; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5809 | request.upload_data_stream = &upload_data_stream; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5810 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5811 | NULL); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5812 | helper.AddData(&data); |
| 5813 | helper.RunPreTestSetup(); |
| 5814 | |
| 5815 | HttpNetworkTransaction* trans = helper.trans(); |
| 5816 | |
| 5817 | TestCompletionCallback callback; |
| 5818 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5819 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5820 | |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5821 | base::RunLoop().RunUntilIdle(); // Write as much as we can. |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5822 | |
| 5823 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5824 | ASSERT_TRUE(stream); |
| 5825 | ASSERT_TRUE(stream->stream()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5826 | EXPECT_EQ(0, stream->stream()->send_window_size()); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5827 | if (initial_window_size % kBufferSize != 0) { |
| 5828 | // If it does not take whole number of full upload buffer to zero out |
| 5829 | // initial window size, then the upload data is not at EOF, because the |
| 5830 | // last read must be stalled. |
| 5831 | EXPECT_FALSE(upload_data_stream.IsEOF()); |
| 5832 | } else { |
| 5833 | // All the body data should have been read. |
| 5834 | // TODO(satorux): This is because of the weirdness in reading the request |
| 5835 | // body in OnSendBodyComplete(). See crbug.com/113107. |
| 5836 | EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 5837 | } |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5838 | // But the body is not yet fully sent (kUploadData is not yet sent) |
| 5839 | // since we're send-stalled. |
| 5840 | EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 5841 | |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5842 | data.Resume(); // Read in WINDOW_UPDATE frame. |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5843 | rv = callback.WaitForResult(); |
| 5844 | helper.VerifyDataConsumed(); |
| 5845 | } |
| 5846 | |
| 5847 | // Test we correctly handle the case where the SETTINGS frame results in |
| 5848 | // unstalling the send window. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5849 | TEST_F(SpdyNetworkTransactionTest, FlowControlStallResumeAfterSettings) { |
bnc | bca843ba | 2016-07-14 13:05:48 | [diff] [blame] | 5850 | const int32_t initial_window_size = kDefaultInitialWindowSize; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5851 | // Number of upload data buffers we need to send to zero out the window size |
| 5852 | // is the minimal number of upload buffers takes to be bigger than |
| 5853 | // |initial_window_size|. |
| 5854 | size_t num_upload_buffers = |
| 5855 | ceil(static_cast<double>(initial_window_size) / kBufferSize); |
| 5856 | // Each upload data buffer consists of |num_frames_in_one_upload_buffer| |
| 5857 | // frames, each with |kMaxSpdyFrameChunkSize| bytes except the last frame, |
| 5858 | // which has kBufferSize % kMaxSpdyChunkSize bytes. |
| 5859 | size_t num_frames_in_one_upload_buffer = |
| 5860 | ceil(static_cast<double>(kBufferSize) / kMaxSpdyFrameChunkSize); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5861 | |
| 5862 | // Construct content for a data frame of maximum size. |
| 5863 | std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 5864 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5865 | SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5866 | kDefaultUrl, 1, |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5867 | /*content_length=*/kBufferSize * num_upload_buffers + kUploadDataSize, |
| 5868 | LOWEST, NULL, 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5869 | |
| 5870 | // Full frames. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5871 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 5872 | 1, content.c_str(), content.size(), false)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5873 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5874 | // Last frame in each upload data buffer. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5875 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5876 | 1, content.c_str(), kBufferSize % kMaxSpdyFrameChunkSize, false)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5877 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5878 | // The very last frame before the stalled frames. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5879 | SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5880 | 1, content.c_str(), |
| 5881 | initial_window_size % kBufferSize % kMaxSpdyFrameChunkSize, false)); |
| 5882 | |
| 5883 | // Data frames to be sent once WINDOW_UPDATE frame is received. |
| 5884 | |
| 5885 | // If kBufferSize * num_upload_buffers > initial_window_size, |
| 5886 | // we need one additional frame to send the rest of 'a'. |
| 5887 | std::string last_body(kBufferSize * num_upload_buffers - initial_window_size, |
| 5888 | 'a'); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5889 | SpdySerializedFrame body4(spdy_util_.ConstructSpdyDataFrame( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5890 | 1, last_body.c_str(), last_body.size(), false)); |
| 5891 | |
| 5892 | // Also send a "hello!" after WINDOW_UPDATE. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5893 | SpdySerializedFrame body5(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5894 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5895 | // Fill in mock writes. |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5896 | size_t i = 0; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5897 | std::vector<MockWrite> writes; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5898 | writes.push_back(CreateMockWrite(req, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5899 | for (size_t j = 0; j < num_upload_buffers; j++) { |
| 5900 | for (size_t k = 0; k < num_frames_in_one_upload_buffer; k++) { |
| 5901 | if (k == num_frames_in_one_upload_buffer - 1 && |
| 5902 | kBufferSize % kMaxSpdyFrameChunkSize != 0) { |
| 5903 | if (j == num_upload_buffers - 1 && |
| 5904 | (initial_window_size % kBufferSize != 0)) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5905 | writes.push_back(CreateMockWrite(body3, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5906 | } else { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5907 | writes.push_back(CreateMockWrite(body2, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5908 | } |
| 5909 | } else { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5910 | writes.push_back(CreateMockWrite(body1, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5911 | } |
| 5912 | } |
| 5913 | } |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5914 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5915 | // Fill in mock reads. |
| 5916 | std::vector<MockRead> reads; |
| 5917 | // Force a pause. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5918 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, i++)); |
| 5919 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5920 | // Construct read frame for SETTINGS that gives enough space to upload the |
| 5921 | // rest of the data. |
| 5922 | SettingsMap settings; |
| 5923 | settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 5924 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, initial_window_size * 2); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5925 | SpdySerializedFrame settings_frame_large( |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5926 | spdy_util_.ConstructSpdySettings(settings)); |
| 5927 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5928 | reads.push_back(CreateMockRead(settings_frame_large, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5929 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5930 | SpdySerializedFrame session_window_update( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5931 | spdy_util_.ConstructSpdyWindowUpdate(0, |
| 5932 | last_body.size() + kUploadDataSize)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5933 | reads.push_back(CreateMockRead(session_window_update, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5934 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5935 | SpdySerializedFrame settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
| 5936 | writes.push_back(CreateMockWrite(settings_ack, i++)); |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 5937 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5938 | // Stalled frames which can be sent after |settings_ack|. |
| 5939 | if (last_body.size() > 0) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5940 | writes.push_back(CreateMockWrite(body4, i++)); |
| 5941 | writes.push_back(CreateMockWrite(body5, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5942 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5943 | SpdySerializedFrame reply(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5944 | reads.push_back(CreateMockRead(reply, i++)); |
| 5945 | reads.push_back(CreateMockRead(body2, i++)); |
| 5946 | reads.push_back(CreateMockRead(body5, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5947 | reads.push_back(MockRead(ASYNC, 0, i++)); // EOF |
| 5948 | |
| 5949 | // Force all writes to happen before any read, last write will not |
| 5950 | // actually queue a frame, due to window size being 0. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5951 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 5952 | writes.size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5953 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5954 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5955 | std::string upload_data_string(kBufferSize * num_upload_buffers, 'a'); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5956 | upload_data_string.append(kUploadData, kUploadDataSize); |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5957 | element_readers.push_back(base::WrapUnique(new UploadBytesElementReader( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5958 | upload_data_string.c_str(), upload_data_string.size()))); |
| 5959 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5960 | |
| 5961 | HttpRequestInfo request; |
| 5962 | request.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5963 | request.url = default_url_; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5964 | request.upload_data_stream = &upload_data_stream; |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5965 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 5966 | NULL); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5967 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5968 | helper.AddData(&data); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5969 | |
| 5970 | HttpNetworkTransaction* trans = helper.trans(); |
| 5971 | |
| 5972 | TestCompletionCallback callback; |
| 5973 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5974 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5975 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5976 | data.RunUntilPaused(); // Write as much as we can. |
| 5977 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5978 | |
| 5979 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5980 | ASSERT_TRUE(stream); |
| 5981 | ASSERT_TRUE(stream->stream()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5982 | EXPECT_EQ(0, stream->stream()->send_window_size()); |
| 5983 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5984 | if (initial_window_size % kBufferSize != 0) { |
| 5985 | // If it does not take whole number of full upload buffer to zero out |
| 5986 | // initial window size, then the upload data is not at EOF, because the |
| 5987 | // last read must be stalled. |
| 5988 | EXPECT_FALSE(upload_data_stream.IsEOF()); |
| 5989 | } else { |
| 5990 | // All the body data should have been read. |
| 5991 | // TODO(satorux): This is because of the weirdness in reading the request |
| 5992 | // body in OnSendBodyComplete(). See crbug.com/113107. |
| 5993 | EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 5994 | } |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5995 | // But the body is not yet fully sent (kUploadData is not yet sent) |
| 5996 | // since we're send-stalled. |
| 5997 | EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 5998 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5999 | // Read in SETTINGS frame to unstall. |
| 6000 | data.Resume(); |
| 6001 | base::RunLoop().RunUntilIdle(); |
| 6002 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6003 | rv = callback.WaitForResult(); |
| 6004 | helper.VerifyDataConsumed(); |
| 6005 | // If stream is NULL, that means it was unstalled and closed. |
| 6006 | EXPECT_TRUE(stream->stream() == NULL); |
| 6007 | } |
| 6008 | |
| 6009 | // Test we correctly handle the case where the SETTINGS frame results in a |
| 6010 | // negative send window size. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6011 | TEST_F(SpdyNetworkTransactionTest, FlowControlNegativeSendWindowSize) { |
bnc | bca843ba | 2016-07-14 13:05:48 | [diff] [blame] | 6012 | const int32_t initial_window_size = kDefaultInitialWindowSize; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6013 | // Number of upload data buffers we need to send to zero out the window size |
| 6014 | // is the minimal number of upload buffers takes to be bigger than |
| 6015 | // |initial_window_size|. |
| 6016 | size_t num_upload_buffers = |
| 6017 | ceil(static_cast<double>(initial_window_size) / kBufferSize); |
| 6018 | // Each upload data buffer consists of |num_frames_in_one_upload_buffer| |
| 6019 | // frames, each with |kMaxSpdyFrameChunkSize| bytes except the last frame, |
| 6020 | // which has kBufferSize % kMaxSpdyChunkSize bytes. |
| 6021 | size_t num_frames_in_one_upload_buffer = |
| 6022 | ceil(static_cast<double>(kBufferSize) / kMaxSpdyFrameChunkSize); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6023 | |
| 6024 | // Construct content for a data frame of maximum size. |
| 6025 | std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 6026 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6027 | SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6028 | kDefaultUrl, 1, |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6029 | /*content_length=*/kBufferSize * num_upload_buffers + kUploadDataSize, |
| 6030 | LOWEST, NULL, 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6031 | |
| 6032 | // Full frames. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6033 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 6034 | 1, content.c_str(), content.size(), false)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6035 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6036 | // Last frame in each upload data buffer. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6037 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6038 | 1, content.c_str(), kBufferSize % kMaxSpdyFrameChunkSize, false)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6039 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6040 | // The very last frame before the stalled frames. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6041 | SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6042 | 1, content.c_str(), |
| 6043 | initial_window_size % kBufferSize % kMaxSpdyFrameChunkSize, false)); |
| 6044 | |
| 6045 | // Data frames to be sent once WINDOW_UPDATE frame is received. |
| 6046 | |
| 6047 | // If kBufferSize * num_upload_buffers > initial_window_size, |
| 6048 | // we need one additional frame to send the rest of 'a'. |
| 6049 | std::string last_body(kBufferSize * num_upload_buffers - initial_window_size, |
| 6050 | 'a'); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6051 | SpdySerializedFrame body4(spdy_util_.ConstructSpdyDataFrame( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6052 | 1, last_body.c_str(), last_body.size(), false)); |
| 6053 | |
| 6054 | // Also send a "hello!" after WINDOW_UPDATE. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6055 | SpdySerializedFrame body5(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6056 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6057 | // Fill in mock writes. |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6058 | size_t i = 0; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6059 | std::vector<MockWrite> writes; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6060 | writes.push_back(CreateMockWrite(req, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6061 | for (size_t j = 0; j < num_upload_buffers; j++) { |
| 6062 | for (size_t k = 0; k < num_frames_in_one_upload_buffer; k++) { |
| 6063 | if (k == num_frames_in_one_upload_buffer - 1 && |
| 6064 | kBufferSize % kMaxSpdyFrameChunkSize != 0) { |
| 6065 | if (j == num_upload_buffers - 1 && |
| 6066 | (initial_window_size % kBufferSize != 0)) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6067 | writes.push_back(CreateMockWrite(body3, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6068 | } else { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6069 | writes.push_back(CreateMockWrite(body2, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6070 | } |
| 6071 | } else { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6072 | writes.push_back(CreateMockWrite(body1, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6073 | } |
| 6074 | } |
| 6075 | } |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6076 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6077 | // Fill in mock reads. |
| 6078 | std::vector<MockRead> reads; |
| 6079 | // Force a pause. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 6080 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6081 | // Construct read frame for SETTINGS that makes the send_window_size |
| 6082 | // negative. |
| 6083 | SettingsMap new_settings; |
| 6084 | new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6085 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, initial_window_size / 2); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6086 | SpdySerializedFrame settings_frame_small( |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6087 | spdy_util_.ConstructSpdySettings(new_settings)); |
| 6088 | // Construct read frames for WINDOW_UPDATE that makes the send_window_size |
| 6089 | // positive. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6090 | SpdySerializedFrame session_window_update_init_size( |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6091 | spdy_util_.ConstructSpdyWindowUpdate(0, initial_window_size)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6092 | SpdySerializedFrame window_update_init_size( |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6093 | spdy_util_.ConstructSpdyWindowUpdate(1, initial_window_size)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6094 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6095 | reads.push_back(CreateMockRead(settings_frame_small, i++)); |
| 6096 | reads.push_back(CreateMockRead(session_window_update_init_size, i++)); |
| 6097 | reads.push_back(CreateMockRead(window_update_init_size, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6098 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6099 | SpdySerializedFrame settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
| 6100 | writes.push_back(CreateMockWrite(settings_ack, i++)); |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 6101 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6102 | // Stalled frames which can be sent after |settings_ack|. |
| 6103 | if (last_body.size() > 0) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6104 | writes.push_back(CreateMockWrite(body4, i++)); |
| 6105 | writes.push_back(CreateMockWrite(body5, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6106 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6107 | SpdySerializedFrame reply(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6108 | reads.push_back(CreateMockRead(reply, i++)); |
| 6109 | reads.push_back(CreateMockRead(body2, i++)); |
| 6110 | reads.push_back(CreateMockRead(body5, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6111 | reads.push_back(MockRead(ASYNC, 0, i++)); // EOF |
| 6112 | |
| 6113 | // Force all writes to happen before any read, last write will not |
| 6114 | // actually queue a frame, due to window size being 0. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 6115 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 6116 | writes.size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6117 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 6118 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6119 | std::string upload_data_string(kBufferSize * num_upload_buffers, 'a'); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6120 | upload_data_string.append(kUploadData, kUploadDataSize); |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 6121 | element_readers.push_back(base::WrapUnique(new UploadBytesElementReader( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6122 | upload_data_string.c_str(), upload_data_string.size()))); |
| 6123 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6124 | |
| 6125 | HttpRequestInfo request; |
| 6126 | request.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6127 | request.url = default_url_; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6128 | request.upload_data_stream = &upload_data_stream; |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6129 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 6130 | NULL); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6131 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 6132 | helper.AddData(&data); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6133 | |
| 6134 | HttpNetworkTransaction* trans = helper.trans(); |
| 6135 | |
| 6136 | TestCompletionCallback callback; |
| 6137 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6138 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6139 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 6140 | data.RunUntilPaused(); // Write as much as we can. |
| 6141 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6142 | |
| 6143 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6144 | ASSERT_TRUE(stream); |
| 6145 | ASSERT_TRUE(stream->stream()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6146 | EXPECT_EQ(0, stream->stream()->send_window_size()); |
| 6147 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6148 | if (initial_window_size % kBufferSize != 0) { |
| 6149 | // If it does not take whole number of full upload buffer to zero out |
| 6150 | // initial window size, then the upload data is not at EOF, because the |
| 6151 | // last read must be stalled. |
| 6152 | EXPECT_FALSE(upload_data_stream.IsEOF()); |
| 6153 | } else { |
| 6154 | // All the body data should have been read. |
| 6155 | // TODO(satorux): This is because of the weirdness in reading the request |
| 6156 | // body in OnSendBodyComplete(). See crbug.com/113107. |
| 6157 | EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 6158 | } |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6159 | |
| 6160 | // Read in WINDOW_UPDATE or SETTINGS frame. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 6161 | data.Resume(); |
| 6162 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6163 | rv = callback.WaitForResult(); |
| 6164 | helper.VerifyDataConsumed(); |
| 6165 | } |
| 6166 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6167 | TEST_F(SpdyNetworkTransactionTest, GoAwayOnOddPushStreamId) { |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 6168 | SpdyHeaderBlock push_headers; |
| 6169 | spdy_util_.AddUrlToHeaderBlock("http://www.example.org/a.dat", &push_headers); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6170 | SpdySerializedFrame push( |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 6171 | spdy_util_.ConstructInitialSpdyPushFrame(std::move(push_headers), 3, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6172 | MockRead reads[] = {CreateMockRead(push, 1)}; |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6173 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6174 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 6175 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6176 | SpdySerializedFrame goaway(spdy_util_.ConstructSpdyGoAway( |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6177 | 0, GOAWAY_PROTOCOL_ERROR, "Odd push stream id.")); |
| 6178 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6179 | CreateMockWrite(req, 0), CreateMockWrite(goaway, 2), |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6180 | }; |
| 6181 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 6182 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6183 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 6184 | BoundNetLog(), NULL); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6185 | helper.RunToCompletion(&data); |
| 6186 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6187 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6188 | } |
| 6189 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6190 | TEST_F(SpdyNetworkTransactionTest, |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6191 | GoAwayOnPushStreamIdLesserOrEqualThanLastAccepted) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6192 | SpdySerializedFrame push_a(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6193 | NULL, 0, 4, 1, GetDefaultUrlWithPath("/a.dat").c_str())); |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 6194 | SpdyHeaderBlock push_b_headers; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6195 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/b.dat"), |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 6196 | &push_b_headers); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6197 | SpdySerializedFrame push_b(spdy_util_.ConstructInitialSpdyPushFrame( |
| 6198 | std::move(push_b_headers), 2, 1)); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6199 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6200 | CreateMockRead(push_a, 1), CreateMockRead(push_b, 2), |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6201 | }; |
| 6202 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6203 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 6204 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6205 | SpdySerializedFrame goaway(spdy_util_.ConstructSpdyGoAway( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 6206 | 4, GOAWAY_PROTOCOL_ERROR, |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6207 | "New push stream id must be greater than the last accepted.")); |
| 6208 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6209 | CreateMockWrite(req, 0), CreateMockWrite(goaway, 3), |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6210 | }; |
| 6211 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 6212 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6213 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 6214 | BoundNetLog(), NULL); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6215 | helper.RunToCompletion(&data); |
| 6216 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6217 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6218 | } |
| 6219 | |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6220 | // Regression test for https://crbug.com/493348: request header exceeds 16 kB |
| 6221 | // and thus sent in multiple frames when using HTTP/2. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6222 | TEST_F(SpdyNetworkTransactionTest, LargeRequest) { |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6223 | const std::string kKey("foo"); |
| 6224 | const std::string kValue(1 << 15, 'z'); |
| 6225 | |
| 6226 | HttpRequestInfo request; |
| 6227 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6228 | request.url = default_url_; |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6229 | request.extra_headers.SetHeader(kKey, kValue); |
| 6230 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6231 | SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 6232 | headers[kKey] = kValue; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6233 | SpdySerializedFrame req( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6234 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6235 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6236 | CreateMockWrite(req, 0), |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6237 | }; |
| 6238 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6239 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6240 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6241 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6242 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6243 | MockRead(ASYNC, 0, 3) // EOF |
| 6244 | }; |
| 6245 | |
| 6246 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 6247 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6248 | nullptr); |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6249 | helper.RunToCompletion(&data); |
| 6250 | TransactionHelperResult out = helper.output(); |
| 6251 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6252 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6253 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6254 | EXPECT_EQ("hello!", out.response_data); |
| 6255 | } |
| 6256 | |
bnc | d6738334 | 2016-01-08 21:58:43 | [diff] [blame] | 6257 | // Regression test for https://crbug.com/535629: response header exceeds 16 kB. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6258 | TEST_F(SpdyNetworkTransactionTest, LargeResponseHeader) { |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6259 | SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6260 | SpdySerializedFrame req( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6261 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
bnc | d6738334 | 2016-01-08 21:58:43 | [diff] [blame] | 6262 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6263 | CreateMockWrite(req, 0), |
bnc | d6738334 | 2016-01-08 21:58:43 | [diff] [blame] | 6264 | }; |
| 6265 | |
| 6266 | // HPACK decoder implementation limits string literal length to 16 kB. |
| 6267 | const char* response_headers[2]; |
| 6268 | const std::string kKey(16 * 1024, 'a'); |
| 6269 | response_headers[0] = kKey.data(); |
| 6270 | const std::string kValue(16 * 1024, 'b'); |
| 6271 | response_headers[1] = kValue.data(); |
| 6272 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6273 | SpdySerializedFrame resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6274 | spdy_util_.ConstructSpdyGetReply(response_headers, 1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6275 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | d6738334 | 2016-01-08 21:58:43 | [diff] [blame] | 6276 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6277 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
bnc | d6738334 | 2016-01-08 21:58:43 | [diff] [blame] | 6278 | MockRead(ASYNC, 0, 3) // EOF |
| 6279 | }; |
| 6280 | |
| 6281 | HttpRequestInfo request; |
| 6282 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6283 | request.url = default_url_; |
bnc | d6738334 | 2016-01-08 21:58:43 | [diff] [blame] | 6284 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6285 | nullptr); |
bnc | d6738334 | 2016-01-08 21:58:43 | [diff] [blame] | 6286 | |
| 6287 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 6288 | helper.RunToCompletion(&data); |
| 6289 | TransactionHelperResult out = helper.output(); |
| 6290 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6291 | EXPECT_THAT(out.rv, IsOk()); |
bnc | d6738334 | 2016-01-08 21:58:43 | [diff] [blame] | 6292 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
| 6293 | EXPECT_EQ("hello!", out.response_data); |
| 6294 | ASSERT_TRUE(out.response_info.headers->HasHeaderValue(kKey, kValue)); |
| 6295 | } |
| 6296 | |
bnc | 204a6d0 | 2016-08-01 14:34:27 | [diff] [blame] | 6297 | // End of line delimiter is forbidden according to RFC 7230 Section 3.2. |
| 6298 | TEST_F(SpdyNetworkTransactionTest, CRLFInHeaderValue) { |
| 6299 | SpdySerializedFrame req( |
| 6300 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 6301 | SpdySerializedFrame rst( |
| 6302 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 6303 | MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(rst, 2)}; |
| 6304 | |
| 6305 | const char* response_headers[] = {"folded", "foo\r\nbar"}; |
| 6306 | SpdySerializedFrame resp( |
| 6307 | spdy_util_.ConstructSpdyGetReply(response_headers, 1, 1)); |
| 6308 | MockRead reads[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3)}; |
| 6309 | |
| 6310 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 6311 | |
| 6312 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 6313 | BoundNetLog(), nullptr); |
| 6314 | helper.RunToCompletion(&data); |
| 6315 | TransactionHelperResult out = helper.output(); |
| 6316 | |
| 6317 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
| 6318 | } |
| 6319 | |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6320 | class SpdyNetworkTransactionTLSUsageCheckTest |
| 6321 | : public SpdyNetworkTransactionTest { |
| 6322 | protected: |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 6323 | void RunTLSUsageCheckTest( |
| 6324 | std::unique_ptr<SSLSocketDataProvider> ssl_provider) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6325 | SpdySerializedFrame goaway( |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 6326 | spdy_util_.ConstructSpdyGoAway(0, GOAWAY_INADEQUATE_SECURITY, "")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6327 | MockWrite writes[] = {CreateMockWrite(goaway)}; |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6328 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 6329 | StaticSocketDataProvider data(NULL, 0, writes, arraysize(writes)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6330 | HttpRequestInfo request; |
| 6331 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6332 | request.url = default_url_; |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6333 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 6334 | NULL); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 6335 | helper.RunToCompletionWithSSLData(&data, std::move(ssl_provider)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6336 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6337 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6338 | } |
| 6339 | }; |
| 6340 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6341 | TEST_F(SpdyNetworkTransactionTLSUsageCheckTest, TLSVersionTooOld) { |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 6342 | std::unique_ptr<SSLSocketDataProvider> ssl_provider( |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6343 | new SSLSocketDataProvider(ASYNC, OK)); |
| 6344 | SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_SSL3, |
| 6345 | &ssl_provider->connection_status); |
| 6346 | |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 6347 | RunTLSUsageCheckTest(std::move(ssl_provider)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6348 | } |
| 6349 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6350 | TEST_F(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 6351 | std::unique_ptr<SSLSocketDataProvider> ssl_provider( |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6352 | new SSLSocketDataProvider(ASYNC, OK)); |
| 6353 | // Set to TLS_RSA_WITH_NULL_MD5 |
| 6354 | SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); |
| 6355 | |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 6356 | RunTLSUsageCheckTest(std::move(ssl_provider)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6357 | } |
| 6358 | |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 6359 | } // namespace net |