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 "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/log/net_log_source.h" |
14 #include "net/spdy/platform/api/spdy_string_piece.h" | 15 #include "net/spdy/platform/api/spdy_string_piece.h" |
15 #include "net/spdy/spdy_read_queue.h" | 16 #include "net/spdy/spdy_read_queue.h" |
16 #include "net/spdy/spdy_stream.h" | 17 #include "net/spdy/spdy_stream.h" |
17 | 18 |
18 namespace net { | 19 namespace net { |
19 | 20 |
20 namespace test { | 21 namespace test { |
21 | 22 |
22 // Delegate that calls Close() on |stream_| on OnClose. Used by tests | 23 // Delegate that calls Close() on |stream_| on OnClose. Used by tests |
23 // to make sure that such an action is harmless. | 24 // to make sure that such an action is harmless. |
24 class ClosingDelegate : public SpdyStream::Delegate { | 25 class ClosingDelegate : public SpdyStream::Delegate { |
25 public: | 26 public: |
26 explicit ClosingDelegate(const base::WeakPtr<SpdyStream>& stream); | 27 explicit ClosingDelegate(const base::WeakPtr<SpdyStream>& stream); |
27 ~ClosingDelegate() override; | 28 ~ClosingDelegate() override; |
28 | 29 |
29 // SpdyStream::Delegate implementation. | 30 // SpdyStream::Delegate implementation. |
30 void OnHeadersSent() override; | 31 void OnHeadersSent() override; |
31 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override; | 32 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override; |
32 void OnDataReceived(std::unique_ptr<SpdyBuffer> buffer) override; | 33 void OnDataReceived(std::unique_ptr<SpdyBuffer> buffer) override; |
33 void OnDataSent() override; | 34 void OnDataSent() override; |
34 void OnTrailers(const SpdyHeaderBlock& trailers) override; | 35 void OnTrailers(const SpdyHeaderBlock& trailers) override; |
35 void OnClose(int status) override; | 36 void OnClose(int status) override; |
| 37 NetLogSource source_dependency() const override; |
36 | 38 |
37 // Returns whether or not the stream is closed. | 39 // Returns whether or not the stream is closed. |
38 bool StreamIsClosed() const { return !stream_.get(); } | 40 bool StreamIsClosed() const { return !stream_.get(); } |
39 | 41 |
40 private: | 42 private: |
41 base::WeakPtr<SpdyStream> stream_; | 43 base::WeakPtr<SpdyStream> stream_; |
42 }; | 44 }; |
43 | 45 |
44 // Base class with shared functionality for test delegate | 46 // Base class with shared functionality for test delegate |
45 // implementations below. | 47 // implementations below. |
46 class StreamDelegateBase : public SpdyStream::Delegate { | 48 class StreamDelegateBase : public SpdyStream::Delegate { |
47 public: | 49 public: |
48 explicit StreamDelegateBase(const base::WeakPtr<SpdyStream>& stream); | 50 explicit StreamDelegateBase(const base::WeakPtr<SpdyStream>& stream); |
49 ~StreamDelegateBase() override; | 51 ~StreamDelegateBase() override; |
50 | 52 |
51 void OnHeadersSent() override; | 53 void OnHeadersSent() override; |
52 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override; | 54 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override; |
53 void OnDataReceived(std::unique_ptr<SpdyBuffer> buffer) override; | 55 void OnDataReceived(std::unique_ptr<SpdyBuffer> buffer) override; |
54 void OnDataSent() override; | 56 void OnDataSent() override; |
55 void OnTrailers(const SpdyHeaderBlock& trailers) override; | 57 void OnTrailers(const SpdyHeaderBlock& trailers) override; |
56 void OnClose(int status) override; | 58 void OnClose(int status) override; |
| 59 NetLogSource source_dependency() const override; |
57 | 60 |
58 // Waits for the stream to be closed and returns the status passed | 61 // Waits for the stream to be closed and returns the status passed |
59 // to OnClose(). | 62 // to OnClose(). |
60 int WaitForClose(); | 63 int WaitForClose(); |
61 | 64 |
62 // Drains all data from the underlying read queue and returns it as | 65 // Drains all data from the underlying read queue and returns it as |
63 // a string. | 66 // a string. |
64 std::string TakeReceivedData(); | 67 std::string TakeReceivedData(); |
65 | 68 |
66 // Returns whether or not the stream is closed. | 69 // Returns whether or not the stream is closed. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 ~StreamDelegateCloseOnHeaders() override; | 131 ~StreamDelegateCloseOnHeaders() override; |
129 | 132 |
130 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override; | 133 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override; |
131 }; | 134 }; |
132 | 135 |
133 } // namespace test | 136 } // namespace test |
134 | 137 |
135 } // namespace net | 138 } // namespace net |
136 | 139 |
137 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ | 140 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ |
OLD | NEW |