| 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/http/http_response_body_drainer.h" | 5 #include "net/http/http_response_body_drainer.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <cstring> | 9 #include <cstring> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/single_thread_task_runner.h" | 17 #include "base/single_thread_task_runner.h" |
| 18 #include "base/threading/thread_task_runner_handle.h" | 18 #include "base/threading/thread_task_runner_handle.h" |
| 19 #include "net/base/io_buffer.h" | 19 #include "net/base/io_buffer.h" |
| 20 #include "net/base/net_errors.h" | 20 #include "net/base/net_errors.h" |
| 21 #include "net/base/test_completion_callback.h" | 21 #include "net/base/test_completion_callback.h" |
| 22 #include "net/cert/ct_policy_enforcer.h" |
| 23 #include "net/cert/mock_cert_verifier.h" |
| 24 #include "net/cert/multi_log_ct_verifier.h" |
| 22 #include "net/http/http_network_session.h" | 25 #include "net/http/http_network_session.h" |
| 23 #include "net/http/http_server_properties_impl.h" | 26 #include "net/http/http_server_properties_impl.h" |
| 24 #include "net/http/http_stream.h" | 27 #include "net/http/http_stream.h" |
| 25 #include "net/http/transport_security_state.h" | 28 #include "net/http/transport_security_state.h" |
| 26 #include "net/proxy/proxy_service.h" | 29 #include "net/proxy/proxy_service.h" |
| 27 #include "net/ssl/ssl_config_service_defaults.h" | 30 #include "net/ssl/ssl_config_service_defaults.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 32 |
| 30 namespace net { | 33 namespace net { |
| 31 | 34 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 callback_.Reset(); | 226 callback_.Reset(); |
| 224 callback.Run(result); | 227 callback.Run(result); |
| 225 } | 228 } |
| 226 | 229 |
| 227 class HttpResponseBodyDrainerTest : public testing::Test { | 230 class HttpResponseBodyDrainerTest : public testing::Test { |
| 228 protected: | 231 protected: |
| 229 HttpResponseBodyDrainerTest() | 232 HttpResponseBodyDrainerTest() |
| 230 : proxy_service_(ProxyService::CreateDirect()), | 233 : proxy_service_(ProxyService::CreateDirect()), |
| 231 ssl_config_service_(new SSLConfigServiceDefaults), | 234 ssl_config_service_(new SSLConfigServiceDefaults), |
| 232 http_server_properties_(new HttpServerPropertiesImpl()), | 235 http_server_properties_(new HttpServerPropertiesImpl()), |
| 233 transport_security_state_(new TransportSecurityState()), | |
| 234 session_(CreateNetworkSession()), | 236 session_(CreateNetworkSession()), |
| 235 mock_stream_(new MockHttpStream(&result_waiter_)), | 237 mock_stream_(new MockHttpStream(&result_waiter_)), |
| 236 drainer_(new HttpResponseBodyDrainer(mock_stream_)) {} | 238 drainer_(new HttpResponseBodyDrainer(mock_stream_)) {} |
| 237 | 239 |
| 238 ~HttpResponseBodyDrainerTest() override {} | 240 ~HttpResponseBodyDrainerTest() override {} |
| 239 | 241 |
| 240 HttpNetworkSession* CreateNetworkSession() const { | 242 HttpNetworkSession* CreateNetworkSession() { |
| 241 HttpNetworkSession::Params params; | 243 HttpNetworkSession::Params params; |
| 242 params.proxy_service = proxy_service_.get(); | 244 params.proxy_service = proxy_service_.get(); |
| 243 params.ssl_config_service = ssl_config_service_.get(); | 245 params.ssl_config_service = ssl_config_service_.get(); |
| 244 params.http_server_properties = http_server_properties_.get(); | 246 params.http_server_properties = http_server_properties_.get(); |
| 245 params.transport_security_state = transport_security_state_.get(); | 247 params.cert_verifier = &cert_verifier_; |
| 248 params.transport_security_state = &transport_security_state_; |
| 249 params.cert_transparency_verifier = &ct_verifier_; |
| 250 params.ct_policy_enforcer = &ct_policy_enforcer_; |
| 246 return new HttpNetworkSession(params); | 251 return new HttpNetworkSession(params); |
| 247 } | 252 } |
| 248 | 253 |
| 249 std::unique_ptr<ProxyService> proxy_service_; | 254 std::unique_ptr<ProxyService> proxy_service_; |
| 250 scoped_refptr<SSLConfigService> ssl_config_service_; | 255 scoped_refptr<SSLConfigService> ssl_config_service_; |
| 251 std::unique_ptr<HttpServerPropertiesImpl> http_server_properties_; | 256 std::unique_ptr<HttpServerPropertiesImpl> http_server_properties_; |
| 252 std::unique_ptr<TransportSecurityState> transport_security_state_; | 257 MockCertVerifier cert_verifier_; |
| 258 TransportSecurityState transport_security_state_; |
| 259 MultiLogCTVerifier ct_verifier_; |
| 260 CTPolicyEnforcer ct_policy_enforcer_; |
| 253 const std::unique_ptr<HttpNetworkSession> session_; | 261 const std::unique_ptr<HttpNetworkSession> session_; |
| 254 CloseResultWaiter result_waiter_; | 262 CloseResultWaiter result_waiter_; |
| 255 MockHttpStream* const mock_stream_; // Owned by |drainer_|. | 263 MockHttpStream* const mock_stream_; // Owned by |drainer_|. |
| 256 HttpResponseBodyDrainer* const drainer_; // Deletes itself. | 264 HttpResponseBodyDrainer* const drainer_; // Deletes itself. |
| 257 }; | 265 }; |
| 258 | 266 |
| 259 TEST_F(HttpResponseBodyDrainerTest, DrainBodySyncSingleOK) { | 267 TEST_F(HttpResponseBodyDrainerTest, DrainBodySyncSingleOK) { |
| 260 mock_stream_->set_num_chunks(1); | 268 mock_stream_->set_num_chunks(1); |
| 261 mock_stream_->set_sync(); | 269 mock_stream_->set_sync(); |
| 262 drainer_->Start(session_.get()); | 270 drainer_->Start(session_.get()); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 TEST_F(HttpResponseBodyDrainerTest, DrainBodyCantReuse) { | 336 TEST_F(HttpResponseBodyDrainerTest, DrainBodyCantReuse) { |
| 329 mock_stream_->set_num_chunks(1); | 337 mock_stream_->set_num_chunks(1); |
| 330 mock_stream_->set_can_reuse_connection(false); | 338 mock_stream_->set_can_reuse_connection(false); |
| 331 drainer_->Start(session_.get()); | 339 drainer_->Start(session_.get()); |
| 332 EXPECT_TRUE(result_waiter_.WaitForResult()); | 340 EXPECT_TRUE(result_waiter_.WaitForResult()); |
| 333 } | 341 } |
| 334 | 342 |
| 335 } // namespace | 343 } // namespace |
| 336 | 344 |
| 337 } // namespace net | 345 } // namespace net |
| OLD | NEW |