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/socket/socket_test_util.h" | 5 #include "net/socket/socket_test_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
20 #include "base/time/time.h" | 20 #include "base/time/time.h" |
21 #include "net/base/address_family.h" | 21 #include "net/base/address_family.h" |
22 #include "net/base/address_list.h" | 22 #include "net/base/address_list.h" |
23 #include "net/base/auth.h" | 23 #include "net/base/auth.h" |
24 #include "net/base/ip_address.h" | 24 #include "net/base/ip_address.h" |
25 #include "net/base/load_timing_info.h" | 25 #include "net/base/load_timing_info.h" |
26 #include "net/http/http_network_session.h" | 26 #include "net/http/http_network_session.h" |
27 #include "net/http/http_request_headers.h" | 27 #include "net/http/http_request_headers.h" |
28 #include "net/http/http_response_headers.h" | 28 #include "net/http/http_response_headers.h" |
| 29 #include "net/log/net_log_source.h" |
29 #include "net/log/net_log_source_type.h" | 30 #include "net/log/net_log_source_type.h" |
30 #include "net/socket/socket.h" | 31 #include "net/socket/socket.h" |
31 #include "net/socket/websocket_endpoint_lock_manager.h" | 32 #include "net/socket/websocket_endpoint_lock_manager.h" |
32 #include "net/ssl/ssl_cert_request_info.h" | 33 #include "net/ssl/ssl_cert_request_info.h" |
33 #include "net/ssl/ssl_connection_status_flags.h" | 34 #include "net/ssl/ssl_connection_status_flags.h" |
34 #include "net/ssl/ssl_info.h" | 35 #include "net/ssl/ssl_info.h" |
35 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
36 | 37 |
37 #define NET_TRACE(level, s) VLOG(level) << s << __FUNCTION__ << "() " | 38 #define NET_TRACE(level, s) VLOG(level) << s << __FUNCTION__ << "() " |
38 | 39 |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 void MockClientSocketFactory::ResetNextMockIndexes() { | 705 void MockClientSocketFactory::ResetNextMockIndexes() { |
705 mock_data_.ResetNextIndex(); | 706 mock_data_.ResetNextIndex(); |
706 mock_ssl_data_.ResetNextIndex(); | 707 mock_ssl_data_.ResetNextIndex(); |
707 } | 708 } |
708 | 709 |
709 std::unique_ptr<DatagramClientSocket> | 710 std::unique_ptr<DatagramClientSocket> |
710 MockClientSocketFactory::CreateDatagramClientSocket( | 711 MockClientSocketFactory::CreateDatagramClientSocket( |
711 DatagramSocket::BindType bind_type, | 712 DatagramSocket::BindType bind_type, |
712 const RandIntCallback& rand_int_cb, | 713 const RandIntCallback& rand_int_cb, |
713 NetLog* net_log, | 714 NetLog* net_log, |
714 const NetLog::Source& source) { | 715 const NetLogSource& source) { |
715 SocketDataProvider* data_provider = mock_data_.GetNext(); | 716 SocketDataProvider* data_provider = mock_data_.GetNext(); |
716 std::unique_ptr<MockUDPClientSocket> socket( | 717 std::unique_ptr<MockUDPClientSocket> socket( |
717 new MockUDPClientSocket(data_provider, net_log)); | 718 new MockUDPClientSocket(data_provider, net_log)); |
718 if (bind_type == DatagramSocket::RANDOM_BIND) | 719 if (bind_type == DatagramSocket::RANDOM_BIND) |
719 socket->set_source_port( | 720 socket->set_source_port( |
720 static_cast<uint16_t>(rand_int_cb.Run(1025, 65535))); | 721 static_cast<uint16_t>(rand_int_cb.Run(1025, 65535))); |
721 udp_client_socket_ports_.push_back(socket->source_port()); | 722 udp_client_socket_ports_.push_back(socket->source_port()); |
722 return std::move(socket); | 723 return std::move(socket); |
723 } | 724 } |
724 | 725 |
725 std::unique_ptr<StreamSocket> | 726 std::unique_ptr<StreamSocket> |
726 MockClientSocketFactory::CreateTransportClientSocket( | 727 MockClientSocketFactory::CreateTransportClientSocket( |
727 const AddressList& addresses, | 728 const AddressList& addresses, |
728 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, | 729 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, |
729 NetLog* net_log, | 730 NetLog* net_log, |
730 const NetLog::Source& source) { | 731 const NetLogSource& source) { |
731 SocketDataProvider* data_provider = mock_data_.GetNext(); | 732 SocketDataProvider* data_provider = mock_data_.GetNext(); |
732 std::unique_ptr<MockTCPClientSocket> socket( | 733 std::unique_ptr<MockTCPClientSocket> socket( |
733 new MockTCPClientSocket(addresses, net_log, data_provider)); | 734 new MockTCPClientSocket(addresses, net_log, data_provider)); |
734 return std::move(socket); | 735 return std::move(socket); |
735 } | 736 } |
736 | 737 |
737 std::unique_ptr<SSLClientSocket> MockClientSocketFactory::CreateSSLClientSocket( | 738 std::unique_ptr<SSLClientSocket> MockClientSocketFactory::CreateSSLClientSocket( |
738 std::unique_ptr<ClientSocketHandle> transport_socket, | 739 std::unique_ptr<ClientSocketHandle> transport_socket, |
739 const HostPortPair& host_and_port, | 740 const HostPortPair& host_and_port, |
740 const SSLConfig& ssl_config, | 741 const SSLConfig& ssl_config, |
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1624 const std::string& group_name, | 1625 const std::string& group_name, |
1625 const void* socket_params, | 1626 const void* socket_params, |
1626 RequestPriority priority, | 1627 RequestPriority priority, |
1627 RespectLimits respect_limits, | 1628 RespectLimits respect_limits, |
1628 ClientSocketHandle* handle, | 1629 ClientSocketHandle* handle, |
1629 const CompletionCallback& callback, | 1630 const CompletionCallback& callback, |
1630 const NetLogWithSource& net_log) { | 1631 const NetLogWithSource& net_log) { |
1631 last_request_priority_ = priority; | 1632 last_request_priority_ = priority; |
1632 std::unique_ptr<StreamSocket> socket = | 1633 std::unique_ptr<StreamSocket> socket = |
1633 client_socket_factory_->CreateTransportClientSocket( | 1634 client_socket_factory_->CreateTransportClientSocket( |
1634 AddressList(), NULL, net_log.net_log(), NetLog::Source()); | 1635 AddressList(), NULL, net_log.net_log(), NetLogSource()); |
1635 MockConnectJob* job = new MockConnectJob(std::move(socket), handle, callback); | 1636 MockConnectJob* job = new MockConnectJob(std::move(socket), handle, callback); |
1636 job_list_.push_back(base::WrapUnique(job)); | 1637 job_list_.push_back(base::WrapUnique(job)); |
1637 handle->set_pool_id(1); | 1638 handle->set_pool_id(1); |
1638 return job->Connect(); | 1639 return job->Connect(); |
1639 } | 1640 } |
1640 | 1641 |
1641 void MockTransportClientSocketPool::CancelRequest(const std::string& group_name, | 1642 void MockTransportClientSocketPool::CancelRequest(const std::string& group_name, |
1642 ClientSocketHandle* handle) { | 1643 ClientSocketHandle* handle) { |
1643 for (std::unique_ptr<MockConnectJob>& it : job_list_) { | 1644 for (std::unique_ptr<MockConnectJob>& it : job_list_) { |
1644 if (it->CancelHandle(handle)) { | 1645 if (it->CancelHandle(handle)) { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1732 } | 1733 } |
1733 | 1734 |
1734 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size) { | 1735 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size) { |
1735 int64_t total = 0; | 1736 int64_t total = 0; |
1736 for (const MockWrite* write = writes; write != writes + writes_size; ++write) | 1737 for (const MockWrite* write = writes; write != writes + writes_size; ++write) |
1737 total += write->data_len; | 1738 total += write->data_len; |
1738 return total; | 1739 return total; |
1739 } | 1740 } |
1740 | 1741 |
1741 } // namespace net | 1742 } // namespace net |
OLD | NEW |