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 15 matching lines...) Expand all Loading... | |
26 #include "net/http/http_transaction_test_util.h" | 26 #include "net/http/http_transaction_test_util.h" |
27 #include "net/socket/client_socket_pool_base.h" | 27 #include "net/socket/client_socket_pool_base.h" |
28 #include "net/socket/next_proto.h" | 28 #include "net/socket/next_proto.h" |
29 #include "net/spdy/buffered_spdy_framer.h" | 29 #include "net/spdy/buffered_spdy_framer.h" |
30 #include "net/spdy/spdy_http_stream.h" | 30 #include "net/spdy/spdy_http_stream.h" |
31 #include "net/spdy/spdy_http_utils.h" | 31 #include "net/spdy/spdy_http_utils.h" |
32 #include "net/spdy/spdy_session.h" | 32 #include "net/spdy/spdy_session.h" |
33 #include "net/spdy/spdy_session_pool.h" | 33 #include "net/spdy/spdy_session_pool.h" |
34 #include "net/spdy/spdy_test_util_common.h" | 34 #include "net/spdy/spdy_test_util_common.h" |
35 #include "net/spdy/spdy_test_utils.h" | 35 #include "net/spdy/spdy_test_utils.h" |
36 #include "net/ssl/ssl_connection_status_flags.h" | |
36 #include "net/url_request/url_request_test_util.h" | 37 #include "net/url_request/url_request_test_util.h" |
37 #include "testing/gmock/include/gmock/gmock.h" | 38 #include "testing/gmock/include/gmock/gmock.h" |
38 #include "testing/platform_test.h" | 39 #include "testing/platform_test.h" |
39 | 40 |
40 //----------------------------------------------------------------------------- | 41 //----------------------------------------------------------------------------- |
41 | 42 |
42 namespace net { | 43 namespace net { |
43 | 44 |
44 namespace { | 45 namespace { |
45 | 46 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 // Start the transaction, read some data, finish. | 211 // Start the transaction, read some data, finish. |
211 void RunDefaultTest() { | 212 void RunDefaultTest() { |
212 LOG(INFO) << __FUNCTION__; | 213 LOG(INFO) << __FUNCTION__; |
213 if (!StartDefaultTest()) | 214 if (!StartDefaultTest()) |
214 return; | 215 return; |
215 FinishDefaultTest(); | 216 FinishDefaultTest(); |
216 LOG(INFO) << __FUNCTION__; | 217 LOG(INFO) << __FUNCTION__; |
217 } | 218 } |
218 | 219 |
219 bool StartDefaultTest() { | 220 bool StartDefaultTest() { |
220 output_.rv = trans_->Start(&request_, callback.callback(), log_); | 221 output_.rv = trans_->Start(&request_, callback_.callback(), log_); |
221 | 222 |
222 // We expect an IO Pending or some sort of error. | 223 // We expect an IO Pending or some sort of error. |
223 EXPECT_LT(output_.rv, 0); | 224 EXPECT_LT(output_.rv, 0); |
224 return output_.rv == ERR_IO_PENDING; | 225 return output_.rv == ERR_IO_PENDING; |
225 } | 226 } |
226 | 227 |
227 void FinishDefaultTest() { | 228 void FinishDefaultTest() { |
228 output_.rv = callback.WaitForResult(); | 229 output_.rv = callback_.WaitForResult(); |
229 if (output_.rv != OK) { | 230 if (output_.rv != OK) { |
230 session_->spdy_session_pool()->CloseCurrentSessions(net::ERR_ABORTED); | 231 session_->spdy_session_pool()->CloseCurrentSessions(net::ERR_ABORTED); |
231 return; | 232 return; |
232 } | 233 } |
233 | 234 |
234 // Verify responses. | 235 // Verify responses. |
235 const HttpResponseInfo* response = trans_->GetResponseInfo(); | 236 const HttpResponseInfo* response = trans_->GetResponseInfo(); |
236 ASSERT_TRUE(response != NULL); | 237 ASSERT_TRUE(response != NULL); |
237 ASSERT_TRUE(response->headers.get() != NULL); | 238 ASSERT_TRUE(response->headers.get() != NULL); |
238 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 239 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
298 } | 299 } |
299 } | 300 } |
300 | 301 |
301 void RunToCompletion(StaticSocketDataProvider* data) { | 302 void RunToCompletion(StaticSocketDataProvider* data) { |
302 RunPreTestSetup(); | 303 RunPreTestSetup(); |
303 AddData(data); | 304 AddData(data); |
304 RunDefaultTest(); | 305 RunDefaultTest(); |
305 VerifyDataConsumed(); | 306 VerifyDataConsumed(); |
306 } | 307 } |
307 | 308 |
309 void RunToCompletionWithSSLData( | |
310 StaticSocketDataProvider* data, | |
311 scoped_ptr<SSLSocketDataProvider> ssl_provider) { | |
312 RunPreTestSetup(); | |
313 AddDataWithSSLSocketDataProvider(data, ssl_provider.Pass()); | |
314 RunDefaultTest(); | |
315 VerifyDataConsumed(); | |
316 } | |
317 | |
308 void AddData(StaticSocketDataProvider* data) { | 318 void AddData(StaticSocketDataProvider* data) { |
319 scoped_ptr<SSLSocketDataProvider> ssl_provider( | |
320 new SSLSocketDataProvider(ASYNC, OK)); | |
321 AddDataWithSSLSocketDataProvider(data, ssl_provider.Pass()); | |
322 } | |
323 | |
324 void AddDataWithSSLSocketDataProvider( | |
325 StaticSocketDataProvider* data, | |
326 scoped_ptr<SSLSocketDataProvider> ssl_provider) { | |
309 DCHECK(!deterministic_); | 327 DCHECK(!deterministic_); |
310 data_vector_.push_back(data); | 328 data_vector_.push_back(data); |
311 SSLSocketDataProvider* ssl_provider = | |
312 new SSLSocketDataProvider(ASYNC, OK); | |
313 if (test_params_.ssl_type == SPDYNPN) | 329 if (test_params_.ssl_type == SPDYNPN) |
314 ssl_provider->SetNextProto(test_params_.protocol); | 330 ssl_provider->SetNextProto(test_params_.protocol); |
315 | 331 |
316 ssl_vector_.push_back(ssl_provider); | 332 if (test_params_.ssl_type == SPDYNPN || |
317 if (test_params_.ssl_type == SPDYNPN || test_params_.ssl_type == SPDYSSL) | 333 test_params_.ssl_type == SPDYSSL) { |
318 session_deps_->socket_factory->AddSSLSocketDataProvider(ssl_provider); | 334 session_deps_->socket_factory->AddSSLSocketDataProvider( |
335 ssl_provider.get()); | |
336 } | |
337 ssl_vector_.push_back(ssl_provider.release()); | |
319 | 338 |
320 session_deps_->socket_factory->AddSocketDataProvider(data); | 339 session_deps_->socket_factory->AddSocketDataProvider(data); |
321 if (test_params_.ssl_type == SPDYNPN) { | 340 if (test_params_.ssl_type == SPDYNPN) { |
322 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); | 341 MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
323 StaticSocketDataProvider* hanging_non_alternate_protocol_socket = | 342 StaticSocketDataProvider* hanging_non_alternate_protocol_socket = |
324 new StaticSocketDataProvider(NULL, 0, NULL, 0); | 343 new StaticSocketDataProvider(NULL, 0, NULL, 0); |
325 hanging_non_alternate_protocol_socket->set_connect_data( | 344 hanging_non_alternate_protocol_socket->set_connect_data( |
326 never_finishing_connect); | 345 never_finishing_connect); |
327 session_deps_->socket_factory->AddSocketDataProvider( | 346 session_deps_->socket_factory->AddSocketDataProvider( |
328 hanging_non_alternate_protocol_socket); | 347 hanging_non_alternate_protocol_socket); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 typedef ScopedVector<SSLSocketDataProvider> SSLVector; | 400 typedef ScopedVector<SSLSocketDataProvider> SSLVector; |
382 typedef ScopedVector<StaticSocketDataProvider> AlternateVector; | 401 typedef ScopedVector<StaticSocketDataProvider> AlternateVector; |
383 typedef ScopedVector<DeterministicSocketData> AlternateDeterministicVector; | 402 typedef ScopedVector<DeterministicSocketData> AlternateDeterministicVector; |
384 HttpRequestInfo request_; | 403 HttpRequestInfo request_; |
385 RequestPriority priority_; | 404 RequestPriority priority_; |
386 scoped_ptr<SpdySessionDependencies> session_deps_; | 405 scoped_ptr<SpdySessionDependencies> session_deps_; |
387 scoped_refptr<HttpNetworkSession> session_; | 406 scoped_refptr<HttpNetworkSession> session_; |
388 TransactionHelperResult output_; | 407 TransactionHelperResult output_; |
389 scoped_ptr<StaticSocketDataProvider> first_transaction_; | 408 scoped_ptr<StaticSocketDataProvider> first_transaction_; |
390 SSLVector ssl_vector_; | 409 SSLVector ssl_vector_; |
391 TestCompletionCallback callback; | 410 TestCompletionCallback callback_; |
392 scoped_ptr<HttpNetworkTransaction> trans_; | 411 scoped_ptr<HttpNetworkTransaction> trans_; |
393 scoped_ptr<HttpNetworkTransaction> trans_http_; | 412 scoped_ptr<HttpNetworkTransaction> trans_http_; |
394 DataVector data_vector_; | 413 DataVector data_vector_; |
395 AlternateVector alternate_vector_; | 414 AlternateVector alternate_vector_; |
396 AlternateDeterministicVector alternate_deterministic_vector_; | 415 AlternateDeterministicVector alternate_deterministic_vector_; |
397 const BoundNetLog& log_; | 416 const BoundNetLog& log_; |
398 SpdyNetworkTransactionTestParams test_params_; | 417 SpdyNetworkTransactionTestParams test_params_; |
399 int port_; | 418 int port_; |
400 bool deterministic_; | 419 bool deterministic_; |
401 bool spdy_enabled_; | 420 bool spdy_enabled_; |
(...skipping 6170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6572 // But the body is not yet fully sent (kUploadData is not yet sent) | 6591 // But the body is not yet fully sent (kUploadData is not yet sent) |
6573 // since we're send-stalled. | 6592 // since we're send-stalled. |
6574 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); | 6593 EXPECT_TRUE(stream->stream()->send_stalled_by_flow_control()); |
6575 | 6594 |
6576 // Read in WINDOW_UPDATE or SETTINGS frame. | 6595 // Read in WINDOW_UPDATE or SETTINGS frame. |
6577 data.RunFor((GetParam().protocol >= kProtoSPDY31) ? 9 : 8); | 6596 data.RunFor((GetParam().protocol >= kProtoSPDY31) ? 9 : 8); |
6578 rv = callback.WaitForResult(); | 6597 rv = callback.WaitForResult(); |
6579 helper.VerifyDataConsumed(); | 6598 helper.VerifyDataConsumed(); |
6580 } | 6599 } |
6581 | 6600 |
6601 typedef SpdyNetworkTransactionTest SpdyNetworkTransactionSSLTest; | |
6602 | |
6603 //----------------------------------------------------------------------------- | |
6604 // All tests are run with three different connection types: SPDY after NPN | |
6605 // negotiation, SPDY without SSL, and SPDY with SSL. | |
6606 // | |
6607 // TODO(akalin): Use ::testing::Combine() when we are able to use | |
6608 // <tr1/tuple>. | |
6609 INSTANTIATE_TEST_CASE_P( | |
6610 Spdy, | |
6611 SpdyNetworkTransactionSSLTest, | |
6612 ::testing::Values(SpdyNetworkTransactionTestParams(kProtoDeprecatedSPDY2, | |
6613 SPDYNPN), | |
6614 SpdyNetworkTransactionTestParams(kProtoSPDY3, SPDYNPN), | |
6615 SpdyNetworkTransactionTestParams(kProtoSPDY31, SPDYNPN), | |
6616 SpdyNetworkTransactionTestParams(kProtoSPDY4, SPDYNPN))); | |
6617 | |
6618 TEST_P(SpdyNetworkTransactionSSLTest, TLSVersionTooOld) { | |
6619 // TODO(willchan): Fix crbug.com/375033 to send GOAWAYs. | |
6620 // scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway()); | |
6621 // MockWrite writes[] = { | |
6622 // CreateMockWrite(*goaway) | |
6623 // }; | |
6624 | |
agl
2014/05/20 02:45:13
This blank line should probably appear under the c
| |
6625 // DelayedSocketData data(1, NULL, 0, writes, arraysize(writes)); | |
6626 DelayedSocketData data(1, NULL, 0, NULL, 0); | |
6627 HttpRequestInfo request; | |
6628 request.method = "GET"; | |
6629 request.url = GURL("https://www.google.com/"); | |
6630 NormalSpdyTransactionHelper helper( | |
6631 request, DEFAULT_PRIORITY, BoundNetLog(), GetParam(), NULL); | |
6632 scoped_ptr<SSLSocketDataProvider> ssl_provider( | |
6633 new SSLSocketDataProvider(ASYNC, OK)); | |
6634 SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_SSL3, | |
6635 &ssl_provider->connection_status); | |
6636 helper.RunToCompletionWithSSLData(&data, ssl_provider.Pass()); | |
6637 TransactionHelperResult out = helper.output(); | |
6638 EXPECT_EQ(ERR_SPDY_PROTOCOL_ERROR, out.rv); | |
6639 } | |
6640 | |
6582 } // namespace net | 6641 } // namespace net |
OLD | NEW |