summaryrefslogtreecommitdiffstats
path: root/net/socket/socket_test_util.h
diff options
context:
space:
mode:
authorarindam@chromium.org <arindam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-27 17:38:10 +0000
committerarindam@chromium.org <arindam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-27 17:38:10 +0000
commitf54c0e28afa284407d9b4066a1f1a8a98da8c409 (patch)
tree36267461d5022fdffea5253abd5d0b5b46f45ae1 /net/socket/socket_test_util.h
parenta2f6bc11cff781a747c96ab68c4289ae43632deb (diff)
downloadchromium_src-f54c0e28afa284407d9b4066a1f1a8a98da8c409.zip
chromium_src-f54c0e28afa284407d9b4066a1f1a8a98da8c409.tar.gz
chromium_src-f54c0e28afa284407d9b4066a1f1a8a98da8c409.tar.bz2
Tests for socks4/4a implementation.
Refactoring of void BuildHandshakeWriteBuffer() to const std::string BuildHandshakeWriteBuffer() const, and removing private members handshake_buf_len_ and buffer_len_ (since buffer_ is now std::string, buffer_.size()) is more than sufficient. TEST=unittests BUG=469 Review URL: http://codereview.chromium.org/139009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19466 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket/socket_test_util.h')
-rw-r--r--net/socket/socket_test_util.h85
1 files changed, 85 insertions, 0 deletions
diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h
index bd7c437..f710820 100644
--- a/net/socket/socket_test_util.h
+++ b/net/socket/socket_test_util.h
@@ -10,10 +10,13 @@
#include "base/basictypes.h"
#include "base/logging.h"
+#include "base/scoped_ptr.h"
#include "net/base/address_list.h"
+#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/base/ssl_config_service.h"
#include "net/socket/client_socket_factory.h"
+#include "net/socket/ssl_client_socket.h"
namespace net {
@@ -200,6 +203,88 @@ class MockClientSocketFactory : public ClientSocketFactory {
MockSocketArray<MockSSLSocket> mock_ssl_sockets_;
};
+class MockClientSocket : public net::SSLClientSocket {
+ public:
+ MockClientSocket();
+
+ // ClientSocket methods:
+ virtual int Connect(net::CompletionCallback* callback) = 0;
+
+ // SSLClientSocket methods:
+ virtual void GetSSLInfo(net::SSLInfo* ssl_info);
+ virtual void GetSSLCertRequestInfo(
+ net::SSLCertRequestInfo* cert_request_info);
+ virtual void Disconnect();
+ virtual bool IsConnected() const;
+ virtual bool IsConnectedAndIdle() const;
+
+ // Socket methods:
+ virtual int Read(net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback) = 0;
+ virtual int Write(net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback) = 0;
+
+#if defined(OS_LINUX)
+ virtual int GetPeerName(struct sockaddr *name, socklen_t *namelen);
+#endif
+
+ protected:
+ void RunCallbackAsync(net::CompletionCallback* callback, int result);
+ void RunCallback(int result);
+
+ ScopedRunnableMethodFactory<MockClientSocket> method_factory_;
+ net::CompletionCallback* callback_;
+ bool connected_;
+};
+
+class MockTCPClientSocket : public MockClientSocket {
+ public:
+ MockTCPClientSocket(const net::AddressList& addresses,
+ net::MockSocket* socket);
+
+ // ClientSocket methods:
+ virtual int Connect(net::CompletionCallback* callback);
+
+ // Socket methods:
+ virtual int Read(net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback);
+ virtual int Write(net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback);
+
+ private:
+ net::MockSocket* data_;
+ int read_offset_;
+ net::MockRead read_data_;
+ bool need_read_data_;
+};
+
+class MockSSLClientSocket : public MockClientSocket {
+ public:
+ MockSSLClientSocket(
+ net::ClientSocket* transport_socket,
+ const std::string& hostname,
+ const net::SSLConfig& ssl_config,
+ net::MockSSLSocket* socket);
+ ~MockSSLClientSocket();
+
+ virtual void GetSSLInfo(net::SSLInfo* ssl_info);
+
+ virtual int Connect(net::CompletionCallback* callback);
+ virtual void Disconnect();
+
+ // Socket methods:
+ virtual int Read(net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback);
+ virtual int Write(net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback);
+
+ private:
+ class ConnectCallback;
+
+ scoped_ptr<ClientSocket> transport_;
+ net::MockSSLSocket* data_;
+};
+
} // namespace net
#endif // NET_SOCKET_SOCKET_TEST_UTIL_H_