Index: google_apis/gcm/base/socket_stream_test_data_provider.h |
diff --git a/google_apis/gcm/base/socket_stream_test_data_provider.h b/google_apis/gcm/base/socket_stream_test_data_provider.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..81b881e1f10a50e2938e4ac1a2a78bfbb03fdae6 |
--- /dev/null |
+++ b/google_apis/gcm/base/socket_stream_test_data_provider.h |
@@ -0,0 +1,53 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef GOOGLE_APIS_GCM_BASE_SOCKET_STREAM_TEST_DATA_PROVIDER_H_ |
+#define GOOGLE_APIS_GCM_BASE_SOCKET_STREAM_TEST_DATA_PROVIDER_H_ |
+ |
+#include <queue> |
+#include <string> |
+ |
+#include "base/basictypes.h" |
+#include "google_apis/gcm/base/socket_stream.h" |
+#include "net/socket/socket_test_util.h" |
+ |
+namespace gcm { |
+ |
+class SocketStreamTestDataProvider : public net::SocketDataProvider { |
Ryan Sleevi
2013/09/03 23:04:08
I'm not clear the motivation why you needed to do
Nicolas Zea
2013/09/04 00:43:33
Ah, I missed most of those implementations. I'll t
Nicolas Zea
2013/09/07 01:07:52
Switched to Delayed SDP.
|
+ public: |
+ SocketStreamTestDataProvider(); |
+ virtual ~SocketStreamTestDataProvider(); |
+ |
+ // net::SocketDataProvider implementation. |
+ // If there's no read, sets the "has pending read" flag. Otherwise, |
+ // pops the next read. |
+ virtual net::MockRead GetNextRead() OVERRIDE; |
+ // Simply pops the next write and, if applicable, compares it to |
+ // |data|. |
+ virtual net::MockWriteResult OnWrite(const std::string& data) OVERRIDE; |
+ // We ignore resets so we can pre-load the socket data provider with |
+ // read/write events. |
+ virtual void Reset() OVERRIDE; |
+ |
+ // If there is a pending read, completes it with the given read. |
+ // Otherwise, queues up the given read. |
+ void AddRead(const net::MockRead& mock_read); |
+ |
+ // If there is a pending write, completes it with the given write. |
+ // Otherwise, queues up the given write. |
+ void AddWrite(const net::MockWrite& mock_write); |
+ |
+ private: |
+ std::deque<net::MockRead> reads_; |
+ bool has_pending_read_; |
+ |
+ std::deque<net::MockWrite> writes_; |
+ bool has_pending_write_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SocketStreamTestDataProvider); |
+}; |
+ |
+} // namespace gcm |
+ |
+#endif // GOOGLE_APIS_GCM_BASE_SOCKET_STREAM_TEST_DATA_PROVIDER_H_ |