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 981723008: Unwind the SSL connection holdback experiment and remove related code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename & reformat 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
« no previous file with comments | « net/socket/client_socket_pool_manager_impl.cc ('k') | net/socket/socket_test_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
959 int Connect(const CompletionCallback& callback) override; 943 int Connect(const CompletionCallback& callback) override;
960 void Disconnect() override; 944 void Disconnect() override;
961 bool IsConnected() const override; 945 bool IsConnected() const override;
962 bool WasEverUsed() const override; 946 bool WasEverUsed() const override;
963 bool UsingTCPFastOpen() const override; 947 bool UsingTCPFastOpen() const override;
964 int GetPeerAddress(IPEndPoint* address) const override; 948 int GetPeerAddress(IPEndPoint* address) const override;
965 bool WasNpnNegotiated() const override; 949 bool WasNpnNegotiated() const override;
966 bool GetSSLInfo(SSLInfo* ssl_info) override; 950 bool GetSSLInfo(SSLInfo* ssl_info) override;
967 951
968 // SSLClientSocket implementation. 952 // 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; 953 void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override;
973 NextProtoStatus GetNextProto(std::string* proto) override; 954 NextProtoStatus GetNextProto(std::string* proto) override;
974 bool set_was_npn_negotiated(bool negotiated) override; 955 bool set_was_npn_negotiated(bool negotiated) override;
975 void set_protocol_negotiated(NextProto protocol_negotiated) override; 956 void set_protocol_negotiated(NextProto protocol_negotiated) override;
976 NextProto GetNegotiatedProtocol() const override; 957 NextProto GetNegotiatedProtocol() const override;
977 958
978 // This MockSocket does not implement the manual async IO feature. 959 // This MockSocket does not implement the manual async IO feature.
979 void OnReadComplete(const MockRead& data) override; 960 void OnReadComplete(const MockRead& data) override;
980 void OnConnectComplete(const MockConnect& data) override; 961 void OnConnectComplete(const MockConnect& data) override;
981 962
982 bool WasChannelIDSent() const override; 963 bool WasChannelIDSent() const override;
983 void set_channel_id_sent(bool channel_id_sent) override; 964 void set_channel_id_sent(bool channel_id_sent) override;
984 ChannelIDService* GetChannelIDService() const override; 965 ChannelIDService* GetChannelIDService() const override;
985 966
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: 967 private:
993 enum ConnectState { 968 static void ConnectCallback(MockSSLClientSocket* ssl_client_socket,
994 STATE_NONE, 969 const CompletionCallback& callback,
995 STATE_SSL_CONNECT, 970 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 971
1007 scoped_ptr<ClientSocketHandle> transport_; 972 scoped_ptr<ClientSocketHandle> transport_;
1008 HostPortPair host_port_pair_;
1009 SSLSocketDataProvider* data_; 973 SSLSocketDataProvider* data_;
1010 bool is_npn_state_set_; 974 bool is_npn_state_set_;
1011 bool new_npn_value_; 975 bool new_npn_value_;
1012 bool is_protocol_negotiated_set_; 976 bool is_protocol_negotiated_set_;
1013 NextProto protocol_negotiated_; 977 NextProto protocol_negotiated_;
1014 978
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); 979 DISALLOW_COPY_AND_ASSIGN(MockSSLClientSocket);
1026 }; 980 };
1027 981
1028 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket { 982 class MockUDPClientSocket : public DatagramClientSocket, public AsyncSocket {
1029 public: 983 public:
1030 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log); 984 MockUDPClientSocket(SocketDataProvider* data, net::NetLog* net_log);
1031 ~MockUDPClientSocket() override; 985 ~MockUDPClientSocket() override;
1032 986
1033 // Socket implementation. 987 // Socket implementation.
1034 int Read(IOBuffer* buf, 988 int Read(IOBuffer* buf,
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 1295
1342 extern const char kSOCKS5OkRequest[]; 1296 extern const char kSOCKS5OkRequest[];
1343 extern const int kSOCKS5OkRequestLength; 1297 extern const int kSOCKS5OkRequestLength;
1344 1298
1345 extern const char kSOCKS5OkResponse[]; 1299 extern const char kSOCKS5OkResponse[];
1346 extern const int kSOCKS5OkResponseLength; 1300 extern const int kSOCKS5OkResponseLength;
1347 1301
1348 } // namespace net 1302 } // namespace net
1349 1303
1350 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_ 1304 #endif // NET_SOCKET_SOCKET_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « net/socket/client_socket_pool_manager_impl.cc ('k') | net/socket/socket_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698