| Index: net/socket/socket_test_util.h
|
| diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h
|
| index 3d1186797581c3e35698ce9d17a07bc9acf1ae0f..a5840eb4009652bf4eb9636a3b09abba56373e5d 100644
|
| --- a/net/socket/socket_test_util.h
|
| +++ b/net/socket/socket_test_util.h
|
| @@ -15,6 +15,7 @@
|
| #include <vector>
|
|
|
| #include "base/callback.h"
|
| +#include "base/callback_helpers.h"
|
| #include "base/logging.h"
|
| #include "base/macros.h"
|
| #include "base/memory/ptr_util.h"
|
| @@ -25,6 +26,8 @@
|
| #include "base/time/time.h"
|
| #include "net/base/address_list.h"
|
| #include "net/base/io_buffer.h"
|
| +#include "net/base/ip_address.h"
|
| +#include "net/base/ip_endpoint.h"
|
| #include "net/base/net_errors.h"
|
| #include "net/base/test_completion_callback.h"
|
| #include "net/http/http_auth_controller.h"
|
| @@ -37,6 +40,7 @@
|
| #include "net/socket/socks_client_socket_pool.h"
|
| #include "net/socket/ssl_client_socket.h"
|
| #include "net/socket/ssl_client_socket_pool.h"
|
| +#include "net/socket/stream_socket.h"
|
| #include "net/socket/transport_client_socket_pool.h"
|
| #include "net/ssl/ssl_config_service.h"
|
| #include "net/udp/datagram_client_socket.h"
|
| @@ -64,7 +68,6 @@ class AsyncSocket;
|
| class ChannelIDService;
|
| class MockClientSocket;
|
| class SSLClientSocket;
|
| -class StreamSocket;
|
|
|
| enum IoMode {
|
| ASYNC,
|
| @@ -493,6 +496,108 @@ class SocketDataProviderArray {
|
| std::vector<T*> data_providers_;
|
| };
|
|
|
| +class FakeDataChannel {
|
| + public:
|
| + FakeDataChannel();
|
| + ~FakeDataChannel();
|
| +
|
| + int Read(IOBuffer* buf, int buf_len, const CompletionCallback& callback);
|
| + int Write(IOBuffer* buf, int buf_len, const CompletionCallback& callback);
|
| +
|
| + // Closes the FakeDataChannel. After Close() is called, Read() returns 0,
|
| + // indicating EOF, and Write() fails with ERR_CONNECTION_RESET. Note that
|
| + // after the FakeDataChannel is closed, the first Write() call completes
|
| + // asynchronously, which is necessary to reproduce bug 127822.
|
| + void Close();
|
| +
|
| + private:
|
| + void DoReadCallback();
|
| + void DoWriteCallback();
|
| +
|
| + int PropagateData(scoped_refptr<IOBuffer> read_buf, int read_buf_len);
|
| +
|
| + CompletionCallback read_callback_;
|
| + scoped_refptr<IOBuffer> read_buf_;
|
| + int read_buf_len_;
|
| +
|
| + CompletionCallback write_callback_;
|
| +
|
| + std::queue<scoped_refptr<DrainableIOBuffer>> data_;
|
| +
|
| + // True if Close() has been called.
|
| + bool closed_;
|
| +
|
| + // Controls the completion of Write() after the FakeDataChannel is closed.
|
| + // After the FakeDataChannel is closed, the first Write() call completes
|
| + // asynchronously.
|
| + bool write_called_after_close_;
|
| +
|
| + base::WeakPtrFactory<FakeDataChannel> weak_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(FakeDataChannel);
|
| +};
|
| +
|
| +class FakeSocket : public StreamSocket {
|
| + public:
|
| + FakeSocket(FakeDataChannel* incoming_channel,
|
| + FakeDataChannel* outgoing_channel)
|
| + : incoming_(incoming_channel), outgoing_(outgoing_channel) {}
|
| +
|
| + ~FakeSocket() override;
|
| +
|
| + int Read(IOBuffer* buf,
|
| + int buf_len,
|
| + const CompletionCallback& callback) override;
|
| +
|
| + int Write(IOBuffer* buf,
|
| + int buf_len,
|
| + const CompletionCallback& callback) override;
|
| +
|
| + int SetReceiveBufferSize(int32_t size) override;
|
| +
|
| + int SetSendBufferSize(int32_t size) override;
|
| +
|
| + int Connect(const CompletionCallback& callback) override;
|
| +
|
| + void Disconnect() override;
|
| +
|
| + bool IsConnected() const override;
|
| +
|
| + bool IsConnectedAndIdle() const override;
|
| +
|
| + int GetPeerAddress(IPEndPoint* address) const override;
|
| +
|
| + int GetLocalAddress(IPEndPoint* address) const override;
|
| +
|
| + const BoundNetLog& NetLog() const override;
|
| +
|
| + void SetSubresourceSpeculation() override;
|
| + void SetOmniboxSpeculation() override;
|
| +
|
| + bool WasEverUsed() const override;
|
| +
|
| + bool WasNpnNegotiated() const override;
|
| +
|
| + NextProto GetNegotiatedProtocol() const override;
|
| +
|
| + bool GetSSLInfo(SSLInfo* ssl_info) override;
|
| +
|
| + void GetConnectionAttempts(ConnectionAttempts* out) const override;
|
| +
|
| + void ClearConnectionAttempts() override;
|
| +
|
| + void AddConnectionAttempts(const ConnectionAttempts& attempts) override;
|
| +
|
| + int64_t GetTotalReceivedBytes() const override;
|
| +
|
| + private:
|
| + BoundNetLog net_log_;
|
| + FakeDataChannel* incoming_;
|
| + FakeDataChannel* outgoing_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(FakeSocket);
|
| +};
|
| +
|
| class MockUDPClientSocket;
|
| class MockTCPClientSocket;
|
| class MockSSLClientSocket;
|
|
|