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

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: Fixed error in SSLSessionIsInCache. Created 6 years, 5 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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 std::string next_proto; 328 std::string next_proto;
329 std::string server_protos; 329 std::string server_protos;
330 bool was_npn_negotiated; 330 bool was_npn_negotiated;
331 NextProto protocol_negotiated; 331 NextProto protocol_negotiated;
332 bool client_cert_sent; 332 bool client_cert_sent;
333 SSLCertRequestInfo* cert_request_info; 333 SSLCertRequestInfo* cert_request_info;
334 scoped_refptr<X509Certificate> cert; 334 scoped_refptr<X509Certificate> cert;
335 bool channel_id_sent; 335 bool channel_id_sent;
336 ServerBoundCertService* server_bound_cert_service; 336 ServerBoundCertService* server_bound_cert_service;
337 int connection_status; 337 int connection_status;
338 // Indicates that the socket should block in the Connect method.
339 bool block_in_connect_;
340 // Indicates that the socket previously blocked in the Connect method.
341 bool blocked_in_connect_;
wtc 2014/07/18 01:17:14 Nit: these two members look similar. I suggest nam
mshelley 2014/07/18 21:08:31 Done.
342 bool is_in_session_cache_;
wtc 2014/07/18 15:39:17 Since SSLSocketDataProvider is a struct, the three
mshelley 2014/07/18 21:08:31 Done.
338 }; 343 };
339 344
340 // 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.
341 // the response) will complete. 346 // the response) will complete.
342 class DelayedSocketData : public StaticSocketDataProvider { 347 class DelayedSocketData : public StaticSocketDataProvider {
343 public: 348 public:
344 // |write_delay| the number of MockWrites to complete before allowing 349 // |write_delay| the number of MockWrites to complete before allowing
345 // a MockRead to complete. 350 // a MockRead to complete.
346 // |reads| the list of MockRead completions. 351 // |reads| the list of MockRead completions.
347 // |writes| the list of MockWrite completions. 352 // |writes| the list of MockWrite completions.
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket( 652 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket(
648 const AddressList& addresses, 653 const AddressList& addresses,
649 NetLog* net_log, 654 NetLog* net_log,
650 const NetLog::Source& source) OVERRIDE; 655 const NetLog::Source& source) OVERRIDE;
651 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket( 656 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket(
652 scoped_ptr<ClientSocketHandle> transport_socket, 657 scoped_ptr<ClientSocketHandle> transport_socket,
653 const HostPortPair& host_and_port, 658 const HostPortPair& host_and_port,
654 const SSLConfig& ssl_config, 659 const SSLConfig& ssl_config,
655 const SSLClientSocketContext& context) OVERRIDE; 660 const SSLClientSocketContext& context) OVERRIDE;
656 virtual void ClearSSLSessionCache() OVERRIDE; 661 virtual void ClearSSLSessionCache() OVERRIDE;
662 virtual std::vector<MockSSLClientSocket*> GetSSLClientSockets();
wtc 2014/07/18 15:39:17 1. Please declare this method before the "ClientSo
mshelley 2014/07/18 21:08:31 Done.
657 663
658 private: 664 private:
659 SocketDataProviderArray<SocketDataProvider> mock_data_; 665 SocketDataProviderArray<SocketDataProvider> mock_data_;
660 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; 666 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
667 std::vector<MockSSLClientSocket*> ssl_client_sockets_;
661 }; 668 };
662 669
663 class MockClientSocket : public SSLClientSocket { 670 class MockClientSocket : public SSLClientSocket {
664 public: 671 public:
665 // Value returned by GetTLSUniqueChannelBinding(). 672 // Value returned by GetTLSUniqueChannelBinding().
666 static const char kTlsUnique[]; 673 static const char kTlsUnique[];
667 674
668 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as 675 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as
669 // unique socket IDs. 676 // unique socket IDs.
670 explicit MockClientSocket(const BoundNetLog& net_log); 677 explicit MockClientSocket(const BoundNetLog& net_log);
671 678
672 // Socket implementation. 679 // Socket implementation.
673 virtual int Read(IOBuffer* buf, 680 virtual int Read(IOBuffer* buf,
674 int buf_len, 681 int buf_len,
675 const CompletionCallback& callback) = 0; 682 const CompletionCallback& callback) = 0;
676 virtual int Write(IOBuffer* buf, 683 virtual int Write(IOBuffer* buf,
677 int buf_len, 684 int buf_len,
678 const CompletionCallback& callback) = 0; 685 const CompletionCallback& callback) = 0;
679 virtual int SetReceiveBufferSize(int32 size) OVERRIDE; 686 virtual int SetReceiveBufferSize(int32 size) OVERRIDE;
680 virtual int SetSendBufferSize(int32 size) OVERRIDE; 687 virtual int SetSendBufferSize(int32 size) OVERRIDE;
681 688
682 // StreamSocket implementation. 689 // StreamSocket implementation.
683 virtual int Connect(const CompletionCallback& callback) = 0; 690 virtual int Connect(const CompletionCallback& callback) = 0;
684 virtual void Disconnect() OVERRIDE; 691 virtual void Disconnect() OVERRIDE;
685 virtual bool IsConnected() const OVERRIDE; 692 virtual bool IsConnected() const OVERRIDE;
693 virtual bool IsConnectedSSL() const OVERRIDE;
wtc 2014/07/18 01:17:14 IMPORTANT: IsConnectedSSL is not a method of the S
wtc 2014/07/18 15:39:17 MockSSLClientSocket has the same problem on line 9
mshelley 2014/07/18 21:08:31 Done.
686 virtual bool IsConnectedAndIdle() const OVERRIDE; 694 virtual bool IsConnectedAndIdle() const OVERRIDE;
687 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; 695 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE;
688 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; 696 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE;
689 virtual const BoundNetLog& NetLog() const OVERRIDE; 697 virtual const BoundNetLog& NetLog() const OVERRIDE;
690 virtual void SetSubresourceSpeculation() OVERRIDE {} 698 virtual void SetSubresourceSpeculation() OVERRIDE {}
691 virtual void SetOmniboxSpeculation() OVERRIDE {} 699 virtual void SetOmniboxSpeculation() OVERRIDE {}
692 700
693 // SSLClientSocket implementation. 701 // SSLClientSocket implementation.
702 virtual bool InSessionCache() const OVERRIDE;
703 virtual void SetHandshakeSuccessCallback(const base::Closure& cb) OVERRIDE;
704 virtual void SetHandshakeFailureCallback(const base::Closure& cb) OVERRIDE;
694 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) 705 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info)
695 OVERRIDE; 706 OVERRIDE;
696 virtual int ExportKeyingMaterial(const base::StringPiece& label, 707 virtual int ExportKeyingMaterial(const base::StringPiece& label,
697 bool has_context, 708 bool has_context,
698 const base::StringPiece& context, 709 const base::StringPiece& context,
699 unsigned char* out, 710 unsigned char* out,
700 unsigned int outlen) OVERRIDE; 711 unsigned int outlen) OVERRIDE;
701 virtual int GetTLSUniqueChannelBinding(std::string* out) OVERRIDE; 712 virtual int GetTLSUniqueChannelBinding(std::string* out) OVERRIDE;
702 virtual NextProtoStatus GetNextProto(std::string* proto, 713 virtual NextProtoStatus GetNextProto(std::string* proto,
703 std::string* server_protos) OVERRIDE; 714 std::string* server_protos) OVERRIDE;
704 virtual ServerBoundCertService* GetServerBoundCertService() const OVERRIDE; 715 virtual ServerBoundCertService* GetServerBoundCertService() const OVERRIDE;
705 716
717 // Resumes the connection of a socket that was paused for testing.
wtc 2014/07/18 01:17:14 This should say "Returns a callback that resumes t
mshelley 2014/07/18 21:08:31 Done.
718 // |resumption_callback_| should be set before invoking this method.
719 CompletionCallback GetResumptionCallback();
wtc 2014/07/18 15:39:17 This is a getter method, so it should be named and
mshelley 2014/07/18 21:08:31 Done.
720
706 protected: 721 protected:
707 virtual ~MockClientSocket(); 722 virtual ~MockClientSocket();
708 void RunCallbackAsync(const CompletionCallback& callback, int result); 723 void RunCallbackAsync(const CompletionCallback& callback, int result);
709 void RunCallback(const CompletionCallback& callback, int result); 724 void RunCallback(const CompletionCallback& callback, int result);
710 725
726 // Callback to be used to resume the connection of a paused socket.
727 CompletionCallback resumption_callback_;
wtc 2014/07/18 15:39:16 1. Declare this data member after line 731 because
mshelley 2014/07/18 21:08:31 Done.
728
711 // SSLClientSocket implementation. 729 // SSLClientSocket implementation.
712 virtual scoped_refptr<X509Certificate> GetUnverifiedServerCertificateChain() 730 virtual scoped_refptr<X509Certificate> GetUnverifiedServerCertificateChain()
713 const OVERRIDE; 731 const OVERRIDE;
714 732
715 // True if Connect completed successfully and Disconnect hasn't been called. 733 // True if Connect completed successfully and Disconnect hasn't been called.
716 bool connected_; 734 bool connected_;
717 735
718 // Address of the "remote" peer we're connected to. 736 // Address of the "remote" peer we're connected to.
719 IPEndPoint peer_addr_; 737 IPEndPoint peer_addr_;
720 738
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
936 int buf_len, 954 int buf_len,
937 const CompletionCallback& callback) OVERRIDE; 955 const CompletionCallback& callback) OVERRIDE;
938 virtual int Write(IOBuffer* buf, 956 virtual int Write(IOBuffer* buf,
939 int buf_len, 957 int buf_len,
940 const CompletionCallback& callback) OVERRIDE; 958 const CompletionCallback& callback) OVERRIDE;
941 959
942 // StreamSocket implementation. 960 // StreamSocket implementation.
943 virtual int Connect(const CompletionCallback& callback) OVERRIDE; 961 virtual int Connect(const CompletionCallback& callback) OVERRIDE;
944 virtual void Disconnect() OVERRIDE; 962 virtual void Disconnect() OVERRIDE;
945 virtual bool IsConnected() const OVERRIDE; 963 virtual bool IsConnected() const OVERRIDE;
964 virtual bool IsConnectedSSL() const OVERRIDE;
946 virtual bool WasEverUsed() const OVERRIDE; 965 virtual bool WasEverUsed() const OVERRIDE;
947 virtual bool UsingTCPFastOpen() const OVERRIDE; 966 virtual bool UsingTCPFastOpen() const OVERRIDE;
948 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; 967 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE;
949 virtual bool WasNpnNegotiated() const OVERRIDE; 968 virtual bool WasNpnNegotiated() const OVERRIDE;
950 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; 969 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE;
951 970
952 // SSLClientSocket implementation. 971 // SSLClientSocket implementation.
972 virtual bool InSessionCache() const OVERRIDE;
973 virtual void SetHandshakeSuccessCallback(const base::Closure& cb) OVERRIDE;
974 virtual void SetHandshakeFailureCallback(const base::Closure& cb) OVERRIDE;
953 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) 975 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info)
954 OVERRIDE; 976 OVERRIDE;
955 virtual NextProtoStatus GetNextProto(std::string* proto, 977 virtual NextProtoStatus GetNextProto(std::string* proto,
956 std::string* server_protos) OVERRIDE; 978 std::string* server_protos) OVERRIDE;
957 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE; 979 virtual bool set_was_npn_negotiated(bool negotiated) OVERRIDE;
958 virtual void set_protocol_negotiated(NextProto protocol_negotiated) OVERRIDE; 980 virtual void set_protocol_negotiated(NextProto protocol_negotiated) OVERRIDE;
959 virtual NextProto GetNegotiatedProtocol() const OVERRIDE; 981 virtual NextProto GetNegotiatedProtocol() const OVERRIDE;
960 982
961 // This MockSocket does not implement the manual async IO feature. 983 // This MockSocket does not implement the manual async IO feature.
962 virtual void OnReadComplete(const MockRead& data) OVERRIDE; 984 virtual void OnReadComplete(const MockRead& data) OVERRIDE;
963 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE; 985 virtual void OnConnectComplete(const MockConnect& data) OVERRIDE;
964 986
965 virtual bool WasChannelIDSent() const OVERRIDE; 987 virtual bool WasChannelIDSent() const OVERRIDE;
966 virtual void set_channel_id_sent(bool channel_id_sent) OVERRIDE; 988 virtual void set_channel_id_sent(bool channel_id_sent) OVERRIDE;
967 virtual ServerBoundCertService* GetServerBoundCertService() const OVERRIDE; 989 virtual ServerBoundCertService* GetServerBoundCertService() const OVERRIDE;
968 990
969 private: 991 private:
970 static void ConnectCallback(MockSSLClientSocket* ssl_client_socket, 992 static void ConnectCallback(MockSSLClientSocket* ssl_client_socket,
971 const CompletionCallback& callback, 993 const CompletionCallback& callback,
972 int rv); 994 int rv);
973 995
974 scoped_ptr<ClientSocketHandle> transport_; 996 scoped_ptr<ClientSocketHandle> transport_;
975 SSLSocketDataProvider* data_; 997 SSLSocketDataProvider* data_;
976 bool is_npn_state_set_; 998 bool is_npn_state_set_;
977 bool new_npn_value_; 999 bool new_npn_value_;
978 bool is_protocol_negotiated_set_; 1000 bool is_protocol_negotiated_set_;
979 NextProto protocol_negotiated_; 1001 NextProto protocol_negotiated_;
980 1002
1003 base::Closure success_callback_;
1004 base::Closure error_callback_;
1005
981 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket); 1006 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket);
982 }; 1007 };
983 1008
984 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket { 1009 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket {
985 public: 1010 public:
986 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); 1011 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log);
987 virtual ~MockUDPClientSocket(); 1012 virtual ~MockUDPClientSocket();
988 1013
989 // Socket implementation. 1014 // Socket implementation.
990 virtual int Read(IOBuffer* buf, 1015 virtual int Read(IOBuffer* buf,
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 1310
1286 extern const char kSOCKS5OkRequest[]; 1311 extern const char kSOCKS5OkRequest[];
1287 extern const int kSOCKS5OkRequestLength; 1312 extern const int kSOCKS5OkRequestLength;
1288 1313
1289 extern const char kSOCKS5OkResponse[]; 1314 extern const char kSOCKS5OkResponse[];
1290 extern const int kSOCKS5OkResponseLength; 1315 extern const int kSOCKS5OkResponseLength;
1291 1316
1292 } // namespace net 1317 } // namespace net
1293 1318
1294 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ 1319 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698