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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 std::string next_proto; | 328 std::string next_proto; |
329 std::string server_protos; | 329 std::string server_protos; |
330 bool was_npn_negotiated; | 330 bool was_npn_negotiated; |
331 NextProto protocol_negotiated; | 331 NextProto protocol_negotiated; |
332 bool client_cert_sent; | 332 bool client_cert_sent; |
333 SSLCertRequestInfo* cert_request_info; | 333 SSLCertRequestInfo* cert_request_info; |
334 scoped_refptr<X509Certificate> cert; | 334 scoped_refptr<X509Certificate> cert; |
335 bool channel_id_sent; | 335 bool channel_id_sent; |
336 ServerBoundCertService* server_bound_cert_service; | 336 ServerBoundCertService* server_bound_cert_service; |
337 int connection_status; | 337 int connection_status; |
338 // Indicates that the socket should block in the Connect method. | |
339 bool should_block_on_connect; | |
340 bool is_in_session_cache; | |
338 }; | 341 }; |
339 | 342 |
340 // A DataProvider where the client must write a request before the reads (e.g. | 343 // A DataProvider where the client must write a request before the reads (e.g. |
341 // the response) will complete. | 344 // the response) will complete. |
342 class DelayedSocketData : public StaticSocketDataProvider { | 345 class DelayedSocketData : public StaticSocketDataProvider { |
343 public: | 346 public: |
344 // |write_delay| the number of MockWrites to complete before allowing | 347 // |write_delay| the number of MockWrites to complete before allowing |
345 // a MockRead to complete. | 348 // a MockRead to complete. |
346 // |reads| the list of MockRead completions. | 349 // |reads| the list of MockRead completions. |
347 // |writes| the list of MockWrite completions. | 350 // |writes| the list of MockWrite completions. |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
631 virtual ~MockClientSocketFactory(); | 634 virtual ~MockClientSocketFactory(); |
632 | 635 |
633 void AddSocketDataProvider(SocketDataProvider* socket); | 636 void AddSocketDataProvider(SocketDataProvider* socket); |
634 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket); | 637 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket); |
635 void ResetNextMockIndexes(); | 638 void ResetNextMockIndexes(); |
636 | 639 |
637 SocketDataProviderArray<SocketDataProvider>& mock_data() { | 640 SocketDataProviderArray<SocketDataProvider>& mock_data() { |
638 return mock_data_; | 641 return mock_data_; |
639 } | 642 } |
640 | 643 |
644 // Note: this method is unsafe; the elements of the returned vecotor | |
645 // are not necessarily valid. | |
646 const std::vector<MockSSLClientSocket*>& ssl_client_sockets() const { | |
647 return ssl_client_sockets_; | |
648 } | |
649 | |
641 // ClientSocketFactory | 650 // ClientSocketFactory |
642 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( | 651 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( |
643 DatagramSocket::BindType bind_type, | 652 DatagramSocket::BindType bind_type, |
644 const RandIntCallback& rand_int_cb, | 653 const RandIntCallback& rand_int_cb, |
645 NetLog* net_log, | 654 NetLog* net_log, |
646 const NetLog::Source& source) OVERRIDE; | 655 const NetLog::Source& source) OVERRIDE; |
647 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket( | 656 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket( |
648 const AddressList& addresses, | 657 const AddressList& addresses, |
649 NetLog* net_log, | 658 NetLog* net_log, |
650 const NetLog::Source& source) OVERRIDE; | 659 const NetLog::Source& source) OVERRIDE; |
651 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket( | 660 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket( |
652 scoped_ptr<ClientSocketHandle> transport_socket, | 661 scoped_ptr<ClientSocketHandle> transport_socket, |
653 const HostPortPair& host_and_port, | 662 const HostPortPair& host_and_port, |
654 const SSLConfig& ssl_config, | 663 const SSLConfig& ssl_config, |
655 const SSLClientSocketContext& context) OVERRIDE; | 664 const SSLClientSocketContext& context) OVERRIDE; |
656 virtual void ClearSSLSessionCache() OVERRIDE; | 665 virtual void ClearSSLSessionCache() OVERRIDE; |
657 | |
658 private: | 666 private: |
wtc
2014/07/23 22:53:32
Resurrect the blank line before this line.
mshelley
2014/07/24 20:37:46
Done.
| |
659 SocketDataProviderArray<SocketDataProvider> mock_data_; | 667 SocketDataProviderArray<SocketDataProvider> mock_data_; |
660 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; | 668 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; |
669 std::vector<MockSSLClientSocket*> ssl_client_sockets_; | |
661 }; | 670 }; |
662 | 671 |
663 class MockClientSocket : public SSLClientSocket { | 672 class MockClientSocket : public SSLClientSocket { |
664 public: | 673 public: |
665 // Value returned by GetTLSUniqueChannelBinding(). | 674 // Value returned by GetTLSUniqueChannelBinding(). |
666 static const char kTlsUnique[]; | 675 static const char kTlsUnique[]; |
667 | 676 |
668 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as | 677 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as |
669 // unique socket IDs. | 678 // unique socket IDs. |
670 explicit MockClientSocket(const BoundNetLog& net_log); | 679 explicit MockClientSocket(const BoundNetLog& net_log); |
(...skipping 13 matching lines...) Expand all Loading... | |
684 virtual void Disconnect() OVERRIDE; | 693 virtual void Disconnect() OVERRIDE; |
685 virtual bool IsConnected() const OVERRIDE; | 694 virtual bool IsConnected() const OVERRIDE; |
686 virtual bool IsConnectedAndIdle() const OVERRIDE; | 695 virtual bool IsConnectedAndIdle() const OVERRIDE; |
687 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; | 696 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; |
688 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; | 697 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; |
689 virtual const BoundNetLog& NetLog() const OVERRIDE; | 698 virtual const BoundNetLog& NetLog() const OVERRIDE; |
690 virtual void SetSubresourceSpeculation() OVERRIDE {} | 699 virtual void SetSubresourceSpeculation() OVERRIDE {} |
691 virtual void SetOmniboxSpeculation() OVERRIDE {} | 700 virtual void SetOmniboxSpeculation() OVERRIDE {} |
692 | 701 |
693 // SSLClientSocket implementation. | 702 // SSLClientSocket implementation. |
703 virtual bool InSessionCache() const OVERRIDE; | |
704 virtual void SetHandshakeCompletionCallback(const base::Closure& cb) OVERRIDE; | |
694 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) | 705 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) |
695 OVERRIDE; | 706 OVERRIDE; |
696 virtual int ExportKeyingMaterial(const base::StringPiece& label, | 707 virtual int ExportKeyingMaterial(const base::StringPiece& label, |
697 bool has_context, | 708 bool has_context, |
698 const base::StringPiece& context, | 709 const base::StringPiece& context, |
699 unsigned char* out, | 710 unsigned char* out, |
700 unsigned int outlen) OVERRIDE; | 711 unsigned int outlen) OVERRIDE; |
701 virtual int GetTLSUniqueChannelBinding(std::string* out) OVERRIDE; | 712 virtual int GetTLSUniqueChannelBinding(std::string* out) OVERRIDE; |
702 virtual NextProtoStatus GetNextProto(std::string* proto, | 713 virtual NextProtoStatus GetNextProto(std::string* proto, |
703 std::string* server_protos) OVERRIDE; | 714 std::string* server_protos) OVERRIDE; |
704 virtual ServerBoundCertService* GetServerBoundCertService() const OVERRIDE; | 715 virtual ServerBoundCertService* GetServerBoundCertService() const OVERRIDE; |
705 | 716 |
706 protected: | 717 protected: |
707 virtual ~MockClientSocket(); | 718 virtual ~MockClientSocket(); |
708 void RunCallbackAsync(const CompletionCallback& callback, int result); | 719 void RunCallbackAsync(const CompletionCallback& callback, int result); |
709 void RunCallback(const CompletionCallback& callback, int result); | 720 void RunCallback(const CompletionCallback& callback, int result); |
710 | 721 |
711 // SSLClientSocket implementation. | 722 // SSLClientSocket implementation. |
712 virtual scoped_refptr<X509Certificate> GetUnverifiedServerCertificateChain() | 723 virtual scoped_refptr<X509Certificate> GetUnverifiedServerCertificateChain() |
713 const OVERRIDE; | 724 const OVERRIDE; |
714 | 725 |
726 // Callback to be used to resume the connection of a paused socket. | |
727 CompletionCallback connect_callback_; | |
wtc
2014/07/23 22:53:32
Should this be moved to the MockSSLClientSocket cl
mshelley
2014/07/24 20:37:47
Done.
| |
728 | |
715 // True if Connect completed successfully and Disconnect hasn't been called. | 729 // True if Connect completed successfully and Disconnect hasn't been called. |
716 bool connected_; | 730 bool connected_; |
717 | 731 |
718 // Address of the "remote" peer we're connected to. | 732 // Address of the "remote" peer we're connected to. |
719 IPEndPoint peer_addr_; | 733 IPEndPoint peer_addr_; |
720 | 734 |
721 BoundNetLog net_log_; | 735 BoundNetLog net_log_; |
722 | 736 |
723 base::WeakPtrFactory<MockClientSocket> weak_factory_; | 737 base::WeakPtrFactory<MockClientSocket> weak_factory_; |
724 | 738 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
943 virtual int Connect(const CompletionCallback& callback) OVERRIDE; | 957 virtual int Connect(const CompletionCallback& callback) OVERRIDE; |
944 virtual void Disconnect() OVERRIDE; | 958 virtual void Disconnect() OVERRIDE; |
945 virtual bool IsConnected() const OVERRIDE; | 959 virtual bool IsConnected() const OVERRIDE; |
946 virtual bool WasEverUsed() const OVERRIDE; | 960 virtual bool WasEverUsed() const OVERRIDE; |
947 virtual bool UsingTCPFastOpen() const OVERRIDE; | 961 virtual bool UsingTCPFastOpen() const OVERRIDE; |
948 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; | 962 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; |
949 virtual bool WasNpnNegotiated() const OVERRIDE; | 963 virtual bool WasNpnNegotiated() const OVERRIDE; |
950 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; | 964 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; |
951 | 965 |
952 // SSLClientSocket implementation. | 966 // SSLClientSocket implementation. |
967 virtual bool InSessionCache() const OVERRIDE; | |
968 virtual void SetHandshakeCompletionCallback(const base::Closure& cb) OVERRIDE; | |
953 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) | 969 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) |
954 OVERRIDE; | 970 OVERRIDE; |
955 virtual NextProtoStatus GetNextProto(std::string* proto, | 971 virtual NextProtoStatus GetNextProto(std::string* proto, |
956 std::string* server_protos) OVERRIDE; | 972 std::string* server_protos) OVERRIDE; |
957 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE; | 973 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE; |
958 virtual void set_protocol_negotiated(NextProto protocol_negotiated) OVERRIDE; | 974 virtual void set_protocol_negotiated(NextProto protocol_negotiated) OVERRIDE; |
959 virtual NextProto GetNegotiatedProtocol() const OVERRIDE; | 975 virtual NextProto GetNegotiatedProtocol() const OVERRIDE; |
960 | 976 |
961 // This MockSocket does not implement the manual async IO feature. | 977 // This MockSocket does not implement the manual async IO feature. |
962 virtual void OnReadComplete(const MockRead& data) OVERRIDE; | 978 virtual void OnReadComplete(const MockRead& data) OVERRIDE; |
963 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; | 979 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; |
964 | 980 |
965 virtual bool WasChannelIDSent() const OVERRIDE; | 981 virtual bool WasChannelIDSent() const OVERRIDE; |
966 virtual void set_channel_id_sent(bool channel_id_sent) OVERRIDE; | 982 virtual void set_channel_id_sent(bool channel_id_sent) OVERRIDE; |
967 virtual ServerBoundCertService* GetServerBoundCertService() const OVERRIDE; | 983 virtual ServerBoundCertService* GetServerBoundCertService() const OVERRIDE; |
968 | 984 |
985 // Resumes the connection of a socket that was paused for testing. | |
986 // |connect_callback_| should be set before invoking this method. | |
987 void RestartPausedConnect(); | |
988 | |
969 private: | 989 private: |
990 enum ConnectState { | |
991 STATE_NONE, | |
992 STATE_CONNECT, | |
993 STATE_CONNECT_COMPLETE, | |
994 }; | |
995 | |
970 static void ConnectCallback(MockSSLClientSocket* ssl_client_socket, | 996 static void ConnectCallback(MockSSLClientSocket* ssl_client_socket, |
971 const CompletionCallback& callback, | 997 const CompletionCallback& callback, |
972 int rv); | 998 int rv); |
973 | 999 |
1000 int DoConnect(const CompletionCallback& callback); | |
1001 int DoConnectComplete(const CompletionCallback& callback); | |
1002 | |
974 scoped_ptr<ClientSocketHandle> transport_; | 1003 scoped_ptr<ClientSocketHandle> transport_; |
975 SSLSocketDataProvider* data_; | 1004 SSLSocketDataProvider* data_; |
976 bool is_npn_state_set_; | 1005 bool is_npn_state_set_; |
977 bool new_npn_value_; | 1006 bool new_npn_value_; |
978 bool is_protocol_negotiated_set_; | 1007 bool is_protocol_negotiated_set_; |
979 NextProto protocol_negotiated_; | 1008 NextProto protocol_negotiated_; |
980 | 1009 |
1010 // Indicates what state of Connect the socket should enter. | |
1011 ConnectState next_connect_state_; | |
1012 | |
1013 base::Closure completion_callback_; | |
wtc
2014/07/23 22:53:32
Please name this field "handshake_completion_callb
mshelley
2014/07/24 20:37:46
Done.
| |
1014 | |
981 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket); | 1015 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket); |
982 }; | 1016 }; |
983 | 1017 |
984 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket { | 1018 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket { |
985 public: | 1019 public: |
986 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); | 1020 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); |
987 virtual ~MockUDPClientSocket(); | 1021 virtual ~MockUDPClientSocket(); |
988 | 1022 |
989 // Socket implementation. | 1023 // Socket implementation. |
990 virtual int Read(IOBuffer* buf, | 1024 virtual int Read(IOBuffer* buf, |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1285 | 1319 |
1286 extern const char kSOCKS5OkRequest[]; | 1320 extern const char kSOCKS5OkRequest[]; |
1287 extern const int kSOCKS5OkRequestLength; | 1321 extern const int kSOCKS5OkRequestLength; |
1288 | 1322 |
1289 extern const char kSOCKS5OkResponse[]; | 1323 extern const char kSOCKS5OkResponse[]; |
1290 extern const int kSOCKS5OkResponseLength; | 1324 extern const int kSOCKS5OkResponseLength; |
1291 | 1325 |
1292 } // namespace net | 1326 } // namespace net |
1293 | 1327 |
1294 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 1328 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
OLD | NEW |