OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/spdy/spdy_test_util_common.h" | 5 #include "net/spdy/spdy_test_util_common.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <cstddef> | 9 #include <cstddef> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
17 #include "net/base/host_port_pair.h" | 17 #include "net/base/host_port_pair.h" |
18 #include "net/cert/ct_policy_enforcer.h" | 18 #include "net/cert/ct_policy_enforcer.h" |
19 #include "net/cert/ct_policy_status.h" | 19 #include "net/cert/ct_policy_status.h" |
20 #include "net/cert/do_nothing_ct_verifier.h" | 20 #include "net/cert/do_nothing_ct_verifier.h" |
21 #include "net/cert/mock_cert_verifier.h" | 21 #include "net/cert/mock_cert_verifier.h" |
22 #include "net/cert/signed_certificate_timestamp_and_status.h" | 22 #include "net/cert/signed_certificate_timestamp_and_status.h" |
23 #include "net/http/http_cache.h" | 23 #include "net/http/http_cache.h" |
24 #include "net/http/http_network_session.h" | 24 #include "net/http/http_network_session.h" |
25 #include "net/http/http_network_transaction.h" | 25 #include "net/http/http_network_transaction.h" |
26 #include "net/http/http_server_properties_impl.h" | 26 #include "net/http/http_server_properties_impl.h" |
27 #include "net/log/net_log_with_source.h" | 27 #include "net/log/net_log_with_source.h" |
| 28 #include "net/socket/client_socket_handle.h" |
28 #include "net/socket/next_proto.h" | 29 #include "net/socket/next_proto.h" |
29 #include "net/socket/socket_test_util.h" | 30 #include "net/socket/socket_test_util.h" |
30 #include "net/socket/ssl_client_socket.h" | 31 #include "net/socket/ssl_client_socket.h" |
31 #include "net/socket/transport_client_socket_pool.h" | 32 #include "net/socket/transport_client_socket_pool.h" |
32 #include "net/spdy/buffered_spdy_framer.h" | 33 #include "net/spdy/buffered_spdy_framer.h" |
33 #include "net/spdy/spdy_alt_svc_wire_format.h" | 34 #include "net/spdy/spdy_alt_svc_wire_format.h" |
34 #include "net/spdy/spdy_framer.h" | 35 #include "net/spdy/spdy_framer.h" |
35 #include "net/spdy/spdy_http_utils.h" | 36 #include "net/spdy/spdy_http_utils.h" |
36 #include "net/spdy/spdy_session.h" | 37 #include "net/spdy/spdy_session.h" |
37 #include "net/spdy/spdy_session_pool.h" | 38 #include "net/spdy/spdy_session_pool.h" |
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 storage_.set_http_transaction_factory(base::MakeUnique<HttpCache>( | 478 storage_.set_http_transaction_factory(base::MakeUnique<HttpCache>( |
478 storage_.http_network_session(), HttpCache::DefaultBackend::InMemory(0), | 479 storage_.http_network_session(), HttpCache::DefaultBackend::InMemory(0), |
479 false)); | 480 false)); |
480 } | 481 } |
481 | 482 |
482 SpdyURLRequestContext::~SpdyURLRequestContext() { | 483 SpdyURLRequestContext::~SpdyURLRequestContext() { |
483 AssertNoURLRequests(); | 484 AssertNoURLRequests(); |
484 } | 485 } |
485 | 486 |
486 bool HasSpdySession(SpdySessionPool* pool, const SpdySessionKey& key) { | 487 bool HasSpdySession(SpdySessionPool* pool, const SpdySessionKey& key) { |
487 return static_cast<bool>( | 488 return static_cast<bool>(pool->FindAvailableSession( |
488 pool->FindAvailableSession(key, GURL(), NetLogWithSource())); | 489 key, GURL(), |
| 490 /* enable_ip_based_pooling = */ true, NetLogWithSource())); |
489 } | 491 } |
490 | 492 |
491 namespace { | 493 namespace { |
492 | 494 |
493 base::WeakPtr<SpdySession> CreateSpdySessionHelper( | 495 base::WeakPtr<SpdySession> CreateSpdySessionHelper( |
494 HttpNetworkSession* http_session, | 496 HttpNetworkSession* http_session, |
495 const SpdySessionKey& key, | 497 const SpdySessionKey& key, |
496 const NetLogWithSource& net_log, | 498 const NetLogWithSource& net_log, |
497 Error expected_status, | 499 Error expected_status, |
498 bool is_secure) { | 500 bool is_secure, |
499 EXPECT_FALSE(HasSpdySession(http_session->spdy_session_pool(), key)); | 501 bool enable_ip_based_pooling) { |
| 502 EXPECT_FALSE(http_session->spdy_session_pool()->FindAvailableSession( |
| 503 key, GURL(), enable_ip_based_pooling, NetLogWithSource())); |
500 | 504 |
501 scoped_refptr<TransportSocketParams> transport_params( | 505 scoped_refptr<TransportSocketParams> transport_params( |
502 new TransportSocketParams( | 506 new TransportSocketParams( |
503 key.host_port_pair(), false, OnHostResolutionCallback(), | 507 key.host_port_pair(), false, OnHostResolutionCallback(), |
504 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); | 508 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); |
505 | 509 |
506 std::unique_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | 510 std::unique_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
507 TestCompletionCallback callback; | 511 TestCompletionCallback callback; |
508 | 512 |
509 int rv = ERR_UNEXPECTED; | 513 int rv = ERR_UNEXPECTED; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 EXPECT_TRUE(HasSpdySession(http_session->spdy_session_pool(), key)); | 549 EXPECT_TRUE(HasSpdySession(http_session->spdy_session_pool(), key)); |
546 return spdy_session; | 550 return spdy_session; |
547 } | 551 } |
548 | 552 |
549 } // namespace | 553 } // namespace |
550 | 554 |
551 base::WeakPtr<SpdySession> CreateInsecureSpdySession( | 555 base::WeakPtr<SpdySession> CreateInsecureSpdySession( |
552 HttpNetworkSession* http_session, | 556 HttpNetworkSession* http_session, |
553 const SpdySessionKey& key, | 557 const SpdySessionKey& key, |
554 const NetLogWithSource& net_log) { | 558 const NetLogWithSource& net_log) { |
555 return CreateSpdySessionHelper(http_session, key, net_log, | 559 return CreateSpdySessionHelper(http_session, key, net_log, OK, |
556 OK, false /* is_secure */); | 560 /* is_secure = */ false, |
| 561 /* enable_ip_based_pooling = */ true); |
557 } | 562 } |
558 | 563 |
559 base::WeakPtr<SpdySession> TryCreateSpdySessionExpectingFailure( | 564 base::WeakPtr<SpdySession> TryCreateSpdySessionExpectingFailure( |
560 HttpNetworkSession* http_session, | 565 HttpNetworkSession* http_session, |
561 const SpdySessionKey& key, | 566 const SpdySessionKey& key, |
562 Error expected_error, | 567 Error expected_error, |
563 const NetLogWithSource& net_log) { | 568 const NetLogWithSource& net_log) { |
564 DCHECK_LT(expected_error, ERR_IO_PENDING); | 569 DCHECK_LT(expected_error, ERR_IO_PENDING); |
565 return CreateSpdySessionHelper(http_session, key, net_log, expected_error, | 570 return CreateSpdySessionHelper(http_session, key, net_log, expected_error, |
566 true /* is_secure */); | 571 /* is_secure = */ true, |
| 572 /* enable_ip_based_pooling = */ true); |
567 } | 573 } |
568 | 574 |
569 base::WeakPtr<SpdySession> CreateSecureSpdySession( | 575 base::WeakPtr<SpdySession> CreateSecureSpdySession( |
570 HttpNetworkSession* http_session, | 576 HttpNetworkSession* http_session, |
571 const SpdySessionKey& key, | 577 const SpdySessionKey& key, |
572 const NetLogWithSource& net_log) { | 578 const NetLogWithSource& net_log) { |
573 return CreateSpdySessionHelper(http_session, key, net_log, | 579 return CreateSpdySessionHelper(http_session, key, net_log, OK, |
574 OK, true /* is_secure */); | 580 /* is_secure = */ true, |
| 581 /* enable_ip_based_pooling = */ true); |
| 582 } |
| 583 |
| 584 base::WeakPtr<SpdySession> CreateSecureSpdySessionWithIpBasedPoolingDisabled( |
| 585 HttpNetworkSession* http_session, |
| 586 const SpdySessionKey& key, |
| 587 const NetLogWithSource& net_log) { |
| 588 return CreateSpdySessionHelper(http_session, key, net_log, OK, |
| 589 /* is_secure = */ true, |
| 590 /* enable_ip_based_pooling = */ false); |
575 } | 591 } |
576 | 592 |
577 namespace { | 593 namespace { |
578 | 594 |
579 // A ClientSocket used for CreateFakeSpdySession() below. | 595 // A ClientSocket used for CreateFakeSpdySession() below. |
580 class FakeSpdySessionClientSocket : public MockClientSocket { | 596 class FakeSpdySessionClientSocket : public MockClientSocket { |
581 public: | 597 public: |
582 explicit FakeSpdySessionClientSocket(int read_result) | 598 explicit FakeSpdySessionClientSocket(int read_result) |
583 : MockClientSocket(NetLogWithSource()), read_result_(read_result) {} | 599 : MockClientSocket(NetLogWithSource()), read_result_(read_result) {} |
584 | 600 |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 headers[GetSchemeKey()] = scheme.c_str(); | 1157 headers[GetSchemeKey()] = scheme.c_str(); |
1142 headers[GetPathKey()] = path.c_str(); | 1158 headers[GetPathKey()] = path.c_str(); |
1143 if (content_length) { | 1159 if (content_length) { |
1144 std::string length_str = base::Int64ToString(*content_length); | 1160 std::string length_str = base::Int64ToString(*content_length); |
1145 headers["content-length"] = length_str; | 1161 headers["content-length"] = length_str; |
1146 } | 1162 } |
1147 return headers; | 1163 return headers; |
1148 } | 1164 } |
1149 | 1165 |
1150 } // namespace net | 1166 } // namespace net |
OLD | NEW |