Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "net/http/http_pipelined_host_pool.h" | |
| 6 | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "net/base/ssl_config_service.h" | |
| 9 #include "net/http/http_pipelined_host.h" | |
| 10 #include "net/proxy/proxy_info.h" | |
| 11 #include "testing/gmock/include/gmock/gmock.h" | |
| 12 #include "testing/gtest/include/gtest/gtest.h" | |
| 13 | |
| 14 using testing::_; | |
| 15 using testing::Ref; | |
| 16 using testing::Return; | |
| 17 using testing::ReturnNull; | |
| 18 | |
| 19 namespace net { | |
| 20 | |
| 21 static ClientSocketHandle* kDummyConnection = | |
|
mmenke
2011/11/17 22:25:37
Instead of making these static, can we just stick
mmenke
2011/11/17 22:27:08
*Everything in this file.
James Simonsen
2011/11/18 00:03:56
Done.
| |
| 22 reinterpret_cast<ClientSocketHandle*>(188); | |
| 23 static HttpPipelinedStream* kDummyStream = | |
| 24 reinterpret_cast<HttpPipelinedStream*>(99); | |
| 25 | |
| 26 class MockPoolDelegate : public HttpPipelinedHostPool::Delegate { | |
| 27 public: | |
| 28 MOCK_METHOD1(OnHttpPipelinedHostHasAdditionalCapacity, | |
| 29 void(const HostPortPair& origin)); | |
| 30 }; | |
| 31 | |
| 32 class MockHostFactory : public HttpPipelinedHost::Factory { | |
| 33 public: | |
| 34 MOCK_METHOD4(CreateNewHost, HttpPipelinedHost*( | |
| 35 HttpPipelinedHost::Delegate* delegate, const HostPortPair& origin, | |
| 36 HttpPipelinedConnection::Factory* factory, | |
| 37 HttpPipelinedHost::Capability capability)); | |
| 38 }; | |
| 39 | |
| 40 class MockHost : public HttpPipelinedHost { | |
| 41 public: | |
| 42 MockHost(const HostPortPair& origin) | |
| 43 : origin_(origin) { | |
| 44 } | |
| 45 | |
| 46 MOCK_METHOD5(CreateStreamOnNewPipeline, HttpPipelinedStream*( | |
| 47 ClientSocketHandle* connection, | |
| 48 const SSLConfig& used_ssl_config, | |
| 49 const ProxyInfo& used_proxy_info, | |
| 50 const BoundNetLog& net_log, | |
| 51 bool was_npn_negotiated)); | |
| 52 MOCK_METHOD0(CreateStreamOnExistingPipeline, HttpPipelinedStream*()); | |
| 53 MOCK_METHOD0(IsExistingPipelineAvailable, bool()); | |
| 54 | |
| 55 const HostPortPair& origin() const OVERRIDE { return origin_; } | |
|
mmenke
2011/11/17 22:25:37
virtual
James Simonsen
2011/11/18 00:03:56
Done.
| |
| 56 | |
| 57 private: | |
| 58 HostPortPair origin_; | |
| 59 }; | |
| 60 | |
| 61 class HttpPipelinedHostPoolTest : public testing::Test { | |
| 62 public: | |
| 63 HttpPipelinedHostPoolTest() | |
| 64 : origin_("host", 123), | |
| 65 factory_(new MockHostFactory), // Owned by pool_. | |
| 66 host_(new MockHost(origin_)), // Owned by pool_. | |
| 67 pool_(new HttpPipelinedHostPool(&delegate_, factory_)), | |
| 68 was_npn_negotiated_(false) { | |
| 69 } | |
| 70 | |
| 71 void CreateDummyStream() { | |
| 72 EXPECT_CALL(*host_, CreateStreamOnNewPipeline(kDummyConnection, | |
| 73 Ref(ssl_config_), | |
| 74 Ref(proxy_info_), | |
| 75 Ref(net_log_), | |
| 76 was_npn_negotiated_)) | |
| 77 .Times(1) | |
| 78 .WillOnce(Return(kDummyStream)); | |
| 79 EXPECT_EQ(kDummyStream, | |
| 80 pool_->CreateStreamOnNewPipeline(origin_, kDummyConnection, | |
| 81 ssl_config_, proxy_info_, | |
| 82 net_log_, was_npn_negotiated_)); | |
| 83 } | |
| 84 | |
| 85 HostPortPair origin_; | |
| 86 MockPoolDelegate delegate_; | |
| 87 MockHostFactory* factory_; | |
| 88 MockHost* host_; | |
| 89 scoped_ptr<HttpPipelinedHostPool> pool_; | |
| 90 | |
| 91 const SSLConfig ssl_config_; | |
| 92 const ProxyInfo proxy_info_; | |
| 93 const BoundNetLog net_log_; | |
| 94 bool was_npn_negotiated_; | |
| 95 }; | |
| 96 | |
| 97 TEST_F(HttpPipelinedHostPoolTest, DefaultUnknown) { | |
| 98 EXPECT_TRUE(pool_->IsHostEligibleForPipelining(origin_)); | |
| 99 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, | |
| 100 HttpPipelinedHost::UNKNOWN)) | |
| 101 .Times(1) | |
| 102 .WillOnce(Return(host_)); | |
| 103 | |
| 104 CreateDummyStream(); | |
| 105 pool_->OnHostIdle(host_); | |
| 106 } | |
| 107 | |
| 108 TEST_F(HttpPipelinedHostPoolTest, RemembersIncapable) { | |
| 109 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, | |
| 110 HttpPipelinedHost::UNKNOWN)) | |
| 111 .Times(1) | |
| 112 .WillOnce(Return(host_)); | |
| 113 | |
| 114 CreateDummyStream(); | |
| 115 pool_->OnHostDeterminedCapability(host_, HttpPipelinedHost::INCAPABLE); | |
| 116 pool_->OnHostIdle(host_); | |
| 117 EXPECT_FALSE(pool_->IsHostEligibleForPipelining(origin_)); | |
| 118 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, | |
| 119 HttpPipelinedHost::INCAPABLE)) | |
| 120 .Times(0); | |
| 121 EXPECT_EQ(NULL, | |
| 122 pool_->CreateStreamOnNewPipeline(origin_, kDummyConnection, | |
| 123 ssl_config_, proxy_info_, net_log_, | |
| 124 was_npn_negotiated_)); | |
| 125 } | |
| 126 | |
| 127 TEST_F(HttpPipelinedHostPoolTest, RemembersCapable) { | |
| 128 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, | |
| 129 HttpPipelinedHost::UNKNOWN)) | |
| 130 .Times(1) | |
| 131 .WillOnce(Return(host_)); | |
| 132 | |
| 133 CreateDummyStream(); | |
| 134 pool_->OnHostDeterminedCapability(host_, HttpPipelinedHost::CAPABLE); | |
| 135 pool_->OnHostIdle(host_); | |
| 136 EXPECT_TRUE(pool_->IsHostEligibleForPipelining(origin_)); | |
| 137 | |
| 138 host_ = new MockHost(origin_); | |
| 139 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, | |
| 140 HttpPipelinedHost::CAPABLE)) | |
| 141 .Times(1) | |
| 142 .WillOnce(Return(host_)); | |
| 143 CreateDummyStream(); | |
| 144 pool_->OnHostIdle(host_); | |
| 145 } | |
| 146 | |
| 147 TEST_F(HttpPipelinedHostPoolTest, IncapableIsSticky) { | |
| 148 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, | |
| 149 HttpPipelinedHost::UNKNOWN)) | |
| 150 .Times(1) | |
| 151 .WillOnce(Return(host_)); | |
| 152 | |
| 153 CreateDummyStream(); | |
| 154 pool_->OnHostDeterminedCapability(host_, HttpPipelinedHost::INCAPABLE); | |
| 155 pool_->OnHostDeterminedCapability(host_, HttpPipelinedHost::CAPABLE); | |
| 156 pool_->OnHostIdle(host_); | |
| 157 EXPECT_FALSE(pool_->IsHostEligibleForPipelining(origin_)); | |
| 158 } | |
| 159 | |
| 160 } // namespace net | |
| OLD | NEW |