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

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

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, 5 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_test_util.h ('k') | net/spdy/spdy_stream_unittest.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 #include "net/spdy/spdy_stream_test_util.h" 5 #include "net/spdy/spdy_stream_test_util.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "net/base/completion_callback.h" 10 #include "net/base/completion_callback.h"
11 #include "net/spdy/spdy_stream.h" 11 #include "net/spdy/spdy_stream.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 namespace net { 14 namespace net {
15 15
16 namespace test { 16 namespace test {
17 17
18 ClosingDelegate::ClosingDelegate( 18 ClosingDelegate::ClosingDelegate(
19 const base::WeakPtr<SpdyStream>& stream) : stream_(stream) {} 19 const base::WeakPtr<SpdyStream>& stream) : stream_(stream) {}
20 20
21 ClosingDelegate::~ClosingDelegate() {} 21 ClosingDelegate::~ClosingDelegate() {}
22 22
23 void ClosingDelegate::OnRequestHeadersSent() {} 23 void ClosingDelegate::OnRequestHeadersSent() {}
24 24
25 int ClosingDelegate::OnResponseHeadersReceived(const SpdyHeaderBlock& response, 25 SpdyResponseHeadersStatus ClosingDelegate::OnResponseHeadersUpdated(
26 base::Time response_time, 26 const SpdyHeaderBlock& response_headers) {
27 int status) { 27 return RESPONSE_HEADERS_ARE_COMPLETE;
28 return OK;
29 } 28 }
30 29
31 int ClosingDelegate::OnDataReceived(scoped_ptr<SpdyBuffer> buffer) { 30 void ClosingDelegate::OnDataReceived(scoped_ptr<SpdyBuffer> buffer) {}
32 return OK;
33 }
34 31
35 void ClosingDelegate::OnDataSent() {} 32 void ClosingDelegate::OnDataSent() {}
36 33
37 void ClosingDelegate::OnClose(int status) { 34 void ClosingDelegate::OnClose(int status) {
38 DCHECK(stream_.get()); 35 DCHECK(stream_.get());
39 stream_->Close(); 36 stream_->Close();
40 DCHECK(!stream_.get()); 37 DCHECK(!stream_.get());
41 } 38 }
42 39
43 StreamDelegateBase::StreamDelegateBase( 40 StreamDelegateBase::StreamDelegateBase(
44 const base::WeakPtr<SpdyStream>& stream) 41 const base::WeakPtr<SpdyStream>& stream)
45 : stream_(stream), 42 : stream_(stream),
46 stream_id_(0), 43 stream_id_(0),
47 send_headers_completed_(false) { 44 send_headers_completed_(false) {
48 } 45 }
49 46
50 StreamDelegateBase::~StreamDelegateBase() { 47 StreamDelegateBase::~StreamDelegateBase() {
51 } 48 }
52 49
53 void StreamDelegateBase::OnRequestHeadersSent() { 50 void StreamDelegateBase::OnRequestHeadersSent() {
54 stream_id_ = stream_->stream_id(); 51 stream_id_ = stream_->stream_id();
55 EXPECT_NE(stream_id_, 0u); 52 EXPECT_NE(stream_id_, 0u);
56 send_headers_completed_ = true; 53 send_headers_completed_ = true;
57 } 54 }
58 55
59 int StreamDelegateBase::OnResponseHeadersReceived( 56 SpdyResponseHeadersStatus StreamDelegateBase::OnResponseHeadersUpdated(
60 const SpdyHeaderBlock& response, 57 const SpdyHeaderBlock& response_headers) {
61 base::Time response_time, 58 EXPECT_EQ(stream_->type() != SPDY_PUSH_STREAM, send_headers_completed_);
62 int status) { 59 response_headers_ = response_headers;
63 EXPECT_TRUE(send_headers_completed_); 60 return RESPONSE_HEADERS_ARE_COMPLETE;
64 response_ = response;
65 return status;
66 } 61 }
67 62
68 int StreamDelegateBase::OnDataReceived(scoped_ptr<SpdyBuffer> buffer) { 63 void StreamDelegateBase::OnDataReceived(scoped_ptr<SpdyBuffer> buffer) {
69 if (buffer) 64 if (buffer)
70 received_data_queue_.Enqueue(buffer.Pass()); 65 received_data_queue_.Enqueue(buffer.Pass());
71 return OK;
72 } 66 }
73 67
74 void StreamDelegateBase::OnDataSent() {} 68 void StreamDelegateBase::OnDataSent() {}
75 69
76 void StreamDelegateBase::OnClose(int status) { 70 void StreamDelegateBase::OnClose(int status) {
77 if (!stream_.get()) 71 if (!stream_.get())
78 return; 72 return;
79 stream_id_ = stream_->stream_id(); 73 stream_id_ = stream_->stream_id();
80 stream_.reset(); 74 stream_.reset();
81 callback_.callback().Run(status); 75 callback_.callback().Run(status);
(...skipping 11 matching lines...) Expand all
93 if (len > 0) { 87 if (len > 0) {
94 EXPECT_EQ( 88 EXPECT_EQ(
95 len, 89 len,
96 received_data_queue_.Dequeue(string_as_array(&received_data), len)); 90 received_data_queue_.Dequeue(string_as_array(&received_data), len));
97 } 91 }
98 return received_data; 92 return received_data;
99 } 93 }
100 94
101 std::string StreamDelegateBase::GetResponseHeaderValue( 95 std::string StreamDelegateBase::GetResponseHeaderValue(
102 const std::string& name) const { 96 const std::string& name) const {
103 SpdyHeaderBlock::const_iterator it = response_.find(name); 97 SpdyHeaderBlock::const_iterator it = response_headers_.find(name);
104 return (it == response_.end()) ? std::string() : it->second; 98 return (it == response_headers_.end()) ? std::string() : it->second;
105 } 99 }
106 100
107 StreamDelegateDoNothing::StreamDelegateDoNothing( 101 StreamDelegateDoNothing::StreamDelegateDoNothing(
108 const base::WeakPtr<SpdyStream>& stream) 102 const base::WeakPtr<SpdyStream>& stream)
109 : StreamDelegateBase(stream) {} 103 : StreamDelegateBase(stream) {}
110 104
111 StreamDelegateDoNothing::~StreamDelegateDoNothing() { 105 StreamDelegateDoNothing::~StreamDelegateDoNothing() {
112 } 106 }
113 107
114 StreamDelegateSendImmediate::StreamDelegateSendImmediate( 108 StreamDelegateSendImmediate::StreamDelegateSendImmediate(
115 const base::WeakPtr<SpdyStream>& stream, 109 const base::WeakPtr<SpdyStream>& stream,
116 base::StringPiece data) 110 base::StringPiece data)
117 : StreamDelegateBase(stream), 111 : StreamDelegateBase(stream),
118 data_(data) {} 112 data_(data) {}
119 113
120 StreamDelegateSendImmediate::~StreamDelegateSendImmediate() { 114 StreamDelegateSendImmediate::~StreamDelegateSendImmediate() {
121 } 115 }
122 116
123 int StreamDelegateSendImmediate::OnResponseHeadersReceived( 117 SpdyResponseHeadersStatus StreamDelegateSendImmediate::OnResponseHeadersUpdated(
124 const SpdyHeaderBlock& response, 118 const SpdyHeaderBlock& response_headers) {
125 base::Time response_time, 119 SpdyResponseHeadersStatus status =
126 int status) { 120 StreamDelegateBase::OnResponseHeadersUpdated(response_headers);
127 status =
128 StreamDelegateBase::OnResponseHeadersReceived(
129 response, response_time, status);
130 if (data_.data()) { 121 if (data_.data()) {
131 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(data_.as_string())); 122 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(data_.as_string()));
132 stream()->SendData(buf.get(), buf->size(), MORE_DATA_TO_SEND); 123 stream()->SendData(buf.get(), buf->size(), MORE_DATA_TO_SEND);
133 } 124 }
134 return status; 125 return status;
135 } 126 }
136 127
137 StreamDelegateWithBody::StreamDelegateWithBody( 128 StreamDelegateWithBody::StreamDelegateWithBody(
138 const base::WeakPtr<SpdyStream>& stream, 129 const base::WeakPtr<SpdyStream>& stream,
139 base::StringPiece data) 130 base::StringPiece data)
140 : StreamDelegateBase(stream), 131 : StreamDelegateBase(stream),
141 buf_(new StringIOBuffer(data.as_string())) {} 132 buf_(new StringIOBuffer(data.as_string())) {}
142 133
143 StreamDelegateWithBody::~StreamDelegateWithBody() { 134 StreamDelegateWithBody::~StreamDelegateWithBody() {
144 } 135 }
145 136
146 void StreamDelegateWithBody::OnRequestHeadersSent() { 137 void StreamDelegateWithBody::OnRequestHeadersSent() {
147 StreamDelegateBase::OnRequestHeadersSent(); 138 StreamDelegateBase::OnRequestHeadersSent();
148 stream()->SendData(buf_.get(), buf_->size(), NO_MORE_DATA_TO_SEND); 139 stream()->SendData(buf_.get(), buf_->size(), NO_MORE_DATA_TO_SEND);
149 } 140 }
150 141
151 } // namespace test 142 } // namespace test
152 143
153 } // namespace net 144 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_stream_test_util.h ('k') | net/spdy/spdy_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698