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. | |
| 338 bool should_block_on_connect; | |
| 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 |
| 719 bool reached_connect() const { return reached_connect_; } | |
| 720 | |
| 704 protected: | 721 protected: |
| 705 virtual ~MockClientSocket(); | 722 virtual ~MockClientSocket(); |
| 706 void RunCallbackAsync(const CompletionCallback& callback, int result); | 723 void RunCallbackAsync(const CompletionCallback& callback, int result); |
| 707 void RunCallback(const CompletionCallback& callback, int result); | 724 void RunCallback(const CompletionCallback& callback, int result); |
| 708 | 725 |
| 709 // SSLClientSocket implementation. | 726 // SSLClientSocket implementation. |
| 710 virtual scoped_refptr<X509Certificate> GetUnverifiedServerCertificateChain() | 727 virtual scoped_refptr<X509Certificate> GetUnverifiedServerCertificateChain() |
| 711 const OVERRIDE; | 728 const OVERRIDE; |
| 712 | 729 |
| 713 // True if Connect completed successfully and Disconnect hasn't been called. | 730 // True if Connect completed successfully and Disconnect hasn't been called. |
| 714 bool connected_; | 731 bool connected_; |
| 715 | 732 |
| 733 // True if the Connect method has been called on the socket. | |
| 734 bool reached_connect_; | |
|
wtc
2014/08/03 01:49:10
Please move the reached_connect_ member and the re
mshelley
2014/08/03 23:37:09
Done.
| |
| 735 | |
| 716 // Address of the "remote" peer we're connected to. | 736 // Address of the "remote" peer we're connected to. |
| 717 IPEndPoint peer_addr_; | 737 IPEndPoint peer_addr_; |
| 718 | 738 |
| 719 BoundNetLog net_log_; | 739 BoundNetLog net_log_; |
| 720 | 740 |
| 741 private: | |
| 721 base::WeakPtrFactory<MockClientSocket> weak_factory_; | 742 base::WeakPtrFactory<MockClientSocket> weak_factory_; |
| 722 | 743 |
| 723 DISALLOW_COPY_AND_ASSIGN(MockClientSocket); | 744 DISALLOW_COPY_AND_ASSIGN(MockClientSocket); |
| 724 }; | 745 }; |
| 725 | 746 |
| 726 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket { | 747 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket { |
| 727 public: | 748 public: |
| 728 MockTCPClientSocket(const AddressList& addresses, | 749 MockTCPClientSocket(const AddressList& addresses, |
| 729 net::NetLog* net_log, | 750 net::NetLog* net_log, |
| 730 SocketDataProvider* socket); | 751 SocketDataProvider* socket); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 941 virtual int Connect(const CompletionCallback& callback) OVERRIDE; | 962 virtual int Connect(const CompletionCallback& callback) OVERRIDE; |
| 942 virtual void Disconnect() OVERRIDE; | 963 virtual void Disconnect() OVERRIDE; |
| 943 virtual bool IsConnected() const OVERRIDE; | 964 virtual bool IsConnected() const OVERRIDE; |
| 944 virtual bool WasEverUsed() const OVERRIDE; | 965 virtual bool WasEverUsed() const OVERRIDE; |
| 945 virtual bool UsingTCPFastOpen() const OVERRIDE; | 966 virtual bool UsingTCPFastOpen() const OVERRIDE; |
| 946 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; | 967 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; |
| 947 virtual bool WasNpnNegotiated() const OVERRIDE; | 968 virtual bool WasNpnNegotiated() const OVERRIDE; |
| 948 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; | 969 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; |
| 949 | 970 |
| 950 // SSLClientSocket implementation. | 971 // SSLClientSocket implementation. |
| 972 virtual bool InSessionCache() const OVERRIDE; | |
| 973 virtual void SetHandshakeCompletionCallback(const base::Closure& cb) OVERRIDE; | |
| 951 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) | 974 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) |
| 952 OVERRIDE; | 975 OVERRIDE; |
| 953 virtual NextProtoStatus GetNextProto(std::string* proto) OVERRIDE; | 976 virtual NextProtoStatus GetNextProto(std::string* proto) OVERRIDE; |
| 954 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE; | 977 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE; |
| 955 virtual void set_protocol_negotiated(NextProto protocol_negotiated) OVERRIDE; | 978 virtual void set_protocol_negotiated(NextProto protocol_negotiated) OVERRIDE; |
| 956 virtual NextProto GetNegotiatedProtocol() const OVERRIDE; | 979 virtual NextProto GetNegotiatedProtocol() const OVERRIDE; |
| 957 | 980 |
| 958 // This MockSocket does not implement the manual async IO feature. | 981 // This MockSocket does not implement the manual async IO feature. |
| 959 virtual void OnReadComplete(const MockRead& data) OVERRIDE; | 982 virtual void OnReadComplete(const MockRead& data) OVERRIDE; |
| 960 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; | 983 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; |
| 961 | 984 |
| 962 virtual bool WasChannelIDSent() const OVERRIDE; | 985 virtual bool WasChannelIDSent() const OVERRIDE; |
| 963 virtual void set_channel_id_sent(bool channel_id_sent) OVERRIDE; | 986 virtual void set_channel_id_sent(bool channel_id_sent) OVERRIDE; |
| 964 virtual ChannelIDService* GetChannelIDService() const OVERRIDE; | 987 virtual ChannelIDService* GetChannelIDService() const OVERRIDE; |
| 965 | 988 |
| 989 // Resumes the connection of a socket that was paused for testing. | |
| 990 // |connect_callback_| should be set before invoking this method. | |
| 991 void RestartPausedConnect(); | |
| 992 | |
| 966 private: | 993 private: |
| 967 static void ConnectCallback(MockSSLClientSocket* ssl_client_socket, | 994 enum ConnectState { |
| 968 const CompletionCallback& callback, | 995 STATE_NONE, |
| 969 int rv); | 996 STATE_TRANSPORT_CONNECT, |
| 997 STATE_TRANSPORT_CONNECT_COMPLETE, | |
| 998 STATE_SSL_CONNECT, | |
| 999 STATE_SSL_CONNECT_COMPLETE, | |
| 1000 }; | |
| 1001 | |
| 1002 void OnIOComplete(int result); | |
| 1003 | |
| 1004 // Runs the state transistion loop. | |
| 1005 int DoConnectLoop(int result); | |
| 1006 | |
| 1007 int DoTransportConnect(); | |
| 1008 int DoTransportConnectComplete(int result); | |
| 1009 int DoSSLConnect(); | |
| 1010 int DoSSLConnectComplete(int result); | |
| 970 | 1011 |
| 971 scoped_ptr<ClientSocketHandle> transport_; | 1012 scoped_ptr<ClientSocketHandle> transport_; |
| 972 SSLSocketDataProvider* data_; | 1013 SSLSocketDataProvider* data_; |
| 973 bool is_npn_state_set_; | 1014 bool is_npn_state_set_; |
| 974 bool new_npn_value_; | 1015 bool new_npn_value_; |
| 975 bool is_protocol_negotiated_set_; | 1016 bool is_protocol_negotiated_set_; |
| 976 NextProto protocol_negotiated_; | 1017 NextProto protocol_negotiated_; |
| 977 | 1018 |
| 1019 CompletionCallback connect_callback_; | |
| 1020 // Indicates what state of Connect the socket should enter. | |
| 1021 ConnectState next_connect_state_; | |
| 1022 | |
| 1023 base::Closure handshake_completion_callback_; | |
| 1024 | |
| 1025 base::WeakPtrFactory<MockSSLClientSocket> weak_factory_; | |
| 1026 | |
| 978 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket); | 1027 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket); |
| 979 }; | 1028 }; |
| 980 | 1029 |
| 981 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket { | 1030 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket { |
| 982 public: | 1031 public: |
| 983 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); | 1032 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); |
| 984 virtual ~MockUDPClientSocket(); | 1033 virtual ~MockUDPClientSocket(); |
| 985 | 1034 |
| 986 // Socket implementation. | 1035 // Socket implementation. |
| 987 virtual int Read(IOBuffer* buf, | 1036 virtual int Read(IOBuffer* buf, |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1282 | 1331 |
| 1283 extern const char kSOCKS5OkRequest[]; | 1332 extern const char kSOCKS5OkRequest[]; |
| 1284 extern const int kSOCKS5OkRequestLength; | 1333 extern const int kSOCKS5OkRequestLength; |
| 1285 | 1334 |
| 1286 extern const char kSOCKS5OkResponse[]; | 1335 extern const char kSOCKS5OkResponse[]; |
| 1287 extern const int kSOCKS5OkResponseLength; | 1336 extern const int kSOCKS5OkResponseLength; |
| 1288 | 1337 |
| 1289 } // namespace net | 1338 } // namespace net |
| 1290 | 1339 |
| 1291 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 1340 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
| OLD | NEW |