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

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

Issue 623213004: replace OVERRIDE and FINAL with override and final in net/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: undo unwanted change in comment Created 6 years, 2 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
« no previous file with comments | « net/socket/socket_libevent.h ('k') | net/socket/socks5_client_socket.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <cstring> 8 #include <cstring>
9 #include <deque> 9 #include <deque>
10 #include <string> 10 #include <string>
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 size_t write_index() const { return write_index_; } 255 size_t write_index() const { return write_index_; }
256 size_t read_count() const { return read_count_; } 256 size_t read_count() const { return read_count_; }
257 size_t write_count() const { return write_count_; } 257 size_t write_count() const { return write_count_; }
258 258
259 bool at_read_eof() const { return read_index_ >= read_count_; } 259 bool at_read_eof() const { return read_index_ >= read_count_; }
260 bool at_write_eof() const { return write_index_ >= write_count_; } 260 bool at_write_eof() const { return write_index_ >= write_count_; }
261 261
262 virtual void CompleteRead() {} 262 virtual void CompleteRead() {}
263 263
264 // SocketDataProvider implementation. 264 // SocketDataProvider implementation.
265 virtual MockRead GetNextRead() OVERRIDE; 265 virtual MockRead GetNextRead() override;
266 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE; 266 virtual MockWriteResult OnWrite(const std::string& data) override;
267 virtual void Reset() OVERRIDE; 267 virtual void Reset() override;
268 268
269 private: 269 private:
270 MockRead* reads_; 270 MockRead* reads_;
271 size_t read_index_; 271 size_t read_index_;
272 size_t read_count_; 272 size_t read_count_;
273 MockWrite* writes_; 273 MockWrite* writes_;
274 size_t write_index_; 274 size_t write_index_;
275 size_t write_count_; 275 size_t write_count_;
276 276
277 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataProvider); 277 DISALLOW_COPY_AND_ASSIGN(StaticSocketDataProvider);
278 }; 278 };
279 279
280 // SocketDataProvider which can make decisions about next mock reads based on 280 // SocketDataProvider which can make decisions about next mock reads based on
281 // received writes. It can also be used to enforce order of operations, for 281 // received writes. It can also be used to enforce order of operations, for
282 // example that tested code must send the "Hello!" message before receiving 282 // example that tested code must send the "Hello!" message before receiving
283 // response. This is useful for testing conversation-like protocols like FTP. 283 // response. This is useful for testing conversation-like protocols like FTP.
284 class DynamicSocketDataProvider : public SocketDataProvider { 284 class DynamicSocketDataProvider : public SocketDataProvider {
285 public: 285 public:
286 DynamicSocketDataProvider(); 286 DynamicSocketDataProvider();
287 virtual ~DynamicSocketDataProvider(); 287 virtual ~DynamicSocketDataProvider();
288 288
289 int short_read_limit() const { return short_read_limit_; } 289 int short_read_limit() const { return short_read_limit_; }
290 void set_short_read_limit(int limit) { short_read_limit_ = limit; } 290 void set_short_read_limit(int limit) { short_read_limit_ = limit; }
291 291
292 void allow_unconsumed_reads(bool allow) { allow_unconsumed_reads_ = allow; } 292 void allow_unconsumed_reads(bool allow) { allow_unconsumed_reads_ = allow; }
293 293
294 // SocketDataProvider implementation. 294 // SocketDataProvider implementation.
295 virtual MockRead GetNextRead() OVERRIDE; 295 virtual MockRead GetNextRead() override;
296 virtual MockWriteResult OnWrite(const std::string& data) = 0; 296 virtual MockWriteResult OnWrite(const std::string& data) = 0;
297 virtual void Reset() OVERRIDE; 297 virtual void Reset() override;
298 298
299 protected: 299 protected:
300 // The next time there is a read from this socket, it will return |data|. 300 // The next time there is a read from this socket, it will return |data|.
301 // Before calling SimulateRead next time, the previous data must be consumed. 301 // Before calling SimulateRead next time, the previous data must be consumed.
302 void SimulateRead(const char* data, size_t length); 302 void SimulateRead(const char* data, size_t length);
303 void SimulateRead(const char* data) { SimulateRead(data, std::strlen(data)); } 303 void SimulateRead(const char* data) { SimulateRead(data, std::strlen(data)); }
304 304
305 private: 305 private:
306 std::deque<MockRead> reads_; 306 std::deque<MockRead> reads_;
307 307
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 int write_delay, 369 int write_delay,
370 MockRead* reads, 370 MockRead* reads,
371 size_t reads_count, 371 size_t reads_count,
372 MockWrite* writes, 372 MockWrite* writes,
373 size_t writes_count); 373 size_t writes_count);
374 virtual ~DelayedSocketData(); 374 virtual ~DelayedSocketData();
375 375
376 void ForceNextRead(); 376 void ForceNextRead();
377 377
378 // StaticSocketDataProvider: 378 // StaticSocketDataProvider:
379 virtual MockRead GetNextRead() OVERRIDE; 379 virtual MockRead GetNextRead() override;
380 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE; 380 virtual MockWriteResult OnWrite(const std::string& data) override;
381 virtual void Reset() OVERRIDE; 381 virtual void Reset() override;
382 virtual void CompleteRead() OVERRIDE; 382 virtual void CompleteRead() override;
383 383
384 private: 384 private:
385 int write_delay_; 385 int write_delay_;
386 bool read_in_progress_; 386 bool read_in_progress_;
387 387
388 base::WeakPtrFactory<DelayedSocketData> weak_factory_; 388 base::WeakPtrFactory<DelayedSocketData> weak_factory_;
389 389
390 DISALLOW_COPY_AND_ASSIGN(DelayedSocketData); 390 DISALLOW_COPY_AND_ASSIGN(DelayedSocketData);
391 }; 391 };
392 392
(...skipping 30 matching lines...) Expand all
423 OrderedSocketData(const MockConnect& connect, 423 OrderedSocketData(const MockConnect& connect,
424 MockRead* reads, 424 MockRead* reads,
425 size_t reads_count, 425 size_t reads_count,
426 MockWrite* writes, 426 MockWrite* writes,
427 size_t writes_count); 427 size_t writes_count);
428 428
429 // Posts a quit message to the current message loop, if one is running. 429 // Posts a quit message to the current message loop, if one is running.
430 void EndLoop(); 430 void EndLoop();
431 431
432 // StaticSocketDataProvider: 432 // StaticSocketDataProvider:
433 virtual MockRead GetNextRead() OVERRIDE; 433 virtual MockRead GetNextRead() override;
434 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE; 434 virtual MockWriteResult OnWrite(const std::string& data) override;
435 virtual void Reset() OVERRIDE; 435 virtual void Reset() override;
436 virtual void CompleteRead() OVERRIDE; 436 virtual void CompleteRead() override;
437 437
438 private: 438 private:
439 int sequence_number_; 439 int sequence_number_;
440 int loop_stop_stage_; 440 int loop_stop_stage_;
441 bool blocked_; 441 bool blocked_;
442 442
443 base::WeakPtrFactory<OrderedSocketData> weak_factory_; 443 base::WeakPtrFactory<OrderedSocketData> weak_factory_;
444 444
445 DISALLOW_COPY_AND_ASSIGN(OrderedSocketData); 445 DISALLOW_COPY_AND_ASSIGN(OrderedSocketData);
446 }; 446 };
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 void SetStopped(bool val) { stopped_ = val; } 553 void SetStopped(bool val) { stopped_ = val; }
554 MockRead& current_read() { return current_read_; } 554 MockRead& current_read() { return current_read_; }
555 MockWrite& current_write() { return current_write_; } 555 MockWrite& current_write() { return current_write_; }
556 int sequence_number() const { return sequence_number_; } 556 int sequence_number() const { return sequence_number_; }
557 void set_delegate(base::WeakPtr<Delegate> delegate) { delegate_ = delegate; } 557 void set_delegate(base::WeakPtr<Delegate> delegate) { delegate_ = delegate; }
558 558
559 // StaticSocketDataProvider: 559 // StaticSocketDataProvider:
560 560
561 // When the socket calls Read(), that calls GetNextRead(), and expects either 561 // When the socket calls Read(), that calls GetNextRead(), and expects either
562 // ERR_IO_PENDING or data. 562 // ERR_IO_PENDING or data.
563 virtual MockRead GetNextRead() OVERRIDE; 563 virtual MockRead GetNextRead() override;
564 564
565 // When the socket calls Write(), it always completes synchronously. OnWrite() 565 // When the socket calls Write(), it always completes synchronously. OnWrite()
566 // checks to make sure the written data matches the expected data. The 566 // checks to make sure the written data matches the expected data. The
567 // callback will not be invoked until its sequence number is reached. 567 // callback will not be invoked until its sequence number is reached.
568 virtual MockWriteResult OnWrite(const std::string& data) OVERRIDE; 568 virtual MockWriteResult OnWrite(const std::string& data) override;
569 virtual void Reset() OVERRIDE; 569 virtual void Reset() override;
570 virtual void CompleteRead() OVERRIDE {} 570 virtual void CompleteRead() override {}
571 571
572 private: 572 private:
573 // Invoke the read and write callbacks, if the timing is appropriate. 573 // Invoke the read and write callbacks, if the timing is appropriate.
574 void InvokeCallbacks(); 574 void InvokeCallbacks();
575 575
576 void NextStep(); 576 void NextStep();
577 577
578 void VerifyCorrectSequenceNumbers(MockRead* reads, 578 void VerifyCorrectSequenceNumbers(MockRead* reads,
579 size_t reads_count, 579 size_t reads_count,
580 MockWrite* writes, 580 MockWrite* writes,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 // are not necessarily valid. 647 // are not necessarily valid.
648 const std::vector<MockSSLClientSocket*>& ssl_client_sockets() const { 648 const std::vector<MockSSLClientSocket*>& ssl_client_sockets() const {
649 return ssl_client_sockets_; 649 return ssl_client_sockets_;
650 } 650 }
651 651
652 // ClientSocketFactory 652 // ClientSocketFactory
653 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( 653 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket(
654 DatagramSocket::BindType bind_type, 654 DatagramSocket::BindType bind_type,
655 const RandIntCallback& rand_int_cb, 655 const RandIntCallback& rand_int_cb,
656 NetLog* net_log, 656 NetLog* net_log,
657 const NetLog::Source& source) OVERRIDE; 657 const NetLog::Source& source) override;
658 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket( 658 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket(
659 const AddressList& addresses, 659 const AddressList& addresses,
660 NetLog* net_log, 660 NetLog* net_log,
661 const NetLog::Source& source) OVERRIDE; 661 const NetLog::Source& source) override;
662 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket( 662 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket(
663 scoped_ptr<ClientSocketHandle> transport_socket, 663 scoped_ptr<ClientSocketHandle> transport_socket,
664 const HostPortPair& host_and_port, 664 const HostPortPair& host_and_port,
665 const SSLConfig& ssl_config, 665 const SSLConfig& ssl_config,
666 const SSLClientSocketContext& context) OVERRIDE; 666 const SSLClientSocketContext& context) override;
667 virtual void ClearSSLSessionCache() OVERRIDE; 667 virtual void ClearSSLSessionCache() override;
668 668
669 private: 669 private:
670 SocketDataProviderArray<SocketDataProvider> mock_data_; 670 SocketDataProviderArray<SocketDataProvider> mock_data_;
671 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; 671 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
672 std::vector<MockSSLClientSocket*> ssl_client_sockets_; 672 std::vector<MockSSLClientSocket*> ssl_client_sockets_;
673 }; 673 };
674 674
675 class MockClientSocket : public SSLClientSocket { 675 class MockClientSocket : public SSLClientSocket {
676 public: 676 public:
677 // Value returned by GetTLSUniqueChannelBinding(). 677 // Value returned by GetTLSUniqueChannelBinding().
678 static const char kTlsUnique[]; 678 static const char kTlsUnique[];
679 679
680 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as 680 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as
681 // unique socket IDs. 681 // unique socket IDs.
682 explicit MockClientSocket(const BoundNetLog& net_log); 682 explicit MockClientSocket(const BoundNetLog& net_log);
683 683
684 // Socket implementation. 684 // Socket implementation.
685 virtual int Read(IOBuffer* buf, 685 virtual int Read(IOBuffer* buf,
686 int buf_len, 686 int buf_len,
687 const CompletionCallback& callback) = 0; 687 const CompletionCallback& callback) = 0;
688 virtual int Write(IOBuffer* buf, 688 virtual int Write(IOBuffer* buf,
689 int buf_len, 689 int buf_len,
690 const CompletionCallback& callback) = 0; 690 const CompletionCallback& callback) = 0;
691 virtual int SetReceiveBufferSize(int32 size) OVERRIDE; 691 virtual int SetReceiveBufferSize(int32 size) override;
692 virtual int SetSendBufferSize(int32 size) OVERRIDE; 692 virtual int SetSendBufferSize(int32 size) override;
693 693
694 // StreamSocket implementation. 694 // StreamSocket implementation.
695 virtual int Connect(const CompletionCallback& callback) = 0; 695 virtual int Connect(const CompletionCallback& callback) = 0;
696 virtual void Disconnect() OVERRIDE; 696 virtual void Disconnect() override;
697 virtual bool IsConnected() const OVERRIDE; 697 virtual bool IsConnected() const override;
698 virtual bool IsConnectedAndIdle() const OVERRIDE; 698 virtual bool IsConnectedAndIdle() const override;
699 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; 699 virtual int GetPeerAddress(IPEndPoint* address) const override;
700 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; 700 virtual int GetLocalAddress(IPEndPoint* address) const override;
701 virtual const BoundNetLog& NetLog() const OVERRIDE; 701 virtual const BoundNetLog& NetLog() const override;
702 virtual void SetSubresourceSpeculation() OVERRIDE {} 702 virtual void SetSubresourceSpeculation() override {}
703 virtual void SetOmniboxSpeculation() OVERRIDE {} 703 virtual void SetOmniboxSpeculation() override {}
704 704
705 // SSLClientSocket implementation. 705 // SSLClientSocket implementation.
706 virtual std::string GetSessionCacheKey() const OVERRIDE; 706 virtual std::string GetSessionCacheKey() const override;
707 virtual bool InSessionCache() const OVERRIDE; 707 virtual bool InSessionCache() const override;
708 virtual void SetHandshakeCompletionCallback(const base::Closure& cb) OVERRIDE; 708 virtual void SetHandshakeCompletionCallback(const base::Closure& cb) override;
709 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) 709 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info)
710 OVERRIDE; 710 override;
711 virtual int ExportKeyingMaterial(const base::StringPiece& label, 711 virtual int ExportKeyingMaterial(const base::StringPiece& label,
712 bool has_context, 712 bool has_context,
713 const base::StringPiece& context, 713 const base::StringPiece& context,
714 unsigned char* out, 714 unsigned char* out,
715 unsigned int outlen) OVERRIDE; 715 unsigned int outlen) override;
716 virtual int GetTLSUniqueChannelBinding(std::string* out) OVERRIDE; 716 virtual int GetTLSUniqueChannelBinding(std::string* out) override;
717 virtual NextProtoStatus GetNextProto(std::string* proto) OVERRIDE; 717 virtual NextProtoStatus GetNextProto(std::string* proto) override;
718 virtual ChannelIDService* GetChannelIDService() const OVERRIDE; 718 virtual ChannelIDService* GetChannelIDService() const override;
719 719
720 protected: 720 protected:
721 virtual ~MockClientSocket(); 721 virtual ~MockClientSocket();
722 void RunCallbackAsync(const CompletionCallback& callback, int result); 722 void RunCallbackAsync(const CompletionCallback& callback, int result);
723 void RunCallback(const CompletionCallback& callback, int result); 723 void RunCallback(const CompletionCallback& callback, int result);
724 724
725 // SSLClientSocket implementation. 725 // SSLClientSocket implementation.
726 virtual scoped_refptr<X509Certificate> GetUnverifiedServerCertificateChain() 726 virtual scoped_refptr<X509Certificate> GetUnverifiedServerCertificateChain()
727 const OVERRIDE; 727 const override;
728 728
729 // True if Connect completed successfully and Disconnect hasn't been called. 729 // True if Connect completed successfully and Disconnect hasn't been called.
730 bool connected_; 730 bool connected_;
731 731
732 // Address of the "remote" peer we're connected to. 732 // Address of the "remote" peer we're connected to.
733 IPEndPoint peer_addr_; 733 IPEndPoint peer_addr_;
734 734
735 BoundNetLog net_log_; 735 BoundNetLog net_log_;
736 736
737 private: 737 private:
738 base::WeakPtrFactory<MockClientSocket> weak_factory_; 738 base::WeakPtrFactory<MockClientSocket> weak_factory_;
739 739
740 DISALLOW_COPY_AND_ASSIGN(MockClientSocket); 740 DISALLOW_COPY_AND_ASSIGN(MockClientSocket);
741 }; 741 };
742 742
743 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket { 743 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket {
744 public: 744 public:
745 MockTCPClientSocket(const AddressList& addresses, 745 MockTCPClientSocket(const AddressList& addresses,
746 net::NetLog* net_log, 746 net::NetLog* net_log,
747 SocketDataProvider* socket); 747 SocketDataProvider* socket);
748 virtual ~MockTCPClientSocket(); 748 virtual ~MockTCPClientSocket();
749 749
750 const AddressList& addresses() const { return addresses_; } 750 const AddressList& addresses() const { return addresses_; }
751 751
752 // Socket implementation. 752 // Socket implementation.
753 virtual int Read(IOBuffer* buf, 753 virtual int Read(IOBuffer* buf,
754 int buf_len, 754 int buf_len,
755 const CompletionCallback& callback) OVERRIDE; 755 const CompletionCallback& callback) override;
756 virtual int Write(IOBuffer* buf, 756 virtual int Write(IOBuffer* buf,
757 int buf_len, 757 int buf_len,
758 const CompletionCallback& callback) OVERRIDE; 758 const CompletionCallback& callback) override;
759 759
760 // StreamSocket implementation. 760 // StreamSocket implementation.
761 virtual int Connect(const CompletionCallback& callback) OVERRIDE; 761 virtual int Connect(const CompletionCallback& callback) override;
762 virtual void Disconnect() OVERRIDE; 762 virtual void Disconnect() override;
763 virtual bool IsConnected() const OVERRIDE; 763 virtual bool IsConnected() const override;
764 virtual bool IsConnectedAndIdle() const OVERRIDE; 764 virtual bool IsConnectedAndIdle() const override;
765 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; 765 virtual int GetPeerAddress(IPEndPoint* address) const override;
766 virtual bool WasEverUsed() const OVERRIDE; 766 virtual bool WasEverUsed() const override;
767 virtual bool UsingTCPFastOpen() const OVERRIDE; 767 virtual bool UsingTCPFastOpen() const override;
768 virtual bool WasNpnNegotiated() const OVERRIDE; 768 virtual bool WasNpnNegotiated() const override;
769 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; 769 virtual bool GetSSLInfo(SSLInfo* ssl_info) override;
770 770
771 // AsyncSocket: 771 // AsyncSocket:
772 virtual void OnReadComplete(const MockRead& data) OVERRIDE; 772 virtual void OnReadComplete(const MockRead& data) override;
773 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; 773 virtual void OnConnectComplete(const MockConnect& data) override;
774 774
775 private: 775 private:
776 int CompleteRead(); 776 int CompleteRead();
777 777
778 AddressList addresses_; 778 AddressList addresses_;
779 779
780 SocketDataProvider* data_; 780 SocketDataProvider* data_;
781 int read_offset_; 781 int read_offset_;
782 MockRead read_data_; 782 MockRead read_data_;
783 bool need_read_data_; 783 bool need_read_data_;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 : public DatagramClientSocket, 847 : public DatagramClientSocket,
848 public AsyncSocket, 848 public AsyncSocket,
849 public DeterministicSocketData::Delegate, 849 public DeterministicSocketData::Delegate,
850 public base::SupportsWeakPtr<DeterministicMockUDPClientSocket> { 850 public base::SupportsWeakPtr<DeterministicMockUDPClientSocket> {
851 public: 851 public:
852 DeterministicMockUDPClientSocket(net::NetLog* net_log, 852 DeterministicMockUDPClientSocket(net::NetLog* net_log,
853 DeterministicSocketData* data); 853 DeterministicSocketData* data);
854 virtual ~DeterministicMockUDPClientSocket(); 854 virtual ~DeterministicMockUDPClientSocket();
855 855
856 // DeterministicSocketData::Delegate: 856 // DeterministicSocketData::Delegate:
857 virtual bool WritePending() const OVERRIDE; 857 virtual bool WritePending() const override;
858 virtual bool ReadPending() const OVERRIDE; 858 virtual bool ReadPending() const override;
859 virtual void CompleteWrite() OVERRIDE; 859 virtual void CompleteWrite() override;
860 virtual int CompleteRead() OVERRIDE; 860 virtual int CompleteRead() override;
861 861
862 // Socket implementation. 862 // Socket implementation.
863 virtual int Read(IOBuffer* buf, 863 virtual int Read(IOBuffer* buf,
864 int buf_len, 864 int buf_len,
865 const CompletionCallback& callback) OVERRIDE; 865 const CompletionCallback& callback) override;
866 virtual int Write(IOBuffer* buf, 866 virtual int Write(IOBuffer* buf,
867 int buf_len, 867 int buf_len,
868 const CompletionCallback& callback) OVERRIDE; 868 const CompletionCallback& callback) override;
869 virtual int SetReceiveBufferSize(int32 size) OVERRIDE; 869 virtual int SetReceiveBufferSize(int32 size) override;
870 virtual int SetSendBufferSize(int32 size) OVERRIDE; 870 virtual int SetSendBufferSize(int32 size) override;
871 871
872 // DatagramSocket implementation. 872 // DatagramSocket implementation.
873 virtual void Close() OVERRIDE; 873 virtual void Close() override;
874 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; 874 virtual int GetPeerAddress(IPEndPoint* address) const override;
875 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; 875 virtual int GetLocalAddress(IPEndPoint* address) const override;
876 virtual const BoundNetLog& NetLog() const OVERRIDE; 876 virtual const BoundNetLog& NetLog() const override;
877 877
878 // DatagramClientSocket implementation. 878 // DatagramClientSocket implementation.
879 virtual int Connect(const IPEndPoint& address) OVERRIDE; 879 virtual int Connect(const IPEndPoint& address) override;
880 880
881 // AsyncSocket implementation. 881 // AsyncSocket implementation.
882 virtual void OnReadComplete(const MockRead& data) OVERRIDE; 882 virtual void OnReadComplete(const MockRead& data) override;
883 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; 883 virtual void OnConnectComplete(const MockConnect& data) override;
884 884
885 void set_source_port(int port) { source_port_ = port; } 885 void set_source_port(int port) { source_port_ = port; }
886 886
887 private: 887 private:
888 bool connected_; 888 bool connected_;
889 IPEndPoint peer_address_; 889 IPEndPoint peer_address_;
890 DeterministicSocketHelper helper_; 890 DeterministicSocketHelper helper_;
891 int source_port_; // Ephemeral source port. 891 int source_port_; // Ephemeral source port.
892 892
893 DISALLOW_COPY_AND_ASSIGN(DeterministicMockUDPClientSocket); 893 DISALLOW_COPY_AND_ASSIGN(DeterministicMockUDPClientSocket);
894 }; 894 };
895 895
896 // Mock TCP socket to be used in conjunction with DeterministicSocketData. 896 // Mock TCP socket to be used in conjunction with DeterministicSocketData.
897 class DeterministicMockTCPClientSocket 897 class DeterministicMockTCPClientSocket
898 : public MockClientSocket, 898 : public MockClientSocket,
899 public AsyncSocket, 899 public AsyncSocket,
900 public DeterministicSocketData::Delegate, 900 public DeterministicSocketData::Delegate,
901 public base::SupportsWeakPtr<DeterministicMockTCPClientSocket> { 901 public base::SupportsWeakPtr<DeterministicMockTCPClientSocket> {
902 public: 902 public:
903 DeterministicMockTCPClientSocket(net::NetLog* net_log, 903 DeterministicMockTCPClientSocket(net::NetLog* net_log,
904 DeterministicSocketData* data); 904 DeterministicSocketData* data);
905 virtual ~DeterministicMockTCPClientSocket(); 905 virtual ~DeterministicMockTCPClientSocket();
906 906
907 // DeterministicSocketData::Delegate: 907 // DeterministicSocketData::Delegate:
908 virtual bool WritePending() const OVERRIDE; 908 virtual bool WritePending() const override;
909 virtual bool ReadPending() const OVERRIDE; 909 virtual bool ReadPending() const override;
910 virtual void CompleteWrite() OVERRIDE; 910 virtual void CompleteWrite() override;
911 virtual int CompleteRead() OVERRIDE; 911 virtual int CompleteRead() override;
912 912
913 // Socket: 913 // Socket:
914 virtual int Write(IOBuffer* buf, 914 virtual int Write(IOBuffer* buf,
915 int buf_len, 915 int buf_len,
916 const CompletionCallback& callback) OVERRIDE; 916 const CompletionCallback& callback) override;
917 virtual int Read(IOBuffer* buf, 917 virtual int Read(IOBuffer* buf,
918 int buf_len, 918 int buf_len,
919 const CompletionCallback& callback) OVERRIDE; 919 const CompletionCallback& callback) override;
920 920
921 // StreamSocket: 921 // StreamSocket:
922 virtual int Connect(const CompletionCallback& callback) OVERRIDE; 922 virtual int Connect(const CompletionCallback& callback) override;
923 virtual void Disconnect() OVERRIDE; 923 virtual void Disconnect() override;
924 virtual bool IsConnected() const OVERRIDE; 924 virtual bool IsConnected() const override;
925 virtual bool IsConnectedAndIdle() const OVERRIDE; 925 virtual bool IsConnectedAndIdle() const override;
926 virtual bool WasEverUsed() const OVERRIDE; 926 virtual bool WasEverUsed() const override;
927 virtual bool UsingTCPFastOpen() const OVERRIDE; 927 virtual bool UsingTCPFastOpen() const override;
928 virtual bool WasNpnNegotiated() const OVERRIDE; 928 virtual bool WasNpnNegotiated() const override;
929 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; 929 virtual bool GetSSLInfo(SSLInfo* ssl_info) override;
930 930
931 // AsyncSocket: 931 // AsyncSocket:
932 virtual void OnReadComplete(const MockRead& data) OVERRIDE; 932 virtual void OnReadComplete(const MockRead& data) override;
933 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; 933 virtual void OnConnectComplete(const MockConnect& data) override;
934 934
935 private: 935 private:
936 DeterministicSocketHelper helper_; 936 DeterministicSocketHelper helper_;
937 937
938 DISALLOW_COPY_AND_ASSIGN(DeterministicMockTCPClientSocket); 938 DISALLOW_COPY_AND_ASSIGN(DeterministicMockTCPClientSocket);
939 }; 939 };
940 940
941 class MockSSLClientSocket : public MockClientSocket, public AsyncSocket { 941 class MockSSLClientSocket : public MockClientSocket, public AsyncSocket {
942 public: 942 public:
943 MockSSLClientSocket(scoped_ptr<ClientSocketHandle> transport_socket, 943 MockSSLClientSocket(scoped_ptr<ClientSocketHandle> transport_socket,
944 const HostPortPair& host_and_port, 944 const HostPortPair& host_and_port,
945 const SSLConfig& ssl_config, 945 const SSLConfig& ssl_config,
946 SSLSocketDataProvider* socket); 946 SSLSocketDataProvider* socket);
947 virtual ~MockSSLClientSocket(); 947 virtual ~MockSSLClientSocket();
948 948
949 // Socket implementation. 949 // Socket implementation.
950 virtual int Read(IOBuffer* buf, 950 virtual int Read(IOBuffer* buf,
951 int buf_len, 951 int buf_len,
952 const CompletionCallback& callback) OVERRIDE; 952 const CompletionCallback& callback) override;
953 virtual int Write(IOBuffer* buf, 953 virtual int Write(IOBuffer* buf,
954 int buf_len, 954 int buf_len,
955 const CompletionCallback& callback) OVERRIDE; 955 const CompletionCallback& callback) override;
956 956
957 // StreamSocket implementation. 957 // StreamSocket implementation.
958 virtual int Connect(const CompletionCallback& callback) OVERRIDE; 958 virtual int Connect(const CompletionCallback& callback) override;
959 virtual void Disconnect() OVERRIDE; 959 virtual void Disconnect() override;
960 virtual bool IsConnected() const OVERRIDE; 960 virtual bool IsConnected() const override;
961 virtual bool WasEverUsed() const OVERRIDE; 961 virtual bool WasEverUsed() const override;
962 virtual bool UsingTCPFastOpen() const OVERRIDE; 962 virtual bool UsingTCPFastOpen() const override;
963 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; 963 virtual int GetPeerAddress(IPEndPoint* address) const override;
964 virtual bool WasNpnNegotiated() const OVERRIDE; 964 virtual bool WasNpnNegotiated() const override;
965 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; 965 virtual bool GetSSLInfo(SSLInfo* ssl_info) override;
966 966
967 // SSLClientSocket implementation. 967 // SSLClientSocket implementation.
968 virtual std::string GetSessionCacheKey() const OVERRIDE; 968 virtual std::string GetSessionCacheKey() const override;
969 virtual bool InSessionCache() const OVERRIDE; 969 virtual bool InSessionCache() const override;
970 virtual void SetHandshakeCompletionCallback(const base::Closure& cb) OVERRIDE; 970 virtual void SetHandshakeCompletionCallback(const base::Closure& cb) override;
971 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) 971 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info)
972 OVERRIDE; 972 override;
973 virtual NextProtoStatus GetNextProto(std::string* proto) OVERRIDE; 973 virtual NextProtoStatus GetNextProto(std::string* proto) override;
974 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE; 974 virtual bool set_was_npn_negotiated(bool negotiated) override;
975 virtual void set_protocol_negotiated(NextProto protocol_negotiated) OVERRIDE; 975 virtual void set_protocol_negotiated(NextProto protocol_negotiated) override;
976 virtual NextProto GetNegotiatedProtocol() const OVERRIDE; 976 virtual NextProto GetNegotiatedProtocol() const override;
977 977
978 // This MockSocket does not implement the manual async IO feature. 978 // This MockSocket does not implement the manual async IO feature.
979 virtual void OnReadComplete(const MockRead& data) OVERRIDE; 979 virtual void OnReadComplete(const MockRead& data) override;
980 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; 980 virtual void OnConnectComplete(const MockConnect& data) override;
981 981
982 virtual bool WasChannelIDSent() const OVERRIDE; 982 virtual bool WasChannelIDSent() const override;
983 virtual void set_channel_id_sent(bool channel_id_sent) OVERRIDE; 983 virtual void set_channel_id_sent(bool channel_id_sent) override;
984 virtual ChannelIDService* GetChannelIDService() const OVERRIDE; 984 virtual ChannelIDService* GetChannelIDService() const override;
985 985
986 bool reached_connect() const { return reached_connect_; } 986 bool reached_connect() const { return reached_connect_; }
987 987
988 // Resumes the connection of a socket that was paused for testing. 988 // Resumes the connection of a socket that was paused for testing.
989 // |connect_callback_| should be set before invoking this method. 989 // |connect_callback_| should be set before invoking this method.
990 void RestartPausedConnect(); 990 void RestartPausedConnect();
991 991
992 private: 992 private:
993 enum ConnectState { 993 enum ConnectState {
994 STATE_NONE, 994 STATE_NONE,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 }; 1026 };
1027 1027
1028 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket { 1028 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket {
1029 public: 1029 public:
1030 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); 1030 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log);
1031 virtual ~MockUDPClientSocket(); 1031 virtual ~MockUDPClientSocket();
1032 1032
1033 // Socket implementation. 1033 // Socket implementation.
1034 virtual int Read(IOBuffer* buf, 1034 virtual int Read(IOBuffer* buf,
1035 int buf_len, 1035 int buf_len,
1036 const CompletionCallback& callback) OVERRIDE; 1036 const CompletionCallback& callback) override;
1037 virtual int Write(IOBuffer* buf, 1037 virtual int Write(IOBuffer* buf,
1038 int buf_len, 1038 int buf_len,
1039 const CompletionCallback& callback) OVERRIDE; 1039 const CompletionCallback& callback) override;
1040 virtual int SetReceiveBufferSize(int32 size) OVERRIDE; 1040 virtual int SetReceiveBufferSize(int32 size) override;
1041 virtual int SetSendBufferSize(int32 size) OVERRIDE; 1041 virtual int SetSendBufferSize(int32 size) override;
1042 1042
1043 // DatagramSocket implementation. 1043 // DatagramSocket implementation.
1044 virtual void Close() OVERRIDE; 1044 virtual void Close() override;
1045 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; 1045 virtual int GetPeerAddress(IPEndPoint* address) const override;
1046 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; 1046 virtual int GetLocalAddress(IPEndPoint* address) const override;
1047 virtual const BoundNetLog& NetLog() const OVERRIDE; 1047 virtual const BoundNetLog& NetLog() const override;
1048 1048
1049 // DatagramClientSocket implementation. 1049 // DatagramClientSocket implementation.
1050 virtual int Connect(const IPEndPoint& address) OVERRIDE; 1050 virtual int Connect(const IPEndPoint& address) override;
1051 1051
1052 // AsyncSocket implementation. 1052 // AsyncSocket implementation.
1053 virtual void OnReadComplete(const MockRead& data) OVERRIDE; 1053 virtual void OnReadComplete(const MockRead& data) override;
1054 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; 1054 virtual void OnConnectComplete(const MockConnect& data) override;
1055 1055
1056 void set_source_port(int port) { source_port_ = port;} 1056 void set_source_port(int port) { source_port_ = port;}
1057 1057
1058 private: 1058 private:
1059 int CompleteRead(); 1059 int CompleteRead();
1060 1060
1061 void RunCallbackAsync(const CompletionCallback& callback, int result); 1061 void RunCallbackAsync(const CompletionCallback& callback, int result);
1062 void RunCallback(const CompletionCallback& callback, int result); 1062 void RunCallback(const CompletionCallback& callback, int result);
1063 1063
1064 bool connected_; 1064 bool connected_;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1214 } 1214 }
1215 int release_count() const { return release_count_; } 1215 int release_count() const { return release_count_; }
1216 int cancel_count() const { return cancel_count_; } 1216 int cancel_count() const { return cancel_count_; }
1217 1217
1218 // TransportClientSocketPool implementation. 1218 // TransportClientSocketPool implementation.
1219 virtual int RequestSocket(const std::string& group_name, 1219 virtual int RequestSocket(const std::string& group_name,
1220 const void* socket_params, 1220 const void* socket_params,
1221 RequestPriority priority, 1221 RequestPriority priority,
1222 ClientSocketHandle* handle, 1222 ClientSocketHandle* handle,
1223 const CompletionCallback& callback, 1223 const CompletionCallback& callback,
1224 const BoundNetLog& net_log) OVERRIDE; 1224 const BoundNetLog& net_log) override;
1225 1225
1226 virtual void CancelRequest(const std::string& group_name, 1226 virtual void CancelRequest(const std::string& group_name,
1227 ClientSocketHandle* handle) OVERRIDE; 1227 ClientSocketHandle* handle) override;
1228 virtual void ReleaseSocket(const std::string& group_name, 1228 virtual void ReleaseSocket(const std::string& group_name,
1229 scoped_ptr<StreamSocket> socket, 1229 scoped_ptr<StreamSocket> socket,
1230 int id) OVERRIDE; 1230 int id) override;
1231 1231
1232 private: 1232 private:
1233 ClientSocketFactory* client_socket_factory_; 1233 ClientSocketFactory* client_socket_factory_;
1234 ScopedVector<MockConnectJob> job_list_; 1234 ScopedVector<MockConnectJob> job_list_;
1235 RequestPriority last_request_priority_; 1235 RequestPriority last_request_priority_;
1236 int release_count_; 1236 int release_count_;
1237 int cancel_count_; 1237 int cancel_count_;
1238 1238
1239 DISALLOW_COPY_AND_ASSIGN(MockTransportClientSocketPool); 1239 DISALLOW_COPY_AND_ASSIGN(MockTransportClientSocketPool);
1240 }; 1240 };
(...skipping 19 matching lines...) Expand all
1260 } 1260 }
1261 std::vector<DeterministicMockUDPClientSocket*>& udp_client_sockets() { 1261 std::vector<DeterministicMockUDPClientSocket*>& udp_client_sockets() {
1262 return udp_client_sockets_; 1262 return udp_client_sockets_;
1263 } 1263 }
1264 1264
1265 // ClientSocketFactory 1265 // ClientSocketFactory
1266 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( 1266 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket(
1267 DatagramSocket::BindType bind_type, 1267 DatagramSocket::BindType bind_type,
1268 const RandIntCallback& rand_int_cb, 1268 const RandIntCallback& rand_int_cb,
1269 NetLog* net_log, 1269 NetLog* net_log,
1270 const NetLog::Source& source) OVERRIDE; 1270 const NetLog::Source& source) override;
1271 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket( 1271 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket(
1272 const AddressList& addresses, 1272 const AddressList& addresses,
1273 NetLog* net_log, 1273 NetLog* net_log,
1274 const NetLog::Source& source) OVERRIDE; 1274 const NetLog::Source& source) override;
1275 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket( 1275 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket(
1276 scoped_ptr<ClientSocketHandle> transport_socket, 1276 scoped_ptr<ClientSocketHandle> transport_socket,
1277 const HostPortPair& host_and_port, 1277 const HostPortPair& host_and_port,
1278 const SSLConfig& ssl_config, 1278 const SSLConfig& ssl_config,
1279 const SSLClientSocketContext& context) OVERRIDE; 1279 const SSLClientSocketContext& context) override;
1280 virtual void ClearSSLSessionCache() OVERRIDE; 1280 virtual void ClearSSLSessionCache() override;
1281 1281
1282 private: 1282 private:
1283 SocketDataProviderArray<DeterministicSocketData> mock_data_; 1283 SocketDataProviderArray<DeterministicSocketData> mock_data_;
1284 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; 1284 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
1285 1285
1286 // Store pointers to handed out sockets in case the test wants to get them. 1286 // Store pointers to handed out sockets in case the test wants to get them.
1287 std::vector<DeterministicMockTCPClientSocket*> tcp_client_sockets_; 1287 std::vector<DeterministicMockTCPClientSocket*> tcp_client_sockets_;
1288 std::vector<DeterministicMockUDPClientSocket*> udp_client_sockets_; 1288 std::vector<DeterministicMockUDPClientSocket*> udp_client_sockets_;
1289 std::vector<MockSSLClientSocket*> ssl_client_sockets_; 1289 std::vector<MockSSLClientSocket*> ssl_client_sockets_;
1290 1290
1291 DISALLOW_COPY_AND_ASSIGN(DeterministicMockClientSocketFactory); 1291 DISALLOW_COPY_AND_ASSIGN(DeterministicMockClientSocketFactory);
1292 }; 1292 };
1293 1293
1294 class MockSOCKSClientSocketPool : public SOCKSClientSocketPool { 1294 class MockSOCKSClientSocketPool : public SOCKSClientSocketPool {
1295 public: 1295 public:
1296 MockSOCKSClientSocketPool(int max_sockets, 1296 MockSOCKSClientSocketPool(int max_sockets,
1297 int max_sockets_per_group, 1297 int max_sockets_per_group,
1298 ClientSocketPoolHistograms* histograms, 1298 ClientSocketPoolHistograms* histograms,
1299 TransportClientSocketPool* transport_pool); 1299 TransportClientSocketPool* transport_pool);
1300 1300
1301 virtual ~MockSOCKSClientSocketPool(); 1301 virtual ~MockSOCKSClientSocketPool();
1302 1302
1303 // SOCKSClientSocketPool implementation. 1303 // SOCKSClientSocketPool implementation.
1304 virtual int RequestSocket(const std::string& group_name, 1304 virtual int RequestSocket(const std::string& group_name,
1305 const void* socket_params, 1305 const void* socket_params,
1306 RequestPriority priority, 1306 RequestPriority priority,
1307 ClientSocketHandle* handle, 1307 ClientSocketHandle* handle,
1308 const CompletionCallback& callback, 1308 const CompletionCallback& callback,
1309 const BoundNetLog& net_log) OVERRIDE; 1309 const BoundNetLog& net_log) override;
1310 1310
1311 virtual void CancelRequest(const std::string& group_name, 1311 virtual void CancelRequest(const std::string& group_name,
1312 ClientSocketHandle* handle) OVERRIDE; 1312 ClientSocketHandle* handle) override;
1313 virtual void ReleaseSocket(const std::string& group_name, 1313 virtual void ReleaseSocket(const std::string& group_name,
1314 scoped_ptr<StreamSocket> socket, 1314 scoped_ptr<StreamSocket> socket,
1315 int id) OVERRIDE; 1315 int id) override;
1316 1316
1317 private: 1317 private:
1318 TransportClientSocketPool* const transport_pool_; 1318 TransportClientSocketPool* const transport_pool_;
1319 1319
1320 DISALLOW_COPY_AND_ASSIGN(MockSOCKSClientSocketPool); 1320 DISALLOW_COPY_AND_ASSIGN(MockSOCKSClientSocketPool);
1321 }; 1321 };
1322 1322
1323 // Constants for a successful SOCKS v5 handshake. 1323 // Constants for a successful SOCKS v5 handshake.
1324 extern const char kSOCKS5GreetRequest[]; 1324 extern const char kSOCKS5GreetRequest[];
1325 extern const int kSOCKS5GreetRequestLength; 1325 extern const int kSOCKS5GreetRequestLength;
1326 1326
1327 extern const char kSOCKS5GreetResponse[]; 1327 extern const char kSOCKS5GreetResponse[];
1328 extern const int kSOCKS5GreetResponseLength; 1328 extern const int kSOCKS5GreetResponseLength;
1329 1329
1330 extern const char kSOCKS5OkRequest[]; 1330 extern const char kSOCKS5OkRequest[];
1331 extern const int kSOCKS5OkRequestLength; 1331 extern const int kSOCKS5OkRequestLength;
1332 1332
1333 extern const char kSOCKS5OkResponse[]; 1333 extern const char kSOCKS5OkResponse[];
1334 extern const int kSOCKS5OkResponseLength; 1334 extern const int kSOCKS5OkResponseLength;
1335 1335
1336 } // namespace net 1336 } // namespace net
1337 1337
1338 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ 1338 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « net/socket/socket_libevent.h ('k') | net/socket/socks5_client_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698