Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(531)

Side by Side Diff: net/spdy/spdy_stream_test_util.h

Issue 17382012: [SPDY] Refactor SpdyStream's handling of response headers (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More updates from rebase Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_stream.cc ('k') | net/spdy/spdy_stream_test_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 int OnResponseHeadersReceived(const SpdyHeaderBlock& response, 30 virtual SpdyResponseHeadersStatus OnResponseHeadersUpdated(
31 base::Time response_time, 31 const SpdyHeaderBlock& response_headers) OVERRIDE;
32 int status) OVERRIDE; 32 virtual void OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE;
33 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE;
34 virtual void OnDataSent() OVERRIDE; 33 virtual void OnDataSent() OVERRIDE;
35 virtual void OnClose(int status) OVERRIDE; 34 virtual void OnClose(int status) OVERRIDE;
36 35
37 // Returns whether or not the stream is closed. 36 // Returns whether or not the stream is closed.
38 bool StreamIsClosed() const { return !stream_.get(); } 37 bool StreamIsClosed() const { return !stream_.get(); }
39 38
40 private: 39 private:
41 base::WeakPtr<SpdyStream> stream_; 40 base::WeakPtr<SpdyStream> stream_;
42 }; 41 };
43 42
44 // Base class with shared functionality for test delegate 43 // Base class with shared functionality for test delegate
45 // implementations below. 44 // implementations below.
46 class StreamDelegateBase : public SpdyStream::Delegate { 45 class StreamDelegateBase : public SpdyStream::Delegate {
47 public: 46 public:
48 explicit StreamDelegateBase(const base::WeakPtr<SpdyStream>& stream); 47 explicit StreamDelegateBase(const base::WeakPtr<SpdyStream>& stream);
49 virtual ~StreamDelegateBase(); 48 virtual ~StreamDelegateBase();
50 49
51 virtual void OnRequestHeadersSent() OVERRIDE; 50 virtual void OnRequestHeadersSent() OVERRIDE;
52 virtual int OnResponseHeadersReceived(const SpdyHeaderBlock& response, 51 virtual SpdyResponseHeadersStatus OnResponseHeadersUpdated(
53 base::Time response_time, 52 const SpdyHeaderBlock& response_headers) OVERRIDE;
54 int status) OVERRIDE; 53 virtual void OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE;
55 virtual int OnDataReceived(scoped_ptr<SpdyBuffer> buffer) OVERRIDE;
56 virtual void OnDataSent() OVERRIDE; 54 virtual void OnDataSent() OVERRIDE;
57 virtual void OnClose(int status) OVERRIDE; 55 virtual void OnClose(int status) OVERRIDE;
58 56
59 // 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
60 // to OnClose(). 58 // to OnClose().
61 int WaitForClose(); 59 int WaitForClose();
62 60
63 // 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
64 // a string. 62 // a string.
65 std::string TakeReceivedData(); 63 std::string TakeReceivedData();
66 64
67 // Returns whether or not the stream is closed. 65 // Returns whether or not the stream is closed.
68 bool StreamIsClosed() const { return !stream_.get(); } 66 bool StreamIsClosed() const { return !stream_.get(); }
69 67
70 // Returns the stream's ID. If called when the stream is closed, 68 // Returns the stream's ID. If called when the stream is closed,
71 // returns the stream's ID when it was open. 69 // returns the stream's ID when it was open.
72 SpdyStreamId stream_id() const { return stream_id_; } 70 SpdyStreamId stream_id() const { return stream_id_; }
73 71
74 std::string GetResponseHeaderValue(const std::string& name) const; 72 std::string GetResponseHeaderValue(const std::string& name) const;
75 bool send_headers_completed() const { return send_headers_completed_; } 73 bool send_headers_completed() const { return send_headers_completed_; }
76 74
77 protected: 75 protected:
78 const base::WeakPtr<SpdyStream>& stream() { return stream_; } 76 const base::WeakPtr<SpdyStream>& stream() { return stream_; }
79 77
80 private: 78 private:
81 base::WeakPtr<SpdyStream> stream_; 79 base::WeakPtr<SpdyStream> stream_;
82 SpdyStreamId stream_id_; 80 SpdyStreamId stream_id_;
83 TestCompletionCallback callback_; 81 TestCompletionCallback callback_;
84 bool send_headers_completed_; 82 bool send_headers_completed_;
85 SpdyHeaderBlock response_; 83 SpdyHeaderBlock response_headers_;
86 SpdyReadQueue received_data_queue_; 84 SpdyReadQueue received_data_queue_;
87 }; 85 };
88 86
89 // Test delegate that does nothing. Used to capture data about the 87 // Test delegate that does nothing. Used to capture data about the
90 // stream, e.g. its id when it was open. 88 // stream, e.g. its id when it was open.
91 class StreamDelegateDoNothing : public StreamDelegateBase { 89 class StreamDelegateDoNothing : public StreamDelegateBase {
92 public: 90 public:
93 StreamDelegateDoNothing(const base::WeakPtr<SpdyStream>& stream); 91 StreamDelegateDoNothing(const base::WeakPtr<SpdyStream>& stream);
94 virtual ~StreamDelegateDoNothing(); 92 virtual ~StreamDelegateDoNothing();
95 }; 93 };
96 94
97 // Test delegate that sends data immediately in OnResponseHeadersReceived(). 95 // Test delegate that sends data immediately in OnResponseHeadersUpdated().
98 class StreamDelegateSendImmediate : public StreamDelegateBase { 96 class StreamDelegateSendImmediate : public StreamDelegateBase {
99 public: 97 public:
100 // |data| can be NULL. 98 // |data| can be NULL.
101 StreamDelegateSendImmediate(const base::WeakPtr<SpdyStream>& stream, 99 StreamDelegateSendImmediate(const base::WeakPtr<SpdyStream>& stream,
102 base::StringPiece data); 100 base::StringPiece data);
103 virtual ~StreamDelegateSendImmediate(); 101 virtual ~StreamDelegateSendImmediate();
104 102
105 virtual int OnResponseHeadersReceived(const SpdyHeaderBlock& response, 103 virtual SpdyResponseHeadersStatus OnResponseHeadersUpdated(
106 base::Time response_time, 104 const SpdyHeaderBlock& response_headers) OVERRIDE;
107 int status) 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 virtual ~StreamDelegateWithBody(); 115 virtual ~StreamDelegateWithBody();
119 116
120 virtual void OnRequestHeadersSent() OVERRIDE; 117 virtual void OnRequestHeadersSent() OVERRIDE;
121 118
122 private: 119 private:
123 scoped_refptr<StringIOBuffer> buf_; 120 scoped_refptr<StringIOBuffer> buf_;
124 }; 121 };
125 122
126 } // namespace test 123 } // namespace test
127 124
128 } // namespace net 125 } // namespace net
129 126
130 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ 127 #endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « net/spdy/spdy_stream.cc ('k') | net/spdy/spdy_stream_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698