| 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 <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 13 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
| 14 #include "net/base/test_completion_callback.h" | 14 #include "net/base/test_completion_callback.h" |
| 15 #include "net/spdy/spdy_read_queue.h" | 15 #include "net/spdy/spdy_read_queue.h" |
| 16 #include "net/spdy/spdy_stream.h" | 16 #include "net/spdy/spdy_stream.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 | 19 |
| 20 namespace test { | 20 namespace test { |
| 21 | 21 |
| 22 // Delegate that calls Close() on |stream_| on OnClose. Used by tests | 22 // Delegate that calls Close() on |stream_| on OnClose. Used by tests |
| 23 // to make sure that such an action is harmless. | 23 // to make sure that such an action is harmless. |
| 24 class ClosingDelegate : public SpdyStream::Delegate { | 24 class ClosingDelegate : public SpdyStream::Delegate { |
| 25 public: | 25 public: |
| 26 explicit ClosingDelegate(const base::WeakPtr<SpdyStream>& stream); | 26 explicit ClosingDelegate(const base::WeakPtr<SpdyStream>& stream); |
| 27 ~ClosingDelegate() override; | 27 ~ClosingDelegate() override; |
| 28 | 28 |
| 29 // SpdyStream::Delegate implementation. | 29 // SpdyStream::Delegate implementation. |
| 30 void OnRequestHeadersSent() override; | 30 void OnHeadersSent() override; |
| 31 SpdyResponseHeadersStatus OnResponseHeadersUpdated( | 31 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override; |
| 32 const SpdyHeaderBlock& response_headers) override; | |
| 33 void OnDataReceived(std::unique_ptr<SpdyBuffer> buffer) override; | 32 void OnDataReceived(std::unique_ptr<SpdyBuffer> buffer) override; |
| 34 void OnDataSent() override; | 33 void OnDataSent() override; |
| 35 void OnTrailers(const SpdyHeaderBlock& trailers) override; | 34 void OnTrailers(const SpdyHeaderBlock& trailers) override; |
| 36 void OnClose(int status) override; | 35 void OnClose(int status) override; |
| 37 | 36 |
| 38 // Returns whether or not the stream is closed. | 37 // Returns whether or not the stream is closed. |
| 39 bool StreamIsClosed() const { return !stream_.get(); } | 38 bool StreamIsClosed() const { return !stream_.get(); } |
| 40 | 39 |
| 41 private: | 40 private: |
| 42 base::WeakPtr<SpdyStream> stream_; | 41 base::WeakPtr<SpdyStream> stream_; |
| 43 }; | 42 }; |
| 44 | 43 |
| 45 // Base class with shared functionality for test delegate | 44 // Base class with shared functionality for test delegate |
| 46 // implementations below. | 45 // implementations below. |
| 47 class StreamDelegateBase : public SpdyStream::Delegate { | 46 class StreamDelegateBase : public SpdyStream::Delegate { |
| 48 public: | 47 public: |
| 49 explicit StreamDelegateBase(const base::WeakPtr<SpdyStream>& stream); | 48 explicit StreamDelegateBase(const base::WeakPtr<SpdyStream>& stream); |
| 50 ~StreamDelegateBase() override; | 49 ~StreamDelegateBase() override; |
| 51 | 50 |
| 52 void OnRequestHeadersSent() override; | 51 void OnHeadersSent() override; |
| 53 SpdyResponseHeadersStatus OnResponseHeadersUpdated( | 52 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override; |
| 54 const SpdyHeaderBlock& response_headers) override; | |
| 55 void OnDataReceived(std::unique_ptr<SpdyBuffer> buffer) override; | 53 void OnDataReceived(std::unique_ptr<SpdyBuffer> buffer) override; |
| 56 void OnDataSent() override; | 54 void OnDataSent() override; |
| 57 void OnTrailers(const SpdyHeaderBlock& trailers) override; | 55 void OnTrailers(const SpdyHeaderBlock& trailers) override; |
| 58 void OnClose(int status) override; | 56 void OnClose(int status) override; |
| 59 | 57 |
| 60 // Waits for the stream to be closed and returns the status passed | 58 // Waits for the stream to be closed and returns the status passed |
| 61 // to OnClose(). | 59 // to OnClose(). |
| 62 int WaitForClose(); | 60 int WaitForClose(); |
| 63 | 61 |
| 64 // Drains all data from the underlying read queue and returns it as | 62 // Drains all data from the underlying read queue and returns it as |
| (...skipping 23 matching lines...) Expand all Loading... |
| 88 }; | 86 }; |
| 89 | 87 |
| 90 // Test delegate that does nothing. Used to capture data about the | 88 // Test delegate that does nothing. Used to capture data about the |
| 91 // stream, e.g. its id when it was open. | 89 // stream, e.g. its id when it was open. |
| 92 class StreamDelegateDoNothing : public StreamDelegateBase { | 90 class StreamDelegateDoNothing : public StreamDelegateBase { |
| 93 public: | 91 public: |
| 94 explicit StreamDelegateDoNothing(const base::WeakPtr<SpdyStream>& stream); | 92 explicit StreamDelegateDoNothing(const base::WeakPtr<SpdyStream>& stream); |
| 95 ~StreamDelegateDoNothing() override; | 93 ~StreamDelegateDoNothing() override; |
| 96 }; | 94 }; |
| 97 | 95 |
| 98 // Test delegate that sends data immediately in OnResponseHeadersUpdated(). | 96 // Test delegate that sends data immediately in OnHeadersReceived(). |
| 99 class StreamDelegateSendImmediate : public StreamDelegateBase { | 97 class StreamDelegateSendImmediate : public StreamDelegateBase { |
| 100 public: | 98 public: |
| 101 // |data| can be NULL. | 99 // |data| can be NULL. |
| 102 StreamDelegateSendImmediate(const base::WeakPtr<SpdyStream>& stream, | 100 StreamDelegateSendImmediate(const base::WeakPtr<SpdyStream>& stream, |
| 103 base::StringPiece data); | 101 base::StringPiece data); |
| 104 ~StreamDelegateSendImmediate() override; | 102 ~StreamDelegateSendImmediate() override; |
| 105 | 103 |
| 106 SpdyResponseHeadersStatus OnResponseHeadersUpdated( | 104 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override; |
| 107 const SpdyHeaderBlock& response_headers) override; | |
| 108 | 105 |
| 109 private: | 106 private: |
| 110 base::StringPiece data_; | 107 base::StringPiece data_; |
| 111 }; | 108 }; |
| 112 | 109 |
| 113 // Test delegate that sends body data. | 110 // Test delegate that sends body data. |
| 114 class StreamDelegateWithBody : public StreamDelegateBase { | 111 class StreamDelegateWithBody : public StreamDelegateBase { |
| 115 public: | 112 public: |
| 116 StreamDelegateWithBody(const base::WeakPtr<SpdyStream>& stream, | 113 StreamDelegateWithBody(const base::WeakPtr<SpdyStream>& stream, |
| 117 base::StringPiece data); | 114 base::StringPiece data); |
| 118 ~StreamDelegateWithBody() override; | 115 ~StreamDelegateWithBody() override; |
| 119 | 116 |
| 120 void OnRequestHeadersSent() override; | 117 void OnHeadersSent() override; |
| 121 | 118 |
| 122 private: | 119 private: |
| 123 scoped_refptr<StringIOBuffer> buf_; | 120 scoped_refptr<StringIOBuffer> buf_; |
| 124 }; | 121 }; |
| 125 | 122 |
| 126 // Test delegate that closes stream in OnResponseHeadersUpdated(). | 123 // Test delegate that closes stream in OnHeadersReceived(). |
| 127 class StreamDelegateCloseOnHeaders : public StreamDelegateBase { | 124 class StreamDelegateCloseOnHeaders : public StreamDelegateBase { |
| 128 public: | 125 public: |
| 129 explicit StreamDelegateCloseOnHeaders( | 126 explicit StreamDelegateCloseOnHeaders( |
| 130 const base::WeakPtr<SpdyStream>& stream); | 127 const base::WeakPtr<SpdyStream>& stream); |
| 131 ~StreamDelegateCloseOnHeaders() override; | 128 ~StreamDelegateCloseOnHeaders() override; |
| 132 | 129 |
| 133 SpdyResponseHeadersStatus OnResponseHeadersUpdated( | 130 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override; |
| 134 const SpdyHeaderBlock& response_headers) override; | |
| 135 }; | 131 }; |
| 136 | 132 |
| 137 } // namespace test | 133 } // namespace test |
| 138 | 134 |
| 139 } // namespace net | 135 } // namespace net |
| 140 | 136 |
| 141 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ | 137 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ |
| OLD | NEW |