| 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 void OnRequestHeadersSent() OVERRIDE; | 29 virtual void OnRequestHeadersSent() override; |
| 30 virtual SpdyResponseHeadersStatus OnResponseHeadersUpdated( | 30 virtual SpdyResponseHeadersStatus OnResponseHeadersUpdated( |
| 31 const SpdyHeaderBlock& response_headers) OVERRIDE; | 31 const SpdyHeaderBlock& response_headers) override; |
| 32 virtual void OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; | 32 virtual void OnDataReceived(scoped_ptr<SpdyBuffer> buffer) override; |
| 33 virtual void OnDataSent() OVERRIDE; | 33 virtual void OnDataSent() override; |
| 34 virtual void OnClose(int status) OVERRIDE; | 34 virtual void OnClose(int status) override; |
| 35 | 35 |
| 36 // Returns whether or not the stream is closed. | 36 // Returns whether or not the stream is closed. |
| 37 bool StreamIsClosed() const { return !stream_.get(); } | 37 bool StreamIsClosed() const { return !stream_.get(); } |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 base::WeakPtr<SpdyStream> stream_; | 40 base::WeakPtr<SpdyStream> stream_; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 // Base class with shared functionality for test delegate | 43 // Base class with shared functionality for test delegate |
| 44 // implementations below. | 44 // implementations below. |
| 45 class StreamDelegateBase : public SpdyStream::Delegate { | 45 class StreamDelegateBase : public SpdyStream::Delegate { |
| 46 public: | 46 public: |
| 47 explicit StreamDelegateBase(const base::WeakPtr<SpdyStream>& stream); | 47 explicit StreamDelegateBase(const base::WeakPtr<SpdyStream>& stream); |
| 48 virtual ~StreamDelegateBase(); | 48 virtual ~StreamDelegateBase(); |
| 49 | 49 |
| 50 virtual void OnRequestHeadersSent() OVERRIDE; | 50 virtual void OnRequestHeadersSent() override; |
| 51 virtual SpdyResponseHeadersStatus OnResponseHeadersUpdated( | 51 virtual SpdyResponseHeadersStatus OnResponseHeadersUpdated( |
| 52 const SpdyHeaderBlock& response_headers) OVERRIDE; | 52 const SpdyHeaderBlock& response_headers) override; |
| 53 virtual void OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; | 53 virtual void OnDataReceived(scoped_ptr<SpdyBuffer> buffer) override; |
| 54 virtual void OnDataSent() OVERRIDE; | 54 virtual void OnDataSent() override; |
| 55 virtual void OnClose(int status) OVERRIDE; | 55 virtual void OnClose(int status) override; |
| 56 | 56 |
| 57 // Waits for the stream to be closed and returns the status passed | 57 // Waits for the stream to be closed and returns the status passed |
| 58 // to OnClose(). | 58 // to OnClose(). |
| 59 int WaitForClose(); | 59 int WaitForClose(); |
| 60 | 60 |
| 61 // Drains all data from the underlying read queue and returns it as | 61 // Drains all data from the underlying read queue and returns it as |
| 62 // a string. | 62 // a string. |
| 63 std::string TakeReceivedData(); | 63 std::string TakeReceivedData(); |
| 64 | 64 |
| 65 // Returns whether or not the stream is closed. | 65 // Returns whether or not the stream is closed. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 94 | 94 |
| 95 // Test delegate that sends data immediately in OnResponseHeadersUpdated(). | 95 // Test delegate that sends data immediately in OnResponseHeadersUpdated(). |
| 96 class StreamDelegateSendImmediate : public StreamDelegateBase { | 96 class StreamDelegateSendImmediate : public StreamDelegateBase { |
| 97 public: | 97 public: |
| 98 // |data| can be NULL. | 98 // |data| can be NULL. |
| 99 StreamDelegateSendImmediate(const base::WeakPtr<SpdyStream>& stream, | 99 StreamDelegateSendImmediate(const base::WeakPtr<SpdyStream>& stream, |
| 100 base::StringPiece data); | 100 base::StringPiece data); |
| 101 virtual ~StreamDelegateSendImmediate(); | 101 virtual ~StreamDelegateSendImmediate(); |
| 102 | 102 |
| 103 virtual SpdyResponseHeadersStatus OnResponseHeadersUpdated( | 103 virtual SpdyResponseHeadersStatus OnResponseHeadersUpdated( |
| 104 const SpdyHeaderBlock& response_headers) OVERRIDE; | 104 const SpdyHeaderBlock& response_headers) override; |
| 105 | 105 |
| 106 private: | 106 private: |
| 107 base::StringPiece data_; | 107 base::StringPiece data_; |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 // Test delegate that sends body data. | 110 // Test delegate that sends body data. |
| 111 class StreamDelegateWithBody : public StreamDelegateBase { | 111 class StreamDelegateWithBody : public StreamDelegateBase { |
| 112 public: | 112 public: |
| 113 StreamDelegateWithBody(const base::WeakPtr<SpdyStream>& stream, | 113 StreamDelegateWithBody(const base::WeakPtr<SpdyStream>& stream, |
| 114 base::StringPiece data); | 114 base::StringPiece data); |
| 115 virtual ~StreamDelegateWithBody(); | 115 virtual ~StreamDelegateWithBody(); |
| 116 | 116 |
| 117 virtual void OnRequestHeadersSent() OVERRIDE; | 117 virtual void OnRequestHeadersSent() override; |
| 118 | 118 |
| 119 private: | 119 private: |
| 120 scoped_refptr<StringIOBuffer> buf_; | 120 scoped_refptr<StringIOBuffer> buf_; |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 // Test delegate that closes stream in OnResponseHeadersUpdated(). | 123 // Test delegate that closes stream in OnResponseHeadersUpdated(). |
| 124 class StreamDelegateCloseOnHeaders : public StreamDelegateBase { | 124 class StreamDelegateCloseOnHeaders : public StreamDelegateBase { |
| 125 public: | 125 public: |
| 126 StreamDelegateCloseOnHeaders(const base::WeakPtr<SpdyStream>& stream); | 126 StreamDelegateCloseOnHeaders(const base::WeakPtr<SpdyStream>& stream); |
| 127 virtual ~StreamDelegateCloseOnHeaders(); | 127 virtual ~StreamDelegateCloseOnHeaders(); |
| 128 | 128 |
| 129 virtual SpdyResponseHeadersStatus OnResponseHeadersUpdated( | 129 virtual SpdyResponseHeadersStatus OnResponseHeadersUpdated( |
| 130 const SpdyHeaderBlock& response_headers) OVERRIDE; | 130 const SpdyHeaderBlock& response_headers) override; |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 } // namespace test | 133 } // namespace test |
| 134 | 134 |
| 135 } // namespace net | 135 } // namespace net |
| 136 | 136 |
| 137 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ | 137 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ |
| OLD | NEW |