| 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" |
| 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 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 int ClosingDelegate::OnSendBody() { | 27 void ClosingDelegate::OnSendBody() { |
| 28 return OK; | 28 ADD_FAILURE() << "OnSendBody should not be called"; |
| 29 } | 29 } |
| 30 | 30 |
| 31 SpdySendStatus ClosingDelegate::OnSendBodyComplete(size_t /*bytes_sent*/) { | 31 SpdySendStatus ClosingDelegate::OnSendBodyComplete(size_t /*bytes_sent*/) { |
| 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; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 return (it == response_.end()) ? std::string() : it->second; | 124 return (it == response_.end()) ? std::string() : it->second; |
| 125 } | 125 } |
| 126 | 126 |
| 127 StreamDelegateDoNothing::StreamDelegateDoNothing( | 127 StreamDelegateDoNothing::StreamDelegateDoNothing( |
| 128 const base::WeakPtr<SpdyStream>& stream) | 128 const base::WeakPtr<SpdyStream>& stream) |
| 129 : StreamDelegateBase(stream) {} | 129 : StreamDelegateBase(stream) {} |
| 130 | 130 |
| 131 StreamDelegateDoNothing::~StreamDelegateDoNothing() { | 131 StreamDelegateDoNothing::~StreamDelegateDoNothing() { |
| 132 } | 132 } |
| 133 | 133 |
| 134 int StreamDelegateDoNothing::OnSendBody() { | 134 void StreamDelegateDoNothing::OnSendBody() { |
| 135 return OK; | 135 ADD_FAILURE() << "OnSendBody should not be called"; |
| 136 } | 136 } |
| 137 |
| 137 SpdySendStatus StreamDelegateDoNothing::OnSendBodyComplete( | 138 SpdySendStatus StreamDelegateDoNothing::OnSendBodyComplete( |
| 138 size_t /*bytes_sent*/) { | 139 size_t /*bytes_sent*/) { |
| 139 return NO_MORE_DATA_TO_SEND; | 140 return NO_MORE_DATA_TO_SEND; |
| 140 } | 141 } |
| 141 | 142 |
| 142 StreamDelegateSendImmediate::StreamDelegateSendImmediate( | 143 StreamDelegateSendImmediate::StreamDelegateSendImmediate( |
| 143 const base::WeakPtr<SpdyStream>& stream, | 144 const base::WeakPtr<SpdyStream>& stream, |
| 144 scoped_ptr<SpdyHeaderBlock> headers, | 145 scoped_ptr<SpdyHeaderBlock> headers, |
| 145 base::StringPiece data) | 146 base::StringPiece data) |
| 146 : StreamDelegateBase(stream), | 147 : StreamDelegateBase(stream), |
| 147 headers_(headers.Pass()), | 148 headers_(headers.Pass()), |
| 148 data_(data) {} | 149 data_(data) {} |
| 149 | 150 |
| 150 StreamDelegateSendImmediate::~StreamDelegateSendImmediate() { | 151 StreamDelegateSendImmediate::~StreamDelegateSendImmediate() { |
| 151 } | 152 } |
| 152 | 153 |
| 153 int StreamDelegateSendImmediate::OnSendBody() { | 154 void StreamDelegateSendImmediate::OnSendBody() { |
| 154 ADD_FAILURE() << "OnSendBody should not be called"; | 155 ADD_FAILURE() << "OnSendBody should not be called"; |
| 155 return ERR_UNEXPECTED; | |
| 156 } | 156 } |
| 157 |
| 157 SpdySendStatus StreamDelegateSendImmediate::OnSendBodyComplete( | 158 SpdySendStatus StreamDelegateSendImmediate::OnSendBodyComplete( |
| 158 size_t /*bytes_sent*/) { | 159 size_t /*bytes_sent*/) { |
| 159 ADD_FAILURE() << "OnSendBodyComplete should not be called"; | 160 ADD_FAILURE() << "OnSendBodyComplete should not be called"; |
| 160 return NO_MORE_DATA_TO_SEND; | 161 return NO_MORE_DATA_TO_SEND; |
| 161 } | 162 } |
| 162 | 163 |
| 163 int StreamDelegateSendImmediate::OnResponseReceived( | 164 int StreamDelegateSendImmediate::OnResponseReceived( |
| 164 const SpdyHeaderBlock& response, | 165 const SpdyHeaderBlock& response, |
| 165 base::Time response_time, | 166 base::Time response_time, |
| 166 int status) { | 167 int status) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 185 body_data_sent_(0) {} | 186 body_data_sent_(0) {} |
| 186 | 187 |
| 187 StreamDelegateWithBody::~StreamDelegateWithBody() { | 188 StreamDelegateWithBody::~StreamDelegateWithBody() { |
| 188 } | 189 } |
| 189 | 190 |
| 190 SpdySendStatus StreamDelegateWithBody::OnSendHeadersComplete() { | 191 SpdySendStatus StreamDelegateWithBody::OnSendHeadersComplete() { |
| 191 StreamDelegateBase::OnSendHeadersComplete(); | 192 StreamDelegateBase::OnSendHeadersComplete(); |
| 192 return MORE_DATA_TO_SEND; | 193 return MORE_DATA_TO_SEND; |
| 193 } | 194 } |
| 194 | 195 |
| 195 int StreamDelegateWithBody::OnSendBody() { | 196 void StreamDelegateWithBody::OnSendBody() { |
| 196 stream()->QueueStreamData(buf_.get(), buf_->BytesRemaining(), | 197 stream()->QueueStreamData(buf_.get(), buf_->BytesRemaining(), |
| 197 DATA_FLAG_NONE); | 198 DATA_FLAG_NONE); |
| 198 return ERR_IO_PENDING; | |
| 199 } | 199 } |
| 200 | 200 |
| 201 SpdySendStatus StreamDelegateWithBody::OnSendBodyComplete(size_t bytes_sent) { | 201 SpdySendStatus StreamDelegateWithBody::OnSendBodyComplete(size_t bytes_sent) { |
| 202 EXPECT_GT(bytes_sent, 0u); | 202 EXPECT_GT(bytes_sent, 0u); |
| 203 | 203 |
| 204 buf_->DidConsume(bytes_sent); | 204 buf_->DidConsume(bytes_sent); |
| 205 body_data_sent_ += bytes_sent; | 205 body_data_sent_ += bytes_sent; |
| 206 if (buf_->BytesRemaining() > 0) { | 206 if (buf_->BytesRemaining() > 0) { |
| 207 // Go back to OnSendBody() to send the remaining data. | 207 // Go back to OnSendBody() to send the remaining data. |
| 208 return MORE_DATA_TO_SEND; | 208 return MORE_DATA_TO_SEND; |
| 209 } | 209 } |
| 210 | 210 |
| 211 return NO_MORE_DATA_TO_SEND; | 211 return NO_MORE_DATA_TO_SEND; |
| 212 } | 212 } |
| 213 | 213 |
| 214 } // namespace test | 214 } // namespace test |
| 215 | 215 |
| 216 } // namespace net | 216 } // namespace net |
| OLD | NEW |