Chromium Code Reviews| 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 #include <string> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/ref_counted.h" | |
| 13 #include "net/base/completion_callback.h" | |
| 14 #include "net/base/io_buffer.h" | |
| 15 #include "net/base/net_errors.h" | |
| 16 #include "net/filter/source_stream.h" | |
| 17 | |
| 18 namespace net { | |
| 19 | |
| 20 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.
| |
| 21 | |
| 22 // A SourceStream implementation used in tests. This allows tests to specify | |
| 23 // what data to return for each Read() call. | |
| 24 class MockSourceStream : public SourceStream { | |
| 25 public: | |
| 26 enum Mode { | |
| 27 SYNC, | |
| 28 ASYNC, | |
| 29 }; | |
| 30 MockSourceStream(); | |
| 31 ~MockSourceStream() override; | |
| 32 | |
| 33 // SourceStream implementation | |
| 34 int Read(IOBuffer* dest_buffer, | |
| 35 int buffer_size, | |
| 36 const CompletionCallback& callback) override; | |
| 37 std::string OrderedTypeStringList() const override; | |
| 38 | |
| 39 // Enqueues a result to be returned by |Read|. This method does not make a | |
| 40 // 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.
| |
| 41 // |Read| will return the supplied data synchronously; otherwise, consumer | |
| 42 // needs to call |CompleteNextRead| | |
| 43 void AddReadResult(const char* data, int len, Error error, Mode mode); | |
| 44 | |
| 45 // Completes a pending Read() call. | |
| 46 void CompleteNextRead(); | |
| 47 | |
| 48 private: | |
| 49 struct QueuedResult { | |
| 50 QueuedResult(const char* data, int len, Error error, Mode mode); | |
| 51 | |
| 52 const char* data; | |
| 53 const int len; | |
| 54 const Error error; | |
| 55 const Mode mode; | |
| 56 }; | |
| 57 | |
| 58 std::queue<QueuedResult> results_; | |
| 59 bool awaiting_completion_; | |
| 60 scoped_refptr<IOBuffer> dest_buffer_; | |
| 61 CompletionCallback callback_; | |
| 62 int dest_buffer_size_; | |
| 63 | |
| 64 DISALLOW_COPY_AND_ASSIGN(MockSourceStream); | |
| 65 }; | |
| 66 | |
| 67 } // namespace net | |
| 68 | |
| 69 #endif // NET_FILTER_MOCK_SOURCE_STREAM_H_ | |
| OLD | NEW |