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