OLD | NEW |
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 SpdySendStatus OnSendRequestHeadersComplete() OVERRIDE; | 29 virtual void OnSendRequestHeadersComplete() OVERRIDE; |
30 virtual void OnSendBody() OVERRIDE; | 30 virtual void OnSendBody() OVERRIDE; |
31 virtual void OnSendBodyComplete() OVERRIDE; | 31 virtual void OnSendBodyComplete() OVERRIDE; |
32 virtual int OnResponseReceived(const SpdyHeaderBlock& response, | 32 virtual int OnResponseReceived(const SpdyHeaderBlock& response, |
33 base::Time response_time, | 33 base::Time response_time, |
34 int status) OVERRIDE; | 34 int status) OVERRIDE; |
35 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; | 35 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; |
36 virtual void OnDataSent() OVERRIDE; | 36 virtual void OnDataSent() OVERRIDE; |
37 virtual void OnClose(int status) OVERRIDE; | 37 virtual void OnClose(int status) OVERRIDE; |
38 | 38 |
39 // Returns whether or not the stream is closed. | 39 // Returns whether or not the stream is closed. |
40 bool StreamIsClosed() const { return !stream_; } | 40 bool StreamIsClosed() const { return !stream_; } |
41 | 41 |
42 private: | 42 private: |
43 base::WeakPtr<SpdyStream> stream_; | 43 base::WeakPtr<SpdyStream> stream_; |
44 }; | 44 }; |
45 | 45 |
46 // Base class with shared functionality for test delegate | 46 // Base class with shared functionality for test delegate |
47 // implementations below. | 47 // implementations below. |
48 class StreamDelegateBase : public SpdyStream::Delegate { | 48 class StreamDelegateBase : public SpdyStream::Delegate { |
49 public: | 49 public: |
50 explicit StreamDelegateBase(const base::WeakPtr<SpdyStream>& stream); | 50 explicit StreamDelegateBase(const base::WeakPtr<SpdyStream>& stream); |
51 virtual ~StreamDelegateBase(); | 51 virtual ~StreamDelegateBase(); |
52 | 52 |
53 virtual SpdySendStatus OnSendRequestHeadersComplete() OVERRIDE; | 53 virtual void OnSendRequestHeadersComplete() OVERRIDE; |
54 virtual void OnSendBody() = 0; | 54 virtual void OnSendBody() = 0; |
55 virtual void OnSendBodyComplete() = 0; | 55 virtual void OnSendBodyComplete() = 0; |
56 virtual int OnResponseReceived(const SpdyHeaderBlock& response, | 56 virtual int OnResponseReceived(const SpdyHeaderBlock& response, |
57 base::Time response_time, | 57 base::Time response_time, |
58 int status) OVERRIDE; | 58 int status) OVERRIDE; |
59 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; | 59 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; |
60 virtual void OnDataSent() OVERRIDE; | 60 virtual void OnDataSent() OVERRIDE; |
61 virtual void OnClose(int status) OVERRIDE; | 61 virtual void OnClose(int status) OVERRIDE; |
62 | 62 |
63 // Waits for the stream to be closed and returns the status passed | 63 // Waits for the stream to be closed and returns the status passed |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 base::StringPiece data_; | 119 base::StringPiece data_; |
120 }; | 120 }; |
121 | 121 |
122 // Test delegate that sends body data. | 122 // Test delegate that sends body data. |
123 class StreamDelegateWithBody : public StreamDelegateBase { | 123 class StreamDelegateWithBody : public StreamDelegateBase { |
124 public: | 124 public: |
125 StreamDelegateWithBody(const base::WeakPtr<SpdyStream>& stream, | 125 StreamDelegateWithBody(const base::WeakPtr<SpdyStream>& stream, |
126 base::StringPiece data); | 126 base::StringPiece data); |
127 virtual ~StreamDelegateWithBody(); | 127 virtual ~StreamDelegateWithBody(); |
128 | 128 |
129 virtual SpdySendStatus OnSendRequestHeadersComplete() OVERRIDE; | |
130 virtual void OnSendBody() OVERRIDE; | 129 virtual void OnSendBody() OVERRIDE; |
131 virtual void OnSendBodyComplete() OVERRIDE; | 130 virtual void OnSendBodyComplete() OVERRIDE; |
132 | 131 |
133 private: | 132 private: |
134 scoped_refptr<StringIOBuffer> buf_; | 133 scoped_refptr<StringIOBuffer> buf_; |
135 }; | 134 }; |
136 | 135 |
137 } // namespace test | 136 } // namespace test |
138 | 137 |
139 } // namespace net | 138 } // namespace net |
140 | 139 |
141 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ | 140 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ |
OLD | NEW |