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

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

Issue 981723008: Unwind the SSL connection holdback experiment and remove related code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 std::string next_proto; 329 std::string next_proto;
330 bool was_npn_negotiated; 330 bool was_npn_negotiated;
331 NextProto protocol_negotiated; 331 NextProto protocol_negotiated;
332 NextProtoVector next_protos_expected_in_ssl_config; 332 NextProtoVector next_protos_expected_in_ssl_config;
333 bool client_cert_sent; 333 bool client_cert_sent;
334 SSLCertRequestInfo* cert_request_info; 334 SSLCertRequestInfo* cert_request_info;
335 scoped_refptr<X509Certificate> cert; 335 scoped_refptr<X509Certificate> cert;
336 bool channel_id_sent; 336 bool channel_id_sent;
337 ChannelIDService* channel_id_service; 337 ChannelIDService* channel_id_service;
338 int connection_status; 338 int connection_status;
339 // Indicates that the socket should pause in the Connect method.
340 bool should_pause_on_connect;
341 // Whether or not the Socket should behave like there is a pre-existing
342 // session to resume. Whether or not such a session is reported as
343 // resumed is controlled by |connection_status|.
344 bool is_in_session_cache;
345 }; 339 };
346 340
347 // A DataProvider where the client must write a request before the reads (e.g. 341 // A DataProvider where the client must write a request before the reads (e.g.
348 // the response) will complete. 342 // the response) will complete.
349 class DelayedSocketData : public StaticSocketDataProvider { 343 class DelayedSocketData : public StaticSocketDataProvider {
350 public: 344 public:
351 // |write_delay| the number of MockWrites to complete before allowing 345 // |write_delay| the number of MockWrites to complete before allowing
352 // a MockRead to complete. 346 // a MockRead to complete.
353 // |reads| the list of MockRead completions. 347 // |reads| the list of MockRead completions.
354 // |writes| the list of MockWrite completions. 348 // |writes| the list of MockWrite completions.
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 ~MockClientSocketFactory() override; 632 ~MockClientSocketFactory() override;
639 633
640 void AddSocketDataProvider(SocketDataProvider* socket); 634 void AddSocketDataProvider(SocketDataProvider* socket);
641 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket); 635 void AddSSLSocketDataProvider(SSLSocketDataProvider* socket);
642 void ResetNextMockIndexes(); 636 void ResetNextMockIndexes();
643 637
644 SocketDataProviderArray<SocketDataProvider>& mock_data() { 638 SocketDataProviderArray<SocketDataProvider>& mock_data() {
645 return mock_data_; 639 return mock_data_;
646 } 640 }
647 641
648 // Note: this method is unsafe; the elements of the returned vector
649 // are not necessarily valid.
650 const std::vector<MockSSLClientSocket*>& ssl_client_sockets() const {
651 return ssl_client_sockets_;
652 }
653
654 // ClientSocketFactory 642 // ClientSocketFactory
655 scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( 643 scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket(
656 DatagramSocket::BindType bind_type, 644 DatagramSocket::BindType bind_type,
657 const RandIntCallback& rand_int_cb, 645 const RandIntCallback& rand_int_cb,
658 NetLog* net_log, 646 NetLog* net_log,
659 const NetLog::Source& source) override; 647 const NetLog::Source& source) override;
660 scoped_ptr<StreamSocket> CreateTransportClientSocket( 648 scoped_ptr<StreamSocket> CreateTransportClientSocket(
661 const AddressList& addresses, 649 const AddressList& addresses,
662 NetLog* net_log, 650 NetLog* net_log,
663 const NetLog::Source& source) override; 651 const NetLog::Source& source) override;
664 scoped_ptr<SSLClientSocket> CreateSSLClientSocket( 652 scoped_ptr<SSLClientSocket> CreateSSLClientSocket(
665 scoped_ptr<ClientSocketHandle> transport_socket, 653 scoped_ptr<ClientSocketHandle> transport_socket,
666 const HostPortPair& host_and_port, 654 const HostPortPair& host_and_port,
667 const SSLConfig& ssl_config, 655 const SSLConfig& ssl_config,
668 const SSLClientSocketContext& context) override; 656 const SSLClientSocketContext& context) override;
669 void ClearSSLSessionCache() override; 657 void ClearSSLSessionCache() override;
670 658
671 private: 659 private:
672 SocketDataProviderArray<SocketDataProvider> mock_data_; 660 SocketDataProviderArray<SocketDataProvider> mock_data_;
673 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_; 661 SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
674 std::vector<MockSSLClientSocket*> ssl_client_sockets_;
675 }; 662 };
676 663
677 class MockClientSocket : public SSLClientSocket { 664 class MockClientSocket : public SSLClientSocket {
678 public: 665 public:
679 // Value returned by GetTLSUniqueChannelBinding(). 666 // Value returned by GetTLSUniqueChannelBinding().
680 static const char kTlsUnique[]; 667 static const char kTlsUnique[];
681 668
682 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as 669 // The BoundNetLog is needed to test LoadTimingInfo, which uses NetLog IDs as
683 // unique socket IDs. 670 // unique socket IDs.
684 explicit MockClientSocket(const BoundNetLog& net_log); 671 explicit MockClientSocket(const BoundNetLog& net_log);
(...skipping 13 matching lines...) Expand all
698 void Disconnect() override; 685 void Disconnect() override;
699 bool IsConnected() const override; 686 bool IsConnected() const override;
700 bool IsConnectedAndIdle() const override; 687 bool IsConnectedAndIdle() const override;
701 int GetPeerAddress(IPEndPoint* address) const override; 688 int GetPeerAddress(IPEndPoint* address) const override;
702 int GetLocalAddress(IPEndPoint* address) const override; 689 int GetLocalAddress(IPEndPoint* address) const override;
703 const BoundNetLog& NetLog() const override; 690 const BoundNetLog& NetLog() const override;
704 void SetSubresourceSpeculation() override {} 691 void SetSubresourceSpeculation() override {}
705 void SetOmniboxSpeculation() override {} 692 void SetOmniboxSpeculation() override {}
706 693
707 // SSLClientSocket implementation. 694 // SSLClientSocket implementation.
708 std::string GetSessionCacheKey() const override;
709 bool InSessionCache() const override;
710 void SetHandshakeCompletionCallback(const base::Closure& cb) override;
711 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override; 695 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override;
712 int ExportKeyingMaterial(const base::StringPiece& label, 696 int ExportKeyingMaterial(const base::StringPiece& label,
713 bool has_context, 697 bool has_context,
714 const base::StringPiece& context, 698 const base::StringPiece& context,
715 unsigned char* out, 699 unsigned char* out,
716 unsigned int outlen) override; 700 unsigned int outlen) override;
717 int GetTLSUniqueChannelBinding(std::string* out) override; 701 int GetTLSUniqueChannelBinding(std::string* out) override;
718 NextProtoStatus GetNextProto(std::string* proto) override; 702 NextProtoStatus GetNextProto(std::string* proto) override;
719 ChannelIDService* GetChannelIDService() const override; 703 ChannelIDService* GetChannelIDService() const override;
720 704
721 protected: 705 protected:
722 ~MockClientSocket() override; 706 ~MockClientSocket() override;
723 void RunCallbackAsync(const CompletionCallback& callback, int result); 707 void RunCallbackAsync(const CompletionCallback& callback, int result);
724 void RunCallback(const CompletionCallback& callback, int result); 708 void RunCallback(const CompletionCallback& callback, int result);
725 709
726 // SSLClientSocket implementation. 710 // SSLClientSocket implementation.
727 scoped_refptr<X509Certificate> GetUnverifiedServerCertificateChain() 711 scoped_refptr<X509Certificate> GetUnverifiedServerCertificateChain()
728 const override; 712 const override;
729 713
730 // True if Connect completed successfully and Disconnect hasn't been called. 714 // True if Connect completed successfully and Disconnect hasn't been called.
731 bool connected_; 715 bool connected_;
732 716
733 // Address of the "remote" peer we're connected to. 717 // Address of the "remote" peer we're connected to.
734 IPEndPoint peer_addr_; 718 IPEndPoint peer_addr_;
735 719
736 BoundNetLog net_log_; 720 BoundNetLog net_log_;
737 721
738 private:
davidben 2015/03/09 18:02:36 Probably want to keep that line.
739 base::WeakPtrFactory<MockClientSocket> weak_factory_; 722 base::WeakPtrFactory<MockClientSocket> weak_factory_;
740 723
741 DISALLOW_COPY_AND_ASSIGN(MockClientSocket); 724 DISALLOW_COPY_AND_ASSIGN(MockClientSocket);
742 }; 725 };
743 726
744 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket { 727 class MockTCPClientSocket : public MockClientSocket, public AsyncSocket {
745 public: 728 public:
746 MockTCPClientSocket(const AddressList& addresses, 729 MockTCPClientSocket(const AddressList& addresses,
747 net::NetLog* net_log, 730 net::NetLog* net_log,
748 SocketDataProvider* socket); 731 SocketDataProvider* socket);
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 int Connect(const CompletionCallback& callback) override; 942 int Connect(const CompletionCallback& callback) override;
960 void Disconnect() override; 943 void Disconnect() override;
961 bool IsConnected() const override; 944 bool IsConnected() const override;
962 bool WasEverUsed() const override; 945 bool WasEverUsed() const override;
963 bool UsingTCPFastOpen() const override; 946 bool UsingTCPFastOpen() const override;
964 int GetPeerAddress(IPEndPoint* address) const override; 947 int GetPeerAddress(IPEndPoint* address) const override;
965 bool WasNpnNegotiated() const override; 948 bool WasNpnNegotiated() const override;
966 bool GetSSLInfo(SSLInfo* ssl_info) override; 949 bool GetSSLInfo(SSLInfo* ssl_info) override;
967 950
968 // SSLClientSocket implementation. 951 // SSLClientSocket implementation.
969 std::string GetSessionCacheKey() const override;
970 bool InSessionCache() const override;
971 void SetHandshakeCompletionCallback(const base::Closure& cb) override;
972 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override; 952 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override;
973 NextProtoStatus GetNextProto(std::string* proto) override; 953 NextProtoStatus GetNextProto(std::string* proto) override;
974 bool set_was_npn_negotiated(bool negotiated) override; 954 bool set_was_npn_negotiated(bool negotiated) override;
975 void set_protocol_negotiated(NextProto protocol_negotiated) override; 955 void set_protocol_negotiated(NextProto protocol_negotiated) override;
976 NextProto GetNegotiatedProtocol() const override; 956 NextProto GetNegotiatedProtocol() const override;
977 957
978 // This MockSocket does not implement the manual async IO feature. 958 // This MockSocket does not implement the manual async IO feature.
979 void OnReadComplete(const MockRead& data) override; 959 void OnReadComplete(const MockRead& data) override;
980 void OnConnectComplete(const MockConnect& data) override; 960 void OnConnectComplete(const MockConnect& data) override;
981 961
982 bool WasChannelIDSent() const override; 962 bool WasChannelIDSent() const override;
983 void set_channel_id_sent(bool channel_id_sent) override; 963 void set_channel_id_sent(bool channel_id_sent) override;
984 ChannelIDService* GetChannelIDService() const override; 964 ChannelIDService* GetChannelIDService() const override;
985 965
986 bool reached_connect() const { return reached_connect_; }
987
988 // Resumes the connection of a socket that was paused for testing.
989 // |connect_callback_| should be set before invoking this method.
990 void RestartPausedConnect();
991
992 private: 966 private:
993 enum ConnectState { 967 static void ConnectCallback(MockSSLClientSocket* ssl_client_socket,
994 STATE_NONE, 968 const CompletionCallback& callback,
995 STATE_SSL_CONNECT, 969 int rv);
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 DoSSLConnect();
1005 int DoSSLConnectComplete(int result);
1006 970
1007 scoped_ptr<ClientSocketHandle> transport_; 971 scoped_ptr<ClientSocketHandle> transport_;
1008 HostPortPair host_port_pair_;
1009 SSLSocketDataProvider* data_; 972 SSLSocketDataProvider* data_;
1010 bool is_npn_state_set_; 973 bool is_npn_state_set_;
1011 bool new_npn_value_; 974 bool new_npn_value_;
1012 bool is_protocol_negotiated_set_; 975 bool is_protocol_negotiated_set_;
1013 NextProto protocol_negotiated_; 976 NextProto protocol_negotiated_;
1014 977
1015 CompletionCallback connect_callback_;
1016 // Indicates what state of Connect the socket should enter.
1017 ConnectState next_connect_state_;
1018 // True if the Connect method has been called on the socket.
1019 bool reached_connect_;
1020
1021 base::Closure handshake_completion_callback_;
1022
1023 base::WeakPtrFactory<MockSSLClientSocket> weak_factory_;
1024
1025 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket); 978 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket);
1026 }; 979 };
1027 980
1028 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket { 981 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket {
1029 public: 982 public:
1030 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); 983 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log);
1031 ~MockUDPClientSocket() override; 984 ~MockUDPClientSocket() override;
1032 985
1033 // Socket implementation. 986 // Socket implementation.
1034 int Read(IOBuffer* buf, 987 int Read(IOBuffer* buf,
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 1294
1342 extern const char kSOCKS5OkRequest[]; 1295 extern const char kSOCKS5OkRequest[];
1343 extern const int kSOCKS5OkRequestLength; 1296 extern const int kSOCKS5OkRequestLength;
1344 1297
1345 extern const char kSOCKS5OkResponse[]; 1298 extern const char kSOCKS5OkResponse[];
1346 extern const int kSOCKS5OkResponseLength; 1299 extern const int kSOCKS5OkResponseLength;
1347 1300
1348 } // namespace net 1301 } // namespace net
1349 1302
1350 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ 1303 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698