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 #ifndef NET_SOCKET_SOCKET_TEST_UTIL_H_ | 5 #ifndef NET_SOCKET_SOCKET_TEST_UTIL_H_ |
| 6 #define NET_SOCKET_SOCKET_TEST_UTIL_H_ | 6 #define NET_SOCKET_SOCKET_TEST_UTIL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <cstring> | 10 #include <cstring> |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 658 const AddressList& addresses, | 658 const AddressList& addresses, |
| 659 NetLog* net_log, | 659 NetLog* net_log, |
| 660 const NetLog::Source& source) override; | 660 const NetLog::Source& source) override; |
| 661 scoped_ptr<SSLClientSocket> CreateSSLClientSocket( | 661 scoped_ptr<SSLClientSocket> CreateSSLClientSocket( |
| 662 scoped_ptr<ClientSocketHandle> transport_socket, | 662 scoped_ptr<ClientSocketHandle> transport_socket, |
| 663 const HostPortPair& host_and_port, | 663 const HostPortPair& host_and_port, |
| 664 const SSLConfig& ssl_config, | 664 const SSLConfig& ssl_config, |
| 665 const SSLClientSocketContext& context) override; | 665 const SSLClientSocketContext& context) override; |
| 666 void ClearSSLSessionCache() override; | 666 void ClearSSLSessionCache() override; |
| 667 | 667 |
| 668 const std::vector<uint16>& udp_client_socket_ports() const { | |
| 669 return udp_client_socket_ports_; | |
| 670 } | |
| 671 | |
| 668 private: | 672 private: |
| 669 SocketDataProviderArray<SocketDataProvider> mock_data_; | 673 SocketDataProviderArray<SocketDataProvider> mock_data_; |
| 670 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; | 674 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; |
| 675 std::vector<uint16> udp_client_socket_ports_; | |
| 676 | |
| 677 DISALLOW_COPY_AND_ASSIGN(MockClientSocketFactory); | |
| 671 }; | 678 }; |
| 672 | 679 |
| 673 class MockClientSocket : public SSLClientSocket { | 680 class MockClientSocket : public SSLClientSocket { |
| 674 public: | 681 public: |
| 675 // Value returned by GetTLSUniqueChannelBinding(). | 682 // Value returned by GetTLSUniqueChannelBinding(). |
| 676 static const char kTlsUnique[]; | 683 static const char kTlsUnique[]; |
| 677 | 684 |
| 678 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as | 685 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as |
| 679 // unique socket IDs. | 686 // unique socket IDs. |
| 680 explicit MockClientSocket(const BoundNetLog& net_log); | 687 explicit MockClientSocket(const BoundNetLog& net_log); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 838 IOBuffer* read_buf_; | 845 IOBuffer* read_buf_; |
| 839 int read_buf_len_; | 846 int read_buf_len_; |
| 840 bool read_pending_; | 847 bool read_pending_; |
| 841 CompletionCallback read_callback_; | 848 CompletionCallback read_callback_; |
| 842 DeterministicSocketData* data_; | 849 DeterministicSocketData* data_; |
| 843 bool was_used_to_convey_data_; | 850 bool was_used_to_convey_data_; |
| 844 bool peer_closed_connection_; | 851 bool peer_closed_connection_; |
| 845 BoundNetLog net_log_; | 852 BoundNetLog net_log_; |
| 846 }; | 853 }; |
| 847 | 854 |
| 848 // Mock UDP socket to be used in conjunction with DeterministicSocketData. | |
| 849 class DeterministicMockUDPClientSocket | |
|
Ryan Hamilton
2015/12/18 19:50:25
YES!!!!!
| |
| 850 : public DatagramClientSocket, | |
| 851 public DeterministicSocketData::Delegate, | |
| 852 public base::SupportsWeakPtr<DeterministicMockUDPClientSocket> { | |
| 853 public: | |
| 854 DeterministicMockUDPClientSocket(net::NetLog* net_log, | |
| 855 DeterministicSocketData* data); | |
| 856 ~DeterministicMockUDPClientSocket() override; | |
| 857 | |
| 858 // DeterministicSocketData::Delegate: | |
| 859 bool WritePending() const override; | |
| 860 bool ReadPending() const override; | |
| 861 void CompleteWrite() override; | |
| 862 int CompleteRead() override; | |
| 863 | |
| 864 // Socket implementation. | |
| 865 int Read(IOBuffer* buf, | |
| 866 int buf_len, | |
| 867 const CompletionCallback& callback) override; | |
| 868 int Write(IOBuffer* buf, | |
| 869 int buf_len, | |
| 870 const CompletionCallback& callback) override; | |
| 871 int SetReceiveBufferSize(int32 size) override; | |
| 872 int SetSendBufferSize(int32 size) override; | |
| 873 | |
| 874 // DatagramSocket implementation. | |
| 875 void Close() override; | |
| 876 int GetPeerAddress(IPEndPoint* address) const override; | |
| 877 int GetLocalAddress(IPEndPoint* address) const override; | |
| 878 const BoundNetLog& NetLog() const override; | |
| 879 | |
| 880 // DatagramClientSocket implementation. | |
| 881 int BindToNetwork(NetworkChangeNotifier::NetworkHandle network) override; | |
| 882 int BindToDefaultNetwork() override; | |
| 883 NetworkChangeNotifier::NetworkHandle GetBoundNetwork() override; | |
| 884 int Connect(const IPEndPoint& address) override; | |
| 885 | |
| 886 void set_source_port(uint16 port) { source_port_ = port; } | |
| 887 | |
| 888 private: | |
| 889 bool connected_; | |
| 890 IPEndPoint peer_address_; | |
| 891 DeterministicSocketHelper helper_; | |
| 892 uint16 source_port_; // Ephemeral source port. | |
| 893 | |
| 894 DISALLOW_COPY_AND_ASSIGN(DeterministicMockUDPClientSocket); | |
| 895 }; | |
| 896 | |
| 897 // Mock TCP socket to be used in conjunction with DeterministicSocketData. | 855 // Mock TCP socket to be used in conjunction with DeterministicSocketData. |
| 898 class DeterministicMockTCPClientSocket | 856 class DeterministicMockTCPClientSocket |
| 899 : public MockClientSocket, | 857 : public MockClientSocket, |
| 900 public DeterministicSocketData::Delegate, | 858 public DeterministicSocketData::Delegate, |
| 901 public base::SupportsWeakPtr<DeterministicMockTCPClientSocket> { | 859 public base::SupportsWeakPtr<DeterministicMockTCPClientSocket> { |
| 902 public: | 860 public: |
| 903 DeterministicMockTCPClientSocket(net::NetLog* net_log, | 861 DeterministicMockTCPClientSocket(net::NetLog* net_log, |
| 904 DeterministicSocketData* data); | 862 DeterministicSocketData* data); |
| 905 ~DeterministicMockTCPClientSocket() override; | 863 ~DeterministicMockTCPClientSocket() override; |
| 906 | 864 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1013 NetworkChangeNotifier::NetworkHandle GetBoundNetwork() override; | 971 NetworkChangeNotifier::NetworkHandle GetBoundNetwork() override; |
| 1014 int Connect(const IPEndPoint& address) override; | 972 int Connect(const IPEndPoint& address) override; |
| 1015 | 973 |
| 1016 // AsyncSocket implementation. | 974 // AsyncSocket implementation. |
| 1017 void OnReadComplete(const MockRead& data) override; | 975 void OnReadComplete(const MockRead& data) override; |
| 1018 void OnWriteComplete(int rv) override; | 976 void OnWriteComplete(int rv) override; |
| 1019 void OnConnectComplete(const MockConnect& data) override; | 977 void OnConnectComplete(const MockConnect& data) override; |
| 1020 void OnDataProviderDestroyed() override; | 978 void OnDataProviderDestroyed() override; |
| 1021 | 979 |
| 1022 void set_source_port(uint16 port) { source_port_ = port;} | 980 void set_source_port(uint16 port) { source_port_ = port;} |
| 981 uint16 source_port() const { return source_port_; } | |
| 1023 | 982 |
| 1024 private: | 983 private: |
| 1025 int CompleteRead(); | 984 int CompleteRead(); |
| 1026 | 985 |
| 1027 void RunCallbackAsync(const CompletionCallback& callback, int result); | 986 void RunCallbackAsync(const CompletionCallback& callback, int result); |
| 1028 void RunCallback(const CompletionCallback& callback, int result); | 987 void RunCallback(const CompletionCallback& callback, int result); |
| 1029 | 988 |
| 1030 bool connected_; | 989 bool connected_; |
| 1031 SocketDataProvider* data_; | 990 SocketDataProvider* data_; |
| 1032 int read_offset_; | 991 int read_offset_; |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1217 // Return |index|-th MockSSLClientSocket (starting from 0) that the factory | 1176 // Return |index|-th MockSSLClientSocket (starting from 0) that the factory |
| 1218 // created. | 1177 // created. |
| 1219 MockSSLClientSocket* GetMockSSLClientSocket(size_t index) const; | 1178 MockSSLClientSocket* GetMockSSLClientSocket(size_t index) const; |
| 1220 | 1179 |
| 1221 SocketDataProviderArray<DeterministicSocketData>& mock_data() { | 1180 SocketDataProviderArray<DeterministicSocketData>& mock_data() { |
| 1222 return mock_data_; | 1181 return mock_data_; |
| 1223 } | 1182 } |
| 1224 std::vector<DeterministicMockTCPClientSocket*>& tcp_client_sockets() { | 1183 std::vector<DeterministicMockTCPClientSocket*>& tcp_client_sockets() { |
| 1225 return tcp_client_sockets_; | 1184 return tcp_client_sockets_; |
| 1226 } | 1185 } |
| 1227 std::vector<DeterministicMockUDPClientSocket*>& udp_client_sockets() { | |
| 1228 return udp_client_sockets_; | |
| 1229 } | |
| 1230 | 1186 |
| 1231 // ClientSocketFactory | 1187 // ClientSocketFactory |
| 1232 scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( | 1188 scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( |
| 1233 DatagramSocket::BindType bind_type, | 1189 DatagramSocket::BindType bind_type, |
| 1234 const RandIntCallback& rand_int_cb, | 1190 const RandIntCallback& rand_int_cb, |
| 1235 NetLog* net_log, | 1191 NetLog* net_log, |
| 1236 const NetLog::Source& source) override; | 1192 const NetLog::Source& source) override; |
| 1237 scoped_ptr<StreamSocket> CreateTransportClientSocket( | 1193 scoped_ptr<StreamSocket> CreateTransportClientSocket( |
| 1238 const AddressList& addresses, | 1194 const AddressList& addresses, |
| 1239 NetLog* net_log, | 1195 NetLog* net_log, |
| 1240 const NetLog::Source& source) override; | 1196 const NetLog::Source& source) override; |
| 1241 scoped_ptr<SSLClientSocket> CreateSSLClientSocket( | 1197 scoped_ptr<SSLClientSocket> CreateSSLClientSocket( |
| 1242 scoped_ptr<ClientSocketHandle> transport_socket, | 1198 scoped_ptr<ClientSocketHandle> transport_socket, |
| 1243 const HostPortPair& host_and_port, | 1199 const HostPortPair& host_and_port, |
| 1244 const SSLConfig& ssl_config, | 1200 const SSLConfig& ssl_config, |
| 1245 const SSLClientSocketContext& context) override; | 1201 const SSLClientSocketContext& context) override; |
| 1246 void ClearSSLSessionCache() override; | 1202 void ClearSSLSessionCache() override; |
| 1247 | 1203 |
| 1248 private: | 1204 private: |
| 1249 SocketDataProviderArray<DeterministicSocketData> mock_data_; | 1205 SocketDataProviderArray<DeterministicSocketData> mock_data_; |
| 1250 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; | 1206 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; |
| 1251 | 1207 |
| 1252 // Store pointers to handed out sockets in case the test wants to get them. | 1208 // Store pointers to handed out sockets in case the test wants to get them. |
| 1253 std::vector<DeterministicMockTCPClientSocket*> tcp_client_sockets_; | 1209 std::vector<DeterministicMockTCPClientSocket*> tcp_client_sockets_; |
| 1254 std::vector<DeterministicMockUDPClientSocket*> udp_client_sockets_; | |
| 1255 std::vector<MockSSLClientSocket*> ssl_client_sockets_; | 1210 std::vector<MockSSLClientSocket*> ssl_client_sockets_; |
| 1256 | 1211 |
| 1257 DISALLOW_COPY_AND_ASSIGN(DeterministicMockClientSocketFactory); | 1212 DISALLOW_COPY_AND_ASSIGN(DeterministicMockClientSocketFactory); |
| 1258 }; | 1213 }; |
| 1259 | 1214 |
| 1260 class MockSOCKSClientSocketPool : public SOCKSClientSocketPool { | 1215 class MockSOCKSClientSocketPool : public SOCKSClientSocketPool { |
| 1261 public: | 1216 public: |
| 1262 MockSOCKSClientSocketPool(int max_sockets, | 1217 MockSOCKSClientSocketPool(int max_sockets, |
| 1263 int max_sockets_per_group, | 1218 int max_sockets_per_group, |
| 1264 TransportClientSocketPool* transport_pool); | 1219 TransportClientSocketPool* transport_pool); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1312 | 1267 |
| 1313 // Helper function to get the total data size of the MockReads in |reads|. | 1268 // Helper function to get the total data size of the MockReads in |reads|. |
| 1314 int64_t CountReadBytes(const MockRead reads[], size_t reads_size); | 1269 int64_t CountReadBytes(const MockRead reads[], size_t reads_size); |
| 1315 | 1270 |
| 1316 // Helper function to get the total data size of the MockWrites in |writes|. | 1271 // Helper function to get the total data size of the MockWrites in |writes|. |
| 1317 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size); | 1272 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size); |
| 1318 | 1273 |
| 1319 } // namespace net | 1274 } // namespace net |
| 1320 | 1275 |
| 1321 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 1276 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
| OLD | NEW |