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

Side by Side Diff: net/spdy/spdy_stream_test_util.h

Issue 2832973003: Split net/spdy into core and chromium subdirectories. (Closed)
Patch Set: Fix some more build rules. Created 3 years, 8 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
« no previous file with comments | « net/spdy/spdy_stream.cc ('k') | net/spdy/spdy_stream_test_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012 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_SPDY_SPDY_STREAM_TEST_UTIL_H_
6 #define NET_SPDY_SPDY_STREAM_TEST_UTIL_H_
7
8 #include <memory>
9
10 #include "base/compiler_specific.h"
11 #include "base/memory/ref_counted.h"
12 #include "net/base/io_buffer.h"
13 #include "net/base/test_completion_callback.h"
14 #include "net/log/net_log_source.h"
15 #include "net/spdy/platform/api/spdy_string_piece.h"
16 #include "net/spdy/spdy_read_queue.h"
17 #include "net/spdy/spdy_stream.h"
18
19 namespace net {
20
21 namespace test {
22
23 // Delegate that calls Close() on |stream_| on OnClose. Used by tests
24 // to make sure that such an action is harmless.
25 class ClosingDelegate : public SpdyStream::Delegate {
26 public:
27 explicit ClosingDelegate(const base::WeakPtr<SpdyStream>& stream);
28 ~ClosingDelegate() override;
29
30 // SpdyStream::Delegate implementation.
31 void OnHeadersSent() override;
32 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override;
33 void OnDataReceived(std::unique_ptr<SpdyBuffer> buffer) override;
34 void OnDataSent() override;
35 void OnTrailers(const SpdyHeaderBlock& trailers) override;
36 void OnClose(int status) override;
37 NetLogSource source_dependency() const override;
38
39 // Returns whether or not the stream is closed.
40 bool StreamIsClosed() const { return !stream_.get(); }
41
42 private:
43 base::WeakPtr<SpdyStream> stream_;
44 };
45
46 // Base class with shared functionality for test delegate
47 // implementations below.
48 class StreamDelegateBase : public SpdyStream::Delegate {
49 public:
50 explicit StreamDelegateBase(const base::WeakPtr<SpdyStream>& stream);
51 ~StreamDelegateBase() override;
52
53 void OnHeadersSent() override;
54 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override;
55 void OnDataReceived(std::unique_ptr<SpdyBuffer> buffer) override;
56 void OnDataSent() override;
57 void OnTrailers(const SpdyHeaderBlock& trailers) override;
58 void OnClose(int status) override;
59 NetLogSource source_dependency() const override;
60
61 // Waits for the stream to be closed and returns the status passed
62 // to OnClose().
63 int WaitForClose();
64
65 // Drains all data from the underlying read queue and returns it as
66 // a string.
67 SpdyString TakeReceivedData();
68
69 // Returns whether or not the stream is closed.
70 bool StreamIsClosed() const { return !stream_.get(); }
71
72 // Returns the stream's ID. If called when the stream is closed,
73 // returns the stream's ID when it was open.
74 SpdyStreamId stream_id() const { return stream_id_; }
75
76 SpdyString GetResponseHeaderValue(const SpdyString& name) const;
77 bool send_headers_completed() const { return send_headers_completed_; }
78
79 protected:
80 const base::WeakPtr<SpdyStream>& stream() { return stream_; }
81
82 private:
83 base::WeakPtr<SpdyStream> stream_;
84 SpdyStreamId stream_id_;
85 TestCompletionCallback callback_;
86 bool send_headers_completed_;
87 SpdyHeaderBlock response_headers_;
88 SpdyReadQueue received_data_queue_;
89 };
90
91 // Test delegate that does nothing. Used to capture data about the
92 // stream, e.g. its id when it was open.
93 class StreamDelegateDoNothing : public StreamDelegateBase {
94 public:
95 explicit StreamDelegateDoNothing(const base::WeakPtr<SpdyStream>& stream);
96 ~StreamDelegateDoNothing() override;
97 };
98
99 // Test delegate that sends data immediately in OnHeadersReceived().
100 class StreamDelegateSendImmediate : public StreamDelegateBase {
101 public:
102 // |data| can be NULL.
103 StreamDelegateSendImmediate(const base::WeakPtr<SpdyStream>& stream,
104 SpdyStringPiece data);
105 ~StreamDelegateSendImmediate() override;
106
107 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override;
108
109 private:
110 SpdyStringPiece data_;
111 };
112
113 // Test delegate that sends body data.
114 class StreamDelegateWithBody : public StreamDelegateBase {
115 public:
116 StreamDelegateWithBody(const base::WeakPtr<SpdyStream>& stream,
117 SpdyStringPiece data);
118 ~StreamDelegateWithBody() override;
119
120 void OnHeadersSent() override;
121
122 private:
123 scoped_refptr<StringIOBuffer> buf_;
124 };
125
126 // Test delegate that closes stream in OnHeadersReceived().
127 class StreamDelegateCloseOnHeaders : public StreamDelegateBase {
128 public:
129 explicit StreamDelegateCloseOnHeaders(
130 const base::WeakPtr<SpdyStream>& stream);
131 ~StreamDelegateCloseOnHeaders() override;
132
133 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override;
134 };
135
136 } // namespace test
137
138 } // namespace net
139
140 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « net/spdy/spdy_stream.cc ('k') | net/spdy/spdy_stream_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698