| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "net/http/http_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "net/base/auth.h" | 10 #include "net/base/auth.h" |
| 11 #include "net/base/net_log_unittest.h" | 11 #include "net/base/net_log_unittest.h" |
| 12 #include "net/http/http_network_session_peer.h" | 12 #include "net/http/http_network_session_peer.h" |
| 13 #include "net/http/http_transaction_unittest.h" | 13 #include "net/http/http_transaction_unittest.h" |
| 14 #include "net/socket/client_socket_pool_base.h" |
| 14 #include "net/spdy/spdy_http_stream.h" | 15 #include "net/spdy/spdy_http_stream.h" |
| 15 #include "net/spdy/spdy_http_utils.h" | 16 #include "net/spdy/spdy_http_utils.h" |
| 16 #include "net/spdy/spdy_session.h" | 17 #include "net/spdy/spdy_session.h" |
| 17 #include "net/spdy/spdy_session_pool.h" | 18 #include "net/spdy/spdy_session_pool.h" |
| 18 #include "net/spdy/spdy_test_util.h" | 19 #include "net/spdy/spdy_test_util.h" |
| 19 #include "net/url_request/url_request_test_util.h" | 20 #include "net/url_request/url_request_test_util.h" |
| 20 #include "testing/platform_test.h" | 21 #include "testing/platform_test.h" |
| 21 | 22 |
| 22 //----------------------------------------------------------------------------- | 23 //----------------------------------------------------------------------------- |
| 23 | 24 |
| 24 namespace net { | 25 namespace net { |
| 25 | 26 |
| 26 // This is the expected list of advertised protocols from the browser's NPN | 27 // This is the expected list of advertised protocols from the browser's NPN |
| 27 // list. | 28 // list. |
| 28 static const char kExpectedNPNString[] = "\x08http/1.1\x06spdy/2"; | 29 static const char kExpectedNPNString[] = "\x08http/1.1\x06spdy/2"; |
| 29 | 30 |
| 30 enum SpdyNetworkTransactionTestTypes { | 31 enum SpdyNetworkTransactionTestTypes { |
| 31 SPDYNPN, | 32 SPDYNPN, |
| 32 SPDYNOSSL, | 33 SPDYNOSSL, |
| 33 SPDYSSL, | 34 SPDYSSL, |
| 34 }; | 35 }; |
| 35 class SpdyNetworkTransactionTest | 36 class SpdyNetworkTransactionTest |
| 36 : public ::testing::TestWithParam<SpdyNetworkTransactionTestTypes> { | 37 : public ::testing::TestWithParam<SpdyNetworkTransactionTestTypes> { |
| 37 protected: | 38 protected: |
| 39 |
| 38 virtual void SetUp() { | 40 virtual void SetUp() { |
| 39 // By default, all tests turn off compression. | 41 // By default, all tests turn off compression. |
| 40 EnableCompression(false); | 42 EnableCompression(false); |
| 41 google_get_request_initialized_ = false; | 43 google_get_request_initialized_ = false; |
| 42 google_post_request_initialized_ = false; | 44 google_post_request_initialized_ = false; |
| 43 google_chunked_post_request_initialized_ = false; | 45 google_chunked_post_request_initialized_ = false; |
| 46 |
| 47 backup_jobs_prev_value_ = |
| 48 internal::ClientSocketPoolBaseHelper::connect_backup_jobs_enabled(); |
| 49 internal::ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled( |
| 50 false); |
| 44 } | 51 } |
| 45 | 52 |
| 46 virtual void TearDown() { | 53 virtual void TearDown() { |
| 47 // Empty the current queue. | 54 // Empty the current queue. |
| 48 MessageLoop::current()->RunAllPending(); | 55 MessageLoop::current()->RunAllPending(); |
| 56 internal::ClientSocketPoolBaseHelper::set_connect_backup_jobs_enabled( |
| 57 backup_jobs_prev_value_); |
| 49 } | 58 } |
| 50 | 59 |
| 51 struct TransactionHelperResult { | 60 struct TransactionHelperResult { |
| 52 int rv; | 61 int rv; |
| 53 std::string status_line; | 62 std::string status_line; |
| 54 std::string response_data; | 63 std::string response_data; |
| 55 HttpResponseInfo response_info; | 64 HttpResponseInfo response_info; |
| 56 }; | 65 }; |
| 57 | 66 |
| 58 void EnableCompression(bool enabled) { | 67 void EnableCompression(bool enabled) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 } | 169 } |
| 161 | 170 |
| 162 // Verify responses. | 171 // Verify responses. |
| 163 const HttpResponseInfo* response = trans_->GetResponseInfo(); | 172 const HttpResponseInfo* response = trans_->GetResponseInfo(); |
| 164 ASSERT_TRUE(response != NULL); | 173 ASSERT_TRUE(response != NULL); |
| 165 ASSERT_TRUE(response->headers != NULL); | 174 ASSERT_TRUE(response->headers != NULL); |
| 166 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 175 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 167 EXPECT_EQ(spdy_enabled_, response->was_fetched_via_spdy); | 176 EXPECT_EQ(spdy_enabled_, response->was_fetched_via_spdy); |
| 168 if (test_type_ == SPDYNPN && spdy_enabled_) { | 177 if (test_type_ == SPDYNPN && spdy_enabled_) { |
| 169 EXPECT_TRUE(response->was_npn_negotiated); | 178 EXPECT_TRUE(response->was_npn_negotiated); |
| 170 EXPECT_TRUE(response->was_alternate_protocol_available); | |
| 171 } else { | 179 } else { |
| 172 EXPECT_TRUE(!response->was_npn_negotiated); | 180 EXPECT_TRUE(!response->was_npn_negotiated); |
| 173 EXPECT_TRUE(!response->was_alternate_protocol_available); | |
| 174 } | 181 } |
| 175 // If SPDY is not enabled, a HTTP request should not be diverted | 182 // If SPDY is not enabled, a HTTP request should not be diverted |
| 176 // over a SSL session. | 183 // over a SSL session. |
| 177 if (!spdy_enabled_) { | 184 if (!spdy_enabled_) { |
| 178 EXPECT_EQ(request_.url.SchemeIs("https"), | 185 EXPECT_EQ(request_.url.SchemeIs("https"), |
| 179 response->was_npn_negotiated); | 186 response->was_npn_negotiated); |
| 180 } | 187 } |
| 181 EXPECT_EQ("192.0.2.33", response->socket_address.host()); | 188 EXPECT_EQ("192.0.2.33", response->socket_address.host()); |
| 182 EXPECT_EQ(0, response->socket_address.port()); | 189 EXPECT_EQ(0, response->socket_address.port()); |
| 183 output_.status_line = response->headers->GetStatusLine(); | 190 output_.status_line = response->headers->GetStatusLine(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 DCHECK(!deterministic_); | 237 DCHECK(!deterministic_); |
| 231 data_vector_.push_back(data); | 238 data_vector_.push_back(data); |
| 232 linked_ptr<SSLSocketDataProvider> ssl_( | 239 linked_ptr<SSLSocketDataProvider> ssl_( |
| 233 new SSLSocketDataProvider(true, OK)); | 240 new SSLSocketDataProvider(true, OK)); |
| 234 if (test_type_ == SPDYNPN) { | 241 if (test_type_ == SPDYNPN) { |
| 235 ssl_->next_proto_status = SSLClientSocket::kNextProtoNegotiated; | 242 ssl_->next_proto_status = SSLClientSocket::kNextProtoNegotiated; |
| 236 ssl_->next_proto = "spdy/2"; | 243 ssl_->next_proto = "spdy/2"; |
| 237 ssl_->was_npn_negotiated = true; | 244 ssl_->was_npn_negotiated = true; |
| 238 } | 245 } |
| 239 ssl_vector_.push_back(ssl_); | 246 ssl_vector_.push_back(ssl_); |
| 240 if(test_type_ == SPDYNPN || test_type_ == SPDYSSL) | 247 if (test_type_ == SPDYNPN || test_type_ == SPDYSSL) |
| 241 session_deps_->socket_factory->AddSSLSocketDataProvider(ssl_.get()); | 248 session_deps_->socket_factory->AddSSLSocketDataProvider(ssl_.get()); |
| 242 session_deps_->socket_factory->AddSocketDataProvider(data); | 249 session_deps_->socket_factory->AddSocketDataProvider(data); |
| 250 if (test_type_ == SPDYNPN) { |
| 251 MockConnect never_finishing_connect(false, ERR_IO_PENDING); |
| 252 linked_ptr<StaticSocketDataProvider> |
| 253 hanging_non_alternate_protocol_socket( |
| 254 new StaticSocketDataProvider(NULL, 0, NULL, 0)); |
| 255 hanging_non_alternate_protocol_socket->set_connect_data( |
| 256 never_finishing_connect); |
| 257 session_deps_->socket_factory->AddSocketDataProvider( |
| 258 hanging_non_alternate_protocol_socket.get()); |
| 259 alternate_vector_.push_back(hanging_non_alternate_protocol_socket); |
| 260 } |
| 243 } | 261 } |
| 244 | 262 |
| 245 void AddDeterministicData(DeterministicSocketData* data) { | 263 void AddDeterministicData(DeterministicSocketData* data) { |
| 246 DCHECK(deterministic_); | 264 DCHECK(deterministic_); |
| 247 data_vector_.push_back(data); | 265 data_vector_.push_back(data); |
| 248 linked_ptr<SSLSocketDataProvider> ssl_( | 266 linked_ptr<SSLSocketDataProvider> ssl_( |
| 249 new SSLSocketDataProvider(true, OK)); | 267 new SSLSocketDataProvider(true, OK)); |
| 250 if (test_type_ == SPDYNPN) { | 268 if (test_type_ == SPDYNPN) { |
| 251 ssl_->next_proto_status = SSLClientSocket::kNextProtoNegotiated; | 269 ssl_->next_proto_status = SSLClientSocket::kNextProtoNegotiated; |
| 252 ssl_->next_proto = "spdy/2"; | 270 ssl_->next_proto = "spdy/2"; |
| 253 ssl_->was_npn_negotiated = true; | 271 ssl_->was_npn_negotiated = true; |
| 254 } | 272 } |
| 255 ssl_vector_.push_back(ssl_); | 273 ssl_vector_.push_back(ssl_); |
| 256 if(test_type_ == SPDYNPN || test_type_ == SPDYSSL) | 274 if (test_type_ == SPDYNPN || test_type_ == SPDYSSL) { |
| 257 session_deps_->deterministic_socket_factory-> | 275 session_deps_->deterministic_socket_factory-> |
| 258 AddSSLSocketDataProvider(ssl_.get()); | 276 AddSSLSocketDataProvider(ssl_.get()); |
| 277 } |
| 259 session_deps_->deterministic_socket_factory->AddSocketDataProvider(data); | 278 session_deps_->deterministic_socket_factory->AddSocketDataProvider(data); |
| 279 if (test_type_ == SPDYNPN) { |
| 280 MockConnect never_finishing_connect(false, ERR_IO_PENDING); |
| 281 scoped_refptr<DeterministicSocketData> |
| 282 hanging_non_alternate_protocol_socket( |
| 283 new DeterministicSocketData(NULL, 0, NULL, 0)); |
| 284 hanging_non_alternate_protocol_socket->set_connect_data( |
| 285 never_finishing_connect); |
| 286 session_deps_->deterministic_socket_factory->AddSocketDataProvider( |
| 287 hanging_non_alternate_protocol_socket); |
| 288 alternate_deterministic_vector_.push_back( |
| 289 hanging_non_alternate_protocol_socket); |
| 290 } |
| 260 } | 291 } |
| 261 | 292 |
| 262 // This can only be called after RunPreTestSetup. It adds a Data Provider, | 293 // This can only be called after RunPreTestSetup. It adds a Data Provider, |
| 263 // but not a corresponding SSL data provider | 294 // but not a corresponding SSL data provider |
| 264 void AddDataNoSSL(StaticSocketDataProvider* data) { | 295 void AddDataNoSSL(StaticSocketDataProvider* data) { |
| 265 DCHECK(!deterministic_); | 296 DCHECK(!deterministic_); |
| 266 session_deps_->socket_factory->AddSocketDataProvider(data); | 297 session_deps_->socket_factory->AddSocketDataProvider(data); |
| 267 } | 298 } |
| 268 void AddDataNoSSL(DeterministicSocketData* data) { | 299 void AddDataNoSSL(DeterministicSocketData* data) { |
| 269 DCHECK(deterministic_); | 300 DCHECK(deterministic_); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 282 } | 313 } |
| 283 scoped_ptr<SpdySessionDependencies>& session_deps() { | 314 scoped_ptr<SpdySessionDependencies>& session_deps() { |
| 284 return session_deps_; | 315 return session_deps_; |
| 285 } | 316 } |
| 286 int port() const { return port_; } | 317 int port() const { return port_; } |
| 287 SpdyNetworkTransactionTestTypes test_type() const { return test_type_; } | 318 SpdyNetworkTransactionTestTypes test_type() const { return test_type_; } |
| 288 | 319 |
| 289 private: | 320 private: |
| 290 typedef std::vector<StaticSocketDataProvider*> DataVector; | 321 typedef std::vector<StaticSocketDataProvider*> DataVector; |
| 291 typedef std::vector<linked_ptr<SSLSocketDataProvider> > SSLVector; | 322 typedef std::vector<linked_ptr<SSLSocketDataProvider> > SSLVector; |
| 323 typedef std::vector<linked_ptr<StaticSocketDataProvider> > AlternateVector; |
| 324 typedef std::vector<scoped_refptr<DeterministicSocketData> > |
| 325 AlternateDeterministicVector; |
| 292 HttpRequestInfo request_; | 326 HttpRequestInfo request_; |
| 293 scoped_ptr<SpdySessionDependencies> session_deps_; | 327 scoped_ptr<SpdySessionDependencies> session_deps_; |
| 294 scoped_refptr<HttpNetworkSession> session_; | 328 scoped_refptr<HttpNetworkSession> session_; |
| 295 TransactionHelperResult output_; | 329 TransactionHelperResult output_; |
| 296 scoped_ptr<StaticSocketDataProvider> first_transaction_; | 330 scoped_ptr<StaticSocketDataProvider> first_transaction_; |
| 297 SSLVector ssl_vector_; | 331 SSLVector ssl_vector_; |
| 298 TestCompletionCallback callback; | 332 TestCompletionCallback callback; |
| 299 scoped_ptr<HttpNetworkTransaction> trans_; | 333 scoped_ptr<HttpNetworkTransaction> trans_; |
| 300 scoped_ptr<HttpNetworkTransaction> trans_http_; | 334 scoped_ptr<HttpNetworkTransaction> trans_http_; |
| 301 DataVector data_vector_; | 335 DataVector data_vector_; |
| 336 AlternateVector alternate_vector_; |
| 337 AlternateDeterministicVector alternate_deterministic_vector_; |
| 302 const BoundNetLog& log_; | 338 const BoundNetLog& log_; |
| 303 SpdyNetworkTransactionTestTypes test_type_; | 339 SpdyNetworkTransactionTestTypes test_type_; |
| 304 int port_; | 340 int port_; |
| 305 bool deterministic_; | 341 bool deterministic_; |
| 306 bool spdy_enabled_; | 342 bool spdy_enabled_; |
| 307 }; | 343 }; |
| 308 | 344 |
| 309 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, | 345 void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 310 int expected_status); | 346 int expected_status); |
| 311 | 347 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 } | 504 } |
| 469 | 505 |
| 470 private: | 506 private: |
| 471 bool google_get_request_initialized_; | 507 bool google_get_request_initialized_; |
| 472 bool google_post_request_initialized_; | 508 bool google_post_request_initialized_; |
| 473 bool google_chunked_post_request_initialized_; | 509 bool google_chunked_post_request_initialized_; |
| 474 HttpRequestInfo google_get_request_; | 510 HttpRequestInfo google_get_request_; |
| 475 HttpRequestInfo google_post_request_; | 511 HttpRequestInfo google_post_request_; |
| 476 HttpRequestInfo google_chunked_post_request_; | 512 HttpRequestInfo google_chunked_post_request_; |
| 477 HttpRequestInfo google_get_push_request_; | 513 HttpRequestInfo google_get_push_request_; |
| 514 |
| 515 bool backup_jobs_prev_value_; |
| 478 }; | 516 }; |
| 479 | 517 |
| 480 //----------------------------------------------------------------------------- | 518 //----------------------------------------------------------------------------- |
| 481 // All tests are run with three different connection types: SPDY after NPN | 519 // All tests are run with three different connection types: SPDY after NPN |
| 482 // negotiation, SPDY without SSL, and SPDY with SSL. | 520 // negotiation, SPDY without SSL, and SPDY with SSL. |
| 483 INSTANTIATE_TEST_CASE_P(Spdy, | 521 INSTANTIATE_TEST_CASE_P(Spdy, |
| 484 SpdyNetworkTransactionTest, | 522 SpdyNetworkTransactionTest, |
| 485 ::testing::Values(SPDYNOSSL, SPDYSSL, SPDYNPN)); | 523 ::testing::Values(SPDYNOSSL, SPDYSSL, SPDYNPN)); |
| 486 | 524 |
| 487 | 525 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 CreateMockRead(*resp2, 4), | 735 CreateMockRead(*resp2, 4), |
| 698 CreateMockRead(*body2), | 736 CreateMockRead(*body2), |
| 699 CreateMockRead(*fbody), | 737 CreateMockRead(*fbody), |
| 700 CreateMockRead(*fbody2), | 738 CreateMockRead(*fbody2), |
| 701 MockRead(true, 0, 0), // EOF | 739 MockRead(true, 0, 0), // EOF |
| 702 }; | 740 }; |
| 703 scoped_refptr<OrderedSocketData> data( | 741 scoped_refptr<OrderedSocketData> data( |
| 704 new OrderedSocketData(reads, arraysize(reads), | 742 new OrderedSocketData(reads, arraysize(reads), |
| 705 writes, arraysize(writes))); | 743 writes, arraysize(writes))); |
| 706 | 744 |
| 707 MockConnect never_finishing_connect(true, ERR_IO_PENDING); | 745 MockConnect never_finishing_connect(false, ERR_IO_PENDING); |
| 708 | 746 |
| 709 scoped_refptr<OrderedSocketData> data_placeholder( | 747 scoped_refptr<OrderedSocketData> data_placeholder( |
| 710 new OrderedSocketData(NULL, 0, NULL, 0)); | 748 new OrderedSocketData(NULL, 0, NULL, 0)); |
| 711 data_placeholder->set_connect_data(never_finishing_connect); | 749 data_placeholder->set_connect_data(never_finishing_connect); |
| 712 | 750 |
| 713 BoundNetLog log; | 751 BoundNetLog log; |
| 714 TransactionHelperResult out; | 752 TransactionHelperResult out; |
| 715 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 753 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| 716 BoundNetLog(), GetParam()); | 754 BoundNetLog(), GetParam()); |
| 717 helper.RunPreTestSetup(); | 755 helper.RunPreTestSetup(); |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 886 scoped_ptr<spdy::SpdyFrame> fbody3(ConstructSpdyBodyFrame(5, true)); | 924 scoped_ptr<spdy::SpdyFrame> fbody3(ConstructSpdyBodyFrame(5, true)); |
| 887 | 925 |
| 888 spdy::SpdySettings settings; | 926 spdy::SpdySettings settings; |
| 889 spdy::SettingsFlagsAndId id(0); | 927 spdy::SettingsFlagsAndId id(0); |
| 890 id.set_id(spdy::SETTINGS_MAX_CONCURRENT_STREAMS); | 928 id.set_id(spdy::SETTINGS_MAX_CONCURRENT_STREAMS); |
| 891 const size_t max_concurrent_streams = 1; | 929 const size_t max_concurrent_streams = 1; |
| 892 | 930 |
| 893 settings.push_back(spdy::SpdySetting(id, max_concurrent_streams)); | 931 settings.push_back(spdy::SpdySetting(id, max_concurrent_streams)); |
| 894 scoped_ptr<spdy::SpdyFrame> settings_frame(ConstructSpdySettings(settings)); | 932 scoped_ptr<spdy::SpdyFrame> settings_frame(ConstructSpdySettings(settings)); |
| 895 | 933 |
| 896 MockWrite writes[] = { CreateMockWrite(*req), | 934 MockWrite writes[] = { |
| 897 CreateMockWrite(*req2), | 935 CreateMockWrite(*req), |
| 898 CreateMockWrite(*req3), | 936 CreateMockWrite(*req2), |
| 937 CreateMockWrite(*req3), |
| 899 }; | 938 }; |
| 939 |
| 900 MockRead reads[] = { | 940 MockRead reads[] = { |
| 901 CreateMockRead(*settings_frame, 1), | 941 CreateMockRead(*settings_frame, 1), |
| 902 CreateMockRead(*resp), | 942 CreateMockRead(*resp), |
| 903 CreateMockRead(*body), | 943 CreateMockRead(*body), |
| 904 CreateMockRead(*fbody), | 944 CreateMockRead(*fbody), |
| 905 CreateMockRead(*resp2, 7), | 945 CreateMockRead(*resp2, 7), |
| 906 CreateMockRead(*body2), | 946 CreateMockRead(*body2), |
| 907 CreateMockRead(*fbody2), | 947 CreateMockRead(*fbody2), |
| 908 CreateMockRead(*resp3, 12), | 948 CreateMockRead(*resp3, 12), |
| 909 CreateMockRead(*body3), | 949 CreateMockRead(*body3), |
| 910 CreateMockRead(*fbody3), | 950 CreateMockRead(*fbody3), |
| 911 | 951 |
| 912 MockRead(true, 0, 0), // EOF | 952 MockRead(true, 0, 0), // EOF |
| 913 }; | 953 }; |
| 914 | 954 |
| 915 scoped_refptr<OrderedSocketData> data( | 955 scoped_refptr<OrderedSocketData> data( |
| 916 new OrderedSocketData(reads, arraysize(reads), | 956 new OrderedSocketData(reads, arraysize(reads), |
| 917 writes, arraysize(writes))); | 957 writes, arraysize(writes))); |
| 918 scoped_refptr<OrderedSocketData> data_placeholder( | 958 scoped_refptr<OrderedSocketData> data_placeholder( |
| 919 new OrderedSocketData(NULL, 0, NULL, 0)); | 959 new OrderedSocketData(NULL, 0, NULL, 0)); |
| 920 | 960 |
| 921 BoundNetLog log; | 961 BoundNetLog log; |
| 922 TransactionHelperResult out; | 962 TransactionHelperResult out; |
| 923 { | 963 { |
| 924 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 964 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| 925 BoundNetLog(), GetParam()); | 965 BoundNetLog(), GetParam()); |
| 926 helper.RunPreTestSetup(); | 966 helper.RunPreTestSetup(); |
| 927 helper.AddData(data.get()); | 967 helper.AddData(data.get()); |
| 928 // We require placeholder data because three get requests are sent out, so | 968 // We require placeholder data because three get requests are sent out, so |
| 929 // there needs to be three sets of SSL connection data. | 969 // there needs to be three sets of SSL connection data. |
| 930 helper.AddData(data_placeholder.get()); | 970 helper.AddData(data_placeholder.get()); |
| 931 helper.AddData(data_placeholder.get()); | 971 helper.AddData(data_placeholder.get()); |
| 932 scoped_ptr<HttpNetworkTransaction> trans1( | 972 scoped_ptr<HttpNetworkTransaction> trans1( |
| 933 new HttpNetworkTransaction(helper.session())); | 973 new HttpNetworkTransaction(helper.session())); |
| 934 scoped_ptr<HttpNetworkTransaction> trans2( | 974 scoped_ptr<HttpNetworkTransaction> trans2( |
| 935 new HttpNetworkTransaction(helper.session())); | 975 new HttpNetworkTransaction(helper.session())); |
| 936 scoped_ptr<HttpNetworkTransaction> trans3( | 976 scoped_ptr<HttpNetworkTransaction> trans3( |
| 937 new HttpNetworkTransaction(helper.session())); | 977 new HttpNetworkTransaction(helper.session())); |
| 938 | 978 |
| 939 TestCompletionCallback callback1; | 979 TestCompletionCallback callback1; |
| 940 TestCompletionCallback callback2; | 980 TestCompletionCallback callback2; |
| 941 TestCompletionCallback callback3; | 981 TestCompletionCallback callback3; |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1709 }; | 1749 }; |
| 1710 | 1750 |
| 1711 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | 1751 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 1712 MockRead reads[] = { | 1752 MockRead reads[] = { |
| 1713 CreateMockRead(*resp.get(), 1, true), | 1753 CreateMockRead(*resp.get(), 1, true), |
| 1714 MockRead(true, 0, 0, 4) // EOF | 1754 MockRead(true, 0, 0, 4) // EOF |
| 1715 }; | 1755 }; |
| 1716 | 1756 |
| 1717 scoped_refptr<DeterministicSocketData> data( | 1757 scoped_refptr<DeterministicSocketData> data( |
| 1718 new DeterministicSocketData(reads, arraysize(reads), | 1758 new DeterministicSocketData(reads, arraysize(reads), |
| 1719 writes, arraysize(writes))); | 1759 writes, arraysize(writes))); |
| 1720 NormalSpdyTransactionHelper helper(CreateGetRequest(), | 1760 NormalSpdyTransactionHelper helper(CreateGetRequest(), |
| 1721 BoundNetLog(), GetParam()); | 1761 BoundNetLog(), GetParam()); |
| 1722 helper.SetDeterministic(); | 1762 helper.SetDeterministic(); |
| 1723 helper.RunPreTestSetup(); | 1763 helper.RunPreTestSetup(); |
| 1724 helper.AddDeterministicData(data.get()); | 1764 helper.AddDeterministicData(data.get()); |
| 1725 HttpNetworkTransaction* trans = helper.trans(); | 1765 HttpNetworkTransaction* trans = helper.trans(); |
| 1726 | 1766 |
| 1727 TestCompletionCallback callback; | 1767 TestCompletionCallback callback; |
| 1728 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); | 1768 int rv = trans->Start(&CreateGetRequest(), &callback, BoundNetLog()); |
| 1729 EXPECT_EQ(ERR_IO_PENDING, rv); | 1769 EXPECT_EQ(ERR_IO_PENDING, rv); |
| (...skipping 2070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3800 MessageLoop::current()->RunAllPending(); | 3840 MessageLoop::current()->RunAllPending(); |
| 3801 | 3841 |
| 3802 // Verify that we consumed all test data. | 3842 // Verify that we consumed all test data. |
| 3803 helper.VerifyDataConsumed(); | 3843 helper.VerifyDataConsumed(); |
| 3804 | 3844 |
| 3805 EXPECT_EQ(OK, out.rv); | 3845 EXPECT_EQ(OK, out.rv); |
| 3806 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); | 3846 EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 3807 EXPECT_EQ("goodbye world", out.response_data); | 3847 EXPECT_EQ("goodbye world", out.response_data); |
| 3808 } | 3848 } |
| 3809 | 3849 |
| 3810 TEST_P(SpdyNetworkTransactionTest, ConnectFailureFallbackToHttp) { | |
| 3811 MockConnect connects[] = { | |
| 3812 MockConnect(true, ERR_NAME_NOT_RESOLVED), | |
| 3813 MockConnect(false, ERR_NAME_NOT_RESOLVED), | |
| 3814 MockConnect(true, ERR_INTERNET_DISCONNECTED), | |
| 3815 MockConnect(false, ERR_INTERNET_DISCONNECTED) | |
| 3816 }; | |
| 3817 | |
| 3818 for (size_t index = 0; index < arraysize(connects); ++index) { | |
| 3819 scoped_ptr<spdy::SpdyFrame> req( | |
| 3820 ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | |
| 3821 MockWrite writes[] = { | |
| 3822 CreateMockWrite(*req), | |
| 3823 MockWrite(true, 0, 0) // EOF | |
| 3824 }; | |
| 3825 | |
| 3826 scoped_ptr<spdy::SpdyFrame> resp(ConstructSpdyGetSynReply(NULL, 0, 1)); | |
| 3827 scoped_ptr<spdy::SpdyFrame> body(ConstructSpdyBodyFrame(1, true)); | |
| 3828 MockRead reads[] = { | |
| 3829 CreateMockRead(*resp), | |
| 3830 CreateMockRead(*body), | |
| 3831 MockRead(true, 0, 0) // EOF | |
| 3832 }; | |
| 3833 | |
| 3834 scoped_refptr<DelayedSocketData> data( | |
| 3835 new DelayedSocketData(connects[index], 1, reads, arraysize(reads), | |
| 3836 writes, arraysize(writes))); | |
| 3837 NormalSpdyTransactionHelper helper(CreateGetRequest(), | |
| 3838 BoundNetLog(), GetParam()); | |
| 3839 helper.RunPreTestSetup(); | |
| 3840 helper.AddData(data.get()); | |
| 3841 | |
| 3842 // Set up http fallback data. | |
| 3843 MockRead http_fallback_data[] = { | |
| 3844 MockRead("HTTP/1.1 200 OK\r\n\r\n"), | |
| 3845 MockRead("hello world!!!"), | |
| 3846 MockRead(true, OK), | |
| 3847 }; | |
| 3848 | |
| 3849 scoped_ptr<StaticSocketDataProvider> http_fallback( | |
| 3850 new StaticSocketDataProvider(http_fallback_data, | |
| 3851 arraysize(http_fallback_data), | |
| 3852 NULL, 0)); | |
| 3853 helper.AddDataNoSSL(http_fallback.get()); | |
| 3854 HttpNetworkTransaction* trans = helper.trans(); | |
| 3855 TestCompletionCallback callback; | |
| 3856 | |
| 3857 int rv = trans->Start(&helper.request(), &callback, BoundNetLog()); | |
| 3858 EXPECT_EQ(rv, ERR_IO_PENDING); | |
| 3859 rv = callback.WaitForResult(); | |
| 3860 const HttpResponseInfo* response = trans->GetResponseInfo(); | |
| 3861 if (GetParam() == SPDYNOSSL || GetParam() == SPDYSSL) { | |
| 3862 ASSERT_TRUE(response == NULL); | |
| 3863 return; | |
| 3864 } | |
| 3865 if (GetParam() != SPDYNPN) | |
| 3866 NOTREACHED(); | |
| 3867 ASSERT_TRUE(response != NULL); | |
| 3868 ASSERT_TRUE(response->headers != NULL); | |
| 3869 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | |
| 3870 std::string response_data; | |
| 3871 rv = ReadTransaction(trans, &response_data); | |
| 3872 EXPECT_EQ(OK, rv); | |
| 3873 | |
| 3874 EXPECT_TRUE(!response->was_fetched_via_spdy); | |
| 3875 EXPECT_TRUE(!response->was_npn_negotiated); | |
| 3876 EXPECT_TRUE(response->was_alternate_protocol_available); | |
| 3877 EXPECT_TRUE(http_fallback->at_read_eof()); | |
| 3878 EXPECT_EQ(0u, data->read_index()); | |
| 3879 EXPECT_EQ(0u, data->write_index()); | |
| 3880 EXPECT_EQ("hello world!!!", response_data); | |
| 3881 } | |
| 3882 } | |
| 3883 | |
| 3884 // Verify that basic buffering works; when multiple data frames arrive | 3850 // Verify that basic buffering works; when multiple data frames arrive |
| 3885 // at the same time, ensure that we don't notify a read completion for | 3851 // at the same time, ensure that we don't notify a read completion for |
| 3886 // each data frame individually. | 3852 // each data frame individually. |
| 3887 TEST_P(SpdyNetworkTransactionTest, Buffering) { | 3853 TEST_P(SpdyNetworkTransactionTest, Buffering) { |
| 3888 spdy::SpdyFramer framer; | 3854 spdy::SpdyFramer framer; |
| 3889 | 3855 |
| 3890 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); | 3856 scoped_ptr<spdy::SpdyFrame> req(ConstructSpdyGet(NULL, 0, false, 1, LOWEST)); |
| 3891 MockWrite writes[] = { CreateMockWrite(*req) }; | 3857 MockWrite writes[] = { CreateMockWrite(*req) }; |
| 3892 | 3858 |
| 3893 // 4 data frames in a single read. | 3859 // 4 data frames in a single read. |
| (...skipping 1756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5650 | 5616 |
| 5651 VerifyStreamsClosed(helper); | 5617 VerifyStreamsClosed(helper); |
| 5652 | 5618 |
| 5653 // Verify the SYN_REPLY. | 5619 // Verify the SYN_REPLY. |
| 5654 EXPECT_TRUE(response.headers != NULL); | 5620 EXPECT_TRUE(response.headers != NULL); |
| 5655 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); | 5621 EXPECT_EQ("HTTP/1.1 200 OK", response.headers->GetStatusLine()); |
| 5656 } | 5622 } |
| 5657 } | 5623 } |
| 5658 | 5624 |
| 5659 } // namespace net | 5625 } // namespace net |
| OLD | NEW |