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 <cstring> | 8 #include <cstring> |
9 #include <deque> | 9 #include <deque> |
10 #include <string> | 10 #include <string> |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 // The AsyncSocket is an interface used by the SocketDataProvider to | 192 // The AsyncSocket is an interface used by the SocketDataProvider to |
193 // complete the asynchronous read operation. | 193 // complete the asynchronous read operation. |
194 class AsyncSocket { | 194 class AsyncSocket { |
195 public: | 195 public: |
196 // If an async IO is pending because the SocketDataProvider returned | 196 // If an async IO is pending because the SocketDataProvider returned |
197 // ERR_IO_PENDING, then the AsyncSocket waits until this OnReadComplete | 197 // ERR_IO_PENDING, then the AsyncSocket waits until this OnReadComplete |
198 // is called to complete the asynchronous read operation. | 198 // is called to complete the asynchronous read operation. |
199 // data.async is ignored, and this read is completed synchronously as | 199 // data.async is ignored, and this read is completed synchronously as |
200 // part of this call. | 200 // part of this call. |
201 virtual void OnReadComplete(const MockRead& data) = 0; | 201 virtual void OnReadComplete(const MockRead& data) = 0; |
| 202 virtual void OnConnectComplete(const MockConnect& data) = 0; |
202 }; | 203 }; |
203 | 204 |
204 // SocketDataProvider which responds based on static tables of mock reads and | 205 // SocketDataProvider which responds based on static tables of mock reads and |
205 // writes. | 206 // writes. |
206 class StaticSocketDataProvider : public SocketDataProvider { | 207 class StaticSocketDataProvider : public SocketDataProvider { |
207 public: | 208 public: |
208 StaticSocketDataProvider(); | 209 StaticSocketDataProvider(); |
209 StaticSocketDataProvider(MockRead* reads, size_t reads_count, | 210 StaticSocketDataProvider(MockRead* reads, size_t reads_count, |
210 MockWrite* writes, size_t writes_count); | 211 MockWrite* writes, size_t writes_count); |
211 virtual ~StaticSocketDataProvider(); | 212 virtual ~StaticSocketDataProvider(); |
(...skipping 10 matching lines...) Expand all Loading... |
222 size_t write_count() const { return write_count_; } | 223 size_t write_count() const { return write_count_; } |
223 | 224 |
224 bool at_read_eof() const { return read_index_ >= read_count_; } | 225 bool at_read_eof() const { return read_index_ >= read_count_; } |
225 bool at_write_eof() const { return write_index_ >= write_count_; } | 226 bool at_write_eof() const { return write_index_ >= write_count_; } |
226 | 227 |
227 virtual void CompleteRead() {} | 228 virtual void CompleteRead() {} |
228 | 229 |
229 // SocketDataProvider implementation. | 230 // SocketDataProvider implementation. |
230 virtual MockRead GetNextRead() OVERRIDE; | 231 virtual MockRead GetNextRead() OVERRIDE; |
231 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE; | 232 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE; |
232 virtual void Reset() OVERRIDE; | 233 ; virtual void Reset() OVERRIDE; |
233 | 234 |
234 private: | 235 private: |
235 MockRead* reads_; | 236 MockRead* reads_; |
236 size_t read_index_; | 237 size_t read_index_; |
237 size_t read_count_; | 238 size_t read_count_; |
238 MockWrite* writes_; | 239 MockWrite* writes_; |
239 size_t write_index_; | 240 size_t write_index_; |
240 size_t write_count_; | 241 size_t write_count_; |
241 | 242 |
242 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataProvider); | 243 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataProvider); |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 virtual bool IsConnected() const OVERRIDE; | 690 virtual bool IsConnected() const OVERRIDE; |
690 virtual bool IsConnectedAndIdle() const OVERRIDE; | 691 virtual bool IsConnectedAndIdle() const OVERRIDE; |
691 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; | 692 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; |
692 virtual bool WasEverUsed() const OVERRIDE; | 693 virtual bool WasEverUsed() const OVERRIDE; |
693 virtual bool UsingTCPFastOpen() const OVERRIDE; | 694 virtual bool UsingTCPFastOpen() const OVERRIDE; |
694 virtual bool WasNpnNegotiated() const OVERRIDE; | 695 virtual bool WasNpnNegotiated() const OVERRIDE; |
695 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; | 696 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; |
696 | 697 |
697 // AsyncSocket: | 698 // AsyncSocket: |
698 virtual void OnReadComplete(const MockRead& data) OVERRIDE; | 699 virtual void OnReadComplete(const MockRead& data) OVERRIDE; |
| 700 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; |
699 | 701 |
700 private: | 702 private: |
701 int CompleteRead(); | 703 int CompleteRead(); |
702 | 704 |
703 AddressList addresses_; | 705 AddressList addresses_; |
704 | 706 |
705 SocketDataProvider* data_; | 707 SocketDataProvider* data_; |
706 int read_offset_; | 708 int read_offset_; |
707 MockRead read_data_; | 709 MockRead read_data_; |
708 bool need_read_data_; | 710 bool need_read_data_; |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 virtual void Close() OVERRIDE; | 798 virtual void Close() OVERRIDE; |
797 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; | 799 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; |
798 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; | 800 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; |
799 virtual const BoundNetLog& NetLog() const OVERRIDE; | 801 virtual const BoundNetLog& NetLog() const OVERRIDE; |
800 | 802 |
801 // DatagramClientSocket implementation. | 803 // DatagramClientSocket implementation. |
802 virtual int Connect(const IPEndPoint& address) OVERRIDE; | 804 virtual int Connect(const IPEndPoint& address) OVERRIDE; |
803 | 805 |
804 // AsyncSocket implementation. | 806 // AsyncSocket implementation. |
805 virtual void OnReadComplete(const MockRead& data) OVERRIDE; | 807 virtual void OnReadComplete(const MockRead& data) OVERRIDE; |
| 808 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; |
806 | 809 |
807 private: | 810 private: |
808 bool connected_; | 811 bool connected_; |
809 IPEndPoint peer_address_; | 812 IPEndPoint peer_address_; |
810 DeterministicSocketHelper helper_; | 813 DeterministicSocketHelper helper_; |
811 }; | 814 }; |
812 | 815 |
813 // Mock TCP socket to be used in conjunction with DeterministicSocketData. | 816 // Mock TCP socket to be used in conjunction with DeterministicSocketData. |
814 class DeterministicMockTCPClientSocket | 817 class DeterministicMockTCPClientSocket |
815 : public MockClientSocket, | 818 : public MockClientSocket, |
(...skipping 22 matching lines...) Expand all Loading... |
838 virtual void Disconnect() OVERRIDE; | 841 virtual void Disconnect() OVERRIDE; |
839 virtual bool IsConnected() const OVERRIDE; | 842 virtual bool IsConnected() const OVERRIDE; |
840 virtual bool IsConnectedAndIdle() const OVERRIDE; | 843 virtual bool IsConnectedAndIdle() const OVERRIDE; |
841 virtual bool WasEverUsed() const OVERRIDE; | 844 virtual bool WasEverUsed() const OVERRIDE; |
842 virtual bool UsingTCPFastOpen() const OVERRIDE; | 845 virtual bool UsingTCPFastOpen() const OVERRIDE; |
843 virtual bool WasNpnNegotiated() const OVERRIDE; | 846 virtual bool WasNpnNegotiated() const OVERRIDE; |
844 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; | 847 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; |
845 | 848 |
846 // AsyncSocket: | 849 // AsyncSocket: |
847 virtual void OnReadComplete(const MockRead& data) OVERRIDE; | 850 virtual void OnReadComplete(const MockRead& data) OVERRIDE; |
| 851 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; |
848 | 852 |
849 private: | 853 private: |
850 DeterministicSocketHelper helper_; | 854 DeterministicSocketHelper helper_; |
851 }; | 855 }; |
852 | 856 |
853 class MockSSLClientSocket : public MockClientSocket, public AsyncSocket { | 857 class MockSSLClientSocket : public MockClientSocket, public AsyncSocket { |
854 public: | 858 public: |
855 MockSSLClientSocket( | 859 MockSSLClientSocket( |
856 ClientSocketHandle* transport_socket, | 860 ClientSocketHandle* transport_socket, |
857 const HostPortPair& host_and_port, | 861 const HostPortPair& host_and_port, |
(...skipping 22 matching lines...) Expand all Loading... |
880 SSLCertRequestInfo* cert_request_info) OVERRIDE; | 884 SSLCertRequestInfo* cert_request_info) OVERRIDE; |
881 virtual NextProtoStatus GetNextProto(std::string* proto, | 885 virtual NextProtoStatus GetNextProto(std::string* proto, |
882 std::string* server_protos) OVERRIDE; | 886 std::string* server_protos) OVERRIDE; |
883 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE; | 887 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE; |
884 virtual void set_protocol_negotiated( | 888 virtual void set_protocol_negotiated( |
885 NextProto protocol_negotiated) OVERRIDE; | 889 NextProto protocol_negotiated) OVERRIDE; |
886 virtual NextProto GetNegotiatedProtocol() const OVERRIDE; | 890 virtual NextProto GetNegotiatedProtocol() const OVERRIDE; |
887 | 891 |
888 // This MockSocket does not implement the manual async IO feature. | 892 // This MockSocket does not implement the manual async IO feature. |
889 virtual void OnReadComplete(const MockRead& data) OVERRIDE; | 893 virtual void OnReadComplete(const MockRead& data) OVERRIDE; |
| 894 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; |
890 | 895 |
891 virtual bool WasChannelIDSent() const OVERRIDE; | 896 virtual bool WasChannelIDSent() const OVERRIDE; |
892 virtual void set_channel_id_sent(bool channel_id_sent) OVERRIDE; | 897 virtual void set_channel_id_sent(bool channel_id_sent) OVERRIDE; |
893 virtual ServerBoundCertService* GetServerBoundCertService() const OVERRIDE; | 898 virtual ServerBoundCertService* GetServerBoundCertService() const OVERRIDE; |
894 | 899 |
895 private: | 900 private: |
896 static void ConnectCallback(MockSSLClientSocket *ssl_client_socket, | 901 static void ConnectCallback(MockSSLClientSocket *ssl_client_socket, |
897 const CompletionCallback& callback, | 902 const CompletionCallback& callback, |
898 int rv); | 903 int rv); |
899 | 904 |
(...skipping 24 matching lines...) Expand all Loading... |
924 virtual void Close() OVERRIDE; | 929 virtual void Close() OVERRIDE; |
925 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; | 930 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; |
926 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; | 931 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; |
927 virtual const BoundNetLog& NetLog() const OVERRIDE; | 932 virtual const BoundNetLog& NetLog() const OVERRIDE; |
928 | 933 |
929 // DatagramClientSocket implementation. | 934 // DatagramClientSocket implementation. |
930 virtual int Connect(const IPEndPoint& address) OVERRIDE; | 935 virtual int Connect(const IPEndPoint& address) OVERRIDE; |
931 | 936 |
932 // AsyncSocket implementation. | 937 // AsyncSocket implementation. |
933 virtual void OnReadComplete(const MockRead& data) OVERRIDE; | 938 virtual void OnReadComplete(const MockRead& data) OVERRIDE; |
| 939 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; |
934 | 940 |
935 private: | 941 private: |
936 int CompleteRead(); | 942 int CompleteRead(); |
937 | 943 |
938 void RunCallbackAsync(const CompletionCallback& callback, int result); | 944 void RunCallbackAsync(const CompletionCallback& callback, int result); |
939 void RunCallback(const CompletionCallback& callback, int result); | 945 void RunCallback(const CompletionCallback& callback, int result); |
940 | 946 |
941 bool connected_; | 947 bool connected_; |
942 SocketDataProvider* data_; | 948 SocketDataProvider* data_; |
943 int read_offset_; | 949 int read_offset_; |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1181 | 1187 |
1182 extern const char kSOCKS5OkRequest[]; | 1188 extern const char kSOCKS5OkRequest[]; |
1183 extern const int kSOCKS5OkRequestLength; | 1189 extern const int kSOCKS5OkRequestLength; |
1184 | 1190 |
1185 extern const char kSOCKS5OkResponse[]; | 1191 extern const char kSOCKS5OkResponse[]; |
1186 extern const int kSOCKS5OkResponseLength; | 1192 extern const int kSOCKS5OkResponseLength; |
1187 | 1193 |
1188 } // namespace net | 1194 } // namespace net |
1189 | 1195 |
1190 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 1196 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
OLD | NEW |