| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <cstring> | 9 #include <cstring> |
| 10 #include <deque> | 10 #include <deque> |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 enum { | 39 enum { |
| 40 // A private network error code used by the socket test utility classes. | 40 // A private network error code used by the socket test utility classes. |
| 41 // If the |result| member of a MockRead is | 41 // If the |result| member of a MockRead is |
| 42 // ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, that MockRead is just a | 42 // ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ, that MockRead is just a |
| 43 // marker that indicates the peer will close the connection after the next | 43 // marker that indicates the peer will close the connection after the next |
| 44 // MockRead. The other members of that MockRead are ignored. | 44 // MockRead. The other members of that MockRead are ignored. |
| 45 ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ = -10000, | 45 ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ = -10000, |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 class ClientSocket; | |
| 49 class MockClientSocket; | 48 class MockClientSocket; |
| 50 class SSLClientSocket; | 49 class SSLClientSocket; |
| 51 class SSLHostInfo; | 50 class SSLHostInfo; |
| 51 class StreamSocket; |
| 52 | 52 |
| 53 struct MockConnect { | 53 struct MockConnect { |
| 54 // Asynchronous connection success. | 54 // Asynchronous connection success. |
| 55 MockConnect() : async(true), result(OK) { } | 55 MockConnect() : async(true), result(OK) { } |
| 56 MockConnect(bool a, int r) : async(a), result(r) { } | 56 MockConnect(bool a, int r) : async(a), result(r) { } |
| 57 | 57 |
| 58 bool async; | 58 bool async; |
| 59 int result; | 59 int result; |
| 60 }; | 60 }; |
| 61 | 61 |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 | 461 |
| 462 int sequence_number_; | 462 int sequence_number_; |
| 463 MockRead current_read_; | 463 MockRead current_read_; |
| 464 MockWrite current_write_; | 464 MockWrite current_write_; |
| 465 int stopping_sequence_number_; | 465 int stopping_sequence_number_; |
| 466 bool stopped_; | 466 bool stopped_; |
| 467 base::WeakPtr<DeterministicMockTCPClientSocket> socket_; | 467 base::WeakPtr<DeterministicMockTCPClientSocket> socket_; |
| 468 bool print_debug_; | 468 bool print_debug_; |
| 469 }; | 469 }; |
| 470 | 470 |
| 471 // Holds an array of SocketDataProvider elements. As Mock{TCP,SSL}ClientSocket | 471 // Holds an array of SocketDataProvider elements. As Mock{TCP,SSL}StreamSocket |
| 472 // objects get instantiated, they take their data from the i'th element of this | 472 // objects get instantiated, they take their data from the i'th element of this |
| 473 // array. | 473 // array. |
| 474 template<typename T> | 474 template<typename T> |
| 475 class SocketDataProviderArray { | 475 class SocketDataProviderArray { |
| 476 public: | 476 public: |
| 477 SocketDataProviderArray() : next_index_(0) { | 477 SocketDataProviderArray() : next_index_(0) { |
| 478 } | 478 } |
| 479 | 479 |
| 480 T* GetNext() { | 480 T* GetNext() { |
| 481 DCHECK_LT(next_index_, data_providers_.size()); | 481 DCHECK_LT(next_index_, data_providers_.size()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 MockSSLClientSocket* GetMockSSLClientSocket(size_t index) const; | 526 MockSSLClientSocket* GetMockSSLClientSocket(size_t index) const; |
| 527 | 527 |
| 528 SocketDataProviderArray<SocketDataProvider>& mock_data() { | 528 SocketDataProviderArray<SocketDataProvider>& mock_data() { |
| 529 return mock_data_; | 529 return mock_data_; |
| 530 } | 530 } |
| 531 std::vector<MockTCPClientSocket*>& tcp_client_sockets() { | 531 std::vector<MockTCPClientSocket*>& tcp_client_sockets() { |
| 532 return tcp_client_sockets_; | 532 return tcp_client_sockets_; |
| 533 } | 533 } |
| 534 | 534 |
| 535 // ClientSocketFactory | 535 // ClientSocketFactory |
| 536 virtual ClientSocket* CreateTransportClientSocket( | 536 virtual StreamSocket* CreateTransportClientSocket( |
| 537 const AddressList& addresses, | 537 const AddressList& addresses, |
| 538 NetLog* net_log, | 538 NetLog* net_log, |
| 539 const NetLog::Source& source); | 539 const NetLog::Source& source); |
| 540 virtual SSLClientSocket* CreateSSLClientSocket( | 540 virtual SSLClientSocket* CreateSSLClientSocket( |
| 541 ClientSocketHandle* transport_socket, | 541 ClientSocketHandle* transport_socket, |
| 542 const HostPortPair& host_and_port, | 542 const HostPortPair& host_and_port, |
| 543 const SSLConfig& ssl_config, | 543 const SSLConfig& ssl_config, |
| 544 SSLHostInfo* ssl_host_info, | 544 SSLHostInfo* ssl_host_info, |
| 545 CertVerifier* cert_verifier, | 545 CertVerifier* cert_verifier, |
| 546 DnsCertProvenanceChecker* dns_cert_checker); | 546 DnsCertProvenanceChecker* dns_cert_checker); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 567 virtual void OnReadComplete(const MockRead& data) = 0; | 567 virtual void OnReadComplete(const MockRead& data) = 0; |
| 568 | 568 |
| 569 // Socket methods: | 569 // Socket methods: |
| 570 virtual int Read(net::IOBuffer* buf, int buf_len, | 570 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 571 net::CompletionCallback* callback) = 0; | 571 net::CompletionCallback* callback) = 0; |
| 572 virtual int Write(net::IOBuffer* buf, int buf_len, | 572 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 573 net::CompletionCallback* callback) = 0; | 573 net::CompletionCallback* callback) = 0; |
| 574 virtual bool SetReceiveBufferSize(int32 size); | 574 virtual bool SetReceiveBufferSize(int32 size); |
| 575 virtual bool SetSendBufferSize(int32 size); | 575 virtual bool SetSendBufferSize(int32 size); |
| 576 | 576 |
| 577 // ClientSocket methods: | 577 // StreamSocket methods: |
| 578 virtual int Connect(net::CompletionCallback* callback) = 0; | 578 virtual int Connect(net::CompletionCallback* callback) = 0; |
| 579 virtual void Disconnect(); | 579 virtual void Disconnect(); |
| 580 virtual bool IsConnected() const; | 580 virtual bool IsConnected() const; |
| 581 virtual bool IsConnectedAndIdle() const; | 581 virtual bool IsConnectedAndIdle() const; |
| 582 virtual int GetPeerAddress(AddressList* address) const; | 582 virtual int GetPeerAddress(AddressList* address) const; |
| 583 virtual int GetLocalAddress(IPEndPoint* address) const; | 583 virtual int GetLocalAddress(IPEndPoint* address) const; |
| 584 virtual const BoundNetLog& NetLog() const; | 584 virtual const BoundNetLog& NetLog() const; |
| 585 virtual void SetSubresourceSpeculation() {} | 585 virtual void SetSubresourceSpeculation() {} |
| 586 virtual void SetOmniboxSpeculation() {} | 586 virtual void SetOmniboxSpeculation() {} |
| 587 | 587 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 610 net::SocketDataProvider* socket); | 610 net::SocketDataProvider* socket); |
| 611 | 611 |
| 612 net::AddressList addresses() const { return addresses_; } | 612 net::AddressList addresses() const { return addresses_; } |
| 613 | 613 |
| 614 // Socket methods: | 614 // Socket methods: |
| 615 virtual int Read(net::IOBuffer* buf, int buf_len, | 615 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 616 net::CompletionCallback* callback); | 616 net::CompletionCallback* callback); |
| 617 virtual int Write(net::IOBuffer* buf, int buf_len, | 617 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 618 net::CompletionCallback* callback); | 618 net::CompletionCallback* callback); |
| 619 | 619 |
| 620 // ClientSocket methods: | 620 // StreamSocket methods: |
| 621 virtual int Connect(net::CompletionCallback* callback); | 621 virtual int Connect(net::CompletionCallback* callback); |
| 622 virtual void Disconnect(); | 622 virtual void Disconnect(); |
| 623 virtual bool IsConnected() const; | 623 virtual bool IsConnected() const; |
| 624 virtual bool IsConnectedAndIdle() const; | 624 virtual bool IsConnectedAndIdle() const; |
| 625 virtual bool WasEverUsed() const; | 625 virtual bool WasEverUsed() const; |
| 626 virtual bool UsingTCPFastOpen() const; | 626 virtual bool UsingTCPFastOpen() const; |
| 627 | 627 |
| 628 // MockClientSocket: | 628 // MockClientSocket: |
| 629 virtual void OnReadComplete(const MockRead& data); | 629 virtual void OnReadComplete(const MockRead& data); |
| 630 | 630 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 | 662 |
| 663 void CompleteWrite(); | 663 void CompleteWrite(); |
| 664 int CompleteRead(); | 664 int CompleteRead(); |
| 665 | 665 |
| 666 // Socket: | 666 // Socket: |
| 667 virtual int Write(net::IOBuffer* buf, int buf_len, | 667 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 668 net::CompletionCallback* callback); | 668 net::CompletionCallback* callback); |
| 669 virtual int Read(net::IOBuffer* buf, int buf_len, | 669 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 670 net::CompletionCallback* callback); | 670 net::CompletionCallback* callback); |
| 671 | 671 |
| 672 // ClientSocket: | 672 // StreamSocket: |
| 673 virtual int Connect(net::CompletionCallback* callback); | 673 virtual int Connect(net::CompletionCallback* callback); |
| 674 virtual void Disconnect(); | 674 virtual void Disconnect(); |
| 675 virtual bool IsConnected() const; | 675 virtual bool IsConnected() const; |
| 676 virtual bool IsConnectedAndIdle() const; | 676 virtual bool IsConnectedAndIdle() const; |
| 677 virtual bool WasEverUsed() const; | 677 virtual bool WasEverUsed() const; |
| 678 virtual bool UsingTCPFastOpen() const; | 678 virtual bool UsingTCPFastOpen() const; |
| 679 | 679 |
| 680 // MockClientSocket: | 680 // MockClientSocket: |
| 681 virtual void OnReadComplete(const MockRead& data); | 681 virtual void OnReadComplete(const MockRead& data); |
| 682 | 682 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 704 SSLHostInfo* ssl_host_info, | 704 SSLHostInfo* ssl_host_info, |
| 705 net::SSLSocketDataProvider* socket); | 705 net::SSLSocketDataProvider* socket); |
| 706 virtual ~MockSSLClientSocket(); | 706 virtual ~MockSSLClientSocket(); |
| 707 | 707 |
| 708 // Socket methods: | 708 // Socket methods: |
| 709 virtual int Read(net::IOBuffer* buf, int buf_len, | 709 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 710 net::CompletionCallback* callback); | 710 net::CompletionCallback* callback); |
| 711 virtual int Write(net::IOBuffer* buf, int buf_len, | 711 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 712 net::CompletionCallback* callback); | 712 net::CompletionCallback* callback); |
| 713 | 713 |
| 714 // ClientSocket methods: | 714 // StreamSocket methods: |
| 715 virtual int Connect(net::CompletionCallback* callback); | 715 virtual int Connect(net::CompletionCallback* callback); |
| 716 virtual void Disconnect(); | 716 virtual void Disconnect(); |
| 717 virtual bool IsConnected() const; | 717 virtual bool IsConnected() const; |
| 718 virtual bool WasEverUsed() const; | 718 virtual bool WasEverUsed() const; |
| 719 virtual bool UsingTCPFastOpen() const; | 719 virtual bool UsingTCPFastOpen() const; |
| 720 | 720 |
| 721 // SSLClientSocket methods: | 721 // SSLClientSocket methods: |
| 722 virtual void GetSSLInfo(net::SSLInfo* ssl_info); | 722 virtual void GetSSLInfo(net::SSLInfo* ssl_info); |
| 723 virtual void GetSSLCertRequestInfo( | 723 virtual void GetSSLCertRequestInfo( |
| 724 net::SSLCertRequestInfo* cert_request_info); | 724 net::SSLCertRequestInfo* cert_request_info); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 private: | 811 private: |
| 812 ScopedVector<TestSocketRequest> requests_; | 812 ScopedVector<TestSocketRequest> requests_; |
| 813 std::vector<TestSocketRequest*> request_order_; | 813 std::vector<TestSocketRequest*> request_order_; |
| 814 size_t completion_count_; | 814 size_t completion_count_; |
| 815 }; | 815 }; |
| 816 | 816 |
| 817 class MockTransportClientSocketPool : public TransportClientSocketPool { | 817 class MockTransportClientSocketPool : public TransportClientSocketPool { |
| 818 public: | 818 public: |
| 819 class MockConnectJob { | 819 class MockConnectJob { |
| 820 public: | 820 public: |
| 821 MockConnectJob(ClientSocket* socket, ClientSocketHandle* handle, | 821 MockConnectJob(StreamSocket* socket, ClientSocketHandle* handle, |
| 822 CompletionCallback* callback); | 822 CompletionCallback* callback); |
| 823 ~MockConnectJob(); | 823 ~MockConnectJob(); |
| 824 | 824 |
| 825 int Connect(); | 825 int Connect(); |
| 826 bool CancelHandle(const ClientSocketHandle* handle); | 826 bool CancelHandle(const ClientSocketHandle* handle); |
| 827 | 827 |
| 828 private: | 828 private: |
| 829 void OnConnect(int rv); | 829 void OnConnect(int rv); |
| 830 | 830 |
| 831 scoped_ptr<ClientSocket> socket_; | 831 scoped_ptr<StreamSocket> socket_; |
| 832 ClientSocketHandle* handle_; | 832 ClientSocketHandle* handle_; |
| 833 CompletionCallback* user_callback_; | 833 CompletionCallback* user_callback_; |
| 834 CompletionCallbackImpl<MockConnectJob> connect_callback_; | 834 CompletionCallbackImpl<MockConnectJob> connect_callback_; |
| 835 | 835 |
| 836 DISALLOW_COPY_AND_ASSIGN(MockConnectJob); | 836 DISALLOW_COPY_AND_ASSIGN(MockConnectJob); |
| 837 }; | 837 }; |
| 838 | 838 |
| 839 MockTransportClientSocketPool( | 839 MockTransportClientSocketPool( |
| 840 int max_sockets, | 840 int max_sockets, |
| 841 int max_sockets_per_group, | 841 int max_sockets_per_group, |
| 842 ClientSocketPoolHistograms* histograms, | 842 ClientSocketPoolHistograms* histograms, |
| 843 ClientSocketFactory* socket_factory); | 843 ClientSocketFactory* socket_factory); |
| 844 | 844 |
| 845 virtual ~MockTransportClientSocketPool(); | 845 virtual ~MockTransportClientSocketPool(); |
| 846 | 846 |
| 847 int release_count() const { return release_count_; } | 847 int release_count() const { return release_count_; } |
| 848 int cancel_count() const { return cancel_count_; } | 848 int cancel_count() const { return cancel_count_; } |
| 849 | 849 |
| 850 // TransportClientSocketPool methods. | 850 // TransportClientSocketPool methods. |
| 851 virtual int RequestSocket(const std::string& group_name, | 851 virtual int RequestSocket(const std::string& group_name, |
| 852 const void* socket_params, | 852 const void* socket_params, |
| 853 RequestPriority priority, | 853 RequestPriority priority, |
| 854 ClientSocketHandle* handle, | 854 ClientSocketHandle* handle, |
| 855 CompletionCallback* callback, | 855 CompletionCallback* callback, |
| 856 const BoundNetLog& net_log); | 856 const BoundNetLog& net_log); |
| 857 | 857 |
| 858 virtual void CancelRequest(const std::string& group_name, | 858 virtual void CancelRequest(const std::string& group_name, |
| 859 ClientSocketHandle* handle); | 859 ClientSocketHandle* handle); |
| 860 virtual void ReleaseSocket(const std::string& group_name, | 860 virtual void ReleaseSocket(const std::string& group_name, |
| 861 ClientSocket* socket, int id); | 861 StreamSocket* socket, int id); |
| 862 | 862 |
| 863 private: | 863 private: |
| 864 ClientSocketFactory* client_socket_factory_; | 864 ClientSocketFactory* client_socket_factory_; |
| 865 ScopedVector<MockConnectJob> job_list_; | 865 ScopedVector<MockConnectJob> job_list_; |
| 866 int release_count_; | 866 int release_count_; |
| 867 int cancel_count_; | 867 int cancel_count_; |
| 868 | 868 |
| 869 DISALLOW_COPY_AND_ASSIGN(MockTransportClientSocketPool); | 869 DISALLOW_COPY_AND_ASSIGN(MockTransportClientSocketPool); |
| 870 }; | 870 }; |
| 871 | 871 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 883 MockSSLClientSocket* GetMockSSLClientSocket(size_t index) const; | 883 MockSSLClientSocket* GetMockSSLClientSocket(size_t index) const; |
| 884 | 884 |
| 885 SocketDataProviderArray<DeterministicSocketData>& mock_data() { | 885 SocketDataProviderArray<DeterministicSocketData>& mock_data() { |
| 886 return mock_data_; | 886 return mock_data_; |
| 887 } | 887 } |
| 888 std::vector<DeterministicMockTCPClientSocket*>& tcp_client_sockets() { | 888 std::vector<DeterministicMockTCPClientSocket*>& tcp_client_sockets() { |
| 889 return tcp_client_sockets_; | 889 return tcp_client_sockets_; |
| 890 } | 890 } |
| 891 | 891 |
| 892 // ClientSocketFactory | 892 // ClientSocketFactory |
| 893 virtual ClientSocket* CreateTransportClientSocket( | 893 virtual StreamSocket* CreateTransportClientSocket( |
| 894 const AddressList& addresses, | 894 const AddressList& addresses, |
| 895 NetLog* net_log, | 895 NetLog* net_log, |
| 896 const NetLog::Source& source); | 896 const NetLog::Source& source); |
| 897 virtual SSLClientSocket* CreateSSLClientSocket( | 897 virtual SSLClientSocket* CreateSSLClientSocket( |
| 898 ClientSocketHandle* transport_socket, | 898 ClientSocketHandle* transport_socket, |
| 899 const HostPortPair& host_and_port, | 899 const HostPortPair& host_and_port, |
| 900 const SSLConfig& ssl_config, | 900 const SSLConfig& ssl_config, |
| 901 SSLHostInfo* ssl_host_info, | 901 SSLHostInfo* ssl_host_info, |
| 902 CertVerifier* cert_verifier, | 902 CertVerifier* cert_verifier, |
| 903 DnsCertProvenanceChecker* dns_cert_checker); | 903 DnsCertProvenanceChecker* dns_cert_checker); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 926 virtual int RequestSocket(const std::string& group_name, | 926 virtual int RequestSocket(const std::string& group_name, |
| 927 const void* socket_params, | 927 const void* socket_params, |
| 928 RequestPriority priority, | 928 RequestPriority priority, |
| 929 ClientSocketHandle* handle, | 929 ClientSocketHandle* handle, |
| 930 CompletionCallback* callback, | 930 CompletionCallback* callback, |
| 931 const BoundNetLog& net_log); | 931 const BoundNetLog& net_log); |
| 932 | 932 |
| 933 virtual void CancelRequest(const std::string& group_name, | 933 virtual void CancelRequest(const std::string& group_name, |
| 934 ClientSocketHandle* handle); | 934 ClientSocketHandle* handle); |
| 935 virtual void ReleaseSocket(const std::string& group_name, | 935 virtual void ReleaseSocket(const std::string& group_name, |
| 936 ClientSocket* socket, int id); | 936 StreamSocket* socket, int id); |
| 937 | 937 |
| 938 private: | 938 private: |
| 939 TransportClientSocketPool* const transport_pool_; | 939 TransportClientSocketPool* const transport_pool_; |
| 940 | 940 |
| 941 DISALLOW_COPY_AND_ASSIGN(MockSOCKSClientSocketPool); | 941 DISALLOW_COPY_AND_ASSIGN(MockSOCKSClientSocketPool); |
| 942 }; | 942 }; |
| 943 | 943 |
| 944 // Constants for a successful SOCKS v5 handshake. | 944 // Constants for a successful SOCKS v5 handshake. |
| 945 extern const char kSOCKS5GreetRequest[]; | 945 extern const char kSOCKS5GreetRequest[]; |
| 946 extern const int kSOCKS5GreetRequestLength; | 946 extern const int kSOCKS5GreetRequestLength; |
| 947 | 947 |
| 948 extern const char kSOCKS5GreetResponse[]; | 948 extern const char kSOCKS5GreetResponse[]; |
| 949 extern const int kSOCKS5GreetResponseLength; | 949 extern const int kSOCKS5GreetResponseLength; |
| 950 | 950 |
| 951 extern const char kSOCKS5OkRequest[]; | 951 extern const char kSOCKS5OkRequest[]; |
| 952 extern const int kSOCKS5OkRequestLength; | 952 extern const int kSOCKS5OkRequestLength; |
| 953 | 953 |
| 954 extern const char kSOCKS5OkResponse[]; | 954 extern const char kSOCKS5OkResponse[]; |
| 955 extern const int kSOCKS5OkResponseLength; | 955 extern const int kSOCKS5OkResponseLength; |
| 956 | 956 |
| 957 } // namespace net | 957 } // namespace net |
| 958 | 958 |
| 959 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 959 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
| OLD | NEW |