| 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 "net/base/completion_callback.h" | 7 #include "net/base/completion_callback.h" |
| 8 #include "net/spdy/spdy_stream.h" | 8 #include "net/spdy/spdy_stream.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 namespace net { | 11 namespace net { |
| 12 | 12 |
| 13 namespace test { | 13 namespace test { |
| 14 | 14 |
| 15 TestSpdyStreamDelegate::TestSpdyStreamDelegate( | 15 TestSpdyStreamDelegate::TestSpdyStreamDelegate( |
| 16 SpdyStream* stream, | 16 SpdyStream* stream, |
| 17 SpdyHeaderBlock* headers, |
| 17 IOBufferWithSize* buf, | 18 IOBufferWithSize* buf, |
| 18 const CompletionCallback& callback) | 19 const CompletionCallback& callback) |
| 19 : stream_(stream), | 20 : stream_(stream), |
| 21 headers_(headers), |
| 20 buf_(buf), | 22 buf_(buf), |
| 21 callback_(callback), | 23 callback_(callback), |
| 22 send_headers_completed_(false), | 24 send_headers_completed_(false), |
| 23 response_(new SpdyHeaderBlock), | 25 response_(new SpdyHeaderBlock), |
| 24 data_sent_(0), | 26 data_sent_(0), |
| 25 closed_(false) { | 27 closed_(false) { |
| 26 } | 28 } |
| 27 | 29 |
| 28 TestSpdyStreamDelegate::~TestSpdyStreamDelegate() { | 30 TestSpdyStreamDelegate::~TestSpdyStreamDelegate() { |
| 29 } | 31 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 40 int TestSpdyStreamDelegate::OnSendBodyComplete(int /*status*/, bool* /*eof*/) { | 42 int TestSpdyStreamDelegate::OnSendBodyComplete(int /*status*/, bool* /*eof*/) { |
| 41 ADD_FAILURE() << "OnSendBodyComplete should not be called"; | 43 ADD_FAILURE() << "OnSendBodyComplete should not be called"; |
| 42 return ERR_UNEXPECTED; | 44 return ERR_UNEXPECTED; |
| 43 } | 45 } |
| 44 | 46 |
| 45 int TestSpdyStreamDelegate::OnResponseReceived(const SpdyHeaderBlock& response, | 47 int TestSpdyStreamDelegate::OnResponseReceived(const SpdyHeaderBlock& response, |
| 46 base::Time response_time, | 48 base::Time response_time, |
| 47 int status) { | 49 int status) { |
| 48 EXPECT_TRUE(send_headers_completed_); | 50 EXPECT_TRUE(send_headers_completed_); |
| 49 *response_ = response; | 51 *response_ = response; |
| 52 if (headers_.get()) { |
| 53 EXPECT_EQ(ERR_IO_PENDING, |
| 54 stream_->WriteHeaders(headers_.release())); |
| 55 } |
| 50 if (buf_) { | 56 if (buf_) { |
| 51 EXPECT_EQ(ERR_IO_PENDING, | 57 EXPECT_EQ(ERR_IO_PENDING, |
| 52 stream_->WriteStreamData(buf_.get(), buf_->size(), | 58 stream_->WriteStreamData(buf_.get(), buf_->size(), |
| 53 DATA_FLAG_NONE)); | 59 DATA_FLAG_NONE)); |
| 54 } | 60 } |
| 55 return status; | 61 return status; |
| 56 } | 62 } |
| 57 | 63 |
| 58 void TestSpdyStreamDelegate::OnDataReceived(const char* buffer, int bytes) { | 64 void TestSpdyStreamDelegate::OnDataReceived(const char* buffer, int bytes) { |
| 59 received_data_ += std::string(buffer, bytes); | 65 received_data_ += std::string(buffer, bytes); |
| 60 } | 66 } |
| 61 | 67 |
| 62 void TestSpdyStreamDelegate::OnDataSent(int length) { | 68 void TestSpdyStreamDelegate::OnDataSent(int length) { |
| 63 data_sent_ += length; | 69 data_sent_ += length; |
| 64 } | 70 } |
| 65 | 71 |
| 66 void TestSpdyStreamDelegate::OnClose(int status) { | 72 void TestSpdyStreamDelegate::OnClose(int status) { |
| 67 closed_ = true; | 73 closed_ = true; |
| 68 CompletionCallback callback = callback_; | 74 CompletionCallback callback = callback_; |
| 69 callback_.Reset(); | 75 callback_.Reset(); |
| 70 callback.Run(OK); | 76 callback.Run(OK); |
| 71 } | 77 } |
| 72 | 78 |
| 73 } // namespace test | 79 } // namespace test |
| 74 | 80 |
| 75 } // namespace net | 81 } // namespace net |
| OLD | NEW |