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

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

Issue 15936003: [SPDY] Refactor SpdyStream::Delegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_stream_spdy3_unittest.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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ 5 #ifndef NET_SPDY_SPDY_STREAM_TEST_UTIL_H_
6 #define NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ 6 #define NET_SPDY_SPDY_STREAM_TEST_UTIL_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/strings/string_piece.h" 11 #include "base/strings/string_piece.h"
12 #include "net/base/io_buffer.h" 12 #include "net/base/io_buffer.h"
13 #include "net/base/test_completion_callback.h" 13 #include "net/base/test_completion_callback.h"
14 #include "net/spdy/spdy_read_queue.h" 14 #include "net/spdy/spdy_read_queue.h"
15 #include "net/spdy/spdy_stream.h" 15 #include "net/spdy/spdy_stream.h"
16 16
17 namespace net { 17 namespace net {
18 18
19 namespace test { 19 namespace test {
20 20
21 // Delegate that calls Close() on |stream_| on OnClose. Used by tests 21 // Delegate that calls Close() on |stream_| on OnClose. Used by tests
22 // to make sure that such an action is harmless. 22 // to make sure that such an action is harmless.
23 class ClosingDelegate : public SpdyStream::Delegate { 23 class ClosingDelegate : public SpdyStream::Delegate {
24 public: 24 public:
25 explicit ClosingDelegate(const base::WeakPtr<SpdyStream>& stream); 25 explicit ClosingDelegate(const base::WeakPtr<SpdyStream>& stream);
26 virtual ~ClosingDelegate(); 26 virtual ~ClosingDelegate();
27 27
28 // SpdyStream::Delegate implementation. 28 // SpdyStream::Delegate implementation.
29 virtual void OnSendRequestHeadersComplete() OVERRIDE; 29 virtual void OnRequestHeadersSent() OVERRIDE;
30 virtual void OnSendBody() OVERRIDE; 30 virtual int OnResponseHeadersReceived(const SpdyHeaderBlock& response,
31 virtual void OnSendBodyComplete() OVERRIDE; 31 base::Time response_time,
32 virtual int OnResponseReceived(const SpdyHeaderBlock& response, 32 int status) OVERRIDE;
33 base::Time response_time,
34 int status) OVERRIDE;
35 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; 33 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE;
36 virtual void OnDataSent() OVERRIDE; 34 virtual void OnDataSent() OVERRIDE;
37 virtual void OnClose(int status) OVERRIDE; 35 virtual void OnClose(int status) OVERRIDE;
38 36
39 // Returns whether or not the stream is closed. 37 // Returns whether or not the stream is closed.
40 bool StreamIsClosed() const { return !stream_; } 38 bool StreamIsClosed() const { return !stream_; }
41 39
42 private: 40 private:
43 base::WeakPtr<SpdyStream> stream_; 41 base::WeakPtr<SpdyStream> stream_;
44 }; 42 };
45 43
46 // Base class with shared functionality for test delegate 44 // Base class with shared functionality for test delegate
47 // implementations below. 45 // implementations below.
48 class StreamDelegateBase : public SpdyStream::Delegate { 46 class StreamDelegateBase : public SpdyStream::Delegate {
49 public: 47 public:
50 explicit StreamDelegateBase(const base::WeakPtr<SpdyStream>& stream); 48 explicit StreamDelegateBase(const base::WeakPtr<SpdyStream>& stream);
51 virtual ~StreamDelegateBase(); 49 virtual ~StreamDelegateBase();
52 50
53 virtual void OnSendRequestHeadersComplete() OVERRIDE; 51 virtual void OnRequestHeadersSent() OVERRIDE;
54 virtual void OnSendBody() = 0; 52 virtual int OnResponseHeadersReceived(const SpdyHeaderBlock& response,
55 virtual void OnSendBodyComplete() = 0; 53 base::Time response_time,
56 virtual int OnResponseReceived(const SpdyHeaderBlock& response, 54 int status) OVERRIDE;
57 base::Time response_time,
58 int status) OVERRIDE;
59 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; 55 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE;
60 virtual void OnDataSent() OVERRIDE; 56 virtual void OnDataSent() OVERRIDE;
61 virtual void OnClose(int status) OVERRIDE; 57 virtual void OnClose(int status) OVERRIDE;
62 58
63 // Waits for the stream to be closed and returns the status passed 59 // Waits for the stream to be closed and returns the status passed
64 // to OnClose(). 60 // to OnClose().
65 int WaitForClose(); 61 int WaitForClose();
66 62
67 // Drains all data from the underlying read queue and returns it as 63 // Drains all data from the underlying read queue and returns it as
68 // a string. 64 // a string.
(...skipping 20 matching lines...) Expand all
89 SpdyHeaderBlock response_; 85 SpdyHeaderBlock response_;
90 SpdyReadQueue received_data_queue_; 86 SpdyReadQueue received_data_queue_;
91 }; 87 };
92 88
93 // Test delegate that does nothing. Used to capture data about the 89 // Test delegate that does nothing. Used to capture data about the
94 // stream, e.g. its id when it was open. 90 // stream, e.g. its id when it was open.
95 class StreamDelegateDoNothing : public StreamDelegateBase { 91 class StreamDelegateDoNothing : public StreamDelegateBase {
96 public: 92 public:
97 StreamDelegateDoNothing(const base::WeakPtr<SpdyStream>& stream); 93 StreamDelegateDoNothing(const base::WeakPtr<SpdyStream>& stream);
98 virtual ~StreamDelegateDoNothing(); 94 virtual ~StreamDelegateDoNothing();
99
100 virtual void OnSendBody() OVERRIDE;
101 virtual void OnSendBodyComplete() OVERRIDE;
102 }; 95 };
103 96
104 // Test delegate that sends data immediately in OnResponseReceived(). 97 // Test delegate that sends data immediately in OnResponseHeadersReceived().
105 class StreamDelegateSendImmediate : public StreamDelegateBase { 98 class StreamDelegateSendImmediate : public StreamDelegateBase {
106 public: 99 public:
107 // |data| can be NULL. 100 // |data| can be NULL.
108 StreamDelegateSendImmediate(const base::WeakPtr<SpdyStream>& stream, 101 StreamDelegateSendImmediate(const base::WeakPtr<SpdyStream>& stream,
109 base::StringPiece data); 102 base::StringPiece data);
110 virtual ~StreamDelegateSendImmediate(); 103 virtual ~StreamDelegateSendImmediate();
111 104
112 virtual void OnSendBody() OVERRIDE; 105 virtual int OnResponseHeadersReceived(const SpdyHeaderBlock& response,
113 virtual void OnSendBodyComplete() OVERRIDE; 106 base::Time response_time,
114 virtual int OnResponseReceived(const SpdyHeaderBlock& response, 107 int status) OVERRIDE;
115 base::Time response_time,
116 int status) OVERRIDE;
117 108
118 private: 109 private:
119 base::StringPiece data_; 110 base::StringPiece data_;
120 }; 111 };
121 112
122 // Test delegate that sends body data. 113 // Test delegate that sends body data.
123 class StreamDelegateWithBody : public StreamDelegateBase { 114 class StreamDelegateWithBody : public StreamDelegateBase {
124 public: 115 public:
125 StreamDelegateWithBody(const base::WeakPtr<SpdyStream>& stream, 116 StreamDelegateWithBody(const base::WeakPtr<SpdyStream>& stream,
126 base::StringPiece data); 117 base::StringPiece data);
127 virtual ~StreamDelegateWithBody(); 118 virtual ~StreamDelegateWithBody();
128 119
129 virtual void OnSendBody() OVERRIDE; 120 virtual void OnRequestHeadersSent() OVERRIDE;
130 virtual void OnSendBodyComplete() OVERRIDE;
131 121
132 private: 122 private:
133 scoped_refptr<StringIOBuffer> buf_; 123 scoped_refptr<StringIOBuffer> buf_;
134 }; 124 };
135 125
136 } // namespace test 126 } // namespace test
137 127
138 } // namespace net 128 } // namespace net
139 129
140 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ 130 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « net/spdy/spdy_stream_spdy3_unittest.cc ('k') | net/spdy/spdy_stream_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698