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