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

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

Issue 353713005: Implements new, more robust design for communicating between SSLConnectJobs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed test from SSLClientSocketOpenSSL, removed false start test, inlined CreateAndConnectSSLClie… Created 6 years, 4 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 <cstring> 8 #include <cstring>
9 #include <deque> 9 #include <deque>
10 #include <string> 10 #include <string>
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 SSLClientSocket::NextProtoStatus next_proto_status; 327 SSLClientSocket::NextProtoStatus next_proto_status;
328 std::string next_proto; 328 std::string next_proto;
329 bool was_npn_negotiated; 329 bool was_npn_negotiated;
330 NextProto protocol_negotiated; 330 NextProto protocol_negotiated;
331 bool client_cert_sent; 331 bool client_cert_sent;
332 SSLCertRequestInfo* cert_request_info; 332 SSLCertRequestInfo* cert_request_info;
333 scoped_refptr<X509Certificate> cert; 333 scoped_refptr<X509Certificate> cert;
334 bool channel_id_sent; 334 bool channel_id_sent;
335 ChannelIDService* channel_id_service; 335 ChannelIDService* channel_id_service;
336 int connection_status; 336 int connection_status;
337 // Indicates that the socket should block in the Connect method.
338 bool should_block_on_connect;
339 // Whether or not the Socket should behave like there is a pre-existing
340 // session to resume. Whether or not such a session is reported as
341 // resumed is controlled by |connection_status|.
342 bool is_in_session_cache;
337 }; 343 };
338 344
339 // A DataProvider where the client must write a request before the reads (e.g. 345 // A DataProvider where the client must write a request before the reads (e.g.
340 // the response) will complete. 346 // the response) will complete.
341 class DelayedSocketData : public StaticSocketDataProvider { 347 class DelayedSocketData : public StaticSocketDataProvider {
342 public: 348 public:
343 // |write_delay| the number of MockWrites to complete before allowing 349 // |write_delay| the number of MockWrites to complete before allowing
344 // a MockRead to complete. 350 // a MockRead to complete.
345 // |reads| the list of MockRead completions. 351 // |reads| the list of MockRead completions.
346 // |writes| the list of MockWrite completions. 352 // |writes| the list of MockWrite completions.
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 virtual ~MockClientSocketFactory(); 636 virtual ~MockClientSocketFactory();
631 637
632 void AddSocketDataProvider(SocketDataProvider* socket); 638 void AddSocketDataProvider(SocketDataProvider* socket);
633 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket); 639 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket);
634 void ResetNextMockIndexes(); 640 void ResetNextMockIndexes();
635 641
636 SocketDataProviderArray<SocketDataProvider>& mock_data() { 642 SocketDataProviderArray<SocketDataProvider>& mock_data() {
637 return mock_data_; 643 return mock_data_;
638 } 644 }
639 645
646 // Note: this method is unsafe; the elements of the returned vector
647 // are not necessarily valid.
648 const std::vector<MockSSLClientSocket*>& ssl_client_sockets() const {
649 return ssl_client_sockets_;
650 }
651
640 // ClientSocketFactory 652 // ClientSocketFactory
641 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( 653 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket(
642 DatagramSocket::BindType bind_type, 654 DatagramSocket::BindType bind_type,
643 const RandIntCallback& rand_int_cb, 655 const RandIntCallback& rand_int_cb,
644 NetLog* net_log, 656 NetLog* net_log,
645 const NetLog::Source& source) OVERRIDE; 657 const NetLog::Source& source) OVERRIDE;
646 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket( 658 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket(
647 const AddressList& addresses, 659 const AddressList& addresses,
648 NetLog* net_log, 660 NetLog* net_log,
649 const NetLog::Source& source) OVERRIDE; 661 const NetLog::Source& source) OVERRIDE;
650 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket( 662 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket(
651 scoped_ptr<ClientSocketHandle> transport_socket, 663 scoped_ptr<ClientSocketHandle> transport_socket,
652 const HostPortPair& host_and_port, 664 const HostPortPair& host_and_port,
653 const SSLConfig& ssl_config, 665 const SSLConfig& ssl_config,
654 const SSLClientSocketContext& context) OVERRIDE; 666 const SSLClientSocketContext& context) OVERRIDE;
655 virtual void ClearSSLSessionCache() OVERRIDE; 667 virtual void ClearSSLSessionCache() OVERRIDE;
656 668
657 private: 669 private:
658 SocketDataProviderArray<SocketDataProvider> mock_data_; 670 SocketDataProviderArray<SocketDataProvider> mock_data_;
659 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; 671 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
672 std::vector<MockSSLClientSocket*> ssl_client_sockets_;
660 }; 673 };
661 674
662 class MockClientSocket : public SSLClientSocket { 675 class MockClientSocket : public SSLClientSocket {
663 public: 676 public:
664 // Value returned by GetTLSUniqueChannelBinding(). 677 // Value returned by GetTLSUniqueChannelBinding().
665 static const char kTlsUnique[]; 678 static const char kTlsUnique[];
666 679
667 // 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
668 // unique socket IDs. 681 // unique socket IDs.
669 explicit MockClientSocket(const BoundNetLog& net_log); 682 explicit MockClientSocket(const BoundNetLog& net_log);
(...skipping 13 matching lines...) Expand all
683 virtual void Disconnect() OVERRIDE; 696 virtual void Disconnect() OVERRIDE;
684 virtual bool IsConnected() const OVERRIDE; 697 virtual bool IsConnected() const OVERRIDE;
685 virtual bool IsConnectedAndIdle() const OVERRIDE; 698 virtual bool IsConnectedAndIdle() const OVERRIDE;
686 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; 699 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE;
687 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; 700 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE;
688 virtual const BoundNetLog& NetLog() const OVERRIDE; 701 virtual const BoundNetLog& NetLog() const OVERRIDE;
689 virtual void SetSubresourceSpeculation() OVERRIDE {} 702 virtual void SetSubresourceSpeculation() OVERRIDE {}
690 virtual void SetOmniboxSpeculation() OVERRIDE {} 703 virtual void SetOmniboxSpeculation() OVERRIDE {}
691 704
692 // SSLClientSocket implementation. 705 // SSLClientSocket implementation.
706 virtual bool InSessionCache() const OVERRIDE;
707 virtual void SetHandshakeCompletionCallback(const base::Closure& cb) OVERRIDE;
693 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) 708 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info)
694 OVERRIDE; 709 OVERRIDE;
695 virtual int ExportKeyingMaterial(const base::StringPiece& label, 710 virtual int ExportKeyingMaterial(const base::StringPiece& label,
696 bool has_context, 711 bool has_context,
697 const base::StringPiece& context, 712 const base::StringPiece& context,
698 unsigned char* out, 713 unsigned char* out,
699 unsigned int outlen) OVERRIDE; 714 unsigned int outlen) OVERRIDE;
700 virtual int GetTLSUniqueChannelBinding(std::string* out) OVERRIDE; 715 virtual int GetTLSUniqueChannelBinding(std::string* out) OVERRIDE;
701 virtual NextProtoStatus GetNextProto(std::string* proto) OVERRIDE; 716 virtual NextProtoStatus GetNextProto(std::string* proto) OVERRIDE;
702 virtual ChannelIDService* GetChannelIDService() const OVERRIDE; 717 virtual ChannelIDService* GetChannelIDService() const OVERRIDE;
703 718
704 protected: 719 protected:
705 virtual ~MockClientSocket(); 720 virtual ~MockClientSocket();
706 void RunCallbackAsync(const CompletionCallback& callback, int result); 721 void RunCallbackAsync(const CompletionCallback& callback, int result);
707 void RunCallback(const CompletionCallback& callback, int result); 722 void RunCallback(const CompletionCallback& callback, int result);
708 723
709 // SSLClientSocket implementation. 724 // SSLClientSocket implementation.
710 virtual scoped_refptr<X509Certificate> GetUnverifiedServerCertificateChain() 725 virtual scoped_refptr<X509Certificate> GetUnverifiedServerCertificateChain()
711 const OVERRIDE; 726 const OVERRIDE;
712 727
713 // True if Connect completed successfully and Disconnect hasn't been called. 728 // True if Connect completed successfully and Disconnect hasn't been called.
714 bool connected_; 729 bool connected_;
715 730
716 // Address of the "remote" peer we're connected to. 731 // Address of the "remote" peer we're connected to.
717 IPEndPoint peer_addr_; 732 IPEndPoint peer_addr_;
718 733
719 BoundNetLog net_log_; 734 BoundNetLog net_log_;
720 735
736 private:
721 base::WeakPtrFactory<MockClientSocket> weak_factory_; 737 base::WeakPtrFactory<MockClientSocket> weak_factory_;
722 738
723 DISALLOW_COPY_AND_ASSIGN(MockClientSocket); 739 DISALLOW_COPY_AND_ASSIGN(MockClientSocket);
724 }; 740 };
725 741
726 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket { 742 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket {
727 public: 743 public:
728 MockTCPClientSocket(const AddressList& addresses, 744 MockTCPClientSocket(const AddressList& addresses,
729 net::NetLog* net_log, 745 net::NetLog* net_log,
730 SocketDataProvider* socket); 746 SocketDataProvider* socket);
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 virtual int Connect(const CompletionCallback& callback) OVERRIDE; 957 virtual int Connect(const CompletionCallback& callback) OVERRIDE;
942 virtual void Disconnect() OVERRIDE; 958 virtual void Disconnect() OVERRIDE;
943 virtual bool IsConnected() const OVERRIDE; 959 virtual bool IsConnected() const OVERRIDE;
944 virtual bool WasEverUsed() const OVERRIDE; 960 virtual bool WasEverUsed() const OVERRIDE;
945 virtual bool UsingTCPFastOpen() const OVERRIDE; 961 virtual bool UsingTCPFastOpen() const OVERRIDE;
946 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; 962 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE;
947 virtual bool WasNpnNegotiated() const OVERRIDE; 963 virtual bool WasNpnNegotiated() const OVERRIDE;
948 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; 964 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE;
949 965
950 // SSLClientSocket implementation. 966 // SSLClientSocket implementation.
967 virtual bool InSessionCache() const OVERRIDE;
968 virtual void SetHandshakeCompletionCallback(const base::Closure& cb) OVERRIDE;
951 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) 969 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info)
952 OVERRIDE; 970 OVERRIDE;
953 virtual NextProtoStatus GetNextProto(std::string* proto) OVERRIDE; 971 virtual NextProtoStatus GetNextProto(std::string* proto) OVERRIDE;
954 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE; 972 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE;
955 virtual void set_protocol_negotiated(NextProto protocol_negotiated) OVERRIDE; 973 virtual void set_protocol_negotiated(NextProto protocol_negotiated) OVERRIDE;
956 virtual NextProto GetNegotiatedProtocol() const OVERRIDE; 974 virtual NextProto GetNegotiatedProtocol() const OVERRIDE;
957 975
958 // This MockSocket does not implement the manual async IO feature. 976 // This MockSocket does not implement the manual async IO feature.
959 virtual void OnReadComplete(const MockRead& data) OVERRIDE; 977 virtual void OnReadComplete(const MockRead& data) OVERRIDE;
960 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; 978 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE;
961 979
962 virtual bool WasChannelIDSent() const OVERRIDE; 980 virtual bool WasChannelIDSent() const OVERRIDE;
963 virtual void set_channel_id_sent(bool channel_id_sent) OVERRIDE; 981 virtual void set_channel_id_sent(bool channel_id_sent) OVERRIDE;
964 virtual ChannelIDService* GetChannelIDService() const OVERRIDE; 982 virtual ChannelIDService* GetChannelIDService() const OVERRIDE;
965 983
984 bool reached_connect() const { return reached_connect_; }
985
986 // Resumes the connection of a socket that was paused for testing.
987 // |connect_callback_| should be set before invoking this method.
988 void RestartPausedConnect();
989
966 private: 990 private:
967 static void ConnectCallback(MockSSLClientSocket* ssl_client_socket, 991 enum ConnectState {
968 const CompletionCallback& callback, 992 STATE_NONE,
969 int rv); 993 STATE_TRANSPORT_CONNECT,
994 STATE_TRANSPORT_CONNECT_COMPLETE,
995 STATE_SSL_CONNECT,
996 STATE_SSL_CONNECT_COMPLETE,
997 };
998
999 void OnIOComplete(int result);
1000
1001 // Runs the state transistion loop.
1002 int DoConnectLoop(int result);
1003
1004 int DoTransportConnect();
1005 int DoTransportConnectComplete(int result);
1006 int DoSSLConnect();
1007 int DoSSLConnectComplete(int result);
970 1008
971 scoped_ptr<ClientSocketHandle> transport_; 1009 scoped_ptr<ClientSocketHandle> transport_;
972 SSLSocketDataProvider* data_; 1010 SSLSocketDataProvider* data_;
973 bool is_npn_state_set_; 1011 bool is_npn_state_set_;
974 bool new_npn_value_; 1012 bool new_npn_value_;
975 bool is_protocol_negotiated_set_; 1013 bool is_protocol_negotiated_set_;
976 NextProto protocol_negotiated_; 1014 NextProto protocol_negotiated_;
977 1015
1016 CompletionCallback connect_callback_;
1017 // Indicates what state of Connect the socket should enter.
1018 ConnectState next_connect_state_;
wtc 2014/08/04 00:04:17 Nit: list the reached_connect_ member here because
mshelley 2014/08/04 16:41:59 Done.
1019
1020 base::Closure handshake_completion_callback_;
1021
1022 base::WeakPtrFactory<MockSSLClientSocket> weak_factory_;
1023
1024 // True if the Connect method has been called on the socket.
1025 bool reached_connect_;
1026
978 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket); 1027 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket);
979 }; 1028 };
980 1029
981 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket { 1030 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket {
982 public: 1031 public:
983 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); 1032 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log);
984 virtual ~MockUDPClientSocket(); 1033 virtual ~MockUDPClientSocket();
985 1034
986 // Socket implementation. 1035 // Socket implementation.
987 virtual int Read(IOBuffer* buf, 1036 virtual int Read(IOBuffer* buf,
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
1282 1331
1283 extern const char kSOCKS5OkRequest[]; 1332 extern const char kSOCKS5OkRequest[];
1284 extern const int kSOCKS5OkRequestLength; 1333 extern const int kSOCKS5OkRequestLength;
1285 1334
1286 extern const char kSOCKS5OkResponse[]; 1335 extern const char kSOCKS5OkResponse[];
1287 extern const int kSOCKS5OkResponseLength; 1336 extern const int kSOCKS5OkResponseLength;
1288 1337
1289 } // namespace net 1338 } // namespace net
1290 1339
1291 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ 1340 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698