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 <cstring> | 8 #include <cstring> |
| 9 #include <deque> | 9 #include <deque> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 327 SSLClientSocket::NextProtoStatus next_proto_status; | 327 SSLClientSocket::NextProtoStatus next_proto_status; |
| 328 std::string next_proto; | 328 std::string next_proto; |
| 329 bool was_npn_negotiated; | 329 bool was_npn_negotiated; |
| 330 NextProto protocol_negotiated; | 330 NextProto protocol_negotiated; |
| 331 bool client_cert_sent; | 331 bool client_cert_sent; |
| 332 SSLCertRequestInfo* cert_request_info; | 332 SSLCertRequestInfo* cert_request_info; |
| 333 scoped_refptr<X509Certificate> cert; | 333 scoped_refptr<X509Certificate> cert; |
| 334 bool channel_id_sent; | 334 bool channel_id_sent; |
| 335 ChannelIDService* channel_id_service; | 335 ChannelIDService* channel_id_service; |
| 336 int connection_status; | 336 int connection_status; |
| 337 // Indicates that the socket should block in the Connect method. | |
|
wtc
2014/08/06 19:01:27
Nit: I suggest changing "block" to "pause". This w
| |
| 338 bool should_block_on_connect; | |
|
wtc
2014/08/06 19:01:26
Nit: similarly, rename this member "should_pause_o
| |
| 339 // Whether or not the Socket should behave like there is a pre-existing | |
| 340 // session to resume. Whether or not such a session is reported as | |
| 341 // resumed is controlled by |connection_status|. | |
| 342 bool is_in_session_cache; | |
| 337 }; | 343 }; |
| 338 | 344 |
| 339 // A DataProvider where the client must write a request before the reads (e.g. | 345 // A DataProvider where the client must write a request before the reads (e.g. |
| 340 // the response) will complete. | 346 // the response) will complete. |
| 341 class DelayedSocketData : public StaticSocketDataProvider { | 347 class DelayedSocketData : public StaticSocketDataProvider { |
| 342 public: | 348 public: |
| 343 // |write_delay| the number of MockWrites to complete before allowing | 349 // |write_delay| the number of MockWrites to complete before allowing |
| 344 // a MockRead to complete. | 350 // a MockRead to complete. |
| 345 // |reads| the list of MockRead completions. | 351 // |reads| the list of MockRead completions. |
| 346 // |writes| the list of MockWrite completions. | 352 // |writes| the list of MockWrite completions. |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 virtual ~MockClientSocketFactory(); | 636 virtual ~MockClientSocketFactory(); |
| 631 | 637 |
| 632 void AddSocketDataProvider(SocketDataProvider* socket); | 638 void AddSocketDataProvider(SocketDataProvider* socket); |
| 633 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket); | 639 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket); |
| 634 void ResetNextMockIndexes(); | 640 void ResetNextMockIndexes(); |
| 635 | 641 |
| 636 SocketDataProviderArray<SocketDataProvider>& mock_data() { | 642 SocketDataProviderArray<SocketDataProvider>& mock_data() { |
| 637 return mock_data_; | 643 return mock_data_; |
| 638 } | 644 } |
| 639 | 645 |
| 646 // Note: this method is unsafe; the elements of the returned vector | |
| 647 // are not necessarily valid. | |
| 648 const std::vector<MockSSLClientSocket*>& ssl_client_sockets() const { | |
| 649 return ssl_client_sockets_; | |
| 650 } | |
| 651 | |
| 640 // ClientSocketFactory | 652 // ClientSocketFactory |
| 641 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( | 653 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( |
| 642 DatagramSocket::BindType bind_type, | 654 DatagramSocket::BindType bind_type, |
| 643 const RandIntCallback& rand_int_cb, | 655 const RandIntCallback& rand_int_cb, |
| 644 NetLog* net_log, | 656 NetLog* net_log, |
| 645 const NetLog::Source& source) OVERRIDE; | 657 const NetLog::Source& source) OVERRIDE; |
| 646 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket( | 658 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket( |
| 647 const AddressList& addresses, | 659 const AddressList& addresses, |
| 648 NetLog* net_log, | 660 NetLog* net_log, |
| 649 const NetLog::Source& source) OVERRIDE; | 661 const NetLog::Source& source) OVERRIDE; |
| 650 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket( | 662 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket( |
| 651 scoped_ptr<ClientSocketHandle> transport_socket, | 663 scoped_ptr<ClientSocketHandle> transport_socket, |
| 652 const HostPortPair& host_and_port, | 664 const HostPortPair& host_and_port, |
| 653 const SSLConfig& ssl_config, | 665 const SSLConfig& ssl_config, |
| 654 const SSLClientSocketContext& context) OVERRIDE; | 666 const SSLClientSocketContext& context) OVERRIDE; |
| 655 virtual void ClearSSLSessionCache() OVERRIDE; | 667 virtual void ClearSSLSessionCache() OVERRIDE; |
| 656 | 668 |
| 657 private: | 669 private: |
| 658 SocketDataProviderArray<SocketDataProvider> mock_data_; | 670 SocketDataProviderArray<SocketDataProvider> mock_data_; |
| 659 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; | 671 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; |
| 672 std::vector<MockSSLClientSocket*> ssl_client_sockets_; | |
| 660 }; | 673 }; |
| 661 | 674 |
| 662 class MockClientSocket : public SSLClientSocket { | 675 class MockClientSocket : public SSLClientSocket { |
| 663 public: | 676 public: |
| 664 // Value returned by GetTLSUniqueChannelBinding(). | 677 // Value returned by GetTLSUniqueChannelBinding(). |
| 665 static const char kTlsUnique[]; | 678 static const char kTlsUnique[]; |
| 666 | 679 |
| 667 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as | 680 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as |
| 668 // unique socket IDs. | 681 // unique socket IDs. |
| 669 explicit MockClientSocket(const BoundNetLog& net_log); | 682 explicit MockClientSocket(const BoundNetLog& net_log); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 683 virtual void Disconnect() OVERRIDE; | 696 virtual void Disconnect() OVERRIDE; |
| 684 virtual bool IsConnected() const OVERRIDE; | 697 virtual bool IsConnected() const OVERRIDE; |
| 685 virtual bool IsConnectedAndIdle() const OVERRIDE; | 698 virtual bool IsConnectedAndIdle() const OVERRIDE; |
| 686 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; | 699 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; |
| 687 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; | 700 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; |
| 688 virtual const BoundNetLog& NetLog() const OVERRIDE; | 701 virtual const BoundNetLog& NetLog() const OVERRIDE; |
| 689 virtual void SetSubresourceSpeculation() OVERRIDE {} | 702 virtual void SetSubresourceSpeculation() OVERRIDE {} |
| 690 virtual void SetOmniboxSpeculation() OVERRIDE {} | 703 virtual void SetOmniboxSpeculation() OVERRIDE {} |
| 691 | 704 |
| 692 // SSLClientSocket implementation. | 705 // SSLClientSocket implementation. |
| 706 virtual bool InSessionCache() const OVERRIDE; | |
| 707 virtual void SetHandshakeCompletionCallback(const base::Closure& cb) OVERRIDE; | |
| 693 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) | 708 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) |
| 694 OVERRIDE; | 709 OVERRIDE; |
| 695 virtual int ExportKeyingMaterial(const base::StringPiece& label, | 710 virtual int ExportKeyingMaterial(const base::StringPiece& label, |
| 696 bool has_context, | 711 bool has_context, |
| 697 const base::StringPiece& context, | 712 const base::StringPiece& context, |
| 698 unsigned char* out, | 713 unsigned char* out, |
| 699 unsigned int outlen) OVERRIDE; | 714 unsigned int outlen) OVERRIDE; |
| 700 virtual int GetTLSUniqueChannelBinding(std::string* out) OVERRIDE; | 715 virtual int GetTLSUniqueChannelBinding(std::string* out) OVERRIDE; |
| 701 virtual NextProtoStatus GetNextProto(std::string* proto) OVERRIDE; | 716 virtual NextProtoStatus GetNextProto(std::string* proto) OVERRIDE; |
| 702 virtual ChannelIDService* GetChannelIDService() const OVERRIDE; | 717 virtual ChannelIDService* GetChannelIDService() const OVERRIDE; |
| 703 | 718 |
| 704 protected: | 719 protected: |
| 705 virtual ~MockClientSocket(); | 720 virtual ~MockClientSocket(); |
| 706 void RunCallbackAsync(const CompletionCallback& callback, int result); | 721 void RunCallbackAsync(const CompletionCallback& callback, int result); |
| 707 void RunCallback(const CompletionCallback& callback, int result); | 722 void RunCallback(const CompletionCallback& callback, int result); |
| 708 | 723 |
| 709 // SSLClientSocket implementation. | 724 // SSLClientSocket implementation. |
| 710 virtual scoped_refptr<X509Certificate> GetUnverifiedServerCertificateChain() | 725 virtual scoped_refptr<X509Certificate> GetUnverifiedServerCertificateChain() |
| 711 const OVERRIDE; | 726 const OVERRIDE; |
| 712 | 727 |
| 713 // True if Connect completed successfully and Disconnect hasn't been called. | 728 // True if Connect completed successfully and Disconnect hasn't been called. |
| 714 bool connected_; | 729 bool connected_; |
| 715 | 730 |
| 716 // Address of the "remote" peer we're connected to. | 731 // Address of the "remote" peer we're connected to. |
| 717 IPEndPoint peer_addr_; | 732 IPEndPoint peer_addr_; |
| 718 | 733 |
| 719 BoundNetLog net_log_; | 734 BoundNetLog net_log_; |
| 720 | 735 |
| 736 private: | |
| 721 base::WeakPtrFactory<MockClientSocket> weak_factory_; | 737 base::WeakPtrFactory<MockClientSocket> weak_factory_; |
| 722 | 738 |
| 723 DISALLOW_COPY_AND_ASSIGN(MockClientSocket); | 739 DISALLOW_COPY_AND_ASSIGN(MockClientSocket); |
| 724 }; | 740 }; |
| 725 | 741 |
| 726 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket { | 742 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket { |
| 727 public: | 743 public: |
| 728 MockTCPClientSocket(const AddressList& addresses, | 744 MockTCPClientSocket(const AddressList& addresses, |
| 729 net::NetLog* net_log, | 745 net::NetLog* net_log, |
| 730 SocketDataProvider* socket); | 746 SocketDataProvider* socket); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 941 virtual int Connect(const CompletionCallback& callback) OVERRIDE; | 957 virtual int Connect(const CompletionCallback& callback) OVERRIDE; |
| 942 virtual void Disconnect() OVERRIDE; | 958 virtual void Disconnect() OVERRIDE; |
| 943 virtual bool IsConnected() const OVERRIDE; | 959 virtual bool IsConnected() const OVERRIDE; |
| 944 virtual bool WasEverUsed() const OVERRIDE; | 960 virtual bool WasEverUsed() const OVERRIDE; |
| 945 virtual bool UsingTCPFastOpen() const OVERRIDE; | 961 virtual bool UsingTCPFastOpen() const OVERRIDE; |
| 946 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; | 962 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; |
| 947 virtual bool WasNpnNegotiated() const OVERRIDE; | 963 virtual bool WasNpnNegotiated() const OVERRIDE; |
| 948 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; | 964 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; |
| 949 | 965 |
| 950 // SSLClientSocket implementation. | 966 // SSLClientSocket implementation. |
| 967 virtual bool InSessionCache() const OVERRIDE; | |
| 968 virtual void SetHandshakeCompletionCallback(const base::Closure& cb) OVERRIDE; | |
| 951 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) | 969 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) |
| 952 OVERRIDE; | 970 OVERRIDE; |
| 953 virtual NextProtoStatus GetNextProto(std::string* proto) OVERRIDE; | 971 virtual NextProtoStatus GetNextProto(std::string* proto) OVERRIDE; |
| 954 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE; | 972 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE; |
| 955 virtual void set_protocol_negotiated(NextProto protocol_negotiated) OVERRIDE; | 973 virtual void set_protocol_negotiated(NextProto protocol_negotiated) OVERRIDE; |
| 956 virtual NextProto GetNegotiatedProtocol() const OVERRIDE; | 974 virtual NextProto GetNegotiatedProtocol() const OVERRIDE; |
| 957 | 975 |
| 958 // This MockSocket does not implement the manual async IO feature. | 976 // This MockSocket does not implement the manual async IO feature. |
| 959 virtual void OnReadComplete(const MockRead& data) OVERRIDE; | 977 virtual void OnReadComplete(const MockRead& data) OVERRIDE; |
| 960 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; | 978 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; |
| 961 | 979 |
| 962 virtual bool WasChannelIDSent() const OVERRIDE; | 980 virtual bool WasChannelIDSent() const OVERRIDE; |
| 963 virtual void set_channel_id_sent(bool channel_id_sent) OVERRIDE; | 981 virtual void set_channel_id_sent(bool channel_id_sent) OVERRIDE; |
| 964 virtual ChannelIDService* GetChannelIDService() const OVERRIDE; | 982 virtual ChannelIDService* GetChannelIDService() const OVERRIDE; |
| 965 | 983 |
| 984 bool reached_connect() const { return reached_connect_; } | |
| 985 | |
| 986 // Resumes the connection of a socket that was paused for testing. | |
| 987 // |connect_callback_| should be set before invoking this method. | |
| 988 void RestartPausedConnect(); | |
| 989 | |
| 966 private: | 990 private: |
| 967 static void ConnectCallback(MockSSLClientSocket* ssl_client_socket, | 991 enum ConnectState { |
| 968 const CompletionCallback& callback, | 992 STATE_NONE, |
| 969 int rv); | 993 STATE_TRANSPORT_CONNECT, |
| 994 STATE_TRANSPORT_CONNECT_COMPLETE, | |
|
wtc
2014/08/06 19:01:26
Please delete the STATE_TRANSPORT_CONNECT and STAT
| |
| 995 STATE_SSL_CONNECT, | |
| 996 STATE_SSL_CONNECT_COMPLETE, | |
| 997 }; | |
| 998 | |
| 999 void OnIOComplete(int result); | |
| 1000 | |
| 1001 // Runs the state transistion loop. | |
| 1002 int DoConnectLoop(int result); | |
| 1003 | |
| 1004 int DoTransportConnect(); | |
| 1005 int DoTransportConnectComplete(int result); | |
| 1006 int DoSSLConnect(); | |
| 1007 int DoSSLConnectComplete(int result); | |
| 970 | 1008 |
| 971 scoped_ptr<ClientSocketHandle> transport_; | 1009 scoped_ptr<ClientSocketHandle> transport_; |
| 972 SSLSocketDataProvider* data_; | 1010 SSLSocketDataProvider* data_; |
| 973 bool is_npn_state_set_; | 1011 bool is_npn_state_set_; |
| 974 bool new_npn_value_; | 1012 bool new_npn_value_; |
| 975 bool is_protocol_negotiated_set_; | 1013 bool is_protocol_negotiated_set_; |
| 976 NextProto protocol_negotiated_; | 1014 NextProto protocol_negotiated_; |
| 977 | 1015 |
| 1016 CompletionCallback connect_callback_; | |
| 1017 // Indicates what state of Connect the socket should enter. | |
| 1018 ConnectState next_connect_state_; | |
| 1019 // True if the Connect method has been called on the socket. | |
| 1020 bool reached_connect_; | |
| 1021 | |
| 1022 base::Closure handshake_completion_callback_; | |
| 1023 | |
| 1024 base::WeakPtrFactory<MockSSLClientSocket> weak_factory_; | |
| 1025 | |
| 978 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket); | 1026 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket); |
| 979 }; | 1027 }; |
| 980 | 1028 |
| 981 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket { | 1029 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket { |
| 982 public: | 1030 public: |
| 983 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); | 1031 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); |
| 984 virtual ~MockUDPClientSocket(); | 1032 virtual ~MockUDPClientSocket(); |
| 985 | 1033 |
| 986 // Socket implementation. | 1034 // Socket implementation. |
| 987 virtual int Read(IOBuffer* buf, | 1035 virtual int Read(IOBuffer* buf, |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1282 | 1330 |
| 1283 extern const char kSOCKS5OkRequest[]; | 1331 extern const char kSOCKS5OkRequest[]; |
| 1284 extern const int kSOCKS5OkRequestLength; | 1332 extern const int kSOCKS5OkRequestLength; |
| 1285 | 1333 |
| 1286 extern const char kSOCKS5OkResponse[]; | 1334 extern const char kSOCKS5OkResponse[]; |
| 1287 extern const int kSOCKS5OkResponseLength; | 1335 extern const int kSOCKS5OkResponseLength; |
| 1288 | 1336 |
| 1289 } // namespace net | 1337 } // namespace net |
| 1290 | 1338 |
| 1291 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 1339 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
| OLD | NEW |