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

Unified Diff: net/filter/mock_stream_source.h

Issue 1662763002: [ON HOLD] Implement pull-based design for content decoding (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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_stream_source.h
diff --git a/net/filter/mock_stream_source.h b/net/filter/mock_stream_source.h
new file mode 100644
index 0000000000000000000000000000000000000000..6ea6bfda18c96f7175082c665fb299c252eb7236
--- /dev/null
+++ b/net/filter/mock_stream_source.h
@@ -0,0 +1,50 @@
+// 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.
+
+#include <queue>
+
+#include "net/filter/stream_source.h"
+
+namespace net {
+
+class MockStreamSource : public StreamSource {
+ public:
+ MockStreamSource();
+ ~MockStreamSource() override;
+
+ // Testing helpers
+ // 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,
+ // |Read| will return the supplied data synchronously; otherwise, the user of
+ // this class needs to call |CompleteNextRead|.
+ void AddReadResult(const char* data, size_t len, Error error, bool sync);
+
+ // Completes a pending Read() call.
+ void CompleteNextRead();
+
+ // StreamSource implementation
+ net::Error Read(IOBuffer* dest_buffer,
+ size_t buffer_size,
+ size_t* bytes_read,
+ const OnReadCompleteCallback& callback) override;
+ size_t GetBytesOutput() const override;
+
+ private:
+ struct QueuedResult {
+ QueuedResult(const char* data, size_t len, Error error, bool sync);
+ const char* data;
+ size_t len;
+ Error error;
+ bool sync;
+ };
+
+ std::queue<QueuedResult> results_;
+ bool awaiting_completion_;
+ IOBuffer* dest_buffer_;
+ size_t dest_buffer_size_;
+ OnReadCompleteCallback callback_;
+ size_t total_bytes_output_;
+};
+
+} // namespace net

Powered by Google App Engine
This is Rietveld 408576698