Chromium Code Reviews| Index: net/http/http_pipelined_host_forced_unittest.cc |
| diff --git a/net/http/http_pipelined_host_forced_unittest.cc b/net/http/http_pipelined_host_forced_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3b97482fdb60b97bcf3259ac00d620b39bf66ac1 |
| --- /dev/null |
| +++ b/net/http/http_pipelined_host_forced_unittest.cc |
| @@ -0,0 +1,104 @@ |
| +// 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/http/http_pipelined_host_forced.h" |
| + |
| +#include "base/memory/scoped_ptr.h" |
| +#include "net/base/ssl_config_service.h" |
| +#include "net/http/http_pipelined_host_test_util.h" |
| +#include "net/proxy/proxy_info.h" |
| +#include "net/socket/client_socket_handle.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +using testing::NiceMock; |
| +using testing::Ref; |
| +using testing::Return; |
| + |
| +namespace net { |
| + |
| +namespace { |
| + |
| +HttpPipelinedStream* kDummyStream = |
| + reinterpret_cast<HttpPipelinedStream*>(24); |
| + |
| +class HttpPipelinedHostForcedTest : public testing::Test { |
| + public: |
| + HttpPipelinedHostForcedTest() |
| + : key_(HostPortPair("host", 123), false), |
| + factory_(new MockPipelineFactory), // Owned by host_. |
|
mmenke
2012/02/23 18:54:58
nit: |host_|
James Simonsen
2012/02/23 23:49:46
Done.
|
| + host_(new HttpPipelinedHostForced(&delegate_, key_, factory_)) { |
| + } |
| + |
| + MockPipeline* AddTestPipeline() { |
| + MockPipeline* pipeline = new MockPipeline(0, true, true); |
| + EXPECT_CALL(*factory_, CreateNewPipeline(&connection_, host_.get(), |
| + MatchesOrigin(key_.origin()), |
| + Ref(ssl_config_), Ref(proxy_info_), |
| + Ref(net_log_), true, |
| + SSLClientSocket::kProtoSPDY21)) |
| + .Times(1) |
| + .WillOnce(Return(pipeline)); |
| + EXPECT_CALL(*pipeline, CreateNewStream()) |
| + .Times(1) |
| + .WillOnce(Return(kDummyStream)); |
| + EXPECT_EQ(kDummyStream, host_->CreateStreamOnNewPipeline( |
| + &connection_, ssl_config_, proxy_info_, net_log_, true, |
| + SSLClientSocket::kProtoSPDY21)); |
| + return pipeline; |
| + } |
| + |
| + void ClearTestPipeline(MockPipeline* pipeline) { |
|
mmenke
2012/02/23 18:54:58
This isn't used.
James Simonsen
2012/02/23 23:49:46
Done.
|
| + pipeline->SetState(0, true, true); |
| + host_->OnPipelineHasCapacity(pipeline); |
| + } |
| + |
| + ClientSocketHandle connection_; |
| + NiceMock<MockHostDelegate> delegate_; |
| + HttpPipelinedHost::Key key_; |
| + MockPipelineFactory* factory_; |
| + scoped_ptr<HttpPipelinedHostForced> host_; |
| + |
| + SSLConfig ssl_config_; |
| + ProxyInfo proxy_info_; |
| + BoundNetLog net_log_; |
| +}; |
| + |
| +TEST_F(HttpPipelinedHostForcedTest, Delegate) { |
| + EXPECT_TRUE(key_.origin().Equals(host_->key().origin())); |
| + EXPECT_EQ(key_.force_pipelining(), host_->key().force_pipelining()); |
| +} |
| + |
| +TEST_F(HttpPipelinedHostForcedTest, SingleUser) { |
| + EXPECT_FALSE(host_->IsExistingPipelineAvailable()); |
| + |
| + MockPipeline* pipeline = AddTestPipeline(); |
| + EXPECT_TRUE(host_->IsExistingPipelineAvailable()); |
| + |
| + EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get())) |
| + .Times(1); |
| + EXPECT_CALL(delegate_, OnHostIdle(host_.get())) |
| + .Times(1); |
| + host_->OnPipelineHasCapacity(pipeline); |
| +} |
| + |
| +TEST_F(HttpPipelinedHostForcedTest, ReuseExisting) { |
| + EXPECT_EQ(NULL, host_->CreateStreamOnExistingPipeline()); |
| + |
| + MockPipeline* pipeline = AddTestPipeline(); |
| + EXPECT_CALL(*pipeline, CreateNewStream()) |
| + .Times(1) |
| + .WillOnce(Return(kDummyStream)); |
| + EXPECT_EQ(kDummyStream, host_->CreateStreamOnExistingPipeline()); |
| + |
| + EXPECT_CALL(delegate_, OnHostHasAdditionalCapacity(host_.get())) |
| + .Times(1); |
| + EXPECT_CALL(delegate_, OnHostIdle(host_.get())) |
| + .Times(1); |
| + host_->OnPipelineHasCapacity(pipeline); |
|
mmenke
2012/02/23 18:54:58
I suggest in one test you set depth to 1 before ca
James Simonsen
2012/02/23 23:49:46
Good idea. Done.
|
| +} |
| + |
| +} // anonymous namespace |
| + |
| +} // namespace net |