| 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_stream.h" | 15 #include "net/spdy/spdy_stream.h" |
| 15 | 16 |
| 16 namespace net { | 17 namespace net { |
| 17 | 18 |
| 18 namespace test { | 19 namespace test { |
| 19 | 20 |
| 20 // Delegate that calls Close() on |stream_| on OnClose. Used by tests | 21 // Delegate that calls Close() on |stream_| on OnClose. Used by tests |
| 21 // to make sure that such an action is harmless. | 22 // to make sure that such an action is harmless. |
| 22 class ClosingDelegate : public SpdyStream::Delegate { | 23 class ClosingDelegate : public SpdyStream::Delegate { |
| 23 public: | 24 public: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 int status) OVERRIDE; | 56 int status) OVERRIDE; |
| 56 virtual void OnHeadersSent() OVERRIDE; | 57 virtual void OnHeadersSent() OVERRIDE; |
| 57 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; | 58 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE; |
| 58 virtual void OnDataSent(size_t bytes_sent) OVERRIDE; | 59 virtual void OnDataSent(size_t bytes_sent) OVERRIDE; |
| 59 virtual void OnClose(int status) OVERRIDE; | 60 virtual void OnClose(int status) OVERRIDE; |
| 60 | 61 |
| 61 // Waits for the stream to be closed and returns the status passed | 62 // Waits for the stream to be closed and returns the status passed |
| 62 // to OnClose(). | 63 // to OnClose(). |
| 63 int WaitForClose(); | 64 int WaitForClose(); |
| 64 | 65 |
| 66 // Drains all data from the underlying read queue and returns it as |
| 67 // a string. |
| 68 std::string TakeReceivedData(); |
| 69 |
| 65 std::string GetResponseHeaderValue(const std::string& name) const; | 70 std::string GetResponseHeaderValue(const std::string& name) const; |
| 66 bool send_headers_completed() const { return send_headers_completed_; } | 71 bool send_headers_completed() const { return send_headers_completed_; } |
| 67 const std::string& received_data() const { return received_data_; } | |
| 68 int headers_sent() const { return headers_sent_; } | 72 int headers_sent() const { return headers_sent_; } |
| 69 int data_sent() const { return data_sent_; } | 73 int data_sent() const { return data_sent_; } |
| 70 | 74 |
| 71 protected: | 75 protected: |
| 72 const scoped_refptr<SpdyStream>& stream() { return stream_; } | 76 const scoped_refptr<SpdyStream>& stream() { return stream_; } |
| 73 | 77 |
| 74 private: | 78 private: |
| 75 scoped_refptr<SpdyStream> stream_; | 79 scoped_refptr<SpdyStream> stream_; |
| 76 TestCompletionCallback callback_; | 80 TestCompletionCallback callback_; |
| 77 bool send_headers_completed_; | 81 bool send_headers_completed_; |
| 78 SpdyHeaderBlock response_; | 82 SpdyHeaderBlock response_; |
| 79 std::string received_data_; | 83 SpdyReadQueue received_data_queue_; |
| 80 int headers_sent_; | 84 int headers_sent_; |
| 81 int data_sent_; | 85 int data_sent_; |
| 82 }; | 86 }; |
| 83 | 87 |
| 84 // Test delegate that sends data immediately in OnResponseReceived(). | 88 // Test delegate that sends data immediately in OnResponseReceived(). |
| 85 class StreamDelegateSendImmediate : public StreamDelegateBase { | 89 class StreamDelegateSendImmediate : public StreamDelegateBase { |
| 86 public: | 90 public: |
| 87 // Both |headers| and |buf| can be NULL. | 91 // Both |headers| and |buf| can be NULL. |
| 88 StreamDelegateSendImmediate(const scoped_refptr<SpdyStream>& stream, | 92 StreamDelegateSendImmediate(const scoped_refptr<SpdyStream>& stream, |
| 89 scoped_ptr<SpdyHeaderBlock> headers, | 93 scoped_ptr<SpdyHeaderBlock> headers, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 116 private: | 120 private: |
| 117 scoped_refptr<DrainableIOBuffer> buf_; | 121 scoped_refptr<DrainableIOBuffer> buf_; |
| 118 int body_data_sent_; | 122 int body_data_sent_; |
| 119 }; | 123 }; |
| 120 | 124 |
| 121 } // namespace test | 125 } // namespace test |
| 122 | 126 |
| 123 } // namespace net | 127 } // namespace net |
| 124 | 128 |
| 125 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ | 129 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ |
| OLD | NEW |