Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Side by Side Diff: net/filter/mock_source_stream.h

Issue 2251853002: Add net::SourceStream and net::FilterSourceStream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Same as PS#18 of old CL but with upstream/downstream name change Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/base/net_export.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 NET_EXPORT_PRIVATE MockSourceStream : public SourceStream {
22 public:
23 MockSourceStream();
24 ~MockSourceStream() override;
25
26 // SourceStream implementation
27 int Read(IOBuffer* dest_buffer,
28 size_t buffer_size,
29 const CompletionCallback& callback) override;
30
31 std::string OrderedTypeStringList() const override;
32
33 // Testing helpers
mmenke 2016/08/17 19:01:56 I don't think this is needed?
xunjieli 2016/08/17 20:00:20 Done.
34 // Enqueues a result to be returned by |Read|. This method does not make a
35 // copy of |data|, so |data| must outlive this object. If |sync| is true,
36 // |Read| will return the supplied data synchronously; otherwise, the user of
37 // this class needs to call |CompleteNextRead|
mmenke 2016/08/17 19:01:56 nit: "user of this class" -> "consumer"
xunjieli 2016/08/17 20:00:20 Done.
38 void AddReadResult(const char* data, size_t len, Error error, bool sync);
39
40 // Completes a pending Read() call.
41 void CompleteNextRead();
42
43 private:
44 struct QueuedResult {
45 QueuedResult(const char* data, size_t len, Error error, bool sync);
46
47 const char* data;
48 const size_t len;
49 const Error error;
50 const bool sync;
51 };
52
53 std::queue<QueuedResult> results_;
54 bool awaiting_completion_;
55 scoped_refptr<IOBuffer> dest_buffer_;
56 CompletionCallback callback_;
57 size_t dest_buffer_size_;
mmenke 2016/08/17 19:01:56 DISALLOW_COPY_AND_ASSIGN
xunjieli 2016/08/17 20:00:20 Done.
58 };
59
60 } // namespace net
61
62 #endif // NET_FILTER_MOCK_SOURCE_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698