| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <cmath> | 5 #include <cmath> |
| 6 #include <memory> | 6 #include <memory> |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 | 58 |
| 59 namespace net { | 59 namespace net { |
| 60 | 60 |
| 61 namespace { | 61 namespace { |
| 62 | 62 |
| 63 using testing::Each; | 63 using testing::Each; |
| 64 using testing::Eq; | 64 using testing::Eq; |
| 65 | 65 |
| 66 const int32_t kBufferSize = SpdyHttpStream::kRequestBodyBufferSize; | 66 const int32_t kBufferSize = SpdyHttpStream::kRequestBodyBufferSize; |
| 67 | 67 |
| 68 struct SpdyNetworkTransactionTestParams { | |
| 69 SpdyNetworkTransactionTestParams() | |
| 70 : protocol(kProtoSPDY31), | |
| 71 priority_to_dependency(false) {} | |
| 72 | |
| 73 SpdyNetworkTransactionTestParams(NextProto protocol, | |
| 74 bool priority_to_dependency) | |
| 75 : protocol(protocol), | |
| 76 priority_to_dependency(priority_to_dependency) {} | |
| 77 | |
| 78 friend std::ostream& operator<<(std::ostream& os, | |
| 79 const SpdyNetworkTransactionTestParams& p) { | |
| 80 os << "{ protocol: " << SSLClientSocket::NextProtoToString(p.protocol) | |
| 81 << ", priority_to_dependency: " << p.priority_to_dependency << " }"; | |
| 82 return os; | |
| 83 } | |
| 84 | |
| 85 NextProto protocol; | |
| 86 bool priority_to_dependency; | |
| 87 }; | |
| 88 | |
| 89 void UpdateSpdySessionDependencies(SpdyNetworkTransactionTestParams test_params, | |
| 90 SpdySessionDependencies* session_deps) { | |
| 91 session_deps->enable_priority_dependencies = | |
| 92 test_params.priority_to_dependency; | |
| 93 } | |
| 94 | |
| 95 std::unique_ptr<SpdySessionDependencies> CreateSpdySessionDependencies( | 68 std::unique_ptr<SpdySessionDependencies> CreateSpdySessionDependencies( |
| 96 SpdyNetworkTransactionTestParams test_params) { | 69 bool priority_to_dependency) { |
| 97 std::unique_ptr<SpdySessionDependencies> session_deps( | 70 std::unique_ptr<SpdySessionDependencies> session_deps( |
| 98 new SpdySessionDependencies(test_params.protocol)); | 71 new SpdySessionDependencies()); |
| 99 UpdateSpdySessionDependencies(test_params, session_deps.get()); | 72 session_deps->enable_priority_dependencies = priority_to_dependency; |
| 100 return session_deps; | 73 return session_deps; |
| 101 } | 74 } |
| 102 | 75 |
| 103 std::unique_ptr<SpdySessionDependencies> CreateSpdySessionDependencies( | 76 std::unique_ptr<SpdySessionDependencies> CreateSpdySessionDependencies( |
| 104 SpdyNetworkTransactionTestParams test_params, | 77 bool priority_to_dependency, |
| 105 std::unique_ptr<ProxyService> proxy_service) { | 78 std::unique_ptr<ProxyService> proxy_service) { |
| 106 std::unique_ptr<SpdySessionDependencies> session_deps( | 79 std::unique_ptr<SpdySessionDependencies> session_deps( |
| 107 new SpdySessionDependencies(test_params.protocol, | 80 new SpdySessionDependencies(std::move(proxy_service))); |
| 108 std::move(proxy_service))); | 81 session_deps->enable_priority_dependencies = priority_to_dependency; |
| 109 UpdateSpdySessionDependencies(test_params, session_deps.get()); | |
| 110 return session_deps; | 82 return session_deps; |
| 111 } | 83 } |
| 112 | 84 |
| 113 } // namespace | 85 } // namespace |
| 114 | 86 |
| 115 class SpdyNetworkTransactionTest | 87 class SpdyNetworkTransactionTest : public ::testing::TestWithParam<bool> { |
| 116 : public ::testing::TestWithParam<SpdyNetworkTransactionTestParams> { | |
| 117 protected: | 88 protected: |
| 118 SpdyNetworkTransactionTest() | 89 SpdyNetworkTransactionTest() |
| 119 : default_url_(kDefaultUrl), | 90 : default_url_(kDefaultUrl), |
| 120 host_port_pair_(HostPortPair::FromURL(default_url_)), | 91 host_port_pair_(HostPortPair::FromURL(default_url_)), |
| 121 spdy_util_(GetParam().protocol, GetParam().priority_to_dependency) {} | 92 spdy_util_(GetParam()) {} |
| 122 | 93 |
| 123 virtual ~SpdyNetworkTransactionTest() { | 94 virtual ~SpdyNetworkTransactionTest() { |
| 124 // UploadDataStream may post a deletion tasks back to the message loop on | 95 // UploadDataStream may post a deletion tasks back to the message loop on |
| 125 // destruction. | 96 // destruction. |
| 126 upload_data_stream_.reset(); | 97 upload_data_stream_.reset(); |
| 127 base::RunLoop().RunUntilIdle(); | 98 base::RunLoop().RunUntilIdle(); |
| 128 } | 99 } |
| 129 | 100 |
| 130 void SetUp() override { | 101 void SetUp() override { |
| 131 get_request_initialized_ = false; | 102 get_request_initialized_ = false; |
| 132 post_request_initialized_ = false; | 103 post_request_initialized_ = false; |
| 133 chunked_post_request_initialized_ = false; | 104 chunked_post_request_initialized_ = false; |
| 134 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 105 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 135 } | 106 } |
| 136 | 107 |
| 137 struct TransactionHelperResult { | 108 struct TransactionHelperResult { |
| 138 int rv; | 109 int rv; |
| 139 std::string status_line; | 110 std::string status_line; |
| 140 std::string response_data; | 111 std::string response_data; |
| 141 HttpResponseInfo response_info; | 112 HttpResponseInfo response_info; |
| 142 }; | 113 }; |
| 143 | 114 |
| 144 // A helper class that handles all the initial npn/ssl setup. | 115 // A helper class that handles all the initial npn/ssl setup. |
| 145 class NormalSpdyTransactionHelper { | 116 class NormalSpdyTransactionHelper { |
| 146 public: | 117 public: |
| 147 NormalSpdyTransactionHelper( | 118 NormalSpdyTransactionHelper( |
| 148 const HttpRequestInfo& request, | 119 const HttpRequestInfo& request, |
| 149 RequestPriority priority, | 120 RequestPriority priority, |
| 150 const BoundNetLog& log, | 121 const BoundNetLog& log, |
| 151 SpdyNetworkTransactionTestParams test_params, | 122 bool priority_to_dependency, |
| 152 std::unique_ptr<SpdySessionDependencies> session_deps) | 123 std::unique_ptr<SpdySessionDependencies> session_deps) |
| 153 : request_(request), | 124 : request_(request), |
| 154 priority_(priority), | 125 priority_(priority), |
| 155 session_deps_(session_deps.get() == NULL | 126 session_deps_( |
| 156 ? CreateSpdySessionDependencies(test_params) | 127 session_deps.get() == NULL |
| 157 : std::move(session_deps)), | 128 ? CreateSpdySessionDependencies(priority_to_dependency) |
| 129 : std::move(session_deps)), |
| 158 session_( | 130 session_( |
| 159 SpdySessionDependencies::SpdyCreateSession(session_deps_.get())), | 131 SpdySessionDependencies::SpdyCreateSession(session_deps_.get())), |
| 160 log_(log), | 132 log_(log), |
| 161 test_params_(test_params), | 133 priority_to_dependency_(priority_to_dependency), |
| 162 spdy_enabled_(true) {} | 134 spdy_enabled_(true) {} |
| 163 | 135 |
| 164 ~NormalSpdyTransactionHelper() { | 136 ~NormalSpdyTransactionHelper() { |
| 165 // Any test which doesn't close the socket by sending it an EOF will | 137 // Any test which doesn't close the socket by sending it an EOF will |
| 166 // have a valid session left open, which leaks the entire session pool. | 138 // have a valid session left open, which leaks the entire session pool. |
| 167 // This is just fine - in fact, some of our tests intentionally do this | 139 // This is just fine - in fact, some of our tests intentionally do this |
| 168 // so that we can check consistency of the SpdySessionPool as the test | 140 // so that we can check consistency of the SpdySessionPool as the test |
| 169 // finishes. If we had put an EOF on the socket, the SpdySession would | 141 // finishes. If we had put an EOF on the socket, the SpdySession would |
| 170 // have closed and we wouldn't be able to check the consistency. | 142 // have closed and we wouldn't be able to check the consistency. |
| 171 | 143 |
| 172 // Forcefully close existing sessions here. | 144 // Forcefully close existing sessions here. |
| 173 session()->spdy_session_pool()->CloseAllSessions(); | 145 session()->spdy_session_pool()->CloseAllSessions(); |
| 174 } | 146 } |
| 175 | 147 |
| 176 void SetSpdyDisabled() { | 148 void SetSpdyDisabled() { |
| 177 spdy_enabled_ = false; | 149 spdy_enabled_ = false; |
| 178 } | 150 } |
| 179 | 151 |
| 180 void RunPreTestSetup() { | 152 void RunPreTestSetup() { |
| 181 if (!session_deps_.get()) | 153 if (!session_deps_.get()) |
| 182 session_deps_ = CreateSpdySessionDependencies(test_params_); | 154 session_deps_ = CreateSpdySessionDependencies(priority_to_dependency_); |
| 183 if (!session_.get()) { | 155 if (!session_.get()) { |
| 184 session_ = SpdySessionDependencies::SpdyCreateSession( | 156 session_ = SpdySessionDependencies::SpdyCreateSession( |
| 185 session_deps_.get()); | 157 session_deps_.get()); |
| 186 } | 158 } |
| 187 | 159 |
| 188 // We're now ready to use SSL-npn SPDY. | 160 // We're now ready to use SSL-npn SPDY. |
| 189 trans_.reset(new HttpNetworkTransaction(priority_, session_.get())); | 161 trans_.reset(new HttpNetworkTransaction(priority_, session_.get())); |
| 190 } | 162 } |
| 191 | 163 |
| 192 // Start the transaction, read some data, finish. | 164 // Start the transaction, read some data, finish. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 209 if (output_.rv != OK) { | 181 if (output_.rv != OK) { |
| 210 session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); | 182 session_->spdy_session_pool()->CloseCurrentSessions(ERR_ABORTED); |
| 211 return; | 183 return; |
| 212 } | 184 } |
| 213 | 185 |
| 214 // Verify responses. | 186 // Verify responses. |
| 215 const HttpResponseInfo* response = trans_->GetResponseInfo(); | 187 const HttpResponseInfo* response = trans_->GetResponseInfo(); |
| 216 ASSERT_TRUE(response); | 188 ASSERT_TRUE(response); |
| 217 ASSERT_TRUE(response->headers); | 189 ASSERT_TRUE(response->headers); |
| 218 if (HttpStreamFactory::spdy_enabled()) { | 190 if (HttpStreamFactory::spdy_enabled()) { |
| 219 EXPECT_EQ( | 191 EXPECT_EQ(HttpResponseInfo::ConnectionInfoFromNextProto(kProtoHTTP2), |
| 220 HttpResponseInfo::ConnectionInfoFromNextProto( | 192 response->connection_info); |
| 221 test_params_.protocol), | |
| 222 response->connection_info); | |
| 223 } else { | 193 } else { |
| 224 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, | 194 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, |
| 225 response->connection_info); | 195 response->connection_info); |
| 226 } | 196 } |
| 227 if (spdy_enabled_) { | 197 if (spdy_enabled_) { |
| 228 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); | 198 EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 229 EXPECT_TRUE(response->was_fetched_via_spdy); | 199 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 230 EXPECT_TRUE(response->was_npn_negotiated); | 200 EXPECT_TRUE(response->was_npn_negotiated); |
| 231 } else { | 201 } else { |
| 232 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 202 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); | 264 ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 295 AddDataWithSSLSocketDataProvider(data, std::move(ssl_provider)); | 265 AddDataWithSSLSocketDataProvider(data, std::move(ssl_provider)); |
| 296 } | 266 } |
| 297 | 267 |
| 298 void AddDataWithSSLSocketDataProvider( | 268 void AddDataWithSSLSocketDataProvider( |
| 299 SocketDataProvider* data, | 269 SocketDataProvider* data, |
| 300 std::unique_ptr<SSLSocketDataProvider> ssl_provider) { | 270 std::unique_ptr<SSLSocketDataProvider> ssl_provider) { |
| 301 data_vector_.push_back(data); | 271 data_vector_.push_back(data); |
| 302 if (ssl_provider->next_proto_status == | 272 if (ssl_provider->next_proto_status == |
| 303 SSLClientSocket::kNextProtoUnsupported) { | 273 SSLClientSocket::kNextProtoUnsupported) { |
| 304 ssl_provider->SetNextProto(test_params_.protocol); | 274 ssl_provider->SetNextProto(kProtoHTTP2); |
| 305 } | 275 } |
| 306 | 276 |
| 307 session_deps_->socket_factory->AddSSLSocketDataProvider( | 277 session_deps_->socket_factory->AddSSLSocketDataProvider( |
| 308 ssl_provider.get()); | 278 ssl_provider.get()); |
| 309 ssl_vector_.push_back(std::move(ssl_provider)); | 279 ssl_vector_.push_back(std::move(ssl_provider)); |
| 310 | 280 |
| 311 session_deps_->socket_factory->AddSocketDataProvider(data); | 281 session_deps_->socket_factory->AddSocketDataProvider(data); |
| 312 } | 282 } |
| 313 | 283 |
| 314 void SetSession(std::unique_ptr<HttpNetworkSession> session) { | 284 void SetSession(std::unique_ptr<HttpNetworkSession> session) { |
| 315 session_ = std::move(session); | 285 session_ = std::move(session); |
| 316 } | 286 } |
| 317 HttpNetworkTransaction* trans() { return trans_.get(); } | 287 HttpNetworkTransaction* trans() { return trans_.get(); } |
| 318 void ResetTrans() { trans_.reset(); } | 288 void ResetTrans() { trans_.reset(); } |
| 319 TransactionHelperResult& output() { return output_; } | 289 TransactionHelperResult& output() { return output_; } |
| 320 const HttpRequestInfo& request() const { return request_; } | 290 const HttpRequestInfo& request() const { return request_; } |
| 321 HttpNetworkSession* session() const { return session_.get(); } | 291 HttpNetworkSession* session() const { return session_.get(); } |
| 322 std::unique_ptr<SpdySessionDependencies>& session_deps() { | 292 std::unique_ptr<SpdySessionDependencies>& session_deps() { |
| 323 return session_deps_; | 293 return session_deps_; |
| 324 } | 294 } |
| 325 SpdyNetworkTransactionTestParams test_params() const { | |
| 326 return test_params_; | |
| 327 } | |
| 328 | 295 |
| 329 private: | 296 private: |
| 330 typedef std::vector<SocketDataProvider*> DataVector; | 297 typedef std::vector<SocketDataProvider*> DataVector; |
| 331 typedef std::vector<std::unique_ptr<SSLSocketDataProvider>> SSLVector; | 298 typedef std::vector<std::unique_ptr<SSLSocketDataProvider>> SSLVector; |
| 332 typedef std::vector<std::unique_ptr<SocketDataProvider>> AlternateVector; | 299 typedef std::vector<std::unique_ptr<SocketDataProvider>> AlternateVector; |
| 333 HttpRequestInfo request_; | 300 HttpRequestInfo request_; |
| 334 RequestPriority priority_; | 301 RequestPriority priority_; |
| 335 std::unique_ptr<SpdySessionDependencies> session_deps_; | 302 std::unique_ptr<SpdySessionDependencies> session_deps_; |
| 336 std::unique_ptr<HttpNetworkSession> session_; | 303 std::unique_ptr<HttpNetworkSession> session_; |
| 337 TransactionHelperResult output_; | 304 TransactionHelperResult output_; |
| 338 std::unique_ptr<SocketDataProvider> first_transaction_; | 305 std::unique_ptr<SocketDataProvider> first_transaction_; |
| 339 SSLVector ssl_vector_; | 306 SSLVector ssl_vector_; |
| 340 TestCompletionCallback callback_; | 307 TestCompletionCallback callback_; |
| 341 std::unique_ptr<HttpNetworkTransaction> trans_; | 308 std::unique_ptr<HttpNetworkTransaction> trans_; |
| 342 std::unique_ptr<HttpNetworkTransaction> trans_http_; | 309 std::unique_ptr<HttpNetworkTransaction> trans_http_; |
| 343 DataVector data_vector_; | 310 DataVector data_vector_; |
| 344 AlternateVector alternate_vector_; | 311 AlternateVector alternate_vector_; |
| 345 const BoundNetLog log_; | 312 const BoundNetLog log_; |
| 346 SpdyNetworkTransactionTestParams test_params_; | 313 bool priority_to_dependency_; |
| 347 bool spdy_enabled_; | 314 bool spdy_enabled_; |
| 348 }; | 315 }; |
| 349 | 316 |
| 350 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, | 317 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 351 int expected_status); | 318 int expected_status); |
| 352 | 319 |
| 353 void ConnectStatusHelper(const MockRead& status); | 320 void ConnectStatusHelper(const MockRead& status); |
| 354 | 321 |
| 355 const HttpRequestInfo& CreateGetPushRequest() { | 322 const HttpRequestInfo& CreateGetPushRequest() { |
| 356 get_push_request_.method = "GET"; | 323 get_push_request_.method = "GET"; |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 bool get_request_initialized_; | 594 bool get_request_initialized_; |
| 628 bool post_request_initialized_; | 595 bool post_request_initialized_; |
| 629 bool chunked_post_request_initialized_; | 596 bool chunked_post_request_initialized_; |
| 630 HttpRequestInfo get_request_; | 597 HttpRequestInfo get_request_; |
| 631 HttpRequestInfo post_request_; | 598 HttpRequestInfo post_request_; |
| 632 HttpRequestInfo chunked_post_request_; | 599 HttpRequestInfo chunked_post_request_; |
| 633 HttpRequestInfo get_push_request_; | 600 HttpRequestInfo get_push_request_; |
| 634 base::ScopedTempDir temp_dir_; | 601 base::ScopedTempDir temp_dir_; |
| 635 }; | 602 }; |
| 636 | 603 |
| 637 //----------------------------------------------------------------------------- | 604 INSTANTIATE_TEST_CASE_P(Spdy, SpdyNetworkTransactionTest, ::testing::Bool()); |
| 638 // All tests are run with three different connection types: SPDY after NPN | |
| 639 // negotiation, SPDY without SSL, and SPDY with SSL. | |
| 640 // | |
| 641 // TODO(akalin): Use ::testing::Combine() when we are able to use | |
| 642 // <tr1/tuple>. | |
| 643 INSTANTIATE_TEST_CASE_P( | |
| 644 Spdy, | |
| 645 SpdyNetworkTransactionTest, | |
| 646 ::testing::Values(SpdyNetworkTransactionTestParams(kProtoSPDY31, false), | |
| 647 SpdyNetworkTransactionTestParams(kProtoSPDY31, true), | |
| 648 SpdyNetworkTransactionTestParams(kProtoHTTP2, false), | |
| 649 SpdyNetworkTransactionTestParams(kProtoHTTP2, true))); | |
| 650 | 605 |
| 651 // Verify HttpNetworkTransaction constructor. | 606 // Verify HttpNetworkTransaction constructor. |
| 652 TEST_P(SpdyNetworkTransactionTest, Constructor) { | 607 TEST_P(SpdyNetworkTransactionTest, Constructor) { |
| 653 std::unique_ptr<SpdySessionDependencies> session_deps( | 608 std::unique_ptr<SpdySessionDependencies> session_deps( |
| 654 CreateSpdySessionDependencies(GetParam())); | 609 CreateSpdySessionDependencies(GetParam())); |
| 655 std::unique_ptr<HttpNetworkSession> session( | 610 std::unique_ptr<HttpNetworkSession> session( |
| 656 SpdySessionDependencies::SpdyCreateSession(session_deps.get())); | 611 SpdySessionDependencies::SpdyCreateSession(session_deps.get())); |
| 657 std::unique_ptr<HttpTransaction> trans( | 612 std::unique_ptr<HttpTransaction> trans( |
| 658 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 613 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 659 } | 614 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 680 helper.RunToCompletion(&data); | 635 helper.RunToCompletion(&data); |
| 681 TransactionHelperResult out = helper.output(); | 636 TransactionHelperResult out = helper.output(); |
| 682 EXPECT_THAT(out.rv, IsOk()); | 637 EXPECT_THAT(out.rv, IsOk()); |
| 683 EXPECT_EQ("HTTP/1.1 200", out.status_line); | 638 EXPECT_EQ("HTTP/1.1 200", out.status_line); |
| 684 EXPECT_EQ("hello!", out.response_data); | 639 EXPECT_EQ("hello!", out.response_data); |
| 685 } | 640 } |
| 686 | 641 |
| 687 TEST_P(SpdyNetworkTransactionTest, GetAtEachPriority) { | 642 TEST_P(SpdyNetworkTransactionTest, GetAtEachPriority) { |
| 688 for (RequestPriority p = MINIMUM_PRIORITY; p <= MAXIMUM_PRIORITY; | 643 for (RequestPriority p = MINIMUM_PRIORITY; p <= MAXIMUM_PRIORITY; |
| 689 p = RequestPriority(p + 1)) { | 644 p = RequestPriority(p + 1)) { |
| 690 SpdyTestUtil spdy_test_util(GetParam().protocol, | 645 SpdyTestUtil spdy_test_util(GetParam()); |
| 691 GetParam().priority_to_dependency); | |
| 692 | 646 |
| 693 // Construct the request. | 647 // Construct the request. |
| 694 std::unique_ptr<SpdySerializedFrame> req( | 648 std::unique_ptr<SpdySerializedFrame> req( |
| 695 spdy_test_util.ConstructSpdyGet(nullptr, 0, 1, p, true)); | 649 spdy_test_util.ConstructSpdyGet(nullptr, 0, 1, p, true)); |
| 696 MockWrite writes[] = {CreateMockWrite(*req, 0)}; | 650 MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
| 697 | 651 |
| 698 SpdyPriority spdy_prio = 0; | 652 SpdyPriority spdy_prio = 0; |
| 699 EXPECT_TRUE( | 653 EXPECT_TRUE(GetSpdyPriority(*req, &spdy_prio)); |
| 700 GetSpdyPriority(spdy_test_util.spdy_version(), *req, &spdy_prio)); | |
| 701 // this repeats the RequestPriority-->SpdyPriority mapping from | 654 // this repeats the RequestPriority-->SpdyPriority mapping from |
| 702 // SpdyFramer::ConvertRequestPriorityToSpdyPriority to make | 655 // SpdyFramer::ConvertRequestPriorityToSpdyPriority to make |
| 703 // sure it's being done right. | 656 // sure it's being done right. |
| 704 switch (p) { | 657 switch (p) { |
| 705 case HIGHEST: | 658 case HIGHEST: |
| 706 EXPECT_EQ(0, spdy_prio); | 659 EXPECT_EQ(0, spdy_prio); |
| 707 break; | 660 break; |
| 708 case MEDIUM: | 661 case MEDIUM: |
| 709 EXPECT_EQ(1, spdy_prio); | 662 EXPECT_EQ(1, spdy_prio); |
| 710 break; | 663 break; |
| (...skipping 1152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1863 expected_response += kUploadData; | 1816 expected_response += kUploadData; |
| 1864 | 1817 |
| 1865 TransactionHelperResult out = helper.output(); | 1818 TransactionHelperResult out = helper.output(); |
| 1866 EXPECT_THAT(out.rv, IsOk()); | 1819 EXPECT_THAT(out.rv, IsOk()); |
| 1867 EXPECT_EQ("HTTP/1.1 200", out.status_line); | 1820 EXPECT_EQ("HTTP/1.1 200", out.status_line); |
| 1868 EXPECT_EQ(expected_response, out.response_data); | 1821 EXPECT_EQ(expected_response, out.response_data); |
| 1869 } | 1822 } |
| 1870 | 1823 |
| 1871 // Test that a POST without any post data works. | 1824 // Test that a POST without any post data works. |
| 1872 TEST_P(SpdyNetworkTransactionTest, NullPost) { | 1825 TEST_P(SpdyNetworkTransactionTest, NullPost) { |
| 1873 BufferedSpdyFramer framer(spdy_util_.spdy_version()); | 1826 BufferedSpdyFramer framer(HTTP2); |
| 1874 // Setup the request | 1827 // Setup the request |
| 1875 HttpRequestInfo request; | 1828 HttpRequestInfo request; |
| 1876 request.method = "POST"; | 1829 request.method = "POST"; |
| 1877 request.url = default_url_; | 1830 request.url = default_url_; |
| 1878 // Create an empty UploadData. | 1831 // Create an empty UploadData. |
| 1879 request.upload_data_stream = NULL; | 1832 request.upload_data_stream = NULL; |
| 1880 | 1833 |
| 1881 // When request.upload_data_stream is NULL for post, content-length is | 1834 // When request.upload_data_stream is NULL for post, content-length is |
| 1882 // expected to be 0. | 1835 // expected to be 0. |
| 1883 SpdyHeaderBlock req_block( | 1836 SpdyHeaderBlock req_block( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1905 BoundNetLog(), GetParam(), NULL); | 1858 BoundNetLog(), GetParam(), NULL); |
| 1906 helper.RunToCompletion(&data); | 1859 helper.RunToCompletion(&data); |
| 1907 TransactionHelperResult out = helper.output(); | 1860 TransactionHelperResult out = helper.output(); |
| 1908 EXPECT_THAT(out.rv, IsOk()); | 1861 EXPECT_THAT(out.rv, IsOk()); |
| 1909 EXPECT_EQ("HTTP/1.1 200", out.status_line); | 1862 EXPECT_EQ("HTTP/1.1 200", out.status_line); |
| 1910 EXPECT_EQ("hello!", out.response_data); | 1863 EXPECT_EQ("hello!", out.response_data); |
| 1911 } | 1864 } |
| 1912 | 1865 |
| 1913 // Test that a simple POST works. | 1866 // Test that a simple POST works. |
| 1914 TEST_P(SpdyNetworkTransactionTest, EmptyPost) { | 1867 TEST_P(SpdyNetworkTransactionTest, EmptyPost) { |
| 1915 BufferedSpdyFramer framer(spdy_util_.spdy_version()); | 1868 BufferedSpdyFramer framer(HTTP2); |
| 1916 // Create an empty UploadDataStream. | 1869 // Create an empty UploadDataStream. |
| 1917 std::vector<std::unique_ptr<UploadElementReader>> element_readers; | 1870 std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 1918 ElementsUploadDataStream stream(std::move(element_readers), 0); | 1871 ElementsUploadDataStream stream(std::move(element_readers), 0); |
| 1919 | 1872 |
| 1920 // Setup the request | 1873 // Setup the request |
| 1921 HttpRequestInfo request; | 1874 HttpRequestInfo request; |
| 1922 request.method = "POST"; | 1875 request.method = "POST"; |
| 1923 request.url = default_url_; | 1876 request.url = default_url_; |
| 1924 request.upload_data_stream = &stream; | 1877 request.upload_data_stream = &stream; |
| 1925 | 1878 |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2420 CreateMockRead(*body2, 3), | 2373 CreateMockRead(*body2, 3), |
| 2421 MockRead(ASYNC, 0, 0, 4) // EOF | 2374 MockRead(ASYNC, 0, 0, 4) // EOF |
| 2422 }; | 2375 }; |
| 2423 | 2376 |
| 2424 SequencedSocketData data2(reads2, arraysize(reads2), writes2, | 2377 SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 2425 arraysize(writes2)); | 2378 arraysize(writes2)); |
| 2426 | 2379 |
| 2427 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN | 2380 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN |
| 2428 TestDelegate d; | 2381 TestDelegate d; |
| 2429 { | 2382 { |
| 2430 SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); | 2383 SpdyURLRequestContext spdy_url_request_context; |
| 2431 std::unique_ptr<URLRequest> r(spdy_url_request_context.CreateRequest( | 2384 std::unique_ptr<URLRequest> r(spdy_url_request_context.CreateRequest( |
| 2432 default_url_, DEFAULT_PRIORITY, &d)); | 2385 default_url_, DEFAULT_PRIORITY, &d)); |
| 2433 spdy_url_request_context.socket_factory(). | 2386 spdy_url_request_context.socket_factory(). |
| 2434 AddSocketDataProvider(&data); | 2387 AddSocketDataProvider(&data); |
| 2435 spdy_url_request_context.socket_factory(). | 2388 spdy_url_request_context.socket_factory(). |
| 2436 AddSocketDataProvider(&data2); | 2389 AddSocketDataProvider(&data2); |
| 2437 | 2390 |
| 2438 d.set_quit_on_redirect(true); | 2391 d.set_quit_on_redirect(true); |
| 2439 r->Start(); | 2392 r->Start(); |
| 2440 base::RunLoop().Run(); | 2393 base::RunLoop().Run(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2502 }; | 2455 }; |
| 2503 MockRead reads2[] = { | 2456 MockRead reads2[] = { |
| 2504 CreateMockRead(*resp2, 2), | 2457 CreateMockRead(*resp2, 2), |
| 2505 CreateMockRead(*body2, 3), | 2458 CreateMockRead(*body2, 3), |
| 2506 MockRead(ASYNC, 0, 0, 5) // EOF | 2459 MockRead(ASYNC, 0, 0, 5) // EOF |
| 2507 }; | 2460 }; |
| 2508 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | 2461 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2509 SequencedSocketData data2(reads2, arraysize(reads2), writes2, | 2462 SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 2510 arraysize(writes2)); | 2463 arraysize(writes2)); |
| 2511 | 2464 |
| 2512 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN | |
| 2513 TestDelegate d; | 2465 TestDelegate d; |
| 2514 TestDelegate d2; | 2466 TestDelegate d2; |
| 2515 SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); | 2467 SpdyURLRequestContext spdy_url_request_context; |
| 2516 { | 2468 { |
| 2517 std::unique_ptr<URLRequest> r(spdy_url_request_context.CreateRequest( | 2469 std::unique_ptr<URLRequest> r(spdy_url_request_context.CreateRequest( |
| 2518 default_url_, DEFAULT_PRIORITY, &d)); | 2470 default_url_, DEFAULT_PRIORITY, &d)); |
| 2519 spdy_url_request_context.socket_factory(). | 2471 spdy_url_request_context.socket_factory(). |
| 2520 AddSocketDataProvider(&data); | 2472 AddSocketDataProvider(&data); |
| 2521 | 2473 |
| 2522 r->Start(); | 2474 r->Start(); |
| 2523 base::RunLoop().Run(); | 2475 base::RunLoop().Run(); |
| 2524 | 2476 |
| 2525 EXPECT_EQ(0, d.received_redirect_count()); | 2477 EXPECT_EQ(0, d.received_redirect_count()); |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2881 | 2833 |
| 2882 // Verify the pushed stream. | 2834 // Verify the pushed stream. |
| 2883 EXPECT_TRUE(response2.headers); | 2835 EXPECT_TRUE(response2.headers); |
| 2884 EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); | 2836 EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
| 2885 } | 2837 } |
| 2886 | 2838 |
| 2887 TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID0) { | 2839 TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID0) { |
| 2888 std::unique_ptr<SpdySerializedFrame> stream1_syn( | 2840 std::unique_ptr<SpdySerializedFrame> stream1_syn( |
| 2889 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 2841 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 2890 std::unique_ptr<SpdySerializedFrame> goaway; | 2842 std::unique_ptr<SpdySerializedFrame> goaway; |
| 2891 if (spdy_util_.spdy_version() == SPDY3) { | |
| 2892 goaway.reset(spdy_util_.ConstructSpdyGoAway(0, GOAWAY_PROTOCOL_ERROR, | |
| 2893 "Push on even stream id.")); | |
| 2894 } else { | |
| 2895 goaway.reset(spdy_util_.ConstructSpdyGoAway( | 2843 goaway.reset(spdy_util_.ConstructSpdyGoAway( |
| 2896 0, GOAWAY_PROTOCOL_ERROR, "Framer error: 1 (INVALID_STREAM_ID).")); | 2844 0, GOAWAY_PROTOCOL_ERROR, "Framer error: 1 (INVALID_STREAM_ID).")); |
| 2897 } | |
| 2898 MockWrite writes[] = { | 2845 MockWrite writes[] = { |
| 2899 CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*goaway, 3), | 2846 CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*goaway, 3), |
| 2900 }; | 2847 }; |
| 2901 | 2848 |
| 2902 std::unique_ptr<SpdySerializedFrame> stream1_reply( | 2849 std::unique_ptr<SpdySerializedFrame> stream1_reply( |
| 2903 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2850 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2904 std::unique_ptr<SpdySerializedFrame> stream2_syn(spdy_util_.ConstructSpdyPush( | 2851 std::unique_ptr<SpdySerializedFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2905 NULL, 0, 2, 0, GetDefaultUrlWithPath("/foo.dat").c_str())); | 2852 NULL, 0, 2, 0, GetDefaultUrlWithPath("/foo.dat").c_str())); |
| 2906 MockRead reads[] = { | 2853 MockRead reads[] = { |
| 2907 CreateMockRead(*stream1_reply, 1), | 2854 CreateMockRead(*stream1_reply, 1), |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2992 std::unique_ptr<SpdySerializedFrame> stream2_rst( | 2939 std::unique_ptr<SpdySerializedFrame> stream2_rst( |
| 2993 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); | 2940 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
| 2994 MockWrite writes[] = { | 2941 MockWrite writes[] = { |
| 2995 CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*stream2_rst, 3), | 2942 CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*stream2_rst, 3), |
| 2996 }; | 2943 }; |
| 2997 | 2944 |
| 2998 std::unique_ptr<SpdySerializedFrame> stream1_reply( | 2945 std::unique_ptr<SpdySerializedFrame> stream1_reply( |
| 2999 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2946 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3000 SpdyHeaderBlock incomplete_headers; | 2947 SpdyHeaderBlock incomplete_headers; |
| 3001 incomplete_headers[spdy_util_.GetStatusKey()] = "200 OK"; | 2948 incomplete_headers[spdy_util_.GetStatusKey()] = "200 OK"; |
| 3002 incomplete_headers[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | |
| 3003 incomplete_headers["hello"] = "bye"; | 2949 incomplete_headers["hello"] = "bye"; |
| 3004 std::unique_ptr<SpdySerializedFrame> stream2_syn( | 2950 std::unique_ptr<SpdySerializedFrame> stream2_syn( |
| 3005 spdy_util_.ConstructInitialSpdyPushFrame(std::move(incomplete_headers), 2, | 2951 spdy_util_.ConstructInitialSpdyPushFrame(std::move(incomplete_headers), 2, |
| 3006 1)); | 2952 1)); |
| 3007 MockRead reads[] = { | 2953 MockRead reads[] = { |
| 3008 CreateMockRead(*stream1_reply, 1), | 2954 CreateMockRead(*stream1_reply, 1), |
| 3009 CreateMockRead(*stream2_syn, 2), | 2955 CreateMockRead(*stream2_syn, 2), |
| 3010 CreateMockRead(*stream1_body, 4), | 2956 CreateMockRead(*stream1_body, 4), |
| 3011 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5) // Force a pause | 2957 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5) // Force a pause |
| 3012 }; | 2958 }; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3199 { "cookie", "val1,val2", | 3145 { "cookie", "val1,val2", |
| 3200 NULL | 3146 NULL |
| 3201 }, | 3147 }, |
| 3202 } | 3148 } |
| 3203 }; | 3149 }; |
| 3204 | 3150 |
| 3205 test_cases[0].expected_headers["status"] = "200"; | 3151 test_cases[0].expected_headers["status"] = "200"; |
| 3206 test_cases[1].expected_headers["status"] = "200"; | 3152 test_cases[1].expected_headers["status"] = "200"; |
| 3207 test_cases[2].expected_headers["status"] = "200"; | 3153 test_cases[2].expected_headers["status"] = "200"; |
| 3208 | 3154 |
| 3209 // HTTP/2 eliminates use of the :version header. | |
| 3210 if (GetParam().protocol == kProtoSPDY31) { | |
| 3211 test_cases[0].expected_headers["version"] = "HTTP/1.1"; | |
| 3212 test_cases[1].expected_headers["version"] = "HTTP/1.1"; | |
| 3213 test_cases[2].expected_headers["version"] = "HTTP/1.1"; | |
| 3214 } | |
| 3215 | |
| 3216 test_cases[0].expected_headers["hello"] = "bye"; | 3155 test_cases[0].expected_headers["hello"] = "bye"; |
| 3217 test_cases[1].expected_headers["hello"] = "bye"; | 3156 test_cases[1].expected_headers["hello"] = "bye"; |
| 3218 test_cases[2].expected_headers["hello"] = "bye"; | 3157 test_cases[2].expected_headers["hello"] = "bye"; |
| 3219 | 3158 |
| 3220 test_cases[0].expected_headers["cookie"] = base::StringPiece("val1\0val2", 9); | 3159 test_cases[0].expected_headers["cookie"] = base::StringPiece("val1\0val2", 9); |
| 3221 test_cases[2].expected_headers["cookie"] = "val1,val2"; | 3160 test_cases[2].expected_headers["cookie"] = "val1,val2"; |
| 3222 | 3161 |
| 3223 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 3162 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 3224 SpdyTestUtil spdy_test_util(GetParam().protocol, | 3163 SpdyTestUtil spdy_test_util(GetParam()); |
| 3225 GetParam().priority_to_dependency); | |
| 3226 std::unique_ptr<SpdySerializedFrame> req( | 3164 std::unique_ptr<SpdySerializedFrame> req( |
| 3227 spdy_test_util.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 3165 spdy_test_util.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 3228 MockWrite writes[] = {CreateMockWrite(*req, 0)}; | 3166 MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
| 3229 | 3167 |
| 3230 std::unique_ptr<SpdySerializedFrame> resp( | 3168 std::unique_ptr<SpdySerializedFrame> resp( |
| 3231 spdy_test_util.ConstructSpdyGetSynReply(test_cases[i].extra_headers, | 3169 spdy_test_util.ConstructSpdyGetSynReply(test_cases[i].extra_headers, |
| 3232 test_cases[i].num_headers, 1)); | 3170 test_cases[i].num_headers, 1)); |
| 3233 std::unique_ptr<SpdySerializedFrame> body( | 3171 std::unique_ptr<SpdySerializedFrame> body( |
| 3234 spdy_test_util.ConstructSpdyBodyFrame(1, true)); | 3172 spdy_test_util.ConstructSpdyBodyFrame(1, true)); |
| 3235 MockRead reads[] = { | 3173 MockRead reads[] = { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3275 TEST_P(SpdyNetworkTransactionTest, SynReplyHeadersVary) { | 3213 TEST_P(SpdyNetworkTransactionTest, SynReplyHeadersVary) { |
| 3276 // Modify the following data to change/add test cases: | 3214 // Modify the following data to change/add test cases: |
| 3277 struct SynReplyTests { | 3215 struct SynReplyTests { |
| 3278 bool vary_matches; | 3216 bool vary_matches; |
| 3279 int num_headers[2]; | 3217 int num_headers[2]; |
| 3280 const char* extra_headers[2][16]; | 3218 const char* extra_headers[2][16]; |
| 3281 } test_cases[] = { | 3219 } test_cases[] = { |
| 3282 // Test the case of a multi-valued cookie. When the value is delimited | 3220 // Test the case of a multi-valued cookie. When the value is delimited |
| 3283 // with NUL characters, it needs to be unfolded into multiple headers. | 3221 // with NUL characters, it needs to be unfolded into multiple headers. |
| 3284 {true, | 3222 {true, |
| 3285 {1, 4}, | 3223 {1, 3}, |
| 3286 {{"cookie", "val1,val2", NULL}, | 3224 {{"cookie", "val1,val2", NULL}, |
| 3287 {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), | 3225 {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
| 3288 "/index.php", spdy_util_.GetVersionKey(), "HTTP/1.1", "vary", "cookie", | 3226 "/index.php", "vary", "cookie", NULL}}}, |
| 3289 NULL}}}, | |
| 3290 {// Multiple vary fields. | 3227 {// Multiple vary fields. |
| 3291 true, | 3228 true, |
| 3292 {2, 5}, | |
| 3293 {{"friend", "barney", "enemy", "snaggletooth", NULL}, | |
| 3294 {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), | |
| 3295 "/index.php", spdy_util_.GetVersionKey(), "HTTP/1.1", "vary", "friend", | |
| 3296 "vary", "enemy", NULL}}}, | |
| 3297 {// Test a '*' vary field. | |
| 3298 false, | |
| 3299 {1, 4}, | |
| 3300 {{"cookie", "val1,val2", NULL}, | |
| 3301 {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), | |
| 3302 "/index.php", spdy_util_.GetVersionKey(), "HTTP/1.1", "vary", "*", | |
| 3303 NULL}}}, | |
| 3304 {// Multiple comma-separated vary fields. | |
| 3305 true, | |
| 3306 {2, 4}, | 3229 {2, 4}, |
| 3307 {{"friend", "barney", "enemy", "snaggletooth", NULL}, | 3230 {{"friend", "barney", "enemy", "snaggletooth", NULL}, |
| 3308 {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), | 3231 {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
| 3309 "/index.php", spdy_util_.GetVersionKey(), "HTTP/1.1", "vary", | 3232 "/index.php", "vary", "friend", "vary", "enemy", NULL}}}, |
| 3310 "friend,enemy", NULL}}}}; | 3233 {// Test a '*' vary field. |
| 3234 false, |
| 3235 {1, 3}, |
| 3236 {{"cookie", "val1,val2", NULL}, |
| 3237 {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
| 3238 "/index.php", "vary", "*", NULL}}}, |
| 3239 {// Multiple comma-separated vary fields. |
| 3240 true, |
| 3241 {2, 3}, |
| 3242 {{"friend", "barney", "enemy", "snaggletooth", NULL}, |
| 3243 {spdy_util_.GetStatusKey(), "200", spdy_util_.GetPathKey(), |
| 3244 "/index.php", "vary", "friend,enemy", NULL}}}}; |
| 3311 | 3245 |
| 3312 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 3246 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 3313 SpdyTestUtil spdy_test_util(GetParam().protocol, | 3247 SpdyTestUtil spdy_test_util(GetParam()); |
| 3314 GetParam().priority_to_dependency); | |
| 3315 | 3248 |
| 3316 // Construct the request. | 3249 // Construct the request. |
| 3317 std::unique_ptr<SpdySerializedFrame> frame_req( | 3250 std::unique_ptr<SpdySerializedFrame> frame_req( |
| 3318 spdy_test_util.ConstructSpdyGet(test_cases[i].extra_headers[0], | 3251 spdy_test_util.ConstructSpdyGet(test_cases[i].extra_headers[0], |
| 3319 test_cases[i].num_headers[0], 1, LOWEST, | 3252 test_cases[i].num_headers[0], 1, LOWEST, |
| 3320 true)); | 3253 true)); |
| 3321 | 3254 |
| 3322 MockWrite writes[] = { | 3255 MockWrite writes[] = { |
| 3323 CreateMockWrite(*frame_req, 0), | 3256 CreateMockWrite(*frame_req, 0), |
| 3324 }; | 3257 }; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3385 } | 3318 } |
| 3386 | 3319 |
| 3387 // Verify that we don't crash on invalid SynReply responses. | 3320 // Verify that we don't crash on invalid SynReply responses. |
| 3388 TEST_P(SpdyNetworkTransactionTest, InvalidSynReply) { | 3321 TEST_P(SpdyNetworkTransactionTest, InvalidSynReply) { |
| 3389 struct InvalidSynReplyTests { | 3322 struct InvalidSynReplyTests { |
| 3390 int num_headers; | 3323 int num_headers; |
| 3391 const char* headers[10]; | 3324 const char* headers[10]; |
| 3392 } test_cases[] = { | 3325 } test_cases[] = { |
| 3393 // SYN_REPLY missing status header | 3326 // SYN_REPLY missing status header |
| 3394 { | 3327 { |
| 3395 4, | 3328 3, |
| 3396 {spdy_util_.GetPathKey(), "/index.php", spdy_util_.GetVersionKey(), | 3329 {spdy_util_.GetPathKey(), "/index.php", "cookie", "val1", "cookie", |
| 3397 "HTTP/1.1", "cookie", "val1", "cookie", "val2", NULL}, | 3330 "val2", NULL}, |
| 3398 }, | 3331 }, |
| 3399 // SYN_REPLY missing version header | 3332 // SYN_REPLY missing version header |
| 3400 { | 3333 { |
| 3401 2, {spdy_util_.GetPathKey(), "/index.php", "status", "200", NULL}, | 3334 1, {spdy_util_.GetPathKey(), "/index.php", "status", "200", NULL}, |
| 3402 }, | 3335 }, |
| 3403 // SYN_REPLY with no headers | 3336 // SYN_REPLY with no headers |
| 3404 { | 3337 { |
| 3405 0, {NULL}, | 3338 0, {NULL}, |
| 3406 }, | 3339 }, |
| 3407 }; | 3340 }; |
| 3408 | 3341 |
| 3409 for (size_t i = 0; i < arraysize(test_cases); ++i) { | 3342 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 3410 SpdyTestUtil spdy_test_util(GetParam().protocol, | 3343 SpdyTestUtil spdy_test_util(GetParam()); |
| 3411 GetParam().priority_to_dependency); | |
| 3412 | 3344 |
| 3413 std::unique_ptr<SpdySerializedFrame> req( | 3345 std::unique_ptr<SpdySerializedFrame> req( |
| 3414 spdy_test_util.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 3346 spdy_test_util.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 3415 std::unique_ptr<SpdySerializedFrame> rst( | 3347 std::unique_ptr<SpdySerializedFrame> rst( |
| 3416 spdy_test_util.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); | 3348 spdy_test_util.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 3417 MockWrite writes[] = { | 3349 MockWrite writes[] = { |
| 3418 CreateMockWrite(*req, 0), CreateMockWrite(*rst, 2), | 3350 CreateMockWrite(*req, 0), CreateMockWrite(*rst, 2), |
| 3419 }; | 3351 }; |
| 3420 | 3352 |
| 3421 // Construct the reply. | 3353 // Construct the reply. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3432 arraysize(writes)); | 3364 arraysize(writes)); |
| 3433 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 3365 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 3434 BoundNetLog(), GetParam(), NULL); | 3366 BoundNetLog(), GetParam(), NULL); |
| 3435 helper.RunToCompletion(&data); | 3367 helper.RunToCompletion(&data); |
| 3436 TransactionHelperResult out = helper.output(); | 3368 TransactionHelperResult out = helper.output(); |
| 3437 EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); | 3369 EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); |
| 3438 } | 3370 } |
| 3439 } | 3371 } |
| 3440 | 3372 |
| 3441 TEST_P(SpdyNetworkTransactionTest, CorruptFrameSessionError) { | 3373 TEST_P(SpdyNetworkTransactionTest, CorruptFrameSessionError) { |
| 3442 if (spdy_util_.spdy_version() != SPDY3) { | |
| 3443 return; | |
| 3444 } | |
| 3445 | |
| 3446 std::unique_ptr<SpdySerializedFrame> req( | 3374 std::unique_ptr<SpdySerializedFrame> req( |
| 3447 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 3375 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 3448 std::unique_ptr<SpdySerializedFrame> goaway(spdy_util_.ConstructSpdyGoAway( | 3376 std::unique_ptr<SpdySerializedFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 3449 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 5 (DECOMPRESS_FAILURE).")); | |
| 3450 MockWrite writes[] = { | |
| 3451 CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 3), | |
| 3452 }; | |
| 3453 | |
| 3454 // This is the length field that's too short. | |
| 3455 std::unique_ptr<SpdySerializedFrame> syn_reply_wrong_length( | |
| 3456 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); | |
| 3457 size_t right_size = | |
| 3458 syn_reply_wrong_length->size() - | |
| 3459 SpdyConstants::GetControlFrameHeaderSize(spdy_util_.spdy_version()); | |
| 3460 size_t wrong_size = right_size - 4; | |
| 3461 test::SetFrameLength(syn_reply_wrong_length.get(), | |
| 3462 wrong_size, | |
| 3463 spdy_util_.spdy_version()); | |
| 3464 std::unique_ptr<SpdySerializedFrame> body( | |
| 3465 spdy_util_.ConstructSpdyBodyFrame(1, true)); | |
| 3466 MockRead reads[] = { | |
| 3467 MockRead(ASYNC, syn_reply_wrong_length->data(), | |
| 3468 syn_reply_wrong_length->size(), 1), | |
| 3469 CreateMockRead(*body, 2), | |
| 3470 }; | |
| 3471 | |
| 3472 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | |
| 3473 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | |
| 3474 BoundNetLog(), GetParam(), nullptr); | |
| 3475 helper.RunToCompletion(&data); | |
| 3476 TransactionHelperResult out = helper.output(); | |
| 3477 EXPECT_THAT(out.rv, IsError(ERR_SPDY_PROTOCOL_ERROR)); | |
| 3478 } | |
| 3479 | |
| 3480 TEST_P(SpdyNetworkTransactionTest, CorruptFrameSessionErrorSpdy4) { | |
| 3481 if (spdy_util_.spdy_version() != HTTP2) { | |
| 3482 return; | |
| 3483 } | |
| 3484 | |
| 3485 std::unique_ptr<SpdySerializedFrame> req( | |
| 3486 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | |
| 3487 std::unique_ptr<SpdySerializedFrame> goaway(spdy_util_.ConstructSpdyGoAway( | |
| 3488 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 6 (DECOMPRESS_FAILURE).")); | 3377 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 6 (DECOMPRESS_FAILURE).")); |
| 3489 MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2)}; | 3378 MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2)}; |
| 3490 | 3379 |
| 3491 // This is the length field that's too short. | 3380 // This is the length field that's too short. |
| 3492 std::unique_ptr<SpdySerializedFrame> syn_reply_wrong_length( | 3381 std::unique_ptr<SpdySerializedFrame> syn_reply_wrong_length( |
| 3493 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); | 3382 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 3494 size_t right_size = | 3383 size_t right_size = syn_reply_wrong_length->size() - |
| 3495 syn_reply_wrong_length->size() - | 3384 SpdyConstants::GetControlFrameHeaderSize(HTTP2); |
| 3496 SpdyConstants::GetControlFrameHeaderSize(spdy_util_.spdy_version()); | |
| 3497 size_t wrong_size = right_size - 4; | 3385 size_t wrong_size = right_size - 4; |
| 3498 test::SetFrameLength(syn_reply_wrong_length.get(), | 3386 test::SetFrameLength(syn_reply_wrong_length.get(), wrong_size, HTTP2); |
| 3499 wrong_size, | |
| 3500 spdy_util_.spdy_version()); | |
| 3501 | 3387 |
| 3502 MockRead reads[] = { | 3388 MockRead reads[] = { |
| 3503 MockRead(ASYNC, syn_reply_wrong_length->data(), | 3389 MockRead(ASYNC, syn_reply_wrong_length->data(), |
| 3504 syn_reply_wrong_length->size() - 4, 1), | 3390 syn_reply_wrong_length->size() - 4, 1), |
| 3505 }; | 3391 }; |
| 3506 | 3392 |
| 3507 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | 3393 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 3508 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 3394 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 3509 BoundNetLog(), GetParam(), NULL); | 3395 BoundNetLog(), GetParam(), NULL); |
| 3510 helper.RunToCompletion(&data); | 3396 helper.RunToCompletion(&data); |
| 3511 TransactionHelperResult out = helper.output(); | 3397 TransactionHelperResult out = helper.output(); |
| 3512 EXPECT_THAT(out.rv, IsError(ERR_SPDY_COMPRESSION_ERROR)); | 3398 EXPECT_THAT(out.rv, IsError(ERR_SPDY_COMPRESSION_ERROR)); |
| 3513 } | 3399 } |
| 3514 | 3400 |
| 3515 TEST_P(SpdyNetworkTransactionTest, GoAwayOnDecompressionFailure) { | 3401 TEST_P(SpdyNetworkTransactionTest, GoAwayOnDecompressionFailure) { |
| 3516 if (GetParam().protocol < kProtoHTTP2) { | |
| 3517 // Decompression failures are a stream error in SPDY3. | |
| 3518 return; | |
| 3519 } | |
| 3520 std::unique_ptr<SpdySerializedFrame> req( | 3402 std::unique_ptr<SpdySerializedFrame> req( |
| 3521 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 3403 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 3522 std::unique_ptr<SpdySerializedFrame> goaway(spdy_util_.ConstructSpdyGoAway( | 3404 std::unique_ptr<SpdySerializedFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 3523 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 6 (DECOMPRESS_FAILURE).")); | 3405 0, GOAWAY_COMPRESSION_ERROR, "Framer error: 6 (DECOMPRESS_FAILURE).")); |
| 3524 MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2)}; | 3406 MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2)}; |
| 3525 | 3407 |
| 3526 // Read HEADERS with corrupted payload. | 3408 // Read HEADERS with corrupted payload. |
| 3527 std::unique_ptr<SpdySerializedFrame> resp( | 3409 std::unique_ptr<SpdySerializedFrame> resp( |
| 3528 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 3410 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3529 memset(resp->data() + 12, 0xcf, resp->size() - 12); | 3411 memset(resp->data() + 12, 0xcf, resp->size() - 12); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3541 std::unique_ptr<SpdySerializedFrame> req( | 3423 std::unique_ptr<SpdySerializedFrame> req( |
| 3542 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 3424 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 3543 std::unique_ptr<SpdySerializedFrame> goaway(spdy_util_.ConstructSpdyGoAway( | 3425 std::unique_ptr<SpdySerializedFrame> goaway(spdy_util_.ConstructSpdyGoAway( |
| 3544 0, GOAWAY_FRAME_SIZE_ERROR, | 3426 0, GOAWAY_FRAME_SIZE_ERROR, |
| 3545 "Framer error: 15 (INVALID_CONTROL_FRAME_SIZE).")); | 3427 "Framer error: 15 (INVALID_CONTROL_FRAME_SIZE).")); |
| 3546 MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2)}; | 3428 MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*goaway, 2)}; |
| 3547 | 3429 |
| 3548 // Read WINDOW_UPDATE with incorrectly-sized payload. | 3430 // Read WINDOW_UPDATE with incorrectly-sized payload. |
| 3549 std::unique_ptr<SpdySerializedFrame> bad_window_update( | 3431 std::unique_ptr<SpdySerializedFrame> bad_window_update( |
| 3550 spdy_util_.ConstructSpdyWindowUpdate(1, 1)); | 3432 spdy_util_.ConstructSpdyWindowUpdate(1, 1)); |
| 3551 test::SetFrameLength(bad_window_update.get(), | 3433 test::SetFrameLength(bad_window_update.get(), bad_window_update->size() - 1, |
| 3552 bad_window_update->size() - 1, | 3434 HTTP2); |
| 3553 spdy_util_.spdy_version()); | |
| 3554 MockRead reads[] = {CreateMockRead(*bad_window_update, 1)}; | 3435 MockRead reads[] = {CreateMockRead(*bad_window_update, 1)}; |
| 3555 | 3436 |
| 3556 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | 3437 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 3557 NormalSpdyTransactionHelper helper( | 3438 NormalSpdyTransactionHelper helper( |
| 3558 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); | 3439 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3559 helper.RunToCompletion(&data); | 3440 helper.RunToCompletion(&data); |
| 3560 TransactionHelperResult out = helper.output(); | 3441 TransactionHelperResult out = helper.output(); |
| 3561 EXPECT_THAT(out.rv, IsError(ERR_SPDY_FRAME_SIZE_ERROR)); | 3442 EXPECT_THAT(out.rv, IsError(ERR_SPDY_FRAME_SIZE_ERROR)); |
| 3562 } | 3443 } |
| 3563 | 3444 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3674 NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, | 3555 NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, |
| 3675 NetLog::PHASE_END); | 3556 NetLog::PHASE_END); |
| 3676 pos = ExpectLogContainsSomewhere(entries, pos + 1, | 3557 pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3677 NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, | 3558 NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, |
| 3678 NetLog::PHASE_BEGIN); | 3559 NetLog::PHASE_BEGIN); |
| 3679 pos = ExpectLogContainsSomewhere(entries, pos + 1, | 3560 pos = ExpectLogContainsSomewhere(entries, pos + 1, |
| 3680 NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, | 3561 NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, |
| 3681 NetLog::PHASE_END); | 3562 NetLog::PHASE_END); |
| 3682 | 3563 |
| 3683 // Check that we logged all the headers correctly | 3564 // Check that we logged all the headers correctly |
| 3684 const NetLog::EventType type = (GetParam().protocol == kProtoSPDY31) | 3565 pos = ExpectLogContainsSomewhere( |
| 3685 ? NetLog::TYPE_HTTP2_SESSION_SYN_STREAM | 3566 entries, 0, NetLog::TYPE_HTTP2_SESSION_SEND_HEADERS, NetLog::PHASE_NONE); |
| 3686 : NetLog::TYPE_HTTP2_SESSION_SEND_HEADERS; | |
| 3687 pos = ExpectLogContainsSomewhere(entries, 0, type, NetLog::PHASE_NONE); | |
| 3688 | 3567 |
| 3689 base::ListValue* header_list; | 3568 base::ListValue* header_list; |
| 3690 ASSERT_TRUE(entries[pos].params.get()); | 3569 ASSERT_TRUE(entries[pos].params.get()); |
| 3691 ASSERT_TRUE(entries[pos].params->GetList("headers", &header_list)); | 3570 ASSERT_TRUE(entries[pos].params->GetList("headers", &header_list)); |
| 3692 | 3571 |
| 3693 std::vector<std::string> expected; | 3572 std::vector<std::string> expected; |
| 3694 expected.push_back(std::string(spdy_util_.GetHostKey()) + | 3573 expected.push_back(std::string(spdy_util_.GetHostKey()) + |
| 3695 ": www.example.org"); | 3574 ": www.example.org"); |
| 3696 expected.push_back(std::string(spdy_util_.GetPathKey()) + ": /"); | 3575 expected.push_back(std::string(spdy_util_.GetPathKey()) + ": /"); |
| 3697 expected.push_back(std::string(spdy_util_.GetSchemeKey()) + ": " + | 3576 expected.push_back(std::string(spdy_util_.GetSchemeKey()) + ": " + |
| 3698 default_url_.scheme()); | 3577 default_url_.scheme()); |
| 3699 expected.push_back(std::string(spdy_util_.GetMethodKey()) + ": GET"); | 3578 expected.push_back(std::string(spdy_util_.GetMethodKey()) + ": GET"); |
| 3700 expected.push_back("user-agent: Chrome"); | 3579 expected.push_back("user-agent: Chrome"); |
| 3701 if (spdy_util_.spdy_version() < HTTP2) { | |
| 3702 // HTTP/2 eliminates use of the :version header. | |
| 3703 expected.push_back(std::string(spdy_util_.GetVersionKey()) + ": HTTP/1.1"); | |
| 3704 } | |
| 3705 EXPECT_EQ(expected.size(), header_list->GetSize()); | 3580 EXPECT_EQ(expected.size(), header_list->GetSize()); |
| 3706 for (std::vector<std::string>::const_iterator it = expected.begin(); | 3581 for (std::vector<std::string>::const_iterator it = expected.begin(); |
| 3707 it != expected.end(); | 3582 it != expected.end(); |
| 3708 ++it) { | 3583 ++it) { |
| 3709 base::StringValue header(*it); | 3584 base::StringValue header(*it); |
| 3710 EXPECT_NE(header_list->end(), header_list->Find(header)) << | 3585 EXPECT_NE(header_list->end(), header_list->Find(header)) << |
| 3711 "Header not found: " << *it; | 3586 "Header not found: " << *it; |
| 3712 } | 3587 } |
| 3713 } | 3588 } |
| 3714 | 3589 |
| 3715 // Since we buffer the IO from the stream to the renderer, this test verifies | 3590 // Since we buffer the IO from the stream to the renderer, this test verifies |
| 3716 // that when we read out the maximum amount of data (e.g. we received 50 bytes | 3591 // that when we read out the maximum amount of data (e.g. we received 50 bytes |
| 3717 // on the network, but issued a Read for only 5 of those bytes) that the data | 3592 // on the network, but issued a Read for only 5 of those bytes) that the data |
| 3718 // flow still works correctly. | 3593 // flow still works correctly. |
| 3719 TEST_P(SpdyNetworkTransactionTest, BufferFull) { | 3594 TEST_P(SpdyNetworkTransactionTest, BufferFull) { |
| 3720 BufferedSpdyFramer framer(spdy_util_.spdy_version()); | 3595 BufferedSpdyFramer framer(HTTP2); |
| 3721 | 3596 |
| 3722 std::unique_ptr<SpdySerializedFrame> req( | 3597 std::unique_ptr<SpdySerializedFrame> req( |
| 3723 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 3598 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 3724 MockWrite writes[] = {CreateMockWrite(*req, 0)}; | 3599 MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
| 3725 | 3600 |
| 3726 // 2 data frames in a single read. | 3601 // 2 data frames in a single read. |
| 3727 std::unique_ptr<SpdySerializedFrame> data_frame_1( | 3602 std::unique_ptr<SpdySerializedFrame> data_frame_1( |
| 3728 framer.CreateDataFrame(1, "goodby", 6, DATA_FLAG_NONE)); | 3603 framer.CreateDataFrame(1, "goodby", 6, DATA_FLAG_NONE)); |
| 3729 std::unique_ptr<SpdySerializedFrame> data_frame_2( | 3604 std::unique_ptr<SpdySerializedFrame> data_frame_2( |
| 3730 framer.CreateDataFrame(1, "e worl", 6, DATA_FLAG_NONE)); | 3605 framer.CreateDataFrame(1, "e worl", 6, DATA_FLAG_NONE)); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3803 | 3678 |
| 3804 EXPECT_THAT(out.rv, IsOk()); | 3679 EXPECT_THAT(out.rv, IsOk()); |
| 3805 EXPECT_EQ("HTTP/1.1 200", out.status_line); | 3680 EXPECT_EQ("HTTP/1.1 200", out.status_line); |
| 3806 EXPECT_EQ("goodbye world", out.response_data); | 3681 EXPECT_EQ("goodbye world", out.response_data); |
| 3807 } | 3682 } |
| 3808 | 3683 |
| 3809 // Verify that basic buffering works; when multiple data frames arrive | 3684 // Verify that basic buffering works; when multiple data frames arrive |
| 3810 // at the same time, ensure that we don't notify a read completion for | 3685 // at the same time, ensure that we don't notify a read completion for |
| 3811 // each data frame individually. | 3686 // each data frame individually. |
| 3812 TEST_P(SpdyNetworkTransactionTest, Buffering) { | 3687 TEST_P(SpdyNetworkTransactionTest, Buffering) { |
| 3813 BufferedSpdyFramer framer(spdy_util_.spdy_version()); | 3688 BufferedSpdyFramer framer(HTTP2); |
| 3814 | 3689 |
| 3815 std::unique_ptr<SpdySerializedFrame> req( | 3690 std::unique_ptr<SpdySerializedFrame> req( |
| 3816 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 3691 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 3817 MockWrite writes[] = {CreateMockWrite(*req, 0)}; | 3692 MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
| 3818 | 3693 |
| 3819 // 4 data frames in a single read. | 3694 // 4 data frames in a single read. |
| 3820 std::unique_ptr<SpdySerializedFrame> data_frame( | 3695 std::unique_ptr<SpdySerializedFrame> data_frame( |
| 3821 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); | 3696 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 3822 std::unique_ptr<SpdySerializedFrame> data_frame_fin( | 3697 std::unique_ptr<SpdySerializedFrame> data_frame_fin( |
| 3823 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN)); | 3698 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN)); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3895 // Verify that we consumed all test data. | 3770 // Verify that we consumed all test data. |
| 3896 helper.VerifyDataConsumed(); | 3771 helper.VerifyDataConsumed(); |
| 3897 | 3772 |
| 3898 EXPECT_THAT(out.rv, IsOk()); | 3773 EXPECT_THAT(out.rv, IsOk()); |
| 3899 EXPECT_EQ("HTTP/1.1 200", out.status_line); | 3774 EXPECT_EQ("HTTP/1.1 200", out.status_line); |
| 3900 EXPECT_EQ("messagemessagemessagemessage", out.response_data); | 3775 EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 3901 } | 3776 } |
| 3902 | 3777 |
| 3903 // Verify the case where we buffer data but read it after it has been buffered. | 3778 // Verify the case where we buffer data but read it after it has been buffered. |
| 3904 TEST_P(SpdyNetworkTransactionTest, BufferedAll) { | 3779 TEST_P(SpdyNetworkTransactionTest, BufferedAll) { |
| 3905 BufferedSpdyFramer framer(spdy_util_.spdy_version()); | 3780 BufferedSpdyFramer framer(HTTP2); |
| 3906 | 3781 |
| 3907 std::unique_ptr<SpdySerializedFrame> req( | 3782 std::unique_ptr<SpdySerializedFrame> req( |
| 3908 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 3783 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 3909 MockWrite writes[] = {CreateMockWrite(*req, 0)}; | 3784 MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
| 3910 | 3785 |
| 3911 // 5 data frames in a single read. | 3786 // 5 data frames in a single read. |
| 3912 std::unique_ptr<SpdySerializedFrame> reply( | 3787 std::unique_ptr<SpdySerializedFrame> reply( |
| 3913 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 3788 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3914 std::unique_ptr<SpdySerializedFrame> data_frame( | 3789 std::unique_ptr<SpdySerializedFrame> data_frame( |
| 3915 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); | 3790 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3981 // Verify that we consumed all test data. | 3856 // Verify that we consumed all test data. |
| 3982 helper.VerifyDataConsumed(); | 3857 helper.VerifyDataConsumed(); |
| 3983 | 3858 |
| 3984 EXPECT_THAT(out.rv, IsOk()); | 3859 EXPECT_THAT(out.rv, IsOk()); |
| 3985 EXPECT_EQ("HTTP/1.1 200", out.status_line); | 3860 EXPECT_EQ("HTTP/1.1 200", out.status_line); |
| 3986 EXPECT_EQ("messagemessagemessagemessage", out.response_data); | 3861 EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 3987 } | 3862 } |
| 3988 | 3863 |
| 3989 // Verify the case where we buffer data and close the connection. | 3864 // Verify the case where we buffer data and close the connection. |
| 3990 TEST_P(SpdyNetworkTransactionTest, BufferedClosed) { | 3865 TEST_P(SpdyNetworkTransactionTest, BufferedClosed) { |
| 3991 BufferedSpdyFramer framer(spdy_util_.spdy_version()); | 3866 BufferedSpdyFramer framer(HTTP2); |
| 3992 | 3867 |
| 3993 std::unique_ptr<SpdySerializedFrame> req( | 3868 std::unique_ptr<SpdySerializedFrame> req( |
| 3994 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 3869 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 3995 MockWrite writes[] = {CreateMockWrite(*req, 0)}; | 3870 MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
| 3996 | 3871 |
| 3997 // All data frames in a single read. | 3872 // All data frames in a single read. |
| 3998 // NOTE: We don't FIN the stream. | 3873 // NOTE: We don't FIN the stream. |
| 3999 std::unique_ptr<SpdySerializedFrame> data_frame( | 3874 std::unique_ptr<SpdySerializedFrame> data_frame( |
| 4000 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); | 3875 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 4001 const SpdySerializedFrame* data_frames[4] = { | 3876 const SpdySerializedFrame* data_frames[4] = { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4068 // Flush the MessageLoop while the SpdySessionDependencies (in particular, the | 3943 // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
| 4069 // MockClientSocketFactory) are still alive. | 3944 // MockClientSocketFactory) are still alive. |
| 4070 base::RunLoop().RunUntilIdle(); | 3945 base::RunLoop().RunUntilIdle(); |
| 4071 | 3946 |
| 4072 // Verify that we consumed all test data. | 3947 // Verify that we consumed all test data. |
| 4073 helper.VerifyDataConsumed(); | 3948 helper.VerifyDataConsumed(); |
| 4074 } | 3949 } |
| 4075 | 3950 |
| 4076 // Verify the case where we buffer data and cancel the transaction. | 3951 // Verify the case where we buffer data and cancel the transaction. |
| 4077 TEST_P(SpdyNetworkTransactionTest, BufferedCancelled) { | 3952 TEST_P(SpdyNetworkTransactionTest, BufferedCancelled) { |
| 4078 BufferedSpdyFramer framer(spdy_util_.spdy_version()); | 3953 BufferedSpdyFramer framer(HTTP2); |
| 4079 | 3954 |
| 4080 std::unique_ptr<SpdySerializedFrame> req( | 3955 std::unique_ptr<SpdySerializedFrame> req( |
| 4081 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 3956 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 4082 std::unique_ptr<SpdySerializedFrame> rst( | 3957 std::unique_ptr<SpdySerializedFrame> rst( |
| 4083 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | 3958 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
| 4084 MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*rst, 4)}; | 3959 MockWrite writes[] = {CreateMockWrite(*req, 0), CreateMockWrite(*rst, 4)}; |
| 4085 | 3960 |
| 4086 // NOTE: We don't FIN the stream. | 3961 // NOTE: We don't FIN the stream. |
| 4087 std::unique_ptr<SpdySerializedFrame> data_frame( | 3962 std::unique_ptr<SpdySerializedFrame> data_frame( |
| 4088 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); | 3963 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4135 helper.ResetTrans(); | 4010 helper.ResetTrans(); |
| 4136 | 4011 |
| 4137 // Flush the MessageLoop; this will cause the buffered IO task | 4012 // Flush the MessageLoop; this will cause the buffered IO task |
| 4138 // to run for the final time. | 4013 // to run for the final time. |
| 4139 base::RunLoop().RunUntilIdle(); | 4014 base::RunLoop().RunUntilIdle(); |
| 4140 | 4015 |
| 4141 // Verify that we consumed all test data. | 4016 // Verify that we consumed all test data. |
| 4142 helper.VerifyDataConsumed(); | 4017 helper.VerifyDataConsumed(); |
| 4143 } | 4018 } |
| 4144 | 4019 |
| 4145 // Test that if the server requests persistence of settings, that we save | |
| 4146 // the settings in the HttpServerProperties. | |
| 4147 TEST_P(SpdyNetworkTransactionTest, SettingsSaved) { | |
| 4148 if (spdy_util_.spdy_version() >= HTTP2) { | |
| 4149 // HTTP/2 doesn't support settings persistence. | |
| 4150 return; | |
| 4151 } | |
| 4152 static const SpdyHeaderInfo kSynReplyInfo = { | |
| 4153 SYN_REPLY, // Syn Reply | |
| 4154 1, // Stream ID | |
| 4155 0, // Associated Stream ID | |
| 4156 ConvertRequestPriorityToSpdyPriority(LOWEST, spdy_util_.spdy_version()), | |
| 4157 0, // Weight (unused) | |
| 4158 CONTROL_FLAG_NONE, // Control Flags | |
| 4159 RST_STREAM_INVALID, // Status | |
| 4160 NULL, // Data | |
| 4161 0, // Data Length | |
| 4162 DATA_FLAG_NONE // Data Flags | |
| 4163 }; | |
| 4164 | |
| 4165 BoundNetLog net_log; | |
| 4166 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | |
| 4167 net_log, GetParam(), NULL); | |
| 4168 helper.RunPreTestSetup(); | |
| 4169 | |
| 4170 // Verify that no settings exist initially. | |
| 4171 url::SchemeHostPort spdy_server(default_url_); | |
| 4172 SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); | |
| 4173 EXPECT_TRUE(spdy_session_pool->http_server_properties() | |
| 4174 ->GetSpdySettings(spdy_server) | |
| 4175 .empty()); | |
| 4176 | |
| 4177 // Construct the request. | |
| 4178 std::unique_ptr<SpdySerializedFrame> req( | |
| 4179 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | |
| 4180 MockWrite writes[] = {CreateMockWrite(*req, 0)}; | |
| 4181 | |
| 4182 // Construct the reply. | |
| 4183 SpdyHeaderBlock reply_headers; | |
| 4184 reply_headers[spdy_util_.GetStatusKey()] = "200"; | |
| 4185 reply_headers[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | |
| 4186 std::unique_ptr<SpdySerializedFrame> reply( | |
| 4187 spdy_util_.ConstructSpdyFrame(kSynReplyInfo, std::move(reply_headers))); | |
| 4188 | |
| 4189 const SpdySettingsIds kSampleId1 = SETTINGS_UPLOAD_BANDWIDTH; | |
| 4190 unsigned int kSampleValue1 = 0x0a0a0a0a; | |
| 4191 const SpdySettingsIds kSampleId2 = SETTINGS_DOWNLOAD_BANDWIDTH; | |
| 4192 unsigned int kSampleValue2 = 0x0b0b0b0b; | |
| 4193 const SpdySettingsIds kSampleId3 = SETTINGS_ROUND_TRIP_TIME; | |
| 4194 unsigned int kSampleValue3 = 0x0c0c0c0c; | |
| 4195 std::unique_ptr<SpdySerializedFrame> settings_frame; | |
| 4196 { | |
| 4197 // Construct the SETTINGS frame. | |
| 4198 SettingsMap settings; | |
| 4199 // First add a persisted setting. | |
| 4200 settings[kSampleId1] = | |
| 4201 SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue1); | |
| 4202 // Next add a non-persisted setting. | |
| 4203 settings[kSampleId2] = | |
| 4204 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kSampleValue2); | |
| 4205 // Next add another persisted setting. | |
| 4206 settings[kSampleId3] = | |
| 4207 SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue3); | |
| 4208 settings_frame.reset(spdy_util_.ConstructSpdySettings(settings)); | |
| 4209 } | |
| 4210 | |
| 4211 std::unique_ptr<SpdySerializedFrame> body( | |
| 4212 spdy_util_.ConstructSpdyBodyFrame(1, true)); | |
| 4213 MockRead reads[] = { | |
| 4214 CreateMockRead(*reply, 1), | |
| 4215 CreateMockRead(*body, 2), | |
| 4216 CreateMockRead(*settings_frame, 3), | |
| 4217 MockRead(ASYNC, 0, 4) // EOF | |
| 4218 }; | |
| 4219 | |
| 4220 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | |
| 4221 helper.AddData(&data); | |
| 4222 helper.RunDefaultTest(); | |
| 4223 helper.VerifyDataConsumed(); | |
| 4224 TransactionHelperResult out = helper.output(); | |
| 4225 EXPECT_THAT(out.rv, IsOk()); | |
| 4226 EXPECT_EQ("HTTP/1.1 200", out.status_line); | |
| 4227 EXPECT_EQ("hello!", out.response_data); | |
| 4228 | |
| 4229 { | |
| 4230 // Verify we had two persisted settings. | |
| 4231 const SettingsMap& settings_map = | |
| 4232 spdy_session_pool->http_server_properties()->GetSpdySettings( | |
| 4233 spdy_server); | |
| 4234 ASSERT_EQ(2u, settings_map.size()); | |
| 4235 | |
| 4236 // Verify the first persisted setting. | |
| 4237 SettingsMap::const_iterator it1 = settings_map.find(kSampleId1); | |
| 4238 EXPECT_TRUE(it1 != settings_map.end()); | |
| 4239 SettingsFlagsAndValue flags_and_value1 = it1->second; | |
| 4240 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1.first); | |
| 4241 EXPECT_EQ(kSampleValue1, flags_and_value1.second); | |
| 4242 | |
| 4243 // Verify the second persisted setting. | |
| 4244 SettingsMap::const_iterator it3 = settings_map.find(kSampleId3); | |
| 4245 EXPECT_TRUE(it3 != settings_map.end()); | |
| 4246 SettingsFlagsAndValue flags_and_value3 = it3->second; | |
| 4247 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value3.first); | |
| 4248 EXPECT_EQ(kSampleValue3, flags_and_value3.second); | |
| 4249 } | |
| 4250 } | |
| 4251 | |
| 4252 // Test that when there are settings saved that they are sent back to the | |
| 4253 // server upon session establishment. | |
| 4254 TEST_P(SpdyNetworkTransactionTest, SettingsPlayback) { | |
| 4255 if (spdy_util_.spdy_version() >= HTTP2) { | |
| 4256 // HTTP/2 doesn't support settings persistence. | |
| 4257 return; | |
| 4258 } | |
| 4259 static const SpdyHeaderInfo kSynReplyInfo = { | |
| 4260 SYN_REPLY, // Syn Reply | |
| 4261 1, // Stream ID | |
| 4262 0, // Associated Stream ID | |
| 4263 ConvertRequestPriorityToSpdyPriority(LOWEST, spdy_util_.spdy_version()), | |
| 4264 0, // Weight (unused) | |
| 4265 CONTROL_FLAG_NONE, // Control Flags | |
| 4266 RST_STREAM_INVALID, // Status | |
| 4267 NULL, // Data | |
| 4268 0, // Data Length | |
| 4269 DATA_FLAG_NONE // Data Flags | |
| 4270 }; | |
| 4271 | |
| 4272 BoundNetLog net_log; | |
| 4273 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | |
| 4274 net_log, GetParam(), NULL); | |
| 4275 helper.RunPreTestSetup(); | |
| 4276 | |
| 4277 SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); | |
| 4278 | |
| 4279 SpdySessionPoolPeer pool_peer(spdy_session_pool); | |
| 4280 pool_peer.SetEnableSendingInitialData(true); | |
| 4281 | |
| 4282 // Verify that no settings exist initially. | |
| 4283 url::SchemeHostPort spdy_server(default_url_); | |
| 4284 EXPECT_TRUE(spdy_session_pool->http_server_properties() | |
| 4285 ->GetSpdySettings(spdy_server) | |
| 4286 .empty()); | |
| 4287 | |
| 4288 const SpdySettingsIds kSampleId1 = SETTINGS_MAX_CONCURRENT_STREAMS; | |
| 4289 unsigned int kSampleValue1 = 0x0a0a0a0a; | |
| 4290 const SpdySettingsIds kSampleId2 = SETTINGS_INITIAL_WINDOW_SIZE; | |
| 4291 unsigned int kSampleValue2 = 0x0c0c0c0c; | |
| 4292 | |
| 4293 // First add a persisted setting. | |
| 4294 spdy_session_pool->http_server_properties()->SetSpdySetting( | |
| 4295 spdy_server, kSampleId1, SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue1); | |
| 4296 | |
| 4297 // Next add another persisted setting. | |
| 4298 spdy_session_pool->http_server_properties()->SetSpdySetting( | |
| 4299 spdy_server, kSampleId2, SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue2); | |
| 4300 | |
| 4301 EXPECT_EQ(2u, spdy_session_pool->http_server_properties() | |
| 4302 ->GetSpdySettings(spdy_server) | |
| 4303 .size()); | |
| 4304 | |
| 4305 // Construct the initial SETTINGS frame. | |
| 4306 SettingsMap initial_settings; | |
| 4307 initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] = | |
| 4308 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); | |
| 4309 std::unique_ptr<SpdySerializedFrame> initial_settings_frame( | |
| 4310 spdy_util_.ConstructSpdySettings(initial_settings)); | |
| 4311 | |
| 4312 // Construct the persisted SETTINGS frame. | |
| 4313 const SettingsMap& settings = | |
| 4314 spdy_session_pool->http_server_properties()->GetSpdySettings(spdy_server); | |
| 4315 std::unique_ptr<SpdySerializedFrame> settings_frame( | |
| 4316 spdy_util_.ConstructSpdySettings(settings)); | |
| 4317 | |
| 4318 // Construct the request. | |
| 4319 std::unique_ptr<SpdySerializedFrame> req( | |
| 4320 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | |
| 4321 | |
| 4322 MockWrite writes[] = { | |
| 4323 CreateMockWrite(*initial_settings_frame, 0), | |
| 4324 CreateMockWrite(*settings_frame, 1), | |
| 4325 CreateMockWrite(*req, 2), | |
| 4326 }; | |
| 4327 | |
| 4328 // Construct the reply. | |
| 4329 SpdyHeaderBlock reply_headers; | |
| 4330 reply_headers[spdy_util_.GetStatusKey()] = "200"; | |
| 4331 reply_headers[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | |
| 4332 std::unique_ptr<SpdySerializedFrame> reply( | |
| 4333 spdy_util_.ConstructSpdyFrame(kSynReplyInfo, std::move(reply_headers))); | |
| 4334 | |
| 4335 std::unique_ptr<SpdySerializedFrame> body( | |
| 4336 spdy_util_.ConstructSpdyBodyFrame(1, true)); | |
| 4337 MockRead reads[] = { | |
| 4338 CreateMockRead(*reply, 3), | |
| 4339 CreateMockRead(*body, 4), | |
| 4340 MockRead(ASYNC, 0, 5) // EOF | |
| 4341 }; | |
| 4342 | |
| 4343 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | |
| 4344 helper.AddData(&data); | |
| 4345 helper.RunDefaultTest(); | |
| 4346 helper.VerifyDataConsumed(); | |
| 4347 TransactionHelperResult out = helper.output(); | |
| 4348 EXPECT_THAT(out.rv, IsOk()); | |
| 4349 EXPECT_EQ("HTTP/1.1 200", out.status_line); | |
| 4350 EXPECT_EQ("hello!", out.response_data); | |
| 4351 | |
| 4352 { | |
| 4353 // Verify we had two persisted settings. | |
| 4354 const SettingsMap& settings_map = | |
| 4355 spdy_session_pool->http_server_properties()->GetSpdySettings( | |
| 4356 spdy_server); | |
| 4357 ASSERT_EQ(2u, settings_map.size()); | |
| 4358 | |
| 4359 // Verify the first persisted setting. | |
| 4360 SettingsMap::const_iterator it1 = settings_map.find(kSampleId1); | |
| 4361 EXPECT_TRUE(it1 != settings_map.end()); | |
| 4362 SettingsFlagsAndValue flags_and_value1 = it1->second; | |
| 4363 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1.first); | |
| 4364 EXPECT_EQ(kSampleValue1, flags_and_value1.second); | |
| 4365 | |
| 4366 // Verify the second persisted setting. | |
| 4367 SettingsMap::const_iterator it2 = settings_map.find(kSampleId2); | |
| 4368 EXPECT_TRUE(it2 != settings_map.end()); | |
| 4369 SettingsFlagsAndValue flags_and_value2 = it2->second; | |
| 4370 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value2.first); | |
| 4371 EXPECT_EQ(kSampleValue2, flags_and_value2.second); | |
| 4372 } | |
| 4373 } | |
| 4374 | |
| 4375 TEST_P(SpdyNetworkTransactionTest, GoAwayWithActiveStream) { | 4020 TEST_P(SpdyNetworkTransactionTest, GoAwayWithActiveStream) { |
| 4376 std::unique_ptr<SpdySerializedFrame> req( | 4021 std::unique_ptr<SpdySerializedFrame> req( |
| 4377 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 4022 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 4378 MockWrite writes[] = {CreateMockWrite(*req, 0)}; | 4023 MockWrite writes[] = {CreateMockWrite(*req, 0)}; |
| 4379 | 4024 |
| 4380 std::unique_ptr<SpdySerializedFrame> go_away( | 4025 std::unique_ptr<SpdySerializedFrame> go_away( |
| 4381 spdy_util_.ConstructSpdyGoAway()); | 4026 spdy_util_.ConstructSpdyGoAway()); |
| 4382 MockRead reads[] = { | 4027 MockRead reads[] = { |
| 4383 CreateMockRead(*go_away, 1), | 4028 CreateMockRead(*go_away, 1), |
| 4384 }; | 4029 }; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4424 EXPECT_TRUE(response->was_fetched_via_spdy); | 4069 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4425 out.rv = ReadTransaction(trans, &out.response_data); | 4070 out.rv = ReadTransaction(trans, &out.response_data); |
| 4426 EXPECT_THAT(out.rv, IsError(ERR_CONNECTION_CLOSED)); | 4071 EXPECT_THAT(out.rv, IsError(ERR_CONNECTION_CLOSED)); |
| 4427 | 4072 |
| 4428 // Verify that we consumed all test data. | 4073 // Verify that we consumed all test data. |
| 4429 helper.VerifyDataConsumed(); | 4074 helper.VerifyDataConsumed(); |
| 4430 } | 4075 } |
| 4431 | 4076 |
| 4432 // HTTP_1_1_REQUIRED results in ERR_HTTP_1_1_REQUIRED. | 4077 // HTTP_1_1_REQUIRED results in ERR_HTTP_1_1_REQUIRED. |
| 4433 TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredError) { | 4078 TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredError) { |
| 4434 // HTTP_1_1_REQUIRED is only supported by HTTP/2. | |
| 4435 if (spdy_util_.spdy_version() < HTTP2) | |
| 4436 return; | |
| 4437 | |
| 4438 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 4079 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, |
| 4439 BoundNetLog(), GetParam(), nullptr); | 4080 BoundNetLog(), GetParam(), nullptr); |
| 4440 | 4081 |
| 4441 std::unique_ptr<SpdySerializedFrame> go_away(spdy_util_.ConstructSpdyGoAway( | 4082 std::unique_ptr<SpdySerializedFrame> go_away(spdy_util_.ConstructSpdyGoAway( |
| 4442 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); | 4083 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); |
| 4443 MockRead reads[] = { | 4084 MockRead reads[] = { |
| 4444 CreateMockRead(*go_away, 0), | 4085 CreateMockRead(*go_away, 0), |
| 4445 }; | 4086 }; |
| 4446 SequencedSocketData data(reads, arraysize(reads), nullptr, 0); | 4087 SequencedSocketData data(reads, arraysize(reads), nullptr, 0); |
| 4447 | 4088 |
| 4448 helper.RunToCompletion(&data); | 4089 helper.RunToCompletion(&data); |
| 4449 TransactionHelperResult out = helper.output(); | 4090 TransactionHelperResult out = helper.output(); |
| 4450 EXPECT_THAT(out.rv, IsError(ERR_HTTP_1_1_REQUIRED)); | 4091 EXPECT_THAT(out.rv, IsError(ERR_HTTP_1_1_REQUIRED)); |
| 4451 } | 4092 } |
| 4452 | 4093 |
| 4453 // Retry with HTTP/1.1 when receiving HTTP_1_1_REQUIRED. Note that no actual | 4094 // Retry with HTTP/1.1 when receiving HTTP_1_1_REQUIRED. Note that no actual |
| 4454 // protocol negotiation happens, instead this test forces protocols for both | 4095 // protocol negotiation happens, instead this test forces protocols for both |
| 4455 // sockets. | 4096 // sockets. |
| 4456 TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredRetry) { | 4097 TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredRetry) { |
| 4457 // HTTP_1_1_REQUIRED is only supported by HTTP/2. | |
| 4458 if (spdy_util_.spdy_version() < HTTP2) | |
| 4459 return; | |
| 4460 | |
| 4461 HttpRequestInfo request; | 4098 HttpRequestInfo request; |
| 4462 request.method = "GET"; | 4099 request.method = "GET"; |
| 4463 request.url = default_url_; | 4100 request.url = default_url_; |
| 4464 std::unique_ptr<SpdySessionDependencies> session_deps( | 4101 std::unique_ptr<SpdySessionDependencies> session_deps( |
| 4465 CreateSpdySessionDependencies(GetParam())); | 4102 CreateSpdySessionDependencies(GetParam())); |
| 4466 // Do not force SPDY so that second socket can negotiate HTTP/1.1. | 4103 // Do not force SPDY so that second socket can negotiate HTTP/1.1. |
| 4467 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), | 4104 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 4468 GetParam(), std::move(session_deps)); | 4105 GetParam(), std::move(session_deps)); |
| 4469 | 4106 |
| 4470 // First socket: HTTP/2 request rejected with HTTP_1_1_REQUIRED. | 4107 // First socket: HTTP/2 request rejected with HTTP_1_1_REQUIRED. |
| 4471 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); | 4108 SpdyHeaderBlock headers(spdy_util_.ConstructGetHeaderBlock(kDefaultUrl)); |
| 4472 std::unique_ptr<SpdySerializedFrame> req( | 4109 std::unique_ptr<SpdySerializedFrame> req( |
| 4473 spdy_util_.ConstructSpdySyn(1, std::move(headers), LOWEST, true)); | 4110 spdy_util_.ConstructSpdySyn(1, std::move(headers), LOWEST, true)); |
| 4474 MockWrite writes0[] = {CreateMockWrite(*req, 0)}; | 4111 MockWrite writes0[] = {CreateMockWrite(*req, 0)}; |
| 4475 std::unique_ptr<SpdySerializedFrame> go_away(spdy_util_.ConstructSpdyGoAway( | 4112 std::unique_ptr<SpdySerializedFrame> go_away(spdy_util_.ConstructSpdyGoAway( |
| 4476 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); | 4113 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); |
| 4477 MockRead reads0[] = {CreateMockRead(*go_away, 1)}; | 4114 MockRead reads0[] = {CreateMockRead(*go_away, 1)}; |
| 4478 SequencedSocketData data0(reads0, arraysize(reads0), writes0, | 4115 SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 4479 arraysize(writes0)); | 4116 arraysize(writes0)); |
| 4480 | 4117 |
| 4481 std::unique_ptr<SSLSocketDataProvider> ssl_provider0( | 4118 std::unique_ptr<SSLSocketDataProvider> ssl_provider0( |
| 4482 new SSLSocketDataProvider(ASYNC, OK)); | 4119 new SSLSocketDataProvider(ASYNC, OK)); |
| 4483 // Expect HTTP/2 protocols too in SSLConfig. | 4120 // Expect HTTP/2 protocols too in SSLConfig. |
| 4484 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP2); | 4121 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP2); |
| 4485 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); | 4122 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4486 // Force SPDY. | 4123 // Force SPDY. |
| 4487 ssl_provider0->SetNextProto(GetParam().protocol); | 4124 ssl_provider0->SetNextProto(kProtoHTTP2); |
| 4488 helper.AddDataWithSSLSocketDataProvider(&data0, std::move(ssl_provider0)); | 4125 helper.AddDataWithSSLSocketDataProvider(&data0, std::move(ssl_provider0)); |
| 4489 | 4126 |
| 4490 // Second socket: falling back to HTTP/1.1. | 4127 // Second socket: falling back to HTTP/1.1. |
| 4491 MockWrite writes1[] = {MockWrite(ASYNC, 0, | 4128 MockWrite writes1[] = {MockWrite(ASYNC, 0, |
| 4492 "GET / HTTP/1.1\r\n" | 4129 "GET / HTTP/1.1\r\n" |
| 4493 "Host: www.example.org\r\n" | 4130 "Host: www.example.org\r\n" |
| 4494 "Connection: keep-alive\r\n\r\n")}; | 4131 "Connection: keep-alive\r\n\r\n")}; |
| 4495 MockRead reads1[] = {MockRead(ASYNC, 1, | 4132 MockRead reads1[] = {MockRead(ASYNC, 1, |
| 4496 "HTTP/1.1 200 OK\r\n" | 4133 "HTTP/1.1 200 OK\r\n" |
| 4497 "Content-Length: 5\r\n\r\n" | 4134 "Content-Length: 5\r\n\r\n" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4529 EXPECT_EQ(443, response->socket_address.port()); | 4166 EXPECT_EQ(443, response->socket_address.port()); |
| 4530 std::string response_data; | 4167 std::string response_data; |
| 4531 ASSERT_THAT(ReadTransaction(helper.trans(), &response_data), IsOk()); | 4168 ASSERT_THAT(ReadTransaction(helper.trans(), &response_data), IsOk()); |
| 4532 EXPECT_EQ("hello", response_data); | 4169 EXPECT_EQ("hello", response_data); |
| 4533 } | 4170 } |
| 4534 | 4171 |
| 4535 // Retry with HTTP/1.1 to the proxy when receiving HTTP_1_1_REQUIRED from the | 4172 // Retry with HTTP/1.1 to the proxy when receiving HTTP_1_1_REQUIRED from the |
| 4536 // proxy. Note that no actual protocol negotiation happens, instead this test | 4173 // proxy. Note that no actual protocol negotiation happens, instead this test |
| 4537 // forces protocols for both sockets. | 4174 // forces protocols for both sockets. |
| 4538 TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredProxyRetry) { | 4175 TEST_P(SpdyNetworkTransactionTest, HTTP11RequiredProxyRetry) { |
| 4539 // HTTP_1_1_REQUIRED is only supported by HTTP/2. | |
| 4540 if (spdy_util_.spdy_version() < HTTP2) | |
| 4541 return; | |
| 4542 | |
| 4543 HttpRequestInfo request; | 4176 HttpRequestInfo request; |
| 4544 request.method = "GET"; | 4177 request.method = "GET"; |
| 4545 request.url = default_url_; | 4178 request.url = default_url_; |
| 4546 std::unique_ptr<SpdySessionDependencies> session_deps( | 4179 std::unique_ptr<SpdySessionDependencies> session_deps( |
| 4547 CreateSpdySessionDependencies( | 4180 CreateSpdySessionDependencies( |
| 4548 GetParam(), | 4181 GetParam(), |
| 4549 ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"))); | 4182 ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"))); |
| 4550 // Do not force SPDY so that second socket can negotiate HTTP/1.1. | 4183 // Do not force SPDY so that second socket can negotiate HTTP/1.1. |
| 4551 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), | 4184 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, BoundNetLog(), |
| 4552 GetParam(), std::move(session_deps)); | 4185 GetParam(), std::move(session_deps)); |
| 4553 | 4186 |
| 4554 // First socket: HTTP/2 CONNECT rejected with HTTP_1_1_REQUIRED. | 4187 // First socket: HTTP/2 CONNECT rejected with HTTP_1_1_REQUIRED. |
| 4555 std::unique_ptr<SpdySerializedFrame> req(spdy_util_.ConstructSpdyConnect( | 4188 std::unique_ptr<SpdySerializedFrame> req(spdy_util_.ConstructSpdyConnect( |
| 4556 nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); | 4189 nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4557 MockWrite writes0[] = {CreateMockWrite(*req, 0)}; | 4190 MockWrite writes0[] = {CreateMockWrite(*req, 0)}; |
| 4558 std::unique_ptr<SpdySerializedFrame> go_away(spdy_util_.ConstructSpdyGoAway( | 4191 std::unique_ptr<SpdySerializedFrame> go_away(spdy_util_.ConstructSpdyGoAway( |
| 4559 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); | 4192 0, GOAWAY_HTTP_1_1_REQUIRED, "Try again using HTTP/1.1 please.")); |
| 4560 MockRead reads0[] = {CreateMockRead(*go_away, 1)}; | 4193 MockRead reads0[] = {CreateMockRead(*go_away, 1)}; |
| 4561 SequencedSocketData data0(reads0, arraysize(reads0), writes0, | 4194 SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 4562 arraysize(writes0)); | 4195 arraysize(writes0)); |
| 4563 | 4196 |
| 4564 std::unique_ptr<SSLSocketDataProvider> ssl_provider0( | 4197 std::unique_ptr<SSLSocketDataProvider> ssl_provider0( |
| 4565 new SSLSocketDataProvider(ASYNC, OK)); | 4198 new SSLSocketDataProvider(ASYNC, OK)); |
| 4566 // Expect HTTP/2 protocols too in SSLConfig. | 4199 // Expect HTTP/2 protocols too in SSLConfig. |
| 4567 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP2); | 4200 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP2); |
| 4568 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); | 4201 ssl_provider0->next_protos_expected_in_ssl_config.push_back(kProtoHTTP11); |
| 4569 // Force SPDY. | 4202 // Force SPDY. |
| 4570 ssl_provider0->SetNextProto(GetParam().protocol); | 4203 ssl_provider0->SetNextProto(kProtoHTTP2); |
| 4571 helper.AddDataWithSSLSocketDataProvider(&data0, std::move(ssl_provider0)); | 4204 helper.AddDataWithSSLSocketDataProvider(&data0, std::move(ssl_provider0)); |
| 4572 | 4205 |
| 4573 // Second socket: retry using HTTP/1.1. | 4206 // Second socket: retry using HTTP/1.1. |
| 4574 MockWrite writes1[] = { | 4207 MockWrite writes1[] = { |
| 4575 MockWrite(ASYNC, 0, | 4208 MockWrite(ASYNC, 0, |
| 4576 "CONNECT www.example.org:443 HTTP/1.1\r\n" | 4209 "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4577 "Host: www.example.org:443\r\n" | 4210 "Host: www.example.org:443\r\n" |
| 4578 "Proxy-Connection: keep-alive\r\n\r\n"), | 4211 "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4579 MockWrite(ASYNC, 2, | 4212 MockWrite(ASYNC, 2, |
| 4580 "GET / HTTP/1.1\r\n" | 4213 "GET / HTTP/1.1\r\n" |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4754 PRIVACY_MODE_DISABLED); | 4387 PRIVACY_MODE_DISABLED); |
| 4755 EXPECT_TRUE(HasSpdySession(spdy_session_pool, session_pool_key_direct)); | 4388 EXPECT_TRUE(HasSpdySession(spdy_session_pool, session_pool_key_direct)); |
| 4756 SpdySessionKey session_pool_key_proxy( | 4389 SpdySessionKey session_pool_key_proxy( |
| 4757 host_port_pair_, | 4390 host_port_pair_, |
| 4758 ProxyServer::FromURI("www.foo.com", ProxyServer::SCHEME_HTTP), | 4391 ProxyServer::FromURI("www.foo.com", ProxyServer::SCHEME_HTTP), |
| 4759 PRIVACY_MODE_DISABLED); | 4392 PRIVACY_MODE_DISABLED); |
| 4760 EXPECT_FALSE(HasSpdySession(spdy_session_pool, session_pool_key_proxy)); | 4393 EXPECT_FALSE(HasSpdySession(spdy_session_pool, session_pool_key_proxy)); |
| 4761 | 4394 |
| 4762 // New SpdyTestUtil instance for the session that will be used for the | 4395 // New SpdyTestUtil instance for the session that will be used for the |
| 4763 // proxy connection. | 4396 // proxy connection. |
| 4764 SpdyTestUtil spdy_util_2(GetParam().protocol, | 4397 SpdyTestUtil spdy_util_2(GetParam()); |
| 4765 GetParam().priority_to_dependency); | |
| 4766 | 4398 |
| 4767 // Set up data for the proxy connection. | 4399 // Set up data for the proxy connection. |
| 4768 const char kConnect443[] = { | 4400 const char kConnect443[] = { |
| 4769 "CONNECT www.example.org:443 HTTP/1.1\r\n" | 4401 "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4770 "Host: www.example.org:443\r\n" | 4402 "Host: www.example.org:443\r\n" |
| 4771 "Proxy-Connection: keep-alive\r\n\r\n"}; | 4403 "Proxy-Connection: keep-alive\r\n\r\n"}; |
| 4772 const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; | 4404 const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; |
| 4773 std::unique_ptr<SpdySerializedFrame> req2(spdy_util_2.ConstructSpdyGet( | 4405 std::unique_ptr<SpdySerializedFrame> req2(spdy_util_2.ConstructSpdyGet( |
| 4774 GetDefaultUrlWithPath("/foo.dat").c_str(), 1, LOWEST)); | 4406 GetDefaultUrlWithPath("/foo.dat").c_str(), 1, LOWEST)); |
| 4775 std::unique_ptr<SpdySerializedFrame> resp2( | 4407 std::unique_ptr<SpdySerializedFrame> resp2( |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5083 | 4715 |
| 5084 SpdyHeaderBlock initial_headers; | 4716 SpdyHeaderBlock initial_headers; |
| 5085 spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), | 4717 spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
| 5086 &initial_headers); | 4718 &initial_headers); |
| 5087 std::unique_ptr<SpdySerializedFrame> stream2_syn( | 4719 std::unique_ptr<SpdySerializedFrame> stream2_syn( |
| 5088 spdy_util_.ConstructInitialSpdyPushFrame(std::move(initial_headers), 2, | 4720 spdy_util_.ConstructInitialSpdyPushFrame(std::move(initial_headers), 2, |
| 5089 1)); | 4721 1)); |
| 5090 | 4722 |
| 5091 SpdyHeaderBlock late_headers; | 4723 SpdyHeaderBlock late_headers; |
| 5092 late_headers[spdy_util_.GetStatusKey()] = "200"; | 4724 late_headers[spdy_util_.GetStatusKey()] = "200"; |
| 5093 late_headers[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | |
| 5094 late_headers["hello"] = "bye"; | 4725 late_headers["hello"] = "bye"; |
| 5095 std::unique_ptr<SpdySerializedFrame> stream2_headers( | 4726 std::unique_ptr<SpdySerializedFrame> stream2_headers( |
| 5096 spdy_util_.ConstructSpdyResponseHeaders(2, std::move(late_headers), | 4727 spdy_util_.ConstructSpdyResponseHeaders(2, std::move(late_headers), |
| 5097 false)); | 4728 false)); |
| 5098 | 4729 |
| 5099 std::unique_ptr<SpdySerializedFrame> stream1_body( | 4730 std::unique_ptr<SpdySerializedFrame> stream1_body( |
| 5100 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 4731 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 5101 | 4732 |
| 5102 const char kPushedData[] = "pushed"; | 4733 const char kPushedData[] = "pushed"; |
| 5103 std::unique_ptr<SpdySerializedFrame> stream2_body( | 4734 std::unique_ptr<SpdySerializedFrame> stream2_body( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5144 SpdyHeaderBlock initial_headers; | 4775 SpdyHeaderBlock initial_headers; |
| 5145 spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), | 4776 spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
| 5146 &initial_headers); | 4777 &initial_headers); |
| 5147 std::unique_ptr<SpdySerializedFrame> stream2_syn( | 4778 std::unique_ptr<SpdySerializedFrame> stream2_syn( |
| 5148 spdy_util_.ConstructInitialSpdyPushFrame(std::move(initial_headers), 2, | 4779 spdy_util_.ConstructInitialSpdyPushFrame(std::move(initial_headers), 2, |
| 5149 1)); | 4780 1)); |
| 5150 std::unique_ptr<SpdySerializedFrame> stream1_body( | 4781 std::unique_ptr<SpdySerializedFrame> stream1_body( |
| 5151 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 4782 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 5152 SpdyHeaderBlock late_headers; | 4783 SpdyHeaderBlock late_headers; |
| 5153 late_headers[spdy_util_.GetStatusKey()] = "200"; | 4784 late_headers[spdy_util_.GetStatusKey()] = "200"; |
| 5154 late_headers[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | |
| 5155 late_headers["hello"] = "bye"; | 4785 late_headers["hello"] = "bye"; |
| 5156 std::unique_ptr<SpdySerializedFrame> stream2_headers( | 4786 std::unique_ptr<SpdySerializedFrame> stream2_headers( |
| 5157 spdy_util_.ConstructSpdyResponseHeaders(2, std::move(late_headers), | 4787 spdy_util_.ConstructSpdyResponseHeaders(2, std::move(late_headers), |
| 5158 false)); | 4788 false)); |
| 5159 const char kPushedData[] = "pushed"; | 4789 const char kPushedData[] = "pushed"; |
| 5160 std::unique_ptr<SpdySerializedFrame> stream2_body( | 4790 std::unique_ptr<SpdySerializedFrame> stream2_body( |
| 5161 spdy_util_.ConstructSpdyBodyFrame(2, kPushedData, strlen(kPushedData), | 4791 spdy_util_.ConstructSpdyBodyFrame(2, kPushedData, strlen(kPushedData), |
| 5162 true)); | 4792 true)); |
| 5163 MockRead reads[] = { | 4793 MockRead reads[] = { |
| 5164 CreateMockRead(*stream1_reply, 1), CreateMockRead(*stream2_syn, 2), | 4794 CreateMockRead(*stream1_reply, 1), CreateMockRead(*stream2_syn, 2), |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5245 std::unique_ptr<SpdySerializedFrame> stream1_syn( | 4875 std::unique_ptr<SpdySerializedFrame> stream1_syn( |
| 5246 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 4876 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 5247 MockWrite writes[] = { | 4877 MockWrite writes[] = { |
| 5248 CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), | 4878 CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), |
| 5249 }; | 4879 }; |
| 5250 | 4880 |
| 5251 std::unique_ptr<SpdySerializedFrame> stream1_reply( | 4881 std::unique_ptr<SpdySerializedFrame> stream1_reply( |
| 5252 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); | 4882 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 5253 | 4883 |
| 5254 SpdyHeaderBlock initial_headers; | 4884 SpdyHeaderBlock initial_headers; |
| 5255 if (spdy_util_.spdy_version() < HTTP2) { | |
| 5256 // In HTTP/2 PUSH_PROMISE headers won't show up in the response headers. | |
| 5257 initial_headers["alpha"] = "beta"; | |
| 5258 } | |
| 5259 spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), | 4885 spdy_util_.AddUrlToHeaderBlock(GetDefaultUrlWithPath("/foo.dat"), |
| 5260 &initial_headers); | 4886 &initial_headers); |
| 5261 std::unique_ptr<SpdySerializedFrame> stream2_syn( | 4887 std::unique_ptr<SpdySerializedFrame> stream2_syn( |
| 5262 spdy_util_.ConstructInitialSpdyPushFrame(std::move(initial_headers), 2, | 4888 spdy_util_.ConstructInitialSpdyPushFrame(std::move(initial_headers), 2, |
| 5263 1)); | 4889 1)); |
| 5264 | 4890 |
| 5265 std::unique_ptr<SpdySerializedFrame> stream1_body( | 4891 std::unique_ptr<SpdySerializedFrame> stream1_body( |
| 5266 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 4892 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 5267 | 4893 |
| 5268 SpdyHeaderBlock middle_headers; | 4894 SpdyHeaderBlock middle_headers; |
| 5269 middle_headers["hello"] = "bye"; | 4895 middle_headers["hello"] = "bye"; |
| 5270 std::unique_ptr<SpdySerializedFrame> stream2_headers1( | 4896 std::unique_ptr<SpdySerializedFrame> stream2_headers1( |
| 5271 spdy_util_.ConstructSpdyResponseHeaders(2, std::move(middle_headers), | 4897 spdy_util_.ConstructSpdyResponseHeaders(2, std::move(middle_headers), |
| 5272 false)); | 4898 false)); |
| 5273 | 4899 |
| 5274 SpdyHeaderBlock late_headers; | 4900 SpdyHeaderBlock late_headers; |
| 5275 late_headers[spdy_util_.GetStatusKey()] = "200"; | 4901 late_headers[spdy_util_.GetStatusKey()] = "200"; |
| 5276 if (spdy_util_.spdy_version() < HTTP2) { | |
| 5277 // HTTP/2 eliminates use of the :version header. | |
| 5278 late_headers[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | |
| 5279 } | |
| 5280 std::unique_ptr<SpdySerializedFrame> stream2_headers2( | 4902 std::unique_ptr<SpdySerializedFrame> stream2_headers2( |
| 5281 spdy_util_.ConstructSpdyResponseHeaders(2, std::move(late_headers), | 4903 spdy_util_.ConstructSpdyResponseHeaders(2, std::move(late_headers), |
| 5282 false)); | 4904 false)); |
| 5283 | 4905 |
| 5284 const char kPushedData[] = "pushed"; | 4906 const char kPushedData[] = "pushed"; |
| 5285 std::unique_ptr<SpdySerializedFrame> stream2_body( | 4907 std::unique_ptr<SpdySerializedFrame> stream2_body( |
| 5286 spdy_util_.ConstructSpdyBodyFrame(2, kPushedData, strlen(kPushedData), | 4908 spdy_util_.ConstructSpdyBodyFrame(2, kPushedData, strlen(kPushedData), |
| 5287 true)); | 4909 true)); |
| 5288 | 4910 |
| 5289 MockRead reads[] = { | 4911 MockRead reads[] = { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5353 | 4975 |
| 5354 // Verify the SYN_REPLY. | 4976 // Verify the SYN_REPLY. |
| 5355 EXPECT_TRUE(response.headers); | 4977 EXPECT_TRUE(response.headers); |
| 5356 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); | 4978 EXPECT_EQ("HTTP/1.1 200", response.headers->GetStatusLine()); |
| 5357 | 4979 |
| 5358 // Verify the pushed stream. | 4980 // Verify the pushed stream. |
| 5359 EXPECT_TRUE(response2.headers); | 4981 EXPECT_TRUE(response2.headers); |
| 5360 EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); | 4982 EXPECT_EQ("HTTP/1.1 200", response2.headers->GetStatusLine()); |
| 5361 | 4983 |
| 5362 // Verify we got all the headers from all header blocks. | 4984 // Verify we got all the headers from all header blocks. |
| 5363 if (spdy_util_.spdy_version() < HTTP2) | |
| 5364 EXPECT_TRUE(response2.headers->HasHeaderValue("alpha", "beta")); | |
| 5365 EXPECT_TRUE(response2.headers->HasHeaderValue("hello", "bye")); | 4985 EXPECT_TRUE(response2.headers->HasHeaderValue("hello", "bye")); |
| 5366 EXPECT_TRUE(response2.headers->HasHeaderValue("status", "200")); | 4986 EXPECT_TRUE(response2.headers->HasHeaderValue("status", "200")); |
| 5367 | 4987 |
| 5368 // Read the final EOF (which will close the session) | 4988 // Read the final EOF (which will close the session) |
| 5369 data.Resume(); | 4989 data.Resume(); |
| 5370 base::RunLoop().RunUntilIdle(); | 4990 base::RunLoop().RunUntilIdle(); |
| 5371 | 4991 |
| 5372 // Verify that we consumed all test data. | 4992 // Verify that we consumed all test data. |
| 5373 EXPECT_TRUE(data.AllReadDataConsumed()); | 4993 EXPECT_TRUE(data.AllReadDataConsumed()); |
| 5374 EXPECT_TRUE(data.AllWriteDataConsumed()); | 4994 EXPECT_TRUE(data.AllWriteDataConsumed()); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5565 "https://blat.www.example.org/foo.js", // Cross subdomain | 5185 "https://blat.www.example.org/foo.js", // Cross subdomain |
| 5566 | 5186 |
| 5567 "https://www.example.org/foo.html", | 5187 "https://www.example.org/foo.html", |
| 5568 "https://www.foo.com/foo.js", // Cross domain | 5188 "https://www.foo.com/foo.js", // Cross domain |
| 5569 }; | 5189 }; |
| 5570 | 5190 |
| 5571 for (size_t index = 0; index < arraysize(kTestCases); index += 2) { | 5191 for (size_t index = 0; index < arraysize(kTestCases); index += 2) { |
| 5572 const char* url_to_fetch = kTestCases[index]; | 5192 const char* url_to_fetch = kTestCases[index]; |
| 5573 const char* url_to_push = kTestCases[index + 1]; | 5193 const char* url_to_push = kTestCases[index + 1]; |
| 5574 | 5194 |
| 5575 SpdyTestUtil spdy_test_util(GetParam().protocol, | 5195 SpdyTestUtil spdy_test_util(GetParam()); |
| 5576 GetParam().priority_to_dependency); | |
| 5577 std::unique_ptr<SpdySerializedFrame> stream1_syn( | 5196 std::unique_ptr<SpdySerializedFrame> stream1_syn( |
| 5578 spdy_test_util.ConstructSpdyGet(url_to_fetch, 1, LOWEST)); | 5197 spdy_test_util.ConstructSpdyGet(url_to_fetch, 1, LOWEST)); |
| 5579 std::unique_ptr<SpdySerializedFrame> stream1_body( | 5198 std::unique_ptr<SpdySerializedFrame> stream1_body( |
| 5580 spdy_test_util.ConstructSpdyBodyFrame(1, true)); | 5199 spdy_test_util.ConstructSpdyBodyFrame(1, true)); |
| 5581 std::unique_ptr<SpdySerializedFrame> push_rst( | 5200 std::unique_ptr<SpdySerializedFrame> push_rst( |
| 5582 spdy_test_util.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); | 5201 spdy_test_util.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
| 5583 MockWrite writes[] = { | 5202 MockWrite writes[] = { |
| 5584 CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*push_rst, 3), | 5203 CreateMockWrite(*stream1_syn, 0), CreateMockWrite(*push_rst, 3), |
| 5585 }; | 5204 }; |
| 5586 | 5205 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5749 EXPECT_EQ(kPushedData, result1); | 5368 EXPECT_EQ(kPushedData, result1); |
| 5750 } | 5369 } |
| 5751 | 5370 |
| 5752 // Verify that push works cross origin, even if there is already a connection | 5371 // Verify that push works cross origin, even if there is already a connection |
| 5753 // open to origin of pushed resource. | 5372 // open to origin of pushed resource. |
| 5754 TEST_P(SpdyNetworkTransactionTest, ServerPushValidCrossOriginWithOpenSession) { | 5373 TEST_P(SpdyNetworkTransactionTest, ServerPushValidCrossOriginWithOpenSession) { |
| 5755 const char* url_to_fetch0 = "https://mail.example.org/foo"; | 5374 const char* url_to_fetch0 = "https://mail.example.org/foo"; |
| 5756 const char* url_to_fetch1 = "https://docs.example.org"; | 5375 const char* url_to_fetch1 = "https://docs.example.org"; |
| 5757 const char* url_to_push = "https://mail.example.org/bar"; | 5376 const char* url_to_push = "https://mail.example.org/bar"; |
| 5758 | 5377 |
| 5759 SpdyTestUtil spdy_util_0(GetParam().protocol, | 5378 SpdyTestUtil spdy_util_0(GetParam()); |
| 5760 GetParam().priority_to_dependency); | |
| 5761 | 5379 |
| 5762 std::unique_ptr<SpdySerializedFrame> headers0( | 5380 std::unique_ptr<SpdySerializedFrame> headers0( |
| 5763 spdy_util_0.ConstructSpdyGet(url_to_fetch0, 1, LOWEST)); | 5381 spdy_util_0.ConstructSpdyGet(url_to_fetch0, 1, LOWEST)); |
| 5764 MockWrite writes0[] = { | 5382 MockWrite writes0[] = { |
| 5765 CreateMockWrite(*headers0, 0), | 5383 CreateMockWrite(*headers0, 0), |
| 5766 }; | 5384 }; |
| 5767 | 5385 |
| 5768 std::unique_ptr<SpdySerializedFrame> reply0( | 5386 std::unique_ptr<SpdySerializedFrame> reply0( |
| 5769 spdy_util_0.ConstructSpdyGetSynReply(nullptr, 0, 1)); | 5387 spdy_util_0.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 5770 const char kData0[] = "first"; | 5388 const char kData0[] = "first"; |
| 5771 std::unique_ptr<SpdySerializedFrame> body0( | 5389 std::unique_ptr<SpdySerializedFrame> body0( |
| 5772 spdy_util_0.ConstructSpdyBodyFrame(1, kData0, strlen(kData0), true)); | 5390 spdy_util_0.ConstructSpdyBodyFrame(1, kData0, strlen(kData0), true)); |
| 5773 MockRead reads0[] = { | 5391 MockRead reads0[] = { |
| 5774 CreateMockRead(*reply0, 1), | 5392 CreateMockRead(*reply0, 1), |
| 5775 CreateMockRead(*body0, 2), | 5393 CreateMockRead(*body0, 2), |
| 5776 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3) | 5394 MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3) |
| 5777 }; | 5395 }; |
| 5778 | 5396 |
| 5779 SequencedSocketData data0(reads0, arraysize(reads0), writes0, | 5397 SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 5780 arraysize(writes0)); | 5398 arraysize(writes0)); |
| 5781 | 5399 |
| 5782 SpdyTestUtil spdy_util_1(GetParam().protocol, | 5400 SpdyTestUtil spdy_util_1(GetParam()); |
| 5783 GetParam().priority_to_dependency); | |
| 5784 | 5401 |
| 5785 std::unique_ptr<SpdySerializedFrame> headers1( | 5402 std::unique_ptr<SpdySerializedFrame> headers1( |
| 5786 spdy_util_1.ConstructSpdyGet(url_to_fetch1, 1, LOWEST)); | 5403 spdy_util_1.ConstructSpdyGet(url_to_fetch1, 1, LOWEST)); |
| 5787 MockWrite writes1[] = { | 5404 MockWrite writes1[] = { |
| 5788 CreateMockWrite(*headers1, 0), | 5405 CreateMockWrite(*headers1, 0), |
| 5789 }; | 5406 }; |
| 5790 | 5407 |
| 5791 std::unique_ptr<SpdySerializedFrame> reply1( | 5408 std::unique_ptr<SpdySerializedFrame> reply1( |
| 5792 spdy_util_1.ConstructSpdyGetSynReply(nullptr, 0, 1)); | 5409 spdy_util_1.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 5793 std::unique_ptr<SpdySerializedFrame> push( | 5410 std::unique_ptr<SpdySerializedFrame> push( |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6210 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); | 5827 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6211 | 5828 |
| 6212 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 5829 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6213 | 5830 |
| 6214 data.RunUntilPaused(); | 5831 data.RunUntilPaused(); |
| 6215 base::RunLoop().RunUntilIdle(); | 5832 base::RunLoop().RunUntilIdle(); |
| 6216 | 5833 |
| 6217 SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); | 5834 SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6218 ASSERT_TRUE(stream); | 5835 ASSERT_TRUE(stream); |
| 6219 ASSERT_TRUE(stream->stream()); | 5836 ASSERT_TRUE(stream->stream()); |
| 6220 EXPECT_EQ(static_cast<int>( | 5837 EXPECT_EQ( |
| 6221 SpdySession::GetDefaultInitialWindowSize(GetParam().protocol)) + | 5838 static_cast<int>(SpdySession::GetDefaultInitialWindowSize(kProtoHTTP2)) + |
| 6222 kDeltaWindowSize * kDeltaCount - | 5839 kDeltaWindowSize * kDeltaCount - kMaxSpdyFrameChunkSize * kFrameCount, |
| 6223 kMaxSpdyFrameChunkSize * kFrameCount, | 5840 stream->stream()->send_window_size()); |
| 6224 stream->stream()->send_window_size()); | |
| 6225 | 5841 |
| 6226 data.Resume(); | 5842 data.Resume(); |
| 6227 base::RunLoop().RunUntilIdle(); | 5843 base::RunLoop().RunUntilIdle(); |
| 6228 | 5844 |
| 6229 rv = callback.WaitForResult(); | 5845 rv = callback.WaitForResult(); |
| 6230 EXPECT_THAT(rv, IsOk()); | 5846 EXPECT_THAT(rv, IsOk()); |
| 6231 | 5847 |
| 6232 helper.VerifyDataConsumed(); | 5848 helper.VerifyDataConsumed(); |
| 6233 } | 5849 } |
| 6234 | 5850 |
| 6235 // Test that received data frames and sent WINDOW_UPDATE frames change | 5851 // Test that received data frames and sent WINDOW_UPDATE frames change |
| 6236 // the recv_window_size_ correctly. | 5852 // the recv_window_size_ correctly. |
| 6237 TEST_P(SpdyNetworkTransactionTest, WindowUpdateSent) { | 5853 TEST_P(SpdyNetworkTransactionTest, WindowUpdateSent) { |
| 6238 const int32_t default_initial_window_size = | 5854 const int32_t default_initial_window_size = |
| 6239 SpdySession::GetDefaultInitialWindowSize(GetParam().protocol); | 5855 SpdySession::GetDefaultInitialWindowSize(kProtoHTTP2); |
| 6240 // Session level maximum window size that is more than twice the default | 5856 // Session level maximum window size that is more than twice the default |
| 6241 // initial window size so that an initial window update is sent. | 5857 // initial window size so that an initial window update is sent. |
| 6242 const int32_t session_max_recv_window_size = 5 * 64 * 1024; | 5858 const int32_t session_max_recv_window_size = 5 * 64 * 1024; |
| 6243 ASSERT_LT(2 * default_initial_window_size, session_max_recv_window_size); | 5859 ASSERT_LT(2 * default_initial_window_size, session_max_recv_window_size); |
| 6244 // Stream level maximum window size that is less than the session level | 5860 // Stream level maximum window size that is less than the session level |
| 6245 // maximum window size so that we test for confusion between the two. | 5861 // maximum window size so that we test for confusion between the two. |
| 6246 const int32_t stream_max_recv_window_size = 4 * 64 * 1024; | 5862 const int32_t stream_max_recv_window_size = 4 * 64 * 1024; |
| 6247 ASSERT_GT(session_max_recv_window_size, stream_max_recv_window_size); | 5863 ASSERT_GT(session_max_recv_window_size, stream_max_recv_window_size); |
| 6248 // Size of body to be sent. Has to be less than or equal to both window sizes | 5864 // Size of body to be sent. Has to be less than or equal to both window sizes |
| 6249 // so that we do not run out of receiving window. Also has to be greater than | 5865 // so that we do not run out of receiving window. Also has to be greater than |
| (...skipping 26 matching lines...) Expand all Loading... |
| 6276 kSessionFlowControlStreamId, | 5892 kSessionFlowControlStreamId, |
| 6277 session_max_recv_window_size - default_initial_window_size)); | 5893 session_max_recv_window_size - default_initial_window_size)); |
| 6278 std::unique_ptr<SpdySerializedFrame> req( | 5894 std::unique_ptr<SpdySerializedFrame> req( |
| 6279 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | 5895 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
| 6280 std::unique_ptr<SpdySerializedFrame> session_window_update( | 5896 std::unique_ptr<SpdySerializedFrame> session_window_update( |
| 6281 spdy_util_.ConstructSpdyWindowUpdate(0, session_window_update_delta)); | 5897 spdy_util_.ConstructSpdyWindowUpdate(0, session_window_update_delta)); |
| 6282 std::unique_ptr<SpdySerializedFrame> stream_window_update( | 5898 std::unique_ptr<SpdySerializedFrame> stream_window_update( |
| 6283 spdy_util_.ConstructSpdyWindowUpdate(1, stream_window_update_delta)); | 5899 spdy_util_.ConstructSpdyWindowUpdate(1, stream_window_update_delta)); |
| 6284 | 5900 |
| 6285 std::vector<MockWrite> writes; | 5901 std::vector<MockWrite> writes; |
| 6286 if (GetParam().protocol == kProtoHTTP2) { | 5902 writes.push_back(MockWrite(ASYNC, kHttp2ConnectionHeaderPrefix, |
| 6287 writes.push_back(MockWrite(ASYNC, kHttp2ConnectionHeaderPrefix, | 5903 kHttp2ConnectionHeaderPrefixSize, 0)); |
| 6288 kHttp2ConnectionHeaderPrefixSize, 0)); | |
| 6289 } | |
| 6290 writes.push_back(CreateMockWrite(*initial_settings_frame, writes.size())); | 5904 writes.push_back(CreateMockWrite(*initial_settings_frame, writes.size())); |
| 6291 writes.push_back(CreateMockWrite(*initial_window_update, writes.size())); | 5905 writes.push_back(CreateMockWrite(*initial_window_update, writes.size())); |
| 6292 writes.push_back(CreateMockWrite(*req, writes.size())); | 5906 writes.push_back(CreateMockWrite(*req, writes.size())); |
| 6293 | 5907 |
| 6294 std::vector<MockRead> reads; | 5908 std::vector<MockRead> reads; |
| 6295 std::unique_ptr<SpdySerializedFrame> resp( | 5909 std::unique_ptr<SpdySerializedFrame> resp( |
| 6296 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 5910 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 6297 reads.push_back(CreateMockRead(*resp, writes.size() + reads.size())); | 5911 reads.push_back(CreateMockRead(*resp, writes.size() + reads.size())); |
| 6298 | 5912 |
| 6299 std::vector<std::unique_ptr<SpdySerializedFrame>> body_frames; | 5913 std::vector<std::unique_ptr<SpdySerializedFrame>> body_frames; |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6438 // writes, save the last, go through before a read could happen. The last frame | 6052 // writes, save the last, go through before a read could happen. The last frame |
| 6439 // ("hello!") is not permitted to go through since by the time its turn | 6053 // ("hello!") is not permitted to go through since by the time its turn |
| 6440 // arrives, window size is 0. At this point MessageLoop::Run() called via | 6054 // arrives, window size is 0. At this point MessageLoop::Run() called via |
| 6441 // callback would block. Therefore we call MessageLoop::RunUntilIdle() | 6055 // callback would block. Therefore we call MessageLoop::RunUntilIdle() |
| 6442 // which returns after performing all possible writes. We use DCHECKS to | 6056 // which returns after performing all possible writes. We use DCHECKS to |
| 6443 // ensure that last data frame is still there and stream has stalled. | 6057 // ensure that last data frame is still there and stream has stalled. |
| 6444 // After that, next read is artifically enforced, which causes a | 6058 // After that, next read is artifically enforced, which causes a |
| 6445 // WINDOW_UPDATE to be read and I/O process resumes. | 6059 // WINDOW_UPDATE to be read and I/O process resumes. |
| 6446 TEST_P(SpdyNetworkTransactionTest, FlowControlStallResume) { | 6060 TEST_P(SpdyNetworkTransactionTest, FlowControlStallResume) { |
| 6447 const int32_t initial_window_size = | 6061 const int32_t initial_window_size = |
| 6448 SpdySession::GetDefaultInitialWindowSize(GetParam().protocol); | 6062 SpdySession::GetDefaultInitialWindowSize(kProtoHTTP2); |
| 6449 // Number of upload data buffers we need to send to zero out the window size | 6063 // Number of upload data buffers we need to send to zero out the window size |
| 6450 // is the minimal number of upload buffers takes to be bigger than | 6064 // is the minimal number of upload buffers takes to be bigger than |
| 6451 // |initial_window_size|. | 6065 // |initial_window_size|. |
| 6452 size_t num_upload_buffers = | 6066 size_t num_upload_buffers = |
| 6453 ceil(static_cast<double>(initial_window_size) / kBufferSize); | 6067 ceil(static_cast<double>(initial_window_size) / kBufferSize); |
| 6454 // Each upload data buffer consists of |num_frames_in_one_upload_buffer| | 6068 // Each upload data buffer consists of |num_frames_in_one_upload_buffer| |
| 6455 // frames, each with |kMaxSpdyFrameChunkSize| bytes except the last frame, | 6069 // frames, each with |kMaxSpdyFrameChunkSize| bytes except the last frame, |
| 6456 // which has kBufferSize % kMaxSpdyChunkSize bytes. | 6070 // which has kBufferSize % kMaxSpdyChunkSize bytes. |
| 6457 size_t num_frames_in_one_upload_buffer = | 6071 size_t num_frames_in_one_upload_buffer = |
| 6458 ceil(static_cast<double>(kBufferSize) / kMaxSpdyFrameChunkSize); | 6072 ceil(static_cast<double>(kBufferSize) / kMaxSpdyFrameChunkSize); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6587 | 6201 |
| 6588 data.Resume(); // Read in WINDOW_UPDATE frame. | 6202 data.Resume(); // Read in WINDOW_UPDATE frame. |
| 6589 rv = callback.WaitForResult(); | 6203 rv = callback.WaitForResult(); |
| 6590 helper.VerifyDataConsumed(); | 6204 helper.VerifyDataConsumed(); |
| 6591 } | 6205 } |
| 6592 | 6206 |
| 6593 // Test we correctly handle the case where the SETTINGS frame results in | 6207 // Test we correctly handle the case where the SETTINGS frame results in |
| 6594 // unstalling the send window. | 6208 // unstalling the send window. |
| 6595 TEST_P(SpdyNetworkTransactionTest, FlowControlStallResumeAfterSettings) { | 6209 TEST_P(SpdyNetworkTransactionTest, FlowControlStallResumeAfterSettings) { |
| 6596 const int32_t initial_window_size = | 6210 const int32_t initial_window_size = |
| 6597 SpdySession::GetDefaultInitialWindowSize(GetParam().protocol); | 6211 SpdySession::GetDefaultInitialWindowSize(kProtoHTTP2); |
| 6598 // Number of upload data buffers we need to send to zero out the window size | 6212 // Number of upload data buffers we need to send to zero out the window size |
| 6599 // is the minimal number of upload buffers takes to be bigger than | 6213 // is the minimal number of upload buffers takes to be bigger than |
| 6600 // |initial_window_size|. | 6214 // |initial_window_size|. |
| 6601 size_t num_upload_buffers = | 6215 size_t num_upload_buffers = |
| 6602 ceil(static_cast<double>(initial_window_size) / kBufferSize); | 6216 ceil(static_cast<double>(initial_window_size) / kBufferSize); |
| 6603 // Each upload data buffer consists of |num_frames_in_one_upload_buffer| | 6217 // Each upload data buffer consists of |num_frames_in_one_upload_buffer| |
| 6604 // frames, each with |kMaxSpdyFrameChunkSize| bytes except the last frame, | 6218 // frames, each with |kMaxSpdyFrameChunkSize| bytes except the last frame, |
| 6605 // which has kBufferSize % kMaxSpdyChunkSize bytes. | 6219 // which has kBufferSize % kMaxSpdyChunkSize bytes. |
| 6606 size_t num_frames_in_one_upload_buffer = | 6220 size_t num_frames_in_one_upload_buffer = |
| 6607 ceil(static_cast<double>(kBufferSize) / kMaxSpdyFrameChunkSize); | 6221 ceil(static_cast<double>(kBufferSize) / kMaxSpdyFrameChunkSize); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6753 rv = callback.WaitForResult(); | 6367 rv = callback.WaitForResult(); |
| 6754 helper.VerifyDataConsumed(); | 6368 helper.VerifyDataConsumed(); |
| 6755 // If stream is NULL, that means it was unstalled and closed. | 6369 // If stream is NULL, that means it was unstalled and closed. |
| 6756 EXPECT_TRUE(stream->stream() == NULL); | 6370 EXPECT_TRUE(stream->stream() == NULL); |
| 6757 } | 6371 } |
| 6758 | 6372 |
| 6759 // Test we correctly handle the case where the SETTINGS frame results in a | 6373 // Test we correctly handle the case where the SETTINGS frame results in a |
| 6760 // negative send window size. | 6374 // negative send window size. |
| 6761 TEST_P(SpdyNetworkTransactionTest, FlowControlNegativeSendWindowSize) { | 6375 TEST_P(SpdyNetworkTransactionTest, FlowControlNegativeSendWindowSize) { |
| 6762 const int32_t initial_window_size = | 6376 const int32_t initial_window_size = |
| 6763 SpdySession::GetDefaultInitialWindowSize(GetParam().protocol); | 6377 SpdySession::GetDefaultInitialWindowSize(kProtoHTTP2); |
| 6764 // Number of upload data buffers we need to send to zero out the window size | 6378 // Number of upload data buffers we need to send to zero out the window size |
| 6765 // is the minimal number of upload buffers takes to be bigger than | 6379 // is the minimal number of upload buffers takes to be bigger than |
| 6766 // |initial_window_size|. | 6380 // |initial_window_size|. |
| 6767 size_t num_upload_buffers = | 6381 size_t num_upload_buffers = |
| 6768 ceil(static_cast<double>(initial_window_size) / kBufferSize); | 6382 ceil(static_cast<double>(initial_window_size) / kBufferSize); |
| 6769 // Each upload data buffer consists of |num_frames_in_one_upload_buffer| | 6383 // Each upload data buffer consists of |num_frames_in_one_upload_buffer| |
| 6770 // frames, each with |kMaxSpdyFrameChunkSize| bytes except the last frame, | 6384 // frames, each with |kMaxSpdyFrameChunkSize| bytes except the last frame, |
| 6771 // which has kBufferSize % kMaxSpdyChunkSize bytes. | 6385 // which has kBufferSize % kMaxSpdyChunkSize bytes. |
| 6772 size_t num_frames_in_one_upload_buffer = | 6386 size_t num_frames_in_one_upload_buffer = |
| 6773 ceil(static_cast<double>(kBufferSize) / kMaxSpdyFrameChunkSize); | 6387 ceil(static_cast<double>(kBufferSize) / kMaxSpdyFrameChunkSize); |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7046 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); | 6660 SequencedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 7047 helper.RunToCompletion(&data); | 6661 helper.RunToCompletion(&data); |
| 7048 TransactionHelperResult out = helper.output(); | 6662 TransactionHelperResult out = helper.output(); |
| 7049 | 6663 |
| 7050 EXPECT_THAT(out.rv, IsOk()); | 6664 EXPECT_THAT(out.rv, IsOk()); |
| 7051 EXPECT_EQ("HTTP/1.1 200", out.status_line); | 6665 EXPECT_EQ("HTTP/1.1 200", out.status_line); |
| 7052 EXPECT_EQ("hello!", out.response_data); | 6666 EXPECT_EQ("hello!", out.response_data); |
| 7053 ASSERT_TRUE(out.response_info.headers->HasHeaderValue(kKey, kValue)); | 6667 ASSERT_TRUE(out.response_info.headers->HasHeaderValue(kKey, kValue)); |
| 7054 } | 6668 } |
| 7055 | 6669 |
| 7056 class SpdyNetworkTransactionNoTLSUsageCheckTest | |
| 7057 : public SpdyNetworkTransactionTest { | |
| 7058 protected: | |
| 7059 void RunNoTLSUsageCheckTest( | |
| 7060 std::unique_ptr<SSLSocketDataProvider> ssl_provider) { | |
| 7061 // Construct the request. | |
| 7062 std::unique_ptr<SpdySerializedFrame> req( | |
| 7063 spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); | |
| 7064 MockWrite writes[] = {CreateMockWrite(*req, 0)}; | |
| 7065 | |
| 7066 std::unique_ptr<SpdySerializedFrame> resp( | |
| 7067 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | |
| 7068 std::unique_ptr<SpdySerializedFrame> body( | |
| 7069 spdy_util_.ConstructSpdyBodyFrame(1, true)); | |
| 7070 MockRead reads[] = { | |
| 7071 CreateMockRead(*resp, 1), | |
| 7072 CreateMockRead(*body, 2), | |
| 7073 MockRead(ASYNC, 0, 3) // EOF | |
| 7074 }; | |
| 7075 | |
| 7076 SequencedSocketData data(reads, arraysize(reads), writes, | |
| 7077 arraysize(writes)); | |
| 7078 HttpRequestInfo request; | |
| 7079 request.method = "GET"; | |
| 7080 request.url = default_url_; | |
| 7081 NormalSpdyTransactionHelper helper( | |
| 7082 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); | |
| 7083 helper.RunToCompletionWithSSLData(&data, std::move(ssl_provider)); | |
| 7084 TransactionHelperResult out = helper.output(); | |
| 7085 EXPECT_THAT(out.rv, IsOk()); | |
| 7086 EXPECT_EQ("HTTP/1.1 200", out.status_line); | |
| 7087 EXPECT_EQ("hello!", out.response_data); | |
| 7088 } | |
| 7089 }; | |
| 7090 | |
| 7091 INSTANTIATE_TEST_CASE_P( | |
| 7092 Spdy, | |
| 7093 SpdyNetworkTransactionNoTLSUsageCheckTest, | |
| 7094 ::testing::Values(SpdyNetworkTransactionTestParams(kProtoSPDY31, | |
| 7095 false))); | |
| 7096 | |
| 7097 TEST_P(SpdyNetworkTransactionNoTLSUsageCheckTest, TLSVersionTooOld) { | |
| 7098 std::unique_ptr<SSLSocketDataProvider> ssl_provider( | |
| 7099 new SSLSocketDataProvider(ASYNC, OK)); | |
| 7100 SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_SSL3, | |
| 7101 &ssl_provider->connection_status); | |
| 7102 | |
| 7103 RunNoTLSUsageCheckTest(std::move(ssl_provider)); | |
| 7104 } | |
| 7105 | |
| 7106 TEST_P(SpdyNetworkTransactionNoTLSUsageCheckTest, TLSCipherSuiteSucky) { | |
| 7107 std::unique_ptr<SSLSocketDataProvider> ssl_provider( | |
| 7108 new SSLSocketDataProvider(ASYNC, OK)); | |
| 7109 // Set to TLS_RSA_WITH_NULL_MD5 | |
| 7110 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); | |
| 7111 | |
| 7112 RunNoTLSUsageCheckTest(std::move(ssl_provider)); | |
| 7113 } | |
| 7114 | |
| 7115 class SpdyNetworkTransactionTLSUsageCheckTest | 6670 class SpdyNetworkTransactionTLSUsageCheckTest |
| 7116 : public SpdyNetworkTransactionTest { | 6671 : public SpdyNetworkTransactionTest { |
| 7117 protected: | 6672 protected: |
| 7118 void RunTLSUsageCheckTest( | 6673 void RunTLSUsageCheckTest( |
| 7119 std::unique_ptr<SSLSocketDataProvider> ssl_provider) { | 6674 std::unique_ptr<SSLSocketDataProvider> ssl_provider) { |
| 7120 std::unique_ptr<SpdySerializedFrame> goaway( | 6675 std::unique_ptr<SpdySerializedFrame> goaway( |
| 7121 spdy_util_.ConstructSpdyGoAway(0, GOAWAY_INADEQUATE_SECURITY, "")); | 6676 spdy_util_.ConstructSpdyGoAway(0, GOAWAY_INADEQUATE_SECURITY, "")); |
| 7122 MockWrite writes[] = {CreateMockWrite(*goaway)}; | 6677 MockWrite writes[] = {CreateMockWrite(*goaway)}; |
| 7123 | 6678 |
| 7124 StaticSocketDataProvider data(NULL, 0, writes, arraysize(writes)); | 6679 StaticSocketDataProvider data(NULL, 0, writes, arraysize(writes)); |
| 7125 HttpRequestInfo request; | 6680 HttpRequestInfo request; |
| 7126 request.method = "GET"; | 6681 request.method = "GET"; |
| 7127 request.url = default_url_; | 6682 request.url = default_url_; |
| 7128 NormalSpdyTransactionHelper helper( | 6683 NormalSpdyTransactionHelper helper( |
| 7129 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); | 6684 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 7130 helper.RunToCompletionWithSSLData(&data, std::move(ssl_provider)); | 6685 helper.RunToCompletionWithSSLData(&data, std::move(ssl_provider)); |
| 7131 TransactionHelperResult out = helper.output(); | 6686 TransactionHelperResult out = helper.output(); |
| 7132 EXPECT_THAT(out.rv, IsError(ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY)); | 6687 EXPECT_THAT(out.rv, IsError(ERR_SPDY_INADEQUATE_TRANSPORT_SECURITY)); |
| 7133 } | 6688 } |
| 7134 }; | 6689 }; |
| 7135 | 6690 |
| 7136 INSTANTIATE_TEST_CASE_P( | 6691 INSTANTIATE_TEST_CASE_P(Spdy, |
| 7137 Spdy, | 6692 SpdyNetworkTransactionTLSUsageCheckTest, |
| 7138 SpdyNetworkTransactionTLSUsageCheckTest, | 6693 ::testing::Bool()); |
| 7139 ::testing::Values(SpdyNetworkTransactionTestParams(kProtoHTTP2, false), | |
| 7140 SpdyNetworkTransactionTestParams(kProtoHTTP2, true))); | |
| 7141 | 6694 |
| 7142 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSVersionTooOld) { | 6695 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSVersionTooOld) { |
| 7143 std::unique_ptr<SSLSocketDataProvider> ssl_provider( | 6696 std::unique_ptr<SSLSocketDataProvider> ssl_provider( |
| 7144 new SSLSocketDataProvider(ASYNC, OK)); | 6697 new SSLSocketDataProvider(ASYNC, OK)); |
| 7145 SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_SSL3, | 6698 SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_SSL3, |
| 7146 &ssl_provider->connection_status); | 6699 &ssl_provider->connection_status); |
| 7147 | 6700 |
| 7148 RunTLSUsageCheckTest(std::move(ssl_provider)); | 6701 RunTLSUsageCheckTest(std::move(ssl_provider)); |
| 7149 } | 6702 } |
| 7150 | 6703 |
| 7151 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { | 6704 TEST_P(SpdyNetworkTransactionTLSUsageCheckTest, TLSCipherSuiteSucky) { |
| 7152 std::unique_ptr<SSLSocketDataProvider> ssl_provider( | 6705 std::unique_ptr<SSLSocketDataProvider> ssl_provider( |
| 7153 new SSLSocketDataProvider(ASYNC, OK)); | 6706 new SSLSocketDataProvider(ASYNC, OK)); |
| 7154 // Set to TLS_RSA_WITH_NULL_MD5 | 6707 // Set to TLS_RSA_WITH_NULL_MD5 |
| 7155 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); | 6708 SSLConnectionStatusSetCipherSuite(0x1, &ssl_provider->connection_status); |
| 7156 | 6709 |
| 7157 RunTLSUsageCheckTest(std::move(ssl_provider)); | 6710 RunTLSUsageCheckTest(std::move(ssl_provider)); |
| 7158 } | 6711 } |
| 7159 | 6712 |
| 7160 } // namespace net | 6713 } // namespace net |
| OLD | NEW |