| 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 #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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 ClosingDelegate::~ClosingDelegate() {} | 21 ClosingDelegate::~ClosingDelegate() {} |
| 22 | 22 |
| 23 SpdySendStatus ClosingDelegate::OnSendHeadersComplete() { | 23 SpdySendStatus ClosingDelegate::OnSendHeadersComplete() { |
| 24 return NO_MORE_DATA_TO_SEND; | 24 return NO_MORE_DATA_TO_SEND; |
| 25 } | 25 } |
| 26 | 26 |
| 27 void ClosingDelegate::OnSendBody() { | 27 void ClosingDelegate::OnSendBody() { |
| 28 ADD_FAILURE() << "OnSendBody should not be called"; | 28 ADD_FAILURE() << "OnSendBody should not be called"; |
| 29 } | 29 } |
| 30 | 30 |
| 31 SpdySendStatus ClosingDelegate::OnSendBodyComplete(size_t /*bytes_sent*/) { | 31 SpdySendStatus ClosingDelegate::OnSendBodyComplete() { |
| 32 return NO_MORE_DATA_TO_SEND; | 32 return NO_MORE_DATA_TO_SEND; |
| 33 } | 33 } |
| 34 | 34 |
| 35 int ClosingDelegate::OnResponseReceived(const SpdyHeaderBlock& response, | 35 int ClosingDelegate::OnResponseReceived(const SpdyHeaderBlock& response, |
| 36 base::Time response_time, | 36 base::Time response_time, |
| 37 int status) { | 37 int status) { |
| 38 return OK; | 38 return OK; |
| 39 } | 39 } |
| 40 | 40 |
| 41 void ClosingDelegate::OnHeadersSent() {} | 41 void ClosingDelegate::OnHeadersSent() {} |
| 42 | 42 |
| 43 int ClosingDelegate::OnDataReceived(scoped_ptr<SpdyBuffer> buffer) { | 43 int ClosingDelegate::OnDataReceived(scoped_ptr<SpdyBuffer> buffer) { |
| 44 return OK; | 44 return OK; |
| 45 } | 45 } |
| 46 | 46 |
| 47 void ClosingDelegate::OnDataSent(size_t bytes_sent) {} | 47 void ClosingDelegate::OnDataSent() {} |
| 48 | 48 |
| 49 void ClosingDelegate::OnClose(int status) { | 49 void ClosingDelegate::OnClose(int status) { |
| 50 DCHECK(stream_); | 50 DCHECK(stream_); |
| 51 stream_->Close(); | 51 stream_->Close(); |
| 52 DCHECK(!stream_); | 52 DCHECK(!stream_); |
| 53 } | 53 } |
| 54 | 54 |
| 55 StreamDelegateBase::StreamDelegateBase( | 55 StreamDelegateBase::StreamDelegateBase( |
| 56 const base::WeakPtr<SpdyStream>& stream) | 56 const base::WeakPtr<SpdyStream>& stream) |
| 57 : stream_(stream), | 57 : stream_(stream), |
| 58 stream_id_(0), | 58 stream_id_(0), |
| 59 send_headers_completed_(false), | 59 send_headers_completed_(false) { |
| 60 headers_sent_(0), | |
| 61 data_sent_(0) { | |
| 62 } | 60 } |
| 63 | 61 |
| 64 StreamDelegateBase::~StreamDelegateBase() { | 62 StreamDelegateBase::~StreamDelegateBase() { |
| 65 } | 63 } |
| 66 | 64 |
| 67 SpdySendStatus StreamDelegateBase::OnSendHeadersComplete() { | 65 SpdySendStatus StreamDelegateBase::OnSendHeadersComplete() { |
| 68 stream_id_ = stream_->stream_id(); | 66 stream_id_ = stream_->stream_id(); |
| 69 EXPECT_NE(stream_id_, 0u); | 67 EXPECT_NE(stream_id_, 0u); |
| 70 send_headers_completed_ = true; | 68 send_headers_completed_ = true; |
| 71 return NO_MORE_DATA_TO_SEND; | 69 return NO_MORE_DATA_TO_SEND; |
| 72 } | 70 } |
| 73 | 71 |
| 74 int StreamDelegateBase::OnResponseReceived(const SpdyHeaderBlock& response, | 72 int StreamDelegateBase::OnResponseReceived(const SpdyHeaderBlock& response, |
| 75 base::Time response_time, | 73 base::Time response_time, |
| 76 int status) { | 74 int status) { |
| 77 EXPECT_TRUE(send_headers_completed_); | 75 EXPECT_TRUE(send_headers_completed_); |
| 78 response_ = response; | 76 response_ = response; |
| 79 return status; | 77 return status; |
| 80 } | 78 } |
| 81 | 79 |
| 82 void StreamDelegateBase::OnHeadersSent() { | 80 void StreamDelegateBase::OnHeadersSent() {} |
| 83 headers_sent_++; | |
| 84 } | |
| 85 | 81 |
| 86 int StreamDelegateBase::OnDataReceived(scoped_ptr<SpdyBuffer> buffer) { | 82 int StreamDelegateBase::OnDataReceived(scoped_ptr<SpdyBuffer> buffer) { |
| 87 if (buffer) | 83 if (buffer) |
| 88 received_data_queue_.Enqueue(buffer.Pass()); | 84 received_data_queue_.Enqueue(buffer.Pass()); |
| 89 return OK; | 85 return OK; |
| 90 } | 86 } |
| 91 | 87 |
| 92 void StreamDelegateBase::OnDataSent(size_t bytes_sent) { | 88 void StreamDelegateBase::OnDataSent() {} |
| 93 data_sent_ += bytes_sent; | |
| 94 } | |
| 95 | 89 |
| 96 void StreamDelegateBase::OnClose(int status) { | 90 void StreamDelegateBase::OnClose(int status) { |
| 97 if (!stream_) | 91 if (!stream_) |
| 98 return; | 92 return; |
| 99 stream_id_ = stream_->stream_id(); | 93 stream_id_ = stream_->stream_id(); |
| 100 stream_.reset(); | 94 stream_.reset(); |
| 101 callback_.callback().Run(status); | 95 callback_.callback().Run(status); |
| 102 } | 96 } |
| 103 | 97 |
| 104 int StreamDelegateBase::WaitForClose() { | 98 int StreamDelegateBase::WaitForClose() { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 128 const base::WeakPtr<SpdyStream>& stream) | 122 const base::WeakPtr<SpdyStream>& stream) |
| 129 : StreamDelegateBase(stream) {} | 123 : StreamDelegateBase(stream) {} |
| 130 | 124 |
| 131 StreamDelegateDoNothing::~StreamDelegateDoNothing() { | 125 StreamDelegateDoNothing::~StreamDelegateDoNothing() { |
| 132 } | 126 } |
| 133 | 127 |
| 134 void StreamDelegateDoNothing::OnSendBody() { | 128 void StreamDelegateDoNothing::OnSendBody() { |
| 135 ADD_FAILURE() << "OnSendBody should not be called"; | 129 ADD_FAILURE() << "OnSendBody should not be called"; |
| 136 } | 130 } |
| 137 | 131 |
| 138 SpdySendStatus StreamDelegateDoNothing::OnSendBodyComplete( | 132 SpdySendStatus StreamDelegateDoNothing::OnSendBodyComplete() { |
| 139 size_t /*bytes_sent*/) { | |
| 140 return NO_MORE_DATA_TO_SEND; | 133 return NO_MORE_DATA_TO_SEND; |
| 141 } | 134 } |
| 142 | 135 |
| 143 StreamDelegateSendImmediate::StreamDelegateSendImmediate( | 136 StreamDelegateSendImmediate::StreamDelegateSendImmediate( |
| 144 const base::WeakPtr<SpdyStream>& stream, | 137 const base::WeakPtr<SpdyStream>& stream, |
| 145 scoped_ptr<SpdyHeaderBlock> headers, | 138 scoped_ptr<SpdyHeaderBlock> headers, |
| 146 base::StringPiece data) | 139 base::StringPiece data) |
| 147 : StreamDelegateBase(stream), | 140 : StreamDelegateBase(stream), |
| 148 headers_(headers.Pass()), | 141 headers_(headers.Pass()), |
| 149 data_(data) {} | 142 data_(data) {} |
| 150 | 143 |
| 151 StreamDelegateSendImmediate::~StreamDelegateSendImmediate() { | 144 StreamDelegateSendImmediate::~StreamDelegateSendImmediate() { |
| 152 } | 145 } |
| 153 | 146 |
| 154 void StreamDelegateSendImmediate::OnSendBody() { | 147 void StreamDelegateSendImmediate::OnSendBody() { |
| 155 ADD_FAILURE() << "OnSendBody should not be called"; | 148 ADD_FAILURE() << "OnSendBody should not be called"; |
| 156 } | 149 } |
| 157 | 150 |
| 158 SpdySendStatus StreamDelegateSendImmediate::OnSendBodyComplete( | 151 SpdySendStatus StreamDelegateSendImmediate::OnSendBodyComplete() { |
| 159 size_t /*bytes_sent*/) { | |
| 160 ADD_FAILURE() << "OnSendBodyComplete should not be called"; | 152 ADD_FAILURE() << "OnSendBodyComplete should not be called"; |
| 161 return NO_MORE_DATA_TO_SEND; | 153 return NO_MORE_DATA_TO_SEND; |
| 162 } | 154 } |
| 163 | 155 |
| 164 int StreamDelegateSendImmediate::OnResponseReceived( | 156 int StreamDelegateSendImmediate::OnResponseReceived( |
| 165 const SpdyHeaderBlock& response, | 157 const SpdyHeaderBlock& response, |
| 166 base::Time response_time, | 158 base::Time response_time, |
| 167 int status) { | 159 int status) { |
| 168 status = | 160 status = |
| 169 StreamDelegateBase::OnResponseReceived(response, response_time, status); | 161 StreamDelegateBase::OnResponseReceived(response, response_time, status); |
| 170 if (headers_.get()) { | 162 if (headers_.get()) { |
| 171 stream()->QueueHeaders(headers_.Pass()); | 163 stream()->SendHeaders(headers_.Pass()); |
| 172 } | 164 } |
| 173 if (data_.data()) { | 165 if (data_.data()) { |
| 174 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(data_.as_string())); | 166 scoped_refptr<StringIOBuffer> buf(new StringIOBuffer(data_.as_string())); |
| 175 stream()->QueueStreamData(buf, buf->size(), DATA_FLAG_NONE); | 167 stream()->SendStreamData(buf, buf->size(), DATA_FLAG_NONE); |
| 176 } | 168 } |
| 177 return status; | 169 return status; |
| 178 } | 170 } |
| 179 | 171 |
| 180 StreamDelegateWithBody::StreamDelegateWithBody( | 172 StreamDelegateWithBody::StreamDelegateWithBody( |
| 181 const base::WeakPtr<SpdyStream>& stream, | 173 const base::WeakPtr<SpdyStream>& stream, |
| 182 base::StringPiece data) | 174 base::StringPiece data) |
| 183 : StreamDelegateBase(stream), | 175 : StreamDelegateBase(stream), |
| 184 buf_(new DrainableIOBuffer(new StringIOBuffer(data.as_string()), | 176 buf_(new StringIOBuffer(data.as_string())) {} |
| 185 data.size())), | |
| 186 body_data_sent_(0) {} | |
| 187 | 177 |
| 188 StreamDelegateWithBody::~StreamDelegateWithBody() { | 178 StreamDelegateWithBody::~StreamDelegateWithBody() { |
| 189 } | 179 } |
| 190 | 180 |
| 191 SpdySendStatus StreamDelegateWithBody::OnSendHeadersComplete() { | 181 SpdySendStatus StreamDelegateWithBody::OnSendHeadersComplete() { |
| 192 StreamDelegateBase::OnSendHeadersComplete(); | 182 StreamDelegateBase::OnSendHeadersComplete(); |
| 193 return MORE_DATA_TO_SEND; | 183 return MORE_DATA_TO_SEND; |
| 194 } | 184 } |
| 195 | 185 |
| 196 void StreamDelegateWithBody::OnSendBody() { | 186 void StreamDelegateWithBody::OnSendBody() { |
| 197 stream()->QueueStreamData(buf_.get(), buf_->BytesRemaining(), | 187 stream()->SendStreamData(buf_.get(), buf_->size(), DATA_FLAG_NONE); |
| 198 DATA_FLAG_NONE); | |
| 199 } | 188 } |
| 200 | 189 |
| 201 SpdySendStatus StreamDelegateWithBody::OnSendBodyComplete(size_t bytes_sent) { | 190 SpdySendStatus StreamDelegateWithBody::OnSendBodyComplete() { |
| 202 EXPECT_GT(bytes_sent, 0u); | |
| 203 | |
| 204 buf_->DidConsume(bytes_sent); | |
| 205 body_data_sent_ += bytes_sent; | |
| 206 if (buf_->BytesRemaining() > 0) { | |
| 207 // Go back to OnSendBody() to send the remaining data. | |
| 208 return MORE_DATA_TO_SEND; | |
| 209 } | |
| 210 | |
| 211 return NO_MORE_DATA_TO_SEND; | 191 return NO_MORE_DATA_TO_SEND; |
| 212 } | 192 } |
| 213 | 193 |
| 214 } // namespace test | 194 } // namespace test |
| 215 | 195 |
| 216 } // namespace net | 196 } // namespace net |
| OLD | NEW |