| 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 568 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 std::vector<MockSSLClientSocket*> ssl_client_sockets_; | 579 std::vector<MockSSLClientSocket*> ssl_client_sockets_; |
| 580 }; | 580 }; |
| 581 | 581 |
| 582 class MockClientSocket : public net::SSLClientSocket { | 582 class MockClientSocket : public net::SSLClientSocket { |
| 583 public: | 583 public: |
| 584 explicit MockClientSocket(net::NetLog* net_log); | 584 explicit MockClientSocket(net::NetLog* net_log); |
| 585 | 585 |
| 586 // Socket implementation. | 586 // Socket implementation. |
| 587 virtual int Read(net::IOBuffer* buf, int buf_len, | 587 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 588 net::OldCompletionCallback* callback) = 0; | 588 net::OldCompletionCallback* callback) = 0; |
| 589 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 590 const net::CompletionCallback& callback) = 0; |
| 589 virtual int Write(net::IOBuffer* buf, int buf_len, | 591 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 590 net::OldCompletionCallback* callback) = 0; | 592 net::OldCompletionCallback* callback) = 0; |
| 591 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; | 593 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; |
| 592 virtual bool SetSendBufferSize(int32 size) OVERRIDE; | 594 virtual bool SetSendBufferSize(int32 size) OVERRIDE; |
| 593 | 595 |
| 594 // StreamSocket implementation. | 596 // StreamSocket implementation. |
| 595 virtual int Connect(net::OldCompletionCallback* callback) = 0; | 597 virtual int Connect(net::OldCompletionCallback* callback) = 0; |
| 596 virtual int Connect(const net::CompletionCallback& callback) = 0; | 598 virtual int Connect(const net::CompletionCallback& callback) = 0; |
| 597 virtual void Disconnect() OVERRIDE; | 599 virtual void Disconnect() OVERRIDE; |
| 598 virtual bool IsConnected() const OVERRIDE; | 600 virtual bool IsConnected() const OVERRIDE; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket { | 633 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket { |
| 632 public: | 634 public: |
| 633 MockTCPClientSocket(const net::AddressList& addresses, net::NetLog* net_log, | 635 MockTCPClientSocket(const net::AddressList& addresses, net::NetLog* net_log, |
| 634 net::SocketDataProvider* socket); | 636 net::SocketDataProvider* socket); |
| 635 | 637 |
| 636 net::AddressList addresses() const { return addresses_; } | 638 net::AddressList addresses() const { return addresses_; } |
| 637 | 639 |
| 638 // Socket implementation. | 640 // Socket implementation. |
| 639 virtual int Read(net::IOBuffer* buf, int buf_len, | 641 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 640 net::OldCompletionCallback* callback) OVERRIDE; | 642 net::OldCompletionCallback* callback) OVERRIDE; |
| 643 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 644 const net::CompletionCallback& callback) OVERRIDE; |
| 641 virtual int Write(net::IOBuffer* buf, int buf_len, | 645 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 642 net::OldCompletionCallback* callback) OVERRIDE; | 646 net::OldCompletionCallback* callback) OVERRIDE; |
| 643 | 647 |
| 644 // StreamSocket implementation. | 648 // StreamSocket implementation. |
| 645 virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE; | 649 virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE; |
| 646 virtual int Connect(const net::CompletionCallback& callback) OVERRIDE; | 650 virtual int Connect(const net::CompletionCallback& callback) OVERRIDE; |
| 647 virtual void Disconnect() OVERRIDE; | 651 virtual void Disconnect() OVERRIDE; |
| 648 virtual bool IsConnected() const OVERRIDE; | 652 virtual bool IsConnected() const OVERRIDE; |
| 649 virtual bool IsConnectedAndIdle() const OVERRIDE; | 653 virtual bool IsConnectedAndIdle() const OVERRIDE; |
| 650 virtual int GetPeerAddress(AddressList* address) const OVERRIDE; | 654 virtual int GetPeerAddress(AddressList* address) const OVERRIDE; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 668 bool need_read_data_; | 672 bool need_read_data_; |
| 669 | 673 |
| 670 // True if the peer has closed the connection. This allows us to simulate | 674 // True if the peer has closed the connection. This allows us to simulate |
| 671 // the recv(..., MSG_PEEK) call in the IsConnectedAndIdle method of the real | 675 // the recv(..., MSG_PEEK) call in the IsConnectedAndIdle method of the real |
| 672 // TCPClientSocket. | 676 // TCPClientSocket. |
| 673 bool peer_closed_connection_; | 677 bool peer_closed_connection_; |
| 674 | 678 |
| 675 // While an asynchronous IO is pending, we save our user-buffer state. | 679 // While an asynchronous IO is pending, we save our user-buffer state. |
| 676 net::IOBuffer* pending_buf_; | 680 net::IOBuffer* pending_buf_; |
| 677 int pending_buf_len_; | 681 int pending_buf_len_; |
| 678 net::OldCompletionCallback* pending_callback_; | 682 net::OldCompletionCallback* old_pending_callback_; |
| 683 net::CompletionCallback pending_callback_; |
| 679 bool was_used_to_convey_data_; | 684 bool was_used_to_convey_data_; |
| 680 }; | 685 }; |
| 681 | 686 |
| 682 class DeterministicMockTCPClientSocket : public MockClientSocket, | 687 class DeterministicMockTCPClientSocket : public MockClientSocket, |
| 683 public AsyncSocket, | 688 public AsyncSocket, |
| 684 public base::SupportsWeakPtr<DeterministicMockTCPClientSocket> { | 689 public base::SupportsWeakPtr<DeterministicMockTCPClientSocket> { |
| 685 public: | 690 public: |
| 686 DeterministicMockTCPClientSocket(net::NetLog* net_log, | 691 DeterministicMockTCPClientSocket(net::NetLog* net_log, |
| 687 net::DeterministicSocketData* data); | 692 net::DeterministicSocketData* data); |
| 688 virtual ~DeterministicMockTCPClientSocket(); | 693 virtual ~DeterministicMockTCPClientSocket(); |
| 689 | 694 |
| 690 bool write_pending() const { return write_pending_; } | 695 bool write_pending() const { return write_pending_; } |
| 691 bool read_pending() const { return read_pending_; } | 696 bool read_pending() const { return read_pending_; } |
| 692 | 697 |
| 693 void CompleteWrite(); | 698 void CompleteWrite(); |
| 694 int CompleteRead(); | 699 int CompleteRead(); |
| 695 | 700 |
| 696 // Socket: | 701 // Socket implementation. |
| 697 virtual int Write(net::IOBuffer* buf, int buf_len, | 702 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 698 net::OldCompletionCallback* callback) OVERRIDE; | 703 net::OldCompletionCallback* callback) OVERRIDE; |
| 699 virtual int Read(net::IOBuffer* buf, int buf_len, | 704 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 700 net::OldCompletionCallback* callback) OVERRIDE; | 705 net::OldCompletionCallback* callback) OVERRIDE; |
| 706 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 707 const net::CompletionCallback& callback) OVERRIDE; |
| 701 | 708 |
| 702 // StreamSocket implementation. | 709 // StreamSocket implementation. |
| 703 virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE; | 710 virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE; |
| 704 virtual int Connect(const net::CompletionCallback& callback) OVERRIDE; | 711 virtual int Connect(const net::CompletionCallback& callback) OVERRIDE; |
| 705 virtual void Disconnect() OVERRIDE; | 712 virtual void Disconnect() OVERRIDE; |
| 706 virtual bool IsConnected() const OVERRIDE; | 713 virtual bool IsConnected() const OVERRIDE; |
| 707 virtual bool IsConnectedAndIdle() const OVERRIDE; | 714 virtual bool IsConnectedAndIdle() const OVERRIDE; |
| 708 virtual bool WasEverUsed() const OVERRIDE; | 715 virtual bool WasEverUsed() const OVERRIDE; |
| 709 virtual bool UsingTCPFastOpen() const OVERRIDE; | 716 virtual bool UsingTCPFastOpen() const OVERRIDE; |
| 710 virtual int64 NumBytesRead() const OVERRIDE; | 717 virtual int64 NumBytesRead() const OVERRIDE; |
| 711 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; | 718 virtual base::TimeDelta GetConnectTimeMicros() const OVERRIDE; |
| 712 | 719 |
| 713 // AsyncSocket: | 720 // AsyncSocket: |
| 714 virtual void OnReadComplete(const MockRead& data) OVERRIDE; | 721 virtual void OnReadComplete(const MockRead& data) OVERRIDE; |
| 715 | 722 |
| 716 private: | 723 private: |
| 717 bool write_pending_; | 724 bool write_pending_; |
| 718 net::OldCompletionCallback* write_callback_; | 725 net::OldCompletionCallback* write_callback_; |
| 719 int write_result_; | 726 int write_result_; |
| 720 | 727 |
| 721 net::MockRead read_data_; | 728 net::MockRead read_data_; |
| 722 | 729 |
| 723 net::IOBuffer* read_buf_; | 730 net::IOBuffer* read_buf_; |
| 724 int read_buf_len_; | 731 int read_buf_len_; |
| 725 bool read_pending_; | 732 bool read_pending_; |
| 726 net::OldCompletionCallback* read_callback_; | 733 net::OldCompletionCallback* old_read_callback_; |
| 734 net::CompletionCallback read_callback_; |
| 727 net::DeterministicSocketData* data_; | 735 net::DeterministicSocketData* data_; |
| 728 bool was_used_to_convey_data_; | 736 bool was_used_to_convey_data_; |
| 729 }; | 737 }; |
| 730 | 738 |
| 731 class MockSSLClientSocket : public MockClientSocket, public AsyncSocket { | 739 class MockSSLClientSocket : public MockClientSocket, public AsyncSocket { |
| 732 public: | 740 public: |
| 733 MockSSLClientSocket( | 741 MockSSLClientSocket( |
| 734 net::ClientSocketHandle* transport_socket, | 742 net::ClientSocketHandle* transport_socket, |
| 735 const HostPortPair& host_and_port, | 743 const HostPortPair& host_and_port, |
| 736 const net::SSLConfig& ssl_config, | 744 const net::SSLConfig& ssl_config, |
| 737 SSLHostInfo* ssl_host_info, | 745 SSLHostInfo* ssl_host_info, |
| 738 net::SSLSocketDataProvider* socket); | 746 net::SSLSocketDataProvider* socket); |
| 739 virtual ~MockSSLClientSocket(); | 747 virtual ~MockSSLClientSocket(); |
| 740 | 748 |
| 741 // Socket implementation. | 749 // Socket implementation. |
| 742 virtual int Read(net::IOBuffer* buf, int buf_len, | 750 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 743 net::OldCompletionCallback* callback) OVERRIDE; | 751 net::OldCompletionCallback* callback) OVERRIDE; |
| 752 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 753 const net::CompletionCallback& callback) OVERRIDE; |
| 744 virtual int Write(net::IOBuffer* buf, int buf_len, | 754 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 745 net::OldCompletionCallback* callback) OVERRIDE; | 755 net::OldCompletionCallback* callback) OVERRIDE; |
| 746 | 756 |
| 747 // StreamSocket implementation. | 757 // StreamSocket implementation. |
| 748 virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE; | 758 virtual int Connect(net::OldCompletionCallback* callback) OVERRIDE; |
| 749 virtual int Connect(const net::CompletionCallback& callback) OVERRIDE; | 759 virtual int Connect(const net::CompletionCallback& callback) OVERRIDE; |
| 750 virtual void Disconnect() OVERRIDE; | 760 virtual void Disconnect() OVERRIDE; |
| 751 virtual bool IsConnected() const OVERRIDE; | 761 virtual bool IsConnected() const OVERRIDE; |
| 752 virtual bool WasEverUsed() const OVERRIDE; | 762 virtual bool WasEverUsed() const OVERRIDE; |
| 753 virtual bool UsingTCPFastOpen() const OVERRIDE; | 763 virtual bool UsingTCPFastOpen() const OVERRIDE; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 775 bool new_npn_value_; | 785 bool new_npn_value_; |
| 776 bool was_used_to_convey_data_; | 786 bool was_used_to_convey_data_; |
| 777 }; | 787 }; |
| 778 | 788 |
| 779 class MockUDPClientSocket : public DatagramClientSocket, | 789 class MockUDPClientSocket : public DatagramClientSocket, |
| 780 public AsyncSocket { | 790 public AsyncSocket { |
| 781 public: | 791 public: |
| 782 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); | 792 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); |
| 783 virtual ~MockUDPClientSocket(); | 793 virtual ~MockUDPClientSocket(); |
| 784 | 794 |
| 785 // Socket interface | 795 // Socket implementation. |
| 786 virtual int Read(net::IOBuffer* buf, int buf_len, | 796 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 787 net::OldCompletionCallback* callback) OVERRIDE; | 797 net::OldCompletionCallback* callback) OVERRIDE; |
| 798 virtual int Read(net::IOBuffer* buf, int buf_len, |
| 799 const net::CompletionCallback& callback) OVERRIDE; |
| 788 virtual int Write(net::IOBuffer* buf, int buf_len, | 800 virtual int Write(net::IOBuffer* buf, int buf_len, |
| 789 net::OldCompletionCallback* callback) OVERRIDE; | 801 net::OldCompletionCallback* callback) OVERRIDE; |
| 790 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; | 802 virtual bool SetReceiveBufferSize(int32 size) OVERRIDE; |
| 791 virtual bool SetSendBufferSize(int32 size) OVERRIDE; | 803 virtual bool SetSendBufferSize(int32 size) OVERRIDE; |
| 792 | 804 |
| 793 // DatagramSocket interface | 805 // DatagramSocket implementation. |
| 794 virtual void Close() OVERRIDE; | 806 virtual void Close() OVERRIDE; |
| 795 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; | 807 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; |
| 796 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; | 808 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; |
| 797 virtual const BoundNetLog& NetLog() const OVERRIDE; | 809 virtual const BoundNetLog& NetLog() const OVERRIDE; |
| 798 | 810 |
| 799 // DatagramClientSocket interface | 811 // DatagramClientSocket implementation. |
| 800 virtual int Connect(const IPEndPoint& address) OVERRIDE; | 812 virtual int Connect(const IPEndPoint& address) OVERRIDE; |
| 801 | 813 |
| 802 // AsyncSocket interface | 814 // AsyncSocket implementation. |
| 803 virtual void OnReadComplete(const MockRead& data) OVERRIDE; | 815 virtual void OnReadComplete(const MockRead& data) OVERRIDE; |
| 804 | 816 |
| 805 private: | 817 private: |
| 806 int CompleteRead(); | 818 int CompleteRead(); |
| 807 | 819 |
| 808 void RunCallbackAsync(net::OldCompletionCallback* callback, int result); | 820 void RunCallbackAsync(net::OldCompletionCallback* callback, int result); |
| 809 void RunCallback(net::OldCompletionCallback* callback, int result); | 821 void RunCallbackAsync(const net::CompletionCallback& callback, int result); |
| 822 void RunOldCallback(net::OldCompletionCallback* callback, int result); |
| 823 void RunCallback(const net::CompletionCallback& callback, int result); |
| 810 | 824 |
| 811 bool connected_; | 825 bool connected_; |
| 812 SocketDataProvider* data_; | 826 SocketDataProvider* data_; |
| 813 int read_offset_; | 827 int read_offset_; |
| 814 net::MockRead read_data_; | 828 net::MockRead read_data_; |
| 815 bool need_read_data_; | 829 bool need_read_data_; |
| 816 | 830 |
| 817 // While an asynchronous IO is pending, we save our user-buffer state. | 831 // While an asynchronous IO is pending, we save our user-buffer state. |
| 818 net::IOBuffer* pending_buf_; | 832 net::IOBuffer* pending_buf_; |
| 819 int pending_buf_len_; | 833 int pending_buf_len_; |
| 820 net::OldCompletionCallback* pending_callback_; | 834 net::OldCompletionCallback* old_pending_callback_; |
| 835 net::CompletionCallback pending_callback_; |
| 821 | 836 |
| 822 BoundNetLog net_log_; | 837 BoundNetLog net_log_; |
| 823 | 838 |
| 824 base::WeakPtrFactory<MockUDPClientSocket> weak_factory_; | 839 base::WeakPtrFactory<MockUDPClientSocket> weak_factory_; |
| 825 | 840 |
| 826 DISALLOW_COPY_AND_ASSIGN(MockUDPClientSocket); | 841 DISALLOW_COPY_AND_ASSIGN(MockUDPClientSocket); |
| 827 }; | 842 }; |
| 828 | 843 |
| 829 class TestSocketRequest : public CallbackRunner< Tuple1<int> > { | 844 class TestSocketRequest : public CallbackRunner< Tuple1<int> > { |
| 830 public: | 845 public: |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1041 | 1056 |
| 1042 extern const char kSOCKS5OkRequest[]; | 1057 extern const char kSOCKS5OkRequest[]; |
| 1043 extern const int kSOCKS5OkRequestLength; | 1058 extern const int kSOCKS5OkRequestLength; |
| 1044 | 1059 |
| 1045 extern const char kSOCKS5OkResponse[]; | 1060 extern const char kSOCKS5OkResponse[]; |
| 1046 extern const int kSOCKS5OkResponseLength; | 1061 extern const int kSOCKS5OkResponseLength; |
| 1047 | 1062 |
| 1048 } // namespace net | 1063 } // namespace net |
| 1049 | 1064 |
| 1050 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 1065 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
| OLD | NEW |