[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" |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 10 | #include "base/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" |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 18 | #include "net/base/net_log_unittest.h" |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 19 | #include "net/base/request_priority.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 20 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | 9fa94db | 2012-10-22 03:34:07 | [diff] [blame] | 21 | #include "net/base/upload_data_stream.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 22 | #include "net/base/upload_file_element_reader.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 23 | #include "net/http/http_network_session_peer.h" |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 24 | #include "net/http/http_network_transaction.h" |
| 25 | #include "net/http/http_server_properties.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame^] | 26 | #include "net/http/http_transaction_test_util.h" |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 27 | #include "net/socket/client_socket_pool_base.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 28 | #include "net/socket/next_proto.h" |
[email protected] | f54c8579 | 2012-03-08 19:06:41 | [diff] [blame] | 29 | #include "net/spdy/buffered_spdy_framer.h" |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 30 | #include "net/spdy/spdy_http_stream.h" |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 31 | #include "net/spdy/spdy_http_utils.h" |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 32 | #include "net/spdy/spdy_session.h" |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 33 | #include "net/spdy/spdy_session_pool.h" |
[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 34 | #include "net/spdy/spdy_test_util_common.h" |
[email protected] | a4bfdf7 | 2013-02-22 04:06:16 | [diff] [blame] | 35 | #include "net/spdy/spdy_test_utils.h" |
[email protected] | d2db029 | 2011-01-26 20:23:44 | [diff] [blame] | 36 | #include "net/url_request/url_request_test_util.h" |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 37 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 38 | #include "testing/platform_test.h" |
| 39 | |
| 40 | //----------------------------------------------------------------------------- |
| 41 | |
[email protected] | d1eda93 | 2009-11-04 01:03:10 | [diff] [blame] | 42 | namespace net { |
[email protected] | dae22c5 | 2010-07-30 02:16:35 | [diff] [blame] | 43 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 44 | namespace { |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 45 | |
| 46 | using testing::Each; |
| 47 | using testing::Eq; |
| 48 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 49 | const char kRequestUrl[] = "http://www.google.com/"; |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 50 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 51 | enum SpdyNetworkTransactionTestSSLType { |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 52 | SPDYNPN, |
| 53 | SPDYNOSSL, |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 54 | SPDYSSL, |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 55 | }; |
[email protected] | ca6459f86 | 2012-04-11 19:43:20 | [diff] [blame] | 56 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 57 | struct SpdyNetworkTransactionTestParams { |
| 58 | SpdyNetworkTransactionTestParams() |
[email protected] | b05bcaa3 | 2013-10-06 05:26:02 | [diff] [blame] | 59 | : protocol(kProtoSPDY3), |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 60 | ssl_type(SPDYNPN) {} |
| 61 | |
| 62 | SpdyNetworkTransactionTestParams( |
| 63 | NextProto protocol, |
| 64 | SpdyNetworkTransactionTestSSLType ssl_type) |
| 65 | : protocol(protocol), |
| 66 | ssl_type(ssl_type) {} |
| 67 | |
| 68 | NextProto protocol; |
| 69 | SpdyNetworkTransactionTestSSLType ssl_type; |
| 70 | }; |
| 71 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 72 | SpdySessionDependencies* CreateSpdySessionDependencies( |
| 73 | SpdyNetworkTransactionTestParams test_params) { |
| 74 | return new SpdySessionDependencies(test_params.protocol); |
| 75 | } |
| 76 | |
| 77 | SpdySessionDependencies* CreateSpdySessionDependencies( |
| 78 | SpdyNetworkTransactionTestParams test_params, |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 79 | ProxyService* proxy_service) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 80 | return new SpdySessionDependencies(test_params.protocol, proxy_service); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 81 | } |
| 82 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 83 | } // namespace |
| 84 | |
| 85 | class SpdyNetworkTransactionTest |
| 86 | : public ::testing::TestWithParam<SpdyNetworkTransactionTestParams> { |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 87 | protected: |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 88 | SpdyNetworkTransactionTest() : spdy_util_(GetParam().protocol) { |
[email protected] | d45f9bd | 2014-01-15 18:47:28 | [diff] [blame] | 89 | LOG(INFO) << __FUNCTION__; |
[email protected] | 9ec54f8 | 2013-05-10 02:53:05 | [diff] [blame] | 90 | } |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 91 | |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 92 | virtual ~SpdyNetworkTransactionTest() { |
[email protected] | d45f9bd | 2014-01-15 18:47:28 | [diff] [blame] | 93 | LOG(INFO) << __FUNCTION__; |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 94 | // UploadDataStream posts deletion tasks back to the message loop on |
| 95 | // destruction. |
| 96 | upload_data_stream_.reset(); |
| 97 | base::RunLoop().RunUntilIdle(); |
[email protected] | d45f9bd | 2014-01-15 18:47:28 | [diff] [blame] | 98 | LOG(INFO) << __FUNCTION__; |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 99 | } |
| 100 | |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 101 | virtual void SetUp() { |
[email protected] | d45f9bd | 2014-01-15 18:47:28 | [diff] [blame] | 102 | LOG(INFO) << __FUNCTION__; |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 103 | google_get_request_initialized_ = false; |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 104 | google_post_request_initialized_ = false; |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 105 | google_chunked_post_request_initialized_ = false; |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 106 | ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
[email protected] | d45f9bd | 2014-01-15 18:47:28 | [diff] [blame] | 107 | LOG(INFO) << __FUNCTION__; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 108 | } |
| 109 | |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 110 | struct TransactionHelperResult { |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 111 | int rv; |
| 112 | std::string status_line; |
| 113 | std::string response_data; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 114 | HttpResponseInfo response_info; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 115 | }; |
| 116 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 117 | // A helper class that handles all the initial npn/ssl setup. |
| 118 | class NormalSpdyTransactionHelper { |
| 119 | public: |
| 120 | NormalSpdyTransactionHelper(const HttpRequestInfo& request, |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 121 | RequestPriority priority, |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 122 | const BoundNetLog& log, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 123 | SpdyNetworkTransactionTestParams test_params, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 124 | SpdySessionDependencies* session_deps) |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 125 | : request_(request), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 126 | priority_(priority), |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 127 | session_deps_(session_deps == NULL ? |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 128 | CreateSpdySessionDependencies(test_params) : |
| 129 | session_deps), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 130 | session_(SpdySessionDependencies::SpdyCreateSession( |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 131 | session_deps_.get())), |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 132 | log_(log), |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 133 | test_params_(test_params), |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 134 | deterministic_(false), |
| 135 | spdy_enabled_(true) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 136 | switch (test_params_.ssl_type) { |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 137 | case SPDYNOSSL: |
| 138 | case SPDYSSL: |
| 139 | port_ = 80; |
| 140 | break; |
| 141 | case SPDYNPN: |
| 142 | port_ = 443; |
| 143 | break; |
| 144 | default: |
| 145 | NOTREACHED(); |
| 146 | } |
[email protected] | e37ce37 | 2012-07-12 01:00:40 | [diff] [blame] | 147 | } |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 148 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 149 | ~NormalSpdyTransactionHelper() { |
| 150 | // Any test which doesn't close the socket by sending it an EOF will |
| 151 | // have a valid session left open, which leaks the entire session pool. |
| 152 | // This is just fine - in fact, some of our tests intentionally do this |
| 153 | // so that we can check consistency of the SpdySessionPool as the test |
| 154 | // finishes. If we had put an EOF on the socket, the SpdySession would |
| 155 | // have closed and we wouldn't be able to check the consistency. |
| 156 | |
| 157 | // Forcefully close existing sessions here. |
| 158 | session()->spdy_session_pool()->CloseAllSessions(); |
| 159 | } |
| 160 | |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 161 | void SetDeterministic() { |
| 162 | session_ = SpdySessionDependencies::SpdyCreateSessionDeterministic( |
| 163 | session_deps_.get()); |
| 164 | deterministic_ = true; |
| 165 | } |
| 166 | |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 167 | void SetSpdyDisabled() { |
| 168 | spdy_enabled_ = false; |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 169 | port_ = 80; |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 170 | } |
| 171 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 172 | void RunPreTestSetup() { |
[email protected] | d45f9bd | 2014-01-15 18:47:28 | [diff] [blame] | 173 | LOG(INFO) << __FUNCTION__; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 174 | if (!session_deps_.get()) |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 175 | session_deps_.reset(CreateSpdySessionDependencies(test_params_)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 176 | if (!session_.get()) |
| 177 | session_ = SpdySessionDependencies::SpdyCreateSession( |
| 178 | session_deps_.get()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 179 | HttpStreamFactory::set_use_alternate_protocols(false); |
| 180 | HttpStreamFactory::set_force_spdy_over_ssl(false); |
| 181 | HttpStreamFactory::set_force_spdy_always(false); |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 182 | |
[email protected] | 0ce3af8 | 2013-07-22 16:17:16 | [diff] [blame] | 183 | std::vector<NextProto> next_protos = SpdyNextProtos(); |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 184 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 185 | switch (test_params_.ssl_type) { |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 186 | case SPDYNPN: |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 187 | session_->http_server_properties()->SetAlternateProtocol( |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 188 | HostPortPair("www.google.com", 80), 443, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 189 | AlternateProtocolFromNextProto(test_params_.protocol)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 190 | HttpStreamFactory::set_use_alternate_protocols(true); |
[email protected] | ecf96e5 | 2012-03-03 00:43:03 | [diff] [blame] | 191 | HttpStreamFactory::SetNextProtos(next_protos); |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 192 | break; |
| 193 | case SPDYNOSSL: |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 194 | HttpStreamFactory::set_force_spdy_over_ssl(false); |
| 195 | HttpStreamFactory::set_force_spdy_always(true); |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 196 | break; |
| 197 | case SPDYSSL: |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 198 | HttpStreamFactory::set_force_spdy_over_ssl(true); |
| 199 | HttpStreamFactory::set_force_spdy_always(true); |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 200 | break; |
| 201 | default: |
| 202 | NOTREACHED(); |
[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] | d45f9bd | 2014-01-15 18:47:28 | [diff] [blame] | 207 | LOG(INFO) << __FUNCTION__; |
[email protected] | cb54b3b2 | 2010-06-03 16:28:55 | [diff] [blame] | 208 | } |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 209 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 210 | // Start the transaction, read some data, finish. |
| 211 | void RunDefaultTest() { |
[email protected] | d45f9bd | 2014-01-15 18:47:28 | [diff] [blame] | 212 | LOG(INFO) << __FUNCTION__; |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 213 | if (!StartDefaultTest()) |
| 214 | return; |
| 215 | FinishDefaultTest(); |
[email protected] | d45f9bd | 2014-01-15 18:47:28 | [diff] [blame] | 216 | LOG(INFO) << __FUNCTION__; |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | bool StartDefaultTest() { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 220 | output_.rv = trans_->Start(&request_, callback.callback(), log_); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 221 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 222 | // We expect an IO Pending or some sort of error. |
| 223 | EXPECT_LT(output_.rv, 0); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 224 | return output_.rv == ERR_IO_PENDING; |
| 225 | } |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 226 | |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 227 | void FinishDefaultTest() { |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 228 | output_.rv = callback.WaitForResult(); |
| 229 | if (output_.rv != OK) { |
[email protected] | 7af985a | 2012-12-14 22:40:42 | [diff] [blame] | 230 | session_->spdy_session_pool()->CloseCurrentSessions(net::ERR_ABORTED); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 231 | return; |
| 232 | } |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 233 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 234 | // Verify responses. |
| 235 | const HttpResponseInfo* response = trans_->GetResponseInfo(); |
| 236 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 237 | ASSERT_TRUE(response->headers.get() != NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 238 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 239 | EXPECT_EQ(spdy_enabled_, response->was_fetched_via_spdy); |
[email protected] | 808957c | 2013-03-13 03:51:27 | [diff] [blame] | 240 | if (HttpStreamFactory::spdy_enabled()) { |
[email protected] | 88a33262 | 2013-07-30 07:13:32 | [diff] [blame] | 241 | EXPECT_EQ( |
| 242 | HttpResponseInfo::ConnectionInfoFromNextProto( |
| 243 | test_params_.protocol), |
| 244 | response->connection_info); |
[email protected] | 808957c | 2013-03-13 03:51:27 | [diff] [blame] | 245 | } else { |
| 246 | EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, |
| 247 | response->connection_info); |
| 248 | } |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 249 | if (test_params_.ssl_type == SPDYNPN && spdy_enabled_) { |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 250 | EXPECT_TRUE(response->was_npn_negotiated); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 251 | } else { |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 252 | EXPECT_TRUE(!response->was_npn_negotiated); |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 253 | } |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 254 | // If SPDY is not enabled, a HTTP request should not be diverted |
| 255 | // over a SSL session. |
| 256 | if (!spdy_enabled_) { |
| 257 | EXPECT_EQ(request_.url.SchemeIs("https"), |
| 258 | response->was_npn_negotiated); |
| 259 | } |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 260 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 261 | EXPECT_EQ(port_, response->socket_address.port()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 262 | output_.status_line = response->headers->GetStatusLine(); |
| 263 | output_.response_info = *response; // Make a copy so we can verify. |
| 264 | output_.rv = ReadTransaction(trans_.get(), &output_.response_data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 265 | } |
| 266 | |
| 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() { |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 271 | for (DataVector::iterator it = data_vector_.begin(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 272 | it != data_vector_.end(); ++it) { |
| 273 | EXPECT_TRUE((*it)->at_read_eof()) << "Read count: " |
| 274 | << (*it)->read_count() |
| 275 | << " Read index: " |
| 276 | << (*it)->read_index(); |
| 277 | EXPECT_TRUE((*it)->at_write_eof()) << "Write count: " |
| 278 | << (*it)->write_count() |
| 279 | << " Write index: " |
| 280 | << (*it)->write_index(); |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | // Occasionally a test will expect to error out before certain reads are |
| 285 | // processed. In that case we want to explicitly ensure that the reads were |
| 286 | // not processed. |
| 287 | void VerifyDataNotConsumed() { |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 288 | for (DataVector::iterator it = data_vector_.begin(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 289 | it != data_vector_.end(); ++it) { |
| 290 | EXPECT_TRUE(!(*it)->at_read_eof()) << "Read count: " |
| 291 | << (*it)->read_count() |
| 292 | << " Read index: " |
| 293 | << (*it)->read_index(); |
| 294 | EXPECT_TRUE(!(*it)->at_write_eof()) << "Write count: " |
| 295 | << (*it)->write_count() |
| 296 | << " Write index: " |
| 297 | << (*it)->write_index(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
| 301 | void RunToCompletion(StaticSocketDataProvider* data) { |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 302 | RunPreTestSetup(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 303 | AddData(data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 304 | RunDefaultTest(); |
| 305 | VerifyDataConsumed(); |
| 306 | } |
[email protected] | e6b0686 | 2010-07-20 16:32:58 | [diff] [blame] | 307 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 308 | void AddData(StaticSocketDataProvider* data) { |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 309 | DCHECK(!deterministic_); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 310 | data_vector_.push_back(data); |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 311 | SSLSocketDataProvider* ssl_provider = |
| 312 | new SSLSocketDataProvider(ASYNC, OK); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 313 | if (test_params_.ssl_type == SPDYNPN) |
| 314 | ssl_provider->SetNextProto(test_params_.protocol); |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 315 | |
| 316 | ssl_vector_.push_back(ssl_provider); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 317 | if (test_params_.ssl_type == SPDYNPN || test_params_.ssl_type == SPDYSSL) |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 318 | session_deps_->socket_factory->AddSSLSocketDataProvider(ssl_provider); |
| 319 | |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 320 | session_deps_->socket_factory->AddSocketDataProvider(data); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 321 | if (test_params_.ssl_type == SPDYNPN) { |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 322 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 323 | StaticSocketDataProvider* hanging_non_alternate_protocol_socket = |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 324 | new StaticSocketDataProvider(NULL, 0, NULL, 0); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 325 | hanging_non_alternate_protocol_socket->set_connect_data( |
| 326 | never_finishing_connect); |
| 327 | session_deps_->socket_factory->AddSocketDataProvider( |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 328 | hanging_non_alternate_protocol_socket); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 329 | alternate_vector_.push_back(hanging_non_alternate_protocol_socket); |
| 330 | } |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | void AddDeterministicData(DeterministicSocketData* data) { |
| 334 | DCHECK(deterministic_); |
| 335 | data_vector_.push_back(data); |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 336 | SSLSocketDataProvider* ssl_provider = |
| 337 | new SSLSocketDataProvider(ASYNC, OK); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 338 | if (test_params_.ssl_type == SPDYNPN) |
| 339 | ssl_provider->SetNextProto(test_params_.protocol); |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 340 | |
| 341 | ssl_vector_.push_back(ssl_provider); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 342 | if (test_params_.ssl_type == SPDYNPN || |
| 343 | test_params_.ssl_type == SPDYSSL) { |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 344 | session_deps_->deterministic_socket_factory-> |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 345 | AddSSLSocketDataProvider(ssl_provider); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 346 | } |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 347 | session_deps_->deterministic_socket_factory->AddSocketDataProvider(data); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 348 | if (test_params_.ssl_type == SPDYNPN) { |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 349 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 350 | DeterministicSocketData* hanging_non_alternate_protocol_socket = |
| 351 | new DeterministicSocketData(NULL, 0, NULL, 0); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 352 | hanging_non_alternate_protocol_socket->set_connect_data( |
| 353 | never_finishing_connect); |
| 354 | session_deps_->deterministic_socket_factory->AddSocketDataProvider( |
| 355 | hanging_non_alternate_protocol_socket); |
| 356 | alternate_deterministic_vector_.push_back( |
| 357 | hanging_non_alternate_protocol_socket); |
| 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: |
| 380 | typedef std::vector<StaticSocketDataProvider*> DataVector; |
[email protected] | d4f0022 | 2012-07-10 06:24:51 | [diff] [blame] | 381 | typedef ScopedVector<SSLSocketDataProvider> SSLVector; |
| 382 | typedef ScopedVector<StaticSocketDataProvider> AlternateVector; |
| 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_; |
| 389 | scoped_ptr<StaticSocketDataProvider> first_transaction_; |
| 390 | SSLVector ssl_vector_; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [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_; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [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() { |
| 410 | google_get_push_request_.method = "GET"; |
| 411 | google_get_push_request_.url = GURL("http://www.google.com/foo.dat"); |
| 412 | google_get_push_request_.load_flags = 0; |
| 413 | return google_get_push_request_; |
| 414 | } |
| 415 | |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 416 | const HttpRequestInfo& CreateGetRequest() { |
| 417 | if (!google_get_request_initialized_) { |
| 418 | google_get_request_.method = "GET"; |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 419 | google_get_request_.url = GURL(kDefaultURL); |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 420 | google_get_request_.load_flags = 0; |
| 421 | google_get_request_initialized_ = true; |
| 422 | } |
| 423 | return google_get_request_; |
| 424 | } |
| 425 | |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 426 | const HttpRequestInfo& CreateGetRequestWithUserAgent() { |
| 427 | if (!google_get_request_initialized_) { |
| 428 | google_get_request_.method = "GET"; |
| 429 | google_get_request_.url = GURL(kDefaultURL); |
| 430 | google_get_request_.load_flags = 0; |
| 431 | google_get_request_.extra_headers.SetHeader("User-Agent", "Chrome"); |
| 432 | google_get_request_initialized_ = true; |
| 433 | } |
| 434 | return google_get_request_; |
| 435 | } |
| 436 | |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 437 | const HttpRequestInfo& CreatePostRequest() { |
| 438 | if (!google_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( |
| 443 | new UploadDataStream(element_readers.Pass(), 0)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 444 | |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 445 | google_post_request_.method = "POST"; |
| 446 | google_post_request_.url = GURL(kDefaultURL); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 447 | google_post_request_.upload_data_stream = upload_data_stream_.get(); |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 448 | google_post_request_initialized_ = true; |
| 449 | } |
| 450 | return google_post_request_; |
| 451 | } |
| 452 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 453 | const HttpRequestInfo& CreateFilePostRequest() { |
| 454 | if (!google_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( |
| 468 | new UploadDataStream(element_readers.Pass(), 0)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 469 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 470 | google_post_request_.method = "POST"; |
| 471 | google_post_request_.url = GURL(kDefaultURL); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 472 | google_post_request_.upload_data_stream = upload_data_stream_.get(); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 473 | google_post_request_initialized_ = true; |
| 474 | } |
| 475 | return google_post_request_; |
| 476 | } |
| 477 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 478 | const HttpRequestInfo& CreateUnreadableFilePostRequest() { |
| 479 | if (google_post_request_initialized_) |
| 480 | return google_post_request_; |
| 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] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 486 | CHECK(file_util::MakeFileUnreadable(file_path)); |
| 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( |
| 496 | new UploadDataStream(element_readers.Pass(), 0)); |
| 497 | |
| 498 | google_post_request_.method = "POST"; |
| 499 | google_post_request_.url = GURL(kDefaultURL); |
| 500 | google_post_request_.upload_data_stream = upload_data_stream_.get(); |
| 501 | google_post_request_initialized_ = true; |
| 502 | return google_post_request_; |
| 503 | } |
| 504 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 505 | const HttpRequestInfo& CreateComplexPostRequest() { |
| 506 | if (!google_post_request_initialized_) { |
| 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( |
| 529 | new UploadDataStream(element_readers.Pass(), 0)); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 530 | |
| 531 | google_post_request_.method = "POST"; |
| 532 | google_post_request_.url = GURL(kDefaultURL); |
| 533 | google_post_request_.upload_data_stream = upload_data_stream_.get(); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 534 | google_post_request_initialized_ = true; |
| 535 | } |
| 536 | return google_post_request_; |
| 537 | } |
| 538 | |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 539 | const HttpRequestInfo& CreateChunkedPostRequest() { |
| 540 | if (!google_chunked_post_request_initialized_) { |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 541 | upload_data_stream_.reset( |
| 542 | new UploadDataStream(UploadDataStream::CHUNKED, 0)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 543 | google_chunked_post_request_.method = "POST"; |
| 544 | google_chunked_post_request_.url = GURL(kDefaultURL); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 545 | google_chunked_post_request_.upload_data_stream = |
| 546 | upload_data_stream_.get(); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 547 | google_chunked_post_request_initialized_ = true; |
| 548 | } |
| 549 | return google_chunked_post_request_; |
| 550 | } |
| 551 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 552 | // Read the result of a particular transaction, knowing that we've got |
| 553 | // multiple transactions in the read pipeline; so as we read, we may have |
| 554 | // to skip over data destined for other transactions while we consume |
| 555 | // the data for |trans|. |
| 556 | int ReadResult(HttpNetworkTransaction* trans, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 557 | StaticSocketDataProvider* data, |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 558 | std::string* result) { |
| 559 | const int kSize = 3000; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 560 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 561 | int bytes_read = 0; |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 562 | scoped_refptr<net::IOBufferWithSize> buf(new net::IOBufferWithSize(kSize)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 563 | TestCompletionCallback callback; |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 564 | while (true) { |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 565 | int rv = trans->Read(buf.get(), kSize, callback.callback()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 566 | if (rv == ERR_IO_PENDING) { |
| 567 | // Multiple transactions may be in the data set. Keep pulling off |
| 568 | // reads until we complete our callback. |
| 569 | while (!callback.have_result()) { |
| 570 | data->CompleteRead(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 571 | base::RunLoop().RunUntilIdle(); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 572 | } |
| 573 | rv = callback.WaitForResult(); |
| 574 | } else if (rv <= 0) { |
| 575 | break; |
| 576 | } |
| 577 | result->append(buf->data(), rv); |
| 578 | bytes_read += rv; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 579 | } |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 580 | return bytes_read; |
| 581 | } |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 582 | |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 583 | void VerifyStreamsClosed(const NormalSpdyTransactionHelper& helper) { |
| 584 | // This lengthy block is reaching into the pool to dig out the active |
| 585 | // session. Once we have the session, we verify that the streams are |
| 586 | // all closed and not leaked at this point. |
| 587 | const GURL& url = helper.request().url; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 588 | int port = helper.test_params().ssl_type == SPDYNPN ? 443 : 80; |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 589 | HostPortPair host_port_pair(url.host(), port); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 590 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 591 | PRIVACY_MODE_DISABLED); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 592 | BoundNetLog log; |
| 593 | const scoped_refptr<HttpNetworkSession>& session = helper.session(); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 594 | base::WeakPtr<SpdySession> spdy_session = |
[email protected] | 04644d4 | 2013-07-08 04:29:59 | [diff] [blame] | 595 | session->spdy_session_pool()->FindAvailableSession(key, log); |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 596 | ASSERT_TRUE(spdy_session != NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 597 | EXPECT_EQ(0u, spdy_session->num_active_streams()); |
| 598 | EXPECT_EQ(0u, spdy_session->num_unclaimed_pushed_streams()); |
| 599 | } |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 600 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 601 | void RunServerPushTest(OrderedSocketData* data, |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 602 | HttpResponseInfo* response, |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 603 | HttpResponseInfo* push_response, |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 604 | const std::string& expected) { |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 605 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 606 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 607 | helper.RunPreTestSetup(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 608 | helper.AddData(data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 609 | |
| 610 | HttpNetworkTransaction* trans = helper.trans(); |
| 611 | |
| 612 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 613 | TestCompletionCallback callback; |
| 614 | int rv = trans->Start( |
| 615 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 616 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 617 | rv = callback.WaitForResult(); |
| 618 | |
| 619 | // Request the pushed path. |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 620 | scoped_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 621 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 622 | rv = trans2->Start( |
| 623 | &CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 624 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 625 | base::RunLoop().RunUntilIdle(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 626 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 627 | // 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] | 628 | // the results into a single string. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 629 | |
| 630 | // Read the server push body. |
| 631 | std::string result2; |
| 632 | ReadResult(trans2.get(), data, &result2); |
| 633 | // Read the response body. |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 634 | std::string result; |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 635 | ReadResult(trans, data, &result); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 636 | |
| 637 | // Verify that we consumed all test data. |
| 638 | EXPECT_TRUE(data->at_read_eof()); |
| 639 | EXPECT_TRUE(data->at_write_eof()); |
| 640 | |
| 641 | // Verify that the received push data is same as the expected push data. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 642 | EXPECT_EQ(result2.compare(expected), 0) << "Received data: " |
| 643 | << result2 |
| 644 | << "||||| Expected data: " |
| 645 | << expected; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 646 | |
| 647 | // Verify the SYN_REPLY. |
| 648 | // Copy the response info, because trans goes away. |
| 649 | *response = *trans->GetResponseInfo(); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 650 | *push_response = *trans2->GetResponseInfo(); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 651 | |
| 652 | VerifyStreamsClosed(helper); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 653 | } |
| 654 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 655 | static void DeleteSessionCallback(NormalSpdyTransactionHelper* helper, |
| 656 | int result) { |
| 657 | helper->ResetTrans(); |
| 658 | } |
| 659 | |
| 660 | static void StartTransactionCallback( |
| 661 | const scoped_refptr<HttpNetworkSession>& session, |
| 662 | int result) { |
| 663 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 664 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 665 | TestCompletionCallback callback; |
| 666 | HttpRequestInfo request; |
| 667 | request.method = "GET"; |
| 668 | request.url = GURL("http://www.google.com/"); |
| 669 | request.load_flags = 0; |
| 670 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 671 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 672 | callback.WaitForResult(); |
| 673 | } |
| 674 | |
[email protected] | 9ec54f8 | 2013-05-10 02:53:05 | [diff] [blame] | 675 | SpdyTestUtil spdy_util_; |
| 676 | |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 677 | private: |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 678 | scoped_ptr<UploadDataStream> upload_data_stream_; |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 679 | bool google_get_request_initialized_; |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 680 | bool google_post_request_initialized_; |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 681 | bool google_chunked_post_request_initialized_; |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 682 | HttpRequestInfo google_get_request_; |
[email protected] | 31024059 | 2010-08-05 21:04:19 | [diff] [blame] | 683 | HttpRequestInfo google_post_request_; |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 684 | HttpRequestInfo google_chunked_post_request_; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 685 | HttpRequestInfo google_get_push_request_; |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 686 | base::ScopedTempDir temp_dir_; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 687 | }; |
| 688 | |
| 689 | //----------------------------------------------------------------------------- |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 690 | // All tests are run with three different connection types: SPDY after NPN |
| 691 | // negotiation, SPDY without SSL, and SPDY with SSL. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 692 | // |
| 693 | // TODO(akalin): Use ::testing::Combine() when we are able to use |
| 694 | // <tr1/tuple>. |
| 695 | INSTANTIATE_TEST_CASE_P( |
| 696 | Spdy, |
| 697 | SpdyNetworkTransactionTest, |
| 698 | ::testing::Values( |
[email protected] | b05bcaa3 | 2013-10-06 05:26:02 | [diff] [blame] | 699 | SpdyNetworkTransactionTestParams(kProtoDeprecatedSPDY2, SPDYNOSSL), |
| 700 | SpdyNetworkTransactionTestParams(kProtoDeprecatedSPDY2, SPDYSSL), |
| 701 | SpdyNetworkTransactionTestParams(kProtoDeprecatedSPDY2, SPDYNPN), |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 702 | SpdyNetworkTransactionTestParams(kProtoSPDY3, SPDYNOSSL), |
| 703 | SpdyNetworkTransactionTestParams(kProtoSPDY3, SPDYSSL), |
| 704 | SpdyNetworkTransactionTestParams(kProtoSPDY3, SPDYNPN), |
| 705 | SpdyNetworkTransactionTestParams(kProtoSPDY31, SPDYNOSSL), |
| 706 | SpdyNetworkTransactionTestParams(kProtoSPDY31, SPDYSSL), |
| 707 | SpdyNetworkTransactionTestParams(kProtoSPDY31, SPDYNPN), |
[email protected] | d10833bc | 2014-04-14 17:50:46 | [diff] [blame] | 708 | SpdyNetworkTransactionTestParams(kProtoSPDY4, SPDYNOSSL), |
| 709 | SpdyNetworkTransactionTestParams(kProtoSPDY4, SPDYSSL), |
| 710 | SpdyNetworkTransactionTestParams(kProtoSPDY4, SPDYNPN))); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 711 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 712 | // Verify HttpNetworkTransaction constructor. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 713 | TEST_P(SpdyNetworkTransactionTest, Constructor) { |
[email protected] | d45f9bd | 2014-01-15 18:47:28 | [diff] [blame] | 714 | LOG(INFO) << __FUNCTION__; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 715 | scoped_ptr<SpdySessionDependencies> session_deps( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 716 | CreateSpdySessionDependencies(GetParam())); |
[email protected] | d45f9bd | 2014-01-15 18:47:28 | [diff] [blame] | 717 | LOG(INFO) << __FUNCTION__; |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 718 | scoped_refptr<HttpNetworkSession> session( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 719 | SpdySessionDependencies::SpdyCreateSession(session_deps.get())); |
[email protected] | d45f9bd | 2014-01-15 18:47:28 | [diff] [blame] | 720 | LOG(INFO) << __FUNCTION__; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 721 | scoped_ptr<HttpTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 722 | new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
[email protected] | d45f9bd | 2014-01-15 18:47:28 | [diff] [blame] | 723 | LOG(INFO) << __FUNCTION__; |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 724 | } |
| 725 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 726 | TEST_P(SpdyNetworkTransactionTest, Get) { |
[email protected] | d45f9bd | 2014-01-15 18:47:28 | [diff] [blame] | 727 | LOG(INFO) << __FUNCTION__; |
[email protected] | 75f30cc2 | 2010-06-28 21:41:38 | [diff] [blame] | 728 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 729 | scoped_ptr<SpdyFrame> req( |
| 730 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 731 | MockWrite writes[] = { CreateMockWrite(*req) }; |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 732 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 733 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 734 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 735 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 736 | CreateMockRead(*resp), |
| 737 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 738 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 739 | }; |
| 740 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 741 | DelayedSocketData data(1, reads, arraysize(reads), |
| 742 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 743 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 744 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 745 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 746 | TransactionHelperResult out = helper.output(); |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 747 | EXPECT_EQ(OK, out.rv); |
| 748 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 749 | EXPECT_EQ("hello!", out.response_data); |
| 750 | } |
| 751 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 752 | TEST_P(SpdyNetworkTransactionTest, GetAtEachPriority) { |
[email protected] | 3d08dd38 | 2013-10-19 00:13:11 | [diff] [blame] | 753 | for (RequestPriority p = MINIMUM_PRIORITY; p <= MAXIMUM_PRIORITY; |
[email protected] | 31ae7ab | 2012-04-24 21:09:05 | [diff] [blame] | 754 | p = RequestPriority(p + 1)) { |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 755 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 756 | scoped_ptr<SpdyFrame> req( |
| 757 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, p, true)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 758 | MockWrite writes[] = { CreateMockWrite(*req) }; |
| 759 | |
[email protected] | 86aa87b | 2013-02-15 01:10:03 | [diff] [blame] | 760 | SpdyPriority spdy_prio = 0; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 761 | EXPECT_TRUE(GetSpdyPriority(spdy_util_.spdy_version(), *req, &spdy_prio)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 762 | // this repeats the RequestPriority-->SpdyPriority mapping from |
| 763 | // SpdyFramer::ConvertRequestPriorityToSpdyPriority to make |
| 764 | // sure it's being done right. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 765 | if (spdy_util_.spdy_version() < SPDY3) { |
| 766 | switch(p) { |
| 767 | case HIGHEST: |
| 768 | EXPECT_EQ(0, spdy_prio); |
| 769 | break; |
| 770 | case MEDIUM: |
| 771 | EXPECT_EQ(1, spdy_prio); |
| 772 | break; |
| 773 | case LOW: |
| 774 | case LOWEST: |
| 775 | EXPECT_EQ(2, spdy_prio); |
| 776 | break; |
| 777 | case IDLE: |
| 778 | EXPECT_EQ(3, spdy_prio); |
| 779 | break; |
| 780 | default: |
| 781 | FAIL(); |
| 782 | } |
| 783 | } else { |
| 784 | switch(p) { |
| 785 | case HIGHEST: |
| 786 | EXPECT_EQ(0, spdy_prio); |
| 787 | break; |
| 788 | case MEDIUM: |
| 789 | EXPECT_EQ(1, spdy_prio); |
| 790 | break; |
| 791 | case LOW: |
| 792 | EXPECT_EQ(2, spdy_prio); |
| 793 | break; |
| 794 | case LOWEST: |
| 795 | EXPECT_EQ(3, spdy_prio); |
| 796 | break; |
| 797 | case IDLE: |
| 798 | EXPECT_EQ(4, spdy_prio); |
| 799 | break; |
| 800 | default: |
| 801 | FAIL(); |
| 802 | } |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 803 | } |
| 804 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 805 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 806 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 807 | MockRead reads[] = { |
| 808 | CreateMockRead(*resp), |
| 809 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 810 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 811 | }; |
| 812 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 813 | DelayedSocketData data(1, reads, arraysize(reads), |
| 814 | writes, arraysize(writes)); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 815 | HttpRequestInfo http_req = CreateGetRequest(); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 816 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 817 | NormalSpdyTransactionHelper helper(http_req, p, BoundNetLog(), |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 818 | GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 819 | helper.RunToCompletion(&data); |
[email protected] | c9c6f5c | 2010-07-31 01:30:03 | [diff] [blame] | 820 | TransactionHelperResult out = helper.output(); |
| 821 | EXPECT_EQ(OK, out.rv); |
| 822 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 823 | EXPECT_EQ("hello!", out.response_data); |
| 824 | } |
| 825 | } |
| 826 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 827 | // Start three gets simultaniously; making sure that multiplexed |
| 828 | // streams work properly. |
| 829 | |
| 830 | // This can't use the TransactionHelper method, since it only |
| 831 | // handles a single transaction, and finishes them as soon |
| 832 | // as it launches them. |
| 833 | |
| 834 | // TODO(gavinp): create a working generalized TransactionHelper that |
| 835 | // can allow multiple streams in flight. |
| 836 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 837 | TEST_P(SpdyNetworkTransactionTest, ThreeGets) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 838 | scoped_ptr<SpdyFrame> req( |
| 839 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 840 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 841 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 842 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 843 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 844 | scoped_ptr<SpdyFrame> req2( |
| 845 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 846 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 847 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 848 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 849 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 850 | scoped_ptr<SpdyFrame> req3( |
| 851 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 852 | scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 853 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(5, false)); |
| 854 | scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 855 | |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 856 | MockWrite writes[] = { |
| 857 | CreateMockWrite(*req), |
| 858 | CreateMockWrite(*req2), |
| 859 | CreateMockWrite(*req3), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 860 | }; |
| 861 | MockRead reads[] = { |
| 862 | CreateMockRead(*resp, 1), |
| 863 | CreateMockRead(*body), |
| 864 | CreateMockRead(*resp2, 4), |
| 865 | CreateMockRead(*body2), |
| 866 | CreateMockRead(*resp3, 7), |
| 867 | CreateMockRead(*body3), |
| 868 | |
| 869 | CreateMockRead(*fbody), |
| 870 | CreateMockRead(*fbody2), |
| 871 | CreateMockRead(*fbody3), |
| 872 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 873 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 874 | }; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 875 | OrderedSocketData data(reads, arraysize(reads), |
| 876 | writes, arraysize(writes)); |
| 877 | OrderedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 878 | |
| 879 | BoundNetLog log; |
| 880 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 881 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 882 | BoundNetLog(), GetParam(), NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 883 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 884 | helper.AddData(&data); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 885 | // We require placeholder data because three get requests are sent out, so |
| 886 | // there needs to be three sets of SSL connection data. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 887 | helper.AddData(&data_placeholder); |
| 888 | helper.AddData(&data_placeholder); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 889 | scoped_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 890 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 891 | scoped_ptr<HttpNetworkTransaction> trans2( |
[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> trans3( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 894 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 895 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 896 | TestCompletionCallback callback1; |
| 897 | TestCompletionCallback callback2; |
| 898 | TestCompletionCallback callback3; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 899 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 900 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 901 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 902 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 903 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 904 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 905 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 906 | out.rv = trans2->Start(&httpreq2, callback2.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 = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 909 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 910 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 911 | out.rv = callback1.WaitForResult(); |
| 912 | ASSERT_EQ(OK, out.rv); |
| 913 | out.rv = callback3.WaitForResult(); |
| 914 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 915 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 916 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 917 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 918 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 919 | out.status_line = response1->headers->GetStatusLine(); |
| 920 | out.response_info = *response1; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 921 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 922 | trans2->GetResponseInfo(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 923 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 924 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 925 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 926 | EXPECT_EQ(OK, out.rv); |
| 927 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 928 | EXPECT_EQ(OK, out.rv); |
| 929 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 930 | EXPECT_EQ("hello!hello!", out.response_data); |
| 931 | } |
| 932 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 933 | TEST_P(SpdyNetworkTransactionTest, TwoGetsLateBinding) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 934 | scoped_ptr<SpdyFrame> req( |
| 935 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 936 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 937 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 938 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 939 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 940 | scoped_ptr<SpdyFrame> req2( |
| 941 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 942 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 943 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 944 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 945 | |
| 946 | MockWrite writes[] = { |
| 947 | CreateMockWrite(*req), |
| 948 | CreateMockWrite(*req2), |
| 949 | }; |
| 950 | MockRead reads[] = { |
| 951 | CreateMockRead(*resp, 1), |
| 952 | CreateMockRead(*body), |
| 953 | CreateMockRead(*resp2, 4), |
| 954 | CreateMockRead(*body2), |
| 955 | CreateMockRead(*fbody), |
| 956 | CreateMockRead(*fbody2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 957 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 958 | }; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 959 | OrderedSocketData data(reads, arraysize(reads), |
| 960 | 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); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 963 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 964 | OrderedSocketData data_placeholder(NULL, 0, NULL, 0); |
| 965 | data_placeholder.set_connect_data(never_finishing_connect); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 966 | |
| 967 | BoundNetLog log; |
| 968 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 969 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 970 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 971 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 972 | helper.AddData(&data); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 973 | // We require placeholder data because two get requests are sent out, so |
| 974 | // there needs to be two sets of SSL connection data. |
[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[] = { |
| 1034 | CreateMockWrite(*req), |
| 1035 | CreateMockWrite(*req2), |
| 1036 | }; |
| 1037 | MockRead reads[] = { |
| 1038 | CreateMockRead(*resp, 1), |
| 1039 | CreateMockRead(*body), |
| 1040 | CreateMockRead(*resp2, 4), |
| 1041 | CreateMockRead(*body2), |
| 1042 | CreateMockRead(*fbody), |
| 1043 | CreateMockRead(*fbody2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1044 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1045 | }; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1046 | OrderedSocketData preconnect_data(reads, arraysize(reads), |
| 1047 | writes, arraysize(writes)); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1048 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 1049 | MockConnect never_finishing_connect(ASYNC, ERR_IO_PENDING); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1050 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1051 | OrderedSocketData data_placeholder(NULL, 0, NULL, 0); |
| 1052 | data_placeholder.set_connect_data(never_finishing_connect); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1053 | |
| 1054 | BoundNetLog log; |
| 1055 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1056 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1057 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1058 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1059 | helper.AddData(&preconnect_data); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1060 | // We require placeholder data because 3 connections are attempted (first is |
| 1061 | // the preconnect, 2nd and 3rd are the never finished connections. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1062 | helper.AddData(&data_placeholder); |
| 1063 | helper.AddData(&data_placeholder); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1064 | |
| 1065 | scoped_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1066 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1067 | scoped_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1068 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1069 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1070 | TestCompletionCallback callback1; |
| 1071 | TestCompletionCallback callback2; |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1072 | |
| 1073 | HttpRequestInfo httpreq = CreateGetRequest(); |
| 1074 | |
| 1075 | // Preconnect the first. |
| 1076 | SSLConfig preconnect_ssl_config; |
| 1077 | helper.session()->ssl_config_service()->GetSSLConfig(&preconnect_ssl_config); |
| 1078 | HttpStreamFactory* http_stream_factory = |
| 1079 | helper.session()->http_stream_factory(); |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 1080 | if (http_stream_factory->has_next_protos()) { |
| 1081 | preconnect_ssl_config.next_protos = http_stream_factory->next_protos(); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | http_stream_factory->PreconnectStreams( |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1085 | 1, httpreq, DEFAULT_PRIORITY, |
| 1086 | preconnect_ssl_config, preconnect_ssl_config); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1087 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1088 | out.rv = trans1->Start(&httpreq, callback1.callback(), log); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1089 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1090 | out.rv = trans2->Start(&httpreq, callback2.callback(), log); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1091 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
| 1092 | |
| 1093 | out.rv = callback1.WaitForResult(); |
| 1094 | ASSERT_EQ(OK, out.rv); |
| 1095 | out.rv = callback2.WaitForResult(); |
| 1096 | ASSERT_EQ(OK, out.rv); |
| 1097 | |
| 1098 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1099 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1100 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1101 | out.status_line = response1->headers->GetStatusLine(); |
| 1102 | out.response_info = *response1; |
| 1103 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 1104 | EXPECT_EQ(OK, out.rv); |
| 1105 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1106 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1107 | |
| 1108 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1109 | EXPECT_TRUE(response2->headers.get() != NULL); |
[email protected] | 1b32317 | 2011-03-01 17:50:17 | [diff] [blame] | 1110 | EXPECT_TRUE(response2->was_fetched_via_spdy); |
| 1111 | out.status_line = response2->headers->GetStatusLine(); |
| 1112 | out.response_info = *response2; |
| 1113 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 1114 | EXPECT_EQ(OK, out.rv); |
| 1115 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1116 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1117 | |
| 1118 | helper.VerifyDataConsumed(); |
| 1119 | } |
| 1120 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1121 | // Similar to ThreeGets above, however this test adds a SETTINGS |
| 1122 | // frame. The SETTINGS frame is read during the IO loop waiting on |
| 1123 | // the first transaction completion, and sets a maximum concurrent |
| 1124 | // stream limit of 1. This means that our IO loop exists after the |
| 1125 | // second transaction completes, so we can assert on read_index(). |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1126 | TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrent) { |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1127 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1128 | scoped_ptr<SpdyFrame> req( |
| 1129 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1130 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1131 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1132 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1133 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1134 | scoped_ptr<SpdyFrame> req2( |
| 1135 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1136 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1137 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 1138 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1139 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1140 | scoped_ptr<SpdyFrame> req3( |
| 1141 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1142 | scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 1143 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(5, false)); |
| 1144 | scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1145 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1146 | SettingsMap settings; |
[email protected] | 9dcec24 | 2013-01-10 23:24:28 | [diff] [blame] | 1147 | const uint32 max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1148 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1149 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1150 | scoped_ptr<SpdyFrame> settings_frame( |
| 1151 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1152 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 1153 | MockWrite writes[] = { |
| 1154 | CreateMockWrite(*req), |
| 1155 | CreateMockWrite(*req2), |
| 1156 | CreateMockWrite(*req3), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1157 | }; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 1158 | |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1159 | MockRead reads[] = { |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1160 | CreateMockRead(*settings_frame, 1), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1161 | CreateMockRead(*resp), |
| 1162 | CreateMockRead(*body), |
| 1163 | CreateMockRead(*fbody), |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1164 | CreateMockRead(*resp2, 7), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1165 | CreateMockRead(*body2), |
| 1166 | CreateMockRead(*fbody2), |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1167 | CreateMockRead(*resp3, 12), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1168 | CreateMockRead(*body3), |
| 1169 | CreateMockRead(*fbody3), |
| 1170 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1171 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1172 | }; |
| 1173 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1174 | OrderedSocketData data(reads, arraysize(reads), |
| 1175 | writes, arraysize(writes)); |
| 1176 | OrderedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1177 | |
| 1178 | BoundNetLog log; |
| 1179 | TransactionHelperResult out; |
| 1180 | { |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1181 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1182 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 1183 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1184 | helper.AddData(&data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 1185 | // We require placeholder data because three get requests are sent out, so |
| 1186 | // there needs to be three sets of SSL connection data. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1187 | helper.AddData(&data_placeholder); |
| 1188 | helper.AddData(&data_placeholder); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1189 | scoped_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1190 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1191 | scoped_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1192 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1193 | scoped_ptr<HttpNetworkTransaction> trans3( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1194 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1195 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1196 | TestCompletionCallback callback1; |
| 1197 | TestCompletionCallback callback2; |
| 1198 | TestCompletionCallback callback3; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1199 | |
| 1200 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1201 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1202 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
| 1203 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1204 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1205 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1206 | // Run transaction 1 through quickly to force a read of our SETTINGS |
| 1207 | // frame. |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1208 | out.rv = callback1.WaitForResult(); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1209 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1210 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1211 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1212 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1213 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1214 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
| 1215 | out.rv = callback2.WaitForResult(); |
| 1216 | ASSERT_EQ(OK, out.rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1217 | EXPECT_EQ(7U, data.read_index()); // i.e. the third trans was queued |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1218 | |
| 1219 | out.rv = callback3.WaitForResult(); |
| 1220 | ASSERT_EQ(OK, out.rv); |
| 1221 | |
| 1222 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1223 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1224 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1225 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1226 | out.status_line = response1->headers->GetStatusLine(); |
| 1227 | out.response_info = *response1; |
| 1228 | out.rv = ReadTransaction(trans1.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* response2 = trans2->GetResponseInfo(); |
| 1234 | out.status_line = response2->headers->GetStatusLine(); |
| 1235 | out.response_info = *response2; |
| 1236 | out.rv = ReadTransaction(trans2.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); |
| 1240 | |
| 1241 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 1242 | out.status_line = response3->headers->GetStatusLine(); |
| 1243 | out.response_info = *response3; |
| 1244 | out.rv = ReadTransaction(trans3.get(), &out.response_data); |
| 1245 | EXPECT_EQ(OK, out.rv); |
| 1246 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1247 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1248 | |
| 1249 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1250 | } |
| 1251 | EXPECT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1252 | } |
| 1253 | |
| 1254 | // Similar to ThreeGetsWithMaxConcurrent above, however this test adds |
| 1255 | // a fourth transaction. The third and fourth transactions have |
| 1256 | // different data ("hello!" vs "hello!hello!") and because of the |
| 1257 | // user specified priority, we expect to see them inverted in |
| 1258 | // the response from the server. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1259 | TEST_P(SpdyNetworkTransactionTest, FourGetsWithMaxConcurrentPriority) { |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1260 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1261 | scoped_ptr<SpdyFrame> req( |
| 1262 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1263 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1264 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1265 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1266 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1267 | scoped_ptr<SpdyFrame> req2( |
| 1268 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1269 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1270 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 1271 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1272 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1273 | scoped_ptr<SpdyFrame> req4( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1274 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, HIGHEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1275 | scoped_ptr<SpdyFrame> resp4(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 1276 | scoped_ptr<SpdyFrame> fbody4(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1277 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1278 | scoped_ptr<SpdyFrame> req3( |
| 1279 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 7, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1280 | scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 7)); |
| 1281 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(7, false)); |
| 1282 | scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(7, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1283 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1284 | SettingsMap settings; |
[email protected] | 9dcec24 | 2013-01-10 23:24:28 | [diff] [blame] | 1285 | const uint32 max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1286 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1287 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1288 | scoped_ptr<SpdyFrame> settings_frame( |
| 1289 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1290 | |
| 1291 | MockWrite writes[] = { CreateMockWrite(*req), |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1292 | CreateMockWrite(*req2), |
| 1293 | CreateMockWrite(*req4), |
| 1294 | CreateMockWrite(*req3), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1295 | }; |
| 1296 | MockRead reads[] = { |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1297 | CreateMockRead(*settings_frame, 1), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1298 | CreateMockRead(*resp), |
| 1299 | CreateMockRead(*body), |
| 1300 | CreateMockRead(*fbody), |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1301 | CreateMockRead(*resp2, 7), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1302 | CreateMockRead(*body2), |
| 1303 | CreateMockRead(*fbody2), |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1304 | CreateMockRead(*resp4, 13), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1305 | CreateMockRead(*fbody4), |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1306 | CreateMockRead(*resp3, 16), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1307 | CreateMockRead(*body3), |
| 1308 | CreateMockRead(*fbody3), |
| 1309 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1310 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1311 | }; |
| 1312 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1313 | OrderedSocketData data(reads, arraysize(reads), |
| 1314 | writes, arraysize(writes)); |
| 1315 | OrderedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1316 | |
| 1317 | BoundNetLog log; |
| 1318 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1319 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 1320 | BoundNetLog(), GetParam(), NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1321 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1322 | helper.AddData(&data); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1323 | // We require placeholder data because four get requests are sent out, so |
| 1324 | // there needs to be four sets of SSL connection data. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1325 | helper.AddData(&data_placeholder); |
| 1326 | helper.AddData(&data_placeholder); |
| 1327 | helper.AddData(&data_placeholder); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1328 | scoped_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1329 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1330 | scoped_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1331 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1332 | scoped_ptr<HttpNetworkTransaction> trans3( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1333 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1334 | scoped_ptr<HttpNetworkTransaction> trans4( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1335 | new HttpNetworkTransaction(HIGHEST, helper.session().get())); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1336 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1337 | TestCompletionCallback callback1; |
| 1338 | TestCompletionCallback callback2; |
| 1339 | TestCompletionCallback callback3; |
| 1340 | TestCompletionCallback callback4; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1341 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1342 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1343 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1344 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
| 1345 | HttpRequestInfo httpreq4 = CreateGetRequest(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1346 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1347 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1348 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1349 | // Run transaction 1 through quickly to force a read of our SETTINGS frame. |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1350 | out.rv = callback1.WaitForResult(); |
| 1351 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1352 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1353 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1354 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1355 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1356 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1357 | out.rv = trans4->Start(&httpreq4, callback4.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1358 | ASSERT_EQ(ERR_IO_PENDING, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1359 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1360 | out.rv = callback2.WaitForResult(); |
| 1361 | ASSERT_EQ(OK, out.rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1362 | EXPECT_EQ(data.read_index(), 7U); // i.e. the third & fourth trans queued |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1363 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1364 | out.rv = callback3.WaitForResult(); |
| 1365 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1366 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1367 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1368 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1369 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1370 | out.status_line = response1->headers->GetStatusLine(); |
| 1371 | out.response_info = *response1; |
| 1372 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 1373 | EXPECT_EQ(OK, out.rv); |
| 1374 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1375 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1376 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1377 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 1378 | out.status_line = response2->headers->GetStatusLine(); |
| 1379 | out.response_info = *response2; |
| 1380 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 1381 | EXPECT_EQ(OK, out.rv); |
| 1382 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1383 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1384 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1385 | // notice: response3 gets two hellos, response4 gets one |
| 1386 | // hello, so we know dequeuing priority was respected. |
| 1387 | const HttpResponseInfo* response3 = trans3->GetResponseInfo(); |
| 1388 | out.status_line = response3->headers->GetStatusLine(); |
| 1389 | out.response_info = *response3; |
| 1390 | out.rv = ReadTransaction(trans3.get(), &out.response_data); |
| 1391 | EXPECT_EQ(OK, out.rv); |
| 1392 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1393 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1394 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1395 | out.rv = callback4.WaitForResult(); |
| 1396 | EXPECT_EQ(OK, out.rv); |
| 1397 | const HttpResponseInfo* response4 = trans4->GetResponseInfo(); |
| 1398 | out.status_line = response4->headers->GetStatusLine(); |
| 1399 | out.response_info = *response4; |
| 1400 | out.rv = ReadTransaction(trans4.get(), &out.response_data); |
| 1401 | EXPECT_EQ(OK, out.rv); |
| 1402 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1403 | EXPECT_EQ("hello!", out.response_data); |
| 1404 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1405 | EXPECT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | // Similar to ThreeGetsMaxConcurrrent above, however, this test |
| 1409 | // deletes a session in the middle of the transaction to insure |
| 1410 | // that we properly remove pendingcreatestream objects from |
| 1411 | // the spdy_session |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1412 | TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentDelete) { |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1413 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1414 | scoped_ptr<SpdyFrame> req( |
| 1415 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1416 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1417 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1418 | scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1419 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1420 | scoped_ptr<SpdyFrame> req2( |
| 1421 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1422 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1423 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 1424 | scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1425 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1426 | SettingsMap settings; |
[email protected] | 9dcec24 | 2013-01-10 23:24:28 | [diff] [blame] | 1427 | const uint32 max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1428 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1429 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1430 | scoped_ptr<SpdyFrame> settings_frame( |
| 1431 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1432 | |
| 1433 | MockWrite writes[] = { CreateMockWrite(*req), |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1434 | CreateMockWrite(*req2), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1435 | }; |
| 1436 | MockRead reads[] = { |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1437 | CreateMockRead(*settings_frame, 1), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1438 | CreateMockRead(*resp), |
| 1439 | CreateMockRead(*body), |
| 1440 | CreateMockRead(*fbody), |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1441 | CreateMockRead(*resp2, 7), |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1442 | CreateMockRead(*body2), |
| 1443 | CreateMockRead(*fbody2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1444 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1445 | }; |
| 1446 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1447 | OrderedSocketData data(reads, arraysize(reads), |
| 1448 | writes, arraysize(writes)); |
| 1449 | OrderedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1450 | |
| 1451 | BoundNetLog log; |
| 1452 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1453 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 1454 | BoundNetLog(), GetParam(), NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1455 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1456 | helper.AddData(&data); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1457 | // We require placeholder data because three get requests are sent out, so |
| 1458 | // there needs to be three sets of SSL connection data. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1459 | helper.AddData(&data_placeholder); |
| 1460 | helper.AddData(&data_placeholder); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1461 | scoped_ptr<HttpNetworkTransaction> trans1( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1462 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1463 | scoped_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1464 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1465 | scoped_ptr<HttpNetworkTransaction> trans3( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1466 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1467 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1468 | TestCompletionCallback callback1; |
| 1469 | TestCompletionCallback callback2; |
| 1470 | TestCompletionCallback callback3; |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1471 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1472 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1473 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1474 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1475 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1476 | out.rv = trans1->Start(&httpreq1, callback1.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1477 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1478 | // Run transaction 1 through quickly to force a read of our SETTINGS frame. |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1479 | out.rv = callback1.WaitForResult(); |
| 1480 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1481 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1482 | out.rv = trans2->Start(&httpreq2, callback2.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1483 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1484 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1485 | delete trans3.release(); |
| 1486 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
| 1487 | out.rv = callback2.WaitForResult(); |
| 1488 | ASSERT_EQ(OK, out.rv); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1489 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1490 | EXPECT_EQ(8U, data.read_index()); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1491 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1492 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 1493 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1494 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1495 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1496 | out.status_line = response1->headers->GetStatusLine(); |
| 1497 | out.response_info = *response1; |
| 1498 | out.rv = ReadTransaction(trans1.get(), &out.response_data); |
| 1499 | EXPECT_EQ(OK, out.rv); |
| 1500 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1501 | EXPECT_EQ("hello!hello!", out.response_data); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1502 | |
[email protected] | bdebd1b | 2010-08-09 20:18:08 | [diff] [blame] | 1503 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 1504 | ASSERT_TRUE(response2 != NULL); |
| 1505 | out.status_line = response2->headers->GetStatusLine(); |
| 1506 | out.response_info = *response2; |
| 1507 | out.rv = ReadTransaction(trans2.get(), &out.response_data); |
| 1508 | EXPECT_EQ(OK, out.rv); |
| 1509 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1510 | EXPECT_EQ("hello!hello!", out.response_data); |
| 1511 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1512 | EXPECT_EQ(OK, out.rv); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1513 | } |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1514 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1515 | namespace { |
| 1516 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1517 | // The KillerCallback will delete the transaction on error as part of the |
| 1518 | // callback. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1519 | class KillerCallback : public TestCompletionCallbackBase { |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1520 | public: |
| 1521 | explicit KillerCallback(HttpNetworkTransaction* transaction) |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1522 | : transaction_(transaction), |
[email protected] | aa249b5 | 2013-04-30 01:04:32 | [diff] [blame] | 1523 | callback_(base::Bind(&KillerCallback::OnComplete, |
| 1524 | base::Unretained(this))) { |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1525 | } |
| 1526 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1527 | virtual ~KillerCallback() {} |
| 1528 | |
| 1529 | const CompletionCallback& callback() const { return callback_; } |
| 1530 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1531 | private: |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1532 | void OnComplete(int result) { |
| 1533 | if (result < 0) |
| 1534 | delete transaction_; |
| 1535 | |
| 1536 | SetResult(result); |
| 1537 | } |
| 1538 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1539 | HttpNetworkTransaction* transaction_; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1540 | CompletionCallback callback_; |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1541 | }; |
| 1542 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 1543 | } // namespace |
| 1544 | |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1545 | // Similar to ThreeGetsMaxConcurrrentDelete above, however, this test |
| 1546 | // closes the socket while we have a pending transaction waiting for |
| 1547 | // a pending stream creation. http://crbug.com/52901 |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1548 | TEST_P(SpdyNetworkTransactionTest, ThreeGetsWithMaxConcurrentSocketClose) { |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1549 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1550 | scoped_ptr<SpdyFrame> req( |
| 1551 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1552 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1553 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1554 | scoped_ptr<SpdyFrame> fin_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1555 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1556 | scoped_ptr<SpdyFrame> req2( |
| 1557 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1558 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1559 | |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1560 | SettingsMap settings; |
[email protected] | 9dcec24 | 2013-01-10 23:24:28 | [diff] [blame] | 1561 | const uint32 max_concurrent_streams = 1; |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 1562 | settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1563 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 1564 | scoped_ptr<SpdyFrame> settings_frame( |
| 1565 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1566 | |
| 1567 | MockWrite writes[] = { CreateMockWrite(*req), |
| 1568 | CreateMockWrite(*req2), |
| 1569 | }; |
| 1570 | MockRead reads[] = { |
| 1571 | CreateMockRead(*settings_frame, 1), |
| 1572 | CreateMockRead(*resp), |
| 1573 | CreateMockRead(*body), |
| 1574 | CreateMockRead(*fin_body), |
| 1575 | CreateMockRead(*resp2, 7), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1576 | MockRead(ASYNC, ERR_CONNECTION_RESET, 0), // Abort! |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1577 | }; |
| 1578 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1579 | OrderedSocketData data(reads, arraysize(reads), |
| 1580 | writes, arraysize(writes)); |
| 1581 | OrderedSocketData data_placeholder(NULL, 0, NULL, 0); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1582 | |
| 1583 | BoundNetLog log; |
| 1584 | TransactionHelperResult out; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1585 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 1586 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1587 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1588 | helper.AddData(&data); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1589 | // We require placeholder data because three get requests are sent out, so |
| 1590 | // there needs to be three sets of SSL connection data. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1591 | helper.AddData(&data_placeholder); |
| 1592 | helper.AddData(&data_placeholder); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1593 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session().get()); |
| 1594 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session().get()); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1595 | HttpNetworkTransaction* trans3( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1596 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1597 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1598 | TestCompletionCallback callback1; |
| 1599 | TestCompletionCallback callback2; |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1600 | KillerCallback callback3(trans3); |
| 1601 | |
| 1602 | HttpRequestInfo httpreq1 = CreateGetRequest(); |
| 1603 | HttpRequestInfo httpreq2 = CreateGetRequest(); |
| 1604 | HttpRequestInfo httpreq3 = CreateGetRequest(); |
| 1605 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1606 | out.rv = trans1.Start(&httpreq1, callback1.callback(), log); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1607 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1608 | // Run transaction 1 through quickly to force a read of our SETTINGS frame. |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1609 | out.rv = callback1.WaitForResult(); |
| 1610 | ASSERT_EQ(OK, out.rv); |
| 1611 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1612 | out.rv = trans2.Start(&httpreq2, callback2.callback(), log); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1613 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1614 | out.rv = trans3->Start(&httpreq3, callback3.callback(), log); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1615 | ASSERT_EQ(out.rv, ERR_IO_PENDING); |
| 1616 | out.rv = callback3.WaitForResult(); |
| 1617 | ASSERT_EQ(ERR_ABORTED, out.rv); |
| 1618 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1619 | EXPECT_EQ(6U, data.read_index()); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1620 | |
| 1621 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
| 1622 | ASSERT_TRUE(response1 != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1623 | EXPECT_TRUE(response1->headers.get() != NULL); |
[email protected] | 044dcc5 | 2010-09-17 15:44:26 | [diff] [blame] | 1624 | EXPECT_TRUE(response1->was_fetched_via_spdy); |
| 1625 | out.status_line = response1->headers->GetStatusLine(); |
| 1626 | out.response_info = *response1; |
| 1627 | out.rv = ReadTransaction(&trans1, &out.response_data); |
| 1628 | EXPECT_EQ(OK, out.rv); |
| 1629 | |
| 1630 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 1631 | ASSERT_TRUE(response2 != NULL); |
| 1632 | out.status_line = response2->headers->GetStatusLine(); |
| 1633 | out.response_info = *response2; |
| 1634 | out.rv = ReadTransaction(&trans2, &out.response_data); |
| 1635 | EXPECT_EQ(ERR_CONNECTION_RESET, out.rv); |
| 1636 | |
| 1637 | helper.VerifyDataConsumed(); |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 1638 | } |
| 1639 | |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1640 | // Test that a simple PUT request works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1641 | TEST_P(SpdyNetworkTransactionTest, Put) { |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1642 | // Setup the request |
| 1643 | HttpRequestInfo request; |
| 1644 | request.method = "PUT"; |
| 1645 | request.url = GURL("http://www.google.com/"); |
| 1646 | |
| 1647 | const SpdyHeaderInfo kSynStartHeader = { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1648 | SYN_STREAM, // Kind = Syn |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1649 | 1, // Stream ID |
| 1650 | 0, // Associated stream ID |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1651 | ConvertRequestPriorityToSpdyPriority( |
| 1652 | LOWEST, spdy_util_.spdy_version()), |
| 1653 | kSpdyCredentialSlotUnused, |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1654 | CONTROL_FLAG_FIN, // Control Flags |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1655 | false, // Compressed |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 1656 | RST_STREAM_INVALID, // Status |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1657 | NULL, // Data |
| 1658 | 0, // Length |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1659 | DATA_FLAG_NONE // Data Flags |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1660 | }; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1661 | scoped_ptr<SpdyHeaderBlock> put_headers( |
| 1662 | spdy_util_.ConstructPutHeaderBlock("http://www.google.com", 0)); |
[email protected] | 9ec54f8 | 2013-05-10 02:53:05 | [diff] [blame] | 1663 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyFrame( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1664 | kSynStartHeader, put_headers.Pass())); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1665 | MockWrite writes[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1666 | CreateMockWrite(*req), |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1667 | }; |
| 1668 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1669 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1670 | const SpdyHeaderInfo kSynReplyHeader = { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1671 | SYN_REPLY, // Kind = SynReply |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1672 | 1, // Stream ID |
| 1673 | 0, // Associated stream ID |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1674 | ConvertRequestPriorityToSpdyPriority( |
| 1675 | LOWEST, spdy_util_.spdy_version()), |
| 1676 | kSpdyCredentialSlotUnused, |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1677 | CONTROL_FLAG_NONE, // Control Flags |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1678 | false, // Compressed |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 1679 | RST_STREAM_INVALID, // Status |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1680 | NULL, // Data |
| 1681 | 0, // Length |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1682 | DATA_FLAG_NONE // Data Flags |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1683 | }; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1684 | scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); |
| 1685 | (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 1686 | (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
| 1687 | (*reply_headers)["content-length"] = "1234"; |
[email protected] | 9ec54f8 | 2013-05-10 02:53:05 | [diff] [blame] | 1688 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyFrame( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1689 | kSynReplyHeader, reply_headers.Pass())); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1690 | MockRead reads[] = { |
| 1691 | CreateMockRead(*resp), |
| 1692 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1693 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1694 | }; |
| 1695 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1696 | DelayedSocketData data(1, reads, arraysize(reads), |
| 1697 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1698 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1699 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1700 | helper.RunToCompletion(&data); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1701 | TransactionHelperResult out = helper.output(); |
| 1702 | |
| 1703 | EXPECT_EQ(OK, out.rv); |
| 1704 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1705 | } |
| 1706 | |
| 1707 | // Test that a simple HEAD request works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1708 | TEST_P(SpdyNetworkTransactionTest, Head) { |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1709 | // Setup the request |
| 1710 | HttpRequestInfo request; |
| 1711 | request.method = "HEAD"; |
| 1712 | request.url = GURL("http://www.google.com/"); |
| 1713 | |
| 1714 | const SpdyHeaderInfo kSynStartHeader = { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1715 | SYN_STREAM, // Kind = Syn |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1716 | 1, // Stream ID |
| 1717 | 0, // Associated stream ID |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1718 | ConvertRequestPriorityToSpdyPriority( |
| 1719 | LOWEST, spdy_util_.spdy_version()), |
| 1720 | kSpdyCredentialSlotUnused, |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1721 | CONTROL_FLAG_FIN, // Control Flags |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1722 | false, // Compressed |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 1723 | RST_STREAM_INVALID, // Status |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1724 | NULL, // Data |
| 1725 | 0, // Length |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1726 | DATA_FLAG_NONE // Data Flags |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1727 | }; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1728 | scoped_ptr<SpdyHeaderBlock> head_headers( |
| 1729 | spdy_util_.ConstructHeadHeaderBlock("http://www.google.com", 0)); |
[email protected] | 9ec54f8 | 2013-05-10 02:53:05 | [diff] [blame] | 1730 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyFrame( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1731 | kSynStartHeader, head_headers.Pass())); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1732 | MockWrite writes[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 1733 | CreateMockWrite(*req), |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1734 | }; |
| 1735 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1736 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1737 | const SpdyHeaderInfo kSynReplyHeader = { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1738 | SYN_REPLY, // Kind = SynReply |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1739 | 1, // Stream ID |
| 1740 | 0, // Associated stream ID |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1741 | ConvertRequestPriorityToSpdyPriority( |
| 1742 | LOWEST, spdy_util_.spdy_version()), |
| 1743 | kSpdyCredentialSlotUnused, |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1744 | CONTROL_FLAG_NONE, // Control Flags |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1745 | false, // Compressed |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 1746 | RST_STREAM_INVALID, // Status |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 1747 | NULL, // Data |
| 1748 | 0, // Length |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 1749 | DATA_FLAG_NONE // Data Flags |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1750 | }; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1751 | scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); |
| 1752 | (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 1753 | (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
| 1754 | (*reply_headers)["content-length"] = "1234"; |
[email protected] | 9ec54f8 | 2013-05-10 02:53:05 | [diff] [blame] | 1755 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyFrame( |
| 1756 | kSynReplyHeader, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1757 | reply_headers.Pass())); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1758 | MockRead reads[] = { |
| 1759 | CreateMockRead(*resp), |
| 1760 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1761 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1762 | }; |
| 1763 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1764 | DelayedSocketData data(1, reads, arraysize(reads), |
| 1765 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1766 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1767 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1768 | helper.RunToCompletion(&data); |
[email protected] | d8ef27b | 2010-08-06 17:34:39 | [diff] [blame] | 1769 | TransactionHelperResult out = helper.output(); |
| 1770 | |
| 1771 | EXPECT_EQ(OK, out.rv); |
| 1772 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1773 | } |
| 1774 | |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 1775 | // Test that a simple POST works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1776 | TEST_P(SpdyNetworkTransactionTest, Post) { |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 1777 | scoped_ptr<SpdyFrame> req( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1778 | spdy_util_.ConstructSpdyPost( |
| 1779 | kRequestUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); |
| 1780 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1781 | MockWrite writes[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 1782 | CreateMockWrite(*req), |
| 1783 | CreateMockWrite(*body), // POST upload frame |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1784 | }; |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 1785 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1786 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 1787 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 1788 | CreateMockRead(*resp), |
| 1789 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1790 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 1791 | }; |
| 1792 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1793 | DelayedSocketData data(2, reads, arraysize(reads), |
| 1794 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1795 | NormalSpdyTransactionHelper helper(CreatePostRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1796 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1797 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 1798 | TransactionHelperResult out = helper.output(); |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 1799 | EXPECT_EQ(OK, out.rv); |
| 1800 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1801 | EXPECT_EQ("hello!", out.response_data); |
| 1802 | } |
| 1803 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1804 | // Test that a POST with a file works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1805 | TEST_P(SpdyNetworkTransactionTest, FilePost) { |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 1806 | scoped_ptr<SpdyFrame> req( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1807 | spdy_util_.ConstructSpdyPost( |
| 1808 | kRequestUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); |
| 1809 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1810 | MockWrite writes[] = { |
| 1811 | CreateMockWrite(*req), |
| 1812 | CreateMockWrite(*body), // POST upload frame |
| 1813 | }; |
| 1814 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1815 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1816 | MockRead reads[] = { |
| 1817 | CreateMockRead(*resp), |
| 1818 | CreateMockRead(*body), |
| 1819 | MockRead(ASYNC, 0, 0) // EOF |
| 1820 | }; |
| 1821 | |
| 1822 | DelayedSocketData data(2, reads, arraysize(reads), |
| 1823 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1824 | NormalSpdyTransactionHelper helper(CreateFilePostRequest(), DEFAULT_PRIORITY, |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1825 | BoundNetLog(), GetParam(), NULL); |
| 1826 | helper.RunToCompletion(&data); |
| 1827 | TransactionHelperResult out = helper.output(); |
| 1828 | EXPECT_EQ(OK, out.rv); |
| 1829 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1830 | EXPECT_EQ("hello!", out.response_data); |
| 1831 | } |
| 1832 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 1833 | // Test that a POST with a unreadable file fails. |
| 1834 | TEST_P(SpdyNetworkTransactionTest, UnreadableFilePost) { |
| 1835 | MockWrite writes[] = { |
| 1836 | MockWrite(ASYNC, 0, 0) // EOF |
| 1837 | }; |
| 1838 | MockRead reads[] = { |
| 1839 | MockRead(ASYNC, 0, 0) // EOF |
| 1840 | }; |
| 1841 | |
| 1842 | DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 1843 | NormalSpdyTransactionHelper helper(CreateUnreadableFilePostRequest(), |
| 1844 | DEFAULT_PRIORITY, |
| 1845 | BoundNetLog(), GetParam(), NULL); |
| 1846 | helper.RunPreTestSetup(); |
| 1847 | helper.AddData(&data); |
| 1848 | helper.RunDefaultTest(); |
| 1849 | |
| 1850 | base::RunLoop().RunUntilIdle(); |
| 1851 | helper.VerifyDataNotConsumed(); |
| 1852 | EXPECT_EQ(ERR_ACCESS_DENIED, helper.output().rv); |
| 1853 | } |
| 1854 | |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1855 | // Test that a complex POST works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1856 | TEST_P(SpdyNetworkTransactionTest, ComplexPost) { |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 1857 | scoped_ptr<SpdyFrame> req( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1858 | spdy_util_.ConstructSpdyPost( |
| 1859 | kRequestUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); |
| 1860 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1861 | MockWrite writes[] = { |
| 1862 | CreateMockWrite(*req), |
| 1863 | CreateMockWrite(*body), // POST upload frame |
| 1864 | }; |
| 1865 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1866 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1867 | MockRead reads[] = { |
| 1868 | CreateMockRead(*resp), |
| 1869 | CreateMockRead(*body), |
| 1870 | MockRead(ASYNC, 0, 0) // EOF |
| 1871 | }; |
| 1872 | |
| 1873 | DelayedSocketData data(2, reads, arraysize(reads), |
| 1874 | writes, arraysize(writes)); |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1875 | NormalSpdyTransactionHelper helper(CreateComplexPostRequest(), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1876 | DEFAULT_PRIORITY, |
[email protected] | 69e6b4a | 2012-10-18 08:03:01 | [diff] [blame] | 1877 | BoundNetLog(), GetParam(), NULL); |
| 1878 | helper.RunToCompletion(&data); |
| 1879 | TransactionHelperResult out = helper.output(); |
| 1880 | EXPECT_EQ(OK, out.rv); |
| 1881 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1882 | EXPECT_EQ("hello!", out.response_data); |
| 1883 | } |
| 1884 | |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1885 | // Test that a chunked POST works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1886 | TEST_P(SpdyNetworkTransactionTest, ChunkedPost) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1887 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1888 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1889 | MockWrite writes[] = { |
| 1890 | CreateMockWrite(*req), |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1891 | CreateMockWrite(*body), |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1892 | }; |
| 1893 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1894 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1895 | MockRead reads[] = { |
| 1896 | CreateMockRead(*resp), |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1897 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1898 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1899 | }; |
| 1900 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1901 | DelayedSocketData data(2, reads, arraysize(reads), |
| 1902 | writes, arraysize(writes)); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1903 | NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1904 | DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 1905 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1906 | |
| 1907 | // These chunks get merged into a single frame when being sent. |
| 1908 | const int kFirstChunkSize = kUploadDataSize/2; |
| 1909 | helper.request().upload_data_stream->AppendChunk( |
| 1910 | kUploadData, kFirstChunkSize, false); |
| 1911 | helper.request().upload_data_stream->AppendChunk( |
| 1912 | kUploadData + kFirstChunkSize, kUploadDataSize - kFirstChunkSize, true); |
| 1913 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 1914 | helper.RunToCompletion(&data); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1915 | TransactionHelperResult out = helper.output(); |
| 1916 | EXPECT_EQ(OK, out.rv); |
| 1917 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1918 | EXPECT_EQ(kUploadData, out.response_data); |
| 1919 | } |
| 1920 | |
| 1921 | // Test that a chunked POST works with chunks appended after transaction starts. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1922 | TEST_P(SpdyNetworkTransactionTest, DelayedChunkedPost) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1923 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1924 | scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1925 | scoped_ptr<SpdyFrame> chunk2(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1926 | scoped_ptr<SpdyFrame> chunk3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1927 | MockWrite writes[] = { |
| 1928 | CreateMockWrite(*req), |
| 1929 | CreateMockWrite(*chunk1), |
| 1930 | CreateMockWrite(*chunk2), |
| 1931 | CreateMockWrite(*chunk3), |
| 1932 | }; |
| 1933 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1934 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1935 | MockRead reads[] = { |
| 1936 | CreateMockRead(*resp), |
| 1937 | CreateMockRead(*chunk1), |
| 1938 | CreateMockRead(*chunk2), |
| 1939 | CreateMockRead(*chunk3), |
| 1940 | MockRead(ASYNC, 0, 0) // EOF |
| 1941 | }; |
| 1942 | |
| 1943 | DelayedSocketData data(4, reads, arraysize(reads), |
| 1944 | writes, arraysize(writes)); |
| 1945 | NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 1946 | DEFAULT_PRIORITY, |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1947 | BoundNetLog(), GetParam(), NULL); |
| 1948 | |
| 1949 | helper.request().upload_data_stream->AppendChunk( |
| 1950 | kUploadData, kUploadDataSize, false); |
| 1951 | |
| 1952 | helper.RunPreTestSetup(); |
| 1953 | helper.AddData(&data); |
| 1954 | ASSERT_TRUE(helper.StartDefaultTest()); |
| 1955 | |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 1956 | base::RunLoop().RunUntilIdle(); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1957 | helper.request().upload_data_stream->AppendChunk( |
| 1958 | kUploadData, kUploadDataSize, false); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 1959 | base::RunLoop().RunUntilIdle(); |
[email protected] | 34b345f9 | 2013-02-22 03:27:26 | [diff] [blame] | 1960 | helper.request().upload_data_stream->AppendChunk( |
| 1961 | kUploadData, kUploadDataSize, true); |
| 1962 | |
| 1963 | helper.FinishDefaultTest(); |
| 1964 | helper.VerifyDataConsumed(); |
| 1965 | |
| 1966 | std::string expected_response; |
| 1967 | expected_response += kUploadData; |
| 1968 | expected_response += kUploadData; |
| 1969 | expected_response += kUploadData; |
| 1970 | |
| 1971 | TransactionHelperResult out = helper.output(); |
| 1972 | EXPECT_EQ(OK, out.rv); |
| 1973 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1974 | EXPECT_EQ(expected_response, out.response_data); |
[email protected] | 0c9bf87 | 2011-03-04 17:53:22 | [diff] [blame] | 1975 | } |
| 1976 | |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1977 | // Test that a POST without any post data works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 1978 | TEST_P(SpdyNetworkTransactionTest, NullPost) { |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1979 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1980 | // Setup the request |
| 1981 | HttpRequestInfo request; |
| 1982 | request.method = "POST"; |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 1983 | request.url = GURL(kRequestUrl); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1984 | // Create an empty UploadData. |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1985 | request.upload_data_stream = NULL; |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1986 | |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1987 | // When request.upload_data_stream is NULL for post, content-length is |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1988 | // expected to be 0. |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 1989 | SpdySynStreamIR syn_ir(1); |
| 1990 | syn_ir.set_name_value_block( |
| 1991 | *spdy_util_.ConstructPostHeaderBlock(kRequestUrl, 0)); |
| 1992 | syn_ir.set_fin(true); // No body. |
| 1993 | syn_ir.set_priority(ConvertRequestPriorityToSpdyPriority( |
| 1994 | LOWEST, spdy_util_.spdy_version())); |
| 1995 | scoped_ptr<SpdyFrame> req(framer.SerializeFrame(syn_ir)); |
| 1996 | |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 1997 | MockWrite writes[] = { |
| 1998 | CreateMockWrite(*req), |
| 1999 | }; |
| 2000 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2001 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 2002 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 2003 | MockRead reads[] = { |
| 2004 | CreateMockRead(*resp), |
| 2005 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2006 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 2007 | }; |
| 2008 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2009 | DelayedSocketData data(1, reads, arraysize(reads), |
| 2010 | writes, arraysize(writes)); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 2011 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2012 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2013 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2014 | helper.RunToCompletion(&data); |
[email protected] | a33cad2b6 | 2010-07-30 22:24:39 | [diff] [blame] | 2015 | TransactionHelperResult out = helper.output(); |
| 2016 | EXPECT_EQ(OK, out.rv); |
| 2017 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 2018 | EXPECT_EQ("hello!", out.response_data); |
| 2019 | } |
| 2020 | |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 2021 | // Test that a simple POST works. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2022 | TEST_P(SpdyNetworkTransactionTest, EmptyPost) { |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 2023 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 2024 | // Create an empty UploadDataStream. |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 2025 | ScopedVector<UploadElementReader> element_readers; |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 2026 | UploadDataStream stream(element_readers.Pass(), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 2027 | |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 2028 | // Setup the request |
| 2029 | HttpRequestInfo request; |
| 2030 | request.method = "POST"; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2031 | request.url = GURL(kRequestUrl); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 2032 | request.upload_data_stream = &stream; |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 2033 | |
[email protected] | ad91dc5 | 2012-09-01 03:46:06 | [diff] [blame] | 2034 | const uint64 kContentLength = 0; |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 2035 | |
| 2036 | SpdySynStreamIR syn_ir(1); |
| 2037 | syn_ir.set_name_value_block( |
| 2038 | *spdy_util_.ConstructPostHeaderBlock(kRequestUrl, kContentLength)); |
| 2039 | syn_ir.set_fin(true); // No body. |
| 2040 | syn_ir.set_priority(ConvertRequestPriorityToSpdyPriority( |
| 2041 | LOWEST, spdy_util_.spdy_version())); |
| 2042 | scoped_ptr<SpdyFrame> req(framer.SerializeFrame(syn_ir)); |
| 2043 | |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 2044 | MockWrite writes[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2045 | CreateMockWrite(*req), |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 2046 | }; |
| 2047 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2048 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 2049 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 2050 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2051 | CreateMockRead(*resp), |
| 2052 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2053 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 2054 | }; |
| 2055 | |
[email protected] | bf3eb00 | 2012-11-15 05:50:11 | [diff] [blame] | 2056 | DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 2057 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2058 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 2059 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2060 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2061 | TransactionHelperResult out = helper.output(); |
[email protected] | edd3b0a5 | 2009-11-24 18:56:36 | [diff] [blame] | 2062 | EXPECT_EQ(OK, out.rv); |
| 2063 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 2064 | EXPECT_EQ("hello!", out.response_data); |
| 2065 | } |
| 2066 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 2067 | // While we're doing a post, the server sends the reply before upload completes. |
| 2068 | TEST_P(SpdyNetworkTransactionTest, ResponseBeforePostCompletes) { |
| 2069 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 2070 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2071 | MockWrite writes[] = { |
| 2072 | CreateMockWrite(*req, 0), |
| 2073 | CreateMockWrite(*body, 3), |
| 2074 | }; |
| 2075 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
[email protected] | a5566f970 | 2010-05-05 22:25:43 | [diff] [blame] | 2076 | MockRead reads[] = { |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 2077 | CreateMockRead(*resp, 1), |
| 2078 | CreateMockRead(*body, 2), |
[email protected] | 099bc7e | 2013-07-18 04:19:16 | [diff] [blame] | 2079 | MockRead(ASYNC, 0, 4) // EOF |
[email protected] | a5566f970 | 2010-05-05 22:25:43 | [diff] [blame] | 2080 | }; |
| 2081 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 2082 | // Write the request headers, and read the complete response |
| 2083 | // while still waiting for chunked request data. |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 2084 | DeterministicSocketData data(reads, arraysize(reads), |
| 2085 | writes, arraysize(writes)); |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 2086 | NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
| 2087 | DEFAULT_PRIORITY, |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 2088 | BoundNetLog(), GetParam(), NULL); |
| 2089 | helper.SetDeterministic(); |
| 2090 | helper.RunPreTestSetup(); |
| 2091 | helper.AddDeterministicData(&data); |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 2092 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 2093 | ASSERT_TRUE(helper.StartDefaultTest()); |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 2094 | |
[email protected] | 35c3fc73 | 2014-02-15 00:16:07 | [diff] [blame] | 2095 | // Process the request headers, SYN_REPLY, and response body. |
| 2096 | // The request body is still in flight. |
| 2097 | data.RunFor(3); |
| 2098 | |
| 2099 | const HttpResponseInfo* response = helper.trans()->GetResponseInfo(); |
| 2100 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2101 | |
| 2102 | // Finish sending the request body. |
| 2103 | helper.request().upload_data_stream->AppendChunk( |
| 2104 | kUploadData, kUploadDataSize, true); |
| 2105 | data.RunFor(2); |
| 2106 | |
| 2107 | std::string response_body; |
| 2108 | EXPECT_EQ(OK, ReadTransaction(helper.trans(), &response_body)); |
| 2109 | EXPECT_EQ(kUploadData, response_body); |
| 2110 | helper.VerifyDataConsumed(); |
[email protected] | a5566f970 | 2010-05-05 22:25:43 | [diff] [blame] | 2111 | } |
| 2112 | |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2113 | // The client upon cancellation tries to send a RST_STREAM frame. The mock |
| 2114 | // socket causes the TCP write to return zero. This test checks that the client |
| 2115 | // tries to queue up the RST_STREAM frame again. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2116 | TEST_P(SpdyNetworkTransactionTest, SocketWriteReturnsZero) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2117 | scoped_ptr<SpdyFrame> req( |
| 2118 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2119 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2120 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2121 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2122 | CreateMockWrite(*req.get(), 0, SYNCHRONOUS), |
| 2123 | MockWrite(SYNCHRONOUS, 0, 0, 2), |
| 2124 | CreateMockWrite(*rst.get(), 3, SYNCHRONOUS), |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2125 | }; |
| 2126 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2127 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2128 | MockRead reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2129 | CreateMockRead(*resp.get(), 1, ASYNC), |
| 2130 | MockRead(ASYNC, 0, 0, 4) // EOF |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2131 | }; |
| 2132 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2133 | DeterministicSocketData data(reads, arraysize(reads), |
| 2134 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2135 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2136 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2137 | helper.SetDeterministic(); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2138 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2139 | helper.AddDeterministicData(&data); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2140 | HttpNetworkTransaction* trans = helper.trans(); |
| 2141 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2142 | TestCompletionCallback callback; |
| 2143 | int rv = trans->Start( |
| 2144 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2145 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2146 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2147 | data.SetStop(2); |
| 2148 | data.Run(); |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2149 | helper.ResetTrans(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2150 | data.SetStop(20); |
| 2151 | data.Run(); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2152 | |
[email protected] | f9a26d7 | 2010-08-03 18:07:13 | [diff] [blame] | 2153 | helper.VerifyDataConsumed(); |
| 2154 | } |
| 2155 | |
[email protected] | 9330067 | 2009-10-24 13:22:51 | [diff] [blame] | 2156 | // 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] | 2157 | TEST_P(SpdyNetworkTransactionTest, ResponseWithoutSynReply) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2158 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | ff57bb8 | 2009-11-12 06:52:14 | [diff] [blame] | 2159 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2160 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2161 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 9330067 | 2009-10-24 13:22:51 | [diff] [blame] | 2162 | }; |
| 2163 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2164 | DelayedSocketData data(1, reads, arraysize(reads), NULL, 0); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2165 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2166 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2167 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2168 | TransactionHelperResult out = helper.output(); |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 2169 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | 9330067 | 2009-10-24 13:22:51 | [diff] [blame] | 2170 | } |
| 2171 | |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2172 | // Test that the transaction doesn't crash when we get two replies on the same |
| 2173 | // stream ID. See http://crbug.com/45639. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2174 | TEST_P(SpdyNetworkTransactionTest, ResponseWithTwoSynReplies) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2175 | scoped_ptr<SpdyFrame> req( |
| 2176 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 2177 | scoped_ptr<SpdyFrame> rst( |
[email protected] | 00b2947 | 2014-01-16 18:10:24 | [diff] [blame] | 2178 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | 2aeef78 | 2013-06-21 18:30:56 | [diff] [blame] | 2179 | MockWrite writes[] = { |
| 2180 | CreateMockWrite(*req), |
| 2181 | CreateMockWrite(*rst), |
| 2182 | }; |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2183 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2184 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2185 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2186 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2187 | CreateMockRead(*resp), |
| 2188 | CreateMockRead(*resp), |
| 2189 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2190 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2191 | }; |
| 2192 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2193 | DelayedSocketData data(1, reads, arraysize(reads), |
| 2194 | writes, arraysize(writes)); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2195 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2196 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2197 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2198 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2199 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2200 | |
| 2201 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2202 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2203 | TestCompletionCallback callback; |
| 2204 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2205 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2206 | rv = callback.WaitForResult(); |
| 2207 | EXPECT_EQ(OK, rv); |
| 2208 | |
| 2209 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | a5c493b9 | 2010-08-06 23:04:29 | [diff] [blame] | 2210 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2211 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2212 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 2213 | std::string response_data; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2214 | rv = ReadTransaction(trans, &response_data); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2215 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, rv); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2216 | |
| 2217 | helper.VerifyDataConsumed(); |
[email protected] | d3002235 | 2010-06-24 19:17:58 | [diff] [blame] | 2218 | } |
| 2219 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2220 | TEST_P(SpdyNetworkTransactionTest, ResetReplyWithTransferEncoding) { |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2221 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2222 | scoped_ptr<SpdyFrame> req( |
| 2223 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 2224 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2225 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2226 | MockWrite writes[] = { |
| 2227 | CreateMockWrite(*req), |
| 2228 | CreateMockWrite(*rst), |
| 2229 | }; |
| 2230 | |
| 2231 | const char* const headers[] = { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2232 | "transfer-encoding", "chunked" |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2233 | }; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2234 | scoped_ptr<SpdyFrame> resp( |
| 2235 | spdy_util_.ConstructSpdyGetSynReply(headers, 1, 1)); |
| 2236 | scoped_ptr<SpdyFrame> body( |
| 2237 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2238 | MockRead reads[] = { |
| 2239 | CreateMockRead(*resp), |
| 2240 | CreateMockRead(*body), |
| 2241 | MockRead(ASYNC, 0, 0) // EOF |
| 2242 | }; |
| 2243 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2244 | DelayedSocketData data(1, reads, arraysize(reads), |
| 2245 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2246 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2247 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2248 | helper.RunToCompletion(&data); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2249 | TransactionHelperResult out = helper.output(); |
| 2250 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 2251 | |
| 2252 | helper.session()->spdy_session_pool()->CloseAllSessions(); |
| 2253 | helper.VerifyDataConsumed(); |
| 2254 | } |
| 2255 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2256 | TEST_P(SpdyNetworkTransactionTest, ResetPushWithTransferEncoding) { |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2257 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2258 | scoped_ptr<SpdyFrame> req( |
| 2259 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 2260 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2261 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2262 | MockWrite writes[] = { |
| 2263 | CreateMockWrite(*req), |
| 2264 | CreateMockWrite(*rst), |
| 2265 | }; |
| 2266 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2267 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2268 | const char* const headers[] = { |
| 2269 | "transfer-encoding", "chunked" |
| 2270 | }; |
| 2271 | scoped_ptr<SpdyFrame> push( |
| 2272 | spdy_util_.ConstructSpdyPush(headers, arraysize(headers) / 2, |
| 2273 | 2, 1, "http://www.google.com/1")); |
| 2274 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2275 | MockRead reads[] = { |
| 2276 | CreateMockRead(*resp), |
| 2277 | CreateMockRead(*push), |
| 2278 | CreateMockRead(*body), |
| 2279 | MockRead(ASYNC, 0, 0) // EOF |
| 2280 | }; |
| 2281 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2282 | DelayedSocketData data(1, reads, arraysize(reads), |
| 2283 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2284 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2285 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2286 | helper.RunToCompletion(&data); |
[email protected] | b350300 | 2012-03-27 04:57:25 | [diff] [blame] | 2287 | TransactionHelperResult out = helper.output(); |
| 2288 | EXPECT_EQ(OK, out.rv); |
| 2289 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 2290 | EXPECT_EQ("hello!", out.response_data); |
| 2291 | |
| 2292 | helper.session()->spdy_session_pool()->CloseAllSessions(); |
| 2293 | helper.VerifyDataConsumed(); |
| 2294 | } |
| 2295 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2296 | TEST_P(SpdyNetworkTransactionTest, CancelledTransaction) { |
[email protected] | 75f30cc2 | 2010-06-28 21:41:38 | [diff] [blame] | 2297 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2298 | scoped_ptr<SpdyFrame> req( |
| 2299 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2300 | MockWrite writes[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2301 | CreateMockWrite(*req), |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2302 | }; |
| 2303 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2304 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2305 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2306 | CreateMockRead(*resp), |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2307 | // This following read isn't used by the test, except during the |
[email protected] | b4c62eb | 2012-11-14 18:36:51 | [diff] [blame] | 2308 | // RunUntilIdle() call at the end since the SpdySession survives the |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2309 | // HttpNetworkTransaction and still tries to continue Read()'ing. Any |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2310 | // MockRead will do here. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2311 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2312 | }; |
| 2313 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2314 | StaticSocketDataProvider data(reads, arraysize(reads), |
| 2315 | writes, arraysize(writes)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2316 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2317 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2318 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2319 | helper.RunPreTestSetup(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2320 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2321 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2322 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2323 | TestCompletionCallback callback; |
| 2324 | int rv = trans->Start( |
| 2325 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2326 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2327 | helper.ResetTrans(); // Cancel the transaction. |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2328 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 2329 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2330 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2331 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2332 | helper.VerifyDataNotConsumed(); |
[email protected] | 34437af8 | 2009-11-06 02:28:49 | [diff] [blame] | 2333 | } |
[email protected] | 72552f0 | 2009-10-28 15:25:01 | [diff] [blame] | 2334 | |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2335 | // Verify that the client sends a Rst Frame upon cancelling the stream. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2336 | TEST_P(SpdyNetworkTransactionTest, CancelledTransactionSendRst) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2337 | scoped_ptr<SpdyFrame> req( |
| 2338 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2339 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2340 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2341 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2342 | CreateMockWrite(*req, 0, SYNCHRONOUS), |
| 2343 | CreateMockWrite(*rst, 2, SYNCHRONOUS), |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2344 | }; |
| 2345 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2346 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2347 | MockRead reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2348 | CreateMockRead(*resp, 1, ASYNC), |
| 2349 | MockRead(ASYNC, 0, 0, 3) // EOF |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2350 | }; |
| 2351 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2352 | DeterministicSocketData data(reads, arraysize(reads), |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2353 | writes, arraysize(writes)); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2354 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2355 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2356 | BoundNetLog(), |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2357 | GetParam(), NULL); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2358 | helper.SetDeterministic(); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2359 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2360 | helper.AddDeterministicData(&data); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2361 | HttpNetworkTransaction* trans = helper.trans(); |
| 2362 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2363 | TestCompletionCallback callback; |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2364 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2365 | int rv = trans->Start( |
| 2366 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2367 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2368 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2369 | data.SetStop(2); |
| 2370 | data.Run(); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2371 | helper.ResetTrans(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2372 | data.SetStop(20); |
| 2373 | data.Run(); |
[email protected] | 3b782843 | 2010-08-18 18:33:27 | [diff] [blame] | 2374 | |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 2375 | helper.VerifyDataConsumed(); |
| 2376 | } |
| 2377 | |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2378 | // Verify that the client can correctly deal with the user callback attempting |
| 2379 | // to start another transaction on a session that is closing down. See |
| 2380 | // http://crbug.com/47455 |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2381 | TEST_P(SpdyNetworkTransactionTest, StartTransactionOnReadCallback) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2382 | scoped_ptr<SpdyFrame> req( |
| 2383 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2384 | MockWrite writes[] = { CreateMockWrite(*req) }; |
| 2385 | MockWrite writes2[] = { CreateMockWrite(*req) }; |
| 2386 | |
[email protected] | cbdd7316 | 2013-03-18 23:27:33 | [diff] [blame] | 2387 | // The indicated length of this frame is longer than its actual length. When |
| 2388 | // the session receives an empty frame after this one, it shuts down the |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2389 | // session, and calls the read callback with the incomplete data. |
| 2390 | const uint8 kGetBodyFrame2[] = { |
| 2391 | 0x00, 0x00, 0x00, 0x01, |
| 2392 | 0x01, 0x00, 0x00, 0x07, |
| 2393 | 'h', 'e', 'l', 'l', 'o', '!', |
| 2394 | }; |
| 2395 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2396 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2397 | MockRead reads[] = { |
| 2398 | CreateMockRead(*resp, 2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2399 | MockRead(ASYNC, ERR_IO_PENDING, 3), // Force a pause |
| 2400 | MockRead(ASYNC, reinterpret_cast<const char*>(kGetBodyFrame2), |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2401 | arraysize(kGetBodyFrame2), 4), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2402 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
| 2403 | MockRead(ASYNC, 0, 0, 6), // EOF |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2404 | }; |
| 2405 | MockRead reads2[] = { |
| 2406 | CreateMockRead(*resp, 2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2407 | MockRead(ASYNC, 0, 0, 3), // EOF |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2408 | }; |
| 2409 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2410 | OrderedSocketData data(reads, arraysize(reads), |
| 2411 | writes, arraysize(writes)); |
| 2412 | DelayedSocketData data2(1, reads2, arraysize(reads2), |
| 2413 | writes2, arraysize(writes2)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2414 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2415 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2416 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2417 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2418 | helper.AddData(&data); |
| 2419 | helper.AddData(&data2); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2420 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2421 | |
| 2422 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2423 | TestCompletionCallback callback; |
| 2424 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2425 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2426 | rv = callback.WaitForResult(); |
| 2427 | |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2428 | const int kSize = 3000; |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 2429 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2430 | rv = trans->Read( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2431 | buf.get(), |
| 2432 | kSize, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2433 | base::Bind(&SpdyNetworkTransactionTest::StartTransactionCallback, |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2434 | helper.session())); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2435 | // This forces an err_IO_pending, which sets the callback. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2436 | data.CompleteRead(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2437 | // This finishes the read. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2438 | data.CompleteRead(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2439 | helper.VerifyDataConsumed(); |
[email protected] | b278eb7 | 2010-07-09 20:17:00 | [diff] [blame] | 2440 | } |
| 2441 | |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2442 | // Verify that the client can correctly deal with the user callback deleting the |
| 2443 | // transaction. Failures will usually be valgrind errors. See |
| 2444 | // http://crbug.com/46925 |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2445 | TEST_P(SpdyNetworkTransactionTest, DeleteSessionOnReadCallback) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2446 | scoped_ptr<SpdyFrame> req( |
| 2447 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2448 | MockWrite writes[] = { CreateMockWrite(*req) }; |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2449 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2450 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2451 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2452 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2453 | CreateMockRead(*resp.get(), 2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2454 | MockRead(ASYNC, ERR_IO_PENDING, 3), // Force a pause |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 2455 | CreateMockRead(*body.get(), 4), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2456 | MockRead(ASYNC, 0, 0, 5), // EOF |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2457 | }; |
| 2458 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2459 | OrderedSocketData data(reads, arraysize(reads), |
| 2460 | writes, arraysize(writes)); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2461 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2462 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2463 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2464 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2465 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2466 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2467 | |
| 2468 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2469 | TestCompletionCallback callback; |
| 2470 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2471 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2472 | rv = callback.WaitForResult(); |
| 2473 | |
| 2474 | // Setup a user callback which will delete the session, and clear out the |
| 2475 | // memory holding the stream object. Note that the callback deletes trans. |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2476 | const int kSize = 3000; |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 2477 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2478 | rv = trans->Read( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2479 | buf.get(), |
| 2480 | kSize, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2481 | base::Bind(&SpdyNetworkTransactionTest::DeleteSessionCallback, |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2482 | base::Unretained(&helper))); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2483 | ASSERT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2484 | data.CompleteRead(); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2485 | |
| 2486 | // Finish running rest of tasks. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2487 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 2488 | helper.VerifyDataConsumed(); |
[email protected] | 9be804c8 | 2010-06-24 17:59:46 | [diff] [blame] | 2489 | } |
| 2490 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2491 | // Send a spdy request to www.google.com that gets redirected to www.foo.com. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2492 | TEST_P(SpdyNetworkTransactionTest, RedirectGetRequest) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2493 | const SpdyHeaderInfo kSynStartHeader = spdy_util_.MakeSpdyHeader(SYN_STREAM); |
| 2494 | scoped_ptr<SpdyHeaderBlock> headers( |
| 2495 | spdy_util_.ConstructGetHeaderBlock("http://www.google.com/")); |
| 2496 | (*headers)["user-agent"] = ""; |
| 2497 | (*headers)["accept-encoding"] = "gzip,deflate"; |
| 2498 | scoped_ptr<SpdyHeaderBlock> headers2( |
| 2499 | spdy_util_.ConstructGetHeaderBlock("http://www.foo.com/index.php")); |
| 2500 | (*headers2)["user-agent"] = ""; |
| 2501 | (*headers2)["accept-encoding"] = "gzip,deflate"; |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2502 | |
| 2503 | // Setup writes/reads to www.google.com |
[email protected] | 9ec54f8 | 2013-05-10 02:53:05 | [diff] [blame] | 2504 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyFrame( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2505 | kSynStartHeader, headers.Pass())); |
[email protected] | 9ec54f8 | 2013-05-10 02:53:05 | [diff] [blame] | 2506 | scoped_ptr<SpdyFrame> req2(spdy_util_.ConstructSpdyFrame( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2507 | kSynStartHeader, headers2.Pass())); |
| 2508 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReplyRedirect(1)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2509 | MockWrite writes[] = { |
| 2510 | CreateMockWrite(*req, 1), |
| 2511 | }; |
| 2512 | MockRead reads[] = { |
| 2513 | CreateMockRead(*resp, 2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2514 | MockRead(ASYNC, 0, 0, 3) // EOF |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2515 | }; |
| 2516 | |
| 2517 | // Setup writes/reads to www.foo.com |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2518 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2519 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2520 | MockWrite writes2[] = { |
| 2521 | CreateMockWrite(*req2, 1), |
| 2522 | }; |
| 2523 | MockRead reads2[] = { |
| 2524 | CreateMockRead(*resp2, 2), |
| 2525 | CreateMockRead(*body2, 3), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2526 | MockRead(ASYNC, 0, 0, 4) // EOF |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2527 | }; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2528 | OrderedSocketData data(reads, arraysize(reads), |
| 2529 | writes, arraysize(writes)); |
| 2530 | OrderedSocketData data2(reads2, arraysize(reads2), |
| 2531 | writes2, arraysize(writes2)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2532 | |
| 2533 | // TODO(erikchen): Make test support SPDYSSL, SPDYNPN |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 2534 | HttpStreamFactory::set_force_spdy_over_ssl(false); |
| 2535 | HttpStreamFactory::set_force_spdy_always(true); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2536 | TestDelegate d; |
| 2537 | { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2538 | SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); |
[email protected] | 2ca01e5 | 2013-10-31 22:05:19 | [diff] [blame] | 2539 | net::URLRequest r(GURL("http://www.google.com/"), |
| 2540 | DEFAULT_PRIORITY, |
| 2541 | &d, |
| 2542 | &spdy_url_request_context); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2543 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2544 | AddSocketDataProvider(&data); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2545 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2546 | AddSocketDataProvider(&data2); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2547 | |
| 2548 | d.set_quit_on_redirect(true); |
| 2549 | r.Start(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2550 | base::RunLoop().Run(); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2551 | |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2552 | EXPECT_EQ(1, d.received_redirect_count()); |
| 2553 | |
| 2554 | r.FollowDeferredRedirect(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2555 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2556 | EXPECT_EQ(1, d.response_started_count()); |
| 2557 | EXPECT_FALSE(d.received_data_before_response()); |
[email protected] | f90bf0d9 | 2011-01-13 02:12:44 | [diff] [blame] | 2558 | EXPECT_EQ(net::URLRequestStatus::SUCCESS, r.status().status()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2559 | std::string contents("hello!"); |
| 2560 | EXPECT_EQ(contents, d.data_received()); |
| 2561 | } |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2562 | EXPECT_TRUE(data.at_read_eof()); |
| 2563 | EXPECT_TRUE(data.at_write_eof()); |
| 2564 | EXPECT_TRUE(data2.at_read_eof()); |
| 2565 | EXPECT_TRUE(data2.at_write_eof()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2566 | } |
| 2567 | |
| 2568 | // Send a spdy request to www.google.com. Get a pushed stream that redirects to |
| 2569 | // www.foo.com. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2570 | TEST_P(SpdyNetworkTransactionTest, RedirectServerPush) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2571 | const SpdyHeaderInfo kSynStartHeader = spdy_util_.MakeSpdyHeader(SYN_STREAM); |
| 2572 | |
| 2573 | scoped_ptr<SpdyHeaderBlock> headers( |
| 2574 | spdy_util_.ConstructGetHeaderBlock("http://www.google.com/")); |
| 2575 | (*headers)["user-agent"] = ""; |
| 2576 | (*headers)["accept-encoding"] = "gzip,deflate"; |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2577 | |
| 2578 | // Setup writes/reads to www.google.com |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2579 | scoped_ptr<SpdyFrame> req( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2580 | spdy_util_.ConstructSpdyFrame(kSynStartHeader, headers.Pass())); |
| 2581 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2582 | scoped_ptr<SpdyFrame> rep( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2583 | spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2584 | 0, |
| 2585 | 2, |
| 2586 | 1, |
| 2587 | "http://www.google.com/foo.dat", |
| 2588 | "301 Moved Permanently", |
| 2589 | "http://www.foo.com/index.php")); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2590 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2591 | scoped_ptr<SpdyFrame> rst( |
| 2592 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_CANCEL)); |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2593 | MockWrite writes[] = { |
| 2594 | CreateMockWrite(*req, 1), |
| 2595 | CreateMockWrite(*rst, 6), |
| 2596 | }; |
| 2597 | MockRead reads[] = { |
| 2598 | CreateMockRead(*resp, 2), |
| 2599 | CreateMockRead(*rep, 3), |
| 2600 | CreateMockRead(*body, 4), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2601 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
| 2602 | MockRead(ASYNC, 0, 0, 7) // EOF |
[email protected] | 3a8d685 | 2011-03-11 23:43:44 | [diff] [blame] | 2603 | }; |
| 2604 | |
| 2605 | // Setup writes/reads to www.foo.com |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2606 | scoped_ptr<SpdyHeaderBlock> headers2( |
| 2607 | spdy_util_.ConstructGetHeaderBlock("http://www.foo.com/index.php")); |
| 2608 | (*headers2)["user-agent"] = ""; |
| 2609 | (*headers2)["accept-encoding"] = "gzip,deflate"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2610 | scoped_ptr<SpdyFrame> req2( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2611 | spdy_util_.ConstructSpdyFrame(kSynStartHeader, headers2.Pass())); |
| 2612 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2613 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2614 | MockWrite writes2[] = { |
| 2615 | CreateMockWrite(*req2, 1), |
| 2616 | }; |
| 2617 | MockRead reads2[] = { |
| 2618 | CreateMockRead(*resp2, 2), |
| 2619 | CreateMockRead(*body2, 3), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2620 | MockRead(ASYNC, 0, 0, 5) // EOF |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2621 | }; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2622 | OrderedSocketData data(reads, arraysize(reads), |
| 2623 | writes, arraysize(writes)); |
| 2624 | OrderedSocketData data2(reads2, arraysize(reads2), |
| 2625 | writes2, arraysize(writes2)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2626 | |
| 2627 | // TODO(erikchen): Make test support SPDYSSL, SPDYNPN |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 2628 | HttpStreamFactory::set_force_spdy_over_ssl(false); |
| 2629 | HttpStreamFactory::set_force_spdy_always(true); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2630 | TestDelegate d; |
| 2631 | TestDelegate d2; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2632 | SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2633 | { |
[email protected] | 2ca01e5 | 2013-10-31 22:05:19 | [diff] [blame] | 2634 | net::URLRequest r(GURL("http://www.google.com/"), |
| 2635 | DEFAULT_PRIORITY, |
| 2636 | &d, |
| 2637 | &spdy_url_request_context); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2638 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2639 | AddSocketDataProvider(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2640 | |
| 2641 | r.Start(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2642 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2643 | |
| 2644 | EXPECT_EQ(0, d.received_redirect_count()); |
| 2645 | std::string contents("hello!"); |
| 2646 | EXPECT_EQ(contents, d.data_received()); |
| 2647 | |
[email protected] | 2ca01e5 | 2013-10-31 22:05:19 | [diff] [blame] | 2648 | net::URLRequest r2(GURL("http://www.google.com/foo.dat"), |
| 2649 | DEFAULT_PRIORITY, |
| 2650 | &d2, |
| 2651 | &spdy_url_request_context); |
[email protected] | ef2bf42 | 2012-05-11 03:27:09 | [diff] [blame] | 2652 | spdy_url_request_context.socket_factory(). |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2653 | AddSocketDataProvider(&data2); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2654 | |
| 2655 | d2.set_quit_on_redirect(true); |
| 2656 | r2.Start(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2657 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2658 | EXPECT_EQ(1, d2.received_redirect_count()); |
| 2659 | |
| 2660 | r2.FollowDeferredRedirect(); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 2661 | base::RunLoop().Run(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2662 | EXPECT_EQ(1, d2.response_started_count()); |
| 2663 | EXPECT_FALSE(d2.received_data_before_response()); |
[email protected] | f90bf0d9 | 2011-01-13 02:12:44 | [diff] [blame] | 2664 | EXPECT_EQ(net::URLRequestStatus::SUCCESS, r2.status().status()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2665 | std::string contents2("hello!"); |
| 2666 | EXPECT_EQ(contents2, d2.data_received()); |
| 2667 | } |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2668 | data.CompleteRead(); |
| 2669 | data2.CompleteRead(); |
| 2670 | EXPECT_TRUE(data.at_read_eof()); |
| 2671 | EXPECT_TRUE(data.at_write_eof()); |
| 2672 | EXPECT_TRUE(data2.at_read_eof()); |
| 2673 | EXPECT_TRUE(data2.at_write_eof()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2674 | } |
| 2675 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2676 | TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2677 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2678 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2679 | scoped_ptr<SpdyFrame> stream1_body( |
| 2680 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2681 | MockWrite writes[] = { |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2682 | CreateMockWrite(*stream1_syn, 1), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2683 | }; |
| 2684 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2685 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2686 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2687 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2688 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2689 | 0, |
| 2690 | 2, |
| 2691 | 1, |
| 2692 | "http://www.google.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2693 | const char kPushedData[] = "pushed"; |
| 2694 | scoped_ptr<SpdyFrame> stream2_body( |
| 2695 | spdy_util_.ConstructSpdyBodyFrame( |
| 2696 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2697 | MockRead reads[] = { |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2698 | CreateMockRead(*stream1_reply, 2), |
| 2699 | CreateMockRead(*stream2_syn, 3), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2700 | CreateMockRead(*stream1_body, 4, SYNCHRONOUS), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2701 | CreateMockRead(*stream2_body, 5), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2702 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2703 | }; |
| 2704 | |
| 2705 | HttpResponseInfo response; |
| 2706 | HttpResponseInfo response2; |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2707 | std::string expected_push_result("pushed"); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2708 | OrderedSocketData data(reads, arraysize(reads), |
| 2709 | writes, arraysize(writes)); |
| 2710 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2711 | &response, |
| 2712 | &response2, |
| 2713 | expected_push_result); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2714 | |
| 2715 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2716 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2717 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2718 | |
| 2719 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2720 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2721 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2722 | } |
| 2723 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2724 | TEST_P(SpdyNetworkTransactionTest, ServerPushBeforeSynReply) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2725 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2726 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2727 | scoped_ptr<SpdyFrame> stream1_body( |
| 2728 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2729 | MockWrite writes[] = { |
| 2730 | CreateMockWrite(*stream1_syn, 1), |
| 2731 | }; |
| 2732 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2733 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2734 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2735 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2736 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2737 | 0, |
| 2738 | 2, |
| 2739 | 1, |
| 2740 | "http://www.google.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2741 | const char kPushedData[] = "pushed"; |
| 2742 | scoped_ptr<SpdyFrame> stream2_body( |
| 2743 | spdy_util_.ConstructSpdyBodyFrame( |
| 2744 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2745 | MockRead reads[] = { |
| 2746 | CreateMockRead(*stream2_syn, 2), |
| 2747 | CreateMockRead(*stream1_reply, 3), |
| 2748 | CreateMockRead(*stream1_body, 4, SYNCHRONOUS), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2749 | CreateMockRead(*stream2_body, 5), |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2750 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 2751 | }; |
| 2752 | |
| 2753 | HttpResponseInfo response; |
| 2754 | HttpResponseInfo response2; |
| 2755 | std::string expected_push_result("pushed"); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2756 | OrderedSocketData data(reads, arraysize(reads), |
| 2757 | writes, arraysize(writes)); |
| 2758 | RunServerPushTest(&data, |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2759 | &response, |
| 2760 | &response2, |
| 2761 | expected_push_result); |
| 2762 | |
| 2763 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2764 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2765 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2766 | |
| 2767 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2768 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | a5b8eb29d | 2012-03-06 06:19:46 | [diff] [blame] | 2769 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2770 | } |
| 2771 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2772 | TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame2) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2773 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2774 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2775 | MockWrite writes[] = { CreateMockWrite(*stream1_syn, 1), }; |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2776 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2777 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2778 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2779 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2780 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2781 | 0, |
| 2782 | 2, |
| 2783 | 1, |
| 2784 | "http://www.google.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2785 | const char kPushedData[] = "pushed"; |
| 2786 | scoped_ptr<SpdyFrame> stream2_body( |
| 2787 | spdy_util_.ConstructSpdyBodyFrame( |
| 2788 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2789 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2790 | stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2791 | MockRead reads[] = { |
| 2792 | CreateMockRead(*stream1_reply, 2), |
| 2793 | CreateMockRead(*stream2_syn, 3), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2794 | CreateMockRead(*stream2_body, 4), |
| 2795 | CreateMockRead(*stream1_body, 5, SYNCHRONOUS), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2796 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2797 | }; |
| 2798 | |
| 2799 | HttpResponseInfo response; |
| 2800 | HttpResponseInfo response2; |
| 2801 | std::string expected_push_result("pushed"); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2802 | OrderedSocketData data(reads, arraysize(reads), |
| 2803 | writes, arraysize(writes)); |
| 2804 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2805 | &response, |
| 2806 | &response2, |
| 2807 | expected_push_result); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2808 | |
| 2809 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2810 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2811 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2812 | |
| 2813 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2814 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | 82918cc | 2010-08-25 17:24:50 | [diff] [blame] | 2815 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2816 | } |
| 2817 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2818 | TEST_P(SpdyNetworkTransactionTest, ServerPushServerAborted) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2819 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2820 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2821 | scoped_ptr<SpdyFrame> stream1_body( |
| 2822 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2823 | MockWrite writes[] = { |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2824 | CreateMockWrite(*stream1_syn, 1), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2825 | }; |
| 2826 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2827 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2828 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2829 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2830 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2831 | 0, |
| 2832 | 2, |
| 2833 | 1, |
| 2834 | "http://www.google.com/foo.dat")); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2835 | scoped_ptr<SpdyFrame> stream2_rst( |
| 2836 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2837 | MockRead reads[] = { |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2838 | CreateMockRead(*stream1_reply, 2), |
| 2839 | CreateMockRead(*stream2_syn, 3), |
| 2840 | CreateMockRead(*stream2_rst, 4), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2841 | CreateMockRead(*stream1_body, 5, SYNCHRONOUS), |
| 2842 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2843 | }; |
| 2844 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2845 | OrderedSocketData data(reads, arraysize(reads), |
| 2846 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 2847 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 2848 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2849 | |
| 2850 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2851 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2852 | |
| 2853 | HttpNetworkTransaction* trans = helper.trans(); |
| 2854 | |
| 2855 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2856 | TestCompletionCallback callback; |
| 2857 | int rv = trans->Start( |
| 2858 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 2859 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2860 | rv = callback.WaitForResult(); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2861 | EXPECT_EQ(OK, rv); |
| 2862 | |
| 2863 | // Verify that we consumed all test data. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2864 | EXPECT_TRUE(data.at_read_eof()) << "Read count: " |
| 2865 | << data.read_count() |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2866 | << " Read index: " |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2867 | << data.read_index(); |
| 2868 | EXPECT_TRUE(data.at_write_eof()) << "Write count: " |
| 2869 | << data.write_count() |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2870 | << " Write index: " |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2871 | << data.write_index(); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2872 | |
| 2873 | // Verify the SYN_REPLY. |
| 2874 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2875 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2876 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2877 | } |
| 2878 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2879 | // Verify that we don't leak streams and that we properly send a reset |
| 2880 | // if the server pushes the same stream twice. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2881 | TEST_P(SpdyNetworkTransactionTest, ServerPushDuplicate) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2882 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2883 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2884 | scoped_ptr<SpdyFrame> stream1_body( |
| 2885 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 2886 | scoped_ptr<SpdyFrame> stream3_rst( |
| 2887 | spdy_util_.ConstructSpdyRstStream(4, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2888 | MockWrite writes[] = { |
| 2889 | CreateMockWrite(*stream1_syn, 1), |
| 2890 | CreateMockWrite(*stream3_rst, 5), |
| 2891 | }; |
| 2892 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2893 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2894 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[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 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2897 | 0, |
| 2898 | 2, |
| 2899 | 1, |
| 2900 | "http://www.google.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2901 | const char kPushedData[] = "pushed"; |
| 2902 | scoped_ptr<SpdyFrame> stream2_body( |
| 2903 | spdy_util_.ConstructSpdyBodyFrame( |
| 2904 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2905 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2906 | stream3_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2907 | 0, |
| 2908 | 4, |
| 2909 | 1, |
| 2910 | "http://www.google.com/foo.dat")); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2911 | MockRead reads[] = { |
| 2912 | CreateMockRead(*stream1_reply, 2), |
| 2913 | CreateMockRead(*stream2_syn, 3), |
| 2914 | CreateMockRead(*stream3_syn, 4), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2915 | CreateMockRead(*stream1_body, 6, SYNCHRONOUS), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2916 | CreateMockRead(*stream2_body, 7), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2917 | MockRead(ASYNC, ERR_IO_PENDING, 8), // Force a pause |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2918 | }; |
| 2919 | |
| 2920 | HttpResponseInfo response; |
| 2921 | HttpResponseInfo response2; |
| 2922 | std::string expected_push_result("pushed"); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2923 | OrderedSocketData data(reads, arraysize(reads), |
| 2924 | writes, arraysize(writes)); |
| 2925 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2926 | &response, |
| 2927 | &response2, |
| 2928 | expected_push_result); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2929 | |
| 2930 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2931 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2932 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2933 | |
| 2934 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2935 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | fdc165a | 2010-09-03 03:51:29 | [diff] [blame] | 2936 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2937 | } |
| 2938 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2939 | TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrame) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2940 | scoped_ptr<SpdyFrame> stream1_syn( |
| 2941 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2942 | scoped_ptr<SpdyFrame> stream1_body( |
| 2943 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2944 | MockWrite writes[] = { |
| 2945 | CreateMockWrite(*stream1_syn, 1), |
| 2946 | }; |
| 2947 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2948 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2949 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 2950 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2951 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 2952 | 0, |
| 2953 | 2, |
| 2954 | 1, |
| 2955 | "http://www.google.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2956 | static const char kPushedData[] = "pushed my darling hello my baby"; |
| 2957 | scoped_ptr<SpdyFrame> stream2_body_base( |
| 2958 | spdy_util_.ConstructSpdyBodyFrame( |
| 2959 | 2, kPushedData, strlen(kPushedData), true)); |
| 2960 | const size_t kChunkSize = strlen(kPushedData) / 4; |
| 2961 | scoped_ptr<SpdyFrame> stream2_body1( |
| 2962 | new SpdyFrame(stream2_body_base->data(), kChunkSize, false)); |
| 2963 | scoped_ptr<SpdyFrame> stream2_body2( |
| 2964 | new SpdyFrame(stream2_body_base->data() + kChunkSize, kChunkSize, false)); |
| 2965 | scoped_ptr<SpdyFrame> stream2_body3( |
| 2966 | new SpdyFrame(stream2_body_base->data() + 2 * kChunkSize, |
| 2967 | kChunkSize, false)); |
| 2968 | scoped_ptr<SpdyFrame> stream2_body4( |
| 2969 | new SpdyFrame(stream2_body_base->data() + 3 * kChunkSize, |
| 2970 | stream2_body_base->size() - 3 * kChunkSize, false)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2971 | MockRead reads[] = { |
| 2972 | CreateMockRead(*stream1_reply, 2), |
| 2973 | CreateMockRead(*stream2_syn, 3), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2974 | CreateMockRead(*stream2_body1, 4), |
| 2975 | CreateMockRead(*stream2_body2, 5), |
| 2976 | CreateMockRead(*stream2_body3, 6), |
| 2977 | CreateMockRead(*stream2_body4, 7), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2978 | CreateMockRead(*stream1_body, 8, SYNCHRONOUS), |
| 2979 | MockRead(ASYNC, ERR_IO_PENDING, 9), // Force a pause |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2980 | }; |
| 2981 | |
| 2982 | HttpResponseInfo response; |
| 2983 | HttpResponseInfo response2; |
| 2984 | std::string expected_push_result("pushed my darling hello my baby"); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 2985 | OrderedSocketData data(reads, arraysize(reads), |
| 2986 | writes, arraysize(writes)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 2987 | RunServerPushTest(&data, &response, &response2, kPushedData); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2988 | |
| 2989 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2990 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2991 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2992 | |
| 2993 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2994 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 2995 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2996 | } |
| 2997 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 2998 | TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrameInterrupted) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 2999 | scoped_ptr<SpdyFrame> stream1_syn( |
| 3000 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3001 | scoped_ptr<SpdyFrame> stream1_body( |
| 3002 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 3003 | MockWrite writes[] = { |
| 3004 | CreateMockWrite(*stream1_syn, 1), |
| 3005 | }; |
| 3006 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3007 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3008 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3009 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3010 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 3011 | 0, |
| 3012 | 2, |
| 3013 | 1, |
| 3014 | "http://www.google.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 3015 | static const char kPushedData[] = "pushed my darling hello my baby"; |
| 3016 | scoped_ptr<SpdyFrame> stream2_body_base( |
| 3017 | spdy_util_.ConstructSpdyBodyFrame( |
| 3018 | 2, kPushedData, strlen(kPushedData), true)); |
| 3019 | const size_t kChunkSize = strlen(kPushedData) / 4; |
| 3020 | scoped_ptr<SpdyFrame> stream2_body1( |
| 3021 | new SpdyFrame(stream2_body_base->data(), kChunkSize, false)); |
| 3022 | scoped_ptr<SpdyFrame> stream2_body2( |
| 3023 | new SpdyFrame(stream2_body_base->data() + kChunkSize, kChunkSize, false)); |
| 3024 | scoped_ptr<SpdyFrame> stream2_body3( |
| 3025 | new SpdyFrame(stream2_body_base->data() + 2 * kChunkSize, |
| 3026 | kChunkSize, false)); |
| 3027 | scoped_ptr<SpdyFrame> stream2_body4( |
| 3028 | new SpdyFrame(stream2_body_base->data() + 3 * kChunkSize, |
| 3029 | stream2_body_base->size() - 3 * kChunkSize, false)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 3030 | MockRead reads[] = { |
| 3031 | CreateMockRead(*stream1_reply, 2), |
| 3032 | CreateMockRead(*stream2_syn, 3), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 3033 | CreateMockRead(*stream2_body1, 4), |
| 3034 | CreateMockRead(*stream2_body2, 5), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3035 | MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 3036 | CreateMockRead(*stream2_body3, 7), |
| 3037 | CreateMockRead(*stream2_body4, 8), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3038 | CreateMockRead(*stream1_body.get(), 9, SYNCHRONOUS), |
| 3039 | MockRead(ASYNC, ERR_IO_PENDING, 10) // Force a pause. |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 3040 | }; |
| 3041 | |
| 3042 | HttpResponseInfo response; |
| 3043 | HttpResponseInfo response2; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3044 | OrderedSocketData data(reads, arraysize(reads), |
| 3045 | writes, arraysize(writes)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 3046 | RunServerPushTest(&data, &response, &response2, kPushedData); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 3047 | |
| 3048 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3049 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 3050 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 3051 | |
| 3052 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3053 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 3054 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 3055 | } |
| 3056 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3057 | TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID0) { |
[email protected] | 00b2947 | 2014-01-16 18:10:24 | [diff] [blame] | 3058 | if (spdy_util_.spdy_version() == SPDY4) { |
| 3059 | // TODO(jgraettinger): We don't support associated stream |
| 3060 | // checks in SPDY4 yet. |
| 3061 | return; |
| 3062 | } |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3063 | scoped_ptr<SpdyFrame> stream1_syn( |
| 3064 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3065 | scoped_ptr<SpdyFrame> stream1_body( |
| 3066 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3067 | scoped_ptr<SpdyFrame> stream2_rst( |
| 3068 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 3069 | MockWrite writes[] = { |
| 3070 | CreateMockWrite(*stream1_syn, 1), |
| 3071 | CreateMockWrite(*stream2_rst, 4), |
| 3072 | }; |
| 3073 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3074 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3075 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3076 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3077 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 3078 | 0, |
| 3079 | 2, |
| 3080 | 0, |
| 3081 | "http://www.google.com/foo.dat")); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 3082 | MockRead reads[] = { |
| 3083 | CreateMockRead(*stream1_reply, 2), |
| 3084 | CreateMockRead(*stream2_syn, 3), |
| 3085 | CreateMockRead(*stream1_body, 4), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3086 | MockRead(ASYNC, ERR_IO_PENDING, 5) // Force a pause |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 3087 | }; |
| 3088 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3089 | OrderedSocketData data(reads, arraysize(reads), |
| 3090 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3091 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3092 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 3093 | |
| 3094 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3095 | helper.AddData(&data); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 3096 | |
| 3097 | HttpNetworkTransaction* trans = helper.trans(); |
| 3098 | |
| 3099 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3100 | TestCompletionCallback callback; |
| 3101 | int rv = trans->Start( |
| 3102 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 3103 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3104 | rv = callback.WaitForResult(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3105 | EXPECT_EQ(OK, rv); |
| 3106 | |
| 3107 | // Verify that we consumed all test data. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3108 | EXPECT_TRUE(data.at_read_eof()) << "Read count: " |
| 3109 | << data.read_count() |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3110 | << " Read index: " |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3111 | << data.read_index(); |
| 3112 | EXPECT_TRUE(data.at_write_eof()) << "Write count: " |
| 3113 | << data.write_count() |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3114 | << " Write index: " |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3115 | << data.write_index(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3116 | |
| 3117 | // Verify the SYN_REPLY. |
| 3118 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3119 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3120 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 3121 | } |
| 3122 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3123 | TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID9) { |
[email protected] | 00b2947 | 2014-01-16 18:10:24 | [diff] [blame] | 3124 | if (spdy_util_.spdy_version() == SPDY4) { |
| 3125 | // TODO(jgraettinger): We don't support associated stream |
| 3126 | // checks in SPDY4 yet. |
| 3127 | return; |
| 3128 | } |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3129 | scoped_ptr<SpdyFrame> stream1_syn( |
| 3130 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3131 | scoped_ptr<SpdyFrame> stream1_body( |
| 3132 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3133 | scoped_ptr<SpdyFrame> stream2_rst( |
| 3134 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_INVALID_STREAM)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3135 | MockWrite writes[] = { |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 3136 | CreateMockWrite(*stream1_syn, 1), |
| 3137 | CreateMockWrite(*stream2_rst, 4), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3138 | }; |
| 3139 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3140 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3141 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3142 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3143 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 3144 | 0, |
| 3145 | 2, |
| 3146 | 9, |
| 3147 | "http://www.google.com/foo.dat")); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3148 | MockRead reads[] = { |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 3149 | CreateMockRead(*stream1_reply, 2), |
| 3150 | CreateMockRead(*stream2_syn, 3), |
| 3151 | CreateMockRead(*stream1_body, 4), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3152 | MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3153 | }; |
| 3154 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3155 | OrderedSocketData data(reads, arraysize(reads), |
| 3156 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3157 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3158 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3159 | |
| 3160 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3161 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3162 | |
| 3163 | HttpNetworkTransaction* trans = helper.trans(); |
| 3164 | |
| 3165 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3166 | TestCompletionCallback callback; |
| 3167 | int rv = trans->Start( |
| 3168 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3169 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3170 | rv = callback.WaitForResult(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3171 | EXPECT_EQ(OK, rv); |
| 3172 | |
| 3173 | // Verify that we consumed all test data. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3174 | EXPECT_TRUE(data.at_read_eof()) << "Read count: " |
| 3175 | << data.read_count() |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3176 | << " Read index: " |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3177 | << data.read_index(); |
| 3178 | EXPECT_TRUE(data.at_write_eof()) << "Write count: " |
| 3179 | << data.write_count() |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3180 | << " Write index: " |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3181 | << data.write_index(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3182 | |
| 3183 | // Verify the SYN_REPLY. |
| 3184 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3185 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3186 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 3187 | } |
| 3188 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3189 | TEST_P(SpdyNetworkTransactionTest, ServerPushNoURL) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3190 | scoped_ptr<SpdyFrame> stream1_syn( |
| 3191 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3192 | scoped_ptr<SpdyFrame> stream1_body( |
| 3193 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3194 | scoped_ptr<SpdyFrame> stream2_rst( |
| 3195 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3196 | MockWrite writes[] = { |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 3197 | CreateMockWrite(*stream1_syn, 1), |
| 3198 | CreateMockWrite(*stream2_rst, 4), |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3199 | }; |
| 3200 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3201 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3202 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8b9211d | 2013-06-24 05:54:45 | [diff] [blame] | 3203 | scoped_ptr<SpdyHeaderBlock> incomplete_headers(new SpdyHeaderBlock()); |
| 3204 | (*incomplete_headers)["hello"] = "bye"; |
| 3205 | (*incomplete_headers)[spdy_util_.GetStatusKey()] = "200 OK"; |
| 3206 | (*incomplete_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
| 3207 | scoped_ptr<SpdyFrame> stream2_syn( |
| 3208 | spdy_util_.ConstructSpdyControlFrame(incomplete_headers.Pass(), |
| 3209 | false, |
| 3210 | 2, // Stream ID |
| 3211 | LOWEST, |
| 3212 | SYN_STREAM, |
| 3213 | CONTROL_FLAG_NONE, |
| 3214 | // Associated stream ID |
| 3215 | 1)); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3216 | MockRead reads[] = { |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 3217 | CreateMockRead(*stream1_reply, 2), |
| 3218 | CreateMockRead(*stream2_syn, 3), |
| 3219 | CreateMockRead(*stream1_body, 4), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3220 | MockRead(ASYNC, ERR_IO_PENDING, 5) // Force a pause |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3221 | }; |
| 3222 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3223 | OrderedSocketData data(reads, arraysize(reads), |
| 3224 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3225 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3226 | BoundNetLog(), GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3227 | |
| 3228 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3229 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3230 | |
| 3231 | HttpNetworkTransaction* trans = helper.trans(); |
| 3232 | |
| 3233 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3234 | TestCompletionCallback callback; |
| 3235 | int rv = trans->Start( |
| 3236 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3237 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3238 | rv = callback.WaitForResult(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3239 | EXPECT_EQ(OK, rv); |
| 3240 | // Verify that we consumed all test data. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3241 | EXPECT_TRUE(data.at_read_eof()) << "Read count: " |
| 3242 | << data.read_count() |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3243 | << " Read index: " |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3244 | << data.read_index(); |
| 3245 | EXPECT_TRUE(data.at_write_eof()) << "Write count: " |
| 3246 | << data.write_count() |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3247 | << " Write index: " |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3248 | << data.write_index(); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3249 | |
| 3250 | // Verify the SYN_REPLY. |
| 3251 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3252 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 3253 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 3254 | } |
| 3255 | |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3256 | // Verify that various SynReply headers parse correctly through the |
| 3257 | // HTTP layer. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3258 | TEST_P(SpdyNetworkTransactionTest, SynReplyHeaders) { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3259 | struct SynReplyHeadersTests { |
| 3260 | int num_headers; |
| 3261 | const char* extra_headers[5]; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3262 | SpdyHeaderBlock expected_headers; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3263 | } test_cases[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3264 | // This uses a multi-valued cookie header. |
| 3265 | { 2, |
| 3266 | { "cookie", "val1", |
| 3267 | "cookie", "val2", // will get appended separated by NULL |
| 3268 | NULL |
| 3269 | }, |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3270 | }, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3271 | // This is the minimalist set of headers. |
| 3272 | { 0, |
| 3273 | { NULL }, |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3274 | }, |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3275 | // Headers with a comma separated list. |
| 3276 | { 1, |
| 3277 | { "cookie", "val1,val2", |
| 3278 | NULL |
| 3279 | }, |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3280 | } |
| 3281 | }; |
| 3282 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3283 | test_cases[0].expected_headers["cookie"] = "val1"; |
| 3284 | test_cases[0].expected_headers["cookie"] += '\0'; |
| 3285 | test_cases[0].expected_headers["cookie"] += "val2"; |
| 3286 | test_cases[0].expected_headers["hello"] = "bye"; |
| 3287 | test_cases[0].expected_headers["status"] = "200"; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3288 | |
| 3289 | test_cases[1].expected_headers["hello"] = "bye"; |
| 3290 | test_cases[1].expected_headers["status"] = "200"; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3291 | |
| 3292 | test_cases[2].expected_headers["cookie"] = "val1,val2"; |
| 3293 | test_cases[2].expected_headers["hello"] = "bye"; |
| 3294 | test_cases[2].expected_headers["status"] = "200"; |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3295 | |
| 3296 | if (spdy_util_.spdy_version() < SPDY4) { |
| 3297 | // SPDY4/HTTP2 eliminates use of the :version header. |
| 3298 | test_cases[0].expected_headers["version"] = "HTTP/1.1"; |
| 3299 | test_cases[1].expected_headers["version"] = "HTTP/1.1"; |
| 3300 | test_cases[2].expected_headers["version"] = "HTTP/1.1"; |
| 3301 | } |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3302 | |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3303 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3304 | scoped_ptr<SpdyFrame> req( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3305 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3306 | MockWrite writes[] = { CreateMockWrite(*req) }; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3307 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3308 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3309 | spdy_util_.ConstructSpdyGetSynReply(test_cases[i].extra_headers, |
[email protected] | 2bd9302 | 2010-07-17 00:58:44 | [diff] [blame] | 3310 | test_cases[i].num_headers, |
| 3311 | 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3312 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3313 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3314 | CreateMockRead(*resp), |
| 3315 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3316 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3317 | }; |
| 3318 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3319 | DelayedSocketData data(1, reads, arraysize(reads), |
| 3320 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3321 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3322 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3323 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3324 | TransactionHelperResult out = helper.output(); |
| 3325 | |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3326 | EXPECT_EQ(OK, out.rv); |
| 3327 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 3328 | EXPECT_EQ("hello!", out.response_data); |
| 3329 | |
| 3330 | scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; |
| 3331 | EXPECT_TRUE(headers.get() != NULL); |
| 3332 | void* iter = NULL; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3333 | std::string name, value; |
| 3334 | SpdyHeaderBlock header_block; |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3335 | while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3336 | if (header_block[name].empty()) { |
| 3337 | header_block[name] = value; |
| 3338 | } else { |
| 3339 | header_block[name] += '\0'; |
| 3340 | header_block[name] += value; |
| 3341 | } |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3342 | } |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3343 | EXPECT_EQ(test_cases[i].expected_headers, header_block); |
[email protected] | 8b07037 | 2009-11-16 22:01:25 | [diff] [blame] | 3344 | } |
| 3345 | } |
| 3346 | |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3347 | // Verify that various SynReply headers parse vary fields correctly |
| 3348 | // through the HTTP layer, and the response matches the request. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3349 | TEST_P(SpdyNetworkTransactionTest, SynReplyHeadersVary) { |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3350 | static const SpdyHeaderInfo syn_reply_info = { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3351 | SYN_REPLY, // Syn Reply |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 3352 | 1, // Stream ID |
| 3353 | 0, // Associated Stream ID |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3354 | ConvertRequestPriorityToSpdyPriority( |
| 3355 | LOWEST, spdy_util_.spdy_version()), |
| 3356 | kSpdyCredentialSlotUnused, |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3357 | CONTROL_FLAG_NONE, // Control Flags |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 3358 | false, // Compressed |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 3359 | RST_STREAM_INVALID, // Status |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 3360 | NULL, // Data |
| 3361 | 0, // Data Length |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3362 | DATA_FLAG_NONE // Data Flags |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3363 | }; |
| 3364 | // Modify the following data to change/add test cases: |
| 3365 | struct SynReplyTests { |
| 3366 | const SpdyHeaderInfo* syn_reply; |
| 3367 | bool vary_matches; |
| 3368 | int num_headers[2]; |
| 3369 | const char* extra_headers[2][16]; |
| 3370 | } test_cases[] = { |
| 3371 | // Test the case of a multi-valued cookie. When the value is delimited |
| 3372 | // with NUL characters, it needs to be unfolded into multiple headers. |
| 3373 | { |
| 3374 | &syn_reply_info, |
| 3375 | true, |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 3376 | { 1, 4 }, |
| 3377 | { { "cookie", "val1,val2", |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3378 | NULL |
| 3379 | }, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3380 | { "vary", "cookie", |
| 3381 | spdy_util_.GetStatusKey(), "200", |
| 3382 | spdy_util_.GetPathKey(), "/index.php", |
| 3383 | spdy_util_.GetVersionKey(), "HTTP/1.1", |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3384 | NULL |
| 3385 | } |
| 3386 | } |
| 3387 | }, { // Multiple vary fields. |
| 3388 | &syn_reply_info, |
| 3389 | true, |
| 3390 | { 2, 5 }, |
| 3391 | { { "friend", "barney", |
| 3392 | "enemy", "snaggletooth", |
| 3393 | NULL |
| 3394 | }, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3395 | { "vary", "friend", |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3396 | "vary", "enemy", |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3397 | spdy_util_.GetStatusKey(), "200", |
| 3398 | spdy_util_.GetPathKey(), "/index.php", |
| 3399 | spdy_util_.GetVersionKey(), "HTTP/1.1", |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3400 | NULL |
| 3401 | } |
| 3402 | } |
| 3403 | }, { // Test a '*' vary field. |
| 3404 | &syn_reply_info, |
| 3405 | false, |
| 3406 | { 1, 4 }, |
| 3407 | { { "cookie", "val1,val2", |
| 3408 | NULL |
| 3409 | }, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3410 | { "vary", "*", |
| 3411 | spdy_util_.GetStatusKey(), "200", |
| 3412 | spdy_util_.GetPathKey(), "/index.php", |
| 3413 | spdy_util_.GetVersionKey(), "HTTP/1.1", |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3414 | NULL |
| 3415 | } |
| 3416 | } |
| 3417 | }, { // Multiple comma-separated vary fields. |
| 3418 | &syn_reply_info, |
| 3419 | true, |
| 3420 | { 2, 4 }, |
| 3421 | { { "friend", "barney", |
| 3422 | "enemy", "snaggletooth", |
| 3423 | NULL |
| 3424 | }, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3425 | { "vary", "friend,enemy", |
| 3426 | spdy_util_.GetStatusKey(), "200", |
| 3427 | spdy_util_.GetPathKey(), "/index.php", |
| 3428 | spdy_util_.GetVersionKey(), "HTTP/1.1", |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3429 | NULL |
| 3430 | } |
| 3431 | } |
| 3432 | } |
| 3433 | }; |
| 3434 | |
| 3435 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3436 | // Construct the request. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3437 | scoped_ptr<SpdyFrame> frame_req( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3438 | spdy_util_.ConstructSpdyGet(test_cases[i].extra_headers[0], |
| 3439 | test_cases[i].num_headers[0], |
| 3440 | false, 1, LOWEST, true)); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3441 | |
| 3442 | MockWrite writes[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3443 | CreateMockWrite(*frame_req), |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3444 | }; |
| 3445 | |
| 3446 | // Construct the reply. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3447 | scoped_ptr<SpdyFrame> frame_reply( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3448 | spdy_util_.ConstructSpdyFrame(*test_cases[i].syn_reply, |
| 3449 | test_cases[i].extra_headers[1], |
| 3450 | test_cases[i].num_headers[1], |
| 3451 | NULL, |
| 3452 | 0)); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3453 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3454 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3455 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3456 | CreateMockRead(*frame_reply), |
| 3457 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3458 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3459 | }; |
| 3460 | |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3461 | // Attach the headers to the request. |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 3462 | int header_count = test_cases[i].num_headers[0]; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3463 | |
[email protected] | d3cee19d | 2010-06-22 18:42:18 | [diff] [blame] | 3464 | HttpRequestInfo request = CreateGetRequest(); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 3465 | for (int ct = 0; ct < header_count; ct++) { |
| 3466 | const char* header_key = test_cases[i].extra_headers[0][ct * 2]; |
| 3467 | const char* header_value = test_cases[i].extra_headers[0][ct * 2 + 1]; |
| 3468 | request.extra_headers.SetHeader(header_key, header_value); |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3469 | } |
| 3470 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3471 | DelayedSocketData data(1, reads, arraysize(reads), |
| 3472 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3473 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3474 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3475 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3476 | TransactionHelperResult out = helper.output(); |
| 3477 | |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3478 | EXPECT_EQ(OK, out.rv) << i; |
| 3479 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line) << i; |
| 3480 | EXPECT_EQ("hello!", out.response_data) << i; |
| 3481 | |
| 3482 | // Test the response information. |
| 3483 | EXPECT_TRUE(out.response_info.response_time > |
| 3484 | out.response_info.request_time) << i; |
| 3485 | base::TimeDelta test_delay = out.response_info.response_time - |
| 3486 | out.response_info.request_time; |
| 3487 | base::TimeDelta min_expected_delay; |
| 3488 | min_expected_delay.FromMilliseconds(10); |
| 3489 | EXPECT_GT(test_delay.InMillisecondsF(), |
| 3490 | min_expected_delay.InMillisecondsF()) << i; |
| 3491 | EXPECT_EQ(out.response_info.vary_data.is_valid(), |
| 3492 | test_cases[i].vary_matches) << i; |
| 3493 | |
| 3494 | // Check the headers. |
| 3495 | scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; |
| 3496 | ASSERT_TRUE(headers.get() != NULL) << i; |
| 3497 | void* iter = NULL; |
| 3498 | std::string name, value, lines; |
| 3499 | while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
| 3500 | lines.append(name); |
| 3501 | lines.append(": "); |
| 3502 | lines.append(value); |
| 3503 | lines.append("\n"); |
| 3504 | } |
| 3505 | |
| 3506 | // Construct the expected header reply string. |
[email protected] | 9aa32319 | 2013-05-31 21:38:40 | [diff] [blame] | 3507 | SpdyHeaderBlock reply_headers; |
| 3508 | AppendToHeaderBlock(test_cases[i].extra_headers[1], |
| 3509 | test_cases[i].num_headers[1], |
| 3510 | &reply_headers); |
| 3511 | std::string expected_reply = |
| 3512 | spdy_util_.ConstructSpdyReplyString(reply_headers); |
| 3513 | EXPECT_EQ(expected_reply, lines) << i; |
[email protected] | 3f662f1 | 2010-03-25 19:56:12 | [diff] [blame] | 3514 | } |
| 3515 | } |
| 3516 | |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3517 | // Verify that we don't crash on invalid SynReply responses. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3518 | TEST_P(SpdyNetworkTransactionTest, InvalidSynReply) { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3519 | const SpdyHeaderInfo kSynStartHeader = { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3520 | SYN_REPLY, // Kind = SynReply |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 3521 | 1, // Stream ID |
| 3522 | 0, // Associated stream ID |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3523 | ConvertRequestPriorityToSpdyPriority( |
| 3524 | LOWEST, spdy_util_.spdy_version()), |
| 3525 | kSpdyCredentialSlotUnused, |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3526 | CONTROL_FLAG_NONE, // Control Flags |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 3527 | false, // Compressed |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 3528 | RST_STREAM_INVALID, // Status |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 3529 | NULL, // Data |
| 3530 | 0, // Length |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3531 | DATA_FLAG_NONE // Data Flags |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3532 | }; |
| 3533 | |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3534 | struct InvalidSynReplyTests { |
| 3535 | int num_headers; |
| 3536 | const char* headers[10]; |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3537 | } test_cases[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3538 | // SYN_REPLY missing status header |
| 3539 | { 4, |
| 3540 | { "cookie", "val1", |
| 3541 | "cookie", "val2", |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3542 | spdy_util_.GetPathKey(), "/index.php", |
| 3543 | spdy_util_.GetVersionKey(), "HTTP/1.1", |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3544 | NULL |
| 3545 | }, |
| 3546 | }, |
| 3547 | // SYN_REPLY missing version header |
| 3548 | { 2, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3549 | { "status", "200", |
| 3550 | spdy_util_.GetPathKey(), "/index.php", |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3551 | NULL |
| 3552 | }, |
| 3553 | }, |
[email protected] | 0d384bb | 2010-07-14 01:51:12 | [diff] [blame] | 3554 | // SYN_REPLY with no headers |
| 3555 | { 0, { NULL }, }, |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3556 | }; |
| 3557 | |
| 3558 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3559 | scoped_ptr<SpdyFrame> req( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3560 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 3561 | scoped_ptr<SpdyFrame> rst( |
| 3562 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3563 | MockWrite writes[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3564 | CreateMockWrite(*req), |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 3565 | CreateMockWrite(*rst), |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3566 | }; |
| 3567 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3568 | scoped_ptr<SpdyFrame> resp( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3569 | spdy_util_.ConstructSpdyFrame(kSynStartHeader, |
| 3570 | NULL, 0, |
| 3571 | test_cases[i].headers, |
| 3572 | test_cases[i].num_headers)); |
| 3573 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3574 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3575 | CreateMockRead(*resp), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3576 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3577 | }; |
| 3578 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3579 | DelayedSocketData data(1, reads, arraysize(reads), |
| 3580 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3581 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3582 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3583 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3584 | TransactionHelperResult out = helper.output(); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 3585 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | dd11b93 | 2009-11-30 19:39:48 | [diff] [blame] | 3586 | } |
| 3587 | } |
| 3588 | |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3589 | // Verify that we don't crash on some corrupt frames. |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3590 | // TODO(jgraettinger): SPDY4 and up treats a header decompression failure as a |
| 3591 | // connection error. I'd like to backport this behavior to SPDY3 as well. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3592 | TEST_P(SpdyNetworkTransactionTest, CorruptFrameSessionError) { |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3593 | if (spdy_util_.spdy_version() >= SPDY4) { |
| 3594 | return; |
| 3595 | } |
[email protected] | 61c83f78 | 2011-01-27 21:00:24 | [diff] [blame] | 3596 | // This is the length field that's too short. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3597 | scoped_ptr<SpdyFrame> syn_reply_wrong_length( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3598 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3599 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 3600 | size_t right_size = |
| 3601 | (spdy_util_.spdy_version() < SPDY4) ? |
| 3602 | syn_reply_wrong_length->size() - framer.GetControlFrameHeaderSize() : |
| 3603 | syn_reply_wrong_length->size(); |
| 3604 | size_t wrong_size = right_size - 4; |
[email protected] | a4bfdf7 | 2013-02-22 04:06:16 | [diff] [blame] | 3605 | test::SetFrameLength(syn_reply_wrong_length.get(), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 3606 | wrong_size, |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3607 | spdy_util_.spdy_version()); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3608 | |
| 3609 | struct SynReplyTests { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3610 | const SpdyFrame* syn_reply; |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3611 | } test_cases[] = { |
[email protected] | 61c83f78 | 2011-01-27 21:00:24 | [diff] [blame] | 3612 | { syn_reply_wrong_length.get(), }, |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3613 | }; |
| 3614 | |
| 3615 | for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3616 | scoped_ptr<SpdyFrame> req( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3617 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 099bc7e | 2013-07-18 04:19:16 | [diff] [blame] | 3618 | scoped_ptr<SpdyFrame> rst( |
| 3619 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 3620 | MockWrite writes[] = { |
| 3621 | CreateMockWrite(*req), |
| 3622 | CreateMockWrite(*rst), |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3623 | }; |
| 3624 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3625 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3626 | MockRead reads[] = { |
[email protected] | d1918d6 | 2013-02-26 10:18:01 | [diff] [blame] | 3627 | MockRead(ASYNC, test_cases[i].syn_reply->data(), wrong_size), |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3628 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3629 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3630 | }; |
| 3631 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3632 | DelayedSocketData data(1, reads, arraysize(reads), |
| 3633 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3634 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3635 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3636 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3637 | TransactionHelperResult out = helper.output(); |
[email protected] | 955fc2e7 | 2010-02-08 20:37:30 | [diff] [blame] | 3638 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3639 | } |
| 3640 | } |
| 3641 | |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3642 | // SPDY4 treats a header decompression failure as a connection-level error. |
| 3643 | TEST_P(SpdyNetworkTransactionTest, CorruptFrameSessionErrorSpdy4) { |
| 3644 | if (spdy_util_.spdy_version() < SPDY4) { |
| 3645 | return; |
| 3646 | } |
| 3647 | // This is the length field that's too short. |
| 3648 | scoped_ptr<SpdyFrame> syn_reply_wrong_length( |
| 3649 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3650 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 3651 | size_t right_size = |
[email protected] | c143f274 | 2014-03-31 00:48:54 | [diff] [blame] | 3652 | syn_reply_wrong_length->size() - framer.GetControlFrameHeaderSize(); |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3653 | size_t wrong_size = right_size - 4; |
| 3654 | test::SetFrameLength(syn_reply_wrong_length.get(), |
| 3655 | wrong_size, |
| 3656 | spdy_util_.spdy_version()); |
| 3657 | |
| 3658 | // TODO(jgraettinger): SpdySession::OnError() should send a GOAWAY before |
| 3659 | // breaking the connection. |
| 3660 | scoped_ptr<SpdyFrame> req( |
| 3661 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3662 | MockWrite writes[] = { |
| 3663 | CreateMockWrite(*req), |
| 3664 | }; |
| 3665 | |
| 3666 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3667 | MockRead reads[] = { |
[email protected] | c143f274 | 2014-03-31 00:48:54 | [diff] [blame] | 3668 | MockRead(ASYNC, syn_reply_wrong_length->data(), |
| 3669 | syn_reply_wrong_length->size() - 4), |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3670 | }; |
| 3671 | |
| 3672 | DelayedSocketData data(1, reads, arraysize(reads), |
| 3673 | writes, arraysize(writes)); |
| 3674 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 3675 | BoundNetLog(), GetParam(), NULL); |
| 3676 | helper.RunToCompletion(&data); |
| 3677 | TransactionHelperResult out = helper.output(); |
| 3678 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 3679 | } |
| 3680 | |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3681 | // Test that we shutdown correctly on write errors. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3682 | TEST_P(SpdyNetworkTransactionTest, WriteError) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3683 | scoped_ptr<SpdyFrame> req( |
| 3684 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3685 | MockWrite writes[] = { |
| 3686 | // We'll write 10 bytes successfully |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3687 | MockWrite(ASYNC, req->data(), 10, 0), |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3688 | // Followed by ERROR! |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3689 | MockWrite(ASYNC, ERR_FAILED, 1), |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3690 | }; |
| 3691 | |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3692 | MockRead reads[] = { |
| 3693 | MockRead(ASYNC, 0, 2) // EOF |
| 3694 | }; |
| 3695 | |
| 3696 | DeterministicSocketData data(reads, arraysize(reads), |
| 3697 | writes, arraysize(writes)); |
| 3698 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3699 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3700 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 238002d | 2013-10-17 02:01:40 | [diff] [blame] | 3701 | helper.SetDeterministic(); |
| 3702 | helper.RunPreTestSetup(); |
| 3703 | helper.AddDeterministicData(&data); |
| 3704 | EXPECT_TRUE(helper.StartDefaultTest()); |
| 3705 | data.RunFor(2); |
| 3706 | helper.FinishDefaultTest(); |
| 3707 | EXPECT_TRUE(data.at_write_eof()); |
| 3708 | EXPECT_TRUE(!data.at_read_eof()); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3709 | TransactionHelperResult out = helper.output(); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3710 | EXPECT_EQ(ERR_FAILED, out.rv); |
| 3711 | } |
| 3712 | |
| 3713 | // Test that partial writes work. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3714 | TEST_P(SpdyNetworkTransactionTest, PartialWrite) { |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3715 | // Chop the SYN_STREAM frame into 5 chunks. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3716 | scoped_ptr<SpdyFrame> req( |
| 3717 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3718 | const int kChunks = 5; |
[email protected] | 4356f0f | 2013-04-07 00:58:17 | [diff] [blame] | 3719 | scoped_ptr<MockWrite[]> writes(ChopWriteFrame(*req.get(), kChunks)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3720 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3721 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3722 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3723 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3724 | CreateMockRead(*resp), |
| 3725 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3726 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3727 | }; |
| 3728 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3729 | DelayedSocketData data(kChunks, reads, arraysize(reads), |
| 3730 | writes.get(), kChunks); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3731 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3732 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3733 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3734 | TransactionHelperResult out = helper.output(); |
[email protected] | bf2491a9 | 2009-11-29 16:39:48 | [diff] [blame] | 3735 | EXPECT_EQ(OK, out.rv); |
| 3736 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 3737 | EXPECT_EQ("hello!", out.response_data); |
| 3738 | } |
| 3739 | |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3740 | // In this test, we enable compression, but get a uncompressed SynReply from |
| 3741 | // the server. Verify that teardown is all clean. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3742 | TEST_P(SpdyNetworkTransactionTest, DecompressFailureOnSynReply) { |
[email protected] | e3352df | 2014-03-19 05:55:42 | [diff] [blame] | 3743 | if (spdy_util_.spdy_version() >= SPDY4) { |
| 3744 | // HPACK doesn't use deflate compression. |
| 3745 | return; |
| 3746 | } |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3747 | scoped_ptr<SpdyFrame> compressed( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3748 | spdy_util_.ConstructSpdyGet(NULL, 0, true, 1, LOWEST, true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3749 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 3750 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3751 | MockWrite writes[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3752 | CreateMockWrite(*compressed), |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3753 | }; |
| 3754 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3755 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3756 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3757 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3758 | CreateMockRead(*resp), |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3759 | }; |
| 3760 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3761 | DelayedSocketData data(1, reads, arraysize(reads), |
| 3762 | writes, arraysize(writes)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3763 | SpdySessionDependencies* session_deps = |
| 3764 | CreateSpdySessionDependencies(GetParam()); |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 3765 | session_deps->enable_compression = true; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3766 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | f9cf557 | 2012-12-04 15:52:09 | [diff] [blame] | 3767 | BoundNetLog(), GetParam(), session_deps); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3768 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3769 | TransactionHelperResult out = helper.output(); |
[email protected] | 6c6ea17 | 2010-07-27 20:04:03 | [diff] [blame] | 3770 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3771 | data.Reset(); |
[email protected] | 94d7813 | 2010-01-22 00:53:00 | [diff] [blame] | 3772 | } |
| 3773 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 3774 | // Test that the NetLog contains good data for a simple GET request. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3775 | TEST_P(SpdyNetworkTransactionTest, NetLog) { |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3776 | static const char* const kExtraHeaders[] = { |
| 3777 | "user-agent", "Chrome", |
| 3778 | }; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3779 | scoped_ptr<SpdyFrame> req( |
| 3780 | spdy_util_.ConstructSpdyGet(kExtraHeaders, 1, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3781 | MockWrite writes[] = { CreateMockWrite(*req) }; |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3782 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3783 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3784 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3785 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3786 | CreateMockRead(*resp), |
| 3787 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3788 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3789 | }; |
| 3790 | |
[email protected] | 333bdf6 | 2012-06-08 22:57:29 | [diff] [blame] | 3791 | CapturingBoundNetLog log; |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3792 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3793 | DelayedSocketData data(1, reads, arraysize(reads), |
| 3794 | writes, arraysize(writes)); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3795 | NormalSpdyTransactionHelper helper(CreateGetRequestWithUserAgent(), |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3796 | DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3797 | log.bound(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3798 | helper.RunToCompletion(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3799 | TransactionHelperResult out = helper.output(); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3800 | EXPECT_EQ(OK, out.rv); |
| 3801 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 3802 | EXPECT_EQ("hello!", out.response_data); |
| 3803 | |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 3804 | // Check that the NetLog was filled reasonably. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3805 | // This test is intentionally non-specific about the exact ordering of the |
| 3806 | // log; instead we just check to make sure that certain events exist, and that |
| 3807 | // they are in the right order. |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3808 | net::CapturingNetLog::CapturedEntryList entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3809 | log.GetEntries(&entries); |
| 3810 | |
| 3811 | EXPECT_LT(0u, entries.size()); |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3812 | int pos = 0; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3813 | pos = net::ExpectLogContainsSomewhere(entries, 0, |
[email protected] | 351ab64 | 2010-08-05 16:55:31 | [diff] [blame] | 3814 | net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 3815 | net::NetLog::PHASE_BEGIN); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3816 | pos = net::ExpectLogContainsSomewhere(entries, pos + 1, |
[email protected] | 351ab64 | 2010-08-05 16:55:31 | [diff] [blame] | 3817 | net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 3818 | net::NetLog::PHASE_END); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3819 | pos = net::ExpectLogContainsSomewhere(entries, pos + 1, |
[email protected] | 351ab64 | 2010-08-05 16:55:31 | [diff] [blame] | 3820 | net::NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 3821 | net::NetLog::PHASE_BEGIN); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3822 | pos = net::ExpectLogContainsSomewhere(entries, pos + 1, |
[email protected] | 351ab64 | 2010-08-05 16:55:31 | [diff] [blame] | 3823 | net::NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 3824 | net::NetLog::PHASE_END); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3825 | pos = net::ExpectLogContainsSomewhere(entries, pos + 1, |
[email protected] | 351ab64 | 2010-08-05 16:55:31 | [diff] [blame] | 3826 | net::NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 3827 | net::NetLog::PHASE_BEGIN); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3828 | pos = net::ExpectLogContainsSomewhere(entries, pos + 1, |
[email protected] | 351ab64 | 2010-08-05 16:55:31 | [diff] [blame] | 3829 | net::NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, |
[email protected] | 9e743cd | 2010-03-16 07:03:53 | [diff] [blame] | 3830 | net::NetLog::PHASE_END); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3831 | |
| 3832 | // Check that we logged all the headers correctly |
| 3833 | pos = net::ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3834 | entries, 0, |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3835 | net::NetLog::TYPE_SPDY_SESSION_SYN_STREAM, |
| 3836 | net::NetLog::PHASE_NONE); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3837 | |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 3838 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3839 | ASSERT_TRUE(entries[pos].params.get()); |
| 3840 | ASSERT_TRUE(entries[pos].params->GetList("headers", &header_list)); |
| 3841 | |
| 3842 | std::vector<std::string> expected; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3843 | expected.push_back(std::string(spdy_util_.GetHostKey()) + ": www.google.com"); |
| 3844 | expected.push_back(std::string(spdy_util_.GetPathKey()) + ": /"); |
| 3845 | expected.push_back(std::string(spdy_util_.GetSchemeKey()) + ": http"); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3846 | expected.push_back(std::string(spdy_util_.GetMethodKey()) + ": GET"); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3847 | expected.push_back("user-agent: Chrome"); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 3848 | if (spdy_util_.spdy_version() < SPDY4) { |
| 3849 | // SPDY4/HTTP2 eliminates use of the :version header. |
| 3850 | expected.push_back(std::string(spdy_util_.GetVersionKey()) + ": HTTP/1.1"); |
| 3851 | } |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 3852 | EXPECT_EQ(expected.size(), header_list->GetSize()); |
| 3853 | for (std::vector<std::string>::const_iterator it = expected.begin(); |
| 3854 | it != expected.end(); |
| 3855 | ++it) { |
| 3856 | base::StringValue header(*it); |
| 3857 | EXPECT_NE(header_list->end(), header_list->Find(header)) << |
| 3858 | "Header not found: " << *it; |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 3859 | } |
[email protected] | dac35804 | 2009-12-18 02:07:48 | [diff] [blame] | 3860 | } |
| 3861 | |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3862 | // Since we buffer the IO from the stream to the renderer, this test verifies |
| 3863 | // that when we read out the maximum amount of data (e.g. we received 50 bytes |
| 3864 | // on the network, but issued a Read for only 5 of those bytes) that the data |
| 3865 | // flow still works correctly. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3866 | TEST_P(SpdyNetworkTransactionTest, BufferFull) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3867 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3868 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3869 | scoped_ptr<SpdyFrame> req( |
| 3870 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3871 | MockWrite writes[] = { CreateMockWrite(*req) }; |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3872 | |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3873 | // 2 data frames in a single read. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3874 | scoped_ptr<SpdyFrame> data_frame_1( |
| 3875 | framer.CreateDataFrame(1, "goodby", 6, DATA_FLAG_NONE)); |
| 3876 | scoped_ptr<SpdyFrame> data_frame_2( |
| 3877 | framer.CreateDataFrame(1, "e worl", 6, DATA_FLAG_NONE)); |
| 3878 | const SpdyFrame* data_frames[2] = { |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3879 | data_frame_1.get(), |
| 3880 | data_frame_2.get(), |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3881 | }; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3882 | char combined_data_frames[100]; |
| 3883 | int combined_data_frames_len = |
| 3884 | CombineFrames(data_frames, arraysize(data_frames), |
| 3885 | combined_data_frames, arraysize(combined_data_frames)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3886 | scoped_ptr<SpdyFrame> last_frame( |
| 3887 | framer.CreateDataFrame(1, "d", 1, DATA_FLAG_FIN)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3888 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3889 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3890 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3891 | CreateMockRead(*resp), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3892 | MockRead(ASYNC, ERR_IO_PENDING), // Force a pause |
| 3893 | MockRead(ASYNC, combined_data_frames, combined_data_frames_len), |
| 3894 | MockRead(ASYNC, ERR_IO_PENDING), // Force a pause |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3895 | CreateMockRead(*last_frame), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3896 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3897 | }; |
| 3898 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3899 | DelayedSocketData data(1, reads, arraysize(reads), |
| 3900 | writes, arraysize(writes)); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3901 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3902 | TestCompletionCallback callback; |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3903 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3904 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3905 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3906 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3907 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3908 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3909 | int rv = trans->Start( |
| 3910 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3911 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3912 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3913 | TransactionHelperResult out = helper.output(); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3914 | out.rv = callback.WaitForResult(); |
| 3915 | EXPECT_EQ(out.rv, OK); |
| 3916 | |
| 3917 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3918 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3919 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3920 | out.status_line = response->headers->GetStatusLine(); |
| 3921 | out.response_info = *response; // Make a copy so we can verify. |
| 3922 | |
| 3923 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3924 | TestCompletionCallback read_callback; |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3925 | |
| 3926 | std::string content; |
| 3927 | do { |
| 3928 | // Read small chunks at a time. |
| 3929 | const int kSmallReadSize = 3; |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 3930 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 3931 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3932 | if (rv == net::ERR_IO_PENDING) { |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3933 | data.CompleteRead(); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3934 | rv = read_callback.WaitForResult(); |
| 3935 | } |
| 3936 | if (rv > 0) { |
| 3937 | content.append(buf->data(), rv); |
| 3938 | } else if (rv < 0) { |
| 3939 | NOTREACHED(); |
| 3940 | } |
| 3941 | } while (rv > 0); |
| 3942 | |
| 3943 | out.response_data.swap(content); |
| 3944 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 3945 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3946 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 3947 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3948 | |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3949 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3950 | helper.VerifyDataConsumed(); |
[email protected] | 79d8422 | 2010-02-26 00:01:44 | [diff] [blame] | 3951 | |
| 3952 | EXPECT_EQ(OK, out.rv); |
| 3953 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 3954 | EXPECT_EQ("goodbye world", out.response_data); |
| 3955 | } |
| 3956 | |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3957 | // Verify that basic buffering works; when multiple data frames arrive |
| 3958 | // at the same time, ensure that we don't notify a read completion for |
| 3959 | // each data frame individually. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3960 | TEST_P(SpdyNetworkTransactionTest, Buffering) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3961 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3962 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 3963 | scoped_ptr<SpdyFrame> req( |
| 3964 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3965 | MockWrite writes[] = { CreateMockWrite(*req) }; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3966 | |
| 3967 | // 4 data frames in a single read. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 3968 | scoped_ptr<SpdyFrame> data_frame( |
| 3969 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 3970 | scoped_ptr<SpdyFrame> data_frame_fin( |
| 3971 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN)); |
| 3972 | const SpdyFrame* data_frames[4] = { |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3973 | data_frame.get(), |
| 3974 | data_frame.get(), |
| 3975 | data_frame.get(), |
| 3976 | data_frame_fin.get() |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3977 | }; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 3978 | char combined_data_frames[100]; |
| 3979 | int combined_data_frames_len = |
| 3980 | CombineFrames(data_frames, arraysize(data_frames), |
| 3981 | combined_data_frames, arraysize(combined_data_frames)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3982 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 3983 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3984 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 3985 | CreateMockRead(*resp), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3986 | MockRead(ASYNC, ERR_IO_PENDING), // Force a pause |
| 3987 | MockRead(ASYNC, combined_data_frames, combined_data_frames_len), |
| 3988 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3989 | }; |
| 3990 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3991 | DelayedSocketData data(1, reads, arraysize(reads), |
| 3992 | writes, arraysize(writes)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3993 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 3994 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 3995 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3996 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 3997 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 3998 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 3999 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4000 | TestCompletionCallback callback; |
| 4001 | int rv = trans->Start( |
| 4002 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4003 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4004 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4005 | TransactionHelperResult out = helper.output(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4006 | out.rv = callback.WaitForResult(); |
| 4007 | EXPECT_EQ(out.rv, OK); |
| 4008 | |
| 4009 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4010 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4011 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4012 | out.status_line = response->headers->GetStatusLine(); |
| 4013 | out.response_info = *response; // Make a copy so we can verify. |
| 4014 | |
| 4015 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4016 | TestCompletionCallback read_callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4017 | |
| 4018 | std::string content; |
| 4019 | int reads_completed = 0; |
| 4020 | do { |
| 4021 | // Read small chunks at a time. |
| 4022 | const int kSmallReadSize = 14; |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 4023 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4024 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4025 | if (rv == net::ERR_IO_PENDING) { |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4026 | data.CompleteRead(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4027 | rv = read_callback.WaitForResult(); |
| 4028 | } |
| 4029 | if (rv > 0) { |
| 4030 | EXPECT_EQ(kSmallReadSize, rv); |
| 4031 | content.append(buf->data(), rv); |
| 4032 | } else if (rv < 0) { |
| 4033 | FAIL() << "Unexpected read error: " << rv; |
| 4034 | } |
| 4035 | reads_completed++; |
| 4036 | } while (rv > 0); |
| 4037 | |
| 4038 | EXPECT_EQ(3, reads_completed); // Reads are: 14 bytes, 14 bytes, 0 bytes. |
| 4039 | |
| 4040 | out.response_data.swap(content); |
| 4041 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 4042 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4043 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4044 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4045 | |
| 4046 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4047 | helper.VerifyDataConsumed(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4048 | |
| 4049 | EXPECT_EQ(OK, out.rv); |
| 4050 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4051 | EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 4052 | } |
| 4053 | |
| 4054 | // 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] | 4055 | TEST_P(SpdyNetworkTransactionTest, BufferedAll) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4056 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 4057 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4058 | scoped_ptr<SpdyFrame> req( |
| 4059 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 4060 | MockWrite writes[] = { CreateMockWrite(*req) }; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4061 | |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 4062 | // 5 data frames in a single read. |
[email protected] | d2c1a97b | 2014-03-03 19:25:09 | [diff] [blame] | 4063 | SpdySynReplyIR reply_ir(1); |
| 4064 | reply_ir.SetHeader(spdy_util_.GetStatusKey(), "200"); |
| 4065 | reply_ir.SetHeader(spdy_util_.GetVersionKey(), "HTTP/1.1"); |
| 4066 | |
| 4067 | scoped_ptr<SpdyFrame> syn_reply(framer.SerializeFrame(reply_ir)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4068 | scoped_ptr<SpdyFrame> data_frame( |
| 4069 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 4070 | scoped_ptr<SpdyFrame> data_frame_fin( |
| 4071 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN)); |
| 4072 | const SpdyFrame* frames[5] = { |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 4073 | syn_reply.get(), |
| 4074 | data_frame.get(), |
| 4075 | data_frame.get(), |
| 4076 | data_frame.get(), |
| 4077 | data_frame_fin.get() |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4078 | }; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 4079 | char combined_frames[200]; |
| 4080 | int combined_frames_len = |
| 4081 | CombineFrames(frames, arraysize(frames), |
| 4082 | combined_frames, arraysize(combined_frames)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4083 | |
| 4084 | MockRead reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4085 | MockRead(ASYNC, combined_frames, combined_frames_len), |
| 4086 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4087 | }; |
| 4088 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4089 | DelayedSocketData data(1, reads, arraysize(reads), |
| 4090 | writes, arraysize(writes)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4091 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4092 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4093 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4094 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4095 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4096 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4097 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4098 | TestCompletionCallback callback; |
| 4099 | int rv = trans->Start( |
| 4100 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4101 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4102 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4103 | TransactionHelperResult out = helper.output(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4104 | out.rv = callback.WaitForResult(); |
| 4105 | EXPECT_EQ(out.rv, OK); |
| 4106 | |
| 4107 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4108 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4109 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4110 | out.status_line = response->headers->GetStatusLine(); |
| 4111 | out.response_info = *response; // Make a copy so we can verify. |
| 4112 | |
| 4113 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4114 | TestCompletionCallback read_callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4115 | |
| 4116 | std::string content; |
| 4117 | int reads_completed = 0; |
| 4118 | do { |
| 4119 | // Read small chunks at a time. |
| 4120 | const int kSmallReadSize = 14; |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 4121 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4122 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4123 | if (rv > 0) { |
| 4124 | EXPECT_EQ(kSmallReadSize, rv); |
| 4125 | content.append(buf->data(), rv); |
| 4126 | } else if (rv < 0) { |
| 4127 | FAIL() << "Unexpected read error: " << rv; |
| 4128 | } |
| 4129 | reads_completed++; |
| 4130 | } while (rv > 0); |
| 4131 | |
| 4132 | EXPECT_EQ(3, reads_completed); |
| 4133 | |
| 4134 | out.response_data.swap(content); |
| 4135 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 4136 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4137 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4138 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4139 | |
| 4140 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4141 | helper.VerifyDataConsumed(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4142 | |
| 4143 | EXPECT_EQ(OK, out.rv); |
| 4144 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4145 | EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 4146 | } |
| 4147 | |
| 4148 | // Verify the case where we buffer data and close the connection. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4149 | TEST_P(SpdyNetworkTransactionTest, BufferedClosed) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4150 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 4151 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4152 | scoped_ptr<SpdyFrame> req( |
| 4153 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 4154 | MockWrite writes[] = { CreateMockWrite(*req) }; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4155 | |
| 4156 | // All data frames in a single read. |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 4157 | // NOTE: We don't FIN the stream. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4158 | scoped_ptr<SpdyFrame> data_frame( |
| 4159 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 4160 | const SpdyFrame* data_frames[4] = { |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 4161 | data_frame.get(), |
| 4162 | data_frame.get(), |
| 4163 | data_frame.get(), |
| 4164 | data_frame.get() |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4165 | }; |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 4166 | char combined_data_frames[100]; |
| 4167 | int combined_data_frames_len = |
| 4168 | CombineFrames(data_frames, arraysize(data_frames), |
| 4169 | combined_data_frames, arraysize(combined_data_frames)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4170 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4171 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 4172 | CreateMockRead(*resp), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4173 | MockRead(ASYNC, ERR_IO_PENDING), // Force a wait |
| 4174 | MockRead(ASYNC, combined_data_frames, combined_data_frames_len), |
| 4175 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4176 | }; |
| 4177 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4178 | DelayedSocketData data(1, reads, arraysize(reads), |
| 4179 | writes, arraysize(writes)); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4180 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4181 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4182 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4183 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4184 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4185 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4186 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4187 | TestCompletionCallback callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4188 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4189 | int rv = trans->Start( |
| 4190 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4191 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4192 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4193 | TransactionHelperResult out = helper.output(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4194 | out.rv = callback.WaitForResult(); |
| 4195 | EXPECT_EQ(out.rv, OK); |
| 4196 | |
| 4197 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4198 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4199 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4200 | out.status_line = response->headers->GetStatusLine(); |
| 4201 | out.response_info = *response; // Make a copy so we can verify. |
| 4202 | |
| 4203 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4204 | TestCompletionCallback read_callback; |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4205 | |
| 4206 | std::string content; |
| 4207 | int reads_completed = 0; |
| 4208 | do { |
| 4209 | // Read small chunks at a time. |
| 4210 | const int kSmallReadSize = 14; |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 4211 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSmallReadSize)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4212 | rv = trans->Read(buf.get(), kSmallReadSize, read_callback.callback()); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4213 | if (rv == net::ERR_IO_PENDING) { |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4214 | data.CompleteRead(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4215 | rv = read_callback.WaitForResult(); |
| 4216 | } |
| 4217 | if (rv > 0) { |
| 4218 | content.append(buf->data(), rv); |
| 4219 | } else if (rv < 0) { |
| 4220 | // This test intentionally closes the connection, and will get an error. |
| 4221 | EXPECT_EQ(ERR_CONNECTION_CLOSED, rv); |
| 4222 | break; |
| 4223 | } |
| 4224 | reads_completed++; |
| 4225 | } while (rv > 0); |
| 4226 | |
| 4227 | EXPECT_EQ(0, reads_completed); |
| 4228 | |
| 4229 | out.response_data.swap(content); |
| 4230 | |
[email protected] | 30c942b | 2010-07-21 16:59:59 | [diff] [blame] | 4231 | // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4232 | // MockClientSocketFactory) are still alive. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4233 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4234 | |
| 4235 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4236 | helper.VerifyDataConsumed(); |
[email protected] | 8918d28 | 2010-03-02 00:57:55 | [diff] [blame] | 4237 | } |
| 4238 | |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4239 | // Verify the case where we buffer data and cancel the transaction. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4240 | TEST_P(SpdyNetworkTransactionTest, BufferedCancelled) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4241 | BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 4242 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4243 | scoped_ptr<SpdyFrame> req( |
| 4244 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 4245 | MockWrite writes[] = { CreateMockWrite(*req) }; |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4246 | |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 4247 | // NOTE: We don't FIN the stream. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4248 | scoped_ptr<SpdyFrame> data_frame( |
| 4249 | framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4250 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4251 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4252 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 4253 | CreateMockRead(*resp), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4254 | MockRead(ASYNC, ERR_IO_PENDING), // Force a wait |
[email protected] | 20d005f | 2010-07-02 19:55:43 | [diff] [blame] | 4255 | CreateMockRead(*data_frame), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4256 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4257 | }; |
| 4258 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4259 | DelayedSocketData data(1, reads, arraysize(reads), |
| 4260 | writes, arraysize(writes)); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4261 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4262 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4263 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4264 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4265 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4266 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4267 | TestCompletionCallback callback; |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4268 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4269 | int rv = trans->Start( |
| 4270 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4271 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4272 | |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4273 | TransactionHelperResult out = helper.output(); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4274 | out.rv = callback.WaitForResult(); |
| 4275 | EXPECT_EQ(out.rv, OK); |
| 4276 | |
| 4277 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4278 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4279 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4280 | out.status_line = response->headers->GetStatusLine(); |
| 4281 | out.response_info = *response; // Make a copy so we can verify. |
| 4282 | |
| 4283 | // Read Data |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4284 | TestCompletionCallback read_callback; |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4285 | |
[email protected] | 88c7b4be | 2014-03-19 23:04:01 | [diff] [blame] | 4286 | const int kReadSize = 256; |
| 4287 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kReadSize)); |
| 4288 | rv = trans->Read(buf.get(), kReadSize, read_callback.callback()); |
| 4289 | ASSERT_EQ(net::ERR_IO_PENDING, rv) << "Unexpected read: " << rv; |
| 4290 | |
| 4291 | // Complete the read now, which causes buffering to start. |
| 4292 | data.CompleteRead(); |
| 4293 | // Destroy the transaction, causing the stream to get cancelled |
| 4294 | // and orphaning the buffered IO task. |
| 4295 | helper.ResetTrans(); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4296 | |
| 4297 | // Flush the MessageLoop; this will cause the buffered IO task |
| 4298 | // to run for the final time. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4299 | base::RunLoop().RunUntilIdle(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4300 | |
| 4301 | // Verify that we consumed all test data. |
| 4302 | helper.VerifyDataConsumed(); |
[email protected] | 1ed7b3dc | 2010-03-04 05:41:45 | [diff] [blame] | 4303 | } |
| 4304 | |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4305 | // Test that if the server requests persistence of settings, that we save |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4306 | // the settings in the HttpServerProperties. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4307 | TEST_P(SpdyNetworkTransactionTest, SettingsSaved) { |
[email protected] | 8a7bc7a | 2014-02-28 21:25:22 | [diff] [blame] | 4308 | if (spdy_util_.spdy_version() >= SPDY4) { |
| 4309 | // SPDY4 doesn't support flags on individual settings, and |
| 4310 | // has no concept of settings persistence. |
| 4311 | return; |
| 4312 | } |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4313 | static const SpdyHeaderInfo kSynReplyInfo = { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4314 | SYN_REPLY, // Syn Reply |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4315 | 1, // Stream ID |
| 4316 | 0, // Associated Stream ID |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4317 | ConvertRequestPriorityToSpdyPriority( |
| 4318 | LOWEST, spdy_util_.spdy_version()), |
| 4319 | kSpdyCredentialSlotUnused, |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4320 | CONTROL_FLAG_NONE, // Control Flags |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4321 | false, // Compressed |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 4322 | RST_STREAM_INVALID, // Status |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4323 | NULL, // Data |
| 4324 | 0, // Data Length |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4325 | DATA_FLAG_NONE // Data Flags |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4326 | }; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4327 | |
[email protected] | c016882 | 2011-12-10 01:24:27 | [diff] [blame] | 4328 | BoundNetLog net_log; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4329 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 4330 | net_log, GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 4331 | helper.RunPreTestSetup(); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4332 | |
| 4333 | // Verify that no settings exist initially. |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 4334 | HostPortPair host_port_pair("www.google.com", helper.port()); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 4335 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4336 | EXPECT_TRUE(spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4337 | host_port_pair).empty()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4338 | |
| 4339 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4340 | scoped_ptr<SpdyFrame> req( |
| 4341 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 4342 | MockWrite writes[] = { CreateMockWrite(*req) }; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4343 | |
| 4344 | // Construct the reply. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4345 | scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); |
| 4346 | (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 4347 | (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4348 | scoped_ptr<SpdyFrame> reply( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4349 | spdy_util_.ConstructSpdyFrame(kSynReplyInfo, reply_headers.Pass())); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4350 | |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4351 | const SpdySettingsIds kSampleId1 = SETTINGS_UPLOAD_BANDWIDTH; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4352 | unsigned int kSampleValue1 = 0x0a0a0a0a; |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4353 | const SpdySettingsIds kSampleId2 = SETTINGS_DOWNLOAD_BANDWIDTH; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4354 | unsigned int kSampleValue2 = 0x0b0b0b0b; |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4355 | const SpdySettingsIds kSampleId3 = SETTINGS_ROUND_TRIP_TIME; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4356 | unsigned int kSampleValue3 = 0x0c0c0c0c; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4357 | scoped_ptr<SpdyFrame> settings_frame; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4358 | { |
| 4359 | // Construct the SETTINGS frame. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4360 | SettingsMap settings; |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4361 | // First add a persisted setting. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4362 | settings[kSampleId1] = |
| 4363 | SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue1); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4364 | // Next add a non-persisted setting. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4365 | settings[kSampleId2] = |
| 4366 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kSampleValue2); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4367 | // Next add another persisted setting. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4368 | settings[kSampleId3] = |
| 4369 | SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue3); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4370 | settings_frame.reset(spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4371 | } |
| 4372 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4373 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4374 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 4375 | CreateMockRead(*reply), |
| 4376 | CreateMockRead(*body), |
| 4377 | CreateMockRead(*settings_frame), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4378 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4379 | }; |
| 4380 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4381 | DelayedSocketData data(1, reads, arraysize(reads), |
| 4382 | writes, arraysize(writes)); |
| 4383 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 4384 | helper.RunDefaultTest(); |
| 4385 | helper.VerifyDataConsumed(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4386 | TransactionHelperResult out = helper.output(); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4387 | EXPECT_EQ(OK, out.rv); |
| 4388 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4389 | EXPECT_EQ("hello!", out.response_data); |
| 4390 | |
| 4391 | { |
| 4392 | // Verify we had two persisted settings. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4393 | const SettingsMap& settings_map = |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4394 | spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4395 | host_port_pair); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4396 | ASSERT_EQ(2u, settings_map.size()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4397 | |
| 4398 | // Verify the first persisted setting. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4399 | SettingsMap::const_iterator it1 = settings_map.find(kSampleId1); |
| 4400 | EXPECT_TRUE(it1 != settings_map.end()); |
| 4401 | SettingsFlagsAndValue flags_and_value1 = it1->second; |
| 4402 | EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1.first); |
| 4403 | EXPECT_EQ(kSampleValue1, flags_and_value1.second); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4404 | |
| 4405 | // Verify the second persisted setting. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4406 | SettingsMap::const_iterator it3 = settings_map.find(kSampleId3); |
| 4407 | EXPECT_TRUE(it3 != settings_map.end()); |
| 4408 | SettingsFlagsAndValue flags_and_value3 = it3->second; |
| 4409 | EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value3.first); |
| 4410 | EXPECT_EQ(kSampleValue3, flags_and_value3.second); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4411 | } |
| 4412 | } |
| 4413 | |
| 4414 | // Test that when there are settings saved that they are sent back to the |
| 4415 | // server upon session establishment. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4416 | TEST_P(SpdyNetworkTransactionTest, SettingsPlayback) { |
[email protected] | c143f274 | 2014-03-31 00:48:54 | [diff] [blame] | 4417 | // TODO(jgraettinger): Remove settings persistence mechanisms altogether. |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4418 | static const SpdyHeaderInfo kSynReplyInfo = { |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4419 | SYN_REPLY, // Syn Reply |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4420 | 1, // Stream ID |
| 4421 | 0, // Associated Stream ID |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4422 | ConvertRequestPriorityToSpdyPriority( |
| 4423 | LOWEST, spdy_util_.spdy_version()), |
| 4424 | kSpdyCredentialSlotUnused, |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4425 | CONTROL_FLAG_NONE, // Control Flags |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4426 | false, // Compressed |
[email protected] | 5a7bb25 | 2013-02-09 00:21:05 | [diff] [blame] | 4427 | RST_STREAM_INVALID, // Status |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4428 | NULL, // Data |
| 4429 | 0, // Data Length |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4430 | DATA_FLAG_NONE // Data Flags |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4431 | }; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4432 | |
[email protected] | c016882 | 2011-12-10 01:24:27 | [diff] [blame] | 4433 | BoundNetLog net_log; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4434 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 4435 | net_log, GetParam(), NULL); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 4436 | helper.RunPreTestSetup(); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4437 | |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4438 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
| 4439 | |
| 4440 | SpdySessionPoolPeer pool_peer(spdy_session_pool); |
| 4441 | pool_peer.SetEnableSendingInitialData(true); |
| 4442 | |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4443 | // Verify that no settings exist initially. |
[email protected] | 9e9e842e | 2010-07-23 23:09:15 | [diff] [blame] | 4444 | HostPortPair host_port_pair("www.google.com", helper.port()); |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4445 | EXPECT_TRUE(spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4446 | host_port_pair).empty()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4447 | |
[email protected] | c143f274 | 2014-03-31 00:48:54 | [diff] [blame] | 4448 | const SpdySettingsIds kSampleId1 = SETTINGS_MAX_CONCURRENT_STREAMS; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4449 | unsigned int kSampleValue1 = 0x0a0a0a0a; |
[email protected] | c143f274 | 2014-03-31 00:48:54 | [diff] [blame] | 4450 | const SpdySettingsIds kSampleId2 = SETTINGS_INITIAL_WINDOW_SIZE; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4451 | unsigned int kSampleValue2 = 0x0c0c0c0c; |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4452 | |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4453 | // First add a persisted setting. |
| 4454 | spdy_session_pool->http_server_properties()->SetSpdySetting( |
| 4455 | host_port_pair, |
| 4456 | kSampleId1, |
| 4457 | SETTINGS_FLAG_PLEASE_PERSIST, |
| 4458 | kSampleValue1); |
| 4459 | |
| 4460 | // Next add another persisted setting. |
| 4461 | spdy_session_pool->http_server_properties()->SetSpdySetting( |
| 4462 | host_port_pair, |
| 4463 | kSampleId2, |
| 4464 | SETTINGS_FLAG_PLEASE_PERSIST, |
| 4465 | kSampleValue2); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4466 | |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4467 | EXPECT_EQ(2u, spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4468 | host_port_pair).size()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4469 | |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4470 | // Construct the initial SETTINGS frame. |
| 4471 | SettingsMap initial_settings; |
| 4472 | initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 4473 | SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); |
| 4474 | scoped_ptr<SpdyFrame> initial_settings_frame( |
| 4475 | spdy_util_.ConstructSpdySettings(initial_settings)); |
| 4476 | |
| 4477 | // Construct the initial window update. |
| 4478 | scoped_ptr<SpdyFrame> initial_window_update( |
| 4479 | spdy_util_.ConstructSpdyWindowUpdate( |
| 4480 | kSessionFlowControlStreamId, |
| 4481 | kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); |
| 4482 | |
| 4483 | // Construct the persisted SETTINGS frame. |
[email protected] | 18b28ab | 2012-04-18 02:14:42 | [diff] [blame] | 4484 | const SettingsMap& settings = |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4485 | spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4486 | host_port_pair); |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4487 | scoped_ptr<SpdyFrame> settings_frame( |
| 4488 | spdy_util_.ConstructSpdySettings(settings)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4489 | |
| 4490 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4491 | scoped_ptr<SpdyFrame> req( |
| 4492 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4493 | |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4494 | std::vector<MockWrite> writes; |
[email protected] | d10833bc | 2014-04-14 17:50:46 | [diff] [blame] | 4495 | if (GetParam().protocol == kProtoSPDY4) { |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4496 | writes.push_back( |
| 4497 | MockWrite(ASYNC, |
| 4498 | kHttp2ConnectionHeaderPrefix, |
| 4499 | kHttp2ConnectionHeaderPrefixSize)); |
| 4500 | } |
| 4501 | writes.push_back(CreateMockWrite(*initial_settings_frame)); |
| 4502 | if (GetParam().protocol >= kProtoSPDY31) { |
| 4503 | writes.push_back(CreateMockWrite(*initial_window_update)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4504 | }; |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4505 | writes.push_back(CreateMockWrite(*settings_frame)); |
| 4506 | writes.push_back(CreateMockWrite(*req)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4507 | |
| 4508 | // Construct the reply. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4509 | scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); |
| 4510 | (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 4511 | (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 4512 | scoped_ptr<SpdyFrame> reply( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4513 | spdy_util_.ConstructSpdyFrame(kSynReplyInfo, reply_headers.Pass())); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4514 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4515 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4516 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 4517 | CreateMockRead(*reply), |
| 4518 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4519 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4520 | }; |
| 4521 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4522 | DelayedSocketData data(2, reads, arraysize(reads), |
[email protected] | b40f7fa | 2013-08-01 16:13:05 | [diff] [blame] | 4523 | vector_as_array(&writes), writes.size()); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4524 | helper.AddData(&data); |
[email protected] | e3ebba0f | 2010-08-05 17:59:58 | [diff] [blame] | 4525 | helper.RunDefaultTest(); |
| 4526 | helper.VerifyDataConsumed(); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4527 | TransactionHelperResult out = helper.output(); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4528 | EXPECT_EQ(OK, out.rv); |
| 4529 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4530 | EXPECT_EQ("hello!", out.response_data); |
| 4531 | |
| 4532 | { |
| 4533 | // Verify we had two persisted settings. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4534 | const SettingsMap& settings_map = |
[email protected] | 53bfa31c | 2011-11-15 19:20:31 | [diff] [blame] | 4535 | spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4536 | host_port_pair); |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4537 | ASSERT_EQ(2u, settings_map.size()); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4538 | |
| 4539 | // Verify the first persisted setting. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4540 | SettingsMap::const_iterator it1 = settings_map.find(kSampleId1); |
| 4541 | EXPECT_TRUE(it1 != settings_map.end()); |
| 4542 | SettingsFlagsAndValue flags_and_value1 = it1->second; |
| 4543 | EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1.first); |
| 4544 | EXPECT_EQ(kSampleValue1, flags_and_value1.second); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4545 | |
| 4546 | // Verify the second persisted setting. |
[email protected] | e0935cc | 2012-03-24 14:12:48 | [diff] [blame] | 4547 | SettingsMap::const_iterator it2 = settings_map.find(kSampleId2); |
| 4548 | EXPECT_TRUE(it2 != settings_map.end()); |
| 4549 | SettingsFlagsAndValue flags_and_value2 = it2->second; |
| 4550 | EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value2.first); |
| 4551 | EXPECT_EQ(kSampleValue2, flags_and_value2.second); |
[email protected] | 74188f2 | 2010-04-09 20:18:50 | [diff] [blame] | 4552 | } |
| 4553 | } |
| 4554 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4555 | TEST_P(SpdyNetworkTransactionTest, GoAwayWithActiveStream) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4556 | scoped_ptr<SpdyFrame> req( |
| 4557 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 4558 | MockWrite writes[] = { CreateMockWrite(*req) }; |
[email protected] | 69d717bd | 2010-04-21 18:43:21 | [diff] [blame] | 4559 | |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 4560 | scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway()); |
[email protected] | 69d717bd | 2010-04-21 18:43:21 | [diff] [blame] | 4561 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 4562 | CreateMockRead(*go_away), |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4563 | }; |
| 4564 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4565 | DelayedSocketData data(1, reads, arraysize(reads), |
| 4566 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4567 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4568 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4569 | helper.AddData(&data); |
| 4570 | helper.RunToCompletion(&data); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4571 | TransactionHelperResult out = helper.output(); |
[email protected] | c9336d2 | 2010-08-10 00:04:18 | [diff] [blame] | 4572 | EXPECT_EQ(ERR_ABORTED, out.rv); |
[email protected] | 69d717bd | 2010-04-21 18:43:21 | [diff] [blame] | 4573 | } |
| 4574 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4575 | TEST_P(SpdyNetworkTransactionTest, CloseWithActiveStream) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4576 | scoped_ptr<SpdyFrame> req( |
| 4577 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 4578 | MockWrite writes[] = { CreateMockWrite(*req) }; |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4579 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4580 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4581 | MockRead reads[] = { |
[email protected] | e7f7509 | 2010-07-01 22:39:13 | [diff] [blame] | 4582 | CreateMockRead(*resp), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4583 | MockRead(SYNCHRONOUS, 0, 0) // EOF |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4584 | }; |
| 4585 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4586 | DelayedSocketData data(1, reads, arraysize(reads), |
| 4587 | writes, arraysize(writes)); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4588 | BoundNetLog log; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4589 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4590 | log, GetParam(), NULL); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4591 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4592 | helper.AddData(&data); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4593 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4594 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4595 | TestCompletionCallback callback; |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4596 | TransactionHelperResult out; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4597 | out.rv = trans->Start(&CreateGetRequest(), callback.callback(), log); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4598 | |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4599 | EXPECT_EQ(out.rv, ERR_IO_PENDING); |
| 4600 | out.rv = callback.WaitForResult(); |
| 4601 | EXPECT_EQ(out.rv, OK); |
| 4602 | |
| 4603 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4604 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4605 | EXPECT_TRUE(response->was_fetched_via_spdy); |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4606 | out.rv = ReadTransaction(trans, &out.response_data); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4607 | EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); |
| 4608 | |
| 4609 | // Verify that we consumed all test data. |
[email protected] | 3caf554 | 2010-07-16 15:19:47 | [diff] [blame] | 4610 | helper.VerifyDataConsumed(); |
[email protected] | f5ed2155 | 2010-05-04 18:39:54 | [diff] [blame] | 4611 | } |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4612 | |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4613 | // Test to make sure we can correctly connect through a proxy. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4614 | TEST_P(SpdyNetworkTransactionTest, ProxyConnect) { |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4615 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4616 | BoundNetLog(), GetParam(), NULL); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4617 | helper.session_deps().reset(CreateSpdySessionDependencies( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4618 | GetParam(), |
[email protected] | 733b7a6d | 2010-08-25 01:38:43 | [diff] [blame] | 4619 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"))); |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 4620 | helper.SetSession(make_scoped_refptr( |
| 4621 | SpdySessionDependencies::SpdyCreateSession(helper.session_deps().get()))); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4622 | helper.RunPreTestSetup(); |
| 4623 | HttpNetworkTransaction* trans = helper.trans(); |
| 4624 | |
| 4625 | const char kConnect443[] = {"CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 4626 | "Host: www.google.com\r\n" |
| 4627 | "Proxy-Connection: keep-alive\r\n\r\n"}; |
| 4628 | const char kConnect80[] = {"CONNECT www.google.com:80 HTTP/1.1\r\n" |
| 4629 | "Host: www.google.com\r\n" |
| 4630 | "Proxy-Connection: keep-alive\r\n\r\n"}; |
| 4631 | const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4632 | scoped_ptr<SpdyFrame> req( |
| 4633 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4634 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4635 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4636 | |
| 4637 | MockWrite writes_SPDYNPN[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4638 | MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4639 | CreateMockWrite(*req, 2), |
| 4640 | }; |
| 4641 | MockRead reads_SPDYNPN[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4642 | MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4643 | CreateMockRead(*resp, 3), |
| 4644 | CreateMockRead(*body.get(), 4), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4645 | MockRead(ASYNC, 0, 0, 5), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4646 | }; |
| 4647 | |
| 4648 | MockWrite writes_SPDYSSL[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4649 | MockWrite(SYNCHRONOUS, kConnect80, arraysize(kConnect80) - 1, 0), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4650 | CreateMockWrite(*req, 2), |
| 4651 | }; |
| 4652 | MockRead reads_SPDYSSL[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4653 | MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4654 | CreateMockRead(*resp, 3), |
| 4655 | CreateMockRead(*body.get(), 4), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4656 | MockRead(ASYNC, 0, 0, 5), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4657 | }; |
| 4658 | |
| 4659 | MockWrite writes_SPDYNOSSL[] = { |
| 4660 | CreateMockWrite(*req, 0), |
| 4661 | }; |
| 4662 | |
| 4663 | MockRead reads_SPDYNOSSL[] = { |
| 4664 | CreateMockRead(*resp, 1), |
| 4665 | CreateMockRead(*body.get(), 2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4666 | MockRead(ASYNC, 0, 0, 3), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4667 | }; |
| 4668 | |
[email protected] | a159531 | 2012-01-22 03:25:04 | [diff] [blame] | 4669 | scoped_ptr<OrderedSocketData> data; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4670 | switch(GetParam().ssl_type) { |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4671 | case SPDYNOSSL: |
[email protected] | a159531 | 2012-01-22 03:25:04 | [diff] [blame] | 4672 | data.reset(new OrderedSocketData(reads_SPDYNOSSL, |
| 4673 | arraysize(reads_SPDYNOSSL), |
| 4674 | writes_SPDYNOSSL, |
| 4675 | arraysize(writes_SPDYNOSSL))); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4676 | break; |
| 4677 | case SPDYSSL: |
[email protected] | a159531 | 2012-01-22 03:25:04 | [diff] [blame] | 4678 | data.reset(new OrderedSocketData(reads_SPDYSSL, |
| 4679 | arraysize(reads_SPDYSSL), |
| 4680 | writes_SPDYSSL, |
| 4681 | arraysize(writes_SPDYSSL))); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4682 | break; |
| 4683 | case SPDYNPN: |
[email protected] | a159531 | 2012-01-22 03:25:04 | [diff] [blame] | 4684 | data.reset(new OrderedSocketData(reads_SPDYNPN, |
| 4685 | arraysize(reads_SPDYNPN), |
| 4686 | writes_SPDYNPN, |
| 4687 | arraysize(writes_SPDYNPN))); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4688 | break; |
| 4689 | default: |
| 4690 | NOTREACHED(); |
| 4691 | } |
| 4692 | |
| 4693 | helper.AddData(data.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4694 | TestCompletionCallback callback; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4695 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4696 | int rv = trans->Start( |
| 4697 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4698 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4699 | |
| 4700 | rv = callback.WaitForResult(); |
| 4701 | EXPECT_EQ(0, rv); |
| 4702 | |
| 4703 | // Verify the SYN_REPLY. |
| 4704 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4705 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4706 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 4707 | |
| 4708 | std::string response_data; |
| 4709 | ASSERT_EQ(OK, ReadTransaction(trans, &response_data)); |
| 4710 | EXPECT_EQ("hello!", response_data); |
| 4711 | helper.VerifyDataConsumed(); |
| 4712 | } |
| 4713 | |
| 4714 | // Test to make sure we can correctly connect through a proxy to www.google.com, |
| 4715 | // if there already exists a direct spdy connection to www.google.com. See |
| 4716 | // http://crbug.com/49874 |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4717 | TEST_P(SpdyNetworkTransactionTest, DirectConnectProxyReconnect) { |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4718 | // When setting up the first transaction, we store the SpdySessionPool so that |
| 4719 | // we can use the same pool in the second transaction. |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4720 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4721 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 733b7a6d | 2010-08-25 01:38:43 | [diff] [blame] | 4722 | |
| 4723 | // Use a proxy service which returns a proxy fallback list from DIRECT to |
| 4724 | // myproxy:70. For this test there will be no fallback, so it is equivalent |
| 4725 | // to simply DIRECT. The reason for appending the second proxy is to verify |
| 4726 | // that the session pool key used does is just "DIRECT". |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4727 | helper.session_deps().reset(CreateSpdySessionDependencies( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4728 | GetParam(), |
[email protected] | 733b7a6d | 2010-08-25 01:38:43 | [diff] [blame] | 4729 | ProxyService::CreateFixedFromPacResult("DIRECT; PROXY myproxy:70"))); |
[email protected] | 00cd9c4 | 2010-11-02 20:15:57 | [diff] [blame] | 4730 | helper.SetSession(make_scoped_refptr( |
| 4731 | SpdySessionDependencies::SpdyCreateSession(helper.session_deps().get()))); |
[email protected] | 733b7a6d | 2010-08-25 01:38:43 | [diff] [blame] | 4732 | |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 4733 | SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4734 | helper.RunPreTestSetup(); |
| 4735 | |
| 4736 | // Construct and send a simple GET request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4737 | scoped_ptr<SpdyFrame> req( |
| 4738 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4739 | MockWrite writes[] = { |
| 4740 | CreateMockWrite(*req, 1), |
| 4741 | }; |
| 4742 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4743 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4744 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4745 | MockRead reads[] = { |
| 4746 | CreateMockRead(*resp, 2), |
| 4747 | CreateMockRead(*body, 3), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4748 | MockRead(ASYNC, ERR_IO_PENDING, 4), // Force a pause |
| 4749 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4750 | }; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4751 | OrderedSocketData data(reads, arraysize(reads), |
| 4752 | writes, arraysize(writes)); |
| 4753 | helper.AddData(&data); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4754 | HttpNetworkTransaction* trans = helper.trans(); |
| 4755 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4756 | TestCompletionCallback callback; |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4757 | TransactionHelperResult out; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4758 | out.rv = trans->Start( |
| 4759 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4760 | |
| 4761 | EXPECT_EQ(out.rv, ERR_IO_PENDING); |
| 4762 | out.rv = callback.WaitForResult(); |
| 4763 | EXPECT_EQ(out.rv, OK); |
| 4764 | |
| 4765 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4766 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4767 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4768 | out.rv = ReadTransaction(trans, &out.response_data); |
| 4769 | EXPECT_EQ(OK, out.rv); |
| 4770 | out.status_line = response->headers->GetStatusLine(); |
| 4771 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4772 | EXPECT_EQ("hello!", out.response_data); |
| 4773 | |
| 4774 | // Check that the SpdySession is still in the SpdySessionPool. |
| 4775 | HostPortPair host_port_pair("www.google.com", helper.port()); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 4776 | SpdySessionKey session_pool_key_direct( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 4777 | host_port_pair, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 4778 | EXPECT_TRUE(HasSpdySession(spdy_session_pool, session_pool_key_direct)); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 4779 | SpdySessionKey session_pool_key_proxy( |
[email protected] | 31e68d7 | 2010-08-25 06:36:58 | [diff] [blame] | 4780 | host_port_pair, |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 4781 | ProxyServer::FromURI("www.foo.com", ProxyServer::SCHEME_HTTP), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 4782 | PRIVACY_MODE_DISABLED); |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 4783 | EXPECT_FALSE(HasSpdySession(spdy_session_pool, session_pool_key_proxy)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4784 | |
| 4785 | // Set up data for the proxy connection. |
| 4786 | const char kConnect443[] = {"CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 4787 | "Host: www.google.com\r\n" |
| 4788 | "Proxy-Connection: keep-alive\r\n\r\n"}; |
| 4789 | const char kConnect80[] = {"CONNECT www.google.com:80 HTTP/1.1\r\n" |
| 4790 | "Host: www.google.com\r\n" |
| 4791 | "Proxy-Connection: keep-alive\r\n\r\n"}; |
| 4792 | const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4793 | scoped_ptr<SpdyFrame> req2(spdy_util_.ConstructSpdyGet( |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4794 | "http://www.google.com/foo.dat", false, 1, LOWEST)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4795 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4796 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4797 | |
| 4798 | MockWrite writes_SPDYNPN[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4799 | MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4800 | CreateMockWrite(*req2, 2), |
| 4801 | }; |
| 4802 | MockRead reads_SPDYNPN[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4803 | MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4804 | CreateMockRead(*resp2, 3), |
| 4805 | CreateMockRead(*body2, 4), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4806 | MockRead(ASYNC, 0, 5) // EOF |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4807 | }; |
| 4808 | |
| 4809 | MockWrite writes_SPDYNOSSL[] = { |
| 4810 | CreateMockWrite(*req2, 0), |
| 4811 | }; |
| 4812 | MockRead reads_SPDYNOSSL[] = { |
| 4813 | CreateMockRead(*resp2, 1), |
| 4814 | CreateMockRead(*body2, 2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4815 | MockRead(ASYNC, 0, 3) // EOF |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4816 | }; |
| 4817 | |
| 4818 | MockWrite writes_SPDYSSL[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4819 | MockWrite(SYNCHRONOUS, kConnect80, arraysize(kConnect80) - 1, 0), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4820 | CreateMockWrite(*req2, 2), |
| 4821 | }; |
| 4822 | MockRead reads_SPDYSSL[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4823 | MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4824 | CreateMockRead(*resp2, 3), |
| 4825 | CreateMockRead(*body2, 4), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4826 | MockRead(ASYNC, 0, 0, 5), |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4827 | }; |
| 4828 | |
[email protected] | a159531 | 2012-01-22 03:25:04 | [diff] [blame] | 4829 | scoped_ptr<OrderedSocketData> data_proxy; |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4830 | switch(GetParam().ssl_type) { |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4831 | case SPDYNPN: |
[email protected] | a159531 | 2012-01-22 03:25:04 | [diff] [blame] | 4832 | data_proxy.reset(new OrderedSocketData(reads_SPDYNPN, |
| 4833 | arraysize(reads_SPDYNPN), |
| 4834 | writes_SPDYNPN, |
| 4835 | arraysize(writes_SPDYNPN))); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4836 | break; |
| 4837 | case SPDYNOSSL: |
[email protected] | a159531 | 2012-01-22 03:25:04 | [diff] [blame] | 4838 | data_proxy.reset(new OrderedSocketData(reads_SPDYNOSSL, |
| 4839 | arraysize(reads_SPDYNOSSL), |
| 4840 | writes_SPDYNOSSL, |
| 4841 | arraysize(writes_SPDYNOSSL))); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4842 | break; |
| 4843 | case SPDYSSL: |
[email protected] | a159531 | 2012-01-22 03:25:04 | [diff] [blame] | 4844 | data_proxy.reset(new OrderedSocketData(reads_SPDYSSL, |
| 4845 | arraysize(reads_SPDYSSL), |
| 4846 | writes_SPDYSSL, |
| 4847 | arraysize(writes_SPDYSSL))); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4848 | break; |
| 4849 | default: |
| 4850 | NOTREACHED(); |
| 4851 | } |
| 4852 | |
| 4853 | // Create another request to www.google.com, but this time through a proxy. |
| 4854 | HttpRequestInfo request_proxy; |
| 4855 | request_proxy.method = "GET"; |
| 4856 | request_proxy.url = GURL("http://www.google.com/foo.dat"); |
| 4857 | request_proxy.load_flags = 0; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4858 | scoped_ptr<SpdySessionDependencies> ssd_proxy( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4859 | CreateSpdySessionDependencies(GetParam())); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4860 | // Ensure that this transaction uses the same SpdySessionPool. |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 4861 | scoped_refptr<HttpNetworkSession> session_proxy( |
| 4862 | SpdySessionDependencies::SpdyCreateSession(ssd_proxy.get())); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4863 | NormalSpdyTransactionHelper helper_proxy(request_proxy, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4864 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 4865 | HttpNetworkSessionPeer session_peer(session_proxy); |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 4866 | scoped_ptr<net::ProxyService> proxy_service( |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 4867 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
[email protected] | 6104ea5d | 2011-04-27 21:37:12 | [diff] [blame] | 4868 | session_peer.SetProxyService(proxy_service.get()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4869 | helper_proxy.session_deps().swap(ssd_proxy); |
[email protected] | 19ec8a7 | 2010-08-23 03:38:23 | [diff] [blame] | 4870 | helper_proxy.SetSession(session_proxy); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4871 | helper_proxy.RunPreTestSetup(); |
| 4872 | helper_proxy.AddData(data_proxy.get()); |
| 4873 | |
| 4874 | HttpNetworkTransaction* trans_proxy = helper_proxy.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4875 | TestCompletionCallback callback_proxy; |
| 4876 | int rv = trans_proxy->Start( |
| 4877 | &request_proxy, callback_proxy.callback(), BoundNetLog()); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4878 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4879 | rv = callback_proxy.WaitForResult(); |
| 4880 | EXPECT_EQ(0, rv); |
| 4881 | |
| 4882 | HttpResponseInfo response_proxy = *trans_proxy->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4883 | EXPECT_TRUE(response_proxy.headers.get() != NULL); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4884 | EXPECT_EQ("HTTP/1.1 200 OK", response_proxy.headers->GetStatusLine()); |
| 4885 | |
| 4886 | std::string response_data; |
| 4887 | ASSERT_EQ(OK, ReadTransaction(trans_proxy, &response_data)); |
| 4888 | EXPECT_EQ("hello!", response_data); |
| 4889 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4890 | data.CompleteRead(); |
[email protected] | b261d0e | 2010-08-02 19:13:24 | [diff] [blame] | 4891 | helper_proxy.VerifyDataConsumed(); |
| 4892 | } |
| 4893 | |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4894 | // When we get a TCP-level RST, we need to retry a HttpNetworkTransaction |
| 4895 | // on a new connection, if the connection was previously known to be good. |
| 4896 | // This can happen when a server reboots without saying goodbye, or when |
| 4897 | // we're behind a NAT that masked the RST. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4898 | TEST_P(SpdyNetworkTransactionTest, VerifyRetryOnConnectionReset) { |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4899 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4900 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4901 | MockRead reads[] = { |
| 4902 | CreateMockRead(*resp), |
| 4903 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4904 | MockRead(ASYNC, ERR_IO_PENDING), |
| 4905 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4906 | }; |
| 4907 | |
| 4908 | MockRead reads2[] = { |
| 4909 | CreateMockRead(*resp), |
| 4910 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4911 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4912 | }; |
| 4913 | |
| 4914 | // This test has a couple of variants. |
| 4915 | enum { |
| 4916 | // Induce the RST while waiting for our transaction to send. |
| 4917 | VARIANT_RST_DURING_SEND_COMPLETION, |
| 4918 | // Induce the RST while waiting for our transaction to read. |
| 4919 | // In this case, the send completed - everything copied into the SNDBUF. |
| 4920 | VARIANT_RST_DURING_READ_COMPLETION |
| 4921 | }; |
| 4922 | |
| 4923 | for (int variant = VARIANT_RST_DURING_SEND_COMPLETION; |
| 4924 | variant <= VARIANT_RST_DURING_READ_COMPLETION; |
| 4925 | ++variant) { |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4926 | DelayedSocketData data1(1, reads, arraysize(reads), NULL, 0); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4927 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4928 | DelayedSocketData data2(1, reads2, arraysize(reads2), NULL, 0); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4929 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4930 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4931 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4932 | helper.AddData(&data1); |
| 4933 | helper.AddData(&data2); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4934 | helper.RunPreTestSetup(); |
| 4935 | |
| 4936 | for (int i = 0; i < 2; ++i) { |
| 4937 | scoped_ptr<HttpNetworkTransaction> trans( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4938 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4939 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4940 | TestCompletionCallback callback; |
| 4941 | int rv = trans->Start( |
| 4942 | &helper.request(), callback.callback(), BoundNetLog()); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4943 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4944 | // On the second transaction, we trigger the RST. |
| 4945 | if (i == 1) { |
| 4946 | if (variant == VARIANT_RST_DURING_READ_COMPLETION) { |
| 4947 | // Writes to the socket complete asynchronously on SPDY by running |
| 4948 | // through the message loop. Complete the write here. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 4949 | base::RunLoop().RunUntilIdle(); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4950 | } |
| 4951 | |
| 4952 | // Now schedule the ERR_CONNECTION_RESET. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4953 | EXPECT_EQ(3u, data1.read_index()); |
| 4954 | data1.CompleteRead(); |
| 4955 | EXPECT_EQ(4u, data1.read_index()); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4956 | } |
| 4957 | rv = callback.WaitForResult(); |
| 4958 | EXPECT_EQ(OK, rv); |
| 4959 | |
| 4960 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
[email protected] | 351ab64 | 2010-08-05 16:55:31 | [diff] [blame] | 4961 | ASSERT_TRUE(response != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 4962 | EXPECT_TRUE(response->headers.get() != NULL); |
[email protected] | 58cebf8f | 2010-07-31 19:20:16 | [diff] [blame] | 4963 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4964 | std::string response_data; |
| 4965 | rv = ReadTransaction(trans.get(), &response_data); |
| 4966 | EXPECT_EQ(OK, rv); |
| 4967 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4968 | EXPECT_EQ("hello!", response_data); |
| 4969 | } |
| 4970 | |
| 4971 | helper.VerifyDataConsumed(); |
| 4972 | } |
| 4973 | } |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4974 | |
| 4975 | // Test that turning SPDY on and off works properly. |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4976 | TEST_P(SpdyNetworkTransactionTest, SpdyOnOffToggle) { |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4977 | net::HttpStreamFactory::set_spdy_enabled(true); |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4978 | scoped_ptr<SpdyFrame> req( |
| 4979 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4980 | MockWrite spdy_writes[] = { CreateMockWrite(*req) }; |
| 4981 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 4982 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4983 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4984 | MockRead spdy_reads[] = { |
| 4985 | CreateMockRead(*resp), |
| 4986 | CreateMockRead(*body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4987 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4988 | }; |
| 4989 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4990 | DelayedSocketData data(1, spdy_reads, arraysize(spdy_reads), |
| 4991 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 4992 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 4993 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 4994 | helper.RunToCompletion(&data); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 4995 | TransactionHelperResult out = helper.output(); |
| 4996 | EXPECT_EQ(OK, out.rv); |
| 4997 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4998 | EXPECT_EQ("hello!", out.response_data); |
| 4999 | |
| 5000 | net::HttpStreamFactory::set_spdy_enabled(false); |
| 5001 | MockRead http_reads[] = { |
| 5002 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 5003 | MockRead("hello from http"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5004 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 5005 | }; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5006 | DelayedSocketData data2(1, http_reads, arraysize(http_reads), NULL, 0); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5007 | NormalSpdyTransactionHelper helper2(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5008 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 5009 | helper2.SetSpdyDisabled(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5010 | helper2.RunToCompletion(&data2); |
[email protected] | 1f418ee | 2010-10-16 19:46:56 | [diff] [blame] | 5011 | TransactionHelperResult out2 = helper2.output(); |
| 5012 | EXPECT_EQ(OK, out2.rv); |
| 5013 | EXPECT_EQ("HTTP/1.1 200 OK", out2.status_line); |
| 5014 | EXPECT_EQ("hello from http", out2.response_data); |
| 5015 | |
| 5016 | net::HttpStreamFactory::set_spdy_enabled(true); |
| 5017 | } |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5018 | |
| 5019 | // Tests that Basic authentication works over SPDY |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5020 | TEST_P(SpdyNetworkTransactionTest, SpdyBasicAuth) { |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5021 | net::HttpStreamFactory::set_spdy_enabled(true); |
| 5022 | |
| 5023 | // The first request will be a bare GET, the second request will be a |
| 5024 | // GET with an Authorization header. |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5025 | scoped_ptr<SpdyFrame> req_get( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5026 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5027 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5028 | "authorization", "Basic Zm9vOmJhcg==" |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5029 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5030 | scoped_ptr<SpdyFrame> req_get_authorization( |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5031 | spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 5032 | arraysize(kExtraAuthorizationHeaders) / 2, |
| 5033 | false, 3, LOWEST, true)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5034 | MockWrite spdy_writes[] = { |
| 5035 | CreateMockWrite(*req_get, 1), |
| 5036 | CreateMockWrite(*req_get_authorization, 4), |
| 5037 | }; |
| 5038 | |
| 5039 | // The first response is a 401 authentication challenge, and the second |
| 5040 | // response will be a 200 response since the second request includes a valid |
| 5041 | // Authorization header. |
| 5042 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | fb9e431 | 2012-02-17 06:27:26 | [diff] [blame] | 5043 | "www-authenticate", |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5044 | "Basic realm=\"MyRealm\"" |
| 5045 | }; |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5046 | scoped_ptr<SpdyFrame> resp_authentication( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5047 | spdy_util_.ConstructSpdySynReplyError( |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5048 | "401 Authentication Required", |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5049 | kExtraAuthenticationHeaders, |
| 5050 | arraysize(kExtraAuthenticationHeaders) / 2, |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5051 | 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5052 | scoped_ptr<SpdyFrame> body_authentication( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5053 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 5054 | scoped_ptr<SpdyFrame> resp_data( |
| 5055 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 5056 | scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5057 | MockRead spdy_reads[] = { |
| 5058 | CreateMockRead(*resp_authentication, 2), |
| 5059 | CreateMockRead(*body_authentication, 3), |
| 5060 | CreateMockRead(*resp_data, 5), |
| 5061 | CreateMockRead(*body_data, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5062 | MockRead(ASYNC, 0, 7), |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5063 | }; |
| 5064 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5065 | OrderedSocketData data(spdy_reads, arraysize(spdy_reads), |
| 5066 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5067 | HttpRequestInfo request(CreateGetRequest()); |
| 5068 | BoundNetLog net_log; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5069 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 5070 | net_log, GetParam(), NULL); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5071 | |
| 5072 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5073 | helper.AddData(&data); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5074 | HttpNetworkTransaction* trans = helper.trans(); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5075 | TestCompletionCallback callback; |
| 5076 | const int rv_start = trans->Start(&request, callback.callback(), net_log); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5077 | EXPECT_EQ(ERR_IO_PENDING, rv_start); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5078 | const int rv_start_complete = callback.WaitForResult(); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5079 | EXPECT_EQ(OK, rv_start_complete); |
| 5080 | |
| 5081 | // Make sure the response has an auth challenge. |
| 5082 | const HttpResponseInfo* const response_start = trans->GetResponseInfo(); |
| 5083 | ASSERT_TRUE(response_start != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5084 | ASSERT_TRUE(response_start->headers.get() != NULL); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5085 | EXPECT_EQ(401, response_start->headers->response_code()); |
| 5086 | EXPECT_TRUE(response_start->was_fetched_via_spdy); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5087 | AuthChallengeInfo* auth_challenge = response_start->auth_challenge.get(); |
| 5088 | ASSERT_TRUE(auth_challenge != NULL); |
| 5089 | EXPECT_FALSE(auth_challenge->is_proxy); |
| 5090 | EXPECT_EQ("basic", auth_challenge->scheme); |
| 5091 | EXPECT_EQ("MyRealm", auth_challenge->realm); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5092 | |
| 5093 | // Restart with a username/password. |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 5094 | AuthCredentials credentials(base::ASCIIToUTF16("foo"), |
| 5095 | base::ASCIIToUTF16("bar")); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5096 | TestCompletionCallback callback_restart; |
| 5097 | const int rv_restart = trans->RestartWithAuth( |
| 5098 | credentials, callback_restart.callback()); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5099 | EXPECT_EQ(ERR_IO_PENDING, rv_restart); |
| 5100 | const int rv_restart_complete = callback_restart.WaitForResult(); |
| 5101 | EXPECT_EQ(OK, rv_restart_complete); |
| 5102 | // TODO(cbentzel): This is actually the same response object as before, but |
| 5103 | // data has changed. |
| 5104 | const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 5105 | ASSERT_TRUE(response_restart != NULL); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5106 | ASSERT_TRUE(response_restart->headers.get() != NULL); |
[email protected] | 018aabc | 2010-10-29 16:16:59 | [diff] [blame] | 5107 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5108 | EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 5109 | } |
| 5110 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5111 | TEST_P(SpdyNetworkTransactionTest, ServerPushWithHeaders) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5112 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5113 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5114 | scoped_ptr<SpdyFrame> stream1_body( |
| 5115 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5116 | MockWrite writes[] = { |
| 5117 | CreateMockWrite(*stream1_syn, 1), |
| 5118 | }; |
| 5119 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5120 | scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
| 5121 | spdy_util_.AddUrlToHeaderBlock( |
| 5122 | "http://www.google.com/foo.dat", initial_headers.get()); |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5123 | scoped_ptr<SpdyFrame> stream2_syn( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5124 | spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5125 | false, |
| 5126 | 2, |
| 5127 | LOWEST, |
| 5128 | SYN_STREAM, |
| 5129 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5130 | 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5131 | |
| 5132 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5133 | (*late_headers)["hello"] = "bye"; |
| 5134 | (*late_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 5135 | (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5136 | scoped_ptr<SpdyFrame> stream2_headers( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5137 | spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5138 | false, |
| 5139 | 2, |
| 5140 | LOWEST, |
| 5141 | HEADERS, |
| 5142 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5143 | 0)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5144 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5145 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5146 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5147 | const char kPushedData[] = "pushed"; |
| 5148 | scoped_ptr<SpdyFrame> stream2_body( |
| 5149 | spdy_util_.ConstructSpdyBodyFrame( |
| 5150 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5151 | MockRead reads[] = { |
| 5152 | CreateMockRead(*stream1_reply, 2), |
| 5153 | CreateMockRead(*stream2_syn, 3), |
| 5154 | CreateMockRead(*stream2_headers, 4), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5155 | CreateMockRead(*stream1_body, 5, SYNCHRONOUS), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5156 | CreateMockRead(*stream2_body, 5), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5157 | MockRead(ASYNC, ERR_IO_PENDING, 7), // Force a pause |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5158 | }; |
| 5159 | |
| 5160 | HttpResponseInfo response; |
| 5161 | HttpResponseInfo response2; |
| 5162 | std::string expected_push_result("pushed"); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5163 | OrderedSocketData data(reads, arraysize(reads), |
| 5164 | writes, arraysize(writes)); |
| 5165 | RunServerPushTest(&data, |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5166 | &response, |
| 5167 | &response2, |
| 5168 | expected_push_result); |
| 5169 | |
| 5170 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5171 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5172 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5173 | |
| 5174 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5175 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5176 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 5177 | } |
| 5178 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5179 | TEST_P(SpdyNetworkTransactionTest, ServerPushClaimBeforeHeaders) { |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5180 | // 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] | 5181 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5182 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5183 | scoped_ptr<SpdyFrame> stream1_body( |
| 5184 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5185 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5186 | CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5187 | }; |
| 5188 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5189 | scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
| 5190 | spdy_util_.AddUrlToHeaderBlock( |
| 5191 | "http://www.google.com/foo.dat", initial_headers.get()); |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5192 | scoped_ptr<SpdyFrame> stream2_syn( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5193 | spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5194 | false, |
| 5195 | 2, |
| 5196 | LOWEST, |
| 5197 | SYN_STREAM, |
| 5198 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5199 | 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5200 | |
| 5201 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5202 | (*late_headers)["hello"] = "bye"; |
| 5203 | (*late_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 5204 | (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5205 | scoped_ptr<SpdyFrame> stream2_headers( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5206 | spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5207 | false, |
| 5208 | 2, |
| 5209 | LOWEST, |
| 5210 | HEADERS, |
| 5211 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5212 | 0)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5213 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5214 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5215 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5216 | const char kPushedData[] = "pushed"; |
| 5217 | scoped_ptr<SpdyFrame> stream2_body( |
| 5218 | spdy_util_.ConstructSpdyBodyFrame( |
| 5219 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5220 | MockRead reads[] = { |
| 5221 | CreateMockRead(*stream1_reply, 1), |
| 5222 | CreateMockRead(*stream2_syn, 2), |
| 5223 | CreateMockRead(*stream1_body, 3), |
| 5224 | CreateMockRead(*stream2_headers, 4), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5225 | CreateMockRead(*stream2_body, 5), |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 5226 | MockRead(ASYNC, 0, 6), // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5227 | }; |
| 5228 | |
| 5229 | HttpResponseInfo response; |
| 5230 | HttpResponseInfo response2; |
| 5231 | std::string expected_push_result("pushed"); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5232 | DeterministicSocketData data(reads, arraysize(reads), |
| 5233 | writes, arraysize(writes)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5234 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5235 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5236 | BoundNetLog(), GetParam(), NULL); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5237 | helper.SetDeterministic(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5238 | helper.AddDeterministicData(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5239 | helper.RunPreTestSetup(); |
| 5240 | |
| 5241 | HttpNetworkTransaction* trans = helper.trans(); |
| 5242 | |
| 5243 | // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM, |
| 5244 | // and the body of the primary stream, but before we've received the HEADERS |
| 5245 | // for the pushed stream. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5246 | data.SetStop(3); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5247 | |
| 5248 | // Start the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5249 | TestCompletionCallback callback; |
| 5250 | int rv = trans->Start( |
| 5251 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5252 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5253 | data.Run(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5254 | rv = callback.WaitForResult(); |
| 5255 | EXPECT_EQ(0, rv); |
| 5256 | |
| 5257 | // Request the pushed path. At this point, we've received the push, but the |
| 5258 | // headers are not yet complete. |
| 5259 | scoped_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5260 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5261 | rv = trans2->Start( |
| 5262 | &CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5263 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5264 | data.RunFor(3); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5265 | base::RunLoop().RunUntilIdle(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5266 | |
| 5267 | // Read the server push body. |
| 5268 | std::string result2; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5269 | ReadResult(trans2.get(), &data, &result2); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5270 | // Read the response body. |
| 5271 | std::string result; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5272 | ReadResult(trans, &data, &result); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5273 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5274 | // Verify that the received push data is same as the expected push data. |
| 5275 | EXPECT_EQ(result2.compare(expected_push_result), 0) |
| 5276 | << "Received data: " |
| 5277 | << result2 |
| 5278 | << "||||| Expected data: " |
| 5279 | << expected_push_result; |
| 5280 | |
| 5281 | // Verify the SYN_REPLY. |
| 5282 | // Copy the response info, because trans goes away. |
| 5283 | response = *trans->GetResponseInfo(); |
| 5284 | response2 = *trans2->GetResponseInfo(); |
| 5285 | |
| 5286 | VerifyStreamsClosed(helper); |
| 5287 | |
| 5288 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5289 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5290 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5291 | |
| 5292 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5293 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5294 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 5295 | |
| 5296 | // Read the final EOF (which will close the session) |
| 5297 | data.RunFor(1); |
| 5298 | |
| 5299 | // Verify that we consumed all test data. |
| 5300 | EXPECT_TRUE(data.at_read_eof()); |
| 5301 | EXPECT_TRUE(data.at_write_eof()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5302 | } |
| 5303 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5304 | TEST_P(SpdyNetworkTransactionTest, ServerPushWithTwoHeaderFrames) { |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5305 | // 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] | 5306 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5307 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5308 | scoped_ptr<SpdyFrame> stream1_body( |
| 5309 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5310 | MockWrite writes[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5311 | CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5312 | }; |
| 5313 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5314 | scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
| 5315 | spdy_util_.AddUrlToHeaderBlock( |
| 5316 | "http://www.google.com/foo.dat", initial_headers.get()); |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5317 | scoped_ptr<SpdyFrame> stream2_syn( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5318 | spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5319 | false, |
| 5320 | 2, |
| 5321 | LOWEST, |
| 5322 | SYN_STREAM, |
| 5323 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5324 | 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5325 | |
| 5326 | scoped_ptr<SpdyHeaderBlock> middle_headers(new SpdyHeaderBlock()); |
| 5327 | (*middle_headers)["hello"] = "bye"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5328 | scoped_ptr<SpdyFrame> stream2_headers1( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5329 | spdy_util_.ConstructSpdyControlFrame(middle_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5330 | false, |
| 5331 | 2, |
| 5332 | LOWEST, |
| 5333 | HEADERS, |
| 5334 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5335 | 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5336 | |
| 5337 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5338 | (*late_headers)[spdy_util_.GetStatusKey()] = "200"; |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5339 | if (spdy_util_.spdy_version() < SPDY4) { |
| 5340 | // SPDY4/HTTP2 eliminates use of the :version header. |
| 5341 | (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
| 5342 | } |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5343 | scoped_ptr<SpdyFrame> stream2_headers2( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5344 | spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5345 | false, |
| 5346 | 2, |
| 5347 | LOWEST, |
| 5348 | HEADERS, |
| 5349 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5350 | 0)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5351 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5352 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5353 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5354 | const char kPushedData[] = "pushed"; |
| 5355 | scoped_ptr<SpdyFrame> stream2_body( |
| 5356 | spdy_util_.ConstructSpdyBodyFrame( |
| 5357 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5358 | MockRead reads[] = { |
| 5359 | CreateMockRead(*stream1_reply, 1), |
| 5360 | CreateMockRead(*stream2_syn, 2), |
| 5361 | CreateMockRead(*stream1_body, 3), |
| 5362 | CreateMockRead(*stream2_headers1, 4), |
| 5363 | CreateMockRead(*stream2_headers2, 5), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5364 | CreateMockRead(*stream2_body, 6), |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 5365 | MockRead(ASYNC, 0, 7), // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5366 | }; |
| 5367 | |
| 5368 | HttpResponseInfo response; |
| 5369 | HttpResponseInfo response2; |
| 5370 | std::string expected_push_result("pushed"); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5371 | DeterministicSocketData data(reads, arraysize(reads), |
| 5372 | writes, arraysize(writes)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5373 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5374 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5375 | BoundNetLog(), GetParam(), NULL); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5376 | helper.SetDeterministic(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5377 | helper.AddDeterministicData(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5378 | helper.RunPreTestSetup(); |
| 5379 | |
| 5380 | HttpNetworkTransaction* trans = helper.trans(); |
| 5381 | |
| 5382 | // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM, |
| 5383 | // the first HEADERS frame, and the body of the primary stream, but before |
| 5384 | // we've received the final HEADERS for the pushed stream. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5385 | data.SetStop(4); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5386 | |
| 5387 | // Start the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5388 | TestCompletionCallback callback; |
| 5389 | int rv = trans->Start( |
| 5390 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5391 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5392 | data.Run(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5393 | rv = callback.WaitForResult(); |
| 5394 | EXPECT_EQ(0, rv); |
| 5395 | |
| 5396 | // Request the pushed path. At this point, we've received the push, but the |
| 5397 | // headers are not yet complete. |
| 5398 | scoped_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5399 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5400 | rv = trans2->Start( |
| 5401 | &CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5402 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5403 | data.RunFor(3); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5404 | base::RunLoop().RunUntilIdle(); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5405 | |
| 5406 | // Read the server push body. |
| 5407 | std::string result2; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5408 | ReadResult(trans2.get(), &data, &result2); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5409 | // Read the response body. |
| 5410 | std::string result; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5411 | ReadResult(trans, &data, &result); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5412 | |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5413 | // Verify that the received push data is same as the expected push data. |
[email protected] | 6d116e1a | 2013-06-24 07:42:15 | [diff] [blame] | 5414 | EXPECT_EQ(expected_push_result, result2); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5415 | |
| 5416 | // Verify the SYN_REPLY. |
| 5417 | // Copy the response info, because trans goes away. |
| 5418 | response = *trans->GetResponseInfo(); |
| 5419 | response2 = *trans2->GetResponseInfo(); |
| 5420 | |
| 5421 | VerifyStreamsClosed(helper); |
| 5422 | |
| 5423 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5424 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5425 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5426 | |
| 5427 | // Verify the pushed stream. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5428 | EXPECT_TRUE(response2.headers.get() != NULL); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5429 | EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 5430 | |
| 5431 | // Verify we got all the headers |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5432 | if (spdy_util_.spdy_version() < SPDY3) { |
| 5433 | EXPECT_TRUE(response2.headers->HasHeaderValue( |
| 5434 | "url", |
| 5435 | "http://www.google.com/foo.dat")); |
| 5436 | } else { |
| 5437 | EXPECT_TRUE(response2.headers->HasHeaderValue( |
| 5438 | "scheme", "http")); |
| 5439 | EXPECT_TRUE(response2.headers->HasHeaderValue( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5440 | "path", "/foo.dat")); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5441 | if (spdy_util_.spdy_version() < SPDY4) { |
| 5442 | EXPECT_TRUE(response2.headers->HasHeaderValue( |
| 5443 | "host", "www.google.com")); |
| 5444 | } else { |
| 5445 | EXPECT_TRUE(response2.headers->HasHeaderValue( |
| 5446 | "authority", "www.google.com")); |
| 5447 | } |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5448 | } |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5449 | EXPECT_TRUE(response2.headers->HasHeaderValue("hello", "bye")); |
| 5450 | EXPECT_TRUE(response2.headers->HasHeaderValue("status", "200")); |
[email protected] | d55b30a | 2012-07-21 00:35:39 | [diff] [blame] | 5451 | |
| 5452 | // Read the final EOF (which will close the session) |
| 5453 | data.RunFor(1); |
| 5454 | |
| 5455 | // Verify that we consumed all test data. |
| 5456 | EXPECT_TRUE(data.at_read_eof()); |
| 5457 | EXPECT_TRUE(data.at_write_eof()); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5458 | } |
| 5459 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5460 | TEST_P(SpdyNetworkTransactionTest, ServerPushWithNoStatusHeaderFrames) { |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5461 | // 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] | 5462 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5463 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5464 | scoped_ptr<SpdyFrame> stream1_body( |
| 5465 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5466 | MockWrite writes[] = { |
| 5467 | CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), |
| 5468 | }; |
| 5469 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5470 | scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
| 5471 | spdy_util_.AddUrlToHeaderBlock( |
| 5472 | "http://www.google.com/foo.dat", initial_headers.get()); |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5473 | scoped_ptr<SpdyFrame> stream2_syn( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5474 | spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5475 | false, |
| 5476 | 2, |
| 5477 | LOWEST, |
| 5478 | SYN_STREAM, |
| 5479 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5480 | 1)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5481 | |
| 5482 | scoped_ptr<SpdyHeaderBlock> middle_headers(new SpdyHeaderBlock()); |
| 5483 | (*middle_headers)["hello"] = "bye"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5484 | scoped_ptr<SpdyFrame> stream2_headers1( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5485 | spdy_util_.ConstructSpdyControlFrame(middle_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5486 | false, |
| 5487 | 2, |
| 5488 | LOWEST, |
| 5489 | HEADERS, |
| 5490 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5491 | 0)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5492 | |
| 5493 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5494 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5495 | const char kPushedData[] = "pushed"; |
| 5496 | scoped_ptr<SpdyFrame> stream2_body( |
| 5497 | spdy_util_.ConstructSpdyBodyFrame( |
| 5498 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5499 | MockRead reads[] = { |
| 5500 | CreateMockRead(*stream1_reply, 1), |
| 5501 | CreateMockRead(*stream2_syn, 2), |
| 5502 | CreateMockRead(*stream1_body, 3), |
| 5503 | CreateMockRead(*stream2_headers1, 4), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5504 | CreateMockRead(*stream2_body, 5), |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5505 | MockRead(ASYNC, 0, 6), // EOF |
| 5506 | }; |
| 5507 | |
| 5508 | DeterministicSocketData data(reads, arraysize(reads), |
| 5509 | writes, arraysize(writes)); |
| 5510 | |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5511 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5512 | BoundNetLog(), GetParam(), NULL); |
| 5513 | helper.SetDeterministic(); |
| 5514 | helper.AddDeterministicData(&data); |
| 5515 | helper.RunPreTestSetup(); |
| 5516 | |
| 5517 | HttpNetworkTransaction* trans = helper.trans(); |
| 5518 | |
| 5519 | // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM, |
| 5520 | // the first HEADERS frame, and the body of the primary stream, but before |
| 5521 | // we've received the final HEADERS for the pushed stream. |
| 5522 | data.SetStop(4); |
| 5523 | |
| 5524 | // Start the transaction. |
| 5525 | TestCompletionCallback callback; |
| 5526 | int rv = trans->Start( |
| 5527 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 5528 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5529 | data.Run(); |
| 5530 | rv = callback.WaitForResult(); |
| 5531 | EXPECT_EQ(0, rv); |
| 5532 | |
| 5533 | // Request the pushed path. At this point, we've received the push, but the |
| 5534 | // headers are not yet complete. |
| 5535 | scoped_ptr<HttpNetworkTransaction> trans2( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5536 | new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5537 | rv = trans2->Start( |
| 5538 | &CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
| 5539 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5540 | data.RunFor(2); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5541 | base::RunLoop().RunUntilIdle(); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5542 | |
| 5543 | // Read the server push body. |
| 5544 | std::string result2; |
| 5545 | ReadResult(trans2.get(), &data, &result2); |
| 5546 | // Read the response body. |
| 5547 | std::string result; |
| 5548 | ReadResult(trans, &data, &result); |
| 5549 | EXPECT_EQ("hello!", result); |
| 5550 | |
| 5551 | // Verify that we haven't received any push data. |
| 5552 | EXPECT_EQ("", result2); |
| 5553 | |
| 5554 | // Verify the SYN_REPLY. |
| 5555 | // Copy the response info, because trans goes away. |
| 5556 | HttpResponseInfo response = *trans->GetResponseInfo(); |
| 5557 | ASSERT_TRUE(trans2->GetResponseInfo() == NULL); |
| 5558 | |
| 5559 | VerifyStreamsClosed(helper); |
| 5560 | |
| 5561 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5562 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | 5c6908e | 2012-08-06 18:53:47 | [diff] [blame] | 5563 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5564 | |
| 5565 | // Read the final EOF (which will close the session). |
| 5566 | data.RunFor(1); |
| 5567 | |
| 5568 | // Verify that we consumed all test data. |
| 5569 | EXPECT_TRUE(data.at_read_eof()); |
| 5570 | EXPECT_TRUE(data.at_write_eof()); |
| 5571 | } |
| 5572 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5573 | TEST_P(SpdyNetworkTransactionTest, SynReplyWithHeaders) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5574 | scoped_ptr<SpdyFrame> req( |
| 5575 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5576 | scoped_ptr<SpdyFrame> rst( |
| 5577 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 5578 | MockWrite writes[] = { |
| 5579 | CreateMockWrite(*req), |
| 5580 | CreateMockWrite(*rst), |
| 5581 | }; |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5582 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5583 | scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
| 5584 | (*initial_headers)[spdy_util_.GetStatusKey()] = "200 OK"; |
| 5585 | (*initial_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5586 | scoped_ptr<SpdyFrame> stream1_reply( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5587 | spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5588 | false, |
| 5589 | 1, |
| 5590 | LOWEST, |
| 5591 | SYN_REPLY, |
| 5592 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5593 | 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5594 | |
| 5595 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5596 | (*late_headers)["hello"] = "bye"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5597 | scoped_ptr<SpdyFrame> stream1_headers( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5598 | spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5599 | false, |
| 5600 | 1, |
| 5601 | LOWEST, |
| 5602 | HEADERS, |
| 5603 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5604 | 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5605 | scoped_ptr<SpdyFrame> stream1_body( |
| 5606 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5607 | MockRead reads[] = { |
| 5608 | CreateMockRead(*stream1_reply), |
| 5609 | CreateMockRead(*stream1_headers), |
| 5610 | CreateMockRead(*stream1_body), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5611 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5612 | }; |
| 5613 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5614 | DelayedSocketData data(1, reads, arraysize(reads), |
| 5615 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5616 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5617 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5618 | helper.RunToCompletion(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5619 | TransactionHelperResult out = helper.output(); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5620 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5621 | } |
| 5622 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5623 | TEST_P(SpdyNetworkTransactionTest, SynReplyWithLateHeaders) { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5624 | scoped_ptr<SpdyFrame> req( |
| 5625 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5626 | scoped_ptr<SpdyFrame> rst( |
| 5627 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 5628 | MockWrite writes[] = { |
| 5629 | CreateMockWrite(*req), |
| 5630 | CreateMockWrite(*rst), |
| 5631 | }; |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5632 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5633 | scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
| 5634 | (*initial_headers)[spdy_util_.GetStatusKey()] = "200 OK"; |
| 5635 | (*initial_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5636 | scoped_ptr<SpdyFrame> stream1_reply( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5637 | spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5638 | false, |
| 5639 | 1, |
| 5640 | LOWEST, |
| 5641 | SYN_REPLY, |
| 5642 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5643 | 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5644 | |
| 5645 | scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5646 | (*late_headers)["hello"] = "bye"; |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5647 | scoped_ptr<SpdyFrame> stream1_headers( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5648 | spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5649 | false, |
| 5650 | 1, |
| 5651 | LOWEST, |
| 5652 | HEADERS, |
| 5653 | CONTROL_FLAG_NONE, |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 5654 | 0)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5655 | scoped_ptr<SpdyFrame> stream1_body( |
| 5656 | spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 5657 | scoped_ptr<SpdyFrame> stream1_body2( |
| 5658 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5659 | MockRead reads[] = { |
| 5660 | CreateMockRead(*stream1_reply), |
| 5661 | CreateMockRead(*stream1_body), |
| 5662 | CreateMockRead(*stream1_headers), |
| 5663 | CreateMockRead(*stream1_body2), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5664 | MockRead(ASYNC, 0, 0) // EOF |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5665 | }; |
| 5666 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5667 | DelayedSocketData data(1, reads, arraysize(reads), |
| 5668 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5669 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5670 | BoundNetLog(), GetParam(), NULL); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5671 | helper.RunToCompletion(&data); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5672 | TransactionHelperResult out = helper.output(); |
[email protected] | b771bb7 | 2013-06-24 09:55:41 | [diff] [blame] | 5673 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
[email protected] | d0835850 | 2010-12-03 22:04:03 | [diff] [blame] | 5674 | } |
| 5675 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5676 | TEST_P(SpdyNetworkTransactionTest, ServerPushCrossOriginCorrectness) { |
[email protected] | 00b2947 | 2014-01-16 18:10:24 | [diff] [blame] | 5677 | if (spdy_util_.spdy_version() == SPDY4) { |
| 5678 | // TODO(jgraettinger): We don't support associated stream |
| 5679 | // checks in SPDY4 yet. |
| 5680 | return; |
| 5681 | } |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5682 | // In this test we want to verify that we can't accidentally push content |
| 5683 | // which can't be pushed by this content server. |
| 5684 | // This test assumes that: |
| 5685 | // - if we're requesting http://www.foo.com/barbaz |
| 5686 | // - the browser has made a connection to "www.foo.com". |
| 5687 | |
| 5688 | // A list of the URL to fetch, followed by the URL being pushed. |
| 5689 | static const char* const kTestCases[] = { |
| 5690 | "http://www.google.com/foo.html", |
| 5691 | "http://www.google.com:81/foo.js", // Bad port |
| 5692 | |
| 5693 | "http://www.google.com/foo.html", |
| 5694 | "https://www.google.com/foo.js", // Bad protocol |
| 5695 | |
| 5696 | "http://www.google.com/foo.html", |
| 5697 | "ftp://www.google.com/foo.js", // Invalid Protocol |
| 5698 | |
| 5699 | "http://www.google.com/foo.html", |
| 5700 | "http://blat.www.google.com/foo.js", // Cross subdomain |
| 5701 | |
| 5702 | "http://www.google.com/foo.html", |
| 5703 | "http://www.foo.com/foo.js", // Cross domain |
| 5704 | }; |
| 5705 | |
[email protected] | b3f89933 | 2010-12-08 18:20:44 | [diff] [blame] | 5706 | for (size_t index = 0; index < arraysize(kTestCases); index += 2) { |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5707 | const char* url_to_fetch = kTestCases[index]; |
| 5708 | const char* url_to_push = kTestCases[index + 1]; |
| 5709 | |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5710 | scoped_ptr<SpdyFrame> stream1_syn( |
| 5711 | spdy_util_.ConstructSpdyGet(url_to_fetch, false, 1, LOWEST)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5712 | scoped_ptr<SpdyFrame> stream1_body( |
| 5713 | spdy_util_.ConstructSpdyBodyFrame(1, true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5714 | scoped_ptr<SpdyFrame> push_rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5715 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5716 | MockWrite writes[] = { |
| 5717 | CreateMockWrite(*stream1_syn, 1), |
| 5718 | CreateMockWrite(*push_rst, 4), |
| 5719 | }; |
| 5720 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5721 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5722 | stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5723 | scoped_ptr<SpdyFrame> |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5724 | stream2_syn(spdy_util_.ConstructSpdyPush(NULL, |
| 5725 | 0, |
| 5726 | 2, |
| 5727 | 1, |
| 5728 | url_to_push)); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5729 | const char kPushedData[] = "pushed"; |
| 5730 | scoped_ptr<SpdyFrame> stream2_body( |
| 5731 | spdy_util_.ConstructSpdyBodyFrame( |
| 5732 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5733 | scoped_ptr<SpdyFrame> rst( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5734 | spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_CANCEL)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5735 | |
| 5736 | MockRead reads[] = { |
| 5737 | CreateMockRead(*stream1_reply, 2), |
| 5738 | CreateMockRead(*stream2_syn, 3), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5739 | CreateMockRead(*stream1_body, 5, SYNCHRONOUS), |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 5740 | CreateMockRead(*stream2_body, 6), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5741 | MockRead(ASYNC, ERR_IO_PENDING, 7), // Force a pause |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5742 | }; |
| 5743 | |
| 5744 | HttpResponseInfo response; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5745 | OrderedSocketData data(reads, arraysize(reads), |
| 5746 | writes, arraysize(writes)); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5747 | |
| 5748 | HttpRequestInfo request; |
| 5749 | request.method = "GET"; |
| 5750 | request.url = GURL(url_to_fetch); |
| 5751 | request.load_flags = 0; |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5752 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 5753 | // Enable cross-origin push. Since we are not using a proxy, this should |
| 5754 | // not actually enable cross-origin SPDY push. |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5755 | scoped_ptr<SpdySessionDependencies> session_deps( |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5756 | CreateSpdySessionDependencies(GetParam())); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5757 | session_deps->trusted_spdy_proxy = "123.45.67.89:8080"; |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5758 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5759 | BoundNetLog(), GetParam(), |
| 5760 | session_deps.release()); |
| 5761 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5762 | helper.AddData(&data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 5763 | |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5764 | HttpNetworkTransaction* trans = helper.trans(); |
| 5765 | |
| 5766 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5767 | TestCompletionCallback callback; |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5768 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5769 | int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5770 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5771 | rv = callback.WaitForResult(); |
| 5772 | |
| 5773 | // Read the response body. |
| 5774 | std::string result; |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5775 | ReadResult(trans, &data, &result); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5776 | |
| 5777 | // Verify that we consumed all test data. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5778 | EXPECT_TRUE(data.at_read_eof()); |
| 5779 | EXPECT_TRUE(data.at_write_eof()); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5780 | |
| 5781 | // Verify the SYN_REPLY. |
| 5782 | // Copy the response info, because trans goes away. |
| 5783 | response = *trans->GetResponseInfo(); |
| 5784 | |
| 5785 | VerifyStreamsClosed(helper); |
| 5786 | |
| 5787 | // Verify the SYN_REPLY. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5788 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | a7a265ef | 2010-12-08 18:05:57 | [diff] [blame] | 5789 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5790 | } |
| 5791 | } |
| 5792 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5793 | TEST_P(SpdyNetworkTransactionTest, RetryAfterRefused) { |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5794 | // Construct the request. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5795 | scoped_ptr<SpdyFrame> req( |
| 5796 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5797 | scoped_ptr<SpdyFrame> req2( |
| 5798 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5799 | MockWrite writes[] = { |
| 5800 | CreateMockWrite(*req, 1), |
| 5801 | CreateMockWrite(*req2, 3), |
| 5802 | }; |
| 5803 | |
[email protected] | ff98d7f0 | 2012-03-22 21:44:19 | [diff] [blame] | 5804 | scoped_ptr<SpdyFrame> refused( |
[email protected] | c10b2085 | 2013-05-15 21:29:20 | [diff] [blame] | 5805 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_REFUSED_STREAM)); |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5806 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 5807 | scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5808 | MockRead reads[] = { |
| 5809 | CreateMockRead(*refused, 2), |
| 5810 | CreateMockRead(*resp, 4), |
| 5811 | CreateMockRead(*body, 5), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5812 | MockRead(ASYNC, 0, 6) // EOF |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5813 | }; |
| 5814 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5815 | OrderedSocketData data(reads, arraysize(reads), |
| 5816 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5817 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 5818 | BoundNetLog(), GetParam(), NULL); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5819 | |
| 5820 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5821 | helper.AddData(&data); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5822 | |
| 5823 | HttpNetworkTransaction* trans = helper.trans(); |
| 5824 | |
| 5825 | // Start the transaction with basic parameters. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5826 | TestCompletionCallback callback; |
| 5827 | int rv = trans->Start( |
| 5828 | &CreateGetRequest(), callback.callback(), BoundNetLog()); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5829 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5830 | rv = callback.WaitForResult(); |
| 5831 | EXPECT_EQ(OK, rv); |
| 5832 | |
| 5833 | // Verify that we consumed all test data. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5834 | EXPECT_TRUE(data.at_read_eof()) << "Read count: " |
| 5835 | << data.read_count() |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5836 | << " Read index: " |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5837 | << data.read_index(); |
| 5838 | EXPECT_TRUE(data.at_write_eof()) << "Write count: " |
| 5839 | << data.write_count() |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5840 | << " Write index: " |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5841 | << data.write_index(); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5842 | |
| 5843 | // Verify the SYN_REPLY. |
| 5844 | HttpResponseInfo response = *trans->GetResponseInfo(); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5845 | EXPECT_TRUE(response.headers.get() != NULL); |
[email protected] | 721c0ce | 2011-10-13 02:41:00 | [diff] [blame] | 5846 | EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5847 | } |
| 5848 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5849 | TEST_P(SpdyNetworkTransactionTest, OutOfOrderSynStream) { |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5850 | // This first request will start to establish the SpdySession. |
| 5851 | // Then we will start the second (MEDIUM priority) and then third |
| 5852 | // (HIGHEST priority) request in such a way that the third will actually |
[email protected] | c92f4b454 | 2012-07-26 23:53:21 | [diff] [blame] | 5853 | // start before the second, causing the second to be numbered differently |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5854 | // than the order they were created. |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5855 | scoped_ptr<SpdyFrame> req1( |
| 5856 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5857 | scoped_ptr<SpdyFrame> req2( |
| 5858 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, HIGHEST, true)); |
| 5859 | scoped_ptr<SpdyFrame> req3( |
| 5860 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, MEDIUM, true)); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5861 | MockWrite writes[] = { |
| 5862 | CreateMockWrite(*req1, 0), |
| 5863 | CreateMockWrite(*req2, 3), |
| 5864 | CreateMockWrite(*req3, 4), |
| 5865 | }; |
| 5866 | |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5867 | scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 5868 | scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 5869 | scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 5870 | scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 5871 | scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 5872 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5873 | MockRead reads[] = { |
| 5874 | CreateMockRead(*resp1, 1), |
| 5875 | CreateMockRead(*body1, 2), |
| 5876 | CreateMockRead(*resp2, 5), |
| 5877 | CreateMockRead(*body2, 6), |
| 5878 | CreateMockRead(*resp3, 7), |
| 5879 | CreateMockRead(*body3, 8), |
| 5880 | MockRead(ASYNC, 0, 9) // EOF |
| 5881 | }; |
| 5882 | |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5883 | DeterministicSocketData data(reads, arraysize(reads), |
[email protected] | 513963e | 2013-06-15 01:53:04 | [diff] [blame] | 5884 | writes, arraysize(writes)); |
[email protected] | 262eec8 | 2013-03-19 21:01:36 | [diff] [blame] | 5885 | NormalSpdyTransactionHelper helper(CreateGetRequest(), LOWEST, |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5886 | BoundNetLog(), GetParam(), NULL); |
| 5887 | helper.SetDeterministic(); |
| 5888 | helper.RunPreTestSetup(); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5889 | helper.AddDeterministicData(&data); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5890 | |
| 5891 | // Start the first transaction to set up the SpdySession |
| 5892 | HttpNetworkTransaction* trans = helper.trans(); |
| 5893 | TestCompletionCallback callback; |
| 5894 | HttpRequestInfo info1 = CreateGetRequest(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5895 | int rv = trans->Start(&info1, callback.callback(), BoundNetLog()); |
| 5896 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5897 | |
| 5898 | // Run the message loop, but do not allow the write to complete. |
| 5899 | // This leaves the SpdySession with a write pending, which prevents |
| 5900 | // SpdySession from attempting subsequent writes until this write completes. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5901 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5902 | |
| 5903 | // Now, start both new transactions |
| 5904 | HttpRequestInfo info2 = CreateGetRequest(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5905 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5906 | scoped_ptr<HttpNetworkTransaction> trans2( |
| 5907 | new HttpNetworkTransaction(MEDIUM, helper.session().get())); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5908 | rv = trans2->Start(&info2, callback2.callback(), BoundNetLog()); |
| 5909 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5910 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5911 | |
| 5912 | HttpRequestInfo info3 = CreateGetRequest(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5913 | TestCompletionCallback callback3; |
| 5914 | scoped_ptr<HttpNetworkTransaction> trans3( |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5915 | new HttpNetworkTransaction(HIGHEST, helper.session().get())); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5916 | rv = trans3->Start(&info3, callback3.callback(), BoundNetLog()); |
| 5917 | EXPECT_EQ(ERR_IO_PENDING, rv); |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 5918 | base::RunLoop().RunUntilIdle(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5919 | |
| 5920 | // We now have two SYN_STREAM frames queued up which will be |
| 5921 | // dequeued only once the first write completes, which we |
| 5922 | // now allow to happen. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5923 | data.RunFor(2); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5924 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 5925 | |
| 5926 | // And now we can allow everything else to run to completion. |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 5927 | data.SetStop(10); |
| 5928 | data.Run(); |
[email protected] | e1f58efa | 2012-05-15 18:23:40 | [diff] [blame] | 5929 | EXPECT_EQ(OK, callback2.WaitForResult()); |
| 5930 | EXPECT_EQ(OK, callback3.WaitForResult()); |
| 5931 | |
| 5932 | helper.VerifyDataConsumed(); |
| 5933 | } |
| 5934 | |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 5935 | // The tests below are only for SPDY/3 and above. |
| 5936 | |
| 5937 | // Test that sent data frames and received WINDOW_UPDATE frames change |
| 5938 | // the send_window_size_ correctly. |
| 5939 | |
| 5940 | // WINDOW_UPDATE is different than most other frames in that it can arrive |
| 5941 | // while the client is still sending the request body. In order to enforce |
| 5942 | // this scenario, we feed a couple of dummy frames and give a delay of 0 to |
| 5943 | // socket data provider, so that initial read that is done as soon as the |
| 5944 | // stream is created, succeeds and schedules another read. This way reads |
| 5945 | // and writes are interleaved; after doing a full frame write, SpdyStream |
| 5946 | // will break out of DoLoop and will read and process a WINDOW_UPDATE. |
| 5947 | // Once our WINDOW_UPDATE is read, we cannot send SYN_REPLY right away |
| 5948 | // since request has not been completely written, therefore we feed |
| 5949 | // enough number of WINDOW_UPDATEs to finish the first read and cause a |
| 5950 | // write, leading to a complete write of request body; after that we send |
| 5951 | // a reply with a body, to cause a graceful shutdown. |
| 5952 | |
| 5953 | // TODO(agayev): develop a socket data provider where both, reads and |
| 5954 | // writes are ordered so that writing tests like these are easy and rewrite |
| 5955 | // all these tests using it. Right now we are working around the |
| 5956 | // limitations as described above and it's not deterministic, tests may |
| 5957 | // fail under specific circumstances. |
| 5958 | TEST_P(SpdyNetworkTransactionTest, WindowUpdateReceived) { |
| 5959 | if (GetParam().protocol < kProtoSPDY3) |
| 5960 | return; |
| 5961 | |
| 5962 | static int kFrameCount = 2; |
| 5963 | scoped_ptr<std::string> content( |
| 5964 | new std::string(kMaxSpdyFrameChunkSize, 'a')); |
| 5965 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 5966 | kRequestUrl, 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, NULL, 0)); |
| 5967 | scoped_ptr<SpdyFrame> body( |
| 5968 | spdy_util_.ConstructSpdyBodyFrame( |
| 5969 | 1, content->c_str(), content->size(), false)); |
| 5970 | scoped_ptr<SpdyFrame> body_end( |
| 5971 | spdy_util_.ConstructSpdyBodyFrame( |
| 5972 | 1, content->c_str(), content->size(), true)); |
| 5973 | |
| 5974 | MockWrite writes[] = { |
| 5975 | CreateMockWrite(*req, 0), |
| 5976 | CreateMockWrite(*body, 1), |
| 5977 | CreateMockWrite(*body_end, 2), |
| 5978 | }; |
| 5979 | |
| 5980 | static const int32 kDeltaWindowSize = 0xff; |
| 5981 | static const int kDeltaCount = 4; |
| 5982 | scoped_ptr<SpdyFrame> window_update( |
| 5983 | spdy_util_.ConstructSpdyWindowUpdate(1, kDeltaWindowSize)); |
| 5984 | scoped_ptr<SpdyFrame> window_update_dummy( |
| 5985 | spdy_util_.ConstructSpdyWindowUpdate(2, kDeltaWindowSize)); |
| 5986 | scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 5987 | MockRead reads[] = { |
| 5988 | CreateMockRead(*window_update_dummy, 3), |
| 5989 | CreateMockRead(*window_update_dummy, 4), |
| 5990 | CreateMockRead(*window_update_dummy, 5), |
| 5991 | CreateMockRead(*window_update, 6), // Four updates, therefore window |
| 5992 | CreateMockRead(*window_update, 7), // size should increase by |
| 5993 | CreateMockRead(*window_update, 8), // kDeltaWindowSize * 4 |
| 5994 | CreateMockRead(*window_update, 9), |
| 5995 | CreateMockRead(*resp, 10), |
| 5996 | CreateMockRead(*body_end, 11), |
| 5997 | MockRead(ASYNC, 0, 0, 12) // EOF |
| 5998 | }; |
| 5999 | |
| 6000 | DeterministicSocketData data(reads, arraysize(reads), |
| 6001 | writes, arraysize(writes)); |
| 6002 | |
| 6003 | ScopedVector<UploadElementReader> element_readers; |
| 6004 | for (int i = 0; i < kFrameCount; ++i) { |
| 6005 | element_readers.push_back( |
| 6006 | new UploadBytesElementReader(content->c_str(), content->size())); |
| 6007 | } |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 6008 | UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6009 | |
| 6010 | // Setup the request |
| 6011 | HttpRequestInfo request; |
| 6012 | request.method = "POST"; |
| 6013 | request.url = GURL(kDefaultURL); |
| 6014 | request.upload_data_stream = &upload_data_stream; |
| 6015 | |
| 6016 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 6017 | BoundNetLog(), GetParam(), NULL); |
| 6018 | helper.SetDeterministic(); |
| 6019 | helper.AddDeterministicData(&data); |
| 6020 | helper.RunPreTestSetup(); |
| 6021 | |
| 6022 | HttpNetworkTransaction* trans = helper.trans(); |
| 6023 | |
| 6024 | TestCompletionCallback callback; |
| 6025 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6026 | |
| 6027 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6028 | |
| 6029 | data.RunFor(11); |
| 6030 | |
| 6031 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6032 | ASSERT_TRUE(stream != NULL); |
| 6033 | ASSERT_TRUE(stream->stream() != NULL); |
| 6034 | EXPECT_EQ(static_cast<int>(kSpdyStreamInitialWindowSize) + |
| 6035 | kDeltaWindowSize * kDeltaCount - |
| 6036 | kMaxSpdyFrameChunkSize * kFrameCount, |
| 6037 | stream->stream()->send_window_size()); |
| 6038 | |
| 6039 | data.RunFor(1); |
| 6040 | |
| 6041 | rv = callback.WaitForResult(); |
| 6042 | EXPECT_EQ(OK, rv); |
| 6043 | |
| 6044 | helper.VerifyDataConsumed(); |
| 6045 | } |
| 6046 | |
| 6047 | // Test that received data frames and sent WINDOW_UPDATE frames change |
| 6048 | // the recv_window_size_ correctly. |
| 6049 | TEST_P(SpdyNetworkTransactionTest, WindowUpdateSent) { |
| 6050 | if (GetParam().protocol < kProtoSPDY3) |
| 6051 | return; |
| 6052 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 6053 | // Amount of body required to trigger a sent window update. |
| 6054 | const size_t kTargetSize = kSpdyStreamInitialWindowSize / 2 + 1; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6055 | |
| 6056 | scoped_ptr<SpdyFrame> req( |
| 6057 | spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 6058 | scoped_ptr<SpdyFrame> session_window_update( |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 6059 | spdy_util_.ConstructSpdyWindowUpdate(0, kTargetSize)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6060 | scoped_ptr<SpdyFrame> window_update( |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 6061 | spdy_util_.ConstructSpdyWindowUpdate(1, kTargetSize)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6062 | |
| 6063 | std::vector<MockWrite> writes; |
| 6064 | writes.push_back(CreateMockWrite(*req)); |
| 6065 | if (GetParam().protocol >= kProtoSPDY31) |
| 6066 | writes.push_back(CreateMockWrite(*session_window_update)); |
| 6067 | writes.push_back(CreateMockWrite(*window_update)); |
| 6068 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 6069 | std::vector<MockRead> reads; |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6070 | scoped_ptr<SpdyFrame> resp( |
| 6071 | spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 6072 | reads.push_back(CreateMockRead(*resp)); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6073 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 6074 | ScopedVector<SpdyFrame> body_frames; |
| 6075 | const std::string body_data(4096, 'x'); |
| 6076 | for (size_t remaining = kTargetSize; remaining != 0;) { |
| 6077 | size_t frame_size = std::min(remaining, body_data.size()); |
| 6078 | body_frames.push_back(spdy_util_.ConstructSpdyBodyFrame( |
| 6079 | 1, body_data.data(), frame_size, false)); |
| 6080 | reads.push_back(CreateMockRead(*body_frames.back())); |
| 6081 | remaining -= frame_size; |
| 6082 | } |
| 6083 | reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 0)); // Yield. |
| 6084 | |
| 6085 | DelayedSocketData data(1, vector_as_array(&reads), reads.size(), |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6086 | vector_as_array(&writes), writes.size()); |
| 6087 | |
| 6088 | NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 6089 | BoundNetLog(), GetParam(), NULL); |
| 6090 | helper.AddData(&data); |
| 6091 | helper.RunPreTestSetup(); |
| 6092 | HttpNetworkTransaction* trans = helper.trans(); |
| 6093 | |
| 6094 | TestCompletionCallback callback; |
| 6095 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6096 | |
| 6097 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6098 | rv = callback.WaitForResult(); |
| 6099 | EXPECT_EQ(OK, rv); |
| 6100 | |
| 6101 | SpdyHttpStream* stream = |
| 6102 | static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6103 | ASSERT_TRUE(stream != NULL); |
| 6104 | ASSERT_TRUE(stream->stream() != NULL); |
| 6105 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 6106 | // All data has been read, but not consumed. The window reflects this. |
| 6107 | EXPECT_EQ(static_cast<int>(kSpdyStreamInitialWindowSize - kTargetSize), |
| 6108 | stream->stream()->recv_window_size()); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6109 | |
| 6110 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6111 | ASSERT_TRUE(response != NULL); |
| 6112 | ASSERT_TRUE(response->headers.get() != NULL); |
| 6113 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6114 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 6115 | |
| 6116 | // Issue a read which will cause a WINDOW_UPDATE to be sent and window |
| 6117 | // size increased to default. |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 6118 | scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kTargetSize)); |
| 6119 | EXPECT_EQ(static_cast<int>(kTargetSize), |
| 6120 | trans->Read(buf.get(), kTargetSize, CompletionCallback())); |
| 6121 | EXPECT_EQ(static_cast<int>(kSpdyStreamInitialWindowSize), |
| 6122 | stream->stream()->recv_window_size()); |
| 6123 | EXPECT_THAT(base::StringPiece(buf->data(), kTargetSize), Each(Eq('x'))); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6124 | |
[email protected] | 251029e | 2014-03-19 06:04:40 | [diff] [blame] | 6125 | // Allow scheduled WINDOW_UPDATE frames to write. |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 6126 | base::RunLoop().RunUntilIdle(); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6127 | helper.VerifyDataConsumed(); |
| 6128 | } |
| 6129 | |
| 6130 | // Test that WINDOW_UPDATE frame causing overflow is handled correctly. |
| 6131 | TEST_P(SpdyNetworkTransactionTest, WindowUpdateOverflow) { |
| 6132 | if (GetParam().protocol < kProtoSPDY3) |
| 6133 | return; |
| 6134 | |
| 6135 | // Number of full frames we hope to write (but will not, used to |
| 6136 | // set content-length header correctly) |
| 6137 | static int kFrameCount = 3; |
| 6138 | |
| 6139 | scoped_ptr<std::string> content( |
| 6140 | new std::string(kMaxSpdyFrameChunkSize, 'a')); |
| 6141 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 6142 | kRequestUrl, 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, NULL, 0)); |
| 6143 | scoped_ptr<SpdyFrame> body( |
| 6144 | spdy_util_.ConstructSpdyBodyFrame( |
| 6145 | 1, content->c_str(), content->size(), false)); |
| 6146 | scoped_ptr<SpdyFrame> rst( |
| 6147 | spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_FLOW_CONTROL_ERROR)); |
| 6148 | |
| 6149 | // We're not going to write a data frame with FIN, we'll receive a bad |
| 6150 | // WINDOW_UPDATE while sending a request and will send a RST_STREAM frame. |
| 6151 | MockWrite writes[] = { |
| 6152 | CreateMockWrite(*req, 0), |
| 6153 | CreateMockWrite(*body, 2), |
| 6154 | CreateMockWrite(*rst, 3), |
| 6155 | }; |
| 6156 | |
| 6157 | static const int32 kDeltaWindowSize = 0x7fffffff; // cause an overflow |
| 6158 | scoped_ptr<SpdyFrame> window_update( |
| 6159 | spdy_util_.ConstructSpdyWindowUpdate(1, kDeltaWindowSize)); |
| 6160 | MockRead reads[] = { |
| 6161 | CreateMockRead(*window_update, 1), |
| 6162 | MockRead(ASYNC, 0, 4) // EOF |
| 6163 | }; |
| 6164 | |
| 6165 | DeterministicSocketData data(reads, arraysize(reads), |
| 6166 | writes, arraysize(writes)); |
| 6167 | |
| 6168 | ScopedVector<UploadElementReader> element_readers; |
| 6169 | for (int i = 0; i < kFrameCount; ++i) { |
| 6170 | element_readers.push_back( |
| 6171 | new UploadBytesElementReader(content->c_str(), content->size())); |
| 6172 | } |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 6173 | UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6174 | |
| 6175 | // Setup the request |
| 6176 | HttpRequestInfo request; |
| 6177 | request.method = "POST"; |
| 6178 | request.url = GURL("http://www.google.com/"); |
| 6179 | request.upload_data_stream = &upload_data_stream; |
| 6180 | |
| 6181 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 6182 | BoundNetLog(), GetParam(), NULL); |
| 6183 | helper.SetDeterministic(); |
| 6184 | helper.RunPreTestSetup(); |
| 6185 | helper.AddDeterministicData(&data); |
| 6186 | HttpNetworkTransaction* trans = helper.trans(); |
| 6187 | |
| 6188 | TestCompletionCallback callback; |
| 6189 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6190 | ASSERT_EQ(ERR_IO_PENDING, rv); |
| 6191 | |
| 6192 | data.RunFor(5); |
| 6193 | ASSERT_TRUE(callback.have_result()); |
| 6194 | EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, callback.WaitForResult()); |
| 6195 | helper.VerifyDataConsumed(); |
| 6196 | } |
| 6197 | |
| 6198 | // Test that after hitting a send window size of 0, the write process |
| 6199 | // stalls and upon receiving WINDOW_UPDATE frame write resumes. |
| 6200 | |
| 6201 | // This test constructs a POST request followed by enough data frames |
| 6202 | // containing 'a' that would make the window size 0, followed by another |
| 6203 | // data frame containing default content (which is "hello!") and this frame |
| 6204 | // also contains a FIN flag. DelayedSocketData is used to enforce all |
| 6205 | // writes go through before a read could happen. However, the last frame |
| 6206 | // ("hello!") is not supposed to go through since by the time its turn |
| 6207 | // arrives, window size is 0. At this point MessageLoop::Run() called via |
| 6208 | // callback would block. Therefore we call MessageLoop::RunUntilIdle() |
| 6209 | // which returns after performing all possible writes. We use DCHECKS to |
| 6210 | // ensure that last data frame is still there and stream has stalled. |
| 6211 | // After that, next read is artifically enforced, which causes a |
| 6212 | // WINDOW_UPDATE to be read and I/O process resumes. |
| 6213 | TEST_P(SpdyNetworkTransactionTest, FlowControlStallResume) { |
| 6214 | if (GetParam().protocol < kProtoSPDY3) |
| 6215 | return; |
| 6216 | |
| 6217 | // Number of frames we need to send to zero out the window size: data |
| 6218 | // frames plus SYN_STREAM plus the last data frame; also we need another |
| 6219 | // data frame that we will send once the WINDOW_UPDATE is received, |
| 6220 | // therefore +3. |
| 6221 | size_t num_writes = kSpdyStreamInitialWindowSize / kMaxSpdyFrameChunkSize + 3; |
| 6222 | |
| 6223 | // Calculate last frame's size; 0 size data frame is legal. |
| 6224 | size_t last_frame_size = |
| 6225 | kSpdyStreamInitialWindowSize % kMaxSpdyFrameChunkSize; |
| 6226 | |
| 6227 | // Construct content for a data frame of maximum size. |
| 6228 | std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 6229 | |
| 6230 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 6231 | kRequestUrl, 1, kSpdyStreamInitialWindowSize + kUploadDataSize, |
| 6232 | LOWEST, NULL, 0)); |
| 6233 | |
| 6234 | // Full frames. |
| 6235 | scoped_ptr<SpdyFrame> body1( |
| 6236 | spdy_util_.ConstructSpdyBodyFrame( |
| 6237 | 1, content.c_str(), content.size(), false)); |
| 6238 | |
| 6239 | // Last frame to zero out the window size. |
| 6240 | scoped_ptr<SpdyFrame> body2( |
| 6241 | spdy_util_.ConstructSpdyBodyFrame( |
| 6242 | 1, content.c_str(), last_frame_size, false)); |
| 6243 | |
| 6244 | // Data frame to be sent once WINDOW_UPDATE frame is received. |
| 6245 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6246 | |
| 6247 | // Fill in mock writes. |
| 6248 | scoped_ptr<MockWrite[]> writes(new MockWrite[num_writes]); |
| 6249 | size_t i = 0; |
| 6250 | writes[i] = CreateMockWrite(*req); |
| 6251 | for (i = 1; i < num_writes - 2; i++) |
| 6252 | writes[i] = CreateMockWrite(*body1); |
| 6253 | writes[i++] = CreateMockWrite(*body2); |
| 6254 | writes[i] = CreateMockWrite(*body3); |
| 6255 | |
| 6256 | // Construct read frame, give enough space to upload the rest of the |
| 6257 | // data. |
| 6258 | scoped_ptr<SpdyFrame> session_window_update( |
| 6259 | spdy_util_.ConstructSpdyWindowUpdate(0, kUploadDataSize)); |
| 6260 | scoped_ptr<SpdyFrame> window_update( |
| 6261 | spdy_util_.ConstructSpdyWindowUpdate(1, kUploadDataSize)); |
| 6262 | scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 6263 | MockRead reads[] = { |
| 6264 | CreateMockRead(*session_window_update), |
| 6265 | CreateMockRead(*session_window_update), |
| 6266 | CreateMockRead(*window_update), |
| 6267 | CreateMockRead(*window_update), |
| 6268 | CreateMockRead(*reply), |
| 6269 | CreateMockRead(*body2), |
| 6270 | CreateMockRead(*body3), |
| 6271 | MockRead(ASYNC, 0, 0) // EOF |
| 6272 | }; |
| 6273 | |
| 6274 | // Skip the session window updates unless we're using SPDY/3.1 and |
| 6275 | // above. |
| 6276 | size_t read_offset = (GetParam().protocol >= kProtoSPDY31) ? 0 : 2; |
| 6277 | size_t num_reads = arraysize(reads) - read_offset; |
| 6278 | |
| 6279 | // Force all writes to happen before any read, last write will not |
| 6280 | // actually queue a frame, due to window size being 0. |
| 6281 | DelayedSocketData data(num_writes, reads + read_offset, num_reads, |
| 6282 | writes.get(), num_writes); |
| 6283 | |
| 6284 | ScopedVector<UploadElementReader> element_readers; |
| 6285 | std::string upload_data_string(kSpdyStreamInitialWindowSize, 'a'); |
| 6286 | upload_data_string.append(kUploadData, kUploadDataSize); |
| 6287 | element_readers.push_back(new UploadBytesElementReader( |
| 6288 | upload_data_string.c_str(), upload_data_string.size())); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 6289 | UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6290 | |
| 6291 | HttpRequestInfo request; |
| 6292 | request.method = "POST"; |
| 6293 | request.url = GURL("http://www.google.com/"); |
| 6294 | request.upload_data_stream = &upload_data_stream; |
| 6295 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 6296 | BoundNetLog(), GetParam(), NULL); |
| 6297 | helper.AddData(&data); |
| 6298 | helper.RunPreTestSetup(); |
| 6299 | |
| 6300 | HttpNetworkTransaction* trans = helper.trans(); |
| 6301 | |
| 6302 | TestCompletionCallback callback; |
| 6303 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6304 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6305 | |
[email protected] | fc9d8847 | 2013-08-14 02:31:17 | [diff] [blame] | 6306 | base::RunLoop().RunUntilIdle(); // Write as much as we can. |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6307 | |
| 6308 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6309 | ASSERT_TRUE(stream != NULL); |
| 6310 | ASSERT_TRUE(stream->stream() != NULL); |
| 6311 | EXPECT_EQ(0, stream->stream()->send_window_size()); |
| 6312 | // All the body data should have been read. |
| 6313 | // TODO(satorux): This is because of the weirdness in reading the request |
| 6314 | // body in OnSendBodyComplete(). See crbug.com/113107. |
| 6315 | EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 6316 | // But the body is not yet fully sent (kUploadData is not yet sent) |
| 6317 | // since we're send-stalled. |
| 6318 | EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 6319 | |
| 6320 | data.ForceNextRead(); // Read in WINDOW_UPDATE frame. |
| 6321 | rv = callback.WaitForResult(); |
| 6322 | helper.VerifyDataConsumed(); |
| 6323 | } |
| 6324 | |
| 6325 | // Test we correctly handle the case where the SETTINGS frame results in |
| 6326 | // unstalling the send window. |
| 6327 | TEST_P(SpdyNetworkTransactionTest, FlowControlStallResumeAfterSettings) { |
| 6328 | if (GetParam().protocol < kProtoSPDY3) |
| 6329 | return; |
| 6330 | |
| 6331 | // Number of frames we need to send to zero out the window size: data |
| 6332 | // frames plus SYN_STREAM plus the last data frame; also we need another |
| 6333 | // data frame that we will send once the SETTING is received, therefore +3. |
| 6334 | size_t num_writes = kSpdyStreamInitialWindowSize / kMaxSpdyFrameChunkSize + 3; |
| 6335 | |
| 6336 | // Calculate last frame's size; 0 size data frame is legal. |
| 6337 | size_t last_frame_size = |
| 6338 | kSpdyStreamInitialWindowSize % kMaxSpdyFrameChunkSize; |
| 6339 | |
| 6340 | // Construct content for a data frame of maximum size. |
| 6341 | std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 6342 | |
| 6343 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 6344 | kRequestUrl, 1, kSpdyStreamInitialWindowSize + kUploadDataSize, |
| 6345 | LOWEST, NULL, 0)); |
| 6346 | |
| 6347 | // Full frames. |
| 6348 | scoped_ptr<SpdyFrame> body1( |
| 6349 | spdy_util_.ConstructSpdyBodyFrame( |
| 6350 | 1, content.c_str(), content.size(), false)); |
| 6351 | |
| 6352 | // Last frame to zero out the window size. |
| 6353 | scoped_ptr<SpdyFrame> body2( |
| 6354 | spdy_util_.ConstructSpdyBodyFrame( |
| 6355 | 1, content.c_str(), last_frame_size, false)); |
| 6356 | |
| 6357 | // Data frame to be sent once SETTINGS frame is received. |
| 6358 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6359 | |
| 6360 | // Fill in mock reads/writes. |
| 6361 | std::vector<MockRead> reads; |
| 6362 | std::vector<MockWrite> writes; |
| 6363 | size_t i = 0; |
| 6364 | writes.push_back(CreateMockWrite(*req, i++)); |
| 6365 | while (i < num_writes - 2) |
| 6366 | writes.push_back(CreateMockWrite(*body1, i++)); |
| 6367 | writes.push_back(CreateMockWrite(*body2, i++)); |
| 6368 | |
| 6369 | // Construct read frame for SETTINGS that gives enough space to upload the |
| 6370 | // rest of the data. |
| 6371 | SettingsMap settings; |
| 6372 | settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
| 6373 | SettingsFlagsAndValue( |
| 6374 | SETTINGS_FLAG_NONE, kSpdyStreamInitialWindowSize * 2); |
| 6375 | scoped_ptr<SpdyFrame> settings_frame_large( |
| 6376 | spdy_util_.ConstructSpdySettings(settings)); |
| 6377 | |
| 6378 | reads.push_back(CreateMockRead(*settings_frame_large, i++)); |
| 6379 | |
| 6380 | scoped_ptr<SpdyFrame> session_window_update( |
| 6381 | spdy_util_.ConstructSpdyWindowUpdate(0, kUploadDataSize)); |
| 6382 | if (GetParam().protocol >= kProtoSPDY31) |
| 6383 | reads.push_back(CreateMockRead(*session_window_update, i++)); |
| 6384 | |
| 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; |
| 6399 | std::string upload_data_string(kSpdyStreamInitialWindowSize, 'a'); |
| 6400 | upload_data_string.append(kUploadData, kUploadDataSize); |
| 6401 | element_readers.push_back(new UploadBytesElementReader( |
| 6402 | upload_data_string.c_str(), upload_data_string.size())); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 6403 | UploadDataStream 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"; |
| 6407 | request.url = GURL("http://www.google.com/"); |
| 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 | data.RunFor(6); // Read in SETTINGS frame to unstall. |
| 6437 | rv = callback.WaitForResult(); |
| 6438 | helper.VerifyDataConsumed(); |
| 6439 | // If stream is NULL, that means it was unstalled and closed. |
| 6440 | EXPECT_TRUE(stream->stream() == NULL); |
| 6441 | } |
| 6442 | |
| 6443 | // Test we correctly handle the case where the SETTINGS frame results in a |
| 6444 | // negative send window size. |
| 6445 | TEST_P(SpdyNetworkTransactionTest, FlowControlNegativeSendWindowSize) { |
| 6446 | if (GetParam().protocol < kProtoSPDY3) |
| 6447 | return; |
| 6448 | |
| 6449 | // Number of frames we need to send to zero out the window size: data |
| 6450 | // frames plus SYN_STREAM plus the last data frame; also we need another |
| 6451 | // data frame that we will send once the SETTING is received, therefore +3. |
| 6452 | size_t num_writes = kSpdyStreamInitialWindowSize / kMaxSpdyFrameChunkSize + 3; |
| 6453 | |
| 6454 | // Calculate last frame's size; 0 size data frame is legal. |
| 6455 | size_t last_frame_size = |
| 6456 | kSpdyStreamInitialWindowSize % kMaxSpdyFrameChunkSize; |
| 6457 | |
| 6458 | // Construct content for a data frame of maximum size. |
| 6459 | std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 6460 | |
| 6461 | scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 6462 | kRequestUrl, 1, kSpdyStreamInitialWindowSize + kUploadDataSize, |
| 6463 | LOWEST, NULL, 0)); |
| 6464 | |
| 6465 | // Full frames. |
| 6466 | scoped_ptr<SpdyFrame> body1( |
| 6467 | spdy_util_.ConstructSpdyBodyFrame( |
| 6468 | 1, content.c_str(), content.size(), false)); |
| 6469 | |
| 6470 | // Last frame to zero out the window size. |
| 6471 | scoped_ptr<SpdyFrame> body2( |
| 6472 | spdy_util_.ConstructSpdyBodyFrame( |
| 6473 | 1, content.c_str(), last_frame_size, false)); |
| 6474 | |
| 6475 | // Data frame to be sent once SETTINGS frame is received. |
| 6476 | scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6477 | |
| 6478 | // Fill in mock reads/writes. |
| 6479 | std::vector<MockRead> reads; |
| 6480 | std::vector<MockWrite> writes; |
| 6481 | size_t i = 0; |
| 6482 | writes.push_back(CreateMockWrite(*req, i++)); |
| 6483 | while (i < num_writes - 2) |
| 6484 | writes.push_back(CreateMockWrite(*body1, i++)); |
| 6485 | writes.push_back(CreateMockWrite(*body2, i++)); |
| 6486 | |
| 6487 | // Construct read frame for SETTINGS that makes the send_window_size |
| 6488 | // negative. |
| 6489 | SettingsMap new_settings; |
| 6490 | new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
| 6491 | SettingsFlagsAndValue( |
| 6492 | SETTINGS_FLAG_NONE, kSpdyStreamInitialWindowSize / 2); |
| 6493 | scoped_ptr<SpdyFrame> settings_frame_small( |
| 6494 | spdy_util_.ConstructSpdySettings(new_settings)); |
| 6495 | // Construct read frames for WINDOW_UPDATE that makes the send_window_size |
| 6496 | // positive. |
| 6497 | scoped_ptr<SpdyFrame> session_window_update_init_size( |
| 6498 | spdy_util_.ConstructSpdyWindowUpdate(0, kSpdyStreamInitialWindowSize)); |
| 6499 | scoped_ptr<SpdyFrame> window_update_init_size( |
| 6500 | spdy_util_.ConstructSpdyWindowUpdate(1, kSpdyStreamInitialWindowSize)); |
| 6501 | |
| 6502 | reads.push_back(CreateMockRead(*settings_frame_small, i++)); |
| 6503 | |
| 6504 | if (GetParam().protocol >= kProtoSPDY3) |
| 6505 | reads.push_back(CreateMockRead(*session_window_update_init_size, i++)); |
| 6506 | |
| 6507 | reads.push_back(CreateMockRead(*window_update_init_size, i++)); |
| 6508 | |
| 6509 | writes.push_back(CreateMockWrite(*body3, i++)); |
| 6510 | |
| 6511 | scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 6512 | reads.push_back(CreateMockRead(*reply, i++)); |
| 6513 | reads.push_back(CreateMockRead(*body2, i++)); |
| 6514 | reads.push_back(CreateMockRead(*body3, i++)); |
| 6515 | reads.push_back(MockRead(ASYNC, 0, i++)); // EOF |
| 6516 | |
| 6517 | // Force all writes to happen before any read, last write will not |
| 6518 | // actually queue a frame, due to window size being 0. |
| 6519 | DeterministicSocketData data(vector_as_array(&reads), reads.size(), |
| 6520 | vector_as_array(&writes), writes.size()); |
| 6521 | |
| 6522 | ScopedVector<UploadElementReader> element_readers; |
| 6523 | std::string upload_data_string(kSpdyStreamInitialWindowSize, 'a'); |
| 6524 | upload_data_string.append(kUploadData, kUploadDataSize); |
| 6525 | element_readers.push_back(new UploadBytesElementReader( |
| 6526 | upload_data_string.c_str(), upload_data_string.size())); |
[email protected] | 96c77a7 | 2013-09-24 09:49:20 | [diff] [blame] | 6527 | UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
[email protected] | d11b691 | 2013-06-27 23:07:32 | [diff] [blame] | 6528 | |
| 6529 | HttpRequestInfo request; |
| 6530 | request.method = "POST"; |
| 6531 | request.url = GURL("http://www.google.com/"); |
| 6532 | request.upload_data_stream = &upload_data_stream; |
| 6533 | NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, |
| 6534 | BoundNetLog(), GetParam(), NULL); |
| 6535 | helper.SetDeterministic(); |
| 6536 | helper.RunPreTestSetup(); |
| 6537 | helper.AddDeterministicData(&data); |
| 6538 | |
| 6539 | HttpNetworkTransaction* trans = helper.trans(); |
| 6540 | |
| 6541 | TestCompletionCallback callback; |
| 6542 | int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6543 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6544 | |
| 6545 | data.RunFor(num_writes - 1); // Write as much as we can. |
| 6546 | |
| 6547 | SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6548 | ASSERT_TRUE(stream != NULL); |
| 6549 | ASSERT_TRUE(stream->stream() != NULL); |
| 6550 | EXPECT_EQ(0, stream->stream()->send_window_size()); |
| 6551 | |
| 6552 | // All the body data should have been read. |
| 6553 | // TODO(satorux): This is because of the weirdness in reading the request |
| 6554 | // body in OnSendBodyComplete(). See crbug.com/113107. |
| 6555 | EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 6556 | // But the body is not yet fully sent (kUploadData is not yet sent) |
| 6557 | // since we're send-stalled. |
| 6558 | EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 6559 | |
| 6560 | // Read in WINDOW_UPDATE or SETTINGS frame. |
| 6561 | data.RunFor((GetParam().protocol >= kProtoSPDY31) ? 8 : 7); |
| 6562 | rv = callback.WaitForResult(); |
| 6563 | helper.VerifyDataConsumed(); |
| 6564 | } |
| 6565 | |
[email protected] | aea8060 | 2009-09-18 00:55:08 | [diff] [blame] | 6566 | } // namespace net |