diff options
author | shouqun.liu@intel.com <shouqun.liu@intel.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-19 16:48:20 +0000 |
---|---|---|
committer | shouqun.liu@intel.com <shouqun.liu@intel.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-07-19 16:48:20 +0000 |
commit | 39d13d9412c68e846a66c1973e87654b34e1beb4 (patch) | |
tree | 4ea2c3b4729cb8360c6f934d84ac548506445535 /net/spdy | |
parent | 0b616cde2ef04f1117a4b18b2b612b85431e31a9 (diff) | |
download | chromium_src-39d13d9412c68e846a66c1973e87654b34e1beb4.zip chromium_src-39d13d9412c68e846a66c1973e87654b34e1beb4.tar.gz chromium_src-39d13d9412c68e846a66c1973e87654b34e1beb4.tar.bz2 |
Refactor the SPDY stream unit test with merging common part.
BUG=
TEST=net_unittests SpdyStreamSpdy2Test SpdyStreamSpdy3Test
Review URL: https://chromiumcodereview.appspot.com/10802006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147458 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/spdy')
-rw-r--r-- | net/spdy/spdy_stream_spdy2_unittest.cc | 75 | ||||
-rw-r--r-- | net/spdy/spdy_stream_spdy3_unittest.cc | 75 | ||||
-rw-r--r-- | net/spdy/spdy_stream_test_util.cc | 75 | ||||
-rw-r--r-- | net/spdy/spdy_stream_test_util.h | 58 |
4 files changed, 143 insertions, 140 deletions
diff --git a/net/spdy/spdy_stream_spdy2_unittest.cc b/net/spdy/spdy_stream_spdy2_unittest.cc index cbc4071..fa51d92 100644 --- a/net/spdy/spdy_stream_spdy2_unittest.cc +++ b/net/spdy/spdy_stream_spdy2_unittest.cc @@ -9,6 +9,7 @@ #include "net/spdy/spdy_stream.h" #include "net/spdy/spdy_http_utils.h" #include "net/spdy/spdy_session.h" +#include "net/spdy/spdy_stream_test_util.h" #include "net/spdy/spdy_test_util_spdy2.h" #include "testing/gtest/include/gtest/gtest.h" @@ -20,76 +21,6 @@ namespace net { namespace { -class TestSpdyStreamDelegate : public SpdyStream::Delegate { - public: - TestSpdyStreamDelegate(SpdyStream* stream, - IOBufferWithSize* buf, - const CompletionCallback& callback) - : stream_(stream), - buf_(buf), - callback_(callback), - send_headers_completed_(false), - response_(new SpdyHeaderBlock), - data_sent_(0), - closed_(false) {} - virtual ~TestSpdyStreamDelegate() {} - - virtual bool OnSendHeadersComplete(int status) { - send_headers_completed_ = true; - return true; - } - virtual int OnSendBody() { - ADD_FAILURE() << "OnSendBody should not be called"; - return ERR_UNEXPECTED; - } - virtual int OnSendBodyComplete(int /*status*/, bool* /*eof*/) { - ADD_FAILURE() << "OnSendBodyComplete should not be called"; - return ERR_UNEXPECTED; - } - - virtual int OnResponseReceived(const SpdyHeaderBlock& response, - base::Time response_time, - int status) { - EXPECT_TRUE(send_headers_completed_); - *response_ = response; - if (buf_) { - EXPECT_EQ(ERR_IO_PENDING, - stream_->WriteStreamData(buf_.get(), buf_->size(), - DATA_FLAG_NONE)); - } - return status; - } - virtual void OnDataReceived(const char* buffer, int bytes) { - received_data_ += std::string(buffer, bytes); - } - virtual void OnDataSent(int length) { - data_sent_ += length; - } - virtual void OnClose(int status) { - closed_ = true; - CompletionCallback callback = callback_; - callback_.Reset(); - callback.Run(OK); - } - bool send_headers_completed() const { return send_headers_completed_; } - const linked_ptr<SpdyHeaderBlock>& response() const { - return response_; - } - const std::string& received_data() const { return received_data_; } - int data_sent() const { return data_sent_; } - bool closed() const { return closed_; } - - private: - SpdyStream* stream_; - scoped_refptr<IOBufferWithSize> buf_; - CompletionCallback callback_; - bool send_headers_completed_; - linked_ptr<SpdyHeaderBlock> response_; - std::string received_data_; - int data_sent_; - bool closed_; -}; - SpdyFrame* ConstructSpdyBodyFrame(const char* data, int length) { BufferedSpdyFramer framer(2); return framer.CreateDataFrame(1, data, length, DATA_FLAG_NONE); @@ -97,6 +28,8 @@ SpdyFrame* ConstructSpdyBodyFrame(const char* data, int length) { } // anonymous namespace +namespace test { + class SpdyStreamSpdy2Test : public testing::Test { protected: SpdyStreamSpdy2Test() { @@ -433,4 +366,6 @@ TEST_F(SpdyStreamSpdy2Test, StreamError) { EXPECT_EQ(static_cast<int>(stream_id), stream_id2); } +} //namespace test + } // namespace net diff --git a/net/spdy/spdy_stream_spdy3_unittest.cc b/net/spdy/spdy_stream_spdy3_unittest.cc index a59ce808..eb777bd 100644 --- a/net/spdy/spdy_stream_spdy3_unittest.cc +++ b/net/spdy/spdy_stream_spdy3_unittest.cc @@ -9,6 +9,7 @@ #include "net/spdy/spdy_stream.h" #include "net/spdy/spdy_http_utils.h" #include "net/spdy/spdy_session.h" +#include "net/spdy/spdy_stream_test_util.h" #include "net/spdy/spdy_test_util_spdy3.h" #include "testing/gtest/include/gtest/gtest.h" @@ -20,76 +21,6 @@ namespace net { namespace { -class TestSpdyStreamDelegate : public SpdyStream::Delegate { - public: - TestSpdyStreamDelegate(SpdyStream* stream, - IOBufferWithSize* buf, - const CompletionCallback& callback) - : stream_(stream), - buf_(buf), - callback_(callback), - send_headers_completed_(false), - response_(new SpdyHeaderBlock), - data_sent_(0), - closed_(false) {} - virtual ~TestSpdyStreamDelegate() {} - - virtual bool OnSendHeadersComplete(int status) { - send_headers_completed_ = true; - return true; - } - virtual int OnSendBody() { - ADD_FAILURE() << "OnSendBody should not be called"; - return ERR_UNEXPECTED; - } - virtual int OnSendBodyComplete(int /*status*/, bool* /*eof*/) { - ADD_FAILURE() << "OnSendBodyComplete should not be called"; - return ERR_UNEXPECTED; - } - - virtual int OnResponseReceived(const SpdyHeaderBlock& response, - base::Time response_time, - int status) { - EXPECT_TRUE(send_headers_completed_); - *response_ = response; - if (buf_) { - EXPECT_EQ(ERR_IO_PENDING, - stream_->WriteStreamData(buf_.get(), buf_->size(), - DATA_FLAG_NONE)); - } - return status; - } - virtual void OnDataReceived(const char* buffer, int bytes) { - received_data_ += std::string(buffer, bytes); - } - virtual void OnDataSent(int length) { - data_sent_ += length; - } - virtual void OnClose(int status) { - closed_ = true; - CompletionCallback callback = callback_; - callback_.Reset(); - callback.Run(OK); - } - bool send_headers_completed() const { return send_headers_completed_; } - const linked_ptr<SpdyHeaderBlock>& response() const { - return response_; - } - const std::string& received_data() const { return received_data_; } - int data_sent() const { return data_sent_; } - bool closed() const { return closed_; } - - private: - SpdyStream* stream_; - scoped_refptr<IOBufferWithSize> buf_; - CompletionCallback callback_; - bool send_headers_completed_; - linked_ptr<SpdyHeaderBlock> response_; - std::string received_data_; - int data_sent_; - bool closed_; -}; - SpdyFrame* ConstructSpdyBodyFrame(const char* data, int length) { BufferedSpdyFramer framer(3); return framer.CreateDataFrame(1, data, length, DATA_FLAG_NONE); @@ -97,6 +28,8 @@ SpdyFrame* ConstructSpdyBodyFrame(const char* data, int length) { } // anonymous namespace +namespace test { + class SpdyStreamSpdy3Test : public testing::Test { protected: SpdyStreamSpdy3Test() { @@ -438,4 +371,6 @@ TEST_F(SpdyStreamSpdy3Test, StreamError) { EXPECT_EQ(static_cast<int>(stream_id), stream_id2); } +} // namespace test + } // namespace net diff --git a/net/spdy/spdy_stream_test_util.cc b/net/spdy/spdy_stream_test_util.cc new file mode 100644 index 0000000..93863d3 --- /dev/null +++ b/net/spdy/spdy_stream_test_util.cc @@ -0,0 +1,75 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/spdy/spdy_stream_test_util.h" + +#include "net/base/completion_callback.h" +#include "net/spdy/spdy_stream.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace net { + +namespace test { + +TestSpdyStreamDelegate::TestSpdyStreamDelegate( + SpdyStream* stream, + IOBufferWithSize* buf, + const CompletionCallback& callback) + : stream_(stream), + buf_(buf), + callback_(callback), + send_headers_completed_(false), + response_(new SpdyHeaderBlock), + data_sent_(0), + closed_(false) { +} + +TestSpdyStreamDelegate::~TestSpdyStreamDelegate() { +} + +bool TestSpdyStreamDelegate::OnSendHeadersComplete(int status) { + send_headers_completed_ = true; + return true; +} + +int TestSpdyStreamDelegate::OnSendBody() { + ADD_FAILURE() << "OnSendBody should not be called"; + return ERR_UNEXPECTED; +} +int TestSpdyStreamDelegate::OnSendBodyComplete(int /*status*/, bool* /*eof*/) { + ADD_FAILURE() << "OnSendBodyComplete should not be called"; + return ERR_UNEXPECTED; +} + +int TestSpdyStreamDelegate::OnResponseReceived(const SpdyHeaderBlock& response, + base::Time response_time, + int status) { + EXPECT_TRUE(send_headers_completed_); + *response_ = response; + if (buf_) { + EXPECT_EQ(ERR_IO_PENDING, + stream_->WriteStreamData(buf_.get(), buf_->size(), + DATA_FLAG_NONE)); + } + return status; +} + +void TestSpdyStreamDelegate::OnDataReceived(const char* buffer, int bytes) { + received_data_ += std::string(buffer, bytes); +} + +void TestSpdyStreamDelegate::OnDataSent(int length) { + data_sent_ += length; +} + +void TestSpdyStreamDelegate::OnClose(int status) { + closed_ = true; + CompletionCallback callback = callback_; + callback_.Reset(); + callback.Run(OK); +} + +} // namespace test + +} // namespace net diff --git a/net/spdy/spdy_stream_test_util.h b/net/spdy/spdy_stream_test_util.h new file mode 100644 index 0000000..76ea49e --- /dev/null +++ b/net/spdy/spdy_stream_test_util.h @@ -0,0 +1,58 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ +#define NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ + +#include "base/memory/linked_ptr.h" +#include "base/memory/ref_counted.h" +#include "net/base/completion_callback.h" +#include "net/spdy/spdy_stream.h" + +namespace net { + +namespace test { + +class TestSpdyStreamDelegate : public SpdyStream::Delegate { + public: + TestSpdyStreamDelegate(SpdyStream* stream, + IOBufferWithSize* buf, + const CompletionCallback& callback); + virtual ~TestSpdyStreamDelegate(); + + virtual bool OnSendHeadersComplete(int status) OVERRIDE; + virtual int OnSendBody() OVERRIDE; + virtual int OnSendBodyComplete(int status, bool* eof) OVERRIDE; + virtual int OnResponseReceived(const SpdyHeaderBlock& response, + base::Time response_time, + int status) OVERRIDE; + virtual void OnDataReceived(const char* buffer, int bytes) OVERRIDE; + virtual void OnDataSent(int length) OVERRIDE; + virtual void OnClose(int status) OVERRIDE; + + bool send_headers_completed() const { return send_headers_completed_; } + const linked_ptr<SpdyHeaderBlock>& response() const { + return response_; + } + const std::string& received_data() const { return received_data_; } + int data_sent() const { return data_sent_; } + bool closed() const { return closed_; } + + private: + SpdyStream* stream_; + scoped_refptr<IOBufferWithSize> buf_; + CompletionCallback callback_; + bool send_headers_completed_; + linked_ptr<SpdyHeaderBlock> response_; + std::string received_data_; + int data_sent_; + bool closed_; + +}; + +} // namespace test + +} // namespace net + +#endif // NET_SPDY_SPDY_STREAM_TEST_UTIL_H_ |