| 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/http/http_pipelined_host_pool.h" | 5 #include "net/http/http_pipelined_host_pool.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "net/base/ssl_config_service.h" | 9 #include "net/base/ssl_config_service.h" |
| 10 #include "net/http/http_pipelined_host.h" | 10 #include "net/http/http_pipelined_host.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 MockHost(const Key& key) | 49 MockHost(const Key& key) |
| 50 : key_(key) { | 50 : key_(key) { |
| 51 } | 51 } |
| 52 | 52 |
| 53 MOCK_METHOD6(CreateStreamOnNewPipeline, HttpPipelinedStream*( | 53 MOCK_METHOD6(CreateStreamOnNewPipeline, HttpPipelinedStream*( |
| 54 ClientSocketHandle* connection, | 54 ClientSocketHandle* connection, |
| 55 const SSLConfig& used_ssl_config, | 55 const SSLConfig& used_ssl_config, |
| 56 const ProxyInfo& used_proxy_info, | 56 const ProxyInfo& used_proxy_info, |
| 57 const BoundNetLog& net_log, | 57 const BoundNetLog& net_log, |
| 58 bool was_npn_negotiated, | 58 bool was_npn_negotiated, |
| 59 SSLClientSocket::NextProto protocol_negotiated)); | 59 NextProto protocol_negotiated)); |
| 60 MOCK_METHOD0(CreateStreamOnExistingPipeline, HttpPipelinedStream*()); | 60 MOCK_METHOD0(CreateStreamOnExistingPipeline, HttpPipelinedStream*()); |
| 61 MOCK_CONST_METHOD0(IsExistingPipelineAvailable, bool()); | 61 MOCK_CONST_METHOD0(IsExistingPipelineAvailable, bool()); |
| 62 MOCK_CONST_METHOD0(PipelineInfoToValue, base::Value*()); | 62 MOCK_CONST_METHOD0(PipelineInfoToValue, base::Value*()); |
| 63 | 63 |
| 64 virtual const Key& GetKey() const OVERRIDE { return key_; } | 64 virtual const Key& GetKey() const OVERRIDE { return key_; } |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 Key key_; | 67 Key key_; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 class HttpPipelinedHostPoolTest : public testing::Test { | 70 class HttpPipelinedHostPoolTest : public testing::Test { |
| 71 public: | 71 public: |
| 72 HttpPipelinedHostPoolTest() | 72 HttpPipelinedHostPoolTest() |
| 73 : key_(HostPortPair("host", 123)), | 73 : key_(HostPortPair("host", 123)), |
| 74 factory_(new MockHostFactory), // Owned by pool_. | 74 factory_(new MockHostFactory), // Owned by pool_. |
| 75 host_(new MockHost(key_)), // Owned by pool_. | 75 host_(new MockHost(key_)), // Owned by pool_. |
| 76 http_server_properties_(new HttpServerPropertiesImpl), | 76 http_server_properties_(new HttpServerPropertiesImpl), |
| 77 pool_(new HttpPipelinedHostPool(&delegate_, factory_, | 77 pool_(new HttpPipelinedHostPool(&delegate_, factory_, |
| 78 http_server_properties_.get(), false)), | 78 http_server_properties_.get(), false)), |
| 79 was_npn_negotiated_(false), | 79 was_npn_negotiated_(false), |
| 80 protocol_negotiated_(SSLClientSocket::kProtoUnknown) { | 80 protocol_negotiated_(kProtoUnknown) { |
| 81 } | 81 } |
| 82 | 82 |
| 83 void CreateDummyStream(const HttpPipelinedHost::Key& key, | 83 void CreateDummyStream(const HttpPipelinedHost::Key& key, |
| 84 ClientSocketHandle* connection, | 84 ClientSocketHandle* connection, |
| 85 HttpPipelinedStream* stream, | 85 HttpPipelinedStream* stream, |
| 86 MockHost* host) { | 86 MockHost* host) { |
| 87 EXPECT_CALL(*host, CreateStreamOnNewPipeline(connection, | 87 EXPECT_CALL(*host, CreateStreamOnNewPipeline(connection, |
| 88 Ref(ssl_config_), | 88 Ref(ssl_config_), |
| 89 Ref(proxy_info_), | 89 Ref(proxy_info_), |
| 90 Ref(net_log_), | 90 Ref(net_log_), |
| (...skipping 26 matching lines...) Expand all Loading... |
| 117 MockPoolDelegate delegate_; | 117 MockPoolDelegate delegate_; |
| 118 MockHostFactory* factory_; | 118 MockHostFactory* factory_; |
| 119 MockHost* host_; | 119 MockHost* host_; |
| 120 scoped_ptr<HttpServerPropertiesImpl> http_server_properties_; | 120 scoped_ptr<HttpServerPropertiesImpl> http_server_properties_; |
| 121 scoped_ptr<HttpPipelinedHostPool> pool_; | 121 scoped_ptr<HttpPipelinedHostPool> pool_; |
| 122 | 122 |
| 123 const SSLConfig ssl_config_; | 123 const SSLConfig ssl_config_; |
| 124 const ProxyInfo proxy_info_; | 124 const ProxyInfo proxy_info_; |
| 125 const BoundNetLog net_log_; | 125 const BoundNetLog net_log_; |
| 126 bool was_npn_negotiated_; | 126 bool was_npn_negotiated_; |
| 127 SSLClientSocket::NextProto protocol_negotiated_; | 127 NextProto protocol_negotiated_; |
| 128 }; | 128 }; |
| 129 | 129 |
| 130 TEST_F(HttpPipelinedHostPoolTest, DefaultUnknown) { | 130 TEST_F(HttpPipelinedHostPoolTest, DefaultUnknown) { |
| 131 EXPECT_TRUE(pool_->IsKeyEligibleForPipelining(key_)); | 131 EXPECT_TRUE(pool_->IsKeyEligibleForPipelining(key_)); |
| 132 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key_), _, | 132 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key_), _, |
| 133 PIPELINE_UNKNOWN, false)) | 133 PIPELINE_UNKNOWN, false)) |
| 134 .Times(1) | 134 .Times(1) |
| 135 .WillOnce(Return(host_)); | 135 .WillOnce(Return(host_)); |
| 136 | 136 |
| 137 CreateDummyStream(key_, kDummyConnection, kDummyStream, host_); | 137 CreateDummyStream(key_, kDummyConnection, kDummyStream, host_); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 pool_->OnHostIdle(host1); | 252 pool_->OnHostIdle(host1); |
| 253 pool_->OnHostIdle(host2); | 253 pool_->OnHostIdle(host2); |
| 254 pool_->OnHostIdle(host3); | 254 pool_->OnHostIdle(host3); |
| 255 | 255 |
| 256 delete host_; // Must manually delete, because it's never added to |pool_|. | 256 delete host_; // Must manually delete, because it's never added to |pool_|. |
| 257 } | 257 } |
| 258 | 258 |
| 259 } // anonymous namespace | 259 } // anonymous namespace |
| 260 | 260 |
| 261 } // namespace net | 261 } // namespace net |
| OLD | NEW |