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

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: Implemented better memory management and callback handling. 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
339 // Denotes that this job may have pending jobs dependant upon its connection.
340 bool is_leader_;
341 bool is_in_session_cache_;
Ryan Sleevi 2014/07/12 00:12:15 Please update the SSLSocketDataProvider ctor to se
mshelley 2014/07/17 00:28:44 Sorry -- my previous response was incorrect. There
338 }; 342 };
339 343
340 // A DataProvider where the client must write a request before the reads (e.g. 344 // A DataProvider where the client must write a request before the reads (e.g.
341 // the response) will complete. 345 // the response) will complete.
342 class DelayedSocketData : public StaticSocketDataProvider { 346 class DelayedSocketData : public StaticSocketDataProvider {
343 public: 347 public:
344 // |write_delay| the number of MockWrites to complete before allowing 348 // |write_delay| the number of MockWrites to complete before allowing
345 // a MockRead to complete. 349 // a MockRead to complete.
346 // |reads| the list of MockRead completions. 350 // |reads| the list of MockRead completions.
347 // |writes| the list of MockWrite completions. 351 // |writes| the list of MockWrite completions.
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 // socket types. 631 // socket types.
628 class MockClientSocketFactory : public ClientSocketFactory { 632 class MockClientSocketFactory : public ClientSocketFactory {
629 public: 633 public:
630 MockClientSocketFactory(); 634 MockClientSocketFactory();
631 virtual ~MockClientSocketFactory(); 635 virtual ~MockClientSocketFactory();
632 636
633 void AddSocketDataProvider(SocketDataProvider* socket); 637 void AddSocketDataProvider(SocketDataProvider* socket);
634 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket); 638 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket);
635 void ResetNextMockIndexes(); 639 void ResetNextMockIndexes();
636 640
641 // Tells the client socket factory that the leading job has connected.
642 static void SetLeaderConnected();
643
644 // Returns |leader_connected_|.
645 static bool IsLeaderConnected();
646
637 SocketDataProviderArray<SocketDataProvider>& mock_data() { 647 SocketDataProviderArray<SocketDataProvider>& mock_data() {
638 return mock_data_; 648 return mock_data_;
639 } 649 }
640 650
641 // ClientSocketFactory 651 // ClientSocketFactory
642 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( 652 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket(
643 DatagramSocket::BindType bind_type, 653 DatagramSocket::BindType bind_type,
644 const RandIntCallback& rand_int_cb, 654 const RandIntCallback& rand_int_cb,
645 NetLog* net_log, 655 NetLog* net_log,
646 const NetLog::Source& source) OVERRIDE; 656 const NetLog::Source& source) OVERRIDE;
647 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket( 657 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket(
648 const AddressList& addresses, 658 const AddressList& addresses,
649 NetLog* net_log, 659 NetLog* net_log,
650 const NetLog::Source& source) OVERRIDE; 660 const NetLog::Source& source) OVERRIDE;
651 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket( 661 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket(
652 scoped_ptr<ClientSocketHandle> transport_socket, 662 scoped_ptr<ClientSocketHandle> transport_socket,
653 const HostPortPair& host_and_port, 663 const HostPortPair& host_and_port,
654 const SSLConfig& ssl_config, 664 const SSLConfig& ssl_config,
655 const SSLClientSocketContext& context) OVERRIDE; 665 const SSLClientSocketContext& context) OVERRIDE;
656 virtual void ClearSSLSessionCache() OVERRIDE; 666 virtual void ClearSSLSessionCache() OVERRIDE;
667 virtual std::vector<MockSSLClientSocket*> GetSSLClientSockets();
657 668
658 private: 669 private:
659 SocketDataProviderArray<SocketDataProvider> mock_data_; 670 SocketDataProviderArray<SocketDataProvider> mock_data_;
660 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; 671 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
672 static bool leader_connected_;
673 std::vector<MockSSLClientSocket*> ssl_client_sockets_;
661 }; 674 };
662 675
663 class MockClientSocket : public SSLClientSocket { 676 class MockClientSocket : public SSLClientSocket {
664 public: 677 public:
665 // Value returned by GetTLSUniqueChannelBinding(). 678 // Value returned by GetTLSUniqueChannelBinding().
666 static const char kTlsUnique[]; 679 static const char kTlsUnique[];
667 680
668 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as 681 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as
669 // unique socket IDs. 682 // unique socket IDs.
670 explicit MockClientSocket(const BoundNetLog& net_log); 683 explicit MockClientSocket(const BoundNetLog& net_log);
(...skipping 13 matching lines...) Expand all
684 virtual void Disconnect() OVERRIDE; 697 virtual void Disconnect() OVERRIDE;
685 virtual bool IsConnected() const OVERRIDE; 698 virtual bool IsConnected() const OVERRIDE;
686 virtual bool IsConnectedAndIdle() const OVERRIDE; 699 virtual bool IsConnectedAndIdle() const OVERRIDE;
687 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; 700 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE;
688 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; 701 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE;
689 virtual const BoundNetLog& NetLog() const OVERRIDE; 702 virtual const BoundNetLog& NetLog() const OVERRIDE;
690 virtual void SetSubresourceSpeculation() OVERRIDE {} 703 virtual void SetSubresourceSpeculation() OVERRIDE {}
691 virtual void SetOmniboxSpeculation() OVERRIDE {} 704 virtual void SetOmniboxSpeculation() OVERRIDE {}
692 705
693 // SSLClientSocket implementation. 706 // SSLClientSocket implementation.
707 virtual bool InSessionCache() const OVERRIDE;
708 virtual void SetHandshakeSuccessCallback(const base::Closure& cb) OVERRIDE;
709 virtual void SetHandshakeFailureCallback(const base::Closure& cb) OVERRIDE;
710 virtual void OnSocketFailure() OVERRIDE;
711 virtual void SetIsLeader() OVERRIDE;
wtc 2014/07/15 19:27:58 Delete these two methods.
mshelley 2014/07/17 00:28:44 Done.
694 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) 712 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info)
695 OVERRIDE; 713 OVERRIDE;
696 virtual int ExportKeyingMaterial(const base::StringPiece& label, 714 virtual int ExportKeyingMaterial(const base::StringPiece& label,
697 bool has_context, 715 bool has_context,
698 const base::StringPiece& context, 716 const base::StringPiece& context,
699 unsigned char* out, 717 unsigned char* out,
700 unsigned int outlen) OVERRIDE; 718 unsigned int outlen) OVERRIDE;
701 virtual int GetTLSUniqueChannelBinding(std::string* out) OVERRIDE; 719 virtual int GetTLSUniqueChannelBinding(std::string* out) OVERRIDE;
702 virtual NextProtoStatus GetNextProto(std::string* proto, 720 virtual NextProtoStatus GetNextProto(std::string* proto,
703 std::string* server_protos) OVERRIDE; 721 std::string* server_protos) OVERRIDE;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
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;
946 virtual bool WasEverUsed() const OVERRIDE; 964 virtual bool WasEverUsed() const OVERRIDE;
947 virtual bool UsingTCPFastOpen() const OVERRIDE; 965 virtual bool UsingTCPFastOpen() const OVERRIDE;
948 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; 966 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE;
949 virtual bool WasNpnNegotiated() const OVERRIDE; 967 virtual bool WasNpnNegotiated() const OVERRIDE;
950 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; 968 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE;
951 969
952 // SSLClientSocket implementation. 970 // SSLClientSocket implementation.
971 virtual bool InSessionCache() const OVERRIDE;
972 virtual void SetHandshakeSuccessCallback(const base::Closure& cb) OVERRIDE;
973 virtual void SetHandshakeFailureCallback(const base::Closure& cb) OVERRIDE;
974 virtual void OnHandshakeFailure() OVERRIDE;
wtc 2014/07/15 19:27:58 Delete this method.
mshelley 2014/07/17 00:28:44 Done.
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
991 // Returns a bool indicating whether or not the socket connected at
992 // the correct time relative to other sockets with the same host/port pair.
993 //
994 // If |is_leader_| is true, the socket should connect before all other
995 // sockets.
996 // If |is_leader_| is false, the socket should not connect until the leading
997 // socket has connected.
998 bool IsGoodOrdering() const;
999
969 private: 1000 private:
970 static void ConnectCallback(MockSSLClientSocket* ssl_client_socket, 1001 static void ConnectCallback(MockSSLClientSocket* ssl_client_socket,
971 const CompletionCallback& callback, 1002 const CompletionCallback& callback,
972 int rv); 1003 int rv);
973 1004
974 scoped_ptr<ClientSocketHandle> transport_; 1005 scoped_ptr<ClientSocketHandle> transport_;
975 SSLSocketDataProvider* data_; 1006 SSLSocketDataProvider* data_;
976 bool is_npn_state_set_; 1007 bool is_npn_state_set_;
977 bool new_npn_value_; 1008 bool new_npn_value_;
978 bool is_protocol_negotiated_set_; 1009 bool is_protocol_negotiated_set_;
979 NextProto protocol_negotiated_; 1010 NextProto protocol_negotiated_;
1011 bool good_ordering_;
1012 base::Closure success_callback_;
1013 base::Closure error_callback_;
980 1014
981 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket); 1015 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket);
982 }; 1016 };
983 1017
984 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket { 1018 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket {
985 public: 1019 public:
986 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); 1020 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log);
987 virtual ~MockUDPClientSocket(); 1021 virtual ~MockUDPClientSocket();
988 1022
989 // Socket implementation. 1023 // Socket implementation.
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 1319
1286 extern const char kSOCKS5OkRequest[]; 1320 extern const char kSOCKS5OkRequest[];
1287 extern const int kSOCKS5OkRequestLength; 1321 extern const int kSOCKS5OkRequestLength;
1288 1322
1289 extern const char kSOCKS5OkResponse[]; 1323 extern const char kSOCKS5OkResponse[];
1290 extern const int kSOCKS5OkResponseLength; 1324 extern const int kSOCKS5OkResponseLength;
1291 1325
1292 } // namespace net 1326 } // namespace net
1293 1327
1294 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ 1328 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698