| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 const char kRequestUrl[] = "http://www.google.com/"; | 49 const char kRequestUrl[] = "http://www.google.com/"; |
| 50 | 50 |
| 51 enum SpdyNetworkTransactionTestSSLType { | 51 enum SpdyNetworkTransactionTestSSLType { |
| 52 SPDYNPN, | 52 SPDYNPN, |
| 53 SPDYNOSSL, | 53 SPDYNOSSL, |
| 54 SPDYSSL, | 54 SPDYSSL, |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 struct SpdyNetworkTransactionTestParams { | 57 struct SpdyNetworkTransactionTestParams { |
| 58 SpdyNetworkTransactionTestParams() | 58 SpdyNetworkTransactionTestParams() |
| 59 : protocol(kProtoSPDY3), | 59 : protocol(kProtoSPDY3), ssl_type(SPDYNPN) {} |
| 60 ssl_type(SPDYNPN) {} | |
| 61 | 60 |
| 62 SpdyNetworkTransactionTestParams( | 61 SpdyNetworkTransactionTestParams(NextProto protocol, |
| 63 NextProto protocol, | 62 SpdyNetworkTransactionTestSSLType ssl_type) |
| 64 SpdyNetworkTransactionTestSSLType ssl_type) | 63 : protocol(protocol), ssl_type(ssl_type) {} |
| 65 : protocol(protocol), | |
| 66 ssl_type(ssl_type) {} | |
| 67 | 64 |
| 68 NextProto protocol; | 65 NextProto protocol; |
| 69 SpdyNetworkTransactionTestSSLType ssl_type; | 66 SpdyNetworkTransactionTestSSLType ssl_type; |
| 70 }; | 67 }; |
| 71 | 68 |
| 72 SpdySessionDependencies* CreateSpdySessionDependencies( | 69 SpdySessionDependencies* CreateSpdySessionDependencies( |
| 73 SpdyNetworkTransactionTestParams test_params) { | 70 SpdyNetworkTransactionTestParams test_params) { |
| 74 return new SpdySessionDependencies(test_params.protocol); | 71 return new SpdySessionDependencies(test_params.protocol); |
| 75 } | 72 } |
| 76 | 73 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 // A helper class that handles all the initial npn/ssl setup. | 114 // A helper class that handles all the initial npn/ssl setup. |
| 118 class NormalSpdyTransactionHelper { | 115 class NormalSpdyTransactionHelper { |
| 119 public: | 116 public: |
| 120 NormalSpdyTransactionHelper(const HttpRequestInfo& request, | 117 NormalSpdyTransactionHelper(const HttpRequestInfo& request, |
| 121 RequestPriority priority, | 118 RequestPriority priority, |
| 122 const BoundNetLog& log, | 119 const BoundNetLog& log, |
| 123 SpdyNetworkTransactionTestParams test_params, | 120 SpdyNetworkTransactionTestParams test_params, |
| 124 SpdySessionDependencies* session_deps) | 121 SpdySessionDependencies* session_deps) |
| 125 : request_(request), | 122 : request_(request), |
| 126 priority_(priority), | 123 priority_(priority), |
| 127 session_deps_(session_deps == NULL ? | 124 session_deps_(session_deps == NULL |
| 128 CreateSpdySessionDependencies(test_params) : | 125 ? CreateSpdySessionDependencies(test_params) |
| 129 session_deps), | 126 : session_deps), |
| 130 session_(SpdySessionDependencies::SpdyCreateSession( | 127 session_( |
| 131 session_deps_.get())), | 128 SpdySessionDependencies::SpdyCreateSession(session_deps_.get())), |
| 132 log_(log), | 129 log_(log), |
| 133 test_params_(test_params), | 130 test_params_(test_params), |
| 134 deterministic_(false), | 131 deterministic_(false), |
| 135 spdy_enabled_(true) { | 132 spdy_enabled_(true) { |
| 136 switch (test_params_.ssl_type) { | 133 switch (test_params_.ssl_type) { |
| 137 case SPDYNOSSL: | 134 case SPDYNOSSL: |
| 138 case SPDYSSL: | 135 case SPDYSSL: |
| 139 port_ = 80; | 136 port_ = 80; |
| 140 break; | 137 break; |
| 141 case SPDYNPN: | 138 case SPDYNPN: |
| (...skipping 25 matching lines...) Expand all Loading... |
| 167 void SetSpdyDisabled() { | 164 void SetSpdyDisabled() { |
| 168 spdy_enabled_ = false; | 165 spdy_enabled_ = false; |
| 169 port_ = 80; | 166 port_ = 80; |
| 170 } | 167 } |
| 171 | 168 |
| 172 void RunPreTestSetup() { | 169 void RunPreTestSetup() { |
| 173 LOG(INFO) << __FUNCTION__; | 170 LOG(INFO) << __FUNCTION__; |
| 174 if (!session_deps_.get()) | 171 if (!session_deps_.get()) |
| 175 session_deps_.reset(CreateSpdySessionDependencies(test_params_)); | 172 session_deps_.reset(CreateSpdySessionDependencies(test_params_)); |
| 176 if (!session_.get()) | 173 if (!session_.get()) |
| 177 session_ = SpdySessionDependencies::SpdyCreateSession( | 174 session_ = |
| 178 session_deps_.get()); | 175 SpdySessionDependencies::SpdyCreateSession(session_deps_.get()); |
| 179 HttpStreamFactory::set_use_alternate_protocols(false); | 176 HttpStreamFactory::set_use_alternate_protocols(false); |
| 180 HttpStreamFactory::set_force_spdy_over_ssl(false); | 177 HttpStreamFactory::set_force_spdy_over_ssl(false); |
| 181 HttpStreamFactory::set_force_spdy_always(false); | 178 HttpStreamFactory::set_force_spdy_always(false); |
| 182 | 179 |
| 183 std::vector<NextProto> next_protos = SpdyNextProtos(); | 180 std::vector<NextProto> next_protos = SpdyNextProtos(); |
| 184 | 181 |
| 185 switch (test_params_.ssl_type) { | 182 switch (test_params_.ssl_type) { |
| 186 case SPDYNPN: | 183 case SPDYNPN: |
| 187 session_->http_server_properties()->SetAlternateProtocol( | 184 session_->http_server_properties()->SetAlternateProtocol( |
| 188 HostPortPair("www.google.com", 80), 443, | 185 HostPortPair("www.google.com", 80), |
| 186 443, |
| 189 AlternateProtocolFromNextProto(test_params_.protocol)); | 187 AlternateProtocolFromNextProto(test_params_.protocol)); |
| 190 HttpStreamFactory::set_use_alternate_protocols(true); | 188 HttpStreamFactory::set_use_alternate_protocols(true); |
| 191 HttpStreamFactory::SetNextProtos(next_protos); | 189 HttpStreamFactory::SetNextProtos(next_protos); |
| 192 break; | 190 break; |
| 193 case SPDYNOSSL: | 191 case SPDYNOSSL: |
| 194 HttpStreamFactory::set_force_spdy_over_ssl(false); | 192 HttpStreamFactory::set_force_spdy_over_ssl(false); |
| 195 HttpStreamFactory::set_force_spdy_always(true); | 193 HttpStreamFactory::set_force_spdy_always(true); |
| 196 break; | 194 break; |
| 197 case SPDYSSL: | 195 case SPDYSSL: |
| 198 HttpStreamFactory::set_force_spdy_over_ssl(true); | 196 HttpStreamFactory::set_force_spdy_over_ssl(true); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 return; | 229 return; |
| 232 } | 230 } |
| 233 | 231 |
| 234 // Verify responses. | 232 // Verify responses. |
| 235 const HttpResponseInfo* response = trans_->GetResponseInfo(); | 233 const HttpResponseInfo* response = trans_->GetResponseInfo(); |
| 236 ASSERT_TRUE(response != NULL); | 234 ASSERT_TRUE(response != NULL); |
| 237 ASSERT_TRUE(response->headers.get() != NULL); | 235 ASSERT_TRUE(response->headers.get() != NULL); |
| 238 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 236 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 239 EXPECT_EQ(spdy_enabled_, response->was_fetched_via_spdy); | 237 EXPECT_EQ(spdy_enabled_, response->was_fetched_via_spdy); |
| 240 if (HttpStreamFactory::spdy_enabled()) { | 238 if (HttpStreamFactory::spdy_enabled()) { |
| 241 EXPECT_EQ( | 239 EXPECT_EQ(HttpResponseInfo::ConnectionInfoFromNextProto( |
| 242 HttpResponseInfo::ConnectionInfoFromNextProto( | 240 test_params_.protocol), |
| 243 test_params_.protocol), | 241 response->connection_info); |
| 244 response->connection_info); | |
| 245 } else { | 242 } else { |
| 246 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, | 243 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_HTTP1, |
| 247 response->connection_info); | 244 response->connection_info); |
| 248 } | 245 } |
| 249 if (test_params_.ssl_type == SPDYNPN && spdy_enabled_) { | 246 if (test_params_.ssl_type == SPDYNPN && spdy_enabled_) { |
| 250 EXPECT_TRUE(response->was_npn_negotiated); | 247 EXPECT_TRUE(response->was_npn_negotiated); |
| 251 } else { | 248 } else { |
| 252 EXPECT_TRUE(!response->was_npn_negotiated); | 249 EXPECT_TRUE(!response->was_npn_negotiated); |
| 253 } | 250 } |
| 254 // If SPDY is not enabled, a HTTP request should not be diverted | 251 // If SPDY is not enabled, a HTTP request should not be diverted |
| 255 // over a SSL session. | 252 // over a SSL session. |
| 256 if (!spdy_enabled_) { | 253 if (!spdy_enabled_) { |
| 257 EXPECT_EQ(request_.url.SchemeIs("https"), | 254 EXPECT_EQ(request_.url.SchemeIs("https"), response->was_npn_negotiated); |
| 258 response->was_npn_negotiated); | |
| 259 } | 255 } |
| 260 EXPECT_EQ("127.0.0.1", response->socket_address.host()); | 256 EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 261 EXPECT_EQ(port_, response->socket_address.port()); | 257 EXPECT_EQ(port_, response->socket_address.port()); |
| 262 output_.status_line = response->headers->GetStatusLine(); | 258 output_.status_line = response->headers->GetStatusLine(); |
| 263 output_.response_info = *response; // Make a copy so we can verify. | 259 output_.response_info = *response; // Make a copy so we can verify. |
| 264 output_.rv = ReadTransaction(trans_.get(), &output_.response_data); | 260 output_.rv = ReadTransaction(trans_.get(), &output_.response_data); |
| 265 } | 261 } |
| 266 | 262 |
| 267 // Most tests will want to call this function. In particular, the MockReads | 263 // Most tests will want to call this function. In particular, the MockReads |
| 268 // should end with an empty read, and that read needs to be processed to | 264 // should end with an empty read, and that read needs to be processed to |
| 269 // ensure proper deletion of the spdy_session_pool. | 265 // ensure proper deletion of the spdy_session_pool. |
| 270 void VerifyDataConsumed() { | 266 void VerifyDataConsumed() { |
| 271 for (DataVector::iterator it = data_vector_.begin(); | 267 for (DataVector::iterator it = data_vector_.begin(); |
| 272 it != data_vector_.end(); ++it) { | 268 it != data_vector_.end(); |
| 273 EXPECT_TRUE((*it)->at_read_eof()) << "Read count: " | 269 ++it) { |
| 274 << (*it)->read_count() | 270 EXPECT_TRUE((*it)->at_read_eof()) |
| 275 << " Read index: " | 271 << "Read count: " << (*it)->read_count() |
| 276 << (*it)->read_index(); | 272 << " Read index: " << (*it)->read_index(); |
| 277 EXPECT_TRUE((*it)->at_write_eof()) << "Write count: " | 273 EXPECT_TRUE((*it)->at_write_eof()) |
| 278 << (*it)->write_count() | 274 << "Write count: " << (*it)->write_count() |
| 279 << " Write index: " | 275 << " Write index: " << (*it)->write_index(); |
| 280 << (*it)->write_index(); | |
| 281 } | 276 } |
| 282 } | 277 } |
| 283 | 278 |
| 284 // Occasionally a test will expect to error out before certain reads are | 279 // Occasionally a test will expect to error out before certain reads are |
| 285 // processed. In that case we want to explicitly ensure that the reads were | 280 // processed. In that case we want to explicitly ensure that the reads were |
| 286 // not processed. | 281 // not processed. |
| 287 void VerifyDataNotConsumed() { | 282 void VerifyDataNotConsumed() { |
| 288 for (DataVector::iterator it = data_vector_.begin(); | 283 for (DataVector::iterator it = data_vector_.begin(); |
| 289 it != data_vector_.end(); ++it) { | 284 it != data_vector_.end(); |
| 290 EXPECT_TRUE(!(*it)->at_read_eof()) << "Read count: " | 285 ++it) { |
| 291 << (*it)->read_count() | 286 EXPECT_TRUE(!(*it)->at_read_eof()) |
| 292 << " Read index: " | 287 << "Read count: " << (*it)->read_count() |
| 293 << (*it)->read_index(); | 288 << " Read index: " << (*it)->read_index(); |
| 294 EXPECT_TRUE(!(*it)->at_write_eof()) << "Write count: " | 289 EXPECT_TRUE(!(*it)->at_write_eof()) |
| 295 << (*it)->write_count() | 290 << "Write count: " << (*it)->write_count() |
| 296 << " Write index: " | 291 << " Write index: " << (*it)->write_index(); |
| 297 << (*it)->write_index(); | |
| 298 } | 292 } |
| 299 } | 293 } |
| 300 | 294 |
| 301 void RunToCompletion(StaticSocketDataProvider* data) { | 295 void RunToCompletion(StaticSocketDataProvider* data) { |
| 302 RunPreTestSetup(); | 296 RunPreTestSetup(); |
| 303 AddData(data); | 297 AddData(data); |
| 304 RunDefaultTest(); | 298 RunDefaultTest(); |
| 305 VerifyDataConsumed(); | 299 VerifyDataConsumed(); |
| 306 } | 300 } |
| 307 | 301 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 334 DCHECK(deterministic_); | 328 DCHECK(deterministic_); |
| 335 data_vector_.push_back(data); | 329 data_vector_.push_back(data); |
| 336 SSLSocketDataProvider* ssl_provider = | 330 SSLSocketDataProvider* ssl_provider = |
| 337 new SSLSocketDataProvider(ASYNC, OK); | 331 new SSLSocketDataProvider(ASYNC, OK); |
| 338 if (test_params_.ssl_type == SPDYNPN) | 332 if (test_params_.ssl_type == SPDYNPN) |
| 339 ssl_provider->SetNextProto(test_params_.protocol); | 333 ssl_provider->SetNextProto(test_params_.protocol); |
| 340 | 334 |
| 341 ssl_vector_.push_back(ssl_provider); | 335 ssl_vector_.push_back(ssl_provider); |
| 342 if (test_params_.ssl_type == SPDYNPN || | 336 if (test_params_.ssl_type == SPDYNPN || |
| 343 test_params_.ssl_type == SPDYSSL) { | 337 test_params_.ssl_type == SPDYSSL) { |
| 344 session_deps_->deterministic_socket_factory-> | 338 session_deps_->deterministic_socket_factory->AddSSLSocketDataProvider( |
| 345 AddSSLSocketDataProvider(ssl_provider); | 339 ssl_provider); |
| 346 } | 340 } |
| 347 session_deps_->deterministic_socket_factory->AddSocketDataProvider(data); | 341 session_deps_->deterministic_socket_factory->AddSocketDataProvider(data); |
| 348 if (test_params_.ssl_type == SPDYNPN) { | 342 if (test_params_.ssl_type == SPDYNPN) { |
| 349 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); | 343 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 350 DeterministicSocketData* hanging_non_alternate_protocol_socket = | 344 DeterministicSocketData* hanging_non_alternate_protocol_socket = |
| 351 new DeterministicSocketData(NULL, 0, NULL, 0); | 345 new DeterministicSocketData(NULL, 0, NULL, 0); |
| 352 hanging_non_alternate_protocol_socket->set_connect_data( | 346 hanging_non_alternate_protocol_socket->set_connect_data( |
| 353 never_finishing_connect); | 347 never_finishing_connect); |
| 354 session_deps_->deterministic_socket_factory->AddSocketDataProvider( | 348 session_deps_->deterministic_socket_factory->AddSocketDataProvider( |
| 355 hanging_non_alternate_protocol_socket); | 349 hanging_non_alternate_protocol_socket); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 base::WriteFile(file_path, kUploadData, kUploadDataSize)); | 479 base::WriteFile(file_path, kUploadData, kUploadDataSize)); |
| 486 CHECK(file_util::MakeFileUnreadable(file_path)); | 480 CHECK(file_util::MakeFileUnreadable(file_path)); |
| 487 | 481 |
| 488 ScopedVector<UploadElementReader> element_readers; | 482 ScopedVector<UploadElementReader> element_readers; |
| 489 element_readers.push_back( | 483 element_readers.push_back( |
| 490 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 484 new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 491 file_path, | 485 file_path, |
| 492 0, | 486 0, |
| 493 kUploadDataSize, | 487 kUploadDataSize, |
| 494 base::Time())); | 488 base::Time())); |
| 495 upload_data_stream_.reset( | 489 upload_data_stream_.reset(new UploadDataStream(element_readers.Pass(), 0)); |
| 496 new UploadDataStream(element_readers.Pass(), 0)); | |
| 497 | 490 |
| 498 google_post_request_.method = "POST"; | 491 google_post_request_.method = "POST"; |
| 499 google_post_request_.url = GURL(kDefaultURL); | 492 google_post_request_.url = GURL(kDefaultURL); |
| 500 google_post_request_.upload_data_stream = upload_data_stream_.get(); | 493 google_post_request_.upload_data_stream = upload_data_stream_.get(); |
| 501 google_post_request_initialized_ = true; | 494 google_post_request_initialized_ = true; |
| 502 return google_post_request_; | 495 return google_post_request_; |
| 503 } | 496 } |
| 504 | 497 |
| 505 const HttpRequestInfo& CreateComplexPostRequest() { | 498 const HttpRequestInfo& CreateComplexPostRequest() { |
| 506 if (!google_post_request_initialized_) { | 499 if (!google_post_request_initialized_) { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 return bytes_read; | 573 return bytes_read; |
| 581 } | 574 } |
| 582 | 575 |
| 583 void VerifyStreamsClosed(const NormalSpdyTransactionHelper& helper) { | 576 void VerifyStreamsClosed(const NormalSpdyTransactionHelper& helper) { |
| 584 // This lengthy block is reaching into the pool to dig out the active | 577 // This lengthy block is reaching into the pool to dig out the active |
| 585 // session. Once we have the session, we verify that the streams are | 578 // session. Once we have the session, we verify that the streams are |
| 586 // all closed and not leaked at this point. | 579 // all closed and not leaked at this point. |
| 587 const GURL& url = helper.request().url; | 580 const GURL& url = helper.request().url; |
| 588 int port = helper.test_params().ssl_type == SPDYNPN ? 443 : 80; | 581 int port = helper.test_params().ssl_type == SPDYNPN ? 443 : 80; |
| 589 HostPortPair host_port_pair(url.host(), port); | 582 HostPortPair host_port_pair(url.host(), port); |
| 590 SpdySessionKey key(host_port_pair, ProxyServer::Direct(), | 583 SpdySessionKey key( |
| 591 PRIVACY_MODE_DISABLED); | 584 host_port_pair, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 592 BoundNetLog log; | 585 BoundNetLog log; |
| 593 const scoped_refptr<HttpNetworkSession>& session = helper.session(); | 586 const scoped_refptr<HttpNetworkSession>& session = helper.session(); |
| 594 base::WeakPtr<SpdySession> spdy_session = | 587 base::WeakPtr<SpdySession> spdy_session = |
| 595 session->spdy_session_pool()->FindAvailableSession(key, log); | 588 session->spdy_session_pool()->FindAvailableSession(key, log); |
| 596 ASSERT_TRUE(spdy_session != NULL); | 589 ASSERT_TRUE(spdy_session != NULL); |
| 597 EXPECT_EQ(0u, spdy_session->num_active_streams()); | 590 EXPECT_EQ(0u, spdy_session->num_active_streams()); |
| 598 EXPECT_EQ(0u, spdy_session->num_unclaimed_pushed_streams()); | 591 EXPECT_EQ(0u, spdy_session->num_unclaimed_pushed_streams()); |
| 599 } | 592 } |
| 600 | 593 |
| 601 void RunServerPushTest(OrderedSocketData* data, | 594 void RunServerPushTest(OrderedSocketData* data, |
| 602 HttpResponseInfo* response, | 595 HttpResponseInfo* response, |
| 603 HttpResponseInfo* push_response, | 596 HttpResponseInfo* push_response, |
| 604 const std::string& expected) { | 597 const std::string& expected) { |
| 605 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 598 NormalSpdyTransactionHelper helper( |
| 606 BoundNetLog(), GetParam(), NULL); | 599 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 607 helper.RunPreTestSetup(); | 600 helper.RunPreTestSetup(); |
| 608 helper.AddData(data); | 601 helper.AddData(data); |
| 609 | 602 |
| 610 HttpNetworkTransaction* trans = helper.trans(); | 603 HttpNetworkTransaction* trans = helper.trans(); |
| 611 | 604 |
| 612 // Start the transaction with basic parameters. | 605 // Start the transaction with basic parameters. |
| 613 TestCompletionCallback callback; | 606 TestCompletionCallback callback; |
| 614 int rv = trans->Start( | 607 int rv = |
| 615 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 608 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 616 EXPECT_EQ(ERR_IO_PENDING, rv); | 609 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 617 rv = callback.WaitForResult(); | 610 rv = callback.WaitForResult(); |
| 618 | 611 |
| 619 // Request the pushed path. | 612 // Request the pushed path. |
| 620 scoped_ptr<HttpNetworkTransaction> trans2( | 613 scoped_ptr<HttpNetworkTransaction> trans2( |
| 621 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); | 614 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
| 622 rv = trans2->Start( | 615 rv = trans2->Start( |
| 623 &CreateGetPushRequest(), callback.callback(), BoundNetLog()); | 616 &CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
| 624 EXPECT_EQ(ERR_IO_PENDING, rv); | 617 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 625 base::RunLoop().RunUntilIdle(); | 618 base::RunLoop().RunUntilIdle(); |
| 626 | 619 |
| 627 // The data for the pushed path may be coming in more than 1 frame. Compile | 620 // The data for the pushed path may be coming in more than 1 frame. Compile |
| 628 // the results into a single string. | 621 // the results into a single string. |
| 629 | 622 |
| 630 // Read the server push body. | 623 // Read the server push body. |
| 631 std::string result2; | 624 std::string result2; |
| 632 ReadResult(trans2.get(), data, &result2); | 625 ReadResult(trans2.get(), data, &result2); |
| 633 // Read the response body. | 626 // Read the response body. |
| 634 std::string result; | 627 std::string result; |
| 635 ReadResult(trans, data, &result); | 628 ReadResult(trans, data, &result); |
| 636 | 629 |
| 637 // Verify that we consumed all test data. | 630 // Verify that we consumed all test data. |
| 638 EXPECT_TRUE(data->at_read_eof()); | 631 EXPECT_TRUE(data->at_read_eof()); |
| 639 EXPECT_TRUE(data->at_write_eof()); | 632 EXPECT_TRUE(data->at_write_eof()); |
| 640 | 633 |
| 641 // Verify that the received push data is same as the expected push data. | 634 // Verify that the received push data is same as the expected push data. |
| 642 EXPECT_EQ(result2.compare(expected), 0) << "Received data: " | 635 EXPECT_EQ(result2.compare(expected), 0) |
| 643 << result2 | 636 << "Received data: " << result2 << "||||| Expected data: " << expected; |
| 644 << "||||| Expected data: " | |
| 645 << expected; | |
| 646 | 637 |
| 647 // Verify the SYN_REPLY. | 638 // Verify the SYN_REPLY. |
| 648 // Copy the response info, because trans goes away. | 639 // Copy the response info, because trans goes away. |
| 649 *response = *trans->GetResponseInfo(); | 640 *response = *trans->GetResponseInfo(); |
| 650 *push_response = *trans2->GetResponseInfo(); | 641 *push_response = *trans2->GetResponseInfo(); |
| 651 | 642 |
| 652 VerifyStreamsClosed(helper); | 643 VerifyStreamsClosed(helper); |
| 653 } | 644 } |
| 654 | 645 |
| 655 static void DeleteSessionCallback(NormalSpdyTransactionHelper* helper, | 646 static void DeleteSessionCallback(NormalSpdyTransactionHelper* helper, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 scoped_ptr<HttpTransaction> trans( | 712 scoped_ptr<HttpTransaction> trans( |
| 722 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 713 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 723 LOG(INFO) << __FUNCTION__; | 714 LOG(INFO) << __FUNCTION__; |
| 724 } | 715 } |
| 725 | 716 |
| 726 TEST_P(SpdyNetworkTransactionTest, Get) { | 717 TEST_P(SpdyNetworkTransactionTest, Get) { |
| 727 LOG(INFO) << __FUNCTION__; | 718 LOG(INFO) << __FUNCTION__; |
| 728 // Construct the request. | 719 // Construct the request. |
| 729 scoped_ptr<SpdyFrame> req( | 720 scoped_ptr<SpdyFrame> req( |
| 730 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 721 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 731 MockWrite writes[] = { CreateMockWrite(*req) }; | 722 MockWrite writes[] = {CreateMockWrite(*req)}; |
| 732 | 723 |
| 733 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 724 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 734 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 725 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 735 MockRead reads[] = { | 726 MockRead reads[] = { |
| 736 CreateMockRead(*resp), | 727 CreateMockRead(*resp), CreateMockRead(*body), |
| 737 CreateMockRead(*body), | 728 MockRead(ASYNC, 0, 0) // EOF |
| 738 MockRead(ASYNC, 0, 0) // EOF | |
| 739 }; | 729 }; |
| 740 | 730 |
| 741 DelayedSocketData data(1, reads, arraysize(reads), | 731 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 742 writes, arraysize(writes)); | 732 NormalSpdyTransactionHelper helper( |
| 743 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 733 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 744 BoundNetLog(), GetParam(), NULL); | |
| 745 helper.RunToCompletion(&data); | 734 helper.RunToCompletion(&data); |
| 746 TransactionHelperResult out = helper.output(); | 735 TransactionHelperResult out = helper.output(); |
| 747 EXPECT_EQ(OK, out.rv); | 736 EXPECT_EQ(OK, out.rv); |
| 748 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 737 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 749 EXPECT_EQ("hello!", out.response_data); | 738 EXPECT_EQ("hello!", out.response_data); |
| 750 } | 739 } |
| 751 | 740 |
| 752 TEST_P(SpdyNetworkTransactionTest, GetAtEachPriority) { | 741 TEST_P(SpdyNetworkTransactionTest, GetAtEachPriority) { |
| 753 for (RequestPriority p = MINIMUM_PRIORITY; p <= MAXIMUM_PRIORITY; | 742 for (RequestPriority p = MINIMUM_PRIORITY; p <= MAXIMUM_PRIORITY; |
| 754 p = RequestPriority(p + 1)) { | 743 p = RequestPriority(p + 1)) { |
| 755 // Construct the request. | 744 // Construct the request. |
| 756 scoped_ptr<SpdyFrame> req( | 745 scoped_ptr<SpdyFrame> req( |
| 757 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, p, true)); | 746 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, p, true)); |
| 758 MockWrite writes[] = { CreateMockWrite(*req) }; | 747 MockWrite writes[] = {CreateMockWrite(*req)}; |
| 759 | 748 |
| 760 SpdyPriority spdy_prio = 0; | 749 SpdyPriority spdy_prio = 0; |
| 761 EXPECT_TRUE(GetSpdyPriority(spdy_util_.spdy_version(), *req, &spdy_prio)); | 750 EXPECT_TRUE(GetSpdyPriority(spdy_util_.spdy_version(), *req, &spdy_prio)); |
| 762 // this repeats the RequestPriority-->SpdyPriority mapping from | 751 // this repeats the RequestPriority-->SpdyPriority mapping from |
| 763 // SpdyFramer::ConvertRequestPriorityToSpdyPriority to make | 752 // SpdyFramer::ConvertRequestPriorityToSpdyPriority to make |
| 764 // sure it's being done right. | 753 // sure it's being done right. |
| 765 if (spdy_util_.spdy_version() < SPDY3) { | 754 if (spdy_util_.spdy_version() < SPDY3) { |
| 766 switch(p) { | 755 switch (p) { |
| 767 case HIGHEST: | 756 case HIGHEST: |
| 768 EXPECT_EQ(0, spdy_prio); | 757 EXPECT_EQ(0, spdy_prio); |
| 769 break; | 758 break; |
| 770 case MEDIUM: | 759 case MEDIUM: |
| 771 EXPECT_EQ(1, spdy_prio); | 760 EXPECT_EQ(1, spdy_prio); |
| 772 break; | 761 break; |
| 773 case LOW: | 762 case LOW: |
| 774 case LOWEST: | 763 case LOWEST: |
| 775 EXPECT_EQ(2, spdy_prio); | 764 EXPECT_EQ(2, spdy_prio); |
| 776 break; | 765 break; |
| 777 case IDLE: | 766 case IDLE: |
| 778 EXPECT_EQ(3, spdy_prio); | 767 EXPECT_EQ(3, spdy_prio); |
| 779 break; | 768 break; |
| 780 default: | 769 default: |
| 781 FAIL(); | 770 FAIL(); |
| 782 } | 771 } |
| 783 } else { | 772 } else { |
| 784 switch(p) { | 773 switch (p) { |
| 785 case HIGHEST: | 774 case HIGHEST: |
| 786 EXPECT_EQ(0, spdy_prio); | 775 EXPECT_EQ(0, spdy_prio); |
| 787 break; | 776 break; |
| 788 case MEDIUM: | 777 case MEDIUM: |
| 789 EXPECT_EQ(1, spdy_prio); | 778 EXPECT_EQ(1, spdy_prio); |
| 790 break; | 779 break; |
| 791 case LOW: | 780 case LOW: |
| 792 EXPECT_EQ(2, spdy_prio); | 781 EXPECT_EQ(2, spdy_prio); |
| 793 break; | 782 break; |
| 794 case LOWEST: | 783 case LOWEST: |
| 795 EXPECT_EQ(3, spdy_prio); | 784 EXPECT_EQ(3, spdy_prio); |
| 796 break; | 785 break; |
| 797 case IDLE: | 786 case IDLE: |
| 798 EXPECT_EQ(4, spdy_prio); | 787 EXPECT_EQ(4, spdy_prio); |
| 799 break; | 788 break; |
| 800 default: | 789 default: |
| 801 FAIL(); | 790 FAIL(); |
| 802 } | 791 } |
| 803 } | 792 } |
| 804 | 793 |
| 805 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 794 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 806 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 795 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 807 MockRead reads[] = { | 796 MockRead reads[] = { |
| 808 CreateMockRead(*resp), | 797 CreateMockRead(*resp), CreateMockRead(*body), |
| 809 CreateMockRead(*body), | 798 MockRead(ASYNC, 0, 0) // EOF |
| 810 MockRead(ASYNC, 0, 0) // EOF | |
| 811 }; | 799 }; |
| 812 | 800 |
| 813 DelayedSocketData data(1, reads, arraysize(reads), | 801 DelayedSocketData data( |
| 814 writes, arraysize(writes)); | 802 1, reads, arraysize(reads), writes, arraysize(writes)); |
| 815 HttpRequestInfo http_req = CreateGetRequest(); | 803 HttpRequestInfo http_req = CreateGetRequest(); |
| 816 | 804 |
| 817 NormalSpdyTransactionHelper helper(http_req, p, BoundNetLog(), | 805 NormalSpdyTransactionHelper helper( |
| 818 GetParam(), NULL); | 806 http_req, p, BoundNetLog(), GetParam(), NULL); |
| 819 helper.RunToCompletion(&data); | 807 helper.RunToCompletion(&data); |
| 820 TransactionHelperResult out = helper.output(); | 808 TransactionHelperResult out = helper.output(); |
| 821 EXPECT_EQ(OK, out.rv); | 809 EXPECT_EQ(OK, out.rv); |
| 822 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 810 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 823 EXPECT_EQ("hello!", out.response_data); | 811 EXPECT_EQ("hello!", out.response_data); |
| 824 } | 812 } |
| 825 } | 813 } |
| 826 | 814 |
| 827 // Start three gets simultaniously; making sure that multiplexed | 815 // Start three gets simultaniously; making sure that multiplexed |
| 828 // streams work properly. | 816 // streams work properly. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 847 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); | 835 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 848 scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); | 836 scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 849 | 837 |
| 850 scoped_ptr<SpdyFrame> req3( | 838 scoped_ptr<SpdyFrame> req3( |
| 851 spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, LOWEST, true)); | 839 spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, LOWEST, true)); |
| 852 scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); | 840 scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 853 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(5, false)); | 841 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(5, false)); |
| 854 scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(5, true)); | 842 scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
| 855 | 843 |
| 856 MockWrite writes[] = { | 844 MockWrite writes[] = { |
| 857 CreateMockWrite(*req), | 845 CreateMockWrite(*req), CreateMockWrite(*req2), CreateMockWrite(*req3), |
| 858 CreateMockWrite(*req2), | |
| 859 CreateMockWrite(*req3), | |
| 860 }; | 846 }; |
| 861 MockRead reads[] = { | 847 MockRead reads[] = { |
| 862 CreateMockRead(*resp, 1), | 848 CreateMockRead(*resp, 1), CreateMockRead(*body), |
| 863 CreateMockRead(*body), | 849 CreateMockRead(*resp2, 4), CreateMockRead(*body2), |
| 864 CreateMockRead(*resp2, 4), | 850 CreateMockRead(*resp3, 7), CreateMockRead(*body3), |
| 865 CreateMockRead(*body2), | 851 CreateMockRead(*fbody), CreateMockRead(*fbody2), |
| 866 CreateMockRead(*resp3, 7), | 852 CreateMockRead(*fbody3), MockRead(ASYNC, 0, 0), // EOF |
| 867 CreateMockRead(*body3), | |
| 868 | |
| 869 CreateMockRead(*fbody), | |
| 870 CreateMockRead(*fbody2), | |
| 871 CreateMockRead(*fbody3), | |
| 872 | |
| 873 MockRead(ASYNC, 0, 0), // EOF | |
| 874 }; | 853 }; |
| 875 OrderedSocketData data(reads, arraysize(reads), | 854 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 876 writes, arraysize(writes)); | |
| 877 OrderedSocketData data_placeholder(NULL, 0, NULL, 0); | 855 OrderedSocketData data_placeholder(NULL, 0, NULL, 0); |
| 878 | 856 |
| 879 BoundNetLog log; | 857 BoundNetLog log; |
| 880 TransactionHelperResult out; | 858 TransactionHelperResult out; |
| 881 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 859 NormalSpdyTransactionHelper helper( |
| 882 BoundNetLog(), GetParam(), NULL); | 860 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 883 helper.RunPreTestSetup(); | 861 helper.RunPreTestSetup(); |
| 884 helper.AddData(&data); | 862 helper.AddData(&data); |
| 885 // We require placeholder data because three get requests are sent out, so | 863 // We require placeholder data because three get requests are sent out, so |
| 886 // there needs to be three sets of SSL connection data. | 864 // there needs to be three sets of SSL connection data. |
| 887 helper.AddData(&data_placeholder); | 865 helper.AddData(&data_placeholder); |
| 888 helper.AddData(&data_placeholder); | 866 helper.AddData(&data_placeholder); |
| 889 scoped_ptr<HttpNetworkTransaction> trans1( | 867 scoped_ptr<HttpNetworkTransaction> trans1( |
| 890 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); | 868 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
| 891 scoped_ptr<HttpNetworkTransaction> trans2( | 869 scoped_ptr<HttpNetworkTransaction> trans2( |
| 892 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); | 870 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); | 915 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 938 scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 916 scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 939 | 917 |
| 940 scoped_ptr<SpdyFrame> req2( | 918 scoped_ptr<SpdyFrame> req2( |
| 941 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); | 919 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
| 942 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); | 920 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 943 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); | 921 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 944 scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); | 922 scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 945 | 923 |
| 946 MockWrite writes[] = { | 924 MockWrite writes[] = { |
| 947 CreateMockWrite(*req), | 925 CreateMockWrite(*req), CreateMockWrite(*req2), |
| 948 CreateMockWrite(*req2), | |
| 949 }; | 926 }; |
| 950 MockRead reads[] = { | 927 MockRead reads[] = { |
| 951 CreateMockRead(*resp, 1), | 928 CreateMockRead(*resp, 1), CreateMockRead(*body), |
| 952 CreateMockRead(*body), | 929 CreateMockRead(*resp2, 4), CreateMockRead(*body2), |
| 953 CreateMockRead(*resp2, 4), | 930 CreateMockRead(*fbody), CreateMockRead(*fbody2), |
| 954 CreateMockRead(*body2), | 931 MockRead(ASYNC, 0, 0), // EOF |
| 955 CreateMockRead(*fbody), | |
| 956 CreateMockRead(*fbody2), | |
| 957 MockRead(ASYNC, 0, 0), // EOF | |
| 958 }; | 932 }; |
| 959 OrderedSocketData data(reads, arraysize(reads), | 933 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 960 writes, arraysize(writes)); | |
| 961 | 934 |
| 962 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); | 935 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 963 | 936 |
| 964 OrderedSocketData data_placeholder(NULL, 0, NULL, 0); | 937 OrderedSocketData data_placeholder(NULL, 0, NULL, 0); |
| 965 data_placeholder.set_connect_data(never_finishing_connect); | 938 data_placeholder.set_connect_data(never_finishing_connect); |
| 966 | 939 |
| 967 BoundNetLog log; | 940 BoundNetLog log; |
| 968 TransactionHelperResult out; | 941 TransactionHelperResult out; |
| 969 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 942 NormalSpdyTransactionHelper helper( |
| 970 BoundNetLog(), GetParam(), NULL); | 943 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 971 helper.RunPreTestSetup(); | 944 helper.RunPreTestSetup(); |
| 972 helper.AddData(&data); | 945 helper.AddData(&data); |
| 973 // We require placeholder data because two get requests are sent out, so | 946 // We require placeholder data because two get requests are sent out, so |
| 974 // there needs to be two sets of SSL connection data. | 947 // there needs to be two sets of SSL connection data. |
| 975 helper.AddData(&data_placeholder); | 948 helper.AddData(&data_placeholder); |
| 976 scoped_ptr<HttpNetworkTransaction> trans1( | 949 scoped_ptr<HttpNetworkTransaction> trans1( |
| 977 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); | 950 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
| 978 scoped_ptr<HttpNetworkTransaction> trans2( | 951 scoped_ptr<HttpNetworkTransaction> trans2( |
| 979 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); | 952 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
| 980 | 953 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1024 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); | 997 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1025 scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 998 scoped_ptr<SpdyFrame> fbody(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 1026 | 999 |
| 1027 scoped_ptr<SpdyFrame> req2( | 1000 scoped_ptr<SpdyFrame> req2( |
| 1028 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); | 1001 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
| 1029 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); | 1002 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1030 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); | 1003 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 1031 scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); | 1004 scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 1032 | 1005 |
| 1033 MockWrite writes[] = { | 1006 MockWrite writes[] = { |
| 1034 CreateMockWrite(*req), | 1007 CreateMockWrite(*req), CreateMockWrite(*req2), |
| 1035 CreateMockWrite(*req2), | |
| 1036 }; | 1008 }; |
| 1037 MockRead reads[] = { | 1009 MockRead reads[] = { |
| 1038 CreateMockRead(*resp, 1), | 1010 CreateMockRead(*resp, 1), CreateMockRead(*body), |
| 1039 CreateMockRead(*body), | 1011 CreateMockRead(*resp2, 4), CreateMockRead(*body2), |
| 1040 CreateMockRead(*resp2, 4), | 1012 CreateMockRead(*fbody), CreateMockRead(*fbody2), |
| 1041 CreateMockRead(*body2), | 1013 MockRead(ASYNC, 0, 0), // EOF |
| 1042 CreateMockRead(*fbody), | |
| 1043 CreateMockRead(*fbody2), | |
| 1044 MockRead(ASYNC, 0, 0), // EOF | |
| 1045 }; | 1014 }; |
| 1046 OrderedSocketData preconnect_data(reads, arraysize(reads), | 1015 OrderedSocketData preconnect_data( |
| 1047 writes, arraysize(writes)); | 1016 reads, arraysize(reads), writes, arraysize(writes)); |
| 1048 | 1017 |
| 1049 MockConnect never_finishing_connect(ASYNC, ERR_IO_PENDING); | 1018 MockConnect never_finishing_connect(ASYNC, ERR_IO_PENDING); |
| 1050 | 1019 |
| 1051 OrderedSocketData data_placeholder(NULL, 0, NULL, 0); | 1020 OrderedSocketData data_placeholder(NULL, 0, NULL, 0); |
| 1052 data_placeholder.set_connect_data(never_finishing_connect); | 1021 data_placeholder.set_connect_data(never_finishing_connect); |
| 1053 | 1022 |
| 1054 BoundNetLog log; | 1023 BoundNetLog log; |
| 1055 TransactionHelperResult out; | 1024 TransactionHelperResult out; |
| 1056 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 1025 NormalSpdyTransactionHelper helper( |
| 1057 BoundNetLog(), GetParam(), NULL); | 1026 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 1058 helper.RunPreTestSetup(); | 1027 helper.RunPreTestSetup(); |
| 1059 helper.AddData(&preconnect_data); | 1028 helper.AddData(&preconnect_data); |
| 1060 // We require placeholder data because 3 connections are attempted (first is | 1029 // We require placeholder data because 3 connections are attempted (first is |
| 1061 // the preconnect, 2nd and 3rd are the never finished connections. | 1030 // the preconnect, 2nd and 3rd are the never finished connections. |
| 1062 helper.AddData(&data_placeholder); | 1031 helper.AddData(&data_placeholder); |
| 1063 helper.AddData(&data_placeholder); | 1032 helper.AddData(&data_placeholder); |
| 1064 | 1033 |
| 1065 scoped_ptr<HttpNetworkTransaction> trans1( | 1034 scoped_ptr<HttpNetworkTransaction> trans1( |
| 1066 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); | 1035 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
| 1067 scoped_ptr<HttpNetworkTransaction> trans2( | 1036 scoped_ptr<HttpNetworkTransaction> trans2( |
| 1068 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); | 1037 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
| 1069 | 1038 |
| 1070 TestCompletionCallback callback1; | 1039 TestCompletionCallback callback1; |
| 1071 TestCompletionCallback callback2; | 1040 TestCompletionCallback callback2; |
| 1072 | 1041 |
| 1073 HttpRequestInfo httpreq = CreateGetRequest(); | 1042 HttpRequestInfo httpreq = CreateGetRequest(); |
| 1074 | 1043 |
| 1075 // Preconnect the first. | 1044 // Preconnect the first. |
| 1076 SSLConfig preconnect_ssl_config; | 1045 SSLConfig preconnect_ssl_config; |
| 1077 helper.session()->ssl_config_service()->GetSSLConfig(&preconnect_ssl_config); | 1046 helper.session()->ssl_config_service()->GetSSLConfig(&preconnect_ssl_config); |
| 1078 HttpStreamFactory* http_stream_factory = | 1047 HttpStreamFactory* http_stream_factory = |
| 1079 helper.session()->http_stream_factory(); | 1048 helper.session()->http_stream_factory(); |
| 1080 if (http_stream_factory->has_next_protos()) { | 1049 if (http_stream_factory->has_next_protos()) { |
| 1081 preconnect_ssl_config.next_protos = http_stream_factory->next_protos(); | 1050 preconnect_ssl_config.next_protos = http_stream_factory->next_protos(); |
| 1082 } | 1051 } |
| 1083 | 1052 |
| 1084 http_stream_factory->PreconnectStreams( | 1053 http_stream_factory->PreconnectStreams(1, |
| 1085 1, httpreq, DEFAULT_PRIORITY, | 1054 httpreq, |
| 1086 preconnect_ssl_config, preconnect_ssl_config); | 1055 DEFAULT_PRIORITY, |
| 1056 preconnect_ssl_config, |
| 1057 preconnect_ssl_config); |
| 1087 | 1058 |
| 1088 out.rv = trans1->Start(&httpreq, callback1.callback(), log); | 1059 out.rv = trans1->Start(&httpreq, callback1.callback(), log); |
| 1089 ASSERT_EQ(ERR_IO_PENDING, out.rv); | 1060 ASSERT_EQ(ERR_IO_PENDING, out.rv); |
| 1090 out.rv = trans2->Start(&httpreq, callback2.callback(), log); | 1061 out.rv = trans2->Start(&httpreq, callback2.callback(), log); |
| 1091 ASSERT_EQ(ERR_IO_PENDING, out.rv); | 1062 ASSERT_EQ(ERR_IO_PENDING, out.rv); |
| 1092 | 1063 |
| 1093 out.rv = callback1.WaitForResult(); | 1064 out.rv = callback1.WaitForResult(); |
| 1094 ASSERT_EQ(OK, out.rv); | 1065 ASSERT_EQ(OK, out.rv); |
| 1095 out.rv = callback2.WaitForResult(); | 1066 out.rv = callback2.WaitForResult(); |
| 1096 ASSERT_EQ(OK, out.rv); | 1067 ASSERT_EQ(OK, out.rv); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1144 scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(5, true)); | 1115 scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
| 1145 | 1116 |
| 1146 SettingsMap settings; | 1117 SettingsMap settings; |
| 1147 const uint32 max_concurrent_streams = 1; | 1118 const uint32 max_concurrent_streams = 1; |
| 1148 settings[SETTINGS_MAX_CONCURRENT_STREAMS] = | 1119 settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1149 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); | 1120 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
| 1150 scoped_ptr<SpdyFrame> settings_frame( | 1121 scoped_ptr<SpdyFrame> settings_frame( |
| 1151 spdy_util_.ConstructSpdySettings(settings)); | 1122 spdy_util_.ConstructSpdySettings(settings)); |
| 1152 | 1123 |
| 1153 MockWrite writes[] = { | 1124 MockWrite writes[] = { |
| 1154 CreateMockWrite(*req), | 1125 CreateMockWrite(*req), CreateMockWrite(*req2), CreateMockWrite(*req3), |
| 1155 CreateMockWrite(*req2), | |
| 1156 CreateMockWrite(*req3), | |
| 1157 }; | 1126 }; |
| 1158 | 1127 |
| 1159 MockRead reads[] = { | 1128 MockRead reads[] = { |
| 1160 CreateMockRead(*settings_frame, 1), | 1129 CreateMockRead(*settings_frame, 1), CreateMockRead(*resp), |
| 1161 CreateMockRead(*resp), | 1130 CreateMockRead(*body), CreateMockRead(*fbody), |
| 1162 CreateMockRead(*body), | 1131 CreateMockRead(*resp2, 7), CreateMockRead(*body2), |
| 1163 CreateMockRead(*fbody), | 1132 CreateMockRead(*fbody2), CreateMockRead(*resp3, 12), |
| 1164 CreateMockRead(*resp2, 7), | 1133 CreateMockRead(*body3), CreateMockRead(*fbody3), |
| 1165 CreateMockRead(*body2), | 1134 MockRead(ASYNC, 0, 0), // EOF |
| 1166 CreateMockRead(*fbody2), | |
| 1167 CreateMockRead(*resp3, 12), | |
| 1168 CreateMockRead(*body3), | |
| 1169 CreateMockRead(*fbody3), | |
| 1170 | |
| 1171 MockRead(ASYNC, 0, 0), // EOF | |
| 1172 }; | 1135 }; |
| 1173 | 1136 |
| 1174 OrderedSocketData data(reads, arraysize(reads), | 1137 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 1175 writes, arraysize(writes)); | |
| 1176 OrderedSocketData data_placeholder(NULL, 0, NULL, 0); | 1138 OrderedSocketData data_placeholder(NULL, 0, NULL, 0); |
| 1177 | 1139 |
| 1178 BoundNetLog log; | 1140 BoundNetLog log; |
| 1179 TransactionHelperResult out; | 1141 TransactionHelperResult out; |
| 1180 { | 1142 { |
| 1181 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 1143 NormalSpdyTransactionHelper helper( |
| 1182 BoundNetLog(), GetParam(), NULL); | 1144 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 1183 helper.RunPreTestSetup(); | 1145 helper.RunPreTestSetup(); |
| 1184 helper.AddData(&data); | 1146 helper.AddData(&data); |
| 1185 // We require placeholder data because three get requests are sent out, so | 1147 // We require placeholder data because three get requests are sent out, so |
| 1186 // there needs to be three sets of SSL connection data. | 1148 // there needs to be three sets of SSL connection data. |
| 1187 helper.AddData(&data_placeholder); | 1149 helper.AddData(&data_placeholder); |
| 1188 helper.AddData(&data_placeholder); | 1150 helper.AddData(&data_placeholder); |
| 1189 scoped_ptr<HttpNetworkTransaction> trans1( | 1151 scoped_ptr<HttpNetworkTransaction> trans1( |
| 1190 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); | 1152 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
| 1191 scoped_ptr<HttpNetworkTransaction> trans2( | 1153 scoped_ptr<HttpNetworkTransaction> trans2( |
| 1192 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); | 1154 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1281 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(7, false)); | 1243 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(7, false)); |
| 1282 scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(7, true)); | 1244 scoped_ptr<SpdyFrame> fbody3(spdy_util_.ConstructSpdyBodyFrame(7, true)); |
| 1283 | 1245 |
| 1284 SettingsMap settings; | 1246 SettingsMap settings; |
| 1285 const uint32 max_concurrent_streams = 1; | 1247 const uint32 max_concurrent_streams = 1; |
| 1286 settings[SETTINGS_MAX_CONCURRENT_STREAMS] = | 1248 settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1287 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); | 1249 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
| 1288 scoped_ptr<SpdyFrame> settings_frame( | 1250 scoped_ptr<SpdyFrame> settings_frame( |
| 1289 spdy_util_.ConstructSpdySettings(settings)); | 1251 spdy_util_.ConstructSpdySettings(settings)); |
| 1290 | 1252 |
| 1291 MockWrite writes[] = { CreateMockWrite(*req), | 1253 MockWrite writes[] = { |
| 1292 CreateMockWrite(*req2), | 1254 CreateMockWrite(*req), CreateMockWrite(*req2), CreateMockWrite(*req4), |
| 1293 CreateMockWrite(*req4), | 1255 CreateMockWrite(*req3), |
| 1294 CreateMockWrite(*req3), | |
| 1295 }; | 1256 }; |
| 1296 MockRead reads[] = { | 1257 MockRead reads[] = { |
| 1297 CreateMockRead(*settings_frame, 1), | 1258 CreateMockRead(*settings_frame, 1), CreateMockRead(*resp), |
| 1298 CreateMockRead(*resp), | 1259 CreateMockRead(*body), CreateMockRead(*fbody), |
| 1299 CreateMockRead(*body), | 1260 CreateMockRead(*resp2, 7), CreateMockRead(*body2), |
| 1300 CreateMockRead(*fbody), | 1261 CreateMockRead(*fbody2), CreateMockRead(*resp4, 13), |
| 1301 CreateMockRead(*resp2, 7), | 1262 CreateMockRead(*fbody4), CreateMockRead(*resp3, 16), |
| 1302 CreateMockRead(*body2), | 1263 CreateMockRead(*body3), CreateMockRead(*fbody3), |
| 1303 CreateMockRead(*fbody2), | 1264 MockRead(ASYNC, 0, 0), // EOF |
| 1304 CreateMockRead(*resp4, 13), | |
| 1305 CreateMockRead(*fbody4), | |
| 1306 CreateMockRead(*resp3, 16), | |
| 1307 CreateMockRead(*body3), | |
| 1308 CreateMockRead(*fbody3), | |
| 1309 | |
| 1310 MockRead(ASYNC, 0, 0), // EOF | |
| 1311 }; | 1265 }; |
| 1312 | 1266 |
| 1313 OrderedSocketData data(reads, arraysize(reads), | 1267 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 1314 writes, arraysize(writes)); | |
| 1315 OrderedSocketData data_placeholder(NULL, 0, NULL, 0); | 1268 OrderedSocketData data_placeholder(NULL, 0, NULL, 0); |
| 1316 | 1269 |
| 1317 BoundNetLog log; | 1270 BoundNetLog log; |
| 1318 TransactionHelperResult out; | 1271 TransactionHelperResult out; |
| 1319 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 1272 NormalSpdyTransactionHelper helper( |
| 1320 BoundNetLog(), GetParam(), NULL); | 1273 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 1321 helper.RunPreTestSetup(); | 1274 helper.RunPreTestSetup(); |
| 1322 helper.AddData(&data); | 1275 helper.AddData(&data); |
| 1323 // We require placeholder data because four get requests are sent out, so | 1276 // We require placeholder data because four get requests are sent out, so |
| 1324 // there needs to be four sets of SSL connection data. | 1277 // there needs to be four sets of SSL connection data. |
| 1325 helper.AddData(&data_placeholder); | 1278 helper.AddData(&data_placeholder); |
| 1326 helper.AddData(&data_placeholder); | 1279 helper.AddData(&data_placeholder); |
| 1327 helper.AddData(&data_placeholder); | 1280 helper.AddData(&data_placeholder); |
| 1328 scoped_ptr<HttpNetworkTransaction> trans1( | 1281 scoped_ptr<HttpNetworkTransaction> trans1( |
| 1329 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); | 1282 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
| 1330 scoped_ptr<HttpNetworkTransaction> trans2( | 1283 scoped_ptr<HttpNetworkTransaction> trans2( |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); | 1376 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, false)); |
| 1424 scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); | 1377 scoped_ptr<SpdyFrame> fbody2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 1425 | 1378 |
| 1426 SettingsMap settings; | 1379 SettingsMap settings; |
| 1427 const uint32 max_concurrent_streams = 1; | 1380 const uint32 max_concurrent_streams = 1; |
| 1428 settings[SETTINGS_MAX_CONCURRENT_STREAMS] = | 1381 settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1429 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); | 1382 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
| 1430 scoped_ptr<SpdyFrame> settings_frame( | 1383 scoped_ptr<SpdyFrame> settings_frame( |
| 1431 spdy_util_.ConstructSpdySettings(settings)); | 1384 spdy_util_.ConstructSpdySettings(settings)); |
| 1432 | 1385 |
| 1433 MockWrite writes[] = { CreateMockWrite(*req), | 1386 MockWrite writes[] = { |
| 1434 CreateMockWrite(*req2), | 1387 CreateMockWrite(*req), CreateMockWrite(*req2), |
| 1435 }; | 1388 }; |
| 1436 MockRead reads[] = { | 1389 MockRead reads[] = { |
| 1437 CreateMockRead(*settings_frame, 1), | 1390 CreateMockRead(*settings_frame, 1), CreateMockRead(*resp), |
| 1438 CreateMockRead(*resp), | 1391 CreateMockRead(*body), CreateMockRead(*fbody), |
| 1439 CreateMockRead(*body), | 1392 CreateMockRead(*resp2, 7), CreateMockRead(*body2), |
| 1440 CreateMockRead(*fbody), | 1393 CreateMockRead(*fbody2), MockRead(ASYNC, 0, 0), // EOF |
| 1441 CreateMockRead(*resp2, 7), | |
| 1442 CreateMockRead(*body2), | |
| 1443 CreateMockRead(*fbody2), | |
| 1444 MockRead(ASYNC, 0, 0), // EOF | |
| 1445 }; | 1394 }; |
| 1446 | 1395 |
| 1447 OrderedSocketData data(reads, arraysize(reads), | 1396 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 1448 writes, arraysize(writes)); | |
| 1449 OrderedSocketData data_placeholder(NULL, 0, NULL, 0); | 1397 OrderedSocketData data_placeholder(NULL, 0, NULL, 0); |
| 1450 | 1398 |
| 1451 BoundNetLog log; | 1399 BoundNetLog log; |
| 1452 TransactionHelperResult out; | 1400 TransactionHelperResult out; |
| 1453 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 1401 NormalSpdyTransactionHelper helper( |
| 1454 BoundNetLog(), GetParam(), NULL); | 1402 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 1455 helper.RunPreTestSetup(); | 1403 helper.RunPreTestSetup(); |
| 1456 helper.AddData(&data); | 1404 helper.AddData(&data); |
| 1457 // We require placeholder data because three get requests are sent out, so | 1405 // We require placeholder data because three get requests are sent out, so |
| 1458 // there needs to be three sets of SSL connection data. | 1406 // there needs to be three sets of SSL connection data. |
| 1459 helper.AddData(&data_placeholder); | 1407 helper.AddData(&data_placeholder); |
| 1460 helper.AddData(&data_placeholder); | 1408 helper.AddData(&data_placeholder); |
| 1461 scoped_ptr<HttpNetworkTransaction> trans1( | 1409 scoped_ptr<HttpNetworkTransaction> trans1( |
| 1462 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); | 1410 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
| 1463 scoped_ptr<HttpNetworkTransaction> trans2( | 1411 scoped_ptr<HttpNetworkTransaction> trans2( |
| 1464 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); | 1412 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1513 } | 1461 } |
| 1514 | 1462 |
| 1515 namespace { | 1463 namespace { |
| 1516 | 1464 |
| 1517 // The KillerCallback will delete the transaction on error as part of the | 1465 // The KillerCallback will delete the transaction on error as part of the |
| 1518 // callback. | 1466 // callback. |
| 1519 class KillerCallback : public TestCompletionCallbackBase { | 1467 class KillerCallback : public TestCompletionCallbackBase { |
| 1520 public: | 1468 public: |
| 1521 explicit KillerCallback(HttpNetworkTransaction* transaction) | 1469 explicit KillerCallback(HttpNetworkTransaction* transaction) |
| 1522 : transaction_(transaction), | 1470 : transaction_(transaction), |
| 1523 callback_(base::Bind(&KillerCallback::OnComplete, | 1471 callback_( |
| 1524 base::Unretained(this))) { | 1472 base::Bind(&KillerCallback::OnComplete, base::Unretained(this))) {} |
| 1525 } | |
| 1526 | 1473 |
| 1527 virtual ~KillerCallback() {} | 1474 virtual ~KillerCallback() {} |
| 1528 | 1475 |
| 1529 const CompletionCallback& callback() const { return callback_; } | 1476 const CompletionCallback& callback() const { return callback_; } |
| 1530 | 1477 |
| 1531 private: | 1478 private: |
| 1532 void OnComplete(int result) { | 1479 void OnComplete(int result) { |
| 1533 if (result < 0) | 1480 if (result < 0) |
| 1534 delete transaction_; | 1481 delete transaction_; |
| 1535 | 1482 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1557 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); | 1504 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
| 1558 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); | 1505 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1559 | 1506 |
| 1560 SettingsMap settings; | 1507 SettingsMap settings; |
| 1561 const uint32 max_concurrent_streams = 1; | 1508 const uint32 max_concurrent_streams = 1; |
| 1562 settings[SETTINGS_MAX_CONCURRENT_STREAMS] = | 1509 settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1563 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); | 1510 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
| 1564 scoped_ptr<SpdyFrame> settings_frame( | 1511 scoped_ptr<SpdyFrame> settings_frame( |
| 1565 spdy_util_.ConstructSpdySettings(settings)); | 1512 spdy_util_.ConstructSpdySettings(settings)); |
| 1566 | 1513 |
| 1567 MockWrite writes[] = { CreateMockWrite(*req), | 1514 MockWrite writes[] = { |
| 1568 CreateMockWrite(*req2), | 1515 CreateMockWrite(*req), CreateMockWrite(*req2), |
| 1569 }; | 1516 }; |
| 1570 MockRead reads[] = { | 1517 MockRead reads[] = { |
| 1571 CreateMockRead(*settings_frame, 1), | 1518 CreateMockRead(*settings_frame, 1), |
| 1572 CreateMockRead(*resp), | 1519 CreateMockRead(*resp), |
| 1573 CreateMockRead(*body), | 1520 CreateMockRead(*body), |
| 1574 CreateMockRead(*fin_body), | 1521 CreateMockRead(*fin_body), |
| 1575 CreateMockRead(*resp2, 7), | 1522 CreateMockRead(*resp2, 7), |
| 1576 MockRead(ASYNC, ERR_CONNECTION_RESET, 0), // Abort! | 1523 MockRead(ASYNC, ERR_CONNECTION_RESET, 0), // Abort! |
| 1577 }; | 1524 }; |
| 1578 | 1525 |
| 1579 OrderedSocketData data(reads, arraysize(reads), | 1526 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 1580 writes, arraysize(writes)); | |
| 1581 OrderedSocketData data_placeholder(NULL, 0, NULL, 0); | 1527 OrderedSocketData data_placeholder(NULL, 0, NULL, 0); |
| 1582 | 1528 |
| 1583 BoundNetLog log; | 1529 BoundNetLog log; |
| 1584 TransactionHelperResult out; | 1530 TransactionHelperResult out; |
| 1585 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 1531 NormalSpdyTransactionHelper helper( |
| 1586 BoundNetLog(), GetParam(), NULL); | 1532 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 1587 helper.RunPreTestSetup(); | 1533 helper.RunPreTestSetup(); |
| 1588 helper.AddData(&data); | 1534 helper.AddData(&data); |
| 1589 // We require placeholder data because three get requests are sent out, so | 1535 // We require placeholder data because three get requests are sent out, so |
| 1590 // there needs to be three sets of SSL connection data. | 1536 // there needs to be three sets of SSL connection data. |
| 1591 helper.AddData(&data_placeholder); | 1537 helper.AddData(&data_placeholder); |
| 1592 helper.AddData(&data_placeholder); | 1538 helper.AddData(&data_placeholder); |
| 1593 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session().get()); | 1539 HttpNetworkTransaction trans1(DEFAULT_PRIORITY, helper.session().get()); |
| 1594 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session().get()); | 1540 HttpNetworkTransaction trans2(DEFAULT_PRIORITY, helper.session().get()); |
| 1595 HttpNetworkTransaction* trans3( | 1541 HttpNetworkTransaction* trans3( |
| 1596 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); | 1542 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1638 } | 1584 } |
| 1639 | 1585 |
| 1640 // Test that a simple PUT request works. | 1586 // Test that a simple PUT request works. |
| 1641 TEST_P(SpdyNetworkTransactionTest, Put) { | 1587 TEST_P(SpdyNetworkTransactionTest, Put) { |
| 1642 // Setup the request | 1588 // Setup the request |
| 1643 HttpRequestInfo request; | 1589 HttpRequestInfo request; |
| 1644 request.method = "PUT"; | 1590 request.method = "PUT"; |
| 1645 request.url = GURL("http://www.google.com/"); | 1591 request.url = GURL("http://www.google.com/"); |
| 1646 | 1592 |
| 1647 const SpdyHeaderInfo kSynStartHeader = { | 1593 const SpdyHeaderInfo kSynStartHeader = { |
| 1648 SYN_STREAM, // Kind = Syn | 1594 SYN_STREAM, // Kind = Syn |
| 1649 1, // Stream ID | 1595 1, // Stream ID |
| 1650 0, // Associated stream ID | 1596 0, // Associated stream ID |
| 1651 ConvertRequestPriorityToSpdyPriority( | 1597 ConvertRequestPriorityToSpdyPriority(LOWEST, spdy_util_.spdy_version()), |
| 1652 LOWEST, spdy_util_.spdy_version()), | 1598 kSpdyCredentialSlotUnused, |
| 1653 kSpdyCredentialSlotUnused, | 1599 CONTROL_FLAG_FIN, // Control Flags |
| 1654 CONTROL_FLAG_FIN, // Control Flags | 1600 false, // Compressed |
| 1655 false, // Compressed | 1601 RST_STREAM_INVALID, // Status |
| 1656 RST_STREAM_INVALID, // Status | 1602 NULL, // Data |
| 1657 NULL, // Data | 1603 0, // Length |
| 1658 0, // Length | 1604 DATA_FLAG_NONE // Data Flags |
| 1659 DATA_FLAG_NONE // Data Flags | |
| 1660 }; | 1605 }; |
| 1661 scoped_ptr<SpdyHeaderBlock> put_headers( | 1606 scoped_ptr<SpdyHeaderBlock> put_headers( |
| 1662 spdy_util_.ConstructPutHeaderBlock("http://www.google.com", 0)); | 1607 spdy_util_.ConstructPutHeaderBlock("http://www.google.com", 0)); |
| 1663 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyFrame( | 1608 scoped_ptr<SpdyFrame> req( |
| 1664 kSynStartHeader, put_headers.Pass())); | 1609 spdy_util_.ConstructSpdyFrame(kSynStartHeader, put_headers.Pass())); |
| 1665 MockWrite writes[] = { | 1610 MockWrite writes[] = { |
| 1666 CreateMockWrite(*req), | 1611 CreateMockWrite(*req), |
| 1667 }; | 1612 }; |
| 1668 | 1613 |
| 1669 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 1614 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 1670 const SpdyHeaderInfo kSynReplyHeader = { | 1615 const SpdyHeaderInfo kSynReplyHeader = { |
| 1671 SYN_REPLY, // Kind = SynReply | 1616 SYN_REPLY, // Kind = SynReply |
| 1672 1, // Stream ID | 1617 1, // Stream ID |
| 1673 0, // Associated stream ID | 1618 0, // Associated stream ID |
| 1674 ConvertRequestPriorityToSpdyPriority( | 1619 ConvertRequestPriorityToSpdyPriority(LOWEST, spdy_util_.spdy_version()), |
| 1675 LOWEST, spdy_util_.spdy_version()), | 1620 kSpdyCredentialSlotUnused, |
| 1676 kSpdyCredentialSlotUnused, | 1621 CONTROL_FLAG_NONE, // Control Flags |
| 1677 CONTROL_FLAG_NONE, // Control Flags | 1622 false, // Compressed |
| 1678 false, // Compressed | 1623 RST_STREAM_INVALID, // Status |
| 1679 RST_STREAM_INVALID, // Status | 1624 NULL, // Data |
| 1680 NULL, // Data | 1625 0, // Length |
| 1681 0, // Length | 1626 DATA_FLAG_NONE // Data Flags |
| 1682 DATA_FLAG_NONE // Data Flags | |
| 1683 }; | 1627 }; |
| 1684 scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); | 1628 scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); |
| 1685 (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; | 1629 (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 1686 (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | 1630 (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
| 1687 (*reply_headers)["content-length"] = "1234"; | 1631 (*reply_headers)["content-length"] = "1234"; |
| 1688 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyFrame( | 1632 scoped_ptr<SpdyFrame> resp( |
| 1689 kSynReplyHeader, reply_headers.Pass())); | 1633 spdy_util_.ConstructSpdyFrame(kSynReplyHeader, reply_headers.Pass())); |
| 1690 MockRead reads[] = { | 1634 MockRead reads[] = { |
| 1691 CreateMockRead(*resp), | 1635 CreateMockRead(*resp), CreateMockRead(*body), |
| 1692 CreateMockRead(*body), | 1636 MockRead(ASYNC, 0, 0) // EOF |
| 1693 MockRead(ASYNC, 0, 0) // EOF | |
| 1694 }; | 1637 }; |
| 1695 | 1638 |
| 1696 DelayedSocketData data(1, reads, arraysize(reads), | 1639 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 1697 writes, arraysize(writes)); | 1640 NormalSpdyTransactionHelper helper( |
| 1698 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, | 1641 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 1699 BoundNetLog(), GetParam(), NULL); | |
| 1700 helper.RunToCompletion(&data); | 1642 helper.RunToCompletion(&data); |
| 1701 TransactionHelperResult out = helper.output(); | 1643 TransactionHelperResult out = helper.output(); |
| 1702 | 1644 |
| 1703 EXPECT_EQ(OK, out.rv); | 1645 EXPECT_EQ(OK, out.rv); |
| 1704 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1646 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1705 } | 1647 } |
| 1706 | 1648 |
| 1707 // Test that a simple HEAD request works. | 1649 // Test that a simple HEAD request works. |
| 1708 TEST_P(SpdyNetworkTransactionTest, Head) { | 1650 TEST_P(SpdyNetworkTransactionTest, Head) { |
| 1709 // Setup the request | 1651 // Setup the request |
| 1710 HttpRequestInfo request; | 1652 HttpRequestInfo request; |
| 1711 request.method = "HEAD"; | 1653 request.method = "HEAD"; |
| 1712 request.url = GURL("http://www.google.com/"); | 1654 request.url = GURL("http://www.google.com/"); |
| 1713 | 1655 |
| 1714 const SpdyHeaderInfo kSynStartHeader = { | 1656 const SpdyHeaderInfo kSynStartHeader = { |
| 1715 SYN_STREAM, // Kind = Syn | 1657 SYN_STREAM, // Kind = Syn |
| 1716 1, // Stream ID | 1658 1, // Stream ID |
| 1717 0, // Associated stream ID | 1659 0, // Associated stream ID |
| 1718 ConvertRequestPriorityToSpdyPriority( | 1660 ConvertRequestPriorityToSpdyPriority(LOWEST, spdy_util_.spdy_version()), |
| 1719 LOWEST, spdy_util_.spdy_version()), | 1661 kSpdyCredentialSlotUnused, |
| 1720 kSpdyCredentialSlotUnused, | 1662 CONTROL_FLAG_FIN, // Control Flags |
| 1721 CONTROL_FLAG_FIN, // Control Flags | 1663 false, // Compressed |
| 1722 false, // Compressed | 1664 RST_STREAM_INVALID, // Status |
| 1723 RST_STREAM_INVALID, // Status | 1665 NULL, // Data |
| 1724 NULL, // Data | 1666 0, // Length |
| 1725 0, // Length | 1667 DATA_FLAG_NONE // Data Flags |
| 1726 DATA_FLAG_NONE // Data Flags | |
| 1727 }; | 1668 }; |
| 1728 scoped_ptr<SpdyHeaderBlock> head_headers( | 1669 scoped_ptr<SpdyHeaderBlock> head_headers( |
| 1729 spdy_util_.ConstructHeadHeaderBlock("http://www.google.com", 0)); | 1670 spdy_util_.ConstructHeadHeaderBlock("http://www.google.com", 0)); |
| 1730 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyFrame( | 1671 scoped_ptr<SpdyFrame> req( |
| 1731 kSynStartHeader, head_headers.Pass())); | 1672 spdy_util_.ConstructSpdyFrame(kSynStartHeader, head_headers.Pass())); |
| 1732 MockWrite writes[] = { | 1673 MockWrite writes[] = { |
| 1733 CreateMockWrite(*req), | 1674 CreateMockWrite(*req), |
| 1734 }; | 1675 }; |
| 1735 | 1676 |
| 1736 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 1677 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 1737 const SpdyHeaderInfo kSynReplyHeader = { | 1678 const SpdyHeaderInfo kSynReplyHeader = { |
| 1738 SYN_REPLY, // Kind = SynReply | 1679 SYN_REPLY, // Kind = SynReply |
| 1739 1, // Stream ID | 1680 1, // Stream ID |
| 1740 0, // Associated stream ID | 1681 0, // Associated stream ID |
| 1741 ConvertRequestPriorityToSpdyPriority( | 1682 ConvertRequestPriorityToSpdyPriority(LOWEST, spdy_util_.spdy_version()), |
| 1742 LOWEST, spdy_util_.spdy_version()), | 1683 kSpdyCredentialSlotUnused, |
| 1743 kSpdyCredentialSlotUnused, | 1684 CONTROL_FLAG_NONE, // Control Flags |
| 1744 CONTROL_FLAG_NONE, // Control Flags | 1685 false, // Compressed |
| 1745 false, // Compressed | 1686 RST_STREAM_INVALID, // Status |
| 1746 RST_STREAM_INVALID, // Status | 1687 NULL, // Data |
| 1747 NULL, // Data | 1688 0, // Length |
| 1748 0, // Length | 1689 DATA_FLAG_NONE // Data Flags |
| 1749 DATA_FLAG_NONE // Data Flags | |
| 1750 }; | 1690 }; |
| 1751 scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); | 1691 scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); |
| 1752 (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; | 1692 (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 1753 (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | 1693 (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
| 1754 (*reply_headers)["content-length"] = "1234"; | 1694 (*reply_headers)["content-length"] = "1234"; |
| 1755 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyFrame( | 1695 scoped_ptr<SpdyFrame> resp( |
| 1756 kSynReplyHeader, | 1696 spdy_util_.ConstructSpdyFrame(kSynReplyHeader, reply_headers.Pass())); |
| 1757 reply_headers.Pass())); | |
| 1758 MockRead reads[] = { | 1697 MockRead reads[] = { |
| 1759 CreateMockRead(*resp), | 1698 CreateMockRead(*resp), CreateMockRead(*body), |
| 1760 CreateMockRead(*body), | 1699 MockRead(ASYNC, 0, 0) // EOF |
| 1761 MockRead(ASYNC, 0, 0) // EOF | |
| 1762 }; | 1700 }; |
| 1763 | 1701 |
| 1764 DelayedSocketData data(1, reads, arraysize(reads), | 1702 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 1765 writes, arraysize(writes)); | 1703 NormalSpdyTransactionHelper helper( |
| 1766 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, | 1704 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 1767 BoundNetLog(), GetParam(), NULL); | |
| 1768 helper.RunToCompletion(&data); | 1705 helper.RunToCompletion(&data); |
| 1769 TransactionHelperResult out = helper.output(); | 1706 TransactionHelperResult out = helper.output(); |
| 1770 | 1707 |
| 1771 EXPECT_EQ(OK, out.rv); | 1708 EXPECT_EQ(OK, out.rv); |
| 1772 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1709 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1773 } | 1710 } |
| 1774 | 1711 |
| 1775 // Test that a simple POST works. | 1712 // Test that a simple POST works. |
| 1776 TEST_P(SpdyNetworkTransactionTest, Post) { | 1713 TEST_P(SpdyNetworkTransactionTest, Post) { |
| 1777 scoped_ptr<SpdyFrame> req( | 1714 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 1778 spdy_util_.ConstructSpdyPost( | 1715 kRequestUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); |
| 1779 kRequestUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); | |
| 1780 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 1716 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 1781 MockWrite writes[] = { | 1717 MockWrite writes[] = { |
| 1782 CreateMockWrite(*req), | 1718 CreateMockWrite(*req), |
| 1783 CreateMockWrite(*body), // POST upload frame | 1719 CreateMockWrite(*body), // POST upload frame |
| 1784 }; | 1720 }; |
| 1785 | 1721 |
| 1786 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 1722 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 1787 MockRead reads[] = { | 1723 MockRead reads[] = { |
| 1788 CreateMockRead(*resp), | 1724 CreateMockRead(*resp), CreateMockRead(*body), |
| 1789 CreateMockRead(*body), | 1725 MockRead(ASYNC, 0, 0) // EOF |
| 1790 MockRead(ASYNC, 0, 0) // EOF | |
| 1791 }; | 1726 }; |
| 1792 | 1727 |
| 1793 DelayedSocketData data(2, reads, arraysize(reads), | 1728 DelayedSocketData data(2, reads, arraysize(reads), writes, arraysize(writes)); |
| 1794 writes, arraysize(writes)); | 1729 NormalSpdyTransactionHelper helper( |
| 1795 NormalSpdyTransactionHelper helper(CreatePostRequest(), DEFAULT_PRIORITY, | 1730 CreatePostRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 1796 BoundNetLog(), GetParam(), NULL); | |
| 1797 helper.RunToCompletion(&data); | 1731 helper.RunToCompletion(&data); |
| 1798 TransactionHelperResult out = helper.output(); | 1732 TransactionHelperResult out = helper.output(); |
| 1799 EXPECT_EQ(OK, out.rv); | 1733 EXPECT_EQ(OK, out.rv); |
| 1800 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1734 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1801 EXPECT_EQ("hello!", out.response_data); | 1735 EXPECT_EQ("hello!", out.response_data); |
| 1802 } | 1736 } |
| 1803 | 1737 |
| 1804 // Test that a POST with a file works. | 1738 // Test that a POST with a file works. |
| 1805 TEST_P(SpdyNetworkTransactionTest, FilePost) { | 1739 TEST_P(SpdyNetworkTransactionTest, FilePost) { |
| 1806 scoped_ptr<SpdyFrame> req( | 1740 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 1807 spdy_util_.ConstructSpdyPost( | 1741 kRequestUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); |
| 1808 kRequestUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); | |
| 1809 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 1742 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 1810 MockWrite writes[] = { | 1743 MockWrite writes[] = { |
| 1811 CreateMockWrite(*req), | 1744 CreateMockWrite(*req), |
| 1812 CreateMockWrite(*body), // POST upload frame | 1745 CreateMockWrite(*body), // POST upload frame |
| 1813 }; | 1746 }; |
| 1814 | 1747 |
| 1815 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 1748 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 1816 MockRead reads[] = { | 1749 MockRead reads[] = { |
| 1817 CreateMockRead(*resp), | 1750 CreateMockRead(*resp), CreateMockRead(*body), |
| 1818 CreateMockRead(*body), | 1751 MockRead(ASYNC, 0, 0) // EOF |
| 1819 MockRead(ASYNC, 0, 0) // EOF | |
| 1820 }; | 1752 }; |
| 1821 | 1753 |
| 1822 DelayedSocketData data(2, reads, arraysize(reads), | 1754 DelayedSocketData data(2, reads, arraysize(reads), writes, arraysize(writes)); |
| 1823 writes, arraysize(writes)); | 1755 NormalSpdyTransactionHelper helper(CreateFilePostRequest(), |
| 1824 NormalSpdyTransactionHelper helper(CreateFilePostRequest(), DEFAULT_PRIORITY, | 1756 DEFAULT_PRIORITY, |
| 1825 BoundNetLog(), GetParam(), NULL); | 1757 BoundNetLog(), |
| 1758 GetParam(), |
| 1759 NULL); |
| 1826 helper.RunToCompletion(&data); | 1760 helper.RunToCompletion(&data); |
| 1827 TransactionHelperResult out = helper.output(); | 1761 TransactionHelperResult out = helper.output(); |
| 1828 EXPECT_EQ(OK, out.rv); | 1762 EXPECT_EQ(OK, out.rv); |
| 1829 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1763 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1830 EXPECT_EQ("hello!", out.response_data); | 1764 EXPECT_EQ("hello!", out.response_data); |
| 1831 } | 1765 } |
| 1832 | 1766 |
| 1833 // Test that a POST with a unreadable file fails. | 1767 // Test that a POST with a unreadable file fails. |
| 1834 TEST_P(SpdyNetworkTransactionTest, UnreadableFilePost) { | 1768 TEST_P(SpdyNetworkTransactionTest, UnreadableFilePost) { |
| 1835 MockWrite writes[] = { | 1769 MockWrite writes[] = { |
| 1836 MockWrite(ASYNC, 0, 0) // EOF | 1770 MockWrite(ASYNC, 0, 0) // EOF |
| 1837 }; | 1771 }; |
| 1838 MockRead reads[] = { | 1772 MockRead reads[] = { |
| 1839 MockRead(ASYNC, 0, 0) // EOF | 1773 MockRead(ASYNC, 0, 0) // EOF |
| 1840 }; | 1774 }; |
| 1841 | 1775 |
| 1842 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); | 1776 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 1843 NormalSpdyTransactionHelper helper(CreateUnreadableFilePostRequest(), | 1777 NormalSpdyTransactionHelper helper(CreateUnreadableFilePostRequest(), |
| 1844 DEFAULT_PRIORITY, | 1778 DEFAULT_PRIORITY, |
| 1845 BoundNetLog(), GetParam(), NULL); | 1779 BoundNetLog(), |
| 1780 GetParam(), |
| 1781 NULL); |
| 1846 helper.RunPreTestSetup(); | 1782 helper.RunPreTestSetup(); |
| 1847 helper.AddData(&data); | 1783 helper.AddData(&data); |
| 1848 helper.RunDefaultTest(); | 1784 helper.RunDefaultTest(); |
| 1849 | 1785 |
| 1850 base::RunLoop().RunUntilIdle(); | 1786 base::RunLoop().RunUntilIdle(); |
| 1851 helper.VerifyDataNotConsumed(); | 1787 helper.VerifyDataNotConsumed(); |
| 1852 EXPECT_EQ(ERR_ACCESS_DENIED, helper.output().rv); | 1788 EXPECT_EQ(ERR_ACCESS_DENIED, helper.output().rv); |
| 1853 } | 1789 } |
| 1854 | 1790 |
| 1855 // Test that a complex POST works. | 1791 // Test that a complex POST works. |
| 1856 TEST_P(SpdyNetworkTransactionTest, ComplexPost) { | 1792 TEST_P(SpdyNetworkTransactionTest, ComplexPost) { |
| 1857 scoped_ptr<SpdyFrame> req( | 1793 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 1858 spdy_util_.ConstructSpdyPost( | 1794 kRequestUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); |
| 1859 kRequestUrl, 1, kUploadDataSize, LOWEST, NULL, 0)); | |
| 1860 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 1795 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 1861 MockWrite writes[] = { | 1796 MockWrite writes[] = { |
| 1862 CreateMockWrite(*req), | 1797 CreateMockWrite(*req), |
| 1863 CreateMockWrite(*body), // POST upload frame | 1798 CreateMockWrite(*body), // POST upload frame |
| 1864 }; | 1799 }; |
| 1865 | 1800 |
| 1866 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 1801 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 1867 MockRead reads[] = { | 1802 MockRead reads[] = { |
| 1868 CreateMockRead(*resp), | 1803 CreateMockRead(*resp), CreateMockRead(*body), |
| 1869 CreateMockRead(*body), | 1804 MockRead(ASYNC, 0, 0) // EOF |
| 1870 MockRead(ASYNC, 0, 0) // EOF | |
| 1871 }; | 1805 }; |
| 1872 | 1806 |
| 1873 DelayedSocketData data(2, reads, arraysize(reads), | 1807 DelayedSocketData data(2, reads, arraysize(reads), writes, arraysize(writes)); |
| 1874 writes, arraysize(writes)); | |
| 1875 NormalSpdyTransactionHelper helper(CreateComplexPostRequest(), | 1808 NormalSpdyTransactionHelper helper(CreateComplexPostRequest(), |
| 1876 DEFAULT_PRIORITY, | 1809 DEFAULT_PRIORITY, |
| 1877 BoundNetLog(), GetParam(), NULL); | 1810 BoundNetLog(), |
| 1811 GetParam(), |
| 1812 NULL); |
| 1878 helper.RunToCompletion(&data); | 1813 helper.RunToCompletion(&data); |
| 1879 TransactionHelperResult out = helper.output(); | 1814 TransactionHelperResult out = helper.output(); |
| 1880 EXPECT_EQ(OK, out.rv); | 1815 EXPECT_EQ(OK, out.rv); |
| 1881 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1816 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1882 EXPECT_EQ("hello!", out.response_data); | 1817 EXPECT_EQ("hello!", out.response_data); |
| 1883 } | 1818 } |
| 1884 | 1819 |
| 1885 // Test that a chunked POST works. | 1820 // Test that a chunked POST works. |
| 1886 TEST_P(SpdyNetworkTransactionTest, ChunkedPost) { | 1821 TEST_P(SpdyNetworkTransactionTest, ChunkedPost) { |
| 1887 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 1822 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1888 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 1823 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 1889 MockWrite writes[] = { | 1824 MockWrite writes[] = { |
| 1890 CreateMockWrite(*req), | 1825 CreateMockWrite(*req), CreateMockWrite(*body), |
| 1891 CreateMockWrite(*body), | |
| 1892 }; | 1826 }; |
| 1893 | 1827 |
| 1894 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 1828 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 1895 MockRead reads[] = { | 1829 MockRead reads[] = { |
| 1896 CreateMockRead(*resp), | 1830 CreateMockRead(*resp), CreateMockRead(*body), |
| 1897 CreateMockRead(*body), | 1831 MockRead(ASYNC, 0, 0) // EOF |
| 1898 MockRead(ASYNC, 0, 0) // EOF | |
| 1899 }; | 1832 }; |
| 1900 | 1833 |
| 1901 DelayedSocketData data(2, reads, arraysize(reads), | 1834 DelayedSocketData data(2, reads, arraysize(reads), writes, arraysize(writes)); |
| 1902 writes, arraysize(writes)); | |
| 1903 NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), | 1835 NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
| 1904 DEFAULT_PRIORITY, | 1836 DEFAULT_PRIORITY, |
| 1905 BoundNetLog(), GetParam(), NULL); | 1837 BoundNetLog(), |
| 1838 GetParam(), |
| 1839 NULL); |
| 1906 | 1840 |
| 1907 // These chunks get merged into a single frame when being sent. | 1841 // These chunks get merged into a single frame when being sent. |
| 1908 const int kFirstChunkSize = kUploadDataSize/2; | 1842 const int kFirstChunkSize = kUploadDataSize / 2; |
| 1909 helper.request().upload_data_stream->AppendChunk( | 1843 helper.request().upload_data_stream->AppendChunk( |
| 1910 kUploadData, kFirstChunkSize, false); | 1844 kUploadData, kFirstChunkSize, false); |
| 1911 helper.request().upload_data_stream->AppendChunk( | 1845 helper.request().upload_data_stream->AppendChunk( |
| 1912 kUploadData + kFirstChunkSize, kUploadDataSize - kFirstChunkSize, true); | 1846 kUploadData + kFirstChunkSize, kUploadDataSize - kFirstChunkSize, true); |
| 1913 | 1847 |
| 1914 helper.RunToCompletion(&data); | 1848 helper.RunToCompletion(&data); |
| 1915 TransactionHelperResult out = helper.output(); | 1849 TransactionHelperResult out = helper.output(); |
| 1916 EXPECT_EQ(OK, out.rv); | 1850 EXPECT_EQ(OK, out.rv); |
| 1917 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1851 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1918 EXPECT_EQ(kUploadData, out.response_data); | 1852 EXPECT_EQ(kUploadData, out.response_data); |
| 1919 } | 1853 } |
| 1920 | 1854 |
| 1921 // Test that a chunked POST works with chunks appended after transaction starts. | 1855 // Test that a chunked POST works with chunks appended after transaction starts. |
| 1922 TEST_P(SpdyNetworkTransactionTest, DelayedChunkedPost) { | 1856 TEST_P(SpdyNetworkTransactionTest, DelayedChunkedPost) { |
| 1923 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 1857 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 1924 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, false)); | 1858 scoped_ptr<SpdyFrame> chunk1(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1925 scoped_ptr<SpdyFrame> chunk2(spdy_util_.ConstructSpdyBodyFrame(1, false)); | 1859 scoped_ptr<SpdyFrame> chunk2(spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 1926 scoped_ptr<SpdyFrame> chunk3(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 1860 scoped_ptr<SpdyFrame> chunk3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 1927 MockWrite writes[] = { | 1861 MockWrite writes[] = { |
| 1928 CreateMockWrite(*req), | 1862 CreateMockWrite(*req), CreateMockWrite(*chunk1), CreateMockWrite(*chunk2), |
| 1929 CreateMockWrite(*chunk1), | 1863 CreateMockWrite(*chunk3), |
| 1930 CreateMockWrite(*chunk2), | |
| 1931 CreateMockWrite(*chunk3), | |
| 1932 }; | 1864 }; |
| 1933 | 1865 |
| 1934 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 1866 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 1935 MockRead reads[] = { | 1867 MockRead reads[] = { |
| 1936 CreateMockRead(*resp), | 1868 CreateMockRead(*resp), CreateMockRead(*chunk1), CreateMockRead(*chunk2), |
| 1937 CreateMockRead(*chunk1), | 1869 CreateMockRead(*chunk3), MockRead(ASYNC, 0, 0) // EOF |
| 1938 CreateMockRead(*chunk2), | |
| 1939 CreateMockRead(*chunk3), | |
| 1940 MockRead(ASYNC, 0, 0) // EOF | |
| 1941 }; | 1870 }; |
| 1942 | 1871 |
| 1943 DelayedSocketData data(4, reads, arraysize(reads), | 1872 DelayedSocketData data(4, reads, arraysize(reads), writes, arraysize(writes)); |
| 1944 writes, arraysize(writes)); | |
| 1945 NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), | 1873 NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
| 1946 DEFAULT_PRIORITY, | 1874 DEFAULT_PRIORITY, |
| 1947 BoundNetLog(), GetParam(), NULL); | 1875 BoundNetLog(), |
| 1876 GetParam(), |
| 1877 NULL); |
| 1948 | 1878 |
| 1949 helper.request().upload_data_stream->AppendChunk( | 1879 helper.request().upload_data_stream->AppendChunk( |
| 1950 kUploadData, kUploadDataSize, false); | 1880 kUploadData, kUploadDataSize, false); |
| 1951 | 1881 |
| 1952 helper.RunPreTestSetup(); | 1882 helper.RunPreTestSetup(); |
| 1953 helper.AddData(&data); | 1883 helper.AddData(&data); |
| 1954 ASSERT_TRUE(helper.StartDefaultTest()); | 1884 ASSERT_TRUE(helper.StartDefaultTest()); |
| 1955 | 1885 |
| 1956 base::RunLoop().RunUntilIdle(); | 1886 base::RunLoop().RunUntilIdle(); |
| 1957 helper.request().upload_data_stream->AppendChunk( | 1887 helper.request().upload_data_stream->AppendChunk( |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1983 request.url = GURL(kRequestUrl); | 1913 request.url = GURL(kRequestUrl); |
| 1984 // Create an empty UploadData. | 1914 // Create an empty UploadData. |
| 1985 request.upload_data_stream = NULL; | 1915 request.upload_data_stream = NULL; |
| 1986 | 1916 |
| 1987 // When request.upload_data_stream is NULL for post, content-length is | 1917 // When request.upload_data_stream is NULL for post, content-length is |
| 1988 // expected to be 0. | 1918 // expected to be 0. |
| 1989 SpdySynStreamIR syn_ir(1); | 1919 SpdySynStreamIR syn_ir(1); |
| 1990 syn_ir.set_name_value_block( | 1920 syn_ir.set_name_value_block( |
| 1991 *spdy_util_.ConstructPostHeaderBlock(kRequestUrl, 0)); | 1921 *spdy_util_.ConstructPostHeaderBlock(kRequestUrl, 0)); |
| 1992 syn_ir.set_fin(true); // No body. | 1922 syn_ir.set_fin(true); // No body. |
| 1993 syn_ir.set_priority(ConvertRequestPriorityToSpdyPriority( | 1923 syn_ir.set_priority( |
| 1994 LOWEST, spdy_util_.spdy_version())); | 1924 ConvertRequestPriorityToSpdyPriority(LOWEST, spdy_util_.spdy_version())); |
| 1995 scoped_ptr<SpdyFrame> req(framer.SerializeFrame(syn_ir)); | 1925 scoped_ptr<SpdyFrame> req(framer.SerializeFrame(syn_ir)); |
| 1996 | 1926 |
| 1997 MockWrite writes[] = { | 1927 MockWrite writes[] = { |
| 1998 CreateMockWrite(*req), | 1928 CreateMockWrite(*req), |
| 1999 }; | 1929 }; |
| 2000 | 1930 |
| 2001 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 1931 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 2002 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 1932 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2003 MockRead reads[] = { | 1933 MockRead reads[] = { |
| 2004 CreateMockRead(*resp), | 1934 CreateMockRead(*resp), CreateMockRead(*body), |
| 2005 CreateMockRead(*body), | 1935 MockRead(ASYNC, 0, 0) // EOF |
| 2006 MockRead(ASYNC, 0, 0) // EOF | |
| 2007 }; | 1936 }; |
| 2008 | 1937 |
| 2009 DelayedSocketData data(1, reads, arraysize(reads), | 1938 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 2010 writes, arraysize(writes)); | |
| 2011 | 1939 |
| 2012 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, | 1940 NormalSpdyTransactionHelper helper( |
| 2013 BoundNetLog(), GetParam(), NULL); | 1941 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 2014 helper.RunToCompletion(&data); | 1942 helper.RunToCompletion(&data); |
| 2015 TransactionHelperResult out = helper.output(); | 1943 TransactionHelperResult out = helper.output(); |
| 2016 EXPECT_EQ(OK, out.rv); | 1944 EXPECT_EQ(OK, out.rv); |
| 2017 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1945 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 2018 EXPECT_EQ("hello!", out.response_data); | 1946 EXPECT_EQ("hello!", out.response_data); |
| 2019 } | 1947 } |
| 2020 | 1948 |
| 2021 // Test that a simple POST works. | 1949 // Test that a simple POST works. |
| 2022 TEST_P(SpdyNetworkTransactionTest, EmptyPost) { | 1950 TEST_P(SpdyNetworkTransactionTest, EmptyPost) { |
| 2023 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); | 1951 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 2024 // Create an empty UploadDataStream. | 1952 // Create an empty UploadDataStream. |
| 2025 ScopedVector<UploadElementReader> element_readers; | 1953 ScopedVector<UploadElementReader> element_readers; |
| 2026 UploadDataStream stream(element_readers.Pass(), 0); | 1954 UploadDataStream stream(element_readers.Pass(), 0); |
| 2027 | 1955 |
| 2028 // Setup the request | 1956 // Setup the request |
| 2029 HttpRequestInfo request; | 1957 HttpRequestInfo request; |
| 2030 request.method = "POST"; | 1958 request.method = "POST"; |
| 2031 request.url = GURL(kRequestUrl); | 1959 request.url = GURL(kRequestUrl); |
| 2032 request.upload_data_stream = &stream; | 1960 request.upload_data_stream = &stream; |
| 2033 | 1961 |
| 2034 const uint64 kContentLength = 0; | 1962 const uint64 kContentLength = 0; |
| 2035 | 1963 |
| 2036 SpdySynStreamIR syn_ir(1); | 1964 SpdySynStreamIR syn_ir(1); |
| 2037 syn_ir.set_name_value_block( | 1965 syn_ir.set_name_value_block( |
| 2038 *spdy_util_.ConstructPostHeaderBlock(kRequestUrl, kContentLength)); | 1966 *spdy_util_.ConstructPostHeaderBlock(kRequestUrl, kContentLength)); |
| 2039 syn_ir.set_fin(true); // No body. | 1967 syn_ir.set_fin(true); // No body. |
| 2040 syn_ir.set_priority(ConvertRequestPriorityToSpdyPriority( | 1968 syn_ir.set_priority( |
| 2041 LOWEST, spdy_util_.spdy_version())); | 1969 ConvertRequestPriorityToSpdyPriority(LOWEST, spdy_util_.spdy_version())); |
| 2042 scoped_ptr<SpdyFrame> req(framer.SerializeFrame(syn_ir)); | 1970 scoped_ptr<SpdyFrame> req(framer.SerializeFrame(syn_ir)); |
| 2043 | 1971 |
| 2044 MockWrite writes[] = { | 1972 MockWrite writes[] = { |
| 2045 CreateMockWrite(*req), | 1973 CreateMockWrite(*req), |
| 2046 }; | 1974 }; |
| 2047 | 1975 |
| 2048 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 1976 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 2049 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 1977 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2050 MockRead reads[] = { | 1978 MockRead reads[] = { |
| 2051 CreateMockRead(*resp), | 1979 CreateMockRead(*resp), CreateMockRead(*body), |
| 2052 CreateMockRead(*body), | 1980 MockRead(ASYNC, 0, 0) // EOF |
| 2053 MockRead(ASYNC, 0, 0) // EOF | |
| 2054 }; | 1981 }; |
| 2055 | 1982 |
| 2056 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); | 1983 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 2057 | 1984 |
| 2058 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, | 1985 NormalSpdyTransactionHelper helper( |
| 2059 BoundNetLog(), GetParam(), NULL); | 1986 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 2060 helper.RunToCompletion(&data); | 1987 helper.RunToCompletion(&data); |
| 2061 TransactionHelperResult out = helper.output(); | 1988 TransactionHelperResult out = helper.output(); |
| 2062 EXPECT_EQ(OK, out.rv); | 1989 EXPECT_EQ(OK, out.rv); |
| 2063 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 1990 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 2064 EXPECT_EQ("hello!", out.response_data); | 1991 EXPECT_EQ("hello!", out.response_data); |
| 2065 } | 1992 } |
| 2066 | 1993 |
| 2067 // While we're doing a post, the server sends the reply before upload completes. | 1994 // While we're doing a post, the server sends the reply before upload completes. |
| 2068 TEST_P(SpdyNetworkTransactionTest, ResponseBeforePostCompletes) { | 1995 TEST_P(SpdyNetworkTransactionTest, ResponseBeforePostCompletes) { |
| 2069 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); | 1996 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructChunkedSpdyPost(NULL, 0)); |
| 2070 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 1997 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2071 MockWrite writes[] = { | 1998 MockWrite writes[] = { |
| 2072 CreateMockWrite(*req, 0), | 1999 CreateMockWrite(*req, 0), CreateMockWrite(*body, 3), |
| 2073 CreateMockWrite(*body, 3), | |
| 2074 }; | 2000 }; |
| 2075 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 2001 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 2076 MockRead reads[] = { | 2002 MockRead reads[] = { |
| 2077 CreateMockRead(*resp, 1), | 2003 CreateMockRead(*resp, 1), CreateMockRead(*body, 2), |
| 2078 CreateMockRead(*body, 2), | 2004 MockRead(ASYNC, 0, 4) // EOF |
| 2079 MockRead(ASYNC, 0, 4) // EOF | |
| 2080 }; | 2005 }; |
| 2081 | 2006 |
| 2082 // Write the request headers, and read the complete response | 2007 // Write the request headers, and read the complete response |
| 2083 // while still waiting for chunked request data. | 2008 // while still waiting for chunked request data. |
| 2084 DeterministicSocketData data(reads, arraysize(reads), | 2009 DeterministicSocketData data( |
| 2085 writes, arraysize(writes)); | 2010 reads, arraysize(reads), writes, arraysize(writes)); |
| 2086 NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), | 2011 NormalSpdyTransactionHelper helper(CreateChunkedPostRequest(), |
| 2087 DEFAULT_PRIORITY, | 2012 DEFAULT_PRIORITY, |
| 2088 BoundNetLog(), GetParam(), NULL); | 2013 BoundNetLog(), |
| 2014 GetParam(), |
| 2015 NULL); |
| 2089 helper.SetDeterministic(); | 2016 helper.SetDeterministic(); |
| 2090 helper.RunPreTestSetup(); | 2017 helper.RunPreTestSetup(); |
| 2091 helper.AddDeterministicData(&data); | 2018 helper.AddDeterministicData(&data); |
| 2092 | 2019 |
| 2093 ASSERT_TRUE(helper.StartDefaultTest()); | 2020 ASSERT_TRUE(helper.StartDefaultTest()); |
| 2094 | 2021 |
| 2095 // Process the request headers, SYN_REPLY, and response body. | 2022 // Process the request headers, SYN_REPLY, and response body. |
| 2096 // The request body is still in flight. | 2023 // The request body is still in flight. |
| 2097 data.RunFor(3); | 2024 data.RunFor(3); |
| 2098 | 2025 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2112 | 2039 |
| 2113 // The client upon cancellation tries to send a RST_STREAM frame. The mock | 2040 // The client upon cancellation tries to send a RST_STREAM frame. The mock |
| 2114 // socket causes the TCP write to return zero. This test checks that the client | 2041 // socket causes the TCP write to return zero. This test checks that the client |
| 2115 // tries to queue up the RST_STREAM frame again. | 2042 // tries to queue up the RST_STREAM frame again. |
| 2116 TEST_P(SpdyNetworkTransactionTest, SocketWriteReturnsZero) { | 2043 TEST_P(SpdyNetworkTransactionTest, SocketWriteReturnsZero) { |
| 2117 scoped_ptr<SpdyFrame> req( | 2044 scoped_ptr<SpdyFrame> req( |
| 2118 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2045 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2119 scoped_ptr<SpdyFrame> rst( | 2046 scoped_ptr<SpdyFrame> rst( |
| 2120 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | 2047 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
| 2121 MockWrite writes[] = { | 2048 MockWrite writes[] = { |
| 2122 CreateMockWrite(*req.get(), 0, SYNCHRONOUS), | 2049 CreateMockWrite(*req.get(), 0, SYNCHRONOUS), |
| 2123 MockWrite(SYNCHRONOUS, 0, 0, 2), | 2050 MockWrite(SYNCHRONOUS, 0, 0, 2), |
| 2124 CreateMockWrite(*rst.get(), 3, SYNCHRONOUS), | 2051 CreateMockWrite(*rst.get(), 3, SYNCHRONOUS), |
| 2125 }; | 2052 }; |
| 2126 | 2053 |
| 2127 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2054 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2128 MockRead reads[] = { | 2055 MockRead reads[] = { |
| 2129 CreateMockRead(*resp.get(), 1, ASYNC), | 2056 CreateMockRead(*resp.get(), 1, ASYNC), MockRead(ASYNC, 0, 0, 4) // EOF |
| 2130 MockRead(ASYNC, 0, 0, 4) // EOF | |
| 2131 }; | 2057 }; |
| 2132 | 2058 |
| 2133 DeterministicSocketData data(reads, arraysize(reads), | 2059 DeterministicSocketData data( |
| 2134 writes, arraysize(writes)); | 2060 reads, arraysize(reads), writes, arraysize(writes)); |
| 2135 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 2061 NormalSpdyTransactionHelper helper( |
| 2136 BoundNetLog(), GetParam(), NULL); | 2062 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 2137 helper.SetDeterministic(); | 2063 helper.SetDeterministic(); |
| 2138 helper.RunPreTestSetup(); | 2064 helper.RunPreTestSetup(); |
| 2139 helper.AddDeterministicData(&data); | 2065 helper.AddDeterministicData(&data); |
| 2140 HttpNetworkTransaction* trans = helper.trans(); | 2066 HttpNetworkTransaction* trans = helper.trans(); |
| 2141 | 2067 |
| 2142 TestCompletionCallback callback; | 2068 TestCompletionCallback callback; |
| 2143 int rv = trans->Start( | 2069 int rv = |
| 2144 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 2070 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 2145 EXPECT_EQ(ERR_IO_PENDING, rv); | 2071 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2146 | 2072 |
| 2147 data.SetStop(2); | 2073 data.SetStop(2); |
| 2148 data.Run(); | 2074 data.Run(); |
| 2149 helper.ResetTrans(); | 2075 helper.ResetTrans(); |
| 2150 data.SetStop(20); | 2076 data.SetStop(20); |
| 2151 data.Run(); | 2077 data.Run(); |
| 2152 | 2078 |
| 2153 helper.VerifyDataConsumed(); | 2079 helper.VerifyDataConsumed(); |
| 2154 } | 2080 } |
| 2155 | 2081 |
| 2156 // Test that the transaction doesn't crash when we don't have a reply. | 2082 // Test that the transaction doesn't crash when we don't have a reply. |
| 2157 TEST_P(SpdyNetworkTransactionTest, ResponseWithoutSynReply) { | 2083 TEST_P(SpdyNetworkTransactionTest, ResponseWithoutSynReply) { |
| 2158 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 2084 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2159 MockRead reads[] = { | 2085 MockRead reads[] = { |
| 2160 CreateMockRead(*body), | 2086 CreateMockRead(*body), MockRead(ASYNC, 0, 0) // EOF |
| 2161 MockRead(ASYNC, 0, 0) // EOF | |
| 2162 }; | 2087 }; |
| 2163 | 2088 |
| 2164 DelayedSocketData data(1, reads, arraysize(reads), NULL, 0); | 2089 DelayedSocketData data(1, reads, arraysize(reads), NULL, 0); |
| 2165 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 2090 NormalSpdyTransactionHelper helper( |
| 2166 BoundNetLog(), GetParam(), NULL); | 2091 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 2167 helper.RunToCompletion(&data); | 2092 helper.RunToCompletion(&data); |
| 2168 TransactionHelperResult out = helper.output(); | 2093 TransactionHelperResult out = helper.output(); |
| 2169 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); | 2094 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 2170 } | 2095 } |
| 2171 | 2096 |
| 2172 // Test that the transaction doesn't crash when we get two replies on the same | 2097 // Test that the transaction doesn't crash when we get two replies on the same |
| 2173 // stream ID. See http://crbug.com/45639. | 2098 // stream ID. See http://crbug.com/45639. |
| 2174 TEST_P(SpdyNetworkTransactionTest, ResponseWithTwoSynReplies) { | 2099 TEST_P(SpdyNetworkTransactionTest, ResponseWithTwoSynReplies) { |
| 2175 scoped_ptr<SpdyFrame> req( | 2100 scoped_ptr<SpdyFrame> req( |
| 2176 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2101 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2177 scoped_ptr<SpdyFrame> rst( | 2102 scoped_ptr<SpdyFrame> rst( |
| 2178 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); | 2103 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 2179 MockWrite writes[] = { | 2104 MockWrite writes[] = { |
| 2180 CreateMockWrite(*req), | 2105 CreateMockWrite(*req), CreateMockWrite(*rst), |
| 2181 CreateMockWrite(*rst), | |
| 2182 }; | 2106 }; |
| 2183 | 2107 |
| 2184 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2108 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2185 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 2109 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2186 MockRead reads[] = { | 2110 MockRead reads[] = { |
| 2187 CreateMockRead(*resp), | 2111 CreateMockRead(*resp), CreateMockRead(*resp), CreateMockRead(*body), |
| 2188 CreateMockRead(*resp), | 2112 MockRead(ASYNC, 0, 0) // EOF |
| 2189 CreateMockRead(*body), | |
| 2190 MockRead(ASYNC, 0, 0) // EOF | |
| 2191 }; | 2113 }; |
| 2192 | 2114 |
| 2193 DelayedSocketData data(1, reads, arraysize(reads), | 2115 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 2194 writes, arraysize(writes)); | |
| 2195 | 2116 |
| 2196 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 2117 NormalSpdyTransactionHelper helper( |
| 2197 BoundNetLog(), GetParam(), NULL); | 2118 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 2198 helper.RunPreTestSetup(); | 2119 helper.RunPreTestSetup(); |
| 2199 helper.AddData(&data); | 2120 helper.AddData(&data); |
| 2200 | 2121 |
| 2201 HttpNetworkTransaction* trans = helper.trans(); | 2122 HttpNetworkTransaction* trans = helper.trans(); |
| 2202 | 2123 |
| 2203 TestCompletionCallback callback; | 2124 TestCompletionCallback callback; |
| 2204 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); | 2125 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 2205 EXPECT_EQ(ERR_IO_PENDING, rv); | 2126 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2206 rv = callback.WaitForResult(); | 2127 rv = callback.WaitForResult(); |
| 2207 EXPECT_EQ(OK, rv); | 2128 EXPECT_EQ(OK, rv); |
| 2208 | 2129 |
| 2209 const HttpResponseInfo* response = trans->GetResponseInfo(); | 2130 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 2210 ASSERT_TRUE(response != NULL); | 2131 ASSERT_TRUE(response != NULL); |
| 2211 EXPECT_TRUE(response->headers.get() != NULL); | 2132 EXPECT_TRUE(response->headers.get() != NULL); |
| 2212 EXPECT_TRUE(response->was_fetched_via_spdy); | 2133 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 2213 std::string response_data; | 2134 std::string response_data; |
| 2214 rv = ReadTransaction(trans, &response_data); | 2135 rv = ReadTransaction(trans, &response_data); |
| 2215 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, rv); | 2136 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, rv); |
| 2216 | 2137 |
| 2217 helper.VerifyDataConsumed(); | 2138 helper.VerifyDataConsumed(); |
| 2218 } | 2139 } |
| 2219 | 2140 |
| 2220 TEST_P(SpdyNetworkTransactionTest, ResetReplyWithTransferEncoding) { | 2141 TEST_P(SpdyNetworkTransactionTest, ResetReplyWithTransferEncoding) { |
| 2221 // Construct the request. | 2142 // Construct the request. |
| 2222 scoped_ptr<SpdyFrame> req( | 2143 scoped_ptr<SpdyFrame> req( |
| 2223 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2144 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2224 scoped_ptr<SpdyFrame> rst( | 2145 scoped_ptr<SpdyFrame> rst( |
| 2225 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); | 2146 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 2226 MockWrite writes[] = { | 2147 MockWrite writes[] = { |
| 2227 CreateMockWrite(*req), | 2148 CreateMockWrite(*req), CreateMockWrite(*rst), |
| 2228 CreateMockWrite(*rst), | |
| 2229 }; | 2149 }; |
| 2230 | 2150 |
| 2231 const char* const headers[] = { | 2151 const char* const headers[] = {"transfer-encoding", "chunked"}; |
| 2232 "transfer-encoding", "chunked" | |
| 2233 }; | |
| 2234 scoped_ptr<SpdyFrame> resp( | 2152 scoped_ptr<SpdyFrame> resp( |
| 2235 spdy_util_.ConstructSpdyGetSynReply(headers, 1, 1)); | 2153 spdy_util_.ConstructSpdyGetSynReply(headers, 1, 1)); |
| 2236 scoped_ptr<SpdyFrame> body( | 2154 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2237 spdy_util_.ConstructSpdyBodyFrame(1, true)); | |
| 2238 MockRead reads[] = { | 2155 MockRead reads[] = { |
| 2239 CreateMockRead(*resp), | 2156 CreateMockRead(*resp), CreateMockRead(*body), |
| 2240 CreateMockRead(*body), | 2157 MockRead(ASYNC, 0, 0) // EOF |
| 2241 MockRead(ASYNC, 0, 0) // EOF | |
| 2242 }; | 2158 }; |
| 2243 | 2159 |
| 2244 DelayedSocketData data(1, reads, arraysize(reads), | 2160 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 2245 writes, arraysize(writes)); | 2161 NormalSpdyTransactionHelper helper( |
| 2246 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 2162 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 2247 BoundNetLog(), GetParam(), NULL); | |
| 2248 helper.RunToCompletion(&data); | 2163 helper.RunToCompletion(&data); |
| 2249 TransactionHelperResult out = helper.output(); | 2164 TransactionHelperResult out = helper.output(); |
| 2250 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); | 2165 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 2251 | 2166 |
| 2252 helper.session()->spdy_session_pool()->CloseAllSessions(); | 2167 helper.session()->spdy_session_pool()->CloseAllSessions(); |
| 2253 helper.VerifyDataConsumed(); | 2168 helper.VerifyDataConsumed(); |
| 2254 } | 2169 } |
| 2255 | 2170 |
| 2256 TEST_P(SpdyNetworkTransactionTest, ResetPushWithTransferEncoding) { | 2171 TEST_P(SpdyNetworkTransactionTest, ResetPushWithTransferEncoding) { |
| 2257 // Construct the request. | 2172 // Construct the request. |
| 2258 scoped_ptr<SpdyFrame> req( | 2173 scoped_ptr<SpdyFrame> req( |
| 2259 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2174 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2260 scoped_ptr<SpdyFrame> rst( | 2175 scoped_ptr<SpdyFrame> rst( |
| 2261 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); | 2176 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
| 2262 MockWrite writes[] = { | 2177 MockWrite writes[] = { |
| 2263 CreateMockWrite(*req), | 2178 CreateMockWrite(*req), CreateMockWrite(*rst), |
| 2264 CreateMockWrite(*rst), | |
| 2265 }; | 2179 }; |
| 2266 | 2180 |
| 2267 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2181 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2268 const char* const headers[] = { | 2182 const char* const headers[] = {"transfer-encoding", "chunked"}; |
| 2269 "transfer-encoding", "chunked" | 2183 scoped_ptr<SpdyFrame> push(spdy_util_.ConstructSpdyPush( |
| 2270 }; | 2184 headers, arraysize(headers) / 2, 2, 1, "http://www.google.com/1")); |
| 2271 scoped_ptr<SpdyFrame> push( | |
| 2272 spdy_util_.ConstructSpdyPush(headers, arraysize(headers) / 2, | |
| 2273 2, 1, "http://www.google.com/1")); | |
| 2274 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 2185 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2275 MockRead reads[] = { | 2186 MockRead reads[] = { |
| 2276 CreateMockRead(*resp), | 2187 CreateMockRead(*resp), CreateMockRead(*push), CreateMockRead(*body), |
| 2277 CreateMockRead(*push), | 2188 MockRead(ASYNC, 0, 0) // EOF |
| 2278 CreateMockRead(*body), | |
| 2279 MockRead(ASYNC, 0, 0) // EOF | |
| 2280 }; | 2189 }; |
| 2281 | 2190 |
| 2282 DelayedSocketData data(1, reads, arraysize(reads), | 2191 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 2283 writes, arraysize(writes)); | 2192 NormalSpdyTransactionHelper helper( |
| 2284 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 2193 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 2285 BoundNetLog(), GetParam(), NULL); | |
| 2286 helper.RunToCompletion(&data); | 2194 helper.RunToCompletion(&data); |
| 2287 TransactionHelperResult out = helper.output(); | 2195 TransactionHelperResult out = helper.output(); |
| 2288 EXPECT_EQ(OK, out.rv); | 2196 EXPECT_EQ(OK, out.rv); |
| 2289 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 2197 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 2290 EXPECT_EQ("hello!", out.response_data); | 2198 EXPECT_EQ("hello!", out.response_data); |
| 2291 | 2199 |
| 2292 helper.session()->spdy_session_pool()->CloseAllSessions(); | 2200 helper.session()->spdy_session_pool()->CloseAllSessions(); |
| 2293 helper.VerifyDataConsumed(); | 2201 helper.VerifyDataConsumed(); |
| 2294 } | 2202 } |
| 2295 | 2203 |
| 2296 TEST_P(SpdyNetworkTransactionTest, CancelledTransaction) { | 2204 TEST_P(SpdyNetworkTransactionTest, CancelledTransaction) { |
| 2297 // Construct the request. | 2205 // Construct the request. |
| 2298 scoped_ptr<SpdyFrame> req( | 2206 scoped_ptr<SpdyFrame> req( |
| 2299 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2207 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2300 MockWrite writes[] = { | 2208 MockWrite writes[] = { |
| 2301 CreateMockWrite(*req), | 2209 CreateMockWrite(*req), |
| 2302 }; | 2210 }; |
| 2303 | 2211 |
| 2304 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2212 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2305 MockRead reads[] = { | 2213 MockRead reads[] = { |
| 2306 CreateMockRead(*resp), | 2214 CreateMockRead(*resp), |
| 2307 // This following read isn't used by the test, except during the | 2215 // This following read isn't used by the test, except during the |
| 2308 // RunUntilIdle() call at the end since the SpdySession survives the | 2216 // RunUntilIdle() call at the end since the SpdySession survives the |
| 2309 // HttpNetworkTransaction and still tries to continue Read()'ing. Any | 2217 // HttpNetworkTransaction and still tries to continue Read()'ing. Any |
| 2310 // MockRead will do here. | 2218 // MockRead will do here. |
| 2311 MockRead(ASYNC, 0, 0) // EOF | 2219 MockRead(ASYNC, 0, 0) // EOF |
| 2312 }; | 2220 }; |
| 2313 | 2221 |
| 2314 StaticSocketDataProvider data(reads, arraysize(reads), | 2222 StaticSocketDataProvider data( |
| 2315 writes, arraysize(writes)); | 2223 reads, arraysize(reads), writes, arraysize(writes)); |
| 2316 | 2224 |
| 2317 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 2225 NormalSpdyTransactionHelper helper( |
| 2318 BoundNetLog(), GetParam(), NULL); | 2226 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 2319 helper.RunPreTestSetup(); | 2227 helper.RunPreTestSetup(); |
| 2320 helper.AddData(&data); | 2228 helper.AddData(&data); |
| 2321 HttpNetworkTransaction* trans = helper.trans(); | 2229 HttpNetworkTransaction* trans = helper.trans(); |
| 2322 | 2230 |
| 2323 TestCompletionCallback callback; | 2231 TestCompletionCallback callback; |
| 2324 int rv = trans->Start( | 2232 int rv = |
| 2325 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 2233 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 2326 EXPECT_EQ(ERR_IO_PENDING, rv); | 2234 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2327 helper.ResetTrans(); // Cancel the transaction. | 2235 helper.ResetTrans(); // Cancel the transaction. |
| 2328 | 2236 |
| 2329 // Flush the MessageLoop while the SpdySessionDependencies (in particular, the | 2237 // Flush the MessageLoop while the SpdySessionDependencies (in particular, the |
| 2330 // MockClientSocketFactory) are still alive. | 2238 // MockClientSocketFactory) are still alive. |
| 2331 base::RunLoop().RunUntilIdle(); | 2239 base::RunLoop().RunUntilIdle(); |
| 2332 helper.VerifyDataNotConsumed(); | 2240 helper.VerifyDataNotConsumed(); |
| 2333 } | 2241 } |
| 2334 | 2242 |
| 2335 // Verify that the client sends a Rst Frame upon cancelling the stream. | 2243 // Verify that the client sends a Rst Frame upon cancelling the stream. |
| 2336 TEST_P(SpdyNetworkTransactionTest, CancelledTransactionSendRst) { | 2244 TEST_P(SpdyNetworkTransactionTest, CancelledTransactionSendRst) { |
| 2337 scoped_ptr<SpdyFrame> req( | 2245 scoped_ptr<SpdyFrame> req( |
| 2338 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2246 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2339 scoped_ptr<SpdyFrame> rst( | 2247 scoped_ptr<SpdyFrame> rst( |
| 2340 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); | 2248 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
| 2341 MockWrite writes[] = { | 2249 MockWrite writes[] = { |
| 2342 CreateMockWrite(*req, 0, SYNCHRONOUS), | 2250 CreateMockWrite(*req, 0, SYNCHRONOUS), |
| 2343 CreateMockWrite(*rst, 2, SYNCHRONOUS), | 2251 CreateMockWrite(*rst, 2, SYNCHRONOUS), |
| 2344 }; | 2252 }; |
| 2345 | 2253 |
| 2346 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2254 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2347 MockRead reads[] = { | 2255 MockRead reads[] = { |
| 2348 CreateMockRead(*resp, 1, ASYNC), | 2256 CreateMockRead(*resp, 1, ASYNC), MockRead(ASYNC, 0, 0, 3) // EOF |
| 2349 MockRead(ASYNC, 0, 0, 3) // EOF | |
| 2350 }; | 2257 }; |
| 2351 | 2258 |
| 2352 DeterministicSocketData data(reads, arraysize(reads), | 2259 DeterministicSocketData data( |
| 2353 writes, arraysize(writes)); | 2260 reads, arraysize(reads), writes, arraysize(writes)); |
| 2354 | 2261 |
| 2355 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 2262 NormalSpdyTransactionHelper helper( |
| 2356 BoundNetLog(), | 2263 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 2357 GetParam(), NULL); | |
| 2358 helper.SetDeterministic(); | 2264 helper.SetDeterministic(); |
| 2359 helper.RunPreTestSetup(); | 2265 helper.RunPreTestSetup(); |
| 2360 helper.AddDeterministicData(&data); | 2266 helper.AddDeterministicData(&data); |
| 2361 HttpNetworkTransaction* trans = helper.trans(); | 2267 HttpNetworkTransaction* trans = helper.trans(); |
| 2362 | 2268 |
| 2363 TestCompletionCallback callback; | 2269 TestCompletionCallback callback; |
| 2364 | 2270 |
| 2365 int rv = trans->Start( | 2271 int rv = |
| 2366 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 2272 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 2367 EXPECT_EQ(ERR_IO_PENDING, rv); | 2273 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2368 | 2274 |
| 2369 data.SetStop(2); | 2275 data.SetStop(2); |
| 2370 data.Run(); | 2276 data.Run(); |
| 2371 helper.ResetTrans(); | 2277 helper.ResetTrans(); |
| 2372 data.SetStop(20); | 2278 data.SetStop(20); |
| 2373 data.Run(); | 2279 data.Run(); |
| 2374 | 2280 |
| 2375 helper.VerifyDataConsumed(); | 2281 helper.VerifyDataConsumed(); |
| 2376 } | 2282 } |
| 2377 | 2283 |
| 2378 // Verify that the client can correctly deal with the user callback attempting | 2284 // Verify that the client can correctly deal with the user callback attempting |
| 2379 // to start another transaction on a session that is closing down. See | 2285 // to start another transaction on a session that is closing down. See |
| 2380 // http://crbug.com/47455 | 2286 // http://crbug.com/47455 |
| 2381 TEST_P(SpdyNetworkTransactionTest, StartTransactionOnReadCallback) { | 2287 TEST_P(SpdyNetworkTransactionTest, StartTransactionOnReadCallback) { |
| 2382 scoped_ptr<SpdyFrame> req( | 2288 scoped_ptr<SpdyFrame> req( |
| 2383 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2289 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2384 MockWrite writes[] = { CreateMockWrite(*req) }; | 2290 MockWrite writes[] = {CreateMockWrite(*req)}; |
| 2385 MockWrite writes2[] = { CreateMockWrite(*req) }; | 2291 MockWrite writes2[] = {CreateMockWrite(*req)}; |
| 2386 | 2292 |
| 2387 // The indicated length of this frame is longer than its actual length. When | 2293 // The indicated length of this frame is longer than its actual length. When |
| 2388 // the session receives an empty frame after this one, it shuts down the | 2294 // the session receives an empty frame after this one, it shuts down the |
| 2389 // session, and calls the read callback with the incomplete data. | 2295 // session, and calls the read callback with the incomplete data. |
| 2390 const uint8 kGetBodyFrame2[] = { | 2296 const uint8 kGetBodyFrame2[] = { |
| 2391 0x00, 0x00, 0x00, 0x01, | 2297 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, |
| 2392 0x01, 0x00, 0x00, 0x07, | 2298 0x07, 'h', 'e', 'l', 'l', 'o', '!', |
| 2393 'h', 'e', 'l', 'l', 'o', '!', | |
| 2394 }; | 2299 }; |
| 2395 | 2300 |
| 2396 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2301 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2397 MockRead reads[] = { | 2302 MockRead reads[] = { |
| 2398 CreateMockRead(*resp, 2), | 2303 CreateMockRead(*resp, 2), |
| 2399 MockRead(ASYNC, ERR_IO_PENDING, 3), // Force a pause | 2304 MockRead(ASYNC, ERR_IO_PENDING, 3), // Force a pause |
| 2400 MockRead(ASYNC, reinterpret_cast<const char*>(kGetBodyFrame2), | 2305 MockRead(ASYNC, |
| 2401 arraysize(kGetBodyFrame2), 4), | 2306 reinterpret_cast<const char*>(kGetBodyFrame2), |
| 2402 MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause | 2307 arraysize(kGetBodyFrame2), |
| 2403 MockRead(ASYNC, 0, 0, 6), // EOF | 2308 4), |
| 2309 MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
| 2310 MockRead(ASYNC, 0, 0, 6), // EOF |
| 2404 }; | 2311 }; |
| 2405 MockRead reads2[] = { | 2312 MockRead reads2[] = { |
| 2406 CreateMockRead(*resp, 2), | 2313 CreateMockRead(*resp, 2), MockRead(ASYNC, 0, 0, 3), // EOF |
| 2407 MockRead(ASYNC, 0, 0, 3), // EOF | |
| 2408 }; | 2314 }; |
| 2409 | 2315 |
| 2410 OrderedSocketData data(reads, arraysize(reads), | 2316 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2411 writes, arraysize(writes)); | 2317 DelayedSocketData data2( |
| 2412 DelayedSocketData data2(1, reads2, arraysize(reads2), | 2318 1, reads2, arraysize(reads2), writes2, arraysize(writes2)); |
| 2413 writes2, arraysize(writes2)); | |
| 2414 | 2319 |
| 2415 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 2320 NormalSpdyTransactionHelper helper( |
| 2416 BoundNetLog(), GetParam(), NULL); | 2321 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 2417 helper.RunPreTestSetup(); | 2322 helper.RunPreTestSetup(); |
| 2418 helper.AddData(&data); | 2323 helper.AddData(&data); |
| 2419 helper.AddData(&data2); | 2324 helper.AddData(&data2); |
| 2420 HttpNetworkTransaction* trans = helper.trans(); | 2325 HttpNetworkTransaction* trans = helper.trans(); |
| 2421 | 2326 |
| 2422 // Start the transaction with basic parameters. | 2327 // Start the transaction with basic parameters. |
| 2423 TestCompletionCallback callback; | 2328 TestCompletionCallback callback; |
| 2424 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); | 2329 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 2425 EXPECT_EQ(ERR_IO_PENDING, rv); | 2330 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2426 rv = callback.WaitForResult(); | 2331 rv = callback.WaitForResult(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2438 data.CompleteRead(); | 2343 data.CompleteRead(); |
| 2439 helper.VerifyDataConsumed(); | 2344 helper.VerifyDataConsumed(); |
| 2440 } | 2345 } |
| 2441 | 2346 |
| 2442 // Verify that the client can correctly deal with the user callback deleting the | 2347 // Verify that the client can correctly deal with the user callback deleting the |
| 2443 // transaction. Failures will usually be valgrind errors. See | 2348 // transaction. Failures will usually be valgrind errors. See |
| 2444 // http://crbug.com/46925 | 2349 // http://crbug.com/46925 |
| 2445 TEST_P(SpdyNetworkTransactionTest, DeleteSessionOnReadCallback) { | 2350 TEST_P(SpdyNetworkTransactionTest, DeleteSessionOnReadCallback) { |
| 2446 scoped_ptr<SpdyFrame> req( | 2351 scoped_ptr<SpdyFrame> req( |
| 2447 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2352 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2448 MockWrite writes[] = { CreateMockWrite(*req) }; | 2353 MockWrite writes[] = {CreateMockWrite(*req)}; |
| 2449 | 2354 |
| 2450 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2355 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2451 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 2356 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2452 MockRead reads[] = { | 2357 MockRead reads[] = { |
| 2453 CreateMockRead(*resp.get(), 2), | 2358 CreateMockRead(*resp.get(), 2), |
| 2454 MockRead(ASYNC, ERR_IO_PENDING, 3), // Force a pause | 2359 MockRead(ASYNC, ERR_IO_PENDING, 3), // Force a pause |
| 2455 CreateMockRead(*body.get(), 4), | 2360 CreateMockRead(*body.get(), 4), MockRead(ASYNC, 0, 0, 5), // EOF |
| 2456 MockRead(ASYNC, 0, 0, 5), // EOF | |
| 2457 }; | 2361 }; |
| 2458 | 2362 |
| 2459 OrderedSocketData data(reads, arraysize(reads), | 2363 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2460 writes, arraysize(writes)); | |
| 2461 | 2364 |
| 2462 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 2365 NormalSpdyTransactionHelper helper( |
| 2463 BoundNetLog(), GetParam(), NULL); | 2366 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 2464 helper.RunPreTestSetup(); | 2367 helper.RunPreTestSetup(); |
| 2465 helper.AddData(&data); | 2368 helper.AddData(&data); |
| 2466 HttpNetworkTransaction* trans = helper.trans(); | 2369 HttpNetworkTransaction* trans = helper.trans(); |
| 2467 | 2370 |
| 2468 // Start the transaction with basic parameters. | 2371 // Start the transaction with basic parameters. |
| 2469 TestCompletionCallback callback; | 2372 TestCompletionCallback callback; |
| 2470 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); | 2373 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 2471 EXPECT_EQ(ERR_IO_PENDING, rv); | 2374 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2472 rv = callback.WaitForResult(); | 2375 rv = callback.WaitForResult(); |
| 2473 | 2376 |
| 2474 // Setup a user callback which will delete the session, and clear out the | 2377 // Setup a user callback which will delete the session, and clear out the |
| 2475 // memory holding the stream object. Note that the callback deletes trans. | 2378 // memory holding the stream object. Note that the callback deletes trans. |
| 2476 const int kSize = 3000; | 2379 const int kSize = 3000; |
| 2477 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); | 2380 scoped_refptr<net::IOBuffer> buf(new net::IOBuffer(kSize)); |
| 2478 rv = trans->Read( | 2381 rv = |
| 2479 buf.get(), | 2382 trans->Read(buf.get(), |
| 2480 kSize, | 2383 kSize, |
| 2481 base::Bind(&SpdyNetworkTransactionTest::DeleteSessionCallback, | 2384 base::Bind(&SpdyNetworkTransactionTest::DeleteSessionCallback, |
| 2482 base::Unretained(&helper))); | 2385 base::Unretained(&helper))); |
| 2483 ASSERT_EQ(ERR_IO_PENDING, rv); | 2386 ASSERT_EQ(ERR_IO_PENDING, rv); |
| 2484 data.CompleteRead(); | 2387 data.CompleteRead(); |
| 2485 | 2388 |
| 2486 // Finish running rest of tasks. | 2389 // Finish running rest of tasks. |
| 2487 base::RunLoop().RunUntilIdle(); | 2390 base::RunLoop().RunUntilIdle(); |
| 2488 helper.VerifyDataConsumed(); | 2391 helper.VerifyDataConsumed(); |
| 2489 } | 2392 } |
| 2490 | 2393 |
| 2491 // Send a spdy request to www.google.com that gets redirected to www.foo.com. | 2394 // Send a spdy request to www.google.com that gets redirected to www.foo.com. |
| 2492 TEST_P(SpdyNetworkTransactionTest, RedirectGetRequest) { | 2395 TEST_P(SpdyNetworkTransactionTest, RedirectGetRequest) { |
| 2493 const SpdyHeaderInfo kSynStartHeader = spdy_util_.MakeSpdyHeader(SYN_STREAM); | 2396 const SpdyHeaderInfo kSynStartHeader = spdy_util_.MakeSpdyHeader(SYN_STREAM); |
| 2494 scoped_ptr<SpdyHeaderBlock> headers( | 2397 scoped_ptr<SpdyHeaderBlock> headers( |
| 2495 spdy_util_.ConstructGetHeaderBlock("http://www.google.com/")); | 2398 spdy_util_.ConstructGetHeaderBlock("http://www.google.com/")); |
| 2496 (*headers)["user-agent"] = ""; | 2399 (*headers)["user-agent"] = ""; |
| 2497 (*headers)["accept-encoding"] = "gzip,deflate"; | 2400 (*headers)["accept-encoding"] = "gzip,deflate"; |
| 2498 scoped_ptr<SpdyHeaderBlock> headers2( | 2401 scoped_ptr<SpdyHeaderBlock> headers2( |
| 2499 spdy_util_.ConstructGetHeaderBlock("http://www.foo.com/index.php")); | 2402 spdy_util_.ConstructGetHeaderBlock("http://www.foo.com/index.php")); |
| 2500 (*headers2)["user-agent"] = ""; | 2403 (*headers2)["user-agent"] = ""; |
| 2501 (*headers2)["accept-encoding"] = "gzip,deflate"; | 2404 (*headers2)["accept-encoding"] = "gzip,deflate"; |
| 2502 | 2405 |
| 2503 // Setup writes/reads to www.google.com | 2406 // Setup writes/reads to www.google.com |
| 2504 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyFrame( | 2407 scoped_ptr<SpdyFrame> req( |
| 2505 kSynStartHeader, headers.Pass())); | 2408 spdy_util_.ConstructSpdyFrame(kSynStartHeader, headers.Pass())); |
| 2506 scoped_ptr<SpdyFrame> req2(spdy_util_.ConstructSpdyFrame( | 2409 scoped_ptr<SpdyFrame> req2( |
| 2507 kSynStartHeader, headers2.Pass())); | 2410 spdy_util_.ConstructSpdyFrame(kSynStartHeader, headers2.Pass())); |
| 2508 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReplyRedirect(1)); | 2411 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReplyRedirect(1)); |
| 2509 MockWrite writes[] = { | 2412 MockWrite writes[] = { |
| 2510 CreateMockWrite(*req, 1), | 2413 CreateMockWrite(*req, 1), |
| 2511 }; | 2414 }; |
| 2512 MockRead reads[] = { | 2415 MockRead reads[] = { |
| 2513 CreateMockRead(*resp, 2), | 2416 CreateMockRead(*resp, 2), MockRead(ASYNC, 0, 0, 3) // EOF |
| 2514 MockRead(ASYNC, 0, 0, 3) // EOF | |
| 2515 }; | 2417 }; |
| 2516 | 2418 |
| 2517 // Setup writes/reads to www.foo.com | 2419 // Setup writes/reads to www.foo.com |
| 2518 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2420 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2519 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 2421 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2520 MockWrite writes2[] = { | 2422 MockWrite writes2[] = { |
| 2521 CreateMockWrite(*req2, 1), | 2423 CreateMockWrite(*req2, 1), |
| 2522 }; | 2424 }; |
| 2523 MockRead reads2[] = { | 2425 MockRead reads2[] = { |
| 2524 CreateMockRead(*resp2, 2), | 2426 CreateMockRead(*resp2, 2), CreateMockRead(*body2, 3), |
| 2525 CreateMockRead(*body2, 3), | 2427 MockRead(ASYNC, 0, 0, 4) // EOF |
| 2526 MockRead(ASYNC, 0, 0, 4) // EOF | |
| 2527 }; | 2428 }; |
| 2528 OrderedSocketData data(reads, arraysize(reads), | 2429 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2529 writes, arraysize(writes)); | 2430 OrderedSocketData data2( |
| 2530 OrderedSocketData data2(reads2, arraysize(reads2), | 2431 reads2, arraysize(reads2), writes2, arraysize(writes2)); |
| 2531 writes2, arraysize(writes2)); | |
| 2532 | 2432 |
| 2533 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN | 2433 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN |
| 2534 HttpStreamFactory::set_force_spdy_over_ssl(false); | 2434 HttpStreamFactory::set_force_spdy_over_ssl(false); |
| 2535 HttpStreamFactory::set_force_spdy_always(true); | 2435 HttpStreamFactory::set_force_spdy_always(true); |
| 2536 TestDelegate d; | 2436 TestDelegate d; |
| 2537 { | 2437 { |
| 2538 SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); | 2438 SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); |
| 2539 net::URLRequest r(GURL("http://www.google.com/"), | 2439 net::URLRequest r(GURL("http://www.google.com/"), |
| 2540 DEFAULT_PRIORITY, | 2440 DEFAULT_PRIORITY, |
| 2541 &d, | 2441 &d, |
| 2542 &spdy_url_request_context); | 2442 &spdy_url_request_context); |
| 2543 spdy_url_request_context.socket_factory(). | 2443 spdy_url_request_context.socket_factory().AddSocketDataProvider(&data); |
| 2544 AddSocketDataProvider(&data); | 2444 spdy_url_request_context.socket_factory().AddSocketDataProvider(&data2); |
| 2545 spdy_url_request_context.socket_factory(). | |
| 2546 AddSocketDataProvider(&data2); | |
| 2547 | 2445 |
| 2548 d.set_quit_on_redirect(true); | 2446 d.set_quit_on_redirect(true); |
| 2549 r.Start(); | 2447 r.Start(); |
| 2550 base::RunLoop().Run(); | 2448 base::RunLoop().Run(); |
| 2551 | 2449 |
| 2552 EXPECT_EQ(1, d.received_redirect_count()); | 2450 EXPECT_EQ(1, d.received_redirect_count()); |
| 2553 | 2451 |
| 2554 r.FollowDeferredRedirect(); | 2452 r.FollowDeferredRedirect(); |
| 2555 base::RunLoop().Run(); | 2453 base::RunLoop().Run(); |
| 2556 EXPECT_EQ(1, d.response_started_count()); | 2454 EXPECT_EQ(1, d.response_started_count()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2574 spdy_util_.ConstructGetHeaderBlock("http://www.google.com/")); | 2472 spdy_util_.ConstructGetHeaderBlock("http://www.google.com/")); |
| 2575 (*headers)["user-agent"] = ""; | 2473 (*headers)["user-agent"] = ""; |
| 2576 (*headers)["accept-encoding"] = "gzip,deflate"; | 2474 (*headers)["accept-encoding"] = "gzip,deflate"; |
| 2577 | 2475 |
| 2578 // Setup writes/reads to www.google.com | 2476 // Setup writes/reads to www.google.com |
| 2579 scoped_ptr<SpdyFrame> req( | 2477 scoped_ptr<SpdyFrame> req( |
| 2580 spdy_util_.ConstructSpdyFrame(kSynStartHeader, headers.Pass())); | 2478 spdy_util_.ConstructSpdyFrame(kSynStartHeader, headers.Pass())); |
| 2581 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2479 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2582 scoped_ptr<SpdyFrame> rep( | 2480 scoped_ptr<SpdyFrame> rep( |
| 2583 spdy_util_.ConstructSpdyPush(NULL, | 2481 spdy_util_.ConstructSpdyPush(NULL, |
| 2584 0, | 2482 0, |
| 2585 2, | 2483 2, |
| 2586 1, | 2484 1, |
| 2587 "http://www.google.com/foo.dat", | 2485 "http://www.google.com/foo.dat", |
| 2588 "301 Moved Permanently", | 2486 "301 Moved Permanently", |
| 2589 "http://www.foo.com/index.php")); | 2487 "http://www.foo.com/index.php")); |
| 2590 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 2488 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2591 scoped_ptr<SpdyFrame> rst( | 2489 scoped_ptr<SpdyFrame> rst( |
| 2592 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_CANCEL)); | 2490 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_CANCEL)); |
| 2593 MockWrite writes[] = { | 2491 MockWrite writes[] = { |
| 2594 CreateMockWrite(*req, 1), | 2492 CreateMockWrite(*req, 1), CreateMockWrite(*rst, 6), |
| 2595 CreateMockWrite(*rst, 6), | |
| 2596 }; | 2493 }; |
| 2597 MockRead reads[] = { | 2494 MockRead reads[] = { |
| 2598 CreateMockRead(*resp, 2), | 2495 CreateMockRead(*resp, 2), CreateMockRead(*rep, 3), |
| 2599 CreateMockRead(*rep, 3), | 2496 CreateMockRead(*body, 4), |
| 2600 CreateMockRead(*body, 4), | 2497 MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
| 2601 MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause | 2498 MockRead(ASYNC, 0, 0, 7) // EOF |
| 2602 MockRead(ASYNC, 0, 0, 7) // EOF | |
| 2603 }; | 2499 }; |
| 2604 | 2500 |
| 2605 // Setup writes/reads to www.foo.com | 2501 // Setup writes/reads to www.foo.com |
| 2606 scoped_ptr<SpdyHeaderBlock> headers2( | 2502 scoped_ptr<SpdyHeaderBlock> headers2( |
| 2607 spdy_util_.ConstructGetHeaderBlock("http://www.foo.com/index.php")); | 2503 spdy_util_.ConstructGetHeaderBlock("http://www.foo.com/index.php")); |
| 2608 (*headers2)["user-agent"] = ""; | 2504 (*headers2)["user-agent"] = ""; |
| 2609 (*headers2)["accept-encoding"] = "gzip,deflate"; | 2505 (*headers2)["accept-encoding"] = "gzip,deflate"; |
| 2610 scoped_ptr<SpdyFrame> req2( | 2506 scoped_ptr<SpdyFrame> req2( |
| 2611 spdy_util_.ConstructSpdyFrame(kSynStartHeader, headers2.Pass())); | 2507 spdy_util_.ConstructSpdyFrame(kSynStartHeader, headers2.Pass())); |
| 2612 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2508 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2613 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 2509 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2614 MockWrite writes2[] = { | 2510 MockWrite writes2[] = { |
| 2615 CreateMockWrite(*req2, 1), | 2511 CreateMockWrite(*req2, 1), |
| 2616 }; | 2512 }; |
| 2617 MockRead reads2[] = { | 2513 MockRead reads2[] = { |
| 2618 CreateMockRead(*resp2, 2), | 2514 CreateMockRead(*resp2, 2), CreateMockRead(*body2, 3), |
| 2619 CreateMockRead(*body2, 3), | 2515 MockRead(ASYNC, 0, 0, 5) // EOF |
| 2620 MockRead(ASYNC, 0, 0, 5) // EOF | |
| 2621 }; | 2516 }; |
| 2622 OrderedSocketData data(reads, arraysize(reads), | 2517 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2623 writes, arraysize(writes)); | 2518 OrderedSocketData data2( |
| 2624 OrderedSocketData data2(reads2, arraysize(reads2), | 2519 reads2, arraysize(reads2), writes2, arraysize(writes2)); |
| 2625 writes2, arraysize(writes2)); | |
| 2626 | 2520 |
| 2627 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN | 2521 // TODO(erikchen): Make test support SPDYSSL, SPDYNPN |
| 2628 HttpStreamFactory::set_force_spdy_over_ssl(false); | 2522 HttpStreamFactory::set_force_spdy_over_ssl(false); |
| 2629 HttpStreamFactory::set_force_spdy_always(true); | 2523 HttpStreamFactory::set_force_spdy_always(true); |
| 2630 TestDelegate d; | 2524 TestDelegate d; |
| 2631 TestDelegate d2; | 2525 TestDelegate d2; |
| 2632 SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); | 2526 SpdyURLRequestContext spdy_url_request_context(GetParam().protocol); |
| 2633 { | 2527 { |
| 2634 net::URLRequest r(GURL("http://www.google.com/"), | 2528 net::URLRequest r(GURL("http://www.google.com/"), |
| 2635 DEFAULT_PRIORITY, | 2529 DEFAULT_PRIORITY, |
| 2636 &d, | 2530 &d, |
| 2637 &spdy_url_request_context); | 2531 &spdy_url_request_context); |
| 2638 spdy_url_request_context.socket_factory(). | 2532 spdy_url_request_context.socket_factory().AddSocketDataProvider(&data); |
| 2639 AddSocketDataProvider(&data); | |
| 2640 | 2533 |
| 2641 r.Start(); | 2534 r.Start(); |
| 2642 base::RunLoop().Run(); | 2535 base::RunLoop().Run(); |
| 2643 | 2536 |
| 2644 EXPECT_EQ(0, d.received_redirect_count()); | 2537 EXPECT_EQ(0, d.received_redirect_count()); |
| 2645 std::string contents("hello!"); | 2538 std::string contents("hello!"); |
| 2646 EXPECT_EQ(contents, d.data_received()); | 2539 EXPECT_EQ(contents, d.data_received()); |
| 2647 | 2540 |
| 2648 net::URLRequest r2(GURL("http://www.google.com/foo.dat"), | 2541 net::URLRequest r2(GURL("http://www.google.com/foo.dat"), |
| 2649 DEFAULT_PRIORITY, | 2542 DEFAULT_PRIORITY, |
| 2650 &d2, | 2543 &d2, |
| 2651 &spdy_url_request_context); | 2544 &spdy_url_request_context); |
| 2652 spdy_url_request_context.socket_factory(). | 2545 spdy_url_request_context.socket_factory().AddSocketDataProvider(&data2); |
| 2653 AddSocketDataProvider(&data2); | |
| 2654 | 2546 |
| 2655 d2.set_quit_on_redirect(true); | 2547 d2.set_quit_on_redirect(true); |
| 2656 r2.Start(); | 2548 r2.Start(); |
| 2657 base::RunLoop().Run(); | 2549 base::RunLoop().Run(); |
| 2658 EXPECT_EQ(1, d2.received_redirect_count()); | 2550 EXPECT_EQ(1, d2.received_redirect_count()); |
| 2659 | 2551 |
| 2660 r2.FollowDeferredRedirect(); | 2552 r2.FollowDeferredRedirect(); |
| 2661 base::RunLoop().Run(); | 2553 base::RunLoop().Run(); |
| 2662 EXPECT_EQ(1, d2.response_started_count()); | 2554 EXPECT_EQ(1, d2.response_started_count()); |
| 2663 EXPECT_FALSE(d2.received_data_before_response()); | 2555 EXPECT_FALSE(d2.received_data_before_response()); |
| 2664 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r2.status().status()); | 2556 EXPECT_EQ(net::URLRequestStatus::SUCCESS, r2.status().status()); |
| 2665 std::string contents2("hello!"); | 2557 std::string contents2("hello!"); |
| 2666 EXPECT_EQ(contents2, d2.data_received()); | 2558 EXPECT_EQ(contents2, d2.data_received()); |
| 2667 } | 2559 } |
| 2668 data.CompleteRead(); | 2560 data.CompleteRead(); |
| 2669 data2.CompleteRead(); | 2561 data2.CompleteRead(); |
| 2670 EXPECT_TRUE(data.at_read_eof()); | 2562 EXPECT_TRUE(data.at_read_eof()); |
| 2671 EXPECT_TRUE(data.at_write_eof()); | 2563 EXPECT_TRUE(data.at_write_eof()); |
| 2672 EXPECT_TRUE(data2.at_read_eof()); | 2564 EXPECT_TRUE(data2.at_read_eof()); |
| 2673 EXPECT_TRUE(data2.at_write_eof()); | 2565 EXPECT_TRUE(data2.at_write_eof()); |
| 2674 } | 2566 } |
| 2675 | 2567 |
| 2676 TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame) { | 2568 TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame) { |
| 2677 scoped_ptr<SpdyFrame> stream1_syn( | 2569 scoped_ptr<SpdyFrame> stream1_syn( |
| 2678 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2570 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2679 scoped_ptr<SpdyFrame> stream1_body( | 2571 scoped_ptr<SpdyFrame> stream1_body( |
| 2680 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 2572 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2681 MockWrite writes[] = { | 2573 MockWrite writes[] = { |
| 2682 CreateMockWrite(*stream1_syn, 1), | 2574 CreateMockWrite(*stream1_syn, 1), |
| 2683 }; | 2575 }; |
| 2684 | 2576 |
| 2685 scoped_ptr<SpdyFrame> | 2577 scoped_ptr<SpdyFrame> stream1_reply( |
| 2686 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2578 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2687 scoped_ptr<SpdyFrame> | 2579 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2688 stream2_syn(spdy_util_.ConstructSpdyPush(NULL, | 2580 NULL, 0, 2, 1, "http://www.google.com/foo.dat")); |
| 2689 0, | |
| 2690 2, | |
| 2691 1, | |
| 2692 "http://www.google.com/foo.dat")); | |
| 2693 const char kPushedData[] = "pushed"; | 2581 const char kPushedData[] = "pushed"; |
| 2694 scoped_ptr<SpdyFrame> stream2_body( | 2582 scoped_ptr<SpdyFrame> stream2_body(spdy_util_.ConstructSpdyBodyFrame( |
| 2695 spdy_util_.ConstructSpdyBodyFrame( | 2583 2, kPushedData, strlen(kPushedData), true)); |
| 2696 2, kPushedData, strlen(kPushedData), true)); | |
| 2697 MockRead reads[] = { | 2584 MockRead reads[] = { |
| 2698 CreateMockRead(*stream1_reply, 2), | 2585 CreateMockRead(*stream1_reply, 2), |
| 2699 CreateMockRead(*stream2_syn, 3), | 2586 CreateMockRead(*stream2_syn, 3), |
| 2700 CreateMockRead(*stream1_body, 4, SYNCHRONOUS), | 2587 CreateMockRead(*stream1_body, 4, SYNCHRONOUS), |
| 2701 CreateMockRead(*stream2_body, 5), | 2588 CreateMockRead(*stream2_body, 5), |
| 2702 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause | 2589 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 2703 }; | 2590 }; |
| 2704 | 2591 |
| 2705 HttpResponseInfo response; | 2592 HttpResponseInfo response; |
| 2706 HttpResponseInfo response2; | 2593 HttpResponseInfo response2; |
| 2707 std::string expected_push_result("pushed"); | 2594 std::string expected_push_result("pushed"); |
| 2708 OrderedSocketData data(reads, arraysize(reads), | 2595 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2709 writes, arraysize(writes)); | 2596 RunServerPushTest(&data, &response, &response2, expected_push_result); |
| 2710 RunServerPushTest(&data, | |
| 2711 &response, | |
| 2712 &response2, | |
| 2713 expected_push_result); | |
| 2714 | 2597 |
| 2715 // Verify the SYN_REPLY. | 2598 // Verify the SYN_REPLY. |
| 2716 EXPECT_TRUE(response.headers.get() != NULL); | 2599 EXPECT_TRUE(response.headers.get() != NULL); |
| 2717 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 2600 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2718 | 2601 |
| 2719 // Verify the pushed stream. | 2602 // Verify the pushed stream. |
| 2720 EXPECT_TRUE(response2.headers.get() != NULL); | 2603 EXPECT_TRUE(response2.headers.get() != NULL); |
| 2721 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); | 2604 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2722 } | 2605 } |
| 2723 | 2606 |
| 2724 TEST_P(SpdyNetworkTransactionTest, ServerPushBeforeSynReply) { | 2607 TEST_P(SpdyNetworkTransactionTest, ServerPushBeforeSynReply) { |
| 2725 scoped_ptr<SpdyFrame> stream1_syn( | 2608 scoped_ptr<SpdyFrame> stream1_syn( |
| 2726 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2609 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2727 scoped_ptr<SpdyFrame> stream1_body( | 2610 scoped_ptr<SpdyFrame> stream1_body( |
| 2728 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 2611 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2729 MockWrite writes[] = { | 2612 MockWrite writes[] = { |
| 2730 CreateMockWrite(*stream1_syn, 1), | 2613 CreateMockWrite(*stream1_syn, 1), |
| 2731 }; | 2614 }; |
| 2732 | 2615 |
| 2733 scoped_ptr<SpdyFrame> | 2616 scoped_ptr<SpdyFrame> stream1_reply( |
| 2734 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2617 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2735 scoped_ptr<SpdyFrame> | 2618 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2736 stream2_syn(spdy_util_.ConstructSpdyPush(NULL, | 2619 NULL, 0, 2, 1, "http://www.google.com/foo.dat")); |
| 2737 0, | |
| 2738 2, | |
| 2739 1, | |
| 2740 "http://www.google.com/foo.dat")); | |
| 2741 const char kPushedData[] = "pushed"; | 2620 const char kPushedData[] = "pushed"; |
| 2742 scoped_ptr<SpdyFrame> stream2_body( | 2621 scoped_ptr<SpdyFrame> stream2_body(spdy_util_.ConstructSpdyBodyFrame( |
| 2743 spdy_util_.ConstructSpdyBodyFrame( | 2622 2, kPushedData, strlen(kPushedData), true)); |
| 2744 2, kPushedData, strlen(kPushedData), true)); | |
| 2745 MockRead reads[] = { | 2623 MockRead reads[] = { |
| 2746 CreateMockRead(*stream2_syn, 2), | 2624 CreateMockRead(*stream2_syn, 2), |
| 2747 CreateMockRead(*stream1_reply, 3), | 2625 CreateMockRead(*stream1_reply, 3), |
| 2748 CreateMockRead(*stream1_body, 4, SYNCHRONOUS), | 2626 CreateMockRead(*stream1_body, 4, SYNCHRONOUS), |
| 2749 CreateMockRead(*stream2_body, 5), | 2627 CreateMockRead(*stream2_body, 5), |
| 2750 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause | 2628 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 2751 }; | 2629 }; |
| 2752 | 2630 |
| 2753 HttpResponseInfo response; | 2631 HttpResponseInfo response; |
| 2754 HttpResponseInfo response2; | 2632 HttpResponseInfo response2; |
| 2755 std::string expected_push_result("pushed"); | 2633 std::string expected_push_result("pushed"); |
| 2756 OrderedSocketData data(reads, arraysize(reads), | 2634 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2757 writes, arraysize(writes)); | 2635 RunServerPushTest(&data, &response, &response2, expected_push_result); |
| 2758 RunServerPushTest(&data, | |
| 2759 &response, | |
| 2760 &response2, | |
| 2761 expected_push_result); | |
| 2762 | 2636 |
| 2763 // Verify the SYN_REPLY. | 2637 // Verify the SYN_REPLY. |
| 2764 EXPECT_TRUE(response.headers.get() != NULL); | 2638 EXPECT_TRUE(response.headers.get() != NULL); |
| 2765 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 2639 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2766 | 2640 |
| 2767 // Verify the pushed stream. | 2641 // Verify the pushed stream. |
| 2768 EXPECT_TRUE(response2.headers.get() != NULL); | 2642 EXPECT_TRUE(response2.headers.get() != NULL); |
| 2769 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); | 2643 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2770 } | 2644 } |
| 2771 | 2645 |
| 2772 TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame2) { | 2646 TEST_P(SpdyNetworkTransactionTest, ServerPushSingleDataFrame2) { |
| 2773 scoped_ptr<SpdyFrame> stream1_syn( | 2647 scoped_ptr<SpdyFrame> stream1_syn( |
| 2774 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2648 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2775 MockWrite writes[] = { CreateMockWrite(*stream1_syn, 1), }; | 2649 MockWrite writes[] = { |
| 2650 CreateMockWrite(*stream1_syn, 1), |
| 2651 }; |
| 2776 | 2652 |
| 2777 scoped_ptr<SpdyFrame> | 2653 scoped_ptr<SpdyFrame> stream1_reply( |
| 2778 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2654 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2779 scoped_ptr<SpdyFrame> | 2655 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2780 stream2_syn(spdy_util_.ConstructSpdyPush(NULL, | 2656 NULL, 0, 2, 1, "http://www.google.com/foo.dat")); |
| 2781 0, | |
| 2782 2, | |
| 2783 1, | |
| 2784 "http://www.google.com/foo.dat")); | |
| 2785 const char kPushedData[] = "pushed"; | 2657 const char kPushedData[] = "pushed"; |
| 2786 scoped_ptr<SpdyFrame> stream2_body( | 2658 scoped_ptr<SpdyFrame> stream2_body(spdy_util_.ConstructSpdyBodyFrame( |
| 2787 spdy_util_.ConstructSpdyBodyFrame( | 2659 2, kPushedData, strlen(kPushedData), true)); |
| 2788 2, kPushedData, strlen(kPushedData), true)); | 2660 scoped_ptr<SpdyFrame> stream1_body( |
| 2789 scoped_ptr<SpdyFrame> | 2661 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2790 stream1_body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | |
| 2791 MockRead reads[] = { | 2662 MockRead reads[] = { |
| 2792 CreateMockRead(*stream1_reply, 2), | 2663 CreateMockRead(*stream1_reply, 2), |
| 2793 CreateMockRead(*stream2_syn, 3), | 2664 CreateMockRead(*stream2_syn, 3), |
| 2794 CreateMockRead(*stream2_body, 4), | 2665 CreateMockRead(*stream2_body, 4), |
| 2795 CreateMockRead(*stream1_body, 5, SYNCHRONOUS), | 2666 CreateMockRead(*stream1_body, 5, SYNCHRONOUS), |
| 2796 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause | 2667 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 2797 }; | 2668 }; |
| 2798 | 2669 |
| 2799 HttpResponseInfo response; | 2670 HttpResponseInfo response; |
| 2800 HttpResponseInfo response2; | 2671 HttpResponseInfo response2; |
| 2801 std::string expected_push_result("pushed"); | 2672 std::string expected_push_result("pushed"); |
| 2802 OrderedSocketData data(reads, arraysize(reads), | 2673 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2803 writes, arraysize(writes)); | 2674 RunServerPushTest(&data, &response, &response2, expected_push_result); |
| 2804 RunServerPushTest(&data, | |
| 2805 &response, | |
| 2806 &response2, | |
| 2807 expected_push_result); | |
| 2808 | 2675 |
| 2809 // Verify the SYN_REPLY. | 2676 // Verify the SYN_REPLY. |
| 2810 EXPECT_TRUE(response.headers.get() != NULL); | 2677 EXPECT_TRUE(response.headers.get() != NULL); |
| 2811 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 2678 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2812 | 2679 |
| 2813 // Verify the pushed stream. | 2680 // Verify the pushed stream. |
| 2814 EXPECT_TRUE(response2.headers.get() != NULL); | 2681 EXPECT_TRUE(response2.headers.get() != NULL); |
| 2815 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); | 2682 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2816 } | 2683 } |
| 2817 | 2684 |
| 2818 TEST_P(SpdyNetworkTransactionTest, ServerPushServerAborted) { | 2685 TEST_P(SpdyNetworkTransactionTest, ServerPushServerAborted) { |
| 2819 scoped_ptr<SpdyFrame> stream1_syn( | 2686 scoped_ptr<SpdyFrame> stream1_syn( |
| 2820 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2687 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2821 scoped_ptr<SpdyFrame> stream1_body( | 2688 scoped_ptr<SpdyFrame> stream1_body( |
| 2822 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 2689 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2823 MockWrite writes[] = { | 2690 MockWrite writes[] = { |
| 2824 CreateMockWrite(*stream1_syn, 1), | 2691 CreateMockWrite(*stream1_syn, 1), |
| 2825 }; | 2692 }; |
| 2826 | 2693 |
| 2827 scoped_ptr<SpdyFrame> | 2694 scoped_ptr<SpdyFrame> stream1_reply( |
| 2828 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2695 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2829 scoped_ptr<SpdyFrame> | 2696 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2830 stream2_syn(spdy_util_.ConstructSpdyPush(NULL, | 2697 NULL, 0, 2, 1, "http://www.google.com/foo.dat")); |
| 2831 0, | |
| 2832 2, | |
| 2833 1, | |
| 2834 "http://www.google.com/foo.dat")); | |
| 2835 scoped_ptr<SpdyFrame> stream2_rst( | 2698 scoped_ptr<SpdyFrame> stream2_rst( |
| 2836 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); | 2699 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
| 2837 MockRead reads[] = { | 2700 MockRead reads[] = { |
| 2838 CreateMockRead(*stream1_reply, 2), | 2701 CreateMockRead(*stream1_reply, 2), |
| 2839 CreateMockRead(*stream2_syn, 3), | 2702 CreateMockRead(*stream2_syn, 3), |
| 2840 CreateMockRead(*stream2_rst, 4), | 2703 CreateMockRead(*stream2_rst, 4), |
| 2841 CreateMockRead(*stream1_body, 5, SYNCHRONOUS), | 2704 CreateMockRead(*stream1_body, 5, SYNCHRONOUS), |
| 2842 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause | 2705 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 2843 }; | 2706 }; |
| 2844 | 2707 |
| 2845 OrderedSocketData data(reads, arraysize(reads), | 2708 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2846 writes, arraysize(writes)); | 2709 NormalSpdyTransactionHelper helper( |
| 2847 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 2710 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 2848 BoundNetLog(), GetParam(), NULL); | |
| 2849 | 2711 |
| 2850 helper.RunPreTestSetup(); | 2712 helper.RunPreTestSetup(); |
| 2851 helper.AddData(&data); | 2713 helper.AddData(&data); |
| 2852 | 2714 |
| 2853 HttpNetworkTransaction* trans = helper.trans(); | 2715 HttpNetworkTransaction* trans = helper.trans(); |
| 2854 | 2716 |
| 2855 // Start the transaction with basic parameters. | 2717 // Start the transaction with basic parameters. |
| 2856 TestCompletionCallback callback; | 2718 TestCompletionCallback callback; |
| 2857 int rv = trans->Start( | 2719 int rv = |
| 2858 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 2720 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 2859 EXPECT_EQ(ERR_IO_PENDING, rv); | 2721 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2860 rv = callback.WaitForResult(); | 2722 rv = callback.WaitForResult(); |
| 2861 EXPECT_EQ(OK, rv); | 2723 EXPECT_EQ(OK, rv); |
| 2862 | 2724 |
| 2863 // Verify that we consumed all test data. | 2725 // Verify that we consumed all test data. |
| 2864 EXPECT_TRUE(data.at_read_eof()) << "Read count: " | 2726 EXPECT_TRUE(data.at_read_eof()) << "Read count: " << data.read_count() |
| 2865 << data.read_count() | 2727 << " Read index: " << data.read_index(); |
| 2866 << " Read index: " | 2728 EXPECT_TRUE(data.at_write_eof()) << "Write count: " << data.write_count() |
| 2867 << data.read_index(); | 2729 << " Write index: " << data.write_index(); |
| 2868 EXPECT_TRUE(data.at_write_eof()) << "Write count: " | |
| 2869 << data.write_count() | |
| 2870 << " Write index: " | |
| 2871 << data.write_index(); | |
| 2872 | 2730 |
| 2873 // Verify the SYN_REPLY. | 2731 // Verify the SYN_REPLY. |
| 2874 HttpResponseInfo response = *trans->GetResponseInfo(); | 2732 HttpResponseInfo response = *trans->GetResponseInfo(); |
| 2875 EXPECT_TRUE(response.headers.get() != NULL); | 2733 EXPECT_TRUE(response.headers.get() != NULL); |
| 2876 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 2734 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2877 } | 2735 } |
| 2878 | 2736 |
| 2879 // Verify that we don't leak streams and that we properly send a reset | 2737 // Verify that we don't leak streams and that we properly send a reset |
| 2880 // if the server pushes the same stream twice. | 2738 // if the server pushes the same stream twice. |
| 2881 TEST_P(SpdyNetworkTransactionTest, ServerPushDuplicate) { | 2739 TEST_P(SpdyNetworkTransactionTest, ServerPushDuplicate) { |
| 2882 scoped_ptr<SpdyFrame> stream1_syn( | 2740 scoped_ptr<SpdyFrame> stream1_syn( |
| 2883 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2741 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2884 scoped_ptr<SpdyFrame> stream1_body( | 2742 scoped_ptr<SpdyFrame> stream1_body( |
| 2885 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 2743 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2886 scoped_ptr<SpdyFrame> stream3_rst( | 2744 scoped_ptr<SpdyFrame> stream3_rst( |
| 2887 spdy_util_.ConstructSpdyRstStream(4, RST_STREAM_PROTOCOL_ERROR)); | 2745 spdy_util_.ConstructSpdyRstStream(4, RST_STREAM_PROTOCOL_ERROR)); |
| 2888 MockWrite writes[] = { | 2746 MockWrite writes[] = { |
| 2889 CreateMockWrite(*stream1_syn, 1), | 2747 CreateMockWrite(*stream1_syn, 1), CreateMockWrite(*stream3_rst, 5), |
| 2890 CreateMockWrite(*stream3_rst, 5), | |
| 2891 }; | 2748 }; |
| 2892 | 2749 |
| 2893 scoped_ptr<SpdyFrame> | 2750 scoped_ptr<SpdyFrame> stream1_reply( |
| 2894 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2751 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2895 scoped_ptr<SpdyFrame> | 2752 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2896 stream2_syn(spdy_util_.ConstructSpdyPush(NULL, | 2753 NULL, 0, 2, 1, "http://www.google.com/foo.dat")); |
| 2897 0, | |
| 2898 2, | |
| 2899 1, | |
| 2900 "http://www.google.com/foo.dat")); | |
| 2901 const char kPushedData[] = "pushed"; | 2754 const char kPushedData[] = "pushed"; |
| 2902 scoped_ptr<SpdyFrame> stream2_body( | 2755 scoped_ptr<SpdyFrame> stream2_body(spdy_util_.ConstructSpdyBodyFrame( |
| 2903 spdy_util_.ConstructSpdyBodyFrame( | 2756 2, kPushedData, strlen(kPushedData), true)); |
| 2904 2, kPushedData, strlen(kPushedData), true)); | 2757 scoped_ptr<SpdyFrame> stream3_syn(spdy_util_.ConstructSpdyPush( |
| 2905 scoped_ptr<SpdyFrame> | 2758 NULL, 0, 4, 1, "http://www.google.com/foo.dat")); |
| 2906 stream3_syn(spdy_util_.ConstructSpdyPush(NULL, | |
| 2907 0, | |
| 2908 4, | |
| 2909 1, | |
| 2910 "http://www.google.com/foo.dat")); | |
| 2911 MockRead reads[] = { | 2759 MockRead reads[] = { |
| 2912 CreateMockRead(*stream1_reply, 2), | 2760 CreateMockRead(*stream1_reply, 2), |
| 2913 CreateMockRead(*stream2_syn, 3), | 2761 CreateMockRead(*stream2_syn, 3), |
| 2914 CreateMockRead(*stream3_syn, 4), | 2762 CreateMockRead(*stream3_syn, 4), |
| 2915 CreateMockRead(*stream1_body, 6, SYNCHRONOUS), | 2763 CreateMockRead(*stream1_body, 6, SYNCHRONOUS), |
| 2916 CreateMockRead(*stream2_body, 7), | 2764 CreateMockRead(*stream2_body, 7), |
| 2917 MockRead(ASYNC, ERR_IO_PENDING, 8), // Force a pause | 2765 MockRead(ASYNC, ERR_IO_PENDING, 8), // Force a pause |
| 2918 }; | 2766 }; |
| 2919 | 2767 |
| 2920 HttpResponseInfo response; | 2768 HttpResponseInfo response; |
| 2921 HttpResponseInfo response2; | 2769 HttpResponseInfo response2; |
| 2922 std::string expected_push_result("pushed"); | 2770 std::string expected_push_result("pushed"); |
| 2923 OrderedSocketData data(reads, arraysize(reads), | 2771 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2924 writes, arraysize(writes)); | 2772 RunServerPushTest(&data, &response, &response2, expected_push_result); |
| 2925 RunServerPushTest(&data, | |
| 2926 &response, | |
| 2927 &response2, | |
| 2928 expected_push_result); | |
| 2929 | 2773 |
| 2930 // Verify the SYN_REPLY. | 2774 // Verify the SYN_REPLY. |
| 2931 EXPECT_TRUE(response.headers.get() != NULL); | 2775 EXPECT_TRUE(response.headers.get() != NULL); |
| 2932 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 2776 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2933 | 2777 |
| 2934 // Verify the pushed stream. | 2778 // Verify the pushed stream. |
| 2935 EXPECT_TRUE(response2.headers.get() != NULL); | 2779 EXPECT_TRUE(response2.headers.get() != NULL); |
| 2936 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); | 2780 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2937 } | 2781 } |
| 2938 | 2782 |
| 2939 TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrame) { | 2783 TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrame) { |
| 2940 scoped_ptr<SpdyFrame> stream1_syn( | 2784 scoped_ptr<SpdyFrame> stream1_syn( |
| 2941 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2785 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 2942 scoped_ptr<SpdyFrame> stream1_body( | 2786 scoped_ptr<SpdyFrame> stream1_body( |
| 2943 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 2787 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 2944 MockWrite writes[] = { | 2788 MockWrite writes[] = { |
| 2945 CreateMockWrite(*stream1_syn, 1), | 2789 CreateMockWrite(*stream1_syn, 1), |
| 2946 }; | 2790 }; |
| 2947 | 2791 |
| 2948 scoped_ptr<SpdyFrame> | 2792 scoped_ptr<SpdyFrame> stream1_reply( |
| 2949 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2793 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 2950 scoped_ptr<SpdyFrame> | 2794 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 2951 stream2_syn(spdy_util_.ConstructSpdyPush(NULL, | 2795 NULL, 0, 2, 1, "http://www.google.com/foo.dat")); |
| 2952 0, | |
| 2953 2, | |
| 2954 1, | |
| 2955 "http://www.google.com/foo.dat")); | |
| 2956 static const char kPushedData[] = "pushed my darling hello my baby"; | 2796 static const char kPushedData[] = "pushed my darling hello my baby"; |
| 2957 scoped_ptr<SpdyFrame> stream2_body_base( | 2797 scoped_ptr<SpdyFrame> stream2_body_base(spdy_util_.ConstructSpdyBodyFrame( |
| 2958 spdy_util_.ConstructSpdyBodyFrame( | 2798 2, kPushedData, strlen(kPushedData), true)); |
| 2959 2, kPushedData, strlen(kPushedData), true)); | |
| 2960 const size_t kChunkSize = strlen(kPushedData) / 4; | 2799 const size_t kChunkSize = strlen(kPushedData) / 4; |
| 2961 scoped_ptr<SpdyFrame> stream2_body1( | 2800 scoped_ptr<SpdyFrame> stream2_body1( |
| 2962 new SpdyFrame(stream2_body_base->data(), kChunkSize, false)); | 2801 new SpdyFrame(stream2_body_base->data(), kChunkSize, false)); |
| 2963 scoped_ptr<SpdyFrame> stream2_body2( | 2802 scoped_ptr<SpdyFrame> stream2_body2( |
| 2964 new SpdyFrame(stream2_body_base->data() + kChunkSize, kChunkSize, false)); | 2803 new SpdyFrame(stream2_body_base->data() + kChunkSize, kChunkSize, false)); |
| 2965 scoped_ptr<SpdyFrame> stream2_body3( | 2804 scoped_ptr<SpdyFrame> stream2_body3(new SpdyFrame( |
| 2966 new SpdyFrame(stream2_body_base->data() + 2 * kChunkSize, | 2805 stream2_body_base->data() + 2 * kChunkSize, kChunkSize, false)); |
| 2967 kChunkSize, false)); | |
| 2968 scoped_ptr<SpdyFrame> stream2_body4( | 2806 scoped_ptr<SpdyFrame> stream2_body4( |
| 2969 new SpdyFrame(stream2_body_base->data() + 3 * kChunkSize, | 2807 new SpdyFrame(stream2_body_base->data() + 3 * kChunkSize, |
| 2970 stream2_body_base->size() - 3 * kChunkSize, false)); | 2808 stream2_body_base->size() - 3 * kChunkSize, |
| 2809 false)); |
| 2971 MockRead reads[] = { | 2810 MockRead reads[] = { |
| 2972 CreateMockRead(*stream1_reply, 2), | 2811 CreateMockRead(*stream1_reply, 2), |
| 2973 CreateMockRead(*stream2_syn, 3), | 2812 CreateMockRead(*stream2_syn, 3), |
| 2974 CreateMockRead(*stream2_body1, 4), | 2813 CreateMockRead(*stream2_body1, 4), |
| 2975 CreateMockRead(*stream2_body2, 5), | 2814 CreateMockRead(*stream2_body2, 5), |
| 2976 CreateMockRead(*stream2_body3, 6), | 2815 CreateMockRead(*stream2_body3, 6), |
| 2977 CreateMockRead(*stream2_body4, 7), | 2816 CreateMockRead(*stream2_body4, 7), |
| 2978 CreateMockRead(*stream1_body, 8, SYNCHRONOUS), | 2817 CreateMockRead(*stream1_body, 8, SYNCHRONOUS), |
| 2979 MockRead(ASYNC, ERR_IO_PENDING, 9), // Force a pause | 2818 MockRead(ASYNC, ERR_IO_PENDING, 9), // Force a pause |
| 2980 }; | 2819 }; |
| 2981 | 2820 |
| 2982 HttpResponseInfo response; | 2821 HttpResponseInfo response; |
| 2983 HttpResponseInfo response2; | 2822 HttpResponseInfo response2; |
| 2984 std::string expected_push_result("pushed my darling hello my baby"); | 2823 std::string expected_push_result("pushed my darling hello my baby"); |
| 2985 OrderedSocketData data(reads, arraysize(reads), | 2824 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 2986 writes, arraysize(writes)); | |
| 2987 RunServerPushTest(&data, &response, &response2, kPushedData); | 2825 RunServerPushTest(&data, &response, &response2, kPushedData); |
| 2988 | 2826 |
| 2989 // Verify the SYN_REPLY. | 2827 // Verify the SYN_REPLY. |
| 2990 EXPECT_TRUE(response.headers.get() != NULL); | 2828 EXPECT_TRUE(response.headers.get() != NULL); |
| 2991 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 2829 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 2992 | 2830 |
| 2993 // Verify the pushed stream. | 2831 // Verify the pushed stream. |
| 2994 EXPECT_TRUE(response2.headers.get() != NULL); | 2832 EXPECT_TRUE(response2.headers.get() != NULL); |
| 2995 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); | 2833 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 2996 } | 2834 } |
| 2997 | 2835 |
| 2998 TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrameInterrupted) { | 2836 TEST_P(SpdyNetworkTransactionTest, ServerPushMultipleDataFrameInterrupted) { |
| 2999 scoped_ptr<SpdyFrame> stream1_syn( | 2837 scoped_ptr<SpdyFrame> stream1_syn( |
| 3000 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2838 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3001 scoped_ptr<SpdyFrame> stream1_body( | 2839 scoped_ptr<SpdyFrame> stream1_body( |
| 3002 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 2840 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3003 MockWrite writes[] = { | 2841 MockWrite writes[] = { |
| 3004 CreateMockWrite(*stream1_syn, 1), | 2842 CreateMockWrite(*stream1_syn, 1), |
| 3005 }; | 2843 }; |
| 3006 | 2844 |
| 3007 scoped_ptr<SpdyFrame> | 2845 scoped_ptr<SpdyFrame> stream1_reply( |
| 3008 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2846 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3009 scoped_ptr<SpdyFrame> | 2847 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 3010 stream2_syn(spdy_util_.ConstructSpdyPush(NULL, | 2848 NULL, 0, 2, 1, "http://www.google.com/foo.dat")); |
| 3011 0, | |
| 3012 2, | |
| 3013 1, | |
| 3014 "http://www.google.com/foo.dat")); | |
| 3015 static const char kPushedData[] = "pushed my darling hello my baby"; | 2849 static const char kPushedData[] = "pushed my darling hello my baby"; |
| 3016 scoped_ptr<SpdyFrame> stream2_body_base( | 2850 scoped_ptr<SpdyFrame> stream2_body_base(spdy_util_.ConstructSpdyBodyFrame( |
| 3017 spdy_util_.ConstructSpdyBodyFrame( | 2851 2, kPushedData, strlen(kPushedData), true)); |
| 3018 2, kPushedData, strlen(kPushedData), true)); | |
| 3019 const size_t kChunkSize = strlen(kPushedData) / 4; | 2852 const size_t kChunkSize = strlen(kPushedData) / 4; |
| 3020 scoped_ptr<SpdyFrame> stream2_body1( | 2853 scoped_ptr<SpdyFrame> stream2_body1( |
| 3021 new SpdyFrame(stream2_body_base->data(), kChunkSize, false)); | 2854 new SpdyFrame(stream2_body_base->data(), kChunkSize, false)); |
| 3022 scoped_ptr<SpdyFrame> stream2_body2( | 2855 scoped_ptr<SpdyFrame> stream2_body2( |
| 3023 new SpdyFrame(stream2_body_base->data() + kChunkSize, kChunkSize, false)); | 2856 new SpdyFrame(stream2_body_base->data() + kChunkSize, kChunkSize, false)); |
| 3024 scoped_ptr<SpdyFrame> stream2_body3( | 2857 scoped_ptr<SpdyFrame> stream2_body3(new SpdyFrame( |
| 3025 new SpdyFrame(stream2_body_base->data() + 2 * kChunkSize, | 2858 stream2_body_base->data() + 2 * kChunkSize, kChunkSize, false)); |
| 3026 kChunkSize, false)); | |
| 3027 scoped_ptr<SpdyFrame> stream2_body4( | 2859 scoped_ptr<SpdyFrame> stream2_body4( |
| 3028 new SpdyFrame(stream2_body_base->data() + 3 * kChunkSize, | 2860 new SpdyFrame(stream2_body_base->data() + 3 * kChunkSize, |
| 3029 stream2_body_base->size() - 3 * kChunkSize, false)); | 2861 stream2_body_base->size() - 3 * kChunkSize, |
| 2862 false)); |
| 3030 MockRead reads[] = { | 2863 MockRead reads[] = { |
| 3031 CreateMockRead(*stream1_reply, 2), | 2864 CreateMockRead(*stream1_reply, 2), CreateMockRead(*stream2_syn, 3), |
| 3032 CreateMockRead(*stream2_syn, 3), | 2865 CreateMockRead(*stream2_body1, 4), CreateMockRead(*stream2_body2, 5), |
| 3033 CreateMockRead(*stream2_body1, 4), | 2866 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause |
| 3034 CreateMockRead(*stream2_body2, 5), | 2867 CreateMockRead(*stream2_body3, 7), CreateMockRead(*stream2_body4, 8), |
| 3035 MockRead(ASYNC, ERR_IO_PENDING, 6), // Force a pause | 2868 CreateMockRead(*stream1_body.get(), 9, SYNCHRONOUS), |
| 3036 CreateMockRead(*stream2_body3, 7), | 2869 MockRead(ASYNC, ERR_IO_PENDING, 10) // Force a pause. |
| 3037 CreateMockRead(*stream2_body4, 8), | |
| 3038 CreateMockRead(*stream1_body.get(), 9, SYNCHRONOUS), | |
| 3039 MockRead(ASYNC, ERR_IO_PENDING, 10) // Force a pause. | |
| 3040 }; | 2870 }; |
| 3041 | 2871 |
| 3042 HttpResponseInfo response; | 2872 HttpResponseInfo response; |
| 3043 HttpResponseInfo response2; | 2873 HttpResponseInfo response2; |
| 3044 OrderedSocketData data(reads, arraysize(reads), | 2874 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 3045 writes, arraysize(writes)); | |
| 3046 RunServerPushTest(&data, &response, &response2, kPushedData); | 2875 RunServerPushTest(&data, &response, &response2, kPushedData); |
| 3047 | 2876 |
| 3048 // Verify the SYN_REPLY. | 2877 // Verify the SYN_REPLY. |
| 3049 EXPECT_TRUE(response.headers.get() != NULL); | 2878 EXPECT_TRUE(response.headers.get() != NULL); |
| 3050 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 2879 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 3051 | 2880 |
| 3052 // Verify the pushed stream. | 2881 // Verify the pushed stream. |
| 3053 EXPECT_TRUE(response2.headers.get() != NULL); | 2882 EXPECT_TRUE(response2.headers.get() != NULL); |
| 3054 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); | 2883 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 3055 } | 2884 } |
| 3056 | 2885 |
| 3057 TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID0) { | 2886 TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID0) { |
| 3058 if (spdy_util_.spdy_version() == SPDY4) { | 2887 if (spdy_util_.spdy_version() == SPDY4) { |
| 3059 // TODO(jgraettinger): We don't support associated stream | 2888 // TODO(jgraettinger): We don't support associated stream |
| 3060 // checks in SPDY4 yet. | 2889 // checks in SPDY4 yet. |
| 3061 return; | 2890 return; |
| 3062 } | 2891 } |
| 3063 scoped_ptr<SpdyFrame> stream1_syn( | 2892 scoped_ptr<SpdyFrame> stream1_syn( |
| 3064 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2893 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3065 scoped_ptr<SpdyFrame> stream1_body( | 2894 scoped_ptr<SpdyFrame> stream1_body( |
| 3066 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 2895 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3067 scoped_ptr<SpdyFrame> stream2_rst( | 2896 scoped_ptr<SpdyFrame> stream2_rst( |
| 3068 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); | 2897 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
| 3069 MockWrite writes[] = { | 2898 MockWrite writes[] = { |
| 3070 CreateMockWrite(*stream1_syn, 1), | 2899 CreateMockWrite(*stream1_syn, 1), CreateMockWrite(*stream2_rst, 4), |
| 3071 CreateMockWrite(*stream2_rst, 4), | |
| 3072 }; | 2900 }; |
| 3073 | 2901 |
| 3074 scoped_ptr<SpdyFrame> | 2902 scoped_ptr<SpdyFrame> stream1_reply( |
| 3075 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2903 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3076 scoped_ptr<SpdyFrame> | 2904 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 3077 stream2_syn(spdy_util_.ConstructSpdyPush(NULL, | 2905 NULL, 0, 2, 0, "http://www.google.com/foo.dat")); |
| 3078 0, | |
| 3079 2, | |
| 3080 0, | |
| 3081 "http://www.google.com/foo.dat")); | |
| 3082 MockRead reads[] = { | 2906 MockRead reads[] = { |
| 3083 CreateMockRead(*stream1_reply, 2), | 2907 CreateMockRead(*stream1_reply, 2), CreateMockRead(*stream2_syn, 3), |
| 3084 CreateMockRead(*stream2_syn, 3), | 2908 CreateMockRead(*stream1_body, 4), |
| 3085 CreateMockRead(*stream1_body, 4), | 2909 MockRead(ASYNC, ERR_IO_PENDING, 5) // Force a pause |
| 3086 MockRead(ASYNC, ERR_IO_PENDING, 5) // Force a pause | |
| 3087 }; | 2910 }; |
| 3088 | 2911 |
| 3089 OrderedSocketData data(reads, arraysize(reads), | 2912 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 3090 writes, arraysize(writes)); | 2913 NormalSpdyTransactionHelper helper( |
| 3091 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 2914 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3092 BoundNetLog(), GetParam(), NULL); | |
| 3093 | 2915 |
| 3094 helper.RunPreTestSetup(); | 2916 helper.RunPreTestSetup(); |
| 3095 helper.AddData(&data); | 2917 helper.AddData(&data); |
| 3096 | 2918 |
| 3097 HttpNetworkTransaction* trans = helper.trans(); | 2919 HttpNetworkTransaction* trans = helper.trans(); |
| 3098 | 2920 |
| 3099 // Start the transaction with basic parameters. | 2921 // Start the transaction with basic parameters. |
| 3100 TestCompletionCallback callback; | 2922 TestCompletionCallback callback; |
| 3101 int rv = trans->Start( | 2923 int rv = |
| 3102 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 2924 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 3103 EXPECT_EQ(ERR_IO_PENDING, rv); | 2925 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3104 rv = callback.WaitForResult(); | 2926 rv = callback.WaitForResult(); |
| 3105 EXPECT_EQ(OK, rv); | 2927 EXPECT_EQ(OK, rv); |
| 3106 | 2928 |
| 3107 // Verify that we consumed all test data. | 2929 // Verify that we consumed all test data. |
| 3108 EXPECT_TRUE(data.at_read_eof()) << "Read count: " | 2930 EXPECT_TRUE(data.at_read_eof()) << "Read count: " << data.read_count() |
| 3109 << data.read_count() | 2931 << " Read index: " << data.read_index(); |
| 3110 << " Read index: " | 2932 EXPECT_TRUE(data.at_write_eof()) << "Write count: " << data.write_count() |
| 3111 << data.read_index(); | 2933 << " Write index: " << data.write_index(); |
| 3112 EXPECT_TRUE(data.at_write_eof()) << "Write count: " | |
| 3113 << data.write_count() | |
| 3114 << " Write index: " | |
| 3115 << data.write_index(); | |
| 3116 | 2934 |
| 3117 // Verify the SYN_REPLY. | 2935 // Verify the SYN_REPLY. |
| 3118 HttpResponseInfo response = *trans->GetResponseInfo(); | 2936 HttpResponseInfo response = *trans->GetResponseInfo(); |
| 3119 EXPECT_TRUE(response.headers.get() != NULL); | 2937 EXPECT_TRUE(response.headers.get() != NULL); |
| 3120 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 2938 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 3121 } | 2939 } |
| 3122 | 2940 |
| 3123 TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID9) { | 2941 TEST_P(SpdyNetworkTransactionTest, ServerPushInvalidAssociatedStreamID9) { |
| 3124 if (spdy_util_.spdy_version() == SPDY4) { | 2942 if (spdy_util_.spdy_version() == SPDY4) { |
| 3125 // TODO(jgraettinger): We don't support associated stream | 2943 // TODO(jgraettinger): We don't support associated stream |
| 3126 // checks in SPDY4 yet. | 2944 // checks in SPDY4 yet. |
| 3127 return; | 2945 return; |
| 3128 } | 2946 } |
| 3129 scoped_ptr<SpdyFrame> stream1_syn( | 2947 scoped_ptr<SpdyFrame> stream1_syn( |
| 3130 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2948 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3131 scoped_ptr<SpdyFrame> stream1_body( | 2949 scoped_ptr<SpdyFrame> stream1_body( |
| 3132 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 2950 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3133 scoped_ptr<SpdyFrame> stream2_rst( | 2951 scoped_ptr<SpdyFrame> stream2_rst( |
| 3134 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_INVALID_STREAM)); | 2952 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_INVALID_STREAM)); |
| 3135 MockWrite writes[] = { | 2953 MockWrite writes[] = { |
| 3136 CreateMockWrite(*stream1_syn, 1), | 2954 CreateMockWrite(*stream1_syn, 1), CreateMockWrite(*stream2_rst, 4), |
| 3137 CreateMockWrite(*stream2_rst, 4), | |
| 3138 }; | 2955 }; |
| 3139 | 2956 |
| 3140 scoped_ptr<SpdyFrame> | 2957 scoped_ptr<SpdyFrame> stream1_reply( |
| 3141 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 2958 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3142 scoped_ptr<SpdyFrame> | 2959 scoped_ptr<SpdyFrame> stream2_syn(spdy_util_.ConstructSpdyPush( |
| 3143 stream2_syn(spdy_util_.ConstructSpdyPush(NULL, | 2960 NULL, 0, 2, 9, "http://www.google.com/foo.dat")); |
| 3144 0, | |
| 3145 2, | |
| 3146 9, | |
| 3147 "http://www.google.com/foo.dat")); | |
| 3148 MockRead reads[] = { | 2961 MockRead reads[] = { |
| 3149 CreateMockRead(*stream1_reply, 2), | 2962 CreateMockRead(*stream1_reply, 2), CreateMockRead(*stream2_syn, 3), |
| 3150 CreateMockRead(*stream2_syn, 3), | 2963 CreateMockRead(*stream1_body, 4), |
| 3151 CreateMockRead(*stream1_body, 4), | 2964 MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause |
| 3152 MockRead(ASYNC, ERR_IO_PENDING, 5), // Force a pause | |
| 3153 }; | 2965 }; |
| 3154 | 2966 |
| 3155 OrderedSocketData data(reads, arraysize(reads), | 2967 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 3156 writes, arraysize(writes)); | 2968 NormalSpdyTransactionHelper helper( |
| 3157 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 2969 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3158 BoundNetLog(), GetParam(), NULL); | |
| 3159 | 2970 |
| 3160 helper.RunPreTestSetup(); | 2971 helper.RunPreTestSetup(); |
| 3161 helper.AddData(&data); | 2972 helper.AddData(&data); |
| 3162 | 2973 |
| 3163 HttpNetworkTransaction* trans = helper.trans(); | 2974 HttpNetworkTransaction* trans = helper.trans(); |
| 3164 | 2975 |
| 3165 // Start the transaction with basic parameters. | 2976 // Start the transaction with basic parameters. |
| 3166 TestCompletionCallback callback; | 2977 TestCompletionCallback callback; |
| 3167 int rv = trans->Start( | 2978 int rv = |
| 3168 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 2979 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 3169 EXPECT_EQ(ERR_IO_PENDING, rv); | 2980 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3170 rv = callback.WaitForResult(); | 2981 rv = callback.WaitForResult(); |
| 3171 EXPECT_EQ(OK, rv); | 2982 EXPECT_EQ(OK, rv); |
| 3172 | 2983 |
| 3173 // Verify that we consumed all test data. | 2984 // Verify that we consumed all test data. |
| 3174 EXPECT_TRUE(data.at_read_eof()) << "Read count: " | 2985 EXPECT_TRUE(data.at_read_eof()) << "Read count: " << data.read_count() |
| 3175 << data.read_count() | 2986 << " Read index: " << data.read_index(); |
| 3176 << " Read index: " | 2987 EXPECT_TRUE(data.at_write_eof()) << "Write count: " << data.write_count() |
| 3177 << data.read_index(); | 2988 << " Write index: " << data.write_index(); |
| 3178 EXPECT_TRUE(data.at_write_eof()) << "Write count: " | |
| 3179 << data.write_count() | |
| 3180 << " Write index: " | |
| 3181 << data.write_index(); | |
| 3182 | 2989 |
| 3183 // Verify the SYN_REPLY. | 2990 // Verify the SYN_REPLY. |
| 3184 HttpResponseInfo response = *trans->GetResponseInfo(); | 2991 HttpResponseInfo response = *trans->GetResponseInfo(); |
| 3185 EXPECT_TRUE(response.headers.get() != NULL); | 2992 EXPECT_TRUE(response.headers.get() != NULL); |
| 3186 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 2993 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 3187 } | 2994 } |
| 3188 | 2995 |
| 3189 TEST_P(SpdyNetworkTransactionTest, ServerPushNoURL) { | 2996 TEST_P(SpdyNetworkTransactionTest, ServerPushNoURL) { |
| 3190 scoped_ptr<SpdyFrame> stream1_syn( | 2997 scoped_ptr<SpdyFrame> stream1_syn( |
| 3191 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 2998 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3192 scoped_ptr<SpdyFrame> stream1_body( | 2999 scoped_ptr<SpdyFrame> stream1_body( |
| 3193 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 3000 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3194 scoped_ptr<SpdyFrame> stream2_rst( | 3001 scoped_ptr<SpdyFrame> stream2_rst( |
| 3195 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); | 3002 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_PROTOCOL_ERROR)); |
| 3196 MockWrite writes[] = { | 3003 MockWrite writes[] = { |
| 3197 CreateMockWrite(*stream1_syn, 1), | 3004 CreateMockWrite(*stream1_syn, 1), CreateMockWrite(*stream2_rst, 4), |
| 3198 CreateMockWrite(*stream2_rst, 4), | |
| 3199 }; | 3005 }; |
| 3200 | 3006 |
| 3201 scoped_ptr<SpdyFrame> | 3007 scoped_ptr<SpdyFrame> stream1_reply( |
| 3202 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 3008 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3203 scoped_ptr<SpdyHeaderBlock> incomplete_headers(new SpdyHeaderBlock()); | 3009 scoped_ptr<SpdyHeaderBlock> incomplete_headers(new SpdyHeaderBlock()); |
| 3204 (*incomplete_headers)["hello"] = "bye"; | 3010 (*incomplete_headers)["hello"] = "bye"; |
| 3205 (*incomplete_headers)[spdy_util_.GetStatusKey()] = "200 OK"; | 3011 (*incomplete_headers)[spdy_util_.GetStatusKey()] = "200 OK"; |
| 3206 (*incomplete_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | 3012 (*incomplete_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
| 3207 scoped_ptr<SpdyFrame> stream2_syn( | 3013 scoped_ptr<SpdyFrame> stream2_syn( |
| 3208 spdy_util_.ConstructSpdyControlFrame(incomplete_headers.Pass(), | 3014 spdy_util_.ConstructSpdyControlFrame(incomplete_headers.Pass(), |
| 3209 false, | 3015 false, |
| 3210 2, // Stream ID | 3016 2, // Stream ID |
| 3211 LOWEST, | 3017 LOWEST, |
| 3212 SYN_STREAM, | 3018 SYN_STREAM, |
| 3213 CONTROL_FLAG_NONE, | 3019 CONTROL_FLAG_NONE, |
| 3214 // Associated stream ID | 3020 // Associated stream ID |
| 3215 1)); | 3021 1)); |
| 3216 MockRead reads[] = { | 3022 MockRead reads[] = { |
| 3217 CreateMockRead(*stream1_reply, 2), | 3023 CreateMockRead(*stream1_reply, 2), CreateMockRead(*stream2_syn, 3), |
| 3218 CreateMockRead(*stream2_syn, 3), | 3024 CreateMockRead(*stream1_body, 4), |
| 3219 CreateMockRead(*stream1_body, 4), | 3025 MockRead(ASYNC, ERR_IO_PENDING, 5) // Force a pause |
| 3220 MockRead(ASYNC, ERR_IO_PENDING, 5) // Force a pause | |
| 3221 }; | 3026 }; |
| 3222 | 3027 |
| 3223 OrderedSocketData data(reads, arraysize(reads), | 3028 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 3224 writes, arraysize(writes)); | 3029 NormalSpdyTransactionHelper helper( |
| 3225 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 3030 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3226 BoundNetLog(), GetParam(), NULL); | |
| 3227 | 3031 |
| 3228 helper.RunPreTestSetup(); | 3032 helper.RunPreTestSetup(); |
| 3229 helper.AddData(&data); | 3033 helper.AddData(&data); |
| 3230 | 3034 |
| 3231 HttpNetworkTransaction* trans = helper.trans(); | 3035 HttpNetworkTransaction* trans = helper.trans(); |
| 3232 | 3036 |
| 3233 // Start the transaction with basic parameters. | 3037 // Start the transaction with basic parameters. |
| 3234 TestCompletionCallback callback; | 3038 TestCompletionCallback callback; |
| 3235 int rv = trans->Start( | 3039 int rv = |
| 3236 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 3040 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 3237 EXPECT_EQ(ERR_IO_PENDING, rv); | 3041 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3238 rv = callback.WaitForResult(); | 3042 rv = callback.WaitForResult(); |
| 3239 EXPECT_EQ(OK, rv); | 3043 EXPECT_EQ(OK, rv); |
| 3240 // Verify that we consumed all test data. | 3044 // Verify that we consumed all test data. |
| 3241 EXPECT_TRUE(data.at_read_eof()) << "Read count: " | 3045 EXPECT_TRUE(data.at_read_eof()) << "Read count: " << data.read_count() |
| 3242 << data.read_count() | 3046 << " Read index: " << data.read_index(); |
| 3243 << " Read index: " | 3047 EXPECT_TRUE(data.at_write_eof()) << "Write count: " << data.write_count() |
| 3244 << data.read_index(); | 3048 << " Write index: " << data.write_index(); |
| 3245 EXPECT_TRUE(data.at_write_eof()) << "Write count: " | |
| 3246 << data.write_count() | |
| 3247 << " Write index: " | |
| 3248 << data.write_index(); | |
| 3249 | 3049 |
| 3250 // Verify the SYN_REPLY. | 3050 // Verify the SYN_REPLY. |
| 3251 HttpResponseInfo response = *trans->GetResponseInfo(); | 3051 HttpResponseInfo response = *trans->GetResponseInfo(); |
| 3252 EXPECT_TRUE(response.headers.get() != NULL); | 3052 EXPECT_TRUE(response.headers.get() != NULL); |
| 3253 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 3053 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 3254 } | 3054 } |
| 3255 | 3055 |
| 3256 // Verify that various SynReply headers parse correctly through the | 3056 // Verify that various SynReply headers parse correctly through the |
| 3257 // HTTP layer. | 3057 // HTTP layer. |
| 3258 TEST_P(SpdyNetworkTransactionTest, SynReplyHeaders) { | 3058 TEST_P(SpdyNetworkTransactionTest, SynReplyHeaders) { |
| 3259 struct SynReplyHeadersTests { | 3059 struct SynReplyHeadersTests { |
| 3260 int num_headers; | 3060 int num_headers; |
| 3261 const char* extra_headers[5]; | 3061 const char* extra_headers[5]; |
| 3262 SpdyHeaderBlock expected_headers; | 3062 SpdyHeaderBlock expected_headers; |
| 3263 } test_cases[] = { | 3063 } test_cases[] = {// This uses a multi-valued cookie header. |
| 3264 // This uses a multi-valued cookie header. | 3064 { |
| 3265 { 2, | 3065 2, |
| 3266 { "cookie", "val1", | 3066 {"cookie", "val1", "cookie", |
| 3267 "cookie", "val2", // will get appended separated by NULL | 3067 "val2", // will get appended separated by NULL |
| 3268 NULL | 3068 NULL}, |
| 3269 }, | 3069 }, |
| 3270 }, | 3070 // This is the minimalist set of headers. |
| 3271 // This is the minimalist set of headers. | 3071 { |
| 3272 { 0, | 3072 0, {NULL}, |
| 3273 { NULL }, | 3073 }, |
| 3274 }, | 3074 // Headers with a comma separated list. |
| 3275 // Headers with a comma separated list. | 3075 { |
| 3276 { 1, | 3076 1, {"cookie", "val1,val2", NULL}, |
| 3277 { "cookie", "val1,val2", | 3077 }}; |
| 3278 NULL | |
| 3279 }, | |
| 3280 } | |
| 3281 }; | |
| 3282 | 3078 |
| 3283 test_cases[0].expected_headers["cookie"] = "val1"; | 3079 test_cases[0].expected_headers["cookie"] = "val1"; |
| 3284 test_cases[0].expected_headers["cookie"] += '\0'; | 3080 test_cases[0].expected_headers["cookie"] += '\0'; |
| 3285 test_cases[0].expected_headers["cookie"] += "val2"; | 3081 test_cases[0].expected_headers["cookie"] += "val2"; |
| 3286 test_cases[0].expected_headers["hello"] = "bye"; | 3082 test_cases[0].expected_headers["hello"] = "bye"; |
| 3287 test_cases[0].expected_headers["status"] = "200"; | 3083 test_cases[0].expected_headers["status"] = "200"; |
| 3288 | 3084 |
| 3289 test_cases[1].expected_headers["hello"] = "bye"; | 3085 test_cases[1].expected_headers["hello"] = "bye"; |
| 3290 test_cases[1].expected_headers["status"] = "200"; | 3086 test_cases[1].expected_headers["status"] = "200"; |
| 3291 | 3087 |
| 3292 test_cases[2].expected_headers["cookie"] = "val1,val2"; | 3088 test_cases[2].expected_headers["cookie"] = "val1,val2"; |
| 3293 test_cases[2].expected_headers["hello"] = "bye"; | 3089 test_cases[2].expected_headers["hello"] = "bye"; |
| 3294 test_cases[2].expected_headers["status"] = "200"; | 3090 test_cases[2].expected_headers["status"] = "200"; |
| 3295 | 3091 |
| 3296 if (spdy_util_.spdy_version() < SPDY4) { | 3092 if (spdy_util_.spdy_version() < SPDY4) { |
| 3297 // SPDY4/HTTP2 eliminates use of the :version header. | 3093 // SPDY4/HTTP2 eliminates use of the :version header. |
| 3298 test_cases[0].expected_headers["version"] = "HTTP/1.1"; | 3094 test_cases[0].expected_headers["version"] = "HTTP/1.1"; |
| 3299 test_cases[1].expected_headers["version"] = "HTTP/1.1"; | 3095 test_cases[1].expected_headers["version"] = "HTTP/1.1"; |
| 3300 test_cases[2].expected_headers["version"] = "HTTP/1.1"; | 3096 test_cases[2].expected_headers["version"] = "HTTP/1.1"; |
| 3301 } | 3097 } |
| 3302 | 3098 |
| 3303 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 3099 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
| 3304 scoped_ptr<SpdyFrame> req( | 3100 scoped_ptr<SpdyFrame> req( |
| 3305 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 3101 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3306 MockWrite writes[] = { CreateMockWrite(*req) }; | 3102 MockWrite writes[] = {CreateMockWrite(*req)}; |
| 3307 | 3103 |
| 3308 scoped_ptr<SpdyFrame> resp( | 3104 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply( |
| 3309 spdy_util_.ConstructSpdyGetSynReply(test_cases[i].extra_headers, | 3105 test_cases[i].extra_headers, test_cases[i].num_headers, 1)); |
| 3310 test_cases[i].num_headers, | |
| 3311 1)); | |
| 3312 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 3106 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3313 MockRead reads[] = { | 3107 MockRead reads[] = { |
| 3314 CreateMockRead(*resp), | 3108 CreateMockRead(*resp), CreateMockRead(*body), |
| 3315 CreateMockRead(*body), | 3109 MockRead(ASYNC, 0, 0) // EOF |
| 3316 MockRead(ASYNC, 0, 0) // EOF | |
| 3317 }; | 3110 }; |
| 3318 | 3111 |
| 3319 DelayedSocketData data(1, reads, arraysize(reads), | 3112 DelayedSocketData data( |
| 3320 writes, arraysize(writes)); | 3113 1, reads, arraysize(reads), writes, arraysize(writes)); |
| 3321 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 3114 NormalSpdyTransactionHelper helper( |
| 3322 BoundNetLog(), GetParam(), NULL); | 3115 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3323 helper.RunToCompletion(&data); | 3116 helper.RunToCompletion(&data); |
| 3324 TransactionHelperResult out = helper.output(); | 3117 TransactionHelperResult out = helper.output(); |
| 3325 | 3118 |
| 3326 EXPECT_EQ(OK, out.rv); | 3119 EXPECT_EQ(OK, out.rv); |
| 3327 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 3120 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 3328 EXPECT_EQ("hello!", out.response_data); | 3121 EXPECT_EQ("hello!", out.response_data); |
| 3329 | 3122 |
| 3330 scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; | 3123 scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; |
| 3331 EXPECT_TRUE(headers.get() != NULL); | 3124 EXPECT_TRUE(headers.get() != NULL); |
| 3332 void* iter = NULL; | 3125 void* iter = NULL; |
| 3333 std::string name, value; | 3126 std::string name, value; |
| 3334 SpdyHeaderBlock header_block; | 3127 SpdyHeaderBlock header_block; |
| 3335 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { | 3128 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
| 3336 if (header_block[name].empty()) { | 3129 if (header_block[name].empty()) { |
| 3337 header_block[name] = value; | 3130 header_block[name] = value; |
| 3338 } else { | 3131 } else { |
| 3339 header_block[name] += '\0'; | 3132 header_block[name] += '\0'; |
| 3340 header_block[name] += value; | 3133 header_block[name] += value; |
| 3341 } | 3134 } |
| 3342 } | 3135 } |
| 3343 EXPECT_EQ(test_cases[i].expected_headers, header_block); | 3136 EXPECT_EQ(test_cases[i].expected_headers, header_block); |
| 3344 } | 3137 } |
| 3345 } | 3138 } |
| 3346 | 3139 |
| 3347 // Verify that various SynReply headers parse vary fields correctly | 3140 // Verify that various SynReply headers parse vary fields correctly |
| 3348 // through the HTTP layer, and the response matches the request. | 3141 // through the HTTP layer, and the response matches the request. |
| 3349 TEST_P(SpdyNetworkTransactionTest, SynReplyHeadersVary) { | 3142 TEST_P(SpdyNetworkTransactionTest, SynReplyHeadersVary) { |
| 3350 static const SpdyHeaderInfo syn_reply_info = { | 3143 static const SpdyHeaderInfo syn_reply_info = { |
| 3351 SYN_REPLY, // Syn Reply | 3144 SYN_REPLY, // Syn Reply |
| 3352 1, // Stream ID | 3145 1, // Stream ID |
| 3353 0, // Associated Stream ID | 3146 0, // Associated Stream ID |
| 3354 ConvertRequestPriorityToSpdyPriority( | 3147 ConvertRequestPriorityToSpdyPriority(LOWEST, spdy_util_.spdy_version()), |
| 3355 LOWEST, spdy_util_.spdy_version()), | 3148 kSpdyCredentialSlotUnused, |
| 3356 kSpdyCredentialSlotUnused, | 3149 CONTROL_FLAG_NONE, // Control Flags |
| 3357 CONTROL_FLAG_NONE, // Control Flags | 3150 false, // Compressed |
| 3358 false, // Compressed | 3151 RST_STREAM_INVALID, // Status |
| 3359 RST_STREAM_INVALID, // Status | 3152 NULL, // Data |
| 3360 NULL, // Data | 3153 0, // Data Length |
| 3361 0, // Data Length | 3154 DATA_FLAG_NONE // Data Flags |
| 3362 DATA_FLAG_NONE // Data Flags | |
| 3363 }; | 3155 }; |
| 3364 // Modify the following data to change/add test cases: | 3156 // Modify the following data to change/add test cases: |
| 3365 struct SynReplyTests { | 3157 struct SynReplyTests { |
| 3366 const SpdyHeaderInfo* syn_reply; | 3158 const SpdyHeaderInfo* syn_reply; |
| 3367 bool vary_matches; | 3159 bool vary_matches; |
| 3368 int num_headers[2]; | 3160 int num_headers[2]; |
| 3369 const char* extra_headers[2][16]; | 3161 const char* extra_headers[2][16]; |
| 3370 } test_cases[] = { | 3162 } test_cases[] = { |
| 3371 // Test the case of a multi-valued cookie. When the value is delimited | 3163 // Test the case of a multi-valued cookie. When the value is delimited |
| 3372 // with NUL characters, it needs to be unfolded into multiple headers. | 3164 // with NUL characters, it needs to be unfolded into multiple headers. |
| 3373 { | 3165 {&syn_reply_info, |
| 3374 &syn_reply_info, | 3166 true, |
| 3375 true, | 3167 {1, 4}, |
| 3376 { 1, 4 }, | 3168 {{"cookie", "val1,val2", NULL}, |
| 3377 { { "cookie", "val1,val2", | 3169 {"vary", "cookie", spdy_util_.GetStatusKey(), "200", |
| 3378 NULL | 3170 spdy_util_.GetPathKey(), "/index.php", spdy_util_.GetVersionKey(), |
| 3379 }, | 3171 "HTTP/1.1", NULL}}}, |
| 3380 { "vary", "cookie", | 3172 {// Multiple vary fields. |
| 3381 spdy_util_.GetStatusKey(), "200", | 3173 &syn_reply_info, |
| 3382 spdy_util_.GetPathKey(), "/index.php", | 3174 true, |
| 3383 spdy_util_.GetVersionKey(), "HTTP/1.1", | 3175 {2, 5}, |
| 3384 NULL | 3176 {{"friend", "barney", "enemy", "snaggletooth", NULL}, |
| 3385 } | 3177 {"vary", "friend", "vary", "enemy", spdy_util_.GetStatusKey(), "200", |
| 3386 } | 3178 spdy_util_.GetPathKey(), "/index.php", spdy_util_.GetVersionKey(), |
| 3387 }, { // Multiple vary fields. | 3179 "HTTP/1.1", NULL}}}, |
| 3388 &syn_reply_info, | 3180 {// Test a '*' vary field. |
| 3389 true, | 3181 &syn_reply_info, |
| 3390 { 2, 5 }, | 3182 false, |
| 3391 { { "friend", "barney", | 3183 {1, 4}, |
| 3392 "enemy", "snaggletooth", | 3184 {{"cookie", "val1,val2", NULL}, |
| 3393 NULL | 3185 {"vary", "*", spdy_util_.GetStatusKey(), "200", |
| 3394 }, | 3186 spdy_util_.GetPathKey(), "/index.php", spdy_util_.GetVersionKey(), |
| 3395 { "vary", "friend", | 3187 "HTTP/1.1", NULL}}}, |
| 3396 "vary", "enemy", | 3188 {// Multiple comma-separated vary fields. |
| 3397 spdy_util_.GetStatusKey(), "200", | 3189 &syn_reply_info, |
| 3398 spdy_util_.GetPathKey(), "/index.php", | 3190 true, |
| 3399 spdy_util_.GetVersionKey(), "HTTP/1.1", | 3191 {2, 4}, |
| 3400 NULL | 3192 {{"friend", "barney", "enemy", "snaggletooth", NULL}, |
| 3401 } | 3193 {"vary", "friend,enemy", spdy_util_.GetStatusKey(), "200", |
| 3402 } | 3194 spdy_util_.GetPathKey(), "/index.php", spdy_util_.GetVersionKey(), |
| 3403 }, { // Test a '*' vary field. | 3195 "HTTP/1.1", NULL}}}}; |
| 3404 &syn_reply_info, | |
| 3405 false, | |
| 3406 { 1, 4 }, | |
| 3407 { { "cookie", "val1,val2", | |
| 3408 NULL | |
| 3409 }, | |
| 3410 { "vary", "*", | |
| 3411 spdy_util_.GetStatusKey(), "200", | |
| 3412 spdy_util_.GetPathKey(), "/index.php", | |
| 3413 spdy_util_.GetVersionKey(), "HTTP/1.1", | |
| 3414 NULL | |
| 3415 } | |
| 3416 } | |
| 3417 }, { // Multiple comma-separated vary fields. | |
| 3418 &syn_reply_info, | |
| 3419 true, | |
| 3420 { 2, 4 }, | |
| 3421 { { "friend", "barney", | |
| 3422 "enemy", "snaggletooth", | |
| 3423 NULL | |
| 3424 }, | |
| 3425 { "vary", "friend,enemy", | |
| 3426 spdy_util_.GetStatusKey(), "200", | |
| 3427 spdy_util_.GetPathKey(), "/index.php", | |
| 3428 spdy_util_.GetVersionKey(), "HTTP/1.1", | |
| 3429 NULL | |
| 3430 } | |
| 3431 } | |
| 3432 } | |
| 3433 }; | |
| 3434 | 3196 |
| 3435 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 3197 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
| 3436 // Construct the request. | 3198 // Construct the request. |
| 3437 scoped_ptr<SpdyFrame> frame_req( | 3199 scoped_ptr<SpdyFrame> frame_req( |
| 3438 spdy_util_.ConstructSpdyGet(test_cases[i].extra_headers[0], | 3200 spdy_util_.ConstructSpdyGet(test_cases[i].extra_headers[0], |
| 3439 test_cases[i].num_headers[0], | 3201 test_cases[i].num_headers[0], |
| 3440 false, 1, LOWEST, true)); | 3202 false, |
| 3203 1, |
| 3204 LOWEST, |
| 3205 true)); |
| 3441 | 3206 |
| 3442 MockWrite writes[] = { | 3207 MockWrite writes[] = { |
| 3443 CreateMockWrite(*frame_req), | 3208 CreateMockWrite(*frame_req), |
| 3444 }; | 3209 }; |
| 3445 | 3210 |
| 3446 // Construct the reply. | 3211 // Construct the reply. |
| 3447 scoped_ptr<SpdyFrame> frame_reply( | 3212 scoped_ptr<SpdyFrame> frame_reply( |
| 3448 spdy_util_.ConstructSpdyFrame(*test_cases[i].syn_reply, | 3213 spdy_util_.ConstructSpdyFrame(*test_cases[i].syn_reply, |
| 3449 test_cases[i].extra_headers[1], | 3214 test_cases[i].extra_headers[1], |
| 3450 test_cases[i].num_headers[1], | 3215 test_cases[i].num_headers[1], |
| 3451 NULL, | 3216 NULL, |
| 3452 0)); | 3217 0)); |
| 3453 | 3218 |
| 3454 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 3219 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3455 MockRead reads[] = { | 3220 MockRead reads[] = { |
| 3456 CreateMockRead(*frame_reply), | 3221 CreateMockRead(*frame_reply), CreateMockRead(*body), |
| 3457 CreateMockRead(*body), | 3222 MockRead(ASYNC, 0, 0) // EOF |
| 3458 MockRead(ASYNC, 0, 0) // EOF | |
| 3459 }; | 3223 }; |
| 3460 | 3224 |
| 3461 // Attach the headers to the request. | 3225 // Attach the headers to the request. |
| 3462 int header_count = test_cases[i].num_headers[0]; | 3226 int header_count = test_cases[i].num_headers[0]; |
| 3463 | 3227 |
| 3464 HttpRequestInfo request = CreateGetRequest(); | 3228 HttpRequestInfo request = CreateGetRequest(); |
| 3465 for (int ct = 0; ct < header_count; ct++) { | 3229 for (int ct = 0; ct < header_count; ct++) { |
| 3466 const char* header_key = test_cases[i].extra_headers[0][ct * 2]; | 3230 const char* header_key = test_cases[i].extra_headers[0][ct * 2]; |
| 3467 const char* header_value = test_cases[i].extra_headers[0][ct * 2 + 1]; | 3231 const char* header_value = test_cases[i].extra_headers[0][ct * 2 + 1]; |
| 3468 request.extra_headers.SetHeader(header_key, header_value); | 3232 request.extra_headers.SetHeader(header_key, header_value); |
| 3469 } | 3233 } |
| 3470 | 3234 |
| 3471 DelayedSocketData data(1, reads, arraysize(reads), | 3235 DelayedSocketData data( |
| 3472 writes, arraysize(writes)); | 3236 1, reads, arraysize(reads), writes, arraysize(writes)); |
| 3473 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, | 3237 NormalSpdyTransactionHelper helper( |
| 3474 BoundNetLog(), GetParam(), NULL); | 3238 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3475 helper.RunToCompletion(&data); | 3239 helper.RunToCompletion(&data); |
| 3476 TransactionHelperResult out = helper.output(); | 3240 TransactionHelperResult out = helper.output(); |
| 3477 | 3241 |
| 3478 EXPECT_EQ(OK, out.rv) << i; | 3242 EXPECT_EQ(OK, out.rv) << i; |
| 3479 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line) << i; | 3243 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line) << i; |
| 3480 EXPECT_EQ("hello!", out.response_data) << i; | 3244 EXPECT_EQ("hello!", out.response_data) << i; |
| 3481 | 3245 |
| 3482 // Test the response information. | 3246 // Test the response information. |
| 3483 EXPECT_TRUE(out.response_info.response_time > | 3247 EXPECT_TRUE(out.response_info.response_time > |
| 3484 out.response_info.request_time) << i; | 3248 out.response_info.request_time) |
| 3485 base::TimeDelta test_delay = out.response_info.response_time - | 3249 << i; |
| 3486 out.response_info.request_time; | 3250 base::TimeDelta test_delay = |
| 3251 out.response_info.response_time - out.response_info.request_time; |
| 3487 base::TimeDelta min_expected_delay; | 3252 base::TimeDelta min_expected_delay; |
| 3488 min_expected_delay.FromMilliseconds(10); | 3253 min_expected_delay.FromMilliseconds(10); |
| 3489 EXPECT_GT(test_delay.InMillisecondsF(), | 3254 EXPECT_GT(test_delay.InMillisecondsF(), |
| 3490 min_expected_delay.InMillisecondsF()) << i; | 3255 min_expected_delay.InMillisecondsF()) |
| 3256 << i; |
| 3491 EXPECT_EQ(out.response_info.vary_data.is_valid(), | 3257 EXPECT_EQ(out.response_info.vary_data.is_valid(), |
| 3492 test_cases[i].vary_matches) << i; | 3258 test_cases[i].vary_matches) |
| 3259 << i; |
| 3493 | 3260 |
| 3494 // Check the headers. | 3261 // Check the headers. |
| 3495 scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; | 3262 scoped_refptr<HttpResponseHeaders> headers = out.response_info.headers; |
| 3496 ASSERT_TRUE(headers.get() != NULL) << i; | 3263 ASSERT_TRUE(headers.get() != NULL) << i; |
| 3497 void* iter = NULL; | 3264 void* iter = NULL; |
| 3498 std::string name, value, lines; | 3265 std::string name, value, lines; |
| 3499 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { | 3266 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
| 3500 lines.append(name); | 3267 lines.append(name); |
| 3501 lines.append(": "); | 3268 lines.append(": "); |
| 3502 lines.append(value); | 3269 lines.append(value); |
| 3503 lines.append("\n"); | 3270 lines.append("\n"); |
| 3504 } | 3271 } |
| 3505 | 3272 |
| 3506 // Construct the expected header reply string. | 3273 // Construct the expected header reply string. |
| 3507 SpdyHeaderBlock reply_headers; | 3274 SpdyHeaderBlock reply_headers; |
| 3508 AppendToHeaderBlock(test_cases[i].extra_headers[1], | 3275 AppendToHeaderBlock(test_cases[i].extra_headers[1], |
| 3509 test_cases[i].num_headers[1], | 3276 test_cases[i].num_headers[1], |
| 3510 &reply_headers); | 3277 &reply_headers); |
| 3511 std::string expected_reply = | 3278 std::string expected_reply = |
| 3512 spdy_util_.ConstructSpdyReplyString(reply_headers); | 3279 spdy_util_.ConstructSpdyReplyString(reply_headers); |
| 3513 EXPECT_EQ(expected_reply, lines) << i; | 3280 EXPECT_EQ(expected_reply, lines) << i; |
| 3514 } | 3281 } |
| 3515 } | 3282 } |
| 3516 | 3283 |
| 3517 // Verify that we don't crash on invalid SynReply responses. | 3284 // Verify that we don't crash on invalid SynReply responses. |
| 3518 TEST_P(SpdyNetworkTransactionTest, InvalidSynReply) { | 3285 TEST_P(SpdyNetworkTransactionTest, InvalidSynReply) { |
| 3519 const SpdyHeaderInfo kSynStartHeader = { | 3286 const SpdyHeaderInfo kSynStartHeader = { |
| 3520 SYN_REPLY, // Kind = SynReply | 3287 SYN_REPLY, // Kind = SynReply |
| 3521 1, // Stream ID | 3288 1, // Stream ID |
| 3522 0, // Associated stream ID | 3289 0, // Associated stream ID |
| 3523 ConvertRequestPriorityToSpdyPriority( | 3290 ConvertRequestPriorityToSpdyPriority(LOWEST, spdy_util_.spdy_version()), |
| 3524 LOWEST, spdy_util_.spdy_version()), | 3291 kSpdyCredentialSlotUnused, |
| 3525 kSpdyCredentialSlotUnused, | 3292 CONTROL_FLAG_NONE, // Control Flags |
| 3526 CONTROL_FLAG_NONE, // Control Flags | 3293 false, // Compressed |
| 3527 false, // Compressed | 3294 RST_STREAM_INVALID, // Status |
| 3528 RST_STREAM_INVALID, // Status | 3295 NULL, // Data |
| 3529 NULL, // Data | 3296 0, // Length |
| 3530 0, // Length | 3297 DATA_FLAG_NONE // Data Flags |
| 3531 DATA_FLAG_NONE // Data Flags | |
| 3532 }; | 3298 }; |
| 3533 | 3299 |
| 3534 struct InvalidSynReplyTests { | 3300 struct InvalidSynReplyTests { |
| 3535 int num_headers; | 3301 int num_headers; |
| 3536 const char* headers[10]; | 3302 const char* headers[10]; |
| 3537 } test_cases[] = { | 3303 } test_cases[] = { |
| 3538 // SYN_REPLY missing status header | 3304 // SYN_REPLY missing status header |
| 3539 { 4, | 3305 { |
| 3540 { "cookie", "val1", | 3306 4, |
| 3541 "cookie", "val2", | 3307 {"cookie", "val1", "cookie", "val2", spdy_util_.GetPathKey(), |
| 3542 spdy_util_.GetPathKey(), "/index.php", | 3308 "/index.php", spdy_util_.GetVersionKey(), "HTTP/1.1", NULL}, |
| 3543 spdy_util_.GetVersionKey(), "HTTP/1.1", | 3309 }, |
| 3544 NULL | 3310 // SYN_REPLY missing version header |
| 3545 }, | 3311 { |
| 3546 }, | 3312 2, {"status", "200", spdy_util_.GetPathKey(), "/index.php", NULL}, |
| 3547 // SYN_REPLY missing version header | 3313 }, |
| 3548 { 2, | 3314 // SYN_REPLY with no headers |
| 3549 { "status", "200", | 3315 { |
| 3550 spdy_util_.GetPathKey(), "/index.php", | 3316 0, {NULL}, |
| 3551 NULL | 3317 }, |
| 3552 }, | 3318 }; |
| 3553 }, | |
| 3554 // SYN_REPLY with no headers | |
| 3555 { 0, { NULL }, }, | |
| 3556 }; | |
| 3557 | 3319 |
| 3558 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 3320 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
| 3559 scoped_ptr<SpdyFrame> req( | 3321 scoped_ptr<SpdyFrame> req( |
| 3560 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 3322 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3561 scoped_ptr<SpdyFrame> rst( | 3323 scoped_ptr<SpdyFrame> rst( |
| 3562 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); | 3324 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 3563 MockWrite writes[] = { | 3325 MockWrite writes[] = { |
| 3564 CreateMockWrite(*req), | 3326 CreateMockWrite(*req), CreateMockWrite(*rst), |
| 3565 CreateMockWrite(*rst), | |
| 3566 }; | 3327 }; |
| 3567 | 3328 |
| 3568 scoped_ptr<SpdyFrame> resp( | 3329 scoped_ptr<SpdyFrame> resp( |
| 3569 spdy_util_.ConstructSpdyFrame(kSynStartHeader, | 3330 spdy_util_.ConstructSpdyFrame(kSynStartHeader, |
| 3570 NULL, 0, | 3331 NULL, |
| 3571 test_cases[i].headers, | 3332 0, |
| 3572 test_cases[i].num_headers)); | 3333 test_cases[i].headers, |
| 3334 test_cases[i].num_headers)); |
| 3573 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 3335 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3574 MockRead reads[] = { | 3336 MockRead reads[] = { |
| 3575 CreateMockRead(*resp), | 3337 CreateMockRead(*resp), MockRead(ASYNC, 0, 0) // EOF |
| 3576 MockRead(ASYNC, 0, 0) // EOF | |
| 3577 }; | 3338 }; |
| 3578 | 3339 |
| 3579 DelayedSocketData data(1, reads, arraysize(reads), | 3340 DelayedSocketData data( |
| 3580 writes, arraysize(writes)); | 3341 1, reads, arraysize(reads), writes, arraysize(writes)); |
| 3581 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 3342 NormalSpdyTransactionHelper helper( |
| 3582 BoundNetLog(), GetParam(), NULL); | 3343 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3583 helper.RunToCompletion(&data); | 3344 helper.RunToCompletion(&data); |
| 3584 TransactionHelperResult out = helper.output(); | 3345 TransactionHelperResult out = helper.output(); |
| 3585 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); | 3346 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 3586 } | 3347 } |
| 3587 } | 3348 } |
| 3588 | 3349 |
| 3589 // Verify that we don't crash on some corrupt frames. | 3350 // Verify that we don't crash on some corrupt frames. |
| 3590 // TODO(jgraettinger): SPDY4 and up treats a header decompression failure as a | 3351 // TODO(jgraettinger): SPDY4 and up treats a header decompression failure as a |
| 3591 // connection error. I'd like to backport this behavior to SPDY3 as well. | 3352 // connection error. I'd like to backport this behavior to SPDY3 as well. |
| 3592 TEST_P(SpdyNetworkTransactionTest, CorruptFrameSessionError) { | 3353 TEST_P(SpdyNetworkTransactionTest, CorruptFrameSessionError) { |
| 3593 if (spdy_util_.spdy_version() >= SPDY4) { | 3354 if (spdy_util_.spdy_version() >= SPDY4) { |
| 3594 return; | 3355 return; |
| 3595 } | 3356 } |
| 3596 // This is the length field that's too short. | 3357 // This is the length field that's too short. |
| 3597 scoped_ptr<SpdyFrame> syn_reply_wrong_length( | 3358 scoped_ptr<SpdyFrame> syn_reply_wrong_length( |
| 3598 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 3359 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3599 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); | 3360 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 3600 size_t right_size = | 3361 size_t right_size = |
| 3601 (spdy_util_.spdy_version() < SPDY4) ? | 3362 (spdy_util_.spdy_version() < SPDY4) |
| 3602 syn_reply_wrong_length->size() - framer.GetControlFrameHeaderSize() : | 3363 ? syn_reply_wrong_length->size() - framer.GetControlFrameHeaderSize() |
| 3603 syn_reply_wrong_length->size(); | 3364 : syn_reply_wrong_length->size(); |
| 3604 size_t wrong_size = right_size - 4; | 3365 size_t wrong_size = right_size - 4; |
| 3605 test::SetFrameLength(syn_reply_wrong_length.get(), | 3366 test::SetFrameLength( |
| 3606 wrong_size, | 3367 syn_reply_wrong_length.get(), wrong_size, spdy_util_.spdy_version()); |
| 3607 spdy_util_.spdy_version()); | |
| 3608 | 3368 |
| 3609 struct SynReplyTests { | 3369 struct SynReplyTests { |
| 3610 const SpdyFrame* syn_reply; | 3370 const SpdyFrame* syn_reply; |
| 3611 } test_cases[] = { | 3371 } test_cases[] = { |
| 3612 { syn_reply_wrong_length.get(), }, | 3372 { |
| 3613 }; | 3373 syn_reply_wrong_length.get(), |
| 3374 }, |
| 3375 }; |
| 3614 | 3376 |
| 3615 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 3377 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
| 3616 scoped_ptr<SpdyFrame> req( | 3378 scoped_ptr<SpdyFrame> req( |
| 3617 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 3379 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3618 scoped_ptr<SpdyFrame> rst( | 3380 scoped_ptr<SpdyFrame> rst( |
| 3619 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); | 3381 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 3620 MockWrite writes[] = { | 3382 MockWrite writes[] = { |
| 3621 CreateMockWrite(*req), | 3383 CreateMockWrite(*req), CreateMockWrite(*rst), |
| 3622 CreateMockWrite(*rst), | |
| 3623 }; | 3384 }; |
| 3624 | 3385 |
| 3625 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 3386 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3626 MockRead reads[] = { | 3387 MockRead reads[] = { |
| 3627 MockRead(ASYNC, test_cases[i].syn_reply->data(), wrong_size), | 3388 MockRead(ASYNC, test_cases[i].syn_reply->data(), wrong_size), |
| 3628 CreateMockRead(*body), | 3389 CreateMockRead(*body), MockRead(ASYNC, 0, 0) // EOF |
| 3629 MockRead(ASYNC, 0, 0) // EOF | |
| 3630 }; | 3390 }; |
| 3631 | 3391 |
| 3632 DelayedSocketData data(1, reads, arraysize(reads), | 3392 DelayedSocketData data( |
| 3633 writes, arraysize(writes)); | 3393 1, reads, arraysize(reads), writes, arraysize(writes)); |
| 3634 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 3394 NormalSpdyTransactionHelper helper( |
| 3635 BoundNetLog(), GetParam(), NULL); | 3395 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3636 helper.RunToCompletion(&data); | 3396 helper.RunToCompletion(&data); |
| 3637 TransactionHelperResult out = helper.output(); | 3397 TransactionHelperResult out = helper.output(); |
| 3638 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); | 3398 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 3639 } | 3399 } |
| 3640 } | 3400 } |
| 3641 | 3401 |
| 3642 // SPDY4 treats a header decompression failure as a connection-level error. | 3402 // SPDY4 treats a header decompression failure as a connection-level error. |
| 3643 TEST_P(SpdyNetworkTransactionTest, CorruptFrameSessionErrorSpdy4) { | 3403 TEST_P(SpdyNetworkTransactionTest, CorruptFrameSessionErrorSpdy4) { |
| 3644 if (spdy_util_.spdy_version() < SPDY4) { | 3404 if (spdy_util_.spdy_version() < SPDY4) { |
| 3645 return; | 3405 return; |
| 3646 } | 3406 } |
| 3647 // This is the length field that's too short. | 3407 // This is the length field that's too short. |
| 3648 scoped_ptr<SpdyFrame> syn_reply_wrong_length( | 3408 scoped_ptr<SpdyFrame> syn_reply_wrong_length( |
| 3649 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 3409 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3650 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); | 3410 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 3651 size_t right_size = | 3411 size_t right_size = |
| 3652 syn_reply_wrong_length->size() - framer.GetControlFrameHeaderSize(); | 3412 syn_reply_wrong_length->size() - framer.GetControlFrameHeaderSize(); |
| 3653 size_t wrong_size = right_size - 4; | 3413 size_t wrong_size = right_size - 4; |
| 3654 test::SetFrameLength(syn_reply_wrong_length.get(), | 3414 test::SetFrameLength( |
| 3655 wrong_size, | 3415 syn_reply_wrong_length.get(), wrong_size, spdy_util_.spdy_version()); |
| 3656 spdy_util_.spdy_version()); | |
| 3657 | 3416 |
| 3658 // TODO(jgraettinger): SpdySession::OnError() should send a GOAWAY before | 3417 // TODO(jgraettinger): SpdySession::OnError() should send a GOAWAY before |
| 3659 // breaking the connection. | 3418 // breaking the connection. |
| 3660 scoped_ptr<SpdyFrame> req( | 3419 scoped_ptr<SpdyFrame> req( |
| 3661 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 3420 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3662 MockWrite writes[] = { | 3421 MockWrite writes[] = { |
| 3663 CreateMockWrite(*req), | 3422 CreateMockWrite(*req), |
| 3664 }; | 3423 }; |
| 3665 | 3424 |
| 3666 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 3425 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3667 MockRead reads[] = { | 3426 MockRead reads[] = { |
| 3668 MockRead(ASYNC, syn_reply_wrong_length->data(), | 3427 MockRead(ASYNC, |
| 3669 syn_reply_wrong_length->size() - 4), | 3428 syn_reply_wrong_length->data(), |
| 3429 syn_reply_wrong_length->size() - 4), |
| 3670 }; | 3430 }; |
| 3671 | 3431 |
| 3672 DelayedSocketData data(1, reads, arraysize(reads), | 3432 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 3673 writes, arraysize(writes)); | 3433 NormalSpdyTransactionHelper helper( |
| 3674 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 3434 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3675 BoundNetLog(), GetParam(), NULL); | |
| 3676 helper.RunToCompletion(&data); | 3435 helper.RunToCompletion(&data); |
| 3677 TransactionHelperResult out = helper.output(); | 3436 TransactionHelperResult out = helper.output(); |
| 3678 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); | 3437 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 3679 } | 3438 } |
| 3680 | 3439 |
| 3681 // Test that we shutdown correctly on write errors. | 3440 // Test that we shutdown correctly on write errors. |
| 3682 TEST_P(SpdyNetworkTransactionTest, WriteError) { | 3441 TEST_P(SpdyNetworkTransactionTest, WriteError) { |
| 3683 scoped_ptr<SpdyFrame> req( | 3442 scoped_ptr<SpdyFrame> req( |
| 3684 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 3443 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3685 MockWrite writes[] = { | 3444 MockWrite writes[] = {// We'll write 10 bytes successfully |
| 3686 // We'll write 10 bytes successfully | 3445 MockWrite(ASYNC, req->data(), 10, 0), |
| 3687 MockWrite(ASYNC, req->data(), 10, 0), | 3446 // Followed by ERROR! |
| 3688 // Followed by ERROR! | 3447 MockWrite(ASYNC, ERR_FAILED, 1), |
| 3689 MockWrite(ASYNC, ERR_FAILED, 1), | |
| 3690 }; | 3448 }; |
| 3691 | 3449 |
| 3692 MockRead reads[] = { | 3450 MockRead reads[] = { |
| 3693 MockRead(ASYNC, 0, 2) // EOF | 3451 MockRead(ASYNC, 0, 2) // EOF |
| 3694 }; | 3452 }; |
| 3695 | 3453 |
| 3696 DeterministicSocketData data(reads, arraysize(reads), | 3454 DeterministicSocketData data( |
| 3697 writes, arraysize(writes)); | 3455 reads, arraysize(reads), writes, arraysize(writes)); |
| 3698 | 3456 |
| 3699 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 3457 NormalSpdyTransactionHelper helper( |
| 3700 BoundNetLog(), GetParam(), NULL); | 3458 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3701 helper.SetDeterministic(); | 3459 helper.SetDeterministic(); |
| 3702 helper.RunPreTestSetup(); | 3460 helper.RunPreTestSetup(); |
| 3703 helper.AddDeterministicData(&data); | 3461 helper.AddDeterministicData(&data); |
| 3704 EXPECT_TRUE(helper.StartDefaultTest()); | 3462 EXPECT_TRUE(helper.StartDefaultTest()); |
| 3705 data.RunFor(2); | 3463 data.RunFor(2); |
| 3706 helper.FinishDefaultTest(); | 3464 helper.FinishDefaultTest(); |
| 3707 EXPECT_TRUE(data.at_write_eof()); | 3465 EXPECT_TRUE(data.at_write_eof()); |
| 3708 EXPECT_TRUE(!data.at_read_eof()); | 3466 EXPECT_TRUE(!data.at_read_eof()); |
| 3709 TransactionHelperResult out = helper.output(); | 3467 TransactionHelperResult out = helper.output(); |
| 3710 EXPECT_EQ(ERR_FAILED, out.rv); | 3468 EXPECT_EQ(ERR_FAILED, out.rv); |
| 3711 } | 3469 } |
| 3712 | 3470 |
| 3713 // Test that partial writes work. | 3471 // Test that partial writes work. |
| 3714 TEST_P(SpdyNetworkTransactionTest, PartialWrite) { | 3472 TEST_P(SpdyNetworkTransactionTest, PartialWrite) { |
| 3715 // Chop the SYN_STREAM frame into 5 chunks. | 3473 // Chop the SYN_STREAM frame into 5 chunks. |
| 3716 scoped_ptr<SpdyFrame> req( | 3474 scoped_ptr<SpdyFrame> req( |
| 3717 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 3475 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3718 const int kChunks = 5; | 3476 const int kChunks = 5; |
| 3719 scoped_ptr<MockWrite[]> writes(ChopWriteFrame(*req.get(), kChunks)); | 3477 scoped_ptr<MockWrite[]> writes(ChopWriteFrame(*req.get(), kChunks)); |
| 3720 | 3478 |
| 3721 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 3479 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3722 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 3480 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3723 MockRead reads[] = { | 3481 MockRead reads[] = { |
| 3724 CreateMockRead(*resp), | 3482 CreateMockRead(*resp), CreateMockRead(*body), |
| 3725 CreateMockRead(*body), | 3483 MockRead(ASYNC, 0, 0) // EOF |
| 3726 MockRead(ASYNC, 0, 0) // EOF | |
| 3727 }; | 3484 }; |
| 3728 | 3485 |
| 3729 DelayedSocketData data(kChunks, reads, arraysize(reads), | 3486 DelayedSocketData data( |
| 3730 writes.get(), kChunks); | 3487 kChunks, reads, arraysize(reads), writes.get(), kChunks); |
| 3731 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 3488 NormalSpdyTransactionHelper helper( |
| 3732 BoundNetLog(), GetParam(), NULL); | 3489 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3733 helper.RunToCompletion(&data); | 3490 helper.RunToCompletion(&data); |
| 3734 TransactionHelperResult out = helper.output(); | 3491 TransactionHelperResult out = helper.output(); |
| 3735 EXPECT_EQ(OK, out.rv); | 3492 EXPECT_EQ(OK, out.rv); |
| 3736 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 3493 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 3737 EXPECT_EQ("hello!", out.response_data); | 3494 EXPECT_EQ("hello!", out.response_data); |
| 3738 } | 3495 } |
| 3739 | 3496 |
| 3740 // In this test, we enable compression, but get a uncompressed SynReply from | 3497 // In this test, we enable compression, but get a uncompressed SynReply from |
| 3741 // the server. Verify that teardown is all clean. | 3498 // the server. Verify that teardown is all clean. |
| 3742 TEST_P(SpdyNetworkTransactionTest, DecompressFailureOnSynReply) { | 3499 TEST_P(SpdyNetworkTransactionTest, DecompressFailureOnSynReply) { |
| 3743 if (spdy_util_.spdy_version() >= SPDY4) { | 3500 if (spdy_util_.spdy_version() >= SPDY4) { |
| 3744 // HPACK doesn't use deflate compression. | 3501 // HPACK doesn't use deflate compression. |
| 3745 return; | 3502 return; |
| 3746 } | 3503 } |
| 3747 scoped_ptr<SpdyFrame> compressed( | 3504 scoped_ptr<SpdyFrame> compressed( |
| 3748 spdy_util_.ConstructSpdyGet(NULL, 0, true, 1, LOWEST, true)); | 3505 spdy_util_.ConstructSpdyGet(NULL, 0, true, 1, LOWEST, true)); |
| 3749 scoped_ptr<SpdyFrame> rst( | 3506 scoped_ptr<SpdyFrame> rst( |
| 3750 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); | 3507 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 3751 MockWrite writes[] = { | 3508 MockWrite writes[] = { |
| 3752 CreateMockWrite(*compressed), | 3509 CreateMockWrite(*compressed), |
| 3753 }; | 3510 }; |
| 3754 | 3511 |
| 3755 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 3512 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3756 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 3513 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3757 MockRead reads[] = { | 3514 MockRead reads[] = { |
| 3758 CreateMockRead(*resp), | 3515 CreateMockRead(*resp), |
| 3759 }; | 3516 }; |
| 3760 | 3517 |
| 3761 DelayedSocketData data(1, reads, arraysize(reads), | 3518 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 3762 writes, arraysize(writes)); | |
| 3763 SpdySessionDependencies* session_deps = | 3519 SpdySessionDependencies* session_deps = |
| 3764 CreateSpdySessionDependencies(GetParam()); | 3520 CreateSpdySessionDependencies(GetParam()); |
| 3765 session_deps->enable_compression = true; | 3521 session_deps->enable_compression = true; |
| 3766 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 3522 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| 3767 BoundNetLog(), GetParam(), session_deps); | 3523 DEFAULT_PRIORITY, |
| 3524 BoundNetLog(), |
| 3525 GetParam(), |
| 3526 session_deps); |
| 3768 helper.RunToCompletion(&data); | 3527 helper.RunToCompletion(&data); |
| 3769 TransactionHelperResult out = helper.output(); | 3528 TransactionHelperResult out = helper.output(); |
| 3770 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); | 3529 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 3771 data.Reset(); | 3530 data.Reset(); |
| 3772 } | 3531 } |
| 3773 | 3532 |
| 3774 // Test that the NetLog contains good data for a simple GET request. | 3533 // Test that the NetLog contains good data for a simple GET request. |
| 3775 TEST_P(SpdyNetworkTransactionTest, NetLog) { | 3534 TEST_P(SpdyNetworkTransactionTest, NetLog) { |
| 3776 static const char* const kExtraHeaders[] = { | 3535 static const char* const kExtraHeaders[] = { |
| 3777 "user-agent", "Chrome", | 3536 "user-agent", "Chrome", |
| 3778 }; | 3537 }; |
| 3779 scoped_ptr<SpdyFrame> req( | 3538 scoped_ptr<SpdyFrame> req( |
| 3780 spdy_util_.ConstructSpdyGet(kExtraHeaders, 1, false, 1, LOWEST, true)); | 3539 spdy_util_.ConstructSpdyGet(kExtraHeaders, 1, false, 1, LOWEST, true)); |
| 3781 MockWrite writes[] = { CreateMockWrite(*req) }; | 3540 MockWrite writes[] = {CreateMockWrite(*req)}; |
| 3782 | 3541 |
| 3783 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 3542 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3784 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 3543 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 3785 MockRead reads[] = { | 3544 MockRead reads[] = { |
| 3786 CreateMockRead(*resp), | 3545 CreateMockRead(*resp), CreateMockRead(*body), |
| 3787 CreateMockRead(*body), | 3546 MockRead(ASYNC, 0, 0) // EOF |
| 3788 MockRead(ASYNC, 0, 0) // EOF | |
| 3789 }; | 3547 }; |
| 3790 | 3548 |
| 3791 CapturingBoundNetLog log; | 3549 CapturingBoundNetLog log; |
| 3792 | 3550 |
| 3793 DelayedSocketData data(1, reads, arraysize(reads), | 3551 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 3794 writes, arraysize(writes)); | |
| 3795 NormalSpdyTransactionHelper helper(CreateGetRequestWithUserAgent(), | 3552 NormalSpdyTransactionHelper helper(CreateGetRequestWithUserAgent(), |
| 3796 DEFAULT_PRIORITY, | 3553 DEFAULT_PRIORITY, |
| 3797 log.bound(), GetParam(), NULL); | 3554 log.bound(), |
| 3555 GetParam(), |
| 3556 NULL); |
| 3798 helper.RunToCompletion(&data); | 3557 helper.RunToCompletion(&data); |
| 3799 TransactionHelperResult out = helper.output(); | 3558 TransactionHelperResult out = helper.output(); |
| 3800 EXPECT_EQ(OK, out.rv); | 3559 EXPECT_EQ(OK, out.rv); |
| 3801 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 3560 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 3802 EXPECT_EQ("hello!", out.response_data); | 3561 EXPECT_EQ("hello!", out.response_data); |
| 3803 | 3562 |
| 3804 // Check that the NetLog was filled reasonably. | 3563 // Check that the NetLog was filled reasonably. |
| 3805 // This test is intentionally non-specific about the exact ordering of the | 3564 // This test is intentionally non-specific about the exact ordering of the |
| 3806 // log; instead we just check to make sure that certain events exist, and that | 3565 // log; instead we just check to make sure that certain events exist, and that |
| 3807 // they are in the right order. | 3566 // they are in the right order. |
| 3808 net::CapturingNetLog::CapturedEntryList entries; | 3567 net::CapturingNetLog::CapturedEntryList entries; |
| 3809 log.GetEntries(&entries); | 3568 log.GetEntries(&entries); |
| 3810 | 3569 |
| 3811 EXPECT_LT(0u, entries.size()); | 3570 EXPECT_LT(0u, entries.size()); |
| 3812 int pos = 0; | 3571 int pos = 0; |
| 3813 pos = net::ExpectLogContainsSomewhere(entries, 0, | 3572 pos = net::ExpectLogContainsSomewhere( |
| 3573 entries, |
| 3574 0, |
| 3814 net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, | 3575 net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, |
| 3815 net::NetLog::PHASE_BEGIN); | 3576 net::NetLog::PHASE_BEGIN); |
| 3816 pos = net::ExpectLogContainsSomewhere(entries, pos + 1, | 3577 pos = net::ExpectLogContainsSomewhere( |
| 3578 entries, |
| 3579 pos + 1, |
| 3817 net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, | 3580 net::NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, |
| 3818 net::NetLog::PHASE_END); | 3581 net::NetLog::PHASE_END); |
| 3819 pos = net::ExpectLogContainsSomewhere(entries, pos + 1, | 3582 pos = net::ExpectLogContainsSomewhere( |
| 3583 entries, |
| 3584 pos + 1, |
| 3820 net::NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, | 3585 net::NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, |
| 3821 net::NetLog::PHASE_BEGIN); | 3586 net::NetLog::PHASE_BEGIN); |
| 3822 pos = net::ExpectLogContainsSomewhere(entries, pos + 1, | 3587 pos = net::ExpectLogContainsSomewhere( |
| 3588 entries, |
| 3589 pos + 1, |
| 3823 net::NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, | 3590 net::NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, |
| 3824 net::NetLog::PHASE_END); | 3591 net::NetLog::PHASE_END); |
| 3825 pos = net::ExpectLogContainsSomewhere(entries, pos + 1, | 3592 pos = net::ExpectLogContainsSomewhere( |
| 3593 entries, |
| 3594 pos + 1, |
| 3826 net::NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, | 3595 net::NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, |
| 3827 net::NetLog::PHASE_BEGIN); | 3596 net::NetLog::PHASE_BEGIN); |
| 3828 pos = net::ExpectLogContainsSomewhere(entries, pos + 1, | 3597 pos = net::ExpectLogContainsSomewhere( |
| 3598 entries, |
| 3599 pos + 1, |
| 3829 net::NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, | 3600 net::NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, |
| 3830 net::NetLog::PHASE_END); | 3601 net::NetLog::PHASE_END); |
| 3831 | 3602 |
| 3832 // Check that we logged all the headers correctly | 3603 // Check that we logged all the headers correctly |
| 3833 pos = net::ExpectLogContainsSomewhere( | 3604 pos = |
| 3834 entries, 0, | 3605 net::ExpectLogContainsSomewhere(entries, |
| 3835 net::NetLog::TYPE_SPDY_SESSION_SYN_STREAM, | 3606 0, |
| 3836 net::NetLog::PHASE_NONE); | 3607 net::NetLog::TYPE_SPDY_SESSION_SYN_STREAM, |
| 3608 net::NetLog::PHASE_NONE); |
| 3837 | 3609 |
| 3838 base::ListValue* header_list; | 3610 base::ListValue* header_list; |
| 3839 ASSERT_TRUE(entries[pos].params.get()); | 3611 ASSERT_TRUE(entries[pos].params.get()); |
| 3840 ASSERT_TRUE(entries[pos].params->GetList("headers", &header_list)); | 3612 ASSERT_TRUE(entries[pos].params->GetList("headers", &header_list)); |
| 3841 | 3613 |
| 3842 std::vector<std::string> expected; | 3614 std::vector<std::string> expected; |
| 3843 expected.push_back(std::string(spdy_util_.GetHostKey()) + ": www.google.com"); | 3615 expected.push_back(std::string(spdy_util_.GetHostKey()) + ": www.google.com"); |
| 3844 expected.push_back(std::string(spdy_util_.GetPathKey()) + ": /"); | 3616 expected.push_back(std::string(spdy_util_.GetPathKey()) + ": /"); |
| 3845 expected.push_back(std::string(spdy_util_.GetSchemeKey()) + ": http"); | 3617 expected.push_back(std::string(spdy_util_.GetSchemeKey()) + ": http"); |
| 3846 expected.push_back(std::string(spdy_util_.GetMethodKey()) + ": GET"); | 3618 expected.push_back(std::string(spdy_util_.GetMethodKey()) + ": GET"); |
| 3847 expected.push_back("user-agent: Chrome"); | 3619 expected.push_back("user-agent: Chrome"); |
| 3848 if (spdy_util_.spdy_version() < SPDY4) { | 3620 if (spdy_util_.spdy_version() < SPDY4) { |
| 3849 // SPDY4/HTTP2 eliminates use of the :version header. | 3621 // SPDY4/HTTP2 eliminates use of the :version header. |
| 3850 expected.push_back(std::string(spdy_util_.GetVersionKey()) + ": HTTP/1.1"); | 3622 expected.push_back(std::string(spdy_util_.GetVersionKey()) + ": HTTP/1.1"); |
| 3851 } | 3623 } |
| 3852 EXPECT_EQ(expected.size(), header_list->GetSize()); | 3624 EXPECT_EQ(expected.size(), header_list->GetSize()); |
| 3853 for (std::vector<std::string>::const_iterator it = expected.begin(); | 3625 for (std::vector<std::string>::const_iterator it = expected.begin(); |
| 3854 it != expected.end(); | 3626 it != expected.end(); |
| 3855 ++it) { | 3627 ++it) { |
| 3856 base::StringValue header(*it); | 3628 base::StringValue header(*it); |
| 3857 EXPECT_NE(header_list->end(), header_list->Find(header)) << | 3629 EXPECT_NE(header_list->end(), header_list->Find(header)) |
| 3858 "Header not found: " << *it; | 3630 << "Header not found: " << *it; |
| 3859 } | 3631 } |
| 3860 } | 3632 } |
| 3861 | 3633 |
| 3862 // Since we buffer the IO from the stream to the renderer, this test verifies | 3634 // Since we buffer the IO from the stream to the renderer, this test verifies |
| 3863 // that when we read out the maximum amount of data (e.g. we received 50 bytes | 3635 // that when we read out the maximum amount of data (e.g. we received 50 bytes |
| 3864 // on the network, but issued a Read for only 5 of those bytes) that the data | 3636 // on the network, but issued a Read for only 5 of those bytes) that the data |
| 3865 // flow still works correctly. | 3637 // flow still works correctly. |
| 3866 TEST_P(SpdyNetworkTransactionTest, BufferFull) { | 3638 TEST_P(SpdyNetworkTransactionTest, BufferFull) { |
| 3867 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); | 3639 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 3868 | 3640 |
| 3869 scoped_ptr<SpdyFrame> req( | 3641 scoped_ptr<SpdyFrame> req( |
| 3870 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 3642 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3871 MockWrite writes[] = { CreateMockWrite(*req) }; | 3643 MockWrite writes[] = {CreateMockWrite(*req)}; |
| 3872 | 3644 |
| 3873 // 2 data frames in a single read. | 3645 // 2 data frames in a single read. |
| 3874 scoped_ptr<SpdyFrame> data_frame_1( | 3646 scoped_ptr<SpdyFrame> data_frame_1( |
| 3875 framer.CreateDataFrame(1, "goodby", 6, DATA_FLAG_NONE)); | 3647 framer.CreateDataFrame(1, "goodby", 6, DATA_FLAG_NONE)); |
| 3876 scoped_ptr<SpdyFrame> data_frame_2( | 3648 scoped_ptr<SpdyFrame> data_frame_2( |
| 3877 framer.CreateDataFrame(1, "e worl", 6, DATA_FLAG_NONE)); | 3649 framer.CreateDataFrame(1, "e worl", 6, DATA_FLAG_NONE)); |
| 3878 const SpdyFrame* data_frames[2] = { | 3650 const SpdyFrame* data_frames[2] = { |
| 3879 data_frame_1.get(), | 3651 data_frame_1.get(), data_frame_2.get(), |
| 3880 data_frame_2.get(), | |
| 3881 }; | 3652 }; |
| 3882 char combined_data_frames[100]; | 3653 char combined_data_frames[100]; |
| 3883 int combined_data_frames_len = | 3654 int combined_data_frames_len = CombineFrames(data_frames, |
| 3884 CombineFrames(data_frames, arraysize(data_frames), | 3655 arraysize(data_frames), |
| 3885 combined_data_frames, arraysize(combined_data_frames)); | 3656 combined_data_frames, |
| 3657 arraysize(combined_data_frames)); |
| 3886 scoped_ptr<SpdyFrame> last_frame( | 3658 scoped_ptr<SpdyFrame> last_frame( |
| 3887 framer.CreateDataFrame(1, "d", 1, DATA_FLAG_FIN)); | 3659 framer.CreateDataFrame(1, "d", 1, DATA_FLAG_FIN)); |
| 3888 | 3660 |
| 3889 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 3661 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3890 MockRead reads[] = { | 3662 MockRead reads[] = { |
| 3891 CreateMockRead(*resp), | 3663 CreateMockRead(*resp), MockRead(ASYNC, ERR_IO_PENDING), // Force a pause |
| 3892 MockRead(ASYNC, ERR_IO_PENDING), // Force a pause | 3664 MockRead(ASYNC, combined_data_frames, combined_data_frames_len), |
| 3893 MockRead(ASYNC, combined_data_frames, combined_data_frames_len), | 3665 MockRead(ASYNC, ERR_IO_PENDING), // Force a pause |
| 3894 MockRead(ASYNC, ERR_IO_PENDING), // Force a pause | 3666 CreateMockRead(*last_frame), MockRead(ASYNC, 0, 0) // EOF |
| 3895 CreateMockRead(*last_frame), | |
| 3896 MockRead(ASYNC, 0, 0) // EOF | |
| 3897 }; | 3667 }; |
| 3898 | 3668 |
| 3899 DelayedSocketData data(1, reads, arraysize(reads), | 3669 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 3900 writes, arraysize(writes)); | |
| 3901 | 3670 |
| 3902 TestCompletionCallback callback; | 3671 TestCompletionCallback callback; |
| 3903 | 3672 |
| 3904 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 3673 NormalSpdyTransactionHelper helper( |
| 3905 BoundNetLog(), GetParam(), NULL); | 3674 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3906 helper.RunPreTestSetup(); | 3675 helper.RunPreTestSetup(); |
| 3907 helper.AddData(&data); | 3676 helper.AddData(&data); |
| 3908 HttpNetworkTransaction* trans = helper.trans(); | 3677 HttpNetworkTransaction* trans = helper.trans(); |
| 3909 int rv = trans->Start( | 3678 int rv = |
| 3910 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 3679 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 3911 EXPECT_EQ(ERR_IO_PENDING, rv); | 3680 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3912 | 3681 |
| 3913 TransactionHelperResult out = helper.output(); | 3682 TransactionHelperResult out = helper.output(); |
| 3914 out.rv = callback.WaitForResult(); | 3683 out.rv = callback.WaitForResult(); |
| 3915 EXPECT_EQ(out.rv, OK); | 3684 EXPECT_EQ(out.rv, OK); |
| 3916 | 3685 |
| 3917 const HttpResponseInfo* response = trans->GetResponseInfo(); | 3686 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3918 EXPECT_TRUE(response->headers.get() != NULL); | 3687 EXPECT_TRUE(response->headers.get() != NULL); |
| 3919 EXPECT_TRUE(response->was_fetched_via_spdy); | 3688 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 3920 out.status_line = response->headers->GetStatusLine(); | 3689 out.status_line = response->headers->GetStatusLine(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3955 } | 3724 } |
| 3956 | 3725 |
| 3957 // Verify that basic buffering works; when multiple data frames arrive | 3726 // Verify that basic buffering works; when multiple data frames arrive |
| 3958 // at the same time, ensure that we don't notify a read completion for | 3727 // at the same time, ensure that we don't notify a read completion for |
| 3959 // each data frame individually. | 3728 // each data frame individually. |
| 3960 TEST_P(SpdyNetworkTransactionTest, Buffering) { | 3729 TEST_P(SpdyNetworkTransactionTest, Buffering) { |
| 3961 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); | 3730 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 3962 | 3731 |
| 3963 scoped_ptr<SpdyFrame> req( | 3732 scoped_ptr<SpdyFrame> req( |
| 3964 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 3733 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 3965 MockWrite writes[] = { CreateMockWrite(*req) }; | 3734 MockWrite writes[] = {CreateMockWrite(*req)}; |
| 3966 | 3735 |
| 3967 // 4 data frames in a single read. | 3736 // 4 data frames in a single read. |
| 3968 scoped_ptr<SpdyFrame> data_frame( | 3737 scoped_ptr<SpdyFrame> data_frame( |
| 3969 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); | 3738 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 3970 scoped_ptr<SpdyFrame> data_frame_fin( | 3739 scoped_ptr<SpdyFrame> data_frame_fin( |
| 3971 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN)); | 3740 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN)); |
| 3972 const SpdyFrame* data_frames[4] = { | 3741 const SpdyFrame* data_frames[4] = {data_frame.get(), data_frame.get(), |
| 3973 data_frame.get(), | 3742 data_frame.get(), data_frame_fin.get()}; |
| 3974 data_frame.get(), | |
| 3975 data_frame.get(), | |
| 3976 data_frame_fin.get() | |
| 3977 }; | |
| 3978 char combined_data_frames[100]; | 3743 char combined_data_frames[100]; |
| 3979 int combined_data_frames_len = | 3744 int combined_data_frames_len = CombineFrames(data_frames, |
| 3980 CombineFrames(data_frames, arraysize(data_frames), | 3745 arraysize(data_frames), |
| 3981 combined_data_frames, arraysize(combined_data_frames)); | 3746 combined_data_frames, |
| 3747 arraysize(combined_data_frames)); |
| 3982 | 3748 |
| 3983 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 3749 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 3984 MockRead reads[] = { | 3750 MockRead reads[] = { |
| 3985 CreateMockRead(*resp), | 3751 CreateMockRead(*resp), MockRead(ASYNC, ERR_IO_PENDING), // Force a pause |
| 3986 MockRead(ASYNC, ERR_IO_PENDING), // Force a pause | 3752 MockRead(ASYNC, combined_data_frames, combined_data_frames_len), |
| 3987 MockRead(ASYNC, combined_data_frames, combined_data_frames_len), | 3753 MockRead(ASYNC, 0, 0) // EOF |
| 3988 MockRead(ASYNC, 0, 0) // EOF | |
| 3989 }; | 3754 }; |
| 3990 | 3755 |
| 3991 DelayedSocketData data(1, reads, arraysize(reads), | 3756 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 3992 writes, arraysize(writes)); | |
| 3993 | 3757 |
| 3994 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 3758 NormalSpdyTransactionHelper helper( |
| 3995 BoundNetLog(), GetParam(), NULL); | 3759 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 3996 helper.RunPreTestSetup(); | 3760 helper.RunPreTestSetup(); |
| 3997 helper.AddData(&data); | 3761 helper.AddData(&data); |
| 3998 HttpNetworkTransaction* trans = helper.trans(); | 3762 HttpNetworkTransaction* trans = helper.trans(); |
| 3999 | 3763 |
| 4000 TestCompletionCallback callback; | 3764 TestCompletionCallback callback; |
| 4001 int rv = trans->Start( | 3765 int rv = |
| 4002 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 3766 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 4003 EXPECT_EQ(ERR_IO_PENDING, rv); | 3767 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4004 | 3768 |
| 4005 TransactionHelperResult out = helper.output(); | 3769 TransactionHelperResult out = helper.output(); |
| 4006 out.rv = callback.WaitForResult(); | 3770 out.rv = callback.WaitForResult(); |
| 4007 EXPECT_EQ(out.rv, OK); | 3771 EXPECT_EQ(out.rv, OK); |
| 4008 | 3772 |
| 4009 const HttpResponseInfo* response = trans->GetResponseInfo(); | 3773 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4010 EXPECT_TRUE(response->headers.get() != NULL); | 3774 EXPECT_TRUE(response->headers.get() != NULL); |
| 4011 EXPECT_TRUE(response->was_fetched_via_spdy); | 3775 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4012 out.status_line = response->headers->GetStatusLine(); | 3776 out.status_line = response->headers->GetStatusLine(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4050 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 3814 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4051 EXPECT_EQ("messagemessagemessagemessage", out.response_data); | 3815 EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 4052 } | 3816 } |
| 4053 | 3817 |
| 4054 // Verify the case where we buffer data but read it after it has been buffered. | 3818 // Verify the case where we buffer data but read it after it has been buffered. |
| 4055 TEST_P(SpdyNetworkTransactionTest, BufferedAll) { | 3819 TEST_P(SpdyNetworkTransactionTest, BufferedAll) { |
| 4056 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); | 3820 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 4057 | 3821 |
| 4058 scoped_ptr<SpdyFrame> req( | 3822 scoped_ptr<SpdyFrame> req( |
| 4059 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 3823 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 4060 MockWrite writes[] = { CreateMockWrite(*req) }; | 3824 MockWrite writes[] = {CreateMockWrite(*req)}; |
| 4061 | 3825 |
| 4062 // 5 data frames in a single read. | 3826 // 5 data frames in a single read. |
| 4063 SpdySynReplyIR reply_ir(1); | 3827 SpdySynReplyIR reply_ir(1); |
| 4064 reply_ir.SetHeader(spdy_util_.GetStatusKey(), "200"); | 3828 reply_ir.SetHeader(spdy_util_.GetStatusKey(), "200"); |
| 4065 reply_ir.SetHeader(spdy_util_.GetVersionKey(), "HTTP/1.1"); | 3829 reply_ir.SetHeader(spdy_util_.GetVersionKey(), "HTTP/1.1"); |
| 4066 | 3830 |
| 4067 scoped_ptr<SpdyFrame> syn_reply(framer.SerializeFrame(reply_ir)); | 3831 scoped_ptr<SpdyFrame> syn_reply(framer.SerializeFrame(reply_ir)); |
| 4068 scoped_ptr<SpdyFrame> data_frame( | 3832 scoped_ptr<SpdyFrame> data_frame( |
| 4069 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); | 3833 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 4070 scoped_ptr<SpdyFrame> data_frame_fin( | 3834 scoped_ptr<SpdyFrame> data_frame_fin( |
| 4071 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN)); | 3835 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_FIN)); |
| 4072 const SpdyFrame* frames[5] = { | 3836 const SpdyFrame* frames[5] = {syn_reply.get(), data_frame.get(), |
| 4073 syn_reply.get(), | 3837 data_frame.get(), data_frame.get(), |
| 4074 data_frame.get(), | 3838 data_frame_fin.get()}; |
| 4075 data_frame.get(), | |
| 4076 data_frame.get(), | |
| 4077 data_frame_fin.get() | |
| 4078 }; | |
| 4079 char combined_frames[200]; | 3839 char combined_frames[200]; |
| 4080 int combined_frames_len = | 3840 int combined_frames_len = CombineFrames( |
| 4081 CombineFrames(frames, arraysize(frames), | 3841 frames, arraysize(frames), combined_frames, arraysize(combined_frames)); |
| 4082 combined_frames, arraysize(combined_frames)); | |
| 4083 | 3842 |
| 4084 MockRead reads[] = { | 3843 MockRead reads[] = { |
| 4085 MockRead(ASYNC, combined_frames, combined_frames_len), | 3844 MockRead(ASYNC, combined_frames, combined_frames_len), |
| 4086 MockRead(ASYNC, 0, 0) // EOF | 3845 MockRead(ASYNC, 0, 0) // EOF |
| 4087 }; | 3846 }; |
| 4088 | 3847 |
| 4089 DelayedSocketData data(1, reads, arraysize(reads), | 3848 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 4090 writes, arraysize(writes)); | |
| 4091 | 3849 |
| 4092 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 3850 NormalSpdyTransactionHelper helper( |
| 4093 BoundNetLog(), GetParam(), NULL); | 3851 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 4094 helper.RunPreTestSetup(); | 3852 helper.RunPreTestSetup(); |
| 4095 helper.AddData(&data); | 3853 helper.AddData(&data); |
| 4096 HttpNetworkTransaction* trans = helper.trans(); | 3854 HttpNetworkTransaction* trans = helper.trans(); |
| 4097 | 3855 |
| 4098 TestCompletionCallback callback; | 3856 TestCompletionCallback callback; |
| 4099 int rv = trans->Start( | 3857 int rv = |
| 4100 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 3858 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 4101 EXPECT_EQ(ERR_IO_PENDING, rv); | 3859 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4102 | 3860 |
| 4103 TransactionHelperResult out = helper.output(); | 3861 TransactionHelperResult out = helper.output(); |
| 4104 out.rv = callback.WaitForResult(); | 3862 out.rv = callback.WaitForResult(); |
| 4105 EXPECT_EQ(out.rv, OK); | 3863 EXPECT_EQ(out.rv, OK); |
| 4106 | 3864 |
| 4107 const HttpResponseInfo* response = trans->GetResponseInfo(); | 3865 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4108 EXPECT_TRUE(response->headers.get() != NULL); | 3866 EXPECT_TRUE(response->headers.get() != NULL); |
| 4109 EXPECT_TRUE(response->was_fetched_via_spdy); | 3867 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4110 out.status_line = response->headers->GetStatusLine(); | 3868 out.status_line = response->headers->GetStatusLine(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4144 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 3902 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4145 EXPECT_EQ("messagemessagemessagemessage", out.response_data); | 3903 EXPECT_EQ("messagemessagemessagemessage", out.response_data); |
| 4146 } | 3904 } |
| 4147 | 3905 |
| 4148 // Verify the case where we buffer data and close the connection. | 3906 // Verify the case where we buffer data and close the connection. |
| 4149 TEST_P(SpdyNetworkTransactionTest, BufferedClosed) { | 3907 TEST_P(SpdyNetworkTransactionTest, BufferedClosed) { |
| 4150 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); | 3908 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 4151 | 3909 |
| 4152 scoped_ptr<SpdyFrame> req( | 3910 scoped_ptr<SpdyFrame> req( |
| 4153 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 3911 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 4154 MockWrite writes[] = { CreateMockWrite(*req) }; | 3912 MockWrite writes[] = {CreateMockWrite(*req)}; |
| 4155 | 3913 |
| 4156 // All data frames in a single read. | 3914 // All data frames in a single read. |
| 4157 // NOTE: We don't FIN the stream. | 3915 // NOTE: We don't FIN the stream. |
| 4158 scoped_ptr<SpdyFrame> data_frame( | 3916 scoped_ptr<SpdyFrame> data_frame( |
| 4159 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); | 3917 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 4160 const SpdyFrame* data_frames[4] = { | 3918 const SpdyFrame* data_frames[4] = {data_frame.get(), data_frame.get(), |
| 4161 data_frame.get(), | 3919 data_frame.get(), data_frame.get()}; |
| 4162 data_frame.get(), | |
| 4163 data_frame.get(), | |
| 4164 data_frame.get() | |
| 4165 }; | |
| 4166 char combined_data_frames[100]; | 3920 char combined_data_frames[100]; |
| 4167 int combined_data_frames_len = | 3921 int combined_data_frames_len = CombineFrames(data_frames, |
| 4168 CombineFrames(data_frames, arraysize(data_frames), | 3922 arraysize(data_frames), |
| 4169 combined_data_frames, arraysize(combined_data_frames)); | 3923 combined_data_frames, |
| 3924 arraysize(combined_data_frames)); |
| 4170 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 3925 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4171 MockRead reads[] = { | 3926 MockRead reads[] = { |
| 4172 CreateMockRead(*resp), | 3927 CreateMockRead(*resp), MockRead(ASYNC, ERR_IO_PENDING), // Force a wait |
| 4173 MockRead(ASYNC, ERR_IO_PENDING), // Force a wait | 3928 MockRead(ASYNC, combined_data_frames, combined_data_frames_len), |
| 4174 MockRead(ASYNC, combined_data_frames, combined_data_frames_len), | 3929 MockRead(ASYNC, 0, 0) // EOF |
| 4175 MockRead(ASYNC, 0, 0) // EOF | |
| 4176 }; | 3930 }; |
| 4177 | 3931 |
| 4178 DelayedSocketData data(1, reads, arraysize(reads), | 3932 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 4179 writes, arraysize(writes)); | |
| 4180 | 3933 |
| 4181 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 3934 NormalSpdyTransactionHelper helper( |
| 4182 BoundNetLog(), GetParam(), NULL); | 3935 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 4183 helper.RunPreTestSetup(); | 3936 helper.RunPreTestSetup(); |
| 4184 helper.AddData(&data); | 3937 helper.AddData(&data); |
| 4185 HttpNetworkTransaction* trans = helper.trans(); | 3938 HttpNetworkTransaction* trans = helper.trans(); |
| 4186 | 3939 |
| 4187 TestCompletionCallback callback; | 3940 TestCompletionCallback callback; |
| 4188 | 3941 |
| 4189 int rv = trans->Start( | 3942 int rv = |
| 4190 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 3943 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 4191 EXPECT_EQ(ERR_IO_PENDING, rv); | 3944 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4192 | 3945 |
| 4193 TransactionHelperResult out = helper.output(); | 3946 TransactionHelperResult out = helper.output(); |
| 4194 out.rv = callback.WaitForResult(); | 3947 out.rv = callback.WaitForResult(); |
| 4195 EXPECT_EQ(out.rv, OK); | 3948 EXPECT_EQ(out.rv, OK); |
| 4196 | 3949 |
| 4197 const HttpResponseInfo* response = trans->GetResponseInfo(); | 3950 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4198 EXPECT_TRUE(response->headers.get() != NULL); | 3951 EXPECT_TRUE(response->headers.get() != NULL); |
| 4199 EXPECT_TRUE(response->was_fetched_via_spdy); | 3952 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4200 out.status_line = response->headers->GetStatusLine(); | 3953 out.status_line = response->headers->GetStatusLine(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4235 // Verify that we consumed all test data. | 3988 // Verify that we consumed all test data. |
| 4236 helper.VerifyDataConsumed(); | 3989 helper.VerifyDataConsumed(); |
| 4237 } | 3990 } |
| 4238 | 3991 |
| 4239 // Verify the case where we buffer data and cancel the transaction. | 3992 // Verify the case where we buffer data and cancel the transaction. |
| 4240 TEST_P(SpdyNetworkTransactionTest, BufferedCancelled) { | 3993 TEST_P(SpdyNetworkTransactionTest, BufferedCancelled) { |
| 4241 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); | 3994 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); |
| 4242 | 3995 |
| 4243 scoped_ptr<SpdyFrame> req( | 3996 scoped_ptr<SpdyFrame> req( |
| 4244 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 3997 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 4245 MockWrite writes[] = { CreateMockWrite(*req) }; | 3998 MockWrite writes[] = {CreateMockWrite(*req)}; |
| 4246 | 3999 |
| 4247 // NOTE: We don't FIN the stream. | 4000 // NOTE: We don't FIN the stream. |
| 4248 scoped_ptr<SpdyFrame> data_frame( | 4001 scoped_ptr<SpdyFrame> data_frame( |
| 4249 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); | 4002 framer.CreateDataFrame(1, "message", 7, DATA_FLAG_NONE)); |
| 4250 | 4003 |
| 4251 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 4004 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4252 MockRead reads[] = { | 4005 MockRead reads[] = { |
| 4253 CreateMockRead(*resp), | 4006 CreateMockRead(*resp), MockRead(ASYNC, ERR_IO_PENDING), // Force a wait |
| 4254 MockRead(ASYNC, ERR_IO_PENDING), // Force a wait | 4007 CreateMockRead(*data_frame), MockRead(ASYNC, 0, 0) // EOF |
| 4255 CreateMockRead(*data_frame), | |
| 4256 MockRead(ASYNC, 0, 0) // EOF | |
| 4257 }; | 4008 }; |
| 4258 | 4009 |
| 4259 DelayedSocketData data(1, reads, arraysize(reads), | 4010 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 4260 writes, arraysize(writes)); | |
| 4261 | 4011 |
| 4262 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 4012 NormalSpdyTransactionHelper helper( |
| 4263 BoundNetLog(), GetParam(), NULL); | 4013 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 4264 helper.RunPreTestSetup(); | 4014 helper.RunPreTestSetup(); |
| 4265 helper.AddData(&data); | 4015 helper.AddData(&data); |
| 4266 HttpNetworkTransaction* trans = helper.trans(); | 4016 HttpNetworkTransaction* trans = helper.trans(); |
| 4267 TestCompletionCallback callback; | 4017 TestCompletionCallback callback; |
| 4268 | 4018 |
| 4269 int rv = trans->Start( | 4019 int rv = |
| 4270 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 4020 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 4271 EXPECT_EQ(ERR_IO_PENDING, rv); | 4021 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4272 | 4022 |
| 4273 TransactionHelperResult out = helper.output(); | 4023 TransactionHelperResult out = helper.output(); |
| 4274 out.rv = callback.WaitForResult(); | 4024 out.rv = callback.WaitForResult(); |
| 4275 EXPECT_EQ(out.rv, OK); | 4025 EXPECT_EQ(out.rv, OK); |
| 4276 | 4026 |
| 4277 const HttpResponseInfo* response = trans->GetResponseInfo(); | 4027 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4278 EXPECT_TRUE(response->headers.get() != NULL); | 4028 EXPECT_TRUE(response->headers.get() != NULL); |
| 4279 EXPECT_TRUE(response->was_fetched_via_spdy); | 4029 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4280 out.status_line = response->headers->GetStatusLine(); | 4030 out.status_line = response->headers->GetStatusLine(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 4304 | 4054 |
| 4305 // Test that if the server requests persistence of settings, that we save | 4055 // Test that if the server requests persistence of settings, that we save |
| 4306 // the settings in the HttpServerProperties. | 4056 // the settings in the HttpServerProperties. |
| 4307 TEST_P(SpdyNetworkTransactionTest, SettingsSaved) { | 4057 TEST_P(SpdyNetworkTransactionTest, SettingsSaved) { |
| 4308 if (spdy_util_.spdy_version() >= SPDY4) { | 4058 if (spdy_util_.spdy_version() >= SPDY4) { |
| 4309 // SPDY4 doesn't support flags on individual settings, and | 4059 // SPDY4 doesn't support flags on individual settings, and |
| 4310 // has no concept of settings persistence. | 4060 // has no concept of settings persistence. |
| 4311 return; | 4061 return; |
| 4312 } | 4062 } |
| 4313 static const SpdyHeaderInfo kSynReplyInfo = { | 4063 static const SpdyHeaderInfo kSynReplyInfo = { |
| 4314 SYN_REPLY, // Syn Reply | 4064 SYN_REPLY, // Syn Reply |
| 4315 1, // Stream ID | 4065 1, // Stream ID |
| 4316 0, // Associated Stream ID | 4066 0, // Associated Stream ID |
| 4317 ConvertRequestPriorityToSpdyPriority( | 4067 ConvertRequestPriorityToSpdyPriority(LOWEST, spdy_util_.spdy_version()), |
| 4318 LOWEST, spdy_util_.spdy_version()), | 4068 kSpdyCredentialSlotUnused, |
| 4319 kSpdyCredentialSlotUnused, | 4069 CONTROL_FLAG_NONE, // Control Flags |
| 4320 CONTROL_FLAG_NONE, // Control Flags | 4070 false, // Compressed |
| 4321 false, // Compressed | 4071 RST_STREAM_INVALID, // Status |
| 4322 RST_STREAM_INVALID, // Status | 4072 NULL, // Data |
| 4323 NULL, // Data | 4073 0, // Data Length |
| 4324 0, // Data Length | 4074 DATA_FLAG_NONE // Data Flags |
| 4325 DATA_FLAG_NONE // Data Flags | |
| 4326 }; | 4075 }; |
| 4327 | 4076 |
| 4328 BoundNetLog net_log; | 4077 BoundNetLog net_log; |
| 4329 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 4078 NormalSpdyTransactionHelper helper( |
| 4330 net_log, GetParam(), NULL); | 4079 CreateGetRequest(), DEFAULT_PRIORITY, net_log, GetParam(), NULL); |
| 4331 helper.RunPreTestSetup(); | 4080 helper.RunPreTestSetup(); |
| 4332 | 4081 |
| 4333 // Verify that no settings exist initially. | 4082 // Verify that no settings exist initially. |
| 4334 HostPortPair host_port_pair("www.google.com", helper.port()); | 4083 HostPortPair host_port_pair("www.google.com", helper.port()); |
| 4335 SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); | 4084 SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
| 4336 EXPECT_TRUE(spdy_session_pool->http_server_properties()->GetSpdySettings( | 4085 EXPECT_TRUE(spdy_session_pool->http_server_properties() |
| 4337 host_port_pair).empty()); | 4086 ->GetSpdySettings(host_port_pair) |
| 4087 .empty()); |
| 4338 | 4088 |
| 4339 // Construct the request. | 4089 // Construct the request. |
| 4340 scoped_ptr<SpdyFrame> req( | 4090 scoped_ptr<SpdyFrame> req( |
| 4341 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 4091 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 4342 MockWrite writes[] = { CreateMockWrite(*req) }; | 4092 MockWrite writes[] = {CreateMockWrite(*req)}; |
| 4343 | 4093 |
| 4344 // Construct the reply. | 4094 // Construct the reply. |
| 4345 scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); | 4095 scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); |
| 4346 (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; | 4096 (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 4347 (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | 4097 (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
| 4348 scoped_ptr<SpdyFrame> reply( | 4098 scoped_ptr<SpdyFrame> reply( |
| 4349 spdy_util_.ConstructSpdyFrame(kSynReplyInfo, reply_headers.Pass())); | 4099 spdy_util_.ConstructSpdyFrame(kSynReplyInfo, reply_headers.Pass())); |
| 4350 | 4100 |
| 4351 const SpdySettingsIds kSampleId1 = SETTINGS_UPLOAD_BANDWIDTH; | 4101 const SpdySettingsIds kSampleId1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 4352 unsigned int kSampleValue1 = 0x0a0a0a0a; | 4102 unsigned int kSampleValue1 = 0x0a0a0a0a; |
| 4353 const SpdySettingsIds kSampleId2 = SETTINGS_DOWNLOAD_BANDWIDTH; | 4103 const SpdySettingsIds kSampleId2 = SETTINGS_DOWNLOAD_BANDWIDTH; |
| 4354 unsigned int kSampleValue2 = 0x0b0b0b0b; | 4104 unsigned int kSampleValue2 = 0x0b0b0b0b; |
| 4355 const SpdySettingsIds kSampleId3 = SETTINGS_ROUND_TRIP_TIME; | 4105 const SpdySettingsIds kSampleId3 = SETTINGS_ROUND_TRIP_TIME; |
| 4356 unsigned int kSampleValue3 = 0x0c0c0c0c; | 4106 unsigned int kSampleValue3 = 0x0c0c0c0c; |
| 4357 scoped_ptr<SpdyFrame> settings_frame; | 4107 scoped_ptr<SpdyFrame> settings_frame; |
| 4358 { | 4108 { |
| 4359 // Construct the SETTINGS frame. | 4109 // Construct the SETTINGS frame. |
| 4360 SettingsMap settings; | 4110 SettingsMap settings; |
| 4361 // First add a persisted setting. | 4111 // First add a persisted setting. |
| 4362 settings[kSampleId1] = | 4112 settings[kSampleId1] = |
| 4363 SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue1); | 4113 SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue1); |
| 4364 // Next add a non-persisted setting. | 4114 // Next add a non-persisted setting. |
| 4365 settings[kSampleId2] = | 4115 settings[kSampleId2] = |
| 4366 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kSampleValue2); | 4116 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kSampleValue2); |
| 4367 // Next add another persisted setting. | 4117 // Next add another persisted setting. |
| 4368 settings[kSampleId3] = | 4118 settings[kSampleId3] = |
| 4369 SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue3); | 4119 SettingsFlagsAndValue(SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue3); |
| 4370 settings_frame.reset(spdy_util_.ConstructSpdySettings(settings)); | 4120 settings_frame.reset(spdy_util_.ConstructSpdySettings(settings)); |
| 4371 } | 4121 } |
| 4372 | 4122 |
| 4373 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 4123 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4374 MockRead reads[] = { | 4124 MockRead reads[] = { |
| 4375 CreateMockRead(*reply), | 4125 CreateMockRead(*reply), CreateMockRead(*body), |
| 4376 CreateMockRead(*body), | 4126 CreateMockRead(*settings_frame), MockRead(ASYNC, 0, 0) // EOF |
| 4377 CreateMockRead(*settings_frame), | |
| 4378 MockRead(ASYNC, 0, 0) // EOF | |
| 4379 }; | 4127 }; |
| 4380 | 4128 |
| 4381 DelayedSocketData data(1, reads, arraysize(reads), | 4129 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 4382 writes, arraysize(writes)); | |
| 4383 helper.AddData(&data); | 4130 helper.AddData(&data); |
| 4384 helper.RunDefaultTest(); | 4131 helper.RunDefaultTest(); |
| 4385 helper.VerifyDataConsumed(); | 4132 helper.VerifyDataConsumed(); |
| 4386 TransactionHelperResult out = helper.output(); | 4133 TransactionHelperResult out = helper.output(); |
| 4387 EXPECT_EQ(OK, out.rv); | 4134 EXPECT_EQ(OK, out.rv); |
| 4388 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 4135 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4389 EXPECT_EQ("hello!", out.response_data); | 4136 EXPECT_EQ("hello!", out.response_data); |
| 4390 | 4137 |
| 4391 { | 4138 { |
| 4392 // Verify we had two persisted settings. | 4139 // Verify we had two persisted settings. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 4409 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value3.first); | 4156 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value3.first); |
| 4410 EXPECT_EQ(kSampleValue3, flags_and_value3.second); | 4157 EXPECT_EQ(kSampleValue3, flags_and_value3.second); |
| 4411 } | 4158 } |
| 4412 } | 4159 } |
| 4413 | 4160 |
| 4414 // Test that when there are settings saved that they are sent back to the | 4161 // Test that when there are settings saved that they are sent back to the |
| 4415 // server upon session establishment. | 4162 // server upon session establishment. |
| 4416 TEST_P(SpdyNetworkTransactionTest, SettingsPlayback) { | 4163 TEST_P(SpdyNetworkTransactionTest, SettingsPlayback) { |
| 4417 // TODO(jgraettinger): Remove settings persistence mechanisms altogether. | 4164 // TODO(jgraettinger): Remove settings persistence mechanisms altogether. |
| 4418 static const SpdyHeaderInfo kSynReplyInfo = { | 4165 static const SpdyHeaderInfo kSynReplyInfo = { |
| 4419 SYN_REPLY, // Syn Reply | 4166 SYN_REPLY, // Syn Reply |
| 4420 1, // Stream ID | 4167 1, // Stream ID |
| 4421 0, // Associated Stream ID | 4168 0, // Associated Stream ID |
| 4422 ConvertRequestPriorityToSpdyPriority( | 4169 ConvertRequestPriorityToSpdyPriority(LOWEST, spdy_util_.spdy_version()), |
| 4423 LOWEST, spdy_util_.spdy_version()), | 4170 kSpdyCredentialSlotUnused, |
| 4424 kSpdyCredentialSlotUnused, | 4171 CONTROL_FLAG_NONE, // Control Flags |
| 4425 CONTROL_FLAG_NONE, // Control Flags | 4172 false, // Compressed |
| 4426 false, // Compressed | 4173 RST_STREAM_INVALID, // Status |
| 4427 RST_STREAM_INVALID, // Status | 4174 NULL, // Data |
| 4428 NULL, // Data | 4175 0, // Data Length |
| 4429 0, // Data Length | 4176 DATA_FLAG_NONE // Data Flags |
| 4430 DATA_FLAG_NONE // Data Flags | |
| 4431 }; | 4177 }; |
| 4432 | 4178 |
| 4433 BoundNetLog net_log; | 4179 BoundNetLog net_log; |
| 4434 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 4180 NormalSpdyTransactionHelper helper( |
| 4435 net_log, GetParam(), NULL); | 4181 CreateGetRequest(), DEFAULT_PRIORITY, net_log, GetParam(), NULL); |
| 4436 helper.RunPreTestSetup(); | 4182 helper.RunPreTestSetup(); |
| 4437 | 4183 |
| 4438 SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); | 4184 SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
| 4439 | 4185 |
| 4440 SpdySessionPoolPeer pool_peer(spdy_session_pool); | 4186 SpdySessionPoolPeer pool_peer(spdy_session_pool); |
| 4441 pool_peer.SetEnableSendingInitialData(true); | 4187 pool_peer.SetEnableSendingInitialData(true); |
| 4442 | 4188 |
| 4443 // Verify that no settings exist initially. | 4189 // Verify that no settings exist initially. |
| 4444 HostPortPair host_port_pair("www.google.com", helper.port()); | 4190 HostPortPair host_port_pair("www.google.com", helper.port()); |
| 4445 EXPECT_TRUE(spdy_session_pool->http_server_properties()->GetSpdySettings( | 4191 EXPECT_TRUE(spdy_session_pool->http_server_properties() |
| 4446 host_port_pair).empty()); | 4192 ->GetSpdySettings(host_port_pair) |
| 4193 .empty()); |
| 4447 | 4194 |
| 4448 const SpdySettingsIds kSampleId1 = SETTINGS_MAX_CONCURRENT_STREAMS; | 4195 const SpdySettingsIds kSampleId1 = SETTINGS_MAX_CONCURRENT_STREAMS; |
| 4449 unsigned int kSampleValue1 = 0x0a0a0a0a; | 4196 unsigned int kSampleValue1 = 0x0a0a0a0a; |
| 4450 const SpdySettingsIds kSampleId2 = SETTINGS_INITIAL_WINDOW_SIZE; | 4197 const SpdySettingsIds kSampleId2 = SETTINGS_INITIAL_WINDOW_SIZE; |
| 4451 unsigned int kSampleValue2 = 0x0c0c0c0c; | 4198 unsigned int kSampleValue2 = 0x0c0c0c0c; |
| 4452 | 4199 |
| 4453 // First add a persisted setting. | 4200 // First add a persisted setting. |
| 4454 spdy_session_pool->http_server_properties()->SetSpdySetting( | 4201 spdy_session_pool->http_server_properties()->SetSpdySetting( |
| 4455 host_port_pair, | 4202 host_port_pair, kSampleId1, SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue1); |
| 4456 kSampleId1, | |
| 4457 SETTINGS_FLAG_PLEASE_PERSIST, | |
| 4458 kSampleValue1); | |
| 4459 | 4203 |
| 4460 // Next add another persisted setting. | 4204 // Next add another persisted setting. |
| 4461 spdy_session_pool->http_server_properties()->SetSpdySetting( | 4205 spdy_session_pool->http_server_properties()->SetSpdySetting( |
| 4462 host_port_pair, | 4206 host_port_pair, kSampleId2, SETTINGS_FLAG_PLEASE_PERSIST, kSampleValue2); |
| 4463 kSampleId2, | |
| 4464 SETTINGS_FLAG_PLEASE_PERSIST, | |
| 4465 kSampleValue2); | |
| 4466 | 4207 |
| 4467 EXPECT_EQ(2u, spdy_session_pool->http_server_properties()->GetSpdySettings( | 4208 EXPECT_EQ(2u, |
| 4468 host_port_pair).size()); | 4209 spdy_session_pool->http_server_properties() |
| 4210 ->GetSpdySettings(host_port_pair) |
| 4211 .size()); |
| 4469 | 4212 |
| 4470 // Construct the initial SETTINGS frame. | 4213 // Construct the initial SETTINGS frame. |
| 4471 SettingsMap initial_settings; | 4214 SettingsMap initial_settings; |
| 4472 initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] = | 4215 initial_settings[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 4473 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); | 4216 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, kMaxConcurrentPushedStreams); |
| 4474 scoped_ptr<SpdyFrame> initial_settings_frame( | 4217 scoped_ptr<SpdyFrame> initial_settings_frame( |
| 4475 spdy_util_.ConstructSpdySettings(initial_settings)); | 4218 spdy_util_.ConstructSpdySettings(initial_settings)); |
| 4476 | 4219 |
| 4477 // Construct the initial window update. | 4220 // Construct the initial window update. |
| 4478 scoped_ptr<SpdyFrame> initial_window_update( | 4221 scoped_ptr<SpdyFrame> initial_window_update( |
| 4479 spdy_util_.ConstructSpdyWindowUpdate( | 4222 spdy_util_.ConstructSpdyWindowUpdate( |
| 4480 kSessionFlowControlStreamId, | 4223 kSessionFlowControlStreamId, |
| 4481 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); | 4224 kDefaultInitialRecvWindowSize - kSpdySessionInitialWindowSize)); |
| 4482 | 4225 |
| 4483 // Construct the persisted SETTINGS frame. | 4226 // Construct the persisted SETTINGS frame. |
| 4484 const SettingsMap& settings = | 4227 const SettingsMap& settings = |
| 4485 spdy_session_pool->http_server_properties()->GetSpdySettings( | 4228 spdy_session_pool->http_server_properties()->GetSpdySettings( |
| 4486 host_port_pair); | 4229 host_port_pair); |
| 4487 scoped_ptr<SpdyFrame> settings_frame( | 4230 scoped_ptr<SpdyFrame> settings_frame( |
| 4488 spdy_util_.ConstructSpdySettings(settings)); | 4231 spdy_util_.ConstructSpdySettings(settings)); |
| 4489 | 4232 |
| 4490 // Construct the request. | 4233 // Construct the request. |
| 4491 scoped_ptr<SpdyFrame> req( | 4234 scoped_ptr<SpdyFrame> req( |
| 4492 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 4235 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 4493 | 4236 |
| 4494 std::vector<MockWrite> writes; | 4237 std::vector<MockWrite> writes; |
| 4495 if (GetParam().protocol == kProtoSPDY4) { | 4238 if (GetParam().protocol == kProtoSPDY4) { |
| 4496 writes.push_back( | 4239 writes.push_back(MockWrite( |
| 4497 MockWrite(ASYNC, | 4240 ASYNC, kHttp2ConnectionHeaderPrefix, kHttp2ConnectionHeaderPrefixSize)); |
| 4498 kHttp2ConnectionHeaderPrefix, | |
| 4499 kHttp2ConnectionHeaderPrefixSize)); | |
| 4500 } | 4241 } |
| 4501 writes.push_back(CreateMockWrite(*initial_settings_frame)); | 4242 writes.push_back(CreateMockWrite(*initial_settings_frame)); |
| 4502 if (GetParam().protocol >= kProtoSPDY31) { | 4243 if (GetParam().protocol >= kProtoSPDY31) { |
| 4503 writes.push_back(CreateMockWrite(*initial_window_update)); | 4244 writes.push_back(CreateMockWrite(*initial_window_update)); |
| 4504 }; | 4245 }; |
| 4505 writes.push_back(CreateMockWrite(*settings_frame)); | 4246 writes.push_back(CreateMockWrite(*settings_frame)); |
| 4506 writes.push_back(CreateMockWrite(*req)); | 4247 writes.push_back(CreateMockWrite(*req)); |
| 4507 | 4248 |
| 4508 // Construct the reply. | 4249 // Construct the reply. |
| 4509 scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); | 4250 scoped_ptr<SpdyHeaderBlock> reply_headers(new SpdyHeaderBlock()); |
| 4510 (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; | 4251 (*reply_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 4511 (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | 4252 (*reply_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
| 4512 scoped_ptr<SpdyFrame> reply( | 4253 scoped_ptr<SpdyFrame> reply( |
| 4513 spdy_util_.ConstructSpdyFrame(kSynReplyInfo, reply_headers.Pass())); | 4254 spdy_util_.ConstructSpdyFrame(kSynReplyInfo, reply_headers.Pass())); |
| 4514 | 4255 |
| 4515 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 4256 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4516 MockRead reads[] = { | 4257 MockRead reads[] = { |
| 4517 CreateMockRead(*reply), | 4258 CreateMockRead(*reply), CreateMockRead(*body), |
| 4518 CreateMockRead(*body), | 4259 MockRead(ASYNC, 0, 0) // EOF |
| 4519 MockRead(ASYNC, 0, 0) // EOF | |
| 4520 }; | 4260 }; |
| 4521 | 4261 |
| 4522 DelayedSocketData data(2, reads, arraysize(reads), | 4262 DelayedSocketData data( |
| 4523 vector_as_array(&writes), writes.size()); | 4263 2, reads, arraysize(reads), vector_as_array(&writes), writes.size()); |
| 4524 helper.AddData(&data); | 4264 helper.AddData(&data); |
| 4525 helper.RunDefaultTest(); | 4265 helper.RunDefaultTest(); |
| 4526 helper.VerifyDataConsumed(); | 4266 helper.VerifyDataConsumed(); |
| 4527 TransactionHelperResult out = helper.output(); | 4267 TransactionHelperResult out = helper.output(); |
| 4528 EXPECT_EQ(OK, out.rv); | 4268 EXPECT_EQ(OK, out.rv); |
| 4529 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 4269 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4530 EXPECT_EQ("hello!", out.response_data); | 4270 EXPECT_EQ("hello!", out.response_data); |
| 4531 | 4271 |
| 4532 { | 4272 { |
| 4533 // Verify we had two persisted settings. | 4273 // Verify we had two persisted settings. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4548 EXPECT_TRUE(it2 != settings_map.end()); | 4288 EXPECT_TRUE(it2 != settings_map.end()); |
| 4549 SettingsFlagsAndValue flags_and_value2 = it2->second; | 4289 SettingsFlagsAndValue flags_and_value2 = it2->second; |
| 4550 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value2.first); | 4290 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value2.first); |
| 4551 EXPECT_EQ(kSampleValue2, flags_and_value2.second); | 4291 EXPECT_EQ(kSampleValue2, flags_and_value2.second); |
| 4552 } | 4292 } |
| 4553 } | 4293 } |
| 4554 | 4294 |
| 4555 TEST_P(SpdyNetworkTransactionTest, GoAwayWithActiveStream) { | 4295 TEST_P(SpdyNetworkTransactionTest, GoAwayWithActiveStream) { |
| 4556 scoped_ptr<SpdyFrame> req( | 4296 scoped_ptr<SpdyFrame> req( |
| 4557 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 4297 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 4558 MockWrite writes[] = { CreateMockWrite(*req) }; | 4298 MockWrite writes[] = {CreateMockWrite(*req)}; |
| 4559 | 4299 |
| 4560 scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway()); | 4300 scoped_ptr<SpdyFrame> go_away(spdy_util_.ConstructSpdyGoAway()); |
| 4561 MockRead reads[] = { | 4301 MockRead reads[] = { |
| 4562 CreateMockRead(*go_away), | 4302 CreateMockRead(*go_away), |
| 4563 }; | 4303 }; |
| 4564 | 4304 |
| 4565 DelayedSocketData data(1, reads, arraysize(reads), | 4305 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 4566 writes, arraysize(writes)); | 4306 NormalSpdyTransactionHelper helper( |
| 4567 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 4307 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 4568 BoundNetLog(), GetParam(), NULL); | |
| 4569 helper.AddData(&data); | 4308 helper.AddData(&data); |
| 4570 helper.RunToCompletion(&data); | 4309 helper.RunToCompletion(&data); |
| 4571 TransactionHelperResult out = helper.output(); | 4310 TransactionHelperResult out = helper.output(); |
| 4572 EXPECT_EQ(ERR_ABORTED, out.rv); | 4311 EXPECT_EQ(ERR_ABORTED, out.rv); |
| 4573 } | 4312 } |
| 4574 | 4313 |
| 4575 TEST_P(SpdyNetworkTransactionTest, CloseWithActiveStream) { | 4314 TEST_P(SpdyNetworkTransactionTest, CloseWithActiveStream) { |
| 4576 scoped_ptr<SpdyFrame> req( | 4315 scoped_ptr<SpdyFrame> req( |
| 4577 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 4316 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 4578 MockWrite writes[] = { CreateMockWrite(*req) }; | 4317 MockWrite writes[] = {CreateMockWrite(*req)}; |
| 4579 | 4318 |
| 4580 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 4319 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4581 MockRead reads[] = { | 4320 MockRead reads[] = { |
| 4582 CreateMockRead(*resp), | 4321 CreateMockRead(*resp), MockRead(SYNCHRONOUS, 0, 0) // EOF |
| 4583 MockRead(SYNCHRONOUS, 0, 0) // EOF | |
| 4584 }; | 4322 }; |
| 4585 | 4323 |
| 4586 DelayedSocketData data(1, reads, arraysize(reads), | 4324 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 4587 writes, arraysize(writes)); | |
| 4588 BoundNetLog log; | 4325 BoundNetLog log; |
| 4589 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 4326 NormalSpdyTransactionHelper helper( |
| 4590 log, GetParam(), NULL); | 4327 CreateGetRequest(), DEFAULT_PRIORITY, log, GetParam(), NULL); |
| 4591 helper.RunPreTestSetup(); | 4328 helper.RunPreTestSetup(); |
| 4592 helper.AddData(&data); | 4329 helper.AddData(&data); |
| 4593 HttpNetworkTransaction* trans = helper.trans(); | 4330 HttpNetworkTransaction* trans = helper.trans(); |
| 4594 | 4331 |
| 4595 TestCompletionCallback callback; | 4332 TestCompletionCallback callback; |
| 4596 TransactionHelperResult out; | 4333 TransactionHelperResult out; |
| 4597 out.rv = trans->Start(&CreateGetRequest(), callback.callback(), log); | 4334 out.rv = trans->Start(&CreateGetRequest(), callback.callback(), log); |
| 4598 | 4335 |
| 4599 EXPECT_EQ(out.rv, ERR_IO_PENDING); | 4336 EXPECT_EQ(out.rv, ERR_IO_PENDING); |
| 4600 out.rv = callback.WaitForResult(); | 4337 out.rv = callback.WaitForResult(); |
| 4601 EXPECT_EQ(out.rv, OK); | 4338 EXPECT_EQ(out.rv, OK); |
| 4602 | 4339 |
| 4603 const HttpResponseInfo* response = trans->GetResponseInfo(); | 4340 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4604 EXPECT_TRUE(response->headers.get() != NULL); | 4341 EXPECT_TRUE(response->headers.get() != NULL); |
| 4605 EXPECT_TRUE(response->was_fetched_via_spdy); | 4342 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4606 out.rv = ReadTransaction(trans, &out.response_data); | 4343 out.rv = ReadTransaction(trans, &out.response_data); |
| 4607 EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); | 4344 EXPECT_EQ(ERR_CONNECTION_CLOSED, out.rv); |
| 4608 | 4345 |
| 4609 // Verify that we consumed all test data. | 4346 // Verify that we consumed all test data. |
| 4610 helper.VerifyDataConsumed(); | 4347 helper.VerifyDataConsumed(); |
| 4611 } | 4348 } |
| 4612 | 4349 |
| 4613 // Test to make sure we can correctly connect through a proxy. | 4350 // Test to make sure we can correctly connect through a proxy. |
| 4614 TEST_P(SpdyNetworkTransactionTest, ProxyConnect) { | 4351 TEST_P(SpdyNetworkTransactionTest, ProxyConnect) { |
| 4615 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 4352 NormalSpdyTransactionHelper helper( |
| 4616 BoundNetLog(), GetParam(), NULL); | 4353 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 4617 helper.session_deps().reset(CreateSpdySessionDependencies( | 4354 helper.session_deps().reset(CreateSpdySessionDependencies( |
| 4618 GetParam(), | 4355 GetParam(), ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"))); |
| 4619 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"))); | |
| 4620 helper.SetSession(make_scoped_refptr( | 4356 helper.SetSession(make_scoped_refptr( |
| 4621 SpdySessionDependencies::SpdyCreateSession(helper.session_deps().get()))); | 4357 SpdySessionDependencies::SpdyCreateSession(helper.session_deps().get()))); |
| 4622 helper.RunPreTestSetup(); | 4358 helper.RunPreTestSetup(); |
| 4623 HttpNetworkTransaction* trans = helper.trans(); | 4359 HttpNetworkTransaction* trans = helper.trans(); |
| 4624 | 4360 |
| 4625 const char kConnect443[] = {"CONNECT www.google.com:443 HTTP/1.1\r\n" | 4361 const char kConnect443[] = { |
| 4626 "Host: www.google.com\r\n" | 4362 "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 4627 "Proxy-Connection: keep-alive\r\n\r\n"}; | 4363 "Host: www.google.com\r\n" |
| 4628 const char kConnect80[] = {"CONNECT www.google.com:80 HTTP/1.1\r\n" | 4364 "Proxy-Connection: keep-alive\r\n\r\n"}; |
| 4629 "Host: www.google.com\r\n" | 4365 const char kConnect80[] = { |
| 4630 "Proxy-Connection: keep-alive\r\n\r\n"}; | 4366 "CONNECT www.google.com:80 HTTP/1.1\r\n" |
| 4367 "Host: www.google.com\r\n" |
| 4368 "Proxy-Connection: keep-alive\r\n\r\n"}; |
| 4631 const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; | 4369 const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; |
| 4632 scoped_ptr<SpdyFrame> req( | 4370 scoped_ptr<SpdyFrame> req( |
| 4633 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 4371 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 4634 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 4372 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4635 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 4373 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4636 | 4374 |
| 4637 MockWrite writes_SPDYNPN[] = { | 4375 MockWrite writes_SPDYNPN[] = { |
| 4638 MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0), | 4376 MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0), |
| 4639 CreateMockWrite(*req, 2), | 4377 CreateMockWrite(*req, 2), |
| 4640 }; | 4378 }; |
| 4641 MockRead reads_SPDYNPN[] = { | 4379 MockRead reads_SPDYNPN[] = { |
| 4642 MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), | 4380 MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), |
| 4643 CreateMockRead(*resp, 3), | 4381 CreateMockRead(*resp, 3), CreateMockRead(*body.get(), 4), |
| 4644 CreateMockRead(*body.get(), 4), | 4382 MockRead(ASYNC, 0, 0, 5), |
| 4645 MockRead(ASYNC, 0, 0, 5), | |
| 4646 }; | 4383 }; |
| 4647 | 4384 |
| 4648 MockWrite writes_SPDYSSL[] = { | 4385 MockWrite writes_SPDYSSL[] = { |
| 4649 MockWrite(SYNCHRONOUS, kConnect80, arraysize(kConnect80) - 1, 0), | 4386 MockWrite(SYNCHRONOUS, kConnect80, arraysize(kConnect80) - 1, 0), |
| 4650 CreateMockWrite(*req, 2), | 4387 CreateMockWrite(*req, 2), |
| 4651 }; | 4388 }; |
| 4652 MockRead reads_SPDYSSL[] = { | 4389 MockRead reads_SPDYSSL[] = { |
| 4653 MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), | 4390 MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), |
| 4654 CreateMockRead(*resp, 3), | 4391 CreateMockRead(*resp, 3), CreateMockRead(*body.get(), 4), |
| 4655 CreateMockRead(*body.get(), 4), | 4392 MockRead(ASYNC, 0, 0, 5), |
| 4656 MockRead(ASYNC, 0, 0, 5), | |
| 4657 }; | 4393 }; |
| 4658 | 4394 |
| 4659 MockWrite writes_SPDYNOSSL[] = { | 4395 MockWrite writes_SPDYNOSSL[] = { |
| 4660 CreateMockWrite(*req, 0), | 4396 CreateMockWrite(*req, 0), |
| 4661 }; | 4397 }; |
| 4662 | 4398 |
| 4663 MockRead reads_SPDYNOSSL[] = { | 4399 MockRead reads_SPDYNOSSL[] = { |
| 4664 CreateMockRead(*resp, 1), | 4400 CreateMockRead(*resp, 1), CreateMockRead(*body.get(), 2), |
| 4665 CreateMockRead(*body.get(), 2), | 4401 MockRead(ASYNC, 0, 0, 3), |
| 4666 MockRead(ASYNC, 0, 0, 3), | |
| 4667 }; | 4402 }; |
| 4668 | 4403 |
| 4669 scoped_ptr<OrderedSocketData> data; | 4404 scoped_ptr<OrderedSocketData> data; |
| 4670 switch(GetParam().ssl_type) { | 4405 switch (GetParam().ssl_type) { |
| 4671 case SPDYNOSSL: | 4406 case SPDYNOSSL: |
| 4672 data.reset(new OrderedSocketData(reads_SPDYNOSSL, | 4407 data.reset(new OrderedSocketData(reads_SPDYNOSSL, |
| 4673 arraysize(reads_SPDYNOSSL), | 4408 arraysize(reads_SPDYNOSSL), |
| 4674 writes_SPDYNOSSL, | 4409 writes_SPDYNOSSL, |
| 4675 arraysize(writes_SPDYNOSSL))); | 4410 arraysize(writes_SPDYNOSSL))); |
| 4676 break; | 4411 break; |
| 4677 case SPDYSSL: | 4412 case SPDYSSL: |
| 4678 data.reset(new OrderedSocketData(reads_SPDYSSL, | 4413 data.reset(new OrderedSocketData(reads_SPDYSSL, |
| 4679 arraysize(reads_SPDYSSL), | 4414 arraysize(reads_SPDYSSL), |
| 4680 writes_SPDYSSL, | 4415 writes_SPDYSSL, |
| 4681 arraysize(writes_SPDYSSL))); | 4416 arraysize(writes_SPDYSSL))); |
| 4682 break; | 4417 break; |
| 4683 case SPDYNPN: | 4418 case SPDYNPN: |
| 4684 data.reset(new OrderedSocketData(reads_SPDYNPN, | 4419 data.reset(new OrderedSocketData(reads_SPDYNPN, |
| 4685 arraysize(reads_SPDYNPN), | 4420 arraysize(reads_SPDYNPN), |
| 4686 writes_SPDYNPN, | 4421 writes_SPDYNPN, |
| 4687 arraysize(writes_SPDYNPN))); | 4422 arraysize(writes_SPDYNPN))); |
| 4688 break; | 4423 break; |
| 4689 default: | 4424 default: |
| 4690 NOTREACHED(); | 4425 NOTREACHED(); |
| 4691 } | 4426 } |
| 4692 | 4427 |
| 4693 helper.AddData(data.get()); | 4428 helper.AddData(data.get()); |
| 4694 TestCompletionCallback callback; | 4429 TestCompletionCallback callback; |
| 4695 | 4430 |
| 4696 int rv = trans->Start( | 4431 int rv = |
| 4697 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 4432 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 4698 EXPECT_EQ(ERR_IO_PENDING, rv); | 4433 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4699 | 4434 |
| 4700 rv = callback.WaitForResult(); | 4435 rv = callback.WaitForResult(); |
| 4701 EXPECT_EQ(0, rv); | 4436 EXPECT_EQ(0, rv); |
| 4702 | 4437 |
| 4703 // Verify the SYN_REPLY. | 4438 // Verify the SYN_REPLY. |
| 4704 HttpResponseInfo response = *trans->GetResponseInfo(); | 4439 HttpResponseInfo response = *trans->GetResponseInfo(); |
| 4705 EXPECT_TRUE(response.headers.get() != NULL); | 4440 EXPECT_TRUE(response.headers.get() != NULL); |
| 4706 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 4441 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 4707 | 4442 |
| 4708 std::string response_data; | 4443 std::string response_data; |
| 4709 ASSERT_EQ(OK, ReadTransaction(trans, &response_data)); | 4444 ASSERT_EQ(OK, ReadTransaction(trans, &response_data)); |
| 4710 EXPECT_EQ("hello!", response_data); | 4445 EXPECT_EQ("hello!", response_data); |
| 4711 helper.VerifyDataConsumed(); | 4446 helper.VerifyDataConsumed(); |
| 4712 } | 4447 } |
| 4713 | 4448 |
| 4714 // Test to make sure we can correctly connect through a proxy to www.google.com, | 4449 // Test to make sure we can correctly connect through a proxy to www.google.com, |
| 4715 // if there already exists a direct spdy connection to www.google.com. See | 4450 // if there already exists a direct spdy connection to www.google.com. See |
| 4716 // http://crbug.com/49874 | 4451 // http://crbug.com/49874 |
| 4717 TEST_P(SpdyNetworkTransactionTest, DirectConnectProxyReconnect) { | 4452 TEST_P(SpdyNetworkTransactionTest, DirectConnectProxyReconnect) { |
| 4718 // When setting up the first transaction, we store the SpdySessionPool so that | 4453 // When setting up the first transaction, we store the SpdySessionPool so that |
| 4719 // we can use the same pool in the second transaction. | 4454 // we can use the same pool in the second transaction. |
| 4720 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 4455 NormalSpdyTransactionHelper helper( |
| 4721 BoundNetLog(), GetParam(), NULL); | 4456 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 4722 | 4457 |
| 4723 // Use a proxy service which returns a proxy fallback list from DIRECT to | 4458 // Use a proxy service which returns a proxy fallback list from DIRECT to |
| 4724 // myproxy:70. For this test there will be no fallback, so it is equivalent | 4459 // myproxy:70. For this test there will be no fallback, so it is equivalent |
| 4725 // to simply DIRECT. The reason for appending the second proxy is to verify | 4460 // to simply DIRECT. The reason for appending the second proxy is to verify |
| 4726 // that the session pool key used does is just "DIRECT". | 4461 // that the session pool key used does is just "DIRECT". |
| 4727 helper.session_deps().reset(CreateSpdySessionDependencies( | 4462 helper.session_deps().reset(CreateSpdySessionDependencies( |
| 4728 GetParam(), | 4463 GetParam(), |
| 4729 ProxyService::CreateFixedFromPacResult("DIRECT; PROXY myproxy:70"))); | 4464 ProxyService::CreateFixedFromPacResult("DIRECT; PROXY myproxy:70"))); |
| 4730 helper.SetSession(make_scoped_refptr( | 4465 helper.SetSession(make_scoped_refptr( |
| 4731 SpdySessionDependencies::SpdyCreateSession(helper.session_deps().get()))); | 4466 SpdySessionDependencies::SpdyCreateSession(helper.session_deps().get()))); |
| 4732 | 4467 |
| 4733 SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); | 4468 SpdySessionPool* spdy_session_pool = helper.session()->spdy_session_pool(); |
| 4734 helper.RunPreTestSetup(); | 4469 helper.RunPreTestSetup(); |
| 4735 | 4470 |
| 4736 // Construct and send a simple GET request. | 4471 // Construct and send a simple GET request. |
| 4737 scoped_ptr<SpdyFrame> req( | 4472 scoped_ptr<SpdyFrame> req( |
| 4738 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 4473 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 4739 MockWrite writes[] = { | 4474 MockWrite writes[] = { |
| 4740 CreateMockWrite(*req, 1), | 4475 CreateMockWrite(*req, 1), |
| 4741 }; | 4476 }; |
| 4742 | 4477 |
| 4743 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 4478 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4744 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 4479 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4745 MockRead reads[] = { | 4480 MockRead reads[] = { |
| 4746 CreateMockRead(*resp, 2), | 4481 CreateMockRead(*resp, 2), CreateMockRead(*body, 3), |
| 4747 CreateMockRead(*body, 3), | 4482 MockRead(ASYNC, ERR_IO_PENDING, 4), // Force a pause |
| 4748 MockRead(ASYNC, ERR_IO_PENDING, 4), // Force a pause | 4483 MockRead(ASYNC, 0, 5) // EOF |
| 4749 MockRead(ASYNC, 0, 5) // EOF | |
| 4750 }; | 4484 }; |
| 4751 OrderedSocketData data(reads, arraysize(reads), | 4485 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 4752 writes, arraysize(writes)); | |
| 4753 helper.AddData(&data); | 4486 helper.AddData(&data); |
| 4754 HttpNetworkTransaction* trans = helper.trans(); | 4487 HttpNetworkTransaction* trans = helper.trans(); |
| 4755 | 4488 |
| 4756 TestCompletionCallback callback; | 4489 TestCompletionCallback callback; |
| 4757 TransactionHelperResult out; | 4490 TransactionHelperResult out; |
| 4758 out.rv = trans->Start( | 4491 out.rv = |
| 4759 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 4492 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 4760 | 4493 |
| 4761 EXPECT_EQ(out.rv, ERR_IO_PENDING); | 4494 EXPECT_EQ(out.rv, ERR_IO_PENDING); |
| 4762 out.rv = callback.WaitForResult(); | 4495 out.rv = callback.WaitForResult(); |
| 4763 EXPECT_EQ(out.rv, OK); | 4496 EXPECT_EQ(out.rv, OK); |
| 4764 | 4497 |
| 4765 const HttpResponseInfo* response = trans->GetResponseInfo(); | 4498 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4766 EXPECT_TRUE(response->headers.get() != NULL); | 4499 EXPECT_TRUE(response->headers.get() != NULL); |
| 4767 EXPECT_TRUE(response->was_fetched_via_spdy); | 4500 EXPECT_TRUE(response->was_fetched_via_spdy); |
| 4768 out.rv = ReadTransaction(trans, &out.response_data); | 4501 out.rv = ReadTransaction(trans, &out.response_data); |
| 4769 EXPECT_EQ(OK, out.rv); | 4502 EXPECT_EQ(OK, out.rv); |
| 4770 out.status_line = response->headers->GetStatusLine(); | 4503 out.status_line = response->headers->GetStatusLine(); |
| 4771 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 4504 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4772 EXPECT_EQ("hello!", out.response_data); | 4505 EXPECT_EQ("hello!", out.response_data); |
| 4773 | 4506 |
| 4774 // Check that the SpdySession is still in the SpdySessionPool. | 4507 // Check that the SpdySession is still in the SpdySessionPool. |
| 4775 HostPortPair host_port_pair("www.google.com", helper.port()); | 4508 HostPortPair host_port_pair("www.google.com", helper.port()); |
| 4776 SpdySessionKey session_pool_key_direct( | 4509 SpdySessionKey session_pool_key_direct( |
| 4777 host_port_pair, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); | 4510 host_port_pair, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4778 EXPECT_TRUE(HasSpdySession(spdy_session_pool, session_pool_key_direct)); | 4511 EXPECT_TRUE(HasSpdySession(spdy_session_pool, session_pool_key_direct)); |
| 4779 SpdySessionKey session_pool_key_proxy( | 4512 SpdySessionKey session_pool_key_proxy( |
| 4780 host_port_pair, | 4513 host_port_pair, |
| 4781 ProxyServer::FromURI("www.foo.com", ProxyServer::SCHEME_HTTP), | 4514 ProxyServer::FromURI("www.foo.com", ProxyServer::SCHEME_HTTP), |
| 4782 PRIVACY_MODE_DISABLED); | 4515 PRIVACY_MODE_DISABLED); |
| 4783 EXPECT_FALSE(HasSpdySession(spdy_session_pool, session_pool_key_proxy)); | 4516 EXPECT_FALSE(HasSpdySession(spdy_session_pool, session_pool_key_proxy)); |
| 4784 | 4517 |
| 4785 // Set up data for the proxy connection. | 4518 // Set up data for the proxy connection. |
| 4786 const char kConnect443[] = {"CONNECT www.google.com:443 HTTP/1.1\r\n" | 4519 const char kConnect443[] = { |
| 4787 "Host: www.google.com\r\n" | 4520 "CONNECT www.google.com:443 HTTP/1.1\r\n" |
| 4788 "Proxy-Connection: keep-alive\r\n\r\n"}; | 4521 "Host: www.google.com\r\n" |
| 4789 const char kConnect80[] = {"CONNECT www.google.com:80 HTTP/1.1\r\n" | 4522 "Proxy-Connection: keep-alive\r\n\r\n"}; |
| 4790 "Host: www.google.com\r\n" | 4523 const char kConnect80[] = { |
| 4791 "Proxy-Connection: keep-alive\r\n\r\n"}; | 4524 "CONNECT www.google.com:80 HTTP/1.1\r\n" |
| 4525 "Host: www.google.com\r\n" |
| 4526 "Proxy-Connection: keep-alive\r\n\r\n"}; |
| 4792 const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; | 4527 const char kHTTP200[] = {"HTTP/1.1 200 OK\r\n\r\n"}; |
| 4793 scoped_ptr<SpdyFrame> req2(spdy_util_.ConstructSpdyGet( | 4528 scoped_ptr<SpdyFrame> req2(spdy_util_.ConstructSpdyGet( |
| 4794 "http://www.google.com/foo.dat", false, 1, LOWEST)); | 4529 "http://www.google.com/foo.dat", false, 1, LOWEST)); |
| 4795 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 4530 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4796 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 4531 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4797 | 4532 |
| 4798 MockWrite writes_SPDYNPN[] = { | 4533 MockWrite writes_SPDYNPN[] = { |
| 4799 MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0), | 4534 MockWrite(SYNCHRONOUS, kConnect443, arraysize(kConnect443) - 1, 0), |
| 4800 CreateMockWrite(*req2, 2), | 4535 CreateMockWrite(*req2, 2), |
| 4801 }; | 4536 }; |
| 4802 MockRead reads_SPDYNPN[] = { | 4537 MockRead reads_SPDYNPN[] = { |
| 4803 MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), | 4538 MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), |
| 4804 CreateMockRead(*resp2, 3), | 4539 CreateMockRead(*resp2, 3), CreateMockRead(*body2, 4), |
| 4805 CreateMockRead(*body2, 4), | 4540 MockRead(ASYNC, 0, 5) // EOF |
| 4806 MockRead(ASYNC, 0, 5) // EOF | |
| 4807 }; | 4541 }; |
| 4808 | 4542 |
| 4809 MockWrite writes_SPDYNOSSL[] = { | 4543 MockWrite writes_SPDYNOSSL[] = { |
| 4810 CreateMockWrite(*req2, 0), | 4544 CreateMockWrite(*req2, 0), |
| 4811 }; | 4545 }; |
| 4812 MockRead reads_SPDYNOSSL[] = { | 4546 MockRead reads_SPDYNOSSL[] = { |
| 4813 CreateMockRead(*resp2, 1), | 4547 CreateMockRead(*resp2, 1), CreateMockRead(*body2, 2), |
| 4814 CreateMockRead(*body2, 2), | 4548 MockRead(ASYNC, 0, 3) // EOF |
| 4815 MockRead(ASYNC, 0, 3) // EOF | |
| 4816 }; | 4549 }; |
| 4817 | 4550 |
| 4818 MockWrite writes_SPDYSSL[] = { | 4551 MockWrite writes_SPDYSSL[] = { |
| 4819 MockWrite(SYNCHRONOUS, kConnect80, arraysize(kConnect80) - 1, 0), | 4552 MockWrite(SYNCHRONOUS, kConnect80, arraysize(kConnect80) - 1, 0), |
| 4820 CreateMockWrite(*req2, 2), | 4553 CreateMockWrite(*req2, 2), |
| 4821 }; | 4554 }; |
| 4822 MockRead reads_SPDYSSL[] = { | 4555 MockRead reads_SPDYSSL[] = { |
| 4823 MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), | 4556 MockRead(SYNCHRONOUS, kHTTP200, arraysize(kHTTP200) - 1, 1), |
| 4824 CreateMockRead(*resp2, 3), | 4557 CreateMockRead(*resp2, 3), CreateMockRead(*body2, 4), |
| 4825 CreateMockRead(*body2, 4), | 4558 MockRead(ASYNC, 0, 0, 5), |
| 4826 MockRead(ASYNC, 0, 0, 5), | |
| 4827 }; | 4559 }; |
| 4828 | 4560 |
| 4829 scoped_ptr<OrderedSocketData> data_proxy; | 4561 scoped_ptr<OrderedSocketData> data_proxy; |
| 4830 switch(GetParam().ssl_type) { | 4562 switch (GetParam().ssl_type) { |
| 4831 case SPDYNPN: | 4563 case SPDYNPN: |
| 4832 data_proxy.reset(new OrderedSocketData(reads_SPDYNPN, | 4564 data_proxy.reset(new OrderedSocketData(reads_SPDYNPN, |
| 4833 arraysize(reads_SPDYNPN), | 4565 arraysize(reads_SPDYNPN), |
| 4834 writes_SPDYNPN, | 4566 writes_SPDYNPN, |
| 4835 arraysize(writes_SPDYNPN))); | 4567 arraysize(writes_SPDYNPN))); |
| 4836 break; | 4568 break; |
| 4837 case SPDYNOSSL: | 4569 case SPDYNOSSL: |
| 4838 data_proxy.reset(new OrderedSocketData(reads_SPDYNOSSL, | 4570 data_proxy.reset(new OrderedSocketData(reads_SPDYNOSSL, |
| 4839 arraysize(reads_SPDYNOSSL), | 4571 arraysize(reads_SPDYNOSSL), |
| 4840 writes_SPDYNOSSL, | 4572 writes_SPDYNOSSL, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4853 // Create another request to www.google.com, but this time through a proxy. | 4585 // Create another request to www.google.com, but this time through a proxy. |
| 4854 HttpRequestInfo request_proxy; | 4586 HttpRequestInfo request_proxy; |
| 4855 request_proxy.method = "GET"; | 4587 request_proxy.method = "GET"; |
| 4856 request_proxy.url = GURL("http://www.google.com/foo.dat"); | 4588 request_proxy.url = GURL("http://www.google.com/foo.dat"); |
| 4857 request_proxy.load_flags = 0; | 4589 request_proxy.load_flags = 0; |
| 4858 scoped_ptr<SpdySessionDependencies> ssd_proxy( | 4590 scoped_ptr<SpdySessionDependencies> ssd_proxy( |
| 4859 CreateSpdySessionDependencies(GetParam())); | 4591 CreateSpdySessionDependencies(GetParam())); |
| 4860 // Ensure that this transaction uses the same SpdySessionPool. | 4592 // Ensure that this transaction uses the same SpdySessionPool. |
| 4861 scoped_refptr<HttpNetworkSession> session_proxy( | 4593 scoped_refptr<HttpNetworkSession> session_proxy( |
| 4862 SpdySessionDependencies::SpdyCreateSession(ssd_proxy.get())); | 4594 SpdySessionDependencies::SpdyCreateSession(ssd_proxy.get())); |
| 4863 NormalSpdyTransactionHelper helper_proxy(request_proxy, DEFAULT_PRIORITY, | 4595 NormalSpdyTransactionHelper helper_proxy( |
| 4864 BoundNetLog(), GetParam(), NULL); | 4596 request_proxy, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 4865 HttpNetworkSessionPeer session_peer(session_proxy); | 4597 HttpNetworkSessionPeer session_peer(session_proxy); |
| 4866 scoped_ptr<net::ProxyService> proxy_service( | 4598 scoped_ptr<net::ProxyService> proxy_service( |
| 4867 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); | 4599 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
| 4868 session_peer.SetProxyService(proxy_service.get()); | 4600 session_peer.SetProxyService(proxy_service.get()); |
| 4869 helper_proxy.session_deps().swap(ssd_proxy); | 4601 helper_proxy.session_deps().swap(ssd_proxy); |
| 4870 helper_proxy.SetSession(session_proxy); | 4602 helper_proxy.SetSession(session_proxy); |
| 4871 helper_proxy.RunPreTestSetup(); | 4603 helper_proxy.RunPreTestSetup(); |
| 4872 helper_proxy.AddData(data_proxy.get()); | 4604 helper_proxy.AddData(data_proxy.get()); |
| 4873 | 4605 |
| 4874 HttpNetworkTransaction* trans_proxy = helper_proxy.trans(); | 4606 HttpNetworkTransaction* trans_proxy = helper_proxy.trans(); |
| 4875 TestCompletionCallback callback_proxy; | 4607 TestCompletionCallback callback_proxy; |
| 4876 int rv = trans_proxy->Start( | 4608 int rv = trans_proxy->Start( |
| 4877 &request_proxy, callback_proxy.callback(), BoundNetLog()); | 4609 &request_proxy, callback_proxy.callback(), BoundNetLog()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4892 } | 4624 } |
| 4893 | 4625 |
| 4894 // When we get a TCP-level RST, we need to retry a HttpNetworkTransaction | 4626 // When we get a TCP-level RST, we need to retry a HttpNetworkTransaction |
| 4895 // on a new connection, if the connection was previously known to be good. | 4627 // on a new connection, if the connection was previously known to be good. |
| 4896 // This can happen when a server reboots without saying goodbye, or when | 4628 // This can happen when a server reboots without saying goodbye, or when |
| 4897 // we're behind a NAT that masked the RST. | 4629 // we're behind a NAT that masked the RST. |
| 4898 TEST_P(SpdyNetworkTransactionTest, VerifyRetryOnConnectionReset) { | 4630 TEST_P(SpdyNetworkTransactionTest, VerifyRetryOnConnectionReset) { |
| 4899 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 4631 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4900 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 4632 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4901 MockRead reads[] = { | 4633 MockRead reads[] = { |
| 4902 CreateMockRead(*resp), | 4634 CreateMockRead(*resp), CreateMockRead(*body), |
| 4903 CreateMockRead(*body), | 4635 MockRead(ASYNC, ERR_IO_PENDING), MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 4904 MockRead(ASYNC, ERR_IO_PENDING), | |
| 4905 MockRead(ASYNC, ERR_CONNECTION_RESET), | |
| 4906 }; | 4636 }; |
| 4907 | 4637 |
| 4908 MockRead reads2[] = { | 4638 MockRead reads2[] = { |
| 4909 CreateMockRead(*resp), | 4639 CreateMockRead(*resp), CreateMockRead(*body), |
| 4910 CreateMockRead(*body), | 4640 MockRead(ASYNC, 0, 0) // EOF |
| 4911 MockRead(ASYNC, 0, 0) // EOF | |
| 4912 }; | 4641 }; |
| 4913 | 4642 |
| 4914 // This test has a couple of variants. | 4643 // This test has a couple of variants. |
| 4915 enum { | 4644 enum { |
| 4916 // Induce the RST while waiting for our transaction to send. | 4645 // Induce the RST while waiting for our transaction to send. |
| 4917 VARIANT_RST_DURING_SEND_COMPLETION, | 4646 VARIANT_RST_DURING_SEND_COMPLETION, |
| 4918 // Induce the RST while waiting for our transaction to read. | 4647 // Induce the RST while waiting for our transaction to read. |
| 4919 // In this case, the send completed - everything copied into the SNDBUF. | 4648 // In this case, the send completed - everything copied into the SNDBUF. |
| 4920 VARIANT_RST_DURING_READ_COMPLETION | 4649 VARIANT_RST_DURING_READ_COMPLETION |
| 4921 }; | 4650 }; |
| 4922 | 4651 |
| 4923 for (int variant = VARIANT_RST_DURING_SEND_COMPLETION; | 4652 for (int variant = VARIANT_RST_DURING_SEND_COMPLETION; |
| 4924 variant <= VARIANT_RST_DURING_READ_COMPLETION; | 4653 variant <= VARIANT_RST_DURING_READ_COMPLETION; |
| 4925 ++variant) { | 4654 ++variant) { |
| 4926 DelayedSocketData data1(1, reads, arraysize(reads), NULL, 0); | 4655 DelayedSocketData data1(1, reads, arraysize(reads), NULL, 0); |
| 4927 | 4656 |
| 4928 DelayedSocketData data2(1, reads2, arraysize(reads2), NULL, 0); | 4657 DelayedSocketData data2(1, reads2, arraysize(reads2), NULL, 0); |
| 4929 | 4658 |
| 4930 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 4659 NormalSpdyTransactionHelper helper( |
| 4931 BoundNetLog(), GetParam(), NULL); | 4660 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 4932 helper.AddData(&data1); | 4661 helper.AddData(&data1); |
| 4933 helper.AddData(&data2); | 4662 helper.AddData(&data2); |
| 4934 helper.RunPreTestSetup(); | 4663 helper.RunPreTestSetup(); |
| 4935 | 4664 |
| 4936 for (int i = 0; i < 2; ++i) { | 4665 for (int i = 0; i < 2; ++i) { |
| 4937 scoped_ptr<HttpNetworkTransaction> trans( | 4666 scoped_ptr<HttpNetworkTransaction> trans( |
| 4938 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); | 4667 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
| 4939 | 4668 |
| 4940 TestCompletionCallback callback; | 4669 TestCompletionCallback callback; |
| 4941 int rv = trans->Start( | 4670 int rv = |
| 4942 &helper.request(), callback.callback(), BoundNetLog()); | 4671 trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 4943 EXPECT_EQ(ERR_IO_PENDING, rv); | 4672 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 4944 // On the second transaction, we trigger the RST. | 4673 // On the second transaction, we trigger the RST. |
| 4945 if (i == 1) { | 4674 if (i == 1) { |
| 4946 if (variant == VARIANT_RST_DURING_READ_COMPLETION) { | 4675 if (variant == VARIANT_RST_DURING_READ_COMPLETION) { |
| 4947 // Writes to the socket complete asynchronously on SPDY by running | 4676 // Writes to the socket complete asynchronously on SPDY by running |
| 4948 // through the message loop. Complete the write here. | 4677 // through the message loop. Complete the write here. |
| 4949 base::RunLoop().RunUntilIdle(); | 4678 base::RunLoop().RunUntilIdle(); |
| 4950 } | 4679 } |
| 4951 | 4680 |
| 4952 // Now schedule the ERR_CONNECTION_RESET. | 4681 // Now schedule the ERR_CONNECTION_RESET. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 4970 | 4699 |
| 4971 helper.VerifyDataConsumed(); | 4700 helper.VerifyDataConsumed(); |
| 4972 } | 4701 } |
| 4973 } | 4702 } |
| 4974 | 4703 |
| 4975 // Test that turning SPDY on and off works properly. | 4704 // Test that turning SPDY on and off works properly. |
| 4976 TEST_P(SpdyNetworkTransactionTest, SpdyOnOffToggle) { | 4705 TEST_P(SpdyNetworkTransactionTest, SpdyOnOffToggle) { |
| 4977 net::HttpStreamFactory::set_spdy_enabled(true); | 4706 net::HttpStreamFactory::set_spdy_enabled(true); |
| 4978 scoped_ptr<SpdyFrame> req( | 4707 scoped_ptr<SpdyFrame> req( |
| 4979 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 4708 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 4980 MockWrite spdy_writes[] = { CreateMockWrite(*req) }; | 4709 MockWrite spdy_writes[] = {CreateMockWrite(*req)}; |
| 4981 | 4710 |
| 4982 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 4711 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 4983 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 4712 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 4984 MockRead spdy_reads[] = { | 4713 MockRead spdy_reads[] = { |
| 4985 CreateMockRead(*resp), | 4714 CreateMockRead(*resp), CreateMockRead(*body), |
| 4986 CreateMockRead(*body), | 4715 MockRead(ASYNC, 0, 0) // EOF |
| 4987 MockRead(ASYNC, 0, 0) // EOF | |
| 4988 }; | 4716 }; |
| 4989 | 4717 |
| 4990 DelayedSocketData data(1, spdy_reads, arraysize(spdy_reads), | 4718 DelayedSocketData data(1, |
| 4991 spdy_writes, arraysize(spdy_writes)); | 4719 spdy_reads, |
| 4992 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 4720 arraysize(spdy_reads), |
| 4993 BoundNetLog(), GetParam(), NULL); | 4721 spdy_writes, |
| 4722 arraysize(spdy_writes)); |
| 4723 NormalSpdyTransactionHelper helper( |
| 4724 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 4994 helper.RunToCompletion(&data); | 4725 helper.RunToCompletion(&data); |
| 4995 TransactionHelperResult out = helper.output(); | 4726 TransactionHelperResult out = helper.output(); |
| 4996 EXPECT_EQ(OK, out.rv); | 4727 EXPECT_EQ(OK, out.rv); |
| 4997 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 4728 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 4998 EXPECT_EQ("hello!", out.response_data); | 4729 EXPECT_EQ("hello!", out.response_data); |
| 4999 | 4730 |
| 5000 net::HttpStreamFactory::set_spdy_enabled(false); | 4731 net::HttpStreamFactory::set_spdy_enabled(false); |
| 5001 MockRead http_reads[] = { | 4732 MockRead http_reads[] = { |
| 5002 MockRead("HTTP/1.1 200 OK\r\n\r\n"), | 4733 MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello from http"), |
| 5003 MockRead("hello from http"), | 4734 MockRead(SYNCHRONOUS, OK), |
| 5004 MockRead(SYNCHRONOUS, OK), | |
| 5005 }; | 4735 }; |
| 5006 DelayedSocketData data2(1, http_reads, arraysize(http_reads), NULL, 0); | 4736 DelayedSocketData data2(1, http_reads, arraysize(http_reads), NULL, 0); |
| 5007 NormalSpdyTransactionHelper helper2(CreateGetRequest(), DEFAULT_PRIORITY, | 4737 NormalSpdyTransactionHelper helper2( |
| 5008 BoundNetLog(), GetParam(), NULL); | 4738 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 5009 helper2.SetSpdyDisabled(); | 4739 helper2.SetSpdyDisabled(); |
| 5010 helper2.RunToCompletion(&data2); | 4740 helper2.RunToCompletion(&data2); |
| 5011 TransactionHelperResult out2 = helper2.output(); | 4741 TransactionHelperResult out2 = helper2.output(); |
| 5012 EXPECT_EQ(OK, out2.rv); | 4742 EXPECT_EQ(OK, out2.rv); |
| 5013 EXPECT_EQ("HTTP/1.1 200 OK", out2.status_line); | 4743 EXPECT_EQ("HTTP/1.1 200 OK", out2.status_line); |
| 5014 EXPECT_EQ("hello from http", out2.response_data); | 4744 EXPECT_EQ("hello from http", out2.response_data); |
| 5015 | 4745 |
| 5016 net::HttpStreamFactory::set_spdy_enabled(true); | 4746 net::HttpStreamFactory::set_spdy_enabled(true); |
| 5017 } | 4747 } |
| 5018 | 4748 |
| 5019 // Tests that Basic authentication works over SPDY | 4749 // Tests that Basic authentication works over SPDY |
| 5020 TEST_P(SpdyNetworkTransactionTest, SpdyBasicAuth) { | 4750 TEST_P(SpdyNetworkTransactionTest, SpdyBasicAuth) { |
| 5021 net::HttpStreamFactory::set_spdy_enabled(true); | 4751 net::HttpStreamFactory::set_spdy_enabled(true); |
| 5022 | 4752 |
| 5023 // The first request will be a bare GET, the second request will be a | 4753 // The first request will be a bare GET, the second request will be a |
| 5024 // GET with an Authorization header. | 4754 // GET with an Authorization header. |
| 5025 scoped_ptr<SpdyFrame> req_get( | 4755 scoped_ptr<SpdyFrame> req_get( |
| 5026 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 4756 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5027 const char* const kExtraAuthorizationHeaders[] = { | 4757 const char* const kExtraAuthorizationHeaders[] = {"authorization", |
| 5028 "authorization", "Basic Zm9vOmJhcg==" | 4758 "Basic Zm9vOmJhcg=="}; |
| 5029 }; | |
| 5030 scoped_ptr<SpdyFrame> req_get_authorization( | 4759 scoped_ptr<SpdyFrame> req_get_authorization( |
| 5031 spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, | 4760 spdy_util_.ConstructSpdyGet(kExtraAuthorizationHeaders, |
| 5032 arraysize(kExtraAuthorizationHeaders) / 2, | 4761 arraysize(kExtraAuthorizationHeaders) / 2, |
| 5033 false, 3, LOWEST, true)); | 4762 false, |
| 4763 3, |
| 4764 LOWEST, |
| 4765 true)); |
| 5034 MockWrite spdy_writes[] = { | 4766 MockWrite spdy_writes[] = { |
| 5035 CreateMockWrite(*req_get, 1), | 4767 CreateMockWrite(*req_get, 1), CreateMockWrite(*req_get_authorization, 4), |
| 5036 CreateMockWrite(*req_get_authorization, 4), | |
| 5037 }; | 4768 }; |
| 5038 | 4769 |
| 5039 // The first response is a 401 authentication challenge, and the second | 4770 // The first response is a 401 authentication challenge, and the second |
| 5040 // response will be a 200 response since the second request includes a valid | 4771 // response will be a 200 response since the second request includes a valid |
| 5041 // Authorization header. | 4772 // Authorization header. |
| 5042 const char* const kExtraAuthenticationHeaders[] = { | 4773 const char* const kExtraAuthenticationHeaders[] = {"www-authenticate", |
| 5043 "www-authenticate", | 4774 "Basic realm=\"MyRealm\""}; |
| 5044 "Basic realm=\"MyRealm\"" | |
| 5045 }; | |
| 5046 scoped_ptr<SpdyFrame> resp_authentication( | 4775 scoped_ptr<SpdyFrame> resp_authentication( |
| 5047 spdy_util_.ConstructSpdySynReplyError( | 4776 spdy_util_.ConstructSpdySynReplyError( |
| 5048 "401 Authentication Required", | 4777 "401 Authentication Required", |
| 5049 kExtraAuthenticationHeaders, | 4778 kExtraAuthenticationHeaders, |
| 5050 arraysize(kExtraAuthenticationHeaders) / 2, | 4779 arraysize(kExtraAuthenticationHeaders) / 2, |
| 5051 1)); | 4780 1)); |
| 5052 scoped_ptr<SpdyFrame> body_authentication( | 4781 scoped_ptr<SpdyFrame> body_authentication( |
| 5053 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 4782 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 5054 scoped_ptr<SpdyFrame> resp_data( | 4783 scoped_ptr<SpdyFrame> resp_data( |
| 5055 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); | 4784 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 5056 scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); | 4785 scoped_ptr<SpdyFrame> body_data(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 5057 MockRead spdy_reads[] = { | 4786 MockRead spdy_reads[] = { |
| 5058 CreateMockRead(*resp_authentication, 2), | 4787 CreateMockRead(*resp_authentication, 2), |
| 5059 CreateMockRead(*body_authentication, 3), | 4788 CreateMockRead(*body_authentication, 3), |
| 5060 CreateMockRead(*resp_data, 5), | 4789 CreateMockRead(*resp_data, 5), |
| 5061 CreateMockRead(*body_data, 6), | 4790 CreateMockRead(*body_data, 6), |
| 5062 MockRead(ASYNC, 0, 7), | 4791 MockRead(ASYNC, 0, 7), |
| 5063 }; | 4792 }; |
| 5064 | 4793 |
| 5065 OrderedSocketData data(spdy_reads, arraysize(spdy_reads), | 4794 OrderedSocketData data( |
| 5066 spdy_writes, arraysize(spdy_writes)); | 4795 spdy_reads, arraysize(spdy_reads), spdy_writes, arraysize(spdy_writes)); |
| 5067 HttpRequestInfo request(CreateGetRequest()); | 4796 HttpRequestInfo request(CreateGetRequest()); |
| 5068 BoundNetLog net_log; | 4797 BoundNetLog net_log; |
| 5069 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, | 4798 NormalSpdyTransactionHelper helper( |
| 5070 net_log, GetParam(), NULL); | 4799 request, DEFAULT_PRIORITY, net_log, GetParam(), NULL); |
| 5071 | 4800 |
| 5072 helper.RunPreTestSetup(); | 4801 helper.RunPreTestSetup(); |
| 5073 helper.AddData(&data); | 4802 helper.AddData(&data); |
| 5074 HttpNetworkTransaction* trans = helper.trans(); | 4803 HttpNetworkTransaction* trans = helper.trans(); |
| 5075 TestCompletionCallback callback; | 4804 TestCompletionCallback callback; |
| 5076 const int rv_start = trans->Start(&request, callback.callback(), net_log); | 4805 const int rv_start = trans->Start(&request, callback.callback(), net_log); |
| 5077 EXPECT_EQ(ERR_IO_PENDING, rv_start); | 4806 EXPECT_EQ(ERR_IO_PENDING, rv_start); |
| 5078 const int rv_start_complete = callback.WaitForResult(); | 4807 const int rv_start_complete = callback.WaitForResult(); |
| 5079 EXPECT_EQ(OK, rv_start_complete); | 4808 EXPECT_EQ(OK, rv_start_complete); |
| 5080 | 4809 |
| 5081 // Make sure the response has an auth challenge. | 4810 // Make sure the response has an auth challenge. |
| 5082 const HttpResponseInfo* const response_start = trans->GetResponseInfo(); | 4811 const HttpResponseInfo* const response_start = trans->GetResponseInfo(); |
| 5083 ASSERT_TRUE(response_start != NULL); | 4812 ASSERT_TRUE(response_start != NULL); |
| 5084 ASSERT_TRUE(response_start->headers.get() != NULL); | 4813 ASSERT_TRUE(response_start->headers.get() != NULL); |
| 5085 EXPECT_EQ(401, response_start->headers->response_code()); | 4814 EXPECT_EQ(401, response_start->headers->response_code()); |
| 5086 EXPECT_TRUE(response_start->was_fetched_via_spdy); | 4815 EXPECT_TRUE(response_start->was_fetched_via_spdy); |
| 5087 AuthChallengeInfo* auth_challenge = response_start->auth_challenge.get(); | 4816 AuthChallengeInfo* auth_challenge = response_start->auth_challenge.get(); |
| 5088 ASSERT_TRUE(auth_challenge != NULL); | 4817 ASSERT_TRUE(auth_challenge != NULL); |
| 5089 EXPECT_FALSE(auth_challenge->is_proxy); | 4818 EXPECT_FALSE(auth_challenge->is_proxy); |
| 5090 EXPECT_EQ("basic", auth_challenge->scheme); | 4819 EXPECT_EQ("basic", auth_challenge->scheme); |
| 5091 EXPECT_EQ("MyRealm", auth_challenge->realm); | 4820 EXPECT_EQ("MyRealm", auth_challenge->realm); |
| 5092 | 4821 |
| 5093 // Restart with a username/password. | 4822 // Restart with a username/password. |
| 5094 AuthCredentials credentials(base::ASCIIToUTF16("foo"), | 4823 AuthCredentials credentials(base::ASCIIToUTF16("foo"), |
| 5095 base::ASCIIToUTF16("bar")); | 4824 base::ASCIIToUTF16("bar")); |
| 5096 TestCompletionCallback callback_restart; | 4825 TestCompletionCallback callback_restart; |
| 5097 const int rv_restart = trans->RestartWithAuth( | 4826 const int rv_restart = |
| 5098 credentials, callback_restart.callback()); | 4827 trans->RestartWithAuth(credentials, callback_restart.callback()); |
| 5099 EXPECT_EQ(ERR_IO_PENDING, rv_restart); | 4828 EXPECT_EQ(ERR_IO_PENDING, rv_restart); |
| 5100 const int rv_restart_complete = callback_restart.WaitForResult(); | 4829 const int rv_restart_complete = callback_restart.WaitForResult(); |
| 5101 EXPECT_EQ(OK, rv_restart_complete); | 4830 EXPECT_EQ(OK, rv_restart_complete); |
| 5102 // TODO(cbentzel): This is actually the same response object as before, but | 4831 // TODO(cbentzel): This is actually the same response object as before, but |
| 5103 // data has changed. | 4832 // data has changed. |
| 5104 const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); | 4833 const HttpResponseInfo* const response_restart = trans->GetResponseInfo(); |
| 5105 ASSERT_TRUE(response_restart != NULL); | 4834 ASSERT_TRUE(response_restart != NULL); |
| 5106 ASSERT_TRUE(response_restart->headers.get() != NULL); | 4835 ASSERT_TRUE(response_restart->headers.get() != NULL); |
| 5107 EXPECT_EQ(200, response_restart->headers->response_code()); | 4836 EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5108 EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); | 4837 EXPECT_TRUE(response_restart->auth_challenge.get() == NULL); |
| 5109 } | 4838 } |
| 5110 | 4839 |
| 5111 TEST_P(SpdyNetworkTransactionTest, ServerPushWithHeaders) { | 4840 TEST_P(SpdyNetworkTransactionTest, ServerPushWithHeaders) { |
| 5112 scoped_ptr<SpdyFrame> stream1_syn( | 4841 scoped_ptr<SpdyFrame> stream1_syn( |
| 5113 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 4842 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5114 scoped_ptr<SpdyFrame> stream1_body( | 4843 scoped_ptr<SpdyFrame> stream1_body( |
| 5115 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 4844 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 5116 MockWrite writes[] = { | 4845 MockWrite writes[] = { |
| 5117 CreateMockWrite(*stream1_syn, 1), | 4846 CreateMockWrite(*stream1_syn, 1), |
| 5118 }; | 4847 }; |
| 5119 | 4848 |
| 5120 scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); | 4849 scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
| 5121 spdy_util_.AddUrlToHeaderBlock( | 4850 spdy_util_.AddUrlToHeaderBlock("http://www.google.com/foo.dat", |
| 5122 "http://www.google.com/foo.dat", initial_headers.get()); | 4851 initial_headers.get()); |
| 5123 scoped_ptr<SpdyFrame> stream2_syn( | 4852 scoped_ptr<SpdyFrame> stream2_syn( |
| 5124 spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), | 4853 spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), |
| 5125 false, | 4854 false, |
| 5126 2, | 4855 2, |
| 5127 LOWEST, | 4856 LOWEST, |
| 5128 SYN_STREAM, | 4857 SYN_STREAM, |
| 5129 CONTROL_FLAG_NONE, | 4858 CONTROL_FLAG_NONE, |
| 5130 1)); | 4859 1)); |
| 5131 | 4860 |
| 5132 scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); | 4861 scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5133 (*late_headers)["hello"] = "bye"; | 4862 (*late_headers)["hello"] = "bye"; |
| 5134 (*late_headers)[spdy_util_.GetStatusKey()] = "200"; | 4863 (*late_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 5135 (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | 4864 (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
| 5136 scoped_ptr<SpdyFrame> stream2_headers( | 4865 scoped_ptr<SpdyFrame> stream2_headers(spdy_util_.ConstructSpdyControlFrame( |
| 5137 spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), | 4866 late_headers.Pass(), false, 2, LOWEST, HEADERS, CONTROL_FLAG_NONE, 0)); |
| 5138 false, | |
| 5139 2, | |
| 5140 LOWEST, | |
| 5141 HEADERS, | |
| 5142 CONTROL_FLAG_NONE, | |
| 5143 0)); | |
| 5144 | 4867 |
| 5145 scoped_ptr<SpdyFrame> | 4868 scoped_ptr<SpdyFrame> stream1_reply( |
| 5146 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 4869 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 5147 const char kPushedData[] = "pushed"; | 4870 const char kPushedData[] = "pushed"; |
| 5148 scoped_ptr<SpdyFrame> stream2_body( | 4871 scoped_ptr<SpdyFrame> stream2_body(spdy_util_.ConstructSpdyBodyFrame( |
| 5149 spdy_util_.ConstructSpdyBodyFrame( | 4872 2, kPushedData, strlen(kPushedData), true)); |
| 5150 2, kPushedData, strlen(kPushedData), true)); | |
| 5151 MockRead reads[] = { | 4873 MockRead reads[] = { |
| 5152 CreateMockRead(*stream1_reply, 2), | 4874 CreateMockRead(*stream1_reply, 2), |
| 5153 CreateMockRead(*stream2_syn, 3), | 4875 CreateMockRead(*stream2_syn, 3), |
| 5154 CreateMockRead(*stream2_headers, 4), | 4876 CreateMockRead(*stream2_headers, 4), |
| 5155 CreateMockRead(*stream1_body, 5, SYNCHRONOUS), | 4877 CreateMockRead(*stream1_body, 5, SYNCHRONOUS), |
| 5156 CreateMockRead(*stream2_body, 5), | 4878 CreateMockRead(*stream2_body, 5), |
| 5157 MockRead(ASYNC, ERR_IO_PENDING, 7), // Force a pause | 4879 MockRead(ASYNC, ERR_IO_PENDING, 7), // Force a pause |
| 5158 }; | 4880 }; |
| 5159 | 4881 |
| 5160 HttpResponseInfo response; | 4882 HttpResponseInfo response; |
| 5161 HttpResponseInfo response2; | 4883 HttpResponseInfo response2; |
| 5162 std::string expected_push_result("pushed"); | 4884 std::string expected_push_result("pushed"); |
| 5163 OrderedSocketData data(reads, arraysize(reads), | 4885 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 5164 writes, arraysize(writes)); | 4886 RunServerPushTest(&data, &response, &response2, expected_push_result); |
| 5165 RunServerPushTest(&data, | |
| 5166 &response, | |
| 5167 &response2, | |
| 5168 expected_push_result); | |
| 5169 | 4887 |
| 5170 // Verify the SYN_REPLY. | 4888 // Verify the SYN_REPLY. |
| 5171 EXPECT_TRUE(response.headers.get() != NULL); | 4889 EXPECT_TRUE(response.headers.get() != NULL); |
| 5172 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 4890 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5173 | 4891 |
| 5174 // Verify the pushed stream. | 4892 // Verify the pushed stream. |
| 5175 EXPECT_TRUE(response2.headers.get() != NULL); | 4893 EXPECT_TRUE(response2.headers.get() != NULL); |
| 5176 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); | 4894 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 5177 } | 4895 } |
| 5178 | 4896 |
| 5179 TEST_P(SpdyNetworkTransactionTest, ServerPushClaimBeforeHeaders) { | 4897 TEST_P(SpdyNetworkTransactionTest, ServerPushClaimBeforeHeaders) { |
| 5180 // We push a stream and attempt to claim it before the headers come down. | 4898 // We push a stream and attempt to claim it before the headers come down. |
| 5181 scoped_ptr<SpdyFrame> stream1_syn( | 4899 scoped_ptr<SpdyFrame> stream1_syn( |
| 5182 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 4900 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5183 scoped_ptr<SpdyFrame> stream1_body( | 4901 scoped_ptr<SpdyFrame> stream1_body( |
| 5184 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 4902 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 5185 MockWrite writes[] = { | 4903 MockWrite writes[] = { |
| 5186 CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), | 4904 CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), |
| 5187 }; | 4905 }; |
| 5188 | 4906 |
| 5189 scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); | 4907 scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
| 5190 spdy_util_.AddUrlToHeaderBlock( | 4908 spdy_util_.AddUrlToHeaderBlock("http://www.google.com/foo.dat", |
| 5191 "http://www.google.com/foo.dat", initial_headers.get()); | 4909 initial_headers.get()); |
| 5192 scoped_ptr<SpdyFrame> stream2_syn( | 4910 scoped_ptr<SpdyFrame> stream2_syn( |
| 5193 spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), | 4911 spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), |
| 5194 false, | 4912 false, |
| 5195 2, | 4913 2, |
| 5196 LOWEST, | 4914 LOWEST, |
| 5197 SYN_STREAM, | 4915 SYN_STREAM, |
| 5198 CONTROL_FLAG_NONE, | 4916 CONTROL_FLAG_NONE, |
| 5199 1)); | 4917 1)); |
| 5200 | 4918 |
| 5201 scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); | 4919 scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5202 (*late_headers)["hello"] = "bye"; | 4920 (*late_headers)["hello"] = "bye"; |
| 5203 (*late_headers)[spdy_util_.GetStatusKey()] = "200"; | 4921 (*late_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 5204 (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | 4922 (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
| 5205 scoped_ptr<SpdyFrame> stream2_headers( | 4923 scoped_ptr<SpdyFrame> stream2_headers(spdy_util_.ConstructSpdyControlFrame( |
| 5206 spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), | 4924 late_headers.Pass(), false, 2, LOWEST, HEADERS, CONTROL_FLAG_NONE, 0)); |
| 5207 false, | |
| 5208 2, | |
| 5209 LOWEST, | |
| 5210 HEADERS, | |
| 5211 CONTROL_FLAG_NONE, | |
| 5212 0)); | |
| 5213 | 4925 |
| 5214 scoped_ptr<SpdyFrame> | 4926 scoped_ptr<SpdyFrame> stream1_reply( |
| 5215 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 4927 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 5216 const char kPushedData[] = "pushed"; | 4928 const char kPushedData[] = "pushed"; |
| 5217 scoped_ptr<SpdyFrame> stream2_body( | 4929 scoped_ptr<SpdyFrame> stream2_body(spdy_util_.ConstructSpdyBodyFrame( |
| 5218 spdy_util_.ConstructSpdyBodyFrame( | 4930 2, kPushedData, strlen(kPushedData), true)); |
| 5219 2, kPushedData, strlen(kPushedData), true)); | |
| 5220 MockRead reads[] = { | 4931 MockRead reads[] = { |
| 5221 CreateMockRead(*stream1_reply, 1), | 4932 CreateMockRead(*stream1_reply, 1), CreateMockRead(*stream2_syn, 2), |
| 5222 CreateMockRead(*stream2_syn, 2), | 4933 CreateMockRead(*stream1_body, 3), CreateMockRead(*stream2_headers, 4), |
| 5223 CreateMockRead(*stream1_body, 3), | 4934 CreateMockRead(*stream2_body, 5), MockRead(ASYNC, 0, 6), // EOF |
| 5224 CreateMockRead(*stream2_headers, 4), | |
| 5225 CreateMockRead(*stream2_body, 5), | |
| 5226 MockRead(ASYNC, 0, 6), // EOF | |
| 5227 }; | 4935 }; |
| 5228 | 4936 |
| 5229 HttpResponseInfo response; | 4937 HttpResponseInfo response; |
| 5230 HttpResponseInfo response2; | 4938 HttpResponseInfo response2; |
| 5231 std::string expected_push_result("pushed"); | 4939 std::string expected_push_result("pushed"); |
| 5232 DeterministicSocketData data(reads, arraysize(reads), | 4940 DeterministicSocketData data( |
| 5233 writes, arraysize(writes)); | 4941 reads, arraysize(reads), writes, arraysize(writes)); |
| 5234 | 4942 |
| 5235 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 4943 NormalSpdyTransactionHelper helper( |
| 5236 BoundNetLog(), GetParam(), NULL); | 4944 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 5237 helper.SetDeterministic(); | 4945 helper.SetDeterministic(); |
| 5238 helper.AddDeterministicData(&data); | 4946 helper.AddDeterministicData(&data); |
| 5239 helper.RunPreTestSetup(); | 4947 helper.RunPreTestSetup(); |
| 5240 | 4948 |
| 5241 HttpNetworkTransaction* trans = helper.trans(); | 4949 HttpNetworkTransaction* trans = helper.trans(); |
| 5242 | 4950 |
| 5243 // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM, | 4951 // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM, |
| 5244 // and the body of the primary stream, but before we've received the HEADERS | 4952 // and the body of the primary stream, but before we've received the HEADERS |
| 5245 // for the pushed stream. | 4953 // for the pushed stream. |
| 5246 data.SetStop(3); | 4954 data.SetStop(3); |
| 5247 | 4955 |
| 5248 // Start the transaction. | 4956 // Start the transaction. |
| 5249 TestCompletionCallback callback; | 4957 TestCompletionCallback callback; |
| 5250 int rv = trans->Start( | 4958 int rv = |
| 5251 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 4959 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 5252 EXPECT_EQ(ERR_IO_PENDING, rv); | 4960 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5253 data.Run(); | 4961 data.Run(); |
| 5254 rv = callback.WaitForResult(); | 4962 rv = callback.WaitForResult(); |
| 5255 EXPECT_EQ(0, rv); | 4963 EXPECT_EQ(0, rv); |
| 5256 | 4964 |
| 5257 // Request the pushed path. At this point, we've received the push, but the | 4965 // Request the pushed path. At this point, we've received the push, but the |
| 5258 // headers are not yet complete. | 4966 // headers are not yet complete. |
| 5259 scoped_ptr<HttpNetworkTransaction> trans2( | 4967 scoped_ptr<HttpNetworkTransaction> trans2( |
| 5260 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); | 4968 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
| 5261 rv = trans2->Start( | 4969 rv = trans2->Start( |
| 5262 &CreateGetPushRequest(), callback.callback(), BoundNetLog()); | 4970 &CreateGetPushRequest(), callback.callback(), BoundNetLog()); |
| 5263 EXPECT_EQ(ERR_IO_PENDING, rv); | 4971 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5264 data.RunFor(3); | 4972 data.RunFor(3); |
| 5265 base::RunLoop().RunUntilIdle(); | 4973 base::RunLoop().RunUntilIdle(); |
| 5266 | 4974 |
| 5267 // Read the server push body. | 4975 // Read the server push body. |
| 5268 std::string result2; | 4976 std::string result2; |
| 5269 ReadResult(trans2.get(), &data, &result2); | 4977 ReadResult(trans2.get(), &data, &result2); |
| 5270 // Read the response body. | 4978 // Read the response body. |
| 5271 std::string result; | 4979 std::string result; |
| 5272 ReadResult(trans, &data, &result); | 4980 ReadResult(trans, &data, &result); |
| 5273 | 4981 |
| 5274 // Verify that the received push data is same as the expected push data. | 4982 // Verify that the received push data is same as the expected push data. |
| 5275 EXPECT_EQ(result2.compare(expected_push_result), 0) | 4983 EXPECT_EQ(result2.compare(expected_push_result), 0) |
| 5276 << "Received data: " | 4984 << "Received data: " << result2 |
| 5277 << result2 | 4985 << "||||| Expected data: " << expected_push_result; |
| 5278 << "||||| Expected data: " | |
| 5279 << expected_push_result; | |
| 5280 | 4986 |
| 5281 // Verify the SYN_REPLY. | 4987 // Verify the SYN_REPLY. |
| 5282 // Copy the response info, because trans goes away. | 4988 // Copy the response info, because trans goes away. |
| 5283 response = *trans->GetResponseInfo(); | 4989 response = *trans->GetResponseInfo(); |
| 5284 response2 = *trans2->GetResponseInfo(); | 4990 response2 = *trans2->GetResponseInfo(); |
| 5285 | 4991 |
| 5286 VerifyStreamsClosed(helper); | 4992 VerifyStreamsClosed(helper); |
| 5287 | 4993 |
| 5288 // Verify the SYN_REPLY. | 4994 // Verify the SYN_REPLY. |
| 5289 EXPECT_TRUE(response.headers.get() != NULL); | 4995 EXPECT_TRUE(response.headers.get() != NULL); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 5301 EXPECT_TRUE(data.at_write_eof()); | 5007 EXPECT_TRUE(data.at_write_eof()); |
| 5302 } | 5008 } |
| 5303 | 5009 |
| 5304 TEST_P(SpdyNetworkTransactionTest, ServerPushWithTwoHeaderFrames) { | 5010 TEST_P(SpdyNetworkTransactionTest, ServerPushWithTwoHeaderFrames) { |
| 5305 // We push a stream and attempt to claim it before the headers come down. | 5011 // We push a stream and attempt to claim it before the headers come down. |
| 5306 scoped_ptr<SpdyFrame> stream1_syn( | 5012 scoped_ptr<SpdyFrame> stream1_syn( |
| 5307 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 5013 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5308 scoped_ptr<SpdyFrame> stream1_body( | 5014 scoped_ptr<SpdyFrame> stream1_body( |
| 5309 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 5015 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 5310 MockWrite writes[] = { | 5016 MockWrite writes[] = { |
| 5311 CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), | 5017 CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), |
| 5312 }; | 5018 }; |
| 5313 | 5019 |
| 5314 scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); | 5020 scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
| 5315 spdy_util_.AddUrlToHeaderBlock( | 5021 spdy_util_.AddUrlToHeaderBlock("http://www.google.com/foo.dat", |
| 5316 "http://www.google.com/foo.dat", initial_headers.get()); | 5022 initial_headers.get()); |
| 5317 scoped_ptr<SpdyFrame> stream2_syn( | 5023 scoped_ptr<SpdyFrame> stream2_syn( |
| 5318 spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), | 5024 spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), |
| 5319 false, | 5025 false, |
| 5320 2, | 5026 2, |
| 5321 LOWEST, | 5027 LOWEST, |
| 5322 SYN_STREAM, | 5028 SYN_STREAM, |
| 5323 CONTROL_FLAG_NONE, | 5029 CONTROL_FLAG_NONE, |
| 5324 1)); | 5030 1)); |
| 5325 | 5031 |
| 5326 scoped_ptr<SpdyHeaderBlock> middle_headers(new SpdyHeaderBlock()); | 5032 scoped_ptr<SpdyHeaderBlock> middle_headers(new SpdyHeaderBlock()); |
| 5327 (*middle_headers)["hello"] = "bye"; | 5033 (*middle_headers)["hello"] = "bye"; |
| 5328 scoped_ptr<SpdyFrame> stream2_headers1( | 5034 scoped_ptr<SpdyFrame> stream2_headers1(spdy_util_.ConstructSpdyControlFrame( |
| 5329 spdy_util_.ConstructSpdyControlFrame(middle_headers.Pass(), | 5035 middle_headers.Pass(), false, 2, LOWEST, HEADERS, CONTROL_FLAG_NONE, 0)); |
| 5330 false, | |
| 5331 2, | |
| 5332 LOWEST, | |
| 5333 HEADERS, | |
| 5334 CONTROL_FLAG_NONE, | |
| 5335 0)); | |
| 5336 | 5036 |
| 5337 scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); | 5037 scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5338 (*late_headers)[spdy_util_.GetStatusKey()] = "200"; | 5038 (*late_headers)[spdy_util_.GetStatusKey()] = "200"; |
| 5339 if (spdy_util_.spdy_version() < SPDY4) { | 5039 if (spdy_util_.spdy_version() < SPDY4) { |
| 5340 // SPDY4/HTTP2 eliminates use of the :version header. | 5040 // SPDY4/HTTP2 eliminates use of the :version header. |
| 5341 (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | 5041 (*late_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
| 5342 } | 5042 } |
| 5343 scoped_ptr<SpdyFrame> stream2_headers2( | 5043 scoped_ptr<SpdyFrame> stream2_headers2(spdy_util_.ConstructSpdyControlFrame( |
| 5344 spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), | 5044 late_headers.Pass(), false, 2, LOWEST, HEADERS, CONTROL_FLAG_NONE, 0)); |
| 5345 false, | |
| 5346 2, | |
| 5347 LOWEST, | |
| 5348 HEADERS, | |
| 5349 CONTROL_FLAG_NONE, | |
| 5350 0)); | |
| 5351 | 5045 |
| 5352 scoped_ptr<SpdyFrame> | 5046 scoped_ptr<SpdyFrame> stream1_reply( |
| 5353 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 5047 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 5354 const char kPushedData[] = "pushed"; | 5048 const char kPushedData[] = "pushed"; |
| 5355 scoped_ptr<SpdyFrame> stream2_body( | 5049 scoped_ptr<SpdyFrame> stream2_body(spdy_util_.ConstructSpdyBodyFrame( |
| 5356 spdy_util_.ConstructSpdyBodyFrame( | 5050 2, kPushedData, strlen(kPushedData), true)); |
| 5357 2, kPushedData, strlen(kPushedData), true)); | |
| 5358 MockRead reads[] = { | 5051 MockRead reads[] = { |
| 5359 CreateMockRead(*stream1_reply, 1), | 5052 CreateMockRead(*stream1_reply, 1), |
| 5360 CreateMockRead(*stream2_syn, 2), | 5053 CreateMockRead(*stream2_syn, 2), |
| 5361 CreateMockRead(*stream1_body, 3), | 5054 CreateMockRead(*stream1_body, 3), |
| 5362 CreateMockRead(*stream2_headers1, 4), | 5055 CreateMockRead(*stream2_headers1, 4), |
| 5363 CreateMockRead(*stream2_headers2, 5), | 5056 CreateMockRead(*stream2_headers2, 5), |
| 5364 CreateMockRead(*stream2_body, 6), | 5057 CreateMockRead(*stream2_body, 6), |
| 5365 MockRead(ASYNC, 0, 7), // EOF | 5058 MockRead(ASYNC, 0, 7), // EOF |
| 5366 }; | 5059 }; |
| 5367 | 5060 |
| 5368 HttpResponseInfo response; | 5061 HttpResponseInfo response; |
| 5369 HttpResponseInfo response2; | 5062 HttpResponseInfo response2; |
| 5370 std::string expected_push_result("pushed"); | 5063 std::string expected_push_result("pushed"); |
| 5371 DeterministicSocketData data(reads, arraysize(reads), | 5064 DeterministicSocketData data( |
| 5372 writes, arraysize(writes)); | 5065 reads, arraysize(reads), writes, arraysize(writes)); |
| 5373 | 5066 |
| 5374 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 5067 NormalSpdyTransactionHelper helper( |
| 5375 BoundNetLog(), GetParam(), NULL); | 5068 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 5376 helper.SetDeterministic(); | 5069 helper.SetDeterministic(); |
| 5377 helper.AddDeterministicData(&data); | 5070 helper.AddDeterministicData(&data); |
| 5378 helper.RunPreTestSetup(); | 5071 helper.RunPreTestSetup(); |
| 5379 | 5072 |
| 5380 HttpNetworkTransaction* trans = helper.trans(); | 5073 HttpNetworkTransaction* trans = helper.trans(); |
| 5381 | 5074 |
| 5382 // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM, | 5075 // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM, |
| 5383 // the first HEADERS frame, and the body of the primary stream, but before | 5076 // the first HEADERS frame, and the body of the primary stream, but before |
| 5384 // we've received the final HEADERS for the pushed stream. | 5077 // we've received the final HEADERS for the pushed stream. |
| 5385 data.SetStop(4); | 5078 data.SetStop(4); |
| 5386 | 5079 |
| 5387 // Start the transaction. | 5080 // Start the transaction. |
| 5388 TestCompletionCallback callback; | 5081 TestCompletionCallback callback; |
| 5389 int rv = trans->Start( | 5082 int rv = |
| 5390 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 5083 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 5391 EXPECT_EQ(ERR_IO_PENDING, rv); | 5084 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5392 data.Run(); | 5085 data.Run(); |
| 5393 rv = callback.WaitForResult(); | 5086 rv = callback.WaitForResult(); |
| 5394 EXPECT_EQ(0, rv); | 5087 EXPECT_EQ(0, rv); |
| 5395 | 5088 |
| 5396 // Request the pushed path. At this point, we've received the push, but the | 5089 // Request the pushed path. At this point, we've received the push, but the |
| 5397 // headers are not yet complete. | 5090 // headers are not yet complete. |
| 5398 scoped_ptr<HttpNetworkTransaction> trans2( | 5091 scoped_ptr<HttpNetworkTransaction> trans2( |
| 5399 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); | 5092 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
| 5400 rv = trans2->Start( | 5093 rv = trans2->Start( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 5424 EXPECT_TRUE(response.headers.get() != NULL); | 5117 EXPECT_TRUE(response.headers.get() != NULL); |
| 5425 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 5118 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5426 | 5119 |
| 5427 // Verify the pushed stream. | 5120 // Verify the pushed stream. |
| 5428 EXPECT_TRUE(response2.headers.get() != NULL); | 5121 EXPECT_TRUE(response2.headers.get() != NULL); |
| 5429 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); | 5122 EXPECT_EQ("HTTP/1.1 200 OK", response2.headers->GetStatusLine()); |
| 5430 | 5123 |
| 5431 // Verify we got all the headers | 5124 // Verify we got all the headers |
| 5432 if (spdy_util_.spdy_version() < SPDY3) { | 5125 if (spdy_util_.spdy_version() < SPDY3) { |
| 5433 EXPECT_TRUE(response2.headers->HasHeaderValue( | 5126 EXPECT_TRUE(response2.headers->HasHeaderValue( |
| 5434 "url", | 5127 "url", "http://www.google.com/foo.dat")); |
| 5435 "http://www.google.com/foo.dat")); | |
| 5436 } else { | 5128 } else { |
| 5437 EXPECT_TRUE(response2.headers->HasHeaderValue( | 5129 EXPECT_TRUE(response2.headers->HasHeaderValue("scheme", "http")); |
| 5438 "scheme", "http")); | 5130 EXPECT_TRUE(response2.headers->HasHeaderValue("path", "/foo.dat")); |
| 5439 EXPECT_TRUE(response2.headers->HasHeaderValue( | |
| 5440 "path", "/foo.dat")); | |
| 5441 if (spdy_util_.spdy_version() < SPDY4) { | 5131 if (spdy_util_.spdy_version() < SPDY4) { |
| 5442 EXPECT_TRUE(response2.headers->HasHeaderValue( | 5132 EXPECT_TRUE(response2.headers->HasHeaderValue("host", "www.google.com")); |
| 5443 "host", "www.google.com")); | |
| 5444 } else { | 5133 } else { |
| 5445 EXPECT_TRUE(response2.headers->HasHeaderValue( | 5134 EXPECT_TRUE( |
| 5446 "authority", "www.google.com")); | 5135 response2.headers->HasHeaderValue("authority", "www.google.com")); |
| 5447 } | 5136 } |
| 5448 } | 5137 } |
| 5449 EXPECT_TRUE(response2.headers->HasHeaderValue("hello", "bye")); | 5138 EXPECT_TRUE(response2.headers->HasHeaderValue("hello", "bye")); |
| 5450 EXPECT_TRUE(response2.headers->HasHeaderValue("status", "200")); | 5139 EXPECT_TRUE(response2.headers->HasHeaderValue("status", "200")); |
| 5451 | 5140 |
| 5452 // Read the final EOF (which will close the session) | 5141 // Read the final EOF (which will close the session) |
| 5453 data.RunFor(1); | 5142 data.RunFor(1); |
| 5454 | 5143 |
| 5455 // Verify that we consumed all test data. | 5144 // Verify that we consumed all test data. |
| 5456 EXPECT_TRUE(data.at_read_eof()); | 5145 EXPECT_TRUE(data.at_read_eof()); |
| 5457 EXPECT_TRUE(data.at_write_eof()); | 5146 EXPECT_TRUE(data.at_write_eof()); |
| 5458 } | 5147 } |
| 5459 | 5148 |
| 5460 TEST_P(SpdyNetworkTransactionTest, ServerPushWithNoStatusHeaderFrames) { | 5149 TEST_P(SpdyNetworkTransactionTest, ServerPushWithNoStatusHeaderFrames) { |
| 5461 // We push a stream and attempt to claim it before the headers come down. | 5150 // We push a stream and attempt to claim it before the headers come down. |
| 5462 scoped_ptr<SpdyFrame> stream1_syn( | 5151 scoped_ptr<SpdyFrame> stream1_syn( |
| 5463 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 5152 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5464 scoped_ptr<SpdyFrame> stream1_body( | 5153 scoped_ptr<SpdyFrame> stream1_body( |
| 5465 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 5154 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 5466 MockWrite writes[] = { | 5155 MockWrite writes[] = { |
| 5467 CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), | 5156 CreateMockWrite(*stream1_syn, 0, SYNCHRONOUS), |
| 5468 }; | 5157 }; |
| 5469 | 5158 |
| 5470 scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); | 5159 scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
| 5471 spdy_util_.AddUrlToHeaderBlock( | 5160 spdy_util_.AddUrlToHeaderBlock("http://www.google.com/foo.dat", |
| 5472 "http://www.google.com/foo.dat", initial_headers.get()); | 5161 initial_headers.get()); |
| 5473 scoped_ptr<SpdyFrame> stream2_syn( | 5162 scoped_ptr<SpdyFrame> stream2_syn( |
| 5474 spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), | 5163 spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), |
| 5475 false, | 5164 false, |
| 5476 2, | 5165 2, |
| 5477 LOWEST, | 5166 LOWEST, |
| 5478 SYN_STREAM, | 5167 SYN_STREAM, |
| 5479 CONTROL_FLAG_NONE, | 5168 CONTROL_FLAG_NONE, |
| 5480 1)); | 5169 1)); |
| 5481 | 5170 |
| 5482 scoped_ptr<SpdyHeaderBlock> middle_headers(new SpdyHeaderBlock()); | 5171 scoped_ptr<SpdyHeaderBlock> middle_headers(new SpdyHeaderBlock()); |
| 5483 (*middle_headers)["hello"] = "bye"; | 5172 (*middle_headers)["hello"] = "bye"; |
| 5484 scoped_ptr<SpdyFrame> stream2_headers1( | 5173 scoped_ptr<SpdyFrame> stream2_headers1(spdy_util_.ConstructSpdyControlFrame( |
| 5485 spdy_util_.ConstructSpdyControlFrame(middle_headers.Pass(), | 5174 middle_headers.Pass(), false, 2, LOWEST, HEADERS, CONTROL_FLAG_NONE, 0)); |
| 5486 false, | |
| 5487 2, | |
| 5488 LOWEST, | |
| 5489 HEADERS, | |
| 5490 CONTROL_FLAG_NONE, | |
| 5491 0)); | |
| 5492 | 5175 |
| 5493 scoped_ptr<SpdyFrame> | 5176 scoped_ptr<SpdyFrame> stream1_reply( |
| 5494 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 5177 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 5495 const char kPushedData[] = "pushed"; | 5178 const char kPushedData[] = "pushed"; |
| 5496 scoped_ptr<SpdyFrame> stream2_body( | 5179 scoped_ptr<SpdyFrame> stream2_body(spdy_util_.ConstructSpdyBodyFrame( |
| 5497 spdy_util_.ConstructSpdyBodyFrame( | 5180 2, kPushedData, strlen(kPushedData), true)); |
| 5498 2, kPushedData, strlen(kPushedData), true)); | |
| 5499 MockRead reads[] = { | 5181 MockRead reads[] = { |
| 5500 CreateMockRead(*stream1_reply, 1), | 5182 CreateMockRead(*stream1_reply, 1), CreateMockRead(*stream2_syn, 2), |
| 5501 CreateMockRead(*stream2_syn, 2), | 5183 CreateMockRead(*stream1_body, 3), CreateMockRead(*stream2_headers1, 4), |
| 5502 CreateMockRead(*stream1_body, 3), | 5184 CreateMockRead(*stream2_body, 5), MockRead(ASYNC, 0, 6), // EOF |
| 5503 CreateMockRead(*stream2_headers1, 4), | |
| 5504 CreateMockRead(*stream2_body, 5), | |
| 5505 MockRead(ASYNC, 0, 6), // EOF | |
| 5506 }; | 5185 }; |
| 5507 | 5186 |
| 5508 DeterministicSocketData data(reads, arraysize(reads), | 5187 DeterministicSocketData data( |
| 5509 writes, arraysize(writes)); | 5188 reads, arraysize(reads), writes, arraysize(writes)); |
| 5510 | 5189 |
| 5511 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 5190 NormalSpdyTransactionHelper helper( |
| 5512 BoundNetLog(), GetParam(), NULL); | 5191 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 5513 helper.SetDeterministic(); | 5192 helper.SetDeterministic(); |
| 5514 helper.AddDeterministicData(&data); | 5193 helper.AddDeterministicData(&data); |
| 5515 helper.RunPreTestSetup(); | 5194 helper.RunPreTestSetup(); |
| 5516 | 5195 |
| 5517 HttpNetworkTransaction* trans = helper.trans(); | 5196 HttpNetworkTransaction* trans = helper.trans(); |
| 5518 | 5197 |
| 5519 // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM, | 5198 // Run until we've received the primary SYN_STREAM, the pushed SYN_STREAM, |
| 5520 // the first HEADERS frame, and the body of the primary stream, but before | 5199 // the first HEADERS frame, and the body of the primary stream, but before |
| 5521 // we've received the final HEADERS for the pushed stream. | 5200 // we've received the final HEADERS for the pushed stream. |
| 5522 data.SetStop(4); | 5201 data.SetStop(4); |
| 5523 | 5202 |
| 5524 // Start the transaction. | 5203 // Start the transaction. |
| 5525 TestCompletionCallback callback; | 5204 TestCompletionCallback callback; |
| 5526 int rv = trans->Start( | 5205 int rv = |
| 5527 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 5206 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 5528 EXPECT_EQ(ERR_IO_PENDING, rv); | 5207 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5529 data.Run(); | 5208 data.Run(); |
| 5530 rv = callback.WaitForResult(); | 5209 rv = callback.WaitForResult(); |
| 5531 EXPECT_EQ(0, rv); | 5210 EXPECT_EQ(0, rv); |
| 5532 | 5211 |
| 5533 // Request the pushed path. At this point, we've received the push, but the | 5212 // Request the pushed path. At this point, we've received the push, but the |
| 5534 // headers are not yet complete. | 5213 // headers are not yet complete. |
| 5535 scoped_ptr<HttpNetworkTransaction> trans2( | 5214 scoped_ptr<HttpNetworkTransaction> trans2( |
| 5536 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); | 5215 new HttpNetworkTransaction(DEFAULT_PRIORITY, helper.session().get())); |
| 5537 rv = trans2->Start( | 5216 rv = trans2->Start( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5569 EXPECT_TRUE(data.at_read_eof()); | 5248 EXPECT_TRUE(data.at_read_eof()); |
| 5570 EXPECT_TRUE(data.at_write_eof()); | 5249 EXPECT_TRUE(data.at_write_eof()); |
| 5571 } | 5250 } |
| 5572 | 5251 |
| 5573 TEST_P(SpdyNetworkTransactionTest, SynReplyWithHeaders) { | 5252 TEST_P(SpdyNetworkTransactionTest, SynReplyWithHeaders) { |
| 5574 scoped_ptr<SpdyFrame> req( | 5253 scoped_ptr<SpdyFrame> req( |
| 5575 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 5254 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5576 scoped_ptr<SpdyFrame> rst( | 5255 scoped_ptr<SpdyFrame> rst( |
| 5577 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); | 5256 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 5578 MockWrite writes[] = { | 5257 MockWrite writes[] = { |
| 5579 CreateMockWrite(*req), | 5258 CreateMockWrite(*req), CreateMockWrite(*rst), |
| 5580 CreateMockWrite(*rst), | 5259 }; |
| 5581 }; | |
| 5582 | 5260 |
| 5583 scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); | 5261 scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
| 5584 (*initial_headers)[spdy_util_.GetStatusKey()] = "200 OK"; | 5262 (*initial_headers)[spdy_util_.GetStatusKey()] = "200 OK"; |
| 5585 (*initial_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | 5263 (*initial_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
| 5586 scoped_ptr<SpdyFrame> stream1_reply( | 5264 scoped_ptr<SpdyFrame> stream1_reply( |
| 5587 spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), | 5265 spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), |
| 5588 false, | 5266 false, |
| 5589 1, | 5267 1, |
| 5590 LOWEST, | 5268 LOWEST, |
| 5591 SYN_REPLY, | 5269 SYN_REPLY, |
| 5592 CONTROL_FLAG_NONE, | 5270 CONTROL_FLAG_NONE, |
| 5593 0)); | 5271 0)); |
| 5594 | 5272 |
| 5595 scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); | 5273 scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5596 (*late_headers)["hello"] = "bye"; | 5274 (*late_headers)["hello"] = "bye"; |
| 5597 scoped_ptr<SpdyFrame> stream1_headers( | 5275 scoped_ptr<SpdyFrame> stream1_headers(spdy_util_.ConstructSpdyControlFrame( |
| 5598 spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), | 5276 late_headers.Pass(), false, 1, LOWEST, HEADERS, CONTROL_FLAG_NONE, 0)); |
| 5599 false, | |
| 5600 1, | |
| 5601 LOWEST, | |
| 5602 HEADERS, | |
| 5603 CONTROL_FLAG_NONE, | |
| 5604 0)); | |
| 5605 scoped_ptr<SpdyFrame> stream1_body( | 5277 scoped_ptr<SpdyFrame> stream1_body( |
| 5606 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 5278 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 5607 MockRead reads[] = { | 5279 MockRead reads[] = { |
| 5608 CreateMockRead(*stream1_reply), | 5280 CreateMockRead(*stream1_reply), CreateMockRead(*stream1_headers), |
| 5609 CreateMockRead(*stream1_headers), | 5281 CreateMockRead(*stream1_body), MockRead(ASYNC, 0, 0) // EOF |
| 5610 CreateMockRead(*stream1_body), | |
| 5611 MockRead(ASYNC, 0, 0) // EOF | |
| 5612 }; | 5282 }; |
| 5613 | 5283 |
| 5614 DelayedSocketData data(1, reads, arraysize(reads), | 5284 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 5615 writes, arraysize(writes)); | 5285 NormalSpdyTransactionHelper helper( |
| 5616 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 5286 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 5617 BoundNetLog(), GetParam(), NULL); | |
| 5618 helper.RunToCompletion(&data); | 5287 helper.RunToCompletion(&data); |
| 5619 TransactionHelperResult out = helper.output(); | 5288 TransactionHelperResult out = helper.output(); |
| 5620 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); | 5289 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 5621 } | 5290 } |
| 5622 | 5291 |
| 5623 TEST_P(SpdyNetworkTransactionTest, SynReplyWithLateHeaders) { | 5292 TEST_P(SpdyNetworkTransactionTest, SynReplyWithLateHeaders) { |
| 5624 scoped_ptr<SpdyFrame> req( | 5293 scoped_ptr<SpdyFrame> req( |
| 5625 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 5294 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5626 scoped_ptr<SpdyFrame> rst( | 5295 scoped_ptr<SpdyFrame> rst( |
| 5627 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); | 5296 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_PROTOCOL_ERROR)); |
| 5628 MockWrite writes[] = { | 5297 MockWrite writes[] = { |
| 5629 CreateMockWrite(*req), | 5298 CreateMockWrite(*req), CreateMockWrite(*rst), |
| 5630 CreateMockWrite(*rst), | |
| 5631 }; | 5299 }; |
| 5632 | 5300 |
| 5633 scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); | 5301 scoped_ptr<SpdyHeaderBlock> initial_headers(new SpdyHeaderBlock()); |
| 5634 (*initial_headers)[spdy_util_.GetStatusKey()] = "200 OK"; | 5302 (*initial_headers)[spdy_util_.GetStatusKey()] = "200 OK"; |
| 5635 (*initial_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; | 5303 (*initial_headers)[spdy_util_.GetVersionKey()] = "HTTP/1.1"; |
| 5636 scoped_ptr<SpdyFrame> stream1_reply( | 5304 scoped_ptr<SpdyFrame> stream1_reply( |
| 5637 spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), | 5305 spdy_util_.ConstructSpdyControlFrame(initial_headers.Pass(), |
| 5638 false, | 5306 false, |
| 5639 1, | 5307 1, |
| 5640 LOWEST, | 5308 LOWEST, |
| 5641 SYN_REPLY, | 5309 SYN_REPLY, |
| 5642 CONTROL_FLAG_NONE, | 5310 CONTROL_FLAG_NONE, |
| 5643 0)); | 5311 0)); |
| 5644 | 5312 |
| 5645 scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); | 5313 scoped_ptr<SpdyHeaderBlock> late_headers(new SpdyHeaderBlock()); |
| 5646 (*late_headers)["hello"] = "bye"; | 5314 (*late_headers)["hello"] = "bye"; |
| 5647 scoped_ptr<SpdyFrame> stream1_headers( | 5315 scoped_ptr<SpdyFrame> stream1_headers(spdy_util_.ConstructSpdyControlFrame( |
| 5648 spdy_util_.ConstructSpdyControlFrame(late_headers.Pass(), | 5316 late_headers.Pass(), false, 1, LOWEST, HEADERS, CONTROL_FLAG_NONE, 0)); |
| 5649 false, | |
| 5650 1, | |
| 5651 LOWEST, | |
| 5652 HEADERS, | |
| 5653 CONTROL_FLAG_NONE, | |
| 5654 0)); | |
| 5655 scoped_ptr<SpdyFrame> stream1_body( | 5317 scoped_ptr<SpdyFrame> stream1_body( |
| 5656 spdy_util_.ConstructSpdyBodyFrame(1, false)); | 5318 spdy_util_.ConstructSpdyBodyFrame(1, false)); |
| 5657 scoped_ptr<SpdyFrame> stream1_body2( | 5319 scoped_ptr<SpdyFrame> stream1_body2( |
| 5658 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 5320 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 5659 MockRead reads[] = { | 5321 MockRead reads[] = { |
| 5660 CreateMockRead(*stream1_reply), | 5322 CreateMockRead(*stream1_reply), CreateMockRead(*stream1_body), |
| 5661 CreateMockRead(*stream1_body), | 5323 CreateMockRead(*stream1_headers), CreateMockRead(*stream1_body2), |
| 5662 CreateMockRead(*stream1_headers), | 5324 MockRead(ASYNC, 0, 0) // EOF |
| 5663 CreateMockRead(*stream1_body2), | |
| 5664 MockRead(ASYNC, 0, 0) // EOF | |
| 5665 }; | 5325 }; |
| 5666 | 5326 |
| 5667 DelayedSocketData data(1, reads, arraysize(reads), | 5327 DelayedSocketData data(1, reads, arraysize(reads), writes, arraysize(writes)); |
| 5668 writes, arraysize(writes)); | 5328 NormalSpdyTransactionHelper helper( |
| 5669 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 5329 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 5670 BoundNetLog(), GetParam(), NULL); | |
| 5671 helper.RunToCompletion(&data); | 5330 helper.RunToCompletion(&data); |
| 5672 TransactionHelperResult out = helper.output(); | 5331 TransactionHelperResult out = helper.output(); |
| 5673 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); | 5332 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); |
| 5674 } | 5333 } |
| 5675 | 5334 |
| 5676 TEST_P(SpdyNetworkTransactionTest, ServerPushCrossOriginCorrectness) { | 5335 TEST_P(SpdyNetworkTransactionTest, ServerPushCrossOriginCorrectness) { |
| 5677 if (spdy_util_.spdy_version() == SPDY4) { | 5336 if (spdy_util_.spdy_version() == SPDY4) { |
| 5678 // TODO(jgraettinger): We don't support associated stream | 5337 // TODO(jgraettinger): We don't support associated stream |
| 5679 // checks in SPDY4 yet. | 5338 // checks in SPDY4 yet. |
| 5680 return; | 5339 return; |
| 5681 } | 5340 } |
| 5682 // In this test we want to verify that we can't accidentally push content | 5341 // In this test we want to verify that we can't accidentally push content |
| 5683 // which can't be pushed by this content server. | 5342 // which can't be pushed by this content server. |
| 5684 // This test assumes that: | 5343 // This test assumes that: |
| 5685 // - if we're requesting http://www.foo.com/barbaz | 5344 // - if we're requesting http://www.foo.com/barbaz |
| 5686 // - the browser has made a connection to "www.foo.com". | 5345 // - the browser has made a connection to "www.foo.com". |
| 5687 | 5346 |
| 5688 // A list of the URL to fetch, followed by the URL being pushed. | 5347 // A list of the URL to fetch, followed by the URL being pushed. |
| 5689 static const char* const kTestCases[] = { | 5348 static const char* const kTestCases[] = { |
| 5690 "http://www.google.com/foo.html", | 5349 "http://www.google.com/foo.html", |
| 5691 "http://www.google.com:81/foo.js", // Bad port | 5350 "http://www.google.com:81/foo.js", // Bad port |
| 5692 | 5351 "http://www.google.com/foo.html", |
| 5693 "http://www.google.com/foo.html", | 5352 "https://www.google.com/foo.js", // Bad protocol |
| 5694 "https://www.google.com/foo.js", // Bad protocol | 5353 "http://www.google.com/foo.html", |
| 5695 | 5354 "ftp://www.google.com/foo.js", // Invalid Protocol |
| 5696 "http://www.google.com/foo.html", | 5355 "http://www.google.com/foo.html", |
| 5697 "ftp://www.google.com/foo.js", // Invalid Protocol | 5356 "http://blat.www.google.com/foo.js", // Cross subdomain |
| 5698 | 5357 "http://www.google.com/foo.html", |
| 5699 "http://www.google.com/foo.html", | 5358 "http://www.foo.com/foo.js", // Cross domain |
| 5700 "http://blat.www.google.com/foo.js", // Cross subdomain | |
| 5701 | |
| 5702 "http://www.google.com/foo.html", | |
| 5703 "http://www.foo.com/foo.js", // Cross domain | |
| 5704 }; | 5359 }; |
| 5705 | 5360 |
| 5706 for (size_t index = 0; index < arraysize(kTestCases); index += 2) { | 5361 for (size_t index = 0; index < arraysize(kTestCases); index += 2) { |
| 5707 const char* url_to_fetch = kTestCases[index]; | 5362 const char* url_to_fetch = kTestCases[index]; |
| 5708 const char* url_to_push = kTestCases[index + 1]; | 5363 const char* url_to_push = kTestCases[index + 1]; |
| 5709 | 5364 |
| 5710 scoped_ptr<SpdyFrame> stream1_syn( | 5365 scoped_ptr<SpdyFrame> stream1_syn( |
| 5711 spdy_util_.ConstructSpdyGet(url_to_fetch, false, 1, LOWEST)); | 5366 spdy_util_.ConstructSpdyGet(url_to_fetch, false, 1, LOWEST)); |
| 5712 scoped_ptr<SpdyFrame> stream1_body( | 5367 scoped_ptr<SpdyFrame> stream1_body( |
| 5713 spdy_util_.ConstructSpdyBodyFrame(1, true)); | 5368 spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 5714 scoped_ptr<SpdyFrame> push_rst( | 5369 scoped_ptr<SpdyFrame> push_rst( |
| 5715 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); | 5370 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_REFUSED_STREAM)); |
| 5716 MockWrite writes[] = { | 5371 MockWrite writes[] = { |
| 5717 CreateMockWrite(*stream1_syn, 1), | 5372 CreateMockWrite(*stream1_syn, 1), CreateMockWrite(*push_rst, 4), |
| 5718 CreateMockWrite(*push_rst, 4), | |
| 5719 }; | 5373 }; |
| 5720 | 5374 |
| 5721 scoped_ptr<SpdyFrame> | 5375 scoped_ptr<SpdyFrame> stream1_reply( |
| 5722 stream1_reply(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 5376 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 5723 scoped_ptr<SpdyFrame> | 5377 scoped_ptr<SpdyFrame> stream2_syn( |
| 5724 stream2_syn(spdy_util_.ConstructSpdyPush(NULL, | 5378 spdy_util_.ConstructSpdyPush(NULL, 0, 2, 1, url_to_push)); |
| 5725 0, | |
| 5726 2, | |
| 5727 1, | |
| 5728 url_to_push)); | |
| 5729 const char kPushedData[] = "pushed"; | 5379 const char kPushedData[] = "pushed"; |
| 5730 scoped_ptr<SpdyFrame> stream2_body( | 5380 scoped_ptr<SpdyFrame> stream2_body(spdy_util_.ConstructSpdyBodyFrame( |
| 5731 spdy_util_.ConstructSpdyBodyFrame( | 5381 2, kPushedData, strlen(kPushedData), true)); |
| 5732 2, kPushedData, strlen(kPushedData), true)); | |
| 5733 scoped_ptr<SpdyFrame> rst( | 5382 scoped_ptr<SpdyFrame> rst( |
| 5734 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_CANCEL)); | 5383 spdy_util_.ConstructSpdyRstStream(2, RST_STREAM_CANCEL)); |
| 5735 | 5384 |
| 5736 MockRead reads[] = { | 5385 MockRead reads[] = { |
| 5737 CreateMockRead(*stream1_reply, 2), | 5386 CreateMockRead(*stream1_reply, 2), |
| 5738 CreateMockRead(*stream2_syn, 3), | 5387 CreateMockRead(*stream2_syn, 3), |
| 5739 CreateMockRead(*stream1_body, 5, SYNCHRONOUS), | 5388 CreateMockRead(*stream1_body, 5, SYNCHRONOUS), |
| 5740 CreateMockRead(*stream2_body, 6), | 5389 CreateMockRead(*stream2_body, 6), |
| 5741 MockRead(ASYNC, ERR_IO_PENDING, 7), // Force a pause | 5390 MockRead(ASYNC, ERR_IO_PENDING, 7), // Force a pause |
| 5742 }; | 5391 }; |
| 5743 | 5392 |
| 5744 HttpResponseInfo response; | 5393 HttpResponseInfo response; |
| 5745 OrderedSocketData data(reads, arraysize(reads), | 5394 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 5746 writes, arraysize(writes)); | |
| 5747 | 5395 |
| 5748 HttpRequestInfo request; | 5396 HttpRequestInfo request; |
| 5749 request.method = "GET"; | 5397 request.method = "GET"; |
| 5750 request.url = GURL(url_to_fetch); | 5398 request.url = GURL(url_to_fetch); |
| 5751 request.load_flags = 0; | 5399 request.load_flags = 0; |
| 5752 | 5400 |
| 5753 // Enable cross-origin push. Since we are not using a proxy, this should | 5401 // Enable cross-origin push. Since we are not using a proxy, this should |
| 5754 // not actually enable cross-origin SPDY push. | 5402 // not actually enable cross-origin SPDY push. |
| 5755 scoped_ptr<SpdySessionDependencies> session_deps( | 5403 scoped_ptr<SpdySessionDependencies> session_deps( |
| 5756 CreateSpdySessionDependencies(GetParam())); | 5404 CreateSpdySessionDependencies(GetParam())); |
| 5757 session_deps->trusted_spdy_proxy = "123.45.67.89:8080"; | 5405 session_deps->trusted_spdy_proxy = "123.45.67.89:8080"; |
| 5758 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, | 5406 NormalSpdyTransactionHelper helper(request, |
| 5759 BoundNetLog(), GetParam(), | 5407 DEFAULT_PRIORITY, |
| 5408 BoundNetLog(), |
| 5409 GetParam(), |
| 5760 session_deps.release()); | 5410 session_deps.release()); |
| 5761 helper.RunPreTestSetup(); | 5411 helper.RunPreTestSetup(); |
| 5762 helper.AddData(&data); | 5412 helper.AddData(&data); |
| 5763 | 5413 |
| 5764 HttpNetworkTransaction* trans = helper.trans(); | 5414 HttpNetworkTransaction* trans = helper.trans(); |
| 5765 | 5415 |
| 5766 // Start the transaction with basic parameters. | 5416 // Start the transaction with basic parameters. |
| 5767 TestCompletionCallback callback; | 5417 TestCompletionCallback callback; |
| 5768 | 5418 |
| 5769 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 5419 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 5790 } | 5440 } |
| 5791 } | 5441 } |
| 5792 | 5442 |
| 5793 TEST_P(SpdyNetworkTransactionTest, RetryAfterRefused) { | 5443 TEST_P(SpdyNetworkTransactionTest, RetryAfterRefused) { |
| 5794 // Construct the request. | 5444 // Construct the request. |
| 5795 scoped_ptr<SpdyFrame> req( | 5445 scoped_ptr<SpdyFrame> req( |
| 5796 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 5446 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5797 scoped_ptr<SpdyFrame> req2( | 5447 scoped_ptr<SpdyFrame> req2( |
| 5798 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); | 5448 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, LOWEST, true)); |
| 5799 MockWrite writes[] = { | 5449 MockWrite writes[] = { |
| 5800 CreateMockWrite(*req, 1), | 5450 CreateMockWrite(*req, 1), CreateMockWrite(*req2, 3), |
| 5801 CreateMockWrite(*req2, 3), | |
| 5802 }; | 5451 }; |
| 5803 | 5452 |
| 5804 scoped_ptr<SpdyFrame> refused( | 5453 scoped_ptr<SpdyFrame> refused( |
| 5805 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_REFUSED_STREAM)); | 5454 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_REFUSED_STREAM)); |
| 5806 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); | 5455 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 5807 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(3, true)); | 5456 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 5808 MockRead reads[] = { | 5457 MockRead reads[] = { |
| 5809 CreateMockRead(*refused, 2), | 5458 CreateMockRead(*refused, 2), CreateMockRead(*resp, 4), |
| 5810 CreateMockRead(*resp, 4), | 5459 CreateMockRead(*body, 5), MockRead(ASYNC, 0, 6) // EOF |
| 5811 CreateMockRead(*body, 5), | |
| 5812 MockRead(ASYNC, 0, 6) // EOF | |
| 5813 }; | 5460 }; |
| 5814 | 5461 |
| 5815 OrderedSocketData data(reads, arraysize(reads), | 5462 OrderedSocketData data(reads, arraysize(reads), writes, arraysize(writes)); |
| 5816 writes, arraysize(writes)); | 5463 NormalSpdyTransactionHelper helper( |
| 5817 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 5464 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 5818 BoundNetLog(), GetParam(), NULL); | |
| 5819 | 5465 |
| 5820 helper.RunPreTestSetup(); | 5466 helper.RunPreTestSetup(); |
| 5821 helper.AddData(&data); | 5467 helper.AddData(&data); |
| 5822 | 5468 |
| 5823 HttpNetworkTransaction* trans = helper.trans(); | 5469 HttpNetworkTransaction* trans = helper.trans(); |
| 5824 | 5470 |
| 5825 // Start the transaction with basic parameters. | 5471 // Start the transaction with basic parameters. |
| 5826 TestCompletionCallback callback; | 5472 TestCompletionCallback callback; |
| 5827 int rv = trans->Start( | 5473 int rv = |
| 5828 &CreateGetRequest(), callback.callback(), BoundNetLog()); | 5474 trans->Start(&CreateGetRequest(), callback.callback(), BoundNetLog()); |
| 5829 EXPECT_EQ(ERR_IO_PENDING, rv); | 5475 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 5830 rv = callback.WaitForResult(); | 5476 rv = callback.WaitForResult(); |
| 5831 EXPECT_EQ(OK, rv); | 5477 EXPECT_EQ(OK, rv); |
| 5832 | 5478 |
| 5833 // Verify that we consumed all test data. | 5479 // Verify that we consumed all test data. |
| 5834 EXPECT_TRUE(data.at_read_eof()) << "Read count: " | 5480 EXPECT_TRUE(data.at_read_eof()) << "Read count: " << data.read_count() |
| 5835 << data.read_count() | 5481 << " Read index: " << data.read_index(); |
| 5836 << " Read index: " | 5482 EXPECT_TRUE(data.at_write_eof()) << "Write count: " << data.write_count() |
| 5837 << data.read_index(); | 5483 << " Write index: " << data.write_index(); |
| 5838 EXPECT_TRUE(data.at_write_eof()) << "Write count: " | |
| 5839 << data.write_count() | |
| 5840 << " Write index: " | |
| 5841 << data.write_index(); | |
| 5842 | 5484 |
| 5843 // Verify the SYN_REPLY. | 5485 // Verify the SYN_REPLY. |
| 5844 HttpResponseInfo response = *trans->GetResponseInfo(); | 5486 HttpResponseInfo response = *trans->GetResponseInfo(); |
| 5845 EXPECT_TRUE(response.headers.get() != NULL); | 5487 EXPECT_TRUE(response.headers.get() != NULL); |
| 5846 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 5488 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5847 } | 5489 } |
| 5848 | 5490 |
| 5849 TEST_P(SpdyNetworkTransactionTest, OutOfOrderSynStream) { | 5491 TEST_P(SpdyNetworkTransactionTest, OutOfOrderSynStream) { |
| 5850 // This first request will start to establish the SpdySession. | 5492 // This first request will start to establish the SpdySession. |
| 5851 // Then we will start the second (MEDIUM priority) and then third | 5493 // Then we will start the second (MEDIUM priority) and then third |
| 5852 // (HIGHEST priority) request in such a way that the third will actually | 5494 // (HIGHEST priority) request in such a way that the third will actually |
| 5853 // start before the second, causing the second to be numbered differently | 5495 // start before the second, causing the second to be numbered differently |
| 5854 // than the order they were created. | 5496 // than the order they were created. |
| 5855 scoped_ptr<SpdyFrame> req1( | 5497 scoped_ptr<SpdyFrame> req1( |
| 5856 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); | 5498 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, LOWEST, true)); |
| 5857 scoped_ptr<SpdyFrame> req2( | 5499 scoped_ptr<SpdyFrame> req2( |
| 5858 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, HIGHEST, true)); | 5500 spdy_util_.ConstructSpdyGet(NULL, 0, false, 3, HIGHEST, true)); |
| 5859 scoped_ptr<SpdyFrame> req3( | 5501 scoped_ptr<SpdyFrame> req3( |
| 5860 spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, MEDIUM, true)); | 5502 spdy_util_.ConstructSpdyGet(NULL, 0, false, 5, MEDIUM, true)); |
| 5861 MockWrite writes[] = { | 5503 MockWrite writes[] = { |
| 5862 CreateMockWrite(*req1, 0), | 5504 CreateMockWrite(*req1, 0), CreateMockWrite(*req2, 3), |
| 5863 CreateMockWrite(*req2, 3), | 5505 CreateMockWrite(*req3, 4), |
| 5864 CreateMockWrite(*req3, 4), | |
| 5865 }; | 5506 }; |
| 5866 | 5507 |
| 5867 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | 5508 scoped_ptr<SpdyFrame> resp1(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 5868 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 5509 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 5869 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); | 5510 scoped_ptr<SpdyFrame> resp2(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 5870 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); | 5511 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame(3, true)); |
| 5871 scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); | 5512 scoped_ptr<SpdyFrame> resp3(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 5872 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(5, true)); | 5513 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(5, true)); |
| 5873 MockRead reads[] = { | 5514 MockRead reads[] = { |
| 5874 CreateMockRead(*resp1, 1), | 5515 CreateMockRead(*resp1, 1), CreateMockRead(*body1, 2), |
| 5875 CreateMockRead(*body1, 2), | 5516 CreateMockRead(*resp2, 5), CreateMockRead(*body2, 6), |
| 5876 CreateMockRead(*resp2, 5), | 5517 CreateMockRead(*resp3, 7), CreateMockRead(*body3, 8), |
| 5877 CreateMockRead(*body2, 6), | 5518 MockRead(ASYNC, 0, 9) // EOF |
| 5878 CreateMockRead(*resp3, 7), | |
| 5879 CreateMockRead(*body3, 8), | |
| 5880 MockRead(ASYNC, 0, 9) // EOF | |
| 5881 }; | 5519 }; |
| 5882 | 5520 |
| 5883 DeterministicSocketData data(reads, arraysize(reads), | 5521 DeterministicSocketData data( |
| 5884 writes, arraysize(writes)); | 5522 reads, arraysize(reads), writes, arraysize(writes)); |
| 5885 NormalSpdyTransactionHelper helper(CreateGetRequest(), LOWEST, | 5523 NormalSpdyTransactionHelper helper( |
| 5886 BoundNetLog(), GetParam(), NULL); | 5524 CreateGetRequest(), LOWEST, BoundNetLog(), GetParam(), NULL); |
| 5887 helper.SetDeterministic(); | 5525 helper.SetDeterministic(); |
| 5888 helper.RunPreTestSetup(); | 5526 helper.RunPreTestSetup(); |
| 5889 helper.AddDeterministicData(&data); | 5527 helper.AddDeterministicData(&data); |
| 5890 | 5528 |
| 5891 // Start the first transaction to set up the SpdySession | 5529 // Start the first transaction to set up the SpdySession |
| 5892 HttpNetworkTransaction* trans = helper.trans(); | 5530 HttpNetworkTransaction* trans = helper.trans(); |
| 5893 TestCompletionCallback callback; | 5531 TestCompletionCallback callback; |
| 5894 HttpRequestInfo info1 = CreateGetRequest(); | 5532 HttpRequestInfo info1 = CreateGetRequest(); |
| 5895 int rv = trans->Start(&info1, callback.callback(), BoundNetLog()); | 5533 int rv = trans->Start(&info1, callback.callback(), BoundNetLog()); |
| 5896 EXPECT_EQ(ERR_IO_PENDING, rv); | 5534 EXPECT_EQ(ERR_IO_PENDING, rv); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5953 // TODO(agayev): develop a socket data provider where both, reads and | 5591 // TODO(agayev): develop a socket data provider where both, reads and |
| 5954 // writes are ordered so that writing tests like these are easy and rewrite | 5592 // writes are ordered so that writing tests like these are easy and rewrite |
| 5955 // all these tests using it. Right now we are working around the | 5593 // all these tests using it. Right now we are working around the |
| 5956 // limitations as described above and it's not deterministic, tests may | 5594 // limitations as described above and it's not deterministic, tests may |
| 5957 // fail under specific circumstances. | 5595 // fail under specific circumstances. |
| 5958 TEST_P(SpdyNetworkTransactionTest, WindowUpdateReceived) { | 5596 TEST_P(SpdyNetworkTransactionTest, WindowUpdateReceived) { |
| 5959 if (GetParam().protocol < kProtoSPDY3) | 5597 if (GetParam().protocol < kProtoSPDY3) |
| 5960 return; | 5598 return; |
| 5961 | 5599 |
| 5962 static int kFrameCount = 2; | 5600 static int kFrameCount = 2; |
| 5963 scoped_ptr<std::string> content( | 5601 scoped_ptr<std::string> content(new std::string(kMaxSpdyFrameChunkSize, 'a')); |
| 5964 new std::string(kMaxSpdyFrameChunkSize, 'a')); | |
| 5965 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( | 5602 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 5966 kRequestUrl, 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, NULL, 0)); | 5603 kRequestUrl, 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, NULL, 0)); |
| 5967 scoped_ptr<SpdyFrame> body( | 5604 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame( |
| 5968 spdy_util_.ConstructSpdyBodyFrame( | 5605 1, content->c_str(), content->size(), false)); |
| 5969 1, content->c_str(), content->size(), false)); | 5606 scoped_ptr<SpdyFrame> body_end(spdy_util_.ConstructSpdyBodyFrame( |
| 5970 scoped_ptr<SpdyFrame> body_end( | 5607 1, content->c_str(), content->size(), true)); |
| 5971 spdy_util_.ConstructSpdyBodyFrame( | |
| 5972 1, content->c_str(), content->size(), true)); | |
| 5973 | 5608 |
| 5974 MockWrite writes[] = { | 5609 MockWrite writes[] = { |
| 5975 CreateMockWrite(*req, 0), | 5610 CreateMockWrite(*req, 0), CreateMockWrite(*body, 1), |
| 5976 CreateMockWrite(*body, 1), | 5611 CreateMockWrite(*body_end, 2), |
| 5977 CreateMockWrite(*body_end, 2), | |
| 5978 }; | 5612 }; |
| 5979 | 5613 |
| 5980 static const int32 kDeltaWindowSize = 0xff; | 5614 static const int32 kDeltaWindowSize = 0xff; |
| 5981 static const int kDeltaCount = 4; | 5615 static const int kDeltaCount = 4; |
| 5982 scoped_ptr<SpdyFrame> window_update( | 5616 scoped_ptr<SpdyFrame> window_update( |
| 5983 spdy_util_.ConstructSpdyWindowUpdate(1, kDeltaWindowSize)); | 5617 spdy_util_.ConstructSpdyWindowUpdate(1, kDeltaWindowSize)); |
| 5984 scoped_ptr<SpdyFrame> window_update_dummy( | 5618 scoped_ptr<SpdyFrame> window_update_dummy( |
| 5985 spdy_util_.ConstructSpdyWindowUpdate(2, kDeltaWindowSize)); | 5619 spdy_util_.ConstructSpdyWindowUpdate(2, kDeltaWindowSize)); |
| 5986 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 5620 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 5987 MockRead reads[] = { | 5621 MockRead reads[] = { |
| 5988 CreateMockRead(*window_update_dummy, 3), | 5622 CreateMockRead(*window_update_dummy, 3), |
| 5989 CreateMockRead(*window_update_dummy, 4), | 5623 CreateMockRead(*window_update_dummy, 4), |
| 5990 CreateMockRead(*window_update_dummy, 5), | 5624 CreateMockRead(*window_update_dummy, 5), |
| 5991 CreateMockRead(*window_update, 6), // Four updates, therefore window | 5625 CreateMockRead(*window_update, 6), // Four updates, therefore window |
| 5992 CreateMockRead(*window_update, 7), // size should increase by | 5626 CreateMockRead(*window_update, 7), // size should increase by |
| 5993 CreateMockRead(*window_update, 8), // kDeltaWindowSize * 4 | 5627 CreateMockRead(*window_update, 8), // kDeltaWindowSize * 4 |
| 5994 CreateMockRead(*window_update, 9), | 5628 CreateMockRead(*window_update, 9), CreateMockRead(*resp, 10), |
| 5995 CreateMockRead(*resp, 10), | 5629 CreateMockRead(*body_end, 11), MockRead(ASYNC, 0, 0, 12) // EOF |
| 5996 CreateMockRead(*body_end, 11), | |
| 5997 MockRead(ASYNC, 0, 0, 12) // EOF | |
| 5998 }; | 5630 }; |
| 5999 | 5631 |
| 6000 DeterministicSocketData data(reads, arraysize(reads), | 5632 DeterministicSocketData data( |
| 6001 writes, arraysize(writes)); | 5633 reads, arraysize(reads), writes, arraysize(writes)); |
| 6002 | 5634 |
| 6003 ScopedVector<UploadElementReader> element_readers; | 5635 ScopedVector<UploadElementReader> element_readers; |
| 6004 for (int i = 0; i < kFrameCount; ++i) { | 5636 for (int i = 0; i < kFrameCount; ++i) { |
| 6005 element_readers.push_back( | 5637 element_readers.push_back( |
| 6006 new UploadBytesElementReader(content->c_str(), content->size())); | 5638 new UploadBytesElementReader(content->c_str(), content->size())); |
| 6007 } | 5639 } |
| 6008 UploadDataStream upload_data_stream(element_readers.Pass(), 0); | 5640 UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
| 6009 | 5641 |
| 6010 // Setup the request | 5642 // Setup the request |
| 6011 HttpRequestInfo request; | 5643 HttpRequestInfo request; |
| 6012 request.method = "POST"; | 5644 request.method = "POST"; |
| 6013 request.url = GURL(kDefaultURL); | 5645 request.url = GURL(kDefaultURL); |
| 6014 request.upload_data_stream = &upload_data_stream; | 5646 request.upload_data_stream = &upload_data_stream; |
| 6015 | 5647 |
| 6016 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, | 5648 NormalSpdyTransactionHelper helper( |
| 6017 BoundNetLog(), GetParam(), NULL); | 5649 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 6018 helper.SetDeterministic(); | 5650 helper.SetDeterministic(); |
| 6019 helper.AddDeterministicData(&data); | 5651 helper.AddDeterministicData(&data); |
| 6020 helper.RunPreTestSetup(); | 5652 helper.RunPreTestSetup(); |
| 6021 | 5653 |
| 6022 HttpNetworkTransaction* trans = helper.trans(); | 5654 HttpNetworkTransaction* trans = helper.trans(); |
| 6023 | 5655 |
| 6024 TestCompletionCallback callback; | 5656 TestCompletionCallback callback; |
| 6025 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); | 5657 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6026 | 5658 |
| 6027 EXPECT_EQ(ERR_IO_PENDING, rv); | 5659 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6028 | 5660 |
| 6029 data.RunFor(11); | 5661 data.RunFor(11); |
| 6030 | 5662 |
| 6031 SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); | 5663 SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6032 ASSERT_TRUE(stream != NULL); | 5664 ASSERT_TRUE(stream != NULL); |
| 6033 ASSERT_TRUE(stream->stream() != NULL); | 5665 ASSERT_TRUE(stream->stream() != NULL); |
| 6034 EXPECT_EQ(static_cast<int>(kSpdyStreamInitialWindowSize) + | 5666 EXPECT_EQ(static_cast<int>(kSpdyStreamInitialWindowSize) + |
| 6035 kDeltaWindowSize * kDeltaCount - | 5667 kDeltaWindowSize * kDeltaCount - |
| 6036 kMaxSpdyFrameChunkSize * kFrameCount, | 5668 kMaxSpdyFrameChunkSize * kFrameCount, |
| 6037 stream->stream()->send_window_size()); | 5669 stream->stream()->send_window_size()); |
| 6038 | 5670 |
| 6039 data.RunFor(1); | 5671 data.RunFor(1); |
| 6040 | 5672 |
| 6041 rv = callback.WaitForResult(); | 5673 rv = callback.WaitForResult(); |
| 6042 EXPECT_EQ(OK, rv); | 5674 EXPECT_EQ(OK, rv); |
| 6043 | 5675 |
| 6044 helper.VerifyDataConsumed(); | 5676 helper.VerifyDataConsumed(); |
| 6045 } | 5677 } |
| 6046 | 5678 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 6060 scoped_ptr<SpdyFrame> window_update( | 5692 scoped_ptr<SpdyFrame> window_update( |
| 6061 spdy_util_.ConstructSpdyWindowUpdate(1, kTargetSize)); | 5693 spdy_util_.ConstructSpdyWindowUpdate(1, kTargetSize)); |
| 6062 | 5694 |
| 6063 std::vector<MockWrite> writes; | 5695 std::vector<MockWrite> writes; |
| 6064 writes.push_back(CreateMockWrite(*req)); | 5696 writes.push_back(CreateMockWrite(*req)); |
| 6065 if (GetParam().protocol >= kProtoSPDY31) | 5697 if (GetParam().protocol >= kProtoSPDY31) |
| 6066 writes.push_back(CreateMockWrite(*session_window_update)); | 5698 writes.push_back(CreateMockWrite(*session_window_update)); |
| 6067 writes.push_back(CreateMockWrite(*window_update)); | 5699 writes.push_back(CreateMockWrite(*window_update)); |
| 6068 | 5700 |
| 6069 std::vector<MockRead> reads; | 5701 std::vector<MockRead> reads; |
| 6070 scoped_ptr<SpdyFrame> resp( | 5702 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 6071 spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); | |
| 6072 reads.push_back(CreateMockRead(*resp)); | 5703 reads.push_back(CreateMockRead(*resp)); |
| 6073 | 5704 |
| 6074 ScopedVector<SpdyFrame> body_frames; | 5705 ScopedVector<SpdyFrame> body_frames; |
| 6075 const std::string body_data(4096, 'x'); | 5706 const std::string body_data(4096, 'x'); |
| 6076 for (size_t remaining = kTargetSize; remaining != 0;) { | 5707 for (size_t remaining = kTargetSize; remaining != 0;) { |
| 6077 size_t frame_size = std::min(remaining, body_data.size()); | 5708 size_t frame_size = std::min(remaining, body_data.size()); |
| 6078 body_frames.push_back(spdy_util_.ConstructSpdyBodyFrame( | 5709 body_frames.push_back(spdy_util_.ConstructSpdyBodyFrame( |
| 6079 1, body_data.data(), frame_size, false)); | 5710 1, body_data.data(), frame_size, false)); |
| 6080 reads.push_back(CreateMockRead(*body_frames.back())); | 5711 reads.push_back(CreateMockRead(*body_frames.back())); |
| 6081 remaining -= frame_size; | 5712 remaining -= frame_size; |
| 6082 } | 5713 } |
| 6083 reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 0)); // Yield. | 5714 reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, 0)); // Yield. |
| 6084 | 5715 |
| 6085 DelayedSocketData data(1, vector_as_array(&reads), reads.size(), | 5716 DelayedSocketData data(1, |
| 6086 vector_as_array(&writes), writes.size()); | 5717 vector_as_array(&reads), |
| 5718 reads.size(), |
| 5719 vector_as_array(&writes), |
| 5720 writes.size()); |
| 6087 | 5721 |
| 6088 NormalSpdyTransactionHelper helper(CreateGetRequest(), DEFAULT_PRIORITY, | 5722 NormalSpdyTransactionHelper helper( |
| 6089 BoundNetLog(), GetParam(), NULL); | 5723 CreateGetRequest(), DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 6090 helper.AddData(&data); | 5724 helper.AddData(&data); |
| 6091 helper.RunPreTestSetup(); | 5725 helper.RunPreTestSetup(); |
| 6092 HttpNetworkTransaction* trans = helper.trans(); | 5726 HttpNetworkTransaction* trans = helper.trans(); |
| 6093 | 5727 |
| 6094 TestCompletionCallback callback; | 5728 TestCompletionCallback callback; |
| 6095 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); | 5729 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6096 | 5730 |
| 6097 EXPECT_EQ(ERR_IO_PENDING, rv); | 5731 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6098 rv = callback.WaitForResult(); | 5732 rv = callback.WaitForResult(); |
| 6099 EXPECT_EQ(OK, rv); | 5733 EXPECT_EQ(OK, rv); |
| 6100 | 5734 |
| 6101 SpdyHttpStream* stream = | 5735 SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6102 static_cast<SpdyHttpStream*>(trans->stream_.get()); | |
| 6103 ASSERT_TRUE(stream != NULL); | 5736 ASSERT_TRUE(stream != NULL); |
| 6104 ASSERT_TRUE(stream->stream() != NULL); | 5737 ASSERT_TRUE(stream->stream() != NULL); |
| 6105 | 5738 |
| 6106 // All data has been read, but not consumed. The window reflects this. | 5739 // All data has been read, but not consumed. The window reflects this. |
| 6107 EXPECT_EQ(static_cast<int>(kSpdyStreamInitialWindowSize - kTargetSize), | 5740 EXPECT_EQ(static_cast<int>(kSpdyStreamInitialWindowSize - kTargetSize), |
| 6108 stream->stream()->recv_window_size()); | 5741 stream->stream()->recv_window_size()); |
| 6109 | 5742 |
| 6110 const HttpResponseInfo* response = trans->GetResponseInfo(); | 5743 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 6111 ASSERT_TRUE(response != NULL); | 5744 ASSERT_TRUE(response != NULL); |
| 6112 ASSERT_TRUE(response->headers.get() != NULL); | 5745 ASSERT_TRUE(response->headers.get() != NULL); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 6129 | 5762 |
| 6130 // Test that WINDOW_UPDATE frame causing overflow is handled correctly. | 5763 // Test that WINDOW_UPDATE frame causing overflow is handled correctly. |
| 6131 TEST_P(SpdyNetworkTransactionTest, WindowUpdateOverflow) { | 5764 TEST_P(SpdyNetworkTransactionTest, WindowUpdateOverflow) { |
| 6132 if (GetParam().protocol < kProtoSPDY3) | 5765 if (GetParam().protocol < kProtoSPDY3) |
| 6133 return; | 5766 return; |
| 6134 | 5767 |
| 6135 // Number of full frames we hope to write (but will not, used to | 5768 // Number of full frames we hope to write (but will not, used to |
| 6136 // set content-length header correctly) | 5769 // set content-length header correctly) |
| 6137 static int kFrameCount = 3; | 5770 static int kFrameCount = 3; |
| 6138 | 5771 |
| 6139 scoped_ptr<std::string> content( | 5772 scoped_ptr<std::string> content(new std::string(kMaxSpdyFrameChunkSize, 'a')); |
| 6140 new std::string(kMaxSpdyFrameChunkSize, 'a')); | |
| 6141 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( | 5773 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 6142 kRequestUrl, 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, NULL, 0)); | 5774 kRequestUrl, 1, kMaxSpdyFrameChunkSize * kFrameCount, LOWEST, NULL, 0)); |
| 6143 scoped_ptr<SpdyFrame> body( | 5775 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame( |
| 6144 spdy_util_.ConstructSpdyBodyFrame( | 5776 1, content->c_str(), content->size(), false)); |
| 6145 1, content->c_str(), content->size(), false)); | |
| 6146 scoped_ptr<SpdyFrame> rst( | 5777 scoped_ptr<SpdyFrame> rst( |
| 6147 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_FLOW_CONTROL_ERROR)); | 5778 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_FLOW_CONTROL_ERROR)); |
| 6148 | 5779 |
| 6149 // We're not going to write a data frame with FIN, we'll receive a bad | 5780 // We're not going to write a data frame with FIN, we'll receive a bad |
| 6150 // WINDOW_UPDATE while sending a request and will send a RST_STREAM frame. | 5781 // WINDOW_UPDATE while sending a request and will send a RST_STREAM frame. |
| 6151 MockWrite writes[] = { | 5782 MockWrite writes[] = { |
| 6152 CreateMockWrite(*req, 0), | 5783 CreateMockWrite(*req, 0), CreateMockWrite(*body, 2), |
| 6153 CreateMockWrite(*body, 2), | 5784 CreateMockWrite(*rst, 3), |
| 6154 CreateMockWrite(*rst, 3), | |
| 6155 }; | 5785 }; |
| 6156 | 5786 |
| 6157 static const int32 kDeltaWindowSize = 0x7fffffff; // cause an overflow | 5787 static const int32 kDeltaWindowSize = 0x7fffffff; // cause an overflow |
| 6158 scoped_ptr<SpdyFrame> window_update( | 5788 scoped_ptr<SpdyFrame> window_update( |
| 6159 spdy_util_.ConstructSpdyWindowUpdate(1, kDeltaWindowSize)); | 5789 spdy_util_.ConstructSpdyWindowUpdate(1, kDeltaWindowSize)); |
| 6160 MockRead reads[] = { | 5790 MockRead reads[] = { |
| 6161 CreateMockRead(*window_update, 1), | 5791 CreateMockRead(*window_update, 1), MockRead(ASYNC, 0, 4) // EOF |
| 6162 MockRead(ASYNC, 0, 4) // EOF | |
| 6163 }; | 5792 }; |
| 6164 | 5793 |
| 6165 DeterministicSocketData data(reads, arraysize(reads), | 5794 DeterministicSocketData data( |
| 6166 writes, arraysize(writes)); | 5795 reads, arraysize(reads), writes, arraysize(writes)); |
| 6167 | 5796 |
| 6168 ScopedVector<UploadElementReader> element_readers; | 5797 ScopedVector<UploadElementReader> element_readers; |
| 6169 for (int i = 0; i < kFrameCount; ++i) { | 5798 for (int i = 0; i < kFrameCount; ++i) { |
| 6170 element_readers.push_back( | 5799 element_readers.push_back( |
| 6171 new UploadBytesElementReader(content->c_str(), content->size())); | 5800 new UploadBytesElementReader(content->c_str(), content->size())); |
| 6172 } | 5801 } |
| 6173 UploadDataStream upload_data_stream(element_readers.Pass(), 0); | 5802 UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
| 6174 | 5803 |
| 6175 // Setup the request | 5804 // Setup the request |
| 6176 HttpRequestInfo request; | 5805 HttpRequestInfo request; |
| 6177 request.method = "POST"; | 5806 request.method = "POST"; |
| 6178 request.url = GURL("http://www.google.com/"); | 5807 request.url = GURL("http://www.google.com/"); |
| 6179 request.upload_data_stream = &upload_data_stream; | 5808 request.upload_data_stream = &upload_data_stream; |
| 6180 | 5809 |
| 6181 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, | 5810 NormalSpdyTransactionHelper helper( |
| 6182 BoundNetLog(), GetParam(), NULL); | 5811 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 6183 helper.SetDeterministic(); | 5812 helper.SetDeterministic(); |
| 6184 helper.RunPreTestSetup(); | 5813 helper.RunPreTestSetup(); |
| 6185 helper.AddDeterministicData(&data); | 5814 helper.AddDeterministicData(&data); |
| 6186 HttpNetworkTransaction* trans = helper.trans(); | 5815 HttpNetworkTransaction* trans = helper.trans(); |
| 6187 | 5816 |
| 6188 TestCompletionCallback callback; | 5817 TestCompletionCallback callback; |
| 6189 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); | 5818 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6190 ASSERT_EQ(ERR_IO_PENDING, rv); | 5819 ASSERT_EQ(ERR_IO_PENDING, rv); |
| 6191 | 5820 |
| 6192 data.RunFor(5); | 5821 data.RunFor(5); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 6221 size_t num_writes = kSpdyStreamInitialWindowSize / kMaxSpdyFrameChunkSize + 3; | 5850 size_t num_writes = kSpdyStreamInitialWindowSize / kMaxSpdyFrameChunkSize + 3; |
| 6222 | 5851 |
| 6223 // Calculate last frame's size; 0 size data frame is legal. | 5852 // Calculate last frame's size; 0 size data frame is legal. |
| 6224 size_t last_frame_size = | 5853 size_t last_frame_size = |
| 6225 kSpdyStreamInitialWindowSize % kMaxSpdyFrameChunkSize; | 5854 kSpdyStreamInitialWindowSize % kMaxSpdyFrameChunkSize; |
| 6226 | 5855 |
| 6227 // Construct content for a data frame of maximum size. | 5856 // Construct content for a data frame of maximum size. |
| 6228 std::string content(kMaxSpdyFrameChunkSize, 'a'); | 5857 std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 6229 | 5858 |
| 6230 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( | 5859 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 6231 kRequestUrl, 1, kSpdyStreamInitialWindowSize + kUploadDataSize, | 5860 kRequestUrl, |
| 6232 LOWEST, NULL, 0)); | 5861 1, |
| 5862 kSpdyStreamInitialWindowSize + kUploadDataSize, |
| 5863 LOWEST, |
| 5864 NULL, |
| 5865 0)); |
| 6233 | 5866 |
| 6234 // Full frames. | 5867 // Full frames. |
| 6235 scoped_ptr<SpdyFrame> body1( | 5868 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame( |
| 6236 spdy_util_.ConstructSpdyBodyFrame( | 5869 1, content.c_str(), content.size(), false)); |
| 6237 1, content.c_str(), content.size(), false)); | |
| 6238 | 5870 |
| 6239 // Last frame to zero out the window size. | 5871 // Last frame to zero out the window size. |
| 6240 scoped_ptr<SpdyFrame> body2( | 5872 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame( |
| 6241 spdy_util_.ConstructSpdyBodyFrame( | 5873 1, content.c_str(), last_frame_size, false)); |
| 6242 1, content.c_str(), last_frame_size, false)); | |
| 6243 | 5874 |
| 6244 // Data frame to be sent once WINDOW_UPDATE frame is received. | 5875 // Data frame to be sent once WINDOW_UPDATE frame is received. |
| 6245 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 5876 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6246 | 5877 |
| 6247 // Fill in mock writes. | 5878 // Fill in mock writes. |
| 6248 scoped_ptr<MockWrite[]> writes(new MockWrite[num_writes]); | 5879 scoped_ptr<MockWrite[]> writes(new MockWrite[num_writes]); |
| 6249 size_t i = 0; | 5880 size_t i = 0; |
| 6250 writes[i] = CreateMockWrite(*req); | 5881 writes[i] = CreateMockWrite(*req); |
| 6251 for (i = 1; i < num_writes - 2; i++) | 5882 for (i = 1; i < num_writes - 2; i++) |
| 6252 writes[i] = CreateMockWrite(*body1); | 5883 writes[i] = CreateMockWrite(*body1); |
| 6253 writes[i++] = CreateMockWrite(*body2); | 5884 writes[i++] = CreateMockWrite(*body2); |
| 6254 writes[i] = CreateMockWrite(*body3); | 5885 writes[i] = CreateMockWrite(*body3); |
| 6255 | 5886 |
| 6256 // Construct read frame, give enough space to upload the rest of the | 5887 // Construct read frame, give enough space to upload the rest of the |
| 6257 // data. | 5888 // data. |
| 6258 scoped_ptr<SpdyFrame> session_window_update( | 5889 scoped_ptr<SpdyFrame> session_window_update( |
| 6259 spdy_util_.ConstructSpdyWindowUpdate(0, kUploadDataSize)); | 5890 spdy_util_.ConstructSpdyWindowUpdate(0, kUploadDataSize)); |
| 6260 scoped_ptr<SpdyFrame> window_update( | 5891 scoped_ptr<SpdyFrame> window_update( |
| 6261 spdy_util_.ConstructSpdyWindowUpdate(1, kUploadDataSize)); | 5892 spdy_util_.ConstructSpdyWindowUpdate(1, kUploadDataSize)); |
| 6262 scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 5893 scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 6263 MockRead reads[] = { | 5894 MockRead reads[] = { |
| 6264 CreateMockRead(*session_window_update), | 5895 CreateMockRead(*session_window_update), |
| 6265 CreateMockRead(*session_window_update), | 5896 CreateMockRead(*session_window_update), CreateMockRead(*window_update), |
| 6266 CreateMockRead(*window_update), | 5897 CreateMockRead(*window_update), CreateMockRead(*reply), |
| 6267 CreateMockRead(*window_update), | 5898 CreateMockRead(*body2), CreateMockRead(*body3), |
| 6268 CreateMockRead(*reply), | 5899 MockRead(ASYNC, 0, 0) // EOF |
| 6269 CreateMockRead(*body2), | |
| 6270 CreateMockRead(*body3), | |
| 6271 MockRead(ASYNC, 0, 0) // EOF | |
| 6272 }; | 5900 }; |
| 6273 | 5901 |
| 6274 // Skip the session window updates unless we're using SPDY/3.1 and | 5902 // Skip the session window updates unless we're using SPDY/3.1 and |
| 6275 // above. | 5903 // above. |
| 6276 size_t read_offset = (GetParam().protocol >= kProtoSPDY31) ? 0 : 2; | 5904 size_t read_offset = (GetParam().protocol >= kProtoSPDY31) ? 0 : 2; |
| 6277 size_t num_reads = arraysize(reads) - read_offset; | 5905 size_t num_reads = arraysize(reads) - read_offset; |
| 6278 | 5906 |
| 6279 // Force all writes to happen before any read, last write will not | 5907 // Force all writes to happen before any read, last write will not |
| 6280 // actually queue a frame, due to window size being 0. | 5908 // actually queue a frame, due to window size being 0. |
| 6281 DelayedSocketData data(num_writes, reads + read_offset, num_reads, | 5909 DelayedSocketData data( |
| 6282 writes.get(), num_writes); | 5910 num_writes, reads + read_offset, num_reads, writes.get(), num_writes); |
| 6283 | 5911 |
| 6284 ScopedVector<UploadElementReader> element_readers; | 5912 ScopedVector<UploadElementReader> element_readers; |
| 6285 std::string upload_data_string(kSpdyStreamInitialWindowSize, 'a'); | 5913 std::string upload_data_string(kSpdyStreamInitialWindowSize, 'a'); |
| 6286 upload_data_string.append(kUploadData, kUploadDataSize); | 5914 upload_data_string.append(kUploadData, kUploadDataSize); |
| 6287 element_readers.push_back(new UploadBytesElementReader( | 5915 element_readers.push_back(new UploadBytesElementReader( |
| 6288 upload_data_string.c_str(), upload_data_string.size())); | 5916 upload_data_string.c_str(), upload_data_string.size())); |
| 6289 UploadDataStream upload_data_stream(element_readers.Pass(), 0); | 5917 UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
| 6290 | 5918 |
| 6291 HttpRequestInfo request; | 5919 HttpRequestInfo request; |
| 6292 request.method = "POST"; | 5920 request.method = "POST"; |
| 6293 request.url = GURL("http://www.google.com/"); | 5921 request.url = GURL("http://www.google.com/"); |
| 6294 request.upload_data_stream = &upload_data_stream; | 5922 request.upload_data_stream = &upload_data_stream; |
| 6295 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, | 5923 NormalSpdyTransactionHelper helper( |
| 6296 BoundNetLog(), GetParam(), NULL); | 5924 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 6297 helper.AddData(&data); | 5925 helper.AddData(&data); |
| 6298 helper.RunPreTestSetup(); | 5926 helper.RunPreTestSetup(); |
| 6299 | 5927 |
| 6300 HttpNetworkTransaction* trans = helper.trans(); | 5928 HttpNetworkTransaction* trans = helper.trans(); |
| 6301 | 5929 |
| 6302 TestCompletionCallback callback; | 5930 TestCompletionCallback callback; |
| 6303 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); | 5931 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6304 EXPECT_EQ(ERR_IO_PENDING, rv); | 5932 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6305 | 5933 |
| 6306 base::RunLoop().RunUntilIdle(); // Write as much as we can. | 5934 base::RunLoop().RunUntilIdle(); // Write as much as we can. |
| 6307 | 5935 |
| 6308 SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); | 5936 SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6309 ASSERT_TRUE(stream != NULL); | 5937 ASSERT_TRUE(stream != NULL); |
| 6310 ASSERT_TRUE(stream->stream() != NULL); | 5938 ASSERT_TRUE(stream->stream() != NULL); |
| 6311 EXPECT_EQ(0, stream->stream()->send_window_size()); | 5939 EXPECT_EQ(0, stream->stream()->send_window_size()); |
| 6312 // All the body data should have been read. | 5940 // All the body data should have been read. |
| 6313 // TODO(satorux): This is because of the weirdness in reading the request | 5941 // TODO(satorux): This is because of the weirdness in reading the request |
| 6314 // body in OnSendBodyComplete(). See crbug.com/113107. | 5942 // body in OnSendBodyComplete(). See crbug.com/113107. |
| 6315 EXPECT_TRUE(upload_data_stream.IsEOF()); | 5943 EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 6316 // But the body is not yet fully sent (kUploadData is not yet sent) | 5944 // But the body is not yet fully sent (kUploadData is not yet sent) |
| 6317 // since we're send-stalled. | 5945 // since we're send-stalled. |
| 6318 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); | 5946 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 6319 | 5947 |
| 6320 data.ForceNextRead(); // Read in WINDOW_UPDATE frame. | 5948 data.ForceNextRead(); // Read in WINDOW_UPDATE frame. |
| 6321 rv = callback.WaitForResult(); | 5949 rv = callback.WaitForResult(); |
| 6322 helper.VerifyDataConsumed(); | 5950 helper.VerifyDataConsumed(); |
| 6323 } | 5951 } |
| 6324 | 5952 |
| 6325 // Test we correctly handle the case where the SETTINGS frame results in | 5953 // Test we correctly handle the case where the SETTINGS frame results in |
| 6326 // unstalling the send window. | 5954 // unstalling the send window. |
| 6327 TEST_P(SpdyNetworkTransactionTest, FlowControlStallResumeAfterSettings) { | 5955 TEST_P(SpdyNetworkTransactionTest, FlowControlStallResumeAfterSettings) { |
| 6328 if (GetParam().protocol < kProtoSPDY3) | 5956 if (GetParam().protocol < kProtoSPDY3) |
| 6329 return; | 5957 return; |
| 6330 | 5958 |
| 6331 // Number of frames we need to send to zero out the window size: data | 5959 // Number of frames we need to send to zero out the window size: data |
| 6332 // frames plus SYN_STREAM plus the last data frame; also we need another | 5960 // frames plus SYN_STREAM plus the last data frame; also we need another |
| 6333 // data frame that we will send once the SETTING is received, therefore +3. | 5961 // data frame that we will send once the SETTING is received, therefore +3. |
| 6334 size_t num_writes = kSpdyStreamInitialWindowSize / kMaxSpdyFrameChunkSize + 3; | 5962 size_t num_writes = kSpdyStreamInitialWindowSize / kMaxSpdyFrameChunkSize + 3; |
| 6335 | 5963 |
| 6336 // Calculate last frame's size; 0 size data frame is legal. | 5964 // Calculate last frame's size; 0 size data frame is legal. |
| 6337 size_t last_frame_size = | 5965 size_t last_frame_size = |
| 6338 kSpdyStreamInitialWindowSize % kMaxSpdyFrameChunkSize; | 5966 kSpdyStreamInitialWindowSize % kMaxSpdyFrameChunkSize; |
| 6339 | 5967 |
| 6340 // Construct content for a data frame of maximum size. | 5968 // Construct content for a data frame of maximum size. |
| 6341 std::string content(kMaxSpdyFrameChunkSize, 'a'); | 5969 std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 6342 | 5970 |
| 6343 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( | 5971 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 6344 kRequestUrl, 1, kSpdyStreamInitialWindowSize + kUploadDataSize, | 5972 kRequestUrl, |
| 6345 LOWEST, NULL, 0)); | 5973 1, |
| 5974 kSpdyStreamInitialWindowSize + kUploadDataSize, |
| 5975 LOWEST, |
| 5976 NULL, |
| 5977 0)); |
| 6346 | 5978 |
| 6347 // Full frames. | 5979 // Full frames. |
| 6348 scoped_ptr<SpdyFrame> body1( | 5980 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame( |
| 6349 spdy_util_.ConstructSpdyBodyFrame( | 5981 1, content.c_str(), content.size(), false)); |
| 6350 1, content.c_str(), content.size(), false)); | |
| 6351 | 5982 |
| 6352 // Last frame to zero out the window size. | 5983 // Last frame to zero out the window size. |
| 6353 scoped_ptr<SpdyFrame> body2( | 5984 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame( |
| 6354 spdy_util_.ConstructSpdyBodyFrame( | 5985 1, content.c_str(), last_frame_size, false)); |
| 6355 1, content.c_str(), last_frame_size, false)); | |
| 6356 | 5986 |
| 6357 // Data frame to be sent once SETTINGS frame is received. | 5987 // Data frame to be sent once SETTINGS frame is received. |
| 6358 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 5988 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6359 | 5989 |
| 6360 // Fill in mock reads/writes. | 5990 // Fill in mock reads/writes. |
| 6361 std::vector<MockRead> reads; | 5991 std::vector<MockRead> reads; |
| 6362 std::vector<MockWrite> writes; | 5992 std::vector<MockWrite> writes; |
| 6363 size_t i = 0; | 5993 size_t i = 0; |
| 6364 writes.push_back(CreateMockWrite(*req, i++)); | 5994 writes.push_back(CreateMockWrite(*req, i++)); |
| 6365 while (i < num_writes - 2) | 5995 while (i < num_writes - 2) |
| 6366 writes.push_back(CreateMockWrite(*body1, i++)); | 5996 writes.push_back(CreateMockWrite(*body1, i++)); |
| 6367 writes.push_back(CreateMockWrite(*body2, i++)); | 5997 writes.push_back(CreateMockWrite(*body2, i++)); |
| 6368 | 5998 |
| 6369 // Construct read frame for SETTINGS that gives enough space to upload the | 5999 // Construct read frame for SETTINGS that gives enough space to upload the |
| 6370 // rest of the data. | 6000 // rest of the data. |
| 6371 SettingsMap settings; | 6001 SettingsMap settings; |
| 6372 settings[SETTINGS_INITIAL_WINDOW_SIZE] = | 6002 settings[SETTINGS_INITIAL_WINDOW_SIZE] = SettingsFlagsAndValue( |
| 6373 SettingsFlagsAndValue( | 6003 SETTINGS_FLAG_NONE, kSpdyStreamInitialWindowSize * 2); |
| 6374 SETTINGS_FLAG_NONE, kSpdyStreamInitialWindowSize * 2); | |
| 6375 scoped_ptr<SpdyFrame> settings_frame_large( | 6004 scoped_ptr<SpdyFrame> settings_frame_large( |
| 6376 spdy_util_.ConstructSpdySettings(settings)); | 6005 spdy_util_.ConstructSpdySettings(settings)); |
| 6377 | 6006 |
| 6378 reads.push_back(CreateMockRead(*settings_frame_large, i++)); | 6007 reads.push_back(CreateMockRead(*settings_frame_large, i++)); |
| 6379 | 6008 |
| 6380 scoped_ptr<SpdyFrame> session_window_update( | 6009 scoped_ptr<SpdyFrame> session_window_update( |
| 6381 spdy_util_.ConstructSpdyWindowUpdate(0, kUploadDataSize)); | 6010 spdy_util_.ConstructSpdyWindowUpdate(0, kUploadDataSize)); |
| 6382 if (GetParam().protocol >= kProtoSPDY31) | 6011 if (GetParam().protocol >= kProtoSPDY31) |
| 6383 reads.push_back(CreateMockRead(*session_window_update, i++)); | 6012 reads.push_back(CreateMockRead(*session_window_update, i++)); |
| 6384 | 6013 |
| 6385 writes.push_back(CreateMockWrite(*body3, i++)); | 6014 writes.push_back(CreateMockWrite(*body3, i++)); |
| 6386 | 6015 |
| 6387 scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 6016 scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 6388 reads.push_back(CreateMockRead(*reply, i++)); | 6017 reads.push_back(CreateMockRead(*reply, i++)); |
| 6389 reads.push_back(CreateMockRead(*body2, i++)); | 6018 reads.push_back(CreateMockRead(*body2, i++)); |
| 6390 reads.push_back(CreateMockRead(*body3, i++)); | 6019 reads.push_back(CreateMockRead(*body3, i++)); |
| 6391 reads.push_back(MockRead(ASYNC, 0, i++)); // EOF | 6020 reads.push_back(MockRead(ASYNC, 0, i++)); // EOF |
| 6392 | 6021 |
| 6393 // Force all writes to happen before any read, last write will not | 6022 // Force all writes to happen before any read, last write will not |
| 6394 // actually queue a frame, due to window size being 0. | 6023 // actually queue a frame, due to window size being 0. |
| 6395 DeterministicSocketData data(vector_as_array(&reads), reads.size(), | 6024 DeterministicSocketData data(vector_as_array(&reads), |
| 6396 vector_as_array(&writes), writes.size()); | 6025 reads.size(), |
| 6026 vector_as_array(&writes), |
| 6027 writes.size()); |
| 6397 | 6028 |
| 6398 ScopedVector<UploadElementReader> element_readers; | 6029 ScopedVector<UploadElementReader> element_readers; |
| 6399 std::string upload_data_string(kSpdyStreamInitialWindowSize, 'a'); | 6030 std::string upload_data_string(kSpdyStreamInitialWindowSize, 'a'); |
| 6400 upload_data_string.append(kUploadData, kUploadDataSize); | 6031 upload_data_string.append(kUploadData, kUploadDataSize); |
| 6401 element_readers.push_back(new UploadBytesElementReader( | 6032 element_readers.push_back(new UploadBytesElementReader( |
| 6402 upload_data_string.c_str(), upload_data_string.size())); | 6033 upload_data_string.c_str(), upload_data_string.size())); |
| 6403 UploadDataStream upload_data_stream(element_readers.Pass(), 0); | 6034 UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
| 6404 | 6035 |
| 6405 HttpRequestInfo request; | 6036 HttpRequestInfo request; |
| 6406 request.method = "POST"; | 6037 request.method = "POST"; |
| 6407 request.url = GURL("http://www.google.com/"); | 6038 request.url = GURL("http://www.google.com/"); |
| 6408 request.upload_data_stream = &upload_data_stream; | 6039 request.upload_data_stream = &upload_data_stream; |
| 6409 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, | 6040 NormalSpdyTransactionHelper helper( |
| 6410 BoundNetLog(), GetParam(), NULL); | 6041 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 6411 helper.SetDeterministic(); | 6042 helper.SetDeterministic(); |
| 6412 helper.RunPreTestSetup(); | 6043 helper.RunPreTestSetup(); |
| 6413 helper.AddDeterministicData(&data); | 6044 helper.AddDeterministicData(&data); |
| 6414 | 6045 |
| 6415 HttpNetworkTransaction* trans = helper.trans(); | 6046 HttpNetworkTransaction* trans = helper.trans(); |
| 6416 | 6047 |
| 6417 TestCompletionCallback callback; | 6048 TestCompletionCallback callback; |
| 6418 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); | 6049 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6419 EXPECT_EQ(ERR_IO_PENDING, rv); | 6050 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6420 | 6051 |
| 6421 data.RunFor(num_writes - 1); // Write as much as we can. | 6052 data.RunFor(num_writes - 1); // Write as much as we can. |
| 6422 | 6053 |
| 6423 SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); | 6054 SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6424 ASSERT_TRUE(stream != NULL); | 6055 ASSERT_TRUE(stream != NULL); |
| 6425 ASSERT_TRUE(stream->stream() != NULL); | 6056 ASSERT_TRUE(stream->stream() != NULL); |
| 6426 EXPECT_EQ(0, stream->stream()->send_window_size()); | 6057 EXPECT_EQ(0, stream->stream()->send_window_size()); |
| 6427 | 6058 |
| 6428 // All the body data should have been read. | 6059 // All the body data should have been read. |
| 6429 // TODO(satorux): This is because of the weirdness in reading the request | 6060 // TODO(satorux): This is because of the weirdness in reading the request |
| 6430 // body in OnSendBodyComplete(). See crbug.com/113107. | 6061 // body in OnSendBodyComplete(). See crbug.com/113107. |
| 6431 EXPECT_TRUE(upload_data_stream.IsEOF()); | 6062 EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 6432 // But the body is not yet fully sent (kUploadData is not yet sent) | 6063 // But the body is not yet fully sent (kUploadData is not yet sent) |
| 6433 // since we're send-stalled. | 6064 // since we're send-stalled. |
| 6434 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); | 6065 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 6435 | 6066 |
| 6436 data.RunFor(6); // Read in SETTINGS frame to unstall. | 6067 data.RunFor(6); // Read in SETTINGS frame to unstall. |
| 6437 rv = callback.WaitForResult(); | 6068 rv = callback.WaitForResult(); |
| 6438 helper.VerifyDataConsumed(); | 6069 helper.VerifyDataConsumed(); |
| 6439 // If stream is NULL, that means it was unstalled and closed. | 6070 // If stream is NULL, that means it was unstalled and closed. |
| 6440 EXPECT_TRUE(stream->stream() == NULL); | 6071 EXPECT_TRUE(stream->stream() == NULL); |
| 6441 } | 6072 } |
| 6442 | 6073 |
| 6443 // Test we correctly handle the case where the SETTINGS frame results in a | 6074 // Test we correctly handle the case where the SETTINGS frame results in a |
| 6444 // negative send window size. | 6075 // negative send window size. |
| 6445 TEST_P(SpdyNetworkTransactionTest, FlowControlNegativeSendWindowSize) { | 6076 TEST_P(SpdyNetworkTransactionTest, FlowControlNegativeSendWindowSize) { |
| 6446 if (GetParam().protocol < kProtoSPDY3) | 6077 if (GetParam().protocol < kProtoSPDY3) |
| 6447 return; | 6078 return; |
| 6448 | 6079 |
| 6449 // Number of frames we need to send to zero out the window size: data | 6080 // Number of frames we need to send to zero out the window size: data |
| 6450 // frames plus SYN_STREAM plus the last data frame; also we need another | 6081 // frames plus SYN_STREAM plus the last data frame; also we need another |
| 6451 // data frame that we will send once the SETTING is received, therefore +3. | 6082 // data frame that we will send once the SETTING is received, therefore +3. |
| 6452 size_t num_writes = kSpdyStreamInitialWindowSize / kMaxSpdyFrameChunkSize + 3; | 6083 size_t num_writes = kSpdyStreamInitialWindowSize / kMaxSpdyFrameChunkSize + 3; |
| 6453 | 6084 |
| 6454 // Calculate last frame's size; 0 size data frame is legal. | 6085 // Calculate last frame's size; 0 size data frame is legal. |
| 6455 size_t last_frame_size = | 6086 size_t last_frame_size = |
| 6456 kSpdyStreamInitialWindowSize % kMaxSpdyFrameChunkSize; | 6087 kSpdyStreamInitialWindowSize % kMaxSpdyFrameChunkSize; |
| 6457 | 6088 |
| 6458 // Construct content for a data frame of maximum size. | 6089 // Construct content for a data frame of maximum size. |
| 6459 std::string content(kMaxSpdyFrameChunkSize, 'a'); | 6090 std::string content(kMaxSpdyFrameChunkSize, 'a'); |
| 6460 | 6091 |
| 6461 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( | 6092 scoped_ptr<SpdyFrame> req(spdy_util_.ConstructSpdyPost( |
| 6462 kRequestUrl, 1, kSpdyStreamInitialWindowSize + kUploadDataSize, | 6093 kRequestUrl, |
| 6463 LOWEST, NULL, 0)); | 6094 1, |
| 6095 kSpdyStreamInitialWindowSize + kUploadDataSize, |
| 6096 LOWEST, |
| 6097 NULL, |
| 6098 0)); |
| 6464 | 6099 |
| 6465 // Full frames. | 6100 // Full frames. |
| 6466 scoped_ptr<SpdyFrame> body1( | 6101 scoped_ptr<SpdyFrame> body1(spdy_util_.ConstructSpdyBodyFrame( |
| 6467 spdy_util_.ConstructSpdyBodyFrame( | 6102 1, content.c_str(), content.size(), false)); |
| 6468 1, content.c_str(), content.size(), false)); | |
| 6469 | 6103 |
| 6470 // Last frame to zero out the window size. | 6104 // Last frame to zero out the window size. |
| 6471 scoped_ptr<SpdyFrame> body2( | 6105 scoped_ptr<SpdyFrame> body2(spdy_util_.ConstructSpdyBodyFrame( |
| 6472 spdy_util_.ConstructSpdyBodyFrame( | 6106 1, content.c_str(), last_frame_size, false)); |
| 6473 1, content.c_str(), last_frame_size, false)); | |
| 6474 | 6107 |
| 6475 // Data frame to be sent once SETTINGS frame is received. | 6108 // Data frame to be sent once SETTINGS frame is received. |
| 6476 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); | 6109 scoped_ptr<SpdyFrame> body3(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 6477 | 6110 |
| 6478 // Fill in mock reads/writes. | 6111 // Fill in mock reads/writes. |
| 6479 std::vector<MockRead> reads; | 6112 std::vector<MockRead> reads; |
| 6480 std::vector<MockWrite> writes; | 6113 std::vector<MockWrite> writes; |
| 6481 size_t i = 0; | 6114 size_t i = 0; |
| 6482 writes.push_back(CreateMockWrite(*req, i++)); | 6115 writes.push_back(CreateMockWrite(*req, i++)); |
| 6483 while (i < num_writes - 2) | 6116 while (i < num_writes - 2) |
| 6484 writes.push_back(CreateMockWrite(*body1, i++)); | 6117 writes.push_back(CreateMockWrite(*body1, i++)); |
| 6485 writes.push_back(CreateMockWrite(*body2, i++)); | 6118 writes.push_back(CreateMockWrite(*body2, i++)); |
| 6486 | 6119 |
| 6487 // Construct read frame for SETTINGS that makes the send_window_size | 6120 // Construct read frame for SETTINGS that makes the send_window_size |
| 6488 // negative. | 6121 // negative. |
| 6489 SettingsMap new_settings; | 6122 SettingsMap new_settings; |
| 6490 new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = | 6123 new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = SettingsFlagsAndValue( |
| 6491 SettingsFlagsAndValue( | 6124 SETTINGS_FLAG_NONE, kSpdyStreamInitialWindowSize / 2); |
| 6492 SETTINGS_FLAG_NONE, kSpdyStreamInitialWindowSize / 2); | |
| 6493 scoped_ptr<SpdyFrame> settings_frame_small( | 6125 scoped_ptr<SpdyFrame> settings_frame_small( |
| 6494 spdy_util_.ConstructSpdySettings(new_settings)); | 6126 spdy_util_.ConstructSpdySettings(new_settings)); |
| 6495 // Construct read frames for WINDOW_UPDATE that makes the send_window_size | 6127 // Construct read frames for WINDOW_UPDATE that makes the send_window_size |
| 6496 // positive. | 6128 // positive. |
| 6497 scoped_ptr<SpdyFrame> session_window_update_init_size( | 6129 scoped_ptr<SpdyFrame> session_window_update_init_size( |
| 6498 spdy_util_.ConstructSpdyWindowUpdate(0, kSpdyStreamInitialWindowSize)); | 6130 spdy_util_.ConstructSpdyWindowUpdate(0, kSpdyStreamInitialWindowSize)); |
| 6499 scoped_ptr<SpdyFrame> window_update_init_size( | 6131 scoped_ptr<SpdyFrame> window_update_init_size( |
| 6500 spdy_util_.ConstructSpdyWindowUpdate(1, kSpdyStreamInitialWindowSize)); | 6132 spdy_util_.ConstructSpdyWindowUpdate(1, kSpdyStreamInitialWindowSize)); |
| 6501 | 6133 |
| 6502 reads.push_back(CreateMockRead(*settings_frame_small, i++)); | 6134 reads.push_back(CreateMockRead(*settings_frame_small, i++)); |
| 6503 | 6135 |
| 6504 if (GetParam().protocol >= kProtoSPDY3) | 6136 if (GetParam().protocol >= kProtoSPDY3) |
| 6505 reads.push_back(CreateMockRead(*session_window_update_init_size, i++)); | 6137 reads.push_back(CreateMockRead(*session_window_update_init_size, i++)); |
| 6506 | 6138 |
| 6507 reads.push_back(CreateMockRead(*window_update_init_size, i++)); | 6139 reads.push_back(CreateMockRead(*window_update_init_size, i++)); |
| 6508 | 6140 |
| 6509 writes.push_back(CreateMockWrite(*body3, i++)); | 6141 writes.push_back(CreateMockWrite(*body3, i++)); |
| 6510 | 6142 |
| 6511 scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); | 6143 scoped_ptr<SpdyFrame> reply(spdy_util_.ConstructSpdyPostSynReply(NULL, 0)); |
| 6512 reads.push_back(CreateMockRead(*reply, i++)); | 6144 reads.push_back(CreateMockRead(*reply, i++)); |
| 6513 reads.push_back(CreateMockRead(*body2, i++)); | 6145 reads.push_back(CreateMockRead(*body2, i++)); |
| 6514 reads.push_back(CreateMockRead(*body3, i++)); | 6146 reads.push_back(CreateMockRead(*body3, i++)); |
| 6515 reads.push_back(MockRead(ASYNC, 0, i++)); // EOF | 6147 reads.push_back(MockRead(ASYNC, 0, i++)); // EOF |
| 6516 | 6148 |
| 6517 // Force all writes to happen before any read, last write will not | 6149 // Force all writes to happen before any read, last write will not |
| 6518 // actually queue a frame, due to window size being 0. | 6150 // actually queue a frame, due to window size being 0. |
| 6519 DeterministicSocketData data(vector_as_array(&reads), reads.size(), | 6151 DeterministicSocketData data(vector_as_array(&reads), |
| 6520 vector_as_array(&writes), writes.size()); | 6152 reads.size(), |
| 6153 vector_as_array(&writes), |
| 6154 writes.size()); |
| 6521 | 6155 |
| 6522 ScopedVector<UploadElementReader> element_readers; | 6156 ScopedVector<UploadElementReader> element_readers; |
| 6523 std::string upload_data_string(kSpdyStreamInitialWindowSize, 'a'); | 6157 std::string upload_data_string(kSpdyStreamInitialWindowSize, 'a'); |
| 6524 upload_data_string.append(kUploadData, kUploadDataSize); | 6158 upload_data_string.append(kUploadData, kUploadDataSize); |
| 6525 element_readers.push_back(new UploadBytesElementReader( | 6159 element_readers.push_back(new UploadBytesElementReader( |
| 6526 upload_data_string.c_str(), upload_data_string.size())); | 6160 upload_data_string.c_str(), upload_data_string.size())); |
| 6527 UploadDataStream upload_data_stream(element_readers.Pass(), 0); | 6161 UploadDataStream upload_data_stream(element_readers.Pass(), 0); |
| 6528 | 6162 |
| 6529 HttpRequestInfo request; | 6163 HttpRequestInfo request; |
| 6530 request.method = "POST"; | 6164 request.method = "POST"; |
| 6531 request.url = GURL("http://www.google.com/"); | 6165 request.url = GURL("http://www.google.com/"); |
| 6532 request.upload_data_stream = &upload_data_stream; | 6166 request.upload_data_stream = &upload_data_stream; |
| 6533 NormalSpdyTransactionHelper helper(request, DEFAULT_PRIORITY, | 6167 NormalSpdyTransactionHelper helper( |
| 6534 BoundNetLog(), GetParam(), NULL); | 6168 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); |
| 6535 helper.SetDeterministic(); | 6169 helper.SetDeterministic(); |
| 6536 helper.RunPreTestSetup(); | 6170 helper.RunPreTestSetup(); |
| 6537 helper.AddDeterministicData(&data); | 6171 helper.AddDeterministicData(&data); |
| 6538 | 6172 |
| 6539 HttpNetworkTransaction* trans = helper.trans(); | 6173 HttpNetworkTransaction* trans = helper.trans(); |
| 6540 | 6174 |
| 6541 TestCompletionCallback callback; | 6175 TestCompletionCallback callback; |
| 6542 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); | 6176 int rv = trans->Start(&helper.request(), callback.callback(), BoundNetLog()); |
| 6543 EXPECT_EQ(ERR_IO_PENDING, rv); | 6177 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 6544 | 6178 |
| 6545 data.RunFor(num_writes - 1); // Write as much as we can. | 6179 data.RunFor(num_writes - 1); // Write as much as we can. |
| 6546 | 6180 |
| 6547 SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); | 6181 SpdyHttpStream* stream = static_cast<SpdyHttpStream*>(trans->stream_.get()); |
| 6548 ASSERT_TRUE(stream != NULL); | 6182 ASSERT_TRUE(stream != NULL); |
| 6549 ASSERT_TRUE(stream->stream() != NULL); | 6183 ASSERT_TRUE(stream->stream() != NULL); |
| 6550 EXPECT_EQ(0, stream->stream()->send_window_size()); | 6184 EXPECT_EQ(0, stream->stream()->send_window_size()); |
| 6551 | 6185 |
| 6552 // All the body data should have been read. | 6186 // All the body data should have been read. |
| 6553 // TODO(satorux): This is because of the weirdness in reading the request | 6187 // TODO(satorux): This is because of the weirdness in reading the request |
| 6554 // body in OnSendBodyComplete(). See crbug.com/113107. | 6188 // body in OnSendBodyComplete(). See crbug.com/113107. |
| 6555 EXPECT_TRUE(upload_data_stream.IsEOF()); | 6189 EXPECT_TRUE(upload_data_stream.IsEOF()); |
| 6556 // But the body is not yet fully sent (kUploadData is not yet sent) | 6190 // But the body is not yet fully sent (kUploadData is not yet sent) |
| 6557 // since we're send-stalled. | 6191 // since we're send-stalled. |
| 6558 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); | 6192 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
| 6559 | 6193 |
| 6560 // Read in WINDOW_UPDATE or SETTINGS frame. | 6194 // Read in WINDOW_UPDATE or SETTINGS frame. |
| 6561 data.RunFor((GetParam().protocol >= kProtoSPDY31) ? 8 : 7); | 6195 data.RunFor((GetParam().protocol >= kProtoSPDY31) ? 8 : 7); |
| 6562 rv = callback.WaitForResult(); | 6196 rv = callback.WaitForResult(); |
| 6563 helper.VerifyDataConsumed(); | 6197 helper.VerifyDataConsumed(); |
| 6564 } | 6198 } |
| 6565 | 6199 |
| 6566 } // namespace net | 6200 } // namespace net |
| OLD | NEW |