| Index: net/http/http_pipelined_host_unittest.cc
|
| diff --git a/net/http/http_pipelined_host_unittest.cc b/net/http/http_pipelined_host_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3768d531cddac4200c8a572a5219cbd14bbb5714
|
| --- /dev/null
|
| +++ b/net/http/http_pipelined_host_unittest.cc
|
| @@ -0,0 +1,191 @@
|
| +// Copyright (c) 2011 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/http/http_pipelined_host.h"
|
| +
|
| +#include "net/base/ssl_config_service.h"
|
| +#include "net/http/http_pipelined_connection.h"
|
| +#include "net/proxy/proxy_info.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#if 0
|
| +#include "base/memory/ref_counted.h"
|
| +#include "base/memory/scoped_vector.h"
|
| +#include "net/base/io_buffer.h"
|
| +#include "net/base/net_errors.h"
|
| +#include "net/base/request_priority.h"
|
| +#include "net/http/http_pipelined_stream.h"
|
| +#include "net/socket/client_socket_handle.h"
|
| +#include "net/socket/client_socket_pool_histograms.h"
|
| +#include "net/socket/socket_test_util.h"
|
| +#endif
|
| +
|
| +using testing::_;
|
| +using testing::NiceMock;
|
| +using testing::Ref;
|
| +using testing::Return;
|
| +
|
| +static const int kMaxCapacity = 3;
|
| +
|
| +namespace net {
|
| +
|
| +class MockHostDelegate : public HttpPipelinedHost::Delegate {
|
| + public:
|
| + MOCK_METHOD1(OnHostIdle, void(HttpPipelinedHost* host));
|
| + MOCK_METHOD1(OnHostHasAdditionalCapacity, void(HttpPipelinedHost* host));
|
| +};
|
| +
|
| +class MockPipelineFactory : public HttpPipelinedConnection::Factory {
|
| + public:
|
| + MOCK_METHOD6(CreateNewPipeline, HttpPipelinedConnection*(
|
| + ClientSocketHandle* connection,
|
| + HttpPipelinedConnection::Delegate* delegate,
|
| + const SSLConfig& used_ssl_config,
|
| + const ProxyInfo& used_proxy_info,
|
| + const BoundNetLog& net_log,
|
| + bool was_npn_negotiated));
|
| +};
|
| +
|
| +class MockPipeline : public HttpPipelinedConnection {
|
| + public:
|
| + MockPipeline(int depth, bool usable, bool active)
|
| + : depth_(depth),
|
| + usable_(usable),
|
| + active_(active) {
|
| + }
|
| +
|
| + void SetState(int depth, bool usable, bool active) {
|
| + depth_ = depth;
|
| + usable_ = usable;
|
| + active_ = active;
|
| + }
|
| +
|
| + virtual int depth() const OVERRIDE { return depth_; }
|
| + virtual bool usable() const OVERRIDE { return usable_; }
|
| + virtual bool active() const OVERRIDE { return active_; }
|
| +
|
| + MOCK_METHOD0(CreateNewStream, HttpStream*());
|
| + MOCK_METHOD1(OnStreamDeleted, void(int pipeline_id));
|
| + MOCK_CONST_METHOD0(used_ssl_config, const SSLConfig&());
|
| + MOCK_CONST_METHOD0(used_proxy_info, const ProxyInfo&());
|
| + MOCK_CONST_METHOD0(source, const NetLog::Source&());
|
| + MOCK_CONST_METHOD0(was_npn_negotiated, bool());
|
| +
|
| + private:
|
| + int depth_;
|
| + bool usable_;
|
| + bool active_;
|
| +};
|
| +
|
| +class HttpPipelinedHostTest : public testing::Test {
|
| + public:
|
| + HttpPipelinedHostTest()
|
| + : origin_("host", 123),
|
| + host_(&delegate_, origin_, &factory_) {
|
| + }
|
| +
|
| + MockPipeline* AddTestPipeline(int depth, bool usable, bool active) {
|
| + MockPipeline* pipeline = new MockPipeline(depth, usable, active);
|
| + EXPECT_CALL(factory_, CreateNewPipeline(connection_, &host_,
|
| + Ref(ssl_config_), Ref(proxy_info_),
|
| + Ref(net_log_), true))
|
| + .Times(1)
|
| + .WillOnce(Return(pipeline));
|
| + EXPECT_EQ(pipeline, host_.CreateNewPipeline(connection_, ssl_config_,
|
| + proxy_info_, net_log_, true));
|
| + return pipeline;
|
| + }
|
| +
|
| + void ClearTestPipeline(MockPipeline* pipeline) {
|
| + pipeline->SetState(0, true, true);
|
| + host_.OnPipelineHasCapacity(pipeline);
|
| + }
|
| +
|
| + NiceMock<MockHostDelegate> delegate_;
|
| + HostPortPair origin_;
|
| + MockPipelineFactory factory_;
|
| + HttpPipelinedHost host_;
|
| +
|
| + ClientSocketHandle* connection_;
|
| + SSLConfig ssl_config_;
|
| + ProxyInfo proxy_info_;
|
| + BoundNetLog net_log_;
|
| +};
|
| +
|
| +TEST_F(HttpPipelinedHostTest, Delegate) {
|
| + EXPECT_TRUE(origin_.Equals(host_.origin()));
|
| +}
|
| +
|
| +TEST_F(HttpPipelinedHostTest, OnHostIdle) {
|
| + MockPipeline* pipeline = AddTestPipeline(0, false, true);
|
| +
|
| + EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(&host_))
|
| + .Times(0);
|
| + EXPECT_CALL(delegate_, OnHostIdle(&host_))
|
| + .Times(1);
|
| + host_.OnPipelineHasCapacity(pipeline);
|
| +}
|
| +
|
| +TEST_F(HttpPipelinedHostTest, OnHostHasAdditionalCapacity) {
|
| + MockPipeline* pipeline = AddTestPipeline(1, true, true);
|
| +
|
| + EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(&host_))
|
| + .Times(2);
|
| + EXPECT_CALL(delegate_, OnHostIdle(&host_))
|
| + .Times(0);
|
| +
|
| + host_.OnPipelineHasCapacity(pipeline);
|
| +
|
| + EXPECT_CALL(delegate_, OnHostIdle(&host_))
|
| + .Times(1);
|
| + ClearTestPipeline(pipeline);
|
| +}
|
| +
|
| +TEST_F(HttpPipelinedHostTest, IgnoresUnusablePipeline) {
|
| + MockPipeline* pipeline = AddTestPipeline(1, false, true);
|
| +
|
| + EXPECT_EQ(NULL, host_.FindAvailablePipeline());
|
| +
|
| + ClearTestPipeline(pipeline);
|
| +}
|
| +
|
| +TEST_F(HttpPipelinedHostTest, IgnoresInactivePipeline) {
|
| + MockPipeline* pipeline = AddTestPipeline(1, true, false);
|
| +
|
| + EXPECT_EQ(NULL, host_.FindAvailablePipeline());
|
| +
|
| + ClearTestPipeline(pipeline);
|
| +}
|
| +
|
| +TEST_F(HttpPipelinedHostTest, IgnoresFullPipeline) {
|
| + MockPipeline* pipeline = AddTestPipeline(kMaxCapacity, true, true);
|
| +
|
| + EXPECT_EQ(NULL, host_.FindAvailablePipeline());
|
| +
|
| + ClearTestPipeline(pipeline);
|
| +}
|
| +
|
| +TEST_F(HttpPipelinedHostTest, PicksLeastLoadedPipeline) {
|
| + MockPipeline* full_pipeline = AddTestPipeline(kMaxCapacity, true, true);
|
| + MockPipeline* usable_pipeline = AddTestPipeline(kMaxCapacity - 1, true, true);
|
| + MockPipeline* empty_pipeline = AddTestPipeline(0, true, true);
|
| +
|
| + EXPECT_EQ(empty_pipeline, host_.FindAvailablePipeline());
|
| +
|
| + ClearTestPipeline(full_pipeline);
|
| + ClearTestPipeline(usable_pipeline);
|
| + ClearTestPipeline(empty_pipeline);
|
| +}
|
| +
|
| +TEST_F(HttpPipelinedHostTest, EmptyPipelineIsRemoved) {
|
| + MockPipeline* empty_pipeline = AddTestPipeline(0, true, true);
|
| +
|
| + EXPECT_EQ(empty_pipeline, host_.FindAvailablePipeline());
|
| +
|
| + ClearTestPipeline(empty_pipeline);
|
| +
|
| + EXPECT_EQ(NULL, host_.FindAvailablePipeline());
|
| +}
|
| +
|
| +} // namespace net
|
|
|