[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> |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 6 | #include <utility> |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 7 | #include <vector> |
| 8 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9 | #include "base/bind.h" |
| 10 | #include "base/bind_helpers.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 11 | #include "base/files/file_util.h" |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 12 | #include "base/files/scoped_temp_dir.h" |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 13 | #include "base/memory/scoped_ptr.h" |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 14 | #include "base/run_loop.h" |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 15 | #include "base/strings/string_piece.h" |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 16 | #include "base/test/test_file_util.h" |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 17 | #include "base/thread_task_runner_handle.h" |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 18 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 19 | #include "net/base/chunked_upload_data_stream.h" |
| 20 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 21 | #include "net/base/request_priority.h" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 22 | #include "net/base/test_data_directory.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 23 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 24 | #include "net/base/upload_file_element_reader.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 25 | #include "net/http/http_auth_scheme.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 26 | #include "net/http/http_network_session_peer.h" |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 27 | #include "net/http/http_network_transaction.h" |
| 28 | #include "net/http/http_server_properties.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 29 | #include "net/http/http_transaction_test_util.h" |
mmenke | 16a7cbdd | 2015-04-24 23:00:56 | [diff] [blame] | 30 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 31 | #include "net/log/test_net_log_entry.h" |
| 32 | #include "net/log/test_net_log_util.h" |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 33 | #include "net/socket/client_socket_pool_base.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 34 | #include "net/socket/next_proto.h" |
[email protected] | f54c8579 | 2012-03-08 19:06:41 | [diff] [blame] | 35 | #include "net/spdy/buffered_spdy_framer.h" |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 36 | #include "net/spdy/spdy_http_stream.h" |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 37 | #include "net/spdy/spdy_http_utils.h" |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 38 | #include "net/spdy/spdy_session.h" |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 39 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 40 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | a4bfdf7 | 2013-02-22 04:06:16 | [diff] [blame] | 41 | #include "net/spdy/spdy_test_utils.h" |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 42 | #include "net/ssl/ssl_connection_status_flags.h" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 43 | #include "net/test/cert_test_util.h" |
[email protected] | d2db029 | 2011-01-26 20:23:44 | [diff] [blame] | 44 | #include "net/url_request/url_request_test_util.h" |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 45 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 46 | #include "testing/platform_test.h" |
| 47 | |
| 48 | //----------------------------------------------------------------------------- |
| 49 | |
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 50 | namespace net { |
[email protected] | dae22c5 | 2010-07-30 02:16:35 | [diff] [blame] | 51 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 52 | namespace { |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 53 | |
| 54 | using testing::Each; |
| 55 | using testing::Eq; |
| 56 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 57 | enum SpdyNetworkTransactionTestSSLType { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 58 | // Request an https:// URL and use NPN (or ALPN) to negotiate SPDY during |
| 59 | // the TLS handshake. |
| 60 | HTTPS_SPDY_VIA_NPN, |
| 61 | // Request and http:// URL to a server that supports SPDY via Alternative |
| 62 | // Service on port 443. |
| 63 | // See: https//tools.ietf.org/id/draft-ietf-httpbis-alt-svc-06.html |
| 64 | HTTP_SPDY_VIA_ALT_SVC, |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 65 | }; |
[email protected] | ca6459f86 | 2012-04-11 19:43:20 | [diff] [blame] | 66 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 67 | struct SpdyNetworkTransactionTestParams { |
| 68 | SpdyNetworkTransactionTestParams() |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 69 | : protocol(kProtoSPDY31), |
| 70 | ssl_type(HTTPS_SPDY_VIA_NPN), |
| 71 | priority_to_dependency(false) {} |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 72 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 73 | SpdyNetworkTransactionTestParams(NextProto protocol, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 74 | SpdyNetworkTransactionTestSSLType ssl_type, |
| 75 | bool priority_to_dependency) |
| 76 | : protocol(protocol), |
| 77 | ssl_type(ssl_type), |
| 78 | priority_to_dependency(priority_to_dependency) {} |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 79 | |
| 80 | friend std::ostream& operator<<(std::ostream& os, |
| 81 | const SpdyNetworkTransactionTestParams& p) { |
| 82 | std::string type_str; |
| 83 | switch (p.ssl_type) { |
| 84 | case HTTP_SPDY_VIA_ALT_SVC: |
| 85 | type_str = "HTTP_SPDY_VIA_ALT_SVC"; |
| 86 | break; |
| 87 | case HTTPS_SPDY_VIA_NPN: |
| 88 | type_str = "HTTPS_SPDY_VIA_NPN"; |
| 89 | break; |
| 90 | } |
| 91 | os << "{ protocol: " << SSLClientSocket::NextProtoToString(p.protocol) |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 92 | << ", ssl_type: " << type_str |
| 93 | << ", priority_to_dependency: " << p.priority_to_dependency << " }"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 94 | return os; |
| 95 | } |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 96 | |
| 97 | NextProto protocol; |
| 98 | SpdyNetworkTransactionTestSSLType ssl_type; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 99 | bool priority_to_dependency; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 100 | }; |
| 101 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 102 | void UpdateSpdySessionDependencies(SpdyNetworkTransactionTestParams test_params, |
| 103 | SpdySessionDependencies* session_deps) { |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 104 | session_deps->use_alternative_services = true; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 105 | session_deps->next_protos = SpdyNextProtos(); |
| 106 | if (test_params.ssl_type == HTTP_SPDY_VIA_ALT_SVC) { |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 107 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 108 | session_deps->http_server_properties.SetAlternativeService( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 109 | HostPortPair("www.example.org", 80), |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 110 | AlternativeService(AlternateProtocolFromNextProto(test_params.protocol), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 111 | "www.example.org", 443), |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 112 | 1.0, expiration); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 116 | scoped_ptr<SpdySessionDependencies> CreateSpdySessionDependencies( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 117 | SpdyNetworkTransactionTestParams test_params) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 118 | scoped_ptr<SpdySessionDependencies> session_deps( |
| 119 | new SpdySessionDependencies(test_params.protocol)); |
| 120 | UpdateSpdySessionDependencies(test_params, session_deps.get()); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 121 | return session_deps; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 122 | } |
| 123 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 124 | scoped_ptr<SpdySessionDependencies> CreateSpdySessionDependencies( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 125 | SpdyNetworkTransactionTestParams test_params, |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 126 | scoped_ptr<ProxyService> proxy_service) { |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 127 | scoped_ptr<SpdySessionDependencies> session_deps(new SpdySessionDependencies( |
| 128 | test_params.protocol, std::move(proxy_service))); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 129 | UpdateSpdySessionDependencies(test_params, session_deps.get()); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 130 | return session_deps; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 131 | } |
| 132 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 133 | } // namespace |
| 134 | |
| 135 | class SpdyNetworkTransactionTest |
| 136 | : public ::testing::TestWithParam<SpdyNetworkTransactionTestParams> { |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 137 | protected: |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 138 | SpdyNetworkTransactionTest() |
| 139 | : spdy_util_(GetParam().protocol, GetParam().priority_to_dependency) { |
| 140 | SpdySession::SetPriorityDependencyDefaultForTesting( |
| 141 | GetParam().priority_to_dependency); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 142 | spdy_util_.set_default_url(GURL(GetDefaultUrl())); |
[email protected] | 9ec54f8 | 2013-05-10 02:53:05 | [diff] [blame] | 143 | } |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 144 | |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 145 | virtual ~SpdyNetworkTransactionTest() { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 146 | // UploadDataStream may post a deletion tasks back to the message loop on |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 147 | // destruction. |
| 148 | upload_data_stream_.reset(); |
| 149 | base::RunLoop().RunUntilIdle(); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 150 | SpdySession::SetPriorityDependencyDefaultForTesting(false); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 151 | } |
| 152 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 153 | void SetUp() override { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 154 | get_request_initialized_ = false; |
| 155 | post_request_initialized_ = false; |
| 156 | chunked_post_request_initialized_ = false; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 157 | ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 158 | } |
| 159 | |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 160 | struct TransactionHelperResult { |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 161 | int rv; |
| 162 | std::string status_line; |
| 163 | std::string response_data; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 164 | HttpResponseInfo response_info; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 165 | }; |
| 166 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 167 | // A helper class that handles all the initial npn/ssl setup. |
| 168 | class NormalSpdyTransactionHelper { |
| 169 | public: |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 170 | NormalSpdyTransactionHelper( |
| 171 | const HttpRequestInfo& request, |
| 172 | RequestPriority priority, |
| 173 | const BoundNetLog& log, |
| 174 | SpdyNetworkTransactionTestParams test_params, |
| 175 | scoped_ptr<SpdySessionDependencies> session_deps) |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 176 | : request_(request), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 177 | priority_(priority), |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 178 | session_deps_(session_deps.get() == NULL |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 179 | ? CreateSpdySessionDependencies(test_params) |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 180 | : std::move(session_deps)), |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 181 | session_( |
| 182 | SpdySessionDependencies::SpdyCreateSession(session_deps_.get())), |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 183 | log_(log), |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 184 | test_params_(test_params), |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 185 | port_(443), |
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] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 200 | void SetSpdyDisabled() { |
| 201 | spdy_enabled_ = false; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 202 | port_ = test_params_.ssl_type == HTTP_SPDY_VIA_ALT_SVC ? 80 : 443; |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 203 | } |
| 204 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 205 | void RunPreTestSetup() { |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 206 | if (!session_deps_.get()) |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 207 | session_deps_ = CreateSpdySessionDependencies(test_params_); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 208 | if (!session_.get()) { |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 209 | session_ = SpdySessionDependencies::SpdyCreateSession( |
| 210 | session_deps_.get()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 211 | } |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 212 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 213 | // We're now ready to use SSL-npn SPDY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 214 | trans_.reset(new HttpNetworkTransaction(priority_, session_.get())); |
[email protected] | cb54b3b2 | 2010-06-03 16:28:55 | [diff] [blame] | 215 | } |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 216 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 217 | // Start the transaction, read some data, finish. |
| 218 | void RunDefaultTest() { |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 219 | if (!StartDefaultTest()) |
| 220 | return; |
| 221 | FinishDefaultTest(); |
| 222 | } |
| 223 | |
| 224 | bool StartDefaultTest() { |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 225 | output_.rv = trans_->Start(&request_, callback_.callback(), log_); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 226 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 227 | // We expect an IO Pending or some sort of error. |
| 228 | EXPECT_LT(output_.rv, 0); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 229 | return output_.rv == ERR_IO_PENDING; |
| 230 | } |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 231 | |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 232 | void FinishDefaultTest() { |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 233 | output_.rv = callback_.WaitForResult(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 234 | if (output_.rv != OK) { |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 235 | session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 236 | return; |
| 237 | } |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 238 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 239 | // Verify responses. |
| 240 | const HttpResponseInfo* response = trans_->GetResponseInfo(); |
| 241 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 242 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 808957c | 2013-03-13 03:51:27 | [diff] [blame] | 243 | if (HttpStreamFactory::spdy_enabled()) { |
[email protected] | 88a33262 | 2013-07-30 07:13:32 | [diff] [blame] | 244 | EXPECT_EQ( |
| 245 | HttpResponseInfo::ConnectionInfoFromNextProto( |
| 246 | test_params_.protocol), |
| 247 | response->connection_info); |
[email protected] | 808957c | 2013-03-13 03:51:27 | [diff] [blame] | 248 | } else { |
| 249 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, |
| 250 | response->connection_info); |
| 251 | } |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 252 | if (spdy_enabled_) { |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 253 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 254 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 255 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 256 | } else { |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 257 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 258 | EXPECT_FALSE(response->was_fetched_via_spdy); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 259 | // If SPDY is disabled, an HTTP request should not be diverted |
| 260 | // over an SSL session. |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 261 | EXPECT_EQ(request_.url.SchemeIs("https"), |
| 262 | response->was_npn_negotiated); |
| 263 | } |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 264 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 265 | EXPECT_EQ(port_, response->socket_address.port()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 266 | output_.status_line = response->headers->GetStatusLine(); |
| 267 | output_.response_info = *response; // Make a copy so we can verify. |
| 268 | output_.rv = ReadTransaction(trans_.get(), &output_.response_data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 269 | } |
| 270 | |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 271 | void FinishDefaultTestWithoutVerification() { |
| 272 | output_.rv = callback_.WaitForResult(); |
| 273 | if (output_.rv != OK) |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 274 | session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 275 | } |
| 276 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 277 | void WaitForHeaders() { output_.rv = callback_.WaitForResult(); } |
| 278 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 279 | // Most tests will want to call this function. In particular, the MockReads |
| 280 | // should end with an empty read, and that read needs to be processed to |
| 281 | // ensure proper deletion of the spdy_session_pool. |
| 282 | void VerifyDataConsumed() { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 283 | for (const SocketDataProvider* provider : data_vector_) { |
| 284 | EXPECT_TRUE(provider->AllReadDataConsumed()); |
| 285 | EXPECT_TRUE(provider->AllWriteDataConsumed()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | |
| 289 | // Occasionally a test will expect to error out before certain reads are |
| 290 | // processed. In that case we want to explicitly ensure that the reads were |
| 291 | // not processed. |
| 292 | void VerifyDataNotConsumed() { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 293 | for (const SocketDataProvider* provider : data_vector_) { |
| 294 | EXPECT_FALSE(provider->AllReadDataConsumed()); |
| 295 | EXPECT_FALSE(provider->AllWriteDataConsumed()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 299 | void RunToCompletion(SocketDataProvider* data) { |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 300 | RunPreTestSetup(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 301 | AddData(data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 302 | RunDefaultTest(); |
| 303 | VerifyDataConsumed(); |
| 304 | } |
[email protected] | e6b0686 | 2010-07-20 16:32:58 | [diff] [blame] | 305 | |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 306 | void RunToCompletionWithSSLData( |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 307 | SocketDataProvider* data, |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 308 | scoped_ptr<SSLSocketDataProvider> ssl_provider) { |
| 309 | RunPreTestSetup(); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 310 | AddDataWithSSLSocketDataProvider(data, std::move(ssl_provider)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 311 | RunDefaultTest(); |
| 312 | VerifyDataConsumed(); |
| 313 | } |
| 314 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 315 | void AddData(SocketDataProvider* data) { |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 316 | scoped_ptr<SSLSocketDataProvider> ssl_provider( |
| 317 | new SSLSocketDataProvider(ASYNC, OK)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 318 | ssl_provider->cert = |
| 319 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 320 | AddDataWithSSLSocketDataProvider(data, std::move(ssl_provider)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | void AddDataWithSSLSocketDataProvider( |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 324 | SocketDataProvider* data, |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 325 | scoped_ptr<SSLSocketDataProvider> ssl_provider) { |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 326 | data_vector_.push_back(data); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 327 | if (ssl_provider->next_proto_status == |
| 328 | SSLClientSocket::kNextProtoUnsupported) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 329 | ssl_provider->SetNextProto(test_params_.protocol); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 330 | } |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 331 | |
| 332 | session_deps_->socket_factory->AddSSLSocketDataProvider( |
| 333 | ssl_provider.get()); |
olli.raula | ae011c42 | 2015-12-10 07:38:51 | [diff] [blame] | 334 | ssl_vector_.push_back(std::move(ssl_provider)); |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 335 | |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 336 | session_deps_->socket_factory->AddSocketDataProvider(data); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 337 | if (test_params_.ssl_type == HTTP_SPDY_VIA_ALT_SVC) { |
| 338 | MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); |
olli.raula | ae011c42 | 2015-12-10 07:38:51 | [diff] [blame] | 339 | scoped_ptr<StaticSocketDataProvider> hanging_non_alt_svc_socket( |
| 340 | make_scoped_ptr(new StaticSocketDataProvider(NULL, 0, NULL, 0))); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 341 | hanging_non_alt_svc_socket->set_connect_data(hanging_connect); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 342 | session_deps_->socket_factory->AddSocketDataProvider( |
olli.raula | ae011c42 | 2015-12-10 07:38:51 | [diff] [blame] | 343 | hanging_non_alt_svc_socket.get()); |
| 344 | alternate_vector_.push_back(std::move(hanging_non_alt_svc_socket)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 345 | } |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 346 | } |
| 347 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 348 | void SetSession(scoped_ptr<HttpNetworkSession> session) { |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 349 | session_ = std::move(session); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 350 | } |
| 351 | HttpNetworkTransaction* trans() { return trans_.get(); } |
| 352 | void ResetTrans() { trans_.reset(); } |
| 353 | TransactionHelperResult& output() { return output_; } |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 354 | const HttpRequestInfo& request() const { return request_; } |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 355 | HttpNetworkSession* session() const { return session_.get(); } |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 356 | scoped_ptr<SpdySessionDependencies>& session_deps() { |
| 357 | return session_deps_; |
| 358 | } |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 359 | int port() const { return port_; } |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 360 | SpdyNetworkTransactionTestParams test_params() const { |
| 361 | return test_params_; |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 362 | } |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 363 | |
| 364 | private: |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 365 | typedef std::vector<SocketDataProvider*> DataVector; |
olli.raula | ae011c42 | 2015-12-10 07:38:51 | [diff] [blame] | 366 | typedef std::vector<scoped_ptr<SSLSocketDataProvider>> SSLVector; |
| 367 | typedef std::vector<scoped_ptr<SocketDataProvider>> AlternateVector; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 368 | HttpRequestInfo request_; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 369 | RequestPriority priority_; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 370 | scoped_ptr<SpdySessionDependencies> session_deps_; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 371 | scoped_ptr<HttpNetworkSession> session_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 372 | TransactionHelperResult output_; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 373 | scoped_ptr<SocketDataProvider> first_transaction_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 374 | SSLVector ssl_vector_; |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 375 | TestCompletionCallback callback_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 376 | scoped_ptr<HttpNetworkTransaction> trans_; |
| 377 | scoped_ptr<HttpNetworkTransaction> trans_http_; |
| 378 | DataVector data_vector_; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 379 | AlternateVector alternate_vector_; |
bnc | 29b1f07 | 2015-01-14 20:37:49 | [diff] [blame] | 380 | const BoundNetLog log_; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 381 | SpdyNetworkTransactionTestParams test_params_; |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 382 | int port_; |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 383 | bool spdy_enabled_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 384 | }; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 385 | |
| 386 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 387 | int expected_status); |
| 388 | |
| 389 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 390 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 391 | const HttpRequestInfo& CreateGetPushRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 392 | get_push_request_.method = "GET"; |
| 393 | get_push_request_.url = GURL(GetDefaultUrlWithPath("/foo.dat")); |
| 394 | get_push_request_.load_flags = 0; |
| 395 | return get_push_request_; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 396 | } |
| 397 | |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 398 | const HttpRequestInfo& CreateGetRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 399 | if (!get_request_initialized_) { |
| 400 | get_request_.method = "GET"; |
| 401 | get_request_.url = GURL(GetDefaultUrl()); |
| 402 | get_request_.load_flags = 0; |
| 403 | get_request_initialized_ = true; |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 404 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 405 | return get_request_; |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 406 | } |
| 407 | |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 408 | const HttpRequestInfo& CreateGetRequestWithUserAgent() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 409 | if (!get_request_initialized_) { |
| 410 | get_request_.method = "GET"; |
| 411 | get_request_.url = GURL(GetDefaultUrl()); |
| 412 | get_request_.load_flags = 0; |
| 413 | get_request_.extra_headers.SetHeader("User-Agent", "Chrome"); |
| 414 | get_request_initialized_ = true; |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 415 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 416 | return get_request_; |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 417 | } |
| 418 | |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 419 | const HttpRequestInfo& CreatePostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 420 | if (!post_request_initialized_) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 421 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 422 | element_readers.push_back(make_scoped_ptr( |
| 423 | new UploadBytesElementReader(kUploadData, kUploadDataSize))); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 424 | upload_data_stream_.reset( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 425 | new ElementsUploadDataStream(std::move(element_readers), 0)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 426 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 427 | post_request_.method = "POST"; |
| 428 | post_request_.url = GURL(GetDefaultUrl()); |
| 429 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 430 | post_request_initialized_ = true; |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 431 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 432 | return post_request_; |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 433 | } |
| 434 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 435 | const HttpRequestInfo& CreateFilePostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 436 | if (!post_request_initialized_) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 437 | base::FilePath file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 438 | CHECK(base::CreateTemporaryFileInDir(temp_dir_.path(), &file_path)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 439 | CHECK_EQ(static_cast<int>(kUploadDataSize), |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 440 | base::WriteFile(file_path, kUploadData, kUploadDataSize)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 441 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 442 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 443 | element_readers.push_back(make_scoped_ptr(new UploadFileElementReader( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 444 | base::ThreadTaskRunnerHandle::Get().get(), file_path, 0, |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 445 | kUploadDataSize, base::Time()))); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 446 | upload_data_stream_.reset( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 447 | new ElementsUploadDataStream(std::move(element_readers), 0)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 448 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 449 | post_request_.method = "POST"; |
| 450 | post_request_.url = GURL(GetDefaultUrl()); |
| 451 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 452 | post_request_initialized_ = true; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 453 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 454 | return post_request_; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 455 | } |
| 456 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 457 | const HttpRequestInfo& CreateUnreadableFilePostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 458 | if (post_request_initialized_) |
| 459 | return post_request_; |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 460 | |
| 461 | base::FilePath file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 462 | CHECK(base::CreateTemporaryFileInDir(temp_dir_.path(), &file_path)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 463 | CHECK_EQ(static_cast<int>(kUploadDataSize), |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 464 | base::WriteFile(file_path, kUploadData, kUploadDataSize)); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 465 | CHECK(base::MakeFileUnreadable(file_path)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 466 | |
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(new UploadFileElementReader( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 469 | base::ThreadTaskRunnerHandle::Get().get(), file_path, 0, |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 470 | kUploadDataSize, base::Time()))); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 471 | upload_data_stream_.reset( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 472 | new ElementsUploadDataStream(std::move(element_readers), 0)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 473 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 474 | post_request_.method = "POST"; |
| 475 | post_request_.url = GURL(GetDefaultUrl()); |
| 476 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 477 | post_request_initialized_ = true; |
| 478 | return post_request_; |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 479 | } |
| 480 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 481 | const HttpRequestInfo& CreateComplexPostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 482 | if (!post_request_initialized_) { |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 483 | const int kFileRangeOffset = 1; |
| 484 | const int kFileRangeLength = 3; |
| 485 | CHECK_LT(kFileRangeOffset + kFileRangeLength, kUploadDataSize); |
| 486 | |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 487 | base::FilePath file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 488 | CHECK(base::CreateTemporaryFileInDir(temp_dir_.path(), &file_path)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 489 | CHECK_EQ(static_cast<int>(kUploadDataSize), |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 490 | base::WriteFile(file_path, kUploadData, kUploadDataSize)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 491 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 492 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 493 | element_readers.push_back(make_scoped_ptr( |
| 494 | new UploadBytesElementReader(kUploadData, kFileRangeOffset))); |
| 495 | element_readers.push_back(make_scoped_ptr(new UploadFileElementReader( |
skyostil | 4891b25b | 2015-06-11 11:43:45 | [diff] [blame] | 496 | base::ThreadTaskRunnerHandle::Get().get(), file_path, |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 497 | kFileRangeOffset, kFileRangeLength, base::Time()))); |
| 498 | element_readers.push_back(make_scoped_ptr(new UploadBytesElementReader( |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 499 | kUploadData + kFileRangeOffset + kFileRangeLength, |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 500 | kUploadDataSize - (kFileRangeOffset + kFileRangeLength)))); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 501 | upload_data_stream_.reset( |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 502 | new ElementsUploadDataStream(std::move(element_readers), 0)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 503 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 504 | post_request_.method = "POST"; |
| 505 | post_request_.url = GURL(GetDefaultUrl()); |
| 506 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 507 | post_request_initialized_ = true; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 508 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 509 | return post_request_; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 510 | } |
| 511 | |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 512 | const HttpRequestInfo& CreateChunkedPostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 513 | if (!chunked_post_request_initialized_) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 514 | upload_chunked_data_stream_.reset(new ChunkedUploadDataStream(0)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 515 | chunked_post_request_.method = "POST"; |
| 516 | chunked_post_request_.url = GURL(GetDefaultUrl()); |
| 517 | chunked_post_request_.upload_data_stream = |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 518 | upload_chunked_data_stream_.get(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 519 | chunked_post_request_initialized_ = true; |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 520 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 521 | return chunked_post_request_; |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 522 | } |
| 523 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 524 | // Read the result of a particular transaction, knowing that we've got |
| 525 | // multiple transactions in the read pipeline; so as we read, we may have |
| 526 | // to skip over data destined for other transactions while we consume |
| 527 | // the data for |trans|. |
| 528 | int ReadResult(HttpNetworkTransaction* trans, |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 529 | std::string* result) { |
| 530 | const int kSize = 3000; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 531 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 532 | int bytes_read = 0; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 533 | scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(kSize)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 534 | TestCompletionCallback callback; |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 535 | while (true) { |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 536 | int rv = trans->Read(buf.get(), kSize, callback.callback()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 537 | if (rv == ERR_IO_PENDING) { |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 538 | rv = callback.WaitForResult(); |
| 539 | } else if (rv <= 0) { |
| 540 | break; |
| 541 | } |
| 542 | result->append(buf->data(), rv); |
| 543 | bytes_read += rv; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 544 | } |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 545 | return bytes_read; |
| 546 | } |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 547 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 548 | void VerifyStreamsClosed(const NormalSpdyTransactionHelper& helper) { |
| 549 | // This lengthy block is reaching into the pool to dig out the active |
| 550 | // session. Once we have the session, we verify that the streams are |
| 551 | // all closed and not leaked at this point. |
| 552 | const GURL& url = helper.request().url; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 553 | HostPortPair host_port_pair(url.host(), 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 554 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 555 | PRIVACY_MODE_DISABLED); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 556 | BoundNetLog log; |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 557 | HttpNetworkSession* session = helper.session(); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 558 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 04644d4 | 2013-07-08 04:29:59 | [diff] [blame] | 559 | session->spdy_session_pool()->FindAvailableSession(key, log); |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 560 | ASSERT_TRUE(spdy_session != NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 561 | EXPECT_EQ(0u, spdy_session->num_active_streams()); |
| 562 | EXPECT_EQ(0u, spdy_session->num_unclaimed_pushed_streams()); |
| 563 | } |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 564 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 565 | void RunServerPushTest(SequencedSocketData* data, |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 566 | HttpResponseInfo* response, |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 567 | HttpResponseInfo* push_response, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 568 | const std::string& expected) { |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 569 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 570 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 571 | helper.RunPreTestSetup(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 572 | helper.AddData(data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 573 | |
| 574 | HttpNetworkTransaction* trans = helper.trans(); |
| 575 | |
| 576 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 577 | TestCompletionCallback callback; |
| 578 | int rv = trans->Start( |
| 579 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 580 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 581 | rv = callback.WaitForResult(); |
| 582 | |
| 583 | // Request the pushed path. |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 584 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 585 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 586 | rv = trans2->Start( |
| 587 | &CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 588 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 589 | base::RunLoop().RunUntilIdle(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 590 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 591 | // 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] | 592 | // the results into a single string. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 593 | |
| 594 | // Read the server push body. |
| 595 | std::string result2; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 596 | ReadResult(trans2.get(), &result2); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 597 | // Read the response body. |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 598 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 599 | ReadResult(trans, &result); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 600 | |
| 601 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 602 | EXPECT_TRUE(data->AllReadDataConsumed()); |
| 603 | EXPECT_TRUE(data->AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 604 | |
| 605 | // Verify that the received push data is same as the expected push data. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 606 | EXPECT_EQ(result2.compare(expected), 0) << "Received data: " |
| 607 | << result2 |
| 608 | << "||||| Expected data: " |
| 609 | << expected; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 610 | |
| 611 | // Verify the SYN_REPLY. |
| 612 | // Copy the response info, because trans goes away. |
| 613 | *response = *trans->GetResponseInfo(); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 614 | *push_response = *trans2->GetResponseInfo(); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 615 | |
| 616 | VerifyStreamsClosed(helper); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 617 | } |
| 618 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 619 | static void DeleteSessionCallback(NormalSpdyTransactionHelper* helper, |
| 620 | int result) { |
| 621 | helper->ResetTrans(); |
| 622 | } |
| 623 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 624 | static void StartTransactionCallback(HttpNetworkSession* session, |
| 625 | GURL url, |
| 626 | int result) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 627 | scoped_ptr<HttpNetworkTransaction> trans( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 628 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 629 | TestCompletionCallback callback; |
| 630 | HttpRequestInfo request; |
| 631 | request.method = "GET"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 632 | request.url = url; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 633 | request.load_flags = 0; |
| 634 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 635 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 636 | callback.WaitForResult(); |
| 637 | } |
| 638 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 639 | ChunkedUploadDataStream* upload_chunked_data_stream() const { |
| 640 | return upload_chunked_data_stream_.get(); |
| 641 | } |
| 642 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 643 | const char* GetDefaultUrl() { |
| 644 | switch (GetParam().ssl_type) { |
| 645 | case HTTP_SPDY_VIA_ALT_SVC: |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 646 | return "http://www.example.org"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 647 | case HTTPS_SPDY_VIA_NPN: |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 648 | return "https://www.example.org"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 649 | default: |
| 650 | NOTREACHED(); |
| 651 | return ""; |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | std::string GetDefaultUrlWithPath(const char* path) { |
| 656 | return std::string(GetDefaultUrl()) + path; |
| 657 | } |
| 658 | |
[email protected] | 9ec54f8 | 2013-05-10 02:53:05 | [diff] [blame] | 659 | SpdyTestUtil spdy_util_; |
| 660 | |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 661 | private: |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 662 | scoped_ptr<ChunkedUploadDataStream> upload_chunked_data_stream_; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 663 | scoped_ptr<UploadDataStream> upload_data_stream_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 664 | bool get_request_initialized_; |
| 665 | bool post_request_initialized_; |
| 666 | bool chunked_post_request_initialized_; |
| 667 | HttpRequestInfo get_request_; |
| 668 | HttpRequestInfo post_request_; |
| 669 | HttpRequestInfo chunked_post_request_; |
| 670 | HttpRequestInfo get_push_request_; |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 671 | base::ScopedTempDir temp_dir_; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 672 | }; |
| 673 | |
| 674 | //----------------------------------------------------------------------------- |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 675 | // All tests are run with three different connection types: SPDY after NPN |
| 676 | // negotiation, SPDY without SSL, and SPDY with SSL. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 677 | // |
| 678 | // TODO(akalin): Use ::testing::Combine() when we are able to use |
| 679 | // <tr1/tuple>. |
| 680 | INSTANTIATE_TEST_CASE_P( |
| 681 | Spdy, |
| 682 | SpdyNetworkTransactionTest, |
| 683 | ::testing::Values( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 684 | SpdyNetworkTransactionTestParams(kProtoSPDY31, |
| 685 | HTTPS_SPDY_VIA_NPN, |
| 686 | false), |
| 687 | SpdyNetworkTransactionTestParams(kProtoSPDY31, |
| 688 | HTTP_SPDY_VIA_ALT_SVC, |
| 689 | false), |
| 690 | SpdyNetworkTransactionTestParams(kProtoHTTP2, |
| 691 | HTTPS_SPDY_VIA_NPN, |
| 692 | false), |
| 693 | SpdyNetworkTransactionTestParams(kProtoHTTP2, HTTPS_SPDY_VIA_NPN, true), |
| 694 | SpdyNetworkTransactionTestParams(kProtoHTTP2, |
| 695 | HTTP_SPDY_VIA_ALT_SVC, |
| 696 | false), |
| 697 | SpdyNetworkTransactionTestParams(kProtoHTTP2, |
| 698 | HTTP_SPDY_VIA_ALT_SVC, |
| 699 | true))); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 700 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 701 | // Verify HttpNetworkTransaction constructor. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 702 | TEST_P(SpdyNetworkTransactionTest, Constructor) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 703 | scoped_ptr<SpdySessionDependencies> session_deps( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 704 | CreateSpdySessionDependencies(GetParam())); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 705 | scoped_ptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 706 | SpdySessionDependencies::SpdyCreateSession(session_deps.get())); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 707 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 708 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 709 | } |
| 710 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 711 | TEST_P(SpdyNetworkTransactionTest, Get) { |
[email protected] | 75f30cc2 | 2010-06-28 21:41:38 | [diff] [blame] | 712 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 713 | scoped_ptr<SpdyFrame> req( |
| 714 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 715 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 716 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 717 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 718 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 719 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 720 | CreateMockRead(*resp, 1), |
| 721 | CreateMockRead(*body, 2), |
| 722 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 723 | }; |
| 724 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 725 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 726 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 727 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 728 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 729 | TransactionHelperResult out = helper.output(); |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 730 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 731 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 732 | EXPECT_EQ("hello!", out.response_data); |
| 733 | } |
| 734 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 735 | TEST_P(SpdyNetworkTransactionTest, GetAtEachPriority) { |
[email protected] | 3d08dd38 | 2013-10-19 00:13:11 | [diff] [blame] | 736 | for (RequestPriority p = MINIMUM_PRIORITY; p <= MAXIMUM_PRIORITY; |
[email protected] | 31ae7ab | 2012-04-24 21:09:05 | [diff] [blame] | 737 | p = RequestPriority(p + 1)) { |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 738 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 739 | scoped_ptr<SpdyFrame> req( |
| 740 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, p, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 741 | spdy_util_.UpdateWithStreamDestruction(1); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 742 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 743 | |
[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 744 | SpdyPriority spdy_prio = 0; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 745 | EXPECT_TRUE(GetSpdyPriority(spdy_util_.spdy_version(), *req, &spdy_prio)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 746 | // this repeats the RequestPriority-->SpdyPriority mapping from |
| 747 | // SpdyFramer::ConvertRequestPriorityToSpdyPriority to make |
| 748 | // sure it's being done right. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 749 | if (spdy_util_.spdy_version() < SPDY3) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 750 | switch (p) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 751 | case HIGHEST: |
| 752 | EXPECT_EQ(0, spdy_prio); |
| 753 | break; |
| 754 | case MEDIUM: |
| 755 | EXPECT_EQ(1, spdy_prio); |
| 756 | break; |
| 757 | case LOW: |
| 758 | case LOWEST: |
| 759 | EXPECT_EQ(2, spdy_prio); |
| 760 | break; |
| 761 | case IDLE: |
| 762 | EXPECT_EQ(3, spdy_prio); |
| 763 | break; |
| 764 | default: |
| 765 | FAIL(); |
| 766 | } |
| 767 | } else { |
bnc | e8aa270 | 2015-08-17 18:11:05 | [diff] [blame] | 768 | switch (p) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 769 | case HIGHEST: |
| 770 | EXPECT_EQ(0, spdy_prio); |
| 771 | break; |
| 772 | case MEDIUM: |
| 773 | EXPECT_EQ(1, spdy_prio); |
| 774 | break; |
| 775 | case LOW: |
| 776 | EXPECT_EQ(2, spdy_prio); |
| 777 | break; |
| 778 | case LOWEST: |
| 779 | EXPECT_EQ(3, spdy_prio); |
| 780 | break; |
| 781 | case IDLE: |
| 782 | EXPECT_EQ(4, spdy_prio); |
| 783 | break; |
| 784 | default: |
| 785 | FAIL(); |
| 786 | } |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 787 | } |
| 788 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 789 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 790 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 791 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 792 | CreateMockRead(*resp, 1), |
| 793 | CreateMockRead(*body, 2), |
| 794 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 795 | }; |
| 796 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 797 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 798 | arraysize(writes)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 799 | HttpRequestInfo http_req = CreateGetRequest(); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 800 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 801 | NormalSpdyTransactionHelper helper(http_req, p, BoundNetLog(), |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 802 | GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 803 | helper.RunToCompletion(&data); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 804 | TransactionHelperResult out = helper.output(); |
| 805 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 806 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 807 | EXPECT_EQ("hello!", out.response_data); |
| 808 | } |
| 809 | } |
| 810 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 811 | // Start three gets simultaniously; making sure that multiplexed |
| 812 | // streams work properly. |
| 813 | |
| 814 | // This can't use the TransactionHelper method, since it only |
| 815 | // handles a single transaction, and finishes them as soon |
| 816 | // as it launches them. |
| 817 | |
| 818 | // TODO(gavinp): create a working generalized TransactionHelper that |
| 819 | // can allow multiple streams in flight. |
| 820 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 821 | TEST_P(SpdyNetworkTransactionTest, ThreeGets) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 822 | scoped_ptr<SpdyFrame> req( |
| 823 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 824 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 825 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 826 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 827 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 828 | scoped_ptr<SpdyFrame> req2( |
| 829 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 830 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 831 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 832 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 833 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 834 | scoped_ptr<SpdyFrame> req3( |
| 835 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 836 | scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 837 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(5, false)); |
| 838 | scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 839 | |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 840 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 841 | CreateMockWrite(*req, 0), |
| 842 | CreateMockWrite(*req2, 3), |
| 843 | CreateMockWrite(*req3, 6), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 844 | }; |
| 845 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 846 | CreateMockRead(*resp, 1), |
| 847 | CreateMockRead(*body, 2), |
| 848 | CreateMockRead(*resp2, 4), |
| 849 | CreateMockRead(*body2, 5), |
| 850 | CreateMockRead(*resp3, 7), |
| 851 | CreateMockRead(*body3, 8), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 852 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 853 | CreateMockRead(*fbody, 9), |
| 854 | CreateMockRead(*fbody2, 10), |
| 855 | CreateMockRead(*fbody3, 11), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 856 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 857 | MockRead(ASYNC, 0, 12), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 858 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 859 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 860 | SequencedSocketData data_placeholder1(NULL, 0, NULL, 0); |
| 861 | SequencedSocketData data_placeholder2(NULL, 0, NULL, 0); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 862 | |
| 863 | BoundNetLog log; |
| 864 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 865 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 866 | BoundNetLog(), GetParam(), NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 867 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 868 | helper.AddData(&data); |
rch | aeb3f05 | 2015-04-14 16:02:49 | [diff] [blame] | 869 | // We require placeholder data because three get requests are sent out at |
| 870 | // the same time which results in three sockets being connected. The first |
| 871 | // on will negotiate SPDY and will be used for all requests. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 872 | helper.AddData(&data_placeholder1); |
| 873 | helper.AddData(&data_placeholder2); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 874 | scoped_ptr<HttpNetworkTransaction> trans1( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 875 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 876 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 877 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 878 | scoped_ptr<HttpNetworkTransaction> trans3( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 879 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 880 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 881 | TestCompletionCallback callback1; |
| 882 | TestCompletionCallback callback2; |
| 883 | TestCompletionCallback callback3; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 884 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 885 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 886 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 887 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 888 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 889 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 890 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 891 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 892 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 893 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 894 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 895 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 896 | out.rv = callback1.WaitForResult(); |
| 897 | ASSERT_EQ(OK, out.rv); |
| 898 | out.rv = callback3.WaitForResult(); |
| 899 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 900 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 901 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 902 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 903 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 904 | out.status_line = response1->headers->GetStatusLine(); |
| 905 | out.response_info = *response1; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 906 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 907 | trans2->GetResponseInfo(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 908 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 909 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 910 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 911 | EXPECT_EQ(OK, out.rv); |
| 912 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 913 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 914 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 915 | EXPECT_EQ("hello!hello!", out.response_data); |
| 916 | } |
| 917 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 918 | TEST_P(SpdyNetworkTransactionTest, TwoGetsLateBinding) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 919 | scoped_ptr<SpdyFrame> req( |
| 920 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 921 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 922 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 923 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 924 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 925 | scoped_ptr<SpdyFrame> req2( |
| 926 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 927 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 928 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 929 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 930 | |
| 931 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 932 | CreateMockWrite(*req, 0), CreateMockWrite(*req2, 3), |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 933 | }; |
| 934 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 935 | CreateMockRead(*resp, 1), |
| 936 | CreateMockRead(*body, 2), |
| 937 | CreateMockRead(*resp2, 4), |
| 938 | CreateMockRead(*body2, 5), |
| 939 | CreateMockRead(*fbody, 6), |
| 940 | CreateMockRead(*fbody2, 7), |
| 941 | MockRead(ASYNC, 0, 8), // EOF |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 942 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 943 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 944 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 945 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 946 | SequencedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 947 | data_placeholder.set_connect_data(never_finishing_connect); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 948 | |
| 949 | BoundNetLog log; |
| 950 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 951 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 952 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 953 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 954 | helper.AddData(&data); |
rch | aeb3f05 | 2015-04-14 16:02:49 | [diff] [blame] | 955 | // We require placeholder data because two requests are sent out at |
| 956 | // the same time which results in two sockets being connected. The first |
| 957 | // on will negotiate SPDY and will be used for all requests. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 958 | helper.AddData(&data_placeholder); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 959 | scoped_ptr<HttpNetworkTransaction> trans1( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 960 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 961 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 962 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 963 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 964 | TestCompletionCallback callback1; |
| 965 | TestCompletionCallback callback2; |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 966 | |
| 967 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 968 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 969 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 970 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 971 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 972 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 973 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
| 974 | |
| 975 | out.rv = callback1.WaitForResult(); |
| 976 | ASSERT_EQ(OK, out.rv); |
| 977 | out.rv = callback2.WaitForResult(); |
| 978 | ASSERT_EQ(OK, out.rv); |
| 979 | |
| 980 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 981 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 982 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 983 | out.status_line = response1->headers->GetStatusLine(); |
| 984 | out.response_info = *response1; |
| 985 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 986 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 987 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 988 | EXPECT_EQ("hello!hello!", out.response_data); |
| 989 | |
| 990 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 991 | EXPECT_TRUE(response2->headers.get() != NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 992 | EXPECT_TRUE(response2->was_fetched_via_spdy); |
| 993 | out.status_line = response2->headers->GetStatusLine(); |
| 994 | out.response_info = *response2; |
| 995 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 996 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 997 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 998 | EXPECT_EQ("hello!hello!", out.response_data); |
| 999 | |
| 1000 | helper.VerifyDataConsumed(); |
| 1001 | } |
| 1002 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1003 | TEST_P(SpdyNetworkTransactionTest, TwoGetsLateBindingFromPreconnect) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1004 | scoped_ptr<SpdyFrame> req( |
| 1005 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1006 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1007 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1008 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1009 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1010 | scoped_ptr<SpdyFrame> req2( |
| 1011 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1012 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1013 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 1014 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1015 | |
| 1016 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1017 | CreateMockWrite(*req, 0), CreateMockWrite(*req2, 3), |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1018 | }; |
| 1019 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1020 | CreateMockRead(*resp, 1), |
| 1021 | CreateMockRead(*body, 2), |
| 1022 | CreateMockRead(*resp2, 4), |
| 1023 | CreateMockRead(*body2, 5), |
| 1024 | CreateMockRead(*fbody, 6), |
| 1025 | CreateMockRead(*fbody2, 7), |
| 1026 | MockRead(ASYNC, 0, 8), // EOF |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1027 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1028 | SequencedSocketData preconnect_data(reads, arraysize(reads), writes, |
| 1029 | arraysize(writes)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1030 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 1031 | MockConnect never_finishing_connect(ASYNC, ERR_IO_PENDING); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1032 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1033 | SequencedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1034 | data_placeholder.set_connect_data(never_finishing_connect); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1035 | |
| 1036 | BoundNetLog log; |
| 1037 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1038 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1039 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1040 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1041 | helper.AddData(&preconnect_data); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1042 | // We require placeholder data because 3 connections are attempted (first is |
| 1043 | // the preconnect, 2nd and 3rd are the never finished connections. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1044 | helper.AddData(&data_placeholder); |
| 1045 | helper.AddData(&data_placeholder); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1046 | |
| 1047 | scoped_ptr<HttpNetworkTransaction> trans1( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1048 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1049 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1050 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1051 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1052 | TestCompletionCallback callback1; |
| 1053 | TestCompletionCallback callback2; |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1054 | |
| 1055 | HttpRequestInfo httpreq = CreateGetRequest(); |
| 1056 | |
| 1057 | // Preconnect the first. |
| 1058 | SSLConfig preconnect_ssl_config; |
| 1059 | helper.session()->ssl_config_service()->GetSSLConfig(&preconnect_ssl_config); |
| 1060 | HttpStreamFactory* http_stream_factory = |
| 1061 | helper.session()->http_stream_factory(); |
bnc | 1f29537 | 2015-10-21 23:24:22 | [diff] [blame] | 1062 | helper.session()->GetAlpnProtos(&preconnect_ssl_config.alpn_protos); |
| 1063 | helper.session()->GetNpnProtos(&preconnect_ssl_config.npn_protos); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1064 | |
mmenke | d1205bd397 | 2015-07-15 22:26:35 | [diff] [blame] | 1065 | http_stream_factory->PreconnectStreams(1, httpreq, preconnect_ssl_config, |
| 1066 | preconnect_ssl_config); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1067 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1068 | out.rv = trans1->Start(&httpreq, callback1.callback(), log); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1069 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1070 | out.rv = trans2->Start(&httpreq, callback2.callback(), log); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1071 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
| 1072 | |
| 1073 | out.rv = callback1.WaitForResult(); |
| 1074 | ASSERT_EQ(OK, out.rv); |
| 1075 | out.rv = callback2.WaitForResult(); |
| 1076 | ASSERT_EQ(OK, out.rv); |
| 1077 | |
| 1078 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1079 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1080 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1081 | out.status_line = response1->headers->GetStatusLine(); |
| 1082 | out.response_info = *response1; |
| 1083 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 1084 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1085 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1086 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1087 | |
| 1088 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1089 | EXPECT_TRUE(response2->headers.get() != NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1090 | EXPECT_TRUE(response2->was_fetched_via_spdy); |
| 1091 | out.status_line = response2->headers->GetStatusLine(); |
| 1092 | out.response_info = *response2; |
| 1093 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 1094 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1095 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1096 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1097 | |
| 1098 | helper.VerifyDataConsumed(); |
| 1099 | } |
| 1100 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1101 | // Similar to ThreeGets above, however this test adds a SETTINGS |
| 1102 | // frame. The SETTINGS frame is read during the IO loop waiting on |
| 1103 | // the first transaction completion, and sets a maximum concurrent |
| 1104 | // stream limit of 1. This means that our IO loop exists after the |
| 1105 | // second transaction completes, so we can assert on read_index(). |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1106 | TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrent) { |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1107 | // Construct the request. |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1108 | // Each request fully completes before the next starts. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1109 | scoped_ptr<SpdyFrame> req( |
| 1110 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1111 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1112 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1113 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1114 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1115 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1116 | scoped_ptr<SpdyFrame> req2( |
| 1117 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1118 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1119 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 1120 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1121 | spdy_util_.UpdateWithStreamDestruction(3); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1122 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1123 | scoped_ptr<SpdyFrame> req3( |
| 1124 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1125 | scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 1126 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(5, false)); |
| 1127 | scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1128 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1129 | SettingsMap settings; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 1130 | const uint32_t max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1131 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1132 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1133 | scoped_ptr<SpdyFrame> settings_frame( |
| 1134 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1135 | scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1136 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 1137 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1138 | CreateMockWrite(*req, 0), |
| 1139 | CreateMockWrite(*settings_ack, 5), |
| 1140 | CreateMockWrite(*req2, 6), |
| 1141 | CreateMockWrite(*req3, 10), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1142 | }; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 1143 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1144 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1145 | CreateMockRead(*settings_frame, 1), |
| 1146 | CreateMockRead(*resp, 2), |
| 1147 | CreateMockRead(*body, 3), |
| 1148 | CreateMockRead(*fbody, 4), |
| 1149 | CreateMockRead(*resp2, 7), |
| 1150 | CreateMockRead(*body2, 8), |
| 1151 | CreateMockRead(*fbody2, 9), |
| 1152 | CreateMockRead(*resp3, 11), |
| 1153 | CreateMockRead(*body3, 12), |
| 1154 | CreateMockRead(*fbody3, 13), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1155 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1156 | MockRead(ASYNC, 0, 14), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1157 | }; |
| 1158 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1159 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1160 | |
| 1161 | BoundNetLog log; |
| 1162 | TransactionHelperResult out; |
| 1163 | { |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1164 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1165 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 1166 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1167 | helper.AddData(&data); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1168 | scoped_ptr<HttpNetworkTransaction> trans1( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1169 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1170 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1171 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1172 | scoped_ptr<HttpNetworkTransaction> trans3( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1173 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1174 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1175 | TestCompletionCallback callback1; |
| 1176 | TestCompletionCallback callback2; |
| 1177 | TestCompletionCallback callback3; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1178 | |
| 1179 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1180 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1181 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
| 1182 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1183 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1184 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1185 | // Run transaction 1 through quickly to force a read of our SETTINGS |
| 1186 | // frame. |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1187 | out.rv = callback1.WaitForResult(); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1188 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1189 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1190 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1191 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1192 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1193 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
| 1194 | out.rv = callback2.WaitForResult(); |
| 1195 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1196 | |
| 1197 | out.rv = callback3.WaitForResult(); |
| 1198 | ASSERT_EQ(OK, out.rv); |
| 1199 | |
| 1200 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1201 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1202 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1203 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1204 | out.status_line = response1->headers->GetStatusLine(); |
| 1205 | out.response_info = *response1; |
| 1206 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 1207 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1208 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1209 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1210 | |
| 1211 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 1212 | out.status_line = response2->headers->GetStatusLine(); |
| 1213 | out.response_info = *response2; |
| 1214 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 1215 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1216 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1217 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1218 | |
| 1219 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 1220 | out.status_line = response3->headers->GetStatusLine(); |
| 1221 | out.response_info = *response3; |
| 1222 | out.rv = ReadTransaction(trans3.get(), &out.response_data); |
| 1223 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1224 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1225 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1226 | |
| 1227 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1228 | } |
| 1229 | EXPECT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | // Similar to ThreeGetsWithMaxConcurrent above, however this test adds |
| 1233 | // a fourth transaction. The third and fourth transactions have |
| 1234 | // different data ("hello!" vs "hello!hello!") and because of the |
| 1235 | // user specified priority, we expect to see them inverted in |
| 1236 | // the response from the server. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1237 | TEST_P(SpdyNetworkTransactionTest, FourGetsWithMaxConcurrentPriority) { |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1238 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1239 | scoped_ptr<SpdyFrame> req( |
| 1240 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1241 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1242 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1243 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1244 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1245 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1246 | scoped_ptr<SpdyFrame> req2( |
| 1247 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1248 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1249 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 1250 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1251 | spdy_util_.UpdateWithStreamDestruction(3); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1252 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1253 | scoped_ptr<SpdyFrame> req4( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1254 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, HIGHEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1255 | scoped_ptr<SpdyFrame> resp4(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 1256 | scoped_ptr<SpdyFrame> fbody4(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1257 | spdy_util_.UpdateWithStreamDestruction(5); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1258 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1259 | scoped_ptr<SpdyFrame> req3( |
| 1260 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 7, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1261 | scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 7)); |
| 1262 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(7, false)); |
| 1263 | scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(7, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1264 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1265 | SettingsMap settings; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 1266 | const uint32_t max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1267 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1268 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1269 | scoped_ptr<SpdyFrame> settings_frame( |
| 1270 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1271 | scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1272 | MockWrite writes[] = { |
| 1273 | CreateMockWrite(*req, 0), |
| 1274 | CreateMockWrite(*settings_ack, 5), |
| 1275 | // By making these synchronous, it guarantees that they are not *started* |
| 1276 | // before their sequence number, which in turn verifies that only a single |
| 1277 | // request is in-flight at a time. |
| 1278 | CreateMockWrite(*req2, 6, SYNCHRONOUS), |
| 1279 | CreateMockWrite(*req4, 10, SYNCHRONOUS), |
| 1280 | CreateMockWrite(*req3, 13, SYNCHRONOUS), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1281 | }; |
| 1282 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1283 | CreateMockRead(*settings_frame, 1), |
| 1284 | CreateMockRead(*resp, 2), |
| 1285 | CreateMockRead(*body, 3), |
| 1286 | CreateMockRead(*fbody, 4), |
| 1287 | CreateMockRead(*resp2, 7), |
| 1288 | CreateMockRead(*body2, 8), |
| 1289 | CreateMockRead(*fbody2, 9), |
| 1290 | CreateMockRead(*resp4, 11), |
| 1291 | CreateMockRead(*fbody4, 12), |
| 1292 | CreateMockRead(*resp3, 14), |
| 1293 | CreateMockRead(*body3, 15), |
| 1294 | CreateMockRead(*fbody3, 16), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1295 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1296 | MockRead(ASYNC, 0, 17), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1297 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1298 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1299 | BoundNetLog log; |
| 1300 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1301 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 1302 | BoundNetLog(), GetParam(), NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1303 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1304 | helper.AddData(&data); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1305 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1306 | scoped_ptr<HttpNetworkTransaction> trans1( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1307 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1308 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1309 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1310 | scoped_ptr<HttpNetworkTransaction> trans3( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1311 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1312 | scoped_ptr<HttpNetworkTransaction> trans4( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1313 | new HttpNetworkTransaction(HIGHEST, helper.session())); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1314 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1315 | TestCompletionCallback callback1; |
| 1316 | TestCompletionCallback callback2; |
| 1317 | TestCompletionCallback callback3; |
| 1318 | TestCompletionCallback callback4; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1319 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1320 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1321 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1322 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
| 1323 | HttpRequestInfo httpreq4 = CreateGetRequest(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1324 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1325 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1326 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1327 | // Run transaction 1 through quickly to force a read of our SETTINGS frame. |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1328 | out.rv = callback1.WaitForResult(); |
| 1329 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1330 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1331 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1332 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1333 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1334 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1335 | out.rv = trans4->Start(&httpreq4, callback4.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1336 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1337 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1338 | out.rv = callback2.WaitForResult(); |
| 1339 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1340 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1341 | out.rv = callback3.WaitForResult(); |
| 1342 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1343 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1344 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1345 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1346 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1347 | out.status_line = response1->headers->GetStatusLine(); |
| 1348 | out.response_info = *response1; |
| 1349 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 1350 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1351 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1352 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1353 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1354 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 1355 | out.status_line = response2->headers->GetStatusLine(); |
| 1356 | out.response_info = *response2; |
| 1357 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 1358 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1359 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1360 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1361 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1362 | // notice: response3 gets two hellos, response4 gets one |
| 1363 | // hello, so we know dequeuing priority was respected. |
| 1364 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 1365 | out.status_line = response3->headers->GetStatusLine(); |
| 1366 | out.response_info = *response3; |
| 1367 | out.rv = ReadTransaction(trans3.get(), &out.response_data); |
| 1368 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1369 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1370 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1371 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1372 | out.rv = callback4.WaitForResult(); |
| 1373 | EXPECT_EQ(OK, out.rv); |
| 1374 | const HttpResponseInfo* response4 = trans4->GetResponseInfo(); |
| 1375 | out.status_line = response4->headers->GetStatusLine(); |
| 1376 | out.response_info = *response4; |
| 1377 | out.rv = ReadTransaction(trans4.get(), &out.response_data); |
| 1378 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1379 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1380 | EXPECT_EQ("hello!", out.response_data); |
| 1381 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1382 | EXPECT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1383 | } |
| 1384 | |
| 1385 | // Similar to ThreeGetsMaxConcurrrent above, however, this test |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1386 | // deletes a session in the middle of the transaction to ensure |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1387 | // that we properly remove pendingcreatestream objects from |
| 1388 | // the spdy_session |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1389 | TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentDelete) { |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1390 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1391 | scoped_ptr<SpdyFrame> req( |
| 1392 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1393 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1394 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1395 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1396 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1397 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1398 | scoped_ptr<SpdyFrame> req2( |
| 1399 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1400 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1401 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 1402 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1403 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1404 | SettingsMap settings; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 1405 | const uint32_t max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1406 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1407 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1408 | scoped_ptr<SpdyFrame> settings_frame( |
| 1409 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1410 | scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1411 | |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1412 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1413 | CreateMockWrite(*req, 0), |
| 1414 | CreateMockWrite(*settings_ack, 5), |
| 1415 | CreateMockWrite(*req2, 6), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1416 | }; |
| 1417 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1418 | CreateMockRead(*settings_frame, 1), |
| 1419 | CreateMockRead(*resp, 2), |
| 1420 | CreateMockRead(*body, 3), |
| 1421 | CreateMockRead(*fbody, 4), |
| 1422 | CreateMockRead(*resp2, 7), |
| 1423 | CreateMockRead(*body2, 8), |
| 1424 | CreateMockRead(*fbody2, 9), |
| 1425 | MockRead(ASYNC, 0, 10), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1426 | }; |
| 1427 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1428 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1429 | |
| 1430 | BoundNetLog log; |
| 1431 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1432 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 1433 | BoundNetLog(), GetParam(), NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1434 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1435 | helper.AddData(&data); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1436 | scoped_ptr<HttpNetworkTransaction> trans1( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1437 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1438 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1439 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1440 | scoped_ptr<HttpNetworkTransaction> trans3( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1441 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1442 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1443 | TestCompletionCallback callback1; |
| 1444 | TestCompletionCallback callback2; |
| 1445 | TestCompletionCallback callback3; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1446 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1447 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1448 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1449 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1450 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1451 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1452 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1453 | // Run transaction 1 through quickly to force a read of our SETTINGS frame. |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1454 | out.rv = callback1.WaitForResult(); |
| 1455 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1456 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1457 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1458 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1459 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1460 | delete trans3.release(); |
| 1461 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
| 1462 | out.rv = callback2.WaitForResult(); |
| 1463 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1464 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1465 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 1466 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1467 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1468 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1469 | out.status_line = response1->headers->GetStatusLine(); |
| 1470 | out.response_info = *response1; |
| 1471 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 1472 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1473 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1474 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1475 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1476 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 1477 | ASSERT_TRUE(response2 != NULL); |
| 1478 | out.status_line = response2->headers->GetStatusLine(); |
| 1479 | out.response_info = *response2; |
| 1480 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 1481 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1482 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1483 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1484 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1485 | EXPECT_EQ(OK, out.rv); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1486 | } |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1487 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1488 | namespace { |
| 1489 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1490 | // The KillerCallback will delete the transaction on error as part of the |
| 1491 | // callback. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1492 | class KillerCallback : public TestCompletionCallbackBase { |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1493 | public: |
| 1494 | explicit KillerCallback(HttpNetworkTransaction* transaction) |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1495 | : transaction_(transaction), |
[email protected] | aa249b5 | 2013-04-30 01:04:32 | [diff] [blame] | 1496 | callback_(base::Bind(&KillerCallback::OnComplete, |
| 1497 | base::Unretained(this))) { |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1498 | } |
| 1499 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 1500 | ~KillerCallback() override {} |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1501 | |
| 1502 | const CompletionCallback& callback() const { return callback_; } |
| 1503 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1504 | private: |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1505 | void OnComplete(int result) { |
| 1506 | if (result < 0) |
| 1507 | delete transaction_; |
| 1508 | |
| 1509 | SetResult(result); |
| 1510 | } |
| 1511 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1512 | HttpNetworkTransaction* transaction_; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1513 | CompletionCallback callback_; |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1514 | }; |
| 1515 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1516 | } // namespace |
| 1517 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1518 | // Similar to ThreeGetsMaxConcurrrentDelete above, however, this test |
| 1519 | // closes the socket while we have a pending transaction waiting for |
| 1520 | // a pending stream creation. http://crbug.com/52901 |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1521 | TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentSocketClose) { |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1522 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1523 | scoped_ptr<SpdyFrame> req( |
| 1524 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1525 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1526 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1527 | scoped_ptr<SpdyFrame> fin_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 1528 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1529 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1530 | scoped_ptr<SpdyFrame> req2( |
| 1531 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1532 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1533 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1534 | SettingsMap settings; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 1535 | const uint32_t max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1536 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1537 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1538 | scoped_ptr<SpdyFrame> settings_frame( |
| 1539 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1540 | scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1541 | |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1542 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1543 | CreateMockWrite(*req, 0), |
| 1544 | CreateMockWrite(*settings_ack, 5), |
| 1545 | CreateMockWrite(*req2, 6), |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1546 | }; |
| 1547 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1548 | CreateMockRead(*settings_frame, 1), |
| 1549 | CreateMockRead(*resp, 2), |
| 1550 | CreateMockRead(*body, 3), |
| 1551 | CreateMockRead(*fin_body, 4), |
| 1552 | CreateMockRead(*resp2, 7), |
| 1553 | MockRead(ASYNC, ERR_CONNECTION_RESET, 8), // Abort! |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1554 | }; |
| 1555 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1556 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 1557 | SequencedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1558 | |
| 1559 | BoundNetLog log; |
| 1560 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1561 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 1562 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1563 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1564 | helper.AddData(&data); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1565 | // We require placeholder data because three get requests are sent out, so |
| 1566 | // there needs to be three sets of SSL connection data. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1567 | helper.AddData(&data_placeholder); |
| 1568 | helper.AddData(&data_placeholder); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1569 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session()); |
| 1570 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session()); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1571 | HttpNetworkTransaction* trans3( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 1572 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1573 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1574 | TestCompletionCallback callback1; |
| 1575 | TestCompletionCallback callback2; |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1576 | KillerCallback callback3(trans3); |
| 1577 | |
| 1578 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1579 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1580 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
| 1581 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1582 | out.rv = trans1.Start(&httpreq1, callback1.callback(), log); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1583 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1584 | // Run transaction 1 through quickly to force a read of our SETTINGS frame. |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1585 | out.rv = callback1.WaitForResult(); |
| 1586 | ASSERT_EQ(OK, out.rv); |
| 1587 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1588 | out.rv = trans2.Start(&httpreq2, callback2.callback(), log); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1589 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1590 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1591 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
| 1592 | out.rv = callback3.WaitForResult(); |
| 1593 | ASSERT_EQ(ERR_ABORTED, out.rv); |
| 1594 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1595 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
| 1596 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1597 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1598 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1599 | out.status_line = response1->headers->GetStatusLine(); |
| 1600 | out.response_info = *response1; |
| 1601 | out.rv = ReadTransaction(&trans1, &out.response_data); |
| 1602 | EXPECT_EQ(OK, out.rv); |
| 1603 | |
| 1604 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 1605 | ASSERT_TRUE(response2 != NULL); |
| 1606 | out.status_line = response2->headers->GetStatusLine(); |
| 1607 | out.response_info = *response2; |
| 1608 | out.rv = ReadTransaction(&trans2, &out.response_data); |
| 1609 | EXPECT_EQ(ERR_CONNECTION_RESET, out.rv); |
| 1610 | |
| 1611 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1612 | } |
| 1613 | |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1614 | // Test that a simple PUT request works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1615 | TEST_P(SpdyNetworkTransactionTest, Put) { |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1616 | // Setup the request |
| 1617 | HttpRequestInfo request; |
| 1618 | request.method = "PUT"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1619 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1620 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1621 | scoped_ptr<SpdyHeaderBlock> put_headers( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1622 | spdy_util_.ConstructPutHeaderBlock(GetDefaultUrl(), 0)); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1623 | scoped_ptr<SpdyFrame> req( |
| 1624 | spdy_util_.ConstructSpdySyn(1, *put_headers, LOWEST, false, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1625 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1626 | CreateMockWrite(*req, 0), |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1627 | }; |
| 1628 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1629 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1630 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1631 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1632 | CreateMockRead(*resp, 1), |
| 1633 | CreateMockRead(*body, 2), |
| 1634 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1635 | }; |
| 1636 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1637 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1638 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1639 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1640 | helper.RunToCompletion(&data); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1641 | TransactionHelperResult out = helper.output(); |
| 1642 | |
| 1643 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1644 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | // Test that a simple HEAD request works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1648 | TEST_P(SpdyNetworkTransactionTest, Head) { |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1649 | // Setup the request |
| 1650 | HttpRequestInfo request; |
| 1651 | request.method = "HEAD"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1652 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1653 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1654 | scoped_ptr<SpdyHeaderBlock> head_headers( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1655 | spdy_util_.ConstructHeadHeaderBlock(GetDefaultUrl(), 0)); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1656 | scoped_ptr<SpdyFrame> req( |
| 1657 | spdy_util_.ConstructSpdySyn(1, *head_headers, LOWEST, false, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1658 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1659 | CreateMockWrite(*req, 0), |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1660 | }; |
| 1661 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1662 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1663 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1664 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1665 | CreateMockRead(*resp, 1), |
| 1666 | CreateMockRead(*body, 2), |
| 1667 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1668 | }; |
| 1669 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1670 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1671 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1672 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1673 | helper.RunToCompletion(&data); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1674 | TransactionHelperResult out = helper.output(); |
| 1675 | |
| 1676 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1677 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1678 | } |
| 1679 | |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 1680 | // Test that a simple POST works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1681 | TEST_P(SpdyNetworkTransactionTest, Post) { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1682 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 1683 | GetDefaultUrl(), 1, kUploadDataSize, LOWEST, NULL, 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1684 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1685 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1686 | CreateMockWrite(*req, 0), CreateMockWrite(*body, 1), // POST upload frame |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1687 | }; |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 1688 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1689 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1690 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1691 | CreateMockRead(*resp, 2), |
| 1692 | CreateMockRead(*body, 3), |
| 1693 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 1694 | }; |
| 1695 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1696 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1697 | NormalSpdyTransactionHelper helper(CreatePostRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1698 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1699 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1700 | TransactionHelperResult out = helper.output(); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 1701 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1702 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 1703 | EXPECT_EQ("hello!", out.response_data); |
| 1704 | } |
| 1705 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1706 | // Test that a POST with a file works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1707 | TEST_P(SpdyNetworkTransactionTest, FilePost) { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1708 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 1709 | GetDefaultUrl(), 1, kUploadDataSize, LOWEST, NULL, 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1710 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1711 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1712 | CreateMockWrite(*req, 0), CreateMockWrite(*body, 1), // POST upload frame |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1713 | }; |
| 1714 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1715 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1716 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1717 | CreateMockRead(*resp, 2), |
| 1718 | CreateMockRead(*body, 3), |
| 1719 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1720 | }; |
| 1721 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1722 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1723 | NormalSpdyTransactionHelper helper(CreateFilePostRequest(), DEFAULT_PRIORITY, |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1724 | BoundNetLog(), GetParam(), NULL); |
| 1725 | helper.RunToCompletion(&data); |
| 1726 | TransactionHelperResult out = helper.output(); |
| 1727 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1728 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1729 | EXPECT_EQ("hello!", out.response_data); |
| 1730 | } |
| 1731 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1732 | // Test that a POST with a unreadable file fails. |
| 1733 | TEST_P(SpdyNetworkTransactionTest, UnreadableFilePost) { |
| 1734 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1735 | MockWrite(ASYNC, 0, 0) // EOF |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1736 | }; |
| 1737 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1738 | MockRead(ASYNC, 0, 1) // EOF |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1739 | }; |
| 1740 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1741 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1742 | NormalSpdyTransactionHelper helper(CreateUnreadableFilePostRequest(), |
| 1743 | DEFAULT_PRIORITY, |
| 1744 | BoundNetLog(), GetParam(), NULL); |
| 1745 | helper.RunPreTestSetup(); |
| 1746 | helper.AddData(&data); |
| 1747 | helper.RunDefaultTest(); |
| 1748 | |
| 1749 | base::RunLoop().RunUntilIdle(); |
| 1750 | helper.VerifyDataNotConsumed(); |
| 1751 | EXPECT_EQ(ERR_ACCESS_DENIED, helper.output().rv); |
| 1752 | } |
| 1753 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1754 | // Test that a complex POST works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1755 | TEST_P(SpdyNetworkTransactionTest, ComplexPost) { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1756 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 1757 | GetDefaultUrl(), 1, kUploadDataSize, LOWEST, NULL, 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1758 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1759 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1760 | CreateMockWrite(*req, 0), CreateMockWrite(*body, 1), // POST upload frame |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1761 | }; |
| 1762 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1763 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1764 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1765 | CreateMockRead(*resp, 2), |
| 1766 | CreateMockRead(*body, 3), |
| 1767 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1768 | }; |
| 1769 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1770 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1771 | NormalSpdyTransactionHelper helper(CreateComplexPostRequest(), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1772 | DEFAULT_PRIORITY, |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1773 | BoundNetLog(), GetParam(), NULL); |
| 1774 | helper.RunToCompletion(&data); |
| 1775 | TransactionHelperResult out = helper.output(); |
| 1776 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1777 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1778 | EXPECT_EQ("hello!", out.response_data); |
| 1779 | } |
| 1780 | |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1781 | // Test that a chunked POST works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1782 | TEST_P(SpdyNetworkTransactionTest, ChunkedPost) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1783 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1784 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1785 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1786 | CreateMockWrite(*req, 0), CreateMockWrite(*body, 1), |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1787 | }; |
| 1788 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1789 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1790 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1791 | CreateMockRead(*resp, 2), |
| 1792 | CreateMockRead(*body, 3), |
| 1793 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1794 | }; |
| 1795 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1796 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1797 | NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1798 | DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1799 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1800 | |
| 1801 | // These chunks get merged into a single frame when being sent. |
| 1802 | const int kFirstChunkSize = kUploadDataSize/2; |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1803 | upload_chunked_data_stream()->AppendData(kUploadData, kFirstChunkSize, false); |
| 1804 | upload_chunked_data_stream()->AppendData( |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1805 | kUploadData + kFirstChunkSize, kUploadDataSize - kFirstChunkSize, true); |
| 1806 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1807 | helper.RunToCompletion(&data); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1808 | TransactionHelperResult out = helper.output(); |
| 1809 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1810 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1811 | EXPECT_EQ(kUploadData, out.response_data); |
| 1812 | } |
| 1813 | |
| 1814 | // Test that a chunked POST works with chunks appended after transaction starts. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1815 | TEST_P(SpdyNetworkTransactionTest, DelayedChunkedPost) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1816 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1817 | scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1818 | scoped_ptr<SpdyFrame> chunk2(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1819 | scoped_ptr<SpdyFrame> chunk3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1820 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1821 | CreateMockWrite(*req, 0), |
| 1822 | CreateMockWrite(*chunk1, 1), |
| 1823 | CreateMockWrite(*chunk2, 2), |
| 1824 | CreateMockWrite(*chunk3, 3), |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1825 | }; |
| 1826 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1827 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1828 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1829 | CreateMockRead(*resp, 4), |
| 1830 | CreateMockRead(*chunk1, 5), |
| 1831 | CreateMockRead(*chunk2, 6), |
| 1832 | CreateMockRead(*chunk3, 7), |
| 1833 | MockRead(ASYNC, 0, 8) // EOF |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1834 | }; |
| 1835 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1836 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1837 | NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1838 | DEFAULT_PRIORITY, |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1839 | BoundNetLog(), GetParam(), NULL); |
| 1840 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1841 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, false); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1842 | |
| 1843 | helper.RunPreTestSetup(); |
| 1844 | helper.AddData(&data); |
| 1845 | ASSERT_TRUE(helper.StartDefaultTest()); |
| 1846 | |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 1847 | base::RunLoop().RunUntilIdle(); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1848 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, false); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 1849 | base::RunLoop().RunUntilIdle(); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1850 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, true); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1851 | |
| 1852 | helper.FinishDefaultTest(); |
| 1853 | helper.VerifyDataConsumed(); |
| 1854 | |
| 1855 | std::string expected_response; |
| 1856 | expected_response += kUploadData; |
| 1857 | expected_response += kUploadData; |
| 1858 | expected_response += kUploadData; |
| 1859 | |
| 1860 | TransactionHelperResult out = helper.output(); |
| 1861 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1862 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1863 | EXPECT_EQ(expected_response, out.response_data); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1864 | } |
| 1865 | |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1866 | // Test that a POST without any post data works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1867 | TEST_P(SpdyNetworkTransactionTest, NullPost) { |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1868 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1869 | // Setup the request |
| 1870 | HttpRequestInfo request; |
| 1871 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1872 | request.url = GURL(GetDefaultUrl()); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1873 | // Create an empty UploadData. |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1874 | request.upload_data_stream = NULL; |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1875 | |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1876 | // When request.upload_data_stream is NULL for post, content-length is |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1877 | // expected to be 0. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1878 | scoped_ptr<SpdyHeaderBlock> req_block( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1879 | spdy_util_.ConstructPostHeaderBlock(GetDefaultUrl(), 0)); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1880 | scoped_ptr<SpdyFrame> req( |
| 1881 | spdy_util_.ConstructSpdySyn(1, *req_block, LOWEST, false, true)); |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1882 | |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1883 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1884 | CreateMockWrite(*req, 0), |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1885 | }; |
| 1886 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1887 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 1888 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1889 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1890 | CreateMockRead(*resp, 1), |
| 1891 | CreateMockRead(*body, 2), |
| 1892 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1893 | }; |
| 1894 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1895 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1896 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1897 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1898 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1899 | helper.RunToCompletion(&data); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1900 | TransactionHelperResult out = helper.output(); |
| 1901 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1902 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1903 | EXPECT_EQ("hello!", out.response_data); |
| 1904 | } |
| 1905 | |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1906 | // Test that a simple POST works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1907 | TEST_P(SpdyNetworkTransactionTest, EmptyPost) { |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1908 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1909 | // Create an empty UploadDataStream. |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1910 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
| 1911 | ElementsUploadDataStream stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1912 | |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1913 | // Setup the request |
| 1914 | HttpRequestInfo request; |
| 1915 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1916 | request.url = GURL(GetDefaultUrl()); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1917 | request.upload_data_stream = &stream; |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1918 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 1919 | const uint64_t kContentLength = 0; |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1920 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1921 | scoped_ptr<SpdyHeaderBlock> req_block( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1922 | spdy_util_.ConstructPostHeaderBlock(GetDefaultUrl(), kContentLength)); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1923 | scoped_ptr<SpdyFrame> req( |
| 1924 | spdy_util_.ConstructSpdySyn(1, *req_block, LOWEST, false, true)); |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1925 | |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1926 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1927 | CreateMockWrite(*req, 0), |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1928 | }; |
| 1929 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1930 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 1931 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1932 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1933 | CreateMockRead(*resp, 1), |
| 1934 | CreateMockRead(*body, 2), |
| 1935 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1936 | }; |
| 1937 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 1938 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 1939 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1940 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 1941 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1942 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1943 | TransactionHelperResult out = helper.output(); |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1944 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1945 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1946 | EXPECT_EQ("hello!", out.response_data); |
| 1947 | } |
| 1948 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1949 | // While we're doing a post, the server sends the reply before upload completes. |
| 1950 | TEST_P(SpdyNetworkTransactionTest, ResponseBeforePostCompletes) { |
| 1951 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1952 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 1953 | MockWrite writes[] = { |
| 1954 | CreateMockWrite(*req, 0), |
| 1955 | CreateMockWrite(*body, 3), |
| 1956 | }; |
| 1957 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | a5566f970 | 2010-05-05 22:25:43 | [diff] [blame] | 1958 | MockRead reads[] = { |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1959 | CreateMockRead(*resp, 1), |
| 1960 | CreateMockRead(*body, 2), |
[email protected] | 099bc7e | 2013-07-18 04:19:16 | [diff] [blame] | 1961 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | a5566f970 | 2010-05-05 22:25:43 | [diff] [blame] | 1962 | }; |
| 1963 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1964 | // Write the request headers, and read the complete response |
| 1965 | // while still waiting for chunked request data. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1966 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1967 | NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
| 1968 | DEFAULT_PRIORITY, |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 1969 | BoundNetLog(), GetParam(), NULL); |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 1970 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1971 | helper.AddData(&data); |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 1972 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1973 | ASSERT_TRUE(helper.StartDefaultTest()); |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 1974 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 1975 | helper.WaitForHeaders(); |
| 1976 | EXPECT_EQ(OK, helper.output().rv); |
| 1977 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1978 | // Process the request headers, SYN_REPLY, and response body. |
| 1979 | // The request body is still in flight. |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1980 | const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1981 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1982 | |
| 1983 | // Finish sending the request body. |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1984 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, true); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1985 | |
| 1986 | std::string response_body; |
| 1987 | EXPECT_EQ(OK, ReadTransaction(helper.trans(), &response_body)); |
| 1988 | EXPECT_EQ(kUploadData, response_body); |
| 1989 | helper.VerifyDataConsumed(); |
[email protected] | a5566f970 | 2010-05-05 22:25:43 | [diff] [blame] | 1990 | } |
| 1991 | |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 1992 | // The client upon cancellation tries to send a RST_STREAM frame. The mock |
| 1993 | // socket causes the TCP write to return zero. This test checks that the client |
| 1994 | // tries to queue up the RST_STREAM frame again. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1995 | TEST_P(SpdyNetworkTransactionTest, SocketWriteReturnsZero) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1996 | scoped_ptr<SpdyFrame> req( |
| 1997 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1998 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1999 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2000 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2001 | CreateMockWrite(*req.get(), 0, SYNCHRONOUS), |
| 2002 | MockWrite(SYNCHRONOUS, 0, 0, 2), |
| 2003 | CreateMockWrite(*rst.get(), 3, SYNCHRONOUS), |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2004 | }; |
| 2005 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2006 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2007 | MockRead reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2008 | CreateMockRead(*resp.get(), 1, ASYNC), |
| 2009 | MockRead(ASYNC, 0, 0, 4) // EOF |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2010 | }; |
| 2011 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 2012 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2013 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2014 | BoundNetLog(), GetParam(), NULL); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2015 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 2016 | helper.AddData(&data); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2017 | HttpNetworkTransaction* trans = helper.trans(); |
| 2018 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2019 | TestCompletionCallback callback; |
| 2020 | int rv = trans->Start( |
| 2021 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 2022 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2023 | |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2024 | helper.ResetTrans(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 2025 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2026 | |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2027 | helper.VerifyDataConsumed(); |
| 2028 | } |
| 2029 | |
[email protected] | 9330067 | 2009-10-24 13:22:51 | [diff] [blame] | 2030 | // 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] | 2031 | TEST_P(SpdyNetworkTransactionTest, ResponseWithoutSynReply) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2032 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 2033 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2034 | CreateMockRead(*body, 1), MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 9330067 | 2009-10-24 13:22:51 | [diff] [blame] | 2035 | }; |
| 2036 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2037 | scoped_ptr<SpdyFrame> req( |
| 2038 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2039 | scoped_ptr<SpdyFrame> rst( |
| 2040 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 2041 | MockWrite writes[] = { |
| 2042 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 2), |
| 2043 | }; |
| 2044 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2045 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2046 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2047 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2048 | TransactionHelperResult out = helper.output(); |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 2049 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | 9330067 | 2009-10-24 13:22:51 | [diff] [blame] | 2050 | } |
| 2051 | |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2052 | // Test that the transaction doesn't crash when we get two replies on the same |
| 2053 | // stream ID. See http://crbug.com/45639. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2054 | TEST_P(SpdyNetworkTransactionTest, ResponseWithTwoSynReplies) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2055 | scoped_ptr<SpdyFrame> req( |
| 2056 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 2057 | scoped_ptr<SpdyFrame> rst( |
[email protected] | 00b2947 | 2014-01-16 18:10:24 | [diff] [blame] | 2058 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 2059 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2060 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 4), |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 2061 | }; |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2062 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2063 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2064 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2065 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2066 | CreateMockRead(*resp, 1), |
| 2067 | CreateMockRead(*resp, 2), |
| 2068 | CreateMockRead(*body, 3), |
| 2069 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2070 | }; |
| 2071 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2072 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2073 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2074 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2075 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2076 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2077 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2078 | |
| 2079 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2080 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2081 | TestCompletionCallback callback; |
| 2082 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2083 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2084 | rv = callback.WaitForResult(); |
| 2085 | EXPECT_EQ(OK, rv); |
| 2086 | |
| 2087 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | a5c493b9 | 2010-08-06 23:04:29 | [diff] [blame] | 2088 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2089 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2090 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 2091 | std::string response_data; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2092 | rv = ReadTransaction(trans, &response_data); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2093 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, rv); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2094 | |
| 2095 | helper.VerifyDataConsumed(); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2096 | } |
| 2097 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2098 | TEST_P(SpdyNetworkTransactionTest, ResetReplyWithTransferEncoding) { |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2099 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2100 | scoped_ptr<SpdyFrame> req( |
| 2101 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 2102 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2103 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2104 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2105 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 2), |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2106 | }; |
| 2107 | |
| 2108 | const char* const headers[] = { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2109 | "transfer-encoding", "chunked" |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2110 | }; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2111 | scoped_ptr<SpdyFrame> resp( |
| 2112 | spdy_util_.ConstructSpdyGetSynReply(headers, 1, 1)); |
| 2113 | scoped_ptr<SpdyFrame> body( |
| 2114 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2115 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2116 | CreateMockRead(*resp, 1), |
| 2117 | CreateMockRead(*body, 3), |
| 2118 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2119 | }; |
| 2120 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2121 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2122 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2123 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2124 | helper.RunToCompletion(&data); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2125 | TransactionHelperResult out = helper.output(); |
| 2126 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 2127 | |
| 2128 | helper.session()->spdy_session_pool()->CloseAllSessions(); |
| 2129 | helper.VerifyDataConsumed(); |
| 2130 | } |
| 2131 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2132 | TEST_P(SpdyNetworkTransactionTest, ResetPushWithTransferEncoding) { |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2133 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2134 | scoped_ptr<SpdyFrame> req( |
| 2135 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 2136 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2137 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2138 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2139 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 4), |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2140 | }; |
| 2141 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2142 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2143 | const char* const headers[] = { |
| 2144 | "transfer-encoding", "chunked" |
| 2145 | }; |
| 2146 | scoped_ptr<SpdyFrame> push( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2147 | spdy_util_.ConstructSpdyPush(headers, arraysize(headers) / 2, 2, 1, |
| 2148 | GetDefaultUrlWithPath("/1").c_str())); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2149 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2150 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2151 | CreateMockRead(*resp, 1), |
| 2152 | CreateMockRead(*push, 2), |
| 2153 | CreateMockRead(*body, 3), |
| 2154 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2155 | }; |
| 2156 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2157 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2158 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2159 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2160 | helper.RunToCompletion(&data); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2161 | TransactionHelperResult out = helper.output(); |
| 2162 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2163 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2164 | EXPECT_EQ("hello!", out.response_data); |
| 2165 | |
| 2166 | helper.session()->spdy_session_pool()->CloseAllSessions(); |
| 2167 | helper.VerifyDataConsumed(); |
| 2168 | } |
| 2169 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2170 | TEST_P(SpdyNetworkTransactionTest, CancelledTransaction) { |
[email protected] | 75f30cc2 | 2010-06-28 21:41:38 | [diff] [blame] | 2171 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2172 | scoped_ptr<SpdyFrame> req( |
| 2173 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2174 | MockWrite writes[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2175 | CreateMockWrite(*req), |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2176 | }; |
| 2177 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2178 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2179 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2180 | CreateMockRead(*resp), |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2181 | // This following read isn't used by the test, except during the |
[email protected] | b4c62eb | 2012-11-14 18:36:51 | [diff] [blame] | 2182 | // RunUntilIdle() call at the end since the SpdySession survives the |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2183 | // HttpNetworkTransaction and still tries to continue Read()'ing. Any |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2184 | // MockRead will do here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2185 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2186 | }; |
| 2187 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2188 | StaticSocketDataProvider data(reads, arraysize(reads), |
| 2189 | writes, arraysize(writes)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2190 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2191 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2192 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2193 | helper.RunPreTestSetup(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2194 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2195 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2196 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2197 | TestCompletionCallback callback; |
| 2198 | int rv = trans->Start( |
| 2199 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2200 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2201 | helper.ResetTrans(); // Cancel the transaction. |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2202 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 2203 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2204 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2205 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2206 | helper.VerifyDataNotConsumed(); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2207 | } |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 2208 | |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2209 | // Verify that the client sends a Rst Frame upon cancelling the stream. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2210 | TEST_P(SpdyNetworkTransactionTest, CancelledTransactionSendRst) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2211 | scoped_ptr<SpdyFrame> req( |
| 2212 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2213 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2214 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2215 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2216 | CreateMockWrite(*req, 0, SYNCHRONOUS), |
| 2217 | CreateMockWrite(*rst, 2, SYNCHRONOUS), |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2218 | }; |
| 2219 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2220 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2221 | MockRead reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2222 | CreateMockRead(*resp, 1, ASYNC), |
| 2223 | MockRead(ASYNC, 0, 0, 3) // EOF |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2224 | }; |
| 2225 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 2226 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2227 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2228 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2229 | BoundNetLog(), |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2230 | GetParam(), NULL); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2231 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 2232 | helper.AddData(&data); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2233 | HttpNetworkTransaction* trans = helper.trans(); |
| 2234 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2235 | TestCompletionCallback callback; |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2236 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2237 | int rv = trans->Start( |
| 2238 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 2239 | EXPECT_EQ(OK, callback.GetResult(rv)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2240 | |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2241 | helper.ResetTrans(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 2242 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2243 | |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2244 | helper.VerifyDataConsumed(); |
| 2245 | } |
| 2246 | |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2247 | // Verify that the client can correctly deal with the user callback attempting |
| 2248 | // to start another transaction on a session that is closing down. See |
| 2249 | // http://crbug.com/47455 |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2250 | TEST_P(SpdyNetworkTransactionTest, StartTransactionOnReadCallback) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2251 | scoped_ptr<SpdyFrame> req( |
| 2252 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2253 | MockWrite writes[] = {CreateMockWrite(*req)}; |
| 2254 | MockWrite writes2[] = {CreateMockWrite(*req, 0)}; |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2255 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 2256 | // The indicated length of this frame is longer than its actual length. When |
| 2257 | // the session receives an empty frame after this one, it shuts down the |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2258 | // session, and calls the read callback with the incomplete data. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 2259 | const uint8_t kGetBodyFrame2[] = { |
| 2260 | 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, |
| 2261 | 0x07, 'h', 'e', 'l', 'l', 'o', '!', |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2262 | }; |
| 2263 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2264 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2265 | MockRead reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 2266 | CreateMockRead(*resp, 1), |
| 2267 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause |
| 2268 | MockRead(ASYNC, reinterpret_cast<const char*>(kGetBodyFrame2), |
| 2269 | arraysize(kGetBodyFrame2), 3), |
| 2270 | MockRead(ASYNC, ERR_IO_PENDING, 4), // Force a pause |
| 2271 | MockRead(ASYNC, 0, 0, 5), // EOF |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2272 | }; |
| 2273 | MockRead reads2[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2274 | CreateMockRead(*resp, 1), MockRead(ASYNC, 0, 0, 2), // EOF |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2275 | }; |
| 2276 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 2277 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2278 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 2279 | arraysize(writes2)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2280 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2281 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2282 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2283 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2284 | helper.AddData(&data); |
| 2285 | helper.AddData(&data2); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2286 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2287 | |
| 2288 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2289 | TestCompletionCallback callback; |
| 2290 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2291 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2292 | rv = callback.WaitForResult(); |
| 2293 | |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2294 | const int kSize = 3000; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 2295 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSize)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2296 | rv = trans->Read( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2297 | buf.get(), kSize, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2298 | base::Bind(&SpdyNetworkTransactionTest::StartTransactionCallback, |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2299 | helper.session(), GURL(GetDefaultUrl()))); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 2300 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2301 | // This forces an err_IO_pending, which sets the callback. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 2302 | data.Resume(); |
| 2303 | data.RunUntilPaused(); |
| 2304 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2305 | // This finishes the read. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 2306 | data.Resume(); |
| 2307 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2308 | helper.VerifyDataConsumed(); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2309 | } |
| 2310 | |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2311 | // Verify that the client can correctly deal with the user callback deleting the |
| 2312 | // transaction. Failures will usually be valgrind errors. See |
| 2313 | // http://crbug.com/46925 |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2314 | TEST_P(SpdyNetworkTransactionTest, DeleteSessionOnReadCallback) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2315 | scoped_ptr<SpdyFrame> req( |
| 2316 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 2317 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2318 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2319 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2320 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2321 | MockRead reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 2322 | CreateMockRead(*resp.get(), 1), |
| 2323 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause |
| 2324 | CreateMockRead(*body.get(), 3), |
| 2325 | MockRead(ASYNC, 0, 0, 4), // EOF |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2326 | }; |
| 2327 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 2328 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2329 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2330 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2331 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2332 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2333 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2334 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2335 | |
| 2336 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2337 | TestCompletionCallback callback; |
| 2338 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2339 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2340 | rv = callback.WaitForResult(); |
| 2341 | |
| 2342 | // Setup a user callback which will delete the session, and clear out the |
| 2343 | // memory holding the stream object. Note that the callback deletes trans. |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2344 | const int kSize = 3000; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 2345 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSize)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2346 | rv = trans->Read( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2347 | buf.get(), |
| 2348 | kSize, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2349 | base::Bind(&SpdyNetworkTransactionTest::DeleteSessionCallback, |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2350 | base::Unretained(&helper))); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2351 | ASSERT_EQ(ERR_IO_PENDING, rv); |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 2352 | data.Resume(); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2353 | |
| 2354 | // Finish running rest of tasks. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2355 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2356 | helper.VerifyDataConsumed(); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2357 | } |
| 2358 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2359 | // 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] | 2360 | TEST_P(SpdyNetworkTransactionTest, DISABLED_RedirectGetRequest) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2361 | scoped_ptr<SpdyHeaderBlock> headers( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2362 | spdy_util_.ConstructGetHeaderBlock(GetDefaultUrl())); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2363 | (*headers)["user-agent"] = ""; |
jgraettinger | 8f00db8b | 2014-09-24 23:00:06 | [diff] [blame] | 2364 | (*headers)["accept-encoding"] = "gzip, deflate"; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2365 | scoped_ptr<SpdyHeaderBlock> headers2( |
| 2366 | spdy_util_.ConstructGetHeaderBlock("http://www.foo.com/index.php")); |
| 2367 | (*headers2)["user-agent"] = ""; |
jgraettinger | 8f00db8b | 2014-09-24 23:00:06 | [diff] [blame] | 2368 | (*headers2)["accept-encoding"] = "gzip, deflate"; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2369 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2370 | // Setup writes/reads to www.example.org |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 2371 | scoped_ptr<SpdyFrame> req( |
| 2372 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
| 2373 | scoped_ptr<SpdyFrame> req2( |
| 2374 | spdy_util_.ConstructSpdySyn(1, *headers2, LOWEST, false, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2375 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReplyRedirect(1)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2376 | MockWrite writes[] = { |
| 2377 | CreateMockWrite(*req, 1), |
| 2378 | }; |
| 2379 | MockRead reads[] = { |
| 2380 | CreateMockRead(*resp, 2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2381 | MockRead(ASYNC, 0, 0, 3) // EOF |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2382 | }; |
| 2383 | |
| 2384 | // Setup writes/reads to www.foo.com |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2385 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2386 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2387 | MockWrite writes2[] = { |
| 2388 | CreateMockWrite(*req2, 1), |
| 2389 | }; |
| 2390 | MockRead reads2[] = { |
| 2391 | CreateMockRead(*resp2, 2), |
| 2392 | CreateMockRead(*body2, 3), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2393 | MockRead(ASYNC, 0, 0, 4) // EOF |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2394 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2395 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2396 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 2397 | arraysize(writes2)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2398 | |
| 2399 | // TODO(erikchen): Make test support SPDYSSL, SPDYNPN |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2400 | TestDelegate d; |
| 2401 | { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2402 | SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); |
davidben | 151423e | 2015-03-23 18:48:36 | [diff] [blame] | 2403 | scoped_ptr<URLRequest> r(spdy_url_request_context.CreateRequest( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2404 | GURL(GetDefaultUrl()), DEFAULT_PRIORITY, &d)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2405 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2406 | AddSocketDataProvider(&data); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2407 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2408 | AddSocketDataProvider(&data2); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2409 | |
| 2410 | d.set_quit_on_redirect(true); |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2411 | r->Start(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2412 | base::RunLoop().Run(); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2413 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2414 | EXPECT_EQ(1, d.received_redirect_count()); |
| 2415 | |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2416 | r->FollowDeferredRedirect(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2417 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2418 | EXPECT_EQ(1, d.response_started_count()); |
| 2419 | EXPECT_FALSE(d.received_data_before_response()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 2420 | EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2421 | std::string contents("hello!"); |
| 2422 | EXPECT_EQ(contents, d.data_received()); |
| 2423 | } |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 2424 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2425 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 2426 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 2427 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2428 | } |
| 2429 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2430 | // 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] | 2431 | // www.foo.com. |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2432 | TEST_P(SpdyNetworkTransactionTest, DISABLED_RedirectServerPush) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2433 | scoped_ptr<SpdyHeaderBlock> headers( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2434 | spdy_util_.ConstructGetHeaderBlock(GetDefaultUrl())); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2435 | (*headers)["user-agent"] = ""; |
jgraettinger | 8f00db8b | 2014-09-24 23:00:06 | [diff] [blame] | 2436 | (*headers)["accept-encoding"] = "gzip, deflate"; |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2437 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2438 | // Setup writes/reads to www.example.org |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2439 | scoped_ptr<SpdyFrame> req( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 2440 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2441 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2442 | scoped_ptr<SpdyFrame> rep(spdy_util_.ConstructSpdyPush( |
| 2443 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str(), |
| 2444 | "301 Moved Permanently", "http://www.foo.com/index.php")); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2445 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2446 | scoped_ptr<SpdyFrame> rst( |
| 2447 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_CANCEL)); |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2448 | MockWrite writes[] = { |
| 2449 | CreateMockWrite(*req, 1), |
| 2450 | CreateMockWrite(*rst, 6), |
| 2451 | }; |
| 2452 | MockRead reads[] = { |
| 2453 | CreateMockRead(*resp, 2), |
| 2454 | CreateMockRead(*rep, 3), |
| 2455 | CreateMockRead(*body, 4), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2456 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
| 2457 | MockRead(ASYNC, 0, 0, 7) // EOF |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2458 | }; |
| 2459 | |
| 2460 | // Setup writes/reads to www.foo.com |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2461 | scoped_ptr<SpdyHeaderBlock> headers2( |
| 2462 | spdy_util_.ConstructGetHeaderBlock("http://www.foo.com/index.php")); |
| 2463 | (*headers2)["user-agent"] = ""; |
jgraettinger | 8f00db8b | 2014-09-24 23:00:06 | [diff] [blame] | 2464 | (*headers2)["accept-encoding"] = "gzip, deflate"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2465 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 2466 | spdy_util_.ConstructSpdySyn(1, *headers2, LOWEST, false, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2467 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2468 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2469 | MockWrite writes2[] = { |
| 2470 | CreateMockWrite(*req2, 1), |
| 2471 | }; |
| 2472 | MockRead reads2[] = { |
| 2473 | CreateMockRead(*resp2, 2), |
| 2474 | CreateMockRead(*body2, 3), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2475 | MockRead(ASYNC, 0, 0, 5) // EOF |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2476 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2477 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2478 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 2479 | arraysize(writes2)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2480 | |
| 2481 | // TODO(erikchen): Make test support SPDYSSL, SPDYNPN |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2482 | TestDelegate d; |
| 2483 | TestDelegate d2; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2484 | SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2485 | { |
davidben | 151423e | 2015-03-23 18:48:36 | [diff] [blame] | 2486 | scoped_ptr<URLRequest> r(spdy_url_request_context.CreateRequest( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2487 | GURL(GetDefaultUrl()), DEFAULT_PRIORITY, &d)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2488 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2489 | AddSocketDataProvider(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2490 | |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2491 | r->Start(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2492 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2493 | |
| 2494 | EXPECT_EQ(0, d.received_redirect_count()); |
| 2495 | std::string contents("hello!"); |
| 2496 | EXPECT_EQ(contents, d.data_received()); |
| 2497 | |
davidben | 151423e | 2015-03-23 18:48:36 | [diff] [blame] | 2498 | scoped_ptr<URLRequest> r2(spdy_url_request_context.CreateRequest( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2499 | GURL(GetDefaultUrlWithPath("/foo.dat")), DEFAULT_PRIORITY, &d2)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2500 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2501 | AddSocketDataProvider(&data2); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2502 | |
| 2503 | d2.set_quit_on_redirect(true); |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2504 | r2->Start(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2505 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2506 | EXPECT_EQ(1, d2.received_redirect_count()); |
| 2507 | |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2508 | r2->FollowDeferredRedirect(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2509 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2510 | EXPECT_EQ(1, d2.response_started_count()); |
| 2511 | EXPECT_FALSE(d2.received_data_before_response()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 2512 | EXPECT_EQ(URLRequestStatus::SUCCESS, r2->status().status()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2513 | std::string contents2("hello!"); |
| 2514 | EXPECT_EQ(contents2, d2.data_received()); |
| 2515 | } |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2516 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2517 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 2518 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 2519 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2520 | } |
| 2521 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2522 | TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2523 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2524 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2525 | scoped_ptr<SpdyFrame> stream1_body( |
| 2526 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2527 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2528 | CreateMockWrite(*stream1_syn, 0), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2529 | }; |
| 2530 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2531 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2532 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2533 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2534 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2535 | const char kPushedData[] = "pushed"; |
| 2536 | scoped_ptr<SpdyFrame> stream2_body( |
| 2537 | spdy_util_.ConstructSpdyBodyFrame( |
| 2538 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2539 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2540 | CreateMockRead(*stream1_reply, 1), |
| 2541 | CreateMockRead(*stream2_syn, 2), |
| 2542 | CreateMockRead(*stream1_body, 3, SYNCHRONOUS), |
| 2543 | CreateMockRead(*stream2_body, 4), |
| 2544 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2545 | }; |
| 2546 | |
| 2547 | HttpResponseInfo response; |
| 2548 | HttpResponseInfo response2; |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2549 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2550 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2551 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2552 | &response, |
| 2553 | &response2, |
| 2554 | expected_push_result); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2555 | |
| 2556 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2557 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2558 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2559 | |
| 2560 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2561 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2562 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2563 | } |
| 2564 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2565 | TEST_P(SpdyNetworkTransactionTest, ServerPushBeforeSynReply) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2566 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2567 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2568 | scoped_ptr<SpdyFrame> stream1_body( |
| 2569 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2570 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2571 | CreateMockWrite(*stream1_syn, 0), |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2572 | }; |
| 2573 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2574 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2575 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2576 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2577 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2578 | const char kPushedData[] = "pushed"; |
| 2579 | scoped_ptr<SpdyFrame> stream2_body( |
| 2580 | spdy_util_.ConstructSpdyBodyFrame( |
| 2581 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2582 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2583 | CreateMockRead(*stream2_syn, 1), |
| 2584 | CreateMockRead(*stream1_reply, 2), |
| 2585 | CreateMockRead(*stream1_body, 3, SYNCHRONOUS), |
| 2586 | CreateMockRead(*stream2_body, 4), |
| 2587 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2588 | }; |
| 2589 | |
| 2590 | HttpResponseInfo response; |
| 2591 | HttpResponseInfo response2; |
| 2592 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2593 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2594 | RunServerPushTest(&data, |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2595 | &response, |
| 2596 | &response2, |
| 2597 | expected_push_result); |
| 2598 | |
| 2599 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2600 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2601 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2602 | |
| 2603 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2604 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2605 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2606 | } |
| 2607 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2608 | TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame2) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2609 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2610 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2611 | MockWrite writes[] = { |
| 2612 | CreateMockWrite(*stream1_syn, 0), |
| 2613 | }; |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2614 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2615 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2616 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2617 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2618 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2619 | const char kPushedData[] = "pushed"; |
| 2620 | scoped_ptr<SpdyFrame> stream2_body( |
| 2621 | spdy_util_.ConstructSpdyBodyFrame( |
| 2622 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2623 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2624 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2625 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2626 | CreateMockRead(*stream1_reply, 1), |
| 2627 | CreateMockRead(*stream2_syn, 2), |
| 2628 | CreateMockRead(*stream2_body, 3), |
| 2629 | CreateMockRead(*stream1_body, 4, SYNCHRONOUS), |
| 2630 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2631 | }; |
| 2632 | |
| 2633 | HttpResponseInfo response; |
| 2634 | HttpResponseInfo response2; |
| 2635 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2636 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2637 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2638 | &response, |
| 2639 | &response2, |
| 2640 | expected_push_result); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2641 | |
| 2642 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2643 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2644 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2645 | |
| 2646 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2647 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2648 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2649 | } |
| 2650 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2651 | TEST_P(SpdyNetworkTransactionTest, ServerPushServerAborted) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2652 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2653 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2654 | scoped_ptr<SpdyFrame> stream1_body( |
| 2655 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2656 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2657 | CreateMockWrite(*stream1_syn, 0), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2658 | }; |
| 2659 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2660 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2661 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2662 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2663 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2664 | scoped_ptr<SpdyFrame> stream2_rst( |
| 2665 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2666 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2667 | CreateMockRead(*stream1_reply, 1), |
| 2668 | CreateMockRead(*stream2_syn, 2), |
| 2669 | CreateMockRead(*stream2_rst, 3), |
| 2670 | CreateMockRead(*stream1_body, 4, SYNCHRONOUS), |
| 2671 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2672 | }; |
| 2673 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2674 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2675 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2676 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2677 | |
| 2678 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2679 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2680 | |
| 2681 | HttpNetworkTransaction* trans = helper.trans(); |
| 2682 | |
| 2683 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2684 | TestCompletionCallback callback; |
| 2685 | int rv = trans->Start( |
| 2686 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2687 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2688 | rv = callback.WaitForResult(); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2689 | EXPECT_EQ(OK, rv); |
| 2690 | |
| 2691 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2692 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2693 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2694 | |
| 2695 | // Verify the SYN_REPLY. |
| 2696 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2697 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2698 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2699 | } |
| 2700 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2701 | // Verify that we don't leak streams and that we properly send a reset |
| 2702 | // if the server pushes the same stream twice. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2703 | TEST_P(SpdyNetworkTransactionTest, ServerPushDuplicate) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2704 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2705 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2706 | scoped_ptr<SpdyFrame> stream1_body( |
| 2707 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2708 | scoped_ptr<SpdyFrame> stream3_rst( |
| 2709 | spdy_util_.ConstructSpdyRstStream(4, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2710 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2711 | CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*stream3_rst, 4), |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2712 | }; |
| 2713 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2714 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2715 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2716 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2717 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2718 | const char kPushedData[] = "pushed"; |
| 2719 | scoped_ptr<SpdyFrame> stream2_body( |
| 2720 | spdy_util_.ConstructSpdyBodyFrame( |
| 2721 | 2, kPushedData, strlen(kPushedData), true)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2722 | scoped_ptr<SpdyFrame> stream3_syn(spdy_util_.ConstructSpdyPush( |
| 2723 | NULL, 0, 4, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2724 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2725 | CreateMockRead(*stream1_reply, 1), |
| 2726 | CreateMockRead(*stream2_syn, 2), |
| 2727 | CreateMockRead(*stream3_syn, 3), |
| 2728 | CreateMockRead(*stream1_body, 5), |
| 2729 | CreateMockRead(*stream2_body, 6), |
| 2730 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 7), // Force a pause |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2731 | }; |
| 2732 | |
| 2733 | HttpResponseInfo response; |
| 2734 | HttpResponseInfo response2; |
| 2735 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2736 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2737 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2738 | &response, |
| 2739 | &response2, |
| 2740 | expected_push_result); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2741 | |
| 2742 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2743 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2744 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2745 | |
| 2746 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2747 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2748 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2749 | } |
| 2750 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2751 | TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrame) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2752 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2753 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2754 | scoped_ptr<SpdyFrame> stream1_body( |
| 2755 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2756 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2757 | CreateMockWrite(*stream1_syn, 0), |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2758 | }; |
| 2759 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2760 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2761 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2762 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2763 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2764 | static const char kPushedData[] = "pushed my darling hello my baby"; |
| 2765 | scoped_ptr<SpdyFrame> stream2_body_base( |
| 2766 | spdy_util_.ConstructSpdyBodyFrame( |
| 2767 | 2, kPushedData, strlen(kPushedData), true)); |
| 2768 | const size_t kChunkSize = strlen(kPushedData) / 4; |
| 2769 | scoped_ptr<SpdyFrame> stream2_body1( |
| 2770 | new SpdyFrame(stream2_body_base->data(), kChunkSize, false)); |
| 2771 | scoped_ptr<SpdyFrame> stream2_body2( |
| 2772 | new SpdyFrame(stream2_body_base->data() + kChunkSize, kChunkSize, false)); |
| 2773 | scoped_ptr<SpdyFrame> stream2_body3( |
| 2774 | new SpdyFrame(stream2_body_base->data() + 2 * kChunkSize, |
| 2775 | kChunkSize, false)); |
| 2776 | scoped_ptr<SpdyFrame> stream2_body4( |
| 2777 | new SpdyFrame(stream2_body_base->data() + 3 * kChunkSize, |
| 2778 | stream2_body_base->size() - 3 * kChunkSize, false)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2779 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2780 | CreateMockRead(*stream1_reply, 1), |
| 2781 | CreateMockRead(*stream2_syn, 2), |
| 2782 | CreateMockRead(*stream2_body1, 3), |
| 2783 | CreateMockRead(*stream2_body2, 4), |
| 2784 | CreateMockRead(*stream2_body3, 5), |
| 2785 | CreateMockRead(*stream2_body4, 6), |
| 2786 | CreateMockRead(*stream1_body, 7, SYNCHRONOUS), |
| 2787 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), // Force a pause |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2788 | }; |
| 2789 | |
| 2790 | HttpResponseInfo response; |
| 2791 | HttpResponseInfo response2; |
| 2792 | std::string expected_push_result("pushed my darling hello my baby"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2793 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2794 | RunServerPushTest(&data, &response, &response2, kPushedData); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2795 | |
| 2796 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2797 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2798 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2799 | |
| 2800 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2801 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2802 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2803 | } |
| 2804 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2805 | TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrameInterrupted) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2806 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2807 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2808 | scoped_ptr<SpdyFrame> stream1_body( |
| 2809 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2810 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2811 | CreateMockWrite(*stream1_syn, 0), |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2812 | }; |
| 2813 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2814 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2815 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2816 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2817 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2818 | static const char kPushedData[] = "pushed my darling hello my baby"; |
| 2819 | scoped_ptr<SpdyFrame> stream2_body_base( |
| 2820 | spdy_util_.ConstructSpdyBodyFrame( |
| 2821 | 2, kPushedData, strlen(kPushedData), true)); |
| 2822 | const size_t kChunkSize = strlen(kPushedData) / 4; |
| 2823 | scoped_ptr<SpdyFrame> stream2_body1( |
| 2824 | new SpdyFrame(stream2_body_base->data(), kChunkSize, false)); |
| 2825 | scoped_ptr<SpdyFrame> stream2_body2( |
| 2826 | new SpdyFrame(stream2_body_base->data() + kChunkSize, kChunkSize, false)); |
| 2827 | scoped_ptr<SpdyFrame> stream2_body3( |
| 2828 | new SpdyFrame(stream2_body_base->data() + 2 * kChunkSize, |
| 2829 | kChunkSize, false)); |
| 2830 | scoped_ptr<SpdyFrame> stream2_body4( |
| 2831 | new SpdyFrame(stream2_body_base->data() + 3 * kChunkSize, |
| 2832 | stream2_body_base->size() - 3 * kChunkSize, false)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2833 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2834 | CreateMockRead(*stream1_reply, 1), |
| 2835 | CreateMockRead(*stream2_syn, 2), |
| 2836 | CreateMockRead(*stream2_body1, 3), |
| 2837 | CreateMockRead(*stream2_body2, 4), |
| 2838 | CreateMockRead(*stream2_body3, 5), |
| 2839 | CreateMockRead(*stream2_body4, 6), |
| 2840 | CreateMockRead(*stream1_body.get(), 7, SYNCHRONOUS), |
| 2841 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8) // Force a pause. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2842 | }; |
| 2843 | |
| 2844 | HttpResponseInfo response; |
| 2845 | HttpResponseInfo response2; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2846 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2847 | RunServerPushTest(&data, &response, &response2, kPushedData); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2848 | |
| 2849 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2850 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2851 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2852 | |
| 2853 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2854 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2855 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2856 | } |
| 2857 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2858 | TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID0) { |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 2859 | if (spdy_util_.spdy_version() == HTTP2) { |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 2860 | // PUSH_PROMISE with stream id 0 is connection-level error. |
| 2861 | // TODO(baranovich): Test session going away. |
[email protected] | 00b2947 | 2014-01-16 18:10:24 | [diff] [blame] | 2862 | return; |
| 2863 | } |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 2864 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2865 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2866 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2867 | scoped_ptr<SpdyFrame> stream1_body( |
| 2868 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2869 | scoped_ptr<SpdyFrame> stream2_rst( |
| 2870 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2871 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2872 | CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*stream2_rst, 3), |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2873 | }; |
| 2874 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2875 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2876 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2877 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2878 | NULL, 0, 2, 0, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2879 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2880 | CreateMockRead(*stream1_reply, 1), |
| 2881 | CreateMockRead(*stream2_syn, 2), |
| 2882 | CreateMockRead(*stream1_body, 4), |
| 2883 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5) // Force a pause |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2884 | }; |
| 2885 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2886 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2887 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2888 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2889 | |
| 2890 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2891 | helper.AddData(&data); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2892 | |
| 2893 | HttpNetworkTransaction* trans = helper.trans(); |
| 2894 | |
| 2895 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2896 | TestCompletionCallback callback; |
| 2897 | int rv = trans->Start( |
| 2898 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2899 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2900 | rv = callback.WaitForResult(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2901 | EXPECT_EQ(OK, rv); |
| 2902 | |
| 2903 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2904 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2905 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2906 | |
| 2907 | // Verify the SYN_REPLY. |
| 2908 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2909 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2910 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2911 | } |
| 2912 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2913 | TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID9) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2914 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2915 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2916 | scoped_ptr<SpdyFrame> stream1_body( |
| 2917 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2918 | scoped_ptr<SpdyFrame> stream2_rst( |
| 2919 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_INVALID_STREAM)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2920 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2921 | CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*stream2_rst, 3), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2922 | }; |
| 2923 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2924 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2925 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2926 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2927 | NULL, 0, 2, 9, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2928 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2929 | CreateMockRead(*stream1_reply, 1), |
| 2930 | CreateMockRead(*stream2_syn, 2), |
| 2931 | CreateMockRead(*stream1_body, 4), |
| 2932 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2933 | }; |
| 2934 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2935 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2936 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2937 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2938 | |
| 2939 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2940 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2941 | |
| 2942 | HttpNetworkTransaction* trans = helper.trans(); |
| 2943 | |
| 2944 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2945 | TestCompletionCallback callback; |
| 2946 | int rv = trans->Start( |
| 2947 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2948 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2949 | rv = callback.WaitForResult(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2950 | EXPECT_EQ(OK, rv); |
| 2951 | |
| 2952 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2953 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2954 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2955 | |
| 2956 | // Verify the SYN_REPLY. |
| 2957 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2958 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 2959 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2960 | } |
| 2961 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2962 | TEST_P(SpdyNetworkTransactionTest, ServerPushNoURL) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2963 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2964 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2965 | scoped_ptr<SpdyFrame> stream1_body( |
| 2966 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2967 | scoped_ptr<SpdyFrame> stream2_rst( |
| 2968 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2969 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2970 | CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*stream2_rst, 3), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2971 | }; |
| 2972 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2973 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2974 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8b9211d | 2013-06-24 05:54:45 | [diff] [blame] | 2975 | scoped_ptr<SpdyHeaderBlock> incomplete_headers(new SpdyHeaderBlock()); |
[email protected] | 8b9211d | 2013-06-24 05:54:45 | [diff] [blame] | 2976 | (*incomplete_headers)[spdy_util_.GetStatusKey()] = "200 OK"; |
| 2977 | (*incomplete_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 2978 | (*incomplete_headers)["hello"] = "bye"; |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 2979 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame( |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 2980 | std::move(incomplete_headers), 2, 1)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2981 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2982 | CreateMockRead(*stream1_reply, 1), |
| 2983 | CreateMockRead(*stream2_syn, 2), |
| 2984 | CreateMockRead(*stream1_body, 4), |
| 2985 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5) // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2986 | }; |
| 2987 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 2988 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2989 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2990 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2991 | |
| 2992 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2993 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2994 | |
| 2995 | HttpNetworkTransaction* trans = helper.trans(); |
| 2996 | |
| 2997 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2998 | TestCompletionCallback callback; |
| 2999 | int rv = trans->Start( |
| 3000 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3001 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3002 | rv = callback.WaitForResult(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3003 | EXPECT_EQ(OK, rv); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3004 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3005 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3006 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 3007 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3008 | |
| 3009 | // Verify the SYN_REPLY. |
| 3010 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3011 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3012 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3013 | } |
| 3014 | |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3015 | // Verify that various SynReply headers parse correctly through the |
| 3016 | // HTTP layer. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3017 | TEST_P(SpdyNetworkTransactionTest, SynReplyHeaders) { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3018 | struct SynReplyHeadersTests { |
| 3019 | int num_headers; |
| 3020 | const char* extra_headers[5]; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3021 | SpdyHeaderBlock expected_headers; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3022 | } test_cases[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3023 | // This uses a multi-valued cookie header. |
| 3024 | { 2, |
| 3025 | { "cookie", "val1", |
| 3026 | "cookie", "val2", // will get appended separated by NULL |
| 3027 | NULL |
| 3028 | }, |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3029 | }, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3030 | // This is the minimalist set of headers. |
| 3031 | { 0, |
| 3032 | { NULL }, |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3033 | }, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3034 | // Headers with a comma separated list. |
| 3035 | { 1, |
| 3036 | { "cookie", "val1,val2", |
| 3037 | NULL |
| 3038 | }, |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3039 | } |
| 3040 | }; |
| 3041 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3042 | test_cases[0].expected_headers["status"] = "200"; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3043 | test_cases[1].expected_headers["status"] = "200"; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3044 | test_cases[2].expected_headers["status"] = "200"; |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3045 | |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3046 | // HTTP/2 eliminates use of the :version header. |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 3047 | if (spdy_util_.spdy_version() < HTTP2) { |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3048 | test_cases[0].expected_headers["version"] = "HTTP/1.1"; |
| 3049 | test_cases[1].expected_headers["version"] = "HTTP/1.1"; |
| 3050 | test_cases[2].expected_headers["version"] = "HTTP/1.1"; |
| 3051 | } |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3052 | |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3053 | test_cases[0].expected_headers["hello"] = "bye"; |
| 3054 | test_cases[1].expected_headers["hello"] = "bye"; |
| 3055 | test_cases[2].expected_headers["hello"] = "bye"; |
| 3056 | |
| 3057 | test_cases[0].expected_headers["cookie"] = StringPiece("val1\0val2", 9); |
| 3058 | test_cases[2].expected_headers["cookie"] = "val1,val2"; |
| 3059 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 3060 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3061 | scoped_ptr<SpdyFrame> req( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3062 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3063 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3064 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3065 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3066 | spdy_util_.ConstructSpdyGetSynReply(test_cases[i].extra_headers, |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 3067 | test_cases[i].num_headers, |
| 3068 | 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3069 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 3070 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3071 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3072 | CreateMockRead(*resp, 1), |
| 3073 | CreateMockRead(*body, 2), |
| 3074 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3075 | }; |
| 3076 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3077 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 3078 | arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3079 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3080 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3081 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3082 | TransactionHelperResult out = helper.output(); |
| 3083 | |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3084 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3085 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3086 | EXPECT_EQ("hello!", out.response_data); |
| 3087 | |
| 3088 | scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; |
| 3089 | EXPECT_TRUE(headers.get() != NULL); |
| 3090 | void* iter = NULL; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3091 | std::string name, value; |
| 3092 | SpdyHeaderBlock header_block; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3093 | while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3094 | SpdyHeaderBlock::StringPieceProxy mutable_header_block_value = |
| 3095 | header_block[name]; |
| 3096 | if (static_cast<StringPiece>(mutable_header_block_value).empty()) { |
| 3097 | mutable_header_block_value = value; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3098 | } else { |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3099 | std::string joint_value = mutable_header_block_value.as_string(); |
| 3100 | joint_value.append(1, '\0'); |
| 3101 | joint_value.append(value); |
| 3102 | mutable_header_block_value = joint_value; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3103 | } |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3104 | } |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3105 | EXPECT_EQ(test_cases[i].expected_headers, header_block); |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3106 | } |
| 3107 | } |
| 3108 | |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3109 | // Verify that various SynReply headers parse vary fields correctly |
| 3110 | // through the HTTP layer, and the response matches the request. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3111 | TEST_P(SpdyNetworkTransactionTest, SynReplyHeadersVary) { |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3112 | // Modify the following data to change/add test cases: |
| 3113 | struct SynReplyTests { |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3114 | bool vary_matches; |
| 3115 | int num_headers[2]; |
| 3116 | const char* extra_headers[2][16]; |
| 3117 | } test_cases[] = { |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3118 | // Test the case of a multi-valued cookie. When the value is delimited |
| 3119 | // with NUL characters, it needs to be unfolded into multiple headers. |
| 3120 | {true, |
| 3121 | {1, 4}, |
| 3122 | {{"cookie", "val1,val2", NULL}, |
| 3123 | {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
| 3124 | "/index.php", spdy_util_.GetVersionKey(), "HTTP/1.1", "vary", "cookie", |
| 3125 | NULL}}}, |
| 3126 | {// Multiple vary fields. |
| 3127 | true, |
| 3128 | {2, 5}, |
| 3129 | {{"friend", "barney", "enemy", "snaggletooth", NULL}, |
| 3130 | {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
| 3131 | "/index.php", spdy_util_.GetVersionKey(), "HTTP/1.1", "vary", "friend", |
| 3132 | "vary", "enemy", NULL}}}, |
| 3133 | {// Test a '*' vary field. |
| 3134 | false, |
| 3135 | {1, 4}, |
| 3136 | {{"cookie", "val1,val2", NULL}, |
| 3137 | {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
| 3138 | "/index.php", spdy_util_.GetVersionKey(), "HTTP/1.1", "vary", "*", |
| 3139 | NULL}}}, |
| 3140 | {// Multiple comma-separated vary fields. |
| 3141 | true, |
| 3142 | {2, 4}, |
| 3143 | {{"friend", "barney", "enemy", "snaggletooth", NULL}, |
| 3144 | {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
| 3145 | "/index.php", spdy_util_.GetVersionKey(), "HTTP/1.1", "vary", |
| 3146 | "friend,enemy", NULL}}}}; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3147 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 3148 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3149 | // Construct the request. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3150 | scoped_ptr<SpdyFrame> frame_req( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3151 | spdy_util_.ConstructSpdyGet(test_cases[i].extra_headers[0], |
| 3152 | test_cases[i].num_headers[0], |
| 3153 | false, 1, LOWEST, true)); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3154 | |
| 3155 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3156 | CreateMockWrite(*frame_req, 0), |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3157 | }; |
| 3158 | |
| 3159 | // Construct the reply. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3160 | SpdyHeaderBlock reply_headers; |
| 3161 | AppendToHeaderBlock(test_cases[i].extra_headers[1], |
| 3162 | test_cases[i].num_headers[1], |
| 3163 | &reply_headers); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3164 | scoped_ptr<SpdyFrame> frame_reply( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3165 | spdy_util_.ConstructSpdyReply(1, reply_headers)); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3166 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3167 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 3168 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3169 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3170 | CreateMockRead(*frame_reply, 1), |
| 3171 | CreateMockRead(*body, 2), |
| 3172 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3173 | }; |
| 3174 | |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3175 | // Attach the headers to the request. |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 3176 | int header_count = test_cases[i].num_headers[0]; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3177 | |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 3178 | HttpRequestInfo request = CreateGetRequest(); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 3179 | for (int ct = 0; ct < header_count; ct++) { |
| 3180 | const char* header_key = test_cases[i].extra_headers[0][ct * 2]; |
| 3181 | const char* header_value = test_cases[i].extra_headers[0][ct * 2 + 1]; |
| 3182 | request.extra_headers.SetHeader(header_key, header_value); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3183 | } |
| 3184 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3185 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 3186 | arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3187 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3188 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3189 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3190 | TransactionHelperResult out = helper.output(); |
| 3191 | |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3192 | EXPECT_EQ(OK, out.rv) << i; |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3193 | EXPECT_EQ("HTTP/1.1 200", out.status_line) << i; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3194 | EXPECT_EQ("hello!", out.response_data) << i; |
| 3195 | |
| 3196 | // Test the response information. |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3197 | EXPECT_EQ(out.response_info.vary_data.is_valid(), |
| 3198 | test_cases[i].vary_matches) << i; |
| 3199 | |
| 3200 | // Check the headers. |
| 3201 | scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; |
| 3202 | ASSERT_TRUE(headers.get() != NULL) << i; |
| 3203 | void* iter = NULL; |
| 3204 | std::string name, value, lines; |
| 3205 | while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
| 3206 | lines.append(name); |
| 3207 | lines.append(": "); |
| 3208 | lines.append(value); |
| 3209 | lines.append("\n"); |
| 3210 | } |
| 3211 | |
| 3212 | // Construct the expected header reply string. |
[email protected] | 9aa32319 | 2013-05-31 21:38:40 | [diff] [blame] | 3213 | std::string expected_reply = |
| 3214 | spdy_util_.ConstructSpdyReplyString(reply_headers); |
| 3215 | EXPECT_EQ(expected_reply, lines) << i; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3216 | } |
| 3217 | } |
| 3218 | |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3219 | // Verify that we don't crash on invalid SynReply responses. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3220 | TEST_P(SpdyNetworkTransactionTest, InvalidSynReply) { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3221 | struct InvalidSynReplyTests { |
| 3222 | int num_headers; |
| 3223 | const char* headers[10]; |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3224 | } test_cases[] = { |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3225 | // SYN_REPLY missing status header |
| 3226 | { |
| 3227 | 4, |
| 3228 | {spdy_util_.GetPathKey(), "/index.php", spdy_util_.GetVersionKey(), |
| 3229 | "HTTP/1.1", "cookie", "val1", "cookie", "val2", NULL}, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3230 | }, |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3231 | // SYN_REPLY missing version header |
| 3232 | { |
| 3233 | 2, {spdy_util_.GetPathKey(), "/index.php", "status", "200", NULL}, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3234 | }, |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 3235 | // SYN_REPLY with no headers |
| 3236 | { |
| 3237 | 0, {NULL}, |
| 3238 | }, |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3239 | }; |
| 3240 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 3241 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3242 | scoped_ptr<SpdyFrame> req( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3243 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 3244 | scoped_ptr<SpdyFrame> rst( |
| 3245 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 3246 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3247 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3248 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 2), |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3249 | }; |
| 3250 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3251 | // Construct the reply. |
| 3252 | SpdyHeaderBlock reply_headers; |
| 3253 | AppendToHeaderBlock( |
| 3254 | test_cases[i].headers, test_cases[i].num_headers, &reply_headers); |
| 3255 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyReply(1, reply_headers)); |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3256 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3257 | CreateMockRead(*resp, 1), MockRead(ASYNC, 0, 3) // EOF |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3258 | }; |
| 3259 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3260 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 3261 | arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3262 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3263 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3264 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3265 | TransactionHelperResult out = helper.output(); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 3266 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3267 | } |
| 3268 | } |
| 3269 | |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3270 | // Verify that we don't crash on some corrupt frames. |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 3271 | // TODO(jgraettinger): HTTP/2 treats a header decompression failure as a |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3272 | // connection error. I'd like to backport this behavior to SPDY3 as well. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3273 | TEST_P(SpdyNetworkTransactionTest, CorruptFrameSessionError) { |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 3274 | if (spdy_util_.spdy_version() >= HTTP2) { |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3275 | return; |
| 3276 | } |
[email protected] | 61c83f78 | 2011-01-27 21:00:24 | [diff] [blame] | 3277 | // This is the length field that's too short. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3278 | scoped_ptr<SpdyFrame> syn_reply_wrong_length( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3279 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3280 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 3281 | size_t right_size = |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 3282 | (spdy_util_.spdy_version() < HTTP2) |
| 3283 | ? syn_reply_wrong_length->size() - framer.GetControlFrameHeaderSize() |
| 3284 | : syn_reply_wrong_length->size(); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 3285 | size_t wrong_size = right_size - 4; |
[email protected] | a4bfdf7 | 2013-02-22 04:06:16 | [diff] [blame] | 3286 | test::SetFrameLength(syn_reply_wrong_length.get(), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 3287 | wrong_size, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3288 | spdy_util_.spdy_version()); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3289 | |
| 3290 | struct SynReplyTests { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3291 | const SpdyFrame* syn_reply; |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3292 | } test_cases[] = { |
[email protected] | 61c83f78 | 2011-01-27 21:00:24 | [diff] [blame] | 3293 | { syn_reply_wrong_length.get(), }, |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3294 | }; |
| 3295 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 3296 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3297 | scoped_ptr<SpdyFrame> req( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3298 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 099bc7e | 2013-07-18 04:19:16 | [diff] [blame] | 3299 | scoped_ptr<SpdyFrame> rst( |
| 3300 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 3301 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3302 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 3), |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3303 | }; |
| 3304 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3305 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3306 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3307 | MockRead(ASYNC, test_cases[i].syn_reply->data(), wrong_size, 1), |
| 3308 | CreateMockRead(*body, 2), |
| 3309 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3310 | }; |
| 3311 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3312 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 3313 | arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3314 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3315 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3316 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3317 | TransactionHelperResult out = helper.output(); |
[email protected] | 955fc2e7 | 2010-02-08 20:37:30 | [diff] [blame] | 3318 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3319 | } |
| 3320 | } |
| 3321 | |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 3322 | // HTTP/2 treats a header decompression failure as a connection-level error. |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3323 | TEST_P(SpdyNetworkTransactionTest, CorruptFrameSessionErrorSpdy4) { |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 3324 | if (spdy_util_.spdy_version() < HTTP2) { |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3325 | return; |
| 3326 | } |
| 3327 | // This is the length field that's too short. |
| 3328 | scoped_ptr<SpdyFrame> syn_reply_wrong_length( |
| 3329 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3330 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 3331 | size_t right_size = |
[email protected] | c143f274 | 2014-03-31 00:48:54 | [diff] [blame] | 3332 | syn_reply_wrong_length->size() - framer.GetControlFrameHeaderSize(); |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3333 | size_t wrong_size = right_size - 4; |
| 3334 | test::SetFrameLength(syn_reply_wrong_length.get(), |
| 3335 | wrong_size, |
| 3336 | spdy_util_.spdy_version()); |
| 3337 | |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3338 | scoped_ptr<SpdyFrame> req( |
| 3339 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3340 | scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 3341 | 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 5 (DECOMPRESS_FAILURE).")); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3342 | MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2)}; |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3343 | |
| 3344 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3345 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3346 | MockRead(ASYNC, syn_reply_wrong_length->data(), |
| 3347 | syn_reply_wrong_length->size() - 4, 1), |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3348 | }; |
| 3349 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3350 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3351 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 3352 | BoundNetLog(), GetParam(), NULL); |
| 3353 | helper.RunToCompletion(&data); |
| 3354 | TransactionHelperResult out = helper.output(); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3355 | EXPECT_EQ(ERR_SPDY_COMPRESSION_ERROR, out.rv); |
| 3356 | } |
| 3357 | |
| 3358 | TEST_P(SpdyNetworkTransactionTest, GoAwayOnDecompressionFailure) { |
bnc | 9b79a57 | 2015-09-02 12:25:03 | [diff] [blame] | 3359 | if (GetParam().protocol < kProtoHTTP2) { |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3360 | // Decompression failures are a stream error in SPDY3 and above. |
| 3361 | return; |
| 3362 | } |
| 3363 | scoped_ptr<SpdyFrame> req( |
| 3364 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3365 | scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 3366 | 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 5 (DECOMPRESS_FAILURE).")); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3367 | MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3368 | |
| 3369 | // Read HEADERS with corrupted payload. |
| 3370 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3371 | memset(resp->data() + 12, 0xff, resp->size() - 12); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3372 | MockRead reads[] = {CreateMockRead(*resp, 1)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3373 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3374 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3375 | NormalSpdyTransactionHelper helper( |
| 3376 | CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3377 | helper.RunToCompletion(&data); |
| 3378 | TransactionHelperResult out = helper.output(); |
| 3379 | EXPECT_EQ(ERR_SPDY_COMPRESSION_ERROR, out.rv); |
| 3380 | } |
| 3381 | |
| 3382 | TEST_P(SpdyNetworkTransactionTest, GoAwayOnFrameSizeError) { |
| 3383 | scoped_ptr<SpdyFrame> req( |
| 3384 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3385 | scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 3386 | 0, GOAWAY_PROTOCOL_ERROR, "Framer error: 1 (INVALID_CONTROL_FRAME).")); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3387 | MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3388 | |
| 3389 | // Read WINDOW_UPDATE with incorrectly-sized payload. |
| 3390 | // TODO(jgraettinger): SpdyFramer signals this as an INVALID_CONTROL_FRAME, |
| 3391 | // which is mapped to a protocol error, and not a frame size error. |
| 3392 | scoped_ptr<SpdyFrame> bad_window_update( |
| 3393 | spdy_util_.ConstructSpdyWindowUpdate(1, 1)); |
| 3394 | test::SetFrameLength(bad_window_update.get(), |
| 3395 | bad_window_update->size() - 1, |
| 3396 | spdy_util_.spdy_version()); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3397 | MockRead reads[] = {CreateMockRead(*bad_window_update, 1)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3398 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3399 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3400 | NormalSpdyTransactionHelper helper( |
| 3401 | CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3402 | helper.RunToCompletion(&data); |
| 3403 | TransactionHelperResult out = helper.output(); |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3404 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 3405 | } |
| 3406 | |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3407 | // Test that we shutdown correctly on write errors. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3408 | TEST_P(SpdyNetworkTransactionTest, WriteError) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3409 | scoped_ptr<SpdyFrame> req( |
| 3410 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3411 | MockWrite writes[] = { |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3412 | // We'll write 10 bytes successfully |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 3413 | MockWrite(ASYNC, req->data(), 10, 1), |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3414 | // Followed by ERROR! |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3415 | MockWrite(ASYNC, ERR_FAILED, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 3416 | // Session drains and attempts to write a GOAWAY: Another ERROR! |
| 3417 | MockWrite(ASYNC, ERR_FAILED, 3), |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3418 | }; |
| 3419 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 3420 | MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3421 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 3422 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3423 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3424 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3425 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3426 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 3427 | helper.AddData(&data); |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3428 | EXPECT_TRUE(helper.StartDefaultTest()); |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3429 | helper.FinishDefaultTest(); |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 3430 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 3431 | EXPECT_TRUE(data.AllReadDataConsumed()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3432 | TransactionHelperResult out = helper.output(); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3433 | EXPECT_EQ(ERR_FAILED, out.rv); |
| 3434 | } |
| 3435 | |
| 3436 | // Test that partial writes work. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3437 | TEST_P(SpdyNetworkTransactionTest, PartialWrite) { |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3438 | // Chop the SYN_STREAM frame into 5 chunks. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3439 | scoped_ptr<SpdyFrame> req( |
| 3440 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3441 | const int kChunks = 5; |
[email protected] | 4356f0f | 2013-04-07 00:58:17 | [diff] [blame] | 3442 | scoped_ptr<MockWrite[]> writes(ChopWriteFrame(*req.get(), kChunks)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3443 | for (int i = 0; i < kChunks; ++i) { |
| 3444 | writes[i].sequence_number = i; |
| 3445 | } |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3446 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3447 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3448 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3449 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3450 | CreateMockRead(*resp, kChunks), |
| 3451 | CreateMockRead(*body, kChunks + 1), |
| 3452 | MockRead(ASYNC, 0, kChunks + 2) // EOF |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3453 | }; |
| 3454 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3455 | SequencedSocketData data(reads, arraysize(reads), writes.get(), kChunks); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3456 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3457 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3458 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3459 | TransactionHelperResult out = helper.output(); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3460 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3461 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3462 | EXPECT_EQ("hello!", out.response_data); |
| 3463 | } |
| 3464 | |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3465 | // In this test, we enable compression, but get a uncompressed SynReply from |
| 3466 | // the server. Verify that teardown is all clean. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3467 | TEST_P(SpdyNetworkTransactionTest, DecompressFailureOnSynReply) { |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 3468 | if (spdy_util_.spdy_version() >= HTTP2) { |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3469 | // HPACK doesn't use deflate compression. |
| 3470 | return; |
| 3471 | } |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3472 | scoped_ptr<SpdyFrame> compressed( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3473 | spdy_util_.ConstructSpdyGet(NULL, 0, true, 1, LOWEST, true)); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3474 | scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 3475 | 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 5 (DECOMPRESS_FAILURE).")); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3476 | MockWrite writes[] = {CreateMockWrite(*compressed, 0), |
| 3477 | CreateMockWrite(*goaway, 2)}; |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3478 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3479 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3480 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3481 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3482 | CreateMockRead(*resp, 1), |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3483 | }; |
| 3484 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3485 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3486 | scoped_ptr<SpdySessionDependencies> session_deps = |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3487 | CreateSpdySessionDependencies(GetParam()); |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 3488 | session_deps->enable_compression = true; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3489 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3490 | BoundNetLog(), GetParam(), |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 3491 | std::move(session_deps)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3492 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3493 | TransactionHelperResult out = helper.output(); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3494 | EXPECT_EQ(ERR_SPDY_COMPRESSION_ERROR, out.rv); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3495 | } |
| 3496 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 3497 | // Test that the NetLog contains good data for a simple GET request. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3498 | TEST_P(SpdyNetworkTransactionTest, NetLog) { |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3499 | static const char* const kExtraHeaders[] = { |
| 3500 | "user-agent", "Chrome", |
| 3501 | }; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3502 | scoped_ptr<SpdyFrame> req( |
| 3503 | spdy_util_.ConstructSpdyGet(kExtraHeaders, 1, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3504 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3505 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3506 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3507 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3508 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3509 | CreateMockRead(*resp, 1), |
| 3510 | CreateMockRead(*body, 2), |
| 3511 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3512 | }; |
| 3513 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3514 | BoundTestNetLog log; |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3515 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3516 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3517 | NormalSpdyTransactionHelper helper(CreateGetRequestWithUserAgent(), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3518 | DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3519 | log.bound(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3520 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3521 | TransactionHelperResult out = helper.output(); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3522 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3523 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3524 | EXPECT_EQ("hello!", out.response_data); |
| 3525 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 3526 | // Check that the NetLog was filled reasonably. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3527 | // This test is intentionally non-specific about the exact ordering of the |
| 3528 | // log; instead we just check to make sure that certain events exist, and that |
| 3529 | // they are in the right order. |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3530 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3531 | log.GetEntries(&entries); |
| 3532 | |
| 3533 | EXPECT_LT(0u, entries.size()); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3534 | int pos = 0; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3535 | pos = ExpectLogContainsSomewhere(entries, 0, |
| 3536 | NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, |
| 3537 | NetLog::PHASE_BEGIN); |
| 3538 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3539 | NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, |
| 3540 | NetLog::PHASE_END); |
| 3541 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3542 | NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, |
| 3543 | NetLog::PHASE_BEGIN); |
| 3544 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3545 | NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, |
| 3546 | NetLog::PHASE_END); |
| 3547 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3548 | NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, |
| 3549 | NetLog::PHASE_BEGIN); |
| 3550 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3551 | NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, |
| 3552 | NetLog::PHASE_END); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3553 | |
| 3554 | // Check that we logged all the headers correctly |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3555 | const NetLog::EventType type = (GetParam().protocol <= kProtoSPDY31) |
| 3556 | ? NetLog::TYPE_HTTP2_SESSION_SYN_STREAM |
| 3557 | : NetLog::TYPE_HTTP2_SESSION_SEND_HEADERS; |
| 3558 | pos = ExpectLogContainsSomewhere(entries, 0, type, NetLog::PHASE_NONE); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3559 | |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 3560 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3561 | ASSERT_TRUE(entries[pos].params.get()); |
| 3562 | ASSERT_TRUE(entries[pos].params->GetList("headers", &header_list)); |
| 3563 | |
| 3564 | std::vector<std::string> expected; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3565 | expected.push_back(std::string(spdy_util_.GetHostKey()) + |
| 3566 | ": www.example.org"); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3567 | expected.push_back(std::string(spdy_util_.GetPathKey()) + ": /"); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 3568 | expected.push_back(std::string(spdy_util_.GetSchemeKey()) + ": " + |
| 3569 | spdy_util_.default_url().scheme()); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3570 | expected.push_back(std::string(spdy_util_.GetMethodKey()) + ": GET"); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3571 | expected.push_back("user-agent: Chrome"); |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 3572 | if (spdy_util_.spdy_version() < HTTP2) { |
| 3573 | // HTTP/2 eliminates use of the :version header. |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3574 | expected.push_back(std::string(spdy_util_.GetVersionKey()) + ": HTTP/1.1"); |
| 3575 | } |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3576 | EXPECT_EQ(expected.size(), header_list->GetSize()); |
| 3577 | for (std::vector<std::string>::const_iterator it = expected.begin(); |
| 3578 | it != expected.end(); |
| 3579 | ++it) { |
| 3580 | base::StringValue header(*it); |
| 3581 | EXPECT_NE(header_list->end(), header_list->Find(header)) << |
| 3582 | "Header not found: " << *it; |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3583 | } |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3584 | } |
| 3585 | |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3586 | // Since we buffer the IO from the stream to the renderer, this test verifies |
| 3587 | // that when we read out the maximum amount of data (e.g. we received 50 bytes |
| 3588 | // on the network, but issued a Read for only 5 of those bytes) that the data |
| 3589 | // flow still works correctly. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3590 | TEST_P(SpdyNetworkTransactionTest, BufferFull) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3591 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3592 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3593 | scoped_ptr<SpdyFrame> req( |
| 3594 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3595 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3596 | |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3597 | // 2 data frames in a single read. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3598 | scoped_ptr<SpdyFrame> data_frame_1( |
| 3599 | framer.CreateDataFrame(1, "goodby", 6, DATA_FLAG_NONE)); |
| 3600 | scoped_ptr<SpdyFrame> data_frame_2( |
| 3601 | framer.CreateDataFrame(1, "e worl", 6, DATA_FLAG_NONE)); |
| 3602 | const SpdyFrame* data_frames[2] = { |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3603 | data_frame_1.get(), |
| 3604 | data_frame_2.get(), |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3605 | }; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3606 | char combined_data_frames[100]; |
| 3607 | int combined_data_frames_len = |
| 3608 | CombineFrames(data_frames, arraysize(data_frames), |
| 3609 | combined_data_frames, arraysize(combined_data_frames)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3610 | scoped_ptr<SpdyFrame> last_frame( |
| 3611 | framer.CreateDataFrame(1, "d", 1, DATA_FLAG_FIN)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3612 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3613 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3614 | MockRead reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3615 | CreateMockRead(*resp, 1), |
| 3616 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause |
| 3617 | MockRead(ASYNC, combined_data_frames, combined_data_frames_len, 3), |
| 3618 | MockRead(ASYNC, ERR_IO_PENDING, 4), // Force a pause |
| 3619 | CreateMockRead(*last_frame, 5), |
| 3620 | MockRead(ASYNC, 0, 6) // EOF |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3621 | }; |
| 3622 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3623 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3624 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3625 | TestCompletionCallback callback; |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3626 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3627 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3628 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3629 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3630 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3631 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3632 | int rv = trans->Start( |
| 3633 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3634 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3635 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3636 | TransactionHelperResult out = helper.output(); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3637 | out.rv = callback.WaitForResult(); |
| 3638 | EXPECT_EQ(out.rv, OK); |
| 3639 | |
| 3640 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3641 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3642 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3643 | out.status_line = response->headers->GetStatusLine(); |
| 3644 | out.response_info = *response; // Make a copy so we can verify. |
| 3645 | |
| 3646 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3647 | TestCompletionCallback read_callback; |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3648 | |
| 3649 | std::string content; |
| 3650 | do { |
| 3651 | // Read small chunks at a time. |
| 3652 | const int kSmallReadSize = 3; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3653 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3654 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3655 | if (rv == ERR_IO_PENDING) { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 3656 | data.Resume(); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3657 | rv = read_callback.WaitForResult(); |
| 3658 | } |
| 3659 | if (rv > 0) { |
| 3660 | content.append(buf->data(), rv); |
| 3661 | } else if (rv < 0) { |
| 3662 | NOTREACHED(); |
| 3663 | } |
| 3664 | } while (rv > 0); |
| 3665 | |
| 3666 | out.response_data.swap(content); |
| 3667 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3668 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3669 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3670 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3671 | |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3672 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3673 | helper.VerifyDataConsumed(); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3674 | |
| 3675 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3676 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3677 | EXPECT_EQ("goodbye world", out.response_data); |
| 3678 | } |
| 3679 | |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3680 | // Verify that basic buffering works; when multiple data frames arrive |
| 3681 | // at the same time, ensure that we don't notify a read completion for |
| 3682 | // each data frame individually. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3683 | TEST_P(SpdyNetworkTransactionTest, Buffering) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3684 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3685 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3686 | scoped_ptr<SpdyFrame> req( |
| 3687 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3688 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3689 | |
| 3690 | // 4 data frames in a single read. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3691 | scoped_ptr<SpdyFrame> data_frame( |
| 3692 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 3693 | scoped_ptr<SpdyFrame> data_frame_fin( |
| 3694 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN)); |
| 3695 | const SpdyFrame* data_frames[4] = { |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3696 | data_frame.get(), |
| 3697 | data_frame.get(), |
| 3698 | data_frame.get(), |
| 3699 | data_frame_fin.get() |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3700 | }; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3701 | char combined_data_frames[100]; |
| 3702 | int combined_data_frames_len = |
| 3703 | CombineFrames(data_frames, arraysize(data_frames), |
| 3704 | combined_data_frames, arraysize(combined_data_frames)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3705 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3706 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3707 | MockRead reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3708 | CreateMockRead(*resp, 1), |
| 3709 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a pause |
| 3710 | MockRead(ASYNC, combined_data_frames, combined_data_frames_len, 3), |
| 3711 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3712 | }; |
| 3713 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3714 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3715 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3716 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3717 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3718 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3719 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3720 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3721 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3722 | TestCompletionCallback callback; |
| 3723 | int rv = trans->Start( |
| 3724 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3725 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3726 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3727 | TransactionHelperResult out = helper.output(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3728 | out.rv = callback.WaitForResult(); |
| 3729 | EXPECT_EQ(out.rv, OK); |
| 3730 | |
| 3731 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3732 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3733 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3734 | out.status_line = response->headers->GetStatusLine(); |
| 3735 | out.response_info = *response; // Make a copy so we can verify. |
| 3736 | |
| 3737 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3738 | TestCompletionCallback read_callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3739 | |
| 3740 | std::string content; |
| 3741 | int reads_completed = 0; |
| 3742 | do { |
| 3743 | // Read small chunks at a time. |
| 3744 | const int kSmallReadSize = 14; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3745 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3746 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3747 | if (rv == ERR_IO_PENDING) { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 3748 | data.Resume(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3749 | rv = read_callback.WaitForResult(); |
| 3750 | } |
| 3751 | if (rv > 0) { |
| 3752 | EXPECT_EQ(kSmallReadSize, rv); |
| 3753 | content.append(buf->data(), rv); |
| 3754 | } else if (rv < 0) { |
| 3755 | FAIL() << "Unexpected read error: " << rv; |
| 3756 | } |
| 3757 | reads_completed++; |
| 3758 | } while (rv > 0); |
| 3759 | |
| 3760 | EXPECT_EQ(3, reads_completed); // Reads are: 14 bytes, 14 bytes, 0 bytes. |
| 3761 | |
| 3762 | out.response_data.swap(content); |
| 3763 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3764 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3765 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3766 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3767 | |
| 3768 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3769 | helper.VerifyDataConsumed(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3770 | |
| 3771 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3772 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3773 | EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 3774 | } |
| 3775 | |
| 3776 | // 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] | 3777 | TEST_P(SpdyNetworkTransactionTest, BufferedAll) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3778 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3779 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3780 | scoped_ptr<SpdyFrame> req( |
| 3781 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3782 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3783 | |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3784 | // 5 data frames in a single read. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3785 | scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3786 | scoped_ptr<SpdyFrame> data_frame( |
| 3787 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 3788 | scoped_ptr<SpdyFrame> data_frame_fin( |
| 3789 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN)); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3790 | const SpdyFrame* frames[5] = {reply.get(), data_frame.get(), data_frame.get(), |
| 3791 | data_frame.get(), data_frame_fin.get()}; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3792 | char combined_frames[200]; |
| 3793 | int combined_frames_len = |
| 3794 | CombineFrames(frames, arraysize(frames), |
| 3795 | combined_frames, arraysize(combined_frames)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3796 | |
| 3797 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3798 | MockRead(ASYNC, combined_frames, combined_frames_len, 1), |
| 3799 | MockRead(ASYNC, 0, 2) // EOF |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3800 | }; |
| 3801 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 3802 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3803 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3804 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3805 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3806 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3807 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3808 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3809 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3810 | TestCompletionCallback callback; |
| 3811 | int rv = trans->Start( |
| 3812 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3813 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3814 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3815 | TransactionHelperResult out = helper.output(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3816 | out.rv = callback.WaitForResult(); |
| 3817 | EXPECT_EQ(out.rv, OK); |
| 3818 | |
| 3819 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3820 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3821 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3822 | out.status_line = response->headers->GetStatusLine(); |
| 3823 | out.response_info = *response; // Make a copy so we can verify. |
| 3824 | |
| 3825 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3826 | TestCompletionCallback read_callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3827 | |
| 3828 | std::string content; |
| 3829 | int reads_completed = 0; |
| 3830 | do { |
| 3831 | // Read small chunks at a time. |
| 3832 | const int kSmallReadSize = 14; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3833 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3834 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3835 | if (rv > 0) { |
| 3836 | EXPECT_EQ(kSmallReadSize, rv); |
| 3837 | content.append(buf->data(), rv); |
| 3838 | } else if (rv < 0) { |
| 3839 | FAIL() << "Unexpected read error: " << rv; |
| 3840 | } |
| 3841 | reads_completed++; |
| 3842 | } while (rv > 0); |
| 3843 | |
| 3844 | EXPECT_EQ(3, reads_completed); |
| 3845 | |
| 3846 | out.response_data.swap(content); |
| 3847 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3848 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3849 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3850 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3851 | |
| 3852 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3853 | helper.VerifyDataConsumed(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3854 | |
| 3855 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 3856 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3857 | EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 3858 | } |
| 3859 | |
| 3860 | // Verify the case where we buffer data and close the connection. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3861 | TEST_P(SpdyNetworkTransactionTest, BufferedClosed) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3862 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3863 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3864 | scoped_ptr<SpdyFrame> req( |
| 3865 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3866 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3867 | |
| 3868 | // All data frames in a single read. |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3869 | // NOTE: We don't FIN the stream. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3870 | scoped_ptr<SpdyFrame> data_frame( |
| 3871 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 3872 | const SpdyFrame* data_frames[4] = { |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3873 | data_frame.get(), |
| 3874 | data_frame.get(), |
| 3875 | data_frame.get(), |
| 3876 | data_frame.get() |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3877 | }; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3878 | char combined_data_frames[100]; |
| 3879 | int combined_data_frames_len = |
| 3880 | CombineFrames(data_frames, arraysize(data_frames), |
| 3881 | combined_data_frames, arraysize(combined_data_frames)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3882 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3883 | MockRead reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3884 | CreateMockRead(*resp, 1), |
| 3885 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a wait |
| 3886 | MockRead(ASYNC, combined_data_frames, combined_data_frames_len, 3), |
| 3887 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3888 | }; |
| 3889 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3890 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3891 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3892 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3893 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3894 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3895 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3896 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3897 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3898 | TestCompletionCallback callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3899 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3900 | int rv = trans->Start( |
| 3901 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3902 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3903 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3904 | TransactionHelperResult out = helper.output(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3905 | out.rv = callback.WaitForResult(); |
| 3906 | EXPECT_EQ(out.rv, OK); |
| 3907 | |
| 3908 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3909 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3910 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3911 | out.status_line = response->headers->GetStatusLine(); |
| 3912 | out.response_info = *response; // Make a copy so we can verify. |
| 3913 | |
| 3914 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3915 | TestCompletionCallback read_callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3916 | |
| 3917 | std::string content; |
| 3918 | int reads_completed = 0; |
| 3919 | do { |
| 3920 | // Read small chunks at a time. |
| 3921 | const int kSmallReadSize = 14; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3922 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3923 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3924 | if (rv == ERR_IO_PENDING) { |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 3925 | data.Resume(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3926 | rv = read_callback.WaitForResult(); |
| 3927 | } |
| 3928 | if (rv > 0) { |
| 3929 | content.append(buf->data(), rv); |
| 3930 | } else if (rv < 0) { |
| 3931 | // This test intentionally closes the connection, and will get an error. |
| 3932 | EXPECT_EQ(ERR_CONNECTION_CLOSED, rv); |
| 3933 | break; |
| 3934 | } |
| 3935 | reads_completed++; |
| 3936 | } while (rv > 0); |
| 3937 | |
| 3938 | EXPECT_EQ(0, reads_completed); |
| 3939 | |
| 3940 | out.response_data.swap(content); |
| 3941 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3942 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3943 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3944 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3945 | |
| 3946 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3947 | helper.VerifyDataConsumed(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3948 | } |
| 3949 | |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3950 | // Verify the case where we buffer data and cancel the transaction. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3951 | TEST_P(SpdyNetworkTransactionTest, BufferedCancelled) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3952 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3953 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3954 | scoped_ptr<SpdyFrame> req( |
| 3955 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 3956 | scoped_ptr<SpdyFrame> rst( |
| 3957 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3958 | MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*rst, 4)}; |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3959 | |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3960 | // NOTE: We don't FIN the stream. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3961 | scoped_ptr<SpdyFrame> data_frame( |
| 3962 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3963 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3964 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3965 | MockRead reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3966 | CreateMockRead(*resp, 1), |
| 3967 | MockRead(ASYNC, ERR_IO_PENDING, 2), // Force a wait |
| 3968 | CreateMockRead(*data_frame, 3), |
| 3969 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3970 | }; |
| 3971 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 3972 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3973 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3974 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3975 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3976 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3977 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3978 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3979 | TestCompletionCallback callback; |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3980 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3981 | int rv = trans->Start( |
| 3982 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3983 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3984 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3985 | TransactionHelperResult out = helper.output(); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3986 | out.rv = callback.WaitForResult(); |
| 3987 | EXPECT_EQ(out.rv, OK); |
| 3988 | |
| 3989 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3990 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3991 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3992 | out.status_line = response->headers->GetStatusLine(); |
| 3993 | out.response_info = *response; // Make a copy so we can verify. |
| 3994 | |
| 3995 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3996 | TestCompletionCallback read_callback; |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 3997 | |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 3998 | const int kReadSize = 256; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3999 | scoped_refptr<IOBuffer> buf(new IOBuffer(kReadSize)); |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 4000 | rv = trans->Read(buf.get(), kReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4001 | ASSERT_EQ(ERR_IO_PENDING, rv) << "Unexpected read: " << rv; |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 4002 | |
| 4003 | // Complete the read now, which causes buffering to start. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 4004 | data.Resume(); |
| 4005 | base::RunLoop().RunUntilIdle(); |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 4006 | // Destroy the transaction, causing the stream to get cancelled |
| 4007 | // and orphaning the buffered IO task. |
| 4008 | helper.ResetTrans(); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4009 | |
| 4010 | // Flush the MessageLoop; this will cause the buffered IO task |
| 4011 | // to run for the final time. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4012 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4013 | |
| 4014 | // Verify that we consumed all test data. |
| 4015 | helper.VerifyDataConsumed(); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4016 | } |
| 4017 | |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4018 | // Test that if the server requests persistence of settings, that we save |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4019 | // the settings in the HttpServerProperties. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4020 | TEST_P(SpdyNetworkTransactionTest, SettingsSaved) { |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 4021 | if (spdy_util_.spdy_version() >= HTTP2) { |
| 4022 | // HTTP/2 doesn't support settings persistence. |
[email protected] | 8a7bc7a | 2014-02-28 21:25:22 | [diff] [blame] | 4023 | return; |
| 4024 | } |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4025 | static const SpdyHeaderInfo kSynReplyInfo = { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4026 | SYN_REPLY, // Syn Reply |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4027 | 1, // Stream ID |
| 4028 | 0, // Associated Stream ID |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4029 | ConvertRequestPriorityToSpdyPriority( |
| 4030 | LOWEST, spdy_util_.spdy_version()), |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4031 | CONTROL_FLAG_NONE, // Control Flags |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4032 | false, // Compressed |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 4033 | RST_STREAM_INVALID, // Status |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4034 | NULL, // Data |
| 4035 | 0, // Data Length |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4036 | DATA_FLAG_NONE // Data Flags |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4037 | }; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4038 | |
[email protected] | c016882 | 2011-12-10 01:24:27 | [diff] [blame] | 4039 | BoundNetLog net_log; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4040 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 4041 | net_log, GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 4042 | helper.RunPreTestSetup(); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4043 | |
| 4044 | // Verify that no settings exist initially. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4045 | HostPortPair host_port_pair("www.example.org", helper.port()); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 4046 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4047 | EXPECT_TRUE(spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4048 | host_port_pair).empty()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4049 | |
| 4050 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4051 | scoped_ptr<SpdyFrame> req( |
| 4052 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4053 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4054 | |
| 4055 | // Construct the reply. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4056 | scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); |
| 4057 | (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 4058 | (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4059 | scoped_ptr<SpdyFrame> reply( |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 4060 | spdy_util_.ConstructSpdyFrame(kSynReplyInfo, std::move(reply_headers))); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4061 | |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4062 | const SpdySettingsIds kSampleId1 = SETTINGS_UPLOAD_BANDWIDTH; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4063 | unsigned int kSampleValue1 = 0x0a0a0a0a; |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4064 | const SpdySettingsIds kSampleId2 = SETTINGS_DOWNLOAD_BANDWIDTH; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4065 | unsigned int kSampleValue2 = 0x0b0b0b0b; |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4066 | const SpdySettingsIds kSampleId3 = SETTINGS_ROUND_TRIP_TIME; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4067 | unsigned int kSampleValue3 = 0x0c0c0c0c; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4068 | scoped_ptr<SpdyFrame> settings_frame; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4069 | { |
| 4070 | // Construct the SETTINGS frame. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4071 | SettingsMap settings; |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4072 | // First add a persisted setting. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4073 | settings[kSampleId1] = |
| 4074 | SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue1); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4075 | // Next add a non-persisted setting. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4076 | settings[kSampleId2] = |
| 4077 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kSampleValue2); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4078 | // Next add another persisted setting. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4079 | settings[kSampleId3] = |
| 4080 | SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue3); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4081 | settings_frame.reset(spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4082 | } |
| 4083 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4084 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4085 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4086 | CreateMockRead(*reply, 1), |
| 4087 | CreateMockRead(*body, 2), |
| 4088 | CreateMockRead(*settings_frame, 3), |
| 4089 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4090 | }; |
| 4091 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4092 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4093 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 4094 | helper.RunDefaultTest(); |
| 4095 | helper.VerifyDataConsumed(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4096 | TransactionHelperResult out = helper.output(); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4097 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4098 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4099 | EXPECT_EQ("hello!", out.response_data); |
| 4100 | |
| 4101 | { |
| 4102 | // Verify we had two persisted settings. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4103 | const SettingsMap& settings_map = |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4104 | spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4105 | host_port_pair); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4106 | ASSERT_EQ(2u, settings_map.size()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4107 | |
| 4108 | // Verify the first persisted setting. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4109 | SettingsMap::const_iterator it1 = settings_map.find(kSampleId1); |
| 4110 | EXPECT_TRUE(it1 != settings_map.end()); |
| 4111 | SettingsFlagsAndValue flags_and_value1 = it1->second; |
| 4112 | EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1.first); |
| 4113 | EXPECT_EQ(kSampleValue1, flags_and_value1.second); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4114 | |
| 4115 | // Verify the second persisted setting. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4116 | SettingsMap::const_iterator it3 = settings_map.find(kSampleId3); |
| 4117 | EXPECT_TRUE(it3 != settings_map.end()); |
| 4118 | SettingsFlagsAndValue flags_and_value3 = it3->second; |
| 4119 | EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value3.first); |
| 4120 | EXPECT_EQ(kSampleValue3, flags_and_value3.second); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4121 | } |
| 4122 | } |
| 4123 | |
| 4124 | // Test that when there are settings saved that they are sent back to the |
| 4125 | // server upon session establishment. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4126 | TEST_P(SpdyNetworkTransactionTest, SettingsPlayback) { |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 4127 | if (spdy_util_.spdy_version() >= HTTP2) { |
| 4128 | // HTTP/2 doesn't support settings persistence. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4129 | return; |
| 4130 | } |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4131 | static const SpdyHeaderInfo kSynReplyInfo = { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4132 | SYN_REPLY, // Syn Reply |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4133 | 1, // Stream ID |
| 4134 | 0, // Associated Stream ID |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4135 | ConvertRequestPriorityToSpdyPriority( |
| 4136 | LOWEST, spdy_util_.spdy_version()), |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4137 | CONTROL_FLAG_NONE, // Control Flags |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4138 | false, // Compressed |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 4139 | RST_STREAM_INVALID, // Status |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4140 | NULL, // Data |
| 4141 | 0, // Data Length |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4142 | DATA_FLAG_NONE // Data Flags |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4143 | }; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4144 | |
[email protected] | c016882 | 2011-12-10 01:24:27 | [diff] [blame] | 4145 | BoundNetLog net_log; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4146 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 4147 | net_log, GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 4148 | helper.RunPreTestSetup(); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4149 | |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4150 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
| 4151 | |
| 4152 | SpdySessionPoolPeer pool_peer(spdy_session_pool); |
| 4153 | pool_peer.SetEnableSendingInitialData(true); |
| 4154 | |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4155 | // Verify that no settings exist initially. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4156 | HostPortPair host_port_pair("www.example.org", helper.port()); |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4157 | EXPECT_TRUE(spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4158 | host_port_pair).empty()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4159 | |
[email protected] | c143f274 | 2014-03-31 00:48:54 | [diff] [blame] | 4160 | const SpdySettingsIds kSampleId1 = SETTINGS_MAX_CONCURRENT_STREAMS; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4161 | unsigned int kSampleValue1 = 0x0a0a0a0a; |
[email protected] | c143f274 | 2014-03-31 00:48:54 | [diff] [blame] | 4162 | const SpdySettingsIds kSampleId2 = SETTINGS_INITIAL_WINDOW_SIZE; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4163 | unsigned int kSampleValue2 = 0x0c0c0c0c; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4164 | |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4165 | // First add a persisted setting. |
| 4166 | spdy_session_pool->http_server_properties()->SetSpdySetting( |
| 4167 | host_port_pair, |
| 4168 | kSampleId1, |
| 4169 | SETTINGS_FLAG_PLEASE_PERSIST, |
| 4170 | kSampleValue1); |
| 4171 | |
| 4172 | // Next add another persisted setting. |
| 4173 | spdy_session_pool->http_server_properties()->SetSpdySetting( |
| 4174 | host_port_pair, |
| 4175 | kSampleId2, |
| 4176 | SETTINGS_FLAG_PLEASE_PERSIST, |
| 4177 | kSampleValue2); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4178 | |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4179 | EXPECT_EQ(2u, spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4180 | host_port_pair).size()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4181 | |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4182 | // Construct the initial SETTINGS frame. |
| 4183 | SettingsMap initial_settings; |
| 4184 | initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 4185 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); |
| 4186 | scoped_ptr<SpdyFrame> initial_settings_frame( |
| 4187 | spdy_util_.ConstructSpdySettings(initial_settings)); |
| 4188 | |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4189 | // Construct the persisted SETTINGS frame. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4190 | const SettingsMap& settings = |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4191 | spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4192 | host_port_pair); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4193 | scoped_ptr<SpdyFrame> settings_frame( |
| 4194 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4195 | |
| 4196 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4197 | scoped_ptr<SpdyFrame> req( |
| 4198 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4199 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4200 | MockWrite writes[] = { |
| 4201 | CreateMockWrite(*initial_settings_frame, 0), |
| 4202 | CreateMockWrite(*settings_frame, 1), |
| 4203 | CreateMockWrite(*req, 2), |
| 4204 | }; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4205 | |
| 4206 | // Construct the reply. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4207 | scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); |
| 4208 | (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 4209 | (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4210 | scoped_ptr<SpdyFrame> reply( |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 4211 | spdy_util_.ConstructSpdyFrame(kSynReplyInfo, std::move(reply_headers))); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4212 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4213 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4214 | MockRead reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4215 | CreateMockRead(*reply, 3), |
| 4216 | CreateMockRead(*body, 4), |
| 4217 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4218 | }; |
| 4219 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4220 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4221 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 4222 | helper.RunDefaultTest(); |
| 4223 | helper.VerifyDataConsumed(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4224 | TransactionHelperResult out = helper.output(); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4225 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4226 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4227 | EXPECT_EQ("hello!", out.response_data); |
| 4228 | |
| 4229 | { |
| 4230 | // Verify we had two persisted settings. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4231 | const SettingsMap& settings_map = |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4232 | spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4233 | host_port_pair); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4234 | ASSERT_EQ(2u, settings_map.size()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4235 | |
| 4236 | // Verify the first persisted setting. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4237 | SettingsMap::const_iterator it1 = settings_map.find(kSampleId1); |
| 4238 | EXPECT_TRUE(it1 != settings_map.end()); |
| 4239 | SettingsFlagsAndValue flags_and_value1 = it1->second; |
| 4240 | EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1.first); |
| 4241 | EXPECT_EQ(kSampleValue1, flags_and_value1.second); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4242 | |
| 4243 | // Verify the second persisted setting. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4244 | SettingsMap::const_iterator it2 = settings_map.find(kSampleId2); |
| 4245 | EXPECT_TRUE(it2 != settings_map.end()); |
| 4246 | SettingsFlagsAndValue flags_and_value2 = it2->second; |
| 4247 | EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value2.first); |
| 4248 | EXPECT_EQ(kSampleValue2, flags_and_value2.second); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4249 | } |
| 4250 | } |
| 4251 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4252 | TEST_P(SpdyNetworkTransactionTest, GoAwayWithActiveStream) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4253 | scoped_ptr<SpdyFrame> req( |
| 4254 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4255 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 69d717bd | 2010-04-21 18:43:21 | [diff] [blame] | 4256 | |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4257 | scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway()); |
[email protected] | 69d717bd | 2010-04-21 18:43:21 | [diff] [blame] | 4258 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4259 | CreateMockRead(*go_away, 1), |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4260 | }; |
| 4261 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4262 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4263 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4264 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4265 | helper.AddData(&data); |
| 4266 | helper.RunToCompletion(&data); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4267 | TransactionHelperResult out = helper.output(); |
[email protected] | c9336d2 | 2010-08-10 00:04:18 | [diff] [blame] | 4268 | EXPECT_EQ(ERR_ABORTED, out.rv); |
[email protected] | 69d717bd | 2010-04-21 18:43:21 | [diff] [blame] | 4269 | } |
| 4270 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4271 | TEST_P(SpdyNetworkTransactionTest, CloseWithActiveStream) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4272 | scoped_ptr<SpdyFrame> req( |
| 4273 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4274 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4275 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4276 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4277 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4278 | CreateMockRead(*resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4279 | }; |
| 4280 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4281 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4282 | BoundNetLog log; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4283 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4284 | log, GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4285 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4286 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4287 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4288 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4289 | TestCompletionCallback callback; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4290 | TransactionHelperResult out; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4291 | out.rv = trans->Start(&CreateGetRequest(), callback.callback(), log); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4292 | |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4293 | EXPECT_EQ(out.rv, ERR_IO_PENDING); |
| 4294 | out.rv = callback.WaitForResult(); |
| 4295 | EXPECT_EQ(out.rv, OK); |
| 4296 | |
| 4297 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4298 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4299 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4300 | out.rv = ReadTransaction(trans, &out.response_data); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4301 | EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); |
| 4302 | |
| 4303 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4304 | helper.VerifyDataConsumed(); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4305 | } |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4306 | |
bnc | a7f994a | 2015-01-20 19:39:41 | [diff] [blame] | 4307 | // HTTP_1_1_REQUIRED results in ERR_HTTP_1_1_REQUIRED. |
| 4308 | TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredError) { |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 4309 | // HTTP_1_1_REQUIRED is only supported by HTTP/2. |
| 4310 | if (spdy_util_.spdy_version() < HTTP2) |
bnc | a7f994a | 2015-01-20 19:39:41 | [diff] [blame] | 4311 | return; |
| 4312 | |
| 4313 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 4314 | BoundNetLog(), GetParam(), nullptr); |
| 4315 | |
| 4316 | scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway( |
| 4317 | 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); |
| 4318 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4319 | CreateMockRead(*go_away, 0), |
bnc | a7f994a | 2015-01-20 19:39:41 | [diff] [blame] | 4320 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4321 | SequencedSocketData data(reads, arraysize(reads), nullptr, 0); |
bnc | a7f994a | 2015-01-20 19:39:41 | [diff] [blame] | 4322 | |
| 4323 | helper.RunToCompletion(&data); |
| 4324 | TransactionHelperResult out = helper.output(); |
| 4325 | EXPECT_EQ(ERR_HTTP_1_1_REQUIRED, out.rv); |
| 4326 | } |
| 4327 | |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4328 | // Retry with HTTP/1.1 when receiving HTTP_1_1_REQUIRED. Note that no actual |
| 4329 | // protocol negotiation happens, instead this test forces protocols for both |
| 4330 | // sockets. |
| 4331 | TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredRetry) { |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 4332 | // HTTP_1_1_REQUIRED is only supported by HTTP/2. |
| 4333 | if (spdy_util_.spdy_version() < HTTP2) |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4334 | return; |
| 4335 | // HTTP_1_1_REQUIRED implementation relies on the assumption that HTTP/2 is |
| 4336 | // only spoken over SSL. |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4337 | if (GetParam().ssl_type != HTTPS_SPDY_VIA_NPN) |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4338 | return; |
| 4339 | |
| 4340 | HttpRequestInfo request; |
| 4341 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4342 | request.url = GURL("https://www.example.org/"); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4343 | scoped_ptr<SpdySessionDependencies> session_deps( |
| 4344 | CreateSpdySessionDependencies(GetParam())); |
| 4345 | // Do not force SPDY so that second socket can negotiate HTTP/1.1. |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4346 | session_deps->next_protos = SpdyNextProtos(); |
| 4347 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 4348 | GetParam(), std::move(session_deps)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4349 | |
| 4350 | // First socket: HTTP/2 request rejected with HTTP_1_1_REQUIRED. |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4351 | const char* url = request.url.spec().c_str(); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4352 | scoped_ptr<SpdyHeaderBlock> headers(spdy_util_.ConstructGetHeaderBlock(url)); |
| 4353 | scoped_ptr<SpdyFrame> req( |
| 4354 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4355 | MockWrite writes0[] = {CreateMockWrite(*req, 0)}; |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4356 | scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway( |
| 4357 | 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4358 | MockRead reads0[] = {CreateMockRead(*go_away, 1)}; |
| 4359 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 4360 | arraysize(writes0)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4361 | |
| 4362 | scoped_ptr<SSLSocketDataProvider> ssl_provider0( |
| 4363 | new SSLSocketDataProvider(ASYNC, OK)); |
| 4364 | // Expect HTTP/2 protocols too in SSLConfig. |
| 4365 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4366 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY31); |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 4367 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP2); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4368 | // Force SPDY. |
| 4369 | ssl_provider0->SetNextProto(GetParam().protocol); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 4370 | helper.AddDataWithSSLSocketDataProvider(&data0, std::move(ssl_provider0)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4371 | |
| 4372 | // Second socket: falling back to HTTP/1.1. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4373 | MockWrite writes1[] = {MockWrite(ASYNC, 0, |
| 4374 | "GET / HTTP/1.1\r\n" |
| 4375 | "Host: www.example.org\r\n" |
| 4376 | "Connection: keep-alive\r\n\r\n")}; |
| 4377 | MockRead reads1[] = {MockRead(ASYNC, 1, |
| 4378 | "HTTP/1.1 200 OK\r\n" |
| 4379 | "Content-Length: 5\r\n\r\n" |
| 4380 | "hello")}; |
| 4381 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 4382 | arraysize(writes1)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4383 | |
| 4384 | scoped_ptr<SSLSocketDataProvider> ssl_provider1( |
| 4385 | new SSLSocketDataProvider(ASYNC, OK)); |
| 4386 | // Expect only HTTP/1.1 protocol in SSLConfig. |
| 4387 | ssl_provider1->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4388 | // Force HTTP/1.1. |
| 4389 | ssl_provider1->SetNextProto(kProtoHTTP11); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 4390 | helper.AddDataWithSSLSocketDataProvider(&data1, std::move(ssl_provider1)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4391 | |
| 4392 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 4393 | helper.session()->spdy_session_pool()->http_server_properties(); |
| 4394 | const HostPortPair host_port_pair = HostPortPair::FromURL(GURL(url)); |
| 4395 | EXPECT_FALSE(http_server_properties->RequiresHTTP11(host_port_pair)); |
| 4396 | |
| 4397 | helper.RunPreTestSetup(); |
| 4398 | helper.StartDefaultTest(); |
| 4399 | helper.FinishDefaultTestWithoutVerification(); |
| 4400 | helper.VerifyDataConsumed(); |
| 4401 | EXPECT_TRUE(http_server_properties->RequiresHTTP11(host_port_pair)); |
| 4402 | |
| 4403 | const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
| 4404 | ASSERT_TRUE(response != nullptr); |
| 4405 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 4406 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4407 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 4408 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, response->connection_info); |
| 4409 | EXPECT_TRUE(response->was_npn_negotiated); |
| 4410 | EXPECT_TRUE(request.url.SchemeIs("https")); |
| 4411 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 4412 | EXPECT_EQ(443, response->socket_address.port()); |
| 4413 | std::string response_data; |
| 4414 | ASSERT_EQ(OK, ReadTransaction(helper.trans(), &response_data)); |
| 4415 | EXPECT_EQ("hello", response_data); |
| 4416 | } |
| 4417 | |
| 4418 | // Retry with HTTP/1.1 to the proxy when receiving HTTP_1_1_REQUIRED from the |
| 4419 | // proxy. Note that no actual protocol negotiation happens, instead this test |
| 4420 | // forces protocols for both sockets. |
| 4421 | TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredProxyRetry) { |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 4422 | // HTTP_1_1_REQUIRED is only supported by HTTP/2. |
| 4423 | if (spdy_util_.spdy_version() < HTTP2) |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4424 | return; |
| 4425 | // HTTP_1_1_REQUIRED implementation relies on the assumption that HTTP/2 is |
| 4426 | // only spoken over SSL. |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4427 | if (GetParam().ssl_type != HTTPS_SPDY_VIA_NPN) |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4428 | return; |
| 4429 | |
| 4430 | HttpRequestInfo request; |
| 4431 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4432 | request.url = GURL("https://www.example.org/"); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4433 | scoped_ptr<SpdySessionDependencies> session_deps( |
| 4434 | CreateSpdySessionDependencies( |
| 4435 | GetParam(), |
| 4436 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"))); |
| 4437 | // Do not force SPDY so that second socket can negotiate HTTP/1.1. |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4438 | session_deps->next_protos = SpdyNextProtos(); |
| 4439 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 4440 | GetParam(), std::move(session_deps)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4441 | |
| 4442 | // First socket: HTTP/2 CONNECT rejected with HTTP_1_1_REQUIRED. |
| 4443 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4444 | nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4445 | MockWrite writes0[] = {CreateMockWrite(*req, 0)}; |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4446 | scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway( |
| 4447 | 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4448 | MockRead reads0[] = {CreateMockRead(*go_away, 1)}; |
| 4449 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 4450 | arraysize(writes0)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4451 | |
| 4452 | scoped_ptr<SSLSocketDataProvider> ssl_provider0( |
| 4453 | new SSLSocketDataProvider(ASYNC, OK)); |
| 4454 | // Expect HTTP/2 protocols too in SSLConfig. |
| 4455 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4456 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY31); |
bnc | 06d2243 | 2015-06-29 12:39:43 | [diff] [blame] | 4457 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP2); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4458 | // Force SPDY. |
| 4459 | ssl_provider0->SetNextProto(GetParam().protocol); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 4460 | helper.AddDataWithSSLSocketDataProvider(&data0, std::move(ssl_provider0)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4461 | |
| 4462 | // Second socket: retry using HTTP/1.1. |
| 4463 | MockWrite writes1[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4464 | MockWrite(ASYNC, 0, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4465 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4466 | "Host: www.example.org:443\r\n" |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4467 | "Proxy-Connection: keep-alive\r\n\r\n"), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4468 | MockWrite(ASYNC, 2, |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4469 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4470 | "Host: www.example.org\r\n" |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4471 | "Connection: keep-alive\r\n\r\n"), |
| 4472 | }; |
| 4473 | |
| 4474 | MockRead reads1[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4475 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 4476 | MockRead(ASYNC, 3, |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4477 | "HTTP/1.1 200 OK\r\n" |
| 4478 | "Content-Length: 5\r\n\r\n" |
| 4479 | "hello"), |
| 4480 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4481 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 4482 | arraysize(writes1)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4483 | |
| 4484 | scoped_ptr<SSLSocketDataProvider> ssl_provider1( |
| 4485 | new SSLSocketDataProvider(ASYNC, OK)); |
| 4486 | // Expect only HTTP/1.1 protocol in SSLConfig. |
| 4487 | ssl_provider1->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4488 | // Force HTTP/1.1. |
| 4489 | ssl_provider1->SetNextProto(kProtoHTTP11); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 4490 | helper.AddDataWithSSLSocketDataProvider(&data1, std::move(ssl_provider1)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4491 | |
| 4492 | // A third socket is needed for the tunnelled connection. |
| 4493 | scoped_ptr<SSLSocketDataProvider> ssl_provider2( |
| 4494 | new SSLSocketDataProvider(ASYNC, OK)); |
| 4495 | helper.session_deps()->socket_factory->AddSSLSocketDataProvider( |
| 4496 | ssl_provider2.get()); |
| 4497 | |
| 4498 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 4499 | helper.session()->spdy_session_pool()->http_server_properties(); |
| 4500 | const HostPortPair proxy_host_port_pair = HostPortPair("myproxy", 70); |
| 4501 | EXPECT_FALSE(http_server_properties->RequiresHTTP11(proxy_host_port_pair)); |
| 4502 | |
| 4503 | helper.RunPreTestSetup(); |
| 4504 | helper.StartDefaultTest(); |
| 4505 | helper.FinishDefaultTestWithoutVerification(); |
| 4506 | helper.VerifyDataConsumed(); |
| 4507 | EXPECT_TRUE(http_server_properties->RequiresHTTP11(proxy_host_port_pair)); |
| 4508 | |
| 4509 | const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
| 4510 | ASSERT_TRUE(response != nullptr); |
| 4511 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 4512 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4513 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 4514 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, response->connection_info); |
| 4515 | EXPECT_FALSE(response->was_npn_negotiated); |
| 4516 | EXPECT_TRUE(request.url.SchemeIs("https")); |
| 4517 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 4518 | EXPECT_EQ(70, response->socket_address.port()); |
| 4519 | std::string response_data; |
| 4520 | ASSERT_EQ(OK, ReadTransaction(helper.trans(), &response_data)); |
| 4521 | EXPECT_EQ("hello", response_data); |
| 4522 | } |
| 4523 | |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4524 | // Test to make sure we can correctly connect through a proxy. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4525 | TEST_P(SpdyNetworkTransactionTest, ProxyConnect) { |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4526 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4527 | BoundNetLog(), GetParam(), NULL); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4528 | helper.session_deps() = CreateSpdySessionDependencies( |
| 4529 | GetParam(), ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4530 | helper.SetSession( |
| 4531 | SpdySessionDependencies::SpdyCreateSession(helper.session_deps().get())); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4532 | helper.RunPreTestSetup(); |
| 4533 | HttpNetworkTransaction* trans = helper.trans(); |
| 4534 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4535 | const char kConnect443[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4536 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4537 | "Host: www.example.org:443\r\n" |
rch | cb934f56 | 2015-04-07 16:25:12 | [diff] [blame] | 4538 | "Proxy-Connection: keep-alive\r\n\r\n"}; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4539 | const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4540 | scoped_ptr<SpdyFrame> req( |
| 4541 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4542 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4543 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4544 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4545 | MockWrite writes[] = { |
| 4546 | MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0), |
| 4547 | CreateMockWrite(*req, 2), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4548 | }; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4549 | MockRead reads[] = { |
| 4550 | MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), |
| 4551 | CreateMockRead(*resp, 3), |
| 4552 | CreateMockRead(*body.get(), 4), |
| 4553 | MockRead(ASYNC, 0, 0, 5), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4554 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4555 | scoped_ptr<SequencedSocketData> data(new SequencedSocketData( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4556 | reads, arraysize(reads), writes, arraysize(writes))); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4557 | |
| 4558 | helper.AddData(data.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4559 | TestCompletionCallback callback; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4560 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4561 | int rv = trans->Start( |
| 4562 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4563 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4564 | |
| 4565 | rv = callback.WaitForResult(); |
| 4566 | EXPECT_EQ(0, rv); |
| 4567 | |
| 4568 | // Verify the SYN_REPLY. |
| 4569 | HttpResponseInfo response = *trans->GetResponseInfo(); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4570 | ASSERT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4571 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4572 | |
| 4573 | std::string response_data; |
| 4574 | ASSERT_EQ(OK, ReadTransaction(trans, &response_data)); |
| 4575 | EXPECT_EQ("hello!", response_data); |
| 4576 | helper.VerifyDataConsumed(); |
| 4577 | } |
| 4578 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4579 | // Test to make sure we can correctly connect through a proxy to |
| 4580 | // www.example.org, if there already exists a direct spdy connection to |
| 4581 | // www.example.org. See https://crbug.com/49874. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4582 | TEST_P(SpdyNetworkTransactionTest, DirectConnectProxyReconnect) { |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4583 | // When setting up the first transaction, we store the SpdySessionPool so that |
| 4584 | // we can use the same pool in the second transaction. |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4585 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4586 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 733b7a6d | 2010-08-25 01:38:43 | [diff] [blame] | 4587 | |
| 4588 | // Use a proxy service which returns a proxy fallback list from DIRECT to |
| 4589 | // myproxy:70. For this test there will be no fallback, so it is equivalent |
| 4590 | // to simply DIRECT. The reason for appending the second proxy is to verify |
| 4591 | // that the session pool key used does is just "DIRECT". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4592 | helper.session_deps() = CreateSpdySessionDependencies( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4593 | GetParam(), |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4594 | ProxyService::CreateFixedFromPacResult("DIRECT; PROXY myproxy:70")); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4595 | helper.SetSession( |
| 4596 | SpdySessionDependencies::SpdyCreateSession(helper.session_deps().get())); |
[email protected] | 733b7a6d | 2010-08-25 01:38:43 | [diff] [blame] | 4597 | |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 4598 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4599 | helper.RunPreTestSetup(); |
| 4600 | |
| 4601 | // Construct and send a simple GET request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4602 | scoped_ptr<SpdyFrame> req( |
| 4603 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4604 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4605 | CreateMockWrite(*req, 0), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4606 | }; |
| 4607 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4608 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4609 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4610 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4611 | CreateMockRead(*resp, 1), |
| 4612 | CreateMockRead(*body, 2), |
| 4613 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), // Force a pause |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4614 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4615 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4616 | helper.AddData(&data); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4617 | HttpNetworkTransaction* trans = helper.trans(); |
| 4618 | |
[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 | TransactionHelperResult out; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4621 | out.rv = trans->Start( |
| 4622 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4623 | |
| 4624 | EXPECT_EQ(out.rv, ERR_IO_PENDING); |
| 4625 | out.rv = callback.WaitForResult(); |
| 4626 | EXPECT_EQ(out.rv, OK); |
| 4627 | |
| 4628 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4629 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4630 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4631 | out.rv = ReadTransaction(trans, &out.response_data); |
| 4632 | EXPECT_EQ(OK, out.rv); |
| 4633 | out.status_line = response->headers->GetStatusLine(); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4634 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4635 | EXPECT_EQ("hello!", out.response_data); |
| 4636 | |
| 4637 | // Check that the SpdySession is still in the SpdySessionPool. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4638 | HostPortPair host_port_pair("www.example.org", helper.port()); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 4639 | SpdySessionKey session_pool_key_direct( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 4640 | host_port_pair, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 4641 | EXPECT_TRUE(HasSpdySession(spdy_session_pool, session_pool_key_direct)); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 4642 | SpdySessionKey session_pool_key_proxy( |
[email protected] | 31e68d7 | 2010-08-25 06:36:58 | [diff] [blame] | 4643 | host_port_pair, |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 4644 | ProxyServer::FromURI("www.foo.com", ProxyServer::SCHEME_HTTP), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 4645 | PRIVACY_MODE_DISABLED); |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 4646 | EXPECT_FALSE(HasSpdySession(spdy_session_pool, session_pool_key_proxy)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4647 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4648 | // New SpdyTestUtil instance for the session that will be used for the |
| 4649 | // proxy connection. |
| 4650 | SpdyTestUtil spdy_util_2(GetParam().protocol, |
| 4651 | GetParam().priority_to_dependency); |
| 4652 | |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4653 | // Set up data for the proxy connection. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4654 | const char kConnect443[] = { |
| 4655 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4656 | "Host: www.example.org:443\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4657 | "Proxy-Connection: keep-alive\r\n\r\n"}; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4658 | const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4659 | scoped_ptr<SpdyFrame> req2(spdy_util_2.ConstructSpdyGet( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4660 | GetDefaultUrlWithPath("/foo.dat").c_str(), false, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4661 | scoped_ptr<SpdyFrame> resp2(spdy_util_2.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4662 | scoped_ptr<SpdyFrame> body2(spdy_util_2.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4663 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4664 | MockWrite writes2[] = { |
| 4665 | MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0), |
| 4666 | CreateMockWrite(*req2, 2), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4667 | }; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4668 | MockRead reads2[] = { |
| 4669 | MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), |
| 4670 | CreateMockRead(*resp2, 3), |
| 4671 | CreateMockRead(*body2, 4), |
| 4672 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4673 | }; |
| 4674 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4675 | scoped_ptr<SequencedSocketData> data_proxy(new SequencedSocketData( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4676 | reads2, arraysize(reads2), writes2, arraysize(writes2))); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4677 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4678 | // Create another request to www.example.org, but this time through a proxy. |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4679 | HttpRequestInfo request_proxy; |
| 4680 | request_proxy.method = "GET"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4681 | request_proxy.url = GURL(GetDefaultUrlWithPath("/foo.dat")); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4682 | request_proxy.load_flags = 0; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4683 | scoped_ptr<SpdySessionDependencies> ssd_proxy( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4684 | CreateSpdySessionDependencies(GetParam())); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4685 | // Ensure that this transaction uses the same SpdySessionPool. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4686 | scoped_ptr<HttpNetworkSession> session_proxy( |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 4687 | SpdySessionDependencies::SpdyCreateSession(ssd_proxy.get())); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4688 | NormalSpdyTransactionHelper helper_proxy(request_proxy, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4689 | BoundNetLog(), GetParam(), NULL); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4690 | HttpNetworkSessionPeer session_peer(session_proxy.get()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4691 | scoped_ptr<ProxyService> proxy_service( |
| 4692 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 4693 | session_peer.SetProxyService(proxy_service.get()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4694 | helper_proxy.session_deps().swap(ssd_proxy); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 4695 | helper_proxy.SetSession(std::move(session_proxy)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4696 | helper_proxy.RunPreTestSetup(); |
| 4697 | helper_proxy.AddData(data_proxy.get()); |
| 4698 | |
| 4699 | HttpNetworkTransaction* trans_proxy = helper_proxy.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4700 | TestCompletionCallback callback_proxy; |
| 4701 | int rv = trans_proxy->Start( |
| 4702 | &request_proxy, callback_proxy.callback(), BoundNetLog()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4703 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4704 | rv = callback_proxy.WaitForResult(); |
| 4705 | EXPECT_EQ(0, rv); |
| 4706 | |
| 4707 | HttpResponseInfo response_proxy = *trans_proxy->GetResponseInfo(); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4708 | ASSERT_TRUE(response_proxy.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4709 | EXPECT_EQ("HTTP/1.1 200", response_proxy.headers->GetStatusLine()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4710 | |
| 4711 | std::string response_data; |
| 4712 | ASSERT_EQ(OK, ReadTransaction(trans_proxy, &response_data)); |
| 4713 | EXPECT_EQ("hello!", response_data); |
| 4714 | |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4715 | helper_proxy.VerifyDataConsumed(); |
| 4716 | } |
| 4717 | |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4718 | // When we get a TCP-level RST, we need to retry a HttpNetworkTransaction |
| 4719 | // on a new connection, if the connection was previously known to be good. |
| 4720 | // This can happen when a server reboots without saying goodbye, or when |
| 4721 | // we're behind a NAT that masked the RST. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4722 | TEST_P(SpdyNetworkTransactionTest, VerifyRetryOnConnectionReset) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4723 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4724 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4725 | MockRead reads[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4726 | CreateMockRead(*resp, 1), |
| 4727 | CreateMockRead(*body, 2), |
| 4728 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 4729 | MockRead(ASYNC, ERR_CONNECTION_RESET, 4), |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4730 | }; |
| 4731 | |
| 4732 | MockRead reads2[] = { |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4733 | CreateMockRead(*resp, 1), |
| 4734 | CreateMockRead(*body, 2), |
| 4735 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4736 | }; |
| 4737 | |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4738 | scoped_ptr<SpdyFrame> req( |
| 4739 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4740 | // In all cases the connection will be reset before req3 can be |
| 4741 | // dispatched, destroying both streams. |
| 4742 | spdy_util_.UpdateWithStreamDestruction(1); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4743 | scoped_ptr<SpdyFrame> req3( |
| 4744 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
| 4745 | MockWrite writes1[] = {CreateMockWrite(*req, 0), CreateMockWrite(*req3, 5)}; |
| 4746 | MockWrite writes2[] = {CreateMockWrite(*req, 0)}; |
| 4747 | |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4748 | // This test has a couple of variants. |
| 4749 | enum { |
| 4750 | // Induce the RST while waiting for our transaction to send. |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4751 | VARIANT_RST_DURING_SEND_COMPLETION = 0, |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4752 | // Induce the RST while waiting for our transaction to read. |
| 4753 | // In this case, the send completed - everything copied into the SNDBUF. |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4754 | VARIANT_RST_DURING_READ_COMPLETION = 1 |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4755 | }; |
| 4756 | |
| 4757 | for (int variant = VARIANT_RST_DURING_SEND_COMPLETION; |
| 4758 | variant <= VARIANT_RST_DURING_READ_COMPLETION; |
| 4759 | ++variant) { |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4760 | SequencedSocketData data1(reads, arraysize(reads), writes1, 1 + variant); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4761 | |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4762 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 4763 | arraysize(writes2)); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4764 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4765 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4766 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4767 | helper.AddData(&data1); |
| 4768 | helper.AddData(&data2); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4769 | helper.RunPreTestSetup(); |
| 4770 | |
| 4771 | for (int i = 0; i < 2; ++i) { |
| 4772 | scoped_ptr<HttpNetworkTransaction> trans( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4773 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4774 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4775 | TestCompletionCallback callback; |
| 4776 | int rv = trans->Start( |
| 4777 | &helper.request(), callback.callback(), BoundNetLog()); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4778 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4779 | // On the second transaction, we trigger the RST. |
| 4780 | if (i == 1) { |
| 4781 | if (variant == VARIANT_RST_DURING_READ_COMPLETION) { |
| 4782 | // Writes to the socket complete asynchronously on SPDY by running |
| 4783 | // through the message loop. Complete the write here. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4784 | base::RunLoop().RunUntilIdle(); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4785 | } |
| 4786 | |
| 4787 | // Now schedule the ERR_CONNECTION_RESET. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 4788 | data1.Resume(); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4789 | } |
| 4790 | rv = callback.WaitForResult(); |
| 4791 | EXPECT_EQ(OK, rv); |
| 4792 | |
| 4793 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 351ab64 | 2010-08-05 16:55:31 | [diff] [blame] | 4794 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4795 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4796 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4797 | std::string response_data; |
| 4798 | rv = ReadTransaction(trans.get(), &response_data); |
| 4799 | EXPECT_EQ(OK, rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4800 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4801 | EXPECT_EQ("hello!", response_data); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4802 | base::RunLoop().RunUntilIdle(); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4803 | } |
| 4804 | |
| 4805 | helper.VerifyDataConsumed(); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 4806 | base::RunLoop().RunUntilIdle(); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4807 | } |
| 4808 | } |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4809 | |
| 4810 | // Test that turning SPDY on and off works properly. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4811 | TEST_P(SpdyNetworkTransactionTest, SpdyOnOffToggle) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 4812 | HttpStreamFactory::set_spdy_enabled(true); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4813 | scoped_ptr<SpdyFrame> req( |
| 4814 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4815 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4816 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4817 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4818 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4819 | MockRead spdy_reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4820 | CreateMockRead(*resp, 1), |
| 4821 | CreateMockRead(*body, 2), |
| 4822 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4823 | }; |
| 4824 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4825 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4826 | arraysize(spdy_writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4827 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4828 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4829 | helper.RunToCompletion(&data); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4830 | TransactionHelperResult out = helper.output(); |
| 4831 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4832 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4833 | EXPECT_EQ("hello!", out.response_data); |
| 4834 | |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4835 | HttpStreamFactory::set_spdy_enabled(false); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4836 | MockWrite http_writes[] = { |
| 4837 | MockWrite(SYNCHRONOUS, 0, |
| 4838 | "GET / HTTP/1.1\r\n" |
| 4839 | "Host: www.example.org\r\n" |
| 4840 | "Connection: keep-alive\r\n\r\n"), |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4841 | }; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4842 | |
| 4843 | MockRead http_reads[] = { |
| 4844 | MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 4845 | MockRead(SYNCHRONOUS, 2, "hello from http"), |
| 4846 | MockRead(SYNCHRONOUS, OK, 3), |
| 4847 | }; |
| 4848 | SequencedSocketData data2(http_reads, arraysize(http_reads), http_writes, |
| 4849 | arraysize(http_writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4850 | NormalSpdyTransactionHelper helper2(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4851 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4852 | helper2.SetSpdyDisabled(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4853 | helper2.RunToCompletion(&data2); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4854 | TransactionHelperResult out2 = helper2.output(); |
| 4855 | EXPECT_EQ(OK, out2.rv); |
| 4856 | EXPECT_EQ("HTTP/1.1 200 OK", out2.status_line); |
| 4857 | EXPECT_EQ("hello from http", out2.response_data); |
| 4858 | |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4859 | HttpStreamFactory::set_spdy_enabled(true); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4860 | } |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4861 | |
| 4862 | // Tests that Basic authentication works over SPDY |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4863 | TEST_P(SpdyNetworkTransactionTest, SpdyBasicAuth) { |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4864 | HttpStreamFactory::set_spdy_enabled(true); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4865 | |
| 4866 | // The first request will be a bare GET, the second request will be a |
| 4867 | // GET with an Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4868 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4869 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4870 | // Will be refused for lack of auth. |
| 4871 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4872 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4873 | "authorization", "Basic Zm9vOmJhcg==" |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4874 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4875 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4876 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 4877 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 4878 | false, 3, LOWEST, true)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4879 | MockWrite spdy_writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4880 | CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4881 | }; |
| 4882 | |
| 4883 | // The first response is a 401 authentication challenge, and the second |
| 4884 | // response will be a 200 response since the second request includes a valid |
| 4885 | // Authorization header. |
| 4886 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | fb9e431 | 2012-02-17 06:27:26 | [diff] [blame] | 4887 | "www-authenticate", |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4888 | "Basic realm=\"MyRealm\"" |
| 4889 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4890 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4891 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4892 | "401 Authentication Required", |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4893 | kExtraAuthenticationHeaders, |
| 4894 | arraysize(kExtraAuthenticationHeaders) / 2, |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4895 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4896 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4897 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4898 | scoped_ptr<SpdyFrame> resp_data( |
| 4899 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4900 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4901 | MockRead spdy_reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4902 | CreateMockRead(*resp_authentication, 1), |
| 4903 | CreateMockRead(*body_authentication, 2), |
| 4904 | CreateMockRead(*resp_data, 4), |
| 4905 | CreateMockRead(*body_data, 5), |
| 4906 | MockRead(ASYNC, 0, 6), |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4907 | }; |
| 4908 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4909 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4910 | arraysize(spdy_writes)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4911 | HttpRequestInfo request(CreateGetRequest()); |
| 4912 | BoundNetLog net_log; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4913 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 4914 | net_log, GetParam(), NULL); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4915 | |
| 4916 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4917 | helper.AddData(&data); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4918 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4919 | TestCompletionCallback callback; |
| 4920 | const int rv_start = trans->Start(&request, callback.callback(), net_log); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4921 | EXPECT_EQ(ERR_IO_PENDING, rv_start); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4922 | const int rv_start_complete = callback.WaitForResult(); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4923 | EXPECT_EQ(OK, rv_start_complete); |
| 4924 | |
| 4925 | // Make sure the response has an auth challenge. |
| 4926 | const HttpResponseInfo* const response_start = trans->GetResponseInfo(); |
| 4927 | ASSERT_TRUE(response_start != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4928 | ASSERT_TRUE(response_start->headers.get() != NULL); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4929 | EXPECT_EQ(401, response_start->headers->response_code()); |
| 4930 | EXPECT_TRUE(response_start->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4931 | AuthChallengeInfo* auth_challenge = response_start->auth_challenge.get(); |
| 4932 | ASSERT_TRUE(auth_challenge != NULL); |
| 4933 | EXPECT_FALSE(auth_challenge->is_proxy); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 4934 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4935 | EXPECT_EQ("MyRealm", auth_challenge->realm); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4936 | |
| 4937 | // Restart with a username/password. |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 4938 | AuthCredentials credentials(base::ASCIIToUTF16("foo"), |
| 4939 | base::ASCIIToUTF16("bar")); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4940 | TestCompletionCallback callback_restart; |
| 4941 | const int rv_restart = trans->RestartWithAuth( |
| 4942 | credentials, callback_restart.callback()); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4943 | EXPECT_EQ(ERR_IO_PENDING, rv_restart); |
| 4944 | const int rv_restart_complete = callback_restart.WaitForResult(); |
| 4945 | EXPECT_EQ(OK, rv_restart_complete); |
| 4946 | // TODO(cbentzel): This is actually the same response object as before, but |
| 4947 | // data has changed. |
| 4948 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 4949 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4950 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4951 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4952 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 4953 | } |
| 4954 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4955 | TEST_P(SpdyNetworkTransactionTest, ServerPushWithHeaders) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4956 | scoped_ptr<SpdyFrame> stream1_syn( |
| 4957 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4958 | scoped_ptr<SpdyFrame> stream1_body( |
| 4959 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4960 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4961 | CreateMockWrite(*stream1_syn, 0), |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4962 | }; |
| 4963 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4964 | scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4965 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
| 4966 | initial_headers.get()); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 4967 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame( |
| 4968 | std::move(initial_headers), 2, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4969 | |
| 4970 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4971 | (*late_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 4972 | (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 4973 | (*late_headers)["hello"] = "bye"; |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 4974 | scoped_ptr<SpdyFrame> stream2_headers(spdy_util_.ConstructSpdyControlFrame( |
| 4975 | std::move(late_headers), false, 2, LOWEST, HEADERS, CONTROL_FLAG_NONE, |
| 4976 | 0)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4977 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4978 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4979 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 4980 | const char kPushedData[] = "pushed"; |
| 4981 | scoped_ptr<SpdyFrame> stream2_body( |
| 4982 | spdy_util_.ConstructSpdyBodyFrame( |
| 4983 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4984 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4985 | CreateMockRead(*stream1_reply, 1), |
| 4986 | CreateMockRead(*stream2_syn, 2), |
| 4987 | CreateMockRead(*stream2_headers, 3), |
| 4988 | CreateMockRead(*stream1_body, 4, SYNCHRONOUS), |
| 4989 | CreateMockRead(*stream2_body, 5), |
| 4990 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a pause |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4991 | }; |
| 4992 | |
| 4993 | HttpResponseInfo response; |
| 4994 | HttpResponseInfo response2; |
| 4995 | std::string expected_push_result("pushed"); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 4996 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4997 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4998 | &response, |
| 4999 | &response2, |
| 5000 | expected_push_result); |
| 5001 | |
| 5002 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5003 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5004 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5005 | |
| 5006 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5007 | EXPECT_TRUE(response2.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5008 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5009 | } |
| 5010 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5011 | TEST_P(SpdyNetworkTransactionTest, ServerPushClaimBeforeHeaders) { |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5012 | // 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] | 5013 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5014 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5015 | scoped_ptr<SpdyFrame> stream1_body( |
| 5016 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5017 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5018 | CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5019 | }; |
| 5020 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5021 | scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5022 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
| 5023 | initial_headers.get()); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 5024 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame( |
| 5025 | std::move(initial_headers), 2, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5026 | |
| 5027 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5028 | (*late_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 5029 | (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 5030 | (*late_headers)["hello"] = "bye"; |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 5031 | scoped_ptr<SpdyFrame> stream2_headers(spdy_util_.ConstructSpdyControlFrame( |
| 5032 | std::move(late_headers), false, 2, LOWEST, HEADERS, CONTROL_FLAG_NONE, |
| 5033 | 0)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5034 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5035 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5036 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5037 | const char kPushedData[] = "pushed"; |
| 5038 | scoped_ptr<SpdyFrame> stream2_body( |
| 5039 | spdy_util_.ConstructSpdyBodyFrame( |
| 5040 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5041 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5042 | CreateMockRead(*stream1_reply, 1), CreateMockRead(*stream2_syn, 2), |
| 5043 | CreateMockRead(*stream1_body, 3), MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 5044 | CreateMockRead(*stream2_headers, 5), CreateMockRead(*stream2_body, 6), |
| 5045 | MockRead(ASYNC, ERR_IO_PENDING, 7), MockRead(ASYNC, 0, 8), // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5046 | }; |
| 5047 | |
| 5048 | HttpResponseInfo response; |
| 5049 | HttpResponseInfo response2; |
| 5050 | std::string expected_push_result("pushed"); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5051 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5052 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5053 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5054 | BoundNetLog(), GetParam(), NULL); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5055 | helper.AddData(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5056 | helper.RunPreTestSetup(); |
| 5057 | |
| 5058 | HttpNetworkTransaction* trans = helper.trans(); |
| 5059 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5060 | // Start the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5061 | TestCompletionCallback callback; |
| 5062 | int rv = trans->Start( |
| 5063 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5064 | EXPECT_EQ(ERR_IO_PENDING, rv); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5065 | // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM, |
| 5066 | // and the body of the primary stream, but before we've received the HEADERS |
| 5067 | // for the pushed stream. |
| 5068 | data.RunUntilPaused(); |
| 5069 | EXPECT_EQ(OK, callback.WaitForResult()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5070 | |
| 5071 | // Request the pushed path. At this point, we've received the push, but the |
| 5072 | // headers are not yet complete. |
| 5073 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5074 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5075 | rv = trans2->Start( |
| 5076 | &CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5077 | EXPECT_EQ(ERR_IO_PENDING, rv); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5078 | data.Resume(); |
| 5079 | data.RunUntilPaused(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5080 | base::RunLoop().RunUntilIdle(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5081 | |
| 5082 | // Read the server push body. |
| 5083 | std::string result2; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 5084 | ReadResult(trans2.get(), &result2); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5085 | // Read the response body. |
| 5086 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 5087 | ReadResult(trans, &result); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5088 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5089 | // Verify that the received push data is same as the expected push data. |
| 5090 | EXPECT_EQ(result2.compare(expected_push_result), 0) |
| 5091 | << "Received data: " |
| 5092 | << result2 |
| 5093 | << "||||| Expected data: " |
| 5094 | << expected_push_result; |
| 5095 | |
| 5096 | // Verify the SYN_REPLY. |
| 5097 | // Copy the response info, because trans goes away. |
| 5098 | response = *trans->GetResponseInfo(); |
| 5099 | response2 = *trans2->GetResponseInfo(); |
| 5100 | |
| 5101 | VerifyStreamsClosed(helper); |
| 5102 | |
| 5103 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5104 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5105 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5106 | |
| 5107 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5108 | EXPECT_TRUE(response2.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5109 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 5110 | |
| 5111 | // Read the final EOF (which will close the session) |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5112 | data.Resume(); |
| 5113 | base::RunLoop().RunUntilIdle(); |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 5114 | |
| 5115 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 5116 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 5117 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5118 | } |
| 5119 | |
[email protected] | 6cd63ba | 2014-06-12 16:14:56 | [diff] [blame] | 5120 | // TODO(baranovich): HTTP 2 does not allow multiple HEADERS frames |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5121 | TEST_P(SpdyNetworkTransactionTest, ServerPushWithTwoHeaderFrames) { |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5122 | // 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] | 5123 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5124 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5125 | scoped_ptr<SpdyFrame> stream1_body( |
| 5126 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5127 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5128 | CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5129 | }; |
| 5130 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5131 | scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 5132 | if (spdy_util_.spdy_version() < HTTP2) { |
| 5133 | // 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] | 5134 | (*initial_headers)["alpha"] = "beta"; |
| 5135 | } |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5136 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
| 5137 | initial_headers.get()); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 5138 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame( |
| 5139 | std::move(initial_headers), 2, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5140 | |
| 5141 | scoped_ptr<SpdyHeaderBlock> middle_headers(new SpdyHeaderBlock()); |
| 5142 | (*middle_headers)["hello"] = "bye"; |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 5143 | scoped_ptr<SpdyFrame> stream2_headers1(spdy_util_.ConstructSpdyControlFrame( |
| 5144 | std::move(middle_headers), false, 2, LOWEST, HEADERS, CONTROL_FLAG_NONE, |
| 5145 | 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5146 | |
| 5147 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5148 | (*late_headers)[spdy_util_.GetStatusKey()] = "200"; |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 5149 | if (spdy_util_.spdy_version() < HTTP2) { |
| 5150 | // HTTP/2 eliminates use of the :version header. |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5151 | (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
| 5152 | } |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 5153 | scoped_ptr<SpdyFrame> stream2_headers2(spdy_util_.ConstructSpdyControlFrame( |
| 5154 | std::move(late_headers), false, 2, LOWEST, HEADERS, CONTROL_FLAG_NONE, |
| 5155 | 0)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5156 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5157 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5158 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5159 | const char kPushedData[] = "pushed"; |
| 5160 | scoped_ptr<SpdyFrame> stream2_body( |
| 5161 | spdy_util_.ConstructSpdyBodyFrame( |
| 5162 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5163 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5164 | CreateMockRead(*stream1_reply, 1), CreateMockRead(*stream2_syn, 2), |
| 5165 | CreateMockRead(*stream1_body, 3), MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 5166 | CreateMockRead(*stream2_headers1, 5), |
| 5167 | // This is needed to work around https://crbug.com/571102. |
| 5168 | MockRead(ASYNC, ERR_IO_PENDING, 6), CreateMockRead(*stream2_headers2, 7), |
| 5169 | CreateMockRead(*stream2_body, 8), MockRead(ASYNC, ERR_IO_PENDING, 9), |
| 5170 | MockRead(ASYNC, 0, 10), // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5171 | }; |
| 5172 | |
| 5173 | HttpResponseInfo response; |
| 5174 | HttpResponseInfo response2; |
| 5175 | std::string expected_push_result("pushed"); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5176 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5177 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5178 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5179 | BoundNetLog(), GetParam(), NULL); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5180 | helper.AddData(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5181 | helper.RunPreTestSetup(); |
| 5182 | |
| 5183 | HttpNetworkTransaction* trans = helper.trans(); |
| 5184 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5185 | // Start the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5186 | TestCompletionCallback callback; |
| 5187 | int rv = trans->Start( |
| 5188 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5189 | EXPECT_EQ(ERR_IO_PENDING, rv); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5190 | // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM, |
| 5191 | // the first HEADERS frame, and the body of the primary stream, but before |
| 5192 | // we've received the final HEADERS for the pushed stream. |
| 5193 | data.RunUntilPaused(); |
| 5194 | EXPECT_EQ(0, callback.WaitForResult()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5195 | |
| 5196 | // Request the pushed path. At this point, we've received the push, but the |
| 5197 | // headers are not yet complete. |
| 5198 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5199 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5200 | rv = trans2->Start( |
| 5201 | &CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5202 | EXPECT_EQ(ERR_IO_PENDING, rv); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5203 | data.Resume(); |
| 5204 | data.RunUntilPaused(); |
| 5205 | base::RunLoop().RunUntilIdle(); |
| 5206 | // This is needed to work around https://crbug.com/571102. |
| 5207 | data.Resume(); |
| 5208 | data.RunUntilPaused(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5209 | base::RunLoop().RunUntilIdle(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5210 | |
| 5211 | // Read the server push body. |
| 5212 | std::string result2; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 5213 | ReadResult(trans2.get(), &result2); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5214 | // Read the response body. |
| 5215 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 5216 | ReadResult(trans, &result); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5217 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5218 | // Verify that the received push data is same as the expected push data. |
[email protected] | 6d116e1a | 2013-06-24 07:42:15 | [diff] [blame] | 5219 | EXPECT_EQ(expected_push_result, result2); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5220 | |
| 5221 | // Verify the SYN_REPLY. |
| 5222 | // Copy the response info, because trans goes away. |
| 5223 | response = *trans->GetResponseInfo(); |
| 5224 | response2 = *trans2->GetResponseInfo(); |
| 5225 | |
| 5226 | VerifyStreamsClosed(helper); |
| 5227 | |
| 5228 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5229 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5230 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5231 | |
| 5232 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5233 | EXPECT_TRUE(response2.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5234 | EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5235 | |
[email protected] | 6cd63ba | 2014-06-12 16:14:56 | [diff] [blame] | 5236 | // Verify we got all the headers from all header blocks. |
bnc | acac4f8a | 2015-06-18 12:24:49 | [diff] [blame] | 5237 | if (spdy_util_.spdy_version() < HTTP2) |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 5238 | EXPECT_TRUE(response2.headers->HasHeaderValue("alpha", "beta")); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5239 | EXPECT_TRUE(response2.headers->HasHeaderValue("hello", "bye")); |
| 5240 | EXPECT_TRUE(response2.headers->HasHeaderValue("status", "200")); |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 5241 | |
| 5242 | // Read the final EOF (which will close the session) |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5243 | data.Resume(); |
| 5244 | base::RunLoop().RunUntilIdle(); |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 5245 | |
| 5246 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 5247 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 5248 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5249 | } |
| 5250 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5251 | TEST_P(SpdyNetworkTransactionTest, ServerPushWithNoStatusHeaderFrames) { |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5252 | // 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] | 5253 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5254 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5255 | scoped_ptr<SpdyFrame> stream1_body( |
| 5256 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5257 | MockWrite writes[] = { |
| 5258 | CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), |
| 5259 | }; |
| 5260 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5261 | scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5262 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
| 5263 | initial_headers.get()); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 5264 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame( |
| 5265 | std::move(initial_headers), 2, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5266 | |
| 5267 | scoped_ptr<SpdyHeaderBlock> middle_headers(new SpdyHeaderBlock()); |
| 5268 | (*middle_headers)["hello"] = "bye"; |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 5269 | scoped_ptr<SpdyFrame> stream2_headers1(spdy_util_.ConstructSpdyControlFrame( |
| 5270 | std::move(middle_headers), false, 2, LOWEST, HEADERS, CONTROL_FLAG_NONE, |
| 5271 | 0)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5272 | |
| 5273 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5274 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5275 | const char kPushedData[] = "pushed"; |
| 5276 | scoped_ptr<SpdyFrame> stream2_body( |
| 5277 | spdy_util_.ConstructSpdyBodyFrame( |
| 5278 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5279 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5280 | CreateMockRead(*stream1_reply, 1), CreateMockRead(*stream2_syn, 2), |
| 5281 | CreateMockRead(*stream1_body, 3), MockRead(ASYNC, ERR_IO_PENDING, 4), |
| 5282 | CreateMockRead(*stream2_headers1, 5), CreateMockRead(*stream2_body, 6), |
| 5283 | MockRead(ASYNC, ERR_IO_PENDING, 7), MockRead(ASYNC, 0, 8), // EOF |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5284 | }; |
| 5285 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5286 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5287 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5288 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5289 | BoundNetLog(), GetParam(), NULL); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5290 | helper.AddData(&data); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5291 | helper.RunPreTestSetup(); |
| 5292 | |
| 5293 | HttpNetworkTransaction* trans = helper.trans(); |
| 5294 | |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5295 | // Start the transaction. |
| 5296 | TestCompletionCallback callback; |
| 5297 | int rv = trans->Start( |
| 5298 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 5299 | EXPECT_EQ(ERR_IO_PENDING, rv); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5300 | // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM, |
| 5301 | // the first HEADERS frame, and the body of the primary stream, but before |
| 5302 | // we've received the final HEADERS for the pushed stream. |
| 5303 | data.RunUntilPaused(); |
| 5304 | EXPECT_EQ(0, callback.WaitForResult()); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5305 | |
| 5306 | // Request the pushed path. At this point, we've received the push, but the |
| 5307 | // headers are not yet complete. |
| 5308 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5309 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session())); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5310 | rv = trans2->Start( |
| 5311 | &CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
| 5312 | EXPECT_EQ(ERR_IO_PENDING, rv); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5313 | data.Resume(); |
| 5314 | data.RunUntilPaused(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5315 | base::RunLoop().RunUntilIdle(); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5316 | |
| 5317 | // Read the server push body. |
| 5318 | std::string result2; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 5319 | ReadResult(trans2.get(), &result2); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5320 | // Read the response body. |
| 5321 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 5322 | ReadResult(trans, &result); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5323 | EXPECT_EQ("hello!", result); |
| 5324 | |
| 5325 | // Verify that we haven't received any push data. |
| 5326 | EXPECT_EQ("", result2); |
| 5327 | |
| 5328 | // Verify the SYN_REPLY. |
| 5329 | // Copy the response info, because trans goes away. |
| 5330 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5331 | |
| 5332 | VerifyStreamsClosed(helper); |
| 5333 | |
| 5334 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5335 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5336 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5337 | |
| 5338 | // Read the final EOF (which will close the session). |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5339 | data.Resume(); |
| 5340 | base::RunLoop().RunUntilIdle(); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5341 | |
| 5342 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 5343 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 5344 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5345 | } |
| 5346 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5347 | TEST_P(SpdyNetworkTransactionTest, SynReplyWithHeaders) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5348 | scoped_ptr<SpdyFrame> req( |
| 5349 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5350 | scoped_ptr<SpdyFrame> rst( |
| 5351 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 5352 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5353 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 4), |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5354 | }; |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5355 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5356 | scoped_ptr<SpdyFrame> stream1_reply( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5357 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5358 | |
| 5359 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5360 | (*late_headers)["hello"] = "bye"; |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 5361 | scoped_ptr<SpdyFrame> stream1_headers(spdy_util_.ConstructSpdyControlFrame( |
| 5362 | std::move(late_headers), false, 1, LOWEST, HEADERS, CONTROL_FLAG_NONE, |
| 5363 | 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5364 | scoped_ptr<SpdyFrame> stream1_body( |
| 5365 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5366 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5367 | CreateMockRead(*stream1_reply, 1), |
| 5368 | CreateMockRead(*stream1_headers, 2), |
| 5369 | CreateMockRead(*stream1_body, 3), |
| 5370 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5371 | }; |
| 5372 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5373 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5374 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5375 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5376 | helper.RunToCompletion(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5377 | TransactionHelperResult out = helper.output(); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5378 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5379 | } |
| 5380 | |
xunjieli | 294da72 | 2015-08-11 19:15:02 | [diff] [blame] | 5381 | // Tests that receiving HEADERS, DATA, HEADERS, and DATA in that sequence will |
| 5382 | // trigger a ERR_SPDY_PROTOCOL_ERROR because trailing HEADERS must not be |
| 5383 | // followed by any DATA frames. |
| 5384 | TEST_P(SpdyNetworkTransactionTest, SyncReplyDataAfterTrailers) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5385 | scoped_ptr<SpdyFrame> req( |
| 5386 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5387 | scoped_ptr<SpdyFrame> rst( |
| 5388 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 5389 | MockWrite writes[] = { |
xunjieli | 294da72 | 2015-08-11 19:15:02 | [diff] [blame] | 5390 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 5), |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5391 | }; |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5392 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5393 | scoped_ptr<SpdyFrame> stream1_reply( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5394 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5395 | |
| 5396 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5397 | (*late_headers)["hello"] = "bye"; |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 5398 | scoped_ptr<SpdyFrame> stream1_headers(spdy_util_.ConstructSpdyControlFrame( |
| 5399 | std::move(late_headers), false, 1, LOWEST, HEADERS, CONTROL_FLAG_NONE, |
| 5400 | 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5401 | scoped_ptr<SpdyFrame> stream1_body( |
| 5402 | spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 5403 | scoped_ptr<SpdyFrame> stream1_body2( |
| 5404 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5405 | MockRead reads[] = { |
xunjieli | 294da72 | 2015-08-11 19:15:02 | [diff] [blame] | 5406 | CreateMockRead(*stream1_reply, 1), CreateMockRead(*stream1_body, 2), |
| 5407 | CreateMockRead(*stream1_headers, 3), CreateMockRead(*stream1_body2, 4), |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5408 | MockRead(ASYNC, 0, 6) // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5409 | }; |
| 5410 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5411 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5412 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5413 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5414 | helper.RunToCompletion(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5415 | TransactionHelperResult out = helper.output(); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5416 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5417 | } |
| 5418 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5419 | TEST_P(SpdyNetworkTransactionTest, ServerPushCrossOriginCorrectness) { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5420 | // Running these tests via Alt-Svc is too complicated to be worthwhile. |
| 5421 | if (GetParam().ssl_type != HTTPS_SPDY_VIA_NPN) |
| 5422 | return; |
| 5423 | |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5424 | // In this test we want to verify that we can't accidentally push content |
| 5425 | // which can't be pushed by this content server. |
| 5426 | // This test assumes that: |
| 5427 | // - if we're requesting http://www.foo.com/barbaz |
| 5428 | // - the browser has made a connection to "www.foo.com". |
| 5429 | |
| 5430 | // A list of the URL to fetch, followed by the URL being pushed. |
| 5431 | static const char* const kTestCases[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5432 | "https://www.example.org/foo.html", |
| 5433 | "https://www.example.org:81/foo.js", // Bad port |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5434 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5435 | "https://www.example.org/foo.html", |
| 5436 | "http://www.example.org/foo.js", // Bad protocol |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5437 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5438 | "https://www.example.org/foo.html", |
| 5439 | "ftp://www.example.org/foo.js", // Invalid Protocol |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5440 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5441 | "https://www.example.org/foo.html", |
| 5442 | "https://blat.www.example.org/foo.js", // Cross subdomain |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5443 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5444 | "https://www.example.org/foo.html", |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5445 | "https://www.foo.com/foo.js", // Cross domain |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5446 | }; |
| 5447 | |
[email protected] | b3f89933 | 2010-12-08 18:20:44 | [diff] [blame] | 5448 | for (size_t index = 0; index < arraysize(kTestCases); index += 2) { |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5449 | const char* url_to_fetch = kTestCases[index]; |
| 5450 | const char* url_to_push = kTestCases[index + 1]; |
| 5451 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5452 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5453 | spdy_util_.ConstructSpdyGet(url_to_fetch, false, 1, LOWEST)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5454 | scoped_ptr<SpdyFrame> stream1_body( |
| 5455 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5456 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5457 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5458 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5459 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5460 | CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*push_rst, 3), |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5461 | }; |
| 5462 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5463 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5464 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5465 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5466 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
| 5467 | 0, |
| 5468 | 2, |
| 5469 | 1, |
| 5470 | url_to_push)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5471 | const char kPushedData[] = "pushed"; |
| 5472 | scoped_ptr<SpdyFrame> stream2_body( |
| 5473 | spdy_util_.ConstructSpdyBodyFrame( |
| 5474 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5475 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5476 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_CANCEL)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5477 | |
| 5478 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5479 | CreateMockRead(*stream1_reply, 1), |
| 5480 | CreateMockRead(*stream2_syn, 2), |
| 5481 | CreateMockRead(*stream1_body, 4), |
| 5482 | CreateMockRead(*stream2_body, 5), |
| 5483 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a pause |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5484 | }; |
| 5485 | |
| 5486 | HttpResponseInfo response; |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5487 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 5488 | arraysize(writes)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5489 | |
| 5490 | HttpRequestInfo request; |
| 5491 | request.method = "GET"; |
| 5492 | request.url = GURL(url_to_fetch); |
| 5493 | request.load_flags = 0; |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5494 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 5495 | // Enable cross-origin push. Since we are not using a proxy, this should |
| 5496 | // not actually enable cross-origin SPDY push. |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5497 | scoped_ptr<SpdySessionDependencies> session_deps( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5498 | CreateSpdySessionDependencies(GetParam())); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5499 | session_deps->trusted_spdy_proxy = "123.45.67.89:8080"; |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5500 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 5501 | GetParam(), std::move(session_deps)); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5502 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5503 | helper.AddData(&data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 5504 | |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5505 | HttpNetworkTransaction* trans = helper.trans(); |
| 5506 | |
| 5507 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5508 | TestCompletionCallback callback; |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5509 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5510 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5511 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5512 | rv = callback.WaitForResult(); |
| 5513 | |
| 5514 | // Read the response body. |
| 5515 | std::string result; |
rch | 0aecfd8 | 2015-05-19 17:22:32 | [diff] [blame] | 5516 | ReadResult(trans, &result); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5517 | |
| 5518 | // Verify that we consumed all test data. |
rch | 37de576c | 2015-05-17 20:28:17 | [diff] [blame] | 5519 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 5520 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5521 | |
| 5522 | // Verify the SYN_REPLY. |
| 5523 | // Copy the response info, because trans goes away. |
| 5524 | response = *trans->GetResponseInfo(); |
| 5525 | |
| 5526 | VerifyStreamsClosed(helper); |
| 5527 | |
| 5528 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5529 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5530 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5531 | } |
| 5532 | } |
| 5533 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5534 | TEST_P(SpdyNetworkTransactionTest, RetryAfterRefused) { |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5535 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5536 | scoped_ptr<SpdyFrame> req( |
| 5537 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5538 | // Will be destroyed by the RST before stream 3 starts. |
| 5539 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5540 | scoped_ptr<SpdyFrame> req2( |
| 5541 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5542 | MockWrite writes[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5543 | CreateMockWrite(*req, 0), CreateMockWrite(*req2, 2), |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5544 | }; |
| 5545 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5546 | scoped_ptr<SpdyFrame> refused( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5547 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5548 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 5549 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5550 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5551 | CreateMockRead(*refused, 1), |
| 5552 | CreateMockRead(*resp, 3), |
| 5553 | CreateMockRead(*body, 4), |
| 5554 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5555 | }; |
| 5556 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5557 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5558 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5559 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5560 | |
| 5561 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5562 | helper.AddData(&data); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5563 | |
| 5564 | HttpNetworkTransaction* trans = helper.trans(); |
| 5565 | |
| 5566 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5567 | TestCompletionCallback callback; |
| 5568 | int rv = trans->Start( |
| 5569 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5570 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5571 | rv = callback.WaitForResult(); |
| 5572 | EXPECT_EQ(OK, rv); |
| 5573 | |
| 5574 | // Verify that we consumed all test data. |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 5575 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 5576 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5577 | |
| 5578 | // Verify the SYN_REPLY. |
| 5579 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5580 | EXPECT_TRUE(response.headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5581 | EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5582 | } |
| 5583 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5584 | TEST_P(SpdyNetworkTransactionTest, OutOfOrderSynStream) { |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5585 | // This first request will start to establish the SpdySession. |
| 5586 | // Then we will start the second (MEDIUM priority) and then third |
| 5587 | // (HIGHEST priority) request in such a way that the third will actually |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 5588 | // start before the second, causing the second to be numbered differently |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5589 | // than the order they were created. |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5590 | // |
| 5591 | // Note that the requests and responses created below are expectations |
| 5592 | // of what the above will produce on the wire, and hence are in the |
| 5593 | // initial->HIGHEST->LOWEST priority. |
| 5594 | // |
| 5595 | // Frames are created by SpdySession just before the write associated |
| 5596 | // with the frame is attempted, so stream dependencies will be based |
| 5597 | // on the streams alive at the point of the request write attempt. Thus |
| 5598 | // req1 is alive when req2 is attempted (during but not after the |
| 5599 | // |data.RunFor(2);| statement below) but not when req3 is attempted. |
| 5600 | // The call to spdy_util_.UpdateWithStreamDestruction() reflects this. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5601 | scoped_ptr<SpdyFrame> req1( |
| 5602 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5603 | scoped_ptr<SpdyFrame> req2( |
| 5604 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, HIGHEST, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5605 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5606 | scoped_ptr<SpdyFrame> req3( |
| 5607 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, MEDIUM, true)); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5608 | MockWrite writes[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5609 | MockWrite(ASYNC, ERR_IO_PENDING, 0), CreateMockWrite(*req1, 1), |
| 5610 | CreateMockWrite(*req2, 5), CreateMockWrite(*req3, 6), |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5611 | }; |
| 5612 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5613 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 5614 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 5615 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 5616 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 5617 | scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 5618 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5619 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5620 | CreateMockRead(*resp1, 2), MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 5621 | CreateMockRead(*body1, 4), CreateMockRead(*resp2, 7), |
| 5622 | CreateMockRead(*body2, 8), CreateMockRead(*resp3, 9), |
| 5623 | CreateMockRead(*body3, 10), MockRead(ASYNC, 0, 11) // EOF |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5624 | }; |
| 5625 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5626 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5627 | NormalSpdyTransactionHelper helper(CreateGetRequest(), LOWEST, |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5628 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5629 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5630 | helper.AddData(&data); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5631 | |
| 5632 | // Start the first transaction to set up the SpdySession |
| 5633 | HttpNetworkTransaction* trans = helper.trans(); |
| 5634 | TestCompletionCallback callback; |
| 5635 | HttpRequestInfo info1 = CreateGetRequest(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5636 | int rv = trans->Start(&info1, callback.callback(), BoundNetLog()); |
| 5637 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5638 | |
| 5639 | // Run the message loop, but do not allow the write to complete. |
| 5640 | // This leaves the SpdySession with a write pending, which prevents |
| 5641 | // SpdySession from attempting subsequent writes until this write completes. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5642 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5643 | |
| 5644 | // Now, start both new transactions |
| 5645 | HttpRequestInfo info2 = CreateGetRequest(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5646 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5647 | scoped_ptr<HttpNetworkTransaction> trans2( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5648 | new HttpNetworkTransaction(MEDIUM, helper.session())); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5649 | rv = trans2->Start(&info2, callback2.callback(), BoundNetLog()); |
| 5650 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5651 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5652 | |
| 5653 | HttpRequestInfo info3 = CreateGetRequest(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5654 | TestCompletionCallback callback3; |
| 5655 | scoped_ptr<HttpNetworkTransaction> trans3( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 5656 | new HttpNetworkTransaction(HIGHEST, helper.session())); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5657 | rv = trans3->Start(&info3, callback3.callback(), BoundNetLog()); |
| 5658 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5659 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5660 | |
| 5661 | // We now have two SYN_STREAM frames queued up which will be |
| 5662 | // dequeued only once the first write completes, which we |
| 5663 | // now allow to happen. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5664 | ASSERT_TRUE(data.IsPaused()); |
| 5665 | data.Resume(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5666 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5667 | |
| 5668 | // And now we can allow everything else to run to completion. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5669 | data.Resume(); |
| 5670 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5671 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 5672 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 5673 | |
| 5674 | helper.VerifyDataConsumed(); |
| 5675 | } |
| 5676 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5677 | // The tests below are only for SPDY/3 and above. |
| 5678 | |
| 5679 | // Test that sent data frames and received WINDOW_UPDATE frames change |
| 5680 | // the send_window_size_ correctly. |
| 5681 | |
| 5682 | // WINDOW_UPDATE is different than most other frames in that it can arrive |
| 5683 | // while the client is still sending the request body. In order to enforce |
| 5684 | // this scenario, we feed a couple of dummy frames and give a delay of 0 to |
| 5685 | // socket data provider, so that initial read that is done as soon as the |
| 5686 | // stream is created, succeeds and schedules another read. This way reads |
| 5687 | // and writes are interleaved; after doing a full frame write, SpdyStream |
| 5688 | // will break out of DoLoop and will read and process a WINDOW_UPDATE. |
| 5689 | // Once our WINDOW_UPDATE is read, we cannot send SYN_REPLY right away |
| 5690 | // since request has not been completely written, therefore we feed |
| 5691 | // enough number of WINDOW_UPDATEs to finish the first read and cause a |
| 5692 | // write, leading to a complete write of request body; after that we send |
| 5693 | // a reply with a body, to cause a graceful shutdown. |
| 5694 | |
| 5695 | // TODO(agayev): develop a socket data provider where both, reads and |
| 5696 | // writes are ordered so that writing tests like these are easy and rewrite |
| 5697 | // all these tests using it. Right now we are working around the |
| 5698 | // limitations as described above and it's not deterministic, tests may |
| 5699 | // fail under specific circumstances. |
| 5700 | TEST_P(SpdyNetworkTransactionTest, WindowUpdateReceived) { |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5701 | static int kFrameCount = 2; |
| 5702 | scoped_ptr<std::string> content( |
| 5703 | new std::string(kMaxSpdyFrameChunkSize, 'a')); |
| 5704 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5705 | GetDefaultUrl(), 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, NULL, |
| 5706 | 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5707 | scoped_ptr<SpdyFrame> body( |
| 5708 | spdy_util_.ConstructSpdyBodyFrame( |
| 5709 | 1, content->c_str(), content->size(), false)); |
| 5710 | scoped_ptr<SpdyFrame> body_end( |
| 5711 | spdy_util_.ConstructSpdyBodyFrame( |
| 5712 | 1, content->c_str(), content->size(), true)); |
| 5713 | |
| 5714 | MockWrite writes[] = { |
| 5715 | CreateMockWrite(*req, 0), |
| 5716 | CreateMockWrite(*body, 1), |
| 5717 | CreateMockWrite(*body_end, 2), |
| 5718 | }; |
| 5719 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5720 | static const int32_t kDeltaWindowSize = 0xff; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5721 | static const int kDeltaCount = 4; |
| 5722 | scoped_ptr<SpdyFrame> window_update( |
| 5723 | spdy_util_.ConstructSpdyWindowUpdate(1, kDeltaWindowSize)); |
| 5724 | scoped_ptr<SpdyFrame> window_update_dummy( |
| 5725 | spdy_util_.ConstructSpdyWindowUpdate(2, kDeltaWindowSize)); |
| 5726 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 5727 | MockRead reads[] = { |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5728 | CreateMockRead(*window_update_dummy, 3), |
| 5729 | CreateMockRead(*window_update_dummy, 4), |
| 5730 | CreateMockRead(*window_update_dummy, 5), |
| 5731 | CreateMockRead(*window_update, 6), // Four updates, therefore window |
| 5732 | CreateMockRead(*window_update, 7), // size should increase by |
| 5733 | CreateMockRead(*window_update, 8), // kDeltaWindowSize * 4 |
| 5734 | CreateMockRead(*window_update, 9), CreateMockRead(*resp, 10), |
| 5735 | MockRead(ASYNC, ERR_IO_PENDING, 11), CreateMockRead(*body_end, 12), |
| 5736 | MockRead(ASYNC, 0, 13) // EOF |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5737 | }; |
| 5738 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5739 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5740 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5741 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5742 | for (int i = 0; i < kFrameCount; ++i) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5743 | element_readers.push_back(make_scoped_ptr( |
| 5744 | new UploadBytesElementReader(content->c_str(), content->size()))); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5745 | } |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5746 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5747 | |
| 5748 | // Setup the request |
| 5749 | HttpRequestInfo request; |
| 5750 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5751 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5752 | request.upload_data_stream = &upload_data_stream; |
| 5753 | |
| 5754 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 5755 | BoundNetLog(), GetParam(), NULL); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5756 | helper.AddData(&data); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5757 | helper.RunPreTestSetup(); |
| 5758 | |
| 5759 | HttpNetworkTransaction* trans = helper.trans(); |
| 5760 | |
| 5761 | TestCompletionCallback callback; |
| 5762 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 5763 | |
| 5764 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5765 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5766 | data.RunUntilPaused(); |
| 5767 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5768 | |
| 5769 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 5770 | ASSERT_TRUE(stream != NULL); |
| 5771 | ASSERT_TRUE(stream->stream() != NULL); |
bnc | 638c470 | 2015-04-09 18:01:18 | [diff] [blame] | 5772 | EXPECT_EQ(static_cast<int>( |
| 5773 | SpdySession::GetDefaultInitialWindowSize(GetParam().protocol)) + |
| 5774 | kDeltaWindowSize * kDeltaCount - |
| 5775 | kMaxSpdyFrameChunkSize * kFrameCount, |
| 5776 | stream->stream()->send_window_size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5777 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5778 | data.Resume(); |
| 5779 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5780 | |
| 5781 | rv = callback.WaitForResult(); |
| 5782 | EXPECT_EQ(OK, rv); |
| 5783 | |
| 5784 | helper.VerifyDataConsumed(); |
| 5785 | } |
| 5786 | |
| 5787 | // Test that received data frames and sent WINDOW_UPDATE frames change |
| 5788 | // the recv_window_size_ correctly. |
| 5789 | TEST_P(SpdyNetworkTransactionTest, WindowUpdateSent) { |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5790 | const int32_t default_initial_window_size = |
bnc | 638c470 | 2015-04-09 18:01:18 | [diff] [blame] | 5791 | SpdySession::GetDefaultInitialWindowSize(GetParam().protocol); |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5792 | // Session level maximum window size that is more than twice the default |
| 5793 | // initial window size so that an initial window update is sent. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5794 | const int32_t session_max_recv_window_size = 5 * 64 * 1024; |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5795 | ASSERT_LT(2 * default_initial_window_size, session_max_recv_window_size); |
| 5796 | // Stream level maximum window size that is less than the session level |
| 5797 | // maximum window size so that we test for confusion between the two. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5798 | const int32_t stream_max_recv_window_size = 4 * 64 * 1024; |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5799 | ASSERT_GT(session_max_recv_window_size, stream_max_recv_window_size); |
| 5800 | // Size of body to be sent. Has to be less than or equal to both window sizes |
| 5801 | // so that we do not run out of receiving window. Also has to be greater than |
| 5802 | // half of them so that it triggers both a session level and a stream level |
| 5803 | // window update frame. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5804 | const int32_t kTargetSize = 3 * 64 * 1024; |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5805 | ASSERT_GE(session_max_recv_window_size, kTargetSize); |
| 5806 | ASSERT_GE(stream_max_recv_window_size, kTargetSize); |
| 5807 | ASSERT_LT(session_max_recv_window_size / 2, kTargetSize); |
| 5808 | ASSERT_LT(stream_max_recv_window_size / 2, kTargetSize); |
| 5809 | // Size of each DATA frame. |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5810 | const int32_t kChunkSize = 4096; |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5811 | // Size of window updates. |
| 5812 | ASSERT_EQ(0, session_max_recv_window_size / 2 % kChunkSize); |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5813 | const int32_t session_window_update_delta = |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5814 | session_max_recv_window_size / 2 + kChunkSize; |
| 5815 | ASSERT_EQ(0, stream_max_recv_window_size / 2 % kChunkSize); |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5816 | const int32_t stream_window_update_delta = |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5817 | stream_max_recv_window_size / 2 + kChunkSize; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5818 | |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5819 | SettingsMap initial_settings; |
| 5820 | initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 5821 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); |
| 5822 | initial_settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
| 5823 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, stream_max_recv_window_size); |
| 5824 | scoped_ptr<SpdyFrame> initial_settings_frame( |
| 5825 | spdy_util_.ConstructSpdySettings(initial_settings)); |
| 5826 | scoped_ptr<SpdyFrame> initial_window_update( |
| 5827 | spdy_util_.ConstructSpdyWindowUpdate( |
| 5828 | kSessionFlowControlStreamId, |
| 5829 | session_max_recv_window_size - default_initial_window_size)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5830 | scoped_ptr<SpdyFrame> req( |
| 5831 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5832 | scoped_ptr<SpdyFrame> session_window_update( |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5833 | spdy_util_.ConstructSpdyWindowUpdate(0, session_window_update_delta)); |
| 5834 | scoped_ptr<SpdyFrame> stream_window_update( |
| 5835 | spdy_util_.ConstructSpdyWindowUpdate(1, stream_window_update_delta)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5836 | |
| 5837 | std::vector<MockWrite> writes; |
bnc | 9b79a57 | 2015-09-02 12:25:03 | [diff] [blame] | 5838 | if (GetParam().protocol == kProtoHTTP2) { |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5839 | writes.push_back(MockWrite(ASYNC, kHttp2ConnectionHeaderPrefix, |
| 5840 | kHttp2ConnectionHeaderPrefixSize, 0)); |
| 5841 | } |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5842 | writes.push_back(CreateMockWrite(*initial_settings_frame, writes.size())); |
| 5843 | writes.push_back(CreateMockWrite(*initial_window_update, writes.size())); |
| 5844 | writes.push_back(CreateMockWrite(*req, writes.size())); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5845 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5846 | std::vector<MockRead> reads; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5847 | scoped_ptr<SpdyFrame> resp( |
| 5848 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5849 | reads.push_back(CreateMockRead(*resp, writes.size() + reads.size())); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5850 | |
olli.raula | 1b62114 | 2015-12-15 07:04:13 | [diff] [blame] | 5851 | std::vector<scoped_ptr<SpdyFrame>> body_frames; |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5852 | const std::string body_data(kChunkSize, 'x'); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5853 | for (size_t remaining = kTargetSize; remaining != 0;) { |
| 5854 | size_t frame_size = std::min(remaining, body_data.size()); |
olli.raula | 1b62114 | 2015-12-15 07:04:13 | [diff] [blame] | 5855 | body_frames.push_back(make_scoped_ptr(spdy_util_.ConstructSpdyBodyFrame( |
| 5856 | 1, body_data.data(), frame_size, false))); |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5857 | reads.push_back( |
| 5858 | CreateMockRead(*body_frames.back(), writes.size() + reads.size())); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5859 | remaining -= frame_size; |
| 5860 | } |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5861 | // Yield. |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5862 | reads.push_back( |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5863 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, writes.size() + reads.size())); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5864 | |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5865 | writes.push_back( |
| 5866 | CreateMockWrite(*session_window_update, writes.size() + reads.size())); |
| 5867 | writes.push_back( |
| 5868 | CreateMockWrite(*stream_window_update, writes.size() + reads.size())); |
| 5869 | |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 5870 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 5871 | writes.size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5872 | |
| 5873 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 5874 | BoundNetLog(), GetParam(), NULL); |
| 5875 | helper.AddData(&data); |
| 5876 | helper.RunPreTestSetup(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5877 | |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5878 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
| 5879 | SpdySessionPoolPeer pool_peer(spdy_session_pool); |
| 5880 | pool_peer.SetEnableSendingInitialData(true); |
| 5881 | pool_peer.SetSessionMaxRecvWindowSize(session_max_recv_window_size); |
| 5882 | pool_peer.SetStreamInitialRecvWindowSize(stream_max_recv_window_size); |
| 5883 | |
| 5884 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5885 | TestCompletionCallback callback; |
| 5886 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 5887 | |
| 5888 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5889 | rv = callback.WaitForResult(); |
| 5890 | EXPECT_EQ(OK, rv); |
| 5891 | |
| 5892 | SpdyHttpStream* stream = |
| 5893 | static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 5894 | ASSERT_TRUE(stream != NULL); |
| 5895 | ASSERT_TRUE(stream->stream() != NULL); |
| 5896 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5897 | // All data has been read, but not consumed. The window reflects this. |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5898 | EXPECT_EQ(static_cast<int>(stream_max_recv_window_size - kTargetSize), |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5899 | stream->stream()->recv_window_size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5900 | |
| 5901 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5902 | ASSERT_TRUE(response != NULL); |
| 5903 | ASSERT_TRUE(response->headers.get() != NULL); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5904 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5905 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 5906 | |
| 5907 | // Issue a read which will cause a WINDOW_UPDATE to be sent and window |
| 5908 | // size increased to default. |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 5909 | scoped_refptr<IOBuffer> buf(new IOBuffer(kTargetSize)); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5910 | EXPECT_EQ(static_cast<int>(kTargetSize), |
| 5911 | trans->Read(buf.get(), kTargetSize, CompletionCallback())); |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5912 | EXPECT_EQ(static_cast<int>(stream_max_recv_window_size), |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5913 | stream->stream()->recv_window_size()); |
| 5914 | EXPECT_THAT(base::StringPiece(buf->data(), kTargetSize), Each(Eq('x'))); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5915 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5916 | // Allow scheduled WINDOW_UPDATE frames to write. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5917 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5918 | helper.VerifyDataConsumed(); |
| 5919 | } |
| 5920 | |
| 5921 | // Test that WINDOW_UPDATE frame causing overflow is handled correctly. |
| 5922 | TEST_P(SpdyNetworkTransactionTest, WindowUpdateOverflow) { |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5923 | // Number of full frames we hope to write (but will not, used to |
| 5924 | // set content-length header correctly) |
| 5925 | static int kFrameCount = 3; |
| 5926 | |
| 5927 | scoped_ptr<std::string> content( |
| 5928 | new std::string(kMaxSpdyFrameChunkSize, 'a')); |
| 5929 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5930 | GetDefaultUrl(), 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, NULL, |
| 5931 | 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5932 | scoped_ptr<SpdyFrame> body( |
| 5933 | spdy_util_.ConstructSpdyBodyFrame( |
| 5934 | 1, content->c_str(), content->size(), false)); |
| 5935 | scoped_ptr<SpdyFrame> rst( |
| 5936 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_FLOW_CONTROL_ERROR)); |
| 5937 | |
| 5938 | // We're not going to write a data frame with FIN, we'll receive a bad |
| 5939 | // WINDOW_UPDATE while sending a request and will send a RST_STREAM frame. |
| 5940 | MockWrite writes[] = { |
| 5941 | CreateMockWrite(*req, 0), |
| 5942 | CreateMockWrite(*body, 2), |
| 5943 | CreateMockWrite(*rst, 3), |
| 5944 | }; |
| 5945 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 5946 | static const int32_t kDeltaWindowSize = 0x7fffffff; // cause an overflow |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5947 | scoped_ptr<SpdyFrame> window_update( |
| 5948 | spdy_util_.ConstructSpdyWindowUpdate(1, kDeltaWindowSize)); |
| 5949 | MockRead reads[] = { |
| 5950 | CreateMockRead(*window_update, 1), |
| 5951 | MockRead(ASYNC, 0, 4) // EOF |
| 5952 | }; |
| 5953 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5954 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5955 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5956 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5957 | for (int i = 0; i < kFrameCount; ++i) { |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5958 | element_readers.push_back(make_scoped_ptr( |
| 5959 | new UploadBytesElementReader(content->c_str(), content->size()))); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5960 | } |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 5961 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5962 | |
| 5963 | // Setup the request |
| 5964 | HttpRequestInfo request; |
| 5965 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5966 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5967 | request.upload_data_stream = &upload_data_stream; |
| 5968 | |
| 5969 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 5970 | BoundNetLog(), GetParam(), NULL); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5971 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5972 | helper.AddData(&data); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5973 | HttpNetworkTransaction* trans = helper.trans(); |
| 5974 | |
| 5975 | TestCompletionCallback callback; |
| 5976 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 5977 | ASSERT_EQ(ERR_IO_PENDING, rv); |
| 5978 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 5979 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5980 | ASSERT_TRUE(callback.have_result()); |
| 5981 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, callback.WaitForResult()); |
| 5982 | helper.VerifyDataConsumed(); |
| 5983 | } |
| 5984 | |
| 5985 | // Test that after hitting a send window size of 0, the write process |
| 5986 | // stalls and upon receiving WINDOW_UPDATE frame write resumes. |
| 5987 | |
| 5988 | // This test constructs a POST request followed by enough data frames |
| 5989 | // containing 'a' that would make the window size 0, followed by another |
| 5990 | // data frame containing default content (which is "hello!") and this frame |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 5991 | // also contains a FIN flag. SequencedSocketData is used to enforce all |
| 5992 | // writes, save the last, go through before a read could happen. The last frame |
| 5993 | // ("hello!") is not permitted to go through since by the time its turn |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5994 | // arrives, window size is 0. At this point MessageLoop::Run() called via |
| 5995 | // callback would block. Therefore we call MessageLoop::RunUntilIdle() |
| 5996 | // which returns after performing all possible writes. We use DCHECKS to |
| 5997 | // ensure that last data frame is still there and stream has stalled. |
| 5998 | // After that, next read is artifically enforced, which causes a |
| 5999 | // WINDOW_UPDATE to be read and I/O process resumes. |
| 6000 | TEST_P(SpdyNetworkTransactionTest, FlowControlStallResume) { |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 6001 | const int32_t initial_window_size = |
bnc | 638c470 | 2015-04-09 18:01:18 | [diff] [blame] | 6002 | SpdySession::GetDefaultInitialWindowSize(GetParam().protocol); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6003 | // Number of frames we need to send to zero out the window size: data |
| 6004 | // frames plus SYN_STREAM plus the last data frame; also we need another |
| 6005 | // data frame that we will send once the WINDOW_UPDATE is received, |
| 6006 | // therefore +3. |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6007 | size_t num_writes = initial_window_size / kMaxSpdyFrameChunkSize + 3; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6008 | |
| 6009 | // Calculate last frame's size; 0 size data frame is legal. |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6010 | size_t last_frame_size = initial_window_size % kMaxSpdyFrameChunkSize; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6011 | |
| 6012 | // Construct content for a data frame of maximum size. |
| 6013 | std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 6014 | |
| 6015 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6016 | GetDefaultUrl(), 1, initial_window_size + kUploadDataSize, LOWEST, NULL, |
| 6017 | 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6018 | |
| 6019 | // Full frames. |
| 6020 | scoped_ptr<SpdyFrame> body1( |
| 6021 | spdy_util_.ConstructSpdyBodyFrame( |
| 6022 | 1, content.c_str(), content.size(), false)); |
| 6023 | |
| 6024 | // Last frame to zero out the window size. |
| 6025 | scoped_ptr<SpdyFrame> body2( |
| 6026 | spdy_util_.ConstructSpdyBodyFrame( |
| 6027 | 1, content.c_str(), last_frame_size, false)); |
| 6028 | |
| 6029 | // Data frame to be sent once WINDOW_UPDATE frame is received. |
| 6030 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6031 | |
| 6032 | // Fill in mock writes. |
| 6033 | scoped_ptr<MockWrite[]> writes(new MockWrite[num_writes]); |
| 6034 | size_t i = 0; |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 6035 | writes[i] = CreateMockWrite(*req, i); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6036 | for (i = 1; i < num_writes - 2; i++) |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 6037 | writes[i] = CreateMockWrite(*body1, i); |
| 6038 | writes[i] = CreateMockWrite(*body2, i); |
| 6039 | // The last write must not be attempted until after the WINDOW_UPDATES |
| 6040 | // have been received. |
| 6041 | writes[i + 1] = CreateMockWrite(*body3, i + 4, SYNCHRONOUS); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6042 | |
| 6043 | // Construct read frame, give enough space to upload the rest of the |
| 6044 | // data. |
| 6045 | scoped_ptr<SpdyFrame> session_window_update( |
| 6046 | spdy_util_.ConstructSpdyWindowUpdate(0, kUploadDataSize)); |
| 6047 | scoped_ptr<SpdyFrame> window_update( |
| 6048 | spdy_util_.ConstructSpdyWindowUpdate(1, kUploadDataSize)); |
| 6049 | scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 6050 | MockRead reads[] = { |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 6051 | MockRead(ASYNC, ERR_IO_PENDING, i + 1), // Force a pause |
| 6052 | CreateMockRead(*session_window_update, i + 2), |
| 6053 | CreateMockRead(*window_update, i + 3), |
| 6054 | // Now the last write will occur. |
| 6055 | CreateMockRead(*reply, i + 5), |
| 6056 | CreateMockRead(*body2, i + 6), |
| 6057 | CreateMockRead(*body3, i + 7), |
| 6058 | MockRead(ASYNC, 0, i + 8) // EOF |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6059 | }; |
| 6060 | |
rch | acdcbdc | 2015-05-16 17:16:00 | [diff] [blame] | 6061 | SequencedSocketData data(reads, arraysize(reads), writes.get(), num_writes); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6062 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6063 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6064 | std::string upload_data_string(initial_window_size, 'a'); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6065 | upload_data_string.append(kUploadData, kUploadDataSize); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6066 | element_readers.push_back(make_scoped_ptr(new UploadBytesElementReader( |
| 6067 | upload_data_string.c_str(), upload_data_string.size()))); |
| 6068 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6069 | |
| 6070 | HttpRequestInfo request; |
| 6071 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6072 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6073 | request.upload_data_stream = &upload_data_stream; |
| 6074 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 6075 | BoundNetLog(), GetParam(), NULL); |
| 6076 | helper.AddData(&data); |
| 6077 | helper.RunPreTestSetup(); |
| 6078 | |
| 6079 | HttpNetworkTransaction* trans = helper.trans(); |
| 6080 | |
| 6081 | TestCompletionCallback callback; |
| 6082 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6083 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6084 | |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 6085 | base::RunLoop().RunUntilIdle(); // Write as much as we can. |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6086 | |
| 6087 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6088 | ASSERT_TRUE(stream != NULL); |
| 6089 | ASSERT_TRUE(stream->stream() != NULL); |
| 6090 | EXPECT_EQ(0, stream->stream()->send_window_size()); |
| 6091 | // All the body data should have been read. |
| 6092 | // TODO(satorux): This is because of the weirdness in reading the request |
| 6093 | // body in OnSendBodyComplete(). See crbug.com/113107. |
| 6094 | EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 6095 | // But the body is not yet fully sent (kUploadData is not yet sent) |
| 6096 | // since we're send-stalled. |
| 6097 | EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 6098 | |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 6099 | data.Resume(); // Read in WINDOW_UPDATE frame. |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6100 | rv = callback.WaitForResult(); |
| 6101 | helper.VerifyDataConsumed(); |
| 6102 | } |
| 6103 | |
| 6104 | // Test we correctly handle the case where the SETTINGS frame results in |
| 6105 | // unstalling the send window. |
| 6106 | TEST_P(SpdyNetworkTransactionTest, FlowControlStallResumeAfterSettings) { |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 6107 | const int32_t initial_window_size = |
bnc | 638c470 | 2015-04-09 18:01:18 | [diff] [blame] | 6108 | SpdySession::GetDefaultInitialWindowSize(GetParam().protocol); |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6109 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6110 | // Number of frames we need to send to zero out the window size: data |
| 6111 | // frames plus SYN_STREAM plus the last data frame; also we need another |
| 6112 | // data frame that we will send once the SETTING is received, therefore +3. |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6113 | size_t num_writes = initial_window_size / kMaxSpdyFrameChunkSize + 3; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6114 | |
| 6115 | // Calculate last frame's size; 0 size data frame is legal. |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6116 | size_t last_frame_size = initial_window_size % kMaxSpdyFrameChunkSize; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6117 | |
| 6118 | // Construct content for a data frame of maximum size. |
| 6119 | std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 6120 | |
| 6121 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6122 | GetDefaultUrl(), 1, initial_window_size + kUploadDataSize, LOWEST, NULL, |
| 6123 | 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6124 | |
| 6125 | // Full frames. |
| 6126 | scoped_ptr<SpdyFrame> body1( |
| 6127 | spdy_util_.ConstructSpdyBodyFrame( |
| 6128 | 1, content.c_str(), content.size(), false)); |
| 6129 | |
| 6130 | // Last frame to zero out the window size. |
| 6131 | scoped_ptr<SpdyFrame> body2( |
| 6132 | spdy_util_.ConstructSpdyBodyFrame( |
| 6133 | 1, content.c_str(), last_frame_size, false)); |
| 6134 | |
| 6135 | // Data frame to be sent once SETTINGS frame is received. |
| 6136 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6137 | |
| 6138 | // Fill in mock reads/writes. |
| 6139 | std::vector<MockRead> reads; |
| 6140 | std::vector<MockWrite> writes; |
| 6141 | size_t i = 0; |
| 6142 | writes.push_back(CreateMockWrite(*req, i++)); |
| 6143 | while (i < num_writes - 2) |
| 6144 | writes.push_back(CreateMockWrite(*body1, i++)); |
| 6145 | writes.push_back(CreateMockWrite(*body2, i++)); |
| 6146 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 6147 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, i++)); |
| 6148 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6149 | // Construct read frame for SETTINGS that gives enough space to upload the |
| 6150 | // rest of the data. |
| 6151 | SettingsMap settings; |
| 6152 | settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6153 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, initial_window_size * 2); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6154 | scoped_ptr<SpdyFrame> settings_frame_large( |
| 6155 | spdy_util_.ConstructSpdySettings(settings)); |
| 6156 | |
| 6157 | reads.push_back(CreateMockRead(*settings_frame_large, i++)); |
| 6158 | |
| 6159 | scoped_ptr<SpdyFrame> session_window_update( |
| 6160 | spdy_util_.ConstructSpdyWindowUpdate(0, kUploadDataSize)); |
| 6161 | if (GetParam().protocol >= kProtoSPDY31) |
| 6162 | reads.push_back(CreateMockRead(*session_window_update, i++)); |
| 6163 | |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 6164 | scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
| 6165 | writes.push_back(CreateMockWrite(*settings_ack, i++)); |
| 6166 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6167 | writes.push_back(CreateMockWrite(*body3, i++)); |
| 6168 | |
| 6169 | scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 6170 | reads.push_back(CreateMockRead(*reply, i++)); |
| 6171 | reads.push_back(CreateMockRead(*body2, i++)); |
| 6172 | reads.push_back(CreateMockRead(*body3, i++)); |
| 6173 | reads.push_back(MockRead(ASYNC, 0, i++)); // EOF |
| 6174 | |
| 6175 | // Force all writes to happen before any read, last write will not |
| 6176 | // actually queue a frame, due to window size being 0. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 6177 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 6178 | writes.size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6179 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6180 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6181 | std::string upload_data_string(initial_window_size, 'a'); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6182 | upload_data_string.append(kUploadData, kUploadDataSize); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6183 | element_readers.push_back(make_scoped_ptr(new UploadBytesElementReader( |
| 6184 | upload_data_string.c_str(), upload_data_string.size()))); |
| 6185 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6186 | |
| 6187 | HttpRequestInfo request; |
| 6188 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6189 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6190 | request.upload_data_stream = &upload_data_stream; |
| 6191 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 6192 | BoundNetLog(), GetParam(), NULL); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6193 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 6194 | helper.AddData(&data); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6195 | |
| 6196 | HttpNetworkTransaction* trans = helper.trans(); |
| 6197 | |
| 6198 | TestCompletionCallback callback; |
| 6199 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6200 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6201 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 6202 | data.RunUntilPaused(); // Write as much as we can. |
| 6203 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6204 | |
| 6205 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6206 | ASSERT_TRUE(stream != NULL); |
| 6207 | ASSERT_TRUE(stream->stream() != NULL); |
| 6208 | EXPECT_EQ(0, stream->stream()->send_window_size()); |
| 6209 | |
| 6210 | // All the body data should have been read. |
| 6211 | // TODO(satorux): This is because of the weirdness in reading the request |
| 6212 | // body in OnSendBodyComplete(). See crbug.com/113107. |
| 6213 | EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 6214 | // But the body is not yet fully sent (kUploadData is not yet sent) |
| 6215 | // since we're send-stalled. |
| 6216 | EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 6217 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 6218 | // Read in SETTINGS frame to unstall. |
| 6219 | data.Resume(); |
| 6220 | base::RunLoop().RunUntilIdle(); |
| 6221 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6222 | rv = callback.WaitForResult(); |
| 6223 | helper.VerifyDataConsumed(); |
| 6224 | // If stream is NULL, that means it was unstalled and closed. |
| 6225 | EXPECT_TRUE(stream->stream() == NULL); |
| 6226 | } |
| 6227 | |
| 6228 | // Test we correctly handle the case where the SETTINGS frame results in a |
| 6229 | // negative send window size. |
| 6230 | TEST_P(SpdyNetworkTransactionTest, FlowControlNegativeSendWindowSize) { |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 6231 | const int32_t initial_window_size = |
bnc | 638c470 | 2015-04-09 18:01:18 | [diff] [blame] | 6232 | SpdySession::GetDefaultInitialWindowSize(GetParam().protocol); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6233 | // Number of frames we need to send to zero out the window size: data |
| 6234 | // frames plus SYN_STREAM plus the last data frame; also we need another |
| 6235 | // data frame that we will send once the SETTING is received, therefore +3. |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6236 | size_t num_writes = initial_window_size / kMaxSpdyFrameChunkSize + 3; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6237 | |
| 6238 | // Calculate last frame's size; 0 size data frame is legal. |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6239 | size_t last_frame_size = initial_window_size % kMaxSpdyFrameChunkSize; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6240 | |
| 6241 | // Construct content for a data frame of maximum size. |
| 6242 | std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 6243 | |
| 6244 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6245 | GetDefaultUrl(), 1, initial_window_size + kUploadDataSize, LOWEST, NULL, |
| 6246 | 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6247 | |
| 6248 | // Full frames. |
| 6249 | scoped_ptr<SpdyFrame> body1( |
| 6250 | spdy_util_.ConstructSpdyBodyFrame( |
| 6251 | 1, content.c_str(), content.size(), false)); |
| 6252 | |
| 6253 | // Last frame to zero out the window size. |
| 6254 | scoped_ptr<SpdyFrame> body2( |
| 6255 | spdy_util_.ConstructSpdyBodyFrame( |
| 6256 | 1, content.c_str(), last_frame_size, false)); |
| 6257 | |
| 6258 | // Data frame to be sent once SETTINGS frame is received. |
| 6259 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6260 | |
| 6261 | // Fill in mock reads/writes. |
| 6262 | std::vector<MockRead> reads; |
| 6263 | std::vector<MockWrite> writes; |
| 6264 | size_t i = 0; |
| 6265 | writes.push_back(CreateMockWrite(*req, i++)); |
| 6266 | while (i < num_writes - 2) |
| 6267 | writes.push_back(CreateMockWrite(*body1, i++)); |
| 6268 | writes.push_back(CreateMockWrite(*body2, i++)); |
| 6269 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 6270 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, i++)); |
| 6271 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6272 | // Construct read frame for SETTINGS that makes the send_window_size |
| 6273 | // negative. |
| 6274 | SettingsMap new_settings; |
| 6275 | new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6276 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, initial_window_size / 2); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6277 | scoped_ptr<SpdyFrame> settings_frame_small( |
| 6278 | spdy_util_.ConstructSpdySettings(new_settings)); |
| 6279 | // Construct read frames for WINDOW_UPDATE that makes the send_window_size |
| 6280 | // positive. |
| 6281 | scoped_ptr<SpdyFrame> session_window_update_init_size( |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6282 | spdy_util_.ConstructSpdyWindowUpdate(0, initial_window_size)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6283 | scoped_ptr<SpdyFrame> window_update_init_size( |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6284 | spdy_util_.ConstructSpdyWindowUpdate(1, initial_window_size)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6285 | |
| 6286 | reads.push_back(CreateMockRead(*settings_frame_small, i++)); |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 6287 | reads.push_back(CreateMockRead(*session_window_update_init_size, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6288 | reads.push_back(CreateMockRead(*window_update_init_size, i++)); |
| 6289 | |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 6290 | scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
| 6291 | writes.push_back(CreateMockWrite(*settings_ack, i++)); |
| 6292 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6293 | writes.push_back(CreateMockWrite(*body3, i++)); |
| 6294 | |
| 6295 | scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 6296 | reads.push_back(CreateMockRead(*reply, i++)); |
| 6297 | reads.push_back(CreateMockRead(*body2, i++)); |
| 6298 | reads.push_back(CreateMockRead(*body3, i++)); |
| 6299 | reads.push_back(MockRead(ASYNC, 0, i++)); // EOF |
| 6300 | |
| 6301 | // Force all writes to happen before any read, last write will not |
| 6302 | // actually queue a frame, due to window size being 0. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 6303 | SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 6304 | writes.size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6305 | |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6306 | std::vector<scoped_ptr<UploadElementReader>> element_readers; |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6307 | std::string upload_data_string(initial_window_size, 'a'); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6308 | upload_data_string.append(kUploadData, kUploadDataSize); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6309 | element_readers.push_back(make_scoped_ptr(new UploadBytesElementReader( |
| 6310 | upload_data_string.c_str(), upload_data_string.size()))); |
| 6311 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6312 | |
| 6313 | HttpRequestInfo request; |
| 6314 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6315 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6316 | request.upload_data_stream = &upload_data_stream; |
| 6317 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 6318 | BoundNetLog(), GetParam(), NULL); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6319 | helper.RunPreTestSetup(); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 6320 | helper.AddData(&data); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6321 | |
| 6322 | HttpNetworkTransaction* trans = helper.trans(); |
| 6323 | |
| 6324 | TestCompletionCallback callback; |
| 6325 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6326 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6327 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 6328 | data.RunUntilPaused(); // Write as much as we can. |
| 6329 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6330 | |
| 6331 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6332 | ASSERT_TRUE(stream != NULL); |
| 6333 | ASSERT_TRUE(stream->stream() != NULL); |
| 6334 | EXPECT_EQ(0, stream->stream()->send_window_size()); |
| 6335 | |
| 6336 | // All the body data should have been read. |
| 6337 | // TODO(satorux): This is because of the weirdness in reading the request |
| 6338 | // body in OnSendBodyComplete(). See crbug.com/113107. |
| 6339 | EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 6340 | // But the body is not yet fully sent (kUploadData is not yet sent) |
| 6341 | // since we're send-stalled. |
| 6342 | EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 6343 | |
| 6344 | // Read in WINDOW_UPDATE or SETTINGS frame. |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 6345 | data.Resume(); |
| 6346 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6347 | rv = callback.WaitForResult(); |
| 6348 | helper.VerifyDataConsumed(); |
| 6349 | } |
| 6350 | |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6351 | TEST_P(SpdyNetworkTransactionTest, GoAwayOnOddPushStreamId) { |
| 6352 | if (spdy_util_.spdy_version() < SPDY3) |
| 6353 | return; |
| 6354 | |
| 6355 | scoped_ptr<SpdyHeaderBlock> push_headers(new SpdyHeaderBlock); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6356 | spdy_util_.AddUrlToHeaderBlock("http://www.example.org/a.dat", |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6357 | push_headers.get()); |
| 6358 | scoped_ptr<SpdyFrame> push( |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 6359 | spdy_util_.ConstructInitialSpdyPushFrame(std::move(push_headers), 3, 1)); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6360 | MockRead reads[] = {CreateMockRead(*push, 1)}; |
| 6361 | |
| 6362 | scoped_ptr<SpdyFrame> req( |
| 6363 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 6364 | scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 6365 | 0, GOAWAY_PROTOCOL_ERROR, "Odd push stream id.")); |
| 6366 | MockWrite writes[] = { |
| 6367 | CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2), |
| 6368 | }; |
| 6369 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 6370 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6371 | NormalSpdyTransactionHelper helper( |
| 6372 | CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 6373 | helper.RunToCompletion(&data); |
| 6374 | TransactionHelperResult out = helper.output(); |
| 6375 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 6376 | } |
| 6377 | |
| 6378 | TEST_P(SpdyNetworkTransactionTest, |
| 6379 | GoAwayOnPushStreamIdLesserOrEqualThanLastAccepted) { |
| 6380 | if (spdy_util_.spdy_version() < SPDY3) |
| 6381 | return; |
| 6382 | |
| 6383 | scoped_ptr<SpdyFrame> push_a(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6384 | NULL, 0, 4, 1, GetDefaultUrlWithPath("/a.dat").c_str())); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6385 | scoped_ptr<SpdyHeaderBlock> push_b_headers(new SpdyHeaderBlock); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6386 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/b.dat"), |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6387 | push_b_headers.get()); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 6388 | scoped_ptr<SpdyFrame> push_b(spdy_util_.ConstructInitialSpdyPushFrame( |
| 6389 | std::move(push_b_headers), 2, 1)); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6390 | MockRead reads[] = { |
| 6391 | CreateMockRead(*push_a, 1), CreateMockRead(*push_b, 2), |
| 6392 | }; |
| 6393 | |
| 6394 | scoped_ptr<SpdyFrame> req( |
| 6395 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 6396 | scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 6397 | 4, |
| 6398 | GOAWAY_PROTOCOL_ERROR, |
| 6399 | "New push stream id must be greater than the last accepted.")); |
| 6400 | MockWrite writes[] = { |
| 6401 | CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 3), |
| 6402 | }; |
| 6403 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 6404 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6405 | NormalSpdyTransactionHelper helper( |
| 6406 | CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 6407 | helper.RunToCompletion(&data); |
| 6408 | TransactionHelperResult out = helper.output(); |
| 6409 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 6410 | } |
| 6411 | |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6412 | // Regression test for https://crbug.com/493348: request header exceeds 16 kB |
| 6413 | // and thus sent in multiple frames when using HTTP/2. |
| 6414 | TEST_P(SpdyNetworkTransactionTest, LargeRequest) { |
| 6415 | const std::string kKey("foo"); |
| 6416 | const std::string kValue(1 << 15, 'z'); |
| 6417 | |
| 6418 | HttpRequestInfo request; |
| 6419 | request.method = "GET"; |
| 6420 | request.url = GURL(GetDefaultUrl()); |
| 6421 | request.extra_headers.SetHeader(kKey, kValue); |
| 6422 | |
| 6423 | scoped_ptr<SpdyHeaderBlock> headers( |
| 6424 | spdy_util_.ConstructGetHeaderBlock(GetDefaultUrl())); |
| 6425 | (*headers)[kKey] = kValue; |
| 6426 | scoped_ptr<SpdyFrame> req( |
| 6427 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
| 6428 | MockWrite writes[] = { |
| 6429 | CreateMockWrite(*req, 0), |
| 6430 | }; |
| 6431 | |
| 6432 | scoped_ptr<SpdyFrame> resp( |
| 6433 | spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 6434 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6435 | MockRead reads[] = { |
| 6436 | CreateMockRead(*resp, 1), |
| 6437 | CreateMockRead(*body, 2), |
| 6438 | MockRead(ASYNC, 0, 3) // EOF |
| 6439 | }; |
| 6440 | |
| 6441 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 6442 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 6443 | GetParam(), nullptr); |
| 6444 | helper.RunToCompletion(&data); |
| 6445 | TransactionHelperResult out = helper.output(); |
| 6446 | |
| 6447 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6448 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
bnc | 76598ab | 2015-06-29 12:43:07 | [diff] [blame] | 6449 | EXPECT_EQ("hello!", out.response_data); |
| 6450 | } |
| 6451 | |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6452 | class SpdyNetworkTransactionNoTLSUsageCheckTest |
| 6453 | : public SpdyNetworkTransactionTest { |
| 6454 | protected: |
| 6455 | void RunNoTLSUsageCheckTest(scoped_ptr<SSLSocketDataProvider> ssl_provider) { |
| 6456 | // Construct the request. |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6457 | scoped_ptr<SpdyFrame> req( |
| 6458 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 6459 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6460 | |
| 6461 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 6462 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6463 | MockRead reads[] = { |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 6464 | CreateMockRead(*resp, 1), |
| 6465 | CreateMockRead(*body, 2), |
| 6466 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6467 | }; |
| 6468 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 6469 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 6470 | arraysize(writes)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6471 | HttpRequestInfo request; |
| 6472 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6473 | request.url = GURL("https://www.example.org/"); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6474 | NormalSpdyTransactionHelper helper( |
| 6475 | request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 6476 | helper.RunToCompletionWithSSLData(&data, std::move(ssl_provider)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6477 | TransactionHelperResult out = helper.output(); |
| 6478 | EXPECT_EQ(OK, out.rv); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6479 | EXPECT_EQ("HTTP/1.1 200", out.status_line); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6480 | EXPECT_EQ("hello!", out.response_data); |
| 6481 | } |
| 6482 | }; |
| 6483 | |
| 6484 | //----------------------------------------------------------------------------- |
| 6485 | // All tests are run with three different connection types: SPDY after NPN |
| 6486 | // negotiation, SPDY without SSL, and SPDY with SSL. |
| 6487 | // |
| 6488 | // TODO(akalin): Use ::testing::Combine() when we are able to use |
| 6489 | // <tr1/tuple>. |
| 6490 | INSTANTIATE_TEST_CASE_P( |
| 6491 | Spdy, |
| 6492 | SpdyNetworkTransactionNoTLSUsageCheckTest, |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6493 | ::testing::Values(SpdyNetworkTransactionTestParams(kProtoSPDY31, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6494 | HTTPS_SPDY_VIA_NPN, |
| 6495 | false))); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6496 | |
| 6497 | TEST_P(SpdyNetworkTransactionNoTLSUsageCheckTest, TLSVersionTooOld) { |
| 6498 | scoped_ptr<SSLSocketDataProvider> ssl_provider( |
| 6499 | new SSLSocketDataProvider(ASYNC, OK)); |
| 6500 | SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_SSL3, |
| 6501 | &ssl_provider->connection_status); |
| 6502 | |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 6503 | RunNoTLSUsageCheckTest(std::move(ssl_provider)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6504 | } |
| 6505 | |
| 6506 | TEST_P(SpdyNetworkTransactionNoTLSUsageCheckTest, TLSCipherSuiteSucky) { |
| 6507 | scoped_ptr<SSLSocketDataProvider> ssl_provider( |
| 6508 | new SSLSocketDataProvider(ASYNC, OK)); |
| 6509 | // Set to TLS_RSA_WITH_NULL_MD5 |
| 6510 | SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); |
| 6511 | |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 6512 | RunNoTLSUsageCheckTest(std::move(ssl_provider)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6513 | } |
| 6514 | |
| 6515 | class SpdyNetworkTransactionTLSUsageCheckTest |
| 6516 | : public SpdyNetworkTransactionTest { |
| 6517 | protected: |
| 6518 | void RunTLSUsageCheckTest(scoped_ptr<SSLSocketDataProvider> ssl_provider) { |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 6519 | scoped_ptr<SpdyFrame> goaway( |
| 6520 | spdy_util_.ConstructSpdyGoAway(0, GOAWAY_INADEQUATE_SECURITY, "")); |
| 6521 | MockWrite writes[] = {CreateMockWrite(*goaway)}; |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6522 | |
rch | 08e3aa3e | 2015-05-16 14:27:52 | [diff] [blame] | 6523 | StaticSocketDataProvider data(NULL, 0, writes, arraysize(writes)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6524 | HttpRequestInfo request; |
| 6525 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6526 | request.url = GURL("https://www.example.org/"); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6527 | NormalSpdyTransactionHelper helper( |
| 6528 | request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 6529 | helper.RunToCompletionWithSSLData(&data, std::move(ssl_provider)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6530 | TransactionHelperResult out = helper.output(); |
| 6531 | EXPECT_EQ(ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY, out.rv); |
| 6532 | } |
| 6533 | }; |
| 6534 | |
| 6535 | INSTANTIATE_TEST_CASE_P( |
| 6536 | Spdy, |
| 6537 | SpdyNetworkTransactionTLSUsageCheckTest, |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6538 | ::testing::Values(SpdyNetworkTransactionTestParams(kProtoHTTP2, |
| 6539 | HTTPS_SPDY_VIA_NPN, |
| 6540 | false), |
| 6541 | SpdyNetworkTransactionTestParams(kProtoHTTP2, |
| 6542 | HTTPS_SPDY_VIA_NPN, |
| 6543 | true))); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6544 | |
| 6545 | TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSVersionTooOld) { |
| 6546 | scoped_ptr<SSLSocketDataProvider> ssl_provider( |
| 6547 | new SSLSocketDataProvider(ASYNC, OK)); |
| 6548 | SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_SSL3, |
| 6549 | &ssl_provider->connection_status); |
| 6550 | |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 6551 | RunTLSUsageCheckTest(std::move(ssl_provider)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6552 | } |
| 6553 | |
| 6554 | TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { |
| 6555 | scoped_ptr<SSLSocketDataProvider> ssl_provider( |
| 6556 | new SSLSocketDataProvider(ASYNC, OK)); |
| 6557 | // Set to TLS_RSA_WITH_NULL_MD5 |
| 6558 | SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); |
| 6559 | |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame^] | 6560 | RunTLSUsageCheckTest(std::move(ssl_provider)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6561 | } |
| 6562 | |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 6563 | } // namespace net |