Chromium Code Reviews| 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/ssl/channel_id_service.h" | 27 #include "net/ssl/channel_id_service.h" |
| 27 #include "net/ssl/default_channel_id_store.h" | 28 #include "net/ssl/default_channel_id_store.h" |
| 28 #include "net/url_request/static_http_user_agent_settings.h" | 29 #include "net/url_request/static_http_user_agent_settings.h" |
| 29 #include "net/url_request/url_request_job.h" | 30 #include "net/url_request/url_request_job.h" |
| 30 #include "net/url_request/url_request_job_factory_impl.h" | 31 #include "net/url_request/url_request_job_factory_impl.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 48 const int kStageCompletedSuccess = 1 << 7; | 49 const int kStageCompletedSuccess = 1 << 7; |
| 49 const int kStageCompletedError = 1 << 8; | 50 const int kStageCompletedError = 1 << 8; |
| 50 const int kStageURLRequestDestroyed = 1 << 9; | 51 const int kStageURLRequestDestroyed = 1 << 9; |
| 51 const int kStageDestruction = 1 << 10; | 52 const int kStageDestruction = 1 << 10; |
| 52 | 53 |
| 53 } // namespace | 54 } // namespace |
| 54 | 55 |
| 55 TestURLRequestContext::TestURLRequestContext() : TestURLRequestContext(false) {} | 56 TestURLRequestContext::TestURLRequestContext() : TestURLRequestContext(false) {} |
| 56 | 57 |
| 57 TestURLRequestContext::TestURLRequestContext(bool delay_initialization) | 58 TestURLRequestContext::TestURLRequestContext(bool delay_initialization) |
| 58 : initialized_(false), | 59 : context_storage_(this) { |
| 59 client_socket_factory_(nullptr), | |
| 60 proxy_delegate_(nullptr), | |
| 61 ct_policy_enforcer_(nullptr), | |
| 62 context_storage_(this) { | |
| 63 if (!delay_initialization) | 60 if (!delay_initialization) |
| 64 Init(); | 61 Init(); |
| 65 } | 62 } |
| 66 | 63 |
| 67 TestURLRequestContext::~TestURLRequestContext() { | 64 TestURLRequestContext::~TestURLRequestContext() { |
| 68 DCHECK(initialized_); | 65 DCHECK(initialized_); |
| 69 AssertNoURLRequests(); | 66 AssertNoURLRequests(); |
| 70 } | 67 } |
| 71 | 68 |
| 72 void TestURLRequestContext::Init() { | 69 void TestURLRequestContext::Init() { |
| 73 DCHECK(!initialized_); | 70 DCHECK(!initialized_); |
| 74 initialized_ = true; | 71 initialized_ = true; |
| 75 | 72 |
| 76 if (!host_resolver()) | 73 if (!host_resolver()) |
| 77 context_storage_.set_host_resolver( | 74 context_storage_.set_host_resolver( |
| 78 std::unique_ptr<HostResolver>(new MockCachingHostResolver())); | 75 std::unique_ptr<HostResolver>(new MockCachingHostResolver())); |
| 79 if (!proxy_service()) | 76 if (!proxy_service()) |
| 80 context_storage_.set_proxy_service(ProxyService::CreateDirect()); | 77 context_storage_.set_proxy_service(ProxyService::CreateDirect()); |
| 81 if (!cert_verifier()) | 78 if (!cert_verifier()) |
| 82 context_storage_.set_cert_verifier(CertVerifier::CreateDefault()); | 79 context_storage_.set_cert_verifier(CertVerifier::CreateDefault()); |
| 83 if (!transport_security_state()) | 80 if (!transport_security_state()) |
| 84 context_storage_.set_transport_security_state( | 81 context_storage_.set_transport_security_state( |
| 85 base::WrapUnique(new TransportSecurityState())); | 82 base::WrapUnique(new TransportSecurityState())); |
| 83 if (!cert_transparency_verifier()) | |
| 84 context_storage_.set_cert_transparency_verifier( | |
| 85 base::WrapUnique(new MultiLogCTVerifier())); | |
|
Ryan Hamilton
2016/06/16 03:31:04
Since the if body is more than one line, should th
| |
| 86 if (!ct_policy_enforcer()) | |
| 87 context_storage_.set_ct_policy_enforcer( | |
| 88 base::WrapUnique(new CTPolicyEnforcer)); | |
| 86 if (!ssl_config_service()) | 89 if (!ssl_config_service()) |
| 87 context_storage_.set_ssl_config_service(new SSLConfigServiceDefaults()); | 90 context_storage_.set_ssl_config_service(new SSLConfigServiceDefaults()); |
| 88 if (!http_auth_handler_factory()) { | 91 if (!http_auth_handler_factory()) { |
| 89 context_storage_.set_http_auth_handler_factory( | 92 context_storage_.set_http_auth_handler_factory( |
| 90 HttpAuthHandlerFactory::CreateDefault(host_resolver())); | 93 HttpAuthHandlerFactory::CreateDefault(host_resolver())); |
| 91 } | 94 } |
| 92 if (!http_server_properties()) { | 95 if (!http_server_properties()) { |
| 93 context_storage_.set_http_server_properties( | 96 context_storage_.set_http_server_properties( |
| 94 std::unique_ptr<HttpServerProperties>(new HttpServerPropertiesImpl())); | 97 std::unique_ptr<HttpServerProperties>(new HttpServerPropertiesImpl())); |
| 95 } | 98 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 111 } else { | 114 } else { |
| 112 HttpNetworkSession::Params params; | 115 HttpNetworkSession::Params params; |
| 113 | 116 |
| 114 if (http_network_session_params_) | 117 if (http_network_session_params_) |
| 115 params = *http_network_session_params_; | 118 params = *http_network_session_params_; |
| 116 params.client_socket_factory = client_socket_factory(); | 119 params.client_socket_factory = client_socket_factory(); |
| 117 params.proxy_delegate = proxy_delegate(); | 120 params.proxy_delegate = proxy_delegate(); |
| 118 params.host_resolver = host_resolver(); | 121 params.host_resolver = host_resolver(); |
| 119 params.cert_verifier = cert_verifier(); | 122 params.cert_verifier = cert_verifier(); |
| 120 params.cert_transparency_verifier = cert_transparency_verifier(); | 123 params.cert_transparency_verifier = cert_transparency_verifier(); |
| 121 if (ct_policy_enforcer()) | 124 params.ct_policy_enforcer = ct_policy_enforcer(); |
| 122 params.ct_policy_enforcer = ct_policy_enforcer(); | |
| 123 params.transport_security_state = transport_security_state(); | 125 params.transport_security_state = transport_security_state(); |
| 124 params.proxy_service = proxy_service(); | 126 params.proxy_service = proxy_service(); |
| 125 params.ssl_config_service = ssl_config_service(); | 127 params.ssl_config_service = ssl_config_service(); |
| 126 params.http_auth_handler_factory = http_auth_handler_factory(); | 128 params.http_auth_handler_factory = http_auth_handler_factory(); |
| 127 params.http_server_properties = http_server_properties(); | 129 params.http_server_properties = http_server_properties(); |
| 128 params.net_log = net_log(); | 130 params.net_log = net_log(); |
| 129 params.channel_id_service = channel_id_service(); | 131 params.channel_id_service = channel_id_service(); |
| 130 context_storage_.set_http_network_session( | 132 context_storage_.set_http_network_session( |
| 131 base::WrapUnique(new HttpNetworkSession(params))); | 133 base::WrapUnique(new HttpNetworkSession(params))); |
| 132 context_storage_.set_http_transaction_factory(base::WrapUnique( | 134 context_storage_.set_http_transaction_factory(base::WrapUnique( |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 NetworkDelegate* network_delegate) const { | 658 NetworkDelegate* network_delegate) const { |
| 657 return main_intercept_job_.release(); | 659 return main_intercept_job_.release(); |
| 658 } | 660 } |
| 659 | 661 |
| 660 void TestJobInterceptor::set_main_intercept_job( | 662 void TestJobInterceptor::set_main_intercept_job( |
| 661 std::unique_ptr<URLRequestJob> job) { | 663 std::unique_ptr<URLRequestJob> job) { |
| 662 main_intercept_job_ = std::move(job); | 664 main_intercept_job_ = std::move(job); |
| 663 } | 665 } |
| 664 | 666 |
| 665 } // namespace net | 667 } // namespace net |
| OLD | NEW |