| 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 "net/url_request/url_request_test_util.h" | 5 #include "net/url_request/url_request_test_util.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "base/threading/worker_pool.h" | 17 #include "base/threading/worker_pool.h" |
| 18 #include "net/base/host_port_pair.h" | 18 #include "net/base/host_port_pair.h" |
| 19 #include "net/cert/cert_verifier.h" | 19 #include "net/cert/cert_verifier.h" |
| 20 #include "net/cert/ct_verifier.h" | 20 #include "net/cert/ct_policy_enforcer.h" |
| 21 #include "net/cert/multi_log_ct_verifier.h" |
| 21 #include "net/dns/mock_host_resolver.h" | 22 #include "net/dns/mock_host_resolver.h" |
| 22 #include "net/http/http_network_session.h" | 23 #include "net/http/http_network_session.h" |
| 23 #include "net/http/http_response_headers.h" | 24 #include "net/http/http_response_headers.h" |
| 24 #include "net/http/http_server_properties_impl.h" | 25 #include "net/http/http_server_properties_impl.h" |
| 25 #include "net/http/transport_security_state.h" | 26 #include "net/http/transport_security_state.h" |
| 26 #include "net/proxy/proxy_retry_info.h" | 27 #include "net/proxy/proxy_retry_info.h" |
| 27 #include "net/ssl/channel_id_service.h" | 28 #include "net/ssl/channel_id_service.h" |
| 28 #include "net/ssl/default_channel_id_store.h" | 29 #include "net/ssl/default_channel_id_store.h" |
| 29 #include "net/url_request/static_http_user_agent_settings.h" | 30 #include "net/url_request/static_http_user_agent_settings.h" |
| 30 #include "net/url_request/url_request_job.h" | 31 #include "net/url_request/url_request_job.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 49 const int kStageCompletedSuccess = 1 << 7; | 50 const int kStageCompletedSuccess = 1 << 7; |
| 50 const int kStageCompletedError = 1 << 8; | 51 const int kStageCompletedError = 1 << 8; |
| 51 const int kStageURLRequestDestroyed = 1 << 9; | 52 const int kStageURLRequestDestroyed = 1 << 9; |
| 52 const int kStageDestruction = 1 << 10; | 53 const int kStageDestruction = 1 << 10; |
| 53 | 54 |
| 54 } // namespace | 55 } // namespace |
| 55 | 56 |
| 56 TestURLRequestContext::TestURLRequestContext() : TestURLRequestContext(false) {} | 57 TestURLRequestContext::TestURLRequestContext() : TestURLRequestContext(false) {} |
| 57 | 58 |
| 58 TestURLRequestContext::TestURLRequestContext(bool delay_initialization) | 59 TestURLRequestContext::TestURLRequestContext(bool delay_initialization) |
| 59 : initialized_(false), | 60 : context_storage_(this) { |
| 60 client_socket_factory_(nullptr), | |
| 61 proxy_delegate_(nullptr), | |
| 62 ct_policy_enforcer_(nullptr), | |
| 63 context_storage_(this) { | |
| 64 if (!delay_initialization) | 61 if (!delay_initialization) |
| 65 Init(); | 62 Init(); |
| 66 } | 63 } |
| 67 | 64 |
| 68 TestURLRequestContext::~TestURLRequestContext() { | 65 TestURLRequestContext::~TestURLRequestContext() { |
| 69 DCHECK(initialized_); | 66 DCHECK(initialized_); |
| 70 AssertNoURLRequests(); | 67 AssertNoURLRequests(); |
| 71 } | 68 } |
| 72 | 69 |
| 73 void TestURLRequestContext::Init() { | 70 void TestURLRequestContext::Init() { |
| 74 DCHECK(!initialized_); | 71 DCHECK(!initialized_); |
| 75 initialized_ = true; | 72 initialized_ = true; |
| 76 | 73 |
| 77 if (!host_resolver()) | 74 if (!host_resolver()) |
| 78 context_storage_.set_host_resolver( | 75 context_storage_.set_host_resolver( |
| 79 std::unique_ptr<HostResolver>(new MockCachingHostResolver())); | 76 std::unique_ptr<HostResolver>(new MockCachingHostResolver())); |
| 80 if (!proxy_service()) | 77 if (!proxy_service()) |
| 81 context_storage_.set_proxy_service(ProxyService::CreateDirect()); | 78 context_storage_.set_proxy_service(ProxyService::CreateDirect()); |
| 82 if (!cert_verifier()) | 79 if (!cert_verifier()) |
| 83 context_storage_.set_cert_verifier(CertVerifier::CreateDefault()); | 80 context_storage_.set_cert_verifier(CertVerifier::CreateDefault()); |
| 84 if (!transport_security_state()) | 81 if (!transport_security_state()) { |
| 85 context_storage_.set_transport_security_state( | 82 context_storage_.set_transport_security_state( |
| 86 base::WrapUnique(new TransportSecurityState())); | 83 base::WrapUnique(new TransportSecurityState())); |
| 84 } |
| 85 if (!cert_transparency_verifier()) { |
| 86 context_storage_.set_cert_transparency_verifier( |
| 87 base::WrapUnique(new MultiLogCTVerifier())); |
| 88 } |
| 89 if (!ct_policy_enforcer()) { |
| 90 context_storage_.set_ct_policy_enforcer( |
| 91 base::WrapUnique(new CTPolicyEnforcer)); |
| 92 } |
| 87 if (!ssl_config_service()) | 93 if (!ssl_config_service()) |
| 88 context_storage_.set_ssl_config_service(new SSLConfigServiceDefaults()); | 94 context_storage_.set_ssl_config_service(new SSLConfigServiceDefaults()); |
| 89 if (!http_auth_handler_factory()) { | 95 if (!http_auth_handler_factory()) { |
| 90 context_storage_.set_http_auth_handler_factory( | 96 context_storage_.set_http_auth_handler_factory( |
| 91 HttpAuthHandlerFactory::CreateDefault(host_resolver())); | 97 HttpAuthHandlerFactory::CreateDefault(host_resolver())); |
| 92 } | 98 } |
| 93 if (!http_server_properties()) { | 99 if (!http_server_properties()) { |
| 94 context_storage_.set_http_server_properties( | 100 context_storage_.set_http_server_properties( |
| 95 std::unique_ptr<HttpServerProperties>(new HttpServerPropertiesImpl())); | 101 std::unique_ptr<HttpServerProperties>(new HttpServerPropertiesImpl())); |
| 96 } | 102 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 112 } else { | 118 } else { |
| 113 HttpNetworkSession::Params params; | 119 HttpNetworkSession::Params params; |
| 114 | 120 |
| 115 if (http_network_session_params_) | 121 if (http_network_session_params_) |
| 116 params = *http_network_session_params_; | 122 params = *http_network_session_params_; |
| 117 params.client_socket_factory = client_socket_factory(); | 123 params.client_socket_factory = client_socket_factory(); |
| 118 params.proxy_delegate = proxy_delegate(); | 124 params.proxy_delegate = proxy_delegate(); |
| 119 params.host_resolver = host_resolver(); | 125 params.host_resolver = host_resolver(); |
| 120 params.cert_verifier = cert_verifier(); | 126 params.cert_verifier = cert_verifier(); |
| 121 params.cert_transparency_verifier = cert_transparency_verifier(); | 127 params.cert_transparency_verifier = cert_transparency_verifier(); |
| 122 if (ct_policy_enforcer()) | 128 params.ct_policy_enforcer = ct_policy_enforcer(); |
| 123 params.ct_policy_enforcer = ct_policy_enforcer(); | |
| 124 params.transport_security_state = transport_security_state(); | 129 params.transport_security_state = transport_security_state(); |
| 125 params.proxy_service = proxy_service(); | 130 params.proxy_service = proxy_service(); |
| 126 params.ssl_config_service = ssl_config_service(); | 131 params.ssl_config_service = ssl_config_service(); |
| 127 params.http_auth_handler_factory = http_auth_handler_factory(); | 132 params.http_auth_handler_factory = http_auth_handler_factory(); |
| 128 params.http_server_properties = http_server_properties(); | 133 params.http_server_properties = http_server_properties(); |
| 129 params.net_log = net_log(); | 134 params.net_log = net_log(); |
| 130 params.channel_id_service = channel_id_service(); | 135 params.channel_id_service = channel_id_service(); |
| 131 context_storage_.set_http_network_session( | 136 context_storage_.set_http_network_session( |
| 132 base::WrapUnique(new HttpNetworkSession(params))); | 137 base::WrapUnique(new HttpNetworkSession(params))); |
| 133 context_storage_.set_http_transaction_factory(base::WrapUnique( | 138 context_storage_.set_http_transaction_factory(base::WrapUnique( |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 NetworkDelegate* network_delegate) const { | 670 NetworkDelegate* network_delegate) const { |
| 666 return main_intercept_job_.release(); | 671 return main_intercept_job_.release(); |
| 667 } | 672 } |
| 668 | 673 |
| 669 void TestJobInterceptor::set_main_intercept_job( | 674 void TestJobInterceptor::set_main_intercept_job( |
| 670 std::unique_ptr<URLRequestJob> job) { | 675 std::unique_ptr<URLRequestJob> job) { |
| 671 main_intercept_job_ = std::move(job); | 676 main_intercept_job_ = std::move(job); |
| 672 } | 677 } |
| 673 | 678 |
| 674 } // namespace net | 679 } // namespace net |
| OLD | NEW |