Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1179)

Side by Side Diff: net/socket/socket_test_util.h

Issue 2351513002: net: rename BoundNetLog to NetLogWithSource (Closed)
Patch Set: one more fix, content bound_net_log_ Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 13 matching lines...) Expand all
592 ~MockClientSocket() override; 593 ~MockClientSocket() override;
593 void RunCallbackAsync(const CompletionCallback& callback, int result); 594 void RunCallbackAsync(const CompletionCallback& callback, int result);
594 void RunCallback(const CompletionCallback& callback, int result); 595 void RunCallback(const CompletionCallback& callback, int result);
595 596
596 // True if Connect completed successfully and Disconnect hasn't been called. 597 // True if Connect completed successfully and Disconnect hasn't been called.
597 bool connected_; 598 bool connected_;
598 599
599 // Address of the "remote" peer we're connected to. 600 // Address of the "remote" peer we're connected to.
600 IPEndPoint peer_addr_; 601 IPEndPoint peer_addr_;
601 602
602 BoundNetLog net_log_; 603 NetLogWithSource net_log_;
603 604
604 private: 605 private:
605 base::WeakPtrFactory<MockClientSocket> weak_factory_; 606 base::WeakPtrFactory<MockClientSocket> weak_factory_;
606 607
607 DISALLOW_COPY_AND_ASSIGN(MockClientSocket); 608 DISALLOW_COPY_AND_ASSIGN(MockClientSocket);
608 }; 609 };
609 610
610 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket { 611 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket {
611 public: 612 public:
612 MockTCPClientSocket(const AddressList& addresses, 613 MockTCPClientSocket(const AddressList& addresses,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 const CompletionCallback& callback) override; 740 const CompletionCallback& callback) override;
740 int SetReceiveBufferSize(int32_t size) override; 741 int SetReceiveBufferSize(int32_t size) override;
741 int SetSendBufferSize(int32_t size) override; 742 int SetSendBufferSize(int32_t size) override;
742 int SetDoNotFragment() override; 743 int SetDoNotFragment() override;
743 744
744 // DatagramSocket implementation. 745 // DatagramSocket implementation.
745 void Close() override; 746 void Close() override;
746 int GetPeerAddress(IPEndPoint* address) const override; 747 int GetPeerAddress(IPEndPoint* address) const override;
747 int GetLocalAddress(IPEndPoint* address) const override; 748 int GetLocalAddress(IPEndPoint* address) const override;
748 void UseNonBlockingIO() override; 749 void UseNonBlockingIO() override;
749 const BoundNetLog& NetLog() const override; 750 const NetLogWithSource& NetLog() const override;
750 751
751 // DatagramClientSocket implementation. 752 // DatagramClientSocket implementation.
752 int Connect(const IPEndPoint& address) override; 753 int Connect(const IPEndPoint& address) override;
753 int ConnectUsingNetwork(NetworkChangeNotifier::NetworkHandle network, 754 int ConnectUsingNetwork(NetworkChangeNotifier::NetworkHandle network,
754 const IPEndPoint& address) override; 755 const IPEndPoint& address) override;
755 int ConnectUsingDefaultNetwork(const IPEndPoint& address) override; 756 int ConnectUsingDefaultNetwork(const IPEndPoint& address) override;
756 NetworkChangeNotifier::NetworkHandle GetBoundNetwork() const override; 757 NetworkChangeNotifier::NetworkHandle GetBoundNetwork() const override;
757 758
758 // AsyncSocket implementation. 759 // AsyncSocket implementation.
759 void OnReadComplete(const MockRead& data) override; 760 void OnReadComplete(const MockRead& data) override;
(...skipping 22 matching lines...) Expand all
782 783
783 // Network that the socket is bound to. 784 // Network that the socket is bound to.
784 NetworkChangeNotifier::NetworkHandle network_; 785 NetworkChangeNotifier::NetworkHandle network_;
785 786
786 // While an asynchronous IO is pending, we save our user-buffer state. 787 // While an asynchronous IO is pending, we save our user-buffer state.
787 scoped_refptr<IOBuffer> pending_read_buf_; 788 scoped_refptr<IOBuffer> pending_read_buf_;
788 int pending_read_buf_len_; 789 int pending_read_buf_len_;
789 CompletionCallback pending_read_callback_; 790 CompletionCallback pending_read_callback_;
790 CompletionCallback pending_write_callback_; 791 CompletionCallback pending_write_callback_;
791 792
792 BoundNetLog net_log_; 793 NetLogWithSource net_log_;
793 794
794 base::WeakPtrFactory<MockUDPClientSocket> weak_factory_; 795 base::WeakPtrFactory<MockUDPClientSocket> weak_factory_;
795 796
796 DISALLOW_COPY_AND_ASSIGN(MockUDPClientSocket); 797 DISALLOW_COPY_AND_ASSIGN(MockUDPClientSocket);
797 }; 798 };
798 799
799 class TestSocketRequest : public TestCompletionCallbackBase { 800 class TestSocketRequest : public TestCompletionCallbackBase {
800 public: 801 public:
801 TestSocketRequest(std::vector<TestSocketRequest*>* request_order, 802 TestSocketRequest(std::vector<TestSocketRequest*>* request_order,
802 size_t* completion_count); 803 size_t* completion_count);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 const std::string& group_name, 839 const std::string& group_name,
839 RequestPriority priority, 840 RequestPriority priority,
840 ClientSocketPool::RespectLimits respect_limits, 841 ClientSocketPool::RespectLimits respect_limits,
841 const scoped_refptr<typename PoolType::SocketParams>& socket_params) { 842 const scoped_refptr<typename PoolType::SocketParams>& socket_params) {
842 DCHECK(socket_pool); 843 DCHECK(socket_pool);
843 TestSocketRequest* request( 844 TestSocketRequest* request(
844 new TestSocketRequest(&request_order_, &completion_count_)); 845 new TestSocketRequest(&request_order_, &completion_count_));
845 requests_.push_back(base::WrapUnique(request)); 846 requests_.push_back(base::WrapUnique(request));
846 int rv = request->handle()->Init(group_name, socket_params, priority, 847 int rv = request->handle()->Init(group_name, socket_params, priority,
847 respect_limits, request->callback(), 848 respect_limits, request->callback(),
848 socket_pool, BoundNetLog()); 849 socket_pool, NetLogWithSource());
849 if (rv != ERR_IO_PENDING) 850 if (rv != ERR_IO_PENDING)
850 request_order_.push_back(request); 851 request_order_.push_back(request);
851 return rv; 852 return rv;
852 } 853 }
853 854
854 // Provided there were n requests started, takes |index| in range 1..n 855 // Provided there were n requests started, takes |index| in range 1..n
855 // and returns order in which that request completed, in range 1..n, 856 // and returns order in which that request completed, in range 1..n,
856 // or kIndexOutOfBounds if |index| is out of bounds, or kRequestNotFound 857 // or kIndexOutOfBounds if |index| is out of bounds, or kRequestNotFound
857 // if that request did not complete (for example was canceled). 858 // if that request did not complete (for example was canceled).
858 int GetOrderOfRequest(size_t index) const; 859 int GetOrderOfRequest(size_t index) const;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 int release_count() const { return release_count_; } 928 int release_count() const { return release_count_; }
928 int cancel_count() const { return cancel_count_; } 929 int cancel_count() const { return cancel_count_; }
929 930
930 // TransportClientSocketPool implementation. 931 // TransportClientSocketPool implementation.
931 int RequestSocket(const std::string& group_name, 932 int RequestSocket(const std::string& group_name,
932 const void* socket_params, 933 const void* socket_params,
933 RequestPriority priority, 934 RequestPriority priority,
934 RespectLimits respect_limits, 935 RespectLimits respect_limits,
935 ClientSocketHandle* handle, 936 ClientSocketHandle* handle,
936 const CompletionCallback& callback, 937 const CompletionCallback& callback,
937 const BoundNetLog& net_log) override; 938 const NetLogWithSource& net_log) override;
938 939
939 void CancelRequest(const std::string& group_name, 940 void CancelRequest(const std::string& group_name,
940 ClientSocketHandle* handle) override; 941 ClientSocketHandle* handle) override;
941 void ReleaseSocket(const std::string& group_name, 942 void ReleaseSocket(const std::string& group_name,
942 std::unique_ptr<StreamSocket> socket, 943 std::unique_ptr<StreamSocket> socket,
943 int id) override; 944 int id) override;
944 945
945 private: 946 private:
946 ClientSocketFactory* client_socket_factory_; 947 ClientSocketFactory* client_socket_factory_;
947 std::vector<std::unique_ptr<MockConnectJob>> job_list_; 948 std::vector<std::unique_ptr<MockConnectJob>> job_list_;
(...skipping 12 matching lines...) Expand all
960 961
961 ~MockSOCKSClientSocketPool() override; 962 ~MockSOCKSClientSocketPool() override;
962 963
963 // SOCKSClientSocketPool implementation. 964 // SOCKSClientSocketPool implementation.
964 int RequestSocket(const std::string& group_name, 965 int RequestSocket(const std::string& group_name,
965 const void* socket_params, 966 const void* socket_params,
966 RequestPriority priority, 967 RequestPriority priority,
967 RespectLimits respect_limits, 968 RespectLimits respect_limits,
968 ClientSocketHandle* handle, 969 ClientSocketHandle* handle,
969 const CompletionCallback& callback, 970 const CompletionCallback& callback,
970 const BoundNetLog& net_log) override; 971 const NetLogWithSource& net_log) override;
971 972
972 void CancelRequest(const std::string& group_name, 973 void CancelRequest(const std::string& group_name,
973 ClientSocketHandle* handle) override; 974 ClientSocketHandle* handle) override;
974 void ReleaseSocket(const std::string& group_name, 975 void ReleaseSocket(const std::string& group_name,
975 std::unique_ptr<StreamSocket> socket, 976 std::unique_ptr<StreamSocket> socket,
976 int id) override; 977 int id) override;
977 978
978 private: 979 private:
979 TransportClientSocketPool* const transport_pool_; 980 TransportClientSocketPool* const transport_pool_;
980 981
(...skipping 27 matching lines...) Expand all
1008 1009
1009 // Helper function to get the total data size of the MockReads in |reads|. 1010 // Helper function to get the total data size of the MockReads in |reads|.
1010 int64_t CountReadBytes(const MockRead reads[], size_t reads_size); 1011 int64_t CountReadBytes(const MockRead reads[], size_t reads_size);
1011 1012
1012 // Helper function to get the total data size of the MockWrites in |writes|. 1013 // Helper function to get the total data size of the MockWrites in |writes|.
1013 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size); 1014 int64_t CountWriteBytes(const MockWrite writes[], size_t writes_size);
1014 1015
1015 } // namespace net 1016 } // namespace net
1016 1017
1017 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ 1018 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698