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 |
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 next_ssl_data->next_protos_expected_in_ssl_config.end(), | 748 next_ssl_data->next_protos_expected_in_ssl_config.end(), |
749 ssl_config.alpn_protos.begin())); | 749 ssl_config.alpn_protos.begin())); |
750 } | 750 } |
751 return std::unique_ptr<SSLClientSocket>(new MockSSLClientSocket( | 751 return std::unique_ptr<SSLClientSocket>(new MockSSLClientSocket( |
752 std::move(transport_socket), host_and_port, ssl_config, next_ssl_data)); | 752 std::move(transport_socket), host_and_port, ssl_config, next_ssl_data)); |
753 } | 753 } |
754 | 754 |
755 void MockClientSocketFactory::ClearSSLSessionCache() { | 755 void MockClientSocketFactory::ClearSSLSessionCache() { |
756 } | 756 } |
757 | 757 |
758 MockClientSocket::MockClientSocket(const BoundNetLog& net_log) | 758 MockClientSocket::MockClientSocket(const NetLogWithSource& net_log) |
759 : connected_(false), | 759 : connected_(false), net_log_(net_log), weak_factory_(this) { |
760 net_log_(net_log), | |
761 weak_factory_(this) { | |
762 peer_addr_ = IPEndPoint(IPAddress(192, 0, 2, 33), 0); | 760 peer_addr_ = IPEndPoint(IPAddress(192, 0, 2, 33), 0); |
763 } | 761 } |
764 | 762 |
765 int MockClientSocket::SetReceiveBufferSize(int32_t size) { | 763 int MockClientSocket::SetReceiveBufferSize(int32_t size) { |
766 return OK; | 764 return OK; |
767 } | 765 } |
768 | 766 |
769 int MockClientSocket::SetSendBufferSize(int32_t size) { | 767 int MockClientSocket::SetSendBufferSize(int32_t size) { |
770 return OK; | 768 return OK; |
771 } | 769 } |
(...skipping 15 matching lines...) Expand all Loading... |
787 return ERR_SOCKET_NOT_CONNECTED; | 785 return ERR_SOCKET_NOT_CONNECTED; |
788 *address = peer_addr_; | 786 *address = peer_addr_; |
789 return OK; | 787 return OK; |
790 } | 788 } |
791 | 789 |
792 int MockClientSocket::GetLocalAddress(IPEndPoint* address) const { | 790 int MockClientSocket::GetLocalAddress(IPEndPoint* address) const { |
793 *address = IPEndPoint(IPAddress(192, 0, 2, 33), 123); | 791 *address = IPEndPoint(IPAddress(192, 0, 2, 33), 123); |
794 return OK; | 792 return OK; |
795 } | 793 } |
796 | 794 |
797 const BoundNetLog& MockClientSocket::NetLog() const { | 795 const NetLogWithSource& MockClientSocket::NetLog() const { |
798 return net_log_; | 796 return net_log_; |
799 } | 797 } |
800 | 798 |
801 bool MockClientSocket::WasNpnNegotiated() const { | 799 bool MockClientSocket::WasNpnNegotiated() const { |
802 return false; | 800 return false; |
803 } | 801 } |
804 | 802 |
805 NextProto MockClientSocket::GetNegotiatedProtocol() const { | 803 NextProto MockClientSocket::GetNegotiatedProtocol() const { |
806 return kProtoUnknown; | 804 return kProtoUnknown; |
807 } | 805 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 | 854 |
857 void MockClientSocket::RunCallback(const CompletionCallback& callback, | 855 void MockClientSocket::RunCallback(const CompletionCallback& callback, |
858 int result) { | 856 int result) { |
859 if (!callback.is_null()) | 857 if (!callback.is_null()) |
860 callback.Run(result); | 858 callback.Run(result); |
861 } | 859 } |
862 | 860 |
863 MockTCPClientSocket::MockTCPClientSocket(const AddressList& addresses, | 861 MockTCPClientSocket::MockTCPClientSocket(const AddressList& addresses, |
864 net::NetLog* net_log, | 862 net::NetLog* net_log, |
865 SocketDataProvider* data) | 863 SocketDataProvider* data) |
866 : MockClientSocket(BoundNetLog::Make(net_log, NetLogSourceType::NONE)), | 864 : MockClientSocket(NetLogWithSource::Make(net_log, NetLogSourceType::NONE)), |
867 addresses_(addresses), | 865 addresses_(addresses), |
868 data_(data), | 866 data_(data), |
869 read_offset_(0), | 867 read_offset_(0), |
870 read_data_(SYNCHRONOUS, ERR_UNEXPECTED), | 868 read_data_(SYNCHRONOUS, ERR_UNEXPECTED), |
871 need_read_data_(true), | 869 need_read_data_(true), |
872 peer_closed_connection_(false), | 870 peer_closed_connection_(false), |
873 pending_read_buf_(NULL), | 871 pending_read_buf_(NULL), |
874 pending_read_buf_len_(0), | 872 pending_read_buf_len_(0), |
875 was_used_to_convey_data_(false) { | 873 was_used_to_convey_data_(false) { |
876 DCHECK(data_); | 874 DCHECK(data_); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 ssl_client_socket->connected_ = true; | 1126 ssl_client_socket->connected_ = true; |
1129 callback.Run(rv); | 1127 callback.Run(rv); |
1130 } | 1128 } |
1131 | 1129 |
1132 MockSSLClientSocket::MockSSLClientSocket( | 1130 MockSSLClientSocket::MockSSLClientSocket( |
1133 std::unique_ptr<ClientSocketHandle> transport_socket, | 1131 std::unique_ptr<ClientSocketHandle> transport_socket, |
1134 const HostPortPair& host_port_pair, | 1132 const HostPortPair& host_port_pair, |
1135 const SSLConfig& ssl_config, | 1133 const SSLConfig& ssl_config, |
1136 SSLSocketDataProvider* data) | 1134 SSLSocketDataProvider* data) |
1137 : MockClientSocket( | 1135 : MockClientSocket( |
1138 // Have to use the right BoundNetLog for LoadTimingInfo regression | 1136 // Have to use the right NetLogWithSource for LoadTimingInfo |
| 1137 // regression |
1139 // tests. | 1138 // tests. |
1140 transport_socket->socket()->NetLog()), | 1139 transport_socket->socket()->NetLog()), |
1141 transport_(std::move(transport_socket)), | 1140 transport_(std::move(transport_socket)), |
1142 data_(data) { | 1141 data_(data) { |
1143 DCHECK(data_); | 1142 DCHECK(data_); |
1144 peer_addr_ = data->connect.peer_addr; | 1143 peer_addr_ = data->connect.peer_addr; |
1145 } | 1144 } |
1146 | 1145 |
1147 MockSSLClientSocket::~MockSSLClientSocket() { | 1146 MockSSLClientSocket::~MockSSLClientSocket() { |
1148 Disconnect(); | 1147 Disconnect(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1253 net::NetLog* net_log) | 1252 net::NetLog* net_log) |
1254 : connected_(false), | 1253 : connected_(false), |
1255 data_(data), | 1254 data_(data), |
1256 read_offset_(0), | 1255 read_offset_(0), |
1257 read_data_(SYNCHRONOUS, ERR_UNEXPECTED), | 1256 read_data_(SYNCHRONOUS, ERR_UNEXPECTED), |
1258 need_read_data_(true), | 1257 need_read_data_(true), |
1259 source_port_(123), | 1258 source_port_(123), |
1260 network_(NetworkChangeNotifier::kInvalidNetworkHandle), | 1259 network_(NetworkChangeNotifier::kInvalidNetworkHandle), |
1261 pending_read_buf_(NULL), | 1260 pending_read_buf_(NULL), |
1262 pending_read_buf_len_(0), | 1261 pending_read_buf_len_(0), |
1263 net_log_(BoundNetLog::Make(net_log, NetLogSourceType::NONE)), | 1262 net_log_(NetLogWithSource::Make(net_log, NetLogSourceType::NONE)), |
1264 weak_factory_(this) { | 1263 weak_factory_(this) { |
1265 DCHECK(data_); | 1264 DCHECK(data_); |
1266 data_->Initialize(this); | 1265 data_->Initialize(this); |
1267 peer_addr_ = data->connect_data().peer_addr; | 1266 peer_addr_ = data->connect_data().peer_addr; |
1268 } | 1267 } |
1269 | 1268 |
1270 MockUDPClientSocket::~MockUDPClientSocket() { | 1269 MockUDPClientSocket::~MockUDPClientSocket() { |
1271 if (data_) | 1270 if (data_) |
1272 data_->DetachSocket(); | 1271 data_->DetachSocket(); |
1273 } | 1272 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 return OK; | 1345 return OK; |
1347 } | 1346 } |
1348 | 1347 |
1349 int MockUDPClientSocket::GetLocalAddress(IPEndPoint* address) const { | 1348 int MockUDPClientSocket::GetLocalAddress(IPEndPoint* address) const { |
1350 *address = IPEndPoint(IPAddress(192, 0, 2, 33), source_port_); | 1349 *address = IPEndPoint(IPAddress(192, 0, 2, 33), source_port_); |
1351 return OK; | 1350 return OK; |
1352 } | 1351 } |
1353 | 1352 |
1354 void MockUDPClientSocket::UseNonBlockingIO() {} | 1353 void MockUDPClientSocket::UseNonBlockingIO() {} |
1355 | 1354 |
1356 const BoundNetLog& MockUDPClientSocket::NetLog() const { | 1355 const NetLogWithSource& MockUDPClientSocket::NetLog() const { |
1357 return net_log_; | 1356 return net_log_; |
1358 } | 1357 } |
1359 | 1358 |
1360 int MockUDPClientSocket::Connect(const IPEndPoint& address) { | 1359 int MockUDPClientSocket::Connect(const IPEndPoint& address) { |
1361 if (!data_) | 1360 if (!data_) |
1362 return ERR_UNEXPECTED; | 1361 return ERR_UNEXPECTED; |
1363 connected_ = true; | 1362 connected_ = true; |
1364 peer_addr_ = address; | 1363 peer_addr_ = address; |
1365 return data_->connect_data().result; | 1364 return data_->connect_data().result; |
1366 } | 1365 } |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1621 | 1620 |
1622 MockTransportClientSocketPool::~MockTransportClientSocketPool() {} | 1621 MockTransportClientSocketPool::~MockTransportClientSocketPool() {} |
1623 | 1622 |
1624 int MockTransportClientSocketPool::RequestSocket( | 1623 int MockTransportClientSocketPool::RequestSocket( |
1625 const std::string& group_name, | 1624 const std::string& group_name, |
1626 const void* socket_params, | 1625 const void* socket_params, |
1627 RequestPriority priority, | 1626 RequestPriority priority, |
1628 RespectLimits respect_limits, | 1627 RespectLimits respect_limits, |
1629 ClientSocketHandle* handle, | 1628 ClientSocketHandle* handle, |
1630 const CompletionCallback& callback, | 1629 const CompletionCallback& callback, |
1631 const BoundNetLog& net_log) { | 1630 const NetLogWithSource& net_log) { |
1632 last_request_priority_ = priority; | 1631 last_request_priority_ = priority; |
1633 std::unique_ptr<StreamSocket> socket = | 1632 std::unique_ptr<StreamSocket> socket = |
1634 client_socket_factory_->CreateTransportClientSocket( | 1633 client_socket_factory_->CreateTransportClientSocket( |
1635 AddressList(), NULL, net_log.net_log(), NetLog::Source()); | 1634 AddressList(), NULL, net_log.net_log(), NetLog::Source()); |
1636 MockConnectJob* job = new MockConnectJob(std::move(socket), handle, callback); | 1635 MockConnectJob* job = new MockConnectJob(std::move(socket), handle, callback); |
1637 job_list_.push_back(base::WrapUnique(job)); | 1636 job_list_.push_back(base::WrapUnique(job)); |
1638 handle->set_pool_id(1); | 1637 handle->set_pool_id(1); |
1639 return job->Connect(); | 1638 return job->Connect(); |
1640 } | 1639 } |
1641 | 1640 |
(...skipping 28 matching lines...) Expand all Loading... |
1670 transport_pool_(transport_pool) {} | 1669 transport_pool_(transport_pool) {} |
1671 | 1670 |
1672 MockSOCKSClientSocketPool::~MockSOCKSClientSocketPool() {} | 1671 MockSOCKSClientSocketPool::~MockSOCKSClientSocketPool() {} |
1673 | 1672 |
1674 int MockSOCKSClientSocketPool::RequestSocket(const std::string& group_name, | 1673 int MockSOCKSClientSocketPool::RequestSocket(const std::string& group_name, |
1675 const void* socket_params, | 1674 const void* socket_params, |
1676 RequestPriority priority, | 1675 RequestPriority priority, |
1677 RespectLimits respect_limits, | 1676 RespectLimits respect_limits, |
1678 ClientSocketHandle* handle, | 1677 ClientSocketHandle* handle, |
1679 const CompletionCallback& callback, | 1678 const CompletionCallback& callback, |
1680 const BoundNetLog& net_log) { | 1679 const NetLogWithSource& net_log) { |
1681 return transport_pool_->RequestSocket(group_name, socket_params, priority, | 1680 return transport_pool_->RequestSocket(group_name, socket_params, priority, |
1682 respect_limits, handle, callback, | 1681 respect_limits, handle, callback, |
1683 net_log); | 1682 net_log); |
1684 } | 1683 } |
1685 | 1684 |
1686 void MockSOCKSClientSocketPool::CancelRequest( | 1685 void MockSOCKSClientSocketPool::CancelRequest( |
1687 const std::string& group_name, | 1686 const std::string& group_name, |
1688 ClientSocketHandle* handle) { | 1687 ClientSocketHandle* handle) { |
1689 return transport_pool_->CancelRequest(group_name, handle); | 1688 return transport_pool_->CancelRequest(group_name, handle); |
1690 } | 1689 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1733 } | 1732 } |
1734 | 1733 |
1735 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size) { | 1734 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size) { |
1736 int64_t total = 0; | 1735 int64_t total = 0; |
1737 for (const MockWrite* write = writes; write != writes + writes_size; ++write) | 1736 for (const MockWrite* write = writes; write != writes + writes_size; ++write) |
1738 total += write->data_len; | 1737 total += write->data_len; |
1739 return total; | 1738 return total; |
1740 } | 1739 } |
1741 | 1740 |
1742 } // namespace net | 1741 } // namespace net |
OLD | NEW |