| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 private: | 537 private: |
| 538 SocketDataProviderArray<SocketDataProvider> mock_data_; | 538 SocketDataProviderArray<SocketDataProvider> mock_data_; |
| 539 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; | 539 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; |
| 540 std::vector<uint16_t> udp_client_socket_ports_; | 540 std::vector<uint16_t> udp_client_socket_ports_; |
| 541 | 541 |
| 542 DISALLOW_COPY_AND_ASSIGN(MockClientSocketFactory); | 542 DISALLOW_COPY_AND_ASSIGN(MockClientSocketFactory); |
| 543 }; | 543 }; |
| 544 | 544 |
| 545 class MockClientSocket : public SSLClientSocket { | 545 class MockClientSocket : public SSLClientSocket { |
| 546 public: | 546 public: |
| 547 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as | 547 // The NetLogWithSource is needed to test LoadTimingInfo, which uses NetLog |
| 548 // IDs as |
| 548 // unique socket IDs. | 549 // unique socket IDs. |
| 549 explicit MockClientSocket(const BoundNetLog& net_log); | 550 explicit MockClientSocket(const NetLogWithSource& net_log); |
| 550 | 551 |
| 551 // Socket implementation. | 552 // Socket implementation. |
| 552 int Read(IOBuffer* buf, | 553 int Read(IOBuffer* buf, |
| 553 int buf_len, | 554 int buf_len, |
| 554 const CompletionCallback& callback) override = 0; | 555 const CompletionCallback& callback) override = 0; |
| 555 int Write(IOBuffer* buf, | 556 int Write(IOBuffer* buf, |
| 556 int buf_len, | 557 int buf_len, |
| 557 const CompletionCallback& callback) override = 0; | 558 const CompletionCallback& callback) override = 0; |
| 558 int SetReceiveBufferSize(int32_t size) override; | 559 int SetReceiveBufferSize(int32_t size) override; |
| 559 int SetSendBufferSize(int32_t size) override; | 560 int SetSendBufferSize(int32_t size) override; |
| 560 | 561 |
| 561 // StreamSocket implementation. | 562 // StreamSocket implementation. |
| 562 int Connect(const CompletionCallback& callback) override = 0; | 563 int Connect(const CompletionCallback& callback) override = 0; |
| 563 void Disconnect() override; | 564 void Disconnect() override; |
| 564 bool IsConnected() const override; | 565 bool IsConnected() const override; |
| 565 bool IsConnectedAndIdle() const override; | 566 bool IsConnectedAndIdle() const override; |
| 566 int GetPeerAddress(IPEndPoint* address) const override; | 567 int GetPeerAddress(IPEndPoint* address) const override; |
| 567 int GetLocalAddress(IPEndPoint* address) const override; | 568 int GetLocalAddress(IPEndPoint* address) const override; |
| 568 const BoundNetLog& NetLog() const override; | 569 const NetLogWithSource& NetLog() const override; |
| 569 void SetSubresourceSpeculation() override {} | 570 void SetSubresourceSpeculation() override {} |
| 570 void SetOmniboxSpeculation() override {} | 571 void SetOmniboxSpeculation() override {} |
| 571 bool WasNpnNegotiated() const override; | 572 bool WasNpnNegotiated() const override; |
| 572 NextProto GetNegotiatedProtocol() const override; | 573 NextProto GetNegotiatedProtocol() const override; |
| 573 void GetConnectionAttempts(ConnectionAttempts* out) const override; | 574 void GetConnectionAttempts(ConnectionAttempts* out) const override; |
| 574 void ClearConnectionAttempts() override {} | 575 void ClearConnectionAttempts() override {} |
| 575 void AddConnectionAttempts(const ConnectionAttempts& attempts) override {} | 576 void AddConnectionAttempts(const ConnectionAttempts& attempts) override {} |
| 576 int64_t GetTotalReceivedBytes() const override; | 577 int64_t GetTotalReceivedBytes() const override; |
| 577 | 578 |
| 578 // SSLClientSocket implementation. | 579 // SSLClientSocket implementation. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 591 ~MockClientSocket() override; | 592 ~MockClientSocket() override; |
| 592 void RunCallbackAsync(const CompletionCallback& callback, int result); | 593 void RunCallbackAsync(const CompletionCallback& callback, int result); |
| 593 void RunCallback(const CompletionCallback& callback, int result); | 594 void RunCallback(const CompletionCallback& callback, int result); |
| 594 | 595 |
| 595 // True if Connect completed successfully and Disconnect hasn't been called. | 596 // True if Connect completed successfully and Disconnect hasn't been called. |
| 596 bool connected_; | 597 bool connected_; |
| 597 | 598 |
| 598 // Address of the "remote" peer we're connected to. | 599 // Address of the "remote" peer we're connected to. |
| 599 IPEndPoint peer_addr_; | 600 IPEndPoint peer_addr_; |
| 600 | 601 |
| 601 BoundNetLog net_log_; | 602 NetLogWithSource net_log_; |
| 602 | 603 |
| 603 private: | 604 private: |
| 604 base::WeakPtrFactory<MockClientSocket> weak_factory_; | 605 base::WeakPtrFactory<MockClientSocket> weak_factory_; |
| 605 | 606 |
| 606 DISALLOW_COPY_AND_ASSIGN(MockClientSocket); | 607 DISALLOW_COPY_AND_ASSIGN(MockClientSocket); |
| 607 }; | 608 }; |
| 608 | 609 |
| 609 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket { | 610 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket { |
| 610 public: | 611 public: |
| 611 MockTCPClientSocket(const AddressList& addresses, | 612 MockTCPClientSocket(const AddressList& addresses, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 const CompletionCallback& callback) override; | 738 const CompletionCallback& callback) override; |
| 738 int SetReceiveBufferSize(int32_t size) override; | 739 int SetReceiveBufferSize(int32_t size) override; |
| 739 int SetSendBufferSize(int32_t size) override; | 740 int SetSendBufferSize(int32_t size) override; |
| 740 int SetDoNotFragment() override; | 741 int SetDoNotFragment() override; |
| 741 | 742 |
| 742 // DatagramSocket implementation. | 743 // DatagramSocket implementation. |
| 743 void Close() override; | 744 void Close() override; |
| 744 int GetPeerAddress(IPEndPoint* address) const override; | 745 int GetPeerAddress(IPEndPoint* address) const override; |
| 745 int GetLocalAddress(IPEndPoint* address) const override; | 746 int GetLocalAddress(IPEndPoint* address) const override; |
| 746 void UseNonBlockingIO() override; | 747 void UseNonBlockingIO() override; |
| 747 const BoundNetLog& NetLog() const override; | 748 const NetLogWithSource& NetLog() const override; |
| 748 | 749 |
| 749 // DatagramClientSocket implementation. | 750 // DatagramClientSocket implementation. |
| 750 int Connect(const IPEndPoint& address) override; | 751 int Connect(const IPEndPoint& address) override; |
| 751 int ConnectUsingNetwork(NetworkChangeNotifier::NetworkHandle network, | 752 int ConnectUsingNetwork(NetworkChangeNotifier::NetworkHandle network, |
| 752 const IPEndPoint& address) override; | 753 const IPEndPoint& address) override; |
| 753 int ConnectUsingDefaultNetwork(const IPEndPoint& address) override; | 754 int ConnectUsingDefaultNetwork(const IPEndPoint& address) override; |
| 754 NetworkChangeNotifier::NetworkHandle GetBoundNetwork() const override; | 755 NetworkChangeNotifier::NetworkHandle GetBoundNetwork() const override; |
| 755 | 756 |
| 756 // AsyncSocket implementation. | 757 // AsyncSocket implementation. |
| 757 void OnReadComplete(const MockRead& data) override; | 758 void OnReadComplete(const MockRead& data) override; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 780 | 781 |
| 781 // Network that the socket is bound to. | 782 // Network that the socket is bound to. |
| 782 NetworkChangeNotifier::NetworkHandle network_; | 783 NetworkChangeNotifier::NetworkHandle network_; |
| 783 | 784 |
| 784 // While an asynchronous IO is pending, we save our user-buffer state. | 785 // While an asynchronous IO is pending, we save our user-buffer state. |
| 785 scoped_refptr<IOBuffer> pending_read_buf_; | 786 scoped_refptr<IOBuffer> pending_read_buf_; |
| 786 int pending_read_buf_len_; | 787 int pending_read_buf_len_; |
| 787 CompletionCallback pending_read_callback_; | 788 CompletionCallback pending_read_callback_; |
| 788 CompletionCallback pending_write_callback_; | 789 CompletionCallback pending_write_callback_; |
| 789 | 790 |
| 790 BoundNetLog net_log_; | 791 NetLogWithSource net_log_; |
| 791 | 792 |
| 792 base::WeakPtrFactory<MockUDPClientSocket> weak_factory_; | 793 base::WeakPtrFactory<MockUDPClientSocket> weak_factory_; |
| 793 | 794 |
| 794 DISALLOW_COPY_AND_ASSIGN(MockUDPClientSocket); | 795 DISALLOW_COPY_AND_ASSIGN(MockUDPClientSocket); |
| 795 }; | 796 }; |
| 796 | 797 |
| 797 class TestSocketRequest : public TestCompletionCallbackBase { | 798 class TestSocketRequest : public TestCompletionCallbackBase { |
| 798 public: | 799 public: |
| 799 TestSocketRequest(std::vector<TestSocketRequest*>* request_order, | 800 TestSocketRequest(std::vector<TestSocketRequest*>* request_order, |
| 800 size_t* completion_count); | 801 size_t* completion_count); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 836 const std::string& group_name, | 837 const std::string& group_name, |
| 837 RequestPriority priority, | 838 RequestPriority priority, |
| 838 ClientSocketPool::RespectLimits respect_limits, | 839 ClientSocketPool::RespectLimits respect_limits, |
| 839 const scoped_refptr<typename PoolType::SocketParams>& socket_params) { | 840 const scoped_refptr<typename PoolType::SocketParams>& socket_params) { |
| 840 DCHECK(socket_pool); | 841 DCHECK(socket_pool); |
| 841 TestSocketRequest* request( | 842 TestSocketRequest* request( |
| 842 new TestSocketRequest(&request_order_, &completion_count_)); | 843 new TestSocketRequest(&request_order_, &completion_count_)); |
| 843 requests_.push_back(base::WrapUnique(request)); | 844 requests_.push_back(base::WrapUnique(request)); |
| 844 int rv = request->handle()->Init(group_name, socket_params, priority, | 845 int rv = request->handle()->Init(group_name, socket_params, priority, |
| 845 respect_limits, request->callback(), | 846 respect_limits, request->callback(), |
| 846 socket_pool, BoundNetLog()); | 847 socket_pool, NetLogWithSource()); |
| 847 if (rv != ERR_IO_PENDING) | 848 if (rv != ERR_IO_PENDING) |
| 848 request_order_.push_back(request); | 849 request_order_.push_back(request); |
| 849 return rv; | 850 return rv; |
| 850 } | 851 } |
| 851 | 852 |
| 852 // Provided there were n requests started, takes |index| in range 1..n | 853 // Provided there were n requests started, takes |index| in range 1..n |
| 853 // and returns order in which that request completed, in range 1..n, | 854 // and returns order in which that request completed, in range 1..n, |
| 854 // or kIndexOutOfBounds if |index| is out of bounds, or kRequestNotFound | 855 // or kIndexOutOfBounds if |index| is out of bounds, or kRequestNotFound |
| 855 // if that request did not complete (for example was canceled). | 856 // if that request did not complete (for example was canceled). |
| 856 int GetOrderOfRequest(size_t index) const; | 857 int GetOrderOfRequest(size_t index) const; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 int release_count() const { return release_count_; } | 926 int release_count() const { return release_count_; } |
| 926 int cancel_count() const { return cancel_count_; } | 927 int cancel_count() const { return cancel_count_; } |
| 927 | 928 |
| 928 // TransportClientSocketPool implementation. | 929 // TransportClientSocketPool implementation. |
| 929 int RequestSocket(const std::string& group_name, | 930 int RequestSocket(const std::string& group_name, |
| 930 const void* socket_params, | 931 const void* socket_params, |
| 931 RequestPriority priority, | 932 RequestPriority priority, |
| 932 RespectLimits respect_limits, | 933 RespectLimits respect_limits, |
| 933 ClientSocketHandle* handle, | 934 ClientSocketHandle* handle, |
| 934 const CompletionCallback& callback, | 935 const CompletionCallback& callback, |
| 935 const BoundNetLog& net_log) override; | 936 const NetLogWithSource& net_log) override; |
| 936 | 937 |
| 937 void CancelRequest(const std::string& group_name, | 938 void CancelRequest(const std::string& group_name, |
| 938 ClientSocketHandle* handle) override; | 939 ClientSocketHandle* handle) override; |
| 939 void ReleaseSocket(const std::string& group_name, | 940 void ReleaseSocket(const std::string& group_name, |
| 940 std::unique_ptr<StreamSocket> socket, | 941 std::unique_ptr<StreamSocket> socket, |
| 941 int id) override; | 942 int id) override; |
| 942 | 943 |
| 943 private: | 944 private: |
| 944 ClientSocketFactory* client_socket_factory_; | 945 ClientSocketFactory* client_socket_factory_; |
| 945 std::vector<std::unique_ptr<MockConnectJob>> job_list_; | 946 std::vector<std::unique_ptr<MockConnectJob>> job_list_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 958 | 959 |
| 959 ~MockSOCKSClientSocketPool() override; | 960 ~MockSOCKSClientSocketPool() override; |
| 960 | 961 |
| 961 // SOCKSClientSocketPool implementation. | 962 // SOCKSClientSocketPool implementation. |
| 962 int RequestSocket(const std::string& group_name, | 963 int RequestSocket(const std::string& group_name, |
| 963 const void* socket_params, | 964 const void* socket_params, |
| 964 RequestPriority priority, | 965 RequestPriority priority, |
| 965 RespectLimits respect_limits, | 966 RespectLimits respect_limits, |
| 966 ClientSocketHandle* handle, | 967 ClientSocketHandle* handle, |
| 967 const CompletionCallback& callback, | 968 const CompletionCallback& callback, |
| 968 const BoundNetLog& net_log) override; | 969 const NetLogWithSource& net_log) override; |
| 969 | 970 |
| 970 void CancelRequest(const std::string& group_name, | 971 void CancelRequest(const std::string& group_name, |
| 971 ClientSocketHandle* handle) override; | 972 ClientSocketHandle* handle) override; |
| 972 void ReleaseSocket(const std::string& group_name, | 973 void ReleaseSocket(const std::string& group_name, |
| 973 std::unique_ptr<StreamSocket> socket, | 974 std::unique_ptr<StreamSocket> socket, |
| 974 int id) override; | 975 int id) override; |
| 975 | 976 |
| 976 private: | 977 private: |
| 977 TransportClientSocketPool* const transport_pool_; | 978 TransportClientSocketPool* const transport_pool_; |
| 978 | 979 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1006 | 1007 |
| 1007 // Helper function to get the total data size of the MockReads in |reads|. | 1008 // Helper function to get the total data size of the MockReads in |reads|. |
| 1008 int64_t CountReadBytes(const MockRead reads[], size_t reads_size); | 1009 int64_t CountReadBytes(const MockRead reads[], size_t reads_size); |
| 1009 | 1010 |
| 1010 // Helper function to get the total data size of the MockWrites in |writes|. | 1011 // Helper function to get the total data size of the MockWrites in |writes|. |
| 1011 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size); | 1012 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size); |
| 1012 | 1013 |
| 1013 } // namespace net | 1014 } // namespace net |
| 1014 | 1015 |
| 1015 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ | 1016 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ |
| OLD | NEW |