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

Unified Diff: net/socket/socket_test_util.cc

Issue 1135553003: Change DeterministicSocketData to no longer inherit from SocketDataProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 7 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
« no previous file with comments | « net/socket/socket_test_util.h ('k') | net/spdy/spdy_network_transaction_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/socket/socket_test_util.cc
diff --git a/net/socket/socket_test_util.cc b/net/socket/socket_test_util.cc
index b92f228ded65ff8b333395109c9b204b7d768d4d..4ef64f91261173de6ae05628b335d5e63fb578c0 100644
--- a/net/socket/socket_test_util.cc
+++ b/net/socket/socket_test_util.cc
@@ -606,8 +606,10 @@ SequencedSocketData::~SequencedSocketData() {
}
DeterministicSocketData::DeterministicSocketData(MockRead* reads,
- size_t reads_count, MockWrite* writes, size_t writes_count)
- : StaticSocketDataProvider(reads, reads_count, writes, writes_count),
+ size_t reads_count,
+ MockWrite* writes,
+ size_t writes_count)
+ : helper_(reads, reads_count, writes, writes_count),
sequence_number_(0),
current_read_(),
current_write_(),
@@ -667,7 +669,7 @@ void DeterministicSocketData::StopAfter(int seq) {
}
MockRead DeterministicSocketData::OnRead() {
- current_read_ = helper()->PeekRead();
+ current_read_ = helper_.PeekRead();
// Synchronous read while stopped is an error
if (stopped() && current_read_.mode == SYNCHRONOUS) {
@@ -691,7 +693,7 @@ MockRead DeterministicSocketData::OnRead() {
}
NET_TRACE(1, " *** ") << "Stage " << sequence_number_ << ": Read "
- << read_index();
+ << helper_.read_index();
if (print_debug_)
DumpMockReadWrite(current_read_);
@@ -700,13 +702,13 @@ MockRead DeterministicSocketData::OnRead() {
NextStep();
DCHECK_NE(ERR_IO_PENDING, current_read_.result);
- StaticSocketDataProvider::OnRead();
+ helper_.AdvanceRead();
return current_read_;
}
MockWriteResult DeterministicSocketData::OnWrite(const std::string& data) {
- const MockWrite& next_write = helper()->PeekWrite();
+ const MockWrite& next_write = helper_.PeekWrite();
current_write_ = next_write;
// Synchronous write while stopped is an error
@@ -725,7 +727,7 @@ MockWriteResult DeterministicSocketData::OnWrite(const std::string& data) {
}
} else {
NET_TRACE(1, " *** ") << "Stage " << sequence_number_ << ": Write "
- << write_index();
+ << helper_.write_index();
}
if (print_debug_)
@@ -736,15 +738,26 @@ MockWriteResult DeterministicSocketData::OnWrite(const std::string& data) {
if (next_write.mode == SYNCHRONOUS)
NextStep();
- // This is either a sync write for this step, or an async write.
- return StaticSocketDataProvider::OnWrite(data);
+ // Check that what we are writing matches the expectation.
+ // Then give the mocked return value.
+ if (!helper_.VerifyWriteData(data))
+ return MockWriteResult(SYNCHRONOUS, ERR_UNEXPECTED);
+
+ helper_.AdvanceWrite();
+
+ // In the case that the write was successful, return the number of bytes
+ // written. Otherwise return the error code.
+ int result =
+ next_write.result == OK ? next_write.data_len : next_write.result;
+ return MockWriteResult(next_write.mode, result);
}
-void DeterministicSocketData::Reset() {
- NET_TRACE(1, " *** ") << "Stage " << sequence_number_ << ": Reset()";
- sequence_number_ = 0;
- StaticSocketDataProvider::Reset();
- NOTREACHED();
+bool DeterministicSocketData::AllReadDataConsumed() const {
+ return helper_.AllReadDataConsumed();
+}
+
+bool DeterministicSocketData::AllWriteDataConsumed() const {
+ return helper_.AllWriteDataConsumed();
}
void DeterministicSocketData::InvokeCallbacks() {
@@ -1391,16 +1404,6 @@ const BoundNetLog& DeterministicMockUDPClientSocket::NetLog() const {
return helper_.net_log();
}
-void DeterministicMockUDPClientSocket::OnReadComplete(const MockRead& data) {}
-
-void DeterministicMockUDPClientSocket::OnWriteComplete(int rv) {
-}
-
-void DeterministicMockUDPClientSocket::OnConnectComplete(
- const MockConnect& data) {
- NOTIMPLEMENTED();
-}
-
DeterministicMockTCPClientSocket::DeterministicMockTCPClientSocket(
net::NetLog* net_log,
DeterministicSocketData* data)
@@ -1488,14 +1491,6 @@ bool DeterministicMockTCPClientSocket::GetSSLInfo(SSLInfo* ssl_info) {
return false;
}
-void DeterministicMockTCPClientSocket::OnReadComplete(const MockRead& data) {}
-
-void DeterministicMockTCPClientSocket::OnWriteComplete(int rv) {
-}
-
-void DeterministicMockTCPClientSocket::OnConnectComplete(
- const MockConnect& data) {}
-
// static
void MockSSLClientSocket::ConnectCallback(
MockSSLClientSocket* ssl_client_socket,
« no previous file with comments | « net/socket/socket_test_util.h ('k') | net/spdy/spdy_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698