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

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: Added checks to determine if false start connections fail, and moved location of enable_job_waiting… 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 11 matching lines...) Expand all
22 #include "net/base/io_buffer.h" 22 #include "net/base/io_buffer.h"
23 #include "net/base/net_errors.h" 23 #include "net/base/net_errors.h"
24 #include "net/base/net_log.h" 24 #include "net/base/net_log.h"
25 #include "net/base/test_completion_callback.h" 25 #include "net/base/test_completion_callback.h"
26 #include "net/http/http_auth_controller.h" 26 #include "net/http/http_auth_controller.h"
27 #include "net/http/http_proxy_client_socket_pool.h" 27 #include "net/http/http_proxy_client_socket_pool.h"
28 #include "net/socket/client_socket_factory.h" 28 #include "net/socket/client_socket_factory.h"
29 #include "net/socket/client_socket_handle.h" 29 #include "net/socket/client_socket_handle.h"
30 #include "net/socket/socks_client_socket_pool.h" 30 #include "net/socket/socks_client_socket_pool.h"
31 #include "net/socket/ssl_client_socket.h" 31 #include "net/socket/ssl_client_socket.h"
32 #include "net/socket/ssl_client_socket_openssl.h"
wtc 2014/07/08 01:25:41 IMPORTANT: this header should not need to include
mshelley 2014/07/09 19:51:00 Done.
32 #include "net/socket/ssl_client_socket_pool.h" 33 #include "net/socket/ssl_client_socket_pool.h"
33 #include "net/socket/transport_client_socket_pool.h" 34 #include "net/socket/transport_client_socket_pool.h"
34 #include "net/ssl/ssl_config_service.h" 35 #include "net/ssl/ssl_config_service.h"
35 #include "net/udp/datagram_client_socket.h" 36 #include "net/udp/datagram_client_socket.h"
36 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
37 38
38 namespace net { 39 namespace net {
39 40
40 enum { 41 enum {
41 // A private network error code used by the socket test utility classes. 42 // A private network error code used by the socket test utility classes.
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 std::string next_proto; 329 std::string next_proto;
329 std::string server_protos; 330 std::string server_protos;
330 bool was_npn_negotiated; 331 bool was_npn_negotiated;
331 NextProto protocol_negotiated; 332 NextProto protocol_negotiated;
332 bool client_cert_sent; 333 bool client_cert_sent;
333 SSLCertRequestInfo* cert_request_info; 334 SSLCertRequestInfo* cert_request_info;
334 scoped_refptr<X509Certificate> cert; 335 scoped_refptr<X509Certificate> cert;
335 bool channel_id_sent; 336 bool channel_id_sent;
336 ServerBoundCertService* server_bound_cert_service; 337 ServerBoundCertService* server_bound_cert_service;
337 int connection_status; 338 int connection_status;
339 bool is_in_session_cache_;
340 bool is_leader_;
wtc 2014/07/08 01:25:41 is_leader_ should be documented because its meanin
mshelley 2014/07/09 19:51:00 Done.
338 }; 341 };
339 342
340 // A DataProvider where the client must write a request before the reads (e.g. 343 // A DataProvider where the client must write a request before the reads (e.g.
341 // the response) will complete. 344 // the response) will complete.
342 class DelayedSocketData : public StaticSocketDataProvider { 345 class DelayedSocketData : public StaticSocketDataProvider {
343 public: 346 public:
344 // |write_delay| the number of MockWrites to complete before allowing 347 // |write_delay| the number of MockWrites to complete before allowing
345 // a MockRead to complete. 348 // a MockRead to complete.
346 // |reads| the list of MockRead completions. 349 // |reads| the list of MockRead completions.
347 // |writes| the list of MockWrite completions. 350 // |writes| the list of MockWrite completions.
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 // socket types. 630 // socket types.
628 class MockClientSocketFactory : public ClientSocketFactory { 631 class MockClientSocketFactory : public ClientSocketFactory {
629 public: 632 public:
630 MockClientSocketFactory(); 633 MockClientSocketFactory();
631 virtual ~MockClientSocketFactory(); 634 virtual ~MockClientSocketFactory();
632 635
633 void AddSocketDataProvider(SocketDataProvider* socket); 636 void AddSocketDataProvider(SocketDataProvider* socket);
634 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket); 637 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket);
635 void ResetNextMockIndexes(); 638 void ResetNextMockIndexes();
636 639
640 // Tell the client socket factory that the leading job has connected.
wtc 2014/07/08 01:25:41 Nit: Tell => Tells
mshelley 2014/07/09 19:50:59 Done.
641 static void LeaderConnected();
wtc 2014/07/08 01:25:41 Name this method "SetLeaderConnected".
mshelley 2014/07/09 19:51:00 Done.
642
643 // Returns |leader_connected_|.
644 static bool IsLeaderConnected();
wtc 2014/07/08 01:25:41 IMPORTANT: it seems that the leader connect job is
mshelley 2014/07/09 19:51:00 I agree that it would make more sense to have thes
645
637 SocketDataProviderArray<SocketDataProvider>& mock_data() { 646 SocketDataProviderArray<SocketDataProvider>& mock_data() {
638 return mock_data_; 647 return mock_data_;
639 } 648 }
640 649
641 // ClientSocketFactory 650 // ClientSocketFactory
642 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( 651 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket(
643 DatagramSocket::BindType bind_type, 652 DatagramSocket::BindType bind_type,
644 const RandIntCallback& rand_int_cb, 653 const RandIntCallback& rand_int_cb,
645 NetLog* net_log, 654 NetLog* net_log,
646 const NetLog::Source& source) OVERRIDE; 655 const NetLog::Source& source) OVERRIDE;
647 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket( 656 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket(
648 const AddressList& addresses, 657 const AddressList& addresses,
649 NetLog* net_log, 658 NetLog* net_log,
650 const NetLog::Source& source) OVERRIDE; 659 const NetLog::Source& source) OVERRIDE;
651 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket( 660 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket(
652 scoped_ptr<ClientSocketHandle> transport_socket, 661 scoped_ptr<ClientSocketHandle> transport_socket,
653 const HostPortPair& host_and_port, 662 const HostPortPair& host_and_port,
654 const SSLConfig& ssl_config, 663 const SSLConfig& ssl_config,
655 const SSLClientSocketContext& context) OVERRIDE; 664 const SSLClientSocketContext& context) OVERRIDE;
656 virtual void ClearSSLSessionCache() OVERRIDE; 665 virtual void ClearSSLSessionCache() OVERRIDE;
666 virtual std::vector<MockSSLClientSocket*> GetSSLClientSockets();
657 667
658 private: 668 private:
659 SocketDataProviderArray<SocketDataProvider> mock_data_; 669 SocketDataProviderArray<SocketDataProvider> mock_data_;
660 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; 670 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
671 static NET_EXPORT bool leader_connected_;
wtc 2014/07/08 01:25:41 Use NET_EXPORT_PRIVATE instead. But, is this reall
mshelley 2014/07/09 19:50:59 Done.
672 std::vector<MockSSLClientSocket*> ssl_client_sockets_;
661 }; 673 };
662 674
663 class MockClientSocket : public SSLClientSocket { 675 class MockClientSocket : public SSLClientSocket {
664 public: 676 public:
665 // Value returned by GetTLSUniqueChannelBinding(). 677 // Value returned by GetTLSUniqueChannelBinding().
666 static const char kTlsUnique[]; 678 static const char kTlsUnique[];
667 679
668 // 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
669 // unique socket IDs. 681 // unique socket IDs.
670 explicit MockClientSocket(const BoundNetLog& net_log); 682 explicit MockClientSocket(const BoundNetLog& net_log);
(...skipping 13 matching lines...) Expand all
684 virtual void Disconnect() OVERRIDE; 696 virtual void Disconnect() OVERRIDE;
685 virtual bool IsConnected() const OVERRIDE; 697 virtual bool IsConnected() const OVERRIDE;
686 virtual bool IsConnectedAndIdle() const OVERRIDE; 698 virtual bool IsConnectedAndIdle() const OVERRIDE;
687 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; 699 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE;
688 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE; 700 virtual int GetLocalAddress(IPEndPoint* address) const OVERRIDE;
689 virtual const BoundNetLog& NetLog() const OVERRIDE; 701 virtual const BoundNetLog& NetLog() const OVERRIDE;
690 virtual void SetSubresourceSpeculation() OVERRIDE {} 702 virtual void SetSubresourceSpeculation() OVERRIDE {}
691 virtual void SetOmniboxSpeculation() OVERRIDE {} 703 virtual void SetOmniboxSpeculation() OVERRIDE {}
692 704
693 // SSLClientSocket implementation. 705 // SSLClientSocket implementation.
706 virtual bool InSessionCache() const OVERRIDE;
707 virtual void WatchSessionForCompletion(
708 const base::Closure& cb) const OVERRIDE;
709 virtual void SetSocketFailureCallback(const base::Closure& cb) OVERRIDE;
710 virtual void OnSocketFailure() OVERRIDE;
694 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) 711 virtual void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info)
695 OVERRIDE; 712 OVERRIDE;
696 virtual int ExportKeyingMaterial(const base::StringPiece& label, 713 virtual int ExportKeyingMaterial(const base::StringPiece& label,
697 bool has_context, 714 bool has_context,
698 const base::StringPiece& context, 715 const base::StringPiece& context,
699 unsigned char* out, 716 unsigned char* out,
700 unsigned int outlen) OVERRIDE; 717 unsigned int outlen) OVERRIDE;
701 virtual int GetTLSUniqueChannelBinding(std::string* out) OVERRIDE; 718 virtual int GetTLSUniqueChannelBinding(std::string* out) OVERRIDE;
702 virtual NextProtoStatus GetNextProto(std::string* proto, 719 virtual NextProtoStatus GetNextProto(std::string* proto,
703 std::string* server_protos) OVERRIDE; 720 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; 960 virtual int Connect(const CompletionCallback& callback) OVERRIDE;
944 virtual void Disconnect() OVERRIDE; 961 virtual void Disconnect() OVERRIDE;
945 virtual bool IsConnected() const OVERRIDE; 962 virtual bool IsConnected() const OVERRIDE;
946 virtual bool WasEverUsed() const OVERRIDE; 963 virtual bool WasEverUsed() const OVERRIDE;
947 virtual bool UsingTCPFastOpen() const OVERRIDE; 964 virtual bool UsingTCPFastOpen() const OVERRIDE;
948 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE; 965 virtual int GetPeerAddress(IPEndPoint* address) const OVERRIDE;
949 virtual bool WasNpnNegotiated() const OVERRIDE; 966 virtual bool WasNpnNegotiated() const OVERRIDE;
950 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE; 967 virtual bool GetSSLInfo(SSLInfo* ssl_info) OVERRIDE;
951 968
952 // SSLClientSocket implementation. 969 // SSLClientSocket implementation.
970 virtual bool InSessionCache() const OVERRIDE;
971 virtual void WatchSessionForCompletion(
972 const base::Closure& cb) const 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 bool IsGoodOrdering() const;
wtc 2014/07/08 01:25:41 Document this method.
mshelley 2014/07/09 19:51:00 Done.
992
969 private: 993 private:
970 static void ConnectCallback(MockSSLClientSocket* ssl_client_socket, 994 static void ConnectCallback(MockSSLClientSocket* ssl_client_socket,
971 const CompletionCallback& callback, 995 const CompletionCallback& callback,
972 int rv); 996 int rv);
973 997
998 mutable base::Closure process_pending_jobs_callback_;
wtc 2014/07/08 01:25:41 Why does this member need to be marked mutable? Ca
mshelley 2014/07/09 19:51:00 This member was marked as mutable because I need t
999
974 scoped_ptr<ClientSocketHandle> transport_; 1000 scoped_ptr<ClientSocketHandle> transport_;
975 SSLSocketDataProvider* data_; 1001 SSLSocketDataProvider* data_;
976 bool is_npn_state_set_; 1002 bool is_npn_state_set_;
977 bool new_npn_value_; 1003 bool new_npn_value_;
978 bool is_protocol_negotiated_set_; 1004 bool is_protocol_negotiated_set_;
979 NextProto protocol_negotiated_; 1005 NextProto protocol_negotiated_;
1006 bool good_ordering_;
980 1007
981 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket); 1008 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket);
982 }; 1009 };
983 1010
984 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket { 1011 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket {
985 public: 1012 public:
986 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); 1013 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log);
987 virtual ~MockUDPClientSocket(); 1014 virtual ~MockUDPClientSocket();
988 1015
989 // Socket implementation. 1016 // Socket implementation.
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 1312
1286 extern const char kSOCKS5OkRequest[]; 1313 extern const char kSOCKS5OkRequest[];
1287 extern const int kSOCKS5OkRequestLength; 1314 extern const int kSOCKS5OkRequestLength;
1288 1315
1289 extern const char kSOCKS5OkResponse[]; 1316 extern const char kSOCKS5OkResponse[];
1290 extern const int kSOCKS5OkResponseLength; 1317 extern const int kSOCKS5OkResponseLength;
1291 1318
1292 } // namespace net 1319 } // namespace net
1293 1320
1294 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ 1321 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698