| 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 OnSendHeadersComplete() OVERRIDE; | 29 virtual SpdySendStatus OnSendHeadersComplete() OVERRIDE; |
| 30 virtual int OnSendBody() OVERRIDE; | 30 virtual void OnSendBody() OVERRIDE; |
| 31 virtual SpdySendStatus OnSendBodyComplete(size_t bytes_sent) OVERRIDE; | 31 virtual SpdySendStatus OnSendBodyComplete(size_t bytes_sent) 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 void OnHeadersSent() OVERRIDE; | 35 virtual void OnHeadersSent() OVERRIDE; |
| 36 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; | 36 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; |
| 37 virtual void OnDataSent(size_t bytes_sent) OVERRIDE; | 37 virtual void OnDataSent(size_t bytes_sent) OVERRIDE; |
| 38 virtual void OnClose(int status) OVERRIDE; | 38 virtual void OnClose(int status) OVERRIDE; |
| 39 | 39 |
| 40 // Returns whether or not the stream is closed. | 40 // Returns whether or not the stream is closed. |
| 41 bool StreamIsClosed() const { return !stream_; } | 41 bool StreamIsClosed() const { return !stream_; } |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 base::WeakPtr<SpdyStream> stream_; | 44 base::WeakPtr<SpdyStream> stream_; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 // Base class with shared functionality for test delegate | 47 // Base class with shared functionality for test delegate |
| 48 // implementations below. | 48 // implementations below. |
| 49 class StreamDelegateBase : public SpdyStream::Delegate { | 49 class StreamDelegateBase : public SpdyStream::Delegate { |
| 50 public: | 50 public: |
| 51 explicit StreamDelegateBase(const base::WeakPtr<SpdyStream>& stream); | 51 explicit StreamDelegateBase(const base::WeakPtr<SpdyStream>& stream); |
| 52 virtual ~StreamDelegateBase(); | 52 virtual ~StreamDelegateBase(); |
| 53 | 53 |
| 54 virtual SpdySendStatus OnSendHeadersComplete() OVERRIDE; | 54 virtual SpdySendStatus OnSendHeadersComplete() OVERRIDE; |
| 55 virtual int OnSendBody() = 0; | 55 virtual void OnSendBody() = 0; |
| 56 virtual SpdySendStatus OnSendBodyComplete(size_t bytes_sent) = 0; | 56 virtual SpdySendStatus OnSendBodyComplete(size_t bytes_sent) = 0; |
| 57 virtual int OnResponseReceived(const SpdyHeaderBlock& response, | 57 virtual int OnResponseReceived(const SpdyHeaderBlock& response, |
| 58 base::Time response_time, | 58 base::Time response_time, |
| 59 int status) OVERRIDE; | 59 int status) OVERRIDE; |
| 60 virtual void OnHeadersSent() OVERRIDE; | 60 virtual void OnHeadersSent() OVERRIDE; |
| 61 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; | 61 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; |
| 62 virtual void OnDataSent(size_t bytes_sent) OVERRIDE; | 62 virtual void OnDataSent(size_t bytes_sent) OVERRIDE; |
| 63 virtual void OnClose(int status) OVERRIDE; | 63 virtual void OnClose(int status) OVERRIDE; |
| 64 | 64 |
| 65 // Waits for the stream to be closed and returns the status passed | 65 // Waits for the stream to be closed and returns the status passed |
| (...skipping 30 matching lines...) Expand all Loading... |
| 96 int data_sent_; | 96 int data_sent_; |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 // Test delegate that does nothing. Used to capture data about the | 99 // Test delegate that does nothing. Used to capture data about the |
| 100 // stream, e.g. its id when it was open. | 100 // stream, e.g. its id when it was open. |
| 101 class StreamDelegateDoNothing : public StreamDelegateBase { | 101 class StreamDelegateDoNothing : public StreamDelegateBase { |
| 102 public: | 102 public: |
| 103 StreamDelegateDoNothing(const base::WeakPtr<SpdyStream>& stream); | 103 StreamDelegateDoNothing(const base::WeakPtr<SpdyStream>& stream); |
| 104 virtual ~StreamDelegateDoNothing(); | 104 virtual ~StreamDelegateDoNothing(); |
| 105 | 105 |
| 106 virtual int OnSendBody() OVERRIDE; | 106 virtual void OnSendBody() OVERRIDE; |
| 107 virtual SpdySendStatus OnSendBodyComplete(size_t bytes_sent) OVERRIDE; | 107 virtual SpdySendStatus OnSendBodyComplete(size_t bytes_sent) OVERRIDE; |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 // Test delegate that sends data immediately in OnResponseReceived(). | 110 // Test delegate that sends data immediately in OnResponseReceived(). |
| 111 class StreamDelegateSendImmediate : public StreamDelegateBase { | 111 class StreamDelegateSendImmediate : public StreamDelegateBase { |
| 112 public: | 112 public: |
| 113 // Both |headers| and |buf| can be NULL. | 113 // Both |headers| and |buf| can be NULL. |
| 114 StreamDelegateSendImmediate(const base::WeakPtr<SpdyStream>& stream, | 114 StreamDelegateSendImmediate(const base::WeakPtr<SpdyStream>& stream, |
| 115 scoped_ptr<SpdyHeaderBlock> headers, | 115 scoped_ptr<SpdyHeaderBlock> headers, |
| 116 base::StringPiece data); | 116 base::StringPiece data); |
| 117 virtual ~StreamDelegateSendImmediate(); | 117 virtual ~StreamDelegateSendImmediate(); |
| 118 | 118 |
| 119 virtual int OnSendBody() OVERRIDE; | 119 virtual void OnSendBody() OVERRIDE; |
| 120 virtual SpdySendStatus OnSendBodyComplete(size_t bytes_sent) OVERRIDE; | 120 virtual SpdySendStatus OnSendBodyComplete(size_t bytes_sent) OVERRIDE; |
| 121 virtual int OnResponseReceived(const SpdyHeaderBlock& response, | 121 virtual int OnResponseReceived(const SpdyHeaderBlock& response, |
| 122 base::Time response_time, | 122 base::Time response_time, |
| 123 int status) OVERRIDE; | 123 int status) OVERRIDE; |
| 124 | 124 |
| 125 private: | 125 private: |
| 126 scoped_ptr<SpdyHeaderBlock> headers_; | 126 scoped_ptr<SpdyHeaderBlock> headers_; |
| 127 base::StringPiece data_; | 127 base::StringPiece data_; |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 // Test delegate that sends body data. | 130 // Test delegate that sends body data. |
| 131 class StreamDelegateWithBody : public StreamDelegateBase { | 131 class StreamDelegateWithBody : public StreamDelegateBase { |
| 132 public: | 132 public: |
| 133 StreamDelegateWithBody(const base::WeakPtr<SpdyStream>& stream, | 133 StreamDelegateWithBody(const base::WeakPtr<SpdyStream>& stream, |
| 134 base::StringPiece data); | 134 base::StringPiece data); |
| 135 virtual ~StreamDelegateWithBody(); | 135 virtual ~StreamDelegateWithBody(); |
| 136 | 136 |
| 137 virtual SpdySendStatus OnSendHeadersComplete() OVERRIDE; | 137 virtual SpdySendStatus OnSendHeadersComplete() OVERRIDE; |
| 138 virtual int OnSendBody() OVERRIDE; | 138 virtual void OnSendBody() OVERRIDE; |
| 139 virtual SpdySendStatus OnSendBodyComplete(size_t bytes_sent) OVERRIDE; | 139 virtual SpdySendStatus OnSendBodyComplete(size_t bytes_sent) OVERRIDE; |
| 140 | 140 |
| 141 int body_data_sent() const { return body_data_sent_; } | 141 int body_data_sent() const { return body_data_sent_; } |
| 142 | 142 |
| 143 private: | 143 private: |
| 144 scoped_refptr<DrainableIOBuffer> buf_; | 144 scoped_refptr<DrainableIOBuffer> buf_; |
| 145 int body_data_sent_; | 145 int body_data_sent_; |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 } // namespace test | 148 } // namespace test |
| 149 | 149 |
| 150 } // namespace net | 150 } // namespace net |
| 151 | 151 |
| 152 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ | 152 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ |
| OLD | NEW |