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 <map> | |
| 8 #include <string> | |
| 7 #include <utility> | 9 #include <utility> |
| 8 | 10 |
| 9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 10 #include "base/location.h" | 12 #include "base/location.h" |
| 11 #include "base/logging.h" | 13 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 13 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 14 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 15 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "base/threading/worker_pool.h" | 19 #include "base/threading/worker_pool.h" |
| 18 #include "net/base/host_port_pair.h" | 20 #include "net/base/host_port_pair.h" |
| 19 #include "net/cert/cert_verifier.h" | 21 #include "net/cert/cert_verifier.h" |
| 20 #include "net/cert/ct_policy_enforcer.h" | 22 #include "net/cert/ct_policy_enforcer.h" |
| 21 #include "net/cert/multi_log_ct_verifier.h" | 23 #include "net/cert/multi_log_ct_verifier.h" |
| 22 #include "net/dns/mock_host_resolver.h" | 24 #include "net/dns/mock_host_resolver.h" |
| 23 #include "net/http/http_network_session.h" | 25 #include "net/http/http_network_session.h" |
| 24 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
| 25 #include "net/http/http_server_properties_impl.h" | 27 #include "net/http/http_server_properties_impl.h" |
| 26 #include "net/http/transport_security_state.h" | 28 #include "net/http/transport_security_state.h" |
| 29 #include "net/nqe/external_estimate_provider.h" | |
| 27 #include "net/proxy/proxy_retry_info.h" | 30 #include "net/proxy/proxy_retry_info.h" |
| 28 #include "net/ssl/channel_id_service.h" | 31 #include "net/ssl/channel_id_service.h" |
| 29 #include "net/ssl/default_channel_id_store.h" | 32 #include "net/ssl/default_channel_id_store.h" |
| 30 #include "net/url_request/static_http_user_agent_settings.h" | 33 #include "net/url_request/static_http_user_agent_settings.h" |
| 31 #include "net/url_request/url_request_job.h" | 34 #include "net/url_request/url_request_job.h" |
| 32 #include "net/url_request/url_request_job_factory_impl.h" | 35 #include "net/url_request/url_request_job_factory_impl.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 34 | 37 |
| 35 namespace net { | 38 namespace net { |
| 36 | 39 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 50 const int kStageCompletedSuccess = 1 << 7; | 53 const int kStageCompletedSuccess = 1 << 7; |
| 51 const int kStageCompletedError = 1 << 8; | 54 const int kStageCompletedError = 1 << 8; |
| 52 const int kStageURLRequestDestroyed = 1 << 9; | 55 const int kStageURLRequestDestroyed = 1 << 9; |
| 53 const int kStageDestruction = 1 << 10; | 56 const int kStageDestruction = 1 << 10; |
| 54 | 57 |
| 55 } // namespace | 58 } // namespace |
| 56 | 59 |
| 57 TestURLRequestContext::TestURLRequestContext() : TestURLRequestContext(false) {} | 60 TestURLRequestContext::TestURLRequestContext() : TestURLRequestContext(false) {} |
| 58 | 61 |
| 59 TestURLRequestContext::TestURLRequestContext(bool delay_initialization) | 62 TestURLRequestContext::TestURLRequestContext(bool delay_initialization) |
| 60 : context_storage_(this) { | 63 : network_quality_estimator_(std::unique_ptr<ExternalEstimateProvider>(), |
| 64 std::map<std::string, std::string>()), | |
| 65 context_storage_(this) { | |
| 61 if (!delay_initialization) | 66 if (!delay_initialization) |
| 62 Init(); | 67 Init(); |
| 63 } | 68 } |
| 64 | 69 |
| 65 TestURLRequestContext::~TestURLRequestContext() { | 70 TestURLRequestContext::~TestURLRequestContext() { |
| 66 DCHECK(initialized_); | 71 DCHECK(initialized_); |
| 67 AssertNoURLRequests(); | 72 AssertNoURLRequests(); |
| 68 } | 73 } |
| 69 | 74 |
| 70 void TestURLRequestContext::Init() { | 75 void TestURLRequestContext::Init() { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 context_storage_.set_cookie_store( | 110 context_storage_.set_cookie_store( |
| 106 base::MakeUnique<CookieMonster>(nullptr, nullptr)); | 111 base::MakeUnique<CookieMonster>(nullptr, nullptr)); |
| 107 } | 112 } |
| 108 // In-memory Channel ID service. Must be created before the | 113 // In-memory Channel ID service. Must be created before the |
| 109 // HttpNetworkSession. | 114 // HttpNetworkSession. |
| 110 if (!channel_id_service()) { | 115 if (!channel_id_service()) { |
| 111 context_storage_.set_channel_id_service(base::MakeUnique<ChannelIDService>( | 116 context_storage_.set_channel_id_service(base::MakeUnique<ChannelIDService>( |
| 112 new DefaultChannelIDStore(nullptr), | 117 new DefaultChannelIDStore(nullptr), |
| 113 base::WorkerPool::GetTaskRunner(true))); | 118 base::WorkerPool::GetTaskRunner(true))); |
| 114 } | 119 } |
| 120 | |
| 121 if (!network_quality_estimator()) | |
| 122 set_network_quality_estimator(&network_quality_estimator_); | |
| 123 | |
| 115 if (http_transaction_factory()) { | 124 if (http_transaction_factory()) { |
| 116 // Make sure we haven't been passed an object we're not going to use. | 125 // Make sure we haven't been passed an object we're not going to use. |
| 117 EXPECT_FALSE(client_socket_factory_); | 126 EXPECT_FALSE(client_socket_factory_); |
| 118 } else { | 127 } else { |
| 119 HttpNetworkSession::Params params; | 128 HttpNetworkSession::Params params; |
| 120 | 129 |
| 121 if (http_network_session_params_) | 130 if (http_network_session_params_) |
| 122 params = *http_network_session_params_; | 131 params = *http_network_session_params_; |
| 123 params.client_socket_factory = client_socket_factory(); | 132 params.client_socket_factory = client_socket_factory(); |
| 124 params.proxy_delegate = proxy_delegate(); | 133 params.proxy_delegate = proxy_delegate(); |
| 125 params.host_resolver = host_resolver(); | 134 params.host_resolver = host_resolver(); |
| 126 params.cert_verifier = cert_verifier(); | 135 params.cert_verifier = cert_verifier(); |
| 127 params.cert_transparency_verifier = cert_transparency_verifier(); | 136 params.cert_transparency_verifier = cert_transparency_verifier(); |
| 128 params.ct_policy_enforcer = ct_policy_enforcer(); | 137 params.ct_policy_enforcer = ct_policy_enforcer(); |
| 129 params.transport_security_state = transport_security_state(); | 138 params.transport_security_state = transport_security_state(); |
| 130 params.proxy_service = proxy_service(); | 139 params.proxy_service = proxy_service(); |
| 131 params.ssl_config_service = ssl_config_service(); | 140 params.ssl_config_service = ssl_config_service(); |
| 132 params.http_auth_handler_factory = http_auth_handler_factory(); | 141 params.http_auth_handler_factory = http_auth_handler_factory(); |
| 133 params.http_server_properties = http_server_properties(); | 142 params.http_server_properties = http_server_properties(); |
| 134 params.net_log = net_log(); | 143 params.net_log = net_log(); |
| 135 params.channel_id_service = channel_id_service(); | 144 params.channel_id_service = channel_id_service(); |
| 145 params.socket_performance_watcher_factory = | |
|
tbansal1
2016/11/14 20:26:01
Currently, the problem is that in some tests, |par
mmenke
2016/11/14 20:29:52
A better solution instead of this CL, or in additi
tbansal1
2016/11/14 20:39:27
"In addition to". OK, I will do that after this CL
| |
| 146 network_quality_estimator()->GetSocketPerformanceWatcherFactory(); | |
| 136 context_storage_.set_http_network_session( | 147 context_storage_.set_http_network_session( |
| 137 base::MakeUnique<HttpNetworkSession>(params)); | 148 base::MakeUnique<HttpNetworkSession>(params)); |
| 138 context_storage_.set_http_transaction_factory(base::MakeUnique<HttpCache>( | 149 context_storage_.set_http_transaction_factory(base::MakeUnique<HttpCache>( |
| 139 context_storage_.http_network_session(), | 150 context_storage_.http_network_session(), |
| 140 HttpCache::DefaultBackend::InMemory(0), false)); | 151 HttpCache::DefaultBackend::InMemory(0), false)); |
| 141 } | 152 } |
| 142 if (!http_user_agent_settings()) { | 153 if (!http_user_agent_settings()) { |
| 143 context_storage_.set_http_user_agent_settings( | 154 context_storage_.set_http_user_agent_settings( |
| 144 base::MakeUnique<StaticHttpUserAgentSettings>("en-us,fr", | 155 base::MakeUnique<StaticHttpUserAgentSettings>("en-us,fr", |
| 145 std::string())); | 156 std::string())); |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 672 NetworkDelegate* network_delegate) const { | 683 NetworkDelegate* network_delegate) const { |
| 673 return main_intercept_job_.release(); | 684 return main_intercept_job_.release(); |
| 674 } | 685 } |
| 675 | 686 |
| 676 void TestJobInterceptor::set_main_intercept_job( | 687 void TestJobInterceptor::set_main_intercept_job( |
| 677 std::unique_ptr<URLRequestJob> job) { | 688 std::unique_ptr<URLRequestJob> job) { |
| 678 main_intercept_job_ = std::move(job); | 689 main_intercept_job_ = std::move(job); |
| 679 } | 690 } |
| 680 | 691 |
| 681 } // namespace net | 692 } // namespace net |
| OLD | NEW |