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_FUZZED_SOURCE_STREAM_H_ | |
| 6 #define NET_FILTER_FUZZED_SOURCE_STREAM_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "net/base/completion_callback.h" | |
| 10 #include "net/filter/source_stream.h" | |
| 11 | |
| 12 namespace base { | |
| 13 class FuzzedDataProvider; | |
| 14 } // namespace base | |
| 15 | |
| 16 namespace net { | |
| 17 | |
| 18 class IOBuffer; | |
| 19 | |
| 20 // A SourceStream implementation used in tests. This allows tests to specify | |
| 21 // what data to return for each Read() call. | |
| 22 class FuzzedSourceStream : public SourceStream { | |
| 23 public: | |
| 24 // |data_provider| is used to determine behavior of the FuzzedSourceStream. | |
| 25 // It must remain valid until after the FuzzedSocket is destroyed. | |
| 26 explicit FuzzedSourceStream(base::FuzzedDataProvider* data_provider); | |
| 27 ~FuzzedSourceStream() override; | |
| 28 | |
| 29 // SourceStream implementation | |
| 30 int Read(IOBuffer* dest_buffer, | |
| 31 int buffer_size, | |
| 32 const CompletionCallback& callback) override; | |
| 33 std::string Description() const override; | |
| 34 | |
| 35 private: | |
| 36 void OnReadComplete(const CompletionCallback& callback, | |
| 37 const std::string& fuzzed_data, | |
|
mmenke
2016/10/31 14:59:52
Should probably include <string> here instead of t
xunjieli
2016/10/31 15:14:56
Done. Thanks for point that out. I recently learne
| |
| 38 scoped_refptr<IOBuffer> read_buf, | |
|
mmenke
2016/10/31 14:59:52
include base/memory/ref_counted.h
xunjieli
2016/10/31 15:14:56
Done.
| |
| 39 int result); | |
| 40 | |
| 41 base::FuzzedDataProvider* data_provider_; | |
| 42 | |
| 43 // Whether there is a pending Read(). | |
| 44 bool read_pending_; | |
| 45 | |
| 46 // Last result returned by Read() is an error or 0. | |
| 47 bool end_returned_; | |
| 48 | |
| 49 DISALLOW_COPY_AND_ASSIGN(FuzzedSourceStream); | |
| 50 }; | |
| 51 | |
| 52 } // namespace net | |
| 53 | |
| 54 #endif // NET_FILTER_FUZZED_SOURCE_STREAM_H_ | |
| OLD | NEW |