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

Unified Diff: net/socket/socket_test_util.h

Issue 2593063003: Add Socket::ReadIfReady() (Closed)
Patch Set: Fix tests for real Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: net/socket/socket_test_util.h
diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h
index fec7819d0e95661ad6a8e223b9d10862aeba73a7..cdcbeb77a7b7e6fbd0784ec34676218028a2cc6d 100644
--- a/net/socket/socket_test_util.h
+++ b/net/socket/socket_test_util.h
@@ -518,6 +518,11 @@ class MockClientSocketFactory : public ClientSocketFactory {
return mock_data_;
}
+ // If |enable_read_if_ready|, ReadIfReady() will be implemented.
+ void set_enable_read_if_ready(bool enable_read_if_ready) {
+ enable_read_if_ready_ = enable_read_if_ready;
+ }
+
// ClientSocketFactory
std::unique_ptr<DatagramClientSocket> CreateDatagramClientSocket(
DatagramSocket::BindType bind_type,
@@ -545,6 +550,7 @@ class MockClientSocketFactory : public ClientSocketFactory {
SocketDataProviderArray<SSLSocketDataProvider> mock_ssl_data_;
std::vector<uint16_t> udp_client_socket_ports_;
+ bool enable_read_if_ready_;
DISALLOW_COPY_AND_ASSIGN(MockClientSocketFactory);
};
@@ -627,6 +633,9 @@ class MockTCPClientSocket : public MockClientSocket, public AsyncSocket {
int Read(IOBuffer* buf,
int buf_len,
const CompletionCallback& callback) override;
+ int ReadIfReady(IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback) override;
int Write(IOBuffer* buf,
int buf_len,
const CompletionCallback& callback) override;
@@ -650,8 +659,26 @@ class MockTCPClientSocket : public MockClientSocket, public AsyncSocket {
void OnConnectComplete(const MockConnect& data) override;
void OnDataProviderDestroyed() override;
+ // If |enable_read_if_ready|, ReadIfReady() will be implemented.
+ void set_enable_read_if_ready(bool enable_read_if_ready) {
+ enable_read_if_ready_ = enable_read_if_ready;
+ }
+
private:
- int CompleteRead();
+ enum PendingReadType {
+ NONE,
+ READ,
+ READ_IF_READY,
+ };
+ // Helper method shared between Read() and ReadIfReady().
+ int ReadCommon(IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback,
+ bool use_read_if_ready);
+
+ int CompleteRead(bool read_if_ready_used);
+ void RunReadCallback(const CompletionCallback& callback, int result);
+ void RunReadCallbackAsync(const CompletionCallback& callback, int result);
AddressList addresses_;
@@ -672,9 +699,13 @@ class MockTCPClientSocket : public MockClientSocket, public AsyncSocket {
CompletionCallback pending_read_callback_;
CompletionCallback pending_write_callback_;
bool was_used_to_convey_data_;
+ bool enable_read_if_ready_;
+ PendingReadType pending_read_type_;
ConnectionAttempts connection_attempts_;
+ base::WeakPtrFactory<MockTCPClientSocket> weak_factory_;
+
DISALLOW_COPY_AND_ASSIGN(MockTCPClientSocket);
};
@@ -690,6 +721,9 @@ class MockSSLClientSocket : public MockClientSocket, public AsyncSocket {
int Read(IOBuffer* buf,
int buf_len,
const CompletionCallback& callback) override;
+ int ReadIfReady(IOBuffer* buf,
+ int buf_len,
+ const CompletionCallback& callback) override;
int Write(IOBuffer* buf,
int buf_len,
const CompletionCallback& callback) override;

Powered by Google App Engine
This is Rietveld 408576698