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 <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
785 callback.Run(result); | 785 callback.Run(result); |
786 } | 786 } |
787 | 787 |
788 MockTCPClientSocket::MockTCPClientSocket(const AddressList& addresses, | 788 MockTCPClientSocket::MockTCPClientSocket(const AddressList& addresses, |
789 net::NetLog* net_log, | 789 net::NetLog* net_log, |
790 SocketDataProvider* data) | 790 SocketDataProvider* data) |
791 : MockClientSocket(BoundNetLog::Make(net_log, net::NetLog::SOURCE_NONE)), | 791 : MockClientSocket(BoundNetLog::Make(net_log, net::NetLog::SOURCE_NONE)), |
792 addresses_(addresses), | 792 addresses_(addresses), |
793 data_(data), | 793 data_(data), |
794 read_offset_(0), | 794 read_offset_(0), |
795 num_bytes_read_(0), | |
796 read_data_(SYNCHRONOUS, ERR_UNEXPECTED), | 795 read_data_(SYNCHRONOUS, ERR_UNEXPECTED), |
797 need_read_data_(true), | 796 need_read_data_(true), |
798 peer_closed_connection_(false), | 797 peer_closed_connection_(false), |
799 pending_buf_(NULL), | 798 pending_buf_(NULL), |
800 pending_buf_len_(0), | 799 pending_buf_len_(0), |
801 was_used_to_convey_data_(false) { | 800 was_used_to_convey_data_(false) { |
802 DCHECK(data_); | 801 DCHECK(data_); |
803 peer_addr_ = data->connect_data().peer_addr; | 802 peer_addr_ = data->connect_data().peer_addr; |
804 data_->Reset(); | 803 data_->Reset(); |
805 } | 804 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 } | 894 } |
896 | 895 |
897 bool MockTCPClientSocket::WasEverUsed() const { | 896 bool MockTCPClientSocket::WasEverUsed() const { |
898 return was_used_to_convey_data_; | 897 return was_used_to_convey_data_; |
899 } | 898 } |
900 | 899 |
901 bool MockTCPClientSocket::UsingTCPFastOpen() const { | 900 bool MockTCPClientSocket::UsingTCPFastOpen() const { |
902 return false; | 901 return false; |
903 } | 902 } |
904 | 903 |
905 int64 MockTCPClientSocket::NumBytesRead() const { | |
906 return num_bytes_read_; | |
907 } | |
908 | |
909 base::TimeDelta MockTCPClientSocket::GetConnectTimeMicros() const { | |
910 // Dummy value. | |
911 static const base::TimeDelta kTestingConnectTimeMicros = | |
912 base::TimeDelta::FromMicroseconds(20); | |
913 return kTestingConnectTimeMicros; | |
914 } | |
915 | |
916 bool MockTCPClientSocket::WasNpnNegotiated() const { | 904 bool MockTCPClientSocket::WasNpnNegotiated() const { |
917 return false; | 905 return false; |
918 } | 906 } |
919 | 907 |
920 bool MockTCPClientSocket::GetSSLInfo(SSLInfo* ssl_info) { | 908 bool MockTCPClientSocket::GetSSLInfo(SSLInfo* ssl_info) { |
921 return false; | 909 return false; |
922 } | 910 } |
923 | 911 |
924 void MockTCPClientSocket::OnReadComplete(const MockRead& data) { | 912 void MockTCPClientSocket::OnReadComplete(const MockRead& data) { |
925 // There must be a read pending. | 913 // There must be a read pending. |
(...skipping 30 matching lines...) Expand all Loading... |
956 pending_callback_.Reset(); | 944 pending_callback_.Reset(); |
957 | 945 |
958 int result = read_data_.result; | 946 int result = read_data_.result; |
959 DCHECK(result != ERR_IO_PENDING); | 947 DCHECK(result != ERR_IO_PENDING); |
960 | 948 |
961 if (read_data_.data) { | 949 if (read_data_.data) { |
962 if (read_data_.data_len - read_offset_ > 0) { | 950 if (read_data_.data_len - read_offset_ > 0) { |
963 result = std::min(buf_len, read_data_.data_len - read_offset_); | 951 result = std::min(buf_len, read_data_.data_len - read_offset_); |
964 memcpy(buf->data(), read_data_.data + read_offset_, result); | 952 memcpy(buf->data(), read_data_.data + read_offset_, result); |
965 read_offset_ += result; | 953 read_offset_ += result; |
966 num_bytes_read_ += result; | |
967 if (read_offset_ == read_data_.data_len) { | 954 if (read_offset_ == read_data_.data_len) { |
968 need_read_data_ = true; | 955 need_read_data_ = true; |
969 read_offset_ = 0; | 956 read_offset_ = 0; |
970 } | 957 } |
971 } else { | 958 } else { |
972 result = 0; // EOF | 959 result = 0; // EOF |
973 } | 960 } |
974 } | 961 } |
975 | 962 |
976 if (read_data_.mode == ASYNC) { | 963 if (read_data_.mode == ASYNC) { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 } | 1092 } |
1106 | 1093 |
1107 bool DeterministicMockTCPClientSocket::WasEverUsed() const { | 1094 bool DeterministicMockTCPClientSocket::WasEverUsed() const { |
1108 return was_used_to_convey_data_; | 1095 return was_used_to_convey_data_; |
1109 } | 1096 } |
1110 | 1097 |
1111 bool DeterministicMockTCPClientSocket::UsingTCPFastOpen() const { | 1098 bool DeterministicMockTCPClientSocket::UsingTCPFastOpen() const { |
1112 return false; | 1099 return false; |
1113 } | 1100 } |
1114 | 1101 |
1115 int64 DeterministicMockTCPClientSocket::NumBytesRead() const { | |
1116 return -1; | |
1117 } | |
1118 | |
1119 base::TimeDelta DeterministicMockTCPClientSocket::GetConnectTimeMicros() const { | |
1120 return base::TimeDelta::FromMicroseconds(-1); | |
1121 } | |
1122 | |
1123 bool DeterministicMockTCPClientSocket::WasNpnNegotiated() const { | 1102 bool DeterministicMockTCPClientSocket::WasNpnNegotiated() const { |
1124 return false; | 1103 return false; |
1125 } | 1104 } |
1126 | 1105 |
1127 bool DeterministicMockTCPClientSocket::GetSSLInfo(SSLInfo* ssl_info) { | 1106 bool DeterministicMockTCPClientSocket::GetSSLInfo(SSLInfo* ssl_info) { |
1128 return false; | 1107 return false; |
1129 } | 1108 } |
1130 | 1109 |
1131 void DeterministicMockTCPClientSocket::OnReadComplete(const MockRead& data) {} | 1110 void DeterministicMockTCPClientSocket::OnReadComplete(const MockRead& data) {} |
1132 | 1111 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 } | 1178 } |
1200 | 1179 |
1201 bool MockSSLClientSocket::WasEverUsed() const { | 1180 bool MockSSLClientSocket::WasEverUsed() const { |
1202 return transport_->socket()->WasEverUsed(); | 1181 return transport_->socket()->WasEverUsed(); |
1203 } | 1182 } |
1204 | 1183 |
1205 bool MockSSLClientSocket::UsingTCPFastOpen() const { | 1184 bool MockSSLClientSocket::UsingTCPFastOpen() const { |
1206 return transport_->socket()->UsingTCPFastOpen(); | 1185 return transport_->socket()->UsingTCPFastOpen(); |
1207 } | 1186 } |
1208 | 1187 |
1209 int64 MockSSLClientSocket::NumBytesRead() const { | |
1210 return -1; | |
1211 } | |
1212 | |
1213 int MockSSLClientSocket::GetPeerAddress(IPEndPoint* address) const { | 1188 int MockSSLClientSocket::GetPeerAddress(IPEndPoint* address) const { |
1214 return transport_->socket()->GetPeerAddress(address); | 1189 return transport_->socket()->GetPeerAddress(address); |
1215 } | 1190 } |
1216 | 1191 |
1217 base::TimeDelta MockSSLClientSocket::GetConnectTimeMicros() const { | |
1218 return base::TimeDelta::FromMicroseconds(-1); | |
1219 } | |
1220 | |
1221 bool MockSSLClientSocket::GetSSLInfo(SSLInfo* ssl_info) { | 1192 bool MockSSLClientSocket::GetSSLInfo(SSLInfo* ssl_info) { |
1222 ssl_info->Reset(); | 1193 ssl_info->Reset(); |
1223 ssl_info->cert = data_->cert; | 1194 ssl_info->cert = data_->cert; |
1224 ssl_info->client_cert_sent = data_->client_cert_sent; | 1195 ssl_info->client_cert_sent = data_->client_cert_sent; |
1225 ssl_info->channel_id_sent = data_->channel_id_sent; | 1196 ssl_info->channel_id_sent = data_->channel_id_sent; |
1226 return true; | 1197 return true; |
1227 } | 1198 } |
1228 | 1199 |
1229 void MockSSLClientSocket::GetSSLCertRequestInfo( | 1200 void MockSSLClientSocket::GetSSLCertRequestInfo( |
1230 SSLCertRequestInfo* cert_request_info) { | 1201 SSLCertRequestInfo* cert_request_info) { |
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1715 | 1686 |
1716 const char kSOCKS5OkRequest[] = | 1687 const char kSOCKS5OkRequest[] = |
1717 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; | 1688 { 0x05, 0x01, 0x00, 0x03, 0x04, 'h', 'o', 's', 't', 0x00, 0x50 }; |
1718 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); | 1689 const int kSOCKS5OkRequestLength = arraysize(kSOCKS5OkRequest); |
1719 | 1690 |
1720 const char kSOCKS5OkResponse[] = | 1691 const char kSOCKS5OkResponse[] = |
1721 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; | 1692 { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
1722 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); | 1693 const int kSOCKS5OkResponseLength = arraysize(kSOCKS5OkResponse); |
1723 | 1694 |
1724 } // namespace net | 1695 } // namespace net |
OLD | NEW |