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