[email protected] | a159531 | 2012-01-22 03:25:04 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 5af3c57 | 2010-07-20 14:16:27 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 5 | #include <string> |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 6 | #include <vector> |
| 7 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8 | #include "base/bind.h" |
| 9 | #include "base/bind_helpers.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 10 | #include "base/files/file_util.h" |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 11 | #include "base/files/scoped_temp_dir.h" |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 12 | #include "base/memory/scoped_vector.h" |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 13 | #include "base/run_loop.h" |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 14 | #include "base/stl_util.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" |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 17 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 18 | #include "net/base/chunked_upload_data_stream.h" |
| 19 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 20 | #include "net/base/request_priority.h" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 21 | #include "net/base/test_data_directory.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 22 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 23 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 24 | #include "net/http/http_network_session_peer.h" |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 25 | #include "net/http/http_network_transaction.h" |
| 26 | #include "net/http/http_server_properties.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 27 | #include "net/http/http_transaction_test_util.h" |
mmenke | 16a7cbdd | 2015-04-24 23:00:56 | [diff] [blame] | 28 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame^] | 29 | #include "net/log/test_net_log_entry.h" |
| 30 | #include "net/log/test_net_log_util.h" |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 31 | #include "net/socket/client_socket_pool_base.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 32 | #include "net/socket/next_proto.h" |
[email protected] | f54c8579 | 2012-03-08 19:06:41 | [diff] [blame] | 33 | #include "net/spdy/buffered_spdy_framer.h" |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 34 | #include "net/spdy/spdy_http_stream.h" |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 35 | #include "net/spdy/spdy_http_utils.h" |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 36 | #include "net/spdy/spdy_session.h" |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 37 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 38 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | a4bfdf7 | 2013-02-22 04:06:16 | [diff] [blame] | 39 | #include "net/spdy/spdy_test_utils.h" |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 40 | #include "net/ssl/ssl_connection_status_flags.h" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 41 | #include "net/test/cert_test_util.h" |
[email protected] | d2db029 | 2011-01-26 20:23:44 | [diff] [blame] | 42 | #include "net/url_request/url_request_test_util.h" |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 43 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 44 | #include "testing/platform_test.h" |
| 45 | |
| 46 | //----------------------------------------------------------------------------- |
| 47 | |
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 48 | namespace net { |
[email protected] | dae22c5 | 2010-07-30 02:16:35 | [diff] [blame] | 49 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 50 | namespace { |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 51 | |
| 52 | using testing::Each; |
| 53 | using testing::Eq; |
| 54 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 55 | enum SpdyNetworkTransactionTestSSLType { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 56 | // Request an https:// URL and use NPN (or ALPN) to negotiate SPDY during |
| 57 | // the TLS handshake. |
| 58 | HTTPS_SPDY_VIA_NPN, |
| 59 | // Request and http:// URL to a server that supports SPDY via Alternative |
| 60 | // Service on port 443. |
| 61 | // See: https//tools.ietf.org/id/draft-ietf-httpbis-alt-svc-06.html |
| 62 | HTTP_SPDY_VIA_ALT_SVC, |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 63 | }; |
[email protected] | ca6459f86 | 2012-04-11 19:43:20 | [diff] [blame] | 64 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 65 | struct SpdyNetworkTransactionTestParams { |
| 66 | SpdyNetworkTransactionTestParams() |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 67 | : protocol(kProtoSPDY31), ssl_type(HTTPS_SPDY_VIA_NPN) {} |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 68 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 69 | SpdyNetworkTransactionTestParams(NextProto protocol, |
| 70 | SpdyNetworkTransactionTestSSLType ssl_type) |
| 71 | : protocol(protocol), ssl_type(ssl_type) {} |
| 72 | |
| 73 | friend std::ostream& operator<<(std::ostream& os, |
| 74 | const SpdyNetworkTransactionTestParams& p) { |
| 75 | std::string type_str; |
| 76 | switch (p.ssl_type) { |
| 77 | case HTTP_SPDY_VIA_ALT_SVC: |
| 78 | type_str = "HTTP_SPDY_VIA_ALT_SVC"; |
| 79 | break; |
| 80 | case HTTPS_SPDY_VIA_NPN: |
| 81 | type_str = "HTTPS_SPDY_VIA_NPN"; |
| 82 | break; |
| 83 | } |
| 84 | os << "{ protocol: " << SSLClientSocket::NextProtoToString(p.protocol) |
| 85 | << ", ssl_type: " << type_str << " }"; |
| 86 | return os; |
| 87 | } |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 88 | |
| 89 | NextProto protocol; |
| 90 | SpdyNetworkTransactionTestSSLType ssl_type; |
| 91 | }; |
| 92 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 93 | void UpdateSpdySessionDependencies(SpdyNetworkTransactionTestParams test_params, |
| 94 | SpdySessionDependencies* session_deps) { |
| 95 | session_deps->use_alternate_protocols = true; |
| 96 | session_deps->next_protos = SpdyNextProtos(); |
| 97 | if (test_params.ssl_type == HTTP_SPDY_VIA_ALT_SVC) { |
| 98 | session_deps->http_server_properties.SetAlternativeService( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 99 | HostPortPair("www.example.org", 80), |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 100 | AlternativeService(AlternateProtocolFromNextProto(test_params.protocol), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 101 | "www.example.org", 443), |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 102 | 1); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 103 | } |
| 104 | } |
| 105 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 106 | SpdySessionDependencies* CreateSpdySessionDependencies( |
| 107 | SpdyNetworkTransactionTestParams test_params) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 108 | SpdySessionDependencies* session_deps = |
| 109 | new SpdySessionDependencies(test_params.protocol); |
| 110 | UpdateSpdySessionDependencies(test_params, session_deps); |
| 111 | return session_deps; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | SpdySessionDependencies* CreateSpdySessionDependencies( |
| 115 | SpdyNetworkTransactionTestParams test_params, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 116 | ProxyService* proxy_service) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 117 | SpdySessionDependencies* session_deps = |
| 118 | new SpdySessionDependencies(test_params.protocol, proxy_service); |
| 119 | UpdateSpdySessionDependencies(test_params, session_deps); |
| 120 | return session_deps; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 121 | } |
| 122 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 123 | } // namespace |
| 124 | |
| 125 | class SpdyNetworkTransactionTest |
| 126 | : public ::testing::TestWithParam<SpdyNetworkTransactionTestParams> { |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 127 | protected: |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 128 | SpdyNetworkTransactionTest() : spdy_util_(GetParam().protocol) { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 129 | spdy_util_.set_default_url(GURL(GetDefaultUrl())); |
[email protected] | 9ec54f8 | 2013-05-10 02:53:05 | [diff] [blame] | 130 | } |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 131 | |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 132 | virtual ~SpdyNetworkTransactionTest() { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 133 | // UploadDataStream may post a deletion tasks back to the message loop on |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 134 | // destruction. |
| 135 | upload_data_stream_.reset(); |
| 136 | base::RunLoop().RunUntilIdle(); |
| 137 | } |
| 138 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 139 | void SetUp() override { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 140 | get_request_initialized_ = false; |
| 141 | post_request_initialized_ = false; |
| 142 | chunked_post_request_initialized_ = false; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 143 | ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 144 | } |
| 145 | |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 146 | struct TransactionHelperResult { |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 147 | int rv; |
| 148 | std::string status_line; |
| 149 | std::string response_data; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 150 | HttpResponseInfo response_info; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 151 | }; |
| 152 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 153 | // A helper class that handles all the initial npn/ssl setup. |
| 154 | class NormalSpdyTransactionHelper { |
| 155 | public: |
| 156 | NormalSpdyTransactionHelper(const HttpRequestInfo& request, |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 157 | RequestPriority priority, |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 158 | const BoundNetLog& log, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 159 | SpdyNetworkTransactionTestParams test_params, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 160 | SpdySessionDependencies* session_deps) |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 161 | : request_(request), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 162 | priority_(priority), |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 163 | session_deps_(session_deps == NULL |
| 164 | ? CreateSpdySessionDependencies(test_params) |
| 165 | : session_deps), |
| 166 | session_( |
| 167 | SpdySessionDependencies::SpdyCreateSession(session_deps_.get())), |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 168 | log_(log), |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 169 | test_params_(test_params), |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 170 | port_(443), |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 171 | deterministic_(false), |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 172 | spdy_enabled_(true) {} |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 173 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 174 | ~NormalSpdyTransactionHelper() { |
| 175 | // Any test which doesn't close the socket by sending it an EOF will |
| 176 | // have a valid session left open, which leaks the entire session pool. |
| 177 | // This is just fine - in fact, some of our tests intentionally do this |
| 178 | // so that we can check consistency of the SpdySessionPool as the test |
| 179 | // finishes. If we had put an EOF on the socket, the SpdySession would |
| 180 | // have closed and we wouldn't be able to check the consistency. |
| 181 | |
| 182 | // Forcefully close existing sessions here. |
| 183 | session()->spdy_session_pool()->CloseAllSessions(); |
| 184 | } |
| 185 | |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 186 | void SetDeterministic() { |
| 187 | session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic( |
| 188 | session_deps_.get()); |
| 189 | deterministic_ = true; |
| 190 | } |
| 191 | |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 192 | void SetSpdyDisabled() { |
| 193 | spdy_enabled_ = false; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 194 | port_ = test_params_.ssl_type == HTTP_SPDY_VIA_ALT_SVC ? 80 : 443; |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 195 | } |
| 196 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 197 | void RunPreTestSetup() { |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 198 | if (!session_deps_.get()) |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 199 | session_deps_.reset(CreateSpdySessionDependencies(test_params_)); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 200 | if (!session_.get()) { |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 201 | session_ = SpdySessionDependencies::SpdyCreateSession( |
| 202 | session_deps_.get()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 203 | } |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 204 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 205 | // We're now ready to use SSL-npn SPDY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 206 | trans_.reset(new HttpNetworkTransaction(priority_, session_.get())); |
[email protected] | cb54b3b2 | 2010-06-03 16:28:55 | [diff] [blame] | 207 | } |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 208 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 209 | // Start the transaction, read some data, finish. |
| 210 | void RunDefaultTest() { |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 211 | if (!StartDefaultTest()) |
| 212 | return; |
| 213 | FinishDefaultTest(); |
| 214 | } |
| 215 | |
| 216 | bool StartDefaultTest() { |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 217 | output_.rv = trans_->Start(&request_, callback_.callback(), log_); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 218 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 219 | // We expect an IO Pending or some sort of error. |
| 220 | EXPECT_LT(output_.rv, 0); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 221 | return output_.rv == ERR_IO_PENDING; |
| 222 | } |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 223 | |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 224 | void FinishDefaultTest() { |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 225 | output_.rv = callback_.WaitForResult(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 226 | if (output_.rv != OK) { |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 227 | session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 228 | return; |
| 229 | } |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 230 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 231 | // Verify responses. |
| 232 | const HttpResponseInfo* response = trans_->GetResponseInfo(); |
| 233 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 234 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 235 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 236 | EXPECT_EQ(spdy_enabled_, response->was_fetched_via_spdy); |
[email protected] | 808957c | 2013-03-13 03:51:27 | [diff] [blame] | 237 | if (HttpStreamFactory::spdy_enabled()) { |
[email protected] | 88a33262 | 2013-07-30 07:13:32 | [diff] [blame] | 238 | EXPECT_EQ( |
| 239 | HttpResponseInfo::ConnectionInfoFromNextProto( |
| 240 | test_params_.protocol), |
| 241 | response->connection_info); |
[email protected] | 808957c | 2013-03-13 03:51:27 | [diff] [blame] | 242 | } else { |
| 243 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, |
| 244 | response->connection_info); |
| 245 | } |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 246 | if (spdy_enabled_) { |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 247 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 248 | } else { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 249 | // If SPDY is disabled, an HTTP request should not be diverted |
| 250 | // over an SSL session. |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 251 | EXPECT_EQ(request_.url.SchemeIs("https"), |
| 252 | response->was_npn_negotiated); |
| 253 | } |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 254 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 255 | EXPECT_EQ(port_, response->socket_address.port()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 256 | output_.status_line = response->headers->GetStatusLine(); |
| 257 | output_.response_info = *response; // Make a copy so we can verify. |
| 258 | output_.rv = ReadTransaction(trans_.get(), &output_.response_data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 259 | } |
| 260 | |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 261 | void FinishDefaultTestWithoutVerification() { |
| 262 | output_.rv = callback_.WaitForResult(); |
| 263 | if (output_.rv != OK) |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 264 | session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 265 | } |
| 266 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 267 | // Most tests will want to call this function. In particular, the MockReads |
| 268 | // should end with an empty read, and that read needs to be processed to |
| 269 | // ensure proper deletion of the spdy_session_pool. |
| 270 | void VerifyDataConsumed() { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 271 | for (const SocketDataProvider* provider : data_vector_) { |
| 272 | EXPECT_TRUE(provider->AllReadDataConsumed()); |
| 273 | EXPECT_TRUE(provider->AllWriteDataConsumed()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 274 | } |
| 275 | } |
| 276 | |
| 277 | // Occasionally a test will expect to error out before certain reads are |
| 278 | // processed. In that case we want to explicitly ensure that the reads were |
| 279 | // not processed. |
| 280 | void VerifyDataNotConsumed() { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 281 | for (const SocketDataProvider* provider : data_vector_) { |
| 282 | EXPECT_FALSE(provider->AllReadDataConsumed()); |
| 283 | EXPECT_FALSE(provider->AllWriteDataConsumed()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 284 | } |
| 285 | } |
| 286 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 287 | void RunToCompletion(SocketDataProvider* data) { |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 288 | RunPreTestSetup(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 289 | AddData(data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 290 | RunDefaultTest(); |
| 291 | VerifyDataConsumed(); |
| 292 | } |
[email protected] | e6b0686 | 2010-07-20 16:32:58 | [diff] [blame] | 293 | |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 294 | void RunToCompletionWithSSLData( |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 295 | SocketDataProvider* data, |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 296 | scoped_ptr<SSLSocketDataProvider> ssl_provider) { |
| 297 | RunPreTestSetup(); |
| 298 | AddDataWithSSLSocketDataProvider(data, ssl_provider.Pass()); |
| 299 | RunDefaultTest(); |
| 300 | VerifyDataConsumed(); |
| 301 | } |
| 302 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 303 | void AddData(SocketDataProvider* data) { |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 304 | scoped_ptr<SSLSocketDataProvider> ssl_provider( |
| 305 | new SSLSocketDataProvider(ASYNC, OK)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 306 | ssl_provider->cert = |
| 307 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 308 | AddDataWithSSLSocketDataProvider(data, ssl_provider.Pass()); |
| 309 | } |
| 310 | |
| 311 | void AddDataWithSSLSocketDataProvider( |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 312 | SocketDataProvider* data, |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 313 | scoped_ptr<SSLSocketDataProvider> ssl_provider) { |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 314 | DCHECK(!deterministic_); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 315 | data_vector_.push_back(data); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 316 | if (ssl_provider->next_proto_status == |
| 317 | SSLClientSocket::kNextProtoUnsupported) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 318 | ssl_provider->SetNextProto(test_params_.protocol); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 319 | } |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 320 | |
| 321 | session_deps_->socket_factory->AddSSLSocketDataProvider( |
| 322 | ssl_provider.get()); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 323 | ssl_vector_.push_back(ssl_provider.release()); |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 324 | |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 325 | session_deps_->socket_factory->AddSocketDataProvider(data); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 326 | if (test_params_.ssl_type == HTTP_SPDY_VIA_ALT_SVC) { |
| 327 | MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 328 | StaticSocketDataProvider* hanging_non_alt_svc_socket = |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 329 | new StaticSocketDataProvider(NULL, 0, NULL, 0); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 330 | hanging_non_alt_svc_socket->set_connect_data(hanging_connect); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 331 | session_deps_->socket_factory->AddSocketDataProvider( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 332 | hanging_non_alt_svc_socket); |
| 333 | alternate_vector_.push_back(hanging_non_alt_svc_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 334 | } |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | void AddDeterministicData(DeterministicSocketData* data) { |
| 338 | DCHECK(deterministic_); |
| 339 | data_vector_.push_back(data); |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 340 | SSLSocketDataProvider* ssl_provider = |
| 341 | new SSLSocketDataProvider(ASYNC, OK); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 342 | ssl_provider->SetNextProto(test_params_.protocol); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 343 | ssl_provider->cert = |
| 344 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 345 | ssl_vector_.push_back(ssl_provider); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 346 | session_deps_->deterministic_socket_factory->AddSSLSocketDataProvider( |
| 347 | ssl_provider); |
| 348 | |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 349 | session_deps_->deterministic_socket_factory->AddSocketDataProvider(data); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 350 | if (test_params_.ssl_type == HTTP_SPDY_VIA_ALT_SVC) { |
| 351 | MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 352 | DeterministicSocketData* hanging_non_alt_svc_socket = |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 353 | new DeterministicSocketData(NULL, 0, NULL, 0); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 354 | hanging_non_alt_svc_socket->set_connect_data(hanging_connect); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 355 | session_deps_->deterministic_socket_factory->AddSocketDataProvider( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 356 | hanging_non_alt_svc_socket); |
| 357 | alternate_vector_.push_back(hanging_non_alt_svc_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 358 | } |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 359 | } |
| 360 | |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 361 | void SetSession(const scoped_refptr<HttpNetworkSession>& session) { |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 362 | session_ = session; |
| 363 | } |
| 364 | HttpNetworkTransaction* trans() { return trans_.get(); } |
| 365 | void ResetTrans() { trans_.reset(); } |
| 366 | TransactionHelperResult& output() { return output_; } |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 367 | const HttpRequestInfo& request() const { return request_; } |
| 368 | const scoped_refptr<HttpNetworkSession>& session() const { |
| 369 | return session_; |
| 370 | } |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 371 | scoped_ptr<SpdySessionDependencies>& session_deps() { |
| 372 | return session_deps_; |
| 373 | } |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 374 | int port() const { return port_; } |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 375 | SpdyNetworkTransactionTestParams test_params() const { |
| 376 | return test_params_; |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 377 | } |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 378 | |
| 379 | private: |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 380 | typedef std::vector<SocketDataProvider*> DataVector; |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 381 | typedef ScopedVector<SSLSocketDataProvider> SSLVector; |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 382 | typedef ScopedVector<SocketDataProvider> AlternateVector; |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 383 | typedef ScopedVector<DeterministicSocketData> AlternateDeterministicVector; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 384 | HttpRequestInfo request_; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 385 | RequestPriority priority_; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 386 | scoped_ptr<SpdySessionDependencies> session_deps_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 387 | scoped_refptr<HttpNetworkSession> session_; |
| 388 | TransactionHelperResult output_; |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 389 | scoped_ptr<SocketDataProvider> first_transaction_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 390 | SSLVector ssl_vector_; |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 391 | TestCompletionCallback callback_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 392 | scoped_ptr<HttpNetworkTransaction> trans_; |
| 393 | scoped_ptr<HttpNetworkTransaction> trans_http_; |
| 394 | DataVector data_vector_; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 395 | AlternateVector alternate_vector_; |
| 396 | AlternateDeterministicVector alternate_deterministic_vector_; |
bnc | 29b1f07 | 2015-01-14 20:37:49 | [diff] [blame] | 397 | const BoundNetLog log_; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 398 | SpdyNetworkTransactionTestParams test_params_; |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 399 | int port_; |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 400 | bool deterministic_; |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 401 | bool spdy_enabled_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 402 | }; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 403 | |
| 404 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 405 | int expected_status); |
| 406 | |
| 407 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 408 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 409 | const HttpRequestInfo& CreateGetPushRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 410 | get_push_request_.method = "GET"; |
| 411 | get_push_request_.url = GURL(GetDefaultUrlWithPath("/foo.dat")); |
| 412 | get_push_request_.load_flags = 0; |
| 413 | return get_push_request_; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 414 | } |
| 415 | |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 416 | const HttpRequestInfo& CreateGetRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 417 | if (!get_request_initialized_) { |
| 418 | get_request_.method = "GET"; |
| 419 | get_request_.url = GURL(GetDefaultUrl()); |
| 420 | get_request_.load_flags = 0; |
| 421 | get_request_initialized_ = true; |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 422 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 423 | return get_request_; |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 424 | } |
| 425 | |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 426 | const HttpRequestInfo& CreateGetRequestWithUserAgent() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 427 | if (!get_request_initialized_) { |
| 428 | get_request_.method = "GET"; |
| 429 | get_request_.url = GURL(GetDefaultUrl()); |
| 430 | get_request_.load_flags = 0; |
| 431 | get_request_.extra_headers.SetHeader("User-Agent", "Chrome"); |
| 432 | get_request_initialized_ = true; |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 433 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 434 | return get_request_; |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 435 | } |
| 436 | |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 437 | const HttpRequestInfo& CreatePostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 438 | if (!post_request_initialized_) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 439 | ScopedVector<UploadElementReader> element_readers; |
| 440 | element_readers.push_back( |
| 441 | new UploadBytesElementReader(kUploadData, kUploadDataSize)); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 442 | upload_data_stream_.reset( |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 443 | new ElementsUploadDataStream(element_readers.Pass(), 0)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 444 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 445 | post_request_.method = "POST"; |
| 446 | post_request_.url = GURL(GetDefaultUrl()); |
| 447 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 448 | post_request_initialized_ = true; |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 449 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 450 | return post_request_; |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 451 | } |
| 452 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 453 | const HttpRequestInfo& CreateFilePostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 454 | if (!post_request_initialized_) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 455 | base::FilePath file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 456 | CHECK(base::CreateTemporaryFileInDir(temp_dir_.path(), &file_path)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 457 | CHECK_EQ(static_cast<int>(kUploadDataSize), |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 458 | base::WriteFile(file_path, kUploadData, kUploadDataSize)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 459 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 460 | ScopedVector<UploadElementReader> element_readers; |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 461 | element_readers.push_back( |
| 462 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 463 | file_path, |
| 464 | 0, |
| 465 | kUploadDataSize, |
| 466 | base::Time())); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 467 | upload_data_stream_.reset( |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 468 | new ElementsUploadDataStream(element_readers.Pass(), 0)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 469 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 470 | post_request_.method = "POST"; |
| 471 | post_request_.url = GURL(GetDefaultUrl()); |
| 472 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 473 | post_request_initialized_ = true; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 474 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 475 | return post_request_; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 476 | } |
| 477 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 478 | const HttpRequestInfo& CreateUnreadableFilePostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 479 | if (post_request_initialized_) |
| 480 | return post_request_; |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 481 | |
| 482 | base::FilePath file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 483 | CHECK(base::CreateTemporaryFileInDir(temp_dir_.path(), &file_path)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 484 | CHECK_EQ(static_cast<int>(kUploadDataSize), |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 485 | base::WriteFile(file_path, kUploadData, kUploadDataSize)); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 486 | CHECK(base::MakeFileUnreadable(file_path)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 487 | |
| 488 | ScopedVector<UploadElementReader> element_readers; |
| 489 | element_readers.push_back( |
| 490 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 491 | file_path, |
| 492 | 0, |
| 493 | kUploadDataSize, |
| 494 | base::Time())); |
| 495 | upload_data_stream_.reset( |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 496 | new ElementsUploadDataStream(element_readers.Pass(), 0)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 497 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 498 | post_request_.method = "POST"; |
| 499 | post_request_.url = GURL(GetDefaultUrl()); |
| 500 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 501 | post_request_initialized_ = true; |
| 502 | return post_request_; |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 503 | } |
| 504 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 505 | const HttpRequestInfo& CreateComplexPostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 506 | if (!post_request_initialized_) { |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 507 | const int kFileRangeOffset = 1; |
| 508 | const int kFileRangeLength = 3; |
| 509 | CHECK_LT(kFileRangeOffset + kFileRangeLength, kUploadDataSize); |
| 510 | |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 511 | base::FilePath file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 512 | CHECK(base::CreateTemporaryFileInDir(temp_dir_.path(), &file_path)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 513 | CHECK_EQ(static_cast<int>(kUploadDataSize), |
[email protected] | e5c2a22e | 2014-03-06 20:42:30 | [diff] [blame] | 514 | base::WriteFile(file_path, kUploadData, kUploadDataSize)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 515 | |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 516 | ScopedVector<UploadElementReader> element_readers; |
| 517 | element_readers.push_back( |
| 518 | new UploadBytesElementReader(kUploadData, kFileRangeOffset)); |
[email protected] | cadac62 | 2013-06-11 16:46:36 | [diff] [blame] | 519 | element_readers.push_back( |
| 520 | new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 521 | file_path, |
| 522 | kFileRangeOffset, |
| 523 | kFileRangeLength, |
| 524 | base::Time())); |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 525 | element_readers.push_back(new UploadBytesElementReader( |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 526 | kUploadData + kFileRangeOffset + kFileRangeLength, |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 527 | kUploadDataSize - (kFileRangeOffset + kFileRangeLength))); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 528 | upload_data_stream_.reset( |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 529 | new ElementsUploadDataStream(element_readers.Pass(), 0)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 530 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 531 | post_request_.method = "POST"; |
| 532 | post_request_.url = GURL(GetDefaultUrl()); |
| 533 | post_request_.upload_data_stream = upload_data_stream_.get(); |
| 534 | post_request_initialized_ = true; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 535 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 536 | return post_request_; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 537 | } |
| 538 | |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 539 | const HttpRequestInfo& CreateChunkedPostRequest() { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 540 | if (!chunked_post_request_initialized_) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 541 | upload_chunked_data_stream_.reset(new ChunkedUploadDataStream(0)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 542 | chunked_post_request_.method = "POST"; |
| 543 | chunked_post_request_.url = GURL(GetDefaultUrl()); |
| 544 | chunked_post_request_.upload_data_stream = |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 545 | upload_chunked_data_stream_.get(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 546 | chunked_post_request_initialized_ = true; |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 547 | } |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 548 | return chunked_post_request_; |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 549 | } |
| 550 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 551 | // Read the result of a particular transaction, knowing that we've got |
| 552 | // multiple transactions in the read pipeline; so as we read, we may have |
| 553 | // to skip over data destined for other transactions while we consume |
| 554 | // the data for |trans|. |
| 555 | int ReadResult(HttpNetworkTransaction* trans, |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 556 | SocketDataProvider* data, |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 557 | std::string* result) { |
| 558 | const int kSize = 3000; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 559 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 560 | int bytes_read = 0; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 561 | scoped_refptr<IOBufferWithSize> buf(new IOBufferWithSize(kSize)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 562 | TestCompletionCallback callback; |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 563 | while (true) { |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 564 | int rv = trans->Read(buf.get(), kSize, callback.callback()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 565 | if (rv == ERR_IO_PENDING) { |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 566 | rv = callback.WaitForResult(); |
| 567 | } else if (rv <= 0) { |
| 568 | break; |
| 569 | } |
| 570 | result->append(buf->data(), rv); |
| 571 | bytes_read += rv; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 572 | } |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 573 | return bytes_read; |
| 574 | } |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 575 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 576 | void VerifyStreamsClosed(const NormalSpdyTransactionHelper& helper) { |
| 577 | // This lengthy block is reaching into the pool to dig out the active |
| 578 | // session. Once we have the session, we verify that the streams are |
| 579 | // all closed and not leaked at this point. |
| 580 | const GURL& url = helper.request().url; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 581 | HostPortPair host_port_pair(url.host(), 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 582 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 583 | PRIVACY_MODE_DISABLED); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 584 | BoundNetLog log; |
| 585 | const scoped_refptr<HttpNetworkSession>& session = helper.session(); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 586 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 04644d4 | 2013-07-08 04:29:59 | [diff] [blame] | 587 | session->spdy_session_pool()->FindAvailableSession(key, log); |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 588 | ASSERT_TRUE(spdy_session != NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 589 | EXPECT_EQ(0u, spdy_session->num_active_streams()); |
| 590 | EXPECT_EQ(0u, spdy_session->num_unclaimed_pushed_streams()); |
| 591 | } |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 592 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 593 | void RunServerPushTest(SequencedSocketData* data, |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 594 | HttpResponseInfo* response, |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 595 | HttpResponseInfo* push_response, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 596 | const std::string& expected) { |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 597 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 598 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 599 | helper.RunPreTestSetup(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 600 | helper.AddData(data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 601 | |
| 602 | HttpNetworkTransaction* trans = helper.trans(); |
| 603 | |
| 604 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 605 | TestCompletionCallback callback; |
| 606 | int rv = trans->Start( |
| 607 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 608 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 609 | rv = callback.WaitForResult(); |
| 610 | |
| 611 | // Request the pushed path. |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 612 | scoped_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 613 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 614 | rv = trans2->Start( |
| 615 | &CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 616 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 617 | base::RunLoop().RunUntilIdle(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 618 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 619 | // 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] | 620 | // the results into a single string. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 621 | |
| 622 | // Read the server push body. |
| 623 | std::string result2; |
| 624 | ReadResult(trans2.get(), data, &result2); |
| 625 | // Read the response body. |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 626 | std::string result; |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 627 | ReadResult(trans, data, &result); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 628 | |
| 629 | // Verify that we consumed all test data. |
rch | bce10d97 | 2015-05-04 18:21:19 | [diff] [blame] | 630 | EXPECT_TRUE(data->AllReadDataConsumed()); |
| 631 | EXPECT_TRUE(data->AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 632 | |
| 633 | // Verify that the received push data is same as the expected push data. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 634 | EXPECT_EQ(result2.compare(expected), 0) << "Received data: " |
| 635 | << result2 |
| 636 | << "||||| Expected data: " |
| 637 | << expected; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 638 | |
| 639 | // Verify the SYN_REPLY. |
| 640 | // Copy the response info, because trans goes away. |
| 641 | *response = *trans->GetResponseInfo(); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 642 | *push_response = *trans2->GetResponseInfo(); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 643 | |
| 644 | VerifyStreamsClosed(helper); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 645 | } |
| 646 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 647 | static void DeleteSessionCallback(NormalSpdyTransactionHelper* helper, |
| 648 | int result) { |
| 649 | helper->ResetTrans(); |
| 650 | } |
| 651 | |
| 652 | static void StartTransactionCallback( |
| 653 | const scoped_refptr<HttpNetworkSession>& session, |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 654 | GURL url, |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 655 | int result) { |
| 656 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 657 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 658 | TestCompletionCallback callback; |
| 659 | HttpRequestInfo request; |
| 660 | request.method = "GET"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 661 | request.url = url; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 662 | request.load_flags = 0; |
| 663 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 664 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 665 | callback.WaitForResult(); |
| 666 | } |
| 667 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 668 | ChunkedUploadDataStream* upload_chunked_data_stream() const { |
| 669 | return upload_chunked_data_stream_.get(); |
| 670 | } |
| 671 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 672 | const char* GetDefaultUrl() { |
| 673 | switch (GetParam().ssl_type) { |
| 674 | case HTTP_SPDY_VIA_ALT_SVC: |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 675 | return "http://www.example.org"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 676 | case HTTPS_SPDY_VIA_NPN: |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 677 | return "https://www.example.org"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 678 | default: |
| 679 | NOTREACHED(); |
| 680 | return ""; |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | std::string GetDefaultUrlWithPath(const char* path) { |
| 685 | return std::string(GetDefaultUrl()) + path; |
| 686 | } |
| 687 | |
[email protected] | 9ec54f8 | 2013-05-10 02:53:05 | [diff] [blame] | 688 | SpdyTestUtil spdy_util_; |
| 689 | |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 690 | private: |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 691 | scoped_ptr<ChunkedUploadDataStream> upload_chunked_data_stream_; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 692 | scoped_ptr<UploadDataStream> upload_data_stream_; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 693 | bool get_request_initialized_; |
| 694 | bool post_request_initialized_; |
| 695 | bool chunked_post_request_initialized_; |
| 696 | HttpRequestInfo get_request_; |
| 697 | HttpRequestInfo post_request_; |
| 698 | HttpRequestInfo chunked_post_request_; |
| 699 | HttpRequestInfo get_push_request_; |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 700 | base::ScopedTempDir temp_dir_; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 701 | }; |
| 702 | |
| 703 | //----------------------------------------------------------------------------- |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 704 | // All tests are run with three different connection types: SPDY after NPN |
| 705 | // negotiation, SPDY without SSL, and SPDY with SSL. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 706 | // |
| 707 | // TODO(akalin): Use ::testing::Combine() when we are able to use |
| 708 | // <tr1/tuple>. |
| 709 | INSTANTIATE_TEST_CASE_P( |
| 710 | Spdy, |
| 711 | SpdyNetworkTransactionTest, |
| 712 | ::testing::Values( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 713 | SpdyNetworkTransactionTestParams(kProtoSPDY31, HTTPS_SPDY_VIA_NPN), |
| 714 | SpdyNetworkTransactionTestParams(kProtoSPDY31, HTTP_SPDY_VIA_ALT_SVC), |
| 715 | SpdyNetworkTransactionTestParams(kProtoSPDY4_14, HTTPS_SPDY_VIA_NPN), |
| 716 | SpdyNetworkTransactionTestParams(kProtoSPDY4_14, HTTP_SPDY_VIA_ALT_SVC), |
| 717 | SpdyNetworkTransactionTestParams(kProtoSPDY4, HTTPS_SPDY_VIA_NPN), |
| 718 | SpdyNetworkTransactionTestParams(kProtoSPDY4, HTTP_SPDY_VIA_ALT_SVC))); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 719 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 720 | // Verify HttpNetworkTransaction constructor. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 721 | TEST_P(SpdyNetworkTransactionTest, Constructor) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 722 | scoped_ptr<SpdySessionDependencies> session_deps( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 723 | CreateSpdySessionDependencies(GetParam())); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 724 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 725 | SpdySessionDependencies::SpdyCreateSession(session_deps.get())); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 726 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 727 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 728 | } |
| 729 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 730 | TEST_P(SpdyNetworkTransactionTest, Get) { |
[email protected] | 75f30cc2 | 2010-06-28 21:41:38 | [diff] [blame] | 731 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 732 | scoped_ptr<SpdyFrame> req( |
| 733 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 734 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 735 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 736 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 737 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 738 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 739 | CreateMockRead(*resp, 1), |
| 740 | CreateMockRead(*body, 2), |
| 741 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 742 | }; |
| 743 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 744 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 745 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 746 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 747 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 748 | TransactionHelperResult out = helper.output(); |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 749 | EXPECT_EQ(OK, out.rv); |
| 750 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 751 | EXPECT_EQ("hello!", out.response_data); |
| 752 | } |
| 753 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 754 | TEST_P(SpdyNetworkTransactionTest, GetAtEachPriority) { |
[email protected] | 3d08dd38 | 2013-10-19 00:13:11 | [diff] [blame] | 755 | for (RequestPriority p = MINIMUM_PRIORITY; p <= MAXIMUM_PRIORITY; |
[email protected] | 31ae7ab | 2012-04-24 21:09:05 | [diff] [blame] | 756 | p = RequestPriority(p + 1)) { |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 757 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 758 | scoped_ptr<SpdyFrame> req( |
| 759 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, p, true)); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 760 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 761 | |
[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 762 | SpdyPriority spdy_prio = 0; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 763 | EXPECT_TRUE(GetSpdyPriority(spdy_util_.spdy_version(), *req, &spdy_prio)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 764 | // this repeats the RequestPriority-->SpdyPriority mapping from |
| 765 | // SpdyFramer::ConvertRequestPriorityToSpdyPriority to make |
| 766 | // sure it's being done right. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 767 | if (spdy_util_.spdy_version() < SPDY3) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [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 | case LOWEST: |
| 777 | EXPECT_EQ(2, spdy_prio); |
| 778 | break; |
| 779 | case IDLE: |
| 780 | EXPECT_EQ(3, spdy_prio); |
| 781 | break; |
| 782 | default: |
| 783 | FAIL(); |
| 784 | } |
| 785 | } else { |
| 786 | switch(p) { |
| 787 | case HIGHEST: |
| 788 | EXPECT_EQ(0, spdy_prio); |
| 789 | break; |
| 790 | case MEDIUM: |
| 791 | EXPECT_EQ(1, spdy_prio); |
| 792 | break; |
| 793 | case LOW: |
| 794 | EXPECT_EQ(2, spdy_prio); |
| 795 | break; |
| 796 | case LOWEST: |
| 797 | EXPECT_EQ(3, spdy_prio); |
| 798 | break; |
| 799 | case IDLE: |
| 800 | EXPECT_EQ(4, spdy_prio); |
| 801 | break; |
| 802 | default: |
| 803 | FAIL(); |
| 804 | } |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 805 | } |
| 806 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 807 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 808 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 809 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 810 | CreateMockRead(*resp, 1), |
| 811 | CreateMockRead(*body, 2), |
| 812 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 813 | }; |
| 814 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 815 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 816 | arraysize(writes)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 817 | HttpRequestInfo http_req = CreateGetRequest(); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 818 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 819 | NormalSpdyTransactionHelper helper(http_req, p, BoundNetLog(), |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 820 | GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 821 | helper.RunToCompletion(&data); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 822 | TransactionHelperResult out = helper.output(); |
| 823 | EXPECT_EQ(OK, out.rv); |
| 824 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 825 | EXPECT_EQ("hello!", out.response_data); |
| 826 | } |
| 827 | } |
| 828 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 829 | // Start three gets simultaniously; making sure that multiplexed |
| 830 | // streams work properly. |
| 831 | |
| 832 | // This can't use the TransactionHelper method, since it only |
| 833 | // handles a single transaction, and finishes them as soon |
| 834 | // as it launches them. |
| 835 | |
| 836 | // TODO(gavinp): create a working generalized TransactionHelper that |
| 837 | // can allow multiple streams in flight. |
| 838 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 839 | TEST_P(SpdyNetworkTransactionTest, ThreeGets) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 840 | scoped_ptr<SpdyFrame> req( |
| 841 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 842 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 843 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 844 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 845 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 846 | scoped_ptr<SpdyFrame> req2( |
| 847 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 848 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 849 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 850 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 851 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 852 | scoped_ptr<SpdyFrame> req3( |
| 853 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 854 | scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 855 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(5, false)); |
| 856 | scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 857 | |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 858 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 859 | CreateMockWrite(*req, 0), |
| 860 | CreateMockWrite(*req2, 3), |
| 861 | CreateMockWrite(*req3, 6), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 862 | }; |
| 863 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 864 | CreateMockRead(*resp, 1), |
| 865 | CreateMockRead(*body, 2), |
| 866 | CreateMockRead(*resp2, 4), |
| 867 | CreateMockRead(*body2, 5), |
| 868 | CreateMockRead(*resp3, 7), |
| 869 | CreateMockRead(*body3, 8), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 870 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 871 | CreateMockRead(*fbody, 9), |
| 872 | CreateMockRead(*fbody2, 10), |
| 873 | CreateMockRead(*fbody3, 11), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 874 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 875 | MockRead(ASYNC, 0, 12), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 876 | }; |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 877 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 878 | SequencedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 879 | |
| 880 | BoundNetLog log; |
| 881 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 882 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 883 | BoundNetLog(), GetParam(), NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 884 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 885 | helper.AddData(&data); |
rch | aeb3f05 | 2015-04-14 16:02:49 | [diff] [blame] | 886 | // We require placeholder data because three get requests are sent out at |
| 887 | // the same time which results in three sockets being connected. The first |
| 888 | // on will negotiate SPDY and will be used for all requests. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 889 | helper.AddData(&data_placeholder); |
| 890 | helper.AddData(&data_placeholder); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 891 | scoped_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 892 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 893 | scoped_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 894 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 895 | scoped_ptr<HttpNetworkTransaction> trans3( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 896 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 897 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 898 | TestCompletionCallback callback1; |
| 899 | TestCompletionCallback callback2; |
| 900 | TestCompletionCallback callback3; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 901 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 902 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 903 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 904 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 905 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 906 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 907 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 908 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 909 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 910 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 911 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 912 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 913 | out.rv = callback1.WaitForResult(); |
| 914 | ASSERT_EQ(OK, out.rv); |
| 915 | out.rv = callback3.WaitForResult(); |
| 916 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 917 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 918 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 919 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 920 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 921 | out.status_line = response1->headers->GetStatusLine(); |
| 922 | out.response_info = *response1; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 923 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 924 | trans2->GetResponseInfo(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 925 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 926 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 927 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 928 | EXPECT_EQ(OK, out.rv); |
| 929 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 930 | EXPECT_EQ(OK, out.rv); |
| 931 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 932 | EXPECT_EQ("hello!hello!", out.response_data); |
| 933 | } |
| 934 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 935 | TEST_P(SpdyNetworkTransactionTest, TwoGetsLateBinding) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 936 | scoped_ptr<SpdyFrame> req( |
| 937 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 938 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 939 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 940 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 941 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 942 | scoped_ptr<SpdyFrame> req2( |
| 943 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 944 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 945 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 946 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 947 | |
| 948 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 949 | CreateMockWrite(*req, 0), CreateMockWrite(*req2, 3), |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 950 | }; |
| 951 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 952 | CreateMockRead(*resp, 1), |
| 953 | CreateMockRead(*body, 2), |
| 954 | CreateMockRead(*resp2, 4), |
| 955 | CreateMockRead(*body2, 5), |
| 956 | CreateMockRead(*fbody, 6), |
| 957 | CreateMockRead(*fbody2, 7), |
| 958 | MockRead(ASYNC, 0, 8), // EOF |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 959 | }; |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 960 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 961 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 962 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 963 | SequencedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 964 | data_placeholder.set_connect_data(never_finishing_connect); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 965 | |
| 966 | BoundNetLog log; |
| 967 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 968 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 969 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 970 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 971 | helper.AddData(&data); |
rch | aeb3f05 | 2015-04-14 16:02:49 | [diff] [blame] | 972 | // We require placeholder data because two requests are sent out at |
| 973 | // the same time which results in two sockets being connected. The first |
| 974 | // on will negotiate SPDY and will be used for all requests. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 975 | helper.AddData(&data_placeholder); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 976 | scoped_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 977 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 978 | scoped_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 979 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 980 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 981 | TestCompletionCallback callback1; |
| 982 | TestCompletionCallback callback2; |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 983 | |
| 984 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 985 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 986 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 987 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 988 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 989 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 990 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
| 991 | |
| 992 | out.rv = callback1.WaitForResult(); |
| 993 | ASSERT_EQ(OK, out.rv); |
| 994 | out.rv = callback2.WaitForResult(); |
| 995 | ASSERT_EQ(OK, out.rv); |
| 996 | |
| 997 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 998 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 999 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1000 | out.status_line = response1->headers->GetStatusLine(); |
| 1001 | out.response_info = *response1; |
| 1002 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 1003 | EXPECT_EQ(OK, out.rv); |
| 1004 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1005 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1006 | |
| 1007 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1008 | EXPECT_TRUE(response2->headers.get() != NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1009 | EXPECT_TRUE(response2->was_fetched_via_spdy); |
| 1010 | out.status_line = response2->headers->GetStatusLine(); |
| 1011 | out.response_info = *response2; |
| 1012 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 1013 | EXPECT_EQ(OK, out.rv); |
| 1014 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1015 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1016 | |
| 1017 | helper.VerifyDataConsumed(); |
| 1018 | } |
| 1019 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1020 | TEST_P(SpdyNetworkTransactionTest, TwoGetsLateBindingFromPreconnect) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1021 | scoped_ptr<SpdyFrame> req( |
| 1022 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1023 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1024 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1025 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1026 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1027 | scoped_ptr<SpdyFrame> req2( |
| 1028 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1029 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1030 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 1031 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1032 | |
| 1033 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1034 | CreateMockWrite(*req, 0), CreateMockWrite(*req2, 3), |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1035 | }; |
| 1036 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1037 | CreateMockRead(*resp, 1), |
| 1038 | CreateMockRead(*body, 2), |
| 1039 | CreateMockRead(*resp2, 4), |
| 1040 | CreateMockRead(*body2, 5), |
| 1041 | CreateMockRead(*fbody, 6), |
| 1042 | CreateMockRead(*fbody2, 7), |
| 1043 | MockRead(ASYNC, 0, 8), // EOF |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1044 | }; |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1045 | SequencedSocketData preconnect_data(reads, arraysize(reads), writes, |
| 1046 | arraysize(writes)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1047 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 1048 | MockConnect never_finishing_connect(ASYNC, ERR_IO_PENDING); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1049 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1050 | SequencedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1051 | data_placeholder.set_connect_data(never_finishing_connect); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1052 | |
| 1053 | BoundNetLog log; |
| 1054 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1055 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1056 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1057 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1058 | helper.AddData(&preconnect_data); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1059 | // We require placeholder data because 3 connections are attempted (first is |
| 1060 | // the preconnect, 2nd and 3rd are the never finished connections. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1061 | helper.AddData(&data_placeholder); |
| 1062 | helper.AddData(&data_placeholder); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1063 | |
| 1064 | scoped_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1065 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1066 | scoped_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1067 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1068 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1069 | TestCompletionCallback callback1; |
| 1070 | TestCompletionCallback callback2; |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1071 | |
| 1072 | HttpRequestInfo httpreq = CreateGetRequest(); |
| 1073 | |
| 1074 | // Preconnect the first. |
| 1075 | SSLConfig preconnect_ssl_config; |
| 1076 | helper.session()->ssl_config_service()->GetSSLConfig(&preconnect_ssl_config); |
| 1077 | HttpStreamFactory* http_stream_factory = |
| 1078 | helper.session()->http_stream_factory(); |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 1079 | helper.session()->GetNextProtos(&preconnect_ssl_config.next_protos); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1080 | |
| 1081 | http_stream_factory->PreconnectStreams( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1082 | 1, httpreq, DEFAULT_PRIORITY, |
| 1083 | preconnect_ssl_config, preconnect_ssl_config); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1084 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1085 | out.rv = trans1->Start(&httpreq, callback1.callback(), log); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1086 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1087 | out.rv = trans2->Start(&httpreq, callback2.callback(), log); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1088 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
| 1089 | |
| 1090 | out.rv = callback1.WaitForResult(); |
| 1091 | ASSERT_EQ(OK, out.rv); |
| 1092 | out.rv = callback2.WaitForResult(); |
| 1093 | ASSERT_EQ(OK, out.rv); |
| 1094 | |
| 1095 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1096 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1097 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1098 | out.status_line = response1->headers->GetStatusLine(); |
| 1099 | out.response_info = *response1; |
| 1100 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 1101 | EXPECT_EQ(OK, out.rv); |
| 1102 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1103 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1104 | |
| 1105 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1106 | EXPECT_TRUE(response2->headers.get() != NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1107 | EXPECT_TRUE(response2->was_fetched_via_spdy); |
| 1108 | out.status_line = response2->headers->GetStatusLine(); |
| 1109 | out.response_info = *response2; |
| 1110 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 1111 | EXPECT_EQ(OK, out.rv); |
| 1112 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1113 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1114 | |
| 1115 | helper.VerifyDataConsumed(); |
| 1116 | } |
| 1117 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1118 | // Similar to ThreeGets above, however this test adds a SETTINGS |
| 1119 | // frame. The SETTINGS frame is read during the IO loop waiting on |
| 1120 | // the first transaction completion, and sets a maximum concurrent |
| 1121 | // stream limit of 1. This means that our IO loop exists after the |
| 1122 | // second transaction completes, so we can assert on read_index(). |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1123 | TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrent) { |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1124 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1125 | scoped_ptr<SpdyFrame> req( |
| 1126 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1127 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1128 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1129 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1130 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1131 | scoped_ptr<SpdyFrame> req2( |
| 1132 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1133 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1134 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 1135 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1136 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1137 | scoped_ptr<SpdyFrame> req3( |
| 1138 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1139 | scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 1140 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(5, false)); |
| 1141 | scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1142 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1143 | SettingsMap settings; |
[email protected] | 9dcec24 | 2013-01-10 23:24:28 | [diff] [blame] | 1144 | const uint32 max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1145 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1146 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1147 | scoped_ptr<SpdyFrame> settings_frame( |
| 1148 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1149 | scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1150 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 1151 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1152 | CreateMockWrite(*req, 0), |
| 1153 | CreateMockWrite(*settings_ack, 5), |
| 1154 | CreateMockWrite(*req2, 6), |
| 1155 | CreateMockWrite(*req3, 10), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1156 | }; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 1157 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1158 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1159 | CreateMockRead(*settings_frame, 1), |
| 1160 | CreateMockRead(*resp, 2), |
| 1161 | CreateMockRead(*body, 3), |
| 1162 | CreateMockRead(*fbody, 4), |
| 1163 | CreateMockRead(*resp2, 7), |
| 1164 | CreateMockRead(*body2, 8), |
| 1165 | CreateMockRead(*fbody2, 9), |
| 1166 | CreateMockRead(*resp3, 11), |
| 1167 | CreateMockRead(*body3, 12), |
| 1168 | CreateMockRead(*fbody3, 13), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1169 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1170 | MockRead(ASYNC, 0, 14), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1171 | }; |
| 1172 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1173 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1174 | |
| 1175 | BoundNetLog log; |
| 1176 | TransactionHelperResult out; |
| 1177 | { |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1178 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1179 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 1180 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1181 | helper.AddData(&data); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1182 | scoped_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1183 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1184 | scoped_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1185 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1186 | scoped_ptr<HttpNetworkTransaction> trans3( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1187 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1188 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1189 | TestCompletionCallback callback1; |
| 1190 | TestCompletionCallback callback2; |
| 1191 | TestCompletionCallback callback3; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1192 | |
| 1193 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1194 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1195 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
| 1196 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1197 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1198 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1199 | // Run transaction 1 through quickly to force a read of our SETTINGS |
| 1200 | // frame. |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1201 | out.rv = callback1.WaitForResult(); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1202 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1203 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1204 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1205 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1206 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1207 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
| 1208 | out.rv = callback2.WaitForResult(); |
| 1209 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1210 | |
| 1211 | out.rv = callback3.WaitForResult(); |
| 1212 | ASSERT_EQ(OK, out.rv); |
| 1213 | |
| 1214 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1215 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1216 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1217 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1218 | out.status_line = response1->headers->GetStatusLine(); |
| 1219 | out.response_info = *response1; |
| 1220 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 1221 | EXPECT_EQ(OK, out.rv); |
| 1222 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1223 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1224 | |
| 1225 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 1226 | out.status_line = response2->headers->GetStatusLine(); |
| 1227 | out.response_info = *response2; |
| 1228 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 1229 | EXPECT_EQ(OK, out.rv); |
| 1230 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1231 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1232 | |
| 1233 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 1234 | out.status_line = response3->headers->GetStatusLine(); |
| 1235 | out.response_info = *response3; |
| 1236 | out.rv = ReadTransaction(trans3.get(), &out.response_data); |
| 1237 | EXPECT_EQ(OK, out.rv); |
| 1238 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1239 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1240 | |
| 1241 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1242 | } |
| 1243 | EXPECT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | // Similar to ThreeGetsWithMaxConcurrent above, however this test adds |
| 1247 | // a fourth transaction. The third and fourth transactions have |
| 1248 | // different data ("hello!" vs "hello!hello!") and because of the |
| 1249 | // user specified priority, we expect to see them inverted in |
| 1250 | // the response from the server. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1251 | TEST_P(SpdyNetworkTransactionTest, FourGetsWithMaxConcurrentPriority) { |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1252 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1253 | scoped_ptr<SpdyFrame> req( |
| 1254 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1255 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1256 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1257 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[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> req2( |
| 1260 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1261 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1262 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 1263 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1264 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1265 | scoped_ptr<SpdyFrame> req4( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1266 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, HIGHEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1267 | scoped_ptr<SpdyFrame> resp4(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 1268 | scoped_ptr<SpdyFrame> fbody4(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1269 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1270 | scoped_ptr<SpdyFrame> req3( |
| 1271 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 7, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1272 | scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 7)); |
| 1273 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(7, false)); |
| 1274 | scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(7, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1275 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1276 | SettingsMap settings; |
[email protected] | 9dcec24 | 2013-01-10 23:24:28 | [diff] [blame] | 1277 | const uint32 max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1278 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1279 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1280 | scoped_ptr<SpdyFrame> settings_frame( |
| 1281 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1282 | scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1283 | MockWrite writes[] = { |
| 1284 | CreateMockWrite(*req, 0), |
| 1285 | CreateMockWrite(*settings_ack, 5), |
| 1286 | // By making these synchronous, it guarantees that they are not *started* |
| 1287 | // before their sequence number, which in turn verifies that only a single |
| 1288 | // request is in-flight at a time. |
| 1289 | CreateMockWrite(*req2, 6, SYNCHRONOUS), |
| 1290 | CreateMockWrite(*req4, 10, SYNCHRONOUS), |
| 1291 | CreateMockWrite(*req3, 13, SYNCHRONOUS), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1292 | }; |
| 1293 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1294 | CreateMockRead(*settings_frame, 1), |
| 1295 | CreateMockRead(*resp, 2), |
| 1296 | CreateMockRead(*body, 3), |
| 1297 | CreateMockRead(*fbody, 4), |
| 1298 | CreateMockRead(*resp2, 7), |
| 1299 | CreateMockRead(*body2, 8), |
| 1300 | CreateMockRead(*fbody2, 9), |
| 1301 | CreateMockRead(*resp4, 11), |
| 1302 | CreateMockRead(*fbody4, 12), |
| 1303 | CreateMockRead(*resp3, 14), |
| 1304 | CreateMockRead(*body3, 15), |
| 1305 | CreateMockRead(*fbody3, 16), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1306 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1307 | MockRead(ASYNC, 0, 17), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1308 | }; |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1309 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1310 | BoundNetLog log; |
| 1311 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1312 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 1313 | BoundNetLog(), GetParam(), NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1314 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1315 | helper.AddData(&data); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1316 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1317 | scoped_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1318 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1319 | scoped_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1320 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1321 | scoped_ptr<HttpNetworkTransaction> trans3( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1322 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1323 | scoped_ptr<HttpNetworkTransaction> trans4( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1324 | new HttpNetworkTransaction(HIGHEST, helper.session().get())); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1325 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1326 | TestCompletionCallback callback1; |
| 1327 | TestCompletionCallback callback2; |
| 1328 | TestCompletionCallback callback3; |
| 1329 | TestCompletionCallback callback4; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1330 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1331 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1332 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1333 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
| 1334 | HttpRequestInfo httpreq4 = CreateGetRequest(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1335 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1336 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1337 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1338 | // Run transaction 1 through quickly to force a read of our SETTINGS frame. |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1339 | out.rv = callback1.WaitForResult(); |
| 1340 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1341 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1342 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1343 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1344 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1345 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1346 | out.rv = trans4->Start(&httpreq4, callback4.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1347 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1348 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1349 | out.rv = callback2.WaitForResult(); |
| 1350 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1351 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1352 | out.rv = callback3.WaitForResult(); |
| 1353 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1354 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1355 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1356 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1357 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1358 | out.status_line = response1->headers->GetStatusLine(); |
| 1359 | out.response_info = *response1; |
| 1360 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 1361 | EXPECT_EQ(OK, out.rv); |
| 1362 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1363 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1364 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1365 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 1366 | out.status_line = response2->headers->GetStatusLine(); |
| 1367 | out.response_info = *response2; |
| 1368 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 1369 | EXPECT_EQ(OK, out.rv); |
| 1370 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1371 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1372 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1373 | // notice: response3 gets two hellos, response4 gets one |
| 1374 | // hello, so we know dequeuing priority was respected. |
| 1375 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 1376 | out.status_line = response3->headers->GetStatusLine(); |
| 1377 | out.response_info = *response3; |
| 1378 | out.rv = ReadTransaction(trans3.get(), &out.response_data); |
| 1379 | EXPECT_EQ(OK, out.rv); |
| 1380 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1381 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1382 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1383 | out.rv = callback4.WaitForResult(); |
| 1384 | EXPECT_EQ(OK, out.rv); |
| 1385 | const HttpResponseInfo* response4 = trans4->GetResponseInfo(); |
| 1386 | out.status_line = response4->headers->GetStatusLine(); |
| 1387 | out.response_info = *response4; |
| 1388 | out.rv = ReadTransaction(trans4.get(), &out.response_data); |
| 1389 | EXPECT_EQ(OK, out.rv); |
| 1390 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1391 | EXPECT_EQ("hello!", out.response_data); |
| 1392 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1393 | EXPECT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | // Similar to ThreeGetsMaxConcurrrent above, however, this test |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1397 | // deletes a session in the middle of the transaction to ensure |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1398 | // that we properly remove pendingcreatestream objects from |
| 1399 | // the spdy_session |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1400 | TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentDelete) { |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1401 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1402 | scoped_ptr<SpdyFrame> req( |
| 1403 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1404 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1405 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1406 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1407 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1408 | scoped_ptr<SpdyFrame> req2( |
| 1409 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1410 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1411 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 1412 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1413 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1414 | SettingsMap settings; |
[email protected] | 9dcec24 | 2013-01-10 23:24:28 | [diff] [blame] | 1415 | const uint32 max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1416 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1417 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1418 | scoped_ptr<SpdyFrame> settings_frame( |
| 1419 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1420 | scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1421 | |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1422 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1423 | CreateMockWrite(*req, 0), |
| 1424 | CreateMockWrite(*settings_ack, 5), |
| 1425 | CreateMockWrite(*req2, 6), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1426 | }; |
| 1427 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1428 | CreateMockRead(*settings_frame, 1), |
| 1429 | CreateMockRead(*resp, 2), |
| 1430 | CreateMockRead(*body, 3), |
| 1431 | CreateMockRead(*fbody, 4), |
| 1432 | CreateMockRead(*resp2, 7), |
| 1433 | CreateMockRead(*body2, 8), |
| 1434 | CreateMockRead(*fbody2, 9), |
| 1435 | MockRead(ASYNC, 0, 10), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1436 | }; |
| 1437 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1438 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1439 | |
| 1440 | BoundNetLog log; |
| 1441 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1442 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 1443 | BoundNetLog(), GetParam(), NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1444 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1445 | helper.AddData(&data); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1446 | scoped_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1447 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1448 | scoped_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1449 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1450 | scoped_ptr<HttpNetworkTransaction> trans3( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1451 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1452 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1453 | TestCompletionCallback callback1; |
| 1454 | TestCompletionCallback callback2; |
| 1455 | TestCompletionCallback callback3; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1456 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1457 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1458 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1459 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1460 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1461 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1462 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1463 | // Run transaction 1 through quickly to force a read of our SETTINGS frame. |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1464 | out.rv = callback1.WaitForResult(); |
| 1465 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1466 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1467 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1468 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1469 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1470 | delete trans3.release(); |
| 1471 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
| 1472 | out.rv = callback2.WaitForResult(); |
| 1473 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1474 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1475 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 1476 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1477 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1478 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1479 | out.status_line = response1->headers->GetStatusLine(); |
| 1480 | out.response_info = *response1; |
| 1481 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 1482 | EXPECT_EQ(OK, out.rv); |
| 1483 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1484 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1485 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1486 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 1487 | ASSERT_TRUE(response2 != NULL); |
| 1488 | out.status_line = response2->headers->GetStatusLine(); |
| 1489 | out.response_info = *response2; |
| 1490 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 1491 | EXPECT_EQ(OK, out.rv); |
| 1492 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1493 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1494 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1495 | EXPECT_EQ(OK, out.rv); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1496 | } |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1497 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1498 | namespace { |
| 1499 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1500 | // The KillerCallback will delete the transaction on error as part of the |
| 1501 | // callback. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1502 | class KillerCallback : public TestCompletionCallbackBase { |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1503 | public: |
| 1504 | explicit KillerCallback(HttpNetworkTransaction* transaction) |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1505 | : transaction_(transaction), |
[email protected] | aa249b5 | 2013-04-30 01:04:32 | [diff] [blame] | 1506 | callback_(base::Bind(&KillerCallback::OnComplete, |
| 1507 | base::Unretained(this))) { |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1508 | } |
| 1509 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 1510 | ~KillerCallback() override {} |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1511 | |
| 1512 | const CompletionCallback& callback() const { return callback_; } |
| 1513 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1514 | private: |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1515 | void OnComplete(int result) { |
| 1516 | if (result < 0) |
| 1517 | delete transaction_; |
| 1518 | |
| 1519 | SetResult(result); |
| 1520 | } |
| 1521 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1522 | HttpNetworkTransaction* transaction_; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1523 | CompletionCallback callback_; |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1524 | }; |
| 1525 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1526 | } // namespace |
| 1527 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1528 | // Similar to ThreeGetsMaxConcurrrentDelete above, however, this test |
| 1529 | // closes the socket while we have a pending transaction waiting for |
| 1530 | // a pending stream creation. http://crbug.com/52901 |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1531 | TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentSocketClose) { |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1532 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1533 | scoped_ptr<SpdyFrame> req( |
| 1534 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1535 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1536 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1537 | scoped_ptr<SpdyFrame> fin_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1538 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1539 | scoped_ptr<SpdyFrame> req2( |
| 1540 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1541 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1542 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1543 | SettingsMap settings; |
[email protected] | 9dcec24 | 2013-01-10 23:24:28 | [diff] [blame] | 1544 | const uint32 max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1545 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1546 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1547 | scoped_ptr<SpdyFrame> settings_frame( |
| 1548 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1549 | scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1550 | |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 1551 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1552 | CreateMockWrite(*req, 0), |
| 1553 | CreateMockWrite(*settings_ack, 5), |
| 1554 | CreateMockWrite(*req2, 6), |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1555 | }; |
| 1556 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1557 | CreateMockRead(*settings_frame, 1), |
| 1558 | CreateMockRead(*resp, 2), |
| 1559 | CreateMockRead(*body, 3), |
| 1560 | CreateMockRead(*fin_body, 4), |
| 1561 | CreateMockRead(*resp2, 7), |
| 1562 | MockRead(ASYNC, ERR_CONNECTION_RESET, 8), // Abort! |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1563 | }; |
| 1564 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1565 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 1566 | SequencedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1567 | |
| 1568 | BoundNetLog log; |
| 1569 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1570 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 1571 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1572 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1573 | helper.AddData(&data); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1574 | // We require placeholder data because three get requests are sent out, so |
| 1575 | // there needs to be three sets of SSL connection data. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1576 | helper.AddData(&data_placeholder); |
| 1577 | helper.AddData(&data_placeholder); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1578 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session().get()); |
| 1579 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session().get()); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1580 | HttpNetworkTransaction* trans3( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1581 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1582 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1583 | TestCompletionCallback callback1; |
| 1584 | TestCompletionCallback callback2; |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1585 | KillerCallback callback3(trans3); |
| 1586 | |
| 1587 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1588 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1589 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
| 1590 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1591 | out.rv = trans1.Start(&httpreq1, callback1.callback(), log); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1592 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1593 | // Run transaction 1 through quickly to force a read of our SETTINGS frame. |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1594 | out.rv = callback1.WaitForResult(); |
| 1595 | ASSERT_EQ(OK, out.rv); |
| 1596 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1597 | out.rv = trans2.Start(&httpreq2, callback2.callback(), log); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1598 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1599 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1600 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
| 1601 | out.rv = callback3.WaitForResult(); |
| 1602 | ASSERT_EQ(ERR_ABORTED, out.rv); |
| 1603 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1604 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
| 1605 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1606 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1607 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1608 | out.status_line = response1->headers->GetStatusLine(); |
| 1609 | out.response_info = *response1; |
| 1610 | out.rv = ReadTransaction(&trans1, &out.response_data); |
| 1611 | EXPECT_EQ(OK, out.rv); |
| 1612 | |
| 1613 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 1614 | ASSERT_TRUE(response2 != NULL); |
| 1615 | out.status_line = response2->headers->GetStatusLine(); |
| 1616 | out.response_info = *response2; |
| 1617 | out.rv = ReadTransaction(&trans2, &out.response_data); |
| 1618 | EXPECT_EQ(ERR_CONNECTION_RESET, out.rv); |
| 1619 | |
| 1620 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1621 | } |
| 1622 | |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1623 | // Test that a simple PUT request works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1624 | TEST_P(SpdyNetworkTransactionTest, Put) { |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1625 | // Setup the request |
| 1626 | HttpRequestInfo request; |
| 1627 | request.method = "PUT"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1628 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1629 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1630 | scoped_ptr<SpdyHeaderBlock> put_headers( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1631 | spdy_util_.ConstructPutHeaderBlock(GetDefaultUrl(), 0)); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1632 | scoped_ptr<SpdyFrame> req( |
| 1633 | spdy_util_.ConstructSpdySyn(1, *put_headers, LOWEST, false, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1634 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1635 | CreateMockWrite(*req, 0), |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1636 | }; |
| 1637 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1638 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1639 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1640 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1641 | CreateMockRead(*resp, 1), |
| 1642 | CreateMockRead(*body, 2), |
| 1643 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1644 | }; |
| 1645 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1646 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1647 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1648 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1649 | helper.RunToCompletion(&data); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1650 | TransactionHelperResult out = helper.output(); |
| 1651 | |
| 1652 | EXPECT_EQ(OK, out.rv); |
| 1653 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1654 | } |
| 1655 | |
| 1656 | // Test that a simple HEAD request works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1657 | TEST_P(SpdyNetworkTransactionTest, Head) { |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1658 | // Setup the request |
| 1659 | HttpRequestInfo request; |
| 1660 | request.method = "HEAD"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1661 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1662 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1663 | scoped_ptr<SpdyHeaderBlock> head_headers( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1664 | spdy_util_.ConstructHeadHeaderBlock(GetDefaultUrl(), 0)); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1665 | scoped_ptr<SpdyFrame> req( |
| 1666 | spdy_util_.ConstructSpdySyn(1, *head_headers, LOWEST, false, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1667 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1668 | CreateMockWrite(*req, 0), |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1669 | }; |
| 1670 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1671 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1672 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1673 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1674 | CreateMockRead(*resp, 1), |
| 1675 | CreateMockRead(*body, 2), |
| 1676 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1677 | }; |
| 1678 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1679 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1680 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1681 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1682 | helper.RunToCompletion(&data); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1683 | TransactionHelperResult out = helper.output(); |
| 1684 | |
| 1685 | EXPECT_EQ(OK, out.rv); |
| 1686 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1687 | } |
| 1688 | |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 1689 | // Test that a simple POST works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1690 | TEST_P(SpdyNetworkTransactionTest, Post) { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1691 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 1692 | GetDefaultUrl(), 1, kUploadDataSize, LOWEST, NULL, 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1693 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1694 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1695 | CreateMockWrite(*req, 0), CreateMockWrite(*body, 1), // POST upload frame |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1696 | }; |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 1697 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1698 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1699 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1700 | CreateMockRead(*resp, 2), |
| 1701 | CreateMockRead(*body, 3), |
| 1702 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 1703 | }; |
| 1704 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1705 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1706 | NormalSpdyTransactionHelper helper(CreatePostRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1707 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1708 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1709 | TransactionHelperResult out = helper.output(); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 1710 | EXPECT_EQ(OK, out.rv); |
| 1711 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1712 | EXPECT_EQ("hello!", out.response_data); |
| 1713 | } |
| 1714 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1715 | // Test that a POST with a file works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1716 | TEST_P(SpdyNetworkTransactionTest, FilePost) { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1717 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 1718 | GetDefaultUrl(), 1, kUploadDataSize, LOWEST, NULL, 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1719 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1720 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1721 | CreateMockWrite(*req, 0), CreateMockWrite(*body, 1), // POST upload frame |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1722 | }; |
| 1723 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1724 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1725 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1726 | CreateMockRead(*resp, 2), |
| 1727 | CreateMockRead(*body, 3), |
| 1728 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1729 | }; |
| 1730 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1731 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1732 | NormalSpdyTransactionHelper helper(CreateFilePostRequest(), DEFAULT_PRIORITY, |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1733 | BoundNetLog(), GetParam(), NULL); |
| 1734 | helper.RunToCompletion(&data); |
| 1735 | TransactionHelperResult out = helper.output(); |
| 1736 | EXPECT_EQ(OK, out.rv); |
| 1737 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1738 | EXPECT_EQ("hello!", out.response_data); |
| 1739 | } |
| 1740 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1741 | // Test that a POST with a unreadable file fails. |
| 1742 | TEST_P(SpdyNetworkTransactionTest, UnreadableFilePost) { |
| 1743 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1744 | MockWrite(ASYNC, 0, 0) // EOF |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1745 | }; |
| 1746 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1747 | MockRead(ASYNC, 0, 1) // EOF |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1748 | }; |
| 1749 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1750 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1751 | NormalSpdyTransactionHelper helper(CreateUnreadableFilePostRequest(), |
| 1752 | DEFAULT_PRIORITY, |
| 1753 | BoundNetLog(), GetParam(), NULL); |
| 1754 | helper.RunPreTestSetup(); |
| 1755 | helper.AddData(&data); |
| 1756 | helper.RunDefaultTest(); |
| 1757 | |
| 1758 | base::RunLoop().RunUntilIdle(); |
| 1759 | helper.VerifyDataNotConsumed(); |
| 1760 | EXPECT_EQ(ERR_ACCESS_DENIED, helper.output().rv); |
| 1761 | } |
| 1762 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1763 | // Test that a complex POST works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1764 | TEST_P(SpdyNetworkTransactionTest, ComplexPost) { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1765 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 1766 | GetDefaultUrl(), 1, kUploadDataSize, LOWEST, NULL, 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1767 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1768 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1769 | CreateMockWrite(*req, 0), CreateMockWrite(*body, 1), // POST upload frame |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1770 | }; |
| 1771 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1772 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1773 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1774 | CreateMockRead(*resp, 2), |
| 1775 | CreateMockRead(*body, 3), |
| 1776 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1777 | }; |
| 1778 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1779 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1780 | NormalSpdyTransactionHelper helper(CreateComplexPostRequest(), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1781 | DEFAULT_PRIORITY, |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1782 | BoundNetLog(), GetParam(), NULL); |
| 1783 | helper.RunToCompletion(&data); |
| 1784 | TransactionHelperResult out = helper.output(); |
| 1785 | EXPECT_EQ(OK, out.rv); |
| 1786 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1787 | EXPECT_EQ("hello!", out.response_data); |
| 1788 | } |
| 1789 | |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1790 | // Test that a chunked POST works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1791 | TEST_P(SpdyNetworkTransactionTest, ChunkedPost) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1792 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1793 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1794 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1795 | CreateMockWrite(*req, 0), CreateMockWrite(*body, 1), |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1796 | }; |
| 1797 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1798 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1799 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1800 | CreateMockRead(*resp, 2), |
| 1801 | CreateMockRead(*body, 3), |
| 1802 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1803 | }; |
| 1804 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1805 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1806 | NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1807 | DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1808 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1809 | |
| 1810 | // These chunks get merged into a single frame when being sent. |
| 1811 | const int kFirstChunkSize = kUploadDataSize/2; |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1812 | upload_chunked_data_stream()->AppendData(kUploadData, kFirstChunkSize, false); |
| 1813 | upload_chunked_data_stream()->AppendData( |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1814 | kUploadData + kFirstChunkSize, kUploadDataSize - kFirstChunkSize, true); |
| 1815 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1816 | helper.RunToCompletion(&data); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1817 | TransactionHelperResult out = helper.output(); |
| 1818 | EXPECT_EQ(OK, out.rv); |
| 1819 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1820 | EXPECT_EQ(kUploadData, out.response_data); |
| 1821 | } |
| 1822 | |
| 1823 | // Test that a chunked POST works with chunks appended after transaction starts. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1824 | TEST_P(SpdyNetworkTransactionTest, DelayedChunkedPost) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1825 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1826 | scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1827 | scoped_ptr<SpdyFrame> chunk2(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1828 | scoped_ptr<SpdyFrame> chunk3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1829 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1830 | CreateMockWrite(*req, 0), |
| 1831 | CreateMockWrite(*chunk1, 1), |
| 1832 | CreateMockWrite(*chunk2, 2), |
| 1833 | CreateMockWrite(*chunk3, 3), |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1834 | }; |
| 1835 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1836 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1837 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1838 | CreateMockRead(*resp, 4), |
| 1839 | CreateMockRead(*chunk1, 5), |
| 1840 | CreateMockRead(*chunk2, 6), |
| 1841 | CreateMockRead(*chunk3, 7), |
| 1842 | MockRead(ASYNC, 0, 8) // EOF |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1843 | }; |
| 1844 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1845 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1846 | NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1847 | DEFAULT_PRIORITY, |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1848 | BoundNetLog(), GetParam(), NULL); |
| 1849 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1850 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, false); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1851 | |
| 1852 | helper.RunPreTestSetup(); |
| 1853 | helper.AddData(&data); |
| 1854 | ASSERT_TRUE(helper.StartDefaultTest()); |
| 1855 | |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 1856 | base::RunLoop().RunUntilIdle(); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1857 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, false); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 1858 | base::RunLoop().RunUntilIdle(); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1859 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, true); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1860 | |
| 1861 | helper.FinishDefaultTest(); |
| 1862 | helper.VerifyDataConsumed(); |
| 1863 | |
| 1864 | std::string expected_response; |
| 1865 | expected_response += kUploadData; |
| 1866 | expected_response += kUploadData; |
| 1867 | expected_response += kUploadData; |
| 1868 | |
| 1869 | TransactionHelperResult out = helper.output(); |
| 1870 | EXPECT_EQ(OK, out.rv); |
| 1871 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1872 | EXPECT_EQ(expected_response, out.response_data); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1873 | } |
| 1874 | |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1875 | // Test that a POST without any post data works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1876 | TEST_P(SpdyNetworkTransactionTest, NullPost) { |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1877 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1878 | // Setup the request |
| 1879 | HttpRequestInfo request; |
| 1880 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1881 | request.url = GURL(GetDefaultUrl()); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1882 | // Create an empty UploadData. |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1883 | request.upload_data_stream = NULL; |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1884 | |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1885 | // When request.upload_data_stream is NULL for post, content-length is |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1886 | // expected to be 0. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1887 | scoped_ptr<SpdyHeaderBlock> req_block( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1888 | spdy_util_.ConstructPostHeaderBlock(GetDefaultUrl(), 0)); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1889 | scoped_ptr<SpdyFrame> req( |
| 1890 | spdy_util_.ConstructSpdySyn(1, *req_block, LOWEST, false, true)); |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1891 | |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1892 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1893 | CreateMockWrite(*req, 0), |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1894 | }; |
| 1895 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1896 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 1897 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1898 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1899 | CreateMockRead(*resp, 1), |
| 1900 | CreateMockRead(*body, 2), |
| 1901 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1902 | }; |
| 1903 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1904 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1905 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1906 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1907 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1908 | helper.RunToCompletion(&data); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1909 | TransactionHelperResult out = helper.output(); |
| 1910 | EXPECT_EQ(OK, out.rv); |
| 1911 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1912 | EXPECT_EQ("hello!", out.response_data); |
| 1913 | } |
| 1914 | |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1915 | // Test that a simple POST works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1916 | TEST_P(SpdyNetworkTransactionTest, EmptyPost) { |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1917 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1918 | // Create an empty UploadDataStream. |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 1919 | ScopedVector<UploadElementReader> element_readers; |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1920 | ElementsUploadDataStream stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1921 | |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1922 | // Setup the request |
| 1923 | HttpRequestInfo request; |
| 1924 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1925 | request.url = GURL(GetDefaultUrl()); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1926 | request.upload_data_stream = &stream; |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1927 | |
[email protected] | ad91dc5 | 2012-09-01 03:46:06 | [diff] [blame] | 1928 | const uint64 kContentLength = 0; |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1929 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1930 | scoped_ptr<SpdyHeaderBlock> req_block( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 1931 | spdy_util_.ConstructPostHeaderBlock(GetDefaultUrl(), kContentLength)); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 1932 | scoped_ptr<SpdyFrame> req( |
| 1933 | spdy_util_.ConstructSpdySyn(1, *req_block, LOWEST, false, true)); |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1934 | |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1935 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1936 | CreateMockWrite(*req, 0), |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1937 | }; |
| 1938 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1939 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 1940 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1941 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1942 | CreateMockRead(*resp, 1), |
| 1943 | CreateMockRead(*body, 2), |
| 1944 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1945 | }; |
| 1946 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 1947 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 1948 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1949 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 1950 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1951 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1952 | TransactionHelperResult out = helper.output(); |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 1953 | EXPECT_EQ(OK, out.rv); |
| 1954 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1955 | EXPECT_EQ("hello!", out.response_data); |
| 1956 | } |
| 1957 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1958 | // While we're doing a post, the server sends the reply before upload completes. |
| 1959 | TEST_P(SpdyNetworkTransactionTest, ResponseBeforePostCompletes) { |
| 1960 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1961 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 1962 | MockWrite writes[] = { |
| 1963 | CreateMockWrite(*req, 0), |
| 1964 | CreateMockWrite(*body, 3), |
| 1965 | }; |
| 1966 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | a5566f970 | 2010-05-05 22:25:43 | [diff] [blame] | 1967 | MockRead reads[] = { |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1968 | CreateMockRead(*resp, 1), |
| 1969 | CreateMockRead(*body, 2), |
[email protected] | 099bc7e | 2013-07-18 04:19:16 | [diff] [blame] | 1970 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | a5566f970 | 2010-05-05 22:25:43 | [diff] [blame] | 1971 | }; |
| 1972 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1973 | // Write the request headers, and read the complete response |
| 1974 | // while still waiting for chunked request data. |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 1975 | DeterministicSocketData data(reads, arraysize(reads), |
| 1976 | writes, arraysize(writes)); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1977 | NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
| 1978 | DEFAULT_PRIORITY, |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 1979 | BoundNetLog(), GetParam(), NULL); |
| 1980 | helper.SetDeterministic(); |
| 1981 | helper.RunPreTestSetup(); |
| 1982 | helper.AddDeterministicData(&data); |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 1983 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1984 | ASSERT_TRUE(helper.StartDefaultTest()); |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 1985 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1986 | // Process the request headers, SYN_REPLY, and response body. |
| 1987 | // The request body is still in flight. |
| 1988 | data.RunFor(3); |
| 1989 | |
| 1990 | const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
| 1991 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1992 | |
| 1993 | // Finish sending the request body. |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 1994 | upload_chunked_data_stream()->AppendData(kUploadData, kUploadDataSize, true); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 1995 | data.RunFor(2); |
| 1996 | |
| 1997 | std::string response_body; |
| 1998 | EXPECT_EQ(OK, ReadTransaction(helper.trans(), &response_body)); |
| 1999 | EXPECT_EQ(kUploadData, response_body); |
| 2000 | helper.VerifyDataConsumed(); |
[email protected] | a5566f970 | 2010-05-05 22:25:43 | [diff] [blame] | 2001 | } |
| 2002 | |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2003 | // The client upon cancellation tries to send a RST_STREAM frame. The mock |
| 2004 | // socket causes the TCP write to return zero. This test checks that the client |
| 2005 | // tries to queue up the RST_STREAM frame again. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2006 | TEST_P(SpdyNetworkTransactionTest, SocketWriteReturnsZero) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2007 | scoped_ptr<SpdyFrame> req( |
| 2008 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2009 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2010 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2011 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2012 | CreateMockWrite(*req.get(), 0, SYNCHRONOUS), |
| 2013 | MockWrite(SYNCHRONOUS, 0, 0, 2), |
| 2014 | CreateMockWrite(*rst.get(), 3, SYNCHRONOUS), |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2015 | }; |
| 2016 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2017 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2018 | MockRead reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2019 | CreateMockRead(*resp.get(), 1, ASYNC), |
| 2020 | MockRead(ASYNC, 0, 0, 4) // EOF |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2021 | }; |
| 2022 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2023 | DeterministicSocketData data(reads, arraysize(reads), |
| 2024 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2025 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2026 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2027 | helper.SetDeterministic(); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2028 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2029 | helper.AddDeterministicData(&data); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2030 | HttpNetworkTransaction* trans = helper.trans(); |
| 2031 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2032 | TestCompletionCallback callback; |
| 2033 | int rv = trans->Start( |
| 2034 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2035 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2036 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2037 | data.SetStop(2); |
| 2038 | data.Run(); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2039 | helper.ResetTrans(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2040 | data.SetStop(20); |
| 2041 | data.Run(); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2042 | |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2043 | helper.VerifyDataConsumed(); |
| 2044 | } |
| 2045 | |
[email protected] | 9330067 | 2009-10-24 13:22:51 | [diff] [blame] | 2046 | // 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] | 2047 | TEST_P(SpdyNetworkTransactionTest, ResponseWithoutSynReply) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2048 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 2049 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2050 | CreateMockRead(*body, 1), MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 9330067 | 2009-10-24 13:22:51 | [diff] [blame] | 2051 | }; |
| 2052 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2053 | scoped_ptr<SpdyFrame> req( |
| 2054 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2055 | scoped_ptr<SpdyFrame> rst( |
| 2056 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 2057 | MockWrite writes[] = { |
| 2058 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 2), |
| 2059 | }; |
| 2060 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2061 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2062 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2063 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2064 | TransactionHelperResult out = helper.output(); |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 2065 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | 9330067 | 2009-10-24 13:22:51 | [diff] [blame] | 2066 | } |
| 2067 | |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2068 | // Test that the transaction doesn't crash when we get two replies on the same |
| 2069 | // stream ID. See http://crbug.com/45639. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2070 | TEST_P(SpdyNetworkTransactionTest, ResponseWithTwoSynReplies) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2071 | scoped_ptr<SpdyFrame> req( |
| 2072 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 2073 | scoped_ptr<SpdyFrame> rst( |
[email protected] | 00b2947 | 2014-01-16 18:10:24 | [diff] [blame] | 2074 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 2075 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2076 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 4), |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 2077 | }; |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2078 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2079 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2080 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2081 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2082 | CreateMockRead(*resp, 1), |
| 2083 | CreateMockRead(*resp, 2), |
| 2084 | CreateMockRead(*body, 3), |
| 2085 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2086 | }; |
| 2087 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2088 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2089 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2090 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2091 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2092 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2093 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2094 | |
| 2095 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2096 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2097 | TestCompletionCallback callback; |
| 2098 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2099 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2100 | rv = callback.WaitForResult(); |
| 2101 | EXPECT_EQ(OK, rv); |
| 2102 | |
| 2103 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | a5c493b9 | 2010-08-06 23:04:29 | [diff] [blame] | 2104 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2105 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2106 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 2107 | std::string response_data; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2108 | rv = ReadTransaction(trans, &response_data); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2109 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, rv); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2110 | |
| 2111 | helper.VerifyDataConsumed(); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2112 | } |
| 2113 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2114 | TEST_P(SpdyNetworkTransactionTest, ResetReplyWithTransferEncoding) { |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2115 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2116 | scoped_ptr<SpdyFrame> req( |
| 2117 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 2118 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2119 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2120 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2121 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 2), |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2122 | }; |
| 2123 | |
| 2124 | const char* const headers[] = { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2125 | "transfer-encoding", "chunked" |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2126 | }; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2127 | scoped_ptr<SpdyFrame> resp( |
| 2128 | spdy_util_.ConstructSpdyGetSynReply(headers, 1, 1)); |
| 2129 | scoped_ptr<SpdyFrame> body( |
| 2130 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2131 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2132 | CreateMockRead(*resp, 1), |
| 2133 | CreateMockRead(*body, 3), |
| 2134 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2135 | }; |
| 2136 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2137 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2138 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2139 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2140 | helper.RunToCompletion(&data); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2141 | TransactionHelperResult out = helper.output(); |
| 2142 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 2143 | |
| 2144 | helper.session()->spdy_session_pool()->CloseAllSessions(); |
| 2145 | helper.VerifyDataConsumed(); |
| 2146 | } |
| 2147 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2148 | TEST_P(SpdyNetworkTransactionTest, ResetPushWithTransferEncoding) { |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2149 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2150 | scoped_ptr<SpdyFrame> req( |
| 2151 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 2152 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2153 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2154 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2155 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 4), |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2156 | }; |
| 2157 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2158 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2159 | const char* const headers[] = { |
| 2160 | "transfer-encoding", "chunked" |
| 2161 | }; |
| 2162 | scoped_ptr<SpdyFrame> push( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2163 | spdy_util_.ConstructSpdyPush(headers, arraysize(headers) / 2, 2, 1, |
| 2164 | GetDefaultUrlWithPath("/1").c_str())); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2165 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2166 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2167 | CreateMockRead(*resp, 1), |
| 2168 | CreateMockRead(*push, 2), |
| 2169 | CreateMockRead(*body, 3), |
| 2170 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2171 | }; |
| 2172 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2173 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2174 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2175 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2176 | helper.RunToCompletion(&data); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2177 | TransactionHelperResult out = helper.output(); |
| 2178 | EXPECT_EQ(OK, out.rv); |
| 2179 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 2180 | EXPECT_EQ("hello!", out.response_data); |
| 2181 | |
| 2182 | helper.session()->spdy_session_pool()->CloseAllSessions(); |
| 2183 | helper.VerifyDataConsumed(); |
| 2184 | } |
| 2185 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2186 | TEST_P(SpdyNetworkTransactionTest, CancelledTransaction) { |
[email protected] | 75f30cc2 | 2010-06-28 21:41:38 | [diff] [blame] | 2187 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2188 | scoped_ptr<SpdyFrame> req( |
| 2189 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2190 | MockWrite writes[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2191 | CreateMockWrite(*req), |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2192 | }; |
| 2193 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2194 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2195 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2196 | CreateMockRead(*resp), |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2197 | // This following read isn't used by the test, except during the |
[email protected] | b4c62eb | 2012-11-14 18:36:51 | [diff] [blame] | 2198 | // RunUntilIdle() call at the end since the SpdySession survives the |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2199 | // HttpNetworkTransaction and still tries to continue Read()'ing. Any |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2200 | // MockRead will do here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2201 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2202 | }; |
| 2203 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2204 | StaticSocketDataProvider data(reads, arraysize(reads), |
| 2205 | writes, arraysize(writes)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2206 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2207 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2208 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2209 | helper.RunPreTestSetup(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2210 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2211 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2212 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2213 | TestCompletionCallback callback; |
| 2214 | int rv = trans->Start( |
| 2215 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2216 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2217 | helper.ResetTrans(); // Cancel the transaction. |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2218 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 2219 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2220 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2221 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2222 | helper.VerifyDataNotConsumed(); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2223 | } |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 2224 | |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2225 | // Verify that the client sends a Rst Frame upon cancelling the stream. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2226 | TEST_P(SpdyNetworkTransactionTest, CancelledTransactionSendRst) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2227 | scoped_ptr<SpdyFrame> req( |
| 2228 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2229 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2230 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2231 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2232 | CreateMockWrite(*req, 0, SYNCHRONOUS), |
| 2233 | CreateMockWrite(*rst, 2, SYNCHRONOUS), |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2234 | }; |
| 2235 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2236 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2237 | MockRead reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2238 | CreateMockRead(*resp, 1, ASYNC), |
| 2239 | MockRead(ASYNC, 0, 0, 3) // EOF |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2240 | }; |
| 2241 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2242 | DeterministicSocketData data(reads, arraysize(reads), |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2243 | writes, arraysize(writes)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2244 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2245 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2246 | BoundNetLog(), |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2247 | GetParam(), NULL); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2248 | helper.SetDeterministic(); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2249 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2250 | helper.AddDeterministicData(&data); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2251 | HttpNetworkTransaction* trans = helper.trans(); |
| 2252 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2253 | TestCompletionCallback callback; |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2254 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2255 | int rv = trans->Start( |
| 2256 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2257 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2258 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2259 | data.SetStop(2); |
| 2260 | data.Run(); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2261 | helper.ResetTrans(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2262 | data.SetStop(20); |
| 2263 | data.Run(); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2264 | |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2265 | helper.VerifyDataConsumed(); |
| 2266 | } |
| 2267 | |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2268 | // Verify that the client can correctly deal with the user callback attempting |
| 2269 | // to start another transaction on a session that is closing down. See |
| 2270 | // http://crbug.com/47455 |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2271 | TEST_P(SpdyNetworkTransactionTest, StartTransactionOnReadCallback) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2272 | scoped_ptr<SpdyFrame> req( |
| 2273 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2274 | MockWrite writes[] = {CreateMockWrite(*req)}; |
| 2275 | MockWrite writes2[] = {CreateMockWrite(*req, 0)}; |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2276 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 2277 | // The indicated length of this frame is longer than its actual length. When |
| 2278 | // the session receives an empty frame after this one, it shuts down the |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2279 | // session, and calls the read callback with the incomplete data. |
| 2280 | const uint8 kGetBodyFrame2[] = { |
| 2281 | 0x00, 0x00, 0x00, 0x01, |
| 2282 | 0x01, 0x00, 0x00, 0x07, |
| 2283 | 'h', 'e', 'l', 'l', 'o', '!', |
| 2284 | }; |
| 2285 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2286 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2287 | MockRead reads[] = { |
| 2288 | CreateMockRead(*resp, 2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2289 | MockRead(ASYNC, ERR_IO_PENDING, 3), // Force a pause |
| 2290 | MockRead(ASYNC, reinterpret_cast<const char*>(kGetBodyFrame2), |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2291 | arraysize(kGetBodyFrame2), 4), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2292 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
| 2293 | MockRead(ASYNC, 0, 0, 6), // EOF |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2294 | }; |
| 2295 | MockRead reads2[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2296 | CreateMockRead(*resp, 1), MockRead(ASYNC, 0, 0, 2), // EOF |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2297 | }; |
| 2298 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2299 | OrderedSocketData data(reads, arraysize(reads), |
| 2300 | writes, arraysize(writes)); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2301 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 2302 | arraysize(writes2)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2303 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2304 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2305 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2306 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2307 | helper.AddData(&data); |
| 2308 | helper.AddData(&data2); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2309 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2310 | |
| 2311 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2312 | TestCompletionCallback callback; |
| 2313 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2314 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2315 | rv = callback.WaitForResult(); |
| 2316 | |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2317 | const int kSize = 3000; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 2318 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSize)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2319 | rv = trans->Read( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2320 | buf.get(), kSize, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2321 | base::Bind(&SpdyNetworkTransactionTest::StartTransactionCallback, |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2322 | helper.session(), GURL(GetDefaultUrl()))); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2323 | // This forces an err_IO_pending, which sets the callback. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2324 | data.CompleteRead(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2325 | // This finishes the read. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2326 | data.CompleteRead(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2327 | helper.VerifyDataConsumed(); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2328 | } |
| 2329 | |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2330 | // Verify that the client can correctly deal with the user callback deleting the |
| 2331 | // transaction. Failures will usually be valgrind errors. See |
| 2332 | // http://crbug.com/46925 |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2333 | TEST_P(SpdyNetworkTransactionTest, DeleteSessionOnReadCallback) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2334 | scoped_ptr<SpdyFrame> req( |
| 2335 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2336 | MockWrite writes[] = { CreateMockWrite(*req) }; |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2337 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2338 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2339 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2340 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2341 | CreateMockRead(*resp.get(), 2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2342 | MockRead(ASYNC, ERR_IO_PENDING, 3), // Force a pause |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2343 | CreateMockRead(*body.get(), 4), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2344 | MockRead(ASYNC, 0, 0, 5), // EOF |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2345 | }; |
| 2346 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2347 | OrderedSocketData data(reads, arraysize(reads), |
| 2348 | writes, arraysize(writes)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2349 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2350 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2351 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2352 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2353 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2354 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2355 | |
| 2356 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2357 | TestCompletionCallback callback; |
| 2358 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2359 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2360 | rv = callback.WaitForResult(); |
| 2361 | |
| 2362 | // Setup a user callback which will delete the session, and clear out the |
| 2363 | // memory holding the stream object. Note that the callback deletes trans. |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2364 | const int kSize = 3000; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 2365 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSize)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2366 | rv = trans->Read( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2367 | buf.get(), |
| 2368 | kSize, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2369 | base::Bind(&SpdyNetworkTransactionTest::DeleteSessionCallback, |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2370 | base::Unretained(&helper))); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2371 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2372 | data.CompleteRead(); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2373 | |
| 2374 | // Finish running rest of tasks. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2375 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2376 | helper.VerifyDataConsumed(); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2377 | } |
| 2378 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2379 | // 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] | 2380 | TEST_P(SpdyNetworkTransactionTest, DISABLED_RedirectGetRequest) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2381 | scoped_ptr<SpdyHeaderBlock> headers( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2382 | spdy_util_.ConstructGetHeaderBlock(GetDefaultUrl())); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2383 | (*headers)["user-agent"] = ""; |
jgraettinger | 8f00db8b | 2014-09-24 23:00:06 | [diff] [blame] | 2384 | (*headers)["accept-encoding"] = "gzip, deflate"; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2385 | scoped_ptr<SpdyHeaderBlock> headers2( |
| 2386 | spdy_util_.ConstructGetHeaderBlock("http://www.foo.com/index.php")); |
| 2387 | (*headers2)["user-agent"] = ""; |
jgraettinger | 8f00db8b | 2014-09-24 23:00:06 | [diff] [blame] | 2388 | (*headers2)["accept-encoding"] = "gzip, deflate"; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2389 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2390 | // Setup writes/reads to www.example.org |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 2391 | scoped_ptr<SpdyFrame> req( |
| 2392 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
| 2393 | scoped_ptr<SpdyFrame> req2( |
| 2394 | spdy_util_.ConstructSpdySyn(1, *headers2, LOWEST, false, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2395 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReplyRedirect(1)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2396 | MockWrite writes[] = { |
| 2397 | CreateMockWrite(*req, 1), |
| 2398 | }; |
| 2399 | MockRead reads[] = { |
| 2400 | CreateMockRead(*resp, 2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2401 | MockRead(ASYNC, 0, 0, 3) // EOF |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2402 | }; |
| 2403 | |
| 2404 | // Setup writes/reads to www.foo.com |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2405 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2406 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2407 | MockWrite writes2[] = { |
| 2408 | CreateMockWrite(*req2, 1), |
| 2409 | }; |
| 2410 | MockRead reads2[] = { |
| 2411 | CreateMockRead(*resp2, 2), |
| 2412 | CreateMockRead(*body2, 3), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2413 | MockRead(ASYNC, 0, 0, 4) // EOF |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2414 | }; |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2415 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2416 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 2417 | arraysize(writes2)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2418 | |
| 2419 | // TODO(erikchen): Make test support SPDYSSL, SPDYNPN |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2420 | TestDelegate d; |
| 2421 | { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2422 | SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); |
davidben | 151423e | 2015-03-23 18:48:36 | [diff] [blame] | 2423 | scoped_ptr<URLRequest> r(spdy_url_request_context.CreateRequest( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2424 | GURL(GetDefaultUrl()), DEFAULT_PRIORITY, &d)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2425 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2426 | AddSocketDataProvider(&data); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2427 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2428 | AddSocketDataProvider(&data2); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2429 | |
| 2430 | d.set_quit_on_redirect(true); |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2431 | r->Start(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2432 | base::RunLoop().Run(); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2433 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2434 | EXPECT_EQ(1, d.received_redirect_count()); |
| 2435 | |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2436 | r->FollowDeferredRedirect(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2437 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2438 | EXPECT_EQ(1, d.response_started_count()); |
| 2439 | EXPECT_FALSE(d.received_data_before_response()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 2440 | EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2441 | std::string contents("hello!"); |
| 2442 | EXPECT_EQ(contents, d.data_received()); |
| 2443 | } |
rch | bce10d97 | 2015-05-04 18:21:19 | [diff] [blame] | 2444 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2445 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 2446 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 2447 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2448 | } |
| 2449 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2450 | // 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] | 2451 | // www.foo.com. |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2452 | TEST_P(SpdyNetworkTransactionTest, DISABLED_RedirectServerPush) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2453 | scoped_ptr<SpdyHeaderBlock> headers( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2454 | spdy_util_.ConstructGetHeaderBlock(GetDefaultUrl())); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2455 | (*headers)["user-agent"] = ""; |
jgraettinger | 8f00db8b | 2014-09-24 23:00:06 | [diff] [blame] | 2456 | (*headers)["accept-encoding"] = "gzip, deflate"; |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2457 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2458 | // Setup writes/reads to www.example.org |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2459 | scoped_ptr<SpdyFrame> req( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 2460 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2461 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2462 | scoped_ptr<SpdyFrame> rep(spdy_util_.ConstructSpdyPush( |
| 2463 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str(), |
| 2464 | "301 Moved Permanently", "http://www.foo.com/index.php")); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2465 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2466 | scoped_ptr<SpdyFrame> rst( |
| 2467 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_CANCEL)); |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2468 | MockWrite writes[] = { |
| 2469 | CreateMockWrite(*req, 1), |
| 2470 | CreateMockWrite(*rst, 6), |
| 2471 | }; |
| 2472 | MockRead reads[] = { |
| 2473 | CreateMockRead(*resp, 2), |
| 2474 | CreateMockRead(*rep, 3), |
| 2475 | CreateMockRead(*body, 4), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2476 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
| 2477 | MockRead(ASYNC, 0, 0, 7) // EOF |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2478 | }; |
| 2479 | |
| 2480 | // Setup writes/reads to www.foo.com |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2481 | scoped_ptr<SpdyHeaderBlock> headers2( |
| 2482 | spdy_util_.ConstructGetHeaderBlock("http://www.foo.com/index.php")); |
| 2483 | (*headers2)["user-agent"] = ""; |
jgraettinger | 8f00db8b | 2014-09-24 23:00:06 | [diff] [blame] | 2484 | (*headers2)["accept-encoding"] = "gzip, deflate"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2485 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 2486 | spdy_util_.ConstructSpdySyn(1, *headers2, LOWEST, false, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2487 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2488 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2489 | MockWrite writes2[] = { |
| 2490 | CreateMockWrite(*req2, 1), |
| 2491 | }; |
| 2492 | MockRead reads2[] = { |
| 2493 | CreateMockRead(*resp2, 2), |
| 2494 | CreateMockRead(*body2, 3), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2495 | MockRead(ASYNC, 0, 0, 5) // EOF |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2496 | }; |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2497 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2498 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 2499 | arraysize(writes2)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2500 | |
| 2501 | // TODO(erikchen): Make test support SPDYSSL, SPDYNPN |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2502 | TestDelegate d; |
| 2503 | TestDelegate d2; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2504 | SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2505 | { |
davidben | 151423e | 2015-03-23 18:48:36 | [diff] [blame] | 2506 | scoped_ptr<URLRequest> r(spdy_url_request_context.CreateRequest( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2507 | GURL(GetDefaultUrl()), DEFAULT_PRIORITY, &d)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2508 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2509 | AddSocketDataProvider(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2510 | |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2511 | r->Start(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2512 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2513 | |
| 2514 | EXPECT_EQ(0, d.received_redirect_count()); |
| 2515 | std::string contents("hello!"); |
| 2516 | EXPECT_EQ(contents, d.data_received()); |
| 2517 | |
davidben | 151423e | 2015-03-23 18:48:36 | [diff] [blame] | 2518 | scoped_ptr<URLRequest> r2(spdy_url_request_context.CreateRequest( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2519 | GURL(GetDefaultUrlWithPath("/foo.dat")), DEFAULT_PRIORITY, &d2)); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2520 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2521 | AddSocketDataProvider(&data2); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2522 | |
| 2523 | d2.set_quit_on_redirect(true); |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2524 | r2->Start(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2525 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2526 | EXPECT_EQ(1, d2.received_redirect_count()); |
| 2527 | |
[email protected] | f7022f3 | 2014-08-21 16:32:19 | [diff] [blame] | 2528 | r2->FollowDeferredRedirect(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2529 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2530 | EXPECT_EQ(1, d2.response_started_count()); |
| 2531 | EXPECT_FALSE(d2.received_data_before_response()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 2532 | EXPECT_EQ(URLRequestStatus::SUCCESS, r2->status().status()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2533 | std::string contents2("hello!"); |
| 2534 | EXPECT_EQ(contents2, d2.data_received()); |
| 2535 | } |
rch | bce10d97 | 2015-05-04 18:21:19 | [diff] [blame] | 2536 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2537 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 2538 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 2539 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2540 | } |
| 2541 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2542 | TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2543 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2544 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2545 | scoped_ptr<SpdyFrame> stream1_body( |
| 2546 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2547 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2548 | CreateMockWrite(*stream1_syn, 0), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2549 | }; |
| 2550 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2551 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2552 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2553 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2554 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2555 | const char kPushedData[] = "pushed"; |
| 2556 | scoped_ptr<SpdyFrame> stream2_body( |
| 2557 | spdy_util_.ConstructSpdyBodyFrame( |
| 2558 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2559 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2560 | CreateMockRead(*stream1_reply, 1), |
| 2561 | CreateMockRead(*stream2_syn, 2), |
| 2562 | CreateMockRead(*stream1_body, 3, SYNCHRONOUS), |
| 2563 | CreateMockRead(*stream2_body, 4), |
| 2564 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2565 | }; |
| 2566 | |
| 2567 | HttpResponseInfo response; |
| 2568 | HttpResponseInfo response2; |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2569 | std::string expected_push_result("pushed"); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2570 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2571 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2572 | &response, |
| 2573 | &response2, |
| 2574 | expected_push_result); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2575 | |
| 2576 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2577 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2578 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2579 | |
| 2580 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2581 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2582 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2583 | } |
| 2584 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2585 | TEST_P(SpdyNetworkTransactionTest, ServerPushBeforeSynReply) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2586 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2587 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2588 | scoped_ptr<SpdyFrame> stream1_body( |
| 2589 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2590 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2591 | CreateMockWrite(*stream1_syn, 0), |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2592 | }; |
| 2593 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2594 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2595 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2596 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2597 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2598 | const char kPushedData[] = "pushed"; |
| 2599 | scoped_ptr<SpdyFrame> stream2_body( |
| 2600 | spdy_util_.ConstructSpdyBodyFrame( |
| 2601 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2602 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2603 | CreateMockRead(*stream2_syn, 1), |
| 2604 | CreateMockRead(*stream1_reply, 2), |
| 2605 | CreateMockRead(*stream1_body, 3, SYNCHRONOUS), |
| 2606 | CreateMockRead(*stream2_body, 4), |
| 2607 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2608 | }; |
| 2609 | |
| 2610 | HttpResponseInfo response; |
| 2611 | HttpResponseInfo response2; |
| 2612 | std::string expected_push_result("pushed"); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2613 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2614 | RunServerPushTest(&data, |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2615 | &response, |
| 2616 | &response2, |
| 2617 | expected_push_result); |
| 2618 | |
| 2619 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2620 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2621 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2622 | |
| 2623 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2624 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2625 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2626 | } |
| 2627 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2628 | TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame2) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2629 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2630 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2631 | MockWrite writes[] = { |
| 2632 | CreateMockWrite(*stream1_syn, 0), |
| 2633 | }; |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2634 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2635 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2636 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2637 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2638 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2639 | const char kPushedData[] = "pushed"; |
| 2640 | scoped_ptr<SpdyFrame> stream2_body( |
| 2641 | spdy_util_.ConstructSpdyBodyFrame( |
| 2642 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2643 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2644 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2645 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2646 | CreateMockRead(*stream1_reply, 1), |
| 2647 | CreateMockRead(*stream2_syn, 2), |
| 2648 | CreateMockRead(*stream2_body, 3), |
| 2649 | CreateMockRead(*stream1_body, 4, SYNCHRONOUS), |
| 2650 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2651 | }; |
| 2652 | |
| 2653 | HttpResponseInfo response; |
| 2654 | HttpResponseInfo response2; |
| 2655 | std::string expected_push_result("pushed"); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2656 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2657 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2658 | &response, |
| 2659 | &response2, |
| 2660 | expected_push_result); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2661 | |
| 2662 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2663 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2664 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2665 | |
| 2666 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2667 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2668 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2669 | } |
| 2670 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2671 | TEST_P(SpdyNetworkTransactionTest, ServerPushServerAborted) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2672 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2673 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2674 | scoped_ptr<SpdyFrame> stream1_body( |
| 2675 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2676 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2677 | CreateMockWrite(*stream1_syn, 0), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2678 | }; |
| 2679 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2680 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2681 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2682 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2683 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2684 | scoped_ptr<SpdyFrame> stream2_rst( |
| 2685 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2686 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2687 | CreateMockRead(*stream1_reply, 1), |
| 2688 | CreateMockRead(*stream2_syn, 2), |
| 2689 | CreateMockRead(*stream2_rst, 3), |
| 2690 | CreateMockRead(*stream1_body, 4, SYNCHRONOUS), |
| 2691 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2692 | }; |
| 2693 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2694 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2695 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2696 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2697 | |
| 2698 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2699 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2700 | |
| 2701 | HttpNetworkTransaction* trans = helper.trans(); |
| 2702 | |
| 2703 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2704 | TestCompletionCallback callback; |
| 2705 | int rv = trans->Start( |
| 2706 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2707 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2708 | rv = callback.WaitForResult(); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2709 | EXPECT_EQ(OK, rv); |
| 2710 | |
| 2711 | // Verify that we consumed all test data. |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2712 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2713 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2714 | |
| 2715 | // Verify the SYN_REPLY. |
| 2716 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2717 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2718 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2719 | } |
| 2720 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2721 | // Verify that we don't leak streams and that we properly send a reset |
| 2722 | // if the server pushes the same stream twice. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2723 | TEST_P(SpdyNetworkTransactionTest, ServerPushDuplicate) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2724 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2725 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2726 | scoped_ptr<SpdyFrame> stream1_body( |
| 2727 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2728 | scoped_ptr<SpdyFrame> stream3_rst( |
| 2729 | spdy_util_.ConstructSpdyRstStream(4, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2730 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2731 | CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*stream3_rst, 4), |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2732 | }; |
| 2733 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2734 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2735 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2736 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2737 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2738 | const char kPushedData[] = "pushed"; |
| 2739 | scoped_ptr<SpdyFrame> stream2_body( |
| 2740 | spdy_util_.ConstructSpdyBodyFrame( |
| 2741 | 2, kPushedData, strlen(kPushedData), true)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2742 | scoped_ptr<SpdyFrame> stream3_syn(spdy_util_.ConstructSpdyPush( |
| 2743 | NULL, 0, 4, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2744 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2745 | CreateMockRead(*stream1_reply, 1), |
| 2746 | CreateMockRead(*stream2_syn, 2), |
| 2747 | CreateMockRead(*stream3_syn, 3), |
| 2748 | CreateMockRead(*stream1_body, 5), |
| 2749 | CreateMockRead(*stream2_body, 6), |
| 2750 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 7), // Force a pause |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2751 | }; |
| 2752 | |
| 2753 | HttpResponseInfo response; |
| 2754 | HttpResponseInfo response2; |
| 2755 | std::string expected_push_result("pushed"); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2756 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2757 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2758 | &response, |
| 2759 | &response2, |
| 2760 | expected_push_result); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2761 | |
| 2762 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2763 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2764 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2765 | |
| 2766 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2767 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2768 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2769 | } |
| 2770 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2771 | TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrame) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2772 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2773 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2774 | scoped_ptr<SpdyFrame> stream1_body( |
| 2775 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2776 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2777 | CreateMockWrite(*stream1_syn, 0), |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2778 | }; |
| 2779 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2780 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2781 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2782 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2783 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2784 | static const char kPushedData[] = "pushed my darling hello my baby"; |
| 2785 | scoped_ptr<SpdyFrame> stream2_body_base( |
| 2786 | spdy_util_.ConstructSpdyBodyFrame( |
| 2787 | 2, kPushedData, strlen(kPushedData), true)); |
| 2788 | const size_t kChunkSize = strlen(kPushedData) / 4; |
| 2789 | scoped_ptr<SpdyFrame> stream2_body1( |
| 2790 | new SpdyFrame(stream2_body_base->data(), kChunkSize, false)); |
| 2791 | scoped_ptr<SpdyFrame> stream2_body2( |
| 2792 | new SpdyFrame(stream2_body_base->data() + kChunkSize, kChunkSize, false)); |
| 2793 | scoped_ptr<SpdyFrame> stream2_body3( |
| 2794 | new SpdyFrame(stream2_body_base->data() + 2 * kChunkSize, |
| 2795 | kChunkSize, false)); |
| 2796 | scoped_ptr<SpdyFrame> stream2_body4( |
| 2797 | new SpdyFrame(stream2_body_base->data() + 3 * kChunkSize, |
| 2798 | stream2_body_base->size() - 3 * kChunkSize, false)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2799 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2800 | CreateMockRead(*stream1_reply, 1), |
| 2801 | CreateMockRead(*stream2_syn, 2), |
| 2802 | CreateMockRead(*stream2_body1, 3), |
| 2803 | CreateMockRead(*stream2_body2, 4), |
| 2804 | CreateMockRead(*stream2_body3, 5), |
| 2805 | CreateMockRead(*stream2_body4, 6), |
| 2806 | CreateMockRead(*stream1_body, 7, SYNCHRONOUS), |
| 2807 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), // Force a pause |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2808 | }; |
| 2809 | |
| 2810 | HttpResponseInfo response; |
| 2811 | HttpResponseInfo response2; |
| 2812 | std::string expected_push_result("pushed my darling hello my baby"); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2813 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2814 | RunServerPushTest(&data, &response, &response2, kPushedData); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2815 | |
| 2816 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2817 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2818 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2819 | |
| 2820 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2821 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2822 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2823 | } |
| 2824 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2825 | TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrameInterrupted) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2826 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2827 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2828 | scoped_ptr<SpdyFrame> stream1_body( |
| 2829 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2830 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2831 | CreateMockWrite(*stream1_syn, 0), |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2832 | }; |
| 2833 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2834 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2835 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2836 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2837 | NULL, 0, 2, 1, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2838 | static const char kPushedData[] = "pushed my darling hello my baby"; |
| 2839 | scoped_ptr<SpdyFrame> stream2_body_base( |
| 2840 | spdy_util_.ConstructSpdyBodyFrame( |
| 2841 | 2, kPushedData, strlen(kPushedData), true)); |
| 2842 | const size_t kChunkSize = strlen(kPushedData) / 4; |
| 2843 | scoped_ptr<SpdyFrame> stream2_body1( |
| 2844 | new SpdyFrame(stream2_body_base->data(), kChunkSize, false)); |
| 2845 | scoped_ptr<SpdyFrame> stream2_body2( |
| 2846 | new SpdyFrame(stream2_body_base->data() + kChunkSize, kChunkSize, false)); |
| 2847 | scoped_ptr<SpdyFrame> stream2_body3( |
| 2848 | new SpdyFrame(stream2_body_base->data() + 2 * kChunkSize, |
| 2849 | kChunkSize, false)); |
| 2850 | scoped_ptr<SpdyFrame> stream2_body4( |
| 2851 | new SpdyFrame(stream2_body_base->data() + 3 * kChunkSize, |
| 2852 | stream2_body_base->size() - 3 * kChunkSize, false)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2853 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2854 | CreateMockRead(*stream1_reply, 1), |
| 2855 | CreateMockRead(*stream2_syn, 2), |
| 2856 | CreateMockRead(*stream2_body1, 3), |
| 2857 | CreateMockRead(*stream2_body2, 4), |
| 2858 | CreateMockRead(*stream2_body3, 5), |
| 2859 | CreateMockRead(*stream2_body4, 6), |
| 2860 | CreateMockRead(*stream1_body.get(), 7, SYNCHRONOUS), |
| 2861 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8) // Force a pause. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2862 | }; |
| 2863 | |
| 2864 | HttpResponseInfo response; |
| 2865 | HttpResponseInfo response2; |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2866 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2867 | RunServerPushTest(&data, &response, &response2, kPushedData); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2868 | |
| 2869 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2870 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2871 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2872 | |
| 2873 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2874 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2875 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2876 | } |
| 2877 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2878 | TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID0) { |
[email protected] | 00b2947 | 2014-01-16 18:10:24 | [diff] [blame] | 2879 | if (spdy_util_.spdy_version() == SPDY4) { |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 2880 | // PUSH_PROMISE with stream id 0 is connection-level error. |
| 2881 | // TODO(baranovich): Test session going away. |
[email protected] | 00b2947 | 2014-01-16 18:10:24 | [diff] [blame] | 2882 | return; |
| 2883 | } |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 2884 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2885 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2886 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2887 | scoped_ptr<SpdyFrame> stream1_body( |
| 2888 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2889 | scoped_ptr<SpdyFrame> stream2_rst( |
| 2890 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2891 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2892 | CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*stream2_rst, 3), |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2893 | }; |
| 2894 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2895 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2896 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2897 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2898 | NULL, 0, 2, 0, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2899 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2900 | CreateMockRead(*stream1_reply, 1), |
| 2901 | CreateMockRead(*stream2_syn, 2), |
| 2902 | CreateMockRead(*stream1_body, 4), |
| 2903 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5) // Force a pause |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2904 | }; |
| 2905 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2906 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2907 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2908 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2909 | |
| 2910 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2911 | helper.AddData(&data); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2912 | |
| 2913 | HttpNetworkTransaction* trans = helper.trans(); |
| 2914 | |
| 2915 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2916 | TestCompletionCallback callback; |
| 2917 | int rv = trans->Start( |
| 2918 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2919 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2920 | rv = callback.WaitForResult(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2921 | EXPECT_EQ(OK, rv); |
| 2922 | |
| 2923 | // Verify that we consumed all test data. |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2924 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2925 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2926 | |
| 2927 | // Verify the SYN_REPLY. |
| 2928 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2929 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2930 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2931 | } |
| 2932 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2933 | TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID9) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2934 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2935 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2936 | scoped_ptr<SpdyFrame> stream1_body( |
| 2937 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2938 | scoped_ptr<SpdyFrame> stream2_rst( |
| 2939 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_INVALID_STREAM)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2940 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2941 | CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*stream2_rst, 3), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2942 | }; |
| 2943 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2944 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2945 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 2946 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2947 | NULL, 0, 2, 9, GetDefaultUrlWithPath("/foo.dat").c_str())); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2948 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2949 | CreateMockRead(*stream1_reply, 1), |
| 2950 | CreateMockRead(*stream2_syn, 2), |
| 2951 | CreateMockRead(*stream1_body, 4), |
| 2952 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2953 | }; |
| 2954 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2955 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2956 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2957 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2958 | |
| 2959 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2960 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2961 | |
| 2962 | HttpNetworkTransaction* trans = helper.trans(); |
| 2963 | |
| 2964 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2965 | TestCompletionCallback callback; |
| 2966 | int rv = trans->Start( |
| 2967 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2968 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2969 | rv = callback.WaitForResult(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2970 | EXPECT_EQ(OK, rv); |
| 2971 | |
| 2972 | // Verify that we consumed all test data. |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2973 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 2974 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2975 | |
| 2976 | // Verify the SYN_REPLY. |
| 2977 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2978 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2979 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2980 | } |
| 2981 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2982 | TEST_P(SpdyNetworkTransactionTest, ServerPushNoURL) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2983 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2984 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2985 | scoped_ptr<SpdyFrame> stream1_body( |
| 2986 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2987 | scoped_ptr<SpdyFrame> stream2_rst( |
| 2988 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2989 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 2990 | CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*stream2_rst, 3), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2991 | }; |
| 2992 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2993 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2994 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8b9211d | 2013-06-24 05:54:45 | [diff] [blame] | 2995 | scoped_ptr<SpdyHeaderBlock> incomplete_headers(new SpdyHeaderBlock()); |
| 2996 | (*incomplete_headers)["hello"] = "bye"; |
| 2997 | (*incomplete_headers)[spdy_util_.GetStatusKey()] = "200 OK"; |
| 2998 | (*incomplete_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 2999 | scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructInitialSpdyPushFrame( |
| 3000 | incomplete_headers.Pass(), 2, 1)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3001 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3002 | CreateMockRead(*stream1_reply, 1), |
| 3003 | CreateMockRead(*stream2_syn, 2), |
| 3004 | CreateMockRead(*stream1_body, 4), |
| 3005 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5) // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3006 | }; |
| 3007 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3008 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3009 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3010 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3011 | |
| 3012 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3013 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3014 | |
| 3015 | HttpNetworkTransaction* trans = helper.trans(); |
| 3016 | |
| 3017 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3018 | TestCompletionCallback callback; |
| 3019 | int rv = trans->Start( |
| 3020 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3021 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3022 | rv = callback.WaitForResult(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3023 | EXPECT_EQ(OK, rv); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3024 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3025 | // Verify that we consumed all test data. |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3026 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 3027 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3028 | |
| 3029 | // Verify the SYN_REPLY. |
| 3030 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3031 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3032 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 3033 | } |
| 3034 | |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3035 | // Verify that various SynReply headers parse correctly through the |
| 3036 | // HTTP layer. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3037 | TEST_P(SpdyNetworkTransactionTest, SynReplyHeaders) { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3038 | struct SynReplyHeadersTests { |
| 3039 | int num_headers; |
| 3040 | const char* extra_headers[5]; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3041 | SpdyHeaderBlock expected_headers; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3042 | } test_cases[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3043 | // This uses a multi-valued cookie header. |
| 3044 | { 2, |
| 3045 | { "cookie", "val1", |
| 3046 | "cookie", "val2", // will get appended separated by NULL |
| 3047 | NULL |
| 3048 | }, |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3049 | }, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3050 | // This is the minimalist set of headers. |
| 3051 | { 0, |
| 3052 | { NULL }, |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3053 | }, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3054 | // Headers with a comma separated list. |
| 3055 | { 1, |
| 3056 | { "cookie", "val1,val2", |
| 3057 | NULL |
| 3058 | }, |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3059 | } |
| 3060 | }; |
| 3061 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3062 | test_cases[0].expected_headers["cookie"] = "val1"; |
| 3063 | test_cases[0].expected_headers["cookie"] += '\0'; |
| 3064 | test_cases[0].expected_headers["cookie"] += "val2"; |
| 3065 | test_cases[0].expected_headers["hello"] = "bye"; |
| 3066 | test_cases[0].expected_headers["status"] = "200"; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3067 | |
| 3068 | test_cases[1].expected_headers["hello"] = "bye"; |
| 3069 | test_cases[1].expected_headers["status"] = "200"; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3070 | |
| 3071 | test_cases[2].expected_headers["cookie"] = "val1,val2"; |
| 3072 | test_cases[2].expected_headers["hello"] = "bye"; |
| 3073 | test_cases[2].expected_headers["status"] = "200"; |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3074 | |
| 3075 | if (spdy_util_.spdy_version() < SPDY4) { |
| 3076 | // SPDY4/HTTP2 eliminates use of the :version header. |
| 3077 | test_cases[0].expected_headers["version"] = "HTTP/1.1"; |
| 3078 | test_cases[1].expected_headers["version"] = "HTTP/1.1"; |
| 3079 | test_cases[2].expected_headers["version"] = "HTTP/1.1"; |
| 3080 | } |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3081 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 3082 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3083 | scoped_ptr<SpdyFrame> req( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3084 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3085 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3086 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3087 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3088 | spdy_util_.ConstructSpdyGetSynReply(test_cases[i].extra_headers, |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 3089 | test_cases[i].num_headers, |
| 3090 | 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3091 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3092 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3093 | CreateMockRead(*resp, 1), |
| 3094 | CreateMockRead(*body, 2), |
| 3095 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3096 | }; |
| 3097 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3098 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 3099 | arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3100 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3101 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3102 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3103 | TransactionHelperResult out = helper.output(); |
| 3104 | |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3105 | EXPECT_EQ(OK, out.rv); |
| 3106 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 3107 | EXPECT_EQ("hello!", out.response_data); |
| 3108 | |
| 3109 | scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; |
| 3110 | EXPECT_TRUE(headers.get() != NULL); |
| 3111 | void* iter = NULL; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3112 | std::string name, value; |
| 3113 | SpdyHeaderBlock header_block; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3114 | while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3115 | if (header_block[name].empty()) { |
| 3116 | header_block[name] = value; |
| 3117 | } else { |
| 3118 | header_block[name] += '\0'; |
| 3119 | header_block[name] += value; |
| 3120 | } |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3121 | } |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3122 | EXPECT_EQ(test_cases[i].expected_headers, header_block); |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3123 | } |
| 3124 | } |
| 3125 | |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3126 | // Verify that various SynReply headers parse vary fields correctly |
| 3127 | // through the HTTP layer, and the response matches the request. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3128 | TEST_P(SpdyNetworkTransactionTest, SynReplyHeadersVary) { |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3129 | // Modify the following data to change/add test cases: |
| 3130 | struct SynReplyTests { |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3131 | bool vary_matches; |
| 3132 | int num_headers[2]; |
| 3133 | const char* extra_headers[2][16]; |
| 3134 | } test_cases[] = { |
| 3135 | // Test the case of a multi-valued cookie. When the value is delimited |
| 3136 | // with NUL characters, it needs to be unfolded into multiple headers. |
| 3137 | { |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3138 | true, |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 3139 | { 1, 4 }, |
| 3140 | { { "cookie", "val1,val2", |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3141 | NULL |
| 3142 | }, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3143 | { "vary", "cookie", |
| 3144 | spdy_util_.GetStatusKey(), "200", |
| 3145 | spdy_util_.GetPathKey(), "/index.php", |
| 3146 | spdy_util_.GetVersionKey(), "HTTP/1.1", |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3147 | NULL |
| 3148 | } |
| 3149 | } |
| 3150 | }, { // Multiple vary fields. |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3151 | true, |
| 3152 | { 2, 5 }, |
| 3153 | { { "friend", "barney", |
| 3154 | "enemy", "snaggletooth", |
| 3155 | NULL |
| 3156 | }, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3157 | { "vary", "friend", |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3158 | "vary", "enemy", |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3159 | spdy_util_.GetStatusKey(), "200", |
| 3160 | spdy_util_.GetPathKey(), "/index.php", |
| 3161 | spdy_util_.GetVersionKey(), "HTTP/1.1", |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3162 | NULL |
| 3163 | } |
| 3164 | } |
| 3165 | }, { // Test a '*' vary field. |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3166 | false, |
| 3167 | { 1, 4 }, |
| 3168 | { { "cookie", "val1,val2", |
| 3169 | NULL |
| 3170 | }, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3171 | { "vary", "*", |
| 3172 | spdy_util_.GetStatusKey(), "200", |
| 3173 | spdy_util_.GetPathKey(), "/index.php", |
| 3174 | spdy_util_.GetVersionKey(), "HTTP/1.1", |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3175 | NULL |
| 3176 | } |
| 3177 | } |
| 3178 | }, { // Multiple comma-separated vary fields. |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3179 | true, |
| 3180 | { 2, 4 }, |
| 3181 | { { "friend", "barney", |
| 3182 | "enemy", "snaggletooth", |
| 3183 | NULL |
| 3184 | }, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3185 | { "vary", "friend,enemy", |
| 3186 | spdy_util_.GetStatusKey(), "200", |
| 3187 | spdy_util_.GetPathKey(), "/index.php", |
| 3188 | spdy_util_.GetVersionKey(), "HTTP/1.1", |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3189 | NULL |
| 3190 | } |
| 3191 | } |
| 3192 | } |
| 3193 | }; |
| 3194 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 3195 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3196 | // Construct the request. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3197 | scoped_ptr<SpdyFrame> frame_req( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3198 | spdy_util_.ConstructSpdyGet(test_cases[i].extra_headers[0], |
| 3199 | test_cases[i].num_headers[0], |
| 3200 | false, 1, LOWEST, true)); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3201 | |
| 3202 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3203 | CreateMockWrite(*frame_req, 0), |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3204 | }; |
| 3205 | |
| 3206 | // Construct the reply. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3207 | SpdyHeaderBlock reply_headers; |
| 3208 | AppendToHeaderBlock(test_cases[i].extra_headers[1], |
| 3209 | test_cases[i].num_headers[1], |
| 3210 | &reply_headers); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3211 | scoped_ptr<SpdyFrame> frame_reply( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3212 | spdy_util_.ConstructSpdyReply(1, reply_headers)); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3213 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3214 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3215 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3216 | CreateMockRead(*frame_reply, 1), |
| 3217 | CreateMockRead(*body, 2), |
| 3218 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3219 | }; |
| 3220 | |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3221 | // Attach the headers to the request. |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 3222 | int header_count = test_cases[i].num_headers[0]; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3223 | |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 3224 | HttpRequestInfo request = CreateGetRequest(); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 3225 | for (int ct = 0; ct < header_count; ct++) { |
| 3226 | const char* header_key = test_cases[i].extra_headers[0][ct * 2]; |
| 3227 | const char* header_value = test_cases[i].extra_headers[0][ct * 2 + 1]; |
| 3228 | request.extra_headers.SetHeader(header_key, header_value); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3229 | } |
| 3230 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3231 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 3232 | arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3233 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3234 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3235 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3236 | TransactionHelperResult out = helper.output(); |
| 3237 | |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3238 | EXPECT_EQ(OK, out.rv) << i; |
| 3239 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line) << i; |
| 3240 | EXPECT_EQ("hello!", out.response_data) << i; |
| 3241 | |
| 3242 | // Test the response information. |
| 3243 | EXPECT_TRUE(out.response_info.response_time > |
| 3244 | out.response_info.request_time) << i; |
| 3245 | base::TimeDelta test_delay = out.response_info.response_time - |
| 3246 | out.response_info.request_time; |
| 3247 | base::TimeDelta min_expected_delay; |
| 3248 | min_expected_delay.FromMilliseconds(10); |
| 3249 | EXPECT_GT(test_delay.InMillisecondsF(), |
| 3250 | min_expected_delay.InMillisecondsF()) << i; |
| 3251 | EXPECT_EQ(out.response_info.vary_data.is_valid(), |
| 3252 | test_cases[i].vary_matches) << i; |
| 3253 | |
| 3254 | // Check the headers. |
| 3255 | scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; |
| 3256 | ASSERT_TRUE(headers.get() != NULL) << i; |
| 3257 | void* iter = NULL; |
| 3258 | std::string name, value, lines; |
| 3259 | while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
| 3260 | lines.append(name); |
| 3261 | lines.append(": "); |
| 3262 | lines.append(value); |
| 3263 | lines.append("\n"); |
| 3264 | } |
| 3265 | |
| 3266 | // Construct the expected header reply string. |
[email protected] | 9aa32319 | 2013-05-31 21:38:40 | [diff] [blame] | 3267 | std::string expected_reply = |
| 3268 | spdy_util_.ConstructSpdyReplyString(reply_headers); |
| 3269 | EXPECT_EQ(expected_reply, lines) << i; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3270 | } |
| 3271 | } |
| 3272 | |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3273 | // Verify that we don't crash on invalid SynReply responses. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3274 | TEST_P(SpdyNetworkTransactionTest, InvalidSynReply) { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3275 | struct InvalidSynReplyTests { |
| 3276 | int num_headers; |
| 3277 | const char* headers[10]; |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3278 | } test_cases[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3279 | // SYN_REPLY missing status header |
| 3280 | { 4, |
| 3281 | { "cookie", "val1", |
| 3282 | "cookie", "val2", |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3283 | spdy_util_.GetPathKey(), "/index.php", |
| 3284 | spdy_util_.GetVersionKey(), "HTTP/1.1", |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3285 | NULL |
| 3286 | }, |
| 3287 | }, |
| 3288 | // SYN_REPLY missing version header |
| 3289 | { 2, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3290 | { "status", "200", |
| 3291 | spdy_util_.GetPathKey(), "/index.php", |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3292 | NULL |
| 3293 | }, |
| 3294 | }, |
[email protected] | 0d384bb | 2010-07-14 01:51:12 | [diff] [blame] | 3295 | // SYN_REPLY with no headers |
| 3296 | { 0, { NULL }, }, |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3297 | }; |
| 3298 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 3299 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3300 | scoped_ptr<SpdyFrame> req( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3301 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 3302 | scoped_ptr<SpdyFrame> rst( |
| 3303 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3304 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3305 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 2), |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3306 | }; |
| 3307 | |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3308 | // Construct the reply. |
| 3309 | SpdyHeaderBlock reply_headers; |
| 3310 | AppendToHeaderBlock( |
| 3311 | test_cases[i].headers, test_cases[i].num_headers, &reply_headers); |
| 3312 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyReply(1, reply_headers)); |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3313 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3314 | CreateMockRead(*resp, 1), MockRead(ASYNC, 0, 3) // EOF |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3315 | }; |
| 3316 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3317 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 3318 | arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3319 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3320 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3321 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3322 | TransactionHelperResult out = helper.output(); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 3323 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3324 | } |
| 3325 | } |
| 3326 | |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3327 | // Verify that we don't crash on some corrupt frames. |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3328 | // TODO(jgraettinger): SPDY4 and up treats a header decompression failure as a |
| 3329 | // connection error. I'd like to backport this behavior to SPDY3 as well. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3330 | TEST_P(SpdyNetworkTransactionTest, CorruptFrameSessionError) { |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3331 | if (spdy_util_.spdy_version() >= SPDY4) { |
| 3332 | return; |
| 3333 | } |
[email protected] | 61c83f78 | 2011-01-27 21:00:24 | [diff] [blame] | 3334 | // This is the length field that's too short. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3335 | scoped_ptr<SpdyFrame> syn_reply_wrong_length( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3336 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3337 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 3338 | size_t right_size = |
| 3339 | (spdy_util_.spdy_version() < SPDY4) ? |
| 3340 | syn_reply_wrong_length->size() - framer.GetControlFrameHeaderSize() : |
| 3341 | syn_reply_wrong_length->size(); |
| 3342 | size_t wrong_size = right_size - 4; |
[email protected] | a4bfdf7 | 2013-02-22 04:06:16 | [diff] [blame] | 3343 | test::SetFrameLength(syn_reply_wrong_length.get(), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 3344 | wrong_size, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3345 | spdy_util_.spdy_version()); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3346 | |
| 3347 | struct SynReplyTests { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3348 | const SpdyFrame* syn_reply; |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3349 | } test_cases[] = { |
[email protected] | 61c83f78 | 2011-01-27 21:00:24 | [diff] [blame] | 3350 | { syn_reply_wrong_length.get(), }, |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3351 | }; |
| 3352 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 3353 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3354 | scoped_ptr<SpdyFrame> req( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3355 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 099bc7e | 2013-07-18 04:19:16 | [diff] [blame] | 3356 | scoped_ptr<SpdyFrame> rst( |
| 3357 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 3358 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3359 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 3), |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3360 | }; |
| 3361 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3362 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3363 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3364 | MockRead(ASYNC, test_cases[i].syn_reply->data(), wrong_size, 1), |
| 3365 | CreateMockRead(*body, 2), |
| 3366 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3367 | }; |
| 3368 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3369 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 3370 | arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3371 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3372 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3373 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3374 | TransactionHelperResult out = helper.output(); |
[email protected] | 955fc2e7 | 2010-02-08 20:37:30 | [diff] [blame] | 3375 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3376 | } |
| 3377 | } |
| 3378 | |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3379 | // SPDY4 treats a header decompression failure as a connection-level error. |
| 3380 | TEST_P(SpdyNetworkTransactionTest, CorruptFrameSessionErrorSpdy4) { |
| 3381 | if (spdy_util_.spdy_version() < SPDY4) { |
| 3382 | return; |
| 3383 | } |
| 3384 | // This is the length field that's too short. |
| 3385 | scoped_ptr<SpdyFrame> syn_reply_wrong_length( |
| 3386 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3387 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 3388 | size_t right_size = |
[email protected] | c143f274 | 2014-03-31 00:48:54 | [diff] [blame] | 3389 | syn_reply_wrong_length->size() - framer.GetControlFrameHeaderSize(); |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3390 | size_t wrong_size = right_size - 4; |
| 3391 | test::SetFrameLength(syn_reply_wrong_length.get(), |
| 3392 | wrong_size, |
| 3393 | spdy_util_.spdy_version()); |
| 3394 | |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3395 | scoped_ptr<SpdyFrame> req( |
| 3396 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3397 | scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 3398 | 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 5 (DECOMPRESS_FAILURE).")); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3399 | MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2)}; |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3400 | |
| 3401 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3402 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3403 | MockRead(ASYNC, syn_reply_wrong_length->data(), |
| 3404 | syn_reply_wrong_length->size() - 4, 1), |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3405 | }; |
| 3406 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3407 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3408 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 3409 | BoundNetLog(), GetParam(), NULL); |
| 3410 | helper.RunToCompletion(&data); |
| 3411 | TransactionHelperResult out = helper.output(); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3412 | EXPECT_EQ(ERR_SPDY_COMPRESSION_ERROR, out.rv); |
| 3413 | } |
| 3414 | |
| 3415 | TEST_P(SpdyNetworkTransactionTest, GoAwayOnDecompressionFailure) { |
bnc | 5b3dce0d | 2014-11-13 19:57:46 | [diff] [blame] | 3416 | if (GetParam().protocol < kProtoSPDY4MinimumVersion) { |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3417 | // Decompression failures are a stream error in SPDY3 and above. |
| 3418 | return; |
| 3419 | } |
| 3420 | scoped_ptr<SpdyFrame> req( |
| 3421 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3422 | scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 3423 | 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 5 (DECOMPRESS_FAILURE).")); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3424 | MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3425 | |
| 3426 | // Read HEADERS with corrupted payload. |
| 3427 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3428 | memset(resp->data() + 12, 0xff, resp->size() - 12); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3429 | MockRead reads[] = {CreateMockRead(*resp, 1)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3430 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3431 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3432 | NormalSpdyTransactionHelper helper( |
| 3433 | CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3434 | helper.RunToCompletion(&data); |
| 3435 | TransactionHelperResult out = helper.output(); |
| 3436 | EXPECT_EQ(ERR_SPDY_COMPRESSION_ERROR, out.rv); |
| 3437 | } |
| 3438 | |
| 3439 | TEST_P(SpdyNetworkTransactionTest, GoAwayOnFrameSizeError) { |
| 3440 | scoped_ptr<SpdyFrame> req( |
| 3441 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3442 | scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 3443 | 0, GOAWAY_PROTOCOL_ERROR, "Framer error: 1 (INVALID_CONTROL_FRAME).")); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3444 | MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3445 | |
| 3446 | // Read WINDOW_UPDATE with incorrectly-sized payload. |
| 3447 | // TODO(jgraettinger): SpdyFramer signals this as an INVALID_CONTROL_FRAME, |
| 3448 | // which is mapped to a protocol error, and not a frame size error. |
| 3449 | scoped_ptr<SpdyFrame> bad_window_update( |
| 3450 | spdy_util_.ConstructSpdyWindowUpdate(1, 1)); |
| 3451 | test::SetFrameLength(bad_window_update.get(), |
| 3452 | bad_window_update->size() - 1, |
| 3453 | spdy_util_.spdy_version()); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3454 | MockRead reads[] = {CreateMockRead(*bad_window_update, 1)}; |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3455 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3456 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3457 | NormalSpdyTransactionHelper helper( |
| 3458 | CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3459 | helper.RunToCompletion(&data); |
| 3460 | TransactionHelperResult out = helper.output(); |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3461 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 3462 | } |
| 3463 | |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3464 | // Test that we shutdown correctly on write errors. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3465 | TEST_P(SpdyNetworkTransactionTest, WriteError) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3466 | scoped_ptr<SpdyFrame> req( |
| 3467 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3468 | MockWrite writes[] = { |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3469 | // We'll write 10 bytes successfully |
| 3470 | MockWrite(ASYNC, req->data(), 10, 0), |
| 3471 | // Followed by ERROR! |
| 3472 | MockWrite(ASYNC, ERR_FAILED, 1), |
| 3473 | // Session drains and attempts to write a GOAWAY: Another ERROR! |
| 3474 | MockWrite(ASYNC, ERR_FAILED, 2), |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3475 | }; |
| 3476 | |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3477 | MockRead reads[] = { |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3478 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3479 | }; |
| 3480 | |
| 3481 | DeterministicSocketData data(reads, arraysize(reads), |
| 3482 | writes, arraysize(writes)); |
| 3483 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3484 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3485 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3486 | helper.SetDeterministic(); |
| 3487 | helper.RunPreTestSetup(); |
| 3488 | helper.AddDeterministicData(&data); |
| 3489 | EXPECT_TRUE(helper.StartDefaultTest()); |
| 3490 | data.RunFor(2); |
| 3491 | helper.FinishDefaultTest(); |
rch | bce10d97 | 2015-05-04 18:21:19 | [diff] [blame] | 3492 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
| 3493 | EXPECT_TRUE(!data.AllReadDataConsumed()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3494 | TransactionHelperResult out = helper.output(); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3495 | EXPECT_EQ(ERR_FAILED, out.rv); |
| 3496 | } |
| 3497 | |
| 3498 | // Test that partial writes work. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3499 | TEST_P(SpdyNetworkTransactionTest, PartialWrite) { |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3500 | // Chop the SYN_STREAM frame into 5 chunks. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3501 | scoped_ptr<SpdyFrame> req( |
| 3502 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3503 | const int kChunks = 5; |
[email protected] | 4356f0f | 2013-04-07 00:58:17 | [diff] [blame] | 3504 | scoped_ptr<MockWrite[]> writes(ChopWriteFrame(*req.get(), kChunks)); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3505 | for (int i = 0; i < kChunks; ++i) { |
| 3506 | writes[i].sequence_number = i; |
| 3507 | } |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3508 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3509 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3510 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3511 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3512 | CreateMockRead(*resp, kChunks), |
| 3513 | CreateMockRead(*body, kChunks + 1), |
| 3514 | MockRead(ASYNC, 0, kChunks + 2) // EOF |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3515 | }; |
| 3516 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3517 | SequencedSocketData data(reads, arraysize(reads), writes.get(), kChunks); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3518 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3519 | BoundNetLog(), 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] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3522 | EXPECT_EQ(OK, out.rv); |
| 3523 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 3524 | EXPECT_EQ("hello!", out.response_data); |
| 3525 | } |
| 3526 | |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3527 | // In this test, we enable compression, but get a uncompressed SynReply from |
| 3528 | // the server. Verify that teardown is all clean. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3529 | TEST_P(SpdyNetworkTransactionTest, DecompressFailureOnSynReply) { |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3530 | if (spdy_util_.spdy_version() >= SPDY4) { |
| 3531 | // HPACK doesn't use deflate compression. |
| 3532 | return; |
| 3533 | } |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3534 | scoped_ptr<SpdyFrame> compressed( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3535 | spdy_util_.ConstructSpdyGet(NULL, 0, true, 1, LOWEST, true)); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3536 | scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 3537 | 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 5 (DECOMPRESS_FAILURE).")); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3538 | MockWrite writes[] = {CreateMockWrite(*compressed, 0), |
| 3539 | CreateMockWrite(*goaway, 2)}; |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3540 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3541 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3542 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3543 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3544 | CreateMockRead(*resp, 1), |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3545 | }; |
| 3546 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3547 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3548 | SpdySessionDependencies* session_deps = |
| 3549 | CreateSpdySessionDependencies(GetParam()); |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 3550 | session_deps->enable_compression = true; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3551 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 3552 | BoundNetLog(), GetParam(), session_deps); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3553 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3554 | TransactionHelperResult out = helper.output(); |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 3555 | EXPECT_EQ(ERR_SPDY_COMPRESSION_ERROR, out.rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3556 | data.Reset(); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3557 | } |
| 3558 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 3559 | // Test that the NetLog contains good data for a simple GET request. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3560 | TEST_P(SpdyNetworkTransactionTest, NetLog) { |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3561 | static const char* const kExtraHeaders[] = { |
| 3562 | "user-agent", "Chrome", |
| 3563 | }; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3564 | scoped_ptr<SpdyFrame> req( |
| 3565 | spdy_util_.ConstructSpdyGet(kExtraHeaders, 1, false, 1, LOWEST, true)); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3566 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3567 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3568 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3569 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3570 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3571 | CreateMockRead(*resp, 1), |
| 3572 | CreateMockRead(*body, 2), |
| 3573 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3574 | }; |
| 3575 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3576 | BoundTestNetLog log; |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3577 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3578 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3579 | NormalSpdyTransactionHelper helper(CreateGetRequestWithUserAgent(), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3580 | DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3581 | log.bound(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3582 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3583 | TransactionHelperResult out = helper.output(); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3584 | EXPECT_EQ(OK, out.rv); |
| 3585 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 3586 | EXPECT_EQ("hello!", out.response_data); |
| 3587 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 3588 | // Check that the NetLog was filled reasonably. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3589 | // This test is intentionally non-specific about the exact ordering of the |
| 3590 | // log; instead we just check to make sure that certain events exist, and that |
| 3591 | // they are in the right order. |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame^] | 3592 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3593 | log.GetEntries(&entries); |
| 3594 | |
| 3595 | EXPECT_LT(0u, entries.size()); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3596 | int pos = 0; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3597 | pos = ExpectLogContainsSomewhere(entries, 0, |
| 3598 | NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, |
| 3599 | NetLog::PHASE_BEGIN); |
| 3600 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3601 | NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, |
| 3602 | NetLog::PHASE_END); |
| 3603 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3604 | NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, |
| 3605 | NetLog::PHASE_BEGIN); |
| 3606 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3607 | NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, |
| 3608 | NetLog::PHASE_END); |
| 3609 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3610 | NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, |
| 3611 | NetLog::PHASE_BEGIN); |
| 3612 | pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3613 | NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, |
| 3614 | NetLog::PHASE_END); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3615 | |
| 3616 | // Check that we logged all the headers correctly |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3617 | const NetLog::EventType type = (GetParam().protocol <= kProtoSPDY31) |
| 3618 | ? NetLog::TYPE_HTTP2_SESSION_SYN_STREAM |
| 3619 | : NetLog::TYPE_HTTP2_SESSION_SEND_HEADERS; |
| 3620 | pos = ExpectLogContainsSomewhere(entries, 0, type, NetLog::PHASE_NONE); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3621 | |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 3622 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3623 | ASSERT_TRUE(entries[pos].params.get()); |
| 3624 | ASSERT_TRUE(entries[pos].params->GetList("headers", &header_list)); |
| 3625 | |
| 3626 | std::vector<std::string> expected; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3627 | expected.push_back(std::string(spdy_util_.GetHostKey()) + |
| 3628 | ": www.example.org"); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3629 | expected.push_back(std::string(spdy_util_.GetPathKey()) + ": /"); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 3630 | expected.push_back(std::string(spdy_util_.GetSchemeKey()) + ": " + |
| 3631 | spdy_util_.default_url().scheme()); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3632 | expected.push_back(std::string(spdy_util_.GetMethodKey()) + ": GET"); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3633 | expected.push_back("user-agent: Chrome"); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3634 | if (spdy_util_.spdy_version() < SPDY4) { |
| 3635 | // SPDY4/HTTP2 eliminates use of the :version header. |
| 3636 | expected.push_back(std::string(spdy_util_.GetVersionKey()) + ": HTTP/1.1"); |
| 3637 | } |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3638 | EXPECT_EQ(expected.size(), header_list->GetSize()); |
| 3639 | for (std::vector<std::string>::const_iterator it = expected.begin(); |
| 3640 | it != expected.end(); |
| 3641 | ++it) { |
| 3642 | base::StringValue header(*it); |
| 3643 | EXPECT_NE(header_list->end(), header_list->Find(header)) << |
| 3644 | "Header not found: " << *it; |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3645 | } |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3646 | } |
| 3647 | |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3648 | // Since we buffer the IO from the stream to the renderer, this test verifies |
| 3649 | // that when we read out the maximum amount of data (e.g. we received 50 bytes |
| 3650 | // on the network, but issued a Read for only 5 of those bytes) that the data |
| 3651 | // flow still works correctly. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3652 | TEST_P(SpdyNetworkTransactionTest, BufferFull) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3653 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3654 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3655 | scoped_ptr<SpdyFrame> req( |
| 3656 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3657 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3658 | |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3659 | // 2 data frames in a single read. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3660 | scoped_ptr<SpdyFrame> data_frame_1( |
| 3661 | framer.CreateDataFrame(1, "goodby", 6, DATA_FLAG_NONE)); |
| 3662 | scoped_ptr<SpdyFrame> data_frame_2( |
| 3663 | framer.CreateDataFrame(1, "e worl", 6, DATA_FLAG_NONE)); |
| 3664 | const SpdyFrame* data_frames[2] = { |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3665 | data_frame_1.get(), |
| 3666 | data_frame_2.get(), |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3667 | }; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3668 | char combined_data_frames[100]; |
| 3669 | int combined_data_frames_len = |
| 3670 | CombineFrames(data_frames, arraysize(data_frames), |
| 3671 | combined_data_frames, arraysize(combined_data_frames)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3672 | scoped_ptr<SpdyFrame> last_frame( |
| 3673 | framer.CreateDataFrame(1, "d", 1, DATA_FLAG_FIN)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3674 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3675 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3676 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3677 | CreateMockRead(*resp), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3678 | MockRead(ASYNC, ERR_IO_PENDING), // Force a pause |
| 3679 | MockRead(ASYNC, combined_data_frames, combined_data_frames_len), |
| 3680 | MockRead(ASYNC, ERR_IO_PENDING), // Force a pause |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3681 | CreateMockRead(*last_frame), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3682 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3683 | }; |
| 3684 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3685 | DelayedSocketData data(1, reads, arraysize(reads), |
| 3686 | writes, arraysize(writes)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3687 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3688 | TestCompletionCallback callback; |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3689 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3690 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3691 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3692 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3693 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3694 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3695 | int rv = trans->Start( |
| 3696 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3697 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3698 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3699 | TransactionHelperResult out = helper.output(); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3700 | out.rv = callback.WaitForResult(); |
| 3701 | EXPECT_EQ(out.rv, OK); |
| 3702 | |
| 3703 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3704 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3705 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3706 | out.status_line = response->headers->GetStatusLine(); |
| 3707 | out.response_info = *response; // Make a copy so we can verify. |
| 3708 | |
| 3709 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3710 | TestCompletionCallback read_callback; |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3711 | |
| 3712 | std::string content; |
| 3713 | do { |
| 3714 | // Read small chunks at a time. |
| 3715 | const int kSmallReadSize = 3; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3716 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3717 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3718 | if (rv == ERR_IO_PENDING) { |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3719 | data.CompleteRead(); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3720 | rv = read_callback.WaitForResult(); |
| 3721 | } |
| 3722 | if (rv > 0) { |
| 3723 | content.append(buf->data(), rv); |
| 3724 | } else if (rv < 0) { |
| 3725 | NOTREACHED(); |
| 3726 | } |
| 3727 | } while (rv > 0); |
| 3728 | |
| 3729 | out.response_data.swap(content); |
| 3730 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3731 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3732 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3733 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3734 | |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3735 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3736 | helper.VerifyDataConsumed(); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3737 | |
| 3738 | EXPECT_EQ(OK, out.rv); |
| 3739 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 3740 | EXPECT_EQ("goodbye world", out.response_data); |
| 3741 | } |
| 3742 | |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3743 | // Verify that basic buffering works; when multiple data frames arrive |
| 3744 | // at the same time, ensure that we don't notify a read completion for |
| 3745 | // each data frame individually. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3746 | TEST_P(SpdyNetworkTransactionTest, Buffering) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3747 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3748 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3749 | scoped_ptr<SpdyFrame> req( |
| 3750 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3751 | MockWrite writes[] = { CreateMockWrite(*req) }; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3752 | |
| 3753 | // 4 data frames in a single read. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3754 | scoped_ptr<SpdyFrame> data_frame( |
| 3755 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 3756 | scoped_ptr<SpdyFrame> data_frame_fin( |
| 3757 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN)); |
| 3758 | const SpdyFrame* data_frames[4] = { |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3759 | data_frame.get(), |
| 3760 | data_frame.get(), |
| 3761 | data_frame.get(), |
| 3762 | data_frame_fin.get() |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3763 | }; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3764 | char combined_data_frames[100]; |
| 3765 | int combined_data_frames_len = |
| 3766 | CombineFrames(data_frames, arraysize(data_frames), |
| 3767 | combined_data_frames, arraysize(combined_data_frames)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3768 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3769 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3770 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3771 | CreateMockRead(*resp), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3772 | MockRead(ASYNC, ERR_IO_PENDING), // Force a pause |
| 3773 | MockRead(ASYNC, combined_data_frames, combined_data_frames_len), |
| 3774 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3775 | }; |
| 3776 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3777 | DelayedSocketData data(1, reads, arraysize(reads), |
| 3778 | writes, arraysize(writes)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3779 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3780 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3781 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3782 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3783 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3784 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3785 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3786 | TestCompletionCallback callback; |
| 3787 | int rv = trans->Start( |
| 3788 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3789 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3790 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3791 | TransactionHelperResult out = helper.output(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3792 | out.rv = callback.WaitForResult(); |
| 3793 | EXPECT_EQ(out.rv, OK); |
| 3794 | |
| 3795 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3796 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3797 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3798 | out.status_line = response->headers->GetStatusLine(); |
| 3799 | out.response_info = *response; // Make a copy so we can verify. |
| 3800 | |
| 3801 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3802 | TestCompletionCallback read_callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3803 | |
| 3804 | std::string content; |
| 3805 | int reads_completed = 0; |
| 3806 | do { |
| 3807 | // Read small chunks at a time. |
| 3808 | const int kSmallReadSize = 14; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3809 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3810 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3811 | if (rv == ERR_IO_PENDING) { |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3812 | data.CompleteRead(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3813 | rv = read_callback.WaitForResult(); |
| 3814 | } |
| 3815 | if (rv > 0) { |
| 3816 | EXPECT_EQ(kSmallReadSize, rv); |
| 3817 | content.append(buf->data(), rv); |
| 3818 | } else if (rv < 0) { |
| 3819 | FAIL() << "Unexpected read error: " << rv; |
| 3820 | } |
| 3821 | reads_completed++; |
| 3822 | } while (rv > 0); |
| 3823 | |
| 3824 | EXPECT_EQ(3, reads_completed); // Reads are: 14 bytes, 14 bytes, 0 bytes. |
| 3825 | |
| 3826 | out.response_data.swap(content); |
| 3827 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3828 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3829 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3830 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3831 | |
| 3832 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3833 | helper.VerifyDataConsumed(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3834 | |
| 3835 | EXPECT_EQ(OK, out.rv); |
| 3836 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 3837 | EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 3838 | } |
| 3839 | |
| 3840 | // 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] | 3841 | TEST_P(SpdyNetworkTransactionTest, BufferedAll) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3842 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3843 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3844 | scoped_ptr<SpdyFrame> req( |
| 3845 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3846 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3847 | |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3848 | // 5 data frames in a single read. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3849 | scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3850 | scoped_ptr<SpdyFrame> data_frame( |
| 3851 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 3852 | scoped_ptr<SpdyFrame> data_frame_fin( |
| 3853 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN)); |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 3854 | const SpdyFrame* frames[5] = {reply.get(), data_frame.get(), data_frame.get(), |
| 3855 | data_frame.get(), data_frame_fin.get()}; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3856 | char combined_frames[200]; |
| 3857 | int combined_frames_len = |
| 3858 | CombineFrames(frames, arraysize(frames), |
| 3859 | combined_frames, arraysize(combined_frames)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3860 | |
| 3861 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3862 | MockRead(ASYNC, combined_frames, combined_frames_len, 1), |
| 3863 | MockRead(ASYNC, 0, 2) // EOF |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3864 | }; |
| 3865 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 3866 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3867 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3868 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3869 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3870 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3871 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3872 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3873 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3874 | TestCompletionCallback callback; |
| 3875 | int rv = trans->Start( |
| 3876 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3877 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3878 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3879 | TransactionHelperResult out = helper.output(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3880 | out.rv = callback.WaitForResult(); |
| 3881 | EXPECT_EQ(out.rv, OK); |
| 3882 | |
| 3883 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3884 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3885 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3886 | out.status_line = response->headers->GetStatusLine(); |
| 3887 | out.response_info = *response; // Make a copy so we can verify. |
| 3888 | |
| 3889 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3890 | TestCompletionCallback read_callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3891 | |
| 3892 | std::string content; |
| 3893 | int reads_completed = 0; |
| 3894 | do { |
| 3895 | // Read small chunks at a time. |
| 3896 | const int kSmallReadSize = 14; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3897 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3898 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3899 | if (rv > 0) { |
| 3900 | EXPECT_EQ(kSmallReadSize, rv); |
| 3901 | content.append(buf->data(), rv); |
| 3902 | } else if (rv < 0) { |
| 3903 | FAIL() << "Unexpected read error: " << rv; |
| 3904 | } |
| 3905 | reads_completed++; |
| 3906 | } while (rv > 0); |
| 3907 | |
| 3908 | EXPECT_EQ(3, reads_completed); |
| 3909 | |
| 3910 | out.response_data.swap(content); |
| 3911 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3912 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3913 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3914 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3915 | |
| 3916 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3917 | helper.VerifyDataConsumed(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3918 | |
| 3919 | EXPECT_EQ(OK, out.rv); |
| 3920 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 3921 | EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 3922 | } |
| 3923 | |
| 3924 | // Verify the case where we buffer data and close the connection. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3925 | TEST_P(SpdyNetworkTransactionTest, BufferedClosed) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3926 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3927 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3928 | scoped_ptr<SpdyFrame> req( |
| 3929 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3930 | MockWrite writes[] = { CreateMockWrite(*req) }; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3931 | |
| 3932 | // All data frames in a single read. |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3933 | // NOTE: We don't FIN the stream. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3934 | scoped_ptr<SpdyFrame> data_frame( |
| 3935 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 3936 | const SpdyFrame* data_frames[4] = { |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3937 | data_frame.get(), |
| 3938 | data_frame.get(), |
| 3939 | data_frame.get(), |
| 3940 | data_frame.get() |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3941 | }; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3942 | char combined_data_frames[100]; |
| 3943 | int combined_data_frames_len = |
| 3944 | CombineFrames(data_frames, arraysize(data_frames), |
| 3945 | combined_data_frames, arraysize(combined_data_frames)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3946 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3947 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3948 | CreateMockRead(*resp), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3949 | MockRead(ASYNC, ERR_IO_PENDING), // Force a wait |
| 3950 | MockRead(ASYNC, combined_data_frames, combined_data_frames_len), |
| 3951 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3952 | }; |
| 3953 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3954 | DelayedSocketData data(1, reads, arraysize(reads), |
| 3955 | writes, arraysize(writes)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3956 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3957 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3958 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3959 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3960 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3961 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3962 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3963 | TestCompletionCallback callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3964 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3965 | int rv = trans->Start( |
| 3966 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3967 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3968 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3969 | TransactionHelperResult out = helper.output(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3970 | out.rv = callback.WaitForResult(); |
| 3971 | EXPECT_EQ(out.rv, OK); |
| 3972 | |
| 3973 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3974 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3975 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3976 | out.status_line = response->headers->GetStatusLine(); |
| 3977 | out.response_info = *response; // Make a copy so we can verify. |
| 3978 | |
| 3979 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3980 | TestCompletionCallback read_callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3981 | |
| 3982 | std::string content; |
| 3983 | int reads_completed = 0; |
| 3984 | do { |
| 3985 | // Read small chunks at a time. |
| 3986 | const int kSmallReadSize = 14; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3987 | scoped_refptr<IOBuffer> buf(new IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3988 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 3989 | if (rv == ERR_IO_PENDING) { |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3990 | data.CompleteRead(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3991 | rv = read_callback.WaitForResult(); |
| 3992 | } |
| 3993 | if (rv > 0) { |
| 3994 | content.append(buf->data(), rv); |
| 3995 | } else if (rv < 0) { |
| 3996 | // This test intentionally closes the connection, and will get an error. |
| 3997 | EXPECT_EQ(ERR_CONNECTION_CLOSED, rv); |
| 3998 | break; |
| 3999 | } |
| 4000 | reads_completed++; |
| 4001 | } while (rv > 0); |
| 4002 | |
| 4003 | EXPECT_EQ(0, reads_completed); |
| 4004 | |
| 4005 | out.response_data.swap(content); |
| 4006 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 4007 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4008 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4009 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4010 | |
| 4011 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4012 | helper.VerifyDataConsumed(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4013 | } |
| 4014 | |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4015 | // Verify the case where we buffer data and cancel the transaction. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4016 | TEST_P(SpdyNetworkTransactionTest, BufferedCancelled) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4017 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 4018 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4019 | scoped_ptr<SpdyFrame> req( |
| 4020 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 975da41a | 2014-06-05 03:36:24 | [diff] [blame] | 4021 | scoped_ptr<SpdyFrame> rst( |
| 4022 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
| 4023 | MockWrite writes[] = {CreateMockWrite(*req), CreateMockWrite(*rst)}; |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4024 | |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 4025 | // NOTE: We don't FIN the stream. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4026 | scoped_ptr<SpdyFrame> data_frame( |
| 4027 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4028 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4029 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4030 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 4031 | CreateMockRead(*resp), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4032 | MockRead(ASYNC, ERR_IO_PENDING), // Force a wait |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 4033 | CreateMockRead(*data_frame), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4034 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4035 | }; |
| 4036 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4037 | DelayedSocketData data(1, reads, arraysize(reads), |
| 4038 | writes, arraysize(writes)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4039 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4040 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4041 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4042 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4043 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4044 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4045 | TestCompletionCallback callback; |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4046 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4047 | int rv = trans->Start( |
| 4048 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4049 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4050 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4051 | TransactionHelperResult out = helper.output(); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4052 | out.rv = callback.WaitForResult(); |
| 4053 | EXPECT_EQ(out.rv, OK); |
| 4054 | |
| 4055 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4056 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4057 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4058 | out.status_line = response->headers->GetStatusLine(); |
| 4059 | out.response_info = *response; // Make a copy so we can verify. |
| 4060 | |
| 4061 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4062 | TestCompletionCallback read_callback; |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4063 | |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 4064 | const int kReadSize = 256; |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4065 | scoped_refptr<IOBuffer> buf(new IOBuffer(kReadSize)); |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 4066 | rv = trans->Read(buf.get(), kReadSize, read_callback.callback()); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4067 | ASSERT_EQ(ERR_IO_PENDING, rv) << "Unexpected read: " << rv; |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 4068 | |
| 4069 | // Complete the read now, which causes buffering to start. |
| 4070 | data.CompleteRead(); |
| 4071 | // Destroy the transaction, causing the stream to get cancelled |
| 4072 | // and orphaning the buffered IO task. |
| 4073 | helper.ResetTrans(); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4074 | |
| 4075 | // Flush the MessageLoop; this will cause the buffered IO task |
| 4076 | // to run for the final time. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4077 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4078 | |
| 4079 | // Verify that we consumed all test data. |
| 4080 | helper.VerifyDataConsumed(); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4081 | } |
| 4082 | |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4083 | // Test that if the server requests persistence of settings, that we save |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4084 | // the settings in the HttpServerProperties. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4085 | TEST_P(SpdyNetworkTransactionTest, SettingsSaved) { |
[email protected] | 8a7bc7a | 2014-02-28 21:25:22 | [diff] [blame] | 4086 | if (spdy_util_.spdy_version() >= SPDY4) { |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4087 | // SPDY4 doesn't support settings persistence. |
[email protected] | 8a7bc7a | 2014-02-28 21:25:22 | [diff] [blame] | 4088 | return; |
| 4089 | } |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4090 | static const SpdyHeaderInfo kSynReplyInfo = { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4091 | SYN_REPLY, // Syn Reply |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4092 | 1, // Stream ID |
| 4093 | 0, // Associated Stream ID |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4094 | ConvertRequestPriorityToSpdyPriority( |
| 4095 | LOWEST, spdy_util_.spdy_version()), |
| 4096 | kSpdyCredentialSlotUnused, |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4097 | CONTROL_FLAG_NONE, // Control Flags |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4098 | false, // Compressed |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 4099 | RST_STREAM_INVALID, // Status |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4100 | NULL, // Data |
| 4101 | 0, // Data Length |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4102 | DATA_FLAG_NONE // Data Flags |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4103 | }; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4104 | |
[email protected] | c016882 | 2011-12-10 01:24:27 | [diff] [blame] | 4105 | BoundNetLog net_log; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4106 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 4107 | net_log, GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 4108 | helper.RunPreTestSetup(); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4109 | |
| 4110 | // Verify that no settings exist initially. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4111 | HostPortPair host_port_pair("www.example.org", helper.port()); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 4112 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4113 | EXPECT_TRUE(spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4114 | host_port_pair).empty()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4115 | |
| 4116 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4117 | scoped_ptr<SpdyFrame> req( |
| 4118 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4119 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4120 | |
| 4121 | // Construct the reply. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4122 | scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); |
| 4123 | (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 4124 | (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4125 | scoped_ptr<SpdyFrame> reply( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4126 | spdy_util_.ConstructSpdyFrame(kSynReplyInfo, reply_headers.Pass())); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4127 | |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4128 | const SpdySettingsIds kSampleId1 = SETTINGS_UPLOAD_BANDWIDTH; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4129 | unsigned int kSampleValue1 = 0x0a0a0a0a; |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4130 | const SpdySettingsIds kSampleId2 = SETTINGS_DOWNLOAD_BANDWIDTH; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4131 | unsigned int kSampleValue2 = 0x0b0b0b0b; |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4132 | const SpdySettingsIds kSampleId3 = SETTINGS_ROUND_TRIP_TIME; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4133 | unsigned int kSampleValue3 = 0x0c0c0c0c; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4134 | scoped_ptr<SpdyFrame> settings_frame; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4135 | { |
| 4136 | // Construct the SETTINGS frame. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4137 | SettingsMap settings; |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4138 | // First add a persisted setting. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4139 | settings[kSampleId1] = |
| 4140 | SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue1); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4141 | // Next add a non-persisted setting. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4142 | settings[kSampleId2] = |
| 4143 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kSampleValue2); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4144 | // Next add another persisted setting. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4145 | settings[kSampleId3] = |
| 4146 | SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue3); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4147 | settings_frame.reset(spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4148 | } |
| 4149 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4150 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4151 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4152 | CreateMockRead(*reply, 1), |
| 4153 | CreateMockRead(*body, 2), |
| 4154 | CreateMockRead(*settings_frame, 3), |
| 4155 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4156 | }; |
| 4157 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4158 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4159 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 4160 | helper.RunDefaultTest(); |
| 4161 | helper.VerifyDataConsumed(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4162 | TransactionHelperResult out = helper.output(); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4163 | EXPECT_EQ(OK, out.rv); |
| 4164 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4165 | EXPECT_EQ("hello!", out.response_data); |
| 4166 | |
| 4167 | { |
| 4168 | // Verify we had two persisted settings. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4169 | const SettingsMap& settings_map = |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4170 | spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4171 | host_port_pair); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4172 | ASSERT_EQ(2u, settings_map.size()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4173 | |
| 4174 | // Verify the first persisted setting. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4175 | SettingsMap::const_iterator it1 = settings_map.find(kSampleId1); |
| 4176 | EXPECT_TRUE(it1 != settings_map.end()); |
| 4177 | SettingsFlagsAndValue flags_and_value1 = it1->second; |
| 4178 | EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1.first); |
| 4179 | EXPECT_EQ(kSampleValue1, flags_and_value1.second); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4180 | |
| 4181 | // Verify the second persisted setting. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4182 | SettingsMap::const_iterator it3 = settings_map.find(kSampleId3); |
| 4183 | EXPECT_TRUE(it3 != settings_map.end()); |
| 4184 | SettingsFlagsAndValue flags_and_value3 = it3->second; |
| 4185 | EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value3.first); |
| 4186 | EXPECT_EQ(kSampleValue3, flags_and_value3.second); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4187 | } |
| 4188 | } |
| 4189 | |
| 4190 | // Test that when there are settings saved that they are sent back to the |
| 4191 | // server upon session establishment. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4192 | TEST_P(SpdyNetworkTransactionTest, SettingsPlayback) { |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 4193 | if (spdy_util_.spdy_version() >= SPDY4) { |
| 4194 | // SPDY4 doesn't support settings persistence. |
| 4195 | return; |
| 4196 | } |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4197 | static const SpdyHeaderInfo kSynReplyInfo = { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4198 | SYN_REPLY, // Syn Reply |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4199 | 1, // Stream ID |
| 4200 | 0, // Associated Stream ID |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4201 | ConvertRequestPriorityToSpdyPriority( |
| 4202 | LOWEST, spdy_util_.spdy_version()), |
| 4203 | kSpdyCredentialSlotUnused, |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4204 | CONTROL_FLAG_NONE, // Control Flags |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4205 | false, // Compressed |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 4206 | RST_STREAM_INVALID, // Status |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4207 | NULL, // Data |
| 4208 | 0, // Data Length |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4209 | DATA_FLAG_NONE // Data Flags |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4210 | }; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4211 | |
[email protected] | c016882 | 2011-12-10 01:24:27 | [diff] [blame] | 4212 | BoundNetLog net_log; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4213 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 4214 | net_log, GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 4215 | helper.RunPreTestSetup(); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4216 | |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4217 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
| 4218 | |
| 4219 | SpdySessionPoolPeer pool_peer(spdy_session_pool); |
| 4220 | pool_peer.SetEnableSendingInitialData(true); |
| 4221 | |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4222 | // Verify that no settings exist initially. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4223 | HostPortPair host_port_pair("www.example.org", helper.port()); |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4224 | EXPECT_TRUE(spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4225 | host_port_pair).empty()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4226 | |
[email protected] | c143f274 | 2014-03-31 00:48:54 | [diff] [blame] | 4227 | const SpdySettingsIds kSampleId1 = SETTINGS_MAX_CONCURRENT_STREAMS; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4228 | unsigned int kSampleValue1 = 0x0a0a0a0a; |
[email protected] | c143f274 | 2014-03-31 00:48:54 | [diff] [blame] | 4229 | const SpdySettingsIds kSampleId2 = SETTINGS_INITIAL_WINDOW_SIZE; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4230 | unsigned int kSampleValue2 = 0x0c0c0c0c; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4231 | |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4232 | // First add a persisted setting. |
| 4233 | spdy_session_pool->http_server_properties()->SetSpdySetting( |
| 4234 | host_port_pair, |
| 4235 | kSampleId1, |
| 4236 | SETTINGS_FLAG_PLEASE_PERSIST, |
| 4237 | kSampleValue1); |
| 4238 | |
| 4239 | // Next add another persisted setting. |
| 4240 | spdy_session_pool->http_server_properties()->SetSpdySetting( |
| 4241 | host_port_pair, |
| 4242 | kSampleId2, |
| 4243 | SETTINGS_FLAG_PLEASE_PERSIST, |
| 4244 | kSampleValue2); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4245 | |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4246 | EXPECT_EQ(2u, spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4247 | host_port_pair).size()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4248 | |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4249 | // Construct the initial SETTINGS frame. |
| 4250 | SettingsMap initial_settings; |
| 4251 | initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 4252 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); |
| 4253 | scoped_ptr<SpdyFrame> initial_settings_frame( |
| 4254 | spdy_util_.ConstructSpdySettings(initial_settings)); |
| 4255 | |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4256 | // Construct the persisted SETTINGS frame. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4257 | const SettingsMap& settings = |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4258 | spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4259 | host_port_pair); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4260 | scoped_ptr<SpdyFrame> settings_frame( |
| 4261 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4262 | |
| 4263 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4264 | scoped_ptr<SpdyFrame> req( |
| 4265 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4266 | |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4267 | std::vector<MockWrite> writes; |
bnc | 5b3dce0d | 2014-11-13 19:57:46 | [diff] [blame] | 4268 | if ((GetParam().protocol >= kProtoSPDY4MinimumVersion) && |
| 4269 | (GetParam().protocol <= kProtoSPDY4MaximumVersion)) { |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4270 | writes.push_back( |
| 4271 | MockWrite(ASYNC, |
| 4272 | kHttp2ConnectionHeaderPrefix, |
| 4273 | kHttp2ConnectionHeaderPrefixSize)); |
| 4274 | } |
| 4275 | writes.push_back(CreateMockWrite(*initial_settings_frame)); |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4276 | writes.push_back(CreateMockWrite(*settings_frame)); |
| 4277 | writes.push_back(CreateMockWrite(*req)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4278 | |
| 4279 | // Construct the reply. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4280 | scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); |
| 4281 | (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 4282 | (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4283 | scoped_ptr<SpdyFrame> reply( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4284 | spdy_util_.ConstructSpdyFrame(kSynReplyInfo, reply_headers.Pass())); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4285 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4286 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4287 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 4288 | CreateMockRead(*reply), |
| 4289 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4290 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4291 | }; |
| 4292 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4293 | DelayedSocketData data(2, reads, arraysize(reads), |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4294 | vector_as_array(&writes), writes.size()); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4295 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 4296 | helper.RunDefaultTest(); |
| 4297 | helper.VerifyDataConsumed(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4298 | TransactionHelperResult out = helper.output(); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4299 | EXPECT_EQ(OK, out.rv); |
| 4300 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4301 | EXPECT_EQ("hello!", out.response_data); |
| 4302 | |
| 4303 | { |
| 4304 | // Verify we had two persisted settings. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4305 | const SettingsMap& settings_map = |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4306 | spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4307 | host_port_pair); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4308 | ASSERT_EQ(2u, settings_map.size()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4309 | |
| 4310 | // Verify the first persisted setting. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4311 | SettingsMap::const_iterator it1 = settings_map.find(kSampleId1); |
| 4312 | EXPECT_TRUE(it1 != settings_map.end()); |
| 4313 | SettingsFlagsAndValue flags_and_value1 = it1->second; |
| 4314 | EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1.first); |
| 4315 | EXPECT_EQ(kSampleValue1, flags_and_value1.second); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4316 | |
| 4317 | // Verify the second persisted setting. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4318 | SettingsMap::const_iterator it2 = settings_map.find(kSampleId2); |
| 4319 | EXPECT_TRUE(it2 != settings_map.end()); |
| 4320 | SettingsFlagsAndValue flags_and_value2 = it2->second; |
| 4321 | EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value2.first); |
| 4322 | EXPECT_EQ(kSampleValue2, flags_and_value2.second); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4323 | } |
| 4324 | } |
| 4325 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4326 | TEST_P(SpdyNetworkTransactionTest, GoAwayWithActiveStream) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4327 | scoped_ptr<SpdyFrame> req( |
| 4328 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4329 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 69d717bd | 2010-04-21 18:43:21 | [diff] [blame] | 4330 | |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4331 | scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway()); |
[email protected] | 69d717bd | 2010-04-21 18:43:21 | [diff] [blame] | 4332 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4333 | CreateMockRead(*go_away, 1), |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4334 | }; |
| 4335 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4336 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4337 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4338 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4339 | helper.AddData(&data); |
| 4340 | helper.RunToCompletion(&data); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4341 | TransactionHelperResult out = helper.output(); |
[email protected] | c9336d2 | 2010-08-10 00:04:18 | [diff] [blame] | 4342 | EXPECT_EQ(ERR_ABORTED, out.rv); |
[email protected] | 69d717bd | 2010-04-21 18:43:21 | [diff] [blame] | 4343 | } |
| 4344 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4345 | TEST_P(SpdyNetworkTransactionTest, CloseWithActiveStream) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4346 | scoped_ptr<SpdyFrame> req( |
| 4347 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4348 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4349 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4350 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4351 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4352 | CreateMockRead(*resp, 1), MockRead(SYNCHRONOUS, 0, 2) // EOF |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4353 | }; |
| 4354 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4355 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4356 | BoundNetLog log; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4357 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4358 | log, GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4359 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4360 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4361 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4362 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4363 | TestCompletionCallback callback; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4364 | TransactionHelperResult out; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4365 | out.rv = trans->Start(&CreateGetRequest(), callback.callback(), log); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4366 | |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4367 | EXPECT_EQ(out.rv, ERR_IO_PENDING); |
| 4368 | out.rv = callback.WaitForResult(); |
| 4369 | EXPECT_EQ(out.rv, OK); |
| 4370 | |
| 4371 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4372 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4373 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4374 | out.rv = ReadTransaction(trans, &out.response_data); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4375 | EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); |
| 4376 | |
| 4377 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4378 | helper.VerifyDataConsumed(); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4379 | } |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4380 | |
bnc | a7f994a | 2015-01-20 19:39:41 | [diff] [blame] | 4381 | // HTTP_1_1_REQUIRED results in ERR_HTTP_1_1_REQUIRED. |
| 4382 | TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredError) { |
| 4383 | // HTTP_1_1_REQUIRED is only supported by SPDY4. |
| 4384 | if (spdy_util_.spdy_version() < SPDY4) |
| 4385 | return; |
| 4386 | |
| 4387 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 4388 | BoundNetLog(), GetParam(), nullptr); |
| 4389 | |
| 4390 | scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway( |
| 4391 | 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); |
| 4392 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4393 | CreateMockRead(*go_away, 0), |
bnc | a7f994a | 2015-01-20 19:39:41 | [diff] [blame] | 4394 | }; |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4395 | SequencedSocketData data(reads, arraysize(reads), nullptr, 0); |
bnc | a7f994a | 2015-01-20 19:39:41 | [diff] [blame] | 4396 | |
| 4397 | helper.RunToCompletion(&data); |
| 4398 | TransactionHelperResult out = helper.output(); |
| 4399 | EXPECT_EQ(ERR_HTTP_1_1_REQUIRED, out.rv); |
| 4400 | } |
| 4401 | |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4402 | // Retry with HTTP/1.1 when receiving HTTP_1_1_REQUIRED. Note that no actual |
| 4403 | // protocol negotiation happens, instead this test forces protocols for both |
| 4404 | // sockets. |
| 4405 | TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredRetry) { |
| 4406 | // HTTP_1_1_REQUIRED is only supported by SPDY4. |
| 4407 | if (spdy_util_.spdy_version() < SPDY4) |
| 4408 | return; |
| 4409 | // HTTP_1_1_REQUIRED implementation relies on the assumption that HTTP/2 is |
| 4410 | // only spoken over SSL. |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4411 | if (GetParam().ssl_type != HTTPS_SPDY_VIA_NPN) |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4412 | return; |
| 4413 | |
| 4414 | HttpRequestInfo request; |
| 4415 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4416 | request.url = GURL("https://www.example.org/"); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4417 | scoped_ptr<SpdySessionDependencies> session_deps( |
| 4418 | CreateSpdySessionDependencies(GetParam())); |
| 4419 | // Do not force SPDY so that second socket can negotiate HTTP/1.1. |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4420 | session_deps->next_protos = SpdyNextProtos(); |
| 4421 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 4422 | GetParam(), session_deps.release()); |
| 4423 | |
| 4424 | // First socket: HTTP/2 request rejected with HTTP_1_1_REQUIRED. |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4425 | const char* url = request.url.spec().c_str(); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4426 | scoped_ptr<SpdyHeaderBlock> headers(spdy_util_.ConstructGetHeaderBlock(url)); |
| 4427 | scoped_ptr<SpdyFrame> req( |
| 4428 | spdy_util_.ConstructSpdySyn(1, *headers, LOWEST, false, true)); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4429 | MockWrite writes0[] = {CreateMockWrite(*req, 0)}; |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4430 | scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway( |
| 4431 | 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4432 | MockRead reads0[] = {CreateMockRead(*go_away, 1)}; |
| 4433 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 4434 | arraysize(writes0)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4435 | |
| 4436 | scoped_ptr<SSLSocketDataProvider> ssl_provider0( |
| 4437 | new SSLSocketDataProvider(ASYNC, OK)); |
| 4438 | // Expect HTTP/2 protocols too in SSLConfig. |
| 4439 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4440 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY31); |
| 4441 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY4_14); |
bnc | bfa20e6 | 2015-03-09 23:29:22 | [diff] [blame] | 4442 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY4); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4443 | // Force SPDY. |
| 4444 | ssl_provider0->SetNextProto(GetParam().protocol); |
| 4445 | helper.AddDataWithSSLSocketDataProvider(&data0, ssl_provider0.Pass()); |
| 4446 | |
| 4447 | // Second socket: falling back to HTTP/1.1. |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4448 | MockWrite writes1[] = {MockWrite(ASYNC, 0, |
| 4449 | "GET / HTTP/1.1\r\n" |
| 4450 | "Host: www.example.org\r\n" |
| 4451 | "Connection: keep-alive\r\n\r\n")}; |
| 4452 | MockRead reads1[] = {MockRead(ASYNC, 1, |
| 4453 | "HTTP/1.1 200 OK\r\n" |
| 4454 | "Content-Length: 5\r\n\r\n" |
| 4455 | "hello")}; |
| 4456 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 4457 | arraysize(writes1)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4458 | |
| 4459 | scoped_ptr<SSLSocketDataProvider> ssl_provider1( |
| 4460 | new SSLSocketDataProvider(ASYNC, OK)); |
| 4461 | // Expect only HTTP/1.1 protocol in SSLConfig. |
| 4462 | ssl_provider1->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4463 | // Force HTTP/1.1. |
| 4464 | ssl_provider1->SetNextProto(kProtoHTTP11); |
| 4465 | helper.AddDataWithSSLSocketDataProvider(&data1, ssl_provider1.Pass()); |
| 4466 | |
| 4467 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 4468 | helper.session()->spdy_session_pool()->http_server_properties(); |
| 4469 | const HostPortPair host_port_pair = HostPortPair::FromURL(GURL(url)); |
| 4470 | EXPECT_FALSE(http_server_properties->RequiresHTTP11(host_port_pair)); |
| 4471 | |
| 4472 | helper.RunPreTestSetup(); |
| 4473 | helper.StartDefaultTest(); |
| 4474 | helper.FinishDefaultTestWithoutVerification(); |
| 4475 | helper.VerifyDataConsumed(); |
| 4476 | EXPECT_TRUE(http_server_properties->RequiresHTTP11(host_port_pair)); |
| 4477 | |
| 4478 | const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
| 4479 | ASSERT_TRUE(response != nullptr); |
| 4480 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 4481 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4482 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 4483 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, response->connection_info); |
| 4484 | EXPECT_TRUE(response->was_npn_negotiated); |
| 4485 | EXPECT_TRUE(request.url.SchemeIs("https")); |
| 4486 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 4487 | EXPECT_EQ(443, response->socket_address.port()); |
| 4488 | std::string response_data; |
| 4489 | ASSERT_EQ(OK, ReadTransaction(helper.trans(), &response_data)); |
| 4490 | EXPECT_EQ("hello", response_data); |
| 4491 | } |
| 4492 | |
| 4493 | // Retry with HTTP/1.1 to the proxy when receiving HTTP_1_1_REQUIRED from the |
| 4494 | // proxy. Note that no actual protocol negotiation happens, instead this test |
| 4495 | // forces protocols for both sockets. |
| 4496 | TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredProxyRetry) { |
| 4497 | // HTTP_1_1_REQUIRED is only supported by SPDY4. |
| 4498 | if (spdy_util_.spdy_version() < SPDY4) |
| 4499 | return; |
| 4500 | // HTTP_1_1_REQUIRED implementation relies on the assumption that HTTP/2 is |
| 4501 | // only spoken over SSL. |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4502 | if (GetParam().ssl_type != HTTPS_SPDY_VIA_NPN) |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4503 | return; |
| 4504 | |
| 4505 | HttpRequestInfo request; |
| 4506 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4507 | request.url = GURL("https://www.example.org/"); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4508 | scoped_ptr<SpdySessionDependencies> session_deps( |
| 4509 | CreateSpdySessionDependencies( |
| 4510 | GetParam(), |
| 4511 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"))); |
| 4512 | // Do not force SPDY so that second socket can negotiate HTTP/1.1. |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4513 | session_deps->next_protos = SpdyNextProtos(); |
| 4514 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 4515 | GetParam(), session_deps.release()); |
| 4516 | |
| 4517 | // First socket: HTTP/2 CONNECT rejected with HTTP_1_1_REQUIRED. |
| 4518 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4519 | nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4520 | MockWrite writes0[] = {CreateMockWrite(*req, 0)}; |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4521 | scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway( |
| 4522 | 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4523 | MockRead reads0[] = {CreateMockRead(*go_away, 1)}; |
| 4524 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 4525 | arraysize(writes0)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4526 | |
| 4527 | scoped_ptr<SSLSocketDataProvider> ssl_provider0( |
| 4528 | new SSLSocketDataProvider(ASYNC, OK)); |
| 4529 | // Expect HTTP/2 protocols too in SSLConfig. |
| 4530 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4531 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY31); |
| 4532 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY4_14); |
bnc | bfa20e6 | 2015-03-09 23:29:22 | [diff] [blame] | 4533 | ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoSPDY4); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4534 | // Force SPDY. |
| 4535 | ssl_provider0->SetNextProto(GetParam().protocol); |
| 4536 | helper.AddDataWithSSLSocketDataProvider(&data0, ssl_provider0.Pass()); |
| 4537 | |
| 4538 | // Second socket: retry using HTTP/1.1. |
| 4539 | MockWrite writes1[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4540 | MockWrite(ASYNC, 0, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4541 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4542 | "Host: www.example.org\r\n" |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4543 | "Proxy-Connection: keep-alive\r\n\r\n"), |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4544 | MockWrite(ASYNC, 2, |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4545 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4546 | "Host: www.example.org\r\n" |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4547 | "Connection: keep-alive\r\n\r\n"), |
| 4548 | }; |
| 4549 | |
| 4550 | MockRead reads1[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4551 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 4552 | MockRead(ASYNC, 3, |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4553 | "HTTP/1.1 200 OK\r\n" |
| 4554 | "Content-Length: 5\r\n\r\n" |
| 4555 | "hello"), |
| 4556 | }; |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4557 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 4558 | arraysize(writes1)); |
bnc | facdd85 | 2015-01-09 19:22:54 | [diff] [blame] | 4559 | |
| 4560 | scoped_ptr<SSLSocketDataProvider> ssl_provider1( |
| 4561 | new SSLSocketDataProvider(ASYNC, OK)); |
| 4562 | // Expect only HTTP/1.1 protocol in SSLConfig. |
| 4563 | ssl_provider1->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4564 | // Force HTTP/1.1. |
| 4565 | ssl_provider1->SetNextProto(kProtoHTTP11); |
| 4566 | helper.AddDataWithSSLSocketDataProvider(&data1, ssl_provider1.Pass()); |
| 4567 | |
| 4568 | // A third socket is needed for the tunnelled connection. |
| 4569 | scoped_ptr<SSLSocketDataProvider> ssl_provider2( |
| 4570 | new SSLSocketDataProvider(ASYNC, OK)); |
| 4571 | helper.session_deps()->socket_factory->AddSSLSocketDataProvider( |
| 4572 | ssl_provider2.get()); |
| 4573 | |
| 4574 | base::WeakPtr<HttpServerProperties> http_server_properties = |
| 4575 | helper.session()->spdy_session_pool()->http_server_properties(); |
| 4576 | const HostPortPair proxy_host_port_pair = HostPortPair("myproxy", 70); |
| 4577 | EXPECT_FALSE(http_server_properties->RequiresHTTP11(proxy_host_port_pair)); |
| 4578 | |
| 4579 | helper.RunPreTestSetup(); |
| 4580 | helper.StartDefaultTest(); |
| 4581 | helper.FinishDefaultTestWithoutVerification(); |
| 4582 | helper.VerifyDataConsumed(); |
| 4583 | EXPECT_TRUE(http_server_properties->RequiresHTTP11(proxy_host_port_pair)); |
| 4584 | |
| 4585 | const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
| 4586 | ASSERT_TRUE(response != nullptr); |
| 4587 | ASSERT_TRUE(response->headers.get() != nullptr); |
| 4588 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4589 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 4590 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, response->connection_info); |
| 4591 | EXPECT_FALSE(response->was_npn_negotiated); |
| 4592 | EXPECT_TRUE(request.url.SchemeIs("https")); |
| 4593 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 4594 | EXPECT_EQ(70, response->socket_address.port()); |
| 4595 | std::string response_data; |
| 4596 | ASSERT_EQ(OK, ReadTransaction(helper.trans(), &response_data)); |
| 4597 | EXPECT_EQ("hello", response_data); |
| 4598 | } |
| 4599 | |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4600 | // Test to make sure we can correctly connect through a proxy. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4601 | TEST_P(SpdyNetworkTransactionTest, ProxyConnect) { |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4602 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4603 | BoundNetLog(), GetParam(), NULL); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4604 | helper.session_deps().reset(CreateSpdySessionDependencies( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4605 | GetParam(), |
[email protected] | 733b7a6d | 2010-08-25 01:38:43 | [diff] [blame] | 4606 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"))); |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 4607 | helper.SetSession(make_scoped_refptr( |
| 4608 | SpdySessionDependencies::SpdyCreateSession(helper.session_deps().get()))); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4609 | helper.RunPreTestSetup(); |
| 4610 | HttpNetworkTransaction* trans = helper.trans(); |
| 4611 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4612 | const char kConnect443[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4613 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4614 | "Host: www.example.org\r\n" |
rch | cb934f56 | 2015-04-07 16:25:12 | [diff] [blame] | 4615 | "Proxy-Connection: keep-alive\r\n\r\n"}; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4616 | const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4617 | scoped_ptr<SpdyFrame> req( |
| 4618 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4619 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4620 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4621 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4622 | MockWrite writes[] = { |
| 4623 | MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0), |
| 4624 | CreateMockWrite(*req, 2), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4625 | }; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4626 | MockRead reads[] = { |
| 4627 | MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), |
| 4628 | CreateMockRead(*resp, 3), |
| 4629 | CreateMockRead(*body.get(), 4), |
| 4630 | MockRead(ASYNC, 0, 0, 5), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4631 | }; |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4632 | scoped_ptr<SequencedSocketData> data(new SequencedSocketData( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4633 | reads, arraysize(reads), writes, arraysize(writes))); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4634 | |
| 4635 | helper.AddData(data.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4636 | TestCompletionCallback callback; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4637 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4638 | int rv = trans->Start( |
| 4639 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4640 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4641 | |
| 4642 | rv = callback.WaitForResult(); |
| 4643 | EXPECT_EQ(0, rv); |
| 4644 | |
| 4645 | // Verify the SYN_REPLY. |
| 4646 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4647 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4648 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 4649 | |
| 4650 | std::string response_data; |
| 4651 | ASSERT_EQ(OK, ReadTransaction(trans, &response_data)); |
| 4652 | EXPECT_EQ("hello!", response_data); |
| 4653 | helper.VerifyDataConsumed(); |
| 4654 | } |
| 4655 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4656 | // Test to make sure we can correctly connect through a proxy to |
| 4657 | // www.example.org, if there already exists a direct spdy connection to |
| 4658 | // www.example.org. See https://crbug.com/49874. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4659 | TEST_P(SpdyNetworkTransactionTest, DirectConnectProxyReconnect) { |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4660 | // When setting up the first transaction, we store the SpdySessionPool so that |
| 4661 | // we can use the same pool in the second transaction. |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4662 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4663 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 733b7a6d | 2010-08-25 01:38:43 | [diff] [blame] | 4664 | |
| 4665 | // Use a proxy service which returns a proxy fallback list from DIRECT to |
| 4666 | // myproxy:70. For this test there will be no fallback, so it is equivalent |
| 4667 | // to simply DIRECT. The reason for appending the second proxy is to verify |
| 4668 | // that the session pool key used does is just "DIRECT". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4669 | helper.session_deps().reset(CreateSpdySessionDependencies( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4670 | GetParam(), |
[email protected] | 733b7a6d | 2010-08-25 01:38:43 | [diff] [blame] | 4671 | ProxyService::CreateFixedFromPacResult("DIRECT; PROXY myproxy:70"))); |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 4672 | helper.SetSession(make_scoped_refptr( |
| 4673 | SpdySessionDependencies::SpdyCreateSession(helper.session_deps().get()))); |
[email protected] | 733b7a6d | 2010-08-25 01:38:43 | [diff] [blame] | 4674 | |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 4675 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4676 | helper.RunPreTestSetup(); |
| 4677 | |
| 4678 | // Construct and send a simple GET request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4679 | scoped_ptr<SpdyFrame> req( |
| 4680 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4681 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4682 | CreateMockWrite(*req, 0), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4683 | }; |
| 4684 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4685 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4686 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4687 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4688 | CreateMockRead(*resp, 1), |
| 4689 | CreateMockRead(*body, 2), |
| 4690 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), // Force a pause |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4691 | }; |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4692 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4693 | helper.AddData(&data); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4694 | HttpNetworkTransaction* trans = helper.trans(); |
| 4695 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4696 | TestCompletionCallback callback; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4697 | TransactionHelperResult out; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4698 | out.rv = trans->Start( |
| 4699 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4700 | |
| 4701 | EXPECT_EQ(out.rv, ERR_IO_PENDING); |
| 4702 | out.rv = callback.WaitForResult(); |
| 4703 | EXPECT_EQ(out.rv, OK); |
| 4704 | |
| 4705 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4706 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4707 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4708 | out.rv = ReadTransaction(trans, &out.response_data); |
| 4709 | EXPECT_EQ(OK, out.rv); |
| 4710 | out.status_line = response->headers->GetStatusLine(); |
| 4711 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4712 | EXPECT_EQ("hello!", out.response_data); |
| 4713 | |
| 4714 | // Check that the SpdySession is still in the SpdySessionPool. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4715 | HostPortPair host_port_pair("www.example.org", helper.port()); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 4716 | SpdySessionKey session_pool_key_direct( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 4717 | host_port_pair, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 4718 | EXPECT_TRUE(HasSpdySession(spdy_session_pool, session_pool_key_direct)); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 4719 | SpdySessionKey session_pool_key_proxy( |
[email protected] | 31e68d7 | 2010-08-25 06:36:58 | [diff] [blame] | 4720 | host_port_pair, |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 4721 | ProxyServer::FromURI("www.foo.com", ProxyServer::SCHEME_HTTP), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 4722 | PRIVACY_MODE_DISABLED); |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 4723 | EXPECT_FALSE(HasSpdySession(spdy_session_pool, session_pool_key_proxy)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4724 | |
| 4725 | // Set up data for the proxy connection. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4726 | const char kConnect443[] = { |
| 4727 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4728 | "Host: www.example.org\r\n" |
| 4729 | "Proxy-Connection: keep-alive\r\n\r\n"}; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4730 | const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4731 | scoped_ptr<SpdyFrame> req2(spdy_util_.ConstructSpdyGet( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4732 | GetDefaultUrlWithPath("/foo.dat").c_str(), false, 1, LOWEST)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4733 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4734 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4735 | |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4736 | MockWrite writes2[] = { |
| 4737 | MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0), |
| 4738 | CreateMockWrite(*req2, 2), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4739 | }; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4740 | MockRead reads2[] = { |
| 4741 | MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), |
| 4742 | CreateMockRead(*resp2, 3), |
| 4743 | CreateMockRead(*body2, 4), |
| 4744 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4745 | }; |
| 4746 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4747 | scoped_ptr<SequencedSocketData> data_proxy(new SequencedSocketData( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4748 | reads2, arraysize(reads2), writes2, arraysize(writes2))); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4749 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4750 | // Create another request to www.example.org, but this time through a proxy. |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4751 | HttpRequestInfo request_proxy; |
| 4752 | request_proxy.method = "GET"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 4753 | request_proxy.url = GURL(GetDefaultUrlWithPath("/foo.dat")); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4754 | request_proxy.load_flags = 0; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4755 | scoped_ptr<SpdySessionDependencies> ssd_proxy( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4756 | CreateSpdySessionDependencies(GetParam())); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4757 | // Ensure that this transaction uses the same SpdySessionPool. |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 4758 | scoped_refptr<HttpNetworkSession> session_proxy( |
| 4759 | SpdySessionDependencies::SpdyCreateSession(ssd_proxy.get())); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4760 | NormalSpdyTransactionHelper helper_proxy(request_proxy, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4761 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 4762 | HttpNetworkSessionPeer session_peer(session_proxy); |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4763 | scoped_ptr<ProxyService> proxy_service( |
| 4764 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 4765 | session_peer.SetProxyService(proxy_service.get()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4766 | helper_proxy.session_deps().swap(ssd_proxy); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 4767 | helper_proxy.SetSession(session_proxy); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4768 | helper_proxy.RunPreTestSetup(); |
| 4769 | helper_proxy.AddData(data_proxy.get()); |
| 4770 | |
| 4771 | HttpNetworkTransaction* trans_proxy = helper_proxy.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4772 | TestCompletionCallback callback_proxy; |
| 4773 | int rv = trans_proxy->Start( |
| 4774 | &request_proxy, callback_proxy.callback(), BoundNetLog()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4775 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4776 | rv = callback_proxy.WaitForResult(); |
| 4777 | EXPECT_EQ(0, rv); |
| 4778 | |
| 4779 | HttpResponseInfo response_proxy = *trans_proxy->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4780 | EXPECT_TRUE(response_proxy.headers.get() != NULL); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4781 | EXPECT_EQ("HTTP/1.1 200 OK", response_proxy.headers->GetStatusLine()); |
| 4782 | |
| 4783 | std::string response_data; |
| 4784 | ASSERT_EQ(OK, ReadTransaction(trans_proxy, &response_data)); |
| 4785 | EXPECT_EQ("hello!", response_data); |
| 4786 | |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4787 | helper_proxy.VerifyDataConsumed(); |
| 4788 | } |
| 4789 | |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4790 | // When we get a TCP-level RST, we need to retry a HttpNetworkTransaction |
| 4791 | // on a new connection, if the connection was previously known to be good. |
| 4792 | // This can happen when a server reboots without saying goodbye, or when |
| 4793 | // we're behind a NAT that masked the RST. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4794 | TEST_P(SpdyNetworkTransactionTest, VerifyRetryOnConnectionReset) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4795 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4796 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4797 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4798 | CreateMockRead(*resp, 0), |
| 4799 | CreateMockRead(*body, 1), |
| 4800 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 4801 | MockRead(ASYNC, ERR_CONNECTION_RESET, 3), |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4802 | }; |
| 4803 | |
| 4804 | MockRead reads2[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4805 | CreateMockRead(*resp, 0), |
| 4806 | CreateMockRead(*body, 1), |
| 4807 | MockRead(ASYNC, 0, 2) // EOF |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4808 | }; |
| 4809 | |
| 4810 | // This test has a couple of variants. |
| 4811 | enum { |
| 4812 | // Induce the RST while waiting for our transaction to send. |
| 4813 | VARIANT_RST_DURING_SEND_COMPLETION, |
| 4814 | // Induce the RST while waiting for our transaction to read. |
| 4815 | // In this case, the send completed - everything copied into the SNDBUF. |
| 4816 | VARIANT_RST_DURING_READ_COMPLETION |
| 4817 | }; |
| 4818 | |
| 4819 | for (int variant = VARIANT_RST_DURING_SEND_COMPLETION; |
| 4820 | variant <= VARIANT_RST_DURING_READ_COMPLETION; |
| 4821 | ++variant) { |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4822 | DelayedSocketData data1(1, reads, arraysize(reads), NULL, 0); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4823 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4824 | DelayedSocketData data2(1, reads2, arraysize(reads2), NULL, 0); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4825 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4826 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4827 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4828 | helper.AddData(&data1); |
| 4829 | helper.AddData(&data2); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4830 | helper.RunPreTestSetup(); |
| 4831 | |
| 4832 | for (int i = 0; i < 2; ++i) { |
| 4833 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4834 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4835 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4836 | TestCompletionCallback callback; |
| 4837 | int rv = trans->Start( |
| 4838 | &helper.request(), callback.callback(), BoundNetLog()); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4839 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4840 | // On the second transaction, we trigger the RST. |
| 4841 | if (i == 1) { |
| 4842 | if (variant == VARIANT_RST_DURING_READ_COMPLETION) { |
| 4843 | // Writes to the socket complete asynchronously on SPDY by running |
| 4844 | // through the message loop. Complete the write here. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4845 | base::RunLoop().RunUntilIdle(); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4846 | } |
| 4847 | |
| 4848 | // Now schedule the ERR_CONNECTION_RESET. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4849 | EXPECT_EQ(3u, data1.read_index()); |
| 4850 | data1.CompleteRead(); |
| 4851 | EXPECT_EQ(4u, data1.read_index()); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4852 | } |
| 4853 | rv = callback.WaitForResult(); |
| 4854 | EXPECT_EQ(OK, rv); |
| 4855 | |
| 4856 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 351ab64 | 2010-08-05 16:55:31 | [diff] [blame] | 4857 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4858 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4859 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4860 | std::string response_data; |
| 4861 | rv = ReadTransaction(trans.get(), &response_data); |
| 4862 | EXPECT_EQ(OK, rv); |
| 4863 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4864 | EXPECT_EQ("hello!", response_data); |
| 4865 | } |
| 4866 | |
| 4867 | helper.VerifyDataConsumed(); |
| 4868 | } |
| 4869 | } |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4870 | |
| 4871 | // Test that turning SPDY on and off works properly. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4872 | TEST_P(SpdyNetworkTransactionTest, SpdyOnOffToggle) { |
[email protected] | d759912 | 2014-05-24 03:37:23 | [diff] [blame] | 4873 | HttpStreamFactory::set_spdy_enabled(true); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4874 | scoped_ptr<SpdyFrame> req( |
| 4875 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4876 | MockWrite spdy_writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4877 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4878 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4879 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4880 | MockRead spdy_reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4881 | CreateMockRead(*resp, 1), |
| 4882 | CreateMockRead(*body, 2), |
| 4883 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4884 | }; |
| 4885 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4886 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4887 | arraysize(spdy_writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4888 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4889 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4890 | helper.RunToCompletion(&data); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4891 | TransactionHelperResult out = helper.output(); |
| 4892 | EXPECT_EQ(OK, out.rv); |
| 4893 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4894 | EXPECT_EQ("hello!", out.response_data); |
| 4895 | |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4896 | HttpStreamFactory::set_spdy_enabled(false); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4897 | MockWrite http_writes[] = { |
| 4898 | MockWrite(SYNCHRONOUS, 0, |
| 4899 | "GET / HTTP/1.1\r\n" |
| 4900 | "Host: www.example.org\r\n" |
| 4901 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4902 | }; |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4903 | |
| 4904 | MockRead http_reads[] = { |
| 4905 | MockRead(SYNCHRONOUS, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 4906 | MockRead(SYNCHRONOUS, 2, "hello from http"), |
| 4907 | MockRead(SYNCHRONOUS, OK, 3), |
| 4908 | }; |
| 4909 | SequencedSocketData data2(http_reads, arraysize(http_reads), http_writes, |
| 4910 | arraysize(http_writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4911 | NormalSpdyTransactionHelper helper2(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4912 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4913 | helper2.SetSpdyDisabled(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4914 | helper2.RunToCompletion(&data2); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4915 | TransactionHelperResult out2 = helper2.output(); |
| 4916 | EXPECT_EQ(OK, out2.rv); |
| 4917 | EXPECT_EQ("HTTP/1.1 200 OK", out2.status_line); |
| 4918 | EXPECT_EQ("hello from http", out2.response_data); |
| 4919 | |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4920 | HttpStreamFactory::set_spdy_enabled(true); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4921 | } |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4922 | |
| 4923 | // Tests that Basic authentication works over SPDY |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4924 | TEST_P(SpdyNetworkTransactionTest, SpdyBasicAuth) { |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 4925 | HttpStreamFactory::set_spdy_enabled(true); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4926 | |
| 4927 | // The first request will be a bare GET, the second request will be a |
| 4928 | // GET with an Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4929 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4930 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4931 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4932 | "authorization", "Basic Zm9vOmJhcg==" |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4933 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4934 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4935 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 4936 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 4937 | false, 3, LOWEST, true)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4938 | MockWrite spdy_writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4939 | CreateMockWrite(*req_get, 0), CreateMockWrite(*req_get_authorization, 3), |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4940 | }; |
| 4941 | |
| 4942 | // The first response is a 401 authentication challenge, and the second |
| 4943 | // response will be a 200 response since the second request includes a valid |
| 4944 | // Authorization header. |
| 4945 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | fb9e431 | 2012-02-17 06:27:26 | [diff] [blame] | 4946 | "www-authenticate", |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4947 | "Basic realm=\"MyRealm\"" |
| 4948 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4949 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4950 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4951 | "401 Authentication Required", |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 4952 | kExtraAuthenticationHeaders, |
| 4953 | arraysize(kExtraAuthenticationHeaders) / 2, |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4954 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4955 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4956 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4957 | scoped_ptr<SpdyFrame> resp_data( |
| 4958 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 4959 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4960 | MockRead spdy_reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4961 | CreateMockRead(*resp_authentication, 1), |
| 4962 | CreateMockRead(*body_authentication, 2), |
| 4963 | CreateMockRead(*resp_data, 4), |
| 4964 | CreateMockRead(*body_data, 5), |
| 4965 | MockRead(ASYNC, 0, 6), |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4966 | }; |
| 4967 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 4968 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4969 | arraysize(spdy_writes)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4970 | HttpRequestInfo request(CreateGetRequest()); |
| 4971 | BoundNetLog net_log; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4972 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 4973 | net_log, GetParam(), NULL); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4974 | |
| 4975 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4976 | helper.AddData(&data); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4977 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4978 | TestCompletionCallback callback; |
| 4979 | const int rv_start = trans->Start(&request, callback.callback(), net_log); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4980 | EXPECT_EQ(ERR_IO_PENDING, rv_start); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4981 | const int rv_start_complete = callback.WaitForResult(); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4982 | EXPECT_EQ(OK, rv_start_complete); |
| 4983 | |
| 4984 | // Make sure the response has an auth challenge. |
| 4985 | const HttpResponseInfo* const response_start = trans->GetResponseInfo(); |
| 4986 | ASSERT_TRUE(response_start != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4987 | ASSERT_TRUE(response_start->headers.get() != NULL); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4988 | EXPECT_EQ(401, response_start->headers->response_code()); |
| 4989 | EXPECT_TRUE(response_start->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4990 | AuthChallengeInfo* auth_challenge = response_start->auth_challenge.get(); |
| 4991 | ASSERT_TRUE(auth_challenge != NULL); |
| 4992 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 4993 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 4994 | EXPECT_EQ("MyRealm", auth_challenge->realm); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 4995 | |
| 4996 | // Restart with a username/password. |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 4997 | AuthCredentials credentials(base::ASCIIToUTF16("foo"), |
| 4998 | base::ASCIIToUTF16("bar")); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4999 | TestCompletionCallback callback_restart; |
| 5000 | const int rv_restart = trans->RestartWithAuth( |
| 5001 | credentials, callback_restart.callback()); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5002 | EXPECT_EQ(ERR_IO_PENDING, rv_restart); |
| 5003 | const int rv_restart_complete = callback_restart.WaitForResult(); |
| 5004 | EXPECT_EQ(OK, rv_restart_complete); |
| 5005 | // TODO(cbentzel): This is actually the same response object as before, but |
| 5006 | // data has changed. |
| 5007 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 5008 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5009 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5010 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5011 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 5012 | } |
| 5013 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5014 | TEST_P(SpdyNetworkTransactionTest, ServerPushWithHeaders) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5015 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5016 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5017 | scoped_ptr<SpdyFrame> stream1_body( |
| 5018 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5019 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 5020 | CreateMockWrite(*stream1_syn, 0), |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5021 | }; |
| 5022 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5023 | scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5024 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
| 5025 | initial_headers.get()); |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5026 | scoped_ptr<SpdyFrame> stream2_syn( |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 5027 | spdy_util_.ConstructInitialSpdyPushFrame(initial_headers.Pass(), 2, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5028 | |
| 5029 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5030 | (*late_headers)["hello"] = "bye"; |
| 5031 | (*late_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 5032 | (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5033 | scoped_ptr<SpdyFrame> stream2_headers( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5034 | spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5035 | false, |
| 5036 | 2, |
| 5037 | LOWEST, |
| 5038 | HEADERS, |
| 5039 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5040 | 0)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5041 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5042 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5043 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5044 | const char kPushedData[] = "pushed"; |
| 5045 | scoped_ptr<SpdyFrame> stream2_body( |
| 5046 | spdy_util_.ConstructSpdyBodyFrame( |
| 5047 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5048 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 5049 | CreateMockRead(*stream1_reply, 1), |
| 5050 | CreateMockRead(*stream2_syn, 2), |
| 5051 | CreateMockRead(*stream2_headers, 3), |
| 5052 | CreateMockRead(*stream1_body, 4, SYNCHRONOUS), |
| 5053 | CreateMockRead(*stream2_body, 5), |
| 5054 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a pause |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5055 | }; |
| 5056 | |
| 5057 | HttpResponseInfo response; |
| 5058 | HttpResponseInfo response2; |
| 5059 | std::string expected_push_result("pushed"); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 5060 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5061 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5062 | &response, |
| 5063 | &response2, |
| 5064 | expected_push_result); |
| 5065 | |
| 5066 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5067 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5068 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5069 | |
| 5070 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5071 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5072 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 5073 | } |
| 5074 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5075 | TEST_P(SpdyNetworkTransactionTest, ServerPushClaimBeforeHeaders) { |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5076 | // 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] | 5077 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5078 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5079 | scoped_ptr<SpdyFrame> stream1_body( |
| 5080 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5081 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5082 | CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5083 | }; |
| 5084 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5085 | scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5086 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
| 5087 | initial_headers.get()); |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5088 | scoped_ptr<SpdyFrame> stream2_syn( |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 5089 | spdy_util_.ConstructInitialSpdyPushFrame(initial_headers.Pass(), 2, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5090 | |
| 5091 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5092 | (*late_headers)["hello"] = "bye"; |
| 5093 | (*late_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 5094 | (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5095 | scoped_ptr<SpdyFrame> stream2_headers( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5096 | spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5097 | false, |
| 5098 | 2, |
| 5099 | LOWEST, |
| 5100 | HEADERS, |
| 5101 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5102 | 0)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5103 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5104 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5105 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5106 | const char kPushedData[] = "pushed"; |
| 5107 | scoped_ptr<SpdyFrame> stream2_body( |
| 5108 | spdy_util_.ConstructSpdyBodyFrame( |
| 5109 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5110 | MockRead reads[] = { |
| 5111 | CreateMockRead(*stream1_reply, 1), |
| 5112 | CreateMockRead(*stream2_syn, 2), |
| 5113 | CreateMockRead(*stream1_body, 3), |
| 5114 | CreateMockRead(*stream2_headers, 4), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5115 | CreateMockRead(*stream2_body, 5), |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 5116 | MockRead(ASYNC, 0, 6), // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5117 | }; |
| 5118 | |
| 5119 | HttpResponseInfo response; |
| 5120 | HttpResponseInfo response2; |
| 5121 | std::string expected_push_result("pushed"); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5122 | DeterministicSocketData data(reads, arraysize(reads), |
| 5123 | writes, arraysize(writes)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5124 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5125 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5126 | BoundNetLog(), GetParam(), NULL); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5127 | helper.SetDeterministic(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5128 | helper.AddDeterministicData(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5129 | helper.RunPreTestSetup(); |
| 5130 | |
| 5131 | HttpNetworkTransaction* trans = helper.trans(); |
| 5132 | |
| 5133 | // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM, |
| 5134 | // and the body of the primary stream, but before we've received the HEADERS |
| 5135 | // for the pushed stream. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5136 | data.SetStop(3); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5137 | |
| 5138 | // Start the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5139 | TestCompletionCallback callback; |
| 5140 | int rv = trans->Start( |
| 5141 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5142 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5143 | data.Run(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5144 | rv = callback.WaitForResult(); |
| 5145 | EXPECT_EQ(0, rv); |
| 5146 | |
| 5147 | // Request the pushed path. At this point, we've received the push, but the |
| 5148 | // headers are not yet complete. |
| 5149 | scoped_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5150 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5151 | rv = trans2->Start( |
| 5152 | &CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5153 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5154 | data.RunFor(3); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5155 | base::RunLoop().RunUntilIdle(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5156 | |
| 5157 | // Read the server push body. |
| 5158 | std::string result2; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5159 | ReadResult(trans2.get(), &data, &result2); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5160 | // Read the response body. |
| 5161 | std::string result; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5162 | ReadResult(trans, &data, &result); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5163 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5164 | // Verify that the received push data is same as the expected push data. |
| 5165 | EXPECT_EQ(result2.compare(expected_push_result), 0) |
| 5166 | << "Received data: " |
| 5167 | << result2 |
| 5168 | << "||||| Expected data: " |
| 5169 | << expected_push_result; |
| 5170 | |
| 5171 | // Verify the SYN_REPLY. |
| 5172 | // Copy the response info, because trans goes away. |
| 5173 | response = *trans->GetResponseInfo(); |
| 5174 | response2 = *trans2->GetResponseInfo(); |
| 5175 | |
| 5176 | VerifyStreamsClosed(helper); |
| 5177 | |
| 5178 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5179 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5180 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5181 | |
| 5182 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5183 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5184 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 5185 | |
| 5186 | // Read the final EOF (which will close the session) |
| 5187 | data.RunFor(1); |
| 5188 | |
| 5189 | // Verify that we consumed all test data. |
rch | bce10d97 | 2015-05-04 18:21:19 | [diff] [blame] | 5190 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 5191 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5192 | } |
| 5193 | |
[email protected] | 6cd63ba | 2014-06-12 16:14:56 | [diff] [blame] | 5194 | // TODO(baranovich): HTTP 2 does not allow multiple HEADERS frames |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5195 | TEST_P(SpdyNetworkTransactionTest, ServerPushWithTwoHeaderFrames) { |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5196 | // 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] | 5197 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5198 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5199 | scoped_ptr<SpdyFrame> stream1_body( |
| 5200 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5201 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5202 | CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5203 | }; |
| 5204 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5205 | scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 5206 | if (spdy_util_.spdy_version() < SPDY4) { |
| 5207 | // In SPDY4 PUSH_PROMISE headers won't show up in the response headers. |
| 5208 | (*initial_headers)["alpha"] = "beta"; |
| 5209 | } |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5210 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
| 5211 | initial_headers.get()); |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5212 | scoped_ptr<SpdyFrame> stream2_syn( |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 5213 | spdy_util_.ConstructInitialSpdyPushFrame(initial_headers.Pass(), 2, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5214 | |
| 5215 | scoped_ptr<SpdyHeaderBlock> middle_headers(new SpdyHeaderBlock()); |
| 5216 | (*middle_headers)["hello"] = "bye"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5217 | scoped_ptr<SpdyFrame> stream2_headers1( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5218 | spdy_util_.ConstructSpdyControlFrame(middle_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5219 | false, |
| 5220 | 2, |
| 5221 | LOWEST, |
| 5222 | HEADERS, |
| 5223 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5224 | 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5225 | |
| 5226 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5227 | (*late_headers)[spdy_util_.GetStatusKey()] = "200"; |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5228 | if (spdy_util_.spdy_version() < SPDY4) { |
| 5229 | // SPDY4/HTTP2 eliminates use of the :version header. |
| 5230 | (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
| 5231 | } |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5232 | scoped_ptr<SpdyFrame> stream2_headers2( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5233 | spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5234 | false, |
| 5235 | 2, |
| 5236 | LOWEST, |
| 5237 | HEADERS, |
| 5238 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5239 | 0)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5240 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5241 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5242 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5243 | const char kPushedData[] = "pushed"; |
| 5244 | scoped_ptr<SpdyFrame> stream2_body( |
| 5245 | spdy_util_.ConstructSpdyBodyFrame( |
| 5246 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5247 | MockRead reads[] = { |
| 5248 | CreateMockRead(*stream1_reply, 1), |
| 5249 | CreateMockRead(*stream2_syn, 2), |
| 5250 | CreateMockRead(*stream1_body, 3), |
| 5251 | CreateMockRead(*stream2_headers1, 4), |
| 5252 | CreateMockRead(*stream2_headers2, 5), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5253 | CreateMockRead(*stream2_body, 6), |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 5254 | MockRead(ASYNC, 0, 7), // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5255 | }; |
| 5256 | |
| 5257 | HttpResponseInfo response; |
| 5258 | HttpResponseInfo response2; |
| 5259 | std::string expected_push_result("pushed"); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5260 | DeterministicSocketData data(reads, arraysize(reads), |
| 5261 | writes, arraysize(writes)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5262 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5263 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5264 | BoundNetLog(), GetParam(), NULL); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5265 | helper.SetDeterministic(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5266 | helper.AddDeterministicData(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5267 | helper.RunPreTestSetup(); |
| 5268 | |
| 5269 | HttpNetworkTransaction* trans = helper.trans(); |
| 5270 | |
| 5271 | // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM, |
| 5272 | // the first HEADERS frame, and the body of the primary stream, but before |
| 5273 | // we've received the final HEADERS for the pushed stream. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5274 | data.SetStop(4); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5275 | |
| 5276 | // Start the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5277 | TestCompletionCallback callback; |
| 5278 | int rv = trans->Start( |
| 5279 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5280 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5281 | data.Run(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5282 | rv = callback.WaitForResult(); |
| 5283 | EXPECT_EQ(0, rv); |
| 5284 | |
| 5285 | // Request the pushed path. At this point, we've received the push, but the |
| 5286 | // headers are not yet complete. |
| 5287 | scoped_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5288 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5289 | rv = trans2->Start( |
| 5290 | &CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5291 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5292 | data.RunFor(3); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5293 | base::RunLoop().RunUntilIdle(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5294 | |
| 5295 | // Read the server push body. |
| 5296 | std::string result2; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5297 | ReadResult(trans2.get(), &data, &result2); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5298 | // Read the response body. |
| 5299 | std::string result; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5300 | ReadResult(trans, &data, &result); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5301 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5302 | // Verify that the received push data is same as the expected push data. |
[email protected] | 6d116e1a | 2013-06-24 07:42:15 | [diff] [blame] | 5303 | EXPECT_EQ(expected_push_result, result2); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5304 | |
| 5305 | // Verify the SYN_REPLY. |
| 5306 | // Copy the response info, because trans goes away. |
| 5307 | response = *trans->GetResponseInfo(); |
| 5308 | response2 = *trans2->GetResponseInfo(); |
| 5309 | |
| 5310 | VerifyStreamsClosed(helper); |
| 5311 | |
| 5312 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5313 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5314 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5315 | |
| 5316 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5317 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5318 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 5319 | |
[email protected] | 6cd63ba | 2014-06-12 16:14:56 | [diff] [blame] | 5320 | // Verify we got all the headers from all header blocks. |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 5321 | if (spdy_util_.spdy_version() < SPDY4) |
| 5322 | EXPECT_TRUE(response2.headers->HasHeaderValue("alpha", "beta")); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5323 | EXPECT_TRUE(response2.headers->HasHeaderValue("hello", "bye")); |
| 5324 | EXPECT_TRUE(response2.headers->HasHeaderValue("status", "200")); |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 5325 | |
| 5326 | // Read the final EOF (which will close the session) |
| 5327 | data.RunFor(1); |
| 5328 | |
| 5329 | // Verify that we consumed all test data. |
rch | bce10d97 | 2015-05-04 18:21:19 | [diff] [blame] | 5330 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 5331 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5332 | } |
| 5333 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5334 | TEST_P(SpdyNetworkTransactionTest, ServerPushWithNoStatusHeaderFrames) { |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5335 | // 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] | 5336 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5337 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5338 | scoped_ptr<SpdyFrame> stream1_body( |
| 5339 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5340 | MockWrite writes[] = { |
| 5341 | CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), |
| 5342 | }; |
| 5343 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5344 | scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5345 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
| 5346 | initial_headers.get()); |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5347 | scoped_ptr<SpdyFrame> stream2_syn( |
[email protected] | 0338bc6 | 2014-06-20 17:09:56 | [diff] [blame] | 5348 | spdy_util_.ConstructInitialSpdyPushFrame(initial_headers.Pass(), 2, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5349 | |
| 5350 | scoped_ptr<SpdyHeaderBlock> middle_headers(new SpdyHeaderBlock()); |
| 5351 | (*middle_headers)["hello"] = "bye"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5352 | scoped_ptr<SpdyFrame> stream2_headers1( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5353 | spdy_util_.ConstructSpdyControlFrame(middle_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5354 | false, |
| 5355 | 2, |
| 5356 | LOWEST, |
| 5357 | HEADERS, |
| 5358 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5359 | 0)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5360 | |
| 5361 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5362 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5363 | const char kPushedData[] = "pushed"; |
| 5364 | scoped_ptr<SpdyFrame> stream2_body( |
| 5365 | spdy_util_.ConstructSpdyBodyFrame( |
| 5366 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5367 | MockRead reads[] = { |
| 5368 | CreateMockRead(*stream1_reply, 1), |
| 5369 | CreateMockRead(*stream2_syn, 2), |
| 5370 | CreateMockRead(*stream1_body, 3), |
| 5371 | CreateMockRead(*stream2_headers1, 4), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5372 | CreateMockRead(*stream2_body, 5), |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5373 | MockRead(ASYNC, 0, 6), // EOF |
| 5374 | }; |
| 5375 | |
| 5376 | DeterministicSocketData data(reads, arraysize(reads), |
| 5377 | writes, arraysize(writes)); |
| 5378 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5379 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5380 | BoundNetLog(), GetParam(), NULL); |
| 5381 | helper.SetDeterministic(); |
| 5382 | helper.AddDeterministicData(&data); |
| 5383 | helper.RunPreTestSetup(); |
| 5384 | |
| 5385 | HttpNetworkTransaction* trans = helper.trans(); |
| 5386 | |
| 5387 | // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM, |
| 5388 | // the first HEADERS frame, and the body of the primary stream, but before |
| 5389 | // we've received the final HEADERS for the pushed stream. |
| 5390 | data.SetStop(4); |
| 5391 | |
| 5392 | // Start the transaction. |
| 5393 | TestCompletionCallback callback; |
| 5394 | int rv = trans->Start( |
| 5395 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 5396 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5397 | data.Run(); |
| 5398 | rv = callback.WaitForResult(); |
| 5399 | EXPECT_EQ(0, rv); |
| 5400 | |
| 5401 | // Request the pushed path. At this point, we've received the push, but the |
| 5402 | // headers are not yet complete. |
| 5403 | scoped_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5404 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5405 | rv = trans2->Start( |
| 5406 | &CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
| 5407 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5408 | data.RunFor(2); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5409 | base::RunLoop().RunUntilIdle(); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5410 | |
| 5411 | // Read the server push body. |
| 5412 | std::string result2; |
| 5413 | ReadResult(trans2.get(), &data, &result2); |
| 5414 | // Read the response body. |
| 5415 | std::string result; |
| 5416 | ReadResult(trans, &data, &result); |
| 5417 | EXPECT_EQ("hello!", result); |
| 5418 | |
| 5419 | // Verify that we haven't received any push data. |
| 5420 | EXPECT_EQ("", result2); |
| 5421 | |
| 5422 | // Verify the SYN_REPLY. |
| 5423 | // Copy the response info, because trans goes away. |
| 5424 | HttpResponseInfo response = *trans->GetResponseInfo(); |
| 5425 | ASSERT_TRUE(trans2->GetResponseInfo() == NULL); |
| 5426 | |
| 5427 | VerifyStreamsClosed(helper); |
| 5428 | |
| 5429 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5430 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5431 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5432 | |
| 5433 | // Read the final EOF (which will close the session). |
| 5434 | data.RunFor(1); |
| 5435 | |
| 5436 | // Verify that we consumed all test data. |
rch | bce10d97 | 2015-05-04 18:21:19 | [diff] [blame] | 5437 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 5438 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5439 | } |
| 5440 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5441 | TEST_P(SpdyNetworkTransactionTest, SynReplyWithHeaders) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5442 | scoped_ptr<SpdyFrame> req( |
| 5443 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5444 | scoped_ptr<SpdyFrame> rst( |
| 5445 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 5446 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 5447 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 4), |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5448 | }; |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5449 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5450 | scoped_ptr<SpdyFrame> stream1_reply( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5451 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5452 | |
| 5453 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5454 | (*late_headers)["hello"] = "bye"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5455 | scoped_ptr<SpdyFrame> stream1_headers( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5456 | spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5457 | false, |
| 5458 | 1, |
| 5459 | LOWEST, |
| 5460 | HEADERS, |
| 5461 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5462 | 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5463 | scoped_ptr<SpdyFrame> stream1_body( |
| 5464 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5465 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 5466 | CreateMockRead(*stream1_reply, 1), |
| 5467 | CreateMockRead(*stream1_headers, 2), |
| 5468 | CreateMockRead(*stream1_body, 3), |
| 5469 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5470 | }; |
| 5471 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 5472 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5473 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5474 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5475 | helper.RunToCompletion(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5476 | TransactionHelperResult out = helper.output(); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5477 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5478 | } |
| 5479 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5480 | TEST_P(SpdyNetworkTransactionTest, SynReplyWithLateHeaders) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5481 | scoped_ptr<SpdyFrame> req( |
| 5482 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5483 | scoped_ptr<SpdyFrame> rst( |
| 5484 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 5485 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 5486 | CreateMockWrite(*req, 0), CreateMockWrite(*rst, 4), |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5487 | }; |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5488 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5489 | scoped_ptr<SpdyFrame> stream1_reply( |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5490 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5491 | |
| 5492 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5493 | (*late_headers)["hello"] = "bye"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5494 | scoped_ptr<SpdyFrame> stream1_headers( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5495 | spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5496 | false, |
| 5497 | 1, |
| 5498 | LOWEST, |
| 5499 | HEADERS, |
| 5500 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5501 | 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5502 | scoped_ptr<SpdyFrame> stream1_body( |
| 5503 | spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 5504 | scoped_ptr<SpdyFrame> stream1_body2( |
| 5505 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5506 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 5507 | CreateMockRead(*stream1_reply, 1), |
| 5508 | CreateMockRead(*stream1_body, 2), |
| 5509 | CreateMockRead(*stream1_headers, 3), |
| 5510 | CreateMockRead(*stream1_body2, 5), |
| 5511 | MockRead(ASYNC, 0, 6) // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5512 | }; |
| 5513 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5514 | DelayedSocketData data(1, reads, arraysize(reads), |
| 5515 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5516 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5517 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5518 | helper.RunToCompletion(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5519 | TransactionHelperResult out = helper.output(); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5520 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5521 | } |
| 5522 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5523 | TEST_P(SpdyNetworkTransactionTest, ServerPushCrossOriginCorrectness) { |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5524 | // Running these tests via Alt-Svc is too complicated to be worthwhile. |
| 5525 | if (GetParam().ssl_type != HTTPS_SPDY_VIA_NPN) |
| 5526 | return; |
| 5527 | |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5528 | // In this test we want to verify that we can't accidentally push content |
| 5529 | // which can't be pushed by this content server. |
| 5530 | // This test assumes that: |
| 5531 | // - if we're requesting http://www.foo.com/barbaz |
| 5532 | // - the browser has made a connection to "www.foo.com". |
| 5533 | |
| 5534 | // A list of the URL to fetch, followed by the URL being pushed. |
| 5535 | static const char* const kTestCases[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5536 | "https://www.example.org/foo.html", |
| 5537 | "https://www.example.org:81/foo.js", // Bad port |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5538 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5539 | "https://www.example.org/foo.html", |
| 5540 | "http://www.example.org/foo.js", // Bad protocol |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5541 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5542 | "https://www.example.org/foo.html", |
| 5543 | "ftp://www.example.org/foo.js", // Invalid Protocol |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5544 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5545 | "https://www.example.org/foo.html", |
| 5546 | "https://blat.www.example.org/foo.js", // Cross subdomain |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5547 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5548 | "https://www.example.org/foo.html", |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5549 | "https://www.foo.com/foo.js", // Cross domain |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5550 | }; |
| 5551 | |
[email protected] | b3f89933 | 2010-12-08 18:20:44 | [diff] [blame] | 5552 | for (size_t index = 0; index < arraysize(kTestCases); index += 2) { |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5553 | const char* url_to_fetch = kTestCases[index]; |
| 5554 | const char* url_to_push = kTestCases[index + 1]; |
| 5555 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5556 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5557 | spdy_util_.ConstructSpdyGet(url_to_fetch, false, 1, LOWEST)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5558 | scoped_ptr<SpdyFrame> stream1_body( |
| 5559 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5560 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5561 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5562 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 5563 | CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*push_rst, 3), |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5564 | }; |
| 5565 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5566 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5567 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5568 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5569 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
| 5570 | 0, |
| 5571 | 2, |
| 5572 | 1, |
| 5573 | url_to_push)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5574 | const char kPushedData[] = "pushed"; |
| 5575 | scoped_ptr<SpdyFrame> stream2_body( |
| 5576 | spdy_util_.ConstructSpdyBodyFrame( |
| 5577 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5578 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5579 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_CANCEL)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5580 | |
| 5581 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 5582 | CreateMockRead(*stream1_reply, 1), |
| 5583 | CreateMockRead(*stream2_syn, 2), |
| 5584 | CreateMockRead(*stream1_body, 4), |
| 5585 | CreateMockRead(*stream2_body, 5), |
| 5586 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a pause |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5587 | }; |
| 5588 | |
| 5589 | HttpResponseInfo response; |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 5590 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 5591 | arraysize(writes)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5592 | |
| 5593 | HttpRequestInfo request; |
| 5594 | request.method = "GET"; |
| 5595 | request.url = GURL(url_to_fetch); |
| 5596 | request.load_flags = 0; |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5597 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 5598 | // Enable cross-origin push. Since we are not using a proxy, this should |
| 5599 | // not actually enable cross-origin SPDY push. |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5600 | scoped_ptr<SpdySessionDependencies> session_deps( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5601 | CreateSpdySessionDependencies(GetParam())); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5602 | session_deps->trusted_spdy_proxy = "123.45.67.89:8080"; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5603 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5604 | BoundNetLog(), GetParam(), |
| 5605 | session_deps.release()); |
| 5606 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5607 | helper.AddData(&data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 5608 | |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5609 | HttpNetworkTransaction* trans = helper.trans(); |
| 5610 | |
| 5611 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5612 | TestCompletionCallback callback; |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5613 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5614 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5615 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5616 | rv = callback.WaitForResult(); |
| 5617 | |
| 5618 | // Read the response body. |
| 5619 | std::string result; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5620 | ReadResult(trans, &data, &result); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5621 | |
| 5622 | // Verify that we consumed all test data. |
rch | bce10d97 | 2015-05-04 18:21:19 | [diff] [blame] | 5623 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 5624 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5625 | |
| 5626 | // Verify the SYN_REPLY. |
| 5627 | // Copy the response info, because trans goes away. |
| 5628 | response = *trans->GetResponseInfo(); |
| 5629 | |
| 5630 | VerifyStreamsClosed(helper); |
| 5631 | |
| 5632 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5633 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5634 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5635 | } |
| 5636 | } |
| 5637 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5638 | TEST_P(SpdyNetworkTransactionTest, RetryAfterRefused) { |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5639 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5640 | scoped_ptr<SpdyFrame> req( |
| 5641 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5642 | scoped_ptr<SpdyFrame> req2( |
| 5643 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5644 | MockWrite writes[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 5645 | CreateMockWrite(*req, 0), CreateMockWrite(*req2, 2), |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5646 | }; |
| 5647 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5648 | scoped_ptr<SpdyFrame> refused( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5649 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5650 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 5651 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5652 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 5653 | CreateMockRead(*refused, 1), |
| 5654 | CreateMockRead(*resp, 3), |
| 5655 | CreateMockRead(*body, 4), |
| 5656 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5657 | }; |
| 5658 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 5659 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5660 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5661 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5662 | |
| 5663 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5664 | helper.AddData(&data); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5665 | |
| 5666 | HttpNetworkTransaction* trans = helper.trans(); |
| 5667 | |
| 5668 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5669 | TestCompletionCallback callback; |
| 5670 | int rv = trans->Start( |
| 5671 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5672 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5673 | rv = callback.WaitForResult(); |
| 5674 | EXPECT_EQ(OK, rv); |
| 5675 | |
| 5676 | // Verify that we consumed all test data. |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 5677 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 5678 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5679 | |
| 5680 | // Verify the SYN_REPLY. |
| 5681 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5682 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5683 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5684 | } |
| 5685 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5686 | TEST_P(SpdyNetworkTransactionTest, OutOfOrderSynStream) { |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5687 | // This first request will start to establish the SpdySession. |
| 5688 | // Then we will start the second (MEDIUM priority) and then third |
| 5689 | // (HIGHEST priority) request in such a way that the third will actually |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 5690 | // start before the second, causing the second to be numbered differently |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5691 | // than the order they were created. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5692 | scoped_ptr<SpdyFrame> req1( |
| 5693 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5694 | scoped_ptr<SpdyFrame> req2( |
| 5695 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, HIGHEST, true)); |
| 5696 | scoped_ptr<SpdyFrame> req3( |
| 5697 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, MEDIUM, true)); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5698 | MockWrite writes[] = { |
| 5699 | CreateMockWrite(*req1, 0), |
| 5700 | CreateMockWrite(*req2, 3), |
| 5701 | CreateMockWrite(*req3, 4), |
| 5702 | }; |
| 5703 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5704 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 5705 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 5706 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 5707 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 5708 | scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 5709 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5710 | MockRead reads[] = { |
| 5711 | CreateMockRead(*resp1, 1), |
| 5712 | CreateMockRead(*body1, 2), |
| 5713 | CreateMockRead(*resp2, 5), |
| 5714 | CreateMockRead(*body2, 6), |
| 5715 | CreateMockRead(*resp3, 7), |
| 5716 | CreateMockRead(*body3, 8), |
| 5717 | MockRead(ASYNC, 0, 9) // EOF |
| 5718 | }; |
| 5719 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5720 | DeterministicSocketData data(reads, arraysize(reads), |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5721 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5722 | NormalSpdyTransactionHelper helper(CreateGetRequest(), LOWEST, |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5723 | BoundNetLog(), GetParam(), NULL); |
| 5724 | helper.SetDeterministic(); |
| 5725 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5726 | helper.AddDeterministicData(&data); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5727 | |
| 5728 | // Start the first transaction to set up the SpdySession |
| 5729 | HttpNetworkTransaction* trans = helper.trans(); |
| 5730 | TestCompletionCallback callback; |
| 5731 | HttpRequestInfo info1 = CreateGetRequest(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5732 | int rv = trans->Start(&info1, callback.callback(), BoundNetLog()); |
| 5733 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5734 | |
| 5735 | // Run the message loop, but do not allow the write to complete. |
| 5736 | // This leaves the SpdySession with a write pending, which prevents |
| 5737 | // SpdySession from attempting subsequent writes until this write completes. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5738 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5739 | |
| 5740 | // Now, start both new transactions |
| 5741 | HttpRequestInfo info2 = CreateGetRequest(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5742 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5743 | scoped_ptr<HttpNetworkTransaction> trans2( |
| 5744 | new HttpNetworkTransaction(MEDIUM, helper.session().get())); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5745 | rv = trans2->Start(&info2, callback2.callback(), BoundNetLog()); |
| 5746 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5747 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5748 | |
| 5749 | HttpRequestInfo info3 = CreateGetRequest(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5750 | TestCompletionCallback callback3; |
| 5751 | scoped_ptr<HttpNetworkTransaction> trans3( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5752 | new HttpNetworkTransaction(HIGHEST, helper.session().get())); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5753 | rv = trans3->Start(&info3, callback3.callback(), BoundNetLog()); |
| 5754 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5755 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5756 | |
| 5757 | // We now have two SYN_STREAM frames queued up which will be |
| 5758 | // dequeued only once the first write completes, which we |
| 5759 | // now allow to happen. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5760 | data.RunFor(2); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5761 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5762 | |
| 5763 | // And now we can allow everything else to run to completion. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5764 | data.SetStop(10); |
| 5765 | data.Run(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5766 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 5767 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 5768 | |
| 5769 | helper.VerifyDataConsumed(); |
| 5770 | } |
| 5771 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5772 | // The tests below are only for SPDY/3 and above. |
| 5773 | |
| 5774 | // Test that sent data frames and received WINDOW_UPDATE frames change |
| 5775 | // the send_window_size_ correctly. |
| 5776 | |
| 5777 | // WINDOW_UPDATE is different than most other frames in that it can arrive |
| 5778 | // while the client is still sending the request body. In order to enforce |
| 5779 | // this scenario, we feed a couple of dummy frames and give a delay of 0 to |
| 5780 | // socket data provider, so that initial read that is done as soon as the |
| 5781 | // stream is created, succeeds and schedules another read. This way reads |
| 5782 | // and writes are interleaved; after doing a full frame write, SpdyStream |
| 5783 | // will break out of DoLoop and will read and process a WINDOW_UPDATE. |
| 5784 | // Once our WINDOW_UPDATE is read, we cannot send SYN_REPLY right away |
| 5785 | // since request has not been completely written, therefore we feed |
| 5786 | // enough number of WINDOW_UPDATEs to finish the first read and cause a |
| 5787 | // write, leading to a complete write of request body; after that we send |
| 5788 | // a reply with a body, to cause a graceful shutdown. |
| 5789 | |
| 5790 | // TODO(agayev): develop a socket data provider where both, reads and |
| 5791 | // writes are ordered so that writing tests like these are easy and rewrite |
| 5792 | // all these tests using it. Right now we are working around the |
| 5793 | // limitations as described above and it's not deterministic, tests may |
| 5794 | // fail under specific circumstances. |
| 5795 | TEST_P(SpdyNetworkTransactionTest, WindowUpdateReceived) { |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5796 | static int kFrameCount = 2; |
| 5797 | scoped_ptr<std::string> content( |
| 5798 | new std::string(kMaxSpdyFrameChunkSize, 'a')); |
| 5799 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5800 | GetDefaultUrl(), 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, NULL, |
| 5801 | 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5802 | scoped_ptr<SpdyFrame> body( |
| 5803 | spdy_util_.ConstructSpdyBodyFrame( |
| 5804 | 1, content->c_str(), content->size(), false)); |
| 5805 | scoped_ptr<SpdyFrame> body_end( |
| 5806 | spdy_util_.ConstructSpdyBodyFrame( |
| 5807 | 1, content->c_str(), content->size(), true)); |
| 5808 | |
| 5809 | MockWrite writes[] = { |
| 5810 | CreateMockWrite(*req, 0), |
| 5811 | CreateMockWrite(*body, 1), |
| 5812 | CreateMockWrite(*body_end, 2), |
| 5813 | }; |
| 5814 | |
| 5815 | static const int32 kDeltaWindowSize = 0xff; |
| 5816 | static const int kDeltaCount = 4; |
| 5817 | scoped_ptr<SpdyFrame> window_update( |
| 5818 | spdy_util_.ConstructSpdyWindowUpdate(1, kDeltaWindowSize)); |
| 5819 | scoped_ptr<SpdyFrame> window_update_dummy( |
| 5820 | spdy_util_.ConstructSpdyWindowUpdate(2, kDeltaWindowSize)); |
| 5821 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 5822 | MockRead reads[] = { |
| 5823 | CreateMockRead(*window_update_dummy, 3), |
| 5824 | CreateMockRead(*window_update_dummy, 4), |
| 5825 | CreateMockRead(*window_update_dummy, 5), |
| 5826 | CreateMockRead(*window_update, 6), // Four updates, therefore window |
| 5827 | CreateMockRead(*window_update, 7), // size should increase by |
| 5828 | CreateMockRead(*window_update, 8), // kDeltaWindowSize * 4 |
| 5829 | CreateMockRead(*window_update, 9), |
| 5830 | CreateMockRead(*resp, 10), |
| 5831 | CreateMockRead(*body_end, 11), |
| 5832 | MockRead(ASYNC, 0, 0, 12) // EOF |
| 5833 | }; |
| 5834 | |
| 5835 | DeterministicSocketData data(reads, arraysize(reads), |
| 5836 | writes, arraysize(writes)); |
| 5837 | |
| 5838 | ScopedVector<UploadElementReader> element_readers; |
| 5839 | for (int i = 0; i < kFrameCount; ++i) { |
| 5840 | element_readers.push_back( |
| 5841 | new UploadBytesElementReader(content->c_str(), content->size())); |
| 5842 | } |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 5843 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5844 | |
| 5845 | // Setup the request |
| 5846 | HttpRequestInfo request; |
| 5847 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 5848 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5849 | request.upload_data_stream = &upload_data_stream; |
| 5850 | |
| 5851 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 5852 | BoundNetLog(), GetParam(), NULL); |
| 5853 | helper.SetDeterministic(); |
| 5854 | helper.AddDeterministicData(&data); |
| 5855 | helper.RunPreTestSetup(); |
| 5856 | |
| 5857 | HttpNetworkTransaction* trans = helper.trans(); |
| 5858 | |
| 5859 | TestCompletionCallback callback; |
| 5860 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 5861 | |
| 5862 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5863 | |
| 5864 | data.RunFor(11); |
| 5865 | |
| 5866 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 5867 | ASSERT_TRUE(stream != NULL); |
| 5868 | ASSERT_TRUE(stream->stream() != NULL); |
bnc | 638c470 | 2015-04-09 18:01:18 | [diff] [blame] | 5869 | EXPECT_EQ(static_cast<int>( |
| 5870 | SpdySession::GetDefaultInitialWindowSize(GetParam().protocol)) + |
| 5871 | kDeltaWindowSize * kDeltaCount - |
| 5872 | kMaxSpdyFrameChunkSize * kFrameCount, |
| 5873 | stream->stream()->send_window_size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5874 | |
| 5875 | data.RunFor(1); |
| 5876 | |
| 5877 | rv = callback.WaitForResult(); |
| 5878 | EXPECT_EQ(OK, rv); |
| 5879 | |
| 5880 | helper.VerifyDataConsumed(); |
| 5881 | } |
| 5882 | |
| 5883 | // Test that received data frames and sent WINDOW_UPDATE frames change |
| 5884 | // the recv_window_size_ correctly. |
| 5885 | TEST_P(SpdyNetworkTransactionTest, WindowUpdateSent) { |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5886 | const int32 default_initial_window_size = |
bnc | 638c470 | 2015-04-09 18:01:18 | [diff] [blame] | 5887 | SpdySession::GetDefaultInitialWindowSize(GetParam().protocol); |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5888 | // Session level maximum window size that is more than twice the default |
| 5889 | // initial window size so that an initial window update is sent. |
| 5890 | const int32 session_max_recv_window_size = 5 * 64 * 1024; |
| 5891 | ASSERT_LT(2 * default_initial_window_size, session_max_recv_window_size); |
| 5892 | // Stream level maximum window size that is less than the session level |
| 5893 | // maximum window size so that we test for confusion between the two. |
| 5894 | const int32 stream_max_recv_window_size = 4 * 64 * 1024; |
| 5895 | ASSERT_GT(session_max_recv_window_size, stream_max_recv_window_size); |
| 5896 | // Size of body to be sent. Has to be less than or equal to both window sizes |
| 5897 | // so that we do not run out of receiving window. Also has to be greater than |
| 5898 | // half of them so that it triggers both a session level and a stream level |
| 5899 | // window update frame. |
| 5900 | const int32 kTargetSize = 3 * 64 * 1024; |
| 5901 | ASSERT_GE(session_max_recv_window_size, kTargetSize); |
| 5902 | ASSERT_GE(stream_max_recv_window_size, kTargetSize); |
| 5903 | ASSERT_LT(session_max_recv_window_size / 2, kTargetSize); |
| 5904 | ASSERT_LT(stream_max_recv_window_size / 2, kTargetSize); |
| 5905 | // Size of each DATA frame. |
| 5906 | const int32 kChunkSize = 4096; |
| 5907 | // Size of window updates. |
| 5908 | ASSERT_EQ(0, session_max_recv_window_size / 2 % kChunkSize); |
| 5909 | const int32 session_window_update_delta = |
| 5910 | session_max_recv_window_size / 2 + kChunkSize; |
| 5911 | ASSERT_EQ(0, stream_max_recv_window_size / 2 % kChunkSize); |
| 5912 | const int32 stream_window_update_delta = |
| 5913 | stream_max_recv_window_size / 2 + kChunkSize; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5914 | |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5915 | SettingsMap initial_settings; |
| 5916 | initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 5917 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); |
| 5918 | initial_settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
| 5919 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, stream_max_recv_window_size); |
| 5920 | scoped_ptr<SpdyFrame> initial_settings_frame( |
| 5921 | spdy_util_.ConstructSpdySettings(initial_settings)); |
| 5922 | scoped_ptr<SpdyFrame> initial_window_update( |
| 5923 | spdy_util_.ConstructSpdyWindowUpdate( |
| 5924 | kSessionFlowControlStreamId, |
| 5925 | session_max_recv_window_size - default_initial_window_size)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5926 | scoped_ptr<SpdyFrame> req( |
| 5927 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5928 | scoped_ptr<SpdyFrame> session_window_update( |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5929 | spdy_util_.ConstructSpdyWindowUpdate(0, session_window_update_delta)); |
| 5930 | scoped_ptr<SpdyFrame> stream_window_update( |
| 5931 | spdy_util_.ConstructSpdyWindowUpdate(1, stream_window_update_delta)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5932 | |
| 5933 | std::vector<MockWrite> writes; |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5934 | if ((GetParam().protocol >= kProtoSPDY4MinimumVersion) && |
| 5935 | (GetParam().protocol <= kProtoSPDY4MaximumVersion)) { |
| 5936 | writes.push_back(MockWrite(ASYNC, kHttp2ConnectionHeaderPrefix, |
| 5937 | kHttp2ConnectionHeaderPrefixSize, 0)); |
| 5938 | } |
| 5939 | writes.push_back(CreateMockWrite(*initial_settings_frame)); |
| 5940 | writes.push_back(CreateMockWrite(*initial_window_update)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5941 | writes.push_back(CreateMockWrite(*req)); |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5942 | writes.push_back(CreateMockWrite(*session_window_update)); |
| 5943 | writes.push_back(CreateMockWrite(*stream_window_update)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5944 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5945 | std::vector<MockRead> reads; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5946 | scoped_ptr<SpdyFrame> resp( |
| 5947 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5948 | reads.push_back(CreateMockRead(*resp)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5949 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5950 | ScopedVector<SpdyFrame> body_frames; |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5951 | const std::string body_data(kChunkSize, 'x'); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5952 | for (size_t remaining = kTargetSize; remaining != 0;) { |
| 5953 | size_t frame_size = std::min(remaining, body_data.size()); |
| 5954 | body_frames.push_back(spdy_util_.ConstructSpdyBodyFrame( |
| 5955 | 1, body_data.data(), frame_size, false)); |
| 5956 | reads.push_back(CreateMockRead(*body_frames.back())); |
| 5957 | remaining -= frame_size; |
| 5958 | } |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 5959 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 0)); // Yield. |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5960 | |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5961 | DelayedSocketData data(2, vector_as_array(&reads), reads.size(), |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5962 | vector_as_array(&writes), writes.size()); |
| 5963 | |
| 5964 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 5965 | BoundNetLog(), GetParam(), NULL); |
| 5966 | helper.AddData(&data); |
| 5967 | helper.RunPreTestSetup(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5968 | |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5969 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
| 5970 | SpdySessionPoolPeer pool_peer(spdy_session_pool); |
| 5971 | pool_peer.SetEnableSendingInitialData(true); |
| 5972 | pool_peer.SetSessionMaxRecvWindowSize(session_max_recv_window_size); |
| 5973 | pool_peer.SetStreamInitialRecvWindowSize(stream_max_recv_window_size); |
| 5974 | |
| 5975 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5976 | TestCompletionCallback callback; |
| 5977 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 5978 | |
| 5979 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5980 | rv = callback.WaitForResult(); |
| 5981 | EXPECT_EQ(OK, rv); |
| 5982 | |
| 5983 | SpdyHttpStream* stream = |
| 5984 | static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 5985 | ASSERT_TRUE(stream != NULL); |
| 5986 | ASSERT_TRUE(stream->stream() != NULL); |
| 5987 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5988 | // All data has been read, but not consumed. The window reflects this. |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 5989 | EXPECT_EQ(static_cast<int>(stream_max_recv_window_size - kTargetSize), |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 5990 | stream->stream()->recv_window_size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5991 | |
| 5992 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5993 | ASSERT_TRUE(response != NULL); |
| 5994 | ASSERT_TRUE(response->headers.get() != NULL); |
| 5995 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5996 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 5997 | |
| 5998 | // Issue a read which will cause a WINDOW_UPDATE to be sent and window |
| 5999 | // size increased to default. |
bnc | 301745a | 2015-03-10 03:22:16 | [diff] [blame] | 6000 | scoped_refptr<IOBuffer> buf(new IOBuffer(kTargetSize)); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 6001 | EXPECT_EQ(static_cast<int>(kTargetSize), |
| 6002 | trans->Read(buf.get(), kTargetSize, CompletionCallback())); |
bnc | 8f0f3b6 | 2015-04-08 04:37:23 | [diff] [blame] | 6003 | EXPECT_EQ(static_cast<int>(stream_max_recv_window_size), |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 6004 | stream->stream()->recv_window_size()); |
| 6005 | EXPECT_THAT(base::StringPiece(buf->data(), kTargetSize), Each(Eq('x'))); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6006 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 6007 | // Allow scheduled WINDOW_UPDATE frames to write. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 6008 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6009 | helper.VerifyDataConsumed(); |
| 6010 | } |
| 6011 | |
| 6012 | // Test that WINDOW_UPDATE frame causing overflow is handled correctly. |
| 6013 | TEST_P(SpdyNetworkTransactionTest, WindowUpdateOverflow) { |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6014 | // Number of full frames we hope to write (but will not, used to |
| 6015 | // set content-length header correctly) |
| 6016 | static int kFrameCount = 3; |
| 6017 | |
| 6018 | scoped_ptr<std::string> content( |
| 6019 | new std::string(kMaxSpdyFrameChunkSize, 'a')); |
| 6020 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6021 | GetDefaultUrl(), 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, NULL, |
| 6022 | 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6023 | scoped_ptr<SpdyFrame> body( |
| 6024 | spdy_util_.ConstructSpdyBodyFrame( |
| 6025 | 1, content->c_str(), content->size(), false)); |
| 6026 | scoped_ptr<SpdyFrame> rst( |
| 6027 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_FLOW_CONTROL_ERROR)); |
| 6028 | |
| 6029 | // We're not going to write a data frame with FIN, we'll receive a bad |
| 6030 | // WINDOW_UPDATE while sending a request and will send a RST_STREAM frame. |
| 6031 | MockWrite writes[] = { |
| 6032 | CreateMockWrite(*req, 0), |
| 6033 | CreateMockWrite(*body, 2), |
| 6034 | CreateMockWrite(*rst, 3), |
| 6035 | }; |
| 6036 | |
| 6037 | static const int32 kDeltaWindowSize = 0x7fffffff; // cause an overflow |
| 6038 | scoped_ptr<SpdyFrame> window_update( |
| 6039 | spdy_util_.ConstructSpdyWindowUpdate(1, kDeltaWindowSize)); |
| 6040 | MockRead reads[] = { |
| 6041 | CreateMockRead(*window_update, 1), |
| 6042 | MockRead(ASYNC, 0, 4) // EOF |
| 6043 | }; |
| 6044 | |
| 6045 | DeterministicSocketData data(reads, arraysize(reads), |
| 6046 | writes, arraysize(writes)); |
| 6047 | |
| 6048 | ScopedVector<UploadElementReader> element_readers; |
| 6049 | for (int i = 0; i < kFrameCount; ++i) { |
| 6050 | element_readers.push_back( |
| 6051 | new UploadBytesElementReader(content->c_str(), content->size())); |
| 6052 | } |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 6053 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6054 | |
| 6055 | // Setup the request |
| 6056 | HttpRequestInfo request; |
| 6057 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6058 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6059 | request.upload_data_stream = &upload_data_stream; |
| 6060 | |
| 6061 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 6062 | BoundNetLog(), GetParam(), NULL); |
| 6063 | helper.SetDeterministic(); |
| 6064 | helper.RunPreTestSetup(); |
| 6065 | helper.AddDeterministicData(&data); |
| 6066 | HttpNetworkTransaction* trans = helper.trans(); |
| 6067 | |
| 6068 | TestCompletionCallback callback; |
| 6069 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6070 | ASSERT_EQ(ERR_IO_PENDING, rv); |
| 6071 | |
| 6072 | data.RunFor(5); |
| 6073 | ASSERT_TRUE(callback.have_result()); |
| 6074 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, callback.WaitForResult()); |
| 6075 | helper.VerifyDataConsumed(); |
| 6076 | } |
| 6077 | |
| 6078 | // Test that after hitting a send window size of 0, the write process |
| 6079 | // stalls and upon receiving WINDOW_UPDATE frame write resumes. |
| 6080 | |
| 6081 | // This test constructs a POST request followed by enough data frames |
| 6082 | // containing 'a' that would make the window size 0, followed by another |
| 6083 | // data frame containing default content (which is "hello!") and this frame |
| 6084 | // also contains a FIN flag. DelayedSocketData is used to enforce all |
| 6085 | // writes go through before a read could happen. However, the last frame |
| 6086 | // ("hello!") is not supposed to go through since by the time its turn |
| 6087 | // arrives, window size is 0. At this point MessageLoop::Run() called via |
| 6088 | // callback would block. Therefore we call MessageLoop::RunUntilIdle() |
| 6089 | // which returns after performing all possible writes. We use DCHECKS to |
| 6090 | // ensure that last data frame is still there and stream has stalled. |
| 6091 | // After that, next read is artifically enforced, which causes a |
| 6092 | // WINDOW_UPDATE to be read and I/O process resumes. |
| 6093 | TEST_P(SpdyNetworkTransactionTest, FlowControlStallResume) { |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6094 | const int32 initial_window_size = |
bnc | 638c470 | 2015-04-09 18:01:18 | [diff] [blame] | 6095 | SpdySession::GetDefaultInitialWindowSize(GetParam().protocol); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6096 | // Number of frames we need to send to zero out the window size: data |
| 6097 | // frames plus SYN_STREAM plus the last data frame; also we need another |
| 6098 | // data frame that we will send once the WINDOW_UPDATE is received, |
| 6099 | // therefore +3. |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6100 | size_t num_writes = initial_window_size / kMaxSpdyFrameChunkSize + 3; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6101 | |
| 6102 | // Calculate last frame's size; 0 size data frame is legal. |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6103 | size_t last_frame_size = initial_window_size % kMaxSpdyFrameChunkSize; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6104 | |
| 6105 | // Construct content for a data frame of maximum size. |
| 6106 | std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 6107 | |
| 6108 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6109 | GetDefaultUrl(), 1, initial_window_size + kUploadDataSize, LOWEST, NULL, |
| 6110 | 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6111 | |
| 6112 | // Full frames. |
| 6113 | scoped_ptr<SpdyFrame> body1( |
| 6114 | spdy_util_.ConstructSpdyBodyFrame( |
| 6115 | 1, content.c_str(), content.size(), false)); |
| 6116 | |
| 6117 | // Last frame to zero out the window size. |
| 6118 | scoped_ptr<SpdyFrame> body2( |
| 6119 | spdy_util_.ConstructSpdyBodyFrame( |
| 6120 | 1, content.c_str(), last_frame_size, false)); |
| 6121 | |
| 6122 | // Data frame to be sent once WINDOW_UPDATE frame is received. |
| 6123 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6124 | |
| 6125 | // Fill in mock writes. |
| 6126 | scoped_ptr<MockWrite[]> writes(new MockWrite[num_writes]); |
| 6127 | size_t i = 0; |
| 6128 | writes[i] = CreateMockWrite(*req); |
| 6129 | for (i = 1; i < num_writes - 2; i++) |
| 6130 | writes[i] = CreateMockWrite(*body1); |
| 6131 | writes[i++] = CreateMockWrite(*body2); |
| 6132 | writes[i] = CreateMockWrite(*body3); |
| 6133 | |
| 6134 | // Construct read frame, give enough space to upload the rest of the |
| 6135 | // data. |
| 6136 | scoped_ptr<SpdyFrame> session_window_update( |
| 6137 | spdy_util_.ConstructSpdyWindowUpdate(0, kUploadDataSize)); |
| 6138 | scoped_ptr<SpdyFrame> window_update( |
| 6139 | spdy_util_.ConstructSpdyWindowUpdate(1, kUploadDataSize)); |
| 6140 | scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 6141 | MockRead reads[] = { |
| 6142 | CreateMockRead(*session_window_update), |
| 6143 | CreateMockRead(*session_window_update), |
| 6144 | CreateMockRead(*window_update), |
| 6145 | CreateMockRead(*window_update), |
| 6146 | CreateMockRead(*reply), |
| 6147 | CreateMockRead(*body2), |
| 6148 | CreateMockRead(*body3), |
| 6149 | MockRead(ASYNC, 0, 0) // EOF |
| 6150 | }; |
| 6151 | |
| 6152 | // Skip the session window updates unless we're using SPDY/3.1 and |
| 6153 | // above. |
| 6154 | size_t read_offset = (GetParam().protocol >= kProtoSPDY31) ? 0 : 2; |
| 6155 | size_t num_reads = arraysize(reads) - read_offset; |
| 6156 | |
| 6157 | // Force all writes to happen before any read, last write will not |
| 6158 | // actually queue a frame, due to window size being 0. |
| 6159 | DelayedSocketData data(num_writes, reads + read_offset, num_reads, |
| 6160 | writes.get(), num_writes); |
| 6161 | |
| 6162 | ScopedVector<UploadElementReader> element_readers; |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6163 | std::string upload_data_string(initial_window_size, 'a'); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6164 | upload_data_string.append(kUploadData, kUploadDataSize); |
| 6165 | element_readers.push_back(new UploadBytesElementReader( |
| 6166 | upload_data_string.c_str(), upload_data_string.size())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 6167 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6168 | |
| 6169 | HttpRequestInfo request; |
| 6170 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6171 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6172 | request.upload_data_stream = &upload_data_stream; |
| 6173 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 6174 | BoundNetLog(), GetParam(), NULL); |
| 6175 | helper.AddData(&data); |
| 6176 | helper.RunPreTestSetup(); |
| 6177 | |
| 6178 | HttpNetworkTransaction* trans = helper.trans(); |
| 6179 | |
| 6180 | TestCompletionCallback callback; |
| 6181 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6182 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6183 | |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 6184 | base::RunLoop().RunUntilIdle(); // Write as much as we can. |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6185 | |
| 6186 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6187 | ASSERT_TRUE(stream != NULL); |
| 6188 | ASSERT_TRUE(stream->stream() != NULL); |
| 6189 | EXPECT_EQ(0, stream->stream()->send_window_size()); |
| 6190 | // All the body data should have been read. |
| 6191 | // TODO(satorux): This is because of the weirdness in reading the request |
| 6192 | // body in OnSendBodyComplete(). See crbug.com/113107. |
| 6193 | EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 6194 | // But the body is not yet fully sent (kUploadData is not yet sent) |
| 6195 | // since we're send-stalled. |
| 6196 | EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 6197 | |
| 6198 | data.ForceNextRead(); // Read in WINDOW_UPDATE frame. |
| 6199 | rv = callback.WaitForResult(); |
| 6200 | helper.VerifyDataConsumed(); |
| 6201 | } |
| 6202 | |
| 6203 | // Test we correctly handle the case where the SETTINGS frame results in |
| 6204 | // unstalling the send window. |
| 6205 | TEST_P(SpdyNetworkTransactionTest, FlowControlStallResumeAfterSettings) { |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6206 | const int32 initial_window_size = |
bnc | 638c470 | 2015-04-09 18:01:18 | [diff] [blame] | 6207 | SpdySession::GetDefaultInitialWindowSize(GetParam().protocol); |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6208 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6209 | // Number of frames we need to send to zero out the window size: data |
| 6210 | // frames plus SYN_STREAM plus the last data frame; also we need another |
| 6211 | // data frame that we will send once the SETTING is received, therefore +3. |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6212 | size_t num_writes = initial_window_size / kMaxSpdyFrameChunkSize + 3; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6213 | |
| 6214 | // Calculate last frame's size; 0 size data frame is legal. |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6215 | size_t last_frame_size = initial_window_size % kMaxSpdyFrameChunkSize; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6216 | |
| 6217 | // Construct content for a data frame of maximum size. |
| 6218 | std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 6219 | |
| 6220 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6221 | GetDefaultUrl(), 1, initial_window_size + kUploadDataSize, LOWEST, NULL, |
| 6222 | 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6223 | |
| 6224 | // Full frames. |
| 6225 | scoped_ptr<SpdyFrame> body1( |
| 6226 | spdy_util_.ConstructSpdyBodyFrame( |
| 6227 | 1, content.c_str(), content.size(), false)); |
| 6228 | |
| 6229 | // Last frame to zero out the window size. |
| 6230 | scoped_ptr<SpdyFrame> body2( |
| 6231 | spdy_util_.ConstructSpdyBodyFrame( |
| 6232 | 1, content.c_str(), last_frame_size, false)); |
| 6233 | |
| 6234 | // Data frame to be sent once SETTINGS frame is received. |
| 6235 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6236 | |
| 6237 | // Fill in mock reads/writes. |
| 6238 | std::vector<MockRead> reads; |
| 6239 | std::vector<MockWrite> writes; |
| 6240 | size_t i = 0; |
| 6241 | writes.push_back(CreateMockWrite(*req, i++)); |
| 6242 | while (i < num_writes - 2) |
| 6243 | writes.push_back(CreateMockWrite(*body1, i++)); |
| 6244 | writes.push_back(CreateMockWrite(*body2, i++)); |
| 6245 | |
| 6246 | // Construct read frame for SETTINGS that gives enough space to upload the |
| 6247 | // rest of the data. |
| 6248 | SettingsMap settings; |
| 6249 | settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6250 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, initial_window_size * 2); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6251 | scoped_ptr<SpdyFrame> settings_frame_large( |
| 6252 | spdy_util_.ConstructSpdySettings(settings)); |
| 6253 | |
| 6254 | reads.push_back(CreateMockRead(*settings_frame_large, i++)); |
| 6255 | |
| 6256 | scoped_ptr<SpdyFrame> session_window_update( |
| 6257 | spdy_util_.ConstructSpdyWindowUpdate(0, kUploadDataSize)); |
| 6258 | if (GetParam().protocol >= kProtoSPDY31) |
| 6259 | reads.push_back(CreateMockRead(*session_window_update, i++)); |
| 6260 | |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 6261 | scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
| 6262 | writes.push_back(CreateMockWrite(*settings_ack, i++)); |
| 6263 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6264 | writes.push_back(CreateMockWrite(*body3, i++)); |
| 6265 | |
| 6266 | scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 6267 | reads.push_back(CreateMockRead(*reply, i++)); |
| 6268 | reads.push_back(CreateMockRead(*body2, i++)); |
| 6269 | reads.push_back(CreateMockRead(*body3, i++)); |
| 6270 | reads.push_back(MockRead(ASYNC, 0, i++)); // EOF |
| 6271 | |
| 6272 | // Force all writes to happen before any read, last write will not |
| 6273 | // actually queue a frame, due to window size being 0. |
| 6274 | DeterministicSocketData data(vector_as_array(&reads), reads.size(), |
| 6275 | vector_as_array(&writes), writes.size()); |
| 6276 | |
| 6277 | ScopedVector<UploadElementReader> element_readers; |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6278 | std::string upload_data_string(initial_window_size, 'a'); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6279 | upload_data_string.append(kUploadData, kUploadDataSize); |
| 6280 | element_readers.push_back(new UploadBytesElementReader( |
| 6281 | upload_data_string.c_str(), upload_data_string.size())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 6282 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6283 | |
| 6284 | HttpRequestInfo request; |
| 6285 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6286 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6287 | request.upload_data_stream = &upload_data_stream; |
| 6288 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 6289 | BoundNetLog(), GetParam(), NULL); |
| 6290 | helper.SetDeterministic(); |
| 6291 | helper.RunPreTestSetup(); |
| 6292 | helper.AddDeterministicData(&data); |
| 6293 | |
| 6294 | HttpNetworkTransaction* trans = helper.trans(); |
| 6295 | |
| 6296 | TestCompletionCallback callback; |
| 6297 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6298 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6299 | |
| 6300 | data.RunFor(num_writes - 1); // Write as much as we can. |
| 6301 | |
| 6302 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6303 | ASSERT_TRUE(stream != NULL); |
| 6304 | ASSERT_TRUE(stream->stream() != NULL); |
| 6305 | EXPECT_EQ(0, stream->stream()->send_window_size()); |
| 6306 | |
| 6307 | // All the body data should have been read. |
| 6308 | // TODO(satorux): This is because of the weirdness in reading the request |
| 6309 | // body in OnSendBodyComplete(). See crbug.com/113107. |
| 6310 | EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 6311 | // But the body is not yet fully sent (kUploadData is not yet sent) |
| 6312 | // since we're send-stalled. |
| 6313 | EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 6314 | |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 6315 | data.RunFor(7); // Read in SETTINGS frame to unstall. |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6316 | rv = callback.WaitForResult(); |
| 6317 | helper.VerifyDataConsumed(); |
| 6318 | // If stream is NULL, that means it was unstalled and closed. |
| 6319 | EXPECT_TRUE(stream->stream() == NULL); |
| 6320 | } |
| 6321 | |
| 6322 | // Test we correctly handle the case where the SETTINGS frame results in a |
| 6323 | // negative send window size. |
| 6324 | TEST_P(SpdyNetworkTransactionTest, FlowControlNegativeSendWindowSize) { |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6325 | const int32 initial_window_size = |
bnc | 638c470 | 2015-04-09 18:01:18 | [diff] [blame] | 6326 | SpdySession::GetDefaultInitialWindowSize(GetParam().protocol); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6327 | // Number of frames we need to send to zero out the window size: data |
| 6328 | // frames plus SYN_STREAM plus the last data frame; also we need another |
| 6329 | // data frame that we will send once the SETTING is received, therefore +3. |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6330 | size_t num_writes = initial_window_size / kMaxSpdyFrameChunkSize + 3; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6331 | |
| 6332 | // Calculate last frame's size; 0 size data frame is legal. |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6333 | size_t last_frame_size = initial_window_size % kMaxSpdyFrameChunkSize; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6334 | |
| 6335 | // Construct content for a data frame of maximum size. |
| 6336 | std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 6337 | |
| 6338 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6339 | GetDefaultUrl(), 1, initial_window_size + kUploadDataSize, LOWEST, NULL, |
| 6340 | 0)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6341 | |
| 6342 | // Full frames. |
| 6343 | scoped_ptr<SpdyFrame> body1( |
| 6344 | spdy_util_.ConstructSpdyBodyFrame( |
| 6345 | 1, content.c_str(), content.size(), false)); |
| 6346 | |
| 6347 | // Last frame to zero out the window size. |
| 6348 | scoped_ptr<SpdyFrame> body2( |
| 6349 | spdy_util_.ConstructSpdyBodyFrame( |
| 6350 | 1, content.c_str(), last_frame_size, false)); |
| 6351 | |
| 6352 | // Data frame to be sent once SETTINGS frame is received. |
| 6353 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6354 | |
| 6355 | // Fill in mock reads/writes. |
| 6356 | std::vector<MockRead> reads; |
| 6357 | std::vector<MockWrite> writes; |
| 6358 | size_t i = 0; |
| 6359 | writes.push_back(CreateMockWrite(*req, i++)); |
| 6360 | while (i < num_writes - 2) |
| 6361 | writes.push_back(CreateMockWrite(*body1, i++)); |
| 6362 | writes.push_back(CreateMockWrite(*body2, i++)); |
| 6363 | |
| 6364 | // Construct read frame for SETTINGS that makes the send_window_size |
| 6365 | // negative. |
| 6366 | SettingsMap new_settings; |
| 6367 | new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6368 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, initial_window_size / 2); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6369 | scoped_ptr<SpdyFrame> settings_frame_small( |
| 6370 | spdy_util_.ConstructSpdySettings(new_settings)); |
| 6371 | // Construct read frames for WINDOW_UPDATE that makes the send_window_size |
| 6372 | // positive. |
| 6373 | scoped_ptr<SpdyFrame> session_window_update_init_size( |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6374 | spdy_util_.ConstructSpdyWindowUpdate(0, initial_window_size)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6375 | scoped_ptr<SpdyFrame> window_update_init_size( |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6376 | spdy_util_.ConstructSpdyWindowUpdate(1, initial_window_size)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6377 | |
| 6378 | reads.push_back(CreateMockRead(*settings_frame_small, i++)); |
bnc | 33b8cef4 | 2014-11-19 17:30:38 | [diff] [blame] | 6379 | reads.push_back(CreateMockRead(*session_window_update_init_size, i++)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6380 | reads.push_back(CreateMockRead(*window_update_init_size, i++)); |
| 6381 | |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 6382 | scoped_ptr<SpdyFrame> settings_ack(spdy_util_.ConstructSpdySettingsAck()); |
| 6383 | writes.push_back(CreateMockWrite(*settings_ack, i++)); |
| 6384 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6385 | writes.push_back(CreateMockWrite(*body3, i++)); |
| 6386 | |
| 6387 | scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 6388 | reads.push_back(CreateMockRead(*reply, i++)); |
| 6389 | reads.push_back(CreateMockRead(*body2, i++)); |
| 6390 | reads.push_back(CreateMockRead(*body3, i++)); |
| 6391 | reads.push_back(MockRead(ASYNC, 0, i++)); // EOF |
| 6392 | |
| 6393 | // Force all writes to happen before any read, last write will not |
| 6394 | // actually queue a frame, due to window size being 0. |
| 6395 | DeterministicSocketData data(vector_as_array(&reads), reads.size(), |
| 6396 | vector_as_array(&writes), writes.size()); |
| 6397 | |
| 6398 | ScopedVector<UploadElementReader> element_readers; |
bnc | 2f54c83 | 2014-12-01 13:31:19 | [diff] [blame] | 6399 | std::string upload_data_string(initial_window_size, 'a'); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6400 | upload_data_string.append(kUploadData, kUploadDataSize); |
| 6401 | element_readers.push_back(new UploadBytesElementReader( |
| 6402 | upload_data_string.c_str(), upload_data_string.size())); |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 6403 | ElementsUploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6404 | |
| 6405 | HttpRequestInfo request; |
| 6406 | request.method = "POST"; |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6407 | request.url = GURL(GetDefaultUrl()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6408 | request.upload_data_stream = &upload_data_stream; |
| 6409 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 6410 | BoundNetLog(), GetParam(), NULL); |
| 6411 | helper.SetDeterministic(); |
| 6412 | helper.RunPreTestSetup(); |
| 6413 | helper.AddDeterministicData(&data); |
| 6414 | |
| 6415 | HttpNetworkTransaction* trans = helper.trans(); |
| 6416 | |
| 6417 | TestCompletionCallback callback; |
| 6418 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6419 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6420 | |
| 6421 | data.RunFor(num_writes - 1); // Write as much as we can. |
| 6422 | |
| 6423 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6424 | ASSERT_TRUE(stream != NULL); |
| 6425 | ASSERT_TRUE(stream->stream() != NULL); |
| 6426 | EXPECT_EQ(0, stream->stream()->send_window_size()); |
| 6427 | |
| 6428 | // All the body data should have been read. |
| 6429 | // TODO(satorux): This is because of the weirdness in reading the request |
| 6430 | // body in OnSendBodyComplete(). See crbug.com/113107. |
| 6431 | EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 6432 | // But the body is not yet fully sent (kUploadData is not yet sent) |
| 6433 | // since we're send-stalled. |
| 6434 | EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 6435 | |
| 6436 | // Read in WINDOW_UPDATE or SETTINGS frame. |
[email protected] | d4a77c1 | 2014-05-15 20:45:21 | [diff] [blame] | 6437 | data.RunFor((GetParam().protocol >= kProtoSPDY31) ? 9 : 8); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6438 | rv = callback.WaitForResult(); |
| 6439 | helper.VerifyDataConsumed(); |
| 6440 | } |
| 6441 | |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6442 | TEST_P(SpdyNetworkTransactionTest, GoAwayOnOddPushStreamId) { |
| 6443 | if (spdy_util_.spdy_version() < SPDY3) |
| 6444 | return; |
| 6445 | |
| 6446 | scoped_ptr<SpdyHeaderBlock> push_headers(new SpdyHeaderBlock); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6447 | spdy_util_.AddUrlToHeaderBlock("http://www.example.org/a.dat", |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6448 | push_headers.get()); |
| 6449 | scoped_ptr<SpdyFrame> push( |
| 6450 | spdy_util_.ConstructInitialSpdyPushFrame(push_headers.Pass(), 3, 1)); |
| 6451 | MockRead reads[] = {CreateMockRead(*push, 1)}; |
| 6452 | |
| 6453 | scoped_ptr<SpdyFrame> req( |
| 6454 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 6455 | scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 6456 | 0, GOAWAY_PROTOCOL_ERROR, "Odd push stream id.")); |
| 6457 | MockWrite writes[] = { |
| 6458 | CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2), |
| 6459 | }; |
| 6460 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 6461 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6462 | NormalSpdyTransactionHelper helper( |
| 6463 | CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 6464 | helper.RunToCompletion(&data); |
| 6465 | TransactionHelperResult out = helper.output(); |
| 6466 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 6467 | } |
| 6468 | |
| 6469 | TEST_P(SpdyNetworkTransactionTest, |
| 6470 | GoAwayOnPushStreamIdLesserOrEqualThanLastAccepted) { |
| 6471 | if (spdy_util_.spdy_version() < SPDY3) |
| 6472 | return; |
| 6473 | |
| 6474 | scoped_ptr<SpdyFrame> push_a(spdy_util_.ConstructSpdyPush( |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6475 | NULL, 0, 4, 1, GetDefaultUrlWithPath("/a.dat").c_str())); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6476 | scoped_ptr<SpdyHeaderBlock> push_b_headers(new SpdyHeaderBlock); |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6477 | spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/b.dat"), |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6478 | push_b_headers.get()); |
| 6479 | scoped_ptr<SpdyFrame> push_b( |
| 6480 | spdy_util_.ConstructInitialSpdyPushFrame(push_b_headers.Pass(), 2, 1)); |
| 6481 | MockRead reads[] = { |
| 6482 | CreateMockRead(*push_a, 1), CreateMockRead(*push_b, 2), |
| 6483 | }; |
| 6484 | |
| 6485 | scoped_ptr<SpdyFrame> req( |
| 6486 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 6487 | scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 6488 | 4, |
| 6489 | GOAWAY_PROTOCOL_ERROR, |
| 6490 | "New push stream id must be greater than the last accepted.")); |
| 6491 | MockWrite writes[] = { |
| 6492 | CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 3), |
| 6493 | }; |
| 6494 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 6495 | SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
baranovich | 212a129 | 2014-09-02 21:45:31 | [diff] [blame] | 6496 | NormalSpdyTransactionHelper helper( |
| 6497 | CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 6498 | helper.RunToCompletion(&data); |
| 6499 | TransactionHelperResult out = helper.output(); |
| 6500 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 6501 | } |
| 6502 | |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6503 | class SpdyNetworkTransactionNoTLSUsageCheckTest |
| 6504 | : public SpdyNetworkTransactionTest { |
| 6505 | protected: |
| 6506 | void RunNoTLSUsageCheckTest(scoped_ptr<SSLSocketDataProvider> ssl_provider) { |
| 6507 | // Construct the request. |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6508 | scoped_ptr<SpdyFrame> req( |
| 6509 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 6510 | MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6511 | |
| 6512 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 6513 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6514 | MockRead reads[] = { |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 6515 | CreateMockRead(*resp, 1), |
| 6516 | CreateMockRead(*body, 2), |
| 6517 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6518 | }; |
| 6519 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 6520 | SequencedSocketData data(reads, arraysize(reads), writes, |
| 6521 | arraysize(writes)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6522 | HttpRequestInfo request; |
| 6523 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6524 | request.url = GURL("https://www.example.org/"); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6525 | NormalSpdyTransactionHelper helper( |
| 6526 | request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 6527 | helper.RunToCompletionWithSSLData(&data, ssl_provider.Pass()); |
| 6528 | TransactionHelperResult out = helper.output(); |
| 6529 | EXPECT_EQ(OK, out.rv); |
| 6530 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 6531 | EXPECT_EQ("hello!", out.response_data); |
| 6532 | } |
| 6533 | }; |
| 6534 | |
| 6535 | //----------------------------------------------------------------------------- |
| 6536 | // All tests are run with three different connection types: SPDY after NPN |
| 6537 | // negotiation, SPDY without SSL, and SPDY with SSL. |
| 6538 | // |
| 6539 | // TODO(akalin): Use ::testing::Combine() when we are able to use |
| 6540 | // <tr1/tuple>. |
| 6541 | INSTANTIATE_TEST_CASE_P( |
| 6542 | Spdy, |
| 6543 | SpdyNetworkTransactionNoTLSUsageCheckTest, |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6544 | ::testing::Values(SpdyNetworkTransactionTestParams(kProtoSPDY31, |
| 6545 | HTTPS_SPDY_VIA_NPN))); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6546 | |
| 6547 | TEST_P(SpdyNetworkTransactionNoTLSUsageCheckTest, TLSVersionTooOld) { |
| 6548 | scoped_ptr<SSLSocketDataProvider> ssl_provider( |
| 6549 | new SSLSocketDataProvider(ASYNC, OK)); |
| 6550 | SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_SSL3, |
| 6551 | &ssl_provider->connection_status); |
| 6552 | |
| 6553 | RunNoTLSUsageCheckTest(ssl_provider.Pass()); |
| 6554 | } |
| 6555 | |
| 6556 | TEST_P(SpdyNetworkTransactionNoTLSUsageCheckTest, TLSCipherSuiteSucky) { |
| 6557 | scoped_ptr<SSLSocketDataProvider> ssl_provider( |
| 6558 | new SSLSocketDataProvider(ASYNC, OK)); |
| 6559 | // Set to TLS_RSA_WITH_NULL_MD5 |
| 6560 | SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); |
| 6561 | |
| 6562 | RunNoTLSUsageCheckTest(ssl_provider.Pass()); |
| 6563 | } |
| 6564 | |
| 6565 | class SpdyNetworkTransactionTLSUsageCheckTest |
| 6566 | : public SpdyNetworkTransactionTest { |
| 6567 | protected: |
| 6568 | void RunTLSUsageCheckTest(scoped_ptr<SSLSocketDataProvider> ssl_provider) { |
[email protected] | bdd1b22 | 2014-06-10 11:08:39 | [diff] [blame] | 6569 | scoped_ptr<SpdyFrame> goaway( |
| 6570 | spdy_util_.ConstructSpdyGoAway(0, GOAWAY_INADEQUATE_SECURITY, "")); |
| 6571 | MockWrite writes[] = {CreateMockWrite(*goaway)}; |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6572 | |
rch | 73e1742 | 2015-05-04 19:52:06 | [diff] [blame] | 6573 | StaticSocketDataProvider data(NULL, 0, writes, arraysize(writes)); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6574 | HttpRequestInfo request; |
| 6575 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6576 | request.url = GURL("https://www.example.org/"); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6577 | NormalSpdyTransactionHelper helper( |
| 6578 | request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 6579 | helper.RunToCompletionWithSSLData(&data, ssl_provider.Pass()); |
| 6580 | TransactionHelperResult out = helper.output(); |
| 6581 | EXPECT_EQ(ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY, out.rv); |
| 6582 | } |
| 6583 | }; |
| 6584 | |
| 6585 | INSTANTIATE_TEST_CASE_P( |
| 6586 | Spdy, |
| 6587 | SpdyNetworkTransactionTLSUsageCheckTest, |
rch | ebf1298 | 2015-04-10 01:15:00 | [diff] [blame] | 6588 | ::testing::Values( |
| 6589 | SpdyNetworkTransactionTestParams(kProtoSPDY4_14, HTTPS_SPDY_VIA_NPN), |
| 6590 | SpdyNetworkTransactionTestParams(kProtoSPDY4, HTTPS_SPDY_VIA_NPN))); |
[email protected] | 514aeaf | 2014-05-23 10:31:51 | [diff] [blame] | 6591 | |
| 6592 | TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSVersionTooOld) { |
| 6593 | scoped_ptr<SSLSocketDataProvider> ssl_provider( |
| 6594 | new SSLSocketDataProvider(ASYNC, OK)); |
| 6595 | SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_SSL3, |
| 6596 | &ssl_provider->connection_status); |
| 6597 | |
| 6598 | RunTLSUsageCheckTest(ssl_provider.Pass()); |
| 6599 | } |
| 6600 | |
| 6601 | TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { |
| 6602 | scoped_ptr<SSLSocketDataProvider> ssl_provider( |
| 6603 | new SSLSocketDataProvider(ASYNC, OK)); |
| 6604 | // Set to TLS_RSA_WITH_NULL_MD5 |
| 6605 | SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); |
| 6606 | |
| 6607 | RunTLSUsageCheckTest(ssl_provider.Pass()); |
| 6608 | } |
| 6609 | |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 6610 | } // namespace net |