[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 | |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 5 | #include <string> |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 6 | #include <vector> |
| 7 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8 | #include "base/bind.h" |
| 9 | #include "base/bind_helpers.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 10 | #include "base/files/file_util.h" |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 11 | #include "base/files/scoped_temp_dir.h" |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 12 | #include "base/memory/scoped_ptr.h" |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 13 | #include "base/run_loop.h" |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 14 | #include "base/strings/string_piece.h" |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 15 | #include "base/test/test_file_util.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 16 | #include "base/thread_task_runner_handle.h" |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 17 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 18 | #include "net/base/chunked_upload_data_stream.h" |
| 19 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 20 | #include "net/base/request_priority.h" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 21 | #include "net/base/test_data_directory.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 22 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 23 | #include "net/base/upload_file_element_reader.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 24 | #include "net/http/http_auth_scheme.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 25 | #include "net/http/http_network_session_peer.h" |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 26 | #include "net/http/http_network_transaction.h" |
| 27 | #include "net/http/http_server_properties.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 28 | #include "net/http/http_transaction_test_util.h" |
mmenke | 16a7cbdd | 2015-04-24 23:00:56 | [diff] [blame] | 29 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 30 | #include "net/log/test_net_log_entry.h" |
| 31 | #include "net/log/test_net_log_util.h" |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 32 | #include "net/socket/client_socket_pool_base.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 33 | #include "net/socket/next_proto.h" |
[email protected] | f54c8579 | 2012-03-08 19:06:41 | [diff] [blame] | 34 | #include "net/spdy/buffered_spdy_framer.h" |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 35 | #include "net/spdy/spdy_http_stream.h" |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 36 | #include "net/spdy/spdy_http_utils.h" |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 37 | #include "net/spdy/spdy_session.h" |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 38 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 39 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | a4bfdf7 | 2013-02-22 04:06:16 | [diff] [blame] | 40 | #include "net/spdy/spdy_test_utils.h" |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 41 | #include "net/ssl/ssl_connection_status_flags.h" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 42 | #include "net/test/cert_test_util.h" |
[email protected] | d2db029 | 2011-01-26 20:23:44 | [diff] [blame] | 43 | #include "net/url_request/url_request_test_util.h" |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 44 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 45 | #include "testing/platform_test.h" |
| 46 | |
| 47 | //----------------------------------------------------------------------------- |
| 48 | |
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 49 | namespace net { |
[email protected] | dae22c5 | 2010-07-30 02:16:35 | [diff] [blame] | 50 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 51 | namespace { |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 52 | |
| 53 | using testing::Each; |
| 54 | using testing::Eq; |
| 55 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 56 | enum SpdyNetworkTransactionTestSSLType { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 57 | // Request an https:// URL and use NPN (or ALPN) to negotiate SPDY during |
| 58 | // the TLS handshake. |
| 59 | HTTPS_SPDY_VIA_NPN, |
| 60 | // Request and http:// URL to a server that supports SPDY via Alternative |
| 61 | // Service on port 443. |
| 62 | // See: https//tools.ietf.org/id/draft-ietf-httpbis-alt-svc-06.html |
| 63 | HTTP_SPDY_VIA_ALT_SVC, |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 64 | }; |
[email protected] | ca6459f86 | 2012-04-11 19:43:20 | [diff] [blame] | 65 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 66 | struct SpdyNetworkTransactionTestParams { |
| 67 | SpdyNetworkTransactionTestParams() |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 68 | : protocol(kProtoSPDY31), |
| 69 | ssl_type(HTTPS_SPDY_VIA_NPN), |
| 70 | priority_to_dependency(false) {} |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 71 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 72 | SpdyNetworkTransactionTestParams(NextProto protocol, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 73 | SpdyNetworkTransactionTestSSLType ssl_type, |
| 74 | bool priority_to_dependency) |
| 75 | : protocol(protocol), |
| 76 | ssl_type(ssl_type), |
| 77 | priority_to_dependency(priority_to_dependency) {} |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 78 | |
| 79 | friend std::ostream& operator<<(std::ostream& os, |
| 80 | const SpdyNetworkTransactionTestParams& p) { |
| 81 | std::string type_str; |
| 82 | switch (p.ssl_type) { |
| 83 | case HTTP_SPDY_VIA_ALT_SVC: |
| 84 | type_str = "HTTP_SPDY_VIA_ALT_SVC"; |
| 85 | break; |
| 86 | case HTTPS_SPDY_VIA_NPN: |
| 87 | type_str = "HTTPS_SPDY_VIA_NPN"; |
| 88 | break; |
| 89 | } |
| 90 | os << "{ protocol: " << SSLClientSocket::NextProtoToString(p.protocol) |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 91 | << ", ssl_type: " << type_str |
| 92 | << ", priority_to_dependency: " << p.priority_to_dependency << " }"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 93 | return os; |
| 94 | } |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 95 | |
| 96 | NextProto protocol; |
| 97 | SpdyNetworkTransactionTestSSLType ssl_type; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 98 | bool priority_to_dependency; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 99 | }; |
| 100 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 101 | void UpdateSpdySessionDependencies(SpdyNetworkTransactionTestParams test_params, |
| 102 | SpdySessionDependencies* session_deps) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 103 | session_deps->use_alternative_services = true; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 104 | session_deps->next_protos = SpdyNextProtos(); |
| 105 | if (test_params.ssl_type == HTTP_SPDY_VIA_ALT_SVC) { |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 106 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 107 | session_deps->http_server_properties.SetAlternativeService( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 108 | HostPortPair("www.example.org", 80), |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 109 | AlternativeService(AlternateProtocolFromNextProto(test_params.protocol), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 110 | "www.example.org", 443), |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 111 | 1.0, expiration); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 115 | scoped_ptr<SpdySessionDependencies> CreateSpdySessionDependencies( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 116 | SpdyNetworkTransactionTestParams test_params) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 117 | scoped_ptr<SpdySessionDependencies> session_deps( |
| 118 | new SpdySessionDependencies(test_params.protocol)); |
| 119 | UpdateSpdySessionDependencies(test_params, session_deps.get()); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 120 | return session_deps; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 121 | } |
| 122 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 123 | scoped_ptr<SpdySessionDependencies> CreateSpdySessionDependencies( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 124 | SpdyNetworkTransactionTestParams test_params, |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 125 | scoped_ptr<ProxyService> proxy_service) { |
| 126 | scoped_ptr<SpdySessionDependencies> session_deps( |
| 127 | new SpdySessionDependencies(test_params.protocol, proxy_service.Pass())); |
| 128 | UpdateSpdySessionDependencies(test_params, session_deps.get()); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 129 | return session_deps; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 130 | } |
| 131 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 132 | } // namespace |
| 133 | |
| 134 | class SpdyNetworkTransactionTest |
| 135 | : public ::testing::TestWithParam<SpdyNetworkTransactionTestParams> { |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 136 | protected: |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 137 | SpdyNetworkTransactionTest() |
| 138 | : spdy_util_(GetParam().protocol, GetParam().priority_to_dependency) { |
| 139 | SpdySession::SetPriorityDependencyDefaultForTesting( |
| 140 | GetParam().priority_to_dependency); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 141 | spdy_util_.set_default_url(GURL(GetDefaultUrl())); |
[email protected] | 9ec54f8 | 2013-05-10 02:53:05 | [diff] [blame] | 142 | } |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 143 | |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 144 | virtual ~SpdyNetworkTransactionTest() { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 145 | // UploadDataStream may post a deletion tasks back to the message loop on |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 146 | // destruction. |
| 147 | upload_data_stream_.reset(); |
| 148 | base::RunLoop().RunUntilIdle(); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 149 | SpdySession::SetPriorityDependencyDefaultForTesting(false); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 150 | } |
| 151 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 152 | void SetUp() override { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 153 | get_request_initialized_ = false; |
| 154 | post_request_initialized_ = false; |
| 155 | chunked_post_request_initialized_ = false; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 156 | ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 157 | } |
| 158 | |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 159 | struct TransactionHelperResult { |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 160 | int rv; |
| 161 | std::string status_line; |
| 162 | std::string response_data; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 163 | HttpResponseInfo response_info; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 164 | }; |
| 165 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 166 | // A helper class that handles all the initial npn/ssl setup. |
| 167 | class NormalSpdyTransactionHelper { |
| 168 | public: |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 169 | NormalSpdyTransactionHelper( |
| 170 | const HttpRequestInfo& request, |
| 171 | RequestPriority priority, |
| 172 | const BoundNetLog& log, |
| 173 | SpdyNetworkTransactionTestParams test_params, |
| 174 | scoped_ptr<SpdySessionDependencies> session_deps) |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 175 | : request_(request), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 176 | priority_(priority), |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 177 | session_deps_(session_deps.get() == NULL |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 178 | ? CreateSpdySessionDependencies(test_params) |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 179 | : session_deps.Pass()), |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 180 | session_( |
| 181 | SpdySessionDependencies::SpdyCreateSession(session_deps_.get())), |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 182 | log_(log), |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 183 | test_params_(test_params), |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 184 | port_(443), |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 185 | deterministic_(false), |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 186 | spdy_enabled_(true) {} |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 187 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 188 | ~NormalSpdyTransactionHelper() { |
| 189 | // Any test which doesn't close the socket by sending it an EOF will |
| 190 | // have a valid session left open, which leaks the entire session pool. |
| 191 | // This is just fine - in fact, some of our tests intentionally do this |
| 192 | // so that we can check consistency of the SpdySessionPool as the test |
| 193 | // finishes. If we had put an EOF on the socket, the SpdySession would |
| 194 | // have closed and we wouldn't be able to check the consistency. |
| 195 | |
| 196 | // Forcefully close existing sessions here. |
| 197 | session()->spdy_session_pool()->CloseAllSessions(); |
| 198 | } |
| 199 | |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 200 | void SetDeterministic() { |
| 201 | session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic( |
| 202 | session_deps_.get()); |
| 203 | deterministic_ = true; |
| 204 | } |
| 205 | |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 206 | void SetSpdyDisabled() { |
| 207 | spdy_enabled_ = false; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 208 | port_ = test_params_.ssl_type == HTTP_SPDY_VIA_ALT_SVC ? 80 : 443; |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 209 | } |
| 210 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 211 | void RunPreTestSetup() { |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 212 | if (!session_deps_.get()) |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 213 | session_deps_ = CreateSpdySessionDependencies(test_params_); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 214 | if (!session_.get()) { |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 215 | session_ = SpdySessionDependencies::SpdyCreateSession( |
| 216 | session_deps_.get()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 217 | } |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 218 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 219 | // We're now ready to use SSL-npn SPDY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 220 | trans_.reset(new HttpNetworkTransaction(priority_, session_.get())); |
[email protected] | cb54b3b2 | 2010-06-03 16:28:55 | [diff] [blame] | 221 | } |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 222 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 223 | // Start the transaction, read some data, finish. |
| 224 | void RunDefaultTest() { |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 225 | if (!StartDefaultTest()) |
| 226 | return; |
| 227 | FinishDefaultTest(); |
| 228 | } |
| 229 | |
| 230 | bool StartDefaultTest() { |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 231 | output_.rv = trans_->Start(&request_, callback_.callback(), log_); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 232 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 233 | // We expect an IO Pending or some sort of error. |
| 234 | EXPECT_LT(output_.rv, 0); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 235 | return output_.rv == ERR_IO_PENDING; |
| 236 | } |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 237 | |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 238 | void FinishDefaultTest() { |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 239 | output_.rv = callback_.WaitForResult(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 240 | if (output_.rv != OK) { |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 241 | session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 242 | return; |
| 243 | } |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 244 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 245 | // Verify responses. |
| 246 | const HttpResponseInfo* response = trans_->GetResponseInfo(); |
| 247 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 248 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 808957c | 2013-03-13 03:51:27 | [diff] [blame] | 249 | if (HttpStreamFactory::spdy_enabled()) { |
[email protected] | 88a33262 | 2013-07-30 07:13:32 | [diff] [blame] | 250 | EXPECT_EQ( |
| 251 | HttpResponseInfo::ConnectionInfoFromNextProto( |
| 252 | test_params_.protocol), |
| 253 | response->connection_info); |
[email protected] | 808957c | 2013-03-13 03:51:27 | [diff] [blame] | 254 | } else { |
| 255 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, |
| 256 | response->connection_info); |
| 257 | } |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 258 | if (spdy_enabled_) { |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 259 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 260 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 261 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 262 | } else { |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 263 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 264 | EXPECT_FALSE(response->was_fetched_via_spdy); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 265 | // If SPDY is disabled, an HTTP request should not be diverted |
| 266 | // over an SSL session. |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 267 | EXPECT_EQ(request_.url.SchemeIs("https"), |
| 268 | response->was_npn_negotiated); |
| 269 | } |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 270 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 271 | EXPECT_EQ(port_, response->socket_address.port()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 272 | output_.status_line = response->headers->GetStatusLine(); |
| 273 | output_.response_info = *response; // Make a copy so we can verify. |
| 274 | output_.rv = ReadTransaction(trans_.get(), &output_.response_data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 275 | } |
| 276 | |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 277 | void FinishDefaultTestWithoutVerification() { |
| 278 | output_.rv = callback_.WaitForResult(); |
| 279 | if (output_.rv != OK) |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 280 | session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 281 | } |
| 282 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 283 | // Most tests will want to call this function. In particular, the MockReads |
| 284 | // should end with an empty read, and that read needs to be processed to |
| 285 | // ensure proper deletion of the spdy_session_pool. |
| 286 | void VerifyDataConsumed() { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 287 | for (const SocketDataProvider* provider : data_vector_) { |
| 288 | EXPECT_TRUE(provider->AllReadDataConsumed()); |
| 289 | EXPECT_TRUE(provider->AllWriteDataConsumed()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 290 | } |
rch | 08051ef | 2015-05-19 20:07:18 | [diff] [blame] | 291 | for (const DeterministicSocketData* provider : |
| 292 | deterministic_data_vector_) { |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 293 | EXPECT_TRUE(provider->AllReadDataConsumed()); |
| 294 | EXPECT_TRUE(provider->AllWriteDataConsumed()); |
| 295 | } |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | // Occasionally a test will expect to error out before certain reads are |
| 299 | // processed. In that case we want to explicitly ensure that the reads were |
| 300 | // not processed. |
| 301 | void VerifyDataNotConsumed() { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 302 | for (const SocketDataProvider* provider : data_vector_) { |
| 303 | EXPECT_FALSE(provider->AllReadDataConsumed()); |
| 304 | EXPECT_FALSE(provider->AllWriteDataConsumed()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 305 | } |
rch | 08051ef | 2015-05-19 20:07:18 | [diff] [blame] | 306 | for (const DeterministicSocketData* provider : |
| 307 | deterministic_data_vector_) { |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 308 | EXPECT_FALSE(provider->AllReadDataConsumed()); |
| 309 | EXPECT_FALSE(provider->AllWriteDataConsumed()); |
| 310 | } |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 311 | } |
| 312 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 313 | void RunToCompletion(SocketDataProvider* data) { |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 314 | RunPreTestSetup(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 315 | AddData(data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 316 | RunDefaultTest(); |
| 317 | VerifyDataConsumed(); |
| 318 | } |
[email protected] | e6b0686 | 2010-07-20 16:32:58 | [diff] [blame] | 319 | |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 320 | void RunToCompletionWithSSLData( |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 321 | SocketDataProvider* data, |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 322 | scoped_ptr<SSLSocketDataProvider> ssl_provider) { |
| 323 | RunPreTestSetup(); |
| 324 | AddDataWithSSLSocketDataProvider(data, ssl_provider.Pass()); |
| 325 | RunDefaultTest(); |
| 326 | VerifyDataConsumed(); |
| 327 | } |
| 328 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 329 | void AddData(SocketDataProvider* data) { |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 330 | scoped_ptr<SSLSocketDataProvider> ssl_provider( |
| 331 | new SSLSocketDataProvider(ASYNC, OK)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 332 | ssl_provider->cert = |
| 333 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 334 | AddDataWithSSLSocketDataProvider(data, ssl_provider.Pass()); |
| 335 | } |
| 336 | |
| 337 | void AddDataWithSSLSocketDataProvider( |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 338 | SocketDataProvider* data, |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 339 | scoped_ptr<SSLSocketDataProvider> ssl_provider) { |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 340 | DCHECK(!deterministic_); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 341 | data_vector_.push_back(data); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 342 | if (ssl_provider->next_proto_status == |
| 343 | SSLClientSocket::kNextProtoUnsupported) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 344 | ssl_provider->SetNextProto(test_params_.protocol); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 345 | } |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 346 | |
| 347 | session_deps_->socket_factory->AddSSLSocketDataProvider( |
| 348 | ssl_provider.get()); |
olli.raula | ae011c42 | 2015-12-10 07:38:51 | [diff] [blame^] | 349 | ssl_vector_.push_back(std::move(ssl_provider)); |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 350 | |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 351 | session_deps_->socket_factory->AddSocketDataProvider(data); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 352 | if (test_params_.ssl_type == HTTP_SPDY_VIA_ALT_SVC) { |
| 353 | MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); |
olli.raula | ae011c42 | 2015-12-10 07:38:51 | [diff] [blame^] | 354 | scoped_ptr<StaticSocketDataProvider> hanging_non_alt_svc_socket( |
| 355 | make_scoped_ptr(new StaticSocketDataProvider(NULL, 0, NULL, 0))); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 356 | hanging_non_alt_svc_socket->set_connect_data(hanging_connect); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 357 | session_deps_->socket_factory->AddSocketDataProvider( |
olli.raula | ae011c42 | 2015-12-10 07:38:51 | [diff] [blame^] | 358 | hanging_non_alt_svc_socket.get()); |
| 359 | alternate_vector_.push_back(std::move(hanging_non_alt_svc_socket)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 360 | } |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | void AddDeterministicData(DeterministicSocketData* data) { |
| 364 | DCHECK(deterministic_); |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 365 | deterministic_data_vector_.push_back(data); |
olli.raula | ae011c42 | 2015-12-10 07:38:51 | [diff] [blame^] | 366 | scoped_ptr<SSLSocketDataProvider> ssl_provider( |
| 367 | make_scoped_ptr(new SSLSocketDataProvider(ASYNC, OK))); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 368 | ssl_provider->SetNextProto(test_params_.protocol); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 369 | ssl_provider->cert = |
| 370 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 371 | session_deps_->deterministic_socket_factory->AddSSLSocketDataProvider( |
olli.raula | ae011c42 | 2015-12-10 07:38:51 | [diff] [blame^] | 372 | ssl_provider.get()); |
| 373 | ssl_vector_.push_back(std::move(ssl_provider)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 374 | |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 375 | session_deps_->deterministic_socket_factory->AddSocketDataProvider(data); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 376 | if (test_params_.ssl_type == HTTP_SPDY_VIA_ALT_SVC) { |
| 377 | MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); |
olli.raula | ae011c42 | 2015-12-10 07:38:51 | [diff] [blame^] | 378 | scoped_ptr<DeterministicSocketData> hanging_non_alt_svc_socket( |
| 379 | make_scoped_ptr(new DeterministicSocketData(NULL, 0, NULL, 0))); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 380 | hanging_non_alt_svc_socket->set_connect_data(hanging_connect); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 381 | session_deps_->deterministic_socket_factory->AddSocketDataProvider( |
olli.raula | ae011c42 | 2015-12-10 07:38:51 | [diff] [blame^] | 382 | hanging_non_alt_svc_socket.get()); |
| 383 | alternate_deterministic_vector_.push_back( |
| 384 | std::move(hanging_non_alt_svc_socket)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 385 | } |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 386 | } |
| 387 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 388 | void SetSession(scoped_ptr<HttpNetworkSession> session) { |
| 389 | session_ = session.Pass(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 390 | } |
| 391 | HttpNetworkTransaction* trans() { return trans_.get(); } |
| 392 | void ResetTrans() { trans_.reset(); } |
| 393 | TransactionHelperResult& output() { return output_; } |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 394 | const HttpRequestInfo& request() const { return request_; } |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 395 | HttpNetworkSession* session() const { return session_.get(); } |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 396 | scoped_ptr<SpdySessionDependencies>& session_deps() { |
| 397 | return session_deps_; |
| 398 | } |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 399 | int port() const { return port_; } |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 400 | SpdyNetworkTransactionTestParams test_params() const { |
| 401 | return test_params_; |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 402 | } |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 403 | |
| 404 | private: |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 405 | typedef std::vector<SocketDataProvider*> DataVector; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 406 | typedef std::vector<DeterministicSocketData*> DeterministicDataVector; |
olli.raula | ae011c42 | 2015-12-10 07:38:51 | [diff] [blame^] | 407 | typedef std::vector<scoped_ptr<SSLSocketDataProvider>> SSLVector; |
| 408 | typedef std::vector<scoped_ptr<SocketDataProvider>> AlternateVector; |
| 409 | typedef std::vector<scoped_ptr<DeterministicSocketData>> |
| 410 | AlternateDeterministicVector; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 411 | HttpRequestInfo request_; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 412 | RequestPriority priority_; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 413 | scoped_ptr<SpdySessionDependencies> session_deps_; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 414 | scoped_ptr<HttpNetworkSession> session_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 415 | TransactionHelperResult output_; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 416 | scoped_ptr<SocketDataProvider> first_transaction_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 417 | SSLVector ssl_vector_; |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 418 | TestCompletionCallback callback_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 419 | scoped_ptr<HttpNetworkTransaction> trans_; |
| 420 | scoped_ptr<HttpNetworkTransaction> trans_http_; |
| 421 | DataVector data_vector_; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 422 | DeterministicDataVector deterministic_data_vector_; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 423 | AlternateVector alternate_vector_; |
| 424 | AlternateDeterministicVector alternate_deterministic_vector_; |
bnc | 29b1f07 | 2015-01-14 20:37:49 | [diff] [blame] | 425 | const BoundNetLog log_; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 426 | SpdyNetworkTransactionTestParams test_params_; |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 427 | int port_; |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 428 | bool deterministic_; |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 429 | bool spdy_enabled_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 430 | }; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 431 | |
| 432 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 433 | int expected_status); |
| 434 | |
| 435 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 436 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 437 | const HttpRequestInfo& CreateGetPushRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 438 | get_push_request_.method = "GET"; |
| 439 | get_push_request_.url = GURL(GetDefaultUrlWithPath("/foo.dat")); |
| 440 | get_push_request_.load_flags = 0; |
| 441 | return get_push_request_; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 442 | } |
| 443 | |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 444 | const HttpRequestInfo& CreateGetRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 445 | if (!get_request_initialized_) { |
| 446 | get_request_.method = "GET"; |
| 447 | get_request_.url = GURL(GetDefaultUrl()); |
| 448 | get_request_.load_flags = 0; |
| 449 | get_request_initialized_ = true; |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 450 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 451 | return get_request_; |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 452 | } |
| 453 | |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 454 | const HttpRequestInfo& CreateGetRequestWithUserAgent() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 455 | if (!get_request_initialized_) { |
| 456 | get_request_.method = "GET"; |
| 457 | get_request_.url = GURL(GetDefaultUrl()); |
| 458 | get_request_.load_flags = 0; |
| 459 | get_request_.extra_headers.SetHeader("User-Agent", "Chrome"); |
| 460 | get_request_initialized_ = true; |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 461 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 462 | return get_request_; |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 463 | } |
| 464 | |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 465 | const HttpRequestInfo& CreatePostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 466 | if (!post_request_initialized_) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 467 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 468 | element_readers.push_back(make_scoped_ptr( |
| 469 | new UploadBytesElementReader(kUploadData, kUploadDataSize))); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 470 | upload_data_stream_.reset( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 471 | new ElementsUploadDataStream(std::move(element_readers), 0)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 472 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 473 | post_request_.method = "POST"; |
| 474 | post_request_.url = GURL(GetDefaultUrl()); |
| 475 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 476 | post_request_initialized_ = true; |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 477 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 478 | return post_request_; |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 479 | } |
| 480 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 481 | const HttpRequestInfo& CreateFilePostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 482 | if (!post_request_initialized_) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 483 | base::FilePath file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 484 | CHECK(base::CreateTemporaryFileInDir(temp_dir_.path(), &file_path)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 485 | CHECK_EQ(static_cast<int>(kUploadDataSize), |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 486 | base::WriteFile(file_path, kUploadData, kUploadDataSize)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 487 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 488 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 489 | element_readers.push_back(make_scoped_ptr(new UploadFileElementReader( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 490 | base::ThreadTaskRunnerHandle::Get().get(), file_path, 0, |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 491 | kUploadDataSize, base::Time()))); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 492 | upload_data_stream_.reset( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 493 | new ElementsUploadDataStream(std::move(element_readers), 0)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 494 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 495 | post_request_.method = "POST"; |
| 496 | post_request_.url = GURL(GetDefaultUrl()); |
| 497 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 498 | post_request_initialized_ = true; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 499 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 500 | return post_request_; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 501 | } |
| 502 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 503 | const HttpRequestInfo& CreateUnreadableFilePostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 504 | if (post_request_initialized_) |
| 505 | return post_request_; |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 506 | |
| 507 | base::FilePath file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 508 | CHECK(base::CreateTemporaryFileInDir(temp_dir_.path(), &file_path)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 509 | CHECK_EQ(static_cast<int>(kUploadDataSize), |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 510 | base::WriteFile(file_path, kUploadData, kUploadDataSize)); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 511 | CHECK(base::MakeFileUnreadable(file_path)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 512 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 513 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 514 | element_readers.push_back(make_scoped_ptr(new UploadFileElementReader( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 515 | base::ThreadTaskRunnerHandle::Get().get(), file_path, 0, |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 516 | kUploadDataSize, base::Time()))); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 517 | upload_data_stream_.reset( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 518 | new ElementsUploadDataStream(std::move(element_readers), 0)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 519 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 520 | post_request_.method = "POST"; |
| 521 | post_request_.url = GURL(GetDefaultUrl()); |
| 522 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 523 | post_request_initialized_ = true; |
| 524 | return post_request_; |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 525 | } |
| 526 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 527 | const HttpRequestInfo& CreateComplexPostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 528 | if (!post_request_initialized_) { |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 529 | const int kFileRangeOffset = 1; |
| 530 | const int kFileRangeLength = 3; |
| 531 | CHECK_LT(kFileRangeOffset + kFileRangeLength, kUploadDataSize); |
| 532 | |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 533 | base::FilePath file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 534 | CHECK(base::CreateTemporaryFileInDir(temp_dir_.path(), &file_path)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 535 | CHECK_EQ(static_cast<int>(kUploadDataSize), |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 536 | base::WriteFile(file_path, kUploadData, kUploadDataSize)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 537 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 538 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 539 | element_readers.push_back(make_scoped_ptr( |
| 540 | new UploadBytesElementReader(kUploadData, kFileRangeOffset))); |
| 541 | element_readers.push_back(make_scoped_ptr(new UploadFileElementReader( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 542 | base::ThreadTaskRunnerHandle::Get().get(), file_path, |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 543 | kFileRangeOffset, kFileRangeLength, base::Time()))); |
| 544 | element_readers.push_back(make_scoped_ptr(new UploadBytesElementReader( |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 545 | kUploadData + kFileRangeOffset + kFileRangeLength, |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 546 | kUploadDataSize - (kFileRangeOffset + kFileRangeLength)))); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 547 | upload_data_stream_.reset( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 548 | new ElementsUploadDataStream(std::move(element_readers), 0)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 549 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 550 | post_request_.method = "POST"; |
| 551 | post_request_.url = GURL(GetDefaultUrl()); |
| 552 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 553 | post_request_initialized_ = true; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 554 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 555 | return post_request_; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 556 | } |
| 557 | |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 558 | const HttpRequestInfo& CreateChunkedPostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 559 | if (!chunked_post_request_initialized_) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 560 | upload_chunked_data_stream_.reset(new ChunkedUploadDataStream(0)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 561 | chunked_post_request_.method = "POST"; |
| 562 | chunked_post_request_.url = GURL(GetDefaultUrl()); |
| 563 | chunked_post_request_.upload_data_stream = |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 564 | upload_chunked_data_stream_.get(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 565 | chunked_post_request_initialized_ = true; |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 566 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 567 | return chunked_post_request_; |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 568 | } |
| 569 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 570 | // Read the result of a particular transaction, knowing that we've got |
| 571 | // multiple transactions in the read pipeline; so as we read, we may have |
| 572 | // to skip over data destined for other transactions while we consume |
| 573 | // the data for |trans|. |
| 574 | int ReadResult(HttpNetworkTransaction* trans, |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 575 | std::string* result) { |
| 576 | const int kSize = 3000; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 577 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 578 | int bytes_read = 0; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 579 | scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(kSize)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 580 | TestCompletionCallback callback; |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 581 | while (true) { |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 582 | int rv = trans->Read(buf.get(), kSize, callback.callback()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 583 | if (rv == ERR_IO_PENDING) { |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 584 | rv = callback.WaitForResult(); |
| 585 | } else if (rv <= 0) { |
| 586 | break; |
| 587 | } |
| 588 | result->append(buf->data(), rv); |
| 589 | bytes_read += rv; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 590 | } |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 591 | return bytes_read; |
| 592 | } |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 593 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 594 | void VerifyStreamsClosed(const NormalSpdyTransactionHelper& helper) { |
| 595 | // This lengthy block is reaching into the pool to dig out the active |
| 596 | // session. Once we have the session, we verify that the streams are |
| 597 | // all closed and not leaked at this point. |
| 598 | const GURL& url = helper.request().url; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 599 | HostPortPair host_port_pair(url.host(), 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 600 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 601 | PRIVACY_MODE_DISABLED); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 602 | BoundNetLog log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 603 | HttpNetworkSession* session = helper.session(); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 604 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 04644d4 | 2013-07-08 04:29:59 | [diff] [blame] | 605 | session->spdy_session_pool()->FindAvailableSession(key, log); |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 606 | ASSERT_TRUE(spdy_session != NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 607 | EXPECT_EQ(0u, spdy_session->num_active_streams()); |
| 608 | EXPECT_EQ(0u, spdy_session->num_unclaimed_pushed_streams()); |
| 609 | } |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 610 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 611 | void RunServerPushTest(SequencedSocketData* data, |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 612 | HttpResponseInfo* response, |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 613 | HttpResponseInfo* push_response, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 614 | const std::string& expected) { |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 615 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 616 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 617 | helper.RunPreTestSetup(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 618 | helper.AddData(data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 619 | |
| 620 | HttpNetworkTransaction* trans = helper.trans(); |
| 621 | |
| 622 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 623 | TestCompletionCallback callback; |
| 624 | int rv = trans->Start( |
| 625 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 626 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 627 | rv = callback.WaitForResult(); |
| 628 | |
| 629 | // Request the pushed path. |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 630 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 631 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 632 | rv = trans2->Start( |
| 633 | &CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 634 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 635 | base::RunLoop().RunUntilIdle(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 636 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 637 | // 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] | 638 | // the results into a single string. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 639 | |
| 640 | // Read the server push body. |
| 641 | std::string result2; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 642 | ReadResult(trans2.get(), &result2); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 643 | // Read the response body. |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 644 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 645 | ReadResult(trans, &result); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 646 | |
| 647 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 648 | EXPECT_TRUE(data->AllReadDataConsumed()); |
| 649 | EXPECT_TRUE(data->AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 650 | |
| 651 | // Verify that the received push data is same as the expected push data. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 652 | EXPECT_EQ(result2.compare(expected), 0) << "Received data: " |
| 653 | << result2 |
| 654 | << "||||| Expected data: " |
| 655 | << expected; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 656 | |
| 657 | // Verify the SYN_REPLY. |
| 658 | // Copy the response info, because trans goes away. |
| 659 | *response = *trans->GetResponseInfo(); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 660 | *push_response = *trans2->GetResponseInfo(); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 661 | |
| 662 | VerifyStreamsClosed(helper); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 663 | } |
| 664 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 665 | static void DeleteSessionCallback(NormalSpdyTransactionHelper* helper, |
| 666 | int result) { |
| 667 | helper->ResetTrans(); |
| 668 | } |
| 669 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 670 | static void StartTransactionCallback(HttpNetworkSession* session, |
| 671 | GURL url, |
| 672 | int result) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 673 | scoped_ptr<HttpNetworkTransaction> trans( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 674 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 675 | TestCompletionCallback callback; |
| 676 | HttpRequestInfo request; |
| 677 | request.method = "GET"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 678 | request.url = url; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 679 | request.load_flags = 0; |
| 680 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 681 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 682 | callback.WaitForResult(); |
| 683 | } |
| 684 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 685 | ChunkedUploadDataStream* upload_chunked_data_stream() const { |
| 686 | return upload_chunked_data_stream_.get(); |
| 687 | } |
| 688 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 689 | const char* GetDefaultUrl() { |
| 690 | switch (GetParam().ssl_type) { |
| 691 | case HTTP_SPDY_VIA_ALT_SVC: |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 692 | return "http://www.example.org"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 693 | case HTTPS_SPDY_VIA_NPN: |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 694 | return "https://www.example.org"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 695 | default: |
| 696 | NOTREACHED(); |
| 697 | return ""; |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | std::string GetDefaultUrlWithPath(const char* path) { |
| 702 | return std::string(GetDefaultUrl()) + path; |
| 703 | } |
| 704 | |
[email protected] | 9ec54f8 | 2013-05-10 02:53:05 | [diff] [blame] | 705 | SpdyTestUtil spdy_util_; |
| 706 | |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 707 | private: |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 708 | scoped_ptr<ChunkedUploadDataStream> upload_chunked_data_stream_; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 709 | scoped_ptr<UploadDataStream> upload_data_stream_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 710 | bool get_request_initialized_; |
| 711 | bool post_request_initialized_; |
| 712 | bool chunked_post_request_initialized_; |
| 713 | HttpRequestInfo get_request_; |
| 714 | HttpRequestInfo post_request_; |
| 715 | HttpRequestInfo chunked_post_request_; |
| 716 | HttpRequestInfo get_push_request_; |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 717 | base::ScopedTempDir temp_dir_; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 718 | }; |
| 719 | |
| 720 | //----------------------------------------------------------------------------- |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 721 | // All tests are run with three different connection types: SPDY after NPN |
| 722 | // negotiation, SPDY without SSL, and SPDY with SSL. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 723 | // |
| 724 | // TODO(akalin): Use ::testing::Combine() when we are able to use |
| 725 | // <tr1/tuple>. |
| 726 | INSTANTIATE_TEST_CASE_P( |
| 727 | Spdy, |
| 728 | SpdyNetworkTransactionTest, |
| 729 | ::testing::Values( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 730 | SpdyNetworkTransactionTestParams(kProtoSPDY31, |
| 731 | HTTPS_SPDY_VIA_NPN, |
| 732 | false), |
| 733 | SpdyNetworkTransactionTestParams(kProtoSPDY31, |
| 734 | HTTP_SPDY_VIA_ALT_SVC, |
| 735 | false), |
| 736 | SpdyNetworkTransactionTestParams(kProtoHTTP2, |
| 737 | HTTPS_SPDY_VIA_NPN, |
| 738 | false), |
| 739 | SpdyNetworkTransactionTestParams(kProtoHTTP2, HTTPS_SPDY_VIA_NPN, true), |
| 740 | SpdyNetworkTransactionTestParams(kProtoHTTP2, |
| 741 | HTTP_SPDY_VIA_ALT_SVC, |
| 742 | false), |
| 743 | SpdyNetworkTransactionTestParams(kProtoHTTP2, |
| 744 | HTTP_SPDY_VIA_ALT_SVC, |
| 745 | true))); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 746 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 747 | // Verify HttpNetworkTransaction constructor. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 748 | TEST_P(SpdyNetworkTransactionTest, Constructor) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 749 | scoped_ptr<SpdySessionDependencies> session_deps( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 750 | CreateSpdySessionDependencies(GetParam())); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 751 | scoped_ptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 752 | SpdySessionDependencies::SpdyCreateSession(session_deps.get())); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 753 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 754 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 755 | } |
| 756 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 757 | TEST_P(SpdyNetworkTransactionTest, Get) { |
[email protected] | 75f30cc2 | 2010-06-28 21:41:38 | [diff] [blame] | 758 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 759 | scoped_ptr<SpdyFrame> req( |
| 760 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 761 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 762 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 763 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 764 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 765 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 766 | CreateMockRead(*resp, 1), |
| 767 | CreateMockRead(*body, 2), |
| 768 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 769 | }; |
| 770 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 771 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 772 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 773 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 774 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 775 | TransactionHelperResult out = helper.output(); |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 776 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 777 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 778 | EXPECT_EQ("hello!", out.response_data); |
| 779 | } |
| 780 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 781 | TEST_P(SpdyNetworkTransactionTest, GetAtEachPriority) { |
[email protected] | 3d08dd38 | 2013-10-19 00:13:11 | [diff] [blame] | 782 | for (RequestPriority p = MINIMUM_PRIORITY; p <= MAXIMUM_PRIORITY; |
[email protected] | 31ae7ab | 2012-04-24 21:09:05 | [diff] [blame] | 783 | p = RequestPriority(p + 1)) { |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 784 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 785 | scoped_ptr<SpdyFrame> req( |
| 786 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, p, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 787 | spdy_util_.UpdateWithStreamDestruction(1); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 788 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 789 | |
[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 790 | SpdyPriority spdy_prio = 0; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 791 | EXPECT_TRUE(GetSpdyPriority(spdy_util_.spdy_version(), *req, &spdy_prio)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 792 | // this repeats the RequestPriority-->SpdyPriority mapping from |
| 793 | // SpdyFramer::ConvertRequestPriorityToSpdyPriority to make |
| 794 | // sure it's being done right. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 795 | if (spdy_util_.spdy_version() < SPDY3) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 796 | switch (p) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 797 | case HIGHEST: |
| 798 | EXPECT_EQ(0, spdy_prio); |
| 799 | break; |
| 800 | case MEDIUM: |
| 801 | EXPECT_EQ(1, spdy_prio); |
| 802 | break; |
| 803 | case LOW: |
| 804 | case LOWEST: |
| 805 | EXPECT_EQ(2, spdy_prio); |
| 806 | break; |
| 807 | case IDLE: |
| 808 | EXPECT_EQ(3, spdy_prio); |
| 809 | break; |
| 810 | default: |
| 811 | FAIL(); |
| 812 | } |
| 813 | } else { |
bnc | e8aa270 | 2015-08-17 18:11:05 | [diff] [blame] | 814 | switch (p) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 815 | case HIGHEST: |
| 816 | EXPECT_EQ(0, spdy_prio); |
| 817 | break; |
| 818 | case MEDIUM: |
| 819 | EXPECT_EQ(1, spdy_prio); |
| 820 | break; |
| 821 | case LOW: |
| 822 | EXPECT_EQ(2, spdy_prio); |
| 823 | break; |
| 824 | case LOWEST: |
| 825 | EXPECT_EQ(3, spdy_prio); |
| 826 | break; |
| 827 | case IDLE: |
| 828 | EXPECT_EQ(4, spdy_prio); |
| 829 | break; |
| 830 | default: |
| 831 | FAIL(); |
| 832 | } |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 833 | } |
| 834 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 835 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 836 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 837 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 838 | CreateMockRead(*resp, 1), |
| 839 | CreateMockRead(*body, 2), |
| 840 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 841 | }; |
| 842 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 843 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 844 | arraysize(writes)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 845 | HttpRequestInfo http_req = CreateGetRequest(); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 846 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 847 | NormalSpdyTransactionHelper helper(http_req, p, BoundNetLog(), |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 848 | GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 849 | helper.RunToCompletion(&data); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 850 | TransactionHelperResult out = helper.output(); |
| 851 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 852 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 853 | EXPECT_EQ("hello!", out.response_data); |
| 854 | } |
| 855 | } |
| 856 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 857 | // Start three gets simultaniously; making sure that multiplexed |
| 858 | // streams work properly. |
| 859 | |
| 860 | // This can't use the TransactionHelper method, since it only |
| 861 | // handles a single transaction, and finishes them as soon |
| 862 | // as it launches them. |
| 863 | |
| 864 | // TODO(gavinp): create a working generalized TransactionHelper that |
| 865 | // can allow multiple streams in flight. |
| 866 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 867 | TEST_P(SpdyNetworkTransactionTest, ThreeGets) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 868 | scoped_ptr<SpdyFrame> req( |
| 869 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 870 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 871 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 872 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 873 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 874 | scoped_ptr<SpdyFrame> req2( |
| 875 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 876 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 877 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 878 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 879 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 880 | scoped_ptr<SpdyFrame> req3( |
| 881 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 882 | scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 883 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(5, false)); |
| 884 | scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 885 | |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 886 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 887 | CreateMockWrite(*req, 0), |
| 888 | CreateMockWrite(*req2, 3), |
| 889 | CreateMockWrite(*req3, 6), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 890 | }; |
| 891 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 892 | CreateMockRead(*resp, 1), |
| 893 | CreateMockRead(*body, 2), |
| 894 | CreateMockRead(*resp2, 4), |
| 895 | CreateMockRead(*body2, 5), |
| 896 | CreateMockRead(*resp3, 7), |
| 897 | CreateMockRead(*body3, 8), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 898 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 899 | CreateMockRead(*fbody, 9), |
| 900 | CreateMockRead(*fbody2, 10), |
| 901 | CreateMockRead(*fbody3, 11), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 902 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 903 | MockRead(ASYNC, 0, 12), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 904 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 905 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 906 | SequencedSocketData data_placeholder1(NULL, 0, NULL, 0); |
| 907 | SequencedSocketData data_placeholder2(NULL, 0, NULL, 0); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 908 | |
| 909 | BoundNetLog log; |
| 910 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 911 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 912 | BoundNetLog(), GetParam(), NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 913 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 914 | helper.AddData(&data); |
rch | aeb3f05 | 2015-04-14 16:02:49 | [diff] [blame] | 915 | // We require placeholder data because three get requests are sent out at |
| 916 | // the same time which results in three sockets being connected. The first |
| 917 | // on will negotiate SPDY and will be used for all requests. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 918 | helper.AddData(&data_placeholder1); |
| 919 | helper.AddData(&data_placeholder2); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 920 | scoped_ptr<HttpNetworkTransaction> trans1( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 921 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 922 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 923 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 924 | scoped_ptr<HttpNetworkTransaction> trans3( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 925 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 926 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 927 | TestCompletionCallback callback1; |
| 928 | TestCompletionCallback callback2; |
| 929 | TestCompletionCallback callback3; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 930 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 931 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 932 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 933 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 934 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 935 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 936 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 937 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 938 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 939 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 940 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 941 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 942 | out.rv = callback1.WaitForResult(); |
| 943 | ASSERT_EQ(OK, out.rv); |
| 944 | out.rv = callback3.WaitForResult(); |
| 945 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 946 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 947 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 948 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 949 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 950 | out.status_line = response1->headers->GetStatusLine(); |
| 951 | out.response_info = *response1; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 952 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 953 | trans2->GetResponseInfo(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 954 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 955 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 956 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 957 | EXPECT_EQ(OK, out.rv); |
| 958 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 959 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 960 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 961 | EXPECT_EQ("hello!hello!", out.response_data); |
| 962 | } |
| 963 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 964 | TEST_P(SpdyNetworkTransactionTest, TwoGetsLateBinding) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 965 | scoped_ptr<SpdyFrame> req( |
| 966 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 967 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 968 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 969 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 970 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 971 | scoped_ptr<SpdyFrame> req2( |
| 972 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 973 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 974 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 975 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 976 | |
| 977 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 978 | CreateMockWrite(*req, 0), CreateMockWrite(*req2, 3), |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 979 | }; |
| 980 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 981 | CreateMockRead(*resp, 1), |
| 982 | CreateMockRead(*body, 2), |
| 983 | CreateMockRead(*resp2, 4), |
| 984 | CreateMockRead(*body2, 5), |
| 985 | CreateMockRead(*fbody, 6), |
| 986 | CreateMockRead(*fbody2, 7), |
| 987 | MockRead(ASYNC, 0, 8), // EOF |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 988 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 989 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 990 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 991 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 992 | SequencedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 993 | data_placeholder.set_connect_data(never_finishing_connect); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 994 | |
| 995 | BoundNetLog log; |
| 996 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 997 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 998 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 999 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1000 | helper.AddData(&data); |
rch | aeb3f05 | 2015-04-14 16:02:49 | [diff] [blame] | 1001 | // We require placeholder data because two requests are sent out at |
| 1002 | // the same time which results in two sockets being connected. The first |
| 1003 | // on will negotiate SPDY and will be used for all requests. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1004 | helper.AddData(&data_placeholder); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1005 | scoped_ptr<HttpNetworkTransaction> trans1( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1006 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1007 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1008 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1009 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1010 | TestCompletionCallback callback1; |
| 1011 | TestCompletionCallback callback2; |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1012 | |
| 1013 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1014 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1015 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1016 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1017 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1018 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1019 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
| 1020 | |
| 1021 | out.rv = callback1.WaitForResult(); |
| 1022 | ASSERT_EQ(OK, out.rv); |
| 1023 | out.rv = callback2.WaitForResult(); |
| 1024 | ASSERT_EQ(OK, out.rv); |
| 1025 | |
| 1026 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1027 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1028 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1029 | out.status_line = response1->headers->GetStatusLine(); |
| 1030 | out.response_info = *response1; |
| 1031 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 1032 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1033 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1034 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1035 | |
| 1036 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1037 | EXPECT_TRUE(response2->headers.get() != NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1038 | EXPECT_TRUE(response2->was_fetched_via_spdy); |
| 1039 | out.status_line = response2->headers->GetStatusLine(); |
| 1040 | out.response_info = *response2; |
| 1041 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 1042 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1043 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1044 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1045 | |
| 1046 | helper.VerifyDataConsumed(); |
| 1047 | } |
| 1048 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1049 | TEST_P(SpdyNetworkTransactionTest, TwoGetsLateBindingFromPreconnect) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1050 | scoped_ptr<SpdyFrame> req( |
| 1051 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1052 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1053 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1054 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1055 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1056 | scoped_ptr<SpdyFrame> req2( |
| 1057 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1058 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1059 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 1060 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1061 | |
| 1062 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1063 | CreateMockWrite(*req, 0), CreateMockWrite(*req2, 3), |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1064 | }; |
| 1065 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1066 | CreateMockRead(*resp, 1), |
| 1067 | CreateMockRead(*body, 2), |
| 1068 | CreateMockRead(*resp2, 4), |
| 1069 | CreateMockRead(*body2, 5), |
| 1070 | CreateMockRead(*fbody, 6), |
| 1071 | CreateMockRead(*fbody2, 7), |
| 1072 | MockRead(ASYNC, 0, 8), // EOF |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1073 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1074 | SequencedSocketData preconnect_data(reads, arraysize(reads), writes, |
| 1075 | arraysize(writes)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1076 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 1077 | MockConnect never_finishing_connect(ASYNC, ERR_IO_PENDING); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1078 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1079 | SequencedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1080 | data_placeholder.set_connect_data(never_finishing_connect); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1081 | |
| 1082 | BoundNetLog log; |
| 1083 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1084 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1085 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1086 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1087 | helper.AddData(&preconnect_data); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1088 | // We require placeholder data because 3 connections are attempted (first is |
| 1089 | // the preconnect, 2nd and 3rd are the never finished connections. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1090 | helper.AddData(&data_placeholder); |
| 1091 | helper.AddData(&data_placeholder); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1092 | |
| 1093 | scoped_ptr<HttpNetworkTransaction> trans1( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1094 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1095 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1096 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1097 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1098 | TestCompletionCallback callback1; |
| 1099 | TestCompletionCallback callback2; |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1100 | |
| 1101 | HttpRequestInfo httpreq = CreateGetRequest(); |
| 1102 | |
| 1103 | // Preconnect the first. |
| 1104 | SSLConfig preconnect_ssl_config; |
| 1105 | helper.session()->ssl_config_service()->GetSSLConfig(&preconnect_ssl_config); |
| 1106 | HttpStreamFactory* http_stream_factory = |
| 1107 | helper.session()->http_stream_factory(); |
bnc | 1f29537 | 2015-10-21 23:24:22 | [diff] [blame] | 1108 | helper.session()->GetAlpnProtos(&preconnect_ssl_config.alpn_protos); |
| 1109 | helper.session()->GetNpnProtos(&preconnect_ssl_config.npn_protos); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1110 | |
mmenke | d1205bd397 | 2015-07-15 22:26:35 | [diff] [blame] | 1111 | http_stream_factory->PreconnectStreams(1, httpreq, preconnect_ssl_config, |
| 1112 | preconnect_ssl_config); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1113 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1114 | out.rv = trans1->Start(&httpreq, callback1.callback(), log); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1115 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1116 | out.rv = trans2->Start(&httpreq, callback2.callback(), log); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1117 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
| 1118 | |
| 1119 | out.rv = callback1.WaitForResult(); |
| 1120 | ASSERT_EQ(OK, out.rv); |
| 1121 | out.rv = callback2.WaitForResult(); |
| 1122 | ASSERT_EQ(OK, out.rv); |
| 1123 | |
| 1124 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1125 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1126 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1127 | out.status_line = response1->headers->GetStatusLine(); |
| 1128 | out.response_info = *response1; |
| 1129 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 1130 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1131 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1132 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1133 | |
| 1134 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1135 | EXPECT_TRUE(response2->headers.get() != NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1136 | EXPECT_TRUE(response2->was_fetched_via_spdy); |
| 1137 | out.status_line = response2->headers->GetStatusLine(); |
| 1138 | out.response_info = *response2; |
| 1139 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 1140 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1141 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1142 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1143 | |
| 1144 | helper.VerifyDataConsumed(); |
| 1145 | } |
| 1146 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1147 | // Similar to ThreeGets above, however this test adds a SETTINGS |
| 1148 | // frame. The SETTINGS frame is read during the IO loop waiting on |
| 1149 | // the first transaction completion, and sets a maximum concurrent |
| 1150 | // stream limit of 1. This means that our IO loop exists after the |
| 1151 | // second transaction completes, so we can assert on read_index(). |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1152 | TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrent) { |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1153 | // Construct the request. |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1154 | // Each request fully completes before the next starts. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1155 | scoped_ptr<SpdyFrame> req( |
| 1156 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1157 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1158 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1159 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1160 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1161 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1162 | scoped_ptr<SpdyFrame> req2( |
| 1163 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1164 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1165 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 1166 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1167 | spdy_util_.UpdateWithStreamDestruction(3); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1168 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1169 | scoped_ptr<SpdyFrame> req3( |
| 1170 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1171 | scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 1172 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(5, false)); |
| 1173 | scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1174 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1175 | SettingsMap settings; |
[email protected] | 9dcec24 | 2013-01-10 23:24:28 | [diff] [blame] | 1176 | const uint32 max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1177 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1178 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1179 | scoped_ptr<SpdyFrame> settings_frame( |
| 1180 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1181 | scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1182 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 1183 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1184 | CreateMockWrite(*req, 0), |
| 1185 | CreateMockWrite(*settings_ack, 5), |
| 1186 | CreateMockWrite(*req2, 6), |
| 1187 | CreateMockWrite(*req3, 10), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1188 | }; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 1189 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1190 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1191 | CreateMockRead(*settings_frame, 1), |
| 1192 | CreateMockRead(*resp, 2), |
| 1193 | CreateMockRead(*body, 3), |
| 1194 | CreateMockRead(*fbody, 4), |
| 1195 | CreateMockRead(*resp2, 7), |
| 1196 | CreateMockRead(*body2, 8), |
| 1197 | CreateMockRead(*fbody2, 9), |
| 1198 | CreateMockRead(*resp3, 11), |
| 1199 | CreateMockRead(*body3, 12), |
| 1200 | CreateMockRead(*fbody3, 13), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1201 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1202 | MockRead(ASYNC, 0, 14), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1203 | }; |
| 1204 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1205 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1206 | |
| 1207 | BoundNetLog log; |
| 1208 | TransactionHelperResult out; |
| 1209 | { |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1210 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1211 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 1212 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1213 | helper.AddData(&data); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1214 | scoped_ptr<HttpNetworkTransaction> trans1( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1215 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1216 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1217 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1218 | scoped_ptr<HttpNetworkTransaction> trans3( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1219 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1220 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1221 | TestCompletionCallback callback1; |
| 1222 | TestCompletionCallback callback2; |
| 1223 | TestCompletionCallback callback3; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1224 | |
| 1225 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1226 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1227 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
| 1228 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1229 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1230 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1231 | // Run transaction 1 through quickly to force a read of our SETTINGS |
| 1232 | // frame. |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1233 | out.rv = callback1.WaitForResult(); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1234 | ASSERT_EQ(OK, out.rv); |
[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 = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1237 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1238 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1239 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
| 1240 | out.rv = callback2.WaitForResult(); |
| 1241 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1242 | |
| 1243 | out.rv = callback3.WaitForResult(); |
| 1244 | ASSERT_EQ(OK, out.rv); |
| 1245 | |
| 1246 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1247 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1248 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1249 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1250 | out.status_line = response1->headers->GetStatusLine(); |
| 1251 | out.response_info = *response1; |
| 1252 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 1253 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1254 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1255 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1256 | |
| 1257 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 1258 | out.status_line = response2->headers->GetStatusLine(); |
| 1259 | out.response_info = *response2; |
| 1260 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 1261 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1262 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1263 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1264 | |
| 1265 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 1266 | out.status_line = response3->headers->GetStatusLine(); |
| 1267 | out.response_info = *response3; |
| 1268 | out.rv = ReadTransaction(trans3.get(), &out.response_data); |
| 1269 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1270 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1271 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1272 | |
| 1273 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1274 | } |
| 1275 | EXPECT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | // Similar to ThreeGetsWithMaxConcurrent above, however this test adds |
| 1279 | // a fourth transaction. The third and fourth transactions have |
| 1280 | // different data ("hello!" vs "hello!hello!") and because of the |
| 1281 | // user specified priority, we expect to see them inverted in |
| 1282 | // the response from the server. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1283 | TEST_P(SpdyNetworkTransactionTest, FourGetsWithMaxConcurrentPriority) { |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1284 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1285 | scoped_ptr<SpdyFrame> req( |
| 1286 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1287 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1288 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1289 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1290 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1291 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1292 | scoped_ptr<SpdyFrame> req2( |
| 1293 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1294 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1295 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 1296 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1297 | spdy_util_.UpdateWithStreamDestruction(3); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1298 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1299 | scoped_ptr<SpdyFrame> req4( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1300 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, HIGHEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1301 | scoped_ptr<SpdyFrame> resp4(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 1302 | scoped_ptr<SpdyFrame> fbody4(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1303 | spdy_util_.UpdateWithStreamDestruction(5); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1304 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1305 | scoped_ptr<SpdyFrame> req3( |
| 1306 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 7, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1307 | scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 7)); |
| 1308 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(7, false)); |
| 1309 | scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(7, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1310 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1311 | SettingsMap settings; |
[email protected] | 9dcec24 | 2013-01-10 23:24:28 | [diff] [blame] | 1312 | const uint32 max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1313 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1314 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1315 | scoped_ptr<SpdyFrame> settings_frame( |
| 1316 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1317 | scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1318 | MockWrite writes[] = { |
| 1319 | CreateMockWrite(*req, 0), |
| 1320 | CreateMockWrite(*settings_ack, 5), |
| 1321 | // By making these synchronous, it guarantees that they are not *started* |
| 1322 | // before their sequence number, which in turn verifies that only a single |
| 1323 | // request is in-flight at a time. |
| 1324 | CreateMockWrite(*req2, 6, SYNCHRONOUS), |
| 1325 | CreateMockWrite(*req4, 10, SYNCHRONOUS), |
| 1326 | CreateMockWrite(*req3, 13, SYNCHRONOUS), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1327 | }; |
| 1328 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1329 | CreateMockRead(*settings_frame, 1), |
| 1330 | CreateMockRead(*resp, 2), |
| 1331 | CreateMockRead(*body, 3), |
| 1332 | CreateMockRead(*fbody, 4), |
| 1333 | CreateMockRead(*resp2, 7), |
| 1334 | CreateMockRead(*body2, 8), |
| 1335 | CreateMockRead(*fbody2, 9), |
| 1336 | CreateMockRead(*resp4, 11), |
| 1337 | CreateMockRead(*fbody4, 12), |
| 1338 | CreateMockRead(*resp3, 14), |
| 1339 | CreateMockRead(*body3, 15), |
| 1340 | CreateMockRead(*fbody3, 16), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1341 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1342 | MockRead(ASYNC, 0, 17), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1343 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1344 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1345 | BoundNetLog log; |
| 1346 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1347 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 1348 | BoundNetLog(), GetParam(), NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1349 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1350 | helper.AddData(&data); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1351 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1352 | scoped_ptr<HttpNetworkTransaction> trans1( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1353 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1354 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1355 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1356 | scoped_ptr<HttpNetworkTransaction> trans3( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1357 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1358 | scoped_ptr<HttpNetworkTransaction> trans4( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1359 | new HttpNetworkTransaction(HIGHEST, helper.session())); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1360 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1361 | TestCompletionCallback callback1; |
| 1362 | TestCompletionCallback callback2; |
| 1363 | TestCompletionCallback callback3; |
| 1364 | TestCompletionCallback callback4; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1365 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1366 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1367 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1368 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
| 1369 | HttpRequestInfo httpreq4 = CreateGetRequest(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1370 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1371 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1372 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1373 | // Run transaction 1 through quickly to force a read of our SETTINGS frame. |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1374 | out.rv = callback1.WaitForResult(); |
| 1375 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1376 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1377 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1378 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1379 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1380 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1381 | out.rv = trans4->Start(&httpreq4, callback4.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1382 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1383 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1384 | out.rv = callback2.WaitForResult(); |
| 1385 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1386 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1387 | out.rv = callback3.WaitForResult(); |
| 1388 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1389 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1390 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1391 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1392 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1393 | out.status_line = response1->headers->GetStatusLine(); |
| 1394 | out.response_info = *response1; |
| 1395 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 1396 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1397 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1398 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1399 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1400 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 1401 | out.status_line = response2->headers->GetStatusLine(); |
| 1402 | out.response_info = *response2; |
| 1403 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 1404 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1405 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1406 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1407 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1408 | // notice: response3 gets two hellos, response4 gets one |
| 1409 | // hello, so we know dequeuing priority was respected. |
| 1410 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 1411 | out.status_line = response3->headers->GetStatusLine(); |
| 1412 | out.response_info = *response3; |
| 1413 | out.rv = ReadTransaction(trans3.get(), &out.response_data); |
| 1414 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1415 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1416 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1417 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1418 | out.rv = callback4.WaitForResult(); |
| 1419 | EXPECT_EQ(OK, out.rv); |
| 1420 | const HttpResponseInfo* response4 = trans4->GetResponseInfo(); |
| 1421 | out.status_line = response4->headers->GetStatusLine(); |
| 1422 | out.response_info = *response4; |
| 1423 | out.rv = ReadTransaction(trans4.get(), &out.response_data); |
| 1424 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1425 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1426 | EXPECT_EQ("hello!", out.response_data); |
| 1427 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1428 | EXPECT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | // Similar to ThreeGetsMaxConcurrrent above, however, this test |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1432 | // deletes a session in the middle of the transaction to ensure |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1433 | // that we properly remove pendingcreatestream objects from |
| 1434 | // the spdy_session |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1435 | TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentDelete) { |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1436 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1437 | scoped_ptr<SpdyFrame> req( |
| 1438 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1439 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1440 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1441 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1442 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1443 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1444 | scoped_ptr<SpdyFrame> req2( |
| 1445 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1446 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1447 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 1448 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1449 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1450 | SettingsMap settings; |
[email protected] | 9dcec24 | 2013-01-10 23:24:28 | [diff] [blame] | 1451 | const uint32 max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1452 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1453 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1454 | scoped_ptr<SpdyFrame> settings_frame( |
| 1455 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1456 | scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1457 | |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1458 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1459 | CreateMockWrite(*req, 0), |
| 1460 | CreateMockWrite(*settings_ack, 5), |
| 1461 | CreateMockWrite(*req2, 6), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1462 | }; |
| 1463 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1464 | CreateMockRead(*settings_frame, 1), |
| 1465 | CreateMockRead(*resp, 2), |
| 1466 | CreateMockRead(*body, 3), |
| 1467 | CreateMockRead(*fbody, 4), |
| 1468 | CreateMockRead(*resp2, 7), |
| 1469 | CreateMockRead(*body2, 8), |
| 1470 | CreateMockRead(*fbody2, 9), |
| 1471 | MockRead(ASYNC, 0, 10), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1472 | }; |
| 1473 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1474 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1475 | |
| 1476 | BoundNetLog log; |
| 1477 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1478 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 1479 | BoundNetLog(), GetParam(), NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1480 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1481 | helper.AddData(&data); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1482 | scoped_ptr<HttpNetworkTransaction> trans1( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1483 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1484 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1485 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1486 | scoped_ptr<HttpNetworkTransaction> trans3( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1487 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1488 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1489 | TestCompletionCallback callback1; |
| 1490 | TestCompletionCallback callback2; |
| 1491 | TestCompletionCallback callback3; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1492 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1493 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1494 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1495 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1496 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1497 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1498 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1499 | // Run transaction 1 through quickly to force a read of our SETTINGS frame. |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1500 | out.rv = callback1.WaitForResult(); |
| 1501 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1502 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1503 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1504 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1505 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1506 | delete trans3.release(); |
| 1507 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
| 1508 | out.rv = callback2.WaitForResult(); |
| 1509 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1510 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1511 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 1512 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1513 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1514 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1515 | out.status_line = response1->headers->GetStatusLine(); |
| 1516 | out.response_info = *response1; |
| 1517 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 1518 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1519 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1520 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1521 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1522 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 1523 | ASSERT_TRUE(response2 != NULL); |
| 1524 | out.status_line = response2->headers->GetStatusLine(); |
| 1525 | out.response_info = *response2; |
| 1526 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 1527 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1528 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1529 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1530 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1531 | EXPECT_EQ(OK, out.rv); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1532 | } |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1533 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1534 | namespace { |
| 1535 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1536 | // The KillerCallback will delete the transaction on error as part of the |
| 1537 | // callback. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1538 | class KillerCallback : public TestCompletionCallbackBase { |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1539 | public: |
| 1540 | explicit KillerCallback(HttpNetworkTransaction* transaction) |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1541 | : transaction_(transaction), |
[email protected] | aa249b5 | 2013-04-30 01:04:32 | [diff] [blame] | 1542 | callback_(base::Bind(&KillerCallback::OnComplete, |
| 1543 | base::Unretained(this))) { |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1544 | } |
| 1545 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 1546 | ~KillerCallback() override {} |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1547 | |
| 1548 | const CompletionCallback& callback() const { return callback_; } |
| 1549 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1550 | private: |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1551 | void OnComplete(int result) { |
| 1552 | if (result < 0) |
| 1553 | delete transaction_; |
| 1554 | |
| 1555 | SetResult(result); |
| 1556 | } |
| 1557 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1558 | HttpNetworkTransaction* transaction_; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1559 | CompletionCallback callback_; |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1560 | }; |
| 1561 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1562 | } // namespace |
| 1563 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1564 | // Similar to ThreeGetsMaxConcurrrentDelete above, however, this test |
| 1565 | // closes the socket while we have a pending transaction waiting for |
| 1566 | // a pending stream creation. http://crbug.com/52901 |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1567 | TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentSocketClose) { |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1568 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1569 | scoped_ptr<SpdyFrame> req( |
| 1570 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1571 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1572 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1573 | scoped_ptr<SpdyFrame> fin_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1574 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1575 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1576 | scoped_ptr<SpdyFrame> req2( |
| 1577 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1578 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1579 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1580 | SettingsMap settings; |
[email protected] | 9dcec24 | 2013-01-10 23:24:28 | [diff] [blame] | 1581 | const uint32 max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1582 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1583 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1584 | scoped_ptr<SpdyFrame> settings_frame( |
| 1585 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1586 | scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1587 | |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1588 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1589 | CreateMockWrite(*req, 0), |
| 1590 | CreateMockWrite(*settings_ack, 5), |
| 1591 | CreateMockWrite(*req2, 6), |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1592 | }; |
| 1593 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1594 | CreateMockRead(*settings_frame, 1), |
| 1595 | CreateMockRead(*resp, 2), |
| 1596 | CreateMockRead(*body, 3), |
| 1597 | CreateMockRead(*fin_body, 4), |
| 1598 | CreateMockRead(*resp2, 7), |
| 1599 | MockRead(ASYNC, ERR_CONNECTION_RESET, 8), // Abort! |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1600 | }; |
| 1601 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1602 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 1603 | SequencedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1604 | |
| 1605 | BoundNetLog log; |
| 1606 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1607 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 1608 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1609 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1610 | helper.AddData(&data); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1611 | // We require placeholder data because three get requests are sent out, so |
| 1612 | // there needs to be three sets of SSL connection data. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1613 | helper.AddData(&data_placeholder); |
| 1614 | helper.AddData(&data_placeholder); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1615 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session()); |
| 1616 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1617 | HttpNetworkTransaction* trans3( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1618 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1619 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1620 | TestCompletionCallback callback1; |
| 1621 | TestCompletionCallback callback2; |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1622 | KillerCallback callback3(trans3); |
| 1623 | |
| 1624 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1625 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1626 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
| 1627 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1628 | out.rv = trans1.Start(&httpreq1, callback1.callback(), log); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1629 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1630 | // Run transaction 1 through quickly to force a read of our SETTINGS frame. |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1631 | out.rv = callback1.WaitForResult(); |
| 1632 | ASSERT_EQ(OK, out.rv); |
| 1633 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1634 | out.rv = trans2.Start(&httpreq2, callback2.callback(), log); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1635 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1636 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1637 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
| 1638 | out.rv = callback3.WaitForResult(); |
| 1639 | ASSERT_EQ(ERR_ABORTED, out.rv); |
| 1640 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1641 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
| 1642 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1643 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1644 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1645 | out.status_line = response1->headers->GetStatusLine(); |
| 1646 | out.response_info = *response1; |
| 1647 | out.rv = ReadTransaction(&trans1, &out.response_data); |
| 1648 | EXPECT_EQ(OK, out.rv); |
| 1649 | |
| 1650 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 1651 | ASSERT_TRUE(response2 != NULL); |
| 1652 | out.status_line = response2->headers->GetStatusLine(); |
| 1653 | out.response_info = *response2; |
| 1654 | out.rv = ReadTransaction(&trans2, &out.response_data); |
| 1655 | EXPECT_EQ(ERR_CONNECTION_RESET, out.rv); |
| 1656 | |
| 1657 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1658 | } |
| 1659 | |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1660 | // Test that a simple PUT request works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1661 | TEST_P(SpdyNetworkTransactionTest, Put) { |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1662 | // Setup the request |
| 1663 | HttpRequestInfo request; |
| 1664 | request.method = "PUT"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1665 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1666 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1667 | scoped_ptr<SpdyHeaderBlock> put_headers( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1668 | spdy_util_.ConstructPutHeaderBlock(GetDefaultUrl(), 0)); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1669 | scoped_ptr<SpdyFrame> req( |
| 1670 | spdy_util_.ConstructSpdySyn(1, *put_headers, LOWEST, false, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1671 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1672 | CreateMockWrite(*req, 0), |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1673 | }; |
| 1674 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1675 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1676 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1677 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1678 | CreateMockRead(*resp, 1), |
| 1679 | CreateMockRead(*body, 2), |
| 1680 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1681 | }; |
| 1682 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1683 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1684 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1685 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1686 | helper.RunToCompletion(&data); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1687 | TransactionHelperResult out = helper.output(); |
| 1688 | |
| 1689 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1690 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | // Test that a simple HEAD request works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1694 | TEST_P(SpdyNetworkTransactionTest, Head) { |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1695 | // Setup the request |
| 1696 | HttpRequestInfo request; |
| 1697 | request.method = "HEAD"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1698 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1699 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1700 | scoped_ptr<SpdyHeaderBlock> head_headers( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1701 | spdy_util_.ConstructHeadHeaderBlock(GetDefaultUrl(), 0)); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1702 | scoped_ptr<SpdyFrame> req( |
| 1703 | spdy_util_.ConstructSpdySyn(1, *head_headers, LOWEST, false, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1704 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1705 | CreateMockWrite(*req, 0), |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1706 | }; |
| 1707 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1708 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1709 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1710 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1711 | CreateMockRead(*resp, 1), |
| 1712 | CreateMockRead(*body, 2), |
| 1713 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1714 | }; |
| 1715 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1716 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1717 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1718 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1719 | helper.RunToCompletion(&data); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1720 | TransactionHelperResult out = helper.output(); |
| 1721 | |
| 1722 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1723 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1724 | } |
| 1725 | |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 1726 | // Test that a simple POST works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1727 | TEST_P(SpdyNetworkTransactionTest, Post) { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1728 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 1729 | GetDefaultUrl(), 1, kUploadDataSize, LOWEST, NULL, 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1730 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1731 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1732 | CreateMockWrite(*req, 0), CreateMockWrite(*body, 1), // POST upload frame |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1733 | }; |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 1734 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1735 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1736 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1737 | CreateMockRead(*resp, 2), |
| 1738 | CreateMockRead(*body, 3), |
| 1739 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 1740 | }; |
| 1741 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1742 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1743 | NormalSpdyTransactionHelper helper(CreatePostRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1744 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1745 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1746 | TransactionHelperResult out = helper.output(); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 1747 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1748 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 1749 | EXPECT_EQ("hello!", out.response_data); |
| 1750 | } |
| 1751 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1752 | // Test that a POST with a file works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1753 | TEST_P(SpdyNetworkTransactionTest, FilePost) { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1754 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 1755 | GetDefaultUrl(), 1, kUploadDataSize, LOWEST, NULL, 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1756 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1757 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1758 | CreateMockWrite(*req, 0), CreateMockWrite(*body, 1), // POST upload frame |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1759 | }; |
| 1760 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1761 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1762 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1763 | CreateMockRead(*resp, 2), |
| 1764 | CreateMockRead(*body, 3), |
| 1765 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1766 | }; |
| 1767 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1768 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1769 | NormalSpdyTransactionHelper helper(CreateFilePostRequest(), DEFAULT_PRIORITY, |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1770 | BoundNetLog(), GetParam(), NULL); |
| 1771 | helper.RunToCompletion(&data); |
| 1772 | TransactionHelperResult out = helper.output(); |
| 1773 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1774 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1775 | EXPECT_EQ("hello!", out.response_data); |
| 1776 | } |
| 1777 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1778 | // Test that a POST with a unreadable file fails. |
| 1779 | TEST_P(SpdyNetworkTransactionTest, UnreadableFilePost) { |
| 1780 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1781 | MockWrite(ASYNC, 0, 0) // EOF |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1782 | }; |
| 1783 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1784 | MockRead(ASYNC, 0, 1) // EOF |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1785 | }; |
| 1786 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1787 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1788 | NormalSpdyTransactionHelper helper(CreateUnreadableFilePostRequest(), |
| 1789 | DEFAULT_PRIORITY, |
| 1790 | BoundNetLog(), GetParam(), NULL); |
| 1791 | helper.RunPreTestSetup(); |
| 1792 | helper.AddData(&data); |
| 1793 | helper.RunDefaultTest(); |
| 1794 | |
| 1795 | base::RunLoop().RunUntilIdle(); |
| 1796 | helper.VerifyDataNotConsumed(); |
| 1797 | EXPECT_EQ(ERR_ACCESS_DENIED, helper.output().rv); |
| 1798 | } |
| 1799 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1800 | // Test that a complex POST works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1801 | TEST_P(SpdyNetworkTransactionTest, ComplexPost) { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1802 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 1803 | GetDefaultUrl(), 1, kUploadDataSize, LOWEST, NULL, 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1804 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1805 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1806 | CreateMockWrite(*req, 0), CreateMockWrite(*body, 1), // POST upload frame |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1807 | }; |
| 1808 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1809 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1810 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1811 | CreateMockRead(*resp, 2), |
| 1812 | CreateMockRead(*body, 3), |
| 1813 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1814 | }; |
| 1815 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1816 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1817 | NormalSpdyTransactionHelper helper(CreateComplexPostRequest(), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1818 | DEFAULT_PRIORITY, |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1819 | BoundNetLog(), GetParam(), NULL); |
| 1820 | helper.RunToCompletion(&data); |
| 1821 | TransactionHelperResult out = helper.output(); |
| 1822 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1823 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1824 | EXPECT_EQ("hello!", out.response_data); |
| 1825 | } |
| 1826 | |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1827 | // Test that a chunked POST works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1828 | TEST_P(SpdyNetworkTransactionTest, ChunkedPost) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1829 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1830 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1831 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1832 | CreateMockWrite(*req, 0), CreateMockWrite(*body, 1), |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1833 | }; |
| 1834 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1835 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1836 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1837 | CreateMockRead(*resp, 2), |
| 1838 | CreateMockRead(*body, 3), |
| 1839 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1840 | }; |
| 1841 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1842 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1843 | NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1844 | DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1845 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1846 | |
| 1847 | // These chunks get merged into a single frame when being sent. |
| 1848 | const int kFirstChunkSize = kUploadDataSize/2; |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1849 | upload_chunked_data_stream()->AppendData(kUploadData, kFirstChunkSize, false); |
| 1850 | upload_chunked_data_stream()->AppendData( |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1851 | kUploadData + kFirstChunkSize, kUploadDataSize - kFirstChunkSize, true); |
| 1852 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1853 | helper.RunToCompletion(&data); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1854 | TransactionHelperResult out = helper.output(); |
| 1855 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1856 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1857 | EXPECT_EQ(kUploadData, out.response_data); |
| 1858 | } |
| 1859 | |
| 1860 | // Test that a chunked POST works with chunks appended after transaction starts. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1861 | TEST_P(SpdyNetworkTransactionTest, DelayedChunkedPost) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1862 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1863 | scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1864 | scoped_ptr<SpdyFrame> chunk2(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1865 | scoped_ptr<SpdyFrame> chunk3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1866 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1867 | CreateMockWrite(*req, 0), |
| 1868 | CreateMockWrite(*chunk1, 1), |
| 1869 | CreateMockWrite(*chunk2, 2), |
| 1870 | CreateMockWrite(*chunk3, 3), |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1871 | }; |
| 1872 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1873 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1874 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1875 | CreateMockRead(*resp, 4), |
| 1876 | CreateMockRead(*chunk1, 5), |
| 1877 | CreateMockRead(*chunk2, 6), |
| 1878 | CreateMockRead(*chunk3, 7), |
| 1879 | MockRead(ASYNC, 0, 8) // EOF |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1880 | }; |
| 1881 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1882 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1883 | NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1884 | DEFAULT_PRIORITY, |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1885 | BoundNetLog(), GetParam(), NULL); |
| 1886 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1887 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, false); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1888 | |
| 1889 | helper.RunPreTestSetup(); |
| 1890 | helper.AddData(&data); |
| 1891 | ASSERT_TRUE(helper.StartDefaultTest()); |
| 1892 | |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 1893 | base::RunLoop().RunUntilIdle(); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1894 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, false); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 1895 | base::RunLoop().RunUntilIdle(); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1896 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, true); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1897 | |
| 1898 | helper.FinishDefaultTest(); |
| 1899 | helper.VerifyDataConsumed(); |
| 1900 | |
| 1901 | std::string expected_response; |
| 1902 | expected_response += kUploadData; |
| 1903 | expected_response += kUploadData; |
| 1904 | expected_response += kUploadData; |
| 1905 | |
| 1906 | TransactionHelperResult out = helper.output(); |
| 1907 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1908 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1909 | EXPECT_EQ(expected_response, out.response_data); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1910 | } |
| 1911 | |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1912 | // Test that a POST without any post data works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1913 | TEST_P(SpdyNetworkTransactionTest, NullPost) { |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1914 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1915 | // Setup the request |
| 1916 | HttpRequestInfo request; |
| 1917 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1918 | request.url = GURL(GetDefaultUrl()); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1919 | // Create an empty UploadData. |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1920 | request.upload_data_stream = NULL; |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1921 | |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1922 | // When request.upload_data_stream is NULL for post, content-length is |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1923 | // expected to be 0. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1924 | scoped_ptr<SpdyHeaderBlock> req_block( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1925 | spdy_util_.ConstructPostHeaderBlock(GetDefaultUrl(), 0)); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1926 | scoped_ptr<SpdyFrame> req( |
| 1927 | spdy_util_.ConstructSpdySyn(1, *req_block, LOWEST, false, true)); |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1928 | |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1929 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1930 | CreateMockWrite(*req, 0), |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1931 | }; |
| 1932 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1933 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 1934 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1935 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1936 | CreateMockRead(*resp, 1), |
| 1937 | CreateMockRead(*body, 2), |
| 1938 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1939 | }; |
| 1940 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1941 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1942 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1943 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1944 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1945 | helper.RunToCompletion(&data); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1946 | TransactionHelperResult out = helper.output(); |
| 1947 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1948 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1949 | EXPECT_EQ("hello!", out.response_data); |
| 1950 | } |
| 1951 | |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1952 | // Test that a simple POST works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1953 | TEST_P(SpdyNetworkTransactionTest, EmptyPost) { |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1954 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1955 | // Create an empty UploadDataStream. |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1956 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 1957 | ElementsUploadDataStream stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1958 | |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1959 | // Setup the request |
| 1960 | HttpRequestInfo request; |
| 1961 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1962 | request.url = GURL(GetDefaultUrl()); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1963 | request.upload_data_stream = &stream; |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1964 | |
[email protected] | ad91dc5 | 2012-09-01 03:46:06 | [diff] [blame] | 1965 | const uint64 kContentLength = 0; |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1966 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1967 | scoped_ptr<SpdyHeaderBlock> req_block( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1968 | spdy_util_.ConstructPostHeaderBlock(GetDefaultUrl(), kContentLength)); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1969 | scoped_ptr<SpdyFrame> req( |
| 1970 | spdy_util_.ConstructSpdySyn(1, *req_block, LOWEST, false, true)); |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1971 | |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1972 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1973 | CreateMockWrite(*req, 0), |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1974 | }; |
| 1975 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1976 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 1977 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1978 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1979 | CreateMockRead(*resp, 1), |
| 1980 | CreateMockRead(*body, 2), |
| 1981 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1982 | }; |
| 1983 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1984 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 1985 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1986 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 1987 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1988 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1989 | TransactionHelperResult out = helper.output(); |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1990 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1991 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1992 | EXPECT_EQ("hello!", out.response_data); |
| 1993 | } |
| 1994 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1995 | // While we're doing a post, the server sends the reply before upload completes. |
| 1996 | TEST_P(SpdyNetworkTransactionTest, ResponseBeforePostCompletes) { |
| 1997 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1998 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 1999 | MockWrite writes[] = { |
| 2000 | CreateMockWrite(*req, 0), |
| 2001 | CreateMockWrite(*body, 3), |
| 2002 | }; |
| 2003 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | a5566f970 | 2010-05-05 22:25:43 | [diff] [blame] | 2004 | MockRead reads[] = { |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 2005 | CreateMockRead(*resp, 1), |
| 2006 | CreateMockRead(*body, 2), |
[email protected] | 099bc7e | 2013-07-18 04:19:16 | [diff] [blame] | 2007 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | a5566f970 | 2010-05-05 22:25:43 | [diff] [blame] | 2008 | }; |
| 2009 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 2010 | // Write the request headers, and read the complete response |
| 2011 | // while still waiting for chunked request data. |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 2012 | DeterministicSocketData data(reads, arraysize(reads), |
| 2013 | writes, arraysize(writes)); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 2014 | NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
| 2015 | DEFAULT_PRIORITY, |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 2016 | BoundNetLog(), GetParam(), NULL); |
| 2017 | helper.SetDeterministic(); |
| 2018 | helper.RunPreTestSetup(); |
| 2019 | helper.AddDeterministicData(&data); |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 2020 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 2021 | ASSERT_TRUE(helper.StartDefaultTest()); |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 2022 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 2023 | // Process the request headers, SYN_REPLY, and response body. |
| 2024 | // The request body is still in flight. |
| 2025 | data.RunFor(3); |
| 2026 | |
| 2027 | const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2028 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 2029 | |
| 2030 | // Finish sending the request body. |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 2031 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, true); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 2032 | data.RunFor(2); |
| 2033 | |
| 2034 | std::string response_body; |
| 2035 | EXPECT_EQ(OK, ReadTransaction(helper.trans(), &response_body)); |
| 2036 | EXPECT_EQ(kUploadData, response_body); |
| 2037 | helper.VerifyDataConsumed(); |
[email protected] | a5566f970 | 2010-05-05 22:25:43 | [diff] [blame] | 2038 | } |
| 2039 | |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2040 | // The client upon cancellation tries to send a RST_STREAM frame. The mock |
| 2041 | // socket causes the TCP write to return zero. This test checks that the client |
| 2042 | // tries to queue up the RST_STREAM frame again. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2043 | TEST_P(SpdyNetworkTransactionTest, SocketWriteReturnsZero) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2044 | scoped_ptr<SpdyFrame> req( |
| 2045 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2046 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2047 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2048 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2049 | CreateMockWrite(*req.get(), 0, SYNCHRONOUS), |
| 2050 | MockWrite(SYNCHRONOUS, 0, 0, 2), |
| 2051 | CreateMockWrite(*rst.get(), 3, SYNCHRONOUS), |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2052 | }; |
| 2053 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2054 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2055 | MockRead reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2056 | CreateMockRead(*resp.get(), 1, ASYNC), |
| 2057 | MockRead(ASYNC, 0, 0, 4) // EOF |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2058 | }; |
| 2059 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2060 | DeterministicSocketData data(reads, arraysize(reads), |
| 2061 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2062 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2063 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2064 | helper.SetDeterministic(); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2065 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2066 | helper.AddDeterministicData(&data); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2067 | HttpNetworkTransaction* trans = helper.trans(); |
| 2068 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2069 | TestCompletionCallback callback; |
| 2070 | int rv = trans->Start( |
| 2071 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2072 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2073 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2074 | data.SetStop(2); |
| 2075 | data.Run(); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2076 | helper.ResetTrans(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2077 | data.SetStop(20); |
| 2078 | data.Run(); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2079 | |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2080 | helper.VerifyDataConsumed(); |
| 2081 | } |
| 2082 | |
[email protected] | 9330067 | 2009-10-24 13:22:51 | [diff] [blame] | 2083 | // Test that the transaction doesn't crash when we don't have a reply. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2084 | TEST_P(SpdyNetworkTransactionTest, ResponseWithoutSynReply) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2085 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 2086 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2087 | CreateMockRead(*body, 1), MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 9330067 | 2009-10-24 13:22:51 | [diff] [blame] | 2088 | }; |
| 2089 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2090 | scoped_ptr<SpdyFrame> req( |
| 2091 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2092 | scoped_ptr<SpdyFrame> rst( |
| 2093 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 2094 | MockWrite writes[] = { |
| 2095 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 2), |
| 2096 | }; |
| 2097 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2098 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2099 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2100 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2101 | TransactionHelperResult out = helper.output(); |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 2102 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | 9330067 | 2009-10-24 13:22:51 | [diff] [blame] | 2103 | } |
| 2104 | |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2105 | // Test that the transaction doesn't crash when we get two replies on the same |
| 2106 | // stream ID. See http://crbug.com/45639. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2107 | TEST_P(SpdyNetworkTransactionTest, ResponseWithTwoSynReplies) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2108 | scoped_ptr<SpdyFrame> req( |
| 2109 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 2110 | scoped_ptr<SpdyFrame> rst( |
[email protected] | 00b2947 | 2014-01-16 18:10:24 | [diff] [blame] | 2111 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 2112 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2113 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 4), |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 2114 | }; |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2115 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2116 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2117 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2118 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2119 | CreateMockRead(*resp, 1), |
| 2120 | CreateMockRead(*resp, 2), |
| 2121 | CreateMockRead(*body, 3), |
| 2122 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2123 | }; |
| 2124 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2125 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2126 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2127 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2128 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2129 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2130 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2131 | |
| 2132 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2133 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2134 | TestCompletionCallback callback; |
| 2135 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2136 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2137 | rv = callback.WaitForResult(); |
| 2138 | EXPECT_EQ(OK, rv); |
| 2139 | |
| 2140 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | a5c493b9 | 2010-08-06 23:04:29 | [diff] [blame] | 2141 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2142 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2143 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 2144 | std::string response_data; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2145 | rv = ReadTransaction(trans, &response_data); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2146 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, rv); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2147 | |
| 2148 | helper.VerifyDataConsumed(); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2149 | } |
| 2150 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2151 | TEST_P(SpdyNetworkTransactionTest, ResetReplyWithTransferEncoding) { |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2152 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2153 | scoped_ptr<SpdyFrame> req( |
| 2154 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 2155 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2156 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2157 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2158 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 2), |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2159 | }; |
| 2160 | |
| 2161 | const char* const headers[] = { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2162 | "transfer-encoding", "chunked" |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2163 | }; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2164 | scoped_ptr<SpdyFrame> resp( |
| 2165 | spdy_util_.ConstructSpdyGetSynReply(headers, 1, 1)); |
| 2166 | scoped_ptr<SpdyFrame> body( |
| 2167 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2168 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2169 | CreateMockRead(*resp, 1), |
| 2170 | CreateMockRead(*body, 3), |
| 2171 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2172 | }; |
| 2173 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2174 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2175 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2176 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2177 | helper.RunToCompletion(&data); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2178 | TransactionHelperResult out = helper.output(); |
| 2179 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 2180 | |
| 2181 | helper.session()->spdy_session_pool()->CloseAllSessions(); |
| 2182 | helper.VerifyDataConsumed(); |
| 2183 | } |
| 2184 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2185 | TEST_P(SpdyNetworkTransactionTest, ResetPushWithTransferEncoding) { |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2186 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2187 | scoped_ptr<SpdyFrame> req( |
| 2188 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 2189 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2190 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2191 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2192 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 4), |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2193 | }; |
| 2194 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2195 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2196 | const char* const headers[] = { |
| 2197 | "transfer-encoding", "chunked" |
| 2198 | }; |
| 2199 | scoped_ptr<SpdyFrame> push( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2200 | spdy_util_.ConstructSpdyPush(headers, arraysize(headers) / 2, 2, 1, |
| 2201 | GetDefaultUrlWithPath("/1").c_str())); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2202 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2203 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2204 | CreateMockRead(*resp, 1), |
| 2205 | CreateMockRead(*push, 2), |
| 2206 | CreateMockRead(*body, 3), |
| 2207 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2208 | }; |
| 2209 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2210 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2211 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2212 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2213 | helper.RunToCompletion(&data); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2214 | TransactionHelperResult out = helper.output(); |
| 2215 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2216 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2217 | EXPECT_EQ("hello!", out.response_data); |
| 2218 | |
| 2219 | helper.session()->spdy_session_pool()->CloseAllSessions(); |
| 2220 | helper.VerifyDataConsumed(); |
| 2221 | } |
| 2222 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2223 | TEST_P(SpdyNetworkTransactionTest, CancelledTransaction) { |
[email protected] | 75f30cc2 | 2010-06-28 21:41:38 | [diff] [blame] | 2224 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2225 | scoped_ptr<SpdyFrame> req( |
| 2226 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2227 | MockWrite writes[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2228 | CreateMockWrite(*req), |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2229 | }; |
| 2230 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2231 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2232 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2233 | CreateMockRead(*resp), |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2234 | // This following read isn't used by the test, except during the |
[email protected] | b4c62eb | 2012-11-14 18:36:51 | [diff] [blame] | 2235 | // RunUntilIdle() call at the end since the SpdySession survives the |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2236 | // HttpNetworkTransaction and still tries to continue Read()'ing. Any |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2237 | // MockRead will do here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2238 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2239 | }; |
| 2240 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2241 | StaticSocketDataProvider data(reads, arraysize(reads), |
| 2242 | writes, arraysize(writes)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2243 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2244 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2245 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2246 | helper.RunPreTestSetup(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2247 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2248 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2249 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2250 | TestCompletionCallback callback; |
| 2251 | int rv = trans->Start( |
| 2252 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2253 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2254 | helper.ResetTrans(); // Cancel the transaction. |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2255 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 2256 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2257 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2258 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2259 | helper.VerifyDataNotConsumed(); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2260 | } |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 2261 | |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2262 | // Verify that the client sends a Rst Frame upon cancelling the stream. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2263 | TEST_P(SpdyNetworkTransactionTest, CancelledTransactionSendRst) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2264 | scoped_ptr<SpdyFrame> req( |
| 2265 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2266 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2267 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2268 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2269 | CreateMockWrite(*req, 0, SYNCHRONOUS), |
| 2270 | CreateMockWrite(*rst, 2, SYNCHRONOUS), |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2271 | }; |
| 2272 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2273 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2274 | MockRead reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2275 | CreateMockRead(*resp, 1, ASYNC), |
| 2276 | MockRead(ASYNC, 0, 0, 3) // EOF |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2277 | }; |
| 2278 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2279 | DeterministicSocketData data(reads, arraysize(reads), |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2280 | writes, arraysize(writes)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2281 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2282 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2283 | BoundNetLog(), |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2284 | GetParam(), NULL); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2285 | helper.SetDeterministic(); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2286 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2287 | helper.AddDeterministicData(&data); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2288 | HttpNetworkTransaction* trans = helper.trans(); |
| 2289 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2290 | TestCompletionCallback callback; |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2291 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2292 | int rv = trans->Start( |
| 2293 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2294 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2295 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2296 | data.SetStop(2); |
| 2297 | data.Run(); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2298 | helper.ResetTrans(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2299 | data.SetStop(20); |
| 2300 | data.Run(); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2301 | |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2302 | helper.VerifyDataConsumed(); |
| 2303 | } |
| 2304 | |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2305 | // Verify that the client can correctly deal with the user callback attempting |
| 2306 | // to start another transaction on a session that is closing down. See |
| 2307 | // http://crbug.com/47455 |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2308 | TEST_P(SpdyNetworkTransactionTest, StartTransactionOnReadCallback) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2309 | scoped_ptr<SpdyFrame> req( |
| 2310 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2311 | MockWrite writes[] = {CreateMockWrite(*req)}; |
| 2312 | MockWrite writes2[] = {CreateMockWrite(*req, 0)}; |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2313 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 2314 | // The indicated length of this frame is longer than its actual length. When |
| 2315 | // the session receives an empty frame after this one, it shuts down the |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2316 | // session, and calls the read callback with the incomplete data. |
| 2317 | const uint8 kGetBodyFrame2[] = { |
| 2318 | 0x00, 0x00, 0x00, 0x01, |
| 2319 | 0x01, 0x00, 0x00, 0x07, |
| 2320 | 'h', 'e', 'l', 'l', 'o', '!', |
| 2321 | }; |
| 2322 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2323 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2324 | MockRead reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 2325 | CreateMockRead(*resp, 1), |
| 2326 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause |
| 2327 | MockRead(ASYNC, reinterpret_cast<const char*>(kGetBodyFrame2), |
| 2328 | arraysize(kGetBodyFrame2), 3), |
| 2329 | MockRead(ASYNC, ERR_IO_PENDING, 4), // Force a pause |
| 2330 | MockRead(ASYNC, 0, 0, 5), // EOF |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2331 | }; |
| 2332 | MockRead reads2[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2333 | CreateMockRead(*resp, 1), MockRead(ASYNC, 0, 0, 2), // EOF |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2334 | }; |
| 2335 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 2336 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2337 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 2338 | arraysize(writes2)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2339 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2340 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2341 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2342 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2343 | helper.AddData(&data); |
| 2344 | helper.AddData(&data2); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2345 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2346 | |
| 2347 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2348 | TestCompletionCallback callback; |
| 2349 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2350 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2351 | rv = callback.WaitForResult(); |
| 2352 | |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2353 | const int kSize = 3000; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 2354 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSize)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2355 | rv = trans->Read( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2356 | buf.get(), kSize, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2357 | base::Bind(&SpdyNetworkTransactionTest::StartTransactionCallback, |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2358 | helper.session(), GURL(GetDefaultUrl()))); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 2359 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2360 | // This forces an err_IO_pending, which sets the callback. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2361 | data.CompleteRead(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2362 | // This finishes the read. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2363 | data.CompleteRead(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2364 | helper.VerifyDataConsumed(); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2365 | } |
| 2366 | |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2367 | // Verify that the client can correctly deal with the user callback deleting the |
| 2368 | // transaction. Failures will usually be valgrind errors. See |
| 2369 | // http://crbug.com/46925 |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2370 | TEST_P(SpdyNetworkTransactionTest, DeleteSessionOnReadCallback) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2371 | scoped_ptr<SpdyFrame> req( |
| 2372 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 2373 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2374 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2375 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2376 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2377 | MockRead reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 2378 | CreateMockRead(*resp.get(), 1), |
| 2379 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause |
| 2380 | CreateMockRead(*body.get(), 3), |
| 2381 | MockRead(ASYNC, 0, 0, 4), // EOF |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2382 | }; |
| 2383 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 2384 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2385 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2386 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2387 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2388 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2389 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2390 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2391 | |
| 2392 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2393 | TestCompletionCallback callback; |
| 2394 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2395 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2396 | rv = callback.WaitForResult(); |
| 2397 | |
| 2398 | // Setup a user callback which will delete the session, and clear out the |
| 2399 | // memory holding the stream object. Note that the callback deletes trans. |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2400 | const int kSize = 3000; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 2401 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSize)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2402 | rv = trans->Read( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2403 | buf.get(), |
| 2404 | kSize, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2405 | base::Bind(&SpdyNetworkTransactionTest::DeleteSessionCallback, |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2406 | base::Unretained(&helper))); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2407 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2408 | data.CompleteRead(); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2409 | |
| 2410 | // Finish running rest of tasks. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2411 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2412 | helper.VerifyDataConsumed(); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2413 | } |
| 2414 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2415 | // Send a spdy request to www.example.org that gets redirected to www.foo.com. |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2416 | TEST_P(SpdyNetworkTransactionTest, DISABLED_RedirectGetRequest) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2417 | scoped_ptr<SpdyHeaderBlock> headers( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2418 | spdy_util_.ConstructGetHeaderBlock(GetDefaultUrl())); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2419 | (*headers)["user-agent"] = ""; |
jgraettinger | 8f00db8b | 2014-09-24 23:00:06 | [diff] [blame] | 2420 | (*headers)["accept-encoding"] = "gzip, deflate"; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2421 | scoped_ptr<SpdyHeaderBlock> headers2( |
| 2422 | spdy_util_.ConstructGetHeaderBlock("http://www.foo.com/index.php")); |
| 2423 | (*headers2)["user-agent"] = ""; |
jgraettinger | 8f00db8b | 2014-09-24 23:00:06 | [diff] [blame] | 2424 | (*headers2)["accept-encoding"] = "gzip, deflate"; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2425 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2426 | // Setup writes/reads to www.example.org |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 2427 | scoped_ptr<SpdyFrame> req( |
| 2428 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
| 2429 | scoped_ptr<SpdyFrame> req2( |
| 2430 | spdy_util_.ConstructSpdySyn(1, *headers2, LOWEST, false, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2431 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReplyRedirect(1)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2432 | MockWrite writes[] = { |
| 2433 | CreateMockWrite(*req, 1), |
| 2434 | }; |
| 2435 | MockRead reads[] = { |
| 2436 | CreateMockRead(*resp, 2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2437 | MockRead(ASYNC, 0, 0, 3) // EOF |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2438 | }; |
| 2439 | |
| 2440 | // Setup writes/reads to www.foo.com |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2441 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2442 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2443 | MockWrite writes2[] = { |
| 2444 | CreateMockWrite(*req2, 1), |
| 2445 | }; |
| 2446 | MockRead reads2[] = { |
| 2447 | CreateMockRead(*resp2, 2), |
| 2448 | CreateMockRead(*body2, 3), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2449 | MockRead(ASYNC, 0, 0, 4) // EOF |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2450 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2451 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2452 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 2453 | arraysize(writes2)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2454 | |
| 2455 | // TODO(erikchen): Make test support SPDYSSL, SPDYNPN |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2456 | TestDelegate d; |
| 2457 | { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2458 | SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); |
davidben | 151423e | 2015-03-23 18:48:36 | [diff] [blame] | 2459 | scoped_ptr<URLRequest> r(spdy_url_request_context.CreateRequest( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2460 | GURL(GetDefaultUrl()), DEFAULT_PRIORITY, &d)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2461 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2462 | AddSocketDataProvider(&data); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2463 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2464 | AddSocketDataProvider(&data2); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2465 | |
| 2466 | d.set_quit_on_redirect(true); |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2467 | r->Start(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2468 | base::RunLoop().Run(); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2469 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2470 | EXPECT_EQ(1, d.received_redirect_count()); |
| 2471 | |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2472 | r->FollowDeferredRedirect(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2473 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2474 | EXPECT_EQ(1, d.response_started_count()); |
| 2475 | EXPECT_FALSE(d.received_data_before_response()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 2476 | EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2477 | std::string contents("hello!"); |
| 2478 | EXPECT_EQ(contents, d.data_received()); |
| 2479 | } |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 2480 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2481 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 2482 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 2483 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2484 | } |
| 2485 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2486 | // 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] | 2487 | // www.foo.com. |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2488 | TEST_P(SpdyNetworkTransactionTest, DISABLED_RedirectServerPush) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2489 | scoped_ptr<SpdyHeaderBlock> headers( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2490 | spdy_util_.ConstructGetHeaderBlock(GetDefaultUrl())); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2491 | (*headers)["user-agent"] = ""; |
jgraettinger | 8f00db8b | 2014-09-24 23:00:06 | [diff] [blame] | 2492 | (*headers)["accept-encoding"] = "gzip, deflate"; |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2493 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2494 | // Setup writes/reads to www.example.org |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2495 | scoped_ptr<SpdyFrame> req( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 2496 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2497 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2498 | scoped_ptr<SpdyFrame> rep(spdy_util_.ConstructSpdyPush( |
| 2499 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str(), |
| 2500 | "301 Moved Permanently", "http://www.foo.com/index.php")); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2501 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2502 | scoped_ptr<SpdyFrame> rst( |
| 2503 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_CANCEL)); |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2504 | MockWrite writes[] = { |
| 2505 | CreateMockWrite(*req, 1), |
| 2506 | CreateMockWrite(*rst, 6), |
| 2507 | }; |
| 2508 | MockRead reads[] = { |
| 2509 | CreateMockRead(*resp, 2), |
| 2510 | CreateMockRead(*rep, 3), |
| 2511 | CreateMockRead(*body, 4), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2512 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
| 2513 | MockRead(ASYNC, 0, 0, 7) // EOF |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2514 | }; |
| 2515 | |
| 2516 | // Setup writes/reads to www.foo.com |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2517 | scoped_ptr<SpdyHeaderBlock> headers2( |
| 2518 | spdy_util_.ConstructGetHeaderBlock("http://www.foo.com/index.php")); |
| 2519 | (*headers2)["user-agent"] = ""; |
jgraettinger | 8f00db8b | 2014-09-24 23:00:06 | [diff] [blame] | 2520 | (*headers2)["accept-encoding"] = "gzip, deflate"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2521 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 2522 | spdy_util_.ConstructSpdySyn(1, *headers2, LOWEST, false, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2523 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2524 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2525 | MockWrite writes2[] = { |
| 2526 | CreateMockWrite(*req2, 1), |
| 2527 | }; |
| 2528 | MockRead reads2[] = { |
| 2529 | CreateMockRead(*resp2, 2), |
| 2530 | CreateMockRead(*body2, 3), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2531 | MockRead(ASYNC, 0, 0, 5) // EOF |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2532 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2533 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2534 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 2535 | arraysize(writes2)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2536 | |
| 2537 | // TODO(erikchen): Make test support SPDYSSL, SPDYNPN |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2538 | TestDelegate d; |
| 2539 | TestDelegate d2; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2540 | SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2541 | { |
davidben | 151423e | 2015-03-23 18:48:36 | [diff] [blame] | 2542 | scoped_ptr<URLRequest> r(spdy_url_request_context.CreateRequest( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2543 | GURL(GetDefaultUrl()), DEFAULT_PRIORITY, &d)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2544 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2545 | AddSocketDataProvider(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2546 | |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2547 | r->Start(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2548 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2549 | |
| 2550 | EXPECT_EQ(0, d.received_redirect_count()); |
| 2551 | std::string contents("hello!"); |
| 2552 | EXPECT_EQ(contents, d.data_received()); |
| 2553 | |
davidben | 151423e | 2015-03-23 18:48:36 | [diff] [blame] | 2554 | scoped_ptr<URLRequest> r2(spdy_url_request_context.CreateRequest( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2555 | GURL(GetDefaultUrlWithPath("/foo.dat")), DEFAULT_PRIORITY, &d2)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2556 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2557 | AddSocketDataProvider(&data2); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2558 | |
| 2559 | d2.set_quit_on_redirect(true); |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2560 | r2->Start(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2561 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2562 | EXPECT_EQ(1, d2.received_redirect_count()); |
| 2563 | |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2564 | r2->FollowDeferredRedirect(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2565 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2566 | EXPECT_EQ(1, d2.response_started_count()); |
| 2567 | EXPECT_FALSE(d2.received_data_before_response()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 2568 | EXPECT_EQ(URLRequestStatus::SUCCESS, r2->status().status()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2569 | std::string contents2("hello!"); |
| 2570 | EXPECT_EQ(contents2, d2.data_received()); |
| 2571 | } |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2572 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2573 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 2574 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 2575 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2576 | } |
| 2577 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2578 | TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2579 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2580 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2581 | scoped_ptr<SpdyFrame> stream1_body( |
| 2582 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2583 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2584 | CreateMockWrite(*stream1_syn, 0), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2585 | }; |
| 2586 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2587 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2588 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2589 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2590 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2591 | const char kPushedData[] = "pushed"; |
| 2592 | scoped_ptr<SpdyFrame> stream2_body( |
| 2593 | spdy_util_.ConstructSpdyBodyFrame( |
| 2594 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2595 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2596 | CreateMockRead(*stream1_reply, 1), |
| 2597 | CreateMockRead(*stream2_syn, 2), |
| 2598 | CreateMockRead(*stream1_body, 3, SYNCHRONOUS), |
| 2599 | CreateMockRead(*stream2_body, 4), |
| 2600 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2601 | }; |
| 2602 | |
| 2603 | HttpResponseInfo response; |
| 2604 | HttpResponseInfo response2; |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2605 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2606 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2607 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2608 | &response, |
| 2609 | &response2, |
| 2610 | expected_push_result); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2611 | |
| 2612 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2613 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2614 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2615 | |
| 2616 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2617 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2618 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2619 | } |
| 2620 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2621 | TEST_P(SpdyNetworkTransactionTest, ServerPushBeforeSynReply) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2622 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2623 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2624 | scoped_ptr<SpdyFrame> stream1_body( |
| 2625 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2626 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2627 | CreateMockWrite(*stream1_syn, 0), |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2628 | }; |
| 2629 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2630 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2631 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2632 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2633 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2634 | const char kPushedData[] = "pushed"; |
| 2635 | scoped_ptr<SpdyFrame> stream2_body( |
| 2636 | spdy_util_.ConstructSpdyBodyFrame( |
| 2637 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2638 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2639 | CreateMockRead(*stream2_syn, 1), |
| 2640 | CreateMockRead(*stream1_reply, 2), |
| 2641 | CreateMockRead(*stream1_body, 3, SYNCHRONOUS), |
| 2642 | CreateMockRead(*stream2_body, 4), |
| 2643 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2644 | }; |
| 2645 | |
| 2646 | HttpResponseInfo response; |
| 2647 | HttpResponseInfo response2; |
| 2648 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2649 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2650 | RunServerPushTest(&data, |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2651 | &response, |
| 2652 | &response2, |
| 2653 | expected_push_result); |
| 2654 | |
| 2655 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2656 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2657 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2658 | |
| 2659 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2660 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2661 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2662 | } |
| 2663 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2664 | TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame2) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2665 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2666 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2667 | MockWrite writes[] = { |
| 2668 | CreateMockWrite(*stream1_syn, 0), |
| 2669 | }; |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2670 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2671 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2672 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2673 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2674 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2675 | const char kPushedData[] = "pushed"; |
| 2676 | scoped_ptr<SpdyFrame> stream2_body( |
| 2677 | spdy_util_.ConstructSpdyBodyFrame( |
| 2678 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2679 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2680 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2681 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2682 | CreateMockRead(*stream1_reply, 1), |
| 2683 | CreateMockRead(*stream2_syn, 2), |
| 2684 | CreateMockRead(*stream2_body, 3), |
| 2685 | CreateMockRead(*stream1_body, 4, SYNCHRONOUS), |
| 2686 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2687 | }; |
| 2688 | |
| 2689 | HttpResponseInfo response; |
| 2690 | HttpResponseInfo response2; |
| 2691 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2692 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2693 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2694 | &response, |
| 2695 | &response2, |
| 2696 | expected_push_result); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2697 | |
| 2698 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2699 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2700 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2701 | |
| 2702 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2703 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2704 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2705 | } |
| 2706 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2707 | TEST_P(SpdyNetworkTransactionTest, ServerPushServerAborted) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2708 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2709 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2710 | scoped_ptr<SpdyFrame> stream1_body( |
| 2711 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2712 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2713 | CreateMockWrite(*stream1_syn, 0), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2714 | }; |
| 2715 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2716 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2717 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2718 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2719 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2720 | scoped_ptr<SpdyFrame> stream2_rst( |
| 2721 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2722 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2723 | CreateMockRead(*stream1_reply, 1), |
| 2724 | CreateMockRead(*stream2_syn, 2), |
| 2725 | CreateMockRead(*stream2_rst, 3), |
| 2726 | CreateMockRead(*stream1_body, 4, SYNCHRONOUS), |
| 2727 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2728 | }; |
| 2729 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2730 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2731 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2732 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2733 | |
| 2734 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2735 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2736 | |
| 2737 | HttpNetworkTransaction* trans = helper.trans(); |
| 2738 | |
| 2739 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2740 | TestCompletionCallback callback; |
| 2741 | int rv = trans->Start( |
| 2742 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2743 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2744 | rv = callback.WaitForResult(); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2745 | EXPECT_EQ(OK, rv); |
| 2746 | |
| 2747 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2748 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2749 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2750 | |
| 2751 | // Verify the SYN_REPLY. |
| 2752 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2753 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2754 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2755 | } |
| 2756 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2757 | // Verify that we don't leak streams and that we properly send a reset |
| 2758 | // if the server pushes the same stream twice. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2759 | TEST_P(SpdyNetworkTransactionTest, ServerPushDuplicate) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2760 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2761 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2762 | scoped_ptr<SpdyFrame> stream1_body( |
| 2763 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2764 | scoped_ptr<SpdyFrame> stream3_rst( |
| 2765 | spdy_util_.ConstructSpdyRstStream(4, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2766 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2767 | CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*stream3_rst, 4), |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2768 | }; |
| 2769 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2770 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2771 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2772 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2773 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2774 | const char kPushedData[] = "pushed"; |
| 2775 | scoped_ptr<SpdyFrame> stream2_body( |
| 2776 | spdy_util_.ConstructSpdyBodyFrame( |
| 2777 | 2, kPushedData, strlen(kPushedData), true)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2778 | scoped_ptr<SpdyFrame> stream3_syn(spdy_util_.ConstructSpdyPush( |
| 2779 | NULL, 0, 4, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2780 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2781 | CreateMockRead(*stream1_reply, 1), |
| 2782 | CreateMockRead(*stream2_syn, 2), |
| 2783 | CreateMockRead(*stream3_syn, 3), |
| 2784 | CreateMockRead(*stream1_body, 5), |
| 2785 | CreateMockRead(*stream2_body, 6), |
| 2786 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 7), // Force a pause |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2787 | }; |
| 2788 | |
| 2789 | HttpResponseInfo response; |
| 2790 | HttpResponseInfo response2; |
| 2791 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2792 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2793 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2794 | &response, |
| 2795 | &response2, |
| 2796 | expected_push_result); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2797 | |
| 2798 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2799 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2800 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2801 | |
| 2802 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2803 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2804 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2805 | } |
| 2806 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2807 | TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrame) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2808 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2809 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2810 | scoped_ptr<SpdyFrame> stream1_body( |
| 2811 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2812 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2813 | CreateMockWrite(*stream1_syn, 0), |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2814 | }; |
| 2815 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2816 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2817 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2818 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2819 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2820 | static const char kPushedData[] = "pushed my darling hello my baby"; |
| 2821 | scoped_ptr<SpdyFrame> stream2_body_base( |
| 2822 | spdy_util_.ConstructSpdyBodyFrame( |
| 2823 | 2, kPushedData, strlen(kPushedData), true)); |
| 2824 | const size_t kChunkSize = strlen(kPushedData) / 4; |
| 2825 | scoped_ptr<SpdyFrame> stream2_body1( |
| 2826 | new SpdyFrame(stream2_body_base->data(), kChunkSize, false)); |
| 2827 | scoped_ptr<SpdyFrame> stream2_body2( |
| 2828 | new SpdyFrame(stream2_body_base->data() + kChunkSize, kChunkSize, false)); |
| 2829 | scoped_ptr<SpdyFrame> stream2_body3( |
| 2830 | new SpdyFrame(stream2_body_base->data() + 2 * kChunkSize, |
| 2831 | kChunkSize, false)); |
| 2832 | scoped_ptr<SpdyFrame> stream2_body4( |
| 2833 | new SpdyFrame(stream2_body_base->data() + 3 * kChunkSize, |
| 2834 | stream2_body_base->size() - 3 * kChunkSize, false)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2835 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2836 | CreateMockRead(*stream1_reply, 1), |
| 2837 | CreateMockRead(*stream2_syn, 2), |
| 2838 | CreateMockRead(*stream2_body1, 3), |
| 2839 | CreateMockRead(*stream2_body2, 4), |
| 2840 | CreateMockRead(*stream2_body3, 5), |
| 2841 | CreateMockRead(*stream2_body4, 6), |
| 2842 | CreateMockRead(*stream1_body, 7, SYNCHRONOUS), |
| 2843 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), // Force a pause |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2844 | }; |
| 2845 | |
| 2846 | HttpResponseInfo response; |
| 2847 | HttpResponseInfo response2; |
| 2848 | std::string expected_push_result("pushed my darling hello my baby"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2849 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2850 | RunServerPushTest(&data, &response, &response2, kPushedData); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2851 | |
| 2852 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2853 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2854 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2855 | |
| 2856 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2857 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2858 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2859 | } |
| 2860 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2861 | TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrameInterrupted) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2862 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2863 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2864 | scoped_ptr<SpdyFrame> stream1_body( |
| 2865 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2866 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2867 | CreateMockWrite(*stream1_syn, 0), |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2868 | }; |
| 2869 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2870 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2871 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2872 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2873 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2874 | static const char kPushedData[] = "pushed my darling hello my baby"; |
| 2875 | scoped_ptr<SpdyFrame> stream2_body_base( |
| 2876 | spdy_util_.ConstructSpdyBodyFrame( |
| 2877 | 2, kPushedData, strlen(kPushedData), true)); |
| 2878 | const size_t kChunkSize = strlen(kPushedData) / 4; |
| 2879 | scoped_ptr<SpdyFrame> stream2_body1( |
| 2880 | new SpdyFrame(stream2_body_base->data(), kChunkSize, false)); |
| 2881 | scoped_ptr<SpdyFrame> stream2_body2( |
| 2882 | new SpdyFrame(stream2_body_base->data() + kChunkSize, kChunkSize, false)); |
| 2883 | scoped_ptr<SpdyFrame> stream2_body3( |
| 2884 | new SpdyFrame(stream2_body_base->data() + 2 * kChunkSize, |
| 2885 | kChunkSize, false)); |
| 2886 | scoped_ptr<SpdyFrame> stream2_body4( |
| 2887 | new SpdyFrame(stream2_body_base->data() + 3 * kChunkSize, |
| 2888 | stream2_body_base->size() - 3 * kChunkSize, false)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2889 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2890 | CreateMockRead(*stream1_reply, 1), |
| 2891 | CreateMockRead(*stream2_syn, 2), |
| 2892 | CreateMockRead(*stream2_body1, 3), |
| 2893 | CreateMockRead(*stream2_body2, 4), |
| 2894 | CreateMockRead(*stream2_body3, 5), |
| 2895 | CreateMockRead(*stream2_body4, 6), |
| 2896 | CreateMockRead(*stream1_body.get(), 7, SYNCHRONOUS), |
| 2897 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8) // Force a pause. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2898 | }; |
| 2899 | |
| 2900 | HttpResponseInfo response; |
| 2901 | HttpResponseInfo response2; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2902 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2903 | RunServerPushTest(&data, &response, &response2, kPushedData); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2904 | |
| 2905 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2906 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2907 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2908 | |
| 2909 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2910 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2911 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2912 | } |
| 2913 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2914 | TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID0) { |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 2915 | if (spdy_util_.spdy_version() == HTTP2) { |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 2916 | // PUSH_PROMISE with stream id 0 is connection-level error. |
| 2917 | // TODO(baranovich): Test session going away. |
[email protected] | 00b2947 | 2014-01-16 18:10:24 | [diff] [blame] | 2918 | return; |
| 2919 | } |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 2920 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2921 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2922 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2923 | scoped_ptr<SpdyFrame> stream1_body( |
| 2924 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2925 | scoped_ptr<SpdyFrame> stream2_rst( |
| 2926 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2927 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2928 | CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*stream2_rst, 3), |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2929 | }; |
| 2930 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2931 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2932 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2933 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2934 | NULL, 0, 2, 0, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2935 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2936 | CreateMockRead(*stream1_reply, 1), |
| 2937 | CreateMockRead(*stream2_syn, 2), |
| 2938 | CreateMockRead(*stream1_body, 4), |
| 2939 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5) // Force a pause |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2940 | }; |
| 2941 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2942 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2943 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2944 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2945 | |
| 2946 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2947 | helper.AddData(&data); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2948 | |
| 2949 | HttpNetworkTransaction* trans = helper.trans(); |
| 2950 | |
| 2951 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2952 | TestCompletionCallback callback; |
| 2953 | int rv = trans->Start( |
| 2954 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2955 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2956 | rv = callback.WaitForResult(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2957 | EXPECT_EQ(OK, rv); |
| 2958 | |
| 2959 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2960 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2961 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2962 | |
| 2963 | // Verify the SYN_REPLY. |
| 2964 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2965 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2966 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2967 | } |
| 2968 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2969 | TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID9) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2970 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2971 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2972 | scoped_ptr<SpdyFrame> stream1_body( |
| 2973 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2974 | scoped_ptr<SpdyFrame> stream2_rst( |
| 2975 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_INVALID_STREAM)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2976 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2977 | CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*stream2_rst, 3), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2978 | }; |
| 2979 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2980 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2981 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2982 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2983 | NULL, 0, 2, 9, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2984 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2985 | CreateMockRead(*stream1_reply, 1), |
| 2986 | CreateMockRead(*stream2_syn, 2), |
| 2987 | CreateMockRead(*stream1_body, 4), |
| 2988 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2989 | }; |
| 2990 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2991 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2992 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2993 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2994 | |
| 2995 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2996 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2997 | |
| 2998 | HttpNetworkTransaction* trans = helper.trans(); |
| 2999 | |
| 3000 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3001 | TestCompletionCallback callback; |
| 3002 | int rv = trans->Start( |
| 3003 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3004 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3005 | rv = callback.WaitForResult(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3006 | EXPECT_EQ(OK, rv); |
| 3007 | |
| 3008 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3009 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 3010 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3011 | |
| 3012 | // Verify the SYN_REPLY. |
| 3013 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3014 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3015 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3016 | } |
| 3017 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3018 | TEST_P(SpdyNetworkTransactionTest, ServerPushNoURL) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3019 | scoped_ptr<SpdyFrame> stream1_syn( |
| 3020 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3021 | scoped_ptr<SpdyFrame> stream1_body( |
| 3022 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3023 | scoped_ptr<SpdyFrame> stream2_rst( |
| 3024 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3025 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3026 | CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*stream2_rst, 3), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3027 | }; |
| 3028 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3029 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3030 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8b9211d | 2013-06-24 05:54:45 | [diff] [blame] | 3031 | scoped_ptr<SpdyHeaderBlock> incomplete_headers(new SpdyHeaderBlock()); |
[email protected] | 8b9211d | 2013-06-24 05:54:45 | [diff] [blame] | 3032 | (*incomplete_headers)[spdy_util_.GetStatusKey()] = "200 OK"; |
| 3033 | (*incomplete_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3034 | (*incomplete_headers)["hello"] = "bye"; |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 3035 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame( |
| 3036 | incomplete_headers.Pass(), 2, 1)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3037 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3038 | CreateMockRead(*stream1_reply, 1), |
| 3039 | CreateMockRead(*stream2_syn, 2), |
| 3040 | CreateMockRead(*stream1_body, 4), |
| 3041 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5) // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3042 | }; |
| 3043 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3044 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3045 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3046 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3047 | |
| 3048 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3049 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3050 | |
| 3051 | HttpNetworkTransaction* trans = helper.trans(); |
| 3052 | |
| 3053 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3054 | TestCompletionCallback callback; |
| 3055 | int rv = trans->Start( |
| 3056 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3057 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3058 | rv = callback.WaitForResult(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3059 | EXPECT_EQ(OK, rv); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3060 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3061 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3062 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 3063 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3064 | |
| 3065 | // Verify the SYN_REPLY. |
| 3066 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3067 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3068 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3069 | } |
| 3070 | |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3071 | // Verify that various SynReply headers parse correctly through the |
| 3072 | // HTTP layer. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3073 | TEST_P(SpdyNetworkTransactionTest, SynReplyHeaders) { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3074 | struct SynReplyHeadersTests { |
| 3075 | int num_headers; |
| 3076 | const char* extra_headers[5]; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3077 | SpdyHeaderBlock expected_headers; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3078 | } test_cases[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3079 | // This uses a multi-valued cookie header. |
| 3080 | { 2, |
| 3081 | { "cookie", "val1", |
| 3082 | "cookie", "val2", // will get appended separated by NULL |
| 3083 | NULL |
| 3084 | }, |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3085 | }, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3086 | // This is the minimalist set of headers. |
| 3087 | { 0, |
| 3088 | { NULL }, |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3089 | }, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3090 | // Headers with a comma separated list. |
| 3091 | { 1, |
| 3092 | { "cookie", "val1,val2", |
| 3093 | NULL |
| 3094 | }, |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3095 | } |
| 3096 | }; |
| 3097 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3098 | test_cases[0].expected_headers["status"] = "200"; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3099 | test_cases[1].expected_headers["status"] = "200"; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3100 | test_cases[2].expected_headers["status"] = "200"; |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3101 | |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3102 | // HTTP/2 eliminates use of the :version header. |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 3103 | if (spdy_util_.spdy_version() < HTTP2) { |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3104 | test_cases[0].expected_headers["version"] = "HTTP/1.1"; |
| 3105 | test_cases[1].expected_headers["version"] = "HTTP/1.1"; |
| 3106 | test_cases[2].expected_headers["version"] = "HTTP/1.1"; |
| 3107 | } |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3108 | |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3109 | test_cases[0].expected_headers["hello"] = "bye"; |
| 3110 | test_cases[1].expected_headers["hello"] = "bye"; |
| 3111 | test_cases[2].expected_headers["hello"] = "bye"; |
| 3112 | |
| 3113 | test_cases[0].expected_headers["cookie"] = StringPiece("val1\0val2", 9); |
| 3114 | test_cases[2].expected_headers["cookie"] = "val1,val2"; |
| 3115 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 3116 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3117 | scoped_ptr<SpdyFrame> req( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3118 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3119 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3120 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3121 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3122 | spdy_util_.ConstructSpdyGetSynReply(test_cases[i].extra_headers, |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 3123 | test_cases[i].num_headers, |
| 3124 | 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3125 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 3126 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3127 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3128 | CreateMockRead(*resp, 1), |
| 3129 | CreateMockRead(*body, 2), |
| 3130 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3131 | }; |
| 3132 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3133 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 3134 | arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3135 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3136 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3137 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3138 | TransactionHelperResult out = helper.output(); |
| 3139 | |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3140 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3141 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3142 | EXPECT_EQ("hello!", out.response_data); |
| 3143 | |
| 3144 | scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; |
| 3145 | EXPECT_TRUE(headers.get() != NULL); |
| 3146 | void* iter = NULL; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3147 | std::string name, value; |
| 3148 | SpdyHeaderBlock header_block; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3149 | while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3150 | SpdyHeaderBlock::StringPieceProxy mutable_header_block_value = |
| 3151 | header_block[name]; |
| 3152 | if (static_cast<StringPiece>(mutable_header_block_value).empty()) { |
| 3153 | mutable_header_block_value = value; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3154 | } else { |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3155 | std::string joint_value = mutable_header_block_value.as_string(); |
| 3156 | joint_value.append(1, '\0'); |
| 3157 | joint_value.append(value); |
| 3158 | mutable_header_block_value = joint_value; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3159 | } |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3160 | } |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3161 | EXPECT_EQ(test_cases[i].expected_headers, header_block); |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3162 | } |
| 3163 | } |
| 3164 | |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3165 | // Verify that various SynReply headers parse vary fields correctly |
| 3166 | // through the HTTP layer, and the response matches the request. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3167 | TEST_P(SpdyNetworkTransactionTest, SynReplyHeadersVary) { |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3168 | // Modify the following data to change/add test cases: |
| 3169 | struct SynReplyTests { |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3170 | bool vary_matches; |
| 3171 | int num_headers[2]; |
| 3172 | const char* extra_headers[2][16]; |
| 3173 | } test_cases[] = { |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3174 | // Test the case of a multi-valued cookie. When the value is delimited |
| 3175 | // with NUL characters, it needs to be unfolded into multiple headers. |
| 3176 | {true, |
| 3177 | {1, 4}, |
| 3178 | {{"cookie", "val1,val2", NULL}, |
| 3179 | {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
| 3180 | "/index.php", spdy_util_.GetVersionKey(), "HTTP/1.1", "vary", "cookie", |
| 3181 | NULL}}}, |
| 3182 | {// Multiple vary fields. |
| 3183 | true, |
| 3184 | {2, 5}, |
| 3185 | {{"friend", "barney", "enemy", "snaggletooth", NULL}, |
| 3186 | {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
| 3187 | "/index.php", spdy_util_.GetVersionKey(), "HTTP/1.1", "vary", "friend", |
| 3188 | "vary", "enemy", NULL}}}, |
| 3189 | {// Test a '*' vary field. |
| 3190 | false, |
| 3191 | {1, 4}, |
| 3192 | {{"cookie", "val1,val2", NULL}, |
| 3193 | {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
| 3194 | "/index.php", spdy_util_.GetVersionKey(), "HTTP/1.1", "vary", "*", |
| 3195 | NULL}}}, |
| 3196 | {// Multiple comma-separated vary fields. |
| 3197 | true, |
| 3198 | {2, 4}, |
| 3199 | {{"friend", "barney", "enemy", "snaggletooth", NULL}, |
| 3200 | {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
| 3201 | "/index.php", spdy_util_.GetVersionKey(), "HTTP/1.1", "vary", |
| 3202 | "friend,enemy", NULL}}}}; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3203 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 3204 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3205 | // Construct the request. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3206 | scoped_ptr<SpdyFrame> frame_req( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3207 | spdy_util_.ConstructSpdyGet(test_cases[i].extra_headers[0], |
| 3208 | test_cases[i].num_headers[0], |
| 3209 | false, 1, LOWEST, true)); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3210 | |
| 3211 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3212 | CreateMockWrite(*frame_req, 0), |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3213 | }; |
| 3214 | |
| 3215 | // Construct the reply. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3216 | SpdyHeaderBlock reply_headers; |
| 3217 | AppendToHeaderBlock(test_cases[i].extra_headers[1], |
| 3218 | test_cases[i].num_headers[1], |
| 3219 | &reply_headers); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3220 | scoped_ptr<SpdyFrame> frame_reply( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3221 | spdy_util_.ConstructSpdyReply(1, reply_headers)); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3222 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3223 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 3224 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3225 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3226 | CreateMockRead(*frame_reply, 1), |
| 3227 | CreateMockRead(*body, 2), |
| 3228 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3229 | }; |
| 3230 | |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3231 | // Attach the headers to the request. |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 3232 | int header_count = test_cases[i].num_headers[0]; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3233 | |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 3234 | HttpRequestInfo request = CreateGetRequest(); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 3235 | for (int ct = 0; ct < header_count; ct++) { |
| 3236 | const char* header_key = test_cases[i].extra_headers[0][ct * 2]; |
| 3237 | const char* header_value = test_cases[i].extra_headers[0][ct * 2 + 1]; |
| 3238 | request.extra_headers.SetHeader(header_key, header_value); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3239 | } |
| 3240 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3241 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 3242 | arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3243 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3244 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3245 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3246 | TransactionHelperResult out = helper.output(); |
| 3247 | |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3248 | EXPECT_EQ(OK, out.rv) << i; |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3249 | EXPECT_EQ("HTTP/1.1 200", out.status_line) << i; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3250 | EXPECT_EQ("hello!", out.response_data) << i; |
| 3251 | |
| 3252 | // Test the response information. |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3253 | EXPECT_EQ(out.response_info.vary_data.is_valid(), |
| 3254 | test_cases[i].vary_matches) << i; |
| 3255 | |
| 3256 | // Check the headers. |
| 3257 | scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; |
| 3258 | ASSERT_TRUE(headers.get() != NULL) << i; |
| 3259 | void* iter = NULL; |
| 3260 | std::string name, value, lines; |
| 3261 | while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
| 3262 | lines.append(name); |
| 3263 | lines.append(": "); |
| 3264 | lines.append(value); |
| 3265 | lines.append("\n"); |
| 3266 | } |
| 3267 | |
| 3268 | // Construct the expected header reply string. |
[email protected] | 9aa32319 | 2013-05-31 21:38:40 | [diff] [blame] | 3269 | std::string expected_reply = |
| 3270 | spdy_util_.ConstructSpdyReplyString(reply_headers); |
| 3271 | EXPECT_EQ(expected_reply, lines) << i; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3272 | } |
| 3273 | } |
| 3274 | |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3275 | // Verify that we don't crash on invalid SynReply responses. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3276 | TEST_P(SpdyNetworkTransactionTest, InvalidSynReply) { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3277 | struct InvalidSynReplyTests { |
| 3278 | int num_headers; |
| 3279 | const char* headers[10]; |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3280 | } test_cases[] = { |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3281 | // SYN_REPLY missing status header |
| 3282 | { |
| 3283 | 4, |
| 3284 | {spdy_util_.GetPathKey(), "/index.php", spdy_util_.GetVersionKey(), |
| 3285 | "HTTP/1.1", "cookie", "val1", "cookie", "val2", NULL}, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3286 | }, |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3287 | // SYN_REPLY missing version header |
| 3288 | { |
| 3289 | 2, {spdy_util_.GetPathKey(), "/index.php", "status", "200", NULL}, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3290 | }, |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3291 | // SYN_REPLY with no headers |
| 3292 | { |
| 3293 | 0, {NULL}, |
| 3294 | }, |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3295 | }; |
| 3296 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 3297 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3298 | scoped_ptr<SpdyFrame> req( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3299 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 3300 | scoped_ptr<SpdyFrame> rst( |
| 3301 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 3302 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3303 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3304 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 2), |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3305 | }; |
| 3306 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3307 | // Construct the reply. |
| 3308 | SpdyHeaderBlock reply_headers; |
| 3309 | AppendToHeaderBlock( |
| 3310 | test_cases[i].headers, test_cases[i].num_headers, &reply_headers); |
| 3311 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyReply(1, reply_headers)); |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3312 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3313 | CreateMockRead(*resp, 1), MockRead(ASYNC, 0, 3) // EOF |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3314 | }; |
| 3315 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3316 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 3317 | arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3318 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3319 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3320 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3321 | TransactionHelperResult out = helper.output(); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 3322 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3323 | } |
| 3324 | } |
| 3325 | |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3326 | // Verify that we don't crash on some corrupt frames. |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 3327 | // TODO(jgraettinger): HTTP/2 treats a header decompression failure as a |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3328 | // connection error. I'd like to backport this behavior to SPDY3 as well. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3329 | TEST_P(SpdyNetworkTransactionTest, CorruptFrameSessionError) { |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 3330 | if (spdy_util_.spdy_version() >= HTTP2) { |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3331 | return; |
| 3332 | } |
[email protected] | 61c83f78 | 2011-01-27 21:00:24 | [diff] [blame] | 3333 | // This is the length field that's too short. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3334 | scoped_ptr<SpdyFrame> syn_reply_wrong_length( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3335 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3336 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 3337 | size_t right_size = |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 3338 | (spdy_util_.spdy_version() < HTTP2) |
| 3339 | ? syn_reply_wrong_length->size() - framer.GetControlFrameHeaderSize() |
| 3340 | : syn_reply_wrong_length->size(); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 3341 | size_t wrong_size = right_size - 4; |
[email protected] | a4bfdf7 | 2013-02-22 04:06:16 | [diff] [blame] | 3342 | test::SetFrameLength(syn_reply_wrong_length.get(), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 3343 | wrong_size, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3344 | spdy_util_.spdy_version()); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3345 | |
| 3346 | struct SynReplyTests { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3347 | const SpdyFrame* syn_reply; |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3348 | } test_cases[] = { |
[email protected] | 61c83f78 | 2011-01-27 21:00:24 | [diff] [blame] | 3349 | { syn_reply_wrong_length.get(), }, |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3350 | }; |
| 3351 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 3352 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3353 | scoped_ptr<SpdyFrame> req( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3354 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 099bc7e | 2013-07-18 04:19:16 | [diff] [blame] | 3355 | scoped_ptr<SpdyFrame> rst( |
| 3356 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 3357 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3358 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 3), |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3359 | }; |
| 3360 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3361 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3362 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3363 | MockRead(ASYNC, test_cases[i].syn_reply->data(), wrong_size, 1), |
| 3364 | CreateMockRead(*body, 2), |
| 3365 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3366 | }; |
| 3367 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3368 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 3369 | arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3370 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3371 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3372 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3373 | TransactionHelperResult out = helper.output(); |
[email protected] | 955fc2e7 | 2010-02-08 20:37:30 | [diff] [blame] | 3374 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3375 | } |
| 3376 | } |
| 3377 | |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 3378 | // HTTP/2 treats a header decompression failure as a connection-level error. |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3379 | TEST_P(SpdyNetworkTransactionTest, CorruptFrameSessionErrorSpdy4) { |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 3380 | if (spdy_util_.spdy_version() < HTTP2) { |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3381 | return; |
| 3382 | } |
| 3383 | // This is the length field that's too short. |
| 3384 | scoped_ptr<SpdyFrame> syn_reply_wrong_length( |
| 3385 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3386 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 3387 | size_t right_size = |
[email protected] | c143f274 | 2014-03-31 00:48:54 | [diff] [blame] | 3388 | syn_reply_wrong_length->size() - framer.GetControlFrameHeaderSize(); |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3389 | size_t wrong_size = right_size - 4; |
| 3390 | test::SetFrameLength(syn_reply_wrong_length.get(), |
| 3391 | wrong_size, |
| 3392 | spdy_util_.spdy_version()); |
| 3393 | |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3394 | scoped_ptr<SpdyFrame> req( |
| 3395 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3396 | scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 3397 | 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 5 (DECOMPRESS_FAILURE).")); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3398 | MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2)}; |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3399 | |
| 3400 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3401 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3402 | MockRead(ASYNC, syn_reply_wrong_length->data(), |
| 3403 | syn_reply_wrong_length->size() - 4, 1), |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3404 | }; |
| 3405 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3406 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3407 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 3408 | BoundNetLog(), GetParam(), NULL); |
| 3409 | helper.RunToCompletion(&data); |
| 3410 | TransactionHelperResult out = helper.output(); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3411 | EXPECT_EQ(ERR_SPDY_COMPRESSION_ERROR, out.rv); |
| 3412 | } |
| 3413 | |
| 3414 | TEST_P(SpdyNetworkTransactionTest, GoAwayOnDecompressionFailure) { |
bnc | 9b79a57 | 2015-09-02 12:25:03 | [diff] [blame] | 3415 | if (GetParam().protocol < kProtoHTTP2) { |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3416 | // Decompression failures are a stream error in SPDY3 and above. |
| 3417 | return; |
| 3418 | } |
| 3419 | scoped_ptr<SpdyFrame> req( |
| 3420 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3421 | scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 3422 | 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 5 (DECOMPRESS_FAILURE).")); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3423 | MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3424 | |
| 3425 | // Read HEADERS with corrupted payload. |
| 3426 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3427 | memset(resp->data() + 12, 0xff, resp->size() - 12); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3428 | MockRead reads[] = {CreateMockRead(*resp, 1)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3429 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3430 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3431 | NormalSpdyTransactionHelper helper( |
| 3432 | CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3433 | helper.RunToCompletion(&data); |
| 3434 | TransactionHelperResult out = helper.output(); |
| 3435 | EXPECT_EQ(ERR_SPDY_COMPRESSION_ERROR, out.rv); |
| 3436 | } |
| 3437 | |
| 3438 | TEST_P(SpdyNetworkTransactionTest, GoAwayOnFrameSizeError) { |
| 3439 | scoped_ptr<SpdyFrame> req( |
| 3440 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3441 | scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 3442 | 0, GOAWAY_PROTOCOL_ERROR, "Framer error: 1 (INVALID_CONTROL_FRAME).")); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3443 | MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3444 | |
| 3445 | // Read WINDOW_UPDATE with incorrectly-sized payload. |
| 3446 | // TODO(jgraettinger): SpdyFramer signals this as an INVALID_CONTROL_FRAME, |
| 3447 | // which is mapped to a protocol error, and not a frame size error. |
| 3448 | scoped_ptr<SpdyFrame> bad_window_update( |
| 3449 | spdy_util_.ConstructSpdyWindowUpdate(1, 1)); |
| 3450 | test::SetFrameLength(bad_window_update.get(), |
| 3451 | bad_window_update->size() - 1, |
| 3452 | spdy_util_.spdy_version()); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3453 | MockRead reads[] = {CreateMockRead(*bad_window_update, 1)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3454 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3455 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3456 | NormalSpdyTransactionHelper helper( |
| 3457 | CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3458 | helper.RunToCompletion(&data); |
| 3459 | TransactionHelperResult out = helper.output(); |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3460 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 3461 | } |
| 3462 | |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3463 | // Test that we shutdown correctly on write errors. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3464 | TEST_P(SpdyNetworkTransactionTest, WriteError) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3465 | scoped_ptr<SpdyFrame> req( |
| 3466 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3467 | MockWrite writes[] = { |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3468 | // We'll write 10 bytes successfully |
| 3469 | MockWrite(ASYNC, req->data(), 10, 0), |
| 3470 | // Followed by ERROR! |
| 3471 | MockWrite(ASYNC, ERR_FAILED, 1), |
| 3472 | // Session drains and attempts to write a GOAWAY: Another ERROR! |
| 3473 | MockWrite(ASYNC, ERR_FAILED, 2), |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3474 | }; |
| 3475 | |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3476 | MockRead reads[] = { |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3477 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3478 | }; |
| 3479 | |
| 3480 | DeterministicSocketData data(reads, arraysize(reads), |
| 3481 | writes, arraysize(writes)); |
| 3482 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3483 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3484 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3485 | helper.SetDeterministic(); |
| 3486 | helper.RunPreTestSetup(); |
| 3487 | helper.AddDeterministicData(&data); |
| 3488 | EXPECT_TRUE(helper.StartDefaultTest()); |
| 3489 | data.RunFor(2); |
| 3490 | helper.FinishDefaultTest(); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 3491 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 3492 | EXPECT_TRUE(!data.AllReadDataConsumed()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3493 | TransactionHelperResult out = helper.output(); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3494 | EXPECT_EQ(ERR_FAILED, out.rv); |
| 3495 | } |
| 3496 | |
| 3497 | // Test that partial writes work. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3498 | TEST_P(SpdyNetworkTransactionTest, PartialWrite) { |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3499 | // Chop the SYN_STREAM frame into 5 chunks. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3500 | scoped_ptr<SpdyFrame> req( |
| 3501 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3502 | const int kChunks = 5; |
[email protected] | 4356f0f | 2013-04-07 00:58:17 | [diff] [blame] | 3503 | scoped_ptr<MockWrite[]> writes(ChopWriteFrame(*req.get(), kChunks)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3504 | for (int i = 0; i < kChunks; ++i) { |
| 3505 | writes[i].sequence_number = i; |
| 3506 | } |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3507 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3508 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3509 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3510 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3511 | CreateMockRead(*resp, kChunks), |
| 3512 | CreateMockRead(*body, kChunks + 1), |
| 3513 | MockRead(ASYNC, 0, kChunks + 2) // EOF |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3514 | }; |
| 3515 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3516 | SequencedSocketData data(reads, arraysize(reads), writes.get(), kChunks); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3517 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3518 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3519 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3520 | TransactionHelperResult out = helper.output(); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3521 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3522 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3523 | EXPECT_EQ("hello!", out.response_data); |
| 3524 | } |
| 3525 | |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3526 | // In this test, we enable compression, but get a uncompressed SynReply from |
| 3527 | // the server. Verify that teardown is all clean. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3528 | TEST_P(SpdyNetworkTransactionTest, DecompressFailureOnSynReply) { |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 3529 | if (spdy_util_.spdy_version() >= HTTP2) { |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3530 | // HPACK doesn't use deflate compression. |
| 3531 | return; |
| 3532 | } |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3533 | scoped_ptr<SpdyFrame> compressed( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3534 | spdy_util_.ConstructSpdyGet(NULL, 0, true, 1, LOWEST, true)); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3535 | scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 3536 | 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 5 (DECOMPRESS_FAILURE).")); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3537 | MockWrite writes[] = {CreateMockWrite(*compressed, 0), |
| 3538 | CreateMockWrite(*goaway, 2)}; |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3539 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3540 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3541 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3542 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3543 | CreateMockRead(*resp, 1), |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3544 | }; |
| 3545 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3546 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3547 | scoped_ptr<SpdySessionDependencies> session_deps = |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3548 | CreateSpdySessionDependencies(GetParam()); |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 3549 | session_deps->enable_compression = true; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3550 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3551 | BoundNetLog(), GetParam(), |
| 3552 | session_deps.Pass()); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3553 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3554 | TransactionHelperResult out = helper.output(); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3555 | EXPECT_EQ(ERR_SPDY_COMPRESSION_ERROR, out.rv); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3556 | } |
| 3557 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 3558 | // Test that the NetLog contains good data for a simple GET request. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3559 | TEST_P(SpdyNetworkTransactionTest, NetLog) { |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3560 | static const char* const kExtraHeaders[] = { |
| 3561 | "user-agent", "Chrome", |
| 3562 | }; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3563 | scoped_ptr<SpdyFrame> req( |
| 3564 | spdy_util_.ConstructSpdyGet(kExtraHeaders, 1, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3565 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3566 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3567 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3568 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3569 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3570 | CreateMockRead(*resp, 1), |
| 3571 | CreateMockRead(*body, 2), |
| 3572 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3573 | }; |
| 3574 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3575 | BoundTestNetLog log; |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3576 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3577 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3578 | NormalSpdyTransactionHelper helper(CreateGetRequestWithUserAgent(), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3579 | DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3580 | log.bound(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3581 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3582 | TransactionHelperResult out = helper.output(); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3583 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3584 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3585 | EXPECT_EQ("hello!", out.response_data); |
| 3586 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 3587 | // Check that the NetLog was filled reasonably. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3588 | // This test is intentionally non-specific about the exact ordering of the |
| 3589 | // log; instead we just check to make sure that certain events exist, and that |
| 3590 | // they are in the right order. |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3591 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3592 | log.GetEntries(&entries); |
| 3593 | |
| 3594 | EXPECT_LT(0u, entries.size()); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3595 | int pos = 0; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3596 | pos = ExpectLogContainsSomewhere(entries, 0, |
| 3597 | NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, |
| 3598 | NetLog::PHASE_BEGIN); |
| 3599 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3600 | NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, |
| 3601 | NetLog::PHASE_END); |
| 3602 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3603 | NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, |
| 3604 | NetLog::PHASE_BEGIN); |
| 3605 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3606 | NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, |
| 3607 | NetLog::PHASE_END); |
| 3608 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3609 | NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, |
| 3610 | NetLog::PHASE_BEGIN); |
| 3611 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3612 | NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, |
| 3613 | NetLog::PHASE_END); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3614 | |
| 3615 | // Check that we logged all the headers correctly |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3616 | const NetLog::EventType type = (GetParam().protocol <= kProtoSPDY31) |
| 3617 | ? NetLog::TYPE_HTTP2_SESSION_SYN_STREAM |
| 3618 | : NetLog::TYPE_HTTP2_SESSION_SEND_HEADERS; |
| 3619 | pos = ExpectLogContainsSomewhere(entries, 0, type, NetLog::PHASE_NONE); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3620 | |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 3621 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3622 | ASSERT_TRUE(entries[pos].params.get()); |
| 3623 | ASSERT_TRUE(entries[pos].params->GetList("headers", &header_list)); |
| 3624 | |
| 3625 | std::vector<std::string> expected; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3626 | expected.push_back(std::string(spdy_util_.GetHostKey()) + |
| 3627 | ": www.example.org"); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3628 | expected.push_back(std::string(spdy_util_.GetPathKey()) + ": /"); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 3629 | expected.push_back(std::string(spdy_util_.GetSchemeKey()) + ": " + |
| 3630 | spdy_util_.default_url().scheme()); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3631 | expected.push_back(std::string(spdy_util_.GetMethodKey()) + ": GET"); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3632 | expected.push_back("user-agent: Chrome"); |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 3633 | if (spdy_util_.spdy_version() < HTTP2) { |
| 3634 | // HTTP/2 eliminates use of the :version header. |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3635 | expected.push_back(std::string(spdy_util_.GetVersionKey()) + ": HTTP/1.1"); |
| 3636 | } |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3637 | EXPECT_EQ(expected.size(), header_list->GetSize()); |
| 3638 | for (std::vector<std::string>::const_iterator it = expected.begin(); |
| 3639 | it != expected.end(); |
| 3640 | ++it) { |
| 3641 | base::StringValue header(*it); |
| 3642 | EXPECT_NE(header_list->end(), header_list->Find(header)) << |
| 3643 | "Header not found: " << *it; |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3644 | } |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3645 | } |
| 3646 | |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3647 | // Since we buffer the IO from the stream to the renderer, this test verifies |
| 3648 | // that when we read out the maximum amount of data (e.g. we received 50 bytes |
| 3649 | // on the network, but issued a Read for only 5 of those bytes) that the data |
| 3650 | // flow still works correctly. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3651 | TEST_P(SpdyNetworkTransactionTest, BufferFull) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3652 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3653 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3654 | scoped_ptr<SpdyFrame> req( |
| 3655 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3656 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3657 | |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3658 | // 2 data frames in a single read. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3659 | scoped_ptr<SpdyFrame> data_frame_1( |
| 3660 | framer.CreateDataFrame(1, "goodby", 6, DATA_FLAG_NONE)); |
| 3661 | scoped_ptr<SpdyFrame> data_frame_2( |
| 3662 | framer.CreateDataFrame(1, "e worl", 6, DATA_FLAG_NONE)); |
| 3663 | const SpdyFrame* data_frames[2] = { |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3664 | data_frame_1.get(), |
| 3665 | data_frame_2.get(), |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3666 | }; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3667 | char combined_data_frames[100]; |
| 3668 | int combined_data_frames_len = |
| 3669 | CombineFrames(data_frames, arraysize(data_frames), |
| 3670 | combined_data_frames, arraysize(combined_data_frames)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3671 | scoped_ptr<SpdyFrame> last_frame( |
| 3672 | framer.CreateDataFrame(1, "d", 1, DATA_FLAG_FIN)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3673 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3674 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3675 | MockRead reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3676 | CreateMockRead(*resp, 1), |
| 3677 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause |
| 3678 | MockRead(ASYNC, combined_data_frames, combined_data_frames_len, 3), |
| 3679 | MockRead(ASYNC, ERR_IO_PENDING, 4), // Force a pause |
| 3680 | CreateMockRead(*last_frame, 5), |
| 3681 | MockRead(ASYNC, 0, 6) // EOF |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3682 | }; |
| 3683 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3684 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3685 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3686 | TestCompletionCallback callback; |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3687 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3688 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3689 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3690 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3691 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3692 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3693 | int rv = trans->Start( |
| 3694 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3695 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3696 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3697 | TransactionHelperResult out = helper.output(); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3698 | out.rv = callback.WaitForResult(); |
| 3699 | EXPECT_EQ(out.rv, OK); |
| 3700 | |
| 3701 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3702 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3703 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3704 | out.status_line = response->headers->GetStatusLine(); |
| 3705 | out.response_info = *response; // Make a copy so we can verify. |
| 3706 | |
| 3707 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3708 | TestCompletionCallback read_callback; |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3709 | |
| 3710 | std::string content; |
| 3711 | do { |
| 3712 | // Read small chunks at a time. |
| 3713 | const int kSmallReadSize = 3; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3714 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3715 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3716 | if (rv == ERR_IO_PENDING) { |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3717 | data.CompleteRead(); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3718 | rv = read_callback.WaitForResult(); |
| 3719 | } |
| 3720 | if (rv > 0) { |
| 3721 | content.append(buf->data(), rv); |
| 3722 | } else if (rv < 0) { |
| 3723 | NOTREACHED(); |
| 3724 | } |
| 3725 | } while (rv > 0); |
| 3726 | |
| 3727 | out.response_data.swap(content); |
| 3728 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3729 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3730 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3731 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3732 | |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3733 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3734 | helper.VerifyDataConsumed(); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3735 | |
| 3736 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3737 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3738 | EXPECT_EQ("goodbye world", out.response_data); |
| 3739 | } |
| 3740 | |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3741 | // Verify that basic buffering works; when multiple data frames arrive |
| 3742 | // at the same time, ensure that we don't notify a read completion for |
| 3743 | // each data frame individually. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3744 | TEST_P(SpdyNetworkTransactionTest, Buffering) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3745 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3746 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3747 | scoped_ptr<SpdyFrame> req( |
| 3748 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3749 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3750 | |
| 3751 | // 4 data frames in a single read. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3752 | scoped_ptr<SpdyFrame> data_frame( |
| 3753 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 3754 | scoped_ptr<SpdyFrame> data_frame_fin( |
| 3755 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN)); |
| 3756 | const SpdyFrame* data_frames[4] = { |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3757 | data_frame.get(), |
| 3758 | data_frame.get(), |
| 3759 | data_frame.get(), |
| 3760 | data_frame_fin.get() |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3761 | }; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3762 | char combined_data_frames[100]; |
| 3763 | int combined_data_frames_len = |
| 3764 | CombineFrames(data_frames, arraysize(data_frames), |
| 3765 | combined_data_frames, arraysize(combined_data_frames)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3766 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3767 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3768 | MockRead reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3769 | CreateMockRead(*resp, 1), |
| 3770 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause |
| 3771 | MockRead(ASYNC, combined_data_frames, combined_data_frames_len, 3), |
| 3772 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3773 | }; |
| 3774 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3775 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3776 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3777 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3778 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3779 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3780 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3781 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3782 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3783 | TestCompletionCallback callback; |
| 3784 | int rv = trans->Start( |
| 3785 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3786 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3787 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3788 | TransactionHelperResult out = helper.output(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3789 | out.rv = callback.WaitForResult(); |
| 3790 | EXPECT_EQ(out.rv, OK); |
| 3791 | |
| 3792 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3793 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3794 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3795 | out.status_line = response->headers->GetStatusLine(); |
| 3796 | out.response_info = *response; // Make a copy so we can verify. |
| 3797 | |
| 3798 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3799 | TestCompletionCallback read_callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3800 | |
| 3801 | std::string content; |
| 3802 | int reads_completed = 0; |
| 3803 | do { |
| 3804 | // Read small chunks at a time. |
| 3805 | const int kSmallReadSize = 14; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3806 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3807 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3808 | if (rv == ERR_IO_PENDING) { |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3809 | data.CompleteRead(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3810 | rv = read_callback.WaitForResult(); |
| 3811 | } |
| 3812 | if (rv > 0) { |
| 3813 | EXPECT_EQ(kSmallReadSize, rv); |
| 3814 | content.append(buf->data(), rv); |
| 3815 | } else if (rv < 0) { |
| 3816 | FAIL() << "Unexpected read error: " << rv; |
| 3817 | } |
| 3818 | reads_completed++; |
| 3819 | } while (rv > 0); |
| 3820 | |
| 3821 | EXPECT_EQ(3, reads_completed); // Reads are: 14 bytes, 14 bytes, 0 bytes. |
| 3822 | |
| 3823 | out.response_data.swap(content); |
| 3824 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3825 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3826 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3827 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3828 | |
| 3829 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3830 | helper.VerifyDataConsumed(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3831 | |
| 3832 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3833 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3834 | EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 3835 | } |
| 3836 | |
| 3837 | // Verify the case where we buffer data but read it after it has been buffered. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3838 | TEST_P(SpdyNetworkTransactionTest, BufferedAll) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3839 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3840 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3841 | scoped_ptr<SpdyFrame> req( |
| 3842 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3843 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3844 | |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3845 | // 5 data frames in a single read. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3846 | scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3847 | scoped_ptr<SpdyFrame> data_frame( |
| 3848 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 3849 | scoped_ptr<SpdyFrame> data_frame_fin( |
| 3850 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN)); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3851 | const SpdyFrame* frames[5] = {reply.get(), data_frame.get(), data_frame.get(), |
| 3852 | data_frame.get(), data_frame_fin.get()}; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3853 | char combined_frames[200]; |
| 3854 | int combined_frames_len = |
| 3855 | CombineFrames(frames, arraysize(frames), |
| 3856 | combined_frames, arraysize(combined_frames)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3857 | |
| 3858 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3859 | MockRead(ASYNC, combined_frames, combined_frames_len, 1), |
| 3860 | MockRead(ASYNC, 0, 2) // EOF |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3861 | }; |
| 3862 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3863 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3864 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3865 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3866 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3867 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3868 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3869 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3870 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3871 | TestCompletionCallback callback; |
| 3872 | int rv = trans->Start( |
| 3873 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3874 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3875 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3876 | TransactionHelperResult out = helper.output(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3877 | out.rv = callback.WaitForResult(); |
| 3878 | EXPECT_EQ(out.rv, OK); |
| 3879 | |
| 3880 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3881 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3882 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3883 | out.status_line = response->headers->GetStatusLine(); |
| 3884 | out.response_info = *response; // Make a copy so we can verify. |
| 3885 | |
| 3886 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3887 | TestCompletionCallback read_callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3888 | |
| 3889 | std::string content; |
| 3890 | int reads_completed = 0; |
| 3891 | do { |
| 3892 | // Read small chunks at a time. |
| 3893 | const int kSmallReadSize = 14; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3894 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3895 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3896 | if (rv > 0) { |
| 3897 | EXPECT_EQ(kSmallReadSize, rv); |
| 3898 | content.append(buf->data(), rv); |
| 3899 | } else if (rv < 0) { |
| 3900 | FAIL() << "Unexpected read error: " << rv; |
| 3901 | } |
| 3902 | reads_completed++; |
| 3903 | } while (rv > 0); |
| 3904 | |
| 3905 | EXPECT_EQ(3, reads_completed); |
| 3906 | |
| 3907 | out.response_data.swap(content); |
| 3908 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3909 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3910 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3911 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3912 | |
| 3913 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3914 | helper.VerifyDataConsumed(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3915 | |
| 3916 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3917 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3918 | EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 3919 | } |
| 3920 | |
| 3921 | // Verify the case where we buffer data and close the connection. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3922 | TEST_P(SpdyNetworkTransactionTest, BufferedClosed) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3923 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3924 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3925 | scoped_ptr<SpdyFrame> req( |
| 3926 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3927 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3928 | |
| 3929 | // All data frames in a single read. |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3930 | // NOTE: We don't FIN the stream. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3931 | scoped_ptr<SpdyFrame> data_frame( |
| 3932 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 3933 | const SpdyFrame* data_frames[4] = { |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3934 | data_frame.get(), |
| 3935 | data_frame.get(), |
| 3936 | data_frame.get(), |
| 3937 | data_frame.get() |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3938 | }; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3939 | char combined_data_frames[100]; |
| 3940 | int combined_data_frames_len = |
| 3941 | CombineFrames(data_frames, arraysize(data_frames), |
| 3942 | combined_data_frames, arraysize(combined_data_frames)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3943 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3944 | MockRead reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3945 | CreateMockRead(*resp, 1), |
| 3946 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a wait |
| 3947 | MockRead(ASYNC, combined_data_frames, combined_data_frames_len, 3), |
| 3948 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3949 | }; |
| 3950 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3951 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3952 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3953 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3954 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3955 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3956 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3957 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3958 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3959 | TestCompletionCallback callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3960 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3961 | int rv = trans->Start( |
| 3962 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3963 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3964 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3965 | TransactionHelperResult out = helper.output(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3966 | out.rv = callback.WaitForResult(); |
| 3967 | EXPECT_EQ(out.rv, OK); |
| 3968 | |
| 3969 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3970 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3971 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3972 | out.status_line = response->headers->GetStatusLine(); |
| 3973 | out.response_info = *response; // Make a copy so we can verify. |
| 3974 | |
| 3975 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3976 | TestCompletionCallback read_callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3977 | |
| 3978 | std::string content; |
| 3979 | int reads_completed = 0; |
| 3980 | do { |
| 3981 | // Read small chunks at a time. |
| 3982 | const int kSmallReadSize = 14; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3983 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3984 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3985 | if (rv == ERR_IO_PENDING) { |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3986 | data.CompleteRead(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3987 | rv = read_callback.WaitForResult(); |
| 3988 | } |
| 3989 | if (rv > 0) { |
| 3990 | content.append(buf->data(), rv); |
| 3991 | } else if (rv < 0) { |
| 3992 | // This test intentionally closes the connection, and will get an error. |
| 3993 | EXPECT_EQ(ERR_CONNECTION_CLOSED, rv); |
| 3994 | break; |
| 3995 | } |
| 3996 | reads_completed++; |
| 3997 | } while (rv > 0); |
| 3998 | |
| 3999 | EXPECT_EQ(0, reads_completed); |
| 4000 | |
| 4001 | out.response_data.swap(content); |
| 4002 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 4003 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4004 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4005 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4006 | |
| 4007 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4008 | helper.VerifyDataConsumed(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4009 | } |
| 4010 | |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4011 | // Verify the case where we buffer data and cancel the transaction. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4012 | TEST_P(SpdyNetworkTransactionTest, BufferedCancelled) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4013 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 4014 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4015 | scoped_ptr<SpdyFrame> req( |
| 4016 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 4017 | scoped_ptr<SpdyFrame> rst( |
| 4018 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4019 | MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*rst, 4)}; |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4020 | |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 4021 | // NOTE: We don't FIN the stream. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4022 | scoped_ptr<SpdyFrame> data_frame( |
| 4023 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4024 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4025 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4026 | MockRead reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4027 | CreateMockRead(*resp, 1), |
| 4028 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a wait |
| 4029 | CreateMockRead(*data_frame, 3), |
| 4030 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4031 | }; |
| 4032 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4033 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4034 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4035 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4036 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4037 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4038 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4039 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4040 | TestCompletionCallback callback; |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4041 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4042 | int rv = trans->Start( |
| 4043 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4044 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4045 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4046 | TransactionHelperResult out = helper.output(); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4047 | out.rv = callback.WaitForResult(); |
| 4048 | EXPECT_EQ(out.rv, OK); |
| 4049 | |
| 4050 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4051 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4052 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4053 | out.status_line = response->headers->GetStatusLine(); |
| 4054 | out.response_info = *response; // Make a copy so we can verify. |
| 4055 | |
| 4056 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4057 | TestCompletionCallback read_callback; |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4058 | |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 4059 | const int kReadSize = 256; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4060 | scoped_refptr<IOBuffer> buf(new IOBuffer(kReadSize)); |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 4061 | rv = trans->Read(buf.get(), kReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4062 | ASSERT_EQ(ERR_IO_PENDING, rv) << "Unexpected read: " << rv; |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 4063 | |
| 4064 | // Complete the read now, which causes buffering to start. |
| 4065 | data.CompleteRead(); |
| 4066 | // Destroy the transaction, causing the stream to get cancelled |
| 4067 | // and orphaning the buffered IO task. |
| 4068 | helper.ResetTrans(); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4069 | |
| 4070 | // Flush the MessageLoop; this will cause the buffered IO task |
| 4071 | // to run for the final time. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4072 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4073 | |
| 4074 | // Verify that we consumed all test data. |
| 4075 | helper.VerifyDataConsumed(); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4076 | } |
| 4077 | |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4078 | // Test that if the server requests persistence of settings, that we save |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4079 | // the settings in the HttpServerProperties. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4080 | TEST_P(SpdyNetworkTransactionTest, SettingsSaved) { |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 4081 | if (spdy_util_.spdy_version() >= HTTP2) { |
| 4082 | // HTTP/2 doesn't support settings persistence. |
[email protected] | 8a7bc7a | 2014-02-28 21:25:22 | [diff] [blame] | 4083 | return; |
| 4084 | } |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4085 | static const SpdyHeaderInfo kSynReplyInfo = { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4086 | SYN_REPLY, // Syn Reply |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4087 | 1, // Stream ID |
| 4088 | 0, // Associated Stream ID |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4089 | ConvertRequestPriorityToSpdyPriority( |
| 4090 | LOWEST, spdy_util_.spdy_version()), |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4091 | CONTROL_FLAG_NONE, // Control Flags |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4092 | false, // Compressed |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 4093 | RST_STREAM_INVALID, // Status |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4094 | NULL, // Data |
| 4095 | 0, // Data Length |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4096 | DATA_FLAG_NONE // Data Flags |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4097 | }; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4098 | |
[email protected] | c016882 | 2011-12-10 01:24:27 | [diff] [blame] | 4099 | BoundNetLog net_log; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4100 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 4101 | net_log, GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 4102 | helper.RunPreTestSetup(); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4103 | |
| 4104 | // Verify that no settings exist initially. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4105 | HostPortPair host_port_pair("www.example.org", helper.port()); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 4106 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4107 | EXPECT_TRUE(spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4108 | host_port_pair).empty()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4109 | |
| 4110 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4111 | scoped_ptr<SpdyFrame> req( |
| 4112 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4113 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4114 | |
| 4115 | // Construct the reply. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4116 | scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); |
| 4117 | (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 4118 | (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4119 | scoped_ptr<SpdyFrame> reply( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4120 | spdy_util_.ConstructSpdyFrame(kSynReplyInfo, reply_headers.Pass())); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4121 | |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4122 | const SpdySettingsIds kSampleId1 = SETTINGS_UPLOAD_BANDWIDTH; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4123 | unsigned int kSampleValue1 = 0x0a0a0a0a; |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4124 | const SpdySettingsIds kSampleId2 = SETTINGS_DOWNLOAD_BANDWIDTH; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4125 | unsigned int kSampleValue2 = 0x0b0b0b0b; |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4126 | const SpdySettingsIds kSampleId3 = SETTINGS_ROUND_TRIP_TIME; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4127 | unsigned int kSampleValue3 = 0x0c0c0c0c; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4128 | scoped_ptr<SpdyFrame> settings_frame; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4129 | { |
| 4130 | // Construct the SETTINGS frame. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4131 | SettingsMap settings; |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4132 | // First add a persisted setting. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4133 | settings[kSampleId1] = |
| 4134 | SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue1); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4135 | // Next add a non-persisted setting. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4136 | settings[kSampleId2] = |
| 4137 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kSampleValue2); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4138 | // Next add another persisted setting. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4139 | settings[kSampleId3] = |
| 4140 | SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue3); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4141 | settings_frame.reset(spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4142 | } |
| 4143 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4144 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4145 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4146 | CreateMockRead(*reply, 1), |
| 4147 | CreateMockRead(*body, 2), |
| 4148 | CreateMockRead(*settings_frame, 3), |
| 4149 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4150 | }; |
| 4151 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4152 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4153 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 4154 | helper.RunDefaultTest(); |
| 4155 | helper.VerifyDataConsumed(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4156 | TransactionHelperResult out = helper.output(); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4157 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4158 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4159 | EXPECT_EQ("hello!", out.response_data); |
| 4160 | |
| 4161 | { |
| 4162 | // Verify we had two persisted settings. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4163 | const SettingsMap& settings_map = |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4164 | spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4165 | host_port_pair); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4166 | ASSERT_EQ(2u, settings_map.size()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4167 | |
| 4168 | // Verify the first persisted setting. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4169 | SettingsMap::const_iterator it1 = settings_map.find(kSampleId1); |
| 4170 | EXPECT_TRUE(it1 != settings_map.end()); |
| 4171 | SettingsFlagsAndValue flags_and_value1 = it1->second; |
| 4172 | EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1.first); |
| 4173 | EXPECT_EQ(kSampleValue1, flags_and_value1.second); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4174 | |
| 4175 | // Verify the second persisted setting. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4176 | SettingsMap::const_iterator it3 = settings_map.find(kSampleId3); |
| 4177 | EXPECT_TRUE(it3 != settings_map.end()); |
| 4178 | SettingsFlagsAndValue flags_and_value3 = it3->second; |
| 4179 | EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value3.first); |
| 4180 | EXPECT_EQ(kSampleValue3, flags_and_value3.second); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4181 | } |
| 4182 | } |
| 4183 | |
| 4184 | // Test that when there are settings saved that they are sent back to the |
| 4185 | // server upon session establishment. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4186 | TEST_P(SpdyNetworkTransactionTest, SettingsPlayback) { |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 4187 | if (spdy_util_.spdy_version() >= HTTP2) { |
| 4188 | // HTTP/2 doesn't support settings persistence. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4189 | return; |
| 4190 | } |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4191 | static const SpdyHeaderInfo kSynReplyInfo = { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4192 | SYN_REPLY, // Syn Reply |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4193 | 1, // Stream ID |
| 4194 | 0, // Associated Stream ID |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4195 | ConvertRequestPriorityToSpdyPriority( |
| 4196 | LOWEST, spdy_util_.spdy_version()), |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4197 | CONTROL_FLAG_NONE, // Control Flags |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4198 | false, // Compressed |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 4199 | RST_STREAM_INVALID, // Status |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4200 | NULL, // Data |
| 4201 | 0, // Data Length |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4202 | DATA_FLAG_NONE // Data Flags |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4203 | }; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4204 | |
[email protected] | c016882 | 2011-12-10 01:24:27 | [diff] [blame] | 4205 | BoundNetLog net_log; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4206 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 4207 | net_log, GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 4208 | helper.RunPreTestSetup(); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4209 | |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4210 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
| 4211 | |
| 4212 | SpdySessionPoolPeer pool_peer(spdy_session_pool); |
| 4213 | pool_peer.SetEnableSendingInitialData(true); |
| 4214 | |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4215 | // Verify that no settings exist initially. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4216 | HostPortPair host_port_pair("www.example.org", helper.port()); |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4217 | EXPECT_TRUE(spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4218 | host_port_pair).empty()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4219 | |
[email protected] | c143f274 | 2014-03-31 00:48:54 | [diff] [blame] | 4220 | const SpdySettingsIds kSampleId1 = SETTINGS_MAX_CONCURRENT_STREAMS; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4221 | unsigned int kSampleValue1 = 0x0a0a0a0a; |
[email protected] | c143f274 | 2014-03-31 00:48:54 | [diff] [blame] | 4222 | const SpdySettingsIds kSampleId2 = SETTINGS_INITIAL_WINDOW_SIZE; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4223 | unsigned int kSampleValue2 = 0x0c0c0c0c; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4224 | |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4225 | // First add a persisted setting. |
| 4226 | spdy_session_pool->http_server_properties()->SetSpdySetting( |
| 4227 | host_port_pair, |
| 4228 | kSampleId1, |
| 4229 | SETTINGS_FLAG_PLEASE_PERSIST, |
| 4230 | kSampleValue1); |
| 4231 | |
| 4232 | // Next add another persisted setting. |
| 4233 | spdy_session_pool->http_server_properties()->SetSpdySetting( |
| 4234 | host_port_pair, |
| 4235 | kSampleId2, |
| 4236 | SETTINGS_FLAG_PLEASE_PERSIST, |
| 4237 | kSampleValue2); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4238 | |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4239 | EXPECT_EQ(2u, spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4240 | host_port_pair).size()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4241 | |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4242 | // Construct the initial SETTINGS frame. |
| 4243 | SettingsMap initial_settings; |
| 4244 | initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 4245 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); |
| 4246 | scoped_ptr<SpdyFrame> initial_settings_frame( |
| 4247 | spdy_util_.ConstructSpdySettings(initial_settings)); |
| 4248 | |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4249 | // Construct the persisted SETTINGS frame. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4250 | const SettingsMap& settings = |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4251 | spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4252 | host_port_pair); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4253 | scoped_ptr<SpdyFrame> settings_frame( |
| 4254 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4255 | |
| 4256 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4257 | scoped_ptr<SpdyFrame> req( |
| 4258 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4259 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4260 | MockWrite writes[] = { |
| 4261 | CreateMockWrite(*initial_settings_frame, 0), |
| 4262 | CreateMockWrite(*settings_frame, 1), |
| 4263 | CreateMockWrite(*req, 2), |
| 4264 | }; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4265 | |
| 4266 | // Construct the reply. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4267 | scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); |
| 4268 | (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 4269 | (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4270 | scoped_ptr<SpdyFrame> reply( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4271 | spdy_util_.ConstructSpdyFrame(kSynReplyInfo, reply_headers.Pass())); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4272 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4273 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4274 | MockRead reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4275 | CreateMockRead(*reply, 3), |
| 4276 | CreateMockRead(*body, 4), |
| 4277 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4278 | }; |
| 4279 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4280 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4281 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 4282 | helper.RunDefaultTest(); |
| 4283 | helper.VerifyDataConsumed(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4284 | TransactionHelperResult out = helper.output(); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4285 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4286 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4287 | EXPECT_EQ("hello!", out.response_data); |
| 4288 | |
| 4289 | { |
| 4290 | // Verify we had two persisted settings. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4291 | const SettingsMap& settings_map = |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4292 | spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4293 | host_port_pair); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4294 | ASSERT_EQ(2u, settings_map.size()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4295 | |
| 4296 | // Verify the first persisted setting. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4297 | SettingsMap::const_iterator it1 = settings_map.find(kSampleId1); |
| 4298 | EXPECT_TRUE(it1 != settings_map.end()); |
| 4299 | SettingsFlagsAndValue flags_and_value1 = it1->second; |
| 4300 | EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1.first); |
| 4301 | EXPECT_EQ(kSampleValue1, flags_and_value1.second); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4302 | |
| 4303 | // Verify the second persisted setting. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4304 | SettingsMap::const_iterator it2 = settings_map.find(kSampleId2); |
| 4305 | EXPECT_TRUE(it2 != settings_map.end()); |
| 4306 | SettingsFlagsAndValue flags_and_value2 = it2->second; |
| 4307 | EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value2.first); |
| 4308 | EXPECT_EQ(kSampleValue2, flags_and_value2.second); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4309 | } |
| 4310 | } |
| 4311 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4312 | TEST_P(SpdyNetworkTransactionTest, GoAwayWithActiveStream) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4313 | scoped_ptr<SpdyFrame> req( |
| 4314 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4315 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 69d717bd | 2010-04-21 18:43:21 | [diff] [blame] | 4316 | |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4317 | scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway()); |
[email protected] | 69d717bd | 2010-04-21 18:43:21 | [diff] [blame] | 4318 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4319 | CreateMockRead(*go_away, 1), |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4320 | }; |
| 4321 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4322 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4323 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4324 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4325 | helper.AddData(&data); |
| 4326 | helper.RunToCompletion(&data); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4327 | TransactionHelperResult out = helper.output(); |
[email protected] | c9336d2 | 2010-08-10 00:04:18 | [diff] [blame] | 4328 | EXPECT_EQ(ERR_ABORTED, out.rv); |
[email protected] | 69d717bd | 2010-04-21 18:43:21 | [diff] [blame] | 4329 | } |
| 4330 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4331 | TEST_P(SpdyNetworkTransactionTest, CloseWithActiveStream) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4332 | scoped_ptr<SpdyFrame> req( |
| 4333 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4334 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4335 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4336 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4337 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4338 | CreateMockRead(*resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4339 | }; |
| 4340 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4341 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4342 | BoundNetLog log; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4343 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4344 | log, GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4345 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4346 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4347 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4348 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4349 | TestCompletionCallback callback; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4350 | TransactionHelperResult out; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4351 | out.rv = trans->Start(&CreateGetRequest(), callback.callback(), log); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4352 | |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4353 | EXPECT_EQ(out.rv, ERR_IO_PENDING); |
| 4354 | out.rv = callback.WaitForResult(); |
| 4355 | EXPECT_EQ(out.rv, OK); |
| 4356 | |
| 4357 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4358 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4359 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4360 | out.rv = ReadTransaction(trans, &out.response_data); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4361 | EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); |
| 4362 | |
| 4363 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4364 | helper.VerifyDataConsumed(); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4365 | } |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4366 | |
bnc | a7f994a | 2015-01-20 19:39:41 | [diff] [blame] | 4367 | // HTTP_1_1_REQUIRED results in ERR_HTTP_1_1_REQUIRED. |
| 4368 | TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredError) { |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 4369 | // HTTP_1_1_REQUIRED is only supported by HTTP/2. |
| 4370 | if (spdy_util_.spdy_version() < HTTP2) |
bnc | a7f994a | 2015-01-20 19:39:41 | [diff] [blame] | 4371 | return; |
| 4372 | |
| 4373 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 4374 | BoundNetLog(), GetParam(), nullptr); |
| 4375 | |
| 4376 | scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway( |
| 4377 | 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); |
| 4378 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4379 | CreateMockRead(*go_away, 0), |
bnc | a7f994a | 2015-01-20 19:39:41 | [diff] [blame] | 4380 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4381 | SequencedSocketData data(reads, arraysize(reads), nullptr, 0); |
bnc | a7f994a | 2015-01-20 19:39:41 | [diff] [blame] | 4382 | |
| 4383 | helper.RunToCompletion(&data); |
| 4384 | TransactionHelperResult out = helper.output(); |
| 4385 | EXPECT_EQ(ERR_HTTP_1_1_REQUIRED, out.rv); |
| 4386 | } |
| 4387 | |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4388 | // Retry with HTTP/1.1 when receiving HTTP_1_1_REQUIRED. Note that no actual |
| 4389 | // protocol negotiation happens, instead this test forces protocols for both |
| 4390 | // sockets. |
| 4391 | TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredRetry) { |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 4392 | // HTTP_1_1_REQUIRED is only supported by HTTP/2. |
| 4393 | if (spdy_util_.spdy_version() < HTTP2) |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4394 | return; |
| 4395 | // HTTP_1_1_REQUIRED implementation relies on the assumption that HTTP/2 is |
| 4396 | // only spoken over SSL. |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4397 | if (GetParam().ssl_type != HTTPS_SPDY_VIA_NPN) |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4398 | return; |
| 4399 | |
| 4400 | HttpRequestInfo request; |
| 4401 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4402 | request.url = GURL("https://www.example.org/"); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4403 | scoped_ptr<SpdySessionDependencies> session_deps( |
| 4404 | CreateSpdySessionDependencies(GetParam())); |
| 4405 | // Do not force SPDY so that second socket can negotiate HTTP/1.1. |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4406 | session_deps->next_protos = SpdyNextProtos(); |
| 4407 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4408 | GetParam(), session_deps.Pass()); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4409 | |
| 4410 | // First socket: HTTP/2 request rejected with HTTP_1_1_REQUIRED. |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4411 | const char* url = request.url.spec().c_str(); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4412 | scoped_ptr<SpdyHeaderBlock> headers(spdy_util_.ConstructGetHeaderBlock(url)); |
| 4413 | scoped_ptr<SpdyFrame> req( |
| 4414 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4415 | MockWrite writes0[] = {CreateMockWrite(*req, 0)}; |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4416 | scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway( |
| 4417 | 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4418 | MockRead reads0[] = {CreateMockRead(*go_away, 1)}; |
| 4419 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 4420 | arraysize(writes0)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4421 | |
| 4422 | scoped_ptr<SSLSocketDataProvider> ssl_provider0( |
| 4423 | new SSLSocketDataProvider(ASYNC, OK)); |
| 4424 | // Expect HTTP/2 protocols too in SSLConfig. |
| 4425 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4426 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY31); |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 4427 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP2); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4428 | // Force SPDY. |
| 4429 | ssl_provider0->SetNextProto(GetParam().protocol); |
| 4430 | helper.AddDataWithSSLSocketDataProvider(&data0, ssl_provider0.Pass()); |
| 4431 | |
| 4432 | // Second socket: falling back to HTTP/1.1. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4433 | MockWrite writes1[] = {MockWrite(ASYNC, 0, |
| 4434 | "GET / HTTP/1.1\r\n" |
| 4435 | "Host: www.example.org\r\n" |
| 4436 | "Connection: keep-alive\r\n\r\n")}; |
| 4437 | MockRead reads1[] = {MockRead(ASYNC, 1, |
| 4438 | "HTTP/1.1 200 OK\r\n" |
| 4439 | "Content-Length: 5\r\n\r\n" |
| 4440 | "hello")}; |
| 4441 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 4442 | arraysize(writes1)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4443 | |
| 4444 | scoped_ptr<SSLSocketDataProvider> ssl_provider1( |
| 4445 | new SSLSocketDataProvider(ASYNC, OK)); |
| 4446 | // Expect only HTTP/1.1 protocol in SSLConfig. |
| 4447 | ssl_provider1->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4448 | // Force HTTP/1.1. |
| 4449 | ssl_provider1->SetNextProto(kProtoHTTP11); |
| 4450 | helper.AddDataWithSSLSocketDataProvider(&data1, ssl_provider1.Pass()); |
| 4451 | |
| 4452 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 4453 | helper.session()->spdy_session_pool()->http_server_properties(); |
| 4454 | const HostPortPair host_port_pair = HostPortPair::FromURL(GURL(url)); |
| 4455 | EXPECT_FALSE(http_server_properties->RequiresHTTP11(host_port_pair)); |
| 4456 | |
| 4457 | helper.RunPreTestSetup(); |
| 4458 | helper.StartDefaultTest(); |
| 4459 | helper.FinishDefaultTestWithoutVerification(); |
| 4460 | helper.VerifyDataConsumed(); |
| 4461 | EXPECT_TRUE(http_server_properties->RequiresHTTP11(host_port_pair)); |
| 4462 | |
| 4463 | const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
| 4464 | ASSERT_TRUE(response != nullptr); |
| 4465 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 4466 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4467 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 4468 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, response->connection_info); |
| 4469 | EXPECT_TRUE(response->was_npn_negotiated); |
| 4470 | EXPECT_TRUE(request.url.SchemeIs("https")); |
| 4471 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 4472 | EXPECT_EQ(443, response->socket_address.port()); |
| 4473 | std::string response_data; |
| 4474 | ASSERT_EQ(OK, ReadTransaction(helper.trans(), &response_data)); |
| 4475 | EXPECT_EQ("hello", response_data); |
| 4476 | } |
| 4477 | |
| 4478 | // Retry with HTTP/1.1 to the proxy when receiving HTTP_1_1_REQUIRED from the |
| 4479 | // proxy. Note that no actual protocol negotiation happens, instead this test |
| 4480 | // forces protocols for both sockets. |
| 4481 | TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredProxyRetry) { |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 4482 | // HTTP_1_1_REQUIRED is only supported by HTTP/2. |
| 4483 | if (spdy_util_.spdy_version() < HTTP2) |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4484 | return; |
| 4485 | // HTTP_1_1_REQUIRED implementation relies on the assumption that HTTP/2 is |
| 4486 | // only spoken over SSL. |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4487 | if (GetParam().ssl_type != HTTPS_SPDY_VIA_NPN) |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4488 | return; |
| 4489 | |
| 4490 | HttpRequestInfo request; |
| 4491 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4492 | request.url = GURL("https://www.example.org/"); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4493 | scoped_ptr<SpdySessionDependencies> session_deps( |
| 4494 | CreateSpdySessionDependencies( |
| 4495 | GetParam(), |
| 4496 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"))); |
| 4497 | // Do not force SPDY so that second socket can negotiate HTTP/1.1. |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4498 | session_deps->next_protos = SpdyNextProtos(); |
| 4499 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4500 | GetParam(), session_deps.Pass()); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4501 | |
| 4502 | // First socket: HTTP/2 CONNECT rejected with HTTP_1_1_REQUIRED. |
| 4503 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4504 | nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4505 | MockWrite writes0[] = {CreateMockWrite(*req, 0)}; |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4506 | scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway( |
| 4507 | 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4508 | MockRead reads0[] = {CreateMockRead(*go_away, 1)}; |
| 4509 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 4510 | arraysize(writes0)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4511 | |
| 4512 | scoped_ptr<SSLSocketDataProvider> ssl_provider0( |
| 4513 | new SSLSocketDataProvider(ASYNC, OK)); |
| 4514 | // Expect HTTP/2 protocols too in SSLConfig. |
| 4515 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4516 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY31); |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 4517 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP2); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4518 | // Force SPDY. |
| 4519 | ssl_provider0->SetNextProto(GetParam().protocol); |
| 4520 | helper.AddDataWithSSLSocketDataProvider(&data0, ssl_provider0.Pass()); |
| 4521 | |
| 4522 | // Second socket: retry using HTTP/1.1. |
| 4523 | MockWrite writes1[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4524 | MockWrite(ASYNC, 0, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4525 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4526 | "Host: www.example.org:443\r\n" |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4527 | "Proxy-Connection: keep-alive\r\n\r\n"), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4528 | MockWrite(ASYNC, 2, |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4529 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4530 | "Host: www.example.org\r\n" |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4531 | "Connection: keep-alive\r\n\r\n"), |
| 4532 | }; |
| 4533 | |
| 4534 | MockRead reads1[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4535 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 4536 | MockRead(ASYNC, 3, |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4537 | "HTTP/1.1 200 OK\r\n" |
| 4538 | "Content-Length: 5\r\n\r\n" |
| 4539 | "hello"), |
| 4540 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4541 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 4542 | arraysize(writes1)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4543 | |
| 4544 | scoped_ptr<SSLSocketDataProvider> ssl_provider1( |
| 4545 | new SSLSocketDataProvider(ASYNC, OK)); |
| 4546 | // Expect only HTTP/1.1 protocol in SSLConfig. |
| 4547 | ssl_provider1->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4548 | // Force HTTP/1.1. |
| 4549 | ssl_provider1->SetNextProto(kProtoHTTP11); |
| 4550 | helper.AddDataWithSSLSocketDataProvider(&data1, ssl_provider1.Pass()); |
| 4551 | |
| 4552 | // A third socket is needed for the tunnelled connection. |
| 4553 | scoped_ptr<SSLSocketDataProvider> ssl_provider2( |
| 4554 | new SSLSocketDataProvider(ASYNC, OK)); |
| 4555 | helper.session_deps()->socket_factory->AddSSLSocketDataProvider( |
| 4556 | ssl_provider2.get()); |
| 4557 | |
| 4558 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 4559 | helper.session()->spdy_session_pool()->http_server_properties(); |
| 4560 | const HostPortPair proxy_host_port_pair = HostPortPair("myproxy", 70); |
| 4561 | EXPECT_FALSE(http_server_properties->RequiresHTTP11(proxy_host_port_pair)); |
| 4562 | |
| 4563 | helper.RunPreTestSetup(); |
| 4564 | helper.StartDefaultTest(); |
| 4565 | helper.FinishDefaultTestWithoutVerification(); |
| 4566 | helper.VerifyDataConsumed(); |
| 4567 | EXPECT_TRUE(http_server_properties->RequiresHTTP11(proxy_host_port_pair)); |
| 4568 | |
| 4569 | const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
| 4570 | ASSERT_TRUE(response != nullptr); |
| 4571 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 4572 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4573 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 4574 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, response->connection_info); |
| 4575 | EXPECT_FALSE(response->was_npn_negotiated); |
| 4576 | EXPECT_TRUE(request.url.SchemeIs("https")); |
| 4577 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 4578 | EXPECT_EQ(70, response->socket_address.port()); |
| 4579 | std::string response_data; |
| 4580 | ASSERT_EQ(OK, ReadTransaction(helper.trans(), &response_data)); |
| 4581 | EXPECT_EQ("hello", response_data); |
| 4582 | } |
| 4583 | |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4584 | // Test to make sure we can correctly connect through a proxy. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4585 | TEST_P(SpdyNetworkTransactionTest, ProxyConnect) { |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4586 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4587 | BoundNetLog(), GetParam(), NULL); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4588 | helper.session_deps() = CreateSpdySessionDependencies( |
| 4589 | GetParam(), ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4590 | helper.SetSession( |
| 4591 | SpdySessionDependencies::SpdyCreateSession(helper.session_deps().get())); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4592 | helper.RunPreTestSetup(); |
| 4593 | HttpNetworkTransaction* trans = helper.trans(); |
| 4594 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4595 | const char kConnect443[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4596 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4597 | "Host: www.example.org:443\r\n" |
rch | cb934f56 | 2015-04-07 16:25:12 | [diff] [blame] | 4598 | "Proxy-Connection: keep-alive\r\n\r\n"}; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4599 | const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4600 | scoped_ptr<SpdyFrame> req( |
| 4601 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4602 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4603 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4604 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4605 | MockWrite writes[] = { |
| 4606 | MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0), |
| 4607 | CreateMockWrite(*req, 2), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4608 | }; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4609 | MockRead reads[] = { |
| 4610 | MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), |
| 4611 | CreateMockRead(*resp, 3), |
| 4612 | CreateMockRead(*body.get(), 4), |
| 4613 | MockRead(ASYNC, 0, 0, 5), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4614 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4615 | scoped_ptr<SequencedSocketData> data(new SequencedSocketData( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4616 | reads, arraysize(reads), writes, arraysize(writes))); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4617 | |
| 4618 | helper.AddData(data.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4619 | TestCompletionCallback callback; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4620 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4621 | int rv = trans->Start( |
| 4622 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4623 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4624 | |
| 4625 | rv = callback.WaitForResult(); |
| 4626 | EXPECT_EQ(0, rv); |
| 4627 | |
| 4628 | // Verify the SYN_REPLY. |
| 4629 | HttpResponseInfo response = *trans->GetResponseInfo(); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4630 | ASSERT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4631 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4632 | |
| 4633 | std::string response_data; |
| 4634 | ASSERT_EQ(OK, ReadTransaction(trans, &response_data)); |
| 4635 | EXPECT_EQ("hello!", response_data); |
| 4636 | helper.VerifyDataConsumed(); |
| 4637 | } |
| 4638 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4639 | // Test to make sure we can correctly connect through a proxy to |
| 4640 | // www.example.org, if there already exists a direct spdy connection to |
| 4641 | // www.example.org. See https://crbug.com/49874. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4642 | TEST_P(SpdyNetworkTransactionTest, DirectConnectProxyReconnect) { |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4643 | // When setting up the first transaction, we store the SpdySessionPool so that |
| 4644 | // we can use the same pool in the second transaction. |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4645 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4646 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 733b7a6d | 2010-08-25 01:38:43 | [diff] [blame] | 4647 | |
| 4648 | // Use a proxy service which returns a proxy fallback list from DIRECT to |
| 4649 | // myproxy:70. For this test there will be no fallback, so it is equivalent |
| 4650 | // to simply DIRECT. The reason for appending the second proxy is to verify |
| 4651 | // that the session pool key used does is just "DIRECT". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4652 | helper.session_deps() = CreateSpdySessionDependencies( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4653 | GetParam(), |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4654 | ProxyService::CreateFixedFromPacResult("DIRECT; PROXY myproxy:70")); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4655 | helper.SetSession( |
| 4656 | SpdySessionDependencies::SpdyCreateSession(helper.session_deps().get())); |
[email protected] | 733b7a6d | 2010-08-25 01:38:43 | [diff] [blame] | 4657 | |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 4658 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4659 | helper.RunPreTestSetup(); |
| 4660 | |
| 4661 | // Construct and send a simple GET request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4662 | scoped_ptr<SpdyFrame> req( |
| 4663 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4664 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4665 | CreateMockWrite(*req, 0), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4666 | }; |
| 4667 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4668 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4669 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4670 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4671 | CreateMockRead(*resp, 1), |
| 4672 | CreateMockRead(*body, 2), |
| 4673 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), // Force a pause |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4674 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4675 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4676 | helper.AddData(&data); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4677 | HttpNetworkTransaction* trans = helper.trans(); |
| 4678 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4679 | TestCompletionCallback callback; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4680 | TransactionHelperResult out; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4681 | out.rv = trans->Start( |
| 4682 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4683 | |
| 4684 | EXPECT_EQ(out.rv, ERR_IO_PENDING); |
| 4685 | out.rv = callback.WaitForResult(); |
| 4686 | EXPECT_EQ(out.rv, OK); |
| 4687 | |
| 4688 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4689 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4690 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4691 | out.rv = ReadTransaction(trans, &out.response_data); |
| 4692 | EXPECT_EQ(OK, out.rv); |
| 4693 | out.status_line = response->headers->GetStatusLine(); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4694 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4695 | EXPECT_EQ("hello!", out.response_data); |
| 4696 | |
| 4697 | // Check that the SpdySession is still in the SpdySessionPool. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4698 | HostPortPair host_port_pair("www.example.org", helper.port()); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 4699 | SpdySessionKey session_pool_key_direct( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 4700 | host_port_pair, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 4701 | EXPECT_TRUE(HasSpdySession(spdy_session_pool, session_pool_key_direct)); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 4702 | SpdySessionKey session_pool_key_proxy( |
[email protected] | 31e68d7 | 2010-08-25 06:36:58 | [diff] [blame] | 4703 | host_port_pair, |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 4704 | ProxyServer::FromURI("www.foo.com", ProxyServer::SCHEME_HTTP), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 4705 | PRIVACY_MODE_DISABLED); |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 4706 | EXPECT_FALSE(HasSpdySession(spdy_session_pool, session_pool_key_proxy)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4707 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4708 | // New SpdyTestUtil instance for the session that will be used for the |
| 4709 | // proxy connection. |
| 4710 | SpdyTestUtil spdy_util_2(GetParam().protocol, |
| 4711 | GetParam().priority_to_dependency); |
| 4712 | |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4713 | // Set up data for the proxy connection. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4714 | const char kConnect443[] = { |
| 4715 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4716 | "Host: www.example.org:443\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4717 | "Proxy-Connection: keep-alive\r\n\r\n"}; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4718 | const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4719 | scoped_ptr<SpdyFrame> req2(spdy_util_2.ConstructSpdyGet( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4720 | GetDefaultUrlWithPath("/foo.dat").c_str(), false, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4721 | scoped_ptr<SpdyFrame> resp2(spdy_util_2.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4722 | scoped_ptr<SpdyFrame> body2(spdy_util_2.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4723 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4724 | MockWrite writes2[] = { |
| 4725 | MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0), |
| 4726 | CreateMockWrite(*req2, 2), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4727 | }; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4728 | MockRead reads2[] = { |
| 4729 | MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), |
| 4730 | CreateMockRead(*resp2, 3), |
| 4731 | CreateMockRead(*body2, 4), |
| 4732 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4733 | }; |
| 4734 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4735 | scoped_ptr<SequencedSocketData> data_proxy(new SequencedSocketData( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4736 | reads2, arraysize(reads2), writes2, arraysize(writes2))); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4737 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4738 | // Create another request to www.example.org, but this time through a proxy. |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4739 | HttpRequestInfo request_proxy; |
| 4740 | request_proxy.method = "GET"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4741 | request_proxy.url = GURL(GetDefaultUrlWithPath("/foo.dat")); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4742 | request_proxy.load_flags = 0; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4743 | scoped_ptr<SpdySessionDependencies> ssd_proxy( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4744 | CreateSpdySessionDependencies(GetParam())); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4745 | // Ensure that this transaction uses the same SpdySessionPool. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4746 | scoped_ptr<HttpNetworkSession> session_proxy( |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 4747 | SpdySessionDependencies::SpdyCreateSession(ssd_proxy.get())); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4748 | NormalSpdyTransactionHelper helper_proxy(request_proxy, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4749 | BoundNetLog(), GetParam(), NULL); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4750 | HttpNetworkSessionPeer session_peer(session_proxy.get()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4751 | scoped_ptr<ProxyService> proxy_service( |
| 4752 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 4753 | session_peer.SetProxyService(proxy_service.get()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4754 | helper_proxy.session_deps().swap(ssd_proxy); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4755 | helper_proxy.SetSession(session_proxy.Pass()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4756 | helper_proxy.RunPreTestSetup(); |
| 4757 | helper_proxy.AddData(data_proxy.get()); |
| 4758 | |
| 4759 | HttpNetworkTransaction* trans_proxy = helper_proxy.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4760 | TestCompletionCallback callback_proxy; |
| 4761 | int rv = trans_proxy->Start( |
| 4762 | &request_proxy, callback_proxy.callback(), BoundNetLog()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4763 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4764 | rv = callback_proxy.WaitForResult(); |
| 4765 | EXPECT_EQ(0, rv); |
| 4766 | |
| 4767 | HttpResponseInfo response_proxy = *trans_proxy->GetResponseInfo(); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4768 | ASSERT_TRUE(response_proxy.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4769 | EXPECT_EQ("HTTP/1.1 200", response_proxy.headers->GetStatusLine()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4770 | |
| 4771 | std::string response_data; |
| 4772 | ASSERT_EQ(OK, ReadTransaction(trans_proxy, &response_data)); |
| 4773 | EXPECT_EQ("hello!", response_data); |
| 4774 | |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4775 | helper_proxy.VerifyDataConsumed(); |
| 4776 | } |
| 4777 | |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4778 | // When we get a TCP-level RST, we need to retry a HttpNetworkTransaction |
| 4779 | // on a new connection, if the connection was previously known to be good. |
| 4780 | // This can happen when a server reboots without saying goodbye, or when |
| 4781 | // we're behind a NAT that masked the RST. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4782 | TEST_P(SpdyNetworkTransactionTest, VerifyRetryOnConnectionReset) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4783 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4784 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4785 | MockRead reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4786 | CreateMockRead(*resp, 1), |
| 4787 | CreateMockRead(*body, 2), |
| 4788 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 4789 | MockRead(ASYNC, ERR_CONNECTION_RESET, 4), |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4790 | }; |
| 4791 | |
| 4792 | MockRead reads2[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4793 | CreateMockRead(*resp, 1), |
| 4794 | CreateMockRead(*body, 2), |
| 4795 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4796 | }; |
| 4797 | |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4798 | scoped_ptr<SpdyFrame> req( |
| 4799 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4800 | // In all cases the connection will be reset before req3 can be |
| 4801 | // dispatched, destroying both streams. |
| 4802 | spdy_util_.UpdateWithStreamDestruction(1); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4803 | scoped_ptr<SpdyFrame> req3( |
| 4804 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
| 4805 | MockWrite writes1[] = {CreateMockWrite(*req, 0), CreateMockWrite(*req3, 5)}; |
| 4806 | MockWrite writes2[] = {CreateMockWrite(*req, 0)}; |
| 4807 | |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4808 | // This test has a couple of variants. |
| 4809 | enum { |
| 4810 | // Induce the RST while waiting for our transaction to send. |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4811 | VARIANT_RST_DURING_SEND_COMPLETION = 0, |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4812 | // Induce the RST while waiting for our transaction to read. |
| 4813 | // In this case, the send completed - everything copied into the SNDBUF. |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4814 | VARIANT_RST_DURING_READ_COMPLETION = 1 |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4815 | }; |
| 4816 | |
| 4817 | for (int variant = VARIANT_RST_DURING_SEND_COMPLETION; |
| 4818 | variant <= VARIANT_RST_DURING_READ_COMPLETION; |
| 4819 | ++variant) { |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4820 | SequencedSocketData data1(reads, arraysize(reads), writes1, 1 + variant); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4821 | |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4822 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 4823 | arraysize(writes2)); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4824 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4825 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4826 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4827 | helper.AddData(&data1); |
| 4828 | helper.AddData(&data2); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4829 | helper.RunPreTestSetup(); |
| 4830 | |
| 4831 | for (int i = 0; i < 2; ++i) { |
| 4832 | scoped_ptr<HttpNetworkTransaction> trans( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4833 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4834 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4835 | TestCompletionCallback callback; |
| 4836 | int rv = trans->Start( |
| 4837 | &helper.request(), callback.callback(), BoundNetLog()); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4838 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4839 | // On the second transaction, we trigger the RST. |
| 4840 | if (i == 1) { |
| 4841 | if (variant == VARIANT_RST_DURING_READ_COMPLETION) { |
| 4842 | // Writes to the socket complete asynchronously on SPDY by running |
| 4843 | // through the message loop. Complete the write here. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4844 | base::RunLoop().RunUntilIdle(); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4845 | } |
| 4846 | |
| 4847 | // Now schedule the ERR_CONNECTION_RESET. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4848 | data1.CompleteRead(); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4849 | } |
| 4850 | rv = callback.WaitForResult(); |
| 4851 | EXPECT_EQ(OK, rv); |
| 4852 | |
| 4853 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 351ab64 | 2010-08-05 16:55:31 | [diff] [blame] | 4854 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4855 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4856 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4857 | std::string response_data; |
| 4858 | rv = ReadTransaction(trans.get(), &response_data); |
| 4859 | EXPECT_EQ(OK, rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4860 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4861 | EXPECT_EQ("hello!", response_data); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4862 | base::RunLoop().RunUntilIdle(); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | helper.VerifyDataConsumed(); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4866 | base::RunLoop().RunUntilIdle(); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4867 | } |
| 4868 | } |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4869 | |
| 4870 | // Test that turning SPDY on and off works properly. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4871 | TEST_P(SpdyNetworkTransactionTest, SpdyOnOffToggle) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 4872 | HttpStreamFactory::set_spdy_enabled(true); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4873 | scoped_ptr<SpdyFrame> req( |
| 4874 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4875 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4876 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4877 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4878 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4879 | MockRead spdy_reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4880 | CreateMockRead(*resp, 1), |
| 4881 | CreateMockRead(*body, 2), |
| 4882 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4883 | }; |
| 4884 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4885 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4886 | arraysize(spdy_writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4887 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4888 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4889 | helper.RunToCompletion(&data); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4890 | TransactionHelperResult out = helper.output(); |
| 4891 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4892 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4893 | EXPECT_EQ("hello!", out.response_data); |
| 4894 | |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4895 | HttpStreamFactory::set_spdy_enabled(false); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4896 | MockWrite http_writes[] = { |
| 4897 | MockWrite(SYNCHRONOUS, 0, |
| 4898 | "GET / HTTP/1.1\r\n" |
| 4899 | "Host: www.example.org\r\n" |
| 4900 | "Connection: keep-alive\r\n\r\n"), |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4901 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4902 | |
| 4903 | MockRead http_reads[] = { |
| 4904 | MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 4905 | MockRead(SYNCHRONOUS, 2, "hello from http"), |
| 4906 | MockRead(SYNCHRONOUS, OK, 3), |
| 4907 | }; |
| 4908 | SequencedSocketData data2(http_reads, arraysize(http_reads), http_writes, |
| 4909 | arraysize(http_writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4910 | NormalSpdyTransactionHelper helper2(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4911 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4912 | helper2.SetSpdyDisabled(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4913 | helper2.RunToCompletion(&data2); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4914 | TransactionHelperResult out2 = helper2.output(); |
| 4915 | EXPECT_EQ(OK, out2.rv); |
| 4916 | EXPECT_EQ("HTTP/1.1 200 OK", out2.status_line); |
| 4917 | EXPECT_EQ("hello from http", out2.response_data); |
| 4918 | |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4919 | HttpStreamFactory::set_spdy_enabled(true); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4920 | } |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4921 | |
| 4922 | // Tests that Basic authentication works over SPDY |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4923 | TEST_P(SpdyNetworkTransactionTest, SpdyBasicAuth) { |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4924 | HttpStreamFactory::set_spdy_enabled(true); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4925 | |
| 4926 | // The first request will be a bare GET, the second request will be a |
| 4927 | // GET with an Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4928 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4929 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4930 | // Will be refused for lack of auth. |
| 4931 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4932 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4933 | "authorization", "Basic Zm9vOmJhcg==" |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4934 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4935 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4936 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 4937 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 4938 | false, 3, LOWEST, true)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4939 | MockWrite spdy_writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4940 | CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4941 | }; |
| 4942 | |
| 4943 | // The first response is a 401 authentication challenge, and the second |
| 4944 | // response will be a 200 response since the second request includes a valid |
| 4945 | // Authorization header. |
| 4946 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | fb9e431 | 2012-02-17 06:27:26 | [diff] [blame] | 4947 | "www-authenticate", |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4948 | "Basic realm=\"MyRealm\"" |
| 4949 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4950 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4951 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4952 | "401 Authentication Required", |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4953 | kExtraAuthenticationHeaders, |
| 4954 | arraysize(kExtraAuthenticationHeaders) / 2, |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4955 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4956 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4957 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4958 | scoped_ptr<SpdyFrame> resp_data( |
| 4959 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4960 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4961 | MockRead spdy_reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4962 | CreateMockRead(*resp_authentication, 1), |
| 4963 | CreateMockRead(*body_authentication, 2), |
| 4964 | CreateMockRead(*resp_data, 4), |
| 4965 | CreateMockRead(*body_data, 5), |
| 4966 | MockRead(ASYNC, 0, 6), |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4967 | }; |
| 4968 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4969 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4970 | arraysize(spdy_writes)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4971 | HttpRequestInfo request(CreateGetRequest()); |
| 4972 | BoundNetLog net_log; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4973 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 4974 | net_log, GetParam(), NULL); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4975 | |
| 4976 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4977 | helper.AddData(&data); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4978 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4979 | TestCompletionCallback callback; |
| 4980 | const int rv_start = trans->Start(&request, callback.callback(), net_log); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4981 | EXPECT_EQ(ERR_IO_PENDING, rv_start); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4982 | const int rv_start_complete = callback.WaitForResult(); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4983 | EXPECT_EQ(OK, rv_start_complete); |
| 4984 | |
| 4985 | // Make sure the response has an auth challenge. |
| 4986 | const HttpResponseInfo* const response_start = trans->GetResponseInfo(); |
| 4987 | ASSERT_TRUE(response_start != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4988 | ASSERT_TRUE(response_start->headers.get() != NULL); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4989 | EXPECT_EQ(401, response_start->headers->response_code()); |
| 4990 | EXPECT_TRUE(response_start->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4991 | AuthChallengeInfo* auth_challenge = response_start->auth_challenge.get(); |
| 4992 | ASSERT_TRUE(auth_challenge != NULL); |
| 4993 | EXPECT_FALSE(auth_challenge->is_proxy); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 4994 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4995 | EXPECT_EQ("MyRealm", auth_challenge->realm); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4996 | |
| 4997 | // Restart with a username/password. |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 4998 | AuthCredentials credentials(base::ASCIIToUTF16("foo"), |
| 4999 | base::ASCIIToUTF16("bar")); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5000 | TestCompletionCallback callback_restart; |
| 5001 | const int rv_restart = trans->RestartWithAuth( |
| 5002 | credentials, callback_restart.callback()); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5003 | EXPECT_EQ(ERR_IO_PENDING, rv_restart); |
| 5004 | const int rv_restart_complete = callback_restart.WaitForResult(); |
| 5005 | EXPECT_EQ(OK, rv_restart_complete); |
| 5006 | // TODO(cbentzel): This is actually the same response object as before, but |
| 5007 | // data has changed. |
| 5008 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 5009 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5010 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5011 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5012 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 5013 | } |
| 5014 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5015 | TEST_P(SpdyNetworkTransactionTest, ServerPushWithHeaders) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5016 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5017 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5018 | scoped_ptr<SpdyFrame> stream1_body( |
| 5019 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5020 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5021 | CreateMockWrite(*stream1_syn, 0), |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5022 | }; |
| 5023 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5024 | scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5025 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
| 5026 | initial_headers.get()); |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5027 | scoped_ptr<SpdyFrame> stream2_syn( |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 5028 | spdy_util_.ConstructInitialSpdyPushFrame(initial_headers.Pass(), 2, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5029 | |
| 5030 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5031 | (*late_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 5032 | (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 5033 | (*late_headers)["hello"] = "bye"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5034 | scoped_ptr<SpdyFrame> stream2_headers( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5035 | spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5036 | false, |
| 5037 | 2, |
| 5038 | LOWEST, |
| 5039 | HEADERS, |
| 5040 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5041 | 0)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5042 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5043 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5044 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5045 | const char kPushedData[] = "pushed"; |
| 5046 | scoped_ptr<SpdyFrame> stream2_body( |
| 5047 | spdy_util_.ConstructSpdyBodyFrame( |
| 5048 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5049 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5050 | CreateMockRead(*stream1_reply, 1), |
| 5051 | CreateMockRead(*stream2_syn, 2), |
| 5052 | CreateMockRead(*stream2_headers, 3), |
| 5053 | CreateMockRead(*stream1_body, 4, SYNCHRONOUS), |
| 5054 | CreateMockRead(*stream2_body, 5), |
| 5055 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a pause |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5056 | }; |
| 5057 | |
| 5058 | HttpResponseInfo response; |
| 5059 | HttpResponseInfo response2; |
| 5060 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5061 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5062 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5063 | &response, |
| 5064 | &response2, |
| 5065 | expected_push_result); |
| 5066 | |
| 5067 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5068 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5069 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5070 | |
| 5071 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5072 | EXPECT_TRUE(response2.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5073 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5074 | } |
| 5075 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5076 | TEST_P(SpdyNetworkTransactionTest, ServerPushClaimBeforeHeaders) { |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5077 | // We push a stream and attempt to claim it before the headers come down. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5078 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5079 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5080 | scoped_ptr<SpdyFrame> stream1_body( |
| 5081 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5082 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5083 | CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5084 | }; |
| 5085 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5086 | scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5087 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
| 5088 | initial_headers.get()); |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5089 | scoped_ptr<SpdyFrame> stream2_syn( |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 5090 | spdy_util_.ConstructInitialSpdyPushFrame(initial_headers.Pass(), 2, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5091 | |
| 5092 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5093 | (*late_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 5094 | (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 5095 | (*late_headers)["hello"] = "bye"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5096 | scoped_ptr<SpdyFrame> stream2_headers( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5097 | spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5098 | false, |
| 5099 | 2, |
| 5100 | LOWEST, |
| 5101 | HEADERS, |
| 5102 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5103 | 0)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5104 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5105 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5106 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5107 | const char kPushedData[] = "pushed"; |
| 5108 | scoped_ptr<SpdyFrame> stream2_body( |
| 5109 | spdy_util_.ConstructSpdyBodyFrame( |
| 5110 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5111 | MockRead reads[] = { |
| 5112 | CreateMockRead(*stream1_reply, 1), |
| 5113 | CreateMockRead(*stream2_syn, 2), |
| 5114 | CreateMockRead(*stream1_body, 3), |
| 5115 | CreateMockRead(*stream2_headers, 4), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5116 | CreateMockRead(*stream2_body, 5), |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 5117 | MockRead(ASYNC, 0, 6), // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5118 | }; |
| 5119 | |
| 5120 | HttpResponseInfo response; |
| 5121 | HttpResponseInfo response2; |
| 5122 | std::string expected_push_result("pushed"); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5123 | DeterministicSocketData data(reads, arraysize(reads), |
| 5124 | writes, arraysize(writes)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5125 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5126 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5127 | BoundNetLog(), GetParam(), NULL); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5128 | helper.SetDeterministic(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5129 | helper.AddDeterministicData(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5130 | helper.RunPreTestSetup(); |
| 5131 | |
| 5132 | HttpNetworkTransaction* trans = helper.trans(); |
| 5133 | |
| 5134 | // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM, |
| 5135 | // and the body of the primary stream, but before we've received the HEADERS |
| 5136 | // for the pushed stream. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5137 | data.SetStop(3); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5138 | |
| 5139 | // Start the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5140 | TestCompletionCallback callback; |
| 5141 | int rv = trans->Start( |
| 5142 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5143 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5144 | data.Run(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5145 | rv = callback.WaitForResult(); |
| 5146 | EXPECT_EQ(0, rv); |
| 5147 | |
| 5148 | // Request the pushed path. At this point, we've received the push, but the |
| 5149 | // headers are not yet complete. |
| 5150 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5151 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5152 | rv = trans2->Start( |
| 5153 | &CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5154 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5155 | data.RunFor(3); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5156 | base::RunLoop().RunUntilIdle(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5157 | |
| 5158 | // Read the server push body. |
| 5159 | std::string result2; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 5160 | ReadResult(trans2.get(), &result2); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5161 | // Read the response body. |
| 5162 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 5163 | ReadResult(trans, &result); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5164 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5165 | // Verify that the received push data is same as the expected push data. |
| 5166 | EXPECT_EQ(result2.compare(expected_push_result), 0) |
| 5167 | << "Received data: " |
| 5168 | << result2 |
| 5169 | << "||||| Expected data: " |
| 5170 | << expected_push_result; |
| 5171 | |
| 5172 | // Verify the SYN_REPLY. |
| 5173 | // Copy the response info, because trans goes away. |
| 5174 | response = *trans->GetResponseInfo(); |
| 5175 | response2 = *trans2->GetResponseInfo(); |
| 5176 | |
| 5177 | VerifyStreamsClosed(helper); |
| 5178 | |
| 5179 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5180 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5181 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5182 | |
| 5183 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5184 | EXPECT_TRUE(response2.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5185 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 5186 | |
| 5187 | // Read the final EOF (which will close the session) |
| 5188 | data.RunFor(1); |
| 5189 | |
| 5190 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 5191 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 5192 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5193 | } |
| 5194 | |
[email protected] | 6cd63ba | 2014-06-12 16:14:56 | [diff] [blame] | 5195 | // TODO(baranovich): HTTP 2 does not allow multiple HEADERS frames |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5196 | TEST_P(SpdyNetworkTransactionTest, ServerPushWithTwoHeaderFrames) { |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5197 | // We push a stream and attempt to claim it before the headers come down. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5198 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5199 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5200 | scoped_ptr<SpdyFrame> stream1_body( |
| 5201 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5202 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5203 | CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5204 | }; |
| 5205 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5206 | scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 5207 | if (spdy_util_.spdy_version() < HTTP2) { |
| 5208 | // In HTTP/2 PUSH_PROMISE headers won't show up in the response headers. |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 5209 | (*initial_headers)["alpha"] = "beta"; |
| 5210 | } |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5211 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
| 5212 | initial_headers.get()); |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5213 | scoped_ptr<SpdyFrame> stream2_syn( |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 5214 | spdy_util_.ConstructInitialSpdyPushFrame(initial_headers.Pass(), 2, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5215 | |
| 5216 | scoped_ptr<SpdyHeaderBlock> middle_headers(new SpdyHeaderBlock()); |
| 5217 | (*middle_headers)["hello"] = "bye"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5218 | scoped_ptr<SpdyFrame> stream2_headers1( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5219 | spdy_util_.ConstructSpdyControlFrame(middle_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5220 | false, |
| 5221 | 2, |
| 5222 | LOWEST, |
| 5223 | HEADERS, |
| 5224 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5225 | 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5226 | |
| 5227 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5228 | (*late_headers)[spdy_util_.GetStatusKey()] = "200"; |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 5229 | if (spdy_util_.spdy_version() < HTTP2) { |
| 5230 | // HTTP/2 eliminates use of the :version header. |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5231 | (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
| 5232 | } |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5233 | scoped_ptr<SpdyFrame> stream2_headers2( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5234 | spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5235 | false, |
| 5236 | 2, |
| 5237 | LOWEST, |
| 5238 | HEADERS, |
| 5239 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5240 | 0)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5241 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5242 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5243 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5244 | const char kPushedData[] = "pushed"; |
| 5245 | scoped_ptr<SpdyFrame> stream2_body( |
| 5246 | spdy_util_.ConstructSpdyBodyFrame( |
| 5247 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5248 | MockRead reads[] = { |
| 5249 | CreateMockRead(*stream1_reply, 1), |
| 5250 | CreateMockRead(*stream2_syn, 2), |
| 5251 | CreateMockRead(*stream1_body, 3), |
| 5252 | CreateMockRead(*stream2_headers1, 4), |
| 5253 | CreateMockRead(*stream2_headers2, 5), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5254 | CreateMockRead(*stream2_body, 6), |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 5255 | MockRead(ASYNC, 0, 7), // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5256 | }; |
| 5257 | |
| 5258 | HttpResponseInfo response; |
| 5259 | HttpResponseInfo response2; |
| 5260 | std::string expected_push_result("pushed"); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5261 | DeterministicSocketData data(reads, arraysize(reads), |
| 5262 | writes, arraysize(writes)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5263 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5264 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5265 | BoundNetLog(), GetParam(), NULL); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5266 | helper.SetDeterministic(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5267 | helper.AddDeterministicData(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5268 | helper.RunPreTestSetup(); |
| 5269 | |
| 5270 | HttpNetworkTransaction* trans = helper.trans(); |
| 5271 | |
| 5272 | // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM, |
| 5273 | // the first HEADERS frame, and the body of the primary stream, but before |
| 5274 | // we've received the final HEADERS for the pushed stream. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5275 | data.SetStop(4); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5276 | |
| 5277 | // Start the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5278 | TestCompletionCallback callback; |
| 5279 | int rv = trans->Start( |
| 5280 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5281 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5282 | data.Run(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5283 | rv = callback.WaitForResult(); |
| 5284 | EXPECT_EQ(0, rv); |
| 5285 | |
| 5286 | // Request the pushed path. At this point, we've received the push, but the |
| 5287 | // headers are not yet complete. |
| 5288 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5289 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5290 | rv = trans2->Start( |
| 5291 | &CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5292 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5293 | data.RunFor(3); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5294 | base::RunLoop().RunUntilIdle(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5295 | |
| 5296 | // Read the server push body. |
| 5297 | std::string result2; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 5298 | ReadResult(trans2.get(), &result2); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5299 | // Read the response body. |
| 5300 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 5301 | ReadResult(trans, &result); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5302 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5303 | // Verify that the received push data is same as the expected push data. |
[email protected] | 6d116e1a | 2013-06-24 07:42:15 | [diff] [blame] | 5304 | EXPECT_EQ(expected_push_result, result2); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5305 | |
| 5306 | // Verify the SYN_REPLY. |
| 5307 | // Copy the response info, because trans goes away. |
| 5308 | response = *trans->GetResponseInfo(); |
| 5309 | response2 = *trans2->GetResponseInfo(); |
| 5310 | |
| 5311 | VerifyStreamsClosed(helper); |
| 5312 | |
| 5313 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5314 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5315 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5316 | |
| 5317 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5318 | EXPECT_TRUE(response2.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5319 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5320 | |
[email protected] | 6cd63ba | 2014-06-12 16:14:56 | [diff] [blame] | 5321 | // Verify we got all the headers from all header blocks. |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 5322 | if (spdy_util_.spdy_version() < HTTP2) |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 5323 | EXPECT_TRUE(response2.headers->HasHeaderValue("alpha", "beta")); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5324 | EXPECT_TRUE(response2.headers->HasHeaderValue("hello", "bye")); |
| 5325 | EXPECT_TRUE(response2.headers->HasHeaderValue("status", "200")); |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 5326 | |
| 5327 | // Read the final EOF (which will close the session) |
| 5328 | data.RunFor(1); |
| 5329 | |
| 5330 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 5331 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 5332 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5333 | } |
| 5334 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5335 | TEST_P(SpdyNetworkTransactionTest, ServerPushWithNoStatusHeaderFrames) { |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5336 | // We push a stream and attempt to claim it before the headers come down. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5337 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5338 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5339 | scoped_ptr<SpdyFrame> stream1_body( |
| 5340 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5341 | MockWrite writes[] = { |
| 5342 | CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), |
| 5343 | }; |
| 5344 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5345 | scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5346 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
| 5347 | initial_headers.get()); |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5348 | scoped_ptr<SpdyFrame> stream2_syn( |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 5349 | spdy_util_.ConstructInitialSpdyPushFrame(initial_headers.Pass(), 2, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5350 | |
| 5351 | scoped_ptr<SpdyHeaderBlock> middle_headers(new SpdyHeaderBlock()); |
| 5352 | (*middle_headers)["hello"] = "bye"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5353 | scoped_ptr<SpdyFrame> stream2_headers1( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5354 | spdy_util_.ConstructSpdyControlFrame(middle_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5355 | false, |
| 5356 | 2, |
| 5357 | LOWEST, |
| 5358 | HEADERS, |
| 5359 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5360 | 0)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5361 | |
| 5362 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5363 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5364 | const char kPushedData[] = "pushed"; |
| 5365 | scoped_ptr<SpdyFrame> stream2_body( |
| 5366 | spdy_util_.ConstructSpdyBodyFrame( |
| 5367 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5368 | MockRead reads[] = { |
| 5369 | CreateMockRead(*stream1_reply, 1), |
| 5370 | CreateMockRead(*stream2_syn, 2), |
| 5371 | CreateMockRead(*stream1_body, 3), |
| 5372 | CreateMockRead(*stream2_headers1, 4), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5373 | CreateMockRead(*stream2_body, 5), |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5374 | MockRead(ASYNC, 0, 6), // EOF |
| 5375 | }; |
| 5376 | |
| 5377 | DeterministicSocketData data(reads, arraysize(reads), |
| 5378 | writes, arraysize(writes)); |
| 5379 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5380 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5381 | BoundNetLog(), GetParam(), NULL); |
| 5382 | helper.SetDeterministic(); |
| 5383 | helper.AddDeterministicData(&data); |
| 5384 | helper.RunPreTestSetup(); |
| 5385 | |
| 5386 | HttpNetworkTransaction* trans = helper.trans(); |
| 5387 | |
| 5388 | // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM, |
| 5389 | // the first HEADERS frame, and the body of the primary stream, but before |
| 5390 | // we've received the final HEADERS for the pushed stream. |
| 5391 | data.SetStop(4); |
| 5392 | |
| 5393 | // Start the transaction. |
| 5394 | TestCompletionCallback callback; |
| 5395 | int rv = trans->Start( |
| 5396 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 5397 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5398 | data.Run(); |
| 5399 | rv = callback.WaitForResult(); |
| 5400 | EXPECT_EQ(0, rv); |
| 5401 | |
| 5402 | // Request the pushed path. At this point, we've received the push, but the |
| 5403 | // headers are not yet complete. |
| 5404 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5405 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5406 | rv = trans2->Start( |
| 5407 | &CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
| 5408 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5409 | data.RunFor(2); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5410 | base::RunLoop().RunUntilIdle(); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5411 | |
| 5412 | // Read the server push body. |
| 5413 | std::string result2; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 5414 | ReadResult(trans2.get(), &result2); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5415 | // Read the response body. |
| 5416 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 5417 | ReadResult(trans, &result); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5418 | EXPECT_EQ("hello!", result); |
| 5419 | |
| 5420 | // Verify that we haven't received any push data. |
| 5421 | EXPECT_EQ("", result2); |
| 5422 | |
| 5423 | // Verify the SYN_REPLY. |
| 5424 | // Copy the response info, because trans goes away. |
| 5425 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5426 | |
| 5427 | VerifyStreamsClosed(helper); |
| 5428 | |
| 5429 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5430 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5431 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5432 | |
| 5433 | // Read the final EOF (which will close the session). |
| 5434 | data.RunFor(1); |
| 5435 | |
| 5436 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 5437 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 5438 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5439 | } |
| 5440 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5441 | TEST_P(SpdyNetworkTransactionTest, SynReplyWithHeaders) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5442 | scoped_ptr<SpdyFrame> req( |
| 5443 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5444 | scoped_ptr<SpdyFrame> rst( |
| 5445 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 5446 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5447 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 4), |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5448 | }; |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5449 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5450 | scoped_ptr<SpdyFrame> stream1_reply( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5451 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5452 | |
| 5453 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5454 | (*late_headers)["hello"] = "bye"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5455 | scoped_ptr<SpdyFrame> stream1_headers( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5456 | spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5457 | false, |
| 5458 | 1, |
| 5459 | LOWEST, |
| 5460 | HEADERS, |
| 5461 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5462 | 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5463 | scoped_ptr<SpdyFrame> stream1_body( |
| 5464 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5465 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5466 | CreateMockRead(*stream1_reply, 1), |
| 5467 | CreateMockRead(*stream1_headers, 2), |
| 5468 | CreateMockRead(*stream1_body, 3), |
| 5469 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5470 | }; |
| 5471 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5472 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5473 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5474 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5475 | helper.RunToCompletion(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5476 | TransactionHelperResult out = helper.output(); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5477 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5478 | } |
| 5479 | |
xunjieli | 294da72 | 2015-08-11 19:15:02 | [diff] [blame] | 5480 | // Tests that receiving HEADERS, DATA, HEADERS, and DATA in that sequence will |
| 5481 | // trigger a ERR_SPDY_PROTOCOL_ERROR because trailing HEADERS must not be |
| 5482 | // followed by any DATA frames. |
| 5483 | TEST_P(SpdyNetworkTransactionTest, SyncReplyDataAfterTrailers) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5484 | scoped_ptr<SpdyFrame> req( |
| 5485 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5486 | scoped_ptr<SpdyFrame> rst( |
| 5487 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 5488 | MockWrite writes[] = { |
xunjieli | 294da72 | 2015-08-11 19:15:02 | [diff] [blame] | 5489 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 5), |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5490 | }; |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5491 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5492 | scoped_ptr<SpdyFrame> stream1_reply( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5493 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5494 | |
| 5495 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5496 | (*late_headers)["hello"] = "bye"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5497 | scoped_ptr<SpdyFrame> stream1_headers( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5498 | spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5499 | false, |
| 5500 | 1, |
| 5501 | LOWEST, |
| 5502 | HEADERS, |
| 5503 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5504 | 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5505 | scoped_ptr<SpdyFrame> stream1_body( |
| 5506 | spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 5507 | scoped_ptr<SpdyFrame> stream1_body2( |
| 5508 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5509 | MockRead reads[] = { |
xunjieli | 294da72 | 2015-08-11 19:15:02 | [diff] [blame] | 5510 | CreateMockRead(*stream1_reply, 1), CreateMockRead(*stream1_body, 2), |
| 5511 | CreateMockRead(*stream1_headers, 3), CreateMockRead(*stream1_body2, 4), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5512 | MockRead(ASYNC, 0, 6) // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5513 | }; |
| 5514 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5515 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5516 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5517 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5518 | helper.RunToCompletion(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5519 | TransactionHelperResult out = helper.output(); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5520 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5521 | } |
| 5522 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5523 | TEST_P(SpdyNetworkTransactionTest, ServerPushCrossOriginCorrectness) { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5524 | // Running these tests via Alt-Svc is too complicated to be worthwhile. |
| 5525 | if (GetParam().ssl_type != HTTPS_SPDY_VIA_NPN) |
| 5526 | return; |
| 5527 | |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5528 | // In this test we want to verify that we can't accidentally push content |
| 5529 | // which can't be pushed by this content server. |
| 5530 | // This test assumes that: |
| 5531 | // - if we're requesting http://www.foo.com/barbaz |
| 5532 | // - the browser has made a connection to "www.foo.com". |
| 5533 | |
| 5534 | // A list of the URL to fetch, followed by the URL being pushed. |
| 5535 | static const char* const kTestCases[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5536 | "https://www.example.org/foo.html", |
| 5537 | "https://www.example.org:81/foo.js", // Bad port |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5538 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5539 | "https://www.example.org/foo.html", |
| 5540 | "http://www.example.org/foo.js", // Bad protocol |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5541 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5542 | "https://www.example.org/foo.html", |
| 5543 | "ftp://www.example.org/foo.js", // Invalid Protocol |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5544 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5545 | "https://www.example.org/foo.html", |
| 5546 | "https://blat.www.example.org/foo.js", // Cross subdomain |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5547 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5548 | "https://www.example.org/foo.html", |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5549 | "https://www.foo.com/foo.js", // Cross domain |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5550 | }; |
| 5551 | |
[email protected] | b3f89933 | 2010-12-08 18:20:44 | [diff] [blame] | 5552 | for (size_t index = 0; index < arraysize(kTestCases); index += 2) { |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5553 | const char* url_to_fetch = kTestCases[index]; |
| 5554 | const char* url_to_push = kTestCases[index + 1]; |
| 5555 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5556 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5557 | spdy_util_.ConstructSpdyGet(url_to_fetch, false, 1, LOWEST)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5558 | scoped_ptr<SpdyFrame> stream1_body( |
| 5559 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5560 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5561 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5562 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5563 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5564 | CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*push_rst, 3), |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5565 | }; |
| 5566 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5567 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5568 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5569 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5570 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
| 5571 | 0, |
| 5572 | 2, |
| 5573 | 1, |
| 5574 | url_to_push)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5575 | const char kPushedData[] = "pushed"; |
| 5576 | scoped_ptr<SpdyFrame> stream2_body( |
| 5577 | spdy_util_.ConstructSpdyBodyFrame( |
| 5578 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5579 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5580 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_CANCEL)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5581 | |
| 5582 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5583 | CreateMockRead(*stream1_reply, 1), |
| 5584 | CreateMockRead(*stream2_syn, 2), |
| 5585 | CreateMockRead(*stream1_body, 4), |
| 5586 | CreateMockRead(*stream2_body, 5), |
| 5587 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a pause |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5588 | }; |
| 5589 | |
| 5590 | HttpResponseInfo response; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5591 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 5592 | arraysize(writes)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5593 | |
| 5594 | HttpRequestInfo request; |
| 5595 | request.method = "GET"; |
| 5596 | request.url = GURL(url_to_fetch); |
| 5597 | request.load_flags = 0; |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5598 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 5599 | // Enable cross-origin push. Since we are not using a proxy, this should |
| 5600 | // not actually enable cross-origin SPDY push. |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5601 | scoped_ptr<SpdySessionDependencies> session_deps( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5602 | CreateSpdySessionDependencies(GetParam())); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5603 | session_deps->trusted_spdy_proxy = "123.45.67.89:8080"; |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5604 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 5605 | GetParam(), session_deps.Pass()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5606 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5607 | helper.AddData(&data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 5608 | |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5609 | HttpNetworkTransaction* trans = helper.trans(); |
| 5610 | |
| 5611 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5612 | TestCompletionCallback callback; |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5613 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5614 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5615 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5616 | rv = callback.WaitForResult(); |
| 5617 | |
| 5618 | // Read the response body. |
| 5619 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 5620 | ReadResult(trans, &result); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5621 | |
| 5622 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 5623 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 5624 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5625 | |
| 5626 | // Verify the SYN_REPLY. |
| 5627 | // Copy the response info, because trans goes away. |
| 5628 | response = *trans->GetResponseInfo(); |
| 5629 | |
| 5630 | VerifyStreamsClosed(helper); |
| 5631 | |
| 5632 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5633 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5634 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5635 | } |
| 5636 | } |
| 5637 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5638 | TEST_P(SpdyNetworkTransactionTest, RetryAfterRefused) { |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5639 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5640 | scoped_ptr<SpdyFrame> req( |
| 5641 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5642 | // Will be destroyed by the RST before stream 3 starts. |
| 5643 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5644 | scoped_ptr<SpdyFrame> req2( |
| 5645 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5646 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5647 | CreateMockWrite(*req, 0), CreateMockWrite(*req2, 2), |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5648 | }; |
| 5649 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5650 | scoped_ptr<SpdyFrame> refused( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5651 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5652 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 5653 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5654 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5655 | CreateMockRead(*refused, 1), |
| 5656 | CreateMockRead(*resp, 3), |
| 5657 | CreateMockRead(*body, 4), |
| 5658 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5659 | }; |
| 5660 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5661 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5662 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5663 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5664 | |
| 5665 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5666 | helper.AddData(&data); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5667 | |
| 5668 | HttpNetworkTransaction* trans = helper.trans(); |
| 5669 | |
| 5670 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5671 | TestCompletionCallback callback; |
| 5672 | int rv = trans->Start( |
| 5673 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5674 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5675 | rv = callback.WaitForResult(); |
| 5676 | EXPECT_EQ(OK, rv); |
| 5677 | |
| 5678 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5679 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 5680 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5681 | |
| 5682 | // Verify the SYN_REPLY. |
| 5683 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5684 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5685 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5686 | } |
| 5687 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5688 | TEST_P(SpdyNetworkTransactionTest, OutOfOrderSynStream) { |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5689 | // This first request will start to establish the SpdySession. |
| 5690 | // Then we will start the second (MEDIUM priority) and then third |
| 5691 | // (HIGHEST priority) request in such a way that the third will actually |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 5692 | // start before the second, causing the second to be numbered differently |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5693 | // than the order they were created. |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5694 | // |
| 5695 | // Note that the requests and responses created below are expectations |
| 5696 | // of what the above will produce on the wire, and hence are in the |
| 5697 | // initial->HIGHEST->LOWEST priority. |
| 5698 | // |
| 5699 | // Frames are created by SpdySession just before the write associated |
| 5700 | // with the frame is attempted, so stream dependencies will be based |
| 5701 | // on the streams alive at the point of the request write attempt. Thus |
| 5702 | // req1 is alive when req2 is attempted (during but not after the |
| 5703 | // |data.RunFor(2);| statement below) but not when req3 is attempted. |
| 5704 | // The call to spdy_util_.UpdateWithStreamDestruction() reflects this. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5705 | scoped_ptr<SpdyFrame> req1( |
| 5706 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5707 | scoped_ptr<SpdyFrame> req2( |
| 5708 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, HIGHEST, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5709 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5710 | scoped_ptr<SpdyFrame> req3( |
| 5711 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, MEDIUM, true)); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5712 | MockWrite writes[] = { |
| 5713 | CreateMockWrite(*req1, 0), |
| 5714 | CreateMockWrite(*req2, 3), |
| 5715 | CreateMockWrite(*req3, 4), |
| 5716 | }; |
| 5717 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5718 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 5719 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 5720 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 5721 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 5722 | scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 5723 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5724 | MockRead reads[] = { |
| 5725 | CreateMockRead(*resp1, 1), |
| 5726 | CreateMockRead(*body1, 2), |
| 5727 | CreateMockRead(*resp2, 5), |
| 5728 | CreateMockRead(*body2, 6), |
| 5729 | CreateMockRead(*resp3, 7), |
| 5730 | CreateMockRead(*body3, 8), |
| 5731 | MockRead(ASYNC, 0, 9) // EOF |
| 5732 | }; |
| 5733 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5734 | DeterministicSocketData data(reads, arraysize(reads), |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5735 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5736 | NormalSpdyTransactionHelper helper(CreateGetRequest(), LOWEST, |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5737 | BoundNetLog(), GetParam(), NULL); |
| 5738 | helper.SetDeterministic(); |
| 5739 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5740 | helper.AddDeterministicData(&data); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5741 | |
| 5742 | // Start the first transaction to set up the SpdySession |
| 5743 | HttpNetworkTransaction* trans = helper.trans(); |
| 5744 | TestCompletionCallback callback; |
| 5745 | HttpRequestInfo info1 = CreateGetRequest(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5746 | int rv = trans->Start(&info1, callback.callback(), BoundNetLog()); |
| 5747 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5748 | |
| 5749 | // Run the message loop, but do not allow the write to complete. |
| 5750 | // This leaves the SpdySession with a write pending, which prevents |
| 5751 | // SpdySession from attempting subsequent writes until this write completes. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5752 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5753 | |
| 5754 | // Now, start both new transactions |
| 5755 | HttpRequestInfo info2 = CreateGetRequest(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5756 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5757 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5758 | new HttpNetworkTransaction(MEDIUM, helper.session())); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5759 | rv = trans2->Start(&info2, callback2.callback(), BoundNetLog()); |
| 5760 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5761 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5762 | |
| 5763 | HttpRequestInfo info3 = CreateGetRequest(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5764 | TestCompletionCallback callback3; |
| 5765 | scoped_ptr<HttpNetworkTransaction> trans3( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5766 | new HttpNetworkTransaction(HIGHEST, helper.session())); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5767 | rv = trans3->Start(&info3, callback3.callback(), BoundNetLog()); |
| 5768 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5769 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5770 | |
| 5771 | // We now have two SYN_STREAM frames queued up which will be |
| 5772 | // dequeued only once the first write completes, which we |
| 5773 | // now allow to happen. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5774 | data.RunFor(2); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5775 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5776 | |
| 5777 | // And now we can allow everything else to run to completion. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5778 | data.SetStop(10); |
| 5779 | data.Run(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5780 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 5781 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 5782 | |
| 5783 | helper.VerifyDataConsumed(); |
| 5784 | } |
| 5785 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5786 | // The tests below are only for SPDY/3 and above. |
| 5787 | |
| 5788 | // Test that sent data frames and received WINDOW_UPDATE frames change |
| 5789 | // the send_window_size_ correctly. |
| 5790 | |
| 5791 | // WINDOW_UPDATE is different than most other frames in that it can arrive |
| 5792 | // while the client is still sending the request body. In order to enforce |
| 5793 | // this scenario, we feed a couple of dummy frames and give a delay of 0 to |
| 5794 | // socket data provider, so that initial read that is done as soon as the |
| 5795 | // stream is created, succeeds and schedules another read. This way reads |
| 5796 | // and writes are interleaved; after doing a full frame write, SpdyStream |
| 5797 | // will break out of DoLoop and will read and process a WINDOW_UPDATE. |
| 5798 | // Once our WINDOW_UPDATE is read, we cannot send SYN_REPLY right away |
| 5799 | // since request has not been completely written, therefore we feed |
| 5800 | // enough number of WINDOW_UPDATEs to finish the first read and cause a |
| 5801 | // write, leading to a complete write of request body; after that we send |
| 5802 | // a reply with a body, to cause a graceful shutdown. |
| 5803 | |
| 5804 | // TODO(agayev): develop a socket data provider where both, reads and |
| 5805 | // writes are ordered so that writing tests like these are easy and rewrite |
| 5806 | // all these tests using it. Right now we are working around the |
| 5807 | // limitations as described above and it's not deterministic, tests may |
| 5808 | // fail under specific circumstances. |
| 5809 | TEST_P(SpdyNetworkTransactionTest, WindowUpdateReceived) { |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5810 | static int kFrameCount = 2; |
| 5811 | scoped_ptr<std::string> content( |
| 5812 | new std::string(kMaxSpdyFrameChunkSize, 'a')); |
| 5813 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5814 | GetDefaultUrl(), 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, NULL, |
| 5815 | 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5816 | scoped_ptr<SpdyFrame> body( |
| 5817 | spdy_util_.ConstructSpdyBodyFrame( |
| 5818 | 1, content->c_str(), content->size(), false)); |
| 5819 | scoped_ptr<SpdyFrame> body_end( |
| 5820 | spdy_util_.ConstructSpdyBodyFrame( |
| 5821 | 1, content->c_str(), content->size(), true)); |
| 5822 | |
| 5823 | MockWrite writes[] = { |
| 5824 | CreateMockWrite(*req, 0), |
| 5825 | CreateMockWrite(*body, 1), |
| 5826 | CreateMockWrite(*body_end, 2), |
| 5827 | }; |
| 5828 | |
| 5829 | static const int32 kDeltaWindowSize = 0xff; |
| 5830 | static const int kDeltaCount = 4; |
| 5831 | scoped_ptr<SpdyFrame> window_update( |
| 5832 | spdy_util_.ConstructSpdyWindowUpdate(1, kDeltaWindowSize)); |
| 5833 | scoped_ptr<SpdyFrame> window_update_dummy( |
| 5834 | spdy_util_.ConstructSpdyWindowUpdate(2, kDeltaWindowSize)); |
| 5835 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 5836 | MockRead reads[] = { |
| 5837 | CreateMockRead(*window_update_dummy, 3), |
| 5838 | CreateMockRead(*window_update_dummy, 4), |
| 5839 | CreateMockRead(*window_update_dummy, 5), |
| 5840 | CreateMockRead(*window_update, 6), // Four updates, therefore window |
| 5841 | CreateMockRead(*window_update, 7), // size should increase by |
| 5842 | CreateMockRead(*window_update, 8), // kDeltaWindowSize * 4 |
| 5843 | CreateMockRead(*window_update, 9), |
| 5844 | CreateMockRead(*resp, 10), |
| 5845 | CreateMockRead(*body_end, 11), |
| 5846 | MockRead(ASYNC, 0, 0, 12) // EOF |
| 5847 | }; |
| 5848 | |
| 5849 | DeterministicSocketData data(reads, arraysize(reads), |
| 5850 | writes, arraysize(writes)); |
| 5851 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5852 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5853 | for (int i = 0; i < kFrameCount; ++i) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5854 | element_readers.push_back(make_scoped_ptr( |
| 5855 | new UploadBytesElementReader(content->c_str(), content->size()))); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5856 | } |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5857 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5858 | |
| 5859 | // Setup the request |
| 5860 | HttpRequestInfo request; |
| 5861 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5862 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5863 | request.upload_data_stream = &upload_data_stream; |
| 5864 | |
| 5865 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 5866 | BoundNetLog(), GetParam(), NULL); |
| 5867 | helper.SetDeterministic(); |
| 5868 | helper.AddDeterministicData(&data); |
| 5869 | helper.RunPreTestSetup(); |
| 5870 | |
| 5871 | HttpNetworkTransaction* trans = helper.trans(); |
| 5872 | |
| 5873 | TestCompletionCallback callback; |
| 5874 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 5875 | |
| 5876 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5877 | |
| 5878 | data.RunFor(11); |
| 5879 | |
| 5880 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 5881 | ASSERT_TRUE(stream != NULL); |
| 5882 | ASSERT_TRUE(stream->stream() != NULL); |
bnc | 638c470 | 2015-04-09 18:01:18 | [diff] [blame] | 5883 | EXPECT_EQ(static_cast<int>( |
| 5884 | SpdySession::GetDefaultInitialWindowSize(GetParam().protocol)) + |
| 5885 | kDeltaWindowSize * kDeltaCount - |
| 5886 | kMaxSpdyFrameChunkSize * kFrameCount, |
| 5887 | stream->stream()->send_window_size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5888 | |
| 5889 | data.RunFor(1); |
| 5890 | |
| 5891 | rv = callback.WaitForResult(); |
| 5892 | EXPECT_EQ(OK, rv); |
| 5893 | |
| 5894 | helper.VerifyDataConsumed(); |
| 5895 | } |
| 5896 | |
| 5897 | // Test that received data frames and sent WINDOW_UPDATE frames change |
| 5898 | // the recv_window_size_ correctly. |
| 5899 | TEST_P(SpdyNetworkTransactionTest, WindowUpdateSent) { |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5900 | const int32 default_initial_window_size = |
bnc | 638c470 | 2015-04-09 18:01:18 | [diff] [blame] | 5901 | SpdySession::GetDefaultInitialWindowSize(GetParam().protocol); |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5902 | // Session level maximum window size that is more than twice the default |
| 5903 | // initial window size so that an initial window update is sent. |
| 5904 | const int32 session_max_recv_window_size = 5 * 64 * 1024; |
| 5905 | ASSERT_LT(2 * default_initial_window_size, session_max_recv_window_size); |
| 5906 | // Stream level maximum window size that is less than the session level |
| 5907 | // maximum window size so that we test for confusion between the two. |
| 5908 | const int32 stream_max_recv_window_size = 4 * 64 * 1024; |
| 5909 | ASSERT_GT(session_max_recv_window_size, stream_max_recv_window_size); |
| 5910 | // Size of body to be sent. Has to be less than or equal to both window sizes |
| 5911 | // so that we do not run out of receiving window. Also has to be greater than |
| 5912 | // half of them so that it triggers both a session level and a stream level |
| 5913 | // window update frame. |
| 5914 | const int32 kTargetSize = 3 * 64 * 1024; |
| 5915 | ASSERT_GE(session_max_recv_window_size, kTargetSize); |
| 5916 | ASSERT_GE(stream_max_recv_window_size, kTargetSize); |
| 5917 | ASSERT_LT(session_max_recv_window_size / 2, kTargetSize); |
| 5918 | ASSERT_LT(stream_max_recv_window_size / 2, kTargetSize); |
| 5919 | // Size of each DATA frame. |
| 5920 | const int32 kChunkSize = 4096; |
| 5921 | // Size of window updates. |
| 5922 | ASSERT_EQ(0, session_max_recv_window_size / 2 % kChunkSize); |
| 5923 | const int32 session_window_update_delta = |
| 5924 | session_max_recv_window_size / 2 + kChunkSize; |
| 5925 | ASSERT_EQ(0, stream_max_recv_window_size / 2 % kChunkSize); |
| 5926 | const int32 stream_window_update_delta = |
| 5927 | stream_max_recv_window_size / 2 + kChunkSize; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5928 | |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5929 | SettingsMap initial_settings; |
| 5930 | initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 5931 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); |
| 5932 | initial_settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
| 5933 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, stream_max_recv_window_size); |
| 5934 | scoped_ptr<SpdyFrame> initial_settings_frame( |
| 5935 | spdy_util_.ConstructSpdySettings(initial_settings)); |
| 5936 | scoped_ptr<SpdyFrame> initial_window_update( |
| 5937 | spdy_util_.ConstructSpdyWindowUpdate( |
| 5938 | kSessionFlowControlStreamId, |
| 5939 | session_max_recv_window_size - default_initial_window_size)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5940 | scoped_ptr<SpdyFrame> req( |
| 5941 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5942 | scoped_ptr<SpdyFrame> session_window_update( |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5943 | spdy_util_.ConstructSpdyWindowUpdate(0, session_window_update_delta)); |
| 5944 | scoped_ptr<SpdyFrame> stream_window_update( |
| 5945 | spdy_util_.ConstructSpdyWindowUpdate(1, stream_window_update_delta)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5946 | |
| 5947 | std::vector<MockWrite> writes; |
bnc | 9b79a57 | 2015-09-02 12:25:03 | [diff] [blame] | 5948 | if (GetParam().protocol == kProtoHTTP2) { |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5949 | writes.push_back(MockWrite(ASYNC, kHttp2ConnectionHeaderPrefix, |
| 5950 | kHttp2ConnectionHeaderPrefixSize, 0)); |
| 5951 | } |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5952 | writes.push_back(CreateMockWrite(*initial_settings_frame, writes.size())); |
| 5953 | writes.push_back(CreateMockWrite(*initial_window_update, writes.size())); |
| 5954 | writes.push_back(CreateMockWrite(*req, writes.size())); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5955 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5956 | std::vector<MockRead> reads; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5957 | scoped_ptr<SpdyFrame> resp( |
| 5958 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5959 | reads.push_back(CreateMockRead(*resp, writes.size() + reads.size())); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5960 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5961 | ScopedVector<SpdyFrame> body_frames; |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5962 | const std::string body_data(kChunkSize, 'x'); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5963 | for (size_t remaining = kTargetSize; remaining != 0;) { |
| 5964 | size_t frame_size = std::min(remaining, body_data.size()); |
| 5965 | body_frames.push_back(spdy_util_.ConstructSpdyBodyFrame( |
| 5966 | 1, body_data.data(), frame_size, false)); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5967 | reads.push_back( |
| 5968 | CreateMockRead(*body_frames.back(), writes.size() + reads.size())); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5969 | remaining -= frame_size; |
| 5970 | } |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5971 | reads.push_back( |
| 5972 | MockRead(ASYNC, ERR_IO_PENDING, writes.size() + reads.size())); // Yield. |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5973 | |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5974 | writes.push_back( |
| 5975 | CreateMockWrite(*session_window_update, writes.size() + reads.size())); |
| 5976 | writes.push_back( |
| 5977 | CreateMockWrite(*stream_window_update, writes.size() + reads.size())); |
| 5978 | |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 5979 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 5980 | writes.size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5981 | |
| 5982 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 5983 | BoundNetLog(), GetParam(), NULL); |
| 5984 | helper.AddData(&data); |
| 5985 | helper.RunPreTestSetup(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5986 | |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5987 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
| 5988 | SpdySessionPoolPeer pool_peer(spdy_session_pool); |
| 5989 | pool_peer.SetEnableSendingInitialData(true); |
| 5990 | pool_peer.SetSessionMaxRecvWindowSize(session_max_recv_window_size); |
| 5991 | pool_peer.SetStreamInitialRecvWindowSize(stream_max_recv_window_size); |
| 5992 | |
| 5993 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5994 | TestCompletionCallback callback; |
| 5995 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 5996 | |
| 5997 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5998 | rv = callback.WaitForResult(); |
| 5999 | EXPECT_EQ(OK, rv); |
| 6000 | |
| 6001 | SpdyHttpStream* stream = |
| 6002 | static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6003 | ASSERT_TRUE(stream != NULL); |
| 6004 | ASSERT_TRUE(stream->stream() != NULL); |
| 6005 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 6006 | // All data has been read, but not consumed. The window reflects this. |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 6007 | EXPECT_EQ(static_cast<int>(stream_max_recv_window_size - kTargetSize), |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 6008 | stream->stream()->recv_window_size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6009 | |
| 6010 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6011 | ASSERT_TRUE(response != NULL); |
| 6012 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6013 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6014 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 6015 | |
| 6016 | // Issue a read which will cause a WINDOW_UPDATE to be sent and window |
| 6017 | // size increased to default. |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 6018 | scoped_refptr<IOBuffer> buf(new IOBuffer(kTargetSize)); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 6019 | EXPECT_EQ(static_cast<int>(kTargetSize), |
| 6020 | trans->Read(buf.get(), kTargetSize, CompletionCallback())); |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 6021 | EXPECT_EQ(static_cast<int>(stream_max_recv_window_size), |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 6022 | stream->stream()->recv_window_size()); |
| 6023 | EXPECT_THAT(base::StringPiece(buf->data(), kTargetSize), Each(Eq('x'))); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6024 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 6025 | // Allow scheduled WINDOW_UPDATE frames to write. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 6026 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6027 | helper.VerifyDataConsumed(); |
| 6028 | } |
| 6029 | |
| 6030 | // Test that WINDOW_UPDATE frame causing overflow is handled correctly. |
| 6031 | TEST_P(SpdyNetworkTransactionTest, WindowUpdateOverflow) { |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6032 | // Number of full frames we hope to write (but will not, used to |
| 6033 | // set content-length header correctly) |
| 6034 | static int kFrameCount = 3; |
| 6035 | |
| 6036 | scoped_ptr<std::string> content( |
| 6037 | new std::string(kMaxSpdyFrameChunkSize, 'a')); |
| 6038 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6039 | GetDefaultUrl(), 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, NULL, |
| 6040 | 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6041 | scoped_ptr<SpdyFrame> body( |
| 6042 | spdy_util_.ConstructSpdyBodyFrame( |
| 6043 | 1, content->c_str(), content->size(), false)); |
| 6044 | scoped_ptr<SpdyFrame> rst( |
| 6045 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_FLOW_CONTROL_ERROR)); |
| 6046 | |
| 6047 | // We're not going to write a data frame with FIN, we'll receive a bad |
| 6048 | // WINDOW_UPDATE while sending a request and will send a RST_STREAM frame. |
| 6049 | MockWrite writes[] = { |
| 6050 | CreateMockWrite(*req, 0), |
| 6051 | CreateMockWrite(*body, 2), |
| 6052 | CreateMockWrite(*rst, 3), |
| 6053 | }; |
| 6054 | |
| 6055 | static const int32 kDeltaWindowSize = 0x7fffffff; // cause an overflow |
| 6056 | scoped_ptr<SpdyFrame> window_update( |
| 6057 | spdy_util_.ConstructSpdyWindowUpdate(1, kDeltaWindowSize)); |
| 6058 | MockRead reads[] = { |
| 6059 | CreateMockRead(*window_update, 1), |
| 6060 | MockRead(ASYNC, 0, 4) // EOF |
| 6061 | }; |
| 6062 | |
| 6063 | DeterministicSocketData data(reads, arraysize(reads), |
| 6064 | writes, arraysize(writes)); |
| 6065 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6066 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6067 | for (int i = 0; i < kFrameCount; ++i) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6068 | element_readers.push_back(make_scoped_ptr( |
| 6069 | new UploadBytesElementReader(content->c_str(), content->size()))); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6070 | } |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6071 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6072 | |
| 6073 | // Setup the request |
| 6074 | HttpRequestInfo request; |
| 6075 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6076 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6077 | request.upload_data_stream = &upload_data_stream; |
| 6078 | |
| 6079 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 6080 | BoundNetLog(), GetParam(), NULL); |
| 6081 | helper.SetDeterministic(); |
| 6082 | helper.RunPreTestSetup(); |
| 6083 | helper.AddDeterministicData(&data); |
| 6084 | HttpNetworkTransaction* trans = helper.trans(); |
| 6085 | |
| 6086 | TestCompletionCallback callback; |
| 6087 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6088 | ASSERT_EQ(ERR_IO_PENDING, rv); |
| 6089 | |
| 6090 | data.RunFor(5); |
| 6091 | ASSERT_TRUE(callback.have_result()); |
| 6092 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, callback.WaitForResult()); |
| 6093 | helper.VerifyDataConsumed(); |
| 6094 | } |
| 6095 | |
| 6096 | // Test that after hitting a send window size of 0, the write process |
| 6097 | // stalls and upon receiving WINDOW_UPDATE frame write resumes. |
| 6098 | |
| 6099 | // This test constructs a POST request followed by enough data frames |
| 6100 | // containing 'a' that would make the window size 0, followed by another |
| 6101 | // data frame containing default content (which is "hello!") and this frame |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 6102 | // also contains a FIN flag. SequencedSocketData is used to enforce all |
| 6103 | // writes, save the last, go through before a read could happen. The last frame |
| 6104 | // ("hello!") is not permitted to go through since by the time its turn |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6105 | // arrives, window size is 0. At this point MessageLoop::Run() called via |
| 6106 | // callback would block. Therefore we call MessageLoop::RunUntilIdle() |
| 6107 | // which returns after performing all possible writes. We use DCHECKS to |
| 6108 | // ensure that last data frame is still there and stream has stalled. |
| 6109 | // After that, next read is artifically enforced, which causes a |
| 6110 | // WINDOW_UPDATE to be read and I/O process resumes. |
| 6111 | TEST_P(SpdyNetworkTransactionTest, FlowControlStallResume) { |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6112 | const int32 initial_window_size = |
bnc | 638c470 | 2015-04-09 18:01:18 | [diff] [blame] | 6113 | SpdySession::GetDefaultInitialWindowSize(GetParam().protocol); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6114 | // Number of frames we need to send to zero out the window size: data |
| 6115 | // frames plus SYN_STREAM plus the last data frame; also we need another |
| 6116 | // data frame that we will send once the WINDOW_UPDATE is received, |
| 6117 | // therefore +3. |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6118 | size_t num_writes = initial_window_size / kMaxSpdyFrameChunkSize + 3; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6119 | |
| 6120 | // Calculate last frame's size; 0 size data frame is legal. |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6121 | size_t last_frame_size = initial_window_size % kMaxSpdyFrameChunkSize; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6122 | |
| 6123 | // Construct content for a data frame of maximum size. |
| 6124 | std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 6125 | |
| 6126 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6127 | GetDefaultUrl(), 1, initial_window_size + kUploadDataSize, LOWEST, NULL, |
| 6128 | 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6129 | |
| 6130 | // Full frames. |
| 6131 | scoped_ptr<SpdyFrame> body1( |
| 6132 | spdy_util_.ConstructSpdyBodyFrame( |
| 6133 | 1, content.c_str(), content.size(), false)); |
| 6134 | |
| 6135 | // Last frame to zero out the window size. |
| 6136 | scoped_ptr<SpdyFrame> body2( |
| 6137 | spdy_util_.ConstructSpdyBodyFrame( |
| 6138 | 1, content.c_str(), last_frame_size, false)); |
| 6139 | |
| 6140 | // Data frame to be sent once WINDOW_UPDATE frame is received. |
| 6141 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6142 | |
| 6143 | // Fill in mock writes. |
| 6144 | scoped_ptr<MockWrite[]> writes(new MockWrite[num_writes]); |
| 6145 | size_t i = 0; |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 6146 | writes[i] = CreateMockWrite(*req, i); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6147 | for (i = 1; i < num_writes - 2; i++) |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 6148 | writes[i] = CreateMockWrite(*body1, i); |
| 6149 | writes[i] = CreateMockWrite(*body2, i); |
| 6150 | // The last write must not be attempted until after the WINDOW_UPDATES |
| 6151 | // have been received. |
| 6152 | writes[i + 1] = CreateMockWrite(*body3, i + 4, SYNCHRONOUS); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6153 | |
| 6154 | // Construct read frame, give enough space to upload the rest of the |
| 6155 | // data. |
| 6156 | scoped_ptr<SpdyFrame> session_window_update( |
| 6157 | spdy_util_.ConstructSpdyWindowUpdate(0, kUploadDataSize)); |
| 6158 | scoped_ptr<SpdyFrame> window_update( |
| 6159 | spdy_util_.ConstructSpdyWindowUpdate(1, kUploadDataSize)); |
| 6160 | scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 6161 | MockRead reads[] = { |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 6162 | MockRead(ASYNC, ERR_IO_PENDING, i + 1), // Force a pause |
| 6163 | CreateMockRead(*session_window_update, i + 2), |
| 6164 | CreateMockRead(*window_update, i + 3), |
| 6165 | // Now the last write will occur. |
| 6166 | CreateMockRead(*reply, i + 5), |
| 6167 | CreateMockRead(*body2, i + 6), |
| 6168 | CreateMockRead(*body3, i + 7), |
| 6169 | MockRead(ASYNC, 0, i + 8) // EOF |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6170 | }; |
| 6171 | |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 6172 | SequencedSocketData data(reads, arraysize(reads), writes.get(), num_writes); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6173 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6174 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6175 | std::string upload_data_string(initial_window_size, 'a'); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6176 | upload_data_string.append(kUploadData, kUploadDataSize); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6177 | element_readers.push_back(make_scoped_ptr(new UploadBytesElementReader( |
| 6178 | upload_data_string.c_str(), upload_data_string.size()))); |
| 6179 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6180 | |
| 6181 | HttpRequestInfo request; |
| 6182 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6183 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6184 | request.upload_data_stream = &upload_data_stream; |
| 6185 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 6186 | BoundNetLog(), GetParam(), NULL); |
| 6187 | helper.AddData(&data); |
| 6188 | helper.RunPreTestSetup(); |
| 6189 | |
| 6190 | HttpNetworkTransaction* trans = helper.trans(); |
| 6191 | |
| 6192 | TestCompletionCallback callback; |
| 6193 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6194 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6195 | |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 6196 | base::RunLoop().RunUntilIdle(); // Write as much as we can. |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6197 | |
| 6198 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6199 | ASSERT_TRUE(stream != NULL); |
| 6200 | ASSERT_TRUE(stream->stream() != NULL); |
| 6201 | EXPECT_EQ(0, stream->stream()->send_window_size()); |
| 6202 | // All the body data should have been read. |
| 6203 | // TODO(satorux): This is because of the weirdness in reading the request |
| 6204 | // body in OnSendBodyComplete(). See crbug.com/113107. |
| 6205 | EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 6206 | // But the body is not yet fully sent (kUploadData is not yet sent) |
| 6207 | // since we're send-stalled. |
| 6208 | EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 6209 | |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 6210 | data.CompleteRead(); // Read in WINDOW_UPDATE frame. |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6211 | rv = callback.WaitForResult(); |
| 6212 | helper.VerifyDataConsumed(); |
| 6213 | } |
| 6214 | |
| 6215 | // Test we correctly handle the case where the SETTINGS frame results in |
| 6216 | // unstalling the send window. |
| 6217 | TEST_P(SpdyNetworkTransactionTest, FlowControlStallResumeAfterSettings) { |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6218 | const int32 initial_window_size = |
bnc | 638c470 | 2015-04-09 18:01:18 | [diff] [blame] | 6219 | SpdySession::GetDefaultInitialWindowSize(GetParam().protocol); |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6220 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6221 | // Number of frames we need to send to zero out the window size: data |
| 6222 | // frames plus SYN_STREAM plus the last data frame; also we need another |
| 6223 | // data frame that we will send once the SETTING is received, therefore +3. |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6224 | size_t num_writes = initial_window_size / kMaxSpdyFrameChunkSize + 3; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6225 | |
| 6226 | // Calculate last frame's size; 0 size data frame is legal. |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6227 | size_t last_frame_size = initial_window_size % kMaxSpdyFrameChunkSize; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6228 | |
| 6229 | // Construct content for a data frame of maximum size. |
| 6230 | std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 6231 | |
| 6232 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6233 | GetDefaultUrl(), 1, initial_window_size + kUploadDataSize, LOWEST, NULL, |
| 6234 | 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6235 | |
| 6236 | // Full frames. |
| 6237 | scoped_ptr<SpdyFrame> body1( |
| 6238 | spdy_util_.ConstructSpdyBodyFrame( |
| 6239 | 1, content.c_str(), content.size(), false)); |
| 6240 | |
| 6241 | // Last frame to zero out the window size. |
| 6242 | scoped_ptr<SpdyFrame> body2( |
| 6243 | spdy_util_.ConstructSpdyBodyFrame( |
| 6244 | 1, content.c_str(), last_frame_size, false)); |
| 6245 | |
| 6246 | // Data frame to be sent once SETTINGS frame is received. |
| 6247 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6248 | |
| 6249 | // Fill in mock reads/writes. |
| 6250 | std::vector<MockRead> reads; |
| 6251 | std::vector<MockWrite> writes; |
| 6252 | size_t i = 0; |
| 6253 | writes.push_back(CreateMockWrite(*req, i++)); |
| 6254 | while (i < num_writes - 2) |
| 6255 | writes.push_back(CreateMockWrite(*body1, i++)); |
| 6256 | writes.push_back(CreateMockWrite(*body2, i++)); |
| 6257 | |
| 6258 | // Construct read frame for SETTINGS that gives enough space to upload the |
| 6259 | // rest of the data. |
| 6260 | SettingsMap settings; |
| 6261 | settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6262 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, initial_window_size * 2); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6263 | scoped_ptr<SpdyFrame> settings_frame_large( |
| 6264 | spdy_util_.ConstructSpdySettings(settings)); |
| 6265 | |
| 6266 | reads.push_back(CreateMockRead(*settings_frame_large, i++)); |
| 6267 | |
| 6268 | scoped_ptr<SpdyFrame> session_window_update( |
| 6269 | spdy_util_.ConstructSpdyWindowUpdate(0, kUploadDataSize)); |
| 6270 | if (GetParam().protocol >= kProtoSPDY31) |
| 6271 | reads.push_back(CreateMockRead(*session_window_update, i++)); |
| 6272 | |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 6273 | scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
| 6274 | writes.push_back(CreateMockWrite(*settings_ack, i++)); |
| 6275 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6276 | writes.push_back(CreateMockWrite(*body3, i++)); |
| 6277 | |
| 6278 | scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 6279 | reads.push_back(CreateMockRead(*reply, i++)); |
| 6280 | reads.push_back(CreateMockRead(*body2, i++)); |
| 6281 | reads.push_back(CreateMockRead(*body3, i++)); |
| 6282 | reads.push_back(MockRead(ASYNC, 0, i++)); // EOF |
| 6283 | |
| 6284 | // Force all writes to happen before any read, last write will not |
| 6285 | // actually queue a frame, due to window size being 0. |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 6286 | DeterministicSocketData data(reads.data(), reads.size(), writes.data(), |
| 6287 | writes.size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6288 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6289 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6290 | std::string upload_data_string(initial_window_size, 'a'); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6291 | upload_data_string.append(kUploadData, kUploadDataSize); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6292 | element_readers.push_back(make_scoped_ptr(new UploadBytesElementReader( |
| 6293 | upload_data_string.c_str(), upload_data_string.size()))); |
| 6294 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6295 | |
| 6296 | HttpRequestInfo request; |
| 6297 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6298 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6299 | request.upload_data_stream = &upload_data_stream; |
| 6300 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 6301 | BoundNetLog(), GetParam(), NULL); |
| 6302 | helper.SetDeterministic(); |
| 6303 | helper.RunPreTestSetup(); |
| 6304 | helper.AddDeterministicData(&data); |
| 6305 | |
| 6306 | HttpNetworkTransaction* trans = helper.trans(); |
| 6307 | |
| 6308 | TestCompletionCallback callback; |
| 6309 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6310 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6311 | |
| 6312 | data.RunFor(num_writes - 1); // Write as much as we can. |
| 6313 | |
| 6314 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6315 | ASSERT_TRUE(stream != NULL); |
| 6316 | ASSERT_TRUE(stream->stream() != NULL); |
| 6317 | EXPECT_EQ(0, stream->stream()->send_window_size()); |
| 6318 | |
| 6319 | // All the body data should have been read. |
| 6320 | // TODO(satorux): This is because of the weirdness in reading the request |
| 6321 | // body in OnSendBodyComplete(). See crbug.com/113107. |
| 6322 | EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 6323 | // But the body is not yet fully sent (kUploadData is not yet sent) |
| 6324 | // since we're send-stalled. |
| 6325 | EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 6326 | |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 6327 | data.RunFor(7); // Read in SETTINGS frame to unstall. |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6328 | rv = callback.WaitForResult(); |
| 6329 | helper.VerifyDataConsumed(); |
| 6330 | // If stream is NULL, that means it was unstalled and closed. |
| 6331 | EXPECT_TRUE(stream->stream() == NULL); |
| 6332 | } |
| 6333 | |
| 6334 | // Test we correctly handle the case where the SETTINGS frame results in a |
| 6335 | // negative send window size. |
| 6336 | TEST_P(SpdyNetworkTransactionTest, FlowControlNegativeSendWindowSize) { |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6337 | const int32 initial_window_size = |
bnc | 638c470 | 2015-04-09 18:01:18 | [diff] [blame] | 6338 | SpdySession::GetDefaultInitialWindowSize(GetParam().protocol); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6339 | // Number of frames we need to send to zero out the window size: data |
| 6340 | // frames plus SYN_STREAM plus the last data frame; also we need another |
| 6341 | // data frame that we will send once the SETTING is received, therefore +3. |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6342 | size_t num_writes = initial_window_size / kMaxSpdyFrameChunkSize + 3; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6343 | |
| 6344 | // Calculate last frame's size; 0 size data frame is legal. |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6345 | size_t last_frame_size = initial_window_size % kMaxSpdyFrameChunkSize; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6346 | |
| 6347 | // Construct content for a data frame of maximum size. |
| 6348 | std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 6349 | |
| 6350 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6351 | GetDefaultUrl(), 1, initial_window_size + kUploadDataSize, LOWEST, NULL, |
| 6352 | 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6353 | |
| 6354 | // Full frames. |
| 6355 | scoped_ptr<SpdyFrame> body1( |
| 6356 | spdy_util_.ConstructSpdyBodyFrame( |
| 6357 | 1, content.c_str(), content.size(), false)); |
| 6358 | |
| 6359 | // Last frame to zero out the window size. |
| 6360 | scoped_ptr<SpdyFrame> body2( |
| 6361 | spdy_util_.ConstructSpdyBodyFrame( |
| 6362 | 1, content.c_str(), last_frame_size, false)); |
| 6363 | |
| 6364 | // Data frame to be sent once SETTINGS frame is received. |
| 6365 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6366 | |
| 6367 | // Fill in mock reads/writes. |
| 6368 | std::vector<MockRead> reads; |
| 6369 | std::vector<MockWrite> writes; |
| 6370 | size_t i = 0; |
| 6371 | writes.push_back(CreateMockWrite(*req, i++)); |
| 6372 | while (i < num_writes - 2) |
| 6373 | writes.push_back(CreateMockWrite(*body1, i++)); |
| 6374 | writes.push_back(CreateMockWrite(*body2, i++)); |
| 6375 | |
| 6376 | // Construct read frame for SETTINGS that makes the send_window_size |
| 6377 | // negative. |
| 6378 | SettingsMap new_settings; |
| 6379 | new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6380 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, initial_window_size / 2); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6381 | scoped_ptr<SpdyFrame> settings_frame_small( |
| 6382 | spdy_util_.ConstructSpdySettings(new_settings)); |
| 6383 | // Construct read frames for WINDOW_UPDATE that makes the send_window_size |
| 6384 | // positive. |
| 6385 | scoped_ptr<SpdyFrame> session_window_update_init_size( |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6386 | spdy_util_.ConstructSpdyWindowUpdate(0, initial_window_size)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6387 | scoped_ptr<SpdyFrame> window_update_init_size( |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6388 | spdy_util_.ConstructSpdyWindowUpdate(1, initial_window_size)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6389 | |
| 6390 | reads.push_back(CreateMockRead(*settings_frame_small, i++)); |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 6391 | reads.push_back(CreateMockRead(*session_window_update_init_size, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6392 | reads.push_back(CreateMockRead(*window_update_init_size, i++)); |
| 6393 | |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 6394 | scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
| 6395 | writes.push_back(CreateMockWrite(*settings_ack, i++)); |
| 6396 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6397 | writes.push_back(CreateMockWrite(*body3, i++)); |
| 6398 | |
| 6399 | scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 6400 | reads.push_back(CreateMockRead(*reply, i++)); |
| 6401 | reads.push_back(CreateMockRead(*body2, i++)); |
| 6402 | reads.push_back(CreateMockRead(*body3, i++)); |
| 6403 | reads.push_back(MockRead(ASYNC, 0, i++)); // EOF |
| 6404 | |
| 6405 | // Force all writes to happen before any read, last write will not |
| 6406 | // actually queue a frame, due to window size being 0. |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 6407 | DeterministicSocketData data(reads.data(), reads.size(), writes.data(), |
| 6408 | writes.size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6409 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6410 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6411 | std::string upload_data_string(initial_window_size, 'a'); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6412 | upload_data_string.append(kUploadData, kUploadDataSize); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6413 | element_readers.push_back(make_scoped_ptr(new UploadBytesElementReader( |
| 6414 | upload_data_string.c_str(), upload_data_string.size()))); |
| 6415 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6416 | |
| 6417 | HttpRequestInfo request; |
| 6418 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6419 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6420 | request.upload_data_stream = &upload_data_stream; |
| 6421 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 6422 | BoundNetLog(), GetParam(), NULL); |
| 6423 | helper.SetDeterministic(); |
| 6424 | helper.RunPreTestSetup(); |
| 6425 | helper.AddDeterministicData(&data); |
| 6426 | |
| 6427 | HttpNetworkTransaction* trans = helper.trans(); |
| 6428 | |
| 6429 | TestCompletionCallback callback; |
| 6430 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6431 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6432 | |
| 6433 | data.RunFor(num_writes - 1); // Write as much as we can. |
| 6434 | |
| 6435 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6436 | ASSERT_TRUE(stream != NULL); |
| 6437 | ASSERT_TRUE(stream->stream() != NULL); |
| 6438 | EXPECT_EQ(0, stream->stream()->send_window_size()); |
| 6439 | |
| 6440 | // All the body data should have been read. |
| 6441 | // TODO(satorux): This is because of the weirdness in reading the request |
| 6442 | // body in OnSendBodyComplete(). See crbug.com/113107. |
| 6443 | EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 6444 | // But the body is not yet fully sent (kUploadData is not yet sent) |
| 6445 | // since we're send-stalled. |
| 6446 | EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 6447 | |
| 6448 | // Read in WINDOW_UPDATE or SETTINGS frame. |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 6449 | data.RunFor((GetParam().protocol >= kProtoSPDY31) ? 9 : 8); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6450 | rv = callback.WaitForResult(); |
| 6451 | helper.VerifyDataConsumed(); |
| 6452 | } |
| 6453 | |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6454 | TEST_P(SpdyNetworkTransactionTest, GoAwayOnOddPushStreamId) { |
| 6455 | if (spdy_util_.spdy_version() < SPDY3) |
| 6456 | return; |
| 6457 | |
| 6458 | scoped_ptr<SpdyHeaderBlock> push_headers(new SpdyHeaderBlock); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6459 | spdy_util_.AddUrlToHeaderBlock("http://www.example.org/a.dat", |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6460 | push_headers.get()); |
| 6461 | scoped_ptr<SpdyFrame> push( |
| 6462 | spdy_util_.ConstructInitialSpdyPushFrame(push_headers.Pass(), 3, 1)); |
| 6463 | MockRead reads[] = {CreateMockRead(*push, 1)}; |
| 6464 | |
| 6465 | scoped_ptr<SpdyFrame> req( |
| 6466 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 6467 | scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 6468 | 0, GOAWAY_PROTOCOL_ERROR, "Odd push stream id.")); |
| 6469 | MockWrite writes[] = { |
| 6470 | CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2), |
| 6471 | }; |
| 6472 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 6473 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6474 | NormalSpdyTransactionHelper helper( |
| 6475 | CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 6476 | helper.RunToCompletion(&data); |
| 6477 | TransactionHelperResult out = helper.output(); |
| 6478 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 6479 | } |
| 6480 | |
| 6481 | TEST_P(SpdyNetworkTransactionTest, |
| 6482 | GoAwayOnPushStreamIdLesserOrEqualThanLastAccepted) { |
| 6483 | if (spdy_util_.spdy_version() < SPDY3) |
| 6484 | return; |
| 6485 | |
| 6486 | scoped_ptr<SpdyFrame> push_a(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6487 | NULL, 0, 4, 1, GetDefaultUrlWithPath("/a.dat").c_str())); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6488 | scoped_ptr<SpdyHeaderBlock> push_b_headers(new SpdyHeaderBlock); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6489 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/b.dat"), |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6490 | push_b_headers.get()); |
| 6491 | scoped_ptr<SpdyFrame> push_b( |
| 6492 | spdy_util_.ConstructInitialSpdyPushFrame(push_b_headers.Pass(), 2, 1)); |
| 6493 | MockRead reads[] = { |
| 6494 | CreateMockRead(*push_a, 1), CreateMockRead(*push_b, 2), |
| 6495 | }; |
| 6496 | |
| 6497 | scoped_ptr<SpdyFrame> req( |
| 6498 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 6499 | scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 6500 | 4, |
| 6501 | GOAWAY_PROTOCOL_ERROR, |
| 6502 | "New push stream id must be greater than the last accepted.")); |
| 6503 | MockWrite writes[] = { |
| 6504 | CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 3), |
| 6505 | }; |
| 6506 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 6507 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6508 | NormalSpdyTransactionHelper helper( |
| 6509 | CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 6510 | helper.RunToCompletion(&data); |
| 6511 | TransactionHelperResult out = helper.output(); |
| 6512 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 6513 | } |
| 6514 | |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6515 | // Regression test for https://crbug.com/493348: request header exceeds 16 kB |
| 6516 | // and thus sent in multiple frames when using HTTP/2. |
| 6517 | TEST_P(SpdyNetworkTransactionTest, LargeRequest) { |
| 6518 | const std::string kKey("foo"); |
| 6519 | const std::string kValue(1 << 15, 'z'); |
| 6520 | |
| 6521 | HttpRequestInfo request; |
| 6522 | request.method = "GET"; |
| 6523 | request.url = GURL(GetDefaultUrl()); |
| 6524 | request.extra_headers.SetHeader(kKey, kValue); |
| 6525 | |
| 6526 | scoped_ptr<SpdyHeaderBlock> headers( |
| 6527 | spdy_util_.ConstructGetHeaderBlock(GetDefaultUrl())); |
| 6528 | (*headers)[kKey] = kValue; |
| 6529 | scoped_ptr<SpdyFrame> req( |
| 6530 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
| 6531 | MockWrite writes[] = { |
| 6532 | CreateMockWrite(*req, 0), |
| 6533 | }; |
| 6534 | |
| 6535 | scoped_ptr<SpdyFrame> resp( |
| 6536 | spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 6537 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6538 | MockRead reads[] = { |
| 6539 | CreateMockRead(*resp, 1), |
| 6540 | CreateMockRead(*body, 2), |
| 6541 | MockRead(ASYNC, 0, 3) // EOF |
| 6542 | }; |
| 6543 | |
| 6544 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 6545 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 6546 | GetParam(), nullptr); |
| 6547 | helper.RunToCompletion(&data); |
| 6548 | TransactionHelperResult out = helper.output(); |
| 6549 | |
| 6550 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6551 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6552 | EXPECT_EQ("hello!", out.response_data); |
| 6553 | } |
| 6554 | |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6555 | class SpdyNetworkTransactionNoTLSUsageCheckTest |
| 6556 | : public SpdyNetworkTransactionTest { |
| 6557 | protected: |
| 6558 | void RunNoTLSUsageCheckTest(scoped_ptr<SSLSocketDataProvider> ssl_provider) { |
| 6559 | // Construct the request. |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6560 | scoped_ptr<SpdyFrame> req( |
| 6561 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 6562 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6563 | |
| 6564 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 6565 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6566 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 6567 | CreateMockRead(*resp, 1), |
| 6568 | CreateMockRead(*body, 2), |
| 6569 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6570 | }; |
| 6571 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 6572 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 6573 | arraysize(writes)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6574 | HttpRequestInfo request; |
| 6575 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6576 | request.url = GURL("https://www.example.org/"); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6577 | NormalSpdyTransactionHelper helper( |
| 6578 | request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 6579 | helper.RunToCompletionWithSSLData(&data, ssl_provider.Pass()); |
| 6580 | TransactionHelperResult out = helper.output(); |
| 6581 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6582 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6583 | EXPECT_EQ("hello!", out.response_data); |
| 6584 | } |
| 6585 | }; |
| 6586 | |
| 6587 | //----------------------------------------------------------------------------- |
| 6588 | // All tests are run with three different connection types: SPDY after NPN |
| 6589 | // negotiation, SPDY without SSL, and SPDY with SSL. |
| 6590 | // |
| 6591 | // TODO(akalin): Use ::testing::Combine() when we are able to use |
| 6592 | // <tr1/tuple>. |
| 6593 | INSTANTIATE_TEST_CASE_P( |
| 6594 | Spdy, |
| 6595 | SpdyNetworkTransactionNoTLSUsageCheckTest, |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6596 | ::testing::Values(SpdyNetworkTransactionTestParams(kProtoSPDY31, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6597 | HTTPS_SPDY_VIA_NPN, |
| 6598 | false))); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6599 | |
| 6600 | TEST_P(SpdyNetworkTransactionNoTLSUsageCheckTest, TLSVersionTooOld) { |
| 6601 | scoped_ptr<SSLSocketDataProvider> ssl_provider( |
| 6602 | new SSLSocketDataProvider(ASYNC, OK)); |
| 6603 | SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_SSL3, |
| 6604 | &ssl_provider->connection_status); |
| 6605 | |
| 6606 | RunNoTLSUsageCheckTest(ssl_provider.Pass()); |
| 6607 | } |
| 6608 | |
| 6609 | TEST_P(SpdyNetworkTransactionNoTLSUsageCheckTest, TLSCipherSuiteSucky) { |
| 6610 | scoped_ptr<SSLSocketDataProvider> ssl_provider( |
| 6611 | new SSLSocketDataProvider(ASYNC, OK)); |
| 6612 | // Set to TLS_RSA_WITH_NULL_MD5 |
| 6613 | SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); |
| 6614 | |
| 6615 | RunNoTLSUsageCheckTest(ssl_provider.Pass()); |
| 6616 | } |
| 6617 | |
| 6618 | class SpdyNetworkTransactionTLSUsageCheckTest |
| 6619 | : public SpdyNetworkTransactionTest { |
| 6620 | protected: |
| 6621 | void RunTLSUsageCheckTest(scoped_ptr<SSLSocketDataProvider> ssl_provider) { |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 6622 | scoped_ptr<SpdyFrame> goaway( |
| 6623 | spdy_util_.ConstructSpdyGoAway(0, GOAWAY_INADEQUATE_SECURITY, "")); |
| 6624 | MockWrite writes[] = {CreateMockWrite(*goaway)}; |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6625 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 6626 | StaticSocketDataProvider data(NULL, 0, writes, arraysize(writes)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6627 | HttpRequestInfo request; |
| 6628 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6629 | request.url = GURL("https://www.example.org/"); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6630 | NormalSpdyTransactionHelper helper( |
| 6631 | request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 6632 | helper.RunToCompletionWithSSLData(&data, ssl_provider.Pass()); |
| 6633 | TransactionHelperResult out = helper.output(); |
| 6634 | EXPECT_EQ(ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY, out.rv); |
| 6635 | } |
| 6636 | }; |
| 6637 | |
| 6638 | INSTANTIATE_TEST_CASE_P( |
| 6639 | Spdy, |
| 6640 | SpdyNetworkTransactionTLSUsageCheckTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6641 | ::testing::Values(SpdyNetworkTransactionTestParams(kProtoHTTP2, |
| 6642 | HTTPS_SPDY_VIA_NPN, |
| 6643 | false), |
| 6644 | SpdyNetworkTransactionTestParams(kProtoHTTP2, |
| 6645 | HTTPS_SPDY_VIA_NPN, |
| 6646 | true))); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6647 | |
| 6648 | TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSVersionTooOld) { |
| 6649 | scoped_ptr<SSLSocketDataProvider> ssl_provider( |
| 6650 | new SSLSocketDataProvider(ASYNC, OK)); |
| 6651 | SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_SSL3, |
| 6652 | &ssl_provider->connection_status); |
| 6653 | |
| 6654 | RunTLSUsageCheckTest(ssl_provider.Pass()); |
| 6655 | } |
| 6656 | |
| 6657 | TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { |
| 6658 | scoped_ptr<SSLSocketDataProvider> ssl_provider( |
| 6659 | new SSLSocketDataProvider(ASYNC, OK)); |
| 6660 | // Set to TLS_RSA_WITH_NULL_MD5 |
| 6661 | SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); |
| 6662 | |
| 6663 | RunTLSUsageCheckTest(ssl_provider.Pass()); |
| 6664 | } |
| 6665 | |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 6666 | } // namespace net |