Chromium Code Reviews| Index: net/socket/socket_test_util.cc |
| diff --git a/net/socket/socket_test_util.cc b/net/socket/socket_test_util.cc |
| index f993801adeb2814aede788bcf82c693bfa99696f..9acfa23f4a105f010787f6fe18dc9b81f3ded0e1 100644 |
| --- a/net/socket/socket_test_util.cc |
| +++ b/net/socket/socket_test_util.cc |
| @@ -10,6 +10,7 @@ |
| #include "base/basictypes.h" |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| +#include "base/callback_helpers.h" |
| #include "base/compiler_specific.h" |
| #include "base/message_loop/message_loop.h" |
| #include "base/run_loop.h" |
| @@ -277,7 +278,10 @@ SSLSocketDataProvider::SSLSocketDataProvider(IoMode mode, int result) |
| client_cert_sent(false), |
| cert_request_info(NULL), |
| channel_id_sent(false), |
| - connection_status(0) { |
| + connection_status(0), |
| + block_in_connect_(false), |
| + blocked_in_connect_(false), |
| + is_in_session_cache_(true) { |
|
wtc
2014/07/18 01:17:14
Why is |is_in_session_cache_| initialized to true?
mshelley
2014/07/18 21:08:30
Done.
|
| SSLConnectionStatusSetVersion(SSL_CONNECTION_VERSION_TLS1_2, |
| &connection_status); |
| // Set to TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 |
| @@ -699,15 +703,23 @@ scoped_ptr<SSLClientSocket> MockClientSocketFactory::CreateSSLClientSocket( |
| const HostPortPair& host_and_port, |
| const SSLConfig& ssl_config, |
| const SSLClientSocketContext& context) { |
| - return scoped_ptr<SSLClientSocket>( |
| + scoped_ptr<MockSSLClientSocket> socket( |
| new MockSSLClientSocket(transport_socket.Pass(), |
| - host_and_port, ssl_config, |
| + host_and_port, |
| + ssl_config, |
| mock_ssl_data_.GetNext())); |
| + ssl_client_sockets_.push_back(socket.get()); |
| + return socket.PassAs<SSLClientSocket>(); |
| } |
| void MockClientSocketFactory::ClearSSLSessionCache() { |
| } |
| +std::vector<MockSSLClientSocket*> |
| +MockClientSocketFactory::GetSSLClientSockets() { |
| + return ssl_client_sockets_; |
| +} |
| + |
| const char MockClientSocket::kTlsUnique[] = "MOCK_TLSUNIQ"; |
| MockClientSocket::MockClientSocket(const BoundNetLog& net_log) |
| @@ -735,6 +747,10 @@ bool MockClientSocket::IsConnected() const { |
| return connected_; |
| } |
| +bool MockClientSocket::IsConnectedSSL() const { |
| + return connected_; |
| +} |
| + |
| bool MockClientSocket::IsConnectedAndIdle() const { |
| return connected_; |
| } |
| @@ -758,6 +774,16 @@ const BoundNetLog& MockClientSocket::NetLog() const { |
| return net_log_; |
| } |
| +bool MockClientSocket::InSessionCache() const { |
| + return true; |
| +} |
| + |
| +void MockClientSocket::SetHandshakeSuccessCallback(const base::Closure& cb) { |
| +} |
| + |
| +void MockClientSocket::SetHandshakeFailureCallback(const base::Closure& cb) { |
| +} |
|
wtc
2014/07/18 15:39:16
You may want to assert NOTREACHED or NOTIMPLEMENTE
mshelley
2014/07/18 21:08:30
Done.
|
| + |
| void MockClientSocket::GetSSLCertRequestInfo( |
| SSLCertRequestInfo* cert_request_info) { |
| } |
| @@ -781,6 +807,10 @@ ServerBoundCertService* MockClientSocket::GetServerBoundCertService() const { |
| return NULL; |
| } |
| +CompletionCallback MockClientSocket::GetResumptionCallback() { |
| + return resumption_callback_; |
| +} |
| + |
| SSLClientSocket::NextProtoStatus |
| MockClientSocket::GetNextProto(std::string* proto, std::string* server_protos) { |
| proto->clear(); |
| @@ -1314,9 +1344,9 @@ MockSSLClientSocket::MockSSLClientSocket( |
| const SSLConfig& ssl_config, |
| SSLSocketDataProvider* data) |
| : MockClientSocket( |
| - // Have to use the right BoundNetLog for LoadTimingInfo regression |
| - // tests. |
| - transport_socket->socket()->NetLog()), |
| + // Have to use the right BoundNetLog for LoadTimingInfo regression |
| + // tests. |
| + transport_socket->socket()->NetLog()), |
| transport_(transport_socket.Pass()), |
| data_(data), |
| is_npn_state_set_(false), |
| @@ -1342,20 +1372,50 @@ int MockSSLClientSocket::Write(IOBuffer* buf, int buf_len, |
| } |
| int MockSSLClientSocket::Connect(const CompletionCallback& callback) { |
| - int rv = transport_->socket()->Connect( |
| - base::Bind(&ConnectCallback, base::Unretained(this), callback)); |
| + int rv; |
| + if (!data_->blocked_in_connect_) |
| + rv = transport_->socket()->Connect( |
| + base::Bind(&ConnectCallback, base::Unretained(this), callback)); |
| + else |
| + rv = OK; |
|
wtc
2014/07/18 01:17:14
Add curly braces to both the "if" and "else" branc
mshelley
2014/07/18 21:08:31
Done.
|
| + |
| if (rv == OK) { |
| - if (data_->connect.result == OK) |
| + if (data_->connect.result == OK) { |
| connected_ = true; |
| - if (data_->connect.mode == ASYNC) { |
| - RunCallbackAsync(callback, data_->connect.result); |
| - return ERR_IO_PENDING; |
| + if (data_->connect.mode == ASYNC) { |
|
wtc
2014/07/18 15:39:16
IMPORTANT: in the original code, the "if (data_->c
mshelley
2014/07/18 21:08:30
That was not intended -- I fixed it.
|
| + if (data_->block_in_connect_) { |
| + resumption_callback_ = callback; |
| + data_->block_in_connect_ = false; |
| + data_->blocked_in_connect_ = true; |
| + return ERR_IO_PENDING; |
| + } else { |
|
wtc
2014/07/18 01:17:14
We usually omit "else" after a return statement. T
mshelley
2014/07/18 21:08:30
Done.
|
| + if (!success_callback_.is_null()) { |
| + success_callback_.Run(); |
| + } |
|
wtc
2014/07/18 01:17:14
Omit curly braces.
The local convention in our ne
mshelley
2014/07/18 21:08:30
Done.
|
| + RunCallbackAsync(callback, data_->connect.result); |
| + } |
| + return ERR_IO_PENDING; |
| + } |
| + |
| + // The presence of |success_callback_| indicates that SSL Connect Job |
| + // Waiting is enabled. |
| + if (!success_callback_.is_null()) { |
| + success_callback_.Run(); |
| + } |
| + } else if (!error_callback_.is_null()) { |
| + if (data_->block_in_connect_) { |
| + resumption_callback_ = callback; |
| + data_->block_in_connect_ = false; |
| + data_->blocked_in_connect_ = true; |
| + return ERR_IO_PENDING; |
| + } |
| + error_callback_.Run(); |
|
wtc
2014/07/18 15:39:16
BUG: we need to reset a callback when we run it. W
mshelley
2014/07/18 21:08:30
Done.
|
| } |
| + |
| return data_->connect.result; |
| } |
| return rv; |
| } |
| - |
| void MockSSLClientSocket::Disconnect() { |
|
wtc
2014/07/18 15:39:16
Resurrect the blank line before this.
mshelley
2014/07/18 21:08:30
Done.
|
| MockClientSocket::Disconnect(); |
| if (transport_->socket() != NULL) |
| @@ -1366,6 +1426,10 @@ bool MockSSLClientSocket::IsConnected() const { |
| return transport_->socket()->IsConnected(); |
| } |
| +bool MockSSLClientSocket::IsConnectedSSL() const { |
| + return connected_; |
|
wtc
2014/07/18 01:17:14
IMPORTANT: it seems better to just use the existin
mshelley
2014/07/18 21:08:31
That makes sense to me. It seemed strange that SSL
|
| +} |
| + |
| bool MockSSLClientSocket::WasEverUsed() const { |
| return transport_->socket()->WasEverUsed(); |
| } |
| @@ -1399,6 +1463,18 @@ void MockSSLClientSocket::GetSSLCertRequestInfo( |
| } |
| } |
| +bool MockSSLClientSocket::InSessionCache() const { |
| + return data_->is_in_session_cache_; |
| +} |
| + |
| +void MockSSLClientSocket::SetHandshakeSuccessCallback(const base::Closure& cb) { |
| + success_callback_ = cb; |
| +} |
| + |
| +void MockSSLClientSocket::SetHandshakeFailureCallback(const base::Closure& cb) { |
| + error_callback_ = cb; |
| +} |
| + |
| SSLClientSocket::NextProtoStatus MockSSLClientSocket::GetNextProto( |
| std::string* proto, std::string* server_protos) { |
| *proto = data_->next_proto; |