[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" |
mmenke | 16a7cbdd | 2015-04-24 23:00:56 | [diff] [blame] | 33 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 34 | #include "net/log/test_net_log_entry.h" |
| 35 | #include "net/log/test_net_log_util.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 36 | #include "net/proxy/proxy_server.h" |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 37 | #include "net/socket/client_socket_pool_base.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 38 | #include "net/socket/next_proto.h" |
[email protected] | f54c8579 | 2012-03-08 19:06:41 | [diff] [blame] | 39 | #include "net/spdy/buffered_spdy_framer.h" |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 40 | #include "net/spdy/spdy_http_stream.h" |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 41 | #include "net/spdy/spdy_http_utils.h" |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 42 | #include "net/spdy/spdy_session.h" |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 43 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 44 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | a4bfdf7 | 2013-02-22 04:06:16 | [diff] [blame] | 45 | #include "net/spdy/spdy_test_utils.h" |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 46 | #include "net/ssl/ssl_connection_status_flags.h" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 47 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 48 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 49 | #include "net/test/test_data_directory.h" |
[email protected] | d2db029 | 2011-01-26 20:23:44 | [diff] [blame] | 50 | #include "net/url_request/url_request_test_util.h" |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 51 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 52 | #include "testing/platform_test.h" |
| 53 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 54 | using net::test::IsError; |
| 55 | using net::test::IsOk; |
| 56 | |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 57 | //----------------------------------------------------------------------------- |
| 58 | |
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 59 | namespace net { |
[email protected] | dae22c5 | 2010-07-30 02:16:35 | [diff] [blame] | 60 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 61 | namespace { |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 62 | |
| 63 | using testing::Each; |
| 64 | using testing::Eq; |
| 65 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 66 | const int32_t kBufferSize = SpdyHttpStream::kRequestBodyBufferSize; |
| 67 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 68 | } // namespace |
| 69 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 70 | class SpdyNetworkTransactionTest : public ::testing::Test { |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 71 | protected: |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 72 | SpdyNetworkTransactionTest() |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 73 | : default_url_(kDefaultUrl), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 74 | host_port_pair_(HostPortPair::FromURL(default_url_)) {} |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 75 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 76 | ~SpdyNetworkTransactionTest() override { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 77 | // UploadDataStream may post a deletion tasks back to the message loop on |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 78 | // destruction. |
| 79 | upload_data_stream_.reset(); |
| 80 | base::RunLoop().RunUntilIdle(); |
| 81 | } |
| 82 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 83 | void SetUp() override { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 84 | get_request_initialized_ = false; |
| 85 | post_request_initialized_ = false; |
| 86 | chunked_post_request_initialized_ = false; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 87 | ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 88 | } |
| 89 | |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 90 | struct TransactionHelperResult { |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 91 | int rv; |
| 92 | std::string status_line; |
| 93 | std::string response_data; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 94 | HttpResponseInfo response_info; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 95 | }; |
| 96 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 97 | // A helper class that handles all the initial npn/ssl setup. |
| 98 | class NormalSpdyTransactionHelper { |
| 99 | public: |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 100 | NormalSpdyTransactionHelper( |
| 101 | const HttpRequestInfo& request, |
| 102 | RequestPriority priority, |
| 103 | const BoundNetLog& log, |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 104 | std::unique_ptr<SpdySessionDependencies> session_deps) |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 105 | : request_(request), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 106 | priority_(priority), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 107 | session_deps_(session_deps.get() == NULL |
| 108 | ? base::MakeUnique<SpdySessionDependencies>() |
| 109 | : std::move(session_deps)), |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 110 | session_( |
| 111 | SpdySessionDependencies::SpdyCreateSession(session_deps_.get())), |
bnc | 927c496 | 2016-07-21 14:45:59 | [diff] [blame] | 112 | log_(log) {} |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 113 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 114 | ~NormalSpdyTransactionHelper() { |
| 115 | // Any test which doesn't close the socket by sending it an EOF will |
| 116 | // have a valid session left open, which leaks the entire session pool. |
| 117 | // This is just fine - in fact, some of our tests intentionally do this |
| 118 | // so that we can check consistency of the SpdySessionPool as the test |
| 119 | // finishes. If we had put an EOF on the socket, the SpdySession would |
| 120 | // have closed and we wouldn't be able to check the consistency. |
| 121 | |
| 122 | // Forcefully close existing sessions here. |
| 123 | session()->spdy_session_pool()->CloseAllSessions(); |
| 124 | } |
| 125 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 126 | void RunPreTestSetup() { |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 127 | // We're now ready to use SSL-npn SPDY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 128 | trans_.reset(new HttpNetworkTransaction(priority_, session_.get())); |
[email protected] | cb54b3b2 | 2010-06-03 16:28:55 | [diff] [blame] | 129 | } |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 130 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 131 | // Start the transaction, read some data, finish. |
| 132 | void RunDefaultTest() { |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 133 | if (!StartDefaultTest()) |
| 134 | return; |
| 135 | FinishDefaultTest(); |
| 136 | } |
| 137 | |
| 138 | bool StartDefaultTest() { |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 139 | output_.rv = trans_->Start(&request_, callback_.callback(), log_); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 140 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 141 | // We expect an IO Pending or some sort of error. |
| 142 | EXPECT_LT(output_.rv, 0); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 143 | return output_.rv == ERR_IO_PENDING; |
| 144 | } |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 145 | |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 146 | void FinishDefaultTest() { |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 147 | output_.rv = callback_.WaitForResult(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 148 | if (output_.rv != OK) { |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 149 | session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 150 | return; |
| 151 | } |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 152 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 153 | // Verify responses. |
| 154 | const HttpResponseInfo* response = trans_->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 155 | ASSERT_TRUE(response); |
| 156 | ASSERT_TRUE(response->headers); |
bnc | 927c496 | 2016-07-21 14:45:59 | [diff] [blame] | 157 | EXPECT_EQ(HttpResponseInfo::ConnectionInfoFromNextProto(kProtoHTTP2), |
| 158 | response->connection_info); |
| 159 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 160 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 161 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 162 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 163 | EXPECT_EQ(443, response->socket_address.port()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 164 | output_.status_line = response->headers->GetStatusLine(); |
| 165 | output_.response_info = *response; // Make a copy so we can verify. |
| 166 | output_.rv = ReadTransaction(trans_.get(), &output_.response_data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 167 | } |
| 168 | |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 169 | void FinishDefaultTestWithoutVerification() { |
| 170 | output_.rv = callback_.WaitForResult(); |
| 171 | if (output_.rv != OK) |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 172 | session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 173 | } |
| 174 | |
maksim.sisov | 8d2df66d | 2016-06-20 07:07:11 | [diff] [blame] | 175 | void WaitForCallbackToComplete() { output_.rv = callback_.WaitForResult(); } |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 176 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 177 | // Most tests will want to call this function. In particular, the MockReads |
| 178 | // should end with an empty read, and that read needs to be processed to |
| 179 | // ensure proper deletion of the spdy_session_pool. |
| 180 | void VerifyDataConsumed() { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 181 | for (const SocketDataProvider* provider : data_vector_) { |
| 182 | EXPECT_TRUE(provider->AllReadDataConsumed()); |
| 183 | EXPECT_TRUE(provider->AllWriteDataConsumed()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | |
| 187 | // Occasionally a test will expect to error out before certain reads are |
| 188 | // processed. In that case we want to explicitly ensure that the reads were |
| 189 | // not processed. |
| 190 | void VerifyDataNotConsumed() { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 191 | for (const SocketDataProvider* provider : data_vector_) { |
| 192 | EXPECT_FALSE(provider->AllReadDataConsumed()); |
| 193 | EXPECT_FALSE(provider->AllWriteDataConsumed()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 197 | void RunToCompletion(SocketDataProvider* data) { |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 198 | RunPreTestSetup(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 199 | AddData(data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 200 | RunDefaultTest(); |
| 201 | VerifyDataConsumed(); |
| 202 | } |
[email protected] | e6b0686 | 2010-07-20 16:32:58 | [diff] [blame] | 203 | |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 204 | void RunToCompletionWithSSLData( |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 205 | SocketDataProvider* data, |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 206 | std::unique_ptr<SSLSocketDataProvider> ssl_provider) { |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 207 | RunPreTestSetup(); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 208 | AddDataWithSSLSocketDataProvider(data, std::move(ssl_provider)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 209 | RunDefaultTest(); |
| 210 | VerifyDataConsumed(); |
| 211 | } |
| 212 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 213 | void AddData(SocketDataProvider* data) { |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 214 | std::unique_ptr<SSLSocketDataProvider> ssl_provider( |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 215 | new SSLSocketDataProvider(ASYNC, OK)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 216 | ssl_provider->cert = |
| 217 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 218 | AddDataWithSSLSocketDataProvider(data, std::move(ssl_provider)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | void AddDataWithSSLSocketDataProvider( |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 222 | SocketDataProvider* data, |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 223 | std::unique_ptr<SSLSocketDataProvider> ssl_provider) { |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 224 | data_vector_.push_back(data); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 225 | if (ssl_provider->next_proto == kProtoUnknown) |
| 226 | ssl_provider->next_proto = kProtoHTTP2; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 227 | |
| 228 | session_deps_->socket_factory->AddSSLSocketDataProvider( |
| 229 | ssl_provider.get()); |
olli.raula | ae011c42 | 2015-12-10 07:38:51 | [diff] [blame] | 230 | ssl_vector_.push_back(std::move(ssl_provider)); |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 231 | |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 232 | session_deps_->socket_factory->AddSocketDataProvider(data); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 233 | } |
| 234 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 235 | HttpNetworkTransaction* trans() { return trans_.get(); } |
| 236 | void ResetTrans() { trans_.reset(); } |
| 237 | TransactionHelperResult& output() { return output_; } |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 238 | const HttpRequestInfo& request() const { return request_; } |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 239 | HttpNetworkSession* session() const { return session_.get(); } |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 240 | SpdySessionDependencies* session_deps() { return session_deps_.get(); } |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 241 | |
| 242 | private: |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 243 | typedef std::vector<SocketDataProvider*> DataVector; |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 244 | typedef std::vector<std::unique_ptr<SSLSocketDataProvider>> SSLVector; |
| 245 | typedef std::vector<std::unique_ptr<SocketDataProvider>> AlternateVector; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 246 | HttpRequestInfo request_; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 247 | RequestPriority priority_; |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 248 | std::unique_ptr<SpdySessionDependencies> session_deps_; |
| 249 | std::unique_ptr<HttpNetworkSession> session_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 250 | TransactionHelperResult output_; |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 251 | std::unique_ptr<SocketDataProvider> first_transaction_; |
[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_; |
| 255 | std::unique_ptr<HttpNetworkTransaction> trans_http_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 256 | DataVector data_vector_; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 257 | AlternateVector alternate_vector_; |
bnc | 29b1f07 | 2015-01-14 20:37:49 | [diff] [blame] | 258 | const BoundNetLog log_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 259 | }; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 260 | |
| 261 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 262 | int expected_status); |
| 263 | |
| 264 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 265 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 266 | const HttpRequestInfo& CreateGetPushRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 267 | get_push_request_.method = "GET"; |
| 268 | get_push_request_.url = GURL(GetDefaultUrlWithPath("/foo.dat")); |
| 269 | get_push_request_.load_flags = 0; |
| 270 | return get_push_request_; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 271 | } |
| 272 | |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 273 | const HttpRequestInfo& CreateGetRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 274 | if (!get_request_initialized_) { |
| 275 | get_request_.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 276 | get_request_.url = default_url_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 277 | get_request_.load_flags = 0; |
| 278 | get_request_initialized_ = true; |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 279 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 280 | return get_request_; |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 281 | } |
| 282 | |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 283 | const HttpRequestInfo& CreateGetRequestWithUserAgent() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 284 | if (!get_request_initialized_) { |
| 285 | get_request_.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 286 | get_request_.url = default_url_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 287 | get_request_.load_flags = 0; |
| 288 | get_request_.extra_headers.SetHeader("User-Agent", "Chrome"); |
| 289 | get_request_initialized_ = true; |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 290 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 291 | return get_request_; |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 292 | } |
| 293 | |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 294 | const HttpRequestInfo& CreatePostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 295 | if (!post_request_initialized_) { |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 296 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 297 | element_readers.push_back(base::WrapUnique( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 298 | new UploadBytesElementReader(kUploadData, kUploadDataSize))); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 299 | upload_data_stream_.reset( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 300 | new ElementsUploadDataStream(std::move(element_readers), 0)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 301 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 302 | post_request_.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 303 | post_request_.url = default_url_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 304 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 305 | post_request_initialized_ = true; |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 306 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 307 | return post_request_; |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 308 | } |
| 309 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 310 | const HttpRequestInfo& CreateFilePostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 311 | if (!post_request_initialized_) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 312 | base::FilePath file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 313 | CHECK(base::CreateTemporaryFileInDir(temp_dir_.path(), &file_path)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 314 | CHECK_EQ(static_cast<int>(kUploadDataSize), |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 315 | base::WriteFile(file_path, kUploadData, kUploadDataSize)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 316 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 317 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 318 | element_readers.push_back(base::WrapUnique(new UploadFileElementReader( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 319 | base::ThreadTaskRunnerHandle::Get().get(), file_path, 0, |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 320 | kUploadDataSize, base::Time()))); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 321 | upload_data_stream_.reset( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 322 | new ElementsUploadDataStream(std::move(element_readers), 0)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 323 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 324 | post_request_.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 325 | post_request_.url = default_url_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 326 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 327 | post_request_initialized_ = true; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 328 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 329 | return post_request_; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 330 | } |
| 331 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 332 | const HttpRequestInfo& CreateUnreadableFilePostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 333 | if (post_request_initialized_) |
| 334 | return post_request_; |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 335 | |
| 336 | base::FilePath file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 337 | CHECK(base::CreateTemporaryFileInDir(temp_dir_.path(), &file_path)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 338 | CHECK_EQ(static_cast<int>(kUploadDataSize), |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 339 | base::WriteFile(file_path, kUploadData, kUploadDataSize)); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 340 | CHECK(base::MakeFileUnreadable(file_path)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 341 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 342 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 343 | element_readers.push_back(base::WrapUnique(new UploadFileElementReader( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 344 | base::ThreadTaskRunnerHandle::Get().get(), file_path, 0, |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 345 | kUploadDataSize, base::Time()))); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 346 | upload_data_stream_.reset( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 347 | new ElementsUploadDataStream(std::move(element_readers), 0)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 348 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 349 | post_request_.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 350 | post_request_.url = default_url_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 351 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 352 | post_request_initialized_ = true; |
| 353 | return post_request_; |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 354 | } |
| 355 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 356 | const HttpRequestInfo& CreateComplexPostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 357 | if (!post_request_initialized_) { |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 358 | const int kFileRangeOffset = 1; |
| 359 | const int kFileRangeLength = 3; |
| 360 | CHECK_LT(kFileRangeOffset + kFileRangeLength, kUploadDataSize); |
| 361 | |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 362 | base::FilePath file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 363 | CHECK(base::CreateTemporaryFileInDir(temp_dir_.path(), &file_path)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 364 | CHECK_EQ(static_cast<int>(kUploadDataSize), |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 365 | base::WriteFile(file_path, kUploadData, kUploadDataSize)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 366 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 367 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 368 | element_readers.push_back(base::WrapUnique( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 369 | new UploadBytesElementReader(kUploadData, kFileRangeOffset))); |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 370 | element_readers.push_back(base::WrapUnique(new UploadFileElementReader( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 371 | base::ThreadTaskRunnerHandle::Get().get(), file_path, |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 372 | kFileRangeOffset, kFileRangeLength, base::Time()))); |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 373 | element_readers.push_back(base::WrapUnique(new UploadBytesElementReader( |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 374 | kUploadData + kFileRangeOffset + kFileRangeLength, |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 375 | kUploadDataSize - (kFileRangeOffset + kFileRangeLength)))); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 376 | upload_data_stream_.reset( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 377 | new ElementsUploadDataStream(std::move(element_readers), 0)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 378 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 379 | post_request_.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 380 | post_request_.url = default_url_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 381 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 382 | post_request_initialized_ = true; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 383 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 384 | return post_request_; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 385 | } |
| 386 | |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 387 | const HttpRequestInfo& CreateChunkedPostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 388 | if (!chunked_post_request_initialized_) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 389 | upload_chunked_data_stream_.reset(new ChunkedUploadDataStream(0)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 390 | chunked_post_request_.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 391 | chunked_post_request_.url = default_url_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 392 | chunked_post_request_.upload_data_stream = |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 393 | upload_chunked_data_stream_.get(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 394 | chunked_post_request_initialized_ = true; |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 395 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 396 | return chunked_post_request_; |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 397 | } |
| 398 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 399 | // Read the result of a particular transaction, knowing that we've got |
| 400 | // multiple transactions in the read pipeline; so as we read, we may have |
| 401 | // to skip over data destined for other transactions while we consume |
| 402 | // the data for |trans|. |
| 403 | int ReadResult(HttpNetworkTransaction* trans, |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 404 | std::string* result) { |
| 405 | const int kSize = 3000; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 406 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 407 | int bytes_read = 0; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 408 | scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(kSize)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 409 | TestCompletionCallback callback; |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 410 | while (true) { |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 411 | int rv = trans->Read(buf.get(), kSize, callback.callback()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 412 | if (rv == ERR_IO_PENDING) { |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 413 | rv = callback.WaitForResult(); |
| 414 | } else if (rv <= 0) { |
| 415 | break; |
| 416 | } |
| 417 | result->append(buf->data(), rv); |
| 418 | bytes_read += rv; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 419 | } |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 420 | return bytes_read; |
| 421 | } |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 422 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 423 | void VerifyStreamsClosed(const NormalSpdyTransactionHelper& helper) { |
| 424 | // This lengthy block is reaching into the pool to dig out the active |
| 425 | // session. Once we have the session, we verify that the streams are |
| 426 | // all closed and not leaked at this point. |
| 427 | const GURL& url = helper.request().url; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 428 | SpdySessionKey key(HostPortPair::FromURL(url), ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 429 | PRIVACY_MODE_DISABLED); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 430 | BoundNetLog log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 431 | HttpNetworkSession* session = helper.session(); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 432 | base::WeakPtr<SpdySession> spdy_session = |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 433 | session->spdy_session_pool()->FindAvailableSession(key, url, log); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 434 | ASSERT_TRUE(spdy_session); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 435 | EXPECT_EQ(0u, spdy_session->num_active_streams()); |
| 436 | EXPECT_EQ(0u, spdy_session->num_unclaimed_pushed_streams()); |
| 437 | } |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 438 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 439 | void RunServerPushTest(SequencedSocketData* data, |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 440 | HttpResponseInfo* response, |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 441 | HttpResponseInfo* push_response, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 442 | const std::string& expected) { |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 443 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 444 | BoundNetLog(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 445 | helper.RunPreTestSetup(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 446 | helper.AddData(data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 447 | |
| 448 | HttpNetworkTransaction* trans = helper.trans(); |
| 449 | |
| 450 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 451 | TestCompletionCallback callback; |
| 452 | int rv = trans->Start( |
| 453 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 454 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 455 | rv = callback.WaitForResult(); |
| 456 | |
| 457 | // Request the pushed path. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 458 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
| 459 | rv = trans2.Start(&CreateGetPushRequest(), callback.callback(), |
| 460 | BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 461 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 462 | base::RunLoop().RunUntilIdle(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 463 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 464 | // 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] | 465 | // the results into a single string. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 466 | |
| 467 | // Read the server push body. |
| 468 | std::string result2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 469 | ReadResult(&trans2, &result2); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 470 | // Read the response body. |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 471 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 472 | ReadResult(trans, &result); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 473 | |
| 474 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 475 | EXPECT_TRUE(data->AllReadDataConsumed()); |
| 476 | EXPECT_TRUE(data->AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 477 | |
caseq | e8340bc9 | 2016-04-20 00:02:57 | [diff] [blame] | 478 | LoadTimingInfo load_timing_info; |
| 479 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 480 | EXPECT_TRUE(load_timing_info.push_start.is_null()); |
| 481 | EXPECT_TRUE(load_timing_info.push_end.is_null()); |
| 482 | |
| 483 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 484 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
caseq | e8340bc9 | 2016-04-20 00:02:57 | [diff] [blame] | 485 | EXPECT_FALSE(load_timing_info2.push_start.is_null()); |
| 486 | EXPECT_FALSE(load_timing_info2.push_end.is_null()); |
| 487 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 488 | // Verify that the received push data is same as the expected push data. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 489 | EXPECT_EQ(result2.compare(expected), 0) << "Received data: " |
| 490 | << result2 |
| 491 | << "||||| Expected data: " |
| 492 | << expected; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 493 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 494 | // Verify the response HEADERS. |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 495 | // Copy the response info, because trans goes away. |
| 496 | *response = *trans->GetResponseInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 497 | *push_response = *trans2.GetResponseInfo(); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 498 | |
| 499 | VerifyStreamsClosed(helper); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 500 | } |
| 501 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 502 | static void DeleteSessionCallback(NormalSpdyTransactionHelper* helper, |
| 503 | int result) { |
| 504 | helper->ResetTrans(); |
| 505 | } |
| 506 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 507 | static void StartTransactionCallback(HttpNetworkSession* session, |
| 508 | GURL url, |
| 509 | int result) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 510 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 511 | TestCompletionCallback callback; |
| 512 | HttpRequestInfo request; |
| 513 | request.method = "GET"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 514 | request.url = url; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 515 | request.load_flags = 0; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 516 | int rv = trans.Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 517 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 518 | callback.WaitForResult(); |
| 519 | } |
| 520 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 521 | ChunkedUploadDataStream* upload_chunked_data_stream() const { |
| 522 | return upload_chunked_data_stream_.get(); |
| 523 | } |
| 524 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 525 | std::string GetDefaultUrlWithPath(const char* path) { |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 526 | return std::string(kDefaultUrl) + path; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 527 | } |
| 528 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 529 | const GURL default_url_; |
| 530 | const HostPortPair host_port_pair_; |
[email protected] | 9ec54f8 | 2013-05-10 02:53:05 | [diff] [blame] | 531 | SpdyTestUtil spdy_util_; |
| 532 | |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 533 | private: |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 534 | std::unique_ptr<ChunkedUploadDataStream> upload_chunked_data_stream_; |
| 535 | std::unique_ptr<UploadDataStream> upload_data_stream_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 536 | bool get_request_initialized_; |
| 537 | bool post_request_initialized_; |
| 538 | bool chunked_post_request_initialized_; |
| 539 | HttpRequestInfo get_request_; |
| 540 | HttpRequestInfo post_request_; |
| 541 | HttpRequestInfo chunked_post_request_; |
| 542 | HttpRequestInfo get_push_request_; |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 543 | base::ScopedTempDir temp_dir_; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 544 | }; |
| 545 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 546 | // Verify HttpNetworkTransaction constructor. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 547 | TEST_F(SpdyNetworkTransactionTest, Constructor) { |
| 548 | auto session_deps = base::MakeUnique<SpdySessionDependencies>(); |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 549 | std::unique_ptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 550 | SpdySessionDependencies::SpdyCreateSession(session_deps.get())); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 551 | auto trans = |
| 552 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 553 | } |
| 554 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 555 | TEST_F(SpdyNetworkTransactionTest, Get) { |
[email protected] | 75f30cc2 | 2010-06-28 21:41:38 | [diff] [blame] | 556 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 557 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 558 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 559 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 560 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 561 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 562 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 563 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 564 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 565 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 566 | }; |
| 567 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 568 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 569 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 570 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 571 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 572 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 573 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 574 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 575 | EXPECT_EQ("hello!", out.response_data); |
| 576 | } |
| 577 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 578 | TEST_F(SpdyNetworkTransactionTest, GetAtEachPriority) { |
[email protected] | 3d08dd38 | 2013-10-19 00:13:11 | [diff] [blame] | 579 | for (RequestPriority p = MINIMUM_PRIORITY; p <= MAXIMUM_PRIORITY; |
[email protected] | 31ae7ab | 2012-04-24 21:09:05 | [diff] [blame] | 580 | p = RequestPriority(p + 1)) { |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 581 | SpdyTestUtil spdy_test_util; |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 582 | |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 583 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 584 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 585 | spdy_test_util.ConstructSpdyGet(nullptr, 0, 1, p, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 586 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 587 | |
[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 588 | SpdyPriority spdy_prio = 0; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 589 | EXPECT_TRUE(GetSpdyPriority(req, &spdy_prio)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 590 | // this repeats the RequestPriority-->SpdyPriority mapping from |
| 591 | // SpdyFramer::ConvertRequestPriorityToSpdyPriority to make |
| 592 | // sure it's being done right. |
bnc | 05808ff4 | 2016-01-08 23:48:25 | [diff] [blame] | 593 | switch (p) { |
| 594 | case HIGHEST: |
| 595 | EXPECT_EQ(0, spdy_prio); |
| 596 | break; |
| 597 | case MEDIUM: |
| 598 | EXPECT_EQ(1, spdy_prio); |
| 599 | break; |
| 600 | case LOW: |
| 601 | EXPECT_EQ(2, spdy_prio); |
| 602 | break; |
| 603 | case LOWEST: |
| 604 | EXPECT_EQ(3, spdy_prio); |
| 605 | break; |
| 606 | case IDLE: |
| 607 | EXPECT_EQ(4, spdy_prio); |
| 608 | break; |
| 609 | default: |
| 610 | FAIL(); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 611 | } |
| 612 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 613 | SpdySerializedFrame resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 614 | spdy_test_util.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 615 | SpdySerializedFrame body(spdy_test_util.ConstructSpdyDataFrame(1, true)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 616 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 617 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 618 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 619 | }; |
| 620 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 621 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 622 | arraysize(writes)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 623 | HttpRequestInfo http_req = CreateGetRequest(); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 624 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 625 | NormalSpdyTransactionHelper helper(http_req, p, BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 626 | helper.RunToCompletion(&data); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 627 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 628 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 629 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 630 | EXPECT_EQ("hello!", out.response_data); |
| 631 | } |
| 632 | } |
| 633 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 634 | // Start three gets simultaniously; making sure that multiplexed |
| 635 | // streams work properly. |
| 636 | |
| 637 | // This can't use the TransactionHelper method, since it only |
| 638 | // handles a single transaction, and finishes them as soon |
| 639 | // as it launches them. |
| 640 | |
| 641 | // TODO(gavinp): create a working generalized TransactionHelper that |
| 642 | // can allow multiple streams in flight. |
| 643 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 644 | TEST_F(SpdyNetworkTransactionTest, ThreeGets) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 645 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 646 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 647 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 648 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 649 | SpdySerializedFrame fbody(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 650 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 651 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 652 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 653 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 654 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, false)); |
| 655 | SpdySerializedFrame fbody2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 656 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 657 | SpdySerializedFrame req3( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 658 | spdy_util_.ConstructSpdyGet(nullptr, 0, 5, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 659 | SpdySerializedFrame resp3(spdy_util_.ConstructSpdyGetReply(NULL, 0, 5)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 660 | SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame(5, false)); |
| 661 | SpdySerializedFrame fbody3(spdy_util_.ConstructSpdyDataFrame(5, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 662 | |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 663 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 664 | CreateMockWrite(req, 0), CreateMockWrite(req2, 3), |
| 665 | CreateMockWrite(req3, 6), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 666 | }; |
| 667 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 668 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
| 669 | CreateMockRead(resp2, 4), CreateMockRead(body2, 5), |
| 670 | CreateMockRead(resp3, 7), CreateMockRead(body3, 8), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 671 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 672 | CreateMockRead(fbody, 9), CreateMockRead(fbody2, 10), |
| 673 | CreateMockRead(fbody3, 11), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 674 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 675 | MockRead(ASYNC, 0, 12), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 676 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 677 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 678 | SequencedSocketData data_placeholder1(NULL, 0, NULL, 0); |
| 679 | SequencedSocketData data_placeholder2(NULL, 0, NULL, 0); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 680 | |
| 681 | BoundNetLog log; |
| 682 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 683 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 684 | BoundNetLog(), NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 685 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 686 | helper.AddData(&data); |
rch | aeb3f05 | 2015-04-14 16:02:49 | [diff] [blame] | 687 | // We require placeholder data because three get requests are sent out at |
| 688 | // the same time which results in three sockets being connected. The first |
| 689 | // on will negotiate SPDY and will be used for all requests. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 690 | helper.AddData(&data_placeholder1); |
| 691 | helper.AddData(&data_placeholder2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 692 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session()); |
| 693 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
| 694 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, helper.session()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 695 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 696 | TestCompletionCallback callback1; |
| 697 | TestCompletionCallback callback2; |
| 698 | TestCompletionCallback callback3; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 699 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 700 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 701 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 702 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 703 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 704 | out.rv = trans1.Start(&httpreq1, callback1.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 = trans2.Start(&httpreq2, callback2.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 707 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 708 | out.rv = trans3.Start(&httpreq3, callback3.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 709 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 710 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 711 | out.rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 712 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 713 | out.rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 714 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 715 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 716 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 717 | EXPECT_TRUE(response1->headers); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 718 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 719 | out.status_line = response1->headers->GetStatusLine(); |
| 720 | out.response_info = *response1; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 721 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 722 | trans2.GetResponseInfo(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 723 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 724 | out.rv = ReadTransaction(&trans1, &out.response_data); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 725 | helper.VerifyDataConsumed(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 726 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 727 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 728 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 729 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 730 | EXPECT_EQ("hello!hello!", out.response_data); |
| 731 | } |
| 732 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 733 | TEST_F(SpdyNetworkTransactionTest, TwoGetsLateBinding) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 734 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 735 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 736 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 737 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 738 | SpdySerializedFrame fbody(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 739 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 740 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 741 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 742 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 743 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, false)); |
| 744 | SpdySerializedFrame fbody2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 745 | |
| 746 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 747 | CreateMockWrite(req, 0), CreateMockWrite(req2, 3), |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 748 | }; |
| 749 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 750 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
| 751 | CreateMockRead(resp2, 4), CreateMockRead(body2, 5), |
| 752 | CreateMockRead(fbody, 6), CreateMockRead(fbody2, 7), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 753 | MockRead(ASYNC, 0, 8), // EOF |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 754 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 755 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 756 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 757 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 758 | SequencedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 759 | data_placeholder.set_connect_data(never_finishing_connect); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 760 | |
| 761 | BoundNetLog log; |
| 762 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 763 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 764 | BoundNetLog(), NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 765 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 766 | helper.AddData(&data); |
rch | aeb3f05 | 2015-04-14 16:02:49 | [diff] [blame] | 767 | // We require placeholder data because two requests are sent out at |
| 768 | // the same time which results in two sockets being connected. The first |
| 769 | // on will negotiate SPDY and will be used for all requests. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 770 | helper.AddData(&data_placeholder); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 771 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session()); |
| 772 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 773 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 774 | TestCompletionCallback callback1; |
| 775 | TestCompletionCallback callback2; |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 776 | |
| 777 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 778 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 779 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 780 | out.rv = trans1.Start(&httpreq1, callback1.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 781 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 782 | out.rv = trans2.Start(&httpreq2, callback2.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 783 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 784 | |
| 785 | out.rv = callback1.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 | out.rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 788 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 789 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 790 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 791 | EXPECT_TRUE(response1->headers); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 792 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 793 | out.status_line = response1->headers->GetStatusLine(); |
| 794 | out.response_info = *response1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 795 | out.rv = ReadTransaction(&trans1, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 796 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 797 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 798 | EXPECT_EQ("hello!hello!", out.response_data); |
| 799 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 800 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 801 | EXPECT_TRUE(response2->headers); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 802 | EXPECT_TRUE(response2->was_fetched_via_spdy); |
| 803 | out.status_line = response2->headers->GetStatusLine(); |
| 804 | out.response_info = *response2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 805 | out.rv = ReadTransaction(&trans2, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 806 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 807 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 808 | EXPECT_EQ("hello!hello!", out.response_data); |
| 809 | |
| 810 | helper.VerifyDataConsumed(); |
| 811 | } |
| 812 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 813 | TEST_F(SpdyNetworkTransactionTest, TwoGetsLateBindingFromPreconnect) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 814 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 815 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 816 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 817 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 818 | SpdySerializedFrame fbody(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 819 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 820 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 821 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 822 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 823 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, false)); |
| 824 | SpdySerializedFrame fbody2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 825 | |
| 826 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 827 | CreateMockWrite(req, 0), CreateMockWrite(req2, 3), |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 828 | }; |
| 829 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 830 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
| 831 | CreateMockRead(resp2, 4), CreateMockRead(body2, 5), |
| 832 | CreateMockRead(fbody, 6), CreateMockRead(fbody2, 7), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 833 | MockRead(ASYNC, 0, 8), // EOF |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 834 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 835 | SequencedSocketData preconnect_data(reads, arraysize(reads), writes, |
| 836 | arraysize(writes)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 837 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 838 | MockConnect never_finishing_connect(ASYNC, ERR_IO_PENDING); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 839 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 840 | SequencedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 841 | data_placeholder.set_connect_data(never_finishing_connect); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 842 | |
| 843 | BoundNetLog log; |
| 844 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 845 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 846 | BoundNetLog(), NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 847 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 848 | helper.AddData(&preconnect_data); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 849 | // We require placeholder data because 3 connections are attempted (first is |
| 850 | // the preconnect, 2nd and 3rd are the never finished connections. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 851 | helper.AddData(&data_placeholder); |
| 852 | helper.AddData(&data_placeholder); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 853 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 854 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session()); |
| 855 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 856 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 857 | TestCompletionCallback callback1; |
| 858 | TestCompletionCallback callback2; |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 859 | |
| 860 | HttpRequestInfo httpreq = CreateGetRequest(); |
| 861 | |
| 862 | // Preconnect the first. |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 863 | HttpStreamFactory* http_stream_factory = |
| 864 | helper.session()->http_stream_factory(); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 865 | |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 866 | http_stream_factory->PreconnectStreams(1, httpreq); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 867 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 868 | out.rv = trans1.Start(&httpreq, callback1.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 869 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 870 | out.rv = trans2.Start(&httpreq, callback2.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 871 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 872 | |
| 873 | out.rv = callback1.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 | out.rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 876 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 877 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 878 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 879 | EXPECT_TRUE(response1->headers); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 880 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 881 | out.status_line = response1->headers->GetStatusLine(); |
| 882 | out.response_info = *response1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 883 | out.rv = ReadTransaction(&trans1, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 884 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 885 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 886 | EXPECT_EQ("hello!hello!", out.response_data); |
| 887 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 888 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 889 | EXPECT_TRUE(response2->headers); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 890 | EXPECT_TRUE(response2->was_fetched_via_spdy); |
| 891 | out.status_line = response2->headers->GetStatusLine(); |
| 892 | out.response_info = *response2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 893 | out.rv = ReadTransaction(&trans2, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 894 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 895 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 896 | EXPECT_EQ("hello!hello!", out.response_data); |
| 897 | |
| 898 | helper.VerifyDataConsumed(); |
| 899 | } |
| 900 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 901 | // Similar to ThreeGets above, however this test adds a SETTINGS |
| 902 | // frame. The SETTINGS frame is read during the IO loop waiting on |
| 903 | // the first transaction completion, and sets a maximum concurrent |
| 904 | // stream limit of 1. This means that our IO loop exists after the |
| 905 | // second transaction completes, so we can assert on read_index(). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 906 | TEST_F(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrent) { |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 907 | // Construct the request. |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 908 | // Each request fully completes before the next starts. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 909 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 910 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 911 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 912 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 913 | SpdySerializedFrame fbody(spdy_util_.ConstructSpdyDataFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 914 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 915 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 916 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 917 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 918 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 919 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, false)); |
| 920 | SpdySerializedFrame fbody2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 921 | spdy_util_.UpdateWithStreamDestruction(3); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 922 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 923 | SpdySerializedFrame req3( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 924 | spdy_util_.ConstructSpdyGet(nullptr, 0, 5, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 925 | SpdySerializedFrame resp3(spdy_util_.ConstructSpdyGetReply(NULL, 0, 5)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 926 | SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame(5, false)); |
| 927 | SpdySerializedFrame fbody3(spdy_util_.ConstructSpdyDataFrame(5, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 928 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 929 | SettingsMap settings; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 930 | const uint32_t max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 931 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 932 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 933 | SpdySerializedFrame settings_frame( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 934 | spdy_util_.ConstructSpdySettings(settings)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 935 | SpdySerializedFrame settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 936 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 937 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 938 | CreateMockWrite(req, 0), CreateMockWrite(settings_ack, 5), |
| 939 | CreateMockWrite(req2, 6), CreateMockWrite(req3, 10), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 940 | }; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 941 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 942 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 943 | CreateMockRead(settings_frame, 1), |
| 944 | CreateMockRead(resp, 2), |
| 945 | CreateMockRead(body, 3), |
| 946 | CreateMockRead(fbody, 4), |
| 947 | CreateMockRead(resp2, 7), |
| 948 | CreateMockRead(body2, 8), |
| 949 | CreateMockRead(fbody2, 9), |
| 950 | CreateMockRead(resp3, 11), |
| 951 | CreateMockRead(body3, 12), |
| 952 | CreateMockRead(fbody3, 13), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 953 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 954 | MockRead(ASYNC, 0, 14), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 955 | }; |
| 956 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 957 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 958 | |
| 959 | BoundNetLog log; |
| 960 | TransactionHelperResult out; |
| 961 | { |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 962 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 963 | BoundNetLog(), NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 964 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 965 | helper.AddData(&data); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 966 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session()); |
| 967 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
| 968 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, helper.session()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 969 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 970 | TestCompletionCallback callback1; |
| 971 | TestCompletionCallback callback2; |
| 972 | TestCompletionCallback callback3; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 973 | |
| 974 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 975 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 976 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
| 977 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 978 | out.rv = trans1.Start(&httpreq1, callback1.callback(), log); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 979 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 980 | // Run transaction 1 through quickly to force a read of our SETTINGS |
| 981 | // frame. |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 982 | out.rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 983 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 984 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 985 | out.rv = trans2.Start(&httpreq2, callback2.callback(), log); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 986 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 987 | out.rv = trans3.Start(&httpreq3, callback3.callback(), log); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 988 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
| 989 | out.rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 990 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 991 | |
| 992 | out.rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 993 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 994 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 995 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 996 | ASSERT_TRUE(response1); |
| 997 | EXPECT_TRUE(response1->headers); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 998 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 999 | out.status_line = response1->headers->GetStatusLine(); |
| 1000 | out.response_info = *response1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 1001 | out.rv = ReadTransaction(&trans1, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1002 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1003 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1004 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1005 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 1006 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1007 | out.status_line = response2->headers->GetStatusLine(); |
| 1008 | out.response_info = *response2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 1009 | out.rv = ReadTransaction(&trans2, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1010 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1011 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1012 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1013 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 1014 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1015 | out.status_line = response3->headers->GetStatusLine(); |
| 1016 | out.response_info = *response3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 1017 | out.rv = ReadTransaction(&trans3, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1018 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1019 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1020 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1021 | |
| 1022 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1023 | } |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1024 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | // Similar to ThreeGetsWithMaxConcurrent above, however this test adds |
| 1028 | // a fourth transaction. The third and fourth transactions have |
| 1029 | // different data ("hello!" vs "hello!hello!") and because of the |
| 1030 | // user specified priority, we expect to see them inverted in |
| 1031 | // the response from the server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1032 | TEST_F(SpdyNetworkTransactionTest, FourGetsWithMaxConcurrentPriority) { |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1033 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1034 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1035 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1036 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1037 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 1038 | SpdySerializedFrame fbody(spdy_util_.ConstructSpdyDataFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1039 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1040 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1041 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1042 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1043 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1044 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, false)); |
| 1045 | SpdySerializedFrame fbody2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1046 | spdy_util_.UpdateWithStreamDestruction(3); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1047 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1048 | SpdySerializedFrame req4( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1049 | spdy_util_.ConstructSpdyGet(nullptr, 0, 5, HIGHEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1050 | SpdySerializedFrame resp4(spdy_util_.ConstructSpdyGetReply(NULL, 0, 5)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1051 | SpdySerializedFrame fbody4(spdy_util_.ConstructSpdyDataFrame(5, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1052 | spdy_util_.UpdateWithStreamDestruction(5); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1053 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1054 | SpdySerializedFrame req3( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1055 | spdy_util_.ConstructSpdyGet(nullptr, 0, 7, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1056 | SpdySerializedFrame resp3(spdy_util_.ConstructSpdyGetReply(NULL, 0, 7)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1057 | SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame(7, false)); |
| 1058 | SpdySerializedFrame fbody3(spdy_util_.ConstructSpdyDataFrame(7, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1059 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1060 | SettingsMap settings; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 1061 | const uint32_t max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1062 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1063 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1064 | SpdySerializedFrame settings_frame( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1065 | spdy_util_.ConstructSpdySettings(settings)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1066 | SpdySerializedFrame settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1067 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1068 | CreateMockWrite(req, 0), CreateMockWrite(settings_ack, 5), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1069 | // By making these synchronous, it guarantees that they are not *started* |
| 1070 | // before their sequence number, which in turn verifies that only a single |
| 1071 | // request is in-flight at a time. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1072 | CreateMockWrite(req2, 6, SYNCHRONOUS), |
| 1073 | CreateMockWrite(req4, 10, SYNCHRONOUS), |
| 1074 | CreateMockWrite(req3, 13, SYNCHRONOUS), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1075 | }; |
| 1076 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1077 | CreateMockRead(settings_frame, 1), |
| 1078 | CreateMockRead(resp, 2), |
| 1079 | CreateMockRead(body, 3), |
| 1080 | CreateMockRead(fbody, 4), |
| 1081 | CreateMockRead(resp2, 7), |
| 1082 | CreateMockRead(body2, 8), |
| 1083 | CreateMockRead(fbody2, 9), |
| 1084 | CreateMockRead(resp4, 11), |
| 1085 | CreateMockRead(fbody4, 12), |
| 1086 | CreateMockRead(resp3, 14), |
| 1087 | CreateMockRead(body3, 15), |
| 1088 | CreateMockRead(fbody3, 16), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1089 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1090 | MockRead(ASYNC, 0, 17), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1091 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1092 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1093 | BoundNetLog log; |
| 1094 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1095 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1096 | BoundNetLog(), NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1097 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1098 | helper.AddData(&data); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1099 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 1100 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session()); |
| 1101 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
| 1102 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, helper.session()); |
| 1103 | HttpNetworkTransaction trans4(HIGHEST, helper.session()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1104 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1105 | TestCompletionCallback callback1; |
| 1106 | TestCompletionCallback callback2; |
| 1107 | TestCompletionCallback callback3; |
| 1108 | TestCompletionCallback callback4; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1109 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1110 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1111 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1112 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
| 1113 | HttpRequestInfo httpreq4 = CreateGetRequest(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1114 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 1115 | out.rv = trans1.Start(&httpreq1, callback1.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1116 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1117 | // Run transaction 1 through quickly to force a read of our SETTINGS frame. |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1118 | out.rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1119 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1120 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 1121 | out.rv = trans2.Start(&httpreq2, callback2.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 = trans3.Start(&httpreq3, callback3.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1124 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 1125 | out.rv = trans4.Start(&httpreq4, callback4.callback(), log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1126 | ASSERT_THAT(out.rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1127 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1128 | out.rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1129 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1130 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1131 | out.rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1132 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1133 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 1134 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1135 | EXPECT_TRUE(response1->headers); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1136 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1137 | out.status_line = response1->headers->GetStatusLine(); |
| 1138 | out.response_info = *response1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 1139 | out.rv = ReadTransaction(&trans1, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1140 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1141 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1142 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1143 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 1144 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1145 | out.status_line = response2->headers->GetStatusLine(); |
| 1146 | out.response_info = *response2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 1147 | out.rv = ReadTransaction(&trans2, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1148 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1149 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1150 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1151 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1152 | // notice: response3 gets two hellos, response4 gets one |
| 1153 | // hello, so we know dequeuing priority was respected. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 1154 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1155 | out.status_line = response3->headers->GetStatusLine(); |
| 1156 | out.response_info = *response3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 1157 | out.rv = ReadTransaction(&trans3, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1158 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1159 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1160 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1161 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1162 | out.rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1163 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 1164 | const HttpResponseInfo* response4 = trans4.GetResponseInfo(); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1165 | out.status_line = response4->headers->GetStatusLine(); |
| 1166 | out.response_info = *response4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 1167 | out.rv = ReadTransaction(&trans4, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1168 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1169 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1170 | EXPECT_EQ("hello!", out.response_data); |
| 1171 | helper.VerifyDataConsumed(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1172 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | // Similar to ThreeGetsMaxConcurrrent above, however, this test |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1176 | // deletes a session in the middle of the transaction to ensure |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1177 | // that we properly remove pendingcreatestream objects from |
| 1178 | // the spdy_session |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1179 | TEST_F(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentDelete) { |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1180 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1181 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1182 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1183 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1184 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 1185 | SpdySerializedFrame fbody(spdy_util_.ConstructSpdyDataFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1186 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1187 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1188 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1189 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1190 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1191 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, false)); |
| 1192 | SpdySerializedFrame fbody2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1193 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1194 | SettingsMap settings; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 1195 | const uint32_t max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1196 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1197 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1198 | SpdySerializedFrame settings_frame( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1199 | spdy_util_.ConstructSpdySettings(settings)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1200 | SpdySerializedFrame settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1201 | |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1202 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1203 | CreateMockWrite(req, 0), CreateMockWrite(settings_ack, 5), |
| 1204 | CreateMockWrite(req2, 6), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1205 | }; |
| 1206 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1207 | CreateMockRead(settings_frame, 1), CreateMockRead(resp, 2), |
| 1208 | CreateMockRead(body, 3), CreateMockRead(fbody, 4), |
| 1209 | CreateMockRead(resp2, 7), CreateMockRead(body2, 8), |
| 1210 | CreateMockRead(fbody2, 9), MockRead(ASYNC, 0, 10), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1211 | }; |
| 1212 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1213 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1214 | |
| 1215 | BoundNetLog log; |
| 1216 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1217 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1218 | BoundNetLog(), NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1219 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1220 | helper.AddData(&data); |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 1221 | std::unique_ptr<HttpNetworkTransaction> trans1( |
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> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1224 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 1225 | std::unique_ptr<HttpNetworkTransaction> trans3( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1226 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1227 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1228 | TestCompletionCallback callback1; |
| 1229 | TestCompletionCallback callback2; |
| 1230 | TestCompletionCallback callback3; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1231 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1232 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1233 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1234 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1235 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1236 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1237 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1238 | // Run transaction 1 through quickly to force a read of our SETTINGS frame. |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1239 | out.rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1240 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1241 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1242 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1243 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1244 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
olli.raula | 7ca9cd1d | 2016-01-04 06:50:37 | [diff] [blame] | 1245 | trans3.reset(); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1246 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
| 1247 | out.rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1248 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1249 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1250 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1251 | ASSERT_TRUE(response1); |
| 1252 | EXPECT_TRUE(response1->headers); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1253 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1254 | out.status_line = response1->headers->GetStatusLine(); |
| 1255 | out.response_info = *response1; |
| 1256 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1257 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1258 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1259 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1260 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1261 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1262 | ASSERT_TRUE(response2); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1263 | out.status_line = response2->headers->GetStatusLine(); |
| 1264 | out.response_info = *response2; |
| 1265 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1266 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1267 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1268 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1269 | helper.VerifyDataConsumed(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1270 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1271 | } |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1272 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1273 | namespace { |
| 1274 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1275 | // The KillerCallback will delete the transaction on error as part of the |
| 1276 | // callback. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1277 | class KillerCallback : public TestCompletionCallbackBase { |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1278 | public: |
| 1279 | explicit KillerCallback(HttpNetworkTransaction* transaction) |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1280 | : transaction_(transaction), |
[email protected] | aa249b5 | 2013-04-30 01:04:32 | [diff] [blame] | 1281 | callback_(base::Bind(&KillerCallback::OnComplete, |
| 1282 | base::Unretained(this))) { |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1283 | } |
| 1284 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 1285 | ~KillerCallback() override {} |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1286 | |
| 1287 | const CompletionCallback& callback() const { return callback_; } |
| 1288 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1289 | private: |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1290 | void OnComplete(int result) { |
| 1291 | if (result < 0) |
| 1292 | delete transaction_; |
| 1293 | |
| 1294 | SetResult(result); |
| 1295 | } |
| 1296 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1297 | HttpNetworkTransaction* transaction_; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1298 | CompletionCallback callback_; |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1299 | }; |
| 1300 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1301 | } // namespace |
| 1302 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1303 | // Similar to ThreeGetsMaxConcurrrentDelete above, however, this test |
| 1304 | // closes the socket while we have a pending transaction waiting for |
| 1305 | // a pending stream creation. http://crbug.com/52901 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1306 | TEST_F(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentSocketClose) { |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1307 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1308 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1309 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1310 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1311 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 1312 | SpdySerializedFrame fin_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1313 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1314 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1315 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1316 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1317 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1318 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1319 | SettingsMap settings; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 1320 | const uint32_t max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1321 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1322 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1323 | SpdySerializedFrame settings_frame( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1324 | spdy_util_.ConstructSpdySettings(settings)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1325 | SpdySerializedFrame settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1326 | |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1327 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1328 | CreateMockWrite(req, 0), CreateMockWrite(settings_ack, 5), |
| 1329 | CreateMockWrite(req2, 6), |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1330 | }; |
| 1331 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1332 | CreateMockRead(settings_frame, 1), |
| 1333 | CreateMockRead(resp, 2), |
| 1334 | CreateMockRead(body, 3), |
| 1335 | CreateMockRead(fin_body, 4), |
| 1336 | CreateMockRead(resp2, 7), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1337 | MockRead(ASYNC, ERR_CONNECTION_RESET, 8), // Abort! |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1338 | }; |
| 1339 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1340 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 1341 | SequencedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1342 | |
| 1343 | BoundNetLog log; |
| 1344 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1345 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1346 | BoundNetLog(), NULL); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1347 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1348 | helper.AddData(&data); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1349 | // We require placeholder data because three get requests are sent out, so |
| 1350 | // there needs to be three sets of SSL connection data. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1351 | helper.AddData(&data_placeholder); |
| 1352 | helper.AddData(&data_placeholder); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1353 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session()); |
| 1354 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1355 | HttpNetworkTransaction* trans3( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1356 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1357 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1358 | TestCompletionCallback callback1; |
| 1359 | TestCompletionCallback callback2; |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1360 | KillerCallback callback3(trans3); |
| 1361 | |
| 1362 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1363 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1364 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
| 1365 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1366 | out.rv = trans1.Start(&httpreq1, callback1.callback(), log); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1367 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1368 | // Run transaction 1 through quickly to force a read of our SETTINGS frame. |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1369 | out.rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1370 | ASSERT_THAT(out.rv, IsOk()); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1371 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1372 | out.rv = trans2.Start(&httpreq2, callback2.callback(), log); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1373 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1374 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1375 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
| 1376 | out.rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1377 | ASSERT_THAT(out.rv, IsError(ERR_ABORTED)); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1378 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1379 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1380 | ASSERT_TRUE(response1); |
| 1381 | EXPECT_TRUE(response1->headers); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1382 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1383 | out.status_line = response1->headers->GetStatusLine(); |
| 1384 | out.response_info = *response1; |
| 1385 | out.rv = ReadTransaction(&trans1, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1386 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1387 | |
| 1388 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1389 | ASSERT_TRUE(response2); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1390 | out.status_line = response2->headers->GetStatusLine(); |
| 1391 | out.response_info = *response2; |
| 1392 | out.rv = ReadTransaction(&trans2, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1393 | EXPECT_THAT(out.rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1394 | |
| 1395 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1396 | } |
| 1397 | |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1398 | // Test that a simple PUT request works. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1399 | TEST_F(SpdyNetworkTransactionTest, Put) { |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1400 | // Setup the request |
| 1401 | HttpRequestInfo request; |
| 1402 | request.method = "PUT"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1403 | request.url = default_url_; |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1404 | |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 1405 | SpdyHeaderBlock put_headers( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1406 | spdy_util_.ConstructPutHeaderBlock(kDefaultUrl, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1407 | SpdySerializedFrame req( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1408 | spdy_util_.ConstructSpdyHeaders(1, std::move(put_headers), LOWEST, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1409 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1410 | CreateMockWrite(req, 0), |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1411 | }; |
| 1412 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1413 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1414 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1415 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1416 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1417 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1418 | }; |
| 1419 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1420 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1421 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 1422 | NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1423 | helper.RunToCompletion(&data); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1424 | TransactionHelperResult out = helper.output(); |
| 1425 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1426 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1427 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | // Test that a simple HEAD request works. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1431 | TEST_F(SpdyNetworkTransactionTest, Head) { |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1432 | // Setup the request |
| 1433 | HttpRequestInfo request; |
| 1434 | request.method = "HEAD"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1435 | request.url = default_url_; |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1436 | |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 1437 | SpdyHeaderBlock head_headers( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1438 | spdy_util_.ConstructHeadHeaderBlock(kDefaultUrl, 0)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1439 | SpdySerializedFrame req(spdy_util_.ConstructSpdyHeaders( |
| 1440 | 1, std::move(head_headers), LOWEST, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1441 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1442 | CreateMockWrite(req, 0), |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1443 | }; |
| 1444 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1445 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1446 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1447 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1448 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1449 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1450 | }; |
| 1451 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1452 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1453 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 1454 | NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1455 | helper.RunToCompletion(&data); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1456 | TransactionHelperResult out = helper.output(); |
| 1457 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1458 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1459 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1460 | } |
| 1461 | |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 1462 | // Test that a simple POST works. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1463 | TEST_F(SpdyNetworkTransactionTest, Post) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1464 | SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1465 | kDefaultUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1466 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1467 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1468 | CreateMockWrite(req, 0), CreateMockWrite(body, 1), // POST upload frame |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1469 | }; |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 1470 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1471 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1472 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1473 | CreateMockRead(resp, 2), CreateMockRead(body, 3), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1474 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 1475 | }; |
| 1476 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1477 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1478 | NormalSpdyTransactionHelper helper(CreatePostRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1479 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1480 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1481 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1482 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1483 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 1484 | EXPECT_EQ("hello!", out.response_data); |
| 1485 | } |
| 1486 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1487 | // Test that a POST with a file works. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1488 | TEST_F(SpdyNetworkTransactionTest, FilePost) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1489 | SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1490 | kDefaultUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1491 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1492 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1493 | CreateMockWrite(req, 0), CreateMockWrite(body, 1), // POST upload frame |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1494 | }; |
| 1495 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1496 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1497 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1498 | CreateMockRead(resp, 2), CreateMockRead(body, 3), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1499 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1500 | }; |
| 1501 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1502 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1503 | NormalSpdyTransactionHelper helper(CreateFilePostRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1504 | BoundNetLog(), NULL); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1505 | helper.RunToCompletion(&data); |
| 1506 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1507 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1508 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1509 | EXPECT_EQ("hello!", out.response_data); |
| 1510 | } |
| 1511 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1512 | // Test that a POST with a unreadable file fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1513 | TEST_F(SpdyNetworkTransactionTest, UnreadableFilePost) { |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1514 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1515 | MockWrite(ASYNC, 0, 0) // EOF |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1516 | }; |
| 1517 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1518 | MockRead(ASYNC, 0, 1) // EOF |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1519 | }; |
| 1520 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1521 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1522 | NormalSpdyTransactionHelper helper(CreateUnreadableFilePostRequest(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1523 | DEFAULT_PRIORITY, BoundNetLog(), NULL); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1524 | helper.RunPreTestSetup(); |
| 1525 | helper.AddData(&data); |
| 1526 | helper.RunDefaultTest(); |
| 1527 | |
| 1528 | base::RunLoop().RunUntilIdle(); |
| 1529 | helper.VerifyDataNotConsumed(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1530 | EXPECT_THAT(helper.output().rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1531 | } |
| 1532 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1533 | // Test that a complex POST works. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1534 | TEST_F(SpdyNetworkTransactionTest, ComplexPost) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1535 | SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1536 | kDefaultUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1537 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1538 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1539 | CreateMockWrite(req, 0), CreateMockWrite(body, 1), // POST upload frame |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1540 | }; |
| 1541 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1542 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1543 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1544 | CreateMockRead(resp, 2), CreateMockRead(body, 3), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1545 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1546 | }; |
| 1547 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1548 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1549 | NormalSpdyTransactionHelper helper(CreateComplexPostRequest(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1550 | DEFAULT_PRIORITY, BoundNetLog(), NULL); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1551 | helper.RunToCompletion(&data); |
| 1552 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1553 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1554 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1555 | EXPECT_EQ("hello!", out.response_data); |
| 1556 | } |
| 1557 | |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1558 | // Test that a chunked POST works. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1559 | TEST_F(SpdyNetworkTransactionTest, ChunkedPost) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1560 | SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1561 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1562 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1563 | CreateMockWrite(req, 0), CreateMockWrite(body, 1), |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1564 | }; |
| 1565 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1566 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1567 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1568 | CreateMockRead(resp, 2), CreateMockRead(body, 3), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1569 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1570 | }; |
| 1571 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1572 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1573 | NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1574 | DEFAULT_PRIORITY, BoundNetLog(), NULL); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1575 | |
| 1576 | // These chunks get merged into a single frame when being sent. |
| 1577 | const int kFirstChunkSize = kUploadDataSize/2; |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1578 | upload_chunked_data_stream()->AppendData(kUploadData, kFirstChunkSize, false); |
| 1579 | upload_chunked_data_stream()->AppendData( |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1580 | kUploadData + kFirstChunkSize, kUploadDataSize - kFirstChunkSize, true); |
| 1581 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1582 | helper.RunToCompletion(&data); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1583 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1584 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1585 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1586 | EXPECT_EQ(kUploadData, out.response_data); |
| 1587 | } |
| 1588 | |
| 1589 | // Test that a chunked POST works with chunks appended after transaction starts. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1590 | TEST_F(SpdyNetworkTransactionTest, DelayedChunkedPost) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1591 | SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1592 | SpdySerializedFrame chunk1(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 1593 | SpdySerializedFrame chunk2(spdy_util_.ConstructSpdyDataFrame(1, false)); |
| 1594 | SpdySerializedFrame chunk3(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1595 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1596 | CreateMockWrite(req, 0), CreateMockWrite(chunk1, 1), |
| 1597 | CreateMockWrite(chunk2, 2), CreateMockWrite(chunk3, 3), |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1598 | }; |
| 1599 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1600 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1601 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1602 | CreateMockRead(resp, 4), CreateMockRead(chunk1, 5), |
| 1603 | CreateMockRead(chunk2, 6), CreateMockRead(chunk3, 7), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1604 | MockRead(ASYNC, 0, 8) // EOF |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1605 | }; |
| 1606 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1607 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1608 | NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1609 | DEFAULT_PRIORITY, BoundNetLog(), NULL); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1610 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1611 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, false); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1612 | |
| 1613 | helper.RunPreTestSetup(); |
| 1614 | helper.AddData(&data); |
| 1615 | ASSERT_TRUE(helper.StartDefaultTest()); |
| 1616 | |
[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, false); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 1619 | base::RunLoop().RunUntilIdle(); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1620 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, true); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1621 | |
| 1622 | helper.FinishDefaultTest(); |
| 1623 | helper.VerifyDataConsumed(); |
| 1624 | |
| 1625 | std::string expected_response; |
| 1626 | expected_response += kUploadData; |
| 1627 | expected_response += kUploadData; |
| 1628 | expected_response += kUploadData; |
| 1629 | |
| 1630 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1631 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1632 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1633 | EXPECT_EQ(expected_response, out.response_data); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1634 | } |
| 1635 | |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1636 | // Test that a POST without any post data works. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1637 | TEST_F(SpdyNetworkTransactionTest, NullPost) { |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1638 | // Setup the request |
| 1639 | HttpRequestInfo request; |
| 1640 | request.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1641 | request.url = default_url_; |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1642 | // Create an empty UploadData. |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1643 | request.upload_data_stream = NULL; |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1644 | |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1645 | // When request.upload_data_stream is NULL for post, content-length is |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1646 | // expected to be 0. |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 1647 | SpdyHeaderBlock req_block( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1648 | spdy_util_.ConstructPostHeaderBlock(kDefaultUrl, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1649 | SpdySerializedFrame req( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1650 | spdy_util_.ConstructSpdyHeaders(1, std::move(req_block), LOWEST, true)); |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1651 | |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1652 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1653 | CreateMockWrite(req, 0), |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1654 | }; |
| 1655 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1656 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1657 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1658 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1659 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1660 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1661 | }; |
| 1662 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1663 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1664 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1665 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 1666 | NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1667 | helper.RunToCompletion(&data); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1668 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1669 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1670 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1671 | EXPECT_EQ("hello!", out.response_data); |
| 1672 | } |
| 1673 | |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1674 | // Test that a simple POST works. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1675 | TEST_F(SpdyNetworkTransactionTest, EmptyPost) { |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1676 | // Create an empty UploadDataStream. |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 1677 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1678 | ElementsUploadDataStream stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1679 | |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1680 | // Setup the request |
| 1681 | HttpRequestInfo request; |
| 1682 | request.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1683 | request.url = default_url_; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1684 | request.upload_data_stream = &stream; |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1685 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 1686 | const uint64_t kContentLength = 0; |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1687 | |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 1688 | SpdyHeaderBlock req_block( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 1689 | spdy_util_.ConstructPostHeaderBlock(kDefaultUrl, kContentLength)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1690 | SpdySerializedFrame req( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1691 | spdy_util_.ConstructSpdyHeaders(1, std::move(req_block), LOWEST, true)); |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1692 | |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1693 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1694 | CreateMockWrite(req, 0), |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1695 | }; |
| 1696 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1697 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1698 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1699 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1700 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1701 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1702 | }; |
| 1703 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1704 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 1705 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1706 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 1707 | NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1708 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1709 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1710 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1711 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1712 | EXPECT_EQ("hello!", out.response_data); |
| 1713 | } |
| 1714 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1715 | // While we're doing a post, the server sends the reply before upload completes. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1716 | TEST_F(SpdyNetworkTransactionTest, ResponseBeforePostCompletes) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1717 | SpdySerializedFrame req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1718 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1719 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1720 | CreateMockWrite(req, 0), CreateMockWrite(body, 3), |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1721 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1722 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
[email protected] | a5566f970 | 2010-05-05 22:25:43 | [diff] [blame] | 1723 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1724 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
| 1725 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | a5566f970 | 2010-05-05 22:25:43 | [diff] [blame] | 1726 | }; |
| 1727 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1728 | // Write the request headers, and read the complete response |
| 1729 | // while still waiting for chunked request data. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1730 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1731 | NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1732 | DEFAULT_PRIORITY, BoundNetLog(), NULL); |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 1733 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1734 | helper.AddData(&data); |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 1735 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1736 | ASSERT_TRUE(helper.StartDefaultTest()); |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 1737 | |
maksim.sisov | 8d2df66d | 2016-06-20 07:07:11 | [diff] [blame] | 1738 | base::RunLoop().RunUntilIdle(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1739 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1740 | // Process the request headers, response headers, and response body. |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1741 | // The request body is still in flight. |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1742 | const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1743 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1744 | |
| 1745 | // Finish sending the request body. |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1746 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, true); |
maksim.sisov | 8d2df66d | 2016-06-20 07:07:11 | [diff] [blame] | 1747 | helper.WaitForCallbackToComplete(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1748 | EXPECT_THAT(helper.output().rv, IsOk()); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1749 | |
| 1750 | std::string response_body; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1751 | EXPECT_THAT(ReadTransaction(helper.trans(), &response_body), IsOk()); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1752 | EXPECT_EQ(kUploadData, response_body); |
| 1753 | helper.VerifyDataConsumed(); |
[email protected] | a5566f970 | 2010-05-05 22:25:43 | [diff] [blame] | 1754 | } |
| 1755 | |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 1756 | // The client upon cancellation tries to send a RST_STREAM frame. The mock |
| 1757 | // socket causes the TCP write to return zero. This test checks that the client |
| 1758 | // tries to queue up the RST_STREAM frame again. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1759 | TEST_F(SpdyNetworkTransactionTest, SocketWriteReturnsZero) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1760 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1761 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1762 | SpdySerializedFrame rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1763 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 1764 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1765 | CreateMockWrite(req, 0, SYNCHRONOUS), MockWrite(SYNCHRONOUS, 0, 0, 2), |
| 1766 | CreateMockWrite(rst, 3, SYNCHRONOUS), |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 1767 | }; |
| 1768 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1769 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 1770 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1771 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 0, 4) // EOF |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 1772 | }; |
| 1773 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1774 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1775 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1776 | BoundNetLog(), NULL); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 1777 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1778 | helper.AddData(&data); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 1779 | HttpNetworkTransaction* trans = helper.trans(); |
| 1780 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1781 | TestCompletionCallback callback; |
| 1782 | int rv = trans->Start( |
| 1783 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1784 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[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.ResetTrans(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1787 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 1788 | |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 1789 | helper.VerifyDataConsumed(); |
| 1790 | } |
| 1791 | |
[email protected] | 9330067 | 2009-10-24 13:22:51 | [diff] [blame] | 1792 | // Test that the transaction doesn't crash when we don't have a reply. |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1793 | TEST_F(SpdyNetworkTransactionTest, ResponseWithoutHeaders) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1794 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1795 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1796 | CreateMockRead(body, 1), MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 9330067 | 2009-10-24 13:22:51 | [diff] [blame] | 1797 | }; |
| 1798 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1799 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1800 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1801 | SpdySerializedFrame rst( |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1802 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 1803 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1804 | CreateMockWrite(req, 0), CreateMockWrite(rst, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1805 | }; |
| 1806 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1807 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1808 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1809 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1810 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1811 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
[email protected] | 9330067 | 2009-10-24 13:22:51 | [diff] [blame] | 1812 | } |
| 1813 | |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1814 | // Test that the transaction doesn't crash when we get two replies on the same |
| 1815 | // stream ID. See http://crbug.com/45639. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1816 | TEST_F(SpdyNetworkTransactionTest, ResponseWithTwoSynReplies) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1817 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1818 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1819 | SpdySerializedFrame rst( |
[email protected] | 00b2947 | 2014-01-16 18:10:24 | [diff] [blame] | 1820 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 1821 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1822 | CreateMockWrite(req, 0), CreateMockWrite(rst, 4), |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 1823 | }; |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1824 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1825 | SpdySerializedFrame resp0(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1826 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1827 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1828 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1829 | CreateMockRead(resp0, 1), CreateMockRead(resp1, 2), |
| 1830 | CreateMockRead(body, 3), MockRead(ASYNC, 0, 5) // EOF |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1831 | }; |
| 1832 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1833 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1834 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1835 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1836 | BoundNetLog(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1837 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1838 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1839 | |
| 1840 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1841 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1842 | TestCompletionCallback callback; |
| 1843 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1844 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1845 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1846 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1847 | |
| 1848 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1849 | ASSERT_TRUE(response); |
| 1850 | EXPECT_TRUE(response->headers); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1851 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 1852 | std::string response_data; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1853 | rv = ReadTransaction(trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1854 | EXPECT_THAT(rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1855 | |
| 1856 | helper.VerifyDataConsumed(); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 1857 | } |
| 1858 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1859 | TEST_F(SpdyNetworkTransactionTest, ResetReplyWithTransferEncoding) { |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1860 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1861 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1862 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1863 | SpdySerializedFrame rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1864 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1865 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1866 | CreateMockWrite(req, 0), CreateMockWrite(rst, 2), |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1867 | }; |
| 1868 | |
| 1869 | const char* const headers[] = { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1870 | "transfer-encoding", "chunked" |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1871 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1872 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(headers, 1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1873 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1874 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1875 | CreateMockRead(resp, 1), CreateMockRead(body, 3), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1876 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1877 | }; |
| 1878 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1879 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1880 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1881 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1882 | helper.RunToCompletion(&data); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1883 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1884 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1885 | |
| 1886 | helper.session()->spdy_session_pool()->CloseAllSessions(); |
| 1887 | helper.VerifyDataConsumed(); |
| 1888 | } |
| 1889 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1890 | TEST_F(SpdyNetworkTransactionTest, ResetPushWithTransferEncoding) { |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1891 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1892 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1893 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1894 | SpdySerializedFrame rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1895 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1896 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1897 | CreateMockWrite(req, 0), CreateMockWrite(rst, 4), |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1898 | }; |
| 1899 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1900 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1901 | const char* const headers[] = { |
| 1902 | "transfer-encoding", "chunked" |
| 1903 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1904 | SpdySerializedFrame push( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1905 | spdy_util_.ConstructSpdyPush(headers, arraysize(headers) / 2, 2, 1, |
| 1906 | GetDefaultUrlWithPath("/1").c_str())); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1907 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1908 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1909 | CreateMockRead(resp, 1), CreateMockRead(push, 2), CreateMockRead(body, 3), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1910 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1911 | }; |
| 1912 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1913 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1914 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1915 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1916 | helper.RunToCompletion(&data); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1917 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1918 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1919 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 1920 | EXPECT_EQ("hello!", out.response_data); |
| 1921 | |
| 1922 | helper.session()->spdy_session_pool()->CloseAllSessions(); |
| 1923 | helper.VerifyDataConsumed(); |
| 1924 | } |
| 1925 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1926 | TEST_F(SpdyNetworkTransactionTest, CancelledTransaction) { |
[email protected] | 75f30cc2 | 2010-06-28 21:41:38 | [diff] [blame] | 1927 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1928 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1929 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 1930 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1931 | CreateMockWrite(req), |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 1932 | }; |
| 1933 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1934 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 1935 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1936 | CreateMockRead(resp), |
| 1937 | // This following read isn't used by the test, except during the |
| 1938 | // RunUntilIdle() call at the end since the SpdySession survives the |
| 1939 | // HttpNetworkTransaction and still tries to continue Read()'ing. Any |
| 1940 | // MockRead will do here. |
| 1941 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 1942 | }; |
| 1943 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1944 | StaticSocketDataProvider data(reads, arraysize(reads), |
| 1945 | writes, arraysize(writes)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1946 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1947 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1948 | BoundNetLog(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1949 | helper.RunPreTestSetup(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 1950 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1951 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 1952 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1953 | TestCompletionCallback callback; |
| 1954 | int rv = trans->Start( |
| 1955 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1956 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1957 | helper.ResetTrans(); // Cancel the transaction. |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 1958 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 1959 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 1960 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 1961 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1962 | helper.VerifyDataNotConsumed(); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 1963 | } |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 1964 | |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1965 | // Verify that the client sends a Rst Frame upon cancelling the stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1966 | TEST_F(SpdyNetworkTransactionTest, CancelledTransactionSendRst) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1967 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1968 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1969 | SpdySerializedFrame rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1970 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1971 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1972 | CreateMockWrite(req, 0, SYNCHRONOUS), |
| 1973 | CreateMockWrite(rst, 2, SYNCHRONOUS), |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1974 | }; |
| 1975 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1976 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1977 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1978 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 0, 3) // EOF |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1979 | }; |
| 1980 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1981 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1982 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1983 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1984 | BoundNetLog(), NULL); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1985 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1986 | helper.AddData(&data); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1987 | HttpNetworkTransaction* trans = helper.trans(); |
| 1988 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1989 | TestCompletionCallback callback; |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1990 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1991 | int rv = trans->Start( |
| 1992 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1993 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1994 | |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 1995 | helper.ResetTrans(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1996 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 1997 | |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 1998 | helper.VerifyDataConsumed(); |
| 1999 | } |
| 2000 | |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2001 | // Verify that the client can correctly deal with the user callback attempting |
| 2002 | // to start another transaction on a session that is closing down. See |
| 2003 | // http://crbug.com/47455 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2004 | TEST_F(SpdyNetworkTransactionTest, StartTransactionOnReadCallback) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2005 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2006 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2007 | MockWrite writes[] = {CreateMockWrite(req)}; |
| 2008 | MockWrite writes2[] = {CreateMockWrite(req, 0)}; |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2009 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 2010 | // The indicated length of this frame is longer than its actual length. When |
| 2011 | // the session receives an empty frame after this one, it shuts down the |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2012 | // session, and calls the read callback with the incomplete data. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 2013 | const uint8_t kGetBodyFrame2[] = { |
| 2014 | 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, |
| 2015 | 0x07, 'h', 'e', 'l', 'l', 'o', '!', |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2016 | }; |
| 2017 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2018 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2019 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2020 | CreateMockRead(resp, 1), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 2021 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause |
| 2022 | MockRead(ASYNC, reinterpret_cast<const char*>(kGetBodyFrame2), |
| 2023 | arraysize(kGetBodyFrame2), 3), |
| 2024 | MockRead(ASYNC, ERR_IO_PENDING, 4), // Force a pause |
| 2025 | MockRead(ASYNC, 0, 0, 5), // EOF |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2026 | }; |
| 2027 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2028 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 0, 2), // EOF |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2029 | }; |
| 2030 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 2031 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2032 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 2033 | arraysize(writes2)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2034 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2035 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2036 | BoundNetLog(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2037 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2038 | helper.AddData(&data); |
| 2039 | helper.AddData(&data2); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2040 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2041 | |
| 2042 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2043 | TestCompletionCallback callback; |
| 2044 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2045 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2046 | rv = callback.WaitForResult(); |
| 2047 | |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2048 | const int kSize = 3000; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 2049 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSize)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2050 | rv = trans->Read( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2051 | buf.get(), kSize, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2052 | base::Bind(&SpdyNetworkTransactionTest::StartTransactionCallback, |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 2053 | helper.session(), default_url_)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2054 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2055 | // This forces an err_IO_pending, which sets the callback. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 2056 | data.Resume(); |
| 2057 | data.RunUntilPaused(); |
| 2058 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2059 | // This finishes the read. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 2060 | data.Resume(); |
| 2061 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2062 | helper.VerifyDataConsumed(); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2063 | } |
| 2064 | |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2065 | // Verify that the client can correctly deal with the user callback deleting the |
| 2066 | // transaction. Failures will usually be valgrind errors. See |
| 2067 | // http://crbug.com/46925 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2068 | TEST_F(SpdyNetworkTransactionTest, DeleteSessionOnReadCallback) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2069 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2070 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2071 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2072 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2073 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2074 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2075 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2076 | CreateMockRead(resp, 1), |
| 2077 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause |
| 2078 | CreateMockRead(body, 3), MockRead(ASYNC, 0, 0, 4), // EOF |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2079 | }; |
| 2080 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 2081 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2082 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2083 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2084 | BoundNetLog(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2085 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2086 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2087 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2088 | |
| 2089 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2090 | TestCompletionCallback callback; |
| 2091 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2092 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2093 | rv = callback.WaitForResult(); |
| 2094 | |
| 2095 | // Setup a user callback which will delete the session, and clear out the |
| 2096 | // memory holding the stream object. Note that the callback deletes trans. |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2097 | const int kSize = 3000; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 2098 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSize)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2099 | rv = trans->Read( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2100 | buf.get(), |
| 2101 | kSize, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2102 | base::Bind(&SpdyNetworkTransactionTest::DeleteSessionCallback, |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2103 | base::Unretained(&helper))); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2104 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 2105 | data.Resume(); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2106 | |
| 2107 | // Finish running rest of tasks. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2108 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2109 | helper.VerifyDataConsumed(); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2110 | } |
| 2111 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2112 | // 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] | 2113 | TEST_F(SpdyNetworkTransactionTest, DISABLED_RedirectGetRequest) { |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 2114 | SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2115 | headers["user-agent"] = ""; |
| 2116 | headers["accept-encoding"] = "gzip, deflate"; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2117 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2118 | // Setup writes/reads to www.example.org |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2119 | SpdySerializedFrame req( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2120 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 2121 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReplyRedirect(1)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2122 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2123 | CreateMockWrite(req, 1), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2124 | }; |
| 2125 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2126 | CreateMockRead(resp, 2), MockRead(ASYNC, 0, 0, 3) // EOF |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2127 | }; |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2128 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2129 | |
| 2130 | // Setup writes/reads to www.foo.com |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2131 | SpdyHeaderBlock headers2( |
| 2132 | spdy_util_.ConstructGetHeaderBlock("http://www.foo.com/index.php")); |
| 2133 | headers2["user-agent"] = ""; |
| 2134 | headers2["accept-encoding"] = "gzip, deflate"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2135 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2136 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers2), LOWEST, true)); |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2137 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2138 | CreateMockWrite(req2, 1), |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2139 | }; |
| 2140 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2141 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2142 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2143 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2144 | CreateMockRead(resp2, 2), CreateMockRead(body2, 3), |
| 2145 | MockRead(ASYNC, 0, 0, 4) // EOF |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2146 | }; |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2147 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2148 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 2149 | arraysize(writes2)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2150 | |
| 2151 | // TODO(erikchen): Make test support SPDYSSL, SPDYNPN |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2152 | TestDelegate d; |
| 2153 | { |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 2154 | SpdyURLRequestContext spdy_url_request_context; |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 2155 | std::unique_ptr<URLRequest> r(spdy_url_request_context.CreateRequest( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 2156 | default_url_, DEFAULT_PRIORITY, &d)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2157 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2158 | AddSocketDataProvider(&data); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2159 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2160 | AddSocketDataProvider(&data2); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2161 | |
| 2162 | d.set_quit_on_redirect(true); |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2163 | r->Start(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2164 | base::RunLoop().Run(); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2165 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2166 | EXPECT_EQ(1, d.received_redirect_count()); |
| 2167 | |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2168 | r->FollowDeferredRedirect(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2169 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2170 | EXPECT_EQ(1, d.response_started_count()); |
| 2171 | EXPECT_FALSE(d.received_data_before_response()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 2172 | EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2173 | std::string contents("hello!"); |
| 2174 | EXPECT_EQ(contents, d.data_received()); |
| 2175 | } |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 2176 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2177 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 2178 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 2179 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2180 | } |
| 2181 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2182 | // 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] | 2183 | // www.foo.com. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2184 | TEST_F(SpdyNetworkTransactionTest, DISABLED_RedirectServerPush) { |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 2185 | SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2186 | headers["user-agent"] = ""; |
| 2187 | headers["accept-encoding"] = "gzip, deflate"; |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2188 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2189 | // Setup writes/reads to www.example.org |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2190 | SpdySerializedFrame req( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2191 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 2192 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2193 | SpdySerializedFrame rep(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2194 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str(), |
| 2195 | "301 Moved Permanently", "http://www.foo.com/index.php")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2196 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 2197 | SpdySerializedFrame rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2198 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_CANCEL)); |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2199 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2200 | CreateMockWrite(req, 1), CreateMockWrite(rst, 6), |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2201 | }; |
| 2202 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2203 | CreateMockRead(resp, 2), CreateMockRead(rep, 3), CreateMockRead(body, 4), |
| 2204 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
| 2205 | MockRead(ASYNC, 0, 0, 7) // EOF |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2206 | }; |
| 2207 | |
| 2208 | // Setup writes/reads to www.foo.com |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2209 | SpdyHeaderBlock headers2( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2210 | spdy_util_.ConstructGetHeaderBlock("http://www.foo.com/index.php")); |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2211 | headers2["user-agent"] = ""; |
| 2212 | headers2["accept-encoding"] = "gzip, deflate"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2213 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2214 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers2), LOWEST, true)); |
| 2215 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2216 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2217 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2218 | CreateMockWrite(req2, 1), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2219 | }; |
| 2220 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2221 | CreateMockRead(resp2, 2), CreateMockRead(body2, 3), |
| 2222 | MockRead(ASYNC, 0, 0, 5) // EOF |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2223 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2224 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2225 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 2226 | arraysize(writes2)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2227 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2228 | TestDelegate d; |
| 2229 | TestDelegate d2; |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 2230 | SpdyURLRequestContext spdy_url_request_context; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2231 | { |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 2232 | std::unique_ptr<URLRequest> r(spdy_url_request_context.CreateRequest( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 2233 | default_url_, DEFAULT_PRIORITY, &d)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2234 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2235 | AddSocketDataProvider(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2236 | |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2237 | r->Start(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2238 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2239 | |
| 2240 | EXPECT_EQ(0, d.received_redirect_count()); |
| 2241 | std::string contents("hello!"); |
| 2242 | EXPECT_EQ(contents, d.data_received()); |
| 2243 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 2244 | std::unique_ptr<URLRequest> r2(spdy_url_request_context.CreateRequest( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2245 | GURL(GetDefaultUrlWithPath("/foo.dat")), DEFAULT_PRIORITY, &d2)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2246 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2247 | AddSocketDataProvider(&data2); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2248 | |
| 2249 | d2.set_quit_on_redirect(true); |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2250 | r2->Start(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2251 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2252 | EXPECT_EQ(1, d2.received_redirect_count()); |
| 2253 | |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2254 | r2->FollowDeferredRedirect(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2255 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2256 | EXPECT_EQ(1, d2.response_started_count()); |
| 2257 | EXPECT_FALSE(d2.received_data_before_response()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 2258 | EXPECT_EQ(URLRequestStatus::SUCCESS, r2->status().status()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2259 | std::string contents2("hello!"); |
| 2260 | EXPECT_EQ(contents2, d2.data_received()); |
| 2261 | } |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2262 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2263 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 2264 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 2265 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2266 | } |
| 2267 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2268 | TEST_F(SpdyNetworkTransactionTest, ServerPushSingleDataFrame) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2269 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2270 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2271 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2272 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2273 | CreateMockWrite(stream1_syn, 0), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2274 | }; |
| 2275 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2276 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2277 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2278 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2279 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2280 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2281 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 2282 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2283 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2284 | CreateMockRead(stream1_reply, 1), |
| 2285 | CreateMockRead(stream2_syn, 2), |
| 2286 | CreateMockRead(stream1_body, 3, SYNCHRONOUS), |
| 2287 | CreateMockRead(stream2_body, 4), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2288 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2289 | }; |
| 2290 | |
| 2291 | HttpResponseInfo response; |
| 2292 | HttpResponseInfo response2; |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2293 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2294 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2295 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2296 | &response, |
| 2297 | &response2, |
| 2298 | expected_push_result); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2299 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2300 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2301 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2302 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2303 | |
| 2304 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2305 | EXPECT_TRUE(response2.headers); |
bnc | cdc749f | 2016-01-27 16:39:04 | [diff] [blame] | 2306 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2307 | } |
| 2308 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2309 | TEST_F(SpdyNetworkTransactionTest, ServerPushBeforeHeaders) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2310 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2311 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2312 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2313 | CreateMockWrite(stream1_syn, 0), |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2314 | }; |
| 2315 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2316 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2317 | nullptr, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2318 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2319 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2320 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2321 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2322 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 2323 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2324 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2325 | CreateMockRead(stream2_syn, 1), |
| 2326 | CreateMockRead(stream1_reply, 2), |
| 2327 | CreateMockRead(stream1_body, 3, SYNCHRONOUS), |
| 2328 | CreateMockRead(stream2_body, 4), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2329 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2330 | }; |
| 2331 | |
| 2332 | HttpResponseInfo response; |
| 2333 | HttpResponseInfo response2; |
| 2334 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2335 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2336 | RunServerPushTest(&data, |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2337 | &response, |
| 2338 | &response2, |
| 2339 | expected_push_result); |
| 2340 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2341 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2342 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2343 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2344 | |
| 2345 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2346 | EXPECT_TRUE(response2.headers); |
bnc | cdc749f | 2016-01-27 16:39:04 | [diff] [blame] | 2347 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2348 | } |
| 2349 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2350 | TEST_F(SpdyNetworkTransactionTest, ServerPushSingleDataFrame2) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2351 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2352 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2353 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2354 | CreateMockWrite(stream1_syn, 0), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2355 | }; |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2356 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2357 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2358 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2359 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2360 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2361 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2362 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 2363 | 2, kPushedData, strlen(kPushedData), true)); |
| 2364 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2365 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2366 | CreateMockRead(stream1_reply, 1), |
| 2367 | CreateMockRead(stream2_syn, 2), |
| 2368 | CreateMockRead(stream2_body, 3), |
| 2369 | CreateMockRead(stream1_body, 4, SYNCHRONOUS), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2370 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2371 | }; |
| 2372 | |
| 2373 | HttpResponseInfo response; |
| 2374 | HttpResponseInfo response2; |
| 2375 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2376 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2377 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2378 | &response, |
| 2379 | &response2, |
| 2380 | expected_push_result); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2381 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2382 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2383 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2384 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2385 | |
| 2386 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2387 | EXPECT_TRUE(response2.headers); |
bnc | cdc749f | 2016-01-27 16:39:04 | [diff] [blame] | 2388 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2389 | } |
| 2390 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2391 | TEST_F(SpdyNetworkTransactionTest, ServerPushServerAborted) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2392 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2393 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2394 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2395 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2396 | CreateMockWrite(stream1_syn, 0), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2397 | }; |
| 2398 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2399 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2400 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2401 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2402 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2403 | SpdySerializedFrame stream2_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2404 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2405 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2406 | CreateMockRead(stream1_reply, 1), |
| 2407 | CreateMockRead(stream2_syn, 2), |
| 2408 | CreateMockRead(stream2_rst, 3), |
| 2409 | CreateMockRead(stream1_body, 4, SYNCHRONOUS), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2410 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2411 | }; |
| 2412 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2413 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2414 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2415 | BoundNetLog(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2416 | |
| 2417 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2418 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2419 | |
| 2420 | HttpNetworkTransaction* trans = helper.trans(); |
| 2421 | |
| 2422 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2423 | TestCompletionCallback callback; |
| 2424 | int rv = trans->Start( |
| 2425 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2426 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2427 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2428 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2429 | |
| 2430 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2431 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2432 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2433 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2434 | // Verify the response headers. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2435 | HttpResponseInfo response = *trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2436 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2437 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2438 | } |
| 2439 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2440 | // Verify that we don't leak streams and that we properly send a reset |
| 2441 | // if the server pushes the same stream twice. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2442 | TEST_F(SpdyNetworkTransactionTest, ServerPushDuplicate) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2443 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2444 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2445 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 2446 | SpdySerializedFrame stream3_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2447 | spdy_util_.ConstructSpdyRstStream(4, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2448 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2449 | CreateMockWrite(stream1_syn, 0), CreateMockWrite(stream3_rst, 4), |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2450 | }; |
| 2451 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2452 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2453 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2454 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2455 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2456 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2457 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 2458 | 2, kPushedData, strlen(kPushedData), true)); |
| 2459 | SpdySerializedFrame stream3_syn(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2460 | NULL, 0, 4, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2461 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2462 | CreateMockRead(stream1_reply, 1), |
| 2463 | CreateMockRead(stream2_syn, 2), |
| 2464 | CreateMockRead(stream3_syn, 3), |
| 2465 | CreateMockRead(stream1_body, 5), |
| 2466 | CreateMockRead(stream2_body, 6), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2467 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 7), // Force a pause |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2468 | }; |
| 2469 | |
| 2470 | HttpResponseInfo response; |
| 2471 | HttpResponseInfo response2; |
| 2472 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2473 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2474 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2475 | &response, |
| 2476 | &response2, |
| 2477 | expected_push_result); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2478 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2479 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2480 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2481 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2482 | |
| 2483 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2484 | EXPECT_TRUE(response2.headers); |
bnc | cdc749f | 2016-01-27 16:39:04 | [diff] [blame] | 2485 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2486 | } |
| 2487 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2488 | TEST_F(SpdyNetworkTransactionTest, ServerPushMultipleDataFrame) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2489 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2490 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2491 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2492 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2493 | CreateMockWrite(stream1_syn, 0), |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2494 | }; |
| 2495 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2496 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2497 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2498 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2499 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2500 | static const char kPushedData[] = "pushed my darling hello my baby"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2501 | SpdySerializedFrame stream2_body_base(spdy_util_.ConstructSpdyDataFrame( |
| 2502 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2503 | const size_t kChunkSize = strlen(kPushedData) / 4; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2504 | SpdySerializedFrame stream2_body1(stream2_body_base.data(), kChunkSize, |
| 2505 | false); |
| 2506 | SpdySerializedFrame stream2_body2(stream2_body_base.data() + kChunkSize, |
| 2507 | kChunkSize, false); |
| 2508 | SpdySerializedFrame stream2_body3(stream2_body_base.data() + 2 * kChunkSize, |
| 2509 | kChunkSize, false); |
| 2510 | SpdySerializedFrame stream2_body4(stream2_body_base.data() + 3 * kChunkSize, |
| 2511 | stream2_body_base.size() - 3 * kChunkSize, |
| 2512 | false); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2513 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2514 | CreateMockRead(stream1_reply, 1), |
| 2515 | CreateMockRead(stream2_syn, 2), |
| 2516 | CreateMockRead(stream2_body1, 3), |
| 2517 | CreateMockRead(stream2_body2, 4), |
| 2518 | CreateMockRead(stream2_body3, 5), |
| 2519 | CreateMockRead(stream2_body4, 6), |
| 2520 | CreateMockRead(stream1_body, 7, SYNCHRONOUS), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2521 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), // Force a pause |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2522 | }; |
| 2523 | |
| 2524 | HttpResponseInfo response; |
| 2525 | HttpResponseInfo response2; |
| 2526 | std::string expected_push_result("pushed my darling hello my baby"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2527 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2528 | RunServerPushTest(&data, &response, &response2, kPushedData); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2529 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2530 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2531 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2532 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2533 | |
| 2534 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2535 | EXPECT_TRUE(response2.headers); |
bnc | cdc749f | 2016-01-27 16:39:04 | [diff] [blame] | 2536 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2537 | } |
| 2538 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2539 | TEST_F(SpdyNetworkTransactionTest, ServerPushMultipleDataFrameInterrupted) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2540 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2541 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2542 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2543 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2544 | CreateMockWrite(stream1_syn, 0), |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2545 | }; |
| 2546 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2547 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2548 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2549 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2550 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2551 | static const char kPushedData[] = "pushed my darling hello my baby"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2552 | SpdySerializedFrame stream2_body_base(spdy_util_.ConstructSpdyDataFrame( |
| 2553 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2554 | const size_t kChunkSize = strlen(kPushedData) / 4; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2555 | SpdySerializedFrame stream2_body1(stream2_body_base.data(), kChunkSize, |
| 2556 | false); |
| 2557 | SpdySerializedFrame stream2_body2(stream2_body_base.data() + kChunkSize, |
| 2558 | kChunkSize, false); |
| 2559 | SpdySerializedFrame stream2_body3(stream2_body_base.data() + 2 * kChunkSize, |
| 2560 | kChunkSize, false); |
| 2561 | SpdySerializedFrame stream2_body4(stream2_body_base.data() + 3 * kChunkSize, |
| 2562 | stream2_body_base.size() - 3 * kChunkSize, |
| 2563 | false); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2564 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2565 | CreateMockRead(stream1_reply, 1), |
| 2566 | CreateMockRead(stream2_syn, 2), |
| 2567 | CreateMockRead(stream2_body1, 3), |
| 2568 | CreateMockRead(stream2_body2, 4), |
| 2569 | CreateMockRead(stream2_body3, 5), |
| 2570 | CreateMockRead(stream2_body4, 6), |
| 2571 | CreateMockRead(stream1_body, 7, SYNCHRONOUS), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2572 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8) // Force a pause. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2573 | }; |
| 2574 | |
| 2575 | HttpResponseInfo response; |
| 2576 | HttpResponseInfo response2; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2577 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2578 | RunServerPushTest(&data, &response, &response2, kPushedData); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2579 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2580 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2581 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2582 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2583 | |
| 2584 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2585 | EXPECT_TRUE(response2.headers); |
bnc | cdc749f | 2016-01-27 16:39:04 | [diff] [blame] | 2586 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2587 | } |
| 2588 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2589 | TEST_F(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID0) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2590 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2591 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2592 | SpdySerializedFrame goaway(spdy_util_.ConstructSpdyGoAway( |
| 2593 | 0, GOAWAY_PROTOCOL_ERROR, "Framer error: 1 (INVALID_STREAM_ID).")); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2594 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2595 | CreateMockWrite(stream1_syn, 0), CreateMockWrite(goaway, 3), |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2596 | }; |
| 2597 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2598 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2599 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2600 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2601 | NULL, 0, 2, 0, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2602 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2603 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2), |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2604 | }; |
| 2605 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2606 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2607 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2608 | BoundNetLog(), NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2609 | |
| 2610 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2611 | helper.AddData(&data); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2612 | |
| 2613 | HttpNetworkTransaction* trans = helper.trans(); |
| 2614 | |
| 2615 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2616 | TestCompletionCallback callback; |
| 2617 | int rv = trans->Start( |
| 2618 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2619 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2620 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2621 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2622 | |
| 2623 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2624 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2625 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2626 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2627 | // Verify the response headers. |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2628 | HttpResponseInfo response = *trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2629 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2630 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2631 | } |
| 2632 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2633 | TEST_F(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID9) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2634 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2635 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2636 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 2637 | SpdySerializedFrame stream2_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2638 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_INVALID_STREAM)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2639 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2640 | CreateMockWrite(stream1_syn, 0), CreateMockWrite(stream2_rst, 3), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2641 | }; |
| 2642 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2643 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2644 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2645 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2646 | NULL, 0, 2, 9, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2647 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2648 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2), |
| 2649 | CreateMockRead(stream1_body, 4), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2650 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2651 | }; |
| 2652 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2653 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2654 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2655 | BoundNetLog(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2656 | |
| 2657 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2658 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2659 | |
| 2660 | HttpNetworkTransaction* trans = helper.trans(); |
| 2661 | |
| 2662 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2663 | TestCompletionCallback callback; |
| 2664 | int rv = trans->Start( |
| 2665 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2666 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2667 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2668 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2669 | |
| 2670 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2671 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2672 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2673 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2674 | // Verify the response headers. |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2675 | HttpResponseInfo response = *trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2676 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2677 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2678 | } |
| 2679 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2680 | TEST_F(SpdyNetworkTransactionTest, ServerPushNoURL) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2681 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2682 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2683 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 2684 | SpdySerializedFrame stream2_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2685 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2686 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2687 | CreateMockWrite(stream1_syn, 0), CreateMockWrite(stream2_rst, 3), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2688 | }; |
| 2689 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2690 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2691 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2692 | SpdyHeaderBlock incomplete_headers; |
| 2693 | incomplete_headers[spdy_util_.GetStatusKey()] = "200 OK"; |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2694 | incomplete_headers["hello"] = "bye"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2695 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame( |
| 2696 | std::move(incomplete_headers), 2, 1)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2697 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2698 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2), |
| 2699 | CreateMockRead(stream1_body, 4), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2700 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5) // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2701 | }; |
| 2702 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2703 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2704 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2705 | BoundNetLog(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2706 | |
| 2707 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2708 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2709 | |
| 2710 | HttpNetworkTransaction* trans = helper.trans(); |
| 2711 | |
| 2712 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2713 | TestCompletionCallback callback; |
| 2714 | int rv = trans->Start( |
| 2715 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2716 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2717 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2718 | EXPECT_THAT(rv, IsOk()); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2719 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2720 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2721 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2722 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2723 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2724 | // Verify the response headers. |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2725 | HttpResponseInfo response = *trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2726 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2727 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2728 | } |
| 2729 | |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2730 | // PUSH_PROMISE on a server-initiated stream should trigger GOAWAY. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2731 | TEST_F(SpdyNetworkTransactionTest, ServerPushOnPushedStream) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2732 | SpdySerializedFrame stream1_syn( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2733 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2734 | SpdySerializedFrame goaway(spdy_util_.ConstructSpdyGoAway( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2735 | 2, GOAWAY_PROTOCOL_ERROR, "Push on even stream id.")); |
| 2736 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2737 | CreateMockWrite(stream1_syn, 0), CreateMockWrite(goaway, 4), |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2738 | }; |
| 2739 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2740 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2741 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2742 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2743 | nullptr, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2744 | SpdySerializedFrame stream3_syn(spdy_util_.ConstructSpdyPush( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2745 | nullptr, 0, 4, 2, GetDefaultUrlWithPath("/bar.dat").c_str())); |
| 2746 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2747 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2), |
| 2748 | CreateMockRead(stream3_syn, 3), |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2749 | }; |
| 2750 | |
| 2751 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2752 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2753 | BoundNetLog(), nullptr); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2754 | helper.RunToCompletion(&data); |
| 2755 | } |
| 2756 | |
| 2757 | // PUSH_PROMISE on a closed client-initiated stream should trigger RST_STREAM. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2758 | TEST_F(SpdyNetworkTransactionTest, ServerPushOnClosedStream) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2759 | SpdySerializedFrame stream1_syn( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2760 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2761 | SpdySerializedFrame rst( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2762 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_INVALID_STREAM)); |
| 2763 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2764 | CreateMockWrite(stream1_syn, 0), CreateMockWrite(rst, 5), |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2765 | }; |
| 2766 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2767 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2768 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2769 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 2770 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2771 | nullptr, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
| 2772 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2773 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream1_body, 2), |
| 2774 | CreateMockRead(stream2_syn, 3), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 4), |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2775 | }; |
| 2776 | |
| 2777 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2778 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2779 | BoundNetLog(), nullptr); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2780 | helper.RunPreTestSetup(); |
| 2781 | helper.AddData(&data); |
| 2782 | |
| 2783 | HttpNetworkTransaction* trans = helper.trans(); |
| 2784 | |
| 2785 | TestCompletionCallback callback; |
| 2786 | int rv = |
| 2787 | trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 2788 | rv = callback.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2789 | EXPECT_THAT(rv, IsOk()); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2790 | HttpResponseInfo response = *trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2791 | EXPECT_TRUE(response.headers); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2792 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
| 2793 | |
| 2794 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2795 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 2796 | VerifyStreamsClosed(helper); |
| 2797 | } |
| 2798 | |
| 2799 | // PUSH_PROMISE on a server-initiated stream should trigger GOAWAY even if |
| 2800 | // stream is closed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2801 | TEST_F(SpdyNetworkTransactionTest, ServerPushOnClosedPushedStream) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2802 | SpdySerializedFrame stream1_syn( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2803 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2804 | SpdySerializedFrame goaway(spdy_util_.ConstructSpdyGoAway( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2805 | 2, GOAWAY_PROTOCOL_ERROR, "Push on even stream id.")); |
| 2806 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2807 | CreateMockWrite(stream1_syn, 0), CreateMockWrite(goaway, 7), |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2808 | }; |
| 2809 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2810 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2811 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2812 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2813 | nullptr, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2814 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2815 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2816 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 2817 | 2, kPushedData, strlen(kPushedData), true)); |
| 2818 | SpdySerializedFrame stream3_syn(spdy_util_.ConstructSpdyPush( |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2819 | nullptr, 0, 4, 2, GetDefaultUrlWithPath("/bar.dat").c_str())); |
| 2820 | |
| 2821 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2822 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2), |
| 2823 | CreateMockRead(stream1_body, 3), CreateMockRead(stream2_body, 4), |
| 2824 | MockRead(ASYNC, ERR_IO_PENDING, 5), CreateMockRead(stream3_syn, 6), |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2825 | }; |
| 2826 | |
| 2827 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2828 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2829 | BoundNetLog(), nullptr); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2830 | helper.RunPreTestSetup(); |
| 2831 | helper.AddData(&data); |
| 2832 | |
| 2833 | HttpNetworkTransaction* trans1 = helper.trans(); |
| 2834 | TestCompletionCallback callback1; |
| 2835 | int rv = |
| 2836 | trans1->Start(&CreateGetRequest(), callback1.callback(), BoundNetLog()); |
| 2837 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2838 | EXPECT_THAT(rv, IsOk()); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2839 | HttpResponseInfo response = *trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2840 | EXPECT_TRUE(response.headers); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2841 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
| 2842 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 2843 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2844 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 2845 | rv = trans2.Start(&CreateGetPushRequest(), callback2.callback(), |
| 2846 | BoundNetLog()); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2847 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2848 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 2849 | response = *trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2850 | EXPECT_TRUE(response.headers); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2851 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
| 2852 | std::string result; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 2853 | ReadResult(&trans2, &result); |
bnc | 0cb98b2 | 2016-03-04 17:10:52 | [diff] [blame] | 2854 | EXPECT_EQ(kPushedData, result); |
| 2855 | |
| 2856 | data.Resume(); |
| 2857 | base::RunLoop().RunUntilIdle(); |
| 2858 | |
| 2859 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2860 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 2861 | } |
| 2862 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2863 | // Verify that various response headers parse correctly through the HTTP layer. |
| 2864 | TEST_F(SpdyNetworkTransactionTest, ResponseHeaders) { |
| 2865 | struct ResponseHeadersTests { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2866 | int num_headers; |
| 2867 | const char* extra_headers[5]; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2868 | SpdyHeaderBlock expected_headers; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 2869 | } test_cases[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2870 | // This uses a multi-valued cookie header. |
| 2871 | { 2, |
| 2872 | { "cookie", "val1", |
| 2873 | "cookie", "val2", // will get appended separated by NULL |
| 2874 | NULL |
| 2875 | }, |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 2876 | }, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2877 | // This is the minimalist set of headers. |
| 2878 | { 0, |
| 2879 | { NULL }, |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 2880 | }, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2881 | // Headers with a comma separated list. |
| 2882 | { 1, |
| 2883 | { "cookie", "val1,val2", |
| 2884 | NULL |
| 2885 | }, |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 2886 | } |
| 2887 | }; |
| 2888 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2889 | test_cases[0].expected_headers["status"] = "200"; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2890 | test_cases[1].expected_headers["status"] = "200"; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2891 | test_cases[2].expected_headers["status"] = "200"; |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 2892 | |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 2893 | test_cases[0].expected_headers["hello"] = "bye"; |
| 2894 | test_cases[1].expected_headers["hello"] = "bye"; |
| 2895 | test_cases[2].expected_headers["hello"] = "bye"; |
| 2896 | |
bnc | 2d24791 | 2016-04-21 23:34:37 | [diff] [blame] | 2897 | test_cases[0].expected_headers["cookie"] = base::StringPiece("val1\0val2", 9); |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 2898 | test_cases[2].expected_headers["cookie"] = "val1,val2"; |
| 2899 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 2900 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2901 | SpdyTestUtil spdy_test_util; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2902 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2903 | spdy_test_util.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2904 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 2905 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2906 | SpdySerializedFrame resp(spdy_test_util.ConstructSpdyGetReply( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2907 | test_cases[i].extra_headers, test_cases[i].num_headers, 1)); |
| 2908 | SpdySerializedFrame body(spdy_test_util.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 2909 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2910 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2911 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 2912 | }; |
| 2913 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2914 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 2915 | arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2916 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2917 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2918 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2919 | TransactionHelperResult out = helper.output(); |
| 2920 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2921 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2922 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 2923 | EXPECT_EQ("hello!", out.response_data); |
| 2924 | |
| 2925 | scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2926 | EXPECT_TRUE(headers); |
olli.raula | 33c282f | 2016-01-21 12:12:49 | [diff] [blame] | 2927 | size_t iter = 0; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2928 | std::string name, value; |
| 2929 | SpdyHeaderBlock header_block; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 2930 | while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 2931 | SpdyHeaderBlock::StringPieceProxy mutable_header_block_value = |
| 2932 | header_block[name]; |
bnc | 2d24791 | 2016-04-21 23:34:37 | [diff] [blame] | 2933 | if (static_cast<base::StringPiece>(mutable_header_block_value).empty()) { |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 2934 | mutable_header_block_value = value; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2935 | } else { |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 2936 | std::string joint_value = mutable_header_block_value.as_string(); |
| 2937 | joint_value.append(1, '\0'); |
| 2938 | joint_value.append(value); |
| 2939 | mutable_header_block_value = joint_value; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2940 | } |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 2941 | } |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2942 | EXPECT_EQ(test_cases[i].expected_headers, header_block); |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 2943 | } |
| 2944 | } |
| 2945 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2946 | // Verify that various response headers parse vary fields correctly through the |
| 2947 | // HTTP layer, and the response matches the request. |
| 2948 | TEST_F(SpdyNetworkTransactionTest, ResponseHeadersVary) { |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 2949 | // Modify the following data to change/add test cases: |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 2950 | struct ResponseTests { |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 2951 | bool vary_matches; |
| 2952 | int num_headers[2]; |
| 2953 | const char* extra_headers[2][16]; |
| 2954 | } test_cases[] = { |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 2955 | // Test the case of a multi-valued cookie. When the value is delimited |
| 2956 | // with NUL characters, it needs to be unfolded into multiple headers. |
| 2957 | {true, |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 2958 | {1, 3}, |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 2959 | {{"cookie", "val1,val2", NULL}, |
| 2960 | {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 2961 | "/index.php", "vary", "cookie", NULL}}}, |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 2962 | {// Multiple vary fields. |
| 2963 | true, |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 2964 | {2, 4}, |
| 2965 | {{"friend", "barney", "enemy", "snaggletooth", NULL}, |
| 2966 | {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 2967 | "/index.php", "vary", "friend", "vary", "enemy", NULL}}}, |
| 2968 | {// Test a '*' vary field. |
| 2969 | false, |
| 2970 | {1, 3}, |
| 2971 | {{"cookie", "val1,val2", NULL}, |
| 2972 | {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
| 2973 | "/index.php", "vary", "*", NULL}}}, |
| 2974 | {// Multiple comma-separated vary fields. |
| 2975 | true, |
| 2976 | {2, 3}, |
| 2977 | {{"friend", "barney", "enemy", "snaggletooth", NULL}, |
| 2978 | {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
| 2979 | "/index.php", "vary", "friend,enemy", NULL}}}}; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 2980 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 2981 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2982 | SpdyTestUtil spdy_test_util; |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 2983 | |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 2984 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2985 | SpdySerializedFrame frame_req(spdy_test_util.ConstructSpdyGet( |
| 2986 | test_cases[i].extra_headers[0], test_cases[i].num_headers[0], 1, LOWEST, |
| 2987 | true)); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 2988 | |
| 2989 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 2990 | CreateMockWrite(frame_req, 0), |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 2991 | }; |
| 2992 | |
| 2993 | // Construct the reply. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 2994 | SpdyHeaderBlock reply_headers; |
| 2995 | AppendToHeaderBlock(test_cases[i].extra_headers[1], |
| 2996 | test_cases[i].num_headers[1], |
| 2997 | &reply_headers); |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 2998 | // Construct the expected header reply string before moving |reply_headers|. |
| 2999 | std::string expected_reply = |
| 3000 | spdy_test_util.ConstructSpdyReplyString(reply_headers); |
| 3001 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3002 | SpdySerializedFrame frame_reply( |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 3003 | spdy_test_util.ConstructSpdyReply(1, std::move(reply_headers))); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3004 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3005 | SpdySerializedFrame body(spdy_test_util.ConstructSpdyDataFrame(1, true)); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3006 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3007 | CreateMockRead(frame_reply, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3008 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3009 | }; |
| 3010 | |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3011 | // Attach the headers to the request. |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 3012 | int header_count = test_cases[i].num_headers[0]; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3013 | |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 3014 | HttpRequestInfo request = CreateGetRequest(); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 3015 | for (int ct = 0; ct < header_count; ct++) { |
| 3016 | const char* header_key = test_cases[i].extra_headers[0][ct * 2]; |
| 3017 | const char* header_value = test_cases[i].extra_headers[0][ct * 2 + 1]; |
| 3018 | request.extra_headers.SetHeader(header_key, header_value); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3019 | } |
| 3020 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3021 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 3022 | arraysize(writes)); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3023 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 3024 | NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3025 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3026 | TransactionHelperResult out = helper.output(); |
| 3027 | |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3028 | EXPECT_EQ(OK, out.rv) << i; |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3029 | EXPECT_EQ("HTTP/1.1 200", out.status_line) << i; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3030 | EXPECT_EQ("hello!", out.response_data) << i; |
| 3031 | |
| 3032 | // Test the response information. |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3033 | EXPECT_EQ(out.response_info.vary_data.is_valid(), |
| 3034 | test_cases[i].vary_matches) << i; |
| 3035 | |
| 3036 | // Check the headers. |
| 3037 | scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3038 | ASSERT_TRUE(headers) << i; |
olli.raula | 33c282f | 2016-01-21 12:12:49 | [diff] [blame] | 3039 | size_t iter = 0; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3040 | std::string name, value, lines; |
| 3041 | while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
| 3042 | lines.append(name); |
| 3043 | lines.append(": "); |
| 3044 | lines.append(value); |
| 3045 | lines.append("\n"); |
| 3046 | } |
| 3047 | |
[email protected] | 9aa32319 | 2013-05-31 21:38:40 | [diff] [blame] | 3048 | EXPECT_EQ(expected_reply, lines) << i; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3049 | } |
| 3050 | } |
| 3051 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3052 | // Verify that we don't crash on invalid response headers. |
| 3053 | TEST_F(SpdyNetworkTransactionTest, InvalidResponseHeaders) { |
| 3054 | struct InvalidResponseHeadersTests { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3055 | int num_headers; |
| 3056 | const char* headers[10]; |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3057 | } test_cases[] = { |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3058 | // Response headers missing status header |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3059 | { |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 3060 | 3, |
| 3061 | {spdy_util_.GetPathKey(), "/index.php", "cookie", "val1", "cookie", |
| 3062 | "val2", NULL}, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3063 | }, |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3064 | // Response headers missing version header |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3065 | { |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 3066 | 1, {spdy_util_.GetPathKey(), "/index.php", "status", "200", NULL}, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3067 | }, |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3068 | // Response headers with no headers |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3069 | { |
| 3070 | 0, {NULL}, |
| 3071 | }, |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3072 | }; |
| 3073 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 3074 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3075 | SpdyTestUtil spdy_test_util; |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3076 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3077 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3078 | spdy_test_util.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3079 | SpdySerializedFrame rst( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3080 | spdy_test_util.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3081 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3082 | CreateMockWrite(req, 0), CreateMockWrite(rst, 2), |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3083 | }; |
| 3084 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3085 | // Construct the reply. |
| 3086 | SpdyHeaderBlock reply_headers; |
| 3087 | AppendToHeaderBlock( |
| 3088 | test_cases[i].headers, test_cases[i].num_headers, &reply_headers); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3089 | SpdySerializedFrame resp( |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 3090 | spdy_test_util.ConstructSpdyReply(1, std::move(reply_headers))); |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3091 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3092 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3) // EOF |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3093 | }; |
| 3094 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3095 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 3096 | arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3097 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3098 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3099 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3100 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3101 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3102 | } |
| 3103 | } |
| 3104 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3105 | TEST_F(SpdyNetworkTransactionTest, CorruptFrameSessionError) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3106 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3107 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3108 | SpdySerializedFrame goaway(spdy_util_.ConstructSpdyGoAway( |
bnc | f501299 | 2016-04-19 16:36:26 | [diff] [blame] | 3109 | 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 6 (DECOMPRESS_FAILURE).")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3110 | MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(goaway, 2)}; |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3111 | |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3112 | // This is the length field that's too short. |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3113 | SpdySerializedFrame reply_wrong_length( |
| 3114 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
diannahu | 86e7a8ab | 2016-08-03 20:11:14 | [diff] [blame] | 3115 | size_t right_size = |
| 3116 | reply_wrong_length.size() - SpdyConstants::GetFrameHeaderSize(HTTP2); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3117 | size_t wrong_size = right_size - 4; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3118 | test::SetFrameLength(&reply_wrong_length, wrong_size, HTTP2); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3119 | |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3120 | MockRead reads[] = { |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3121 | MockRead(ASYNC, reply_wrong_length.data(), reply_wrong_length.size() - 4, |
| 3122 | 1), |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3123 | }; |
| 3124 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3125 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3126 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3127 | BoundNetLog(), NULL); |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3128 | helper.RunToCompletion(&data); |
| 3129 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3130 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_COMPRESSION_ERROR)); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3131 | } |
| 3132 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3133 | TEST_F(SpdyNetworkTransactionTest, GoAwayOnDecompressionFailure) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3134 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3135 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3136 | SpdySerializedFrame goaway(spdy_util_.ConstructSpdyGoAway( |
bnc | f501299 | 2016-04-19 16:36:26 | [diff] [blame] | 3137 | 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 6 (DECOMPRESS_FAILURE).")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3138 | MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(goaway, 2)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3139 | |
| 3140 | // Read HEADERS with corrupted payload. |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3141 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3142 | memset(resp.data() + 12, 0xcf, resp.size() - 12); |
| 3143 | MockRead reads[] = {CreateMockRead(resp, 1)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3144 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3145 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3146 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 3147 | BoundNetLog(), NULL); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3148 | helper.RunToCompletion(&data); |
| 3149 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3150 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_COMPRESSION_ERROR)); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3151 | } |
| 3152 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3153 | TEST_F(SpdyNetworkTransactionTest, GoAwayOnFrameSizeError) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3154 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3155 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3156 | SpdySerializedFrame goaway(spdy_util_.ConstructSpdyGoAway( |
bnc | 20df67c | 2016-04-07 01:36:18 | [diff] [blame] | 3157 | 0, GOAWAY_FRAME_SIZE_ERROR, |
dahollings | af379649 | 2016-05-25 19:21:35 | [diff] [blame] | 3158 | "Framer error: 15 (INVALID_CONTROL_FRAME_SIZE).")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3159 | MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(goaway, 2)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3160 | |
| 3161 | // Read WINDOW_UPDATE with incorrectly-sized payload. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3162 | SpdySerializedFrame bad_window_update( |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3163 | spdy_util_.ConstructSpdyWindowUpdate(1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3164 | test::SetFrameLength(&bad_window_update, bad_window_update.size() - 1, HTTP2); |
| 3165 | MockRead reads[] = {CreateMockRead(bad_window_update, 1)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3166 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3167 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3168 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 3169 | BoundNetLog(), NULL); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3170 | helper.RunToCompletion(&data); |
| 3171 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3172 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_FRAME_SIZE_ERROR)); |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3173 | } |
| 3174 | |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3175 | // Test that we shutdown correctly on write errors. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3176 | TEST_F(SpdyNetworkTransactionTest, WriteError) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3177 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3178 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3179 | MockWrite writes[] = { |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3180 | // We'll write 10 bytes successfully |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3181 | MockWrite(ASYNC, req.data(), 10, 1), |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3182 | // Followed by ERROR! |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3183 | MockWrite(ASYNC, ERR_FAILED, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 3184 | // Session drains and attempts to write a GOAWAY: Another ERROR! |
| 3185 | MockWrite(ASYNC, ERR_FAILED, 3), |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3186 | }; |
| 3187 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 3188 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3189 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 3190 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3191 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3192 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3193 | BoundNetLog(), NULL); |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3194 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 3195 | helper.AddData(&data); |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3196 | EXPECT_TRUE(helper.StartDefaultTest()); |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3197 | helper.FinishDefaultTest(); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 3198 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 3199 | EXPECT_TRUE(data.AllReadDataConsumed()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3200 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3201 | EXPECT_THAT(out.rv, IsError(ERR_FAILED)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3202 | } |
| 3203 | |
| 3204 | // Test that partial writes work. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3205 | TEST_F(SpdyNetworkTransactionTest, PartialWrite) { |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3206 | // Chop the HEADERS frame into 5 chunks. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3207 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3208 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3209 | const int kChunks = 5; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3210 | std::unique_ptr<MockWrite[]> writes(ChopWriteFrame(req, kChunks)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3211 | for (int i = 0; i < kChunks; ++i) { |
| 3212 | writes[i].sequence_number = i; |
| 3213 | } |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3214 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3215 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3216 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3217 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3218 | CreateMockRead(resp, kChunks), CreateMockRead(body, kChunks + 1), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3219 | MockRead(ASYNC, 0, kChunks + 2) // EOF |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3220 | }; |
| 3221 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3222 | SequencedSocketData data(reads, arraysize(reads), writes.get(), kChunks); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3223 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3224 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3225 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3226 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3227 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3228 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3229 | EXPECT_EQ("hello!", out.response_data); |
| 3230 | } |
| 3231 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 3232 | // Test that the NetLog contains good data for a simple GET request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3233 | TEST_F(SpdyNetworkTransactionTest, NetLog) { |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3234 | static const char* const kExtraHeaders[] = { |
| 3235 | "user-agent", "Chrome", |
| 3236 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3237 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3238 | spdy_util_.ConstructSpdyGet(kExtraHeaders, 1, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3239 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3240 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3241 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3242 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3243 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3244 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3245 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3246 | }; |
| 3247 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3248 | BoundTestNetLog log; |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3249 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3250 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3251 | NormalSpdyTransactionHelper helper(CreateGetRequestWithUserAgent(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3252 | DEFAULT_PRIORITY, log.bound(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3253 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3254 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3255 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3256 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3257 | EXPECT_EQ("hello!", out.response_data); |
| 3258 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 3259 | // Check that the NetLog was filled reasonably. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3260 | // This test is intentionally non-specific about the exact ordering of the |
| 3261 | // log; instead we just check to make sure that certain events exist, and that |
| 3262 | // they are in the right order. |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3263 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3264 | log.GetEntries(&entries); |
| 3265 | |
| 3266 | EXPECT_LT(0u, entries.size()); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3267 | int pos = 0; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3268 | pos = ExpectLogContainsSomewhere(entries, 0, |
| 3269 | NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, |
| 3270 | NetLog::PHASE_BEGIN); |
| 3271 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3272 | NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, |
| 3273 | NetLog::PHASE_END); |
| 3274 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3275 | NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, |
| 3276 | NetLog::PHASE_BEGIN); |
| 3277 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3278 | NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, |
| 3279 | NetLog::PHASE_END); |
| 3280 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3281 | NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, |
| 3282 | NetLog::PHASE_BEGIN); |
| 3283 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3284 | NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, |
| 3285 | NetLog::PHASE_END); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3286 | |
| 3287 | // Check that we logged all the headers correctly |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 3288 | pos = ExpectLogContainsSomewhere( |
| 3289 | entries, 0, NetLog::TYPE_HTTP2_SESSION_SEND_HEADERS, NetLog::PHASE_NONE); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3290 | |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 3291 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3292 | ASSERT_TRUE(entries[pos].params.get()); |
| 3293 | ASSERT_TRUE(entries[pos].params->GetList("headers", &header_list)); |
| 3294 | |
| 3295 | std::vector<std::string> expected; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3296 | expected.push_back(std::string(spdy_util_.GetHostKey()) + |
| 3297 | ": www.example.org"); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3298 | expected.push_back(std::string(spdy_util_.GetPathKey()) + ": /"); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 3299 | expected.push_back(std::string(spdy_util_.GetSchemeKey()) + ": " + |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 3300 | default_url_.scheme()); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3301 | expected.push_back(std::string(spdy_util_.GetMethodKey()) + ": GET"); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3302 | expected.push_back("user-agent: Chrome"); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3303 | EXPECT_EQ(expected.size(), header_list->GetSize()); |
| 3304 | for (std::vector<std::string>::const_iterator it = expected.begin(); |
| 3305 | it != expected.end(); |
| 3306 | ++it) { |
| 3307 | base::StringValue header(*it); |
| 3308 | EXPECT_NE(header_list->end(), header_list->Find(header)) << |
| 3309 | "Header not found: " << *it; |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3310 | } |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3311 | } |
| 3312 | |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3313 | // Since we buffer the IO from the stream to the renderer, this test verifies |
| 3314 | // that when we read out the maximum amount of data (e.g. we received 50 bytes |
| 3315 | // on the network, but issued a Read for only 5 of those bytes) that the data |
| 3316 | // flow still works correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3317 | TEST_F(SpdyNetworkTransactionTest, BufferFull) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3318 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3319 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3320 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3321 | |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3322 | // 2 data frames in a single read. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3323 | SpdySerializedFrame data_frame_1( |
| 3324 | spdy_util_.ConstructSpdyDataFrame(1, "goodby", 6, /*fin=*/false)); |
| 3325 | SpdySerializedFrame data_frame_2( |
| 3326 | spdy_util_.ConstructSpdyDataFrame(1, "e worl", 6, /*fin=*/false)); |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 3327 | const SpdySerializedFrame* data_frames[2] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3328 | &data_frame_1, &data_frame_2, |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3329 | }; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3330 | char combined_data_frames[100]; |
| 3331 | int combined_data_frames_len = |
| 3332 | CombineFrames(data_frames, arraysize(data_frames), |
| 3333 | combined_data_frames, arraysize(combined_data_frames)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3334 | SpdySerializedFrame last_frame( |
| 3335 | spdy_util_.ConstructSpdyDataFrame(1, "d", 1, /*fin=*/true)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3336 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3337 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3338 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3339 | CreateMockRead(resp, 1), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3340 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause |
| 3341 | MockRead(ASYNC, combined_data_frames, combined_data_frames_len, 3), |
| 3342 | MockRead(ASYNC, ERR_IO_PENDING, 4), // Force a pause |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3343 | CreateMockRead(last_frame, 5), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3344 | MockRead(ASYNC, 0, 6) // EOF |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3345 | }; |
| 3346 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3347 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3348 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3349 | TestCompletionCallback callback; |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3350 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3351 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3352 | BoundNetLog(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3353 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3354 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3355 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3356 | int rv = trans->Start( |
| 3357 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3358 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3359 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3360 | TransactionHelperResult out = helper.output(); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3361 | out.rv = callback.WaitForResult(); |
| 3362 | EXPECT_EQ(out.rv, OK); |
| 3363 | |
| 3364 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3365 | EXPECT_TRUE(response->headers); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3366 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3367 | out.status_line = response->headers->GetStatusLine(); |
| 3368 | out.response_info = *response; // Make a copy so we can verify. |
| 3369 | |
| 3370 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3371 | TestCompletionCallback read_callback; |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3372 | |
| 3373 | std::string content; |
| 3374 | do { |
| 3375 | // Read small chunks at a time. |
| 3376 | const int kSmallReadSize = 3; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3377 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3378 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3379 | if (rv == ERR_IO_PENDING) { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 3380 | data.Resume(); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3381 | rv = read_callback.WaitForResult(); |
| 3382 | } |
| 3383 | if (rv > 0) { |
| 3384 | content.append(buf->data(), rv); |
| 3385 | } else if (rv < 0) { |
| 3386 | NOTREACHED(); |
| 3387 | } |
| 3388 | } while (rv > 0); |
| 3389 | |
| 3390 | out.response_data.swap(content); |
| 3391 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3392 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3393 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3394 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3395 | |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3396 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3397 | helper.VerifyDataConsumed(); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3398 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3399 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3400 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3401 | EXPECT_EQ("goodbye world", out.response_data); |
| 3402 | } |
| 3403 | |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3404 | // Verify that basic buffering works; when multiple data frames arrive |
| 3405 | // at the same time, ensure that we don't notify a read completion for |
| 3406 | // each data frame individually. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3407 | TEST_F(SpdyNetworkTransactionTest, Buffering) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3408 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3409 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3410 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3411 | |
| 3412 | // 4 data frames in a single read. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3413 | SpdySerializedFrame data_frame( |
| 3414 | spdy_util_.ConstructSpdyDataFrame(1, "message", 7, /*fin=*/false)); |
| 3415 | SpdySerializedFrame data_frame_fin( |
| 3416 | spdy_util_.ConstructSpdyDataFrame(1, "message", 7, /*fin=*/true)); |
| 3417 | const SpdySerializedFrame* data_frames[4] = {&data_frame, &data_frame, |
| 3418 | &data_frame, &data_frame_fin}; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3419 | char combined_data_frames[100]; |
| 3420 | int combined_data_frames_len = |
| 3421 | CombineFrames(data_frames, arraysize(data_frames), |
| 3422 | combined_data_frames, arraysize(combined_data_frames)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3423 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3424 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3425 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3426 | CreateMockRead(resp, 1), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3427 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause |
| 3428 | MockRead(ASYNC, combined_data_frames, combined_data_frames_len, 3), |
| 3429 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3430 | }; |
| 3431 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3432 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3433 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3434 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3435 | BoundNetLog(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3436 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3437 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3438 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3439 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3440 | TestCompletionCallback callback; |
| 3441 | int rv = trans->Start( |
| 3442 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3443 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3444 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3445 | TransactionHelperResult out = helper.output(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3446 | out.rv = callback.WaitForResult(); |
| 3447 | EXPECT_EQ(out.rv, OK); |
| 3448 | |
| 3449 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3450 | EXPECT_TRUE(response->headers); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3451 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3452 | out.status_line = response->headers->GetStatusLine(); |
| 3453 | out.response_info = *response; // Make a copy so we can verify. |
| 3454 | |
| 3455 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3456 | TestCompletionCallback read_callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3457 | |
| 3458 | std::string content; |
| 3459 | int reads_completed = 0; |
| 3460 | do { |
| 3461 | // Read small chunks at a time. |
| 3462 | const int kSmallReadSize = 14; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3463 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3464 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3465 | if (rv == ERR_IO_PENDING) { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 3466 | data.Resume(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3467 | rv = read_callback.WaitForResult(); |
| 3468 | } |
| 3469 | if (rv > 0) { |
| 3470 | EXPECT_EQ(kSmallReadSize, rv); |
| 3471 | content.append(buf->data(), rv); |
| 3472 | } else if (rv < 0) { |
| 3473 | FAIL() << "Unexpected read error: " << rv; |
| 3474 | } |
| 3475 | reads_completed++; |
| 3476 | } while (rv > 0); |
| 3477 | |
| 3478 | EXPECT_EQ(3, reads_completed); // Reads are: 14 bytes, 14 bytes, 0 bytes. |
| 3479 | |
| 3480 | out.response_data.swap(content); |
| 3481 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3482 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3483 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3484 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3485 | |
| 3486 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3487 | helper.VerifyDataConsumed(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3488 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3489 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3490 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3491 | EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 3492 | } |
| 3493 | |
| 3494 | // 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] | 3495 | TEST_F(SpdyNetworkTransactionTest, BufferedAll) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3496 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3497 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3498 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3499 | |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3500 | // 5 data frames in a single read. |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3501 | SpdySerializedFrame reply(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3502 | SpdySerializedFrame data_frame( |
| 3503 | spdy_util_.ConstructSpdyDataFrame(1, "message", 7, /*fin=*/false)); |
| 3504 | SpdySerializedFrame data_frame_fin( |
| 3505 | spdy_util_.ConstructSpdyDataFrame(1, "message", 7, /*fin=*/true)); |
| 3506 | const SpdySerializedFrame* frames[5] = {&reply, &data_frame, &data_frame, |
| 3507 | &data_frame, &data_frame_fin}; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3508 | char combined_frames[200]; |
| 3509 | int combined_frames_len = |
| 3510 | CombineFrames(frames, arraysize(frames), |
| 3511 | combined_frames, arraysize(combined_frames)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3512 | |
| 3513 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3514 | MockRead(ASYNC, combined_frames, combined_frames_len, 1), |
| 3515 | MockRead(ASYNC, 0, 2) // EOF |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3516 | }; |
| 3517 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3518 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3519 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3520 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3521 | BoundNetLog(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3522 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3523 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3524 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3525 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3526 | TestCompletionCallback callback; |
| 3527 | int rv = trans->Start( |
| 3528 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3529 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3530 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3531 | TransactionHelperResult out = helper.output(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3532 | out.rv = callback.WaitForResult(); |
| 3533 | EXPECT_EQ(out.rv, OK); |
| 3534 | |
| 3535 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3536 | EXPECT_TRUE(response->headers); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3537 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3538 | out.status_line = response->headers->GetStatusLine(); |
| 3539 | out.response_info = *response; // Make a copy so we can verify. |
| 3540 | |
| 3541 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3542 | TestCompletionCallback read_callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3543 | |
| 3544 | std::string content; |
| 3545 | int reads_completed = 0; |
| 3546 | do { |
| 3547 | // Read small chunks at a time. |
| 3548 | const int kSmallReadSize = 14; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3549 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3550 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3551 | if (rv > 0) { |
| 3552 | EXPECT_EQ(kSmallReadSize, rv); |
| 3553 | content.append(buf->data(), rv); |
| 3554 | } else if (rv < 0) { |
| 3555 | FAIL() << "Unexpected read error: " << rv; |
| 3556 | } |
| 3557 | reads_completed++; |
| 3558 | } while (rv > 0); |
| 3559 | |
| 3560 | EXPECT_EQ(3, reads_completed); |
| 3561 | |
| 3562 | out.response_data.swap(content); |
| 3563 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3564 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3565 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3566 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3567 | |
| 3568 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3569 | helper.VerifyDataConsumed(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3570 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3571 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3572 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3573 | EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 3574 | } |
| 3575 | |
| 3576 | // Verify the case where we buffer data and close the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3577 | TEST_F(SpdyNetworkTransactionTest, BufferedClosed) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3578 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3579 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3580 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3581 | |
| 3582 | // All data frames in a single read. |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3583 | // NOTE: We don't FIN the stream. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3584 | SpdySerializedFrame data_frame( |
| 3585 | spdy_util_.ConstructSpdyDataFrame(1, "message", 7, /*fin=*/false)); |
| 3586 | const SpdySerializedFrame* data_frames[4] = {&data_frame, &data_frame, |
| 3587 | &data_frame, &data_frame}; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3588 | char combined_data_frames[100]; |
| 3589 | int combined_data_frames_len = |
| 3590 | CombineFrames(data_frames, arraysize(data_frames), |
| 3591 | combined_data_frames, arraysize(combined_data_frames)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3592 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3593 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3594 | CreateMockRead(resp, 1), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3595 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a wait |
| 3596 | MockRead(ASYNC, combined_data_frames, combined_data_frames_len, 3), |
| 3597 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3598 | }; |
| 3599 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3600 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3601 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3602 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3603 | BoundNetLog(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3604 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3605 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3606 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3607 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3608 | TestCompletionCallback callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3609 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3610 | int rv = trans->Start( |
| 3611 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3612 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3613 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3614 | TransactionHelperResult out = helper.output(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3615 | out.rv = callback.WaitForResult(); |
| 3616 | EXPECT_EQ(out.rv, OK); |
| 3617 | |
| 3618 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3619 | EXPECT_TRUE(response->headers); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3620 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3621 | out.status_line = response->headers->GetStatusLine(); |
| 3622 | out.response_info = *response; // Make a copy so we can verify. |
| 3623 | |
| 3624 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3625 | TestCompletionCallback read_callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3626 | |
| 3627 | std::string content; |
| 3628 | int reads_completed = 0; |
| 3629 | do { |
| 3630 | // Read small chunks at a time. |
| 3631 | const int kSmallReadSize = 14; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3632 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3633 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3634 | if (rv == ERR_IO_PENDING) { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 3635 | data.Resume(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3636 | rv = read_callback.WaitForResult(); |
| 3637 | } |
| 3638 | if (rv > 0) { |
| 3639 | content.append(buf->data(), rv); |
| 3640 | } else if (rv < 0) { |
| 3641 | // This test intentionally closes the connection, and will get an error. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3642 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3643 | break; |
| 3644 | } |
| 3645 | reads_completed++; |
| 3646 | } while (rv > 0); |
| 3647 | |
| 3648 | EXPECT_EQ(0, reads_completed); |
| 3649 | |
| 3650 | out.response_data.swap(content); |
| 3651 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3652 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3653 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3654 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3655 | |
| 3656 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3657 | helper.VerifyDataConsumed(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3658 | } |
| 3659 | |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3660 | // Verify the case where we buffer data and cancel the transaction. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3661 | TEST_F(SpdyNetworkTransactionTest, BufferedCancelled) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3662 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3663 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3664 | SpdySerializedFrame rst( |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 3665 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3666 | MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(rst, 4)}; |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3667 | |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3668 | // NOTE: We don't FIN the stream. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3669 | SpdySerializedFrame data_frame( |
| 3670 | spdy_util_.ConstructSpdyDataFrame(1, "message", 7, /*fin=*/false)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3671 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3672 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3673 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3674 | CreateMockRead(resp, 1), |
| 3675 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a wait |
| 3676 | CreateMockRead(data_frame, 3), MockRead(ASYNC, 0, 5) // EOF |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3677 | }; |
| 3678 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3679 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3680 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3681 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3682 | BoundNetLog(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3683 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3684 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3685 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3686 | TestCompletionCallback callback; |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3687 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3688 | int rv = trans->Start( |
| 3689 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3690 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3691 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3692 | TransactionHelperResult out = helper.output(); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3693 | out.rv = callback.WaitForResult(); |
| 3694 | EXPECT_EQ(out.rv, OK); |
| 3695 | |
| 3696 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3697 | EXPECT_TRUE(response->headers); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3698 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3699 | out.status_line = response->headers->GetStatusLine(); |
| 3700 | out.response_info = *response; // Make a copy so we can verify. |
| 3701 | |
| 3702 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3703 | TestCompletionCallback read_callback; |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3704 | |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 3705 | const int kReadSize = 256; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3706 | scoped_refptr<IOBuffer> buf(new IOBuffer(kReadSize)); |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 3707 | rv = trans->Read(buf.get(), kReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3708 | ASSERT_EQ(ERR_IO_PENDING, rv) << "Unexpected read: " << rv; |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 3709 | |
| 3710 | // Complete the read now, which causes buffering to start. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 3711 | data.Resume(); |
| 3712 | base::RunLoop().RunUntilIdle(); |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 3713 | // Destroy the transaction, causing the stream to get cancelled |
| 3714 | // and orphaning the buffered IO task. |
| 3715 | helper.ResetTrans(); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3716 | |
| 3717 | // Flush the MessageLoop; this will cause the buffered IO task |
| 3718 | // to run for the final time. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3719 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3720 | |
| 3721 | // Verify that we consumed all test data. |
| 3722 | helper.VerifyDataConsumed(); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3723 | } |
| 3724 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3725 | TEST_F(SpdyNetworkTransactionTest, GoAwayWithActiveStream) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3726 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3727 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3728 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 69d717bd | 2010-04-21 18:43:21 | [diff] [blame] | 3729 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3730 | SpdySerializedFrame go_away(spdy_util_.ConstructSpdyGoAway()); |
[email protected] | 69d717bd | 2010-04-21 18:43:21 | [diff] [blame] | 3731 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3732 | CreateMockRead(go_away, 1), |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 3733 | }; |
| 3734 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3735 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3736 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3737 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3738 | helper.AddData(&data); |
| 3739 | helper.RunToCompletion(&data); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 3740 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3741 | EXPECT_THAT(out.rv, IsError(ERR_ABORTED)); |
[email protected] | 69d717bd | 2010-04-21 18:43:21 | [diff] [blame] | 3742 | } |
| 3743 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3744 | TEST_F(SpdyNetworkTransactionTest, CloseWithActiveStream) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3745 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3746 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3747 | MockWrite writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 3748 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3749 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 3750 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3751 | CreateMockRead(resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 3752 | }; |
| 3753 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3754 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 3755 | BoundNetLog log; |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3756 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, log, |
| 3757 | NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3758 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3759 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3760 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 3761 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3762 | TestCompletionCallback callback; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3763 | TransactionHelperResult out; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3764 | out.rv = trans->Start(&CreateGetRequest(), callback.callback(), log); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3765 | |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 3766 | EXPECT_EQ(out.rv, ERR_IO_PENDING); |
| 3767 | out.rv = callback.WaitForResult(); |
bnc | aa17133 | 2016-07-20 14:47:36 | [diff] [blame] | 3768 | EXPECT_EQ(out.rv, ERR_CONNECTION_CLOSED); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 3769 | |
| 3770 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3771 | EXPECT_TRUE(response->headers); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 3772 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3773 | out.rv = ReadTransaction(trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3774 | EXPECT_THAT(out.rv, IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [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] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 3778 | } |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 3779 | |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3780 | // Retry with HTTP/1.1 when receiving HTTP_1_1_REQUIRED. Note that no actual |
| 3781 | // protocol negotiation happens, instead this test forces protocols for both |
| 3782 | // sockets. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3783 | TEST_F(SpdyNetworkTransactionTest, HTTP11RequiredRetry) { |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3784 | HttpRequestInfo request; |
| 3785 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 3786 | request.url = default_url_; |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3787 | // Do not force SPDY so that second socket can negotiate HTTP/1.1. |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3788 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3789 | nullptr); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3790 | |
| 3791 | // First socket: HTTP/2 request rejected with HTTP_1_1_REQUIRED. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 3792 | SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3793 | SpdySerializedFrame req( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3794 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3795 | MockWrite writes0[] = {CreateMockWrite(req, 0)}; |
| 3796 | SpdySerializedFrame go_away(spdy_util_.ConstructSpdyGoAway( |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3797 | 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3798 | MockRead reads0[] = {CreateMockRead(go_away, 1)}; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3799 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 3800 | arraysize(writes0)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3801 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 3802 | std::unique_ptr<SSLSocketDataProvider> ssl_provider0( |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3803 | new SSLSocketDataProvider(ASYNC, OK)); |
| 3804 | // Expect HTTP/2 protocols too in SSLConfig. |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 3805 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP2); |
bnc | 3f0118e | 2016-02-02 15:42:22 | [diff] [blame] | 3806 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3807 | // Force SPDY. |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 3808 | ssl_provider0->next_proto = kProtoHTTP2; |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3809 | helper.AddDataWithSSLSocketDataProvider(&data0, std::move(ssl_provider0)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3810 | |
| 3811 | // Second socket: falling back to HTTP/1.1. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3812 | MockWrite writes1[] = {MockWrite(ASYNC, 0, |
| 3813 | "GET / HTTP/1.1\r\n" |
| 3814 | "Host: www.example.org\r\n" |
| 3815 | "Connection: keep-alive\r\n\r\n")}; |
| 3816 | MockRead reads1[] = {MockRead(ASYNC, 1, |
| 3817 | "HTTP/1.1 200 OK\r\n" |
| 3818 | "Content-Length: 5\r\n\r\n" |
| 3819 | "hello")}; |
| 3820 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 3821 | arraysize(writes1)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3822 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 3823 | std::unique_ptr<SSLSocketDataProvider> ssl_provider1( |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3824 | new SSLSocketDataProvider(ASYNC, OK)); |
| 3825 | // Expect only HTTP/1.1 protocol in SSLConfig. |
| 3826 | ssl_provider1->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 3827 | // Force HTTP/1.1. |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 3828 | ssl_provider1->next_proto = kProtoHTTP11; |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3829 | helper.AddDataWithSSLSocketDataProvider(&data1, std::move(ssl_provider1)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3830 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 3831 | HttpServerProperties* http_server_properties = |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3832 | helper.session()->spdy_session_pool()->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 3833 | EXPECT_FALSE(http_server_properties->RequiresHTTP11(host_port_pair_)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3834 | |
| 3835 | helper.RunPreTestSetup(); |
| 3836 | helper.StartDefaultTest(); |
| 3837 | helper.FinishDefaultTestWithoutVerification(); |
| 3838 | helper.VerifyDataConsumed(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 3839 | EXPECT_TRUE(http_server_properties->RequiresHTTP11(host_port_pair_)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3840 | |
| 3841 | const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3842 | ASSERT_TRUE(response); |
| 3843 | ASSERT_TRUE(response->headers); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3844 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3845 | EXPECT_FALSE(response->was_fetched_via_spdy); |
mmenke | 8210acc | 2016-07-11 16:34:52 | [diff] [blame] | 3846 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1_1, |
| 3847 | response->connection_info); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3848 | EXPECT_TRUE(response->was_npn_negotiated); |
| 3849 | EXPECT_TRUE(request.url.SchemeIs("https")); |
| 3850 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 3851 | EXPECT_EQ(443, response->socket_address.port()); |
| 3852 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3853 | ASSERT_THAT(ReadTransaction(helper.trans(), &response_data), IsOk()); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3854 | EXPECT_EQ("hello", response_data); |
| 3855 | } |
| 3856 | |
| 3857 | // Retry with HTTP/1.1 to the proxy when receiving HTTP_1_1_REQUIRED from the |
| 3858 | // proxy. Note that no actual protocol negotiation happens, instead this test |
| 3859 | // forces protocols for both sockets. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3860 | TEST_F(SpdyNetworkTransactionTest, HTTP11RequiredProxyRetry) { |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3861 | HttpRequestInfo request; |
| 3862 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 3863 | request.url = default_url_; |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3864 | auto session_deps = base::MakeUnique<SpdySessionDependencies>( |
| 3865 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70")); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3866 | // Do not force SPDY so that second socket can negotiate HTTP/1.1. |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3867 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3868 | std::move(session_deps)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3869 | |
| 3870 | // First socket: HTTP/2 CONNECT rejected with HTTP_1_1_REQUIRED. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3871 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3872 | nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3873 | MockWrite writes0[] = {CreateMockWrite(req, 0)}; |
| 3874 | SpdySerializedFrame go_away(spdy_util_.ConstructSpdyGoAway( |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3875 | 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3876 | MockRead reads0[] = {CreateMockRead(go_away, 1)}; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3877 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 3878 | arraysize(writes0)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3879 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 3880 | std::unique_ptr<SSLSocketDataProvider> ssl_provider0( |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3881 | new SSLSocketDataProvider(ASYNC, OK)); |
| 3882 | // Expect HTTP/2 protocols too in SSLConfig. |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 3883 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP2); |
bnc | 3f0118e | 2016-02-02 15:42:22 | [diff] [blame] | 3884 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3885 | // Force SPDY. |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 3886 | ssl_provider0->next_proto = kProtoHTTP2; |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3887 | helper.AddDataWithSSLSocketDataProvider(&data0, std::move(ssl_provider0)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3888 | |
| 3889 | // Second socket: retry using HTTP/1.1. |
| 3890 | MockWrite writes1[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3891 | MockWrite(ASYNC, 0, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3892 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3893 | "Host: www.example.org:443\r\n" |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3894 | "Proxy-Connection: keep-alive\r\n\r\n"), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3895 | MockWrite(ASYNC, 2, |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3896 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3897 | "Host: www.example.org\r\n" |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3898 | "Connection: keep-alive\r\n\r\n"), |
| 3899 | }; |
| 3900 | |
| 3901 | MockRead reads1[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3902 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 3903 | MockRead(ASYNC, 3, |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3904 | "HTTP/1.1 200 OK\r\n" |
| 3905 | "Content-Length: 5\r\n\r\n" |
| 3906 | "hello"), |
| 3907 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3908 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 3909 | arraysize(writes1)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3910 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 3911 | std::unique_ptr<SSLSocketDataProvider> ssl_provider1( |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3912 | new SSLSocketDataProvider(ASYNC, OK)); |
| 3913 | // Expect only HTTP/1.1 protocol in SSLConfig. |
| 3914 | ssl_provider1->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 3915 | // Force HTTP/1.1. |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 3916 | ssl_provider1->next_proto = kProtoHTTP11; |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3917 | helper.AddDataWithSSLSocketDataProvider(&data1, std::move(ssl_provider1)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3918 | |
| 3919 | // A third socket is needed for the tunnelled connection. |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 3920 | std::unique_ptr<SSLSocketDataProvider> ssl_provider2( |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3921 | new SSLSocketDataProvider(ASYNC, OK)); |
| 3922 | helper.session_deps()->socket_factory->AddSSLSocketDataProvider( |
| 3923 | ssl_provider2.get()); |
| 3924 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 3925 | HttpServerProperties* http_server_properties = |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3926 | helper.session()->spdy_session_pool()->http_server_properties(); |
| 3927 | const HostPortPair proxy_host_port_pair = HostPortPair("myproxy", 70); |
| 3928 | EXPECT_FALSE(http_server_properties->RequiresHTTP11(proxy_host_port_pair)); |
| 3929 | |
| 3930 | helper.RunPreTestSetup(); |
| 3931 | helper.StartDefaultTest(); |
| 3932 | helper.FinishDefaultTestWithoutVerification(); |
| 3933 | helper.VerifyDataConsumed(); |
| 3934 | EXPECT_TRUE(http_server_properties->RequiresHTTP11(proxy_host_port_pair)); |
| 3935 | |
| 3936 | const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3937 | ASSERT_TRUE(response); |
| 3938 | ASSERT_TRUE(response->headers); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3939 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 3940 | EXPECT_FALSE(response->was_fetched_via_spdy); |
mmenke | 8210acc | 2016-07-11 16:34:52 | [diff] [blame] | 3941 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1_1, |
| 3942 | response->connection_info); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3943 | EXPECT_FALSE(response->was_npn_negotiated); |
| 3944 | EXPECT_TRUE(request.url.SchemeIs("https")); |
| 3945 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 3946 | EXPECT_EQ(70, response->socket_address.port()); |
| 3947 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3948 | ASSERT_THAT(ReadTransaction(helper.trans(), &response_data), IsOk()); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 3949 | EXPECT_EQ("hello", response_data); |
| 3950 | } |
| 3951 | |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 3952 | // Test to make sure we can correctly connect through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3953 | TEST_F(SpdyNetworkTransactionTest, ProxyConnect) { |
| 3954 | auto session_deps = base::MakeUnique<SpdySessionDependencies>( |
| 3955 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3956 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3957 | BoundNetLog(), std::move(session_deps)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 3958 | helper.RunPreTestSetup(); |
| 3959 | HttpNetworkTransaction* trans = helper.trans(); |
| 3960 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 3961 | const char kConnect443[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3962 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3963 | "Host: www.example.org:443\r\n" |
rch | cb934f56 | 2015-04-07 16:25:12 | [diff] [blame] | 3964 | "Proxy-Connection: keep-alive\r\n\r\n"}; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 3965 | const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3966 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 3967 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3968 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3969 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 3970 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 3971 | MockWrite writes[] = { |
| 3972 | MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3973 | CreateMockWrite(req, 2), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 3974 | }; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 3975 | MockRead reads[] = { |
| 3976 | MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 3977 | CreateMockRead(resp, 3), CreateMockRead(body, 4), |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 3978 | MockRead(ASYNC, 0, 0, 5), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 3979 | }; |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 3980 | std::unique_ptr<SequencedSocketData> data(new SequencedSocketData( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 3981 | reads, arraysize(reads), writes, arraysize(writes))); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 3982 | |
| 3983 | helper.AddData(data.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3984 | TestCompletionCallback callback; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 3985 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3986 | int rv = trans->Start( |
| 3987 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3988 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 3989 | |
| 3990 | rv = callback.WaitForResult(); |
| 3991 | EXPECT_EQ(0, rv); |
| 3992 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 3993 | // Verify the response headers. |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 3994 | HttpResponseInfo response = *trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3995 | ASSERT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3996 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 3997 | |
| 3998 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3999 | ASSERT_THAT(ReadTransaction(trans, &response_data), IsOk()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4000 | EXPECT_EQ("hello!", response_data); |
| 4001 | helper.VerifyDataConsumed(); |
| 4002 | } |
| 4003 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4004 | // Test to make sure we can correctly connect through a proxy to |
| 4005 | // www.example.org, if there already exists a direct spdy connection to |
| 4006 | // www.example.org. See https://crbug.com/49874. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4007 | TEST_F(SpdyNetworkTransactionTest, DirectConnectProxyReconnect) { |
[email protected] | 733b7a6d | 2010-08-25 01:38:43 | [diff] [blame] | 4008 | // Use a proxy service which returns a proxy fallback list from DIRECT to |
| 4009 | // myproxy:70. For this test there will be no fallback, so it is equivalent |
| 4010 | // to simply DIRECT. The reason for appending the second proxy is to verify |
| 4011 | // that the session pool key used does is just "DIRECT". |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4012 | auto session_deps = base::MakeUnique<SpdySessionDependencies>( |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4013 | ProxyService::CreateFixedFromPacResult("DIRECT; PROXY myproxy:70")); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4014 | // When setting up the first transaction, we store the SpdySessionPool so that |
| 4015 | // we can use the same pool in the second transaction. |
| 4016 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 4017 | BoundNetLog(), std::move(session_deps)); |
[email protected] | 733b7a6d | 2010-08-25 01:38:43 | [diff] [blame] | 4018 | |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 4019 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4020 | helper.RunPreTestSetup(); |
| 4021 | |
| 4022 | // Construct and send a simple GET request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4023 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4024 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4025 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4026 | CreateMockWrite(req, 0), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4027 | }; |
| 4028 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4029 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4030 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4031 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4032 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4033 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), // Force a pause |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4034 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4035 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4036 | helper.AddData(&data); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4037 | HttpNetworkTransaction* trans = helper.trans(); |
| 4038 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4039 | TestCompletionCallback callback; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4040 | TransactionHelperResult out; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4041 | out.rv = trans->Start( |
| 4042 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4043 | |
| 4044 | EXPECT_EQ(out.rv, ERR_IO_PENDING); |
| 4045 | out.rv = callback.WaitForResult(); |
| 4046 | EXPECT_EQ(out.rv, OK); |
| 4047 | |
| 4048 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4049 | EXPECT_TRUE(response->headers); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4050 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4051 | out.rv = ReadTransaction(trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4052 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4053 | out.status_line = response->headers->GetStatusLine(); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4054 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4055 | EXPECT_EQ("hello!", out.response_data); |
| 4056 | |
| 4057 | // Check that the SpdySession is still in the SpdySessionPool. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4058 | SpdySessionKey session_pool_key_direct(host_port_pair_, ProxyServer::Direct(), |
| 4059 | PRIVACY_MODE_DISABLED); |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 4060 | EXPECT_TRUE(HasSpdySession(spdy_session_pool, session_pool_key_direct)); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 4061 | SpdySessionKey session_pool_key_proxy( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4062 | host_port_pair_, |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 4063 | ProxyServer::FromURI("www.foo.com", ProxyServer::SCHEME_HTTP), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 4064 | PRIVACY_MODE_DISABLED); |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 4065 | EXPECT_FALSE(HasSpdySession(spdy_session_pool, session_pool_key_proxy)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4066 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4067 | // New SpdyTestUtil instance for the session that will be used for the |
| 4068 | // proxy connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4069 | SpdyTestUtil spdy_util_2; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4070 | |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4071 | // Set up data for the proxy connection. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4072 | const char kConnect443[] = { |
| 4073 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4074 | "Host: www.example.org:443\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4075 | "Proxy-Connection: keep-alive\r\n\r\n"}; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4076 | const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4077 | SpdySerializedFrame req2(spdy_util_2.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4078 | GetDefaultUrlWithPath("/foo.dat").c_str(), 1, LOWEST)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4079 | SpdySerializedFrame resp2(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4080 | SpdySerializedFrame body2(spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4081 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4082 | MockWrite writes2[] = { |
| 4083 | MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4084 | CreateMockWrite(req2, 2), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4085 | }; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4086 | MockRead reads2[] = { |
| 4087 | MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4088 | CreateMockRead(resp2, 3), CreateMockRead(body2, 4), |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4089 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4090 | }; |
| 4091 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 4092 | std::unique_ptr<SequencedSocketData> data_proxy(new SequencedSocketData( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4093 | reads2, arraysize(reads2), writes2, arraysize(writes2))); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4094 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4095 | // Create another request to www.example.org, but this time through a proxy. |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4096 | HttpRequestInfo request_proxy; |
| 4097 | request_proxy.method = "GET"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4098 | request_proxy.url = GURL(GetDefaultUrlWithPath("/foo.dat")); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4099 | request_proxy.load_flags = 0; |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4100 | auto session_deps_proxy = base::MakeUnique<SpdySessionDependencies>( |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4101 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4102 | NormalSpdyTransactionHelper helper_proxy(request_proxy, DEFAULT_PRIORITY, |
| 4103 | BoundNetLog(), |
| 4104 | std::move(session_deps_proxy)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4105 | helper_proxy.RunPreTestSetup(); |
| 4106 | helper_proxy.AddData(data_proxy.get()); |
| 4107 | |
| 4108 | HttpNetworkTransaction* trans_proxy = helper_proxy.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4109 | TestCompletionCallback callback_proxy; |
| 4110 | int rv = trans_proxy->Start( |
| 4111 | &request_proxy, callback_proxy.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4112 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4113 | rv = callback_proxy.WaitForResult(); |
| 4114 | EXPECT_EQ(0, rv); |
| 4115 | |
| 4116 | HttpResponseInfo response_proxy = *trans_proxy->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4117 | ASSERT_TRUE(response_proxy.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4118 | EXPECT_EQ("HTTP/1.1 200", response_proxy.headers->GetStatusLine()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4119 | |
| 4120 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4121 | ASSERT_THAT(ReadTransaction(trans_proxy, &response_data), IsOk()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4122 | EXPECT_EQ("hello!", response_data); |
| 4123 | |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4124 | helper_proxy.VerifyDataConsumed(); |
| 4125 | } |
| 4126 | |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4127 | // When we get a TCP-level RST, we need to retry a HttpNetworkTransaction |
| 4128 | // on a new connection, if the connection was previously known to be good. |
| 4129 | // This can happen when a server reboots without saying goodbye, or when |
| 4130 | // we're behind a NAT that masked the RST. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4131 | TEST_F(SpdyNetworkTransactionTest, VerifyRetryOnConnectionReset) { |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4132 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4133 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4134 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4135 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4136 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 4137 | MockRead(ASYNC, ERR_CONNECTION_RESET, 4), |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4138 | }; |
| 4139 | |
| 4140 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4141 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4142 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4143 | }; |
| 4144 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4145 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4146 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4147 | // In all cases the connection will be reset before req3 can be |
| 4148 | // dispatched, destroying both streams. |
| 4149 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4150 | SpdySerializedFrame req3( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4151 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4152 | MockWrite writes1[] = {CreateMockWrite(req, 0), CreateMockWrite(req3, 5)}; |
| 4153 | MockWrite writes2[] = {CreateMockWrite(req, 0)}; |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4154 | |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4155 | // This test has a couple of variants. |
| 4156 | enum { |
| 4157 | // Induce the RST while waiting for our transaction to send. |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4158 | VARIANT_RST_DURING_SEND_COMPLETION = 0, |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4159 | // Induce the RST while waiting for our transaction to read. |
| 4160 | // In this case, the send completed - everything copied into the SNDBUF. |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4161 | VARIANT_RST_DURING_READ_COMPLETION = 1 |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4162 | }; |
| 4163 | |
| 4164 | for (int variant = VARIANT_RST_DURING_SEND_COMPLETION; |
| 4165 | variant <= VARIANT_RST_DURING_READ_COMPLETION; |
| 4166 | ++variant) { |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4167 | SequencedSocketData data1(reads, arraysize(reads), writes1, 1 + variant); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4168 | |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4169 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 4170 | arraysize(writes2)); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4171 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4172 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4173 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4174 | helper.AddData(&data1); |
| 4175 | helper.AddData(&data2); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4176 | helper.RunPreTestSetup(); |
| 4177 | |
| 4178 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 4179 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, helper.session()); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4180 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4181 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 4182 | int rv = |
| 4183 | trans.Start(&helper.request(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4184 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4185 | // On the second transaction, we trigger the RST. |
| 4186 | if (i == 1) { |
| 4187 | if (variant == VARIANT_RST_DURING_READ_COMPLETION) { |
| 4188 | // Writes to the socket complete asynchronously on SPDY by running |
| 4189 | // through the message loop. Complete the write here. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4190 | base::RunLoop().RunUntilIdle(); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4191 | } |
| 4192 | |
| 4193 | // Now schedule the ERR_CONNECTION_RESET. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 4194 | data1.Resume(); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4195 | } |
| 4196 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4197 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4198 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 4199 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4200 | ASSERT_TRUE(response); |
| 4201 | EXPECT_TRUE(response->headers); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4202 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4203 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 4204 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4205 | EXPECT_THAT(rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4206 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4207 | EXPECT_EQ("hello!", response_data); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4208 | base::RunLoop().RunUntilIdle(); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4209 | } |
| 4210 | |
| 4211 | helper.VerifyDataConsumed(); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4212 | base::RunLoop().RunUntilIdle(); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4213 | } |
| 4214 | } |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4215 | |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4216 | // Tests that Basic authentication works over SPDY |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4217 | TEST_F(SpdyNetworkTransactionTest, SpdyBasicAuth) { |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4218 | // The first request will be a bare GET, the second request will be a |
| 4219 | // GET with an Authorization header. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4220 | SpdySerializedFrame req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4221 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4222 | // Will be refused for lack of auth. |
| 4223 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4224 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4225 | "authorization", "Basic Zm9vOmJhcg==" |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4226 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4227 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 4228 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 4229 | LOWEST, true)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4230 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4231 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4232 | }; |
| 4233 | |
| 4234 | // The first response is a 401 authentication challenge, and the second |
| 4235 | // response will be a 200 response since the second request includes a valid |
| 4236 | // Authorization header. |
| 4237 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | fb9e431 | 2012-02-17 06:27:26 | [diff] [blame] | 4238 | "www-authenticate", |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4239 | "Basic realm=\"MyRealm\"" |
| 4240 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4241 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4242 | "401 Authentication Required", kExtraAuthenticationHeaders, |
| 4243 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 4244 | SpdySerializedFrame body_authentication( |
| 4245 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4246 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4247 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4248 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4249 | CreateMockRead(resp_authentication, 1), |
| 4250 | CreateMockRead(body_authentication, 2), |
| 4251 | CreateMockRead(resp_data, 4), |
| 4252 | CreateMockRead(body_data, 5), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4253 | MockRead(ASYNC, 0, 6), |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4254 | }; |
| 4255 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4256 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4257 | arraysize(spdy_writes)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4258 | HttpRequestInfo request(CreateGetRequest()); |
| 4259 | BoundNetLog net_log; |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4260 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, net_log, NULL); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4261 | |
| 4262 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4263 | helper.AddData(&data); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4264 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4265 | TestCompletionCallback callback; |
| 4266 | const int rv_start = trans->Start(&request, callback.callback(), net_log); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4267 | EXPECT_THAT(rv_start, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4268 | const int rv_start_complete = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4269 | EXPECT_THAT(rv_start_complete, IsOk()); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4270 | |
| 4271 | // Make sure the response has an auth challenge. |
| 4272 | const HttpResponseInfo* const response_start = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4273 | ASSERT_TRUE(response_start); |
| 4274 | ASSERT_TRUE(response_start->headers); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4275 | EXPECT_EQ(401, response_start->headers->response_code()); |
| 4276 | EXPECT_TRUE(response_start->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4277 | AuthChallengeInfo* auth_challenge = response_start->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4278 | ASSERT_TRUE(auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4279 | EXPECT_FALSE(auth_challenge->is_proxy); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 4280 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4281 | EXPECT_EQ("MyRealm", auth_challenge->realm); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4282 | |
| 4283 | // Restart with a username/password. |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 4284 | AuthCredentials credentials(base::ASCIIToUTF16("foo"), |
| 4285 | base::ASCIIToUTF16("bar")); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4286 | TestCompletionCallback callback_restart; |
| 4287 | const int rv_restart = trans->RestartWithAuth( |
| 4288 | credentials, callback_restart.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4289 | EXPECT_THAT(rv_restart, IsError(ERR_IO_PENDING)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4290 | const int rv_restart_complete = callback_restart.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4291 | EXPECT_THAT(rv_restart_complete, IsOk()); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4292 | // TODO(cbentzel): This is actually the same response object as before, but |
| 4293 | // data has changed. |
| 4294 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4295 | ASSERT_TRUE(response_restart); |
| 4296 | ASSERT_TRUE(response_restart->headers); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4297 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4298 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 4299 | } |
| 4300 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4301 | TEST_F(SpdyNetworkTransactionTest, ServerPushWithHeaders) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4302 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4303 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4304 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4305 | CreateMockWrite(stream1_syn, 0), |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4306 | }; |
| 4307 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4308 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4309 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4310 | |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 4311 | SpdyHeaderBlock initial_headers; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4312 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 4313 | &initial_headers); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4314 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame( |
| 4315 | std::move(initial_headers), 2, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4316 | |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4317 | SpdyHeaderBlock late_headers; |
| 4318 | late_headers[spdy_util_.GetStatusKey()] = "200"; |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4319 | late_headers["hello"] = "bye"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4320 | SpdySerializedFrame stream2_headers(spdy_util_.ConstructSpdyResponseHeaders( |
| 4321 | 2, std::move(late_headers), false)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4322 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4323 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4324 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 4325 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4326 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 4327 | 2, kPushedData, strlen(kPushedData), true)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4328 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4329 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4330 | CreateMockRead(stream1_reply, 1), |
| 4331 | CreateMockRead(stream2_syn, 2), |
| 4332 | CreateMockRead(stream2_headers, 3), |
| 4333 | CreateMockRead(stream1_body, 4, SYNCHRONOUS), |
| 4334 | CreateMockRead(stream2_body, 5), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4335 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a pause |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4336 | }; |
| 4337 | |
| 4338 | HttpResponseInfo response; |
| 4339 | HttpResponseInfo response2; |
| 4340 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4341 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4342 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4343 | &response, |
| 4344 | &response2, |
| 4345 | expected_push_result); |
| 4346 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4347 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4348 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4349 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4350 | |
| 4351 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4352 | EXPECT_TRUE(response2.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4353 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4354 | } |
| 4355 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4356 | TEST_F(SpdyNetworkTransactionTest, ServerPushClaimBeforeHeaders) { |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4357 | // We push a stream and attempt to claim it before the headers come down. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4358 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4359 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4360 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4361 | CreateMockWrite(stream1_syn, 0, SYNCHRONOUS), |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4362 | }; |
| 4363 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4364 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4365 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 4366 | SpdyHeaderBlock initial_headers; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4367 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 4368 | &initial_headers); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4369 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame( |
| 4370 | std::move(initial_headers), 2, 1)); |
| 4371 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4372 | SpdyHeaderBlock late_headers; |
| 4373 | late_headers[spdy_util_.GetStatusKey()] = "200"; |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4374 | late_headers["hello"] = "bye"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4375 | SpdySerializedFrame stream2_headers(spdy_util_.ConstructSpdyResponseHeaders( |
| 4376 | 2, std::move(late_headers), false)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 4377 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4378 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 4379 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4380 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4381 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2), |
| 4382 | CreateMockRead(stream1_body, 3), MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 4383 | CreateMockRead(stream2_headers, 5), CreateMockRead(stream2_body, 6), |
| 4384 | MockRead(ASYNC, ERR_IO_PENDING, 7), MockRead(ASYNC, 0, 8), // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4385 | }; |
| 4386 | |
| 4387 | HttpResponseInfo response; |
| 4388 | HttpResponseInfo response2; |
| 4389 | std::string expected_push_result("pushed"); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4390 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4391 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4392 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4393 | BoundNetLog(), NULL); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4394 | helper.AddData(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4395 | helper.RunPreTestSetup(); |
| 4396 | |
| 4397 | HttpNetworkTransaction* trans = helper.trans(); |
| 4398 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4399 | // Start the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4400 | TestCompletionCallback callback; |
| 4401 | int rv = trans->Start( |
| 4402 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4403 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4404 | // Run until we've received the primary HEADERS, the pushed HEADERS, |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4405 | // and the body of the primary stream, but before we've received the HEADERS |
| 4406 | // for the pushed stream. |
| 4407 | data.RunUntilPaused(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4408 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4409 | |
| 4410 | // Request the pushed path. At this point, we've received the push, but the |
| 4411 | // headers are not yet complete. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 4412 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
| 4413 | rv = |
| 4414 | trans2.Start(&CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4415 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4416 | data.Resume(); |
| 4417 | data.RunUntilPaused(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4418 | base::RunLoop().RunUntilIdle(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4419 | |
| 4420 | // Read the server push body. |
| 4421 | std::string result2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 4422 | ReadResult(&trans2, &result2); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4423 | // Read the response body. |
| 4424 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 4425 | ReadResult(trans, &result); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4426 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4427 | // Verify that the received push data is same as the expected push data. |
| 4428 | EXPECT_EQ(result2.compare(expected_push_result), 0) |
| 4429 | << "Received data: " |
| 4430 | << result2 |
| 4431 | << "||||| Expected data: " |
| 4432 | << expected_push_result; |
| 4433 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4434 | // Verify the response headers. |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4435 | // Copy the response info, because trans goes away. |
| 4436 | response = *trans->GetResponseInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 4437 | response2 = *trans2.GetResponseInfo(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4438 | |
| 4439 | VerifyStreamsClosed(helper); |
| 4440 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4441 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4442 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4443 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4444 | |
| 4445 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4446 | EXPECT_TRUE(response2.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4447 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 4448 | |
| 4449 | // Read the final EOF (which will close the session) |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4450 | data.Resume(); |
| 4451 | base::RunLoop().RunUntilIdle(); |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 4452 | |
| 4453 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 4454 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 4455 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4456 | } |
| 4457 | |
[email protected] | 6cd63ba | 2014-06-12 16:14:56 | [diff] [blame] | 4458 | // TODO(baranovich): HTTP 2 does not allow multiple HEADERS frames |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4459 | TEST_F(SpdyNetworkTransactionTest, ServerPushWithTwoHeaderFrames) { |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4460 | // We push a stream and attempt to claim it before the headers come down. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4461 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4462 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4463 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4464 | CreateMockWrite(stream1_syn, 0, SYNCHRONOUS), |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4465 | }; |
| 4466 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4467 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4468 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4469 | |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 4470 | SpdyHeaderBlock initial_headers; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4471 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 4472 | &initial_headers); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4473 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame( |
| 4474 | std::move(initial_headers), 2, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4475 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4476 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4477 | |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4478 | SpdyHeaderBlock middle_headers; |
| 4479 | middle_headers["hello"] = "bye"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4480 | SpdySerializedFrame stream2_headers1(spdy_util_.ConstructSpdyResponseHeaders( |
| 4481 | 2, std::move(middle_headers), false)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4482 | |
| 4483 | SpdyHeaderBlock late_headers; |
| 4484 | late_headers[spdy_util_.GetStatusKey()] = "200"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4485 | SpdySerializedFrame stream2_headers2(spdy_util_.ConstructSpdyResponseHeaders( |
| 4486 | 2, std::move(late_headers), false)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4487 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 4488 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4489 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 4490 | 2, kPushedData, strlen(kPushedData), true)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4491 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4492 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4493 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2), |
| 4494 | CreateMockRead(stream1_body, 3), MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 4495 | CreateMockRead(stream2_headers1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4496 | // This is needed to work around https://crbug.com/571102. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4497 | MockRead(ASYNC, ERR_IO_PENDING, 6), CreateMockRead(stream2_headers2, 7), |
| 4498 | CreateMockRead(stream2_body, 8), MockRead(ASYNC, ERR_IO_PENDING, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4499 | MockRead(ASYNC, 0, 10), // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4500 | }; |
| 4501 | |
| 4502 | HttpResponseInfo response; |
| 4503 | HttpResponseInfo response2; |
| 4504 | std::string expected_push_result("pushed"); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4505 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4506 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4507 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4508 | BoundNetLog(), NULL); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4509 | helper.AddData(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4510 | helper.RunPreTestSetup(); |
| 4511 | |
| 4512 | HttpNetworkTransaction* trans = helper.trans(); |
| 4513 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4514 | // Start the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4515 | TestCompletionCallback callback; |
| 4516 | int rv = trans->Start( |
| 4517 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4518 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4519 | // Run until we've received the primary HEADERS, the pushed HEADERS, |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4520 | // the first HEADERS frame, and the body of the primary stream, but before |
| 4521 | // we've received the final HEADERS for the pushed stream. |
| 4522 | data.RunUntilPaused(); |
| 4523 | EXPECT_EQ(0, callback.WaitForResult()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4524 | |
| 4525 | // Request the pushed path. At this point, we've received the push, but the |
| 4526 | // headers are not yet complete. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 4527 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
| 4528 | rv = |
| 4529 | trans2.Start(&CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4530 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4531 | data.Resume(); |
| 4532 | data.RunUntilPaused(); |
| 4533 | base::RunLoop().RunUntilIdle(); |
| 4534 | // This is needed to work around https://crbug.com/571102. |
| 4535 | data.Resume(); |
| 4536 | data.RunUntilPaused(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4537 | base::RunLoop().RunUntilIdle(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4538 | |
| 4539 | // Read the server push body. |
| 4540 | std::string result2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 4541 | ReadResult(&trans2, &result2); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4542 | // Read the response body. |
| 4543 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 4544 | ReadResult(trans, &result); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4545 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4546 | // Verify that the received push data is same as the expected push data. |
[email protected] | 6d116e1a | 2013-06-24 07:42:15 | [diff] [blame] | 4547 | EXPECT_EQ(expected_push_result, result2); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4548 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4549 | // Verify the response headers. |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4550 | // Copy the response info, because trans goes away. |
| 4551 | response = *trans->GetResponseInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 4552 | response2 = *trans2.GetResponseInfo(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4553 | |
| 4554 | VerifyStreamsClosed(helper); |
| 4555 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4556 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4557 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4558 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4559 | |
| 4560 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4561 | EXPECT_TRUE(response2.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4562 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4563 | |
[email protected] | 6cd63ba | 2014-06-12 16:14:56 | [diff] [blame] | 4564 | // Verify we got all the headers from all header blocks. |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4565 | EXPECT_TRUE(response2.headers->HasHeaderValue("hello", "bye")); |
| 4566 | EXPECT_TRUE(response2.headers->HasHeaderValue("status", "200")); |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 4567 | |
| 4568 | // Read the final EOF (which will close the session) |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4569 | data.Resume(); |
| 4570 | base::RunLoop().RunUntilIdle(); |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 4571 | |
| 4572 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 4573 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 4574 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4575 | } |
| 4576 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4577 | TEST_F(SpdyNetworkTransactionTest, ServerPushWithNoStatusHeaderFrames) { |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4578 | // We push a stream and attempt to claim it before the headers come down. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4579 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4580 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4581 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4582 | CreateMockWrite(stream1_syn, 0, SYNCHRONOUS), |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4583 | }; |
| 4584 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4585 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4586 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4587 | |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 4588 | SpdyHeaderBlock initial_headers; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4589 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 4590 | &initial_headers); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4591 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame( |
| 4592 | std::move(initial_headers), 2, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4593 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4594 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4595 | |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4596 | SpdyHeaderBlock middle_headers; |
| 4597 | middle_headers["hello"] = "bye"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4598 | SpdySerializedFrame stream2_headers1(spdy_util_.ConstructSpdyResponseHeaders( |
| 4599 | 2, std::move(middle_headers), false)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4600 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 4601 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4602 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 4603 | 2, kPushedData, strlen(kPushedData), true)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4604 | |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4605 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4606 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream2_syn, 2), |
| 4607 | CreateMockRead(stream1_body, 3), MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 4608 | CreateMockRead(stream2_headers1, 5), CreateMockRead(stream2_body, 6), |
| 4609 | MockRead(ASYNC, ERR_IO_PENDING, 7), MockRead(ASYNC, 0, 8), // EOF |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4610 | }; |
| 4611 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4612 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4613 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4614 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4615 | BoundNetLog(), NULL); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4616 | helper.AddData(&data); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4617 | helper.RunPreTestSetup(); |
| 4618 | |
| 4619 | HttpNetworkTransaction* trans = helper.trans(); |
| 4620 | |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4621 | // Start the transaction. |
| 4622 | TestCompletionCallback callback; |
| 4623 | int rv = trans->Start( |
| 4624 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4625 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4626 | // Run until we've received the primary HEADERS, the pushed HEADERS, |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4627 | // the first HEADERS frame, and the body of the primary stream, but before |
| 4628 | // we've received the final HEADERS for the pushed stream. |
| 4629 | data.RunUntilPaused(); |
| 4630 | EXPECT_EQ(0, callback.WaitForResult()); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4631 | |
| 4632 | // Request the pushed path. At this point, we've received the push, but the |
| 4633 | // headers are not yet complete. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 4634 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
| 4635 | rv = |
| 4636 | trans2.Start(&CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4637 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4638 | data.Resume(); |
| 4639 | data.RunUntilPaused(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4640 | base::RunLoop().RunUntilIdle(); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4641 | |
| 4642 | // Read the server push body. |
| 4643 | std::string result2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 4644 | ReadResult(&trans2, &result2); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4645 | // Read the response body. |
| 4646 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 4647 | ReadResult(trans, &result); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4648 | EXPECT_EQ("hello!", result); |
| 4649 | |
| 4650 | // Verify that we haven't received any push data. |
| 4651 | EXPECT_EQ("", result2); |
| 4652 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4653 | // Verify the response headers. |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4654 | // Copy the response info, because trans goes away. |
| 4655 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4656 | |
| 4657 | VerifyStreamsClosed(helper); |
| 4658 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4659 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4660 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4661 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4662 | |
| 4663 | // Read the final EOF (which will close the session). |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 4664 | data.Resume(); |
| 4665 | base::RunLoop().RunUntilIdle(); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4666 | |
| 4667 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 4668 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 4669 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 4670 | } |
| 4671 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4672 | TEST_F(SpdyNetworkTransactionTest, ResponseHeadersTwice) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4673 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4674 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4675 | SpdySerializedFrame rst( |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 4676 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 4677 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4678 | CreateMockWrite(req, 0), CreateMockWrite(rst, 4), |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4679 | }; |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4680 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4681 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4682 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4683 | |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4684 | SpdyHeaderBlock late_headers; |
| 4685 | late_headers["hello"] = "bye"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4686 | SpdySerializedFrame stream1_headers(spdy_util_.ConstructSpdyResponseHeaders( |
| 4687 | 1, std::move(late_headers), false)); |
| 4688 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4689 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4690 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream1_headers, 2), |
| 4691 | CreateMockRead(stream1_body, 3), MockRead(ASYNC, 0, 5) // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4692 | }; |
| 4693 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4694 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4695 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4696 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4697 | helper.RunToCompletion(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4698 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4699 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4700 | } |
| 4701 | |
xunjieli | 294da72 | 2015-08-11 19:15:02 | [diff] [blame] | 4702 | // Tests that receiving HEADERS, DATA, HEADERS, and DATA in that sequence will |
| 4703 | // trigger a ERR_SPDY_PROTOCOL_ERROR because trailing HEADERS must not be |
| 4704 | // followed by any DATA frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4705 | TEST_F(SpdyNetworkTransactionTest, SyncReplyDataAfterTrailers) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4706 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4707 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4708 | SpdySerializedFrame rst( |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 4709 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 4710 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4711 | CreateMockWrite(req, 0), CreateMockWrite(rst, 5), |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 4712 | }; |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4713 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4714 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4715 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4716 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, false)); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4717 | |
| 4718 | SpdyHeaderBlock late_headers; |
| 4719 | late_headers["hello"] = "bye"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4720 | SpdySerializedFrame stream1_headers(spdy_util_.ConstructSpdyResponseHeaders( |
| 4721 | 1, std::move(late_headers), false)); |
| 4722 | SpdySerializedFrame stream1_body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4723 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4724 | CreateMockRead(stream1_reply, 1), CreateMockRead(stream1_body, 2), |
| 4725 | CreateMockRead(stream1_headers, 3), CreateMockRead(stream1_body2, 4), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4726 | MockRead(ASYNC, 0, 6) // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4727 | }; |
| 4728 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4729 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4730 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4731 | BoundNetLog(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4732 | helper.RunToCompletion(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4733 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4734 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4735 | } |
| 4736 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4737 | TEST_F(SpdyNetworkTransactionTest, ServerPushCrossOriginCorrectness) { |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4738 | // In this test we want to verify that we can't accidentally push content |
| 4739 | // which can't be pushed by this content server. |
| 4740 | // This test assumes that: |
| 4741 | // - if we're requesting http://www.foo.com/barbaz |
| 4742 | // - the browser has made a connection to "www.foo.com". |
| 4743 | |
| 4744 | // A list of the URL to fetch, followed by the URL being pushed. |
| 4745 | static const char* const kTestCases[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4746 | "https://www.example.org/foo.html", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4747 | "http://www.example.org/foo.js", // Bad protocol |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4748 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4749 | "https://www.example.org/foo.html", |
| 4750 | "ftp://www.example.org/foo.js", // Invalid Protocol |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4751 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4752 | "https://www.example.org/foo.html", |
| 4753 | "https://blat.www.example.org/foo.js", // Cross subdomain |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4754 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4755 | "https://www.example.org/foo.html", |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4756 | "https://www.foo.com/foo.js", // Cross domain |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4757 | }; |
| 4758 | |
[email protected] | b3f89933 | 2010-12-08 18:20:44 | [diff] [blame] | 4759 | for (size_t index = 0; index < arraysize(kTestCases); index += 2) { |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4760 | const char* url_to_fetch = kTestCases[index]; |
| 4761 | const char* url_to_push = kTestCases[index + 1]; |
| 4762 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4763 | SpdyTestUtil spdy_test_util; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4764 | SpdySerializedFrame stream1_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4765 | spdy_test_util.ConstructSpdyGet(url_to_fetch, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4766 | SpdySerializedFrame stream1_body( |
| 4767 | spdy_test_util.ConstructSpdyDataFrame(1, true)); |
| 4768 | SpdySerializedFrame push_rst( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4769 | spdy_test_util.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4770 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4771 | CreateMockWrite(stream1_syn, 0), CreateMockWrite(push_rst, 3), |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4772 | }; |
| 4773 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4774 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4775 | spdy_test_util.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4776 | SpdySerializedFrame stream2_syn( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4777 | spdy_test_util.ConstructSpdyPush(nullptr, 0, 2, 1, url_to_push)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 4778 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4779 | SpdySerializedFrame stream2_body(spdy_test_util.ConstructSpdyDataFrame( |
| 4780 | 2, kPushedData, strlen(kPushedData), true)); |
| 4781 | SpdySerializedFrame rst( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4782 | spdy_test_util.ConstructSpdyRstStream(2, RST_STREAM_CANCEL)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4783 | |
| 4784 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4785 | CreateMockRead(stream1_reply, 1), |
| 4786 | CreateMockRead(stream2_syn, 2), |
| 4787 | CreateMockRead(stream1_body, 4), |
| 4788 | CreateMockRead(stream2_body, 5), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4789 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a pause |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4790 | }; |
| 4791 | |
| 4792 | HttpResponseInfo response; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4793 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 4794 | arraysize(writes)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4795 | |
| 4796 | HttpRequestInfo request; |
| 4797 | request.method = "GET"; |
| 4798 | request.url = GURL(url_to_fetch); |
| 4799 | request.load_flags = 0; |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4800 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 4801 | // Enable cross-origin push. Since we are not using a proxy, this should |
| 4802 | // not actually enable cross-origin SPDY push. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4803 | auto session_deps = base::MakeUnique<SpdySessionDependencies>(); |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 4804 | std::unique_ptr<TestProxyDelegate> proxy_delegate(new TestProxyDelegate()); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 4805 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 4806 | "https://123.45.67.89:443", net::ProxyServer::SCHEME_HTTP)); |
| 4807 | session_deps->proxy_delegate.reset(proxy_delegate.release()); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4808 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4809 | std::move(session_deps)); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4810 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4811 | helper.AddData(&data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 4812 | |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4813 | HttpNetworkTransaction* trans = helper.trans(); |
| 4814 | |
| 4815 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4816 | TestCompletionCallback callback; |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4817 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4818 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4819 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4820 | rv = callback.WaitForResult(); |
| 4821 | |
| 4822 | // Read the response body. |
| 4823 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 4824 | ReadResult(trans, &result); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4825 | |
| 4826 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 4827 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 4828 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4829 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4830 | // Verify the response headers. |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4831 | // Copy the response info, because trans goes away. |
| 4832 | response = *trans->GetResponseInfo(); |
| 4833 | |
| 4834 | VerifyStreamsClosed(helper); |
| 4835 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4836 | // Verify the response headers. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4837 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4838 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 4839 | } |
| 4840 | } |
| 4841 | |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4842 | // Verify that push works cross origin as long as the certificate is valid for |
| 4843 | // the pushed authority. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4844 | TEST_F(SpdyNetworkTransactionTest, ServerPushValidCrossOrigin) { |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4845 | // "spdy_pooling.pem" is valid for both www.example.org and mail.example.org. |
| 4846 | const char* url_to_fetch = "https://www.example.org"; |
| 4847 | const char* url_to_push = "https://mail.example.org"; |
| 4848 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4849 | SpdySerializedFrame headers( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4850 | spdy_util_.ConstructSpdyGet(url_to_fetch, 1, LOWEST)); |
| 4851 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4852 | CreateMockWrite(headers, 0), |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4853 | }; |
| 4854 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4855 | SpdySerializedFrame reply(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4856 | SpdySerializedFrame push( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4857 | spdy_util_.ConstructSpdyPush(nullptr, 0, 2, 1, url_to_push)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4858 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4859 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4860 | SpdySerializedFrame pushed_body(spdy_util_.ConstructSpdyDataFrame( |
| 4861 | 2, kPushedData, strlen(kPushedData), true)); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4862 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4863 | CreateMockRead(reply, 1), |
| 4864 | CreateMockRead(push, 2), |
| 4865 | CreateMockRead(body, 3), |
| 4866 | CreateMockRead(pushed_body, 4), |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4867 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
| 4868 | }; |
| 4869 | |
| 4870 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 4871 | |
| 4872 | HttpRequestInfo request; |
| 4873 | request.method = "GET"; |
| 4874 | request.url = GURL(url_to_fetch); |
| 4875 | request.load_flags = 0; |
| 4876 | |
| 4877 | BoundNetLog log; |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4878 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, log, nullptr); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4879 | helper.RunPreTestSetup(); |
| 4880 | helper.AddData(&data); |
| 4881 | |
| 4882 | HttpNetworkTransaction* trans0 = helper.trans(); |
| 4883 | TestCompletionCallback callback0; |
| 4884 | int rv = trans0->Start(&request, callback0.callback(), log); |
| 4885 | rv = callback0.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4886 | EXPECT_THAT(rv, IsOk()); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4887 | |
| 4888 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4889 | SpdySessionKey key(host_port_pair_, ProxyServer::Direct(), |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4890 | PRIVACY_MODE_DISABLED); |
| 4891 | base::WeakPtr<SpdySession> spdy_session = |
| 4892 | spdy_session_pool->FindAvailableSession(key, GURL(), log); |
| 4893 | |
| 4894 | EXPECT_FALSE(spdy_session->unclaimed_pushed_streams_.empty()); |
| 4895 | EXPECT_EQ(1u, spdy_session->unclaimed_pushed_streams_.size()); |
| 4896 | EXPECT_EQ(1u, |
| 4897 | spdy_session->unclaimed_pushed_streams_.count(GURL(url_to_push))); |
| 4898 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 4899 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session()); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4900 | HttpRequestInfo push_request; |
| 4901 | push_request.method = "GET"; |
| 4902 | push_request.url = GURL(url_to_push); |
| 4903 | push_request.load_flags = 0; |
| 4904 | TestCompletionCallback callback1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 4905 | rv = trans1.Start(&push_request, callback1.callback(), log); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4906 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4907 | EXPECT_THAT(rv, IsOk()); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4908 | |
| 4909 | EXPECT_TRUE(spdy_session->unclaimed_pushed_streams_.empty()); |
| 4910 | EXPECT_EQ(0u, spdy_session->unclaimed_pushed_streams_.size()); |
| 4911 | |
| 4912 | helper.VerifyDataConsumed(); |
| 4913 | VerifyStreamsClosed(helper); |
| 4914 | |
| 4915 | HttpResponseInfo response = *trans0->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4916 | EXPECT_TRUE(response.headers); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4917 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
| 4918 | |
| 4919 | std::string result0; |
| 4920 | ReadResult(trans0, &result0); |
| 4921 | EXPECT_EQ("hello!", result0); |
| 4922 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 4923 | HttpResponseInfo push_response = *trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4924 | EXPECT_TRUE(push_response.headers); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4925 | EXPECT_EQ("HTTP/1.1 200", push_response.headers->GetStatusLine()); |
| 4926 | |
| 4927 | std::string result1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 4928 | ReadResult(&trans1, &result1); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4929 | EXPECT_EQ(kPushedData, result1); |
| 4930 | } |
| 4931 | |
| 4932 | // Verify that push works cross origin, even if there is already a connection |
| 4933 | // open to origin of pushed resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4934 | TEST_F(SpdyNetworkTransactionTest, ServerPushValidCrossOriginWithOpenSession) { |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4935 | const char* url_to_fetch0 = "https://mail.example.org/foo"; |
| 4936 | const char* url_to_fetch1 = "https://docs.example.org"; |
| 4937 | const char* url_to_push = "https://mail.example.org/bar"; |
| 4938 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4939 | SpdyTestUtil spdy_util_0; |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4940 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4941 | SpdySerializedFrame headers0( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4942 | spdy_util_0.ConstructSpdyGet(url_to_fetch0, 1, LOWEST)); |
| 4943 | MockWrite writes0[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4944 | CreateMockWrite(headers0, 0), |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4945 | }; |
| 4946 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4947 | SpdySerializedFrame reply0(spdy_util_0.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4948 | const char kData0[] = "first"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4949 | SpdySerializedFrame body0( |
| 4950 | spdy_util_0.ConstructSpdyDataFrame(1, kData0, strlen(kData0), true)); |
| 4951 | MockRead reads0[] = {CreateMockRead(reply0, 1), CreateMockRead(body0, 2), |
| 4952 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4953 | |
| 4954 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 4955 | arraysize(writes0)); |
| 4956 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4957 | SpdyTestUtil spdy_util_1; |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4958 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4959 | SpdySerializedFrame headers1( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4960 | spdy_util_1.ConstructSpdyGet(url_to_fetch1, 1, LOWEST)); |
| 4961 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4962 | CreateMockWrite(headers1, 0), |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4963 | }; |
| 4964 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4965 | SpdySerializedFrame reply1(spdy_util_1.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4966 | SpdySerializedFrame push( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4967 | spdy_util_1.ConstructSpdyPush(nullptr, 0, 2, 1, url_to_push)); |
| 4968 | const char kData1[] = "second"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4969 | SpdySerializedFrame body1( |
| 4970 | spdy_util_1.ConstructSpdyDataFrame(1, kData1, strlen(kData1), true)); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4971 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4972 | SpdySerializedFrame pushed_body(spdy_util_1.ConstructSpdyDataFrame( |
| 4973 | 2, kPushedData, strlen(kPushedData), true)); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4974 | |
| 4975 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4976 | CreateMockRead(reply1, 1), |
| 4977 | CreateMockRead(push, 2), |
| 4978 | CreateMockRead(body1, 3), |
| 4979 | CreateMockRead(pushed_body, 4), |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4980 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
| 4981 | }; |
| 4982 | |
| 4983 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 4984 | arraysize(writes1)); |
| 4985 | |
| 4986 | // Request |url_to_fetch0| to open connection to mail.example.org. |
| 4987 | HttpRequestInfo request0; |
| 4988 | request0.method = "GET"; |
| 4989 | request0.url = GURL(url_to_fetch0); |
| 4990 | request0.load_flags = 0; |
| 4991 | |
| 4992 | BoundNetLog log; |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4993 | NormalSpdyTransactionHelper helper(request0, DEFAULT_PRIORITY, log, nullptr); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4994 | helper.RunPreTestSetup(); |
| 4995 | |
| 4996 | // "spdy_pooling.pem" is valid for www.example.org, but not for |
| 4997 | // docs.example.org. |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 4998 | std::unique_ptr<SSLSocketDataProvider> ssl_provider0( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 4999 | new SSLSocketDataProvider(ASYNC, OK)); |
| 5000 | ssl_provider0->cert = |
| 5001 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 5002 | helper.AddDataWithSSLSocketDataProvider(&data0, std::move(ssl_provider0)); |
| 5003 | |
| 5004 | // "wildcard.pem" is valid for both www.example.org and docs.example.org. |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5005 | std::unique_ptr<SSLSocketDataProvider> ssl_provider1( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5006 | new SSLSocketDataProvider(ASYNC, OK)); |
| 5007 | ssl_provider1->cert = |
| 5008 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 5009 | helper.AddDataWithSSLSocketDataProvider(&data1, std::move(ssl_provider1)); |
| 5010 | |
| 5011 | HttpNetworkTransaction* trans0 = helper.trans(); |
| 5012 | TestCompletionCallback callback0; |
| 5013 | int rv = trans0->Start(&request0, callback0.callback(), log); |
| 5014 | rv = callback0.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5015 | EXPECT_THAT(rv, IsOk()); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5016 | |
| 5017 | // Request |url_to_fetch1|, during which docs.example.org pushes |
| 5018 | // |url_to_push|, which happens to be for www.example.org, to which there is |
| 5019 | // already an open connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 5020 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session()); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5021 | HttpRequestInfo request1; |
| 5022 | request1.method = "GET"; |
| 5023 | request1.url = GURL(url_to_fetch1); |
| 5024 | request1.load_flags = 0; |
| 5025 | TestCompletionCallback callback1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 5026 | rv = trans1.Start(&request1, callback1.callback(), log); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5027 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5028 | EXPECT_THAT(rv, IsOk()); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5029 | |
| 5030 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
| 5031 | HostPortPair host_port_pair0("mail.example.org", 443); |
| 5032 | SpdySessionKey key0(host_port_pair0, ProxyServer::Direct(), |
| 5033 | PRIVACY_MODE_DISABLED); |
| 5034 | base::WeakPtr<SpdySession> spdy_session0 = |
| 5035 | spdy_session_pool->FindAvailableSession(key0, GURL(), log); |
| 5036 | |
| 5037 | EXPECT_TRUE(spdy_session0->unclaimed_pushed_streams_.empty()); |
| 5038 | EXPECT_EQ(0u, spdy_session0->unclaimed_pushed_streams_.size()); |
| 5039 | |
| 5040 | HostPortPair host_port_pair1("docs.example.org", 443); |
| 5041 | SpdySessionKey key1(host_port_pair1, ProxyServer::Direct(), |
| 5042 | PRIVACY_MODE_DISABLED); |
| 5043 | base::WeakPtr<SpdySession> spdy_session1 = |
| 5044 | spdy_session_pool->FindAvailableSession(key1, GURL(), log); |
| 5045 | |
| 5046 | EXPECT_FALSE(spdy_session1->unclaimed_pushed_streams_.empty()); |
| 5047 | EXPECT_EQ(1u, spdy_session1->unclaimed_pushed_streams_.size()); |
| 5048 | EXPECT_EQ(1u, |
| 5049 | spdy_session1->unclaimed_pushed_streams_.count(GURL(url_to_push))); |
| 5050 | |
| 5051 | // Request |url_to_push|, which should be served from the pushed resource. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 5052 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5053 | HttpRequestInfo push_request; |
| 5054 | push_request.method = "GET"; |
| 5055 | push_request.url = GURL(url_to_push); |
| 5056 | push_request.load_flags = 0; |
| 5057 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 5058 | rv = trans2.Start(&push_request, callback2.callback(), log); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5059 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5060 | EXPECT_THAT(rv, IsOk()); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5061 | |
| 5062 | EXPECT_TRUE(spdy_session0->unclaimed_pushed_streams_.empty()); |
| 5063 | EXPECT_EQ(0u, spdy_session0->unclaimed_pushed_streams_.size()); |
| 5064 | |
| 5065 | EXPECT_TRUE(spdy_session1->unclaimed_pushed_streams_.empty()); |
| 5066 | EXPECT_EQ(0u, spdy_session1->unclaimed_pushed_streams_.size()); |
| 5067 | |
| 5068 | helper.VerifyDataConsumed(); |
| 5069 | VerifyStreamsClosed(helper); |
| 5070 | |
| 5071 | HttpResponseInfo response0 = *trans0->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5072 | EXPECT_TRUE(response0.headers); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5073 | EXPECT_EQ("HTTP/1.1 200", response0.headers->GetStatusLine()); |
| 5074 | |
| 5075 | std::string result0; |
| 5076 | ReadResult(trans0, &result0); |
| 5077 | EXPECT_EQ(kData0, result0); |
| 5078 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 5079 | HttpResponseInfo response1 = *trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5080 | EXPECT_TRUE(response1.headers); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5081 | EXPECT_EQ("HTTP/1.1 200", response1.headers->GetStatusLine()); |
| 5082 | |
| 5083 | std::string result1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 5084 | ReadResult(&trans1, &result1); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5085 | EXPECT_EQ(kData1, result1); |
| 5086 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 5087 | HttpResponseInfo push_response = *trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5088 | EXPECT_TRUE(push_response.headers); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5089 | EXPECT_EQ("HTTP/1.1 200", push_response.headers->GetStatusLine()); |
| 5090 | |
| 5091 | std::string result2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 5092 | ReadResult(&trans2, &result2); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5093 | EXPECT_EQ(kPushedData, result2); |
| 5094 | } |
| 5095 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5096 | TEST_F(SpdyNetworkTransactionTest, ServerPushInvalidCrossOrigin) { |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5097 | // "spdy_pooling.pem" is valid for www.example.org, |
| 5098 | // but not for invalid.example.org. |
| 5099 | const char* url_to_fetch = "https://www.example.org"; |
| 5100 | const char* url_to_push = "https://invalid.example.org"; |
| 5101 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5102 | SpdySerializedFrame headers( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5103 | spdy_util_.ConstructSpdyGet(url_to_fetch, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5104 | SpdySerializedFrame rst( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5105 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
| 5106 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5107 | CreateMockWrite(headers, 0), CreateMockWrite(rst, 3), |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5108 | }; |
| 5109 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5110 | SpdySerializedFrame reply(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5111 | SpdySerializedFrame push( |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5112 | spdy_util_.ConstructSpdyPush(nullptr, 0, 2, 1, url_to_push)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5113 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5114 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5115 | SpdySerializedFrame pushed_body(spdy_util_.ConstructSpdyDataFrame( |
| 5116 | 2, kPushedData, strlen(kPushedData), true)); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5117 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5118 | CreateMockRead(reply, 1), |
| 5119 | CreateMockRead(push, 2), |
| 5120 | CreateMockRead(body, 4), |
| 5121 | CreateMockRead(pushed_body, 5), |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5122 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), |
| 5123 | }; |
| 5124 | |
| 5125 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 5126 | |
| 5127 | HttpRequestInfo request; |
| 5128 | request.method = "GET"; |
| 5129 | request.url = GURL(url_to_fetch); |
| 5130 | request.load_flags = 0; |
| 5131 | |
| 5132 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5133 | nullptr); |
bnc | 3e79387f | 2016-03-15 14:49:20 | [diff] [blame] | 5134 | helper.RunToCompletion(&data); |
| 5135 | TransactionHelperResult out = helper.output(); |
| 5136 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
| 5137 | EXPECT_EQ("hello!", out.response_data); |
| 5138 | } |
| 5139 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5140 | TEST_F(SpdyNetworkTransactionTest, RetryAfterRefused) { |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5141 | // Construct the request. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5142 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5143 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5144 | // Will be destroyed by the RST before stream 3 starts. |
| 5145 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5146 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5147 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, LOWEST, true)); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5148 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5149 | CreateMockWrite(req, 0), CreateMockWrite(req2, 2), |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5150 | }; |
| 5151 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5152 | SpdySerializedFrame refused( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5153 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_REFUSED_STREAM)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5154 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5155 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5156 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5157 | CreateMockRead(refused, 1), CreateMockRead(resp, 3), |
| 5158 | CreateMockRead(body, 4), MockRead(ASYNC, 0, 5) // EOF |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5159 | }; |
| 5160 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5161 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5162 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5163 | BoundNetLog(), NULL); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5164 | |
| 5165 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5166 | helper.AddData(&data); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5167 | |
| 5168 | HttpNetworkTransaction* trans = helper.trans(); |
| 5169 | |
| 5170 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5171 | TestCompletionCallback callback; |
| 5172 | int rv = trans->Start( |
| 5173 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5174 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5175 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5176 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5177 | |
| 5178 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5179 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 5180 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5181 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5182 | // Verify the response headers. |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5183 | HttpResponseInfo response = *trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5184 | EXPECT_TRUE(response.headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5185 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5186 | } |
| 5187 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5188 | TEST_F(SpdyNetworkTransactionTest, OutOfOrderHeaders) { |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5189 | // This first request will start to establish the SpdySession. |
| 5190 | // Then we will start the second (MEDIUM priority) and then third |
| 5191 | // (HIGHEST priority) request in such a way that the third will actually |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 5192 | // start before the second, causing the second to be numbered differently |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5193 | // than the order they were created. |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5194 | // |
| 5195 | // Note that the requests and responses created below are expectations |
| 5196 | // of what the above will produce on the wire, and hence are in the |
| 5197 | // initial->HIGHEST->LOWEST priority. |
| 5198 | // |
| 5199 | // Frames are created by SpdySession just before the write associated |
| 5200 | // with the frame is attempted, so stream dependencies will be based |
| 5201 | // on the streams alive at the point of the request write attempt. Thus |
| 5202 | // req1 is alive when req2 is attempted (during but not after the |
| 5203 | // |data.RunFor(2);| statement below) but not when req3 is attempted. |
| 5204 | // The call to spdy_util_.UpdateWithStreamDestruction() reflects this. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5205 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5206 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5207 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5208 | spdy_util_.ConstructSpdyGet(nullptr, 0, 3, HIGHEST, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5209 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5210 | SpdySerializedFrame req3( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5211 | spdy_util_.ConstructSpdyGet(nullptr, 0, 5, MEDIUM, true)); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5212 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5213 | MockWrite(ASYNC, ERR_IO_PENDING, 0), CreateMockWrite(req1, 1), |
| 5214 | CreateMockWrite(req2, 5), CreateMockWrite(req3, 6), |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5215 | }; |
| 5216 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5217 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5218 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5219 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5220 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5221 | SpdySerializedFrame resp3(spdy_util_.ConstructSpdyGetReply(NULL, 0, 5)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5222 | SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame(5, true)); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5223 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5224 | CreateMockRead(resp1, 2), MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 5225 | CreateMockRead(body1, 4), CreateMockRead(resp2, 7), |
| 5226 | CreateMockRead(body2, 8), CreateMockRead(resp3, 9), |
| 5227 | CreateMockRead(body3, 10), MockRead(ASYNC, 0, 11) // EOF |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5228 | }; |
| 5229 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5230 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5231 | NormalSpdyTransactionHelper helper(CreateGetRequest(), LOWEST, BoundNetLog(), |
| 5232 | NULL); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5233 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5234 | helper.AddData(&data); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5235 | |
| 5236 | // Start the first transaction to set up the SpdySession |
| 5237 | HttpNetworkTransaction* trans = helper.trans(); |
| 5238 | TestCompletionCallback callback; |
| 5239 | HttpRequestInfo info1 = CreateGetRequest(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5240 | int rv = trans->Start(&info1, callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5241 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5242 | |
| 5243 | // Run the message loop, but do not allow the write to complete. |
| 5244 | // This leaves the SpdySession with a write pending, which prevents |
| 5245 | // SpdySession from attempting subsequent writes until this write completes. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5246 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5247 | |
| 5248 | // Now, start both new transactions |
| 5249 | HttpRequestInfo info2 = CreateGetRequest(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5250 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 5251 | HttpNetworkTransaction trans2(MEDIUM, helper.session()); |
| 5252 | rv = trans2.Start(&info2, callback2.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5253 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5254 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5255 | |
| 5256 | HttpRequestInfo info3 = CreateGetRequest(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5257 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame^] | 5258 | HttpNetworkTransaction trans3(HIGHEST, helper.session()); |
| 5259 | rv = trans3.Start(&info3, callback3.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5260 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5261 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5262 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5263 | // We now have two HEADERS frames queued up which will be |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5264 | // dequeued only once the first write completes, which we |
| 5265 | // now allow to happen. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5266 | ASSERT_TRUE(data.IsPaused()); |
| 5267 | data.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5268 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5269 | |
| 5270 | // And now we can allow everything else to run to completion. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5271 | data.Resume(); |
| 5272 | base::RunLoop().RunUntilIdle(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5273 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 5274 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5275 | |
| 5276 | helper.VerifyDataConsumed(); |
| 5277 | } |
| 5278 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5279 | // Test that sent data frames and received WINDOW_UPDATE frames change |
| 5280 | // the send_window_size_ correctly. |
| 5281 | |
| 5282 | // WINDOW_UPDATE is different than most other frames in that it can arrive |
| 5283 | // while the client is still sending the request body. In order to enforce |
| 5284 | // this scenario, we feed a couple of dummy frames and give a delay of 0 to |
| 5285 | // socket data provider, so that initial read that is done as soon as the |
| 5286 | // stream is created, succeeds and schedules another read. This way reads |
| 5287 | // and writes are interleaved; after doing a full frame write, SpdyStream |
| 5288 | // will break out of DoLoop and will read and process a WINDOW_UPDATE. |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5289 | // Once our WINDOW_UPDATE is read, we cannot send HEADERS right away |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5290 | // since request has not been completely written, therefore we feed |
| 5291 | // enough number of WINDOW_UPDATEs to finish the first read and cause a |
| 5292 | // write, leading to a complete write of request body; after that we send |
| 5293 | // a reply with a body, to cause a graceful shutdown. |
| 5294 | |
| 5295 | // TODO(agayev): develop a socket data provider where both, reads and |
| 5296 | // writes are ordered so that writing tests like these are easy and rewrite |
| 5297 | // all these tests using it. Right now we are working around the |
| 5298 | // limitations as described above and it's not deterministic, tests may |
| 5299 | // fail under specific circumstances. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5300 | TEST_F(SpdyNetworkTransactionTest, WindowUpdateReceived) { |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5301 | static int kFrameCount = 2; |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5302 | std::unique_ptr<std::string> content( |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5303 | new std::string(kMaxSpdyFrameChunkSize, 'a')); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5304 | SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5305 | kDefaultUrl, 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5306 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 5307 | 1, content->c_str(), content->size(), false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5308 | SpdySerializedFrame body_end(spdy_util_.ConstructSpdyDataFrame( |
| 5309 | 1, content->c_str(), content->size(), true)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5310 | |
| 5311 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5312 | CreateMockWrite(req, 0), CreateMockWrite(body, 1), |
| 5313 | CreateMockWrite(body_end, 2), |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5314 | }; |
| 5315 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5316 | static const int32_t kDeltaWindowSize = 0xff; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5317 | static const int kDeltaCount = 4; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5318 | SpdySerializedFrame window_update( |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5319 | spdy_util_.ConstructSpdyWindowUpdate(1, kDeltaWindowSize)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5320 | SpdySerializedFrame window_update_dummy( |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5321 | spdy_util_.ConstructSpdyWindowUpdate(2, kDeltaWindowSize)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5322 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5323 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5324 | CreateMockRead(window_update_dummy, 3), |
| 5325 | CreateMockRead(window_update_dummy, 4), |
| 5326 | CreateMockRead(window_update_dummy, 5), |
| 5327 | CreateMockRead(window_update, 6), // Four updates, therefore window |
| 5328 | CreateMockRead(window_update, 7), // size should increase by |
| 5329 | CreateMockRead(window_update, 8), // kDeltaWindowSize * 4 |
| 5330 | CreateMockRead(window_update, 9), |
| 5331 | CreateMockRead(resp, 10), |
| 5332 | MockRead(ASYNC, ERR_IO_PENDING, 11), |
| 5333 | CreateMockRead(body_end, 12), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5334 | MockRead(ASYNC, 0, 13) // EOF |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5335 | }; |
| 5336 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5337 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5338 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5339 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5340 | for (int i = 0; i < kFrameCount; ++i) { |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5341 | element_readers.push_back(base::WrapUnique( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5342 | new UploadBytesElementReader(content->c_str(), content->size()))); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5343 | } |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5344 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5345 | |
| 5346 | // Setup the request |
| 5347 | HttpRequestInfo request; |
| 5348 | request.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5349 | request.url = default_url_; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5350 | request.upload_data_stream = &upload_data_stream; |
| 5351 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5352 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 5353 | NULL); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5354 | helper.AddData(&data); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5355 | helper.RunPreTestSetup(); |
| 5356 | |
| 5357 | HttpNetworkTransaction* trans = helper.trans(); |
| 5358 | |
| 5359 | TestCompletionCallback callback; |
| 5360 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 5361 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5362 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5363 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5364 | data.RunUntilPaused(); |
| 5365 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5366 | |
| 5367 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5368 | ASSERT_TRUE(stream); |
| 5369 | ASSERT_TRUE(stream->stream()); |
bnc | bca843ba | 2016-07-14 13:05:48 | [diff] [blame] | 5370 | EXPECT_EQ(static_cast<int>(kDefaultInitialWindowSize) + |
| 5371 | kDeltaWindowSize * kDeltaCount - |
| 5372 | kMaxSpdyFrameChunkSize * kFrameCount, |
| 5373 | stream->stream()->send_window_size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5374 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5375 | data.Resume(); |
| 5376 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5377 | |
| 5378 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5379 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5380 | |
| 5381 | helper.VerifyDataConsumed(); |
| 5382 | } |
| 5383 | |
| 5384 | // Test that received data frames and sent WINDOW_UPDATE frames change |
| 5385 | // the recv_window_size_ correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5386 | TEST_F(SpdyNetworkTransactionTest, WindowUpdateSent) { |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5387 | // Session level maximum window size that is more than twice the default |
| 5388 | // initial window size so that an initial window update is sent. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5389 | const int32_t session_max_recv_window_size = 5 * 64 * 1024; |
bnc | bca843ba | 2016-07-14 13:05:48 | [diff] [blame] | 5390 | ASSERT_LT(2 * kDefaultInitialWindowSize, session_max_recv_window_size); |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5391 | // Stream level maximum window size that is less than the session level |
| 5392 | // maximum window size so that we test for confusion between the two. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5393 | const int32_t stream_max_recv_window_size = 4 * 64 * 1024; |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5394 | ASSERT_GT(session_max_recv_window_size, stream_max_recv_window_size); |
| 5395 | // Size of body to be sent. Has to be less than or equal to both window sizes |
| 5396 | // so that we do not run out of receiving window. Also has to be greater than |
| 5397 | // half of them so that it triggers both a session level and a stream level |
| 5398 | // window update frame. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5399 | const int32_t kTargetSize = 3 * 64 * 1024; |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5400 | ASSERT_GE(session_max_recv_window_size, kTargetSize); |
| 5401 | ASSERT_GE(stream_max_recv_window_size, kTargetSize); |
| 5402 | ASSERT_LT(session_max_recv_window_size / 2, kTargetSize); |
| 5403 | ASSERT_LT(stream_max_recv_window_size / 2, kTargetSize); |
| 5404 | // Size of each DATA frame. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5405 | const int32_t kChunkSize = 4096; |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5406 | // Size of window updates. |
| 5407 | ASSERT_EQ(0, session_max_recv_window_size / 2 % kChunkSize); |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5408 | const int32_t session_window_update_delta = |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5409 | session_max_recv_window_size / 2 + kChunkSize; |
| 5410 | ASSERT_EQ(0, stream_max_recv_window_size / 2 % kChunkSize); |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5411 | const int32_t stream_window_update_delta = |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5412 | stream_max_recv_window_size / 2 + kChunkSize; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5413 | |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5414 | SettingsMap initial_settings; |
| 5415 | initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 5416 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); |
| 5417 | initial_settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
| 5418 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, stream_max_recv_window_size); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5419 | SpdySerializedFrame initial_settings_frame( |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5420 | spdy_util_.ConstructSpdySettings(initial_settings)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5421 | SpdySerializedFrame initial_window_update( |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5422 | spdy_util_.ConstructSpdyWindowUpdate( |
| 5423 | kSessionFlowControlStreamId, |
bnc | bca843ba | 2016-07-14 13:05:48 | [diff] [blame] | 5424 | session_max_recv_window_size - kDefaultInitialWindowSize)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5425 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5426 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5427 | SpdySerializedFrame session_window_update( |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5428 | spdy_util_.ConstructSpdyWindowUpdate(0, session_window_update_delta)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5429 | SpdySerializedFrame stream_window_update( |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5430 | spdy_util_.ConstructSpdyWindowUpdate(1, stream_window_update_delta)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5431 | |
| 5432 | std::vector<MockWrite> writes; |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 5433 | writes.push_back(MockWrite(ASYNC, kHttp2ConnectionHeaderPrefix, |
| 5434 | kHttp2ConnectionHeaderPrefixSize, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5435 | writes.push_back(CreateMockWrite(initial_settings_frame, writes.size())); |
| 5436 | writes.push_back(CreateMockWrite(initial_window_update, writes.size())); |
| 5437 | writes.push_back(CreateMockWrite(req, writes.size())); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5438 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5439 | std::vector<MockRead> reads; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5440 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5441 | reads.push_back(CreateMockRead(resp, writes.size() + reads.size())); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5442 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5443 | std::vector<SpdySerializedFrame> body_frames; |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5444 | const std::string body_data(kChunkSize, 'x'); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5445 | for (size_t remaining = kTargetSize; remaining != 0;) { |
| 5446 | size_t frame_size = std::min(remaining, body_data.size()); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5447 | body_frames.push_back(spdy_util_.ConstructSpdyDataFrame(1, body_data.data(), |
| 5448 | frame_size, false)); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5449 | reads.push_back( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5450 | CreateMockRead(body_frames.back(), writes.size() + reads.size())); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5451 | remaining -= frame_size; |
| 5452 | } |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5453 | // Yield. |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5454 | reads.push_back( |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5455 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, writes.size() + reads.size())); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5456 | |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5457 | writes.push_back( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5458 | CreateMockWrite(session_window_update, writes.size() + reads.size())); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5459 | writes.push_back( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5460 | CreateMockWrite(stream_window_update, writes.size() + reads.size())); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5461 | |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 5462 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 5463 | writes.size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5464 | |
| 5465 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5466 | BoundNetLog(), NULL); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5467 | helper.AddData(&data); |
| 5468 | helper.RunPreTestSetup(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5469 | |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5470 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
| 5471 | SpdySessionPoolPeer pool_peer(spdy_session_pool); |
| 5472 | pool_peer.SetEnableSendingInitialData(true); |
| 5473 | pool_peer.SetSessionMaxRecvWindowSize(session_max_recv_window_size); |
| 5474 | pool_peer.SetStreamInitialRecvWindowSize(stream_max_recv_window_size); |
| 5475 | |
| 5476 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5477 | TestCompletionCallback callback; |
| 5478 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 5479 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5480 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5481 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5482 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5483 | |
| 5484 | SpdyHttpStream* stream = |
| 5485 | static_cast<SpdyHttpStream*>(trans->stream_.get()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5486 | ASSERT_TRUE(stream); |
| 5487 | ASSERT_TRUE(stream->stream()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5488 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5489 | // All data has been read, but not consumed. The window reflects this. |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5490 | EXPECT_EQ(static_cast<int>(stream_max_recv_window_size - kTargetSize), |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5491 | stream->stream()->recv_window_size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5492 | |
| 5493 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5494 | ASSERT_TRUE(response); |
| 5495 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5496 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5497 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 5498 | |
| 5499 | // Issue a read which will cause a WINDOW_UPDATE to be sent and window |
| 5500 | // size increased to default. |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 5501 | scoped_refptr<IOBuffer> buf(new IOBuffer(kTargetSize)); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5502 | EXPECT_EQ(static_cast<int>(kTargetSize), |
| 5503 | trans->Read(buf.get(), kTargetSize, CompletionCallback())); |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5504 | EXPECT_EQ(static_cast<int>(stream_max_recv_window_size), |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5505 | stream->stream()->recv_window_size()); |
| 5506 | EXPECT_THAT(base::StringPiece(buf->data(), kTargetSize), Each(Eq('x'))); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5507 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5508 | // Allow scheduled WINDOW_UPDATE frames to write. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5509 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5510 | helper.VerifyDataConsumed(); |
| 5511 | } |
| 5512 | |
| 5513 | // Test that WINDOW_UPDATE frame causing overflow is handled correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5514 | TEST_F(SpdyNetworkTransactionTest, WindowUpdateOverflow) { |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5515 | // Number of full frames we hope to write (but will not, used to |
| 5516 | // set content-length header correctly) |
| 5517 | static int kFrameCount = 3; |
| 5518 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5519 | std::unique_ptr<std::string> content( |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5520 | new std::string(kMaxSpdyFrameChunkSize, 'a')); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5521 | SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5522 | kDefaultUrl, 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5523 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 5524 | 1, content->c_str(), content->size(), false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5525 | SpdySerializedFrame rst( |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5526 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_FLOW_CONTROL_ERROR)); |
| 5527 | |
| 5528 | // We're not going to write a data frame with FIN, we'll receive a bad |
| 5529 | // WINDOW_UPDATE while sending a request and will send a RST_STREAM frame. |
| 5530 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5531 | CreateMockWrite(req, 0), CreateMockWrite(body, 2), |
| 5532 | CreateMockWrite(rst, 3), |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5533 | }; |
| 5534 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5535 | static const int32_t kDeltaWindowSize = 0x7fffffff; // cause an overflow |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5536 | SpdySerializedFrame window_update( |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5537 | spdy_util_.ConstructSpdyWindowUpdate(1, kDeltaWindowSize)); |
| 5538 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5539 | CreateMockRead(window_update, 1), MockRead(ASYNC, 0, 4) // EOF |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5540 | }; |
| 5541 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5542 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5543 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5544 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5545 | for (int i = 0; i < kFrameCount; ++i) { |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5546 | element_readers.push_back(base::WrapUnique( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5547 | new UploadBytesElementReader(content->c_str(), content->size()))); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5548 | } |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5549 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5550 | |
| 5551 | // Setup the request |
| 5552 | HttpRequestInfo request; |
| 5553 | request.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5554 | request.url = default_url_; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5555 | request.upload_data_stream = &upload_data_stream; |
| 5556 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5557 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 5558 | NULL); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5559 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5560 | helper.AddData(&data); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5561 | HttpNetworkTransaction* trans = helper.trans(); |
| 5562 | |
| 5563 | TestCompletionCallback callback; |
| 5564 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5565 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5566 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5567 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5568 | ASSERT_TRUE(callback.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5569 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_SPDY_PROTOCOL_ERROR)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5570 | helper.VerifyDataConsumed(); |
| 5571 | } |
| 5572 | |
| 5573 | // Test that after hitting a send window size of 0, the write process |
| 5574 | // stalls and upon receiving WINDOW_UPDATE frame write resumes. |
| 5575 | |
| 5576 | // This test constructs a POST request followed by enough data frames |
| 5577 | // containing 'a' that would make the window size 0, followed by another |
| 5578 | // data frame containing default content (which is "hello!") and this frame |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5579 | // also contains a FIN flag. SequencedSocketData is used to enforce all |
| 5580 | // writes, save the last, go through before a read could happen. The last frame |
| 5581 | // ("hello!") is not permitted to go through since by the time its turn |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5582 | // arrives, window size is 0. At this point MessageLoop::Run() called via |
| 5583 | // callback would block. Therefore we call MessageLoop::RunUntilIdle() |
| 5584 | // which returns after performing all possible writes. We use DCHECKS to |
| 5585 | // ensure that last data frame is still there and stream has stalled. |
| 5586 | // After that, next read is artifically enforced, which causes a |
| 5587 | // WINDOW_UPDATE to be read and I/O process resumes. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5588 | TEST_F(SpdyNetworkTransactionTest, FlowControlStallResume) { |
bnc | bca843ba | 2016-07-14 13:05:48 | [diff] [blame] | 5589 | const int32_t initial_window_size = kDefaultInitialWindowSize; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5590 | // Number of upload data buffers we need to send to zero out the window size |
| 5591 | // is the minimal number of upload buffers takes to be bigger than |
| 5592 | // |initial_window_size|. |
| 5593 | size_t num_upload_buffers = |
| 5594 | ceil(static_cast<double>(initial_window_size) / kBufferSize); |
| 5595 | // Each upload data buffer consists of |num_frames_in_one_upload_buffer| |
| 5596 | // frames, each with |kMaxSpdyFrameChunkSize| bytes except the last frame, |
| 5597 | // which has kBufferSize % kMaxSpdyChunkSize bytes. |
| 5598 | size_t num_frames_in_one_upload_buffer = |
| 5599 | ceil(static_cast<double>(kBufferSize) / kMaxSpdyFrameChunkSize); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5600 | |
| 5601 | // Construct content for a data frame of maximum size. |
| 5602 | std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 5603 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5604 | SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5605 | kDefaultUrl, 1, |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5606 | /*content_length=*/kBufferSize * num_upload_buffers + kUploadDataSize, |
| 5607 | LOWEST, NULL, 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5608 | |
| 5609 | // Full frames. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5610 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 5611 | 1, content.c_str(), content.size(), false)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5612 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5613 | // Last frame in each upload data buffer. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5614 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5615 | 1, content.c_str(), kBufferSize % kMaxSpdyFrameChunkSize, false)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5616 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5617 | // The very last frame before the stalled frames. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5618 | SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5619 | 1, content.c_str(), |
| 5620 | initial_window_size % kBufferSize % kMaxSpdyFrameChunkSize, false)); |
| 5621 | |
| 5622 | // Data frames to be sent once WINDOW_UPDATE frame is received. |
| 5623 | |
| 5624 | // If kBufferSize * num_upload_buffers > initial_window_size, |
| 5625 | // we need one additional frame to send the rest of 'a'. |
| 5626 | std::string last_body(kBufferSize * num_upload_buffers - initial_window_size, |
| 5627 | 'a'); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5628 | SpdySerializedFrame body4(spdy_util_.ConstructSpdyDataFrame( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5629 | 1, last_body.c_str(), last_body.size(), false)); |
| 5630 | |
| 5631 | // Also send a "hello!" after WINDOW_UPDATE. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5632 | SpdySerializedFrame body5(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5633 | |
| 5634 | // Fill in mock writes. |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5635 | size_t i = 0; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5636 | std::vector<MockWrite> writes; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5637 | writes.push_back(CreateMockWrite(req, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5638 | for (size_t j = 0; j < num_upload_buffers; j++) { |
| 5639 | for (size_t k = 0; k < num_frames_in_one_upload_buffer; k++) { |
| 5640 | if (k == num_frames_in_one_upload_buffer - 1 && |
| 5641 | kBufferSize % kMaxSpdyFrameChunkSize != 0) { |
| 5642 | if (j == num_upload_buffers - 1 && |
| 5643 | (initial_window_size % kBufferSize != 0)) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5644 | writes.push_back(CreateMockWrite(body3, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5645 | } else { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5646 | writes.push_back(CreateMockWrite(body2, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5647 | } |
| 5648 | } else { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5649 | writes.push_back(CreateMockWrite(body1, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5650 | } |
| 5651 | } |
| 5652 | } |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5653 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5654 | // Fill in mock reads. |
| 5655 | std::vector<MockRead> reads; |
| 5656 | // Force a pause. |
| 5657 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, i++)); |
| 5658 | // Construct read frame for window updates that gives enough space to upload |
| 5659 | // the rest of the data. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5660 | SpdySerializedFrame session_window_update( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5661 | spdy_util_.ConstructSpdyWindowUpdate(0, |
| 5662 | kUploadDataSize + last_body.size())); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5663 | SpdySerializedFrame window_update(spdy_util_.ConstructSpdyWindowUpdate( |
| 5664 | 1, kUploadDataSize + last_body.size())); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5665 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5666 | reads.push_back(CreateMockRead(session_window_update, i++)); |
| 5667 | reads.push_back(CreateMockRead(window_update, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5668 | |
| 5669 | // Stalled frames which can be sent after receiving window updates. |
| 5670 | if (last_body.size() > 0) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5671 | writes.push_back(CreateMockWrite(body4, i++)); |
| 5672 | writes.push_back(CreateMockWrite(body5, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5673 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5674 | SpdySerializedFrame reply(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5675 | reads.push_back(CreateMockRead(reply, i++)); |
| 5676 | reads.push_back(CreateMockRead(body2, i++)); |
| 5677 | reads.push_back(CreateMockRead(body5, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5678 | reads.push_back(MockRead(ASYNC, 0, i++)); // EOF |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5679 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5680 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 5681 | writes.size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5682 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5683 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5684 | std::string upload_data_string(kBufferSize * num_upload_buffers, 'a'); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5685 | upload_data_string.append(kUploadData, kUploadDataSize); |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5686 | element_readers.push_back(base::WrapUnique(new UploadBytesElementReader( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5687 | upload_data_string.c_str(), upload_data_string.size()))); |
| 5688 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5689 | |
| 5690 | HttpRequestInfo request; |
| 5691 | request.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5692 | request.url = default_url_; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5693 | request.upload_data_stream = &upload_data_stream; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5694 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5695 | NULL); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5696 | helper.AddData(&data); |
| 5697 | helper.RunPreTestSetup(); |
| 5698 | |
| 5699 | HttpNetworkTransaction* trans = helper.trans(); |
| 5700 | |
| 5701 | TestCompletionCallback callback; |
| 5702 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5703 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5704 | |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5705 | base::RunLoop().RunUntilIdle(); // Write as much as we can. |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5706 | |
| 5707 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5708 | ASSERT_TRUE(stream); |
| 5709 | ASSERT_TRUE(stream->stream()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5710 | EXPECT_EQ(0, stream->stream()->send_window_size()); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5711 | if (initial_window_size % kBufferSize != 0) { |
| 5712 | // If it does not take whole number of full upload buffer to zero out |
| 5713 | // initial window size, then the upload data is not at EOF, because the |
| 5714 | // last read must be stalled. |
| 5715 | EXPECT_FALSE(upload_data_stream.IsEOF()); |
| 5716 | } else { |
| 5717 | // All the body data should have been read. |
| 5718 | // TODO(satorux): This is because of the weirdness in reading the request |
| 5719 | // body in OnSendBodyComplete(). See crbug.com/113107. |
| 5720 | EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 5721 | } |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5722 | // But the body is not yet fully sent (kUploadData is not yet sent) |
| 5723 | // since we're send-stalled. |
| 5724 | EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 5725 | |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5726 | data.Resume(); // Read in WINDOW_UPDATE frame. |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5727 | rv = callback.WaitForResult(); |
| 5728 | helper.VerifyDataConsumed(); |
| 5729 | } |
| 5730 | |
| 5731 | // Test we correctly handle the case where the SETTINGS frame results in |
| 5732 | // unstalling the send window. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5733 | TEST_F(SpdyNetworkTransactionTest, FlowControlStallResumeAfterSettings) { |
bnc | bca843ba | 2016-07-14 13:05:48 | [diff] [blame] | 5734 | const int32_t initial_window_size = kDefaultInitialWindowSize; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5735 | // Number of upload data buffers we need to send to zero out the window size |
| 5736 | // is the minimal number of upload buffers takes to be bigger than |
| 5737 | // |initial_window_size|. |
| 5738 | size_t num_upload_buffers = |
| 5739 | ceil(static_cast<double>(initial_window_size) / kBufferSize); |
| 5740 | // Each upload data buffer consists of |num_frames_in_one_upload_buffer| |
| 5741 | // frames, each with |kMaxSpdyFrameChunkSize| bytes except the last frame, |
| 5742 | // which has kBufferSize % kMaxSpdyChunkSize bytes. |
| 5743 | size_t num_frames_in_one_upload_buffer = |
| 5744 | ceil(static_cast<double>(kBufferSize) / kMaxSpdyFrameChunkSize); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5745 | |
| 5746 | // Construct content for a data frame of maximum size. |
| 5747 | std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 5748 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5749 | SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5750 | kDefaultUrl, 1, |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5751 | /*content_length=*/kBufferSize * num_upload_buffers + kUploadDataSize, |
| 5752 | LOWEST, NULL, 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5753 | |
| 5754 | // Full frames. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5755 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 5756 | 1, content.c_str(), content.size(), false)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5757 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5758 | // Last frame in each upload data buffer. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5759 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5760 | 1, content.c_str(), kBufferSize % kMaxSpdyFrameChunkSize, false)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5761 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5762 | // The very last frame before the stalled frames. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5763 | SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5764 | 1, content.c_str(), |
| 5765 | initial_window_size % kBufferSize % kMaxSpdyFrameChunkSize, false)); |
| 5766 | |
| 5767 | // Data frames to be sent once WINDOW_UPDATE frame is received. |
| 5768 | |
| 5769 | // If kBufferSize * num_upload_buffers > initial_window_size, |
| 5770 | // we need one additional frame to send the rest of 'a'. |
| 5771 | std::string last_body(kBufferSize * num_upload_buffers - initial_window_size, |
| 5772 | 'a'); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5773 | SpdySerializedFrame body4(spdy_util_.ConstructSpdyDataFrame( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5774 | 1, last_body.c_str(), last_body.size(), false)); |
| 5775 | |
| 5776 | // Also send a "hello!" after WINDOW_UPDATE. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5777 | SpdySerializedFrame body5(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5778 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5779 | // Fill in mock writes. |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5780 | size_t i = 0; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5781 | std::vector<MockWrite> writes; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5782 | writes.push_back(CreateMockWrite(req, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5783 | for (size_t j = 0; j < num_upload_buffers; j++) { |
| 5784 | for (size_t k = 0; k < num_frames_in_one_upload_buffer; k++) { |
| 5785 | if (k == num_frames_in_one_upload_buffer - 1 && |
| 5786 | kBufferSize % kMaxSpdyFrameChunkSize != 0) { |
| 5787 | if (j == num_upload_buffers - 1 && |
| 5788 | (initial_window_size % kBufferSize != 0)) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5789 | writes.push_back(CreateMockWrite(body3, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5790 | } else { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5791 | writes.push_back(CreateMockWrite(body2, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5792 | } |
| 5793 | } else { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5794 | writes.push_back(CreateMockWrite(body1, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5795 | } |
| 5796 | } |
| 5797 | } |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5798 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5799 | // Fill in mock reads. |
| 5800 | std::vector<MockRead> reads; |
| 5801 | // Force a pause. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5802 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, i++)); |
| 5803 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5804 | // Construct read frame for SETTINGS that gives enough space to upload the |
| 5805 | // rest of the data. |
| 5806 | SettingsMap settings; |
| 5807 | settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 5808 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, initial_window_size * 2); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5809 | SpdySerializedFrame settings_frame_large( |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5810 | spdy_util_.ConstructSpdySettings(settings)); |
| 5811 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5812 | reads.push_back(CreateMockRead(settings_frame_large, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5813 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5814 | SpdySerializedFrame session_window_update( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5815 | spdy_util_.ConstructSpdyWindowUpdate(0, |
| 5816 | last_body.size() + kUploadDataSize)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5817 | reads.push_back(CreateMockRead(session_window_update, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5818 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5819 | SpdySerializedFrame settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
| 5820 | writes.push_back(CreateMockWrite(settings_ack, i++)); |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 5821 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5822 | // Stalled frames which can be sent after |settings_ack|. |
| 5823 | if (last_body.size() > 0) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5824 | writes.push_back(CreateMockWrite(body4, i++)); |
| 5825 | writes.push_back(CreateMockWrite(body5, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5826 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5827 | SpdySerializedFrame reply(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5828 | reads.push_back(CreateMockRead(reply, i++)); |
| 5829 | reads.push_back(CreateMockRead(body2, i++)); |
| 5830 | reads.push_back(CreateMockRead(body5, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5831 | reads.push_back(MockRead(ASYNC, 0, i++)); // EOF |
| 5832 | |
| 5833 | // Force all writes to happen before any read, last write will not |
| 5834 | // actually queue a frame, due to window size being 0. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5835 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 5836 | writes.size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5837 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5838 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5839 | std::string upload_data_string(kBufferSize * num_upload_buffers, 'a'); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5840 | upload_data_string.append(kUploadData, kUploadDataSize); |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 5841 | element_readers.push_back(base::WrapUnique(new UploadBytesElementReader( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5842 | upload_data_string.c_str(), upload_data_string.size()))); |
| 5843 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5844 | |
| 5845 | HttpRequestInfo request; |
| 5846 | request.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5847 | request.url = default_url_; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5848 | request.upload_data_stream = &upload_data_stream; |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5849 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 5850 | NULL); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5851 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5852 | helper.AddData(&data); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5853 | |
| 5854 | HttpNetworkTransaction* trans = helper.trans(); |
| 5855 | |
| 5856 | TestCompletionCallback callback; |
| 5857 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5858 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5859 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5860 | data.RunUntilPaused(); // Write as much as we can. |
| 5861 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5862 | |
| 5863 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5864 | ASSERT_TRUE(stream); |
| 5865 | ASSERT_TRUE(stream->stream()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5866 | EXPECT_EQ(0, stream->stream()->send_window_size()); |
| 5867 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5868 | if (initial_window_size % kBufferSize != 0) { |
| 5869 | // If it does not take whole number of full upload buffer to zero out |
| 5870 | // initial window size, then the upload data is not at EOF, because the |
| 5871 | // last read must be stalled. |
| 5872 | EXPECT_FALSE(upload_data_stream.IsEOF()); |
| 5873 | } else { |
| 5874 | // All the body data should have been read. |
| 5875 | // TODO(satorux): This is because of the weirdness in reading the request |
| 5876 | // body in OnSendBodyComplete(). See crbug.com/113107. |
| 5877 | EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 5878 | } |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5879 | // But the body is not yet fully sent (kUploadData is not yet sent) |
| 5880 | // since we're send-stalled. |
| 5881 | EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 5882 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5883 | // Read in SETTINGS frame to unstall. |
| 5884 | data.Resume(); |
| 5885 | base::RunLoop().RunUntilIdle(); |
| 5886 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5887 | rv = callback.WaitForResult(); |
| 5888 | helper.VerifyDataConsumed(); |
| 5889 | // If stream is NULL, that means it was unstalled and closed. |
| 5890 | EXPECT_TRUE(stream->stream() == NULL); |
| 5891 | } |
| 5892 | |
| 5893 | // Test we correctly handle the case where the SETTINGS frame results in a |
| 5894 | // negative send window size. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5895 | TEST_F(SpdyNetworkTransactionTest, FlowControlNegativeSendWindowSize) { |
bnc | bca843ba | 2016-07-14 13:05:48 | [diff] [blame] | 5896 | const int32_t initial_window_size = kDefaultInitialWindowSize; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5897 | // Number of upload data buffers we need to send to zero out the window size |
| 5898 | // is the minimal number of upload buffers takes to be bigger than |
| 5899 | // |initial_window_size|. |
| 5900 | size_t num_upload_buffers = |
| 5901 | ceil(static_cast<double>(initial_window_size) / kBufferSize); |
| 5902 | // Each upload data buffer consists of |num_frames_in_one_upload_buffer| |
| 5903 | // frames, each with |kMaxSpdyFrameChunkSize| bytes except the last frame, |
| 5904 | // which has kBufferSize % kMaxSpdyChunkSize bytes. |
| 5905 | size_t num_frames_in_one_upload_buffer = |
| 5906 | ceil(static_cast<double>(kBufferSize) / kMaxSpdyFrameChunkSize); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5907 | |
| 5908 | // Construct content for a data frame of maximum size. |
| 5909 | std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 5910 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5911 | SpdySerializedFrame req(spdy_util_.ConstructSpdyPost( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5912 | kDefaultUrl, 1, |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5913 | /*content_length=*/kBufferSize * num_upload_buffers + kUploadDataSize, |
| 5914 | LOWEST, NULL, 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5915 | |
| 5916 | // Full frames. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5917 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 5918 | 1, content.c_str(), content.size(), false)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5919 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5920 | // Last frame in each upload data buffer. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5921 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5922 | 1, content.c_str(), kBufferSize % kMaxSpdyFrameChunkSize, false)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5923 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5924 | // The very last frame before the stalled frames. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5925 | SpdySerializedFrame body3(spdy_util_.ConstructSpdyDataFrame( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5926 | 1, content.c_str(), |
| 5927 | initial_window_size % kBufferSize % kMaxSpdyFrameChunkSize, false)); |
| 5928 | |
| 5929 | // Data frames to be sent once WINDOW_UPDATE frame is received. |
| 5930 | |
| 5931 | // If kBufferSize * num_upload_buffers > initial_window_size, |
| 5932 | // we need one additional frame to send the rest of 'a'. |
| 5933 | std::string last_body(kBufferSize * num_upload_buffers - initial_window_size, |
| 5934 | 'a'); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5935 | SpdySerializedFrame body4(spdy_util_.ConstructSpdyDataFrame( |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5936 | 1, last_body.c_str(), last_body.size(), false)); |
| 5937 | |
| 5938 | // Also send a "hello!" after WINDOW_UPDATE. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5939 | SpdySerializedFrame body5(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5940 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5941 | // Fill in mock writes. |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5942 | size_t i = 0; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5943 | std::vector<MockWrite> writes; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5944 | writes.push_back(CreateMockWrite(req, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5945 | for (size_t j = 0; j < num_upload_buffers; j++) { |
| 5946 | for (size_t k = 0; k < num_frames_in_one_upload_buffer; k++) { |
| 5947 | if (k == num_frames_in_one_upload_buffer - 1 && |
| 5948 | kBufferSize % kMaxSpdyFrameChunkSize != 0) { |
| 5949 | if (j == num_upload_buffers - 1 && |
| 5950 | (initial_window_size % kBufferSize != 0)) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5951 | writes.push_back(CreateMockWrite(body3, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5952 | } else { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5953 | writes.push_back(CreateMockWrite(body2, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5954 | } |
| 5955 | } else { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5956 | writes.push_back(CreateMockWrite(body1, i++)); |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5957 | } |
| 5958 | } |
| 5959 | } |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5960 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5961 | // Fill in mock reads. |
| 5962 | std::vector<MockRead> reads; |
| 5963 | // Force a pause. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5964 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5965 | // Construct read frame for SETTINGS that makes the send_window_size |
| 5966 | // negative. |
| 5967 | SettingsMap new_settings; |
| 5968 | new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 5969 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, initial_window_size / 2); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5970 | SpdySerializedFrame settings_frame_small( |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5971 | spdy_util_.ConstructSpdySettings(new_settings)); |
| 5972 | // Construct read frames for WINDOW_UPDATE that makes the send_window_size |
| 5973 | // positive. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5974 | SpdySerializedFrame session_window_update_init_size( |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 5975 | spdy_util_.ConstructSpdyWindowUpdate(0, initial_window_size)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5976 | SpdySerializedFrame window_update_init_size( |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 5977 | spdy_util_.ConstructSpdyWindowUpdate(1, initial_window_size)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5978 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5979 | reads.push_back(CreateMockRead(settings_frame_small, i++)); |
| 5980 | reads.push_back(CreateMockRead(session_window_update_init_size, i++)); |
| 5981 | reads.push_back(CreateMockRead(window_update_init_size, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5982 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5983 | SpdySerializedFrame settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
| 5984 | writes.push_back(CreateMockWrite(settings_ack, i++)); |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 5985 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 5986 | // Stalled frames which can be sent after |settings_ack|. |
| 5987 | if (last_body.size() > 0) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5988 | writes.push_back(CreateMockWrite(body4, i++)); |
| 5989 | writes.push_back(CreateMockWrite(body5, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5990 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5991 | SpdySerializedFrame reply(spdy_util_.ConstructSpdyPostReply(NULL, 0)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5992 | reads.push_back(CreateMockRead(reply, i++)); |
| 5993 | reads.push_back(CreateMockRead(body2, i++)); |
| 5994 | reads.push_back(CreateMockRead(body5, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5995 | reads.push_back(MockRead(ASYNC, 0, i++)); // EOF |
| 5996 | |
| 5997 | // Force all writes to happen before any read, last write will not |
| 5998 | // actually queue a frame, due to window size being 0. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5999 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 6000 | writes.size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6001 | |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 6002 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6003 | std::string upload_data_string(kBufferSize * num_upload_buffers, 'a'); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6004 | upload_data_string.append(kUploadData, kUploadDataSize); |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 6005 | element_readers.push_back(base::WrapUnique(new UploadBytesElementReader( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6006 | upload_data_string.c_str(), upload_data_string.size()))); |
| 6007 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6008 | |
| 6009 | HttpRequestInfo request; |
| 6010 | request.method = "POST"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6011 | request.url = default_url_; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6012 | request.upload_data_stream = &upload_data_stream; |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6013 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 6014 | NULL); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6015 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 6016 | helper.AddData(&data); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6017 | |
| 6018 | HttpNetworkTransaction* trans = helper.trans(); |
| 6019 | |
| 6020 | TestCompletionCallback callback; |
| 6021 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6022 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6023 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 6024 | data.RunUntilPaused(); // Write as much as we can. |
| 6025 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6026 | |
| 6027 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6028 | ASSERT_TRUE(stream); |
| 6029 | ASSERT_TRUE(stream->stream()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6030 | EXPECT_EQ(0, stream->stream()->send_window_size()); |
| 6031 | |
xunjieli | 179a6e7 | 2016-04-26 19:47:45 | [diff] [blame] | 6032 | if (initial_window_size % kBufferSize != 0) { |
| 6033 | // If it does not take whole number of full upload buffer to zero out |
| 6034 | // initial window size, then the upload data is not at EOF, because the |
| 6035 | // last read must be stalled. |
| 6036 | EXPECT_FALSE(upload_data_stream.IsEOF()); |
| 6037 | } else { |
| 6038 | // All the body data should have been read. |
| 6039 | // TODO(satorux): This is because of the weirdness in reading the request |
| 6040 | // body in OnSendBodyComplete(). See crbug.com/113107. |
| 6041 | EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 6042 | } |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6043 | |
| 6044 | // Read in WINDOW_UPDATE or SETTINGS frame. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 6045 | data.Resume(); |
| 6046 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6047 | rv = callback.WaitForResult(); |
| 6048 | helper.VerifyDataConsumed(); |
| 6049 | } |
| 6050 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6051 | TEST_F(SpdyNetworkTransactionTest, GoAwayOnOddPushStreamId) { |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 6052 | SpdyHeaderBlock push_headers; |
| 6053 | spdy_util_.AddUrlToHeaderBlock("http://www.example.org/a.dat", &push_headers); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6054 | SpdySerializedFrame push( |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 6055 | spdy_util_.ConstructInitialSpdyPushFrame(std::move(push_headers), 3, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6056 | MockRead reads[] = {CreateMockRead(push, 1)}; |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6057 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6058 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 6059 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6060 | SpdySerializedFrame goaway(spdy_util_.ConstructSpdyGoAway( |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6061 | 0, GOAWAY_PROTOCOL_ERROR, "Odd push stream id.")); |
| 6062 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6063 | CreateMockWrite(req, 0), CreateMockWrite(goaway, 2), |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6064 | }; |
| 6065 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 6066 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6067 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 6068 | BoundNetLog(), NULL); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6069 | helper.RunToCompletion(&data); |
| 6070 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6071 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6072 | } |
| 6073 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6074 | TEST_F(SpdyNetworkTransactionTest, |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6075 | GoAwayOnPushStreamIdLesserOrEqualThanLastAccepted) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6076 | SpdySerializedFrame push_a(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6077 | NULL, 0, 4, 1, GetDefaultUrlWithPath("/a.dat").c_str())); |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 6078 | SpdyHeaderBlock push_b_headers; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6079 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/b.dat"), |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 6080 | &push_b_headers); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6081 | SpdySerializedFrame push_b(spdy_util_.ConstructInitialSpdyPushFrame( |
| 6082 | std::move(push_b_headers), 2, 1)); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6083 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6084 | CreateMockRead(push_a, 1), CreateMockRead(push_b, 2), |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6085 | }; |
| 6086 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6087 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 6088 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6089 | SpdySerializedFrame goaway(spdy_util_.ConstructSpdyGoAway( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 6090 | 4, GOAWAY_PROTOCOL_ERROR, |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6091 | "New push stream id must be greater than the last accepted.")); |
| 6092 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6093 | CreateMockWrite(req, 0), CreateMockWrite(goaway, 3), |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6094 | }; |
| 6095 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 6096 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6097 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 6098 | BoundNetLog(), NULL); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6099 | helper.RunToCompletion(&data); |
| 6100 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6101 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6102 | } |
| 6103 | |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6104 | // Regression test for https://crbug.com/493348: request header exceeds 16 kB |
| 6105 | // and thus sent in multiple frames when using HTTP/2. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6106 | TEST_F(SpdyNetworkTransactionTest, LargeRequest) { |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6107 | const std::string kKey("foo"); |
| 6108 | const std::string kValue(1 << 15, 'z'); |
| 6109 | |
| 6110 | HttpRequestInfo request; |
| 6111 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6112 | request.url = default_url_; |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6113 | request.extra_headers.SetHeader(kKey, kValue); |
| 6114 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6115 | SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 6116 | headers[kKey] = kValue; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6117 | SpdySerializedFrame req( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6118 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6119 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6120 | CreateMockWrite(req, 0), |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6121 | }; |
| 6122 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6123 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6124 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6125 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6126 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6127 | MockRead(ASYNC, 0, 3) // EOF |
| 6128 | }; |
| 6129 | |
| 6130 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 6131 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6132 | nullptr); |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6133 | helper.RunToCompletion(&data); |
| 6134 | TransactionHelperResult out = helper.output(); |
| 6135 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6136 | EXPECT_THAT(out.rv, IsOk()); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6137 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6138 | EXPECT_EQ("hello!", out.response_data); |
| 6139 | } |
| 6140 | |
bnc | d6738334 | 2016-01-08 21:58:43 | [diff] [blame] | 6141 | // Regression test for https://crbug.com/535629: response header exceeds 16 kB. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6142 | TEST_F(SpdyNetworkTransactionTest, LargeResponseHeader) { |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6143 | SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6144 | SpdySerializedFrame req( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6145 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
bnc | d6738334 | 2016-01-08 21:58:43 | [diff] [blame] | 6146 | MockWrite writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6147 | CreateMockWrite(req, 0), |
bnc | d6738334 | 2016-01-08 21:58:43 | [diff] [blame] | 6148 | }; |
| 6149 | |
| 6150 | // HPACK decoder implementation limits string literal length to 16 kB. |
| 6151 | const char* response_headers[2]; |
| 6152 | const std::string kKey(16 * 1024, 'a'); |
| 6153 | response_headers[0] = kKey.data(); |
| 6154 | const std::string kValue(16 * 1024, 'b'); |
| 6155 | response_headers[1] = kValue.data(); |
| 6156 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6157 | SpdySerializedFrame resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6158 | spdy_util_.ConstructSpdyGetReply(response_headers, 1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6159 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | d6738334 | 2016-01-08 21:58:43 | [diff] [blame] | 6160 | MockRead reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6161 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
bnc | d6738334 | 2016-01-08 21:58:43 | [diff] [blame] | 6162 | MockRead(ASYNC, 0, 3) // EOF |
| 6163 | }; |
| 6164 | |
| 6165 | HttpRequestInfo request; |
| 6166 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6167 | request.url = default_url_; |
bnc | d6738334 | 2016-01-08 21:58:43 | [diff] [blame] | 6168 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6169 | nullptr); |
bnc | d6738334 | 2016-01-08 21:58:43 | [diff] [blame] | 6170 | |
| 6171 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 6172 | helper.RunToCompletion(&data); |
| 6173 | TransactionHelperResult out = helper.output(); |
| 6174 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6175 | EXPECT_THAT(out.rv, IsOk()); |
bnc | d6738334 | 2016-01-08 21:58:43 | [diff] [blame] | 6176 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
| 6177 | EXPECT_EQ("hello!", out.response_data); |
| 6178 | ASSERT_TRUE(out.response_info.headers->HasHeaderValue(kKey, kValue)); |
| 6179 | } |
| 6180 | |
bnc | 204a6d0 | 2016-08-01 14:34:27 | [diff] [blame] | 6181 | // End of line delimiter is forbidden according to RFC 7230 Section 3.2. |
| 6182 | TEST_F(SpdyNetworkTransactionTest, CRLFInHeaderValue) { |
| 6183 | SpdySerializedFrame req( |
| 6184 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 6185 | SpdySerializedFrame rst( |
| 6186 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 6187 | MockWrite writes[] = {CreateMockWrite(req, 0), CreateMockWrite(rst, 2)}; |
| 6188 | |
| 6189 | const char* response_headers[] = {"folded", "foo\r\nbar"}; |
| 6190 | SpdySerializedFrame resp( |
| 6191 | spdy_util_.ConstructSpdyGetReply(response_headers, 1, 1)); |
| 6192 | MockRead reads[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3)}; |
| 6193 | |
| 6194 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 6195 | |
| 6196 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 6197 | BoundNetLog(), nullptr); |
| 6198 | helper.RunToCompletion(&data); |
| 6199 | TransactionHelperResult out = helper.output(); |
| 6200 | |
| 6201 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
| 6202 | } |
| 6203 | |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6204 | class SpdyNetworkTransactionTLSUsageCheckTest |
| 6205 | : public SpdyNetworkTransactionTest { |
| 6206 | protected: |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 6207 | void RunTLSUsageCheckTest( |
| 6208 | std::unique_ptr<SSLSocketDataProvider> ssl_provider) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6209 | SpdySerializedFrame goaway( |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 6210 | spdy_util_.ConstructSpdyGoAway(0, GOAWAY_INADEQUATE_SECURITY, "")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6211 | MockWrite writes[] = {CreateMockWrite(goaway)}; |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6212 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 6213 | StaticSocketDataProvider data(NULL, 0, writes, arraysize(writes)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6214 | HttpRequestInfo request; |
| 6215 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 6216 | request.url = default_url_; |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6217 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 6218 | NULL); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 6219 | helper.RunToCompletionWithSSLData(&data, std::move(ssl_provider)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6220 | TransactionHelperResult out = helper.output(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6221 | EXPECT_THAT(out.rv, IsError(ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6222 | } |
| 6223 | }; |
| 6224 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6225 | TEST_F(SpdyNetworkTransactionTLSUsageCheckTest, TLSVersionTooOld) { |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 6226 | std::unique_ptr<SSLSocketDataProvider> ssl_provider( |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6227 | new SSLSocketDataProvider(ASYNC, OK)); |
| 6228 | SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_SSL3, |
| 6229 | &ssl_provider->connection_status); |
| 6230 | |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 6231 | RunTLSUsageCheckTest(std::move(ssl_provider)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6232 | } |
| 6233 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6234 | TEST_F(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { |
danakj | aee3e1ec | 2016-04-16 00:23:18 | [diff] [blame] | 6235 | std::unique_ptr<SSLSocketDataProvider> ssl_provider( |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6236 | new SSLSocketDataProvider(ASYNC, OK)); |
| 6237 | // Set to TLS_RSA_WITH_NULL_MD5 |
| 6238 | SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); |
| 6239 | |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 6240 | RunTLSUsageCheckTest(std::move(ssl_provider)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6241 | } |
| 6242 | |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 6243 | } // namespace net |