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

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: Changed the structure of pending_sockets_and_callbacks_ and made cl compatible with nss. (Fixed one… 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 bool is_in_session_cache_;
Ryan Sleevi 2014/07/10 19:51:05 Probably needs a comment here as well, since conne
mshelley 2014/07/10 22:07:14 I just realized that this shouldn't even be here -
339
340 // Denotes that this job may have pending jobs dependant upon its connection.
341 bool is_leader_;
Ryan Sleevi 2014/07/10 19:51:05 So, I'm a little confused by this - is this bookke
mshelley 2014/07/10 22:07:15 This is something that the test sets to affect the
Ryan Sleevi 2014/07/12 00:12:15 What I meant is that your tests that use this also
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();
Ryan Sleevi 2014/07/10 19:51:05 Static variables are very bad, especially in tests
mshelley 2014/07/10 22:07:15 Yeah I used the static variable because I wanted t
Ryan Sleevi 2014/07/12 00:12:15 The SocketDataProvider has a path to the ClientSoc
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 WatchSessionForCompletion(const base::Closure& cb) OVERRIDE;
709 virtual void SetSocketFailureCallback(const base::Closure& cb) OVERRIDE;
710 virtual void OnSocketFailure() OVERRIDE;
711 virtual void SetIsLeader() OVERRIDE;
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 WatchSessionForCompletion(const base::Closure& cb) OVERRIDE;
973 virtual void SetSocketFailureCallback(const base::Closure& cb) OVERRIDE;
974 virtual void OnSocketFailure() 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
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.
Ryan Sleevi 2014/07/10 19:51:05 Just from reading this, "the correct time" is uncl
mshelley 2014/07/10 22:07:15 Done.
993 bool IsGoodOrdering() const;
994
969 private: 995 private:
970 static void ConnectCallback(MockSSLClientSocket* ssl_client_socket, 996 static void ConnectCallback(MockSSLClientSocket* ssl_client_socket,
971 const CompletionCallback& callback, 997 const CompletionCallback& callback,
972 int rv); 998 int rv);
973 999
1000 base::Closure process_pending_jobs_callback_;
1001
974 scoped_ptr<ClientSocketHandle> transport_; 1002 scoped_ptr<ClientSocketHandle> transport_;
975 SSLSocketDataProvider* data_; 1003 SSLSocketDataProvider* data_;
976 bool is_npn_state_set_; 1004 bool is_npn_state_set_;
977 bool new_npn_value_; 1005 bool new_npn_value_;
978 bool is_protocol_negotiated_set_; 1006 bool is_protocol_negotiated_set_;
979 NextProto protocol_negotiated_; 1007 NextProto protocol_negotiated_;
1008 bool good_ordering_;
980 1009
981 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket); 1010 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket);
982 }; 1011 };
983 1012
984 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket { 1013 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket {
985 public: 1014 public:
986 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); 1015 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log);
987 virtual ~MockUDPClientSocket(); 1016 virtual ~MockUDPClientSocket();
988 1017
989 // Socket implementation. 1018 // Socket implementation.
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 1314
1286 extern const char kSOCKS5OkRequest[]; 1315 extern const char kSOCKS5OkRequest[];
1287 extern const int kSOCKS5OkRequestLength; 1316 extern const int kSOCKS5OkRequestLength;
1288 1317
1289 extern const char kSOCKS5OkResponse[]; 1318 extern const char kSOCKS5OkResponse[];
1290 extern const int kSOCKS5OkResponseLength; 1319 extern const int kSOCKS5OkResponseLength;
1291 1320
1292 } // namespace net 1321 } // namespace net
1293 1322
1294 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ 1323 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698