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

Unified Diff: net/filter/mock_source_stream.h

Issue 2251853002: Add net::SourceStream and net::FilterSourceStream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self review Created 4 years, 4 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/filter/mock_source_stream.h
diff --git a/net/filter/mock_source_stream.h b/net/filter/mock_source_stream.h
new file mode 100644
index 0000000000000000000000000000000000000000..7afdd3922a9dc145f4aaaa31b978715d858f9365
--- /dev/null
+++ b/net/filter/mock_source_stream.h
@@ -0,0 +1,69 @@
+// Copyright 2016 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 NET_FILTER_MOCK_SOURCE_STREAM_H_
+#define NET_FILTER_MOCK_SOURCE_STREAM_H_
+
+#include <queue>
+#include <string>
+
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "net/base/completion_callback.h"
+#include "net/base/io_buffer.h"
+#include "net/base/net_errors.h"
+#include "net/filter/source_stream.h"
+
+namespace net {
+
+class IOBuffer;
Randy Smith (Not in Mondays) 2016/08/22 22:37:17 Why both this and the include file?
xunjieli 2016/08/29 16:25:29 Done.
+
+// A SourceStream implementation used in tests. This allows tests to specify
+// what data to return for each Read() call.
+class MockSourceStream : public SourceStream {
+ public:
+ enum Mode {
+ SYNC,
+ ASYNC,
+ };
+ MockSourceStream();
+ ~MockSourceStream() override;
+
+ // SourceStream implementation
+ int Read(IOBuffer* dest_buffer,
+ int buffer_size,
+ const CompletionCallback& callback) override;
+ std::string OrderedTypeStringList() const override;
+
+ // Enqueues a result to be returned by |Read|. This method does not make a
+ // copy of |data|, so |data| must outlive this object. If |sync| is true,
Randy Smith (Not in Mondays) 2016/08/22 22:37:17 nit: I think you mean |mode == SYNC|?
xunjieli 2016/08/29 16:25:29 Done.
+ // |Read| will return the supplied data synchronously; otherwise, consumer
+ // needs to call |CompleteNextRead|
+ void AddReadResult(const char* data, int len, Error error, Mode mode);
+
+ // Completes a pending Read() call.
+ void CompleteNextRead();
+
+ private:
+ struct QueuedResult {
+ QueuedResult(const char* data, int len, Error error, Mode mode);
+
+ const char* data;
+ const int len;
+ const Error error;
+ const Mode mode;
+ };
+
+ std::queue<QueuedResult> results_;
+ bool awaiting_completion_;
+ scoped_refptr<IOBuffer> dest_buffer_;
+ CompletionCallback callback_;
+ int dest_buffer_size_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockSourceStream);
+};
+
+} // namespace net
+
+#endif // NET_FILTER_MOCK_SOURCE_STREAM_H_

Powered by Google App Engine
This is Rietveld 408576698