| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef NET_FILTER_MOCK_SOURCE_STREAM_H_ |
| 6 #define NET_FILTER_MOCK_SOURCE_STREAM_H_ |
| 7 |
| 8 #include <queue> |
| 9 |
| 10 #include "net/base/completion_callback.h" |
| 11 #include "net/base/io_buffer.h" |
| 12 #include "net/filter/source_stream.h" |
| 13 |
| 14 namespace net { |
| 15 |
| 16 class IOBuffer; |
| 17 |
| 18 // A SourceStream implementation used in tests. This allows tests to specify |
| 19 // what data to return for each Read() call. |
| 20 class MockSourceStream : public SourceStream { |
| 21 public: |
| 22 MockSourceStream(); |
| 23 ~MockSourceStream() override; |
| 24 |
| 25 // SourceStream implementation |
| 26 int Read(IOBuffer* dest_buffer, |
| 27 size_t buffer_size, |
| 28 const CompletionCallback& callback) override; |
| 29 |
| 30 // Testing helpers |
| 31 // Enqueues a result to be returned by |Read|. This method does not make a |
| 32 // copy of |data|, so |data| must outlive this object. If |sync| is true, |
| 33 // |Read| will return the supplied data synchronously; otherwise, the user of |
| 34 // this class needs to call |CompleteNextRead| |
| 35 void AddReadResult(const char* data, size_t len, Error error, bool sync); |
| 36 |
| 37 // Completes a pending Read() call. |
| 38 void CompleteNextRead(); |
| 39 |
| 40 private: |
| 41 struct QueuedResult { |
| 42 QueuedResult(const char* data, size_t len, Error error, bool sync); |
| 43 |
| 44 const char* data; |
| 45 const size_t len; |
| 46 const Error error; |
| 47 const bool sync; |
| 48 }; |
| 49 |
| 50 std::queue<QueuedResult> results_; |
| 51 bool awaiting_completion_; |
| 52 scoped_refptr<IOBuffer> dest_buffer_; |
| 53 CompletionCallback callback_; |
| 54 size_t dest_buffer_size_; |
| 55 }; |
| 56 |
| 57 } // namespace net |
| 58 |
| 59 #endif // NET_FILTER_MOCK_SOURCE_STREAM_H_ |
| OLD | NEW |