Chromium Code Reviews| 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..14502435ab52b725242522aa26a7402dff06e72b |
| --- /dev/null |
| +++ b/net/filter/mock_stream_source.h |
| @@ -0,0 +1,55 @@ |
| +// 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_STREAM_SOURCE_H |
| +#define NET_FILTER_MOCK_STREAM_SOURCE_H |
|
mmenke
2016/07/21 18:14:08
+_ (x3)
xunjieli
2016/07/27 20:32:02
Done.
|
| + |
| +#include <queue> |
| + |
| +#include "net/base/completion_callback.h" |
| +#include "net/filter/stream_source.h" |
| + |
| +namespace net { |
| + |
| +class IOBuffer; |
| + |
| +class MockStreamSource : public StreamSource { |
|
mmenke
2016/07/21 18:14:08
Think this needs a description
xunjieli
2016/07/27 20:32:03
Done.
|
| + public: |
| + MockStreamSource(); |
| + ~MockStreamSource() override; |
| + |
| + // StreamSource implementation |
| + int Read(IOBuffer* dest_buffer, |
| + size_t buffer_size, |
| + const CompletionCallback& callback) 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); |
|
mmenke
2016/07/21 18:14:09
include net/base/net_errors.h
xunjieli
2016/07/27 20:32:02
Done.
|
| + |
| + // Completes a pending Read() call. |
| + void CompleteNextRead(); |
| + |
| + private: |
| + struct QueuedResult { |
| + QueuedResult(const char* data, size_t len, Error error, bool sync); |
|
mmenke
2016/07/21 18:14:09
nit: Add blank line before member variables.
xunjieli
2016/07/27 20:32:02
Done.
|
| + const char* data; |
| + size_t len; |
| + Error error; |
| + bool sync; |
|
mmenke
2016/07/21 18:14:08
Can these all be constant? Fine if not. Could ev
xunjieli
2016/07/27 20:32:03
Done. I couldn't get "std::queue<const QueuedResul
|
| + }; |
| + |
| + std::queue<QueuedResult> results_; |
| + bool awaiting_completion_; |
| + IOBuffer* dest_buffer_; |
|
mmenke
2016/07/21 18:14:09
scoped_refptr? (+include header for it)
xunjieli
2016/07/27 20:32:02
Done.
|
| + CompletionCallback callback_; |
| + size_t dest_buffer_size_; |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_FILTER_MOCK_STREAM_SOURCE_H |