Chromium Code Reviews| 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..0a357532992c0816c87463bb43fe59e048128311 |
| --- /dev/null |
| +++ b/net/filter/mock_source_stream.h |
| @@ -0,0 +1,62 @@ |
| +// 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 "net/base/completion_callback.h" |
| +#include "net/base/io_buffer.h" |
| +#include "net/base/net_export.h" |
| +#include "net/filter/source_stream.h" |
| + |
| +namespace net { |
| + |
| +class IOBuffer; |
| + |
| +// A SourceStream implementation used in tests. This allows tests to specify |
| +// what data to return for each Read() call. |
| +class NET_EXPORT_PRIVATE MockSourceStream : public SourceStream { |
| + public: |
| + MockSourceStream(); |
| + ~MockSourceStream() override; |
| + |
| + // SourceStream implementation |
| + int Read(IOBuffer* dest_buffer, |
| + size_t buffer_size, |
| + const CompletionCallback& callback) override; |
| + |
| + std::string OrderedTypeStringList() const override; |
| + |
| + // Testing helpers |
|
mmenke
2016/08/17 19:01:56
I don't think this is needed?
xunjieli
2016/08/17 20:00:20
Done.
|
| + // 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| |
|
mmenke
2016/08/17 19:01:56
nit: "user of this class" -> "consumer"
xunjieli
2016/08/17 20:00:20
Done.
|
| + void AddReadResult(const char* data, size_t len, Error error, bool sync); |
| + |
| + // Completes a pending Read() call. |
| + void CompleteNextRead(); |
| + |
| + private: |
| + struct QueuedResult { |
| + QueuedResult(const char* data, size_t len, Error error, bool sync); |
| + |
| + const char* data; |
| + const size_t len; |
| + const Error error; |
| + const bool sync; |
| + }; |
| + |
| + std::queue<QueuedResult> results_; |
| + bool awaiting_completion_; |
| + scoped_refptr<IOBuffer> dest_buffer_; |
| + CompletionCallback callback_; |
| + size_t dest_buffer_size_; |
|
mmenke
2016/08/17 19:01:56
DISALLOW_COPY_AND_ASSIGN
xunjieli
2016/08/17 20:00:20
Done.
|
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_FILTER_MOCK_SOURCE_STREAM_H_ |