| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 void OnSendBody() OVERRIDE; | 30 virtual void OnSendBody() OVERRIDE; |
| 31 virtual SpdySendStatus OnSendBodyComplete(size_t bytes_sent) OVERRIDE; | 31 virtual SpdySendStatus 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 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() 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 void OnSendBody() = 0; | 55 virtual void OnSendBody() = 0; |
| 56 virtual SpdySendStatus OnSendBodyComplete(size_t bytes_sent) = 0; | 56 virtual SpdySendStatus OnSendBodyComplete() = 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() 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 |
| 66 // to OnClose(). | 66 // to OnClose(). |
| 67 int WaitForClose(); | 67 int WaitForClose(); |
| 68 | 68 |
| 69 // Drains all data from the underlying read queue and returns it as | 69 // Drains all data from the underlying read queue and returns it as |
| 70 // a string. | 70 // a string. |
| 71 std::string TakeReceivedData(); | 71 std::string TakeReceivedData(); |
| 72 | 72 |
| 73 // Returns whether or not the stream is closed. | 73 // Returns whether or not the stream is closed. |
| 74 bool StreamIsClosed() const { return !stream_; } | 74 bool StreamIsClosed() const { return !stream_; } |
| 75 | 75 |
| 76 // Returns the stream's ID. If called when the stream is closed, | 76 // Returns the stream's ID. If called when the stream is closed, |
| 77 // returns the stream's ID when it was open. | 77 // returns the stream's ID when it was open. |
| 78 SpdyStreamId stream_id() const { return stream_id_; } | 78 SpdyStreamId stream_id() const { return stream_id_; } |
| 79 | 79 |
| 80 std::string GetResponseHeaderValue(const std::string& name) const; | 80 std::string GetResponseHeaderValue(const std::string& name) const; |
| 81 bool send_headers_completed() const { return send_headers_completed_; } | 81 bool send_headers_completed() const { return send_headers_completed_; } |
| 82 int headers_sent() const { return headers_sent_; } | |
| 83 int data_sent() const { return data_sent_; } | |
| 84 | 82 |
| 85 protected: | 83 protected: |
| 86 const base::WeakPtr<SpdyStream>& stream() { return stream_; } | 84 const base::WeakPtr<SpdyStream>& stream() { return stream_; } |
| 87 | 85 |
| 88 private: | 86 private: |
| 89 base::WeakPtr<SpdyStream> stream_; | 87 base::WeakPtr<SpdyStream> stream_; |
| 90 SpdyStreamId stream_id_; | 88 SpdyStreamId stream_id_; |
| 91 TestCompletionCallback callback_; | 89 TestCompletionCallback callback_; |
| 92 bool send_headers_completed_; | 90 bool send_headers_completed_; |
| 93 SpdyHeaderBlock response_; | 91 SpdyHeaderBlock response_; |
| 94 SpdyReadQueue received_data_queue_; | 92 SpdyReadQueue received_data_queue_; |
| 95 int headers_sent_; | |
| 96 int data_sent_; | |
| 97 }; | 93 }; |
| 98 | 94 |
| 99 // Test delegate that does nothing. Used to capture data about the | 95 // Test delegate that does nothing. Used to capture data about the |
| 100 // stream, e.g. its id when it was open. | 96 // stream, e.g. its id when it was open. |
| 101 class StreamDelegateDoNothing : public StreamDelegateBase { | 97 class StreamDelegateDoNothing : public StreamDelegateBase { |
| 102 public: | 98 public: |
| 103 StreamDelegateDoNothing(const base::WeakPtr<SpdyStream>& stream); | 99 StreamDelegateDoNothing(const base::WeakPtr<SpdyStream>& stream); |
| 104 virtual ~StreamDelegateDoNothing(); | 100 virtual ~StreamDelegateDoNothing(); |
| 105 | 101 |
| 106 virtual void OnSendBody() OVERRIDE; | 102 virtual void OnSendBody() OVERRIDE; |
| 107 virtual SpdySendStatus OnSendBodyComplete(size_t bytes_sent) OVERRIDE; | 103 virtual SpdySendStatus OnSendBodyComplete() OVERRIDE; |
| 108 }; | 104 }; |
| 109 | 105 |
| 110 // Test delegate that sends data immediately in OnResponseReceived(). | 106 // Test delegate that sends data immediately in OnResponseReceived(). |
| 111 class StreamDelegateSendImmediate : public StreamDelegateBase { | 107 class StreamDelegateSendImmediate : public StreamDelegateBase { |
| 112 public: | 108 public: |
| 113 // Both |headers| and |buf| can be NULL. | 109 // Both |headers| and |buf| can be NULL. |
| 114 StreamDelegateSendImmediate(const base::WeakPtr<SpdyStream>& stream, | 110 StreamDelegateSendImmediate(const base::WeakPtr<SpdyStream>& stream, |
| 115 scoped_ptr<SpdyHeaderBlock> headers, | 111 scoped_ptr<SpdyHeaderBlock> headers, |
| 116 base::StringPiece data); | 112 base::StringPiece data); |
| 117 virtual ~StreamDelegateSendImmediate(); | 113 virtual ~StreamDelegateSendImmediate(); |
| 118 | 114 |
| 119 virtual void OnSendBody() OVERRIDE; | 115 virtual void OnSendBody() OVERRIDE; |
| 120 virtual SpdySendStatus OnSendBodyComplete(size_t bytes_sent) OVERRIDE; | 116 virtual SpdySendStatus OnSendBodyComplete() OVERRIDE; |
| 121 virtual int OnResponseReceived(const SpdyHeaderBlock& response, | 117 virtual int OnResponseReceived(const SpdyHeaderBlock& response, |
| 122 base::Time response_time, | 118 base::Time response_time, |
| 123 int status) OVERRIDE; | 119 int status) OVERRIDE; |
| 124 | 120 |
| 125 private: | 121 private: |
| 126 scoped_ptr<SpdyHeaderBlock> headers_; | 122 scoped_ptr<SpdyHeaderBlock> headers_; |
| 127 base::StringPiece data_; | 123 base::StringPiece data_; |
| 128 }; | 124 }; |
| 129 | 125 |
| 130 // Test delegate that sends body data. | 126 // Test delegate that sends body data. |
| 131 class StreamDelegateWithBody : public StreamDelegateBase { | 127 class StreamDelegateWithBody : public StreamDelegateBase { |
| 132 public: | 128 public: |
| 133 StreamDelegateWithBody(const base::WeakPtr<SpdyStream>& stream, | 129 StreamDelegateWithBody(const base::WeakPtr<SpdyStream>& stream, |
| 134 base::StringPiece data); | 130 base::StringPiece data); |
| 135 virtual ~StreamDelegateWithBody(); | 131 virtual ~StreamDelegateWithBody(); |
| 136 | 132 |
| 137 virtual SpdySendStatus OnSendHeadersComplete() OVERRIDE; | 133 virtual SpdySendStatus OnSendHeadersComplete() OVERRIDE; |
| 138 virtual void OnSendBody() OVERRIDE; | 134 virtual void OnSendBody() OVERRIDE; |
| 139 virtual SpdySendStatus OnSendBodyComplete(size_t bytes_sent) OVERRIDE; | 135 virtual SpdySendStatus OnSendBodyComplete() OVERRIDE; |
| 140 | |
| 141 int body_data_sent() const { return body_data_sent_; } | |
| 142 | 136 |
| 143 private: | 137 private: |
| 144 scoped_refptr<DrainableIOBuffer> buf_; | 138 scoped_refptr<StringIOBuffer> buf_; |
| 145 int body_data_sent_; | |
| 146 }; | 139 }; |
| 147 | 140 |
| 148 } // namespace test | 141 } // namespace test |
| 149 | 142 |
| 150 } // namespace net | 143 } // namespace net |
| 151 | 144 |
| 152 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ | 145 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ |
| OLD | NEW |