Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: net/http/http_pipelined_host_pool_unittest.cc

Issue 9433015: Add a force pipelining option to load flags. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix build on other platforms Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 "net/base/ssl_config_service.h" 8 #include "net/base/ssl_config_service.h"
9 #include "net/http/http_pipelined_host.h" 9 #include "net/http/http_pipelined_host.h"
10 #include "net/http/http_pipelined_host_capability.h" 10 #include "net/http/http_pipelined_host_capability.h"
(...skipping 12 matching lines...) Expand all
23 namespace { 23 namespace {
24 24
25 ClientSocketHandle* kDummyConnection = 25 ClientSocketHandle* kDummyConnection =
26 reinterpret_cast<ClientSocketHandle*>(188); 26 reinterpret_cast<ClientSocketHandle*>(188);
27 HttpPipelinedStream* kDummyStream = 27 HttpPipelinedStream* kDummyStream =
28 reinterpret_cast<HttpPipelinedStream*>(99); 28 reinterpret_cast<HttpPipelinedStream*>(99);
29 29
30 class MockPoolDelegate : public HttpPipelinedHostPool::Delegate { 30 class MockPoolDelegate : public HttpPipelinedHostPool::Delegate {
31 public: 31 public:
32 MOCK_METHOD1(OnHttpPipelinedHostHasAdditionalCapacity, 32 MOCK_METHOD1(OnHttpPipelinedHostHasAdditionalCapacity,
33 void(const HostPortPair& origin)); 33 void(HttpPipelinedHost* host));
34 }; 34 };
35 35
36 class MockHostFactory : public HttpPipelinedHost::Factory { 36 class MockHostFactory : public HttpPipelinedHost::Factory {
37 public: 37 public:
38 MOCK_METHOD4(CreateNewHost, HttpPipelinedHost*( 38 MOCK_METHOD4(CreateNewHost, HttpPipelinedHost*(
39 HttpPipelinedHost::Delegate* delegate, const HostPortPair& origin, 39 HttpPipelinedHost::Delegate* delegate,
40 const HttpPipelinedHost::Key& key,
40 HttpPipelinedConnection::Factory* factory, 41 HttpPipelinedConnection::Factory* factory,
41 HttpPipelinedHostCapability capability)); 42 HttpPipelinedHostCapability capability));
42 }; 43 };
43 44
44 class MockHost : public HttpPipelinedHost { 45 class MockHost : public HttpPipelinedHost {
45 public: 46 public:
46 MockHost(const HostPortPair& origin) 47 MockHost(const Key& key)
47 : origin_(origin) { 48 : key_(key) {
48 } 49 }
49 50
50 MOCK_METHOD6(CreateStreamOnNewPipeline, HttpPipelinedStream*( 51 MOCK_METHOD6(CreateStreamOnNewPipeline, HttpPipelinedStream*(
51 ClientSocketHandle* connection, 52 ClientSocketHandle* connection,
52 const SSLConfig& used_ssl_config, 53 const SSLConfig& used_ssl_config,
53 const ProxyInfo& used_proxy_info, 54 const ProxyInfo& used_proxy_info,
54 const BoundNetLog& net_log, 55 const BoundNetLog& net_log,
55 bool was_npn_negotiated, 56 bool was_npn_negotiated,
56 SSLClientSocket::NextProto protocol_negotiated)); 57 SSLClientSocket::NextProto protocol_negotiated));
57 MOCK_METHOD0(CreateStreamOnExistingPipeline, HttpPipelinedStream*()); 58 MOCK_METHOD0(CreateStreamOnExistingPipeline, HttpPipelinedStream*());
58 MOCK_CONST_METHOD0(IsExistingPipelineAvailable, bool()); 59 MOCK_CONST_METHOD0(IsExistingPipelineAvailable, bool());
59 MOCK_CONST_METHOD0(PipelineInfoToValue, base::Value*()); 60 MOCK_CONST_METHOD0(PipelineInfoToValue, base::Value*());
60 61
61 virtual const HostPortPair& origin() const OVERRIDE { return origin_; } 62 virtual const Key& key() const OVERRIDE { return key_; }
62 63
63 private: 64 private:
64 HostPortPair origin_; 65 Key key_;
65 }; 66 };
66 67
67 class HttpPipelinedHostPoolTest : public testing::Test { 68 class HttpPipelinedHostPoolTest : public testing::Test {
68 public: 69 public:
69 HttpPipelinedHostPoolTest() 70 HttpPipelinedHostPoolTest()
70 : origin_("host", 123), 71 : key_(HostPortPair("host", 123), false),
71 factory_(new MockHostFactory), // Owned by pool_. 72 factory_(new MockHostFactory), // Owned by pool_.
72 host_(new MockHost(origin_)), // Owned by pool_. 73 host_(new MockHost(key_)), // Owned by pool_.
73 http_server_properties_(new HttpServerPropertiesImpl), 74 http_server_properties_(new HttpServerPropertiesImpl),
74 pool_(new HttpPipelinedHostPool(&delegate_, factory_, 75 pool_(new HttpPipelinedHostPool(&delegate_, factory_,
75 http_server_properties_.get())), 76 http_server_properties_.get())),
76 was_npn_negotiated_(false), 77 was_npn_negotiated_(false),
77 protocol_negotiated_(SSLClientSocket::kProtoUnknown) { 78 protocol_negotiated_(SSLClientSocket::kProtoUnknown) {
78 } 79 }
79 80
80 void CreateDummyStream() { 81 void CreateDummyStream() {
81 EXPECT_CALL(*host_, CreateStreamOnNewPipeline(kDummyConnection, 82 EXPECT_CALL(*host_, CreateStreamOnNewPipeline(kDummyConnection,
82 Ref(ssl_config_), 83 Ref(ssl_config_),
83 Ref(proxy_info_), 84 Ref(proxy_info_),
84 Ref(net_log_), 85 Ref(net_log_),
85 was_npn_negotiated_, 86 was_npn_negotiated_,
86 protocol_negotiated_)) 87 protocol_negotiated_))
87 .Times(1) 88 .Times(1)
88 .WillOnce(Return(kDummyStream)); 89 .WillOnce(Return(kDummyStream));
89 EXPECT_EQ(kDummyStream, 90 EXPECT_EQ(kDummyStream,
90 pool_->CreateStreamOnNewPipeline(origin_, kDummyConnection, 91 pool_->CreateStreamOnNewPipeline(key_, kDummyConnection,
91 ssl_config_, proxy_info_, 92 ssl_config_, proxy_info_,
92 net_log_, was_npn_negotiated_, 93 net_log_, was_npn_negotiated_,
93 protocol_negotiated_)); 94 protocol_negotiated_));
94 } 95 }
95 96
96 HostPortPair origin_; 97 HttpPipelinedHost::Key key_;
97 MockPoolDelegate delegate_; 98 MockPoolDelegate delegate_;
98 MockHostFactory* factory_; 99 MockHostFactory* factory_;
99 MockHost* host_; 100 MockHost* host_;
100 scoped_ptr<HttpServerPropertiesImpl> http_server_properties_; 101 scoped_ptr<HttpServerPropertiesImpl> http_server_properties_;
101 scoped_ptr<HttpPipelinedHostPool> pool_; 102 scoped_ptr<HttpPipelinedHostPool> pool_;
102 103
103 const SSLConfig ssl_config_; 104 const SSLConfig ssl_config_;
104 const ProxyInfo proxy_info_; 105 const ProxyInfo proxy_info_;
105 const BoundNetLog net_log_; 106 const BoundNetLog net_log_;
106 bool was_npn_negotiated_; 107 bool was_npn_negotiated_;
107 SSLClientSocket::NextProto protocol_negotiated_; 108 SSLClientSocket::NextProto protocol_negotiated_;
108 }; 109 };
109 110
110 TEST_F(HttpPipelinedHostPoolTest, DefaultUnknown) { 111 TEST_F(HttpPipelinedHostPoolTest, DefaultUnknown) {
111 EXPECT_TRUE(pool_->IsHostEligibleForPipelining(origin_)); 112 EXPECT_TRUE(pool_->IsKeyEligibleForPipelining(key_));
112 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, 113 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key_), _,
113 PIPELINE_UNKNOWN)) 114 PIPELINE_UNKNOWN))
114 .Times(1) 115 .Times(1)
115 .WillOnce(Return(host_)); 116 .WillOnce(Return(host_));
116 117
117 CreateDummyStream(); 118 CreateDummyStream();
118 pool_->OnHostIdle(host_); 119 pool_->OnHostIdle(host_);
119 } 120 }
120 121
121 TEST_F(HttpPipelinedHostPoolTest, RemembersIncapable) { 122 TEST_F(HttpPipelinedHostPoolTest, RemembersIncapable) {
122 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, 123 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key_), _,
123 PIPELINE_UNKNOWN)) 124 PIPELINE_UNKNOWN))
124 .Times(1) 125 .Times(1)
125 .WillOnce(Return(host_)); 126 .WillOnce(Return(host_));
126 127
127 CreateDummyStream(); 128 CreateDummyStream();
128 pool_->OnHostDeterminedCapability(host_, PIPELINE_INCAPABLE); 129 pool_->OnHostDeterminedCapability(host_, PIPELINE_INCAPABLE);
129 pool_->OnHostIdle(host_); 130 pool_->OnHostIdle(host_);
130 EXPECT_FALSE(pool_->IsHostEligibleForPipelining(origin_)); 131 EXPECT_FALSE(pool_->IsKeyEligibleForPipelining(key_));
131 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, 132 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key_), _,
132 PIPELINE_INCAPABLE)) 133 PIPELINE_INCAPABLE))
133 .Times(0); 134 .Times(0);
134 EXPECT_EQ(NULL, 135 EXPECT_EQ(NULL,
135 pool_->CreateStreamOnNewPipeline(origin_, kDummyConnection, 136 pool_->CreateStreamOnNewPipeline(key_, kDummyConnection,
136 ssl_config_, proxy_info_, net_log_, 137 ssl_config_, proxy_info_, net_log_,
137 was_npn_negotiated_, 138 was_npn_negotiated_,
138 protocol_negotiated_)); 139 protocol_negotiated_));
139 } 140 }
140 141
141 TEST_F(HttpPipelinedHostPoolTest, RemembersCapable) { 142 TEST_F(HttpPipelinedHostPoolTest, RemembersCapable) {
142 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, 143 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key_), _,
143 PIPELINE_UNKNOWN)) 144 PIPELINE_UNKNOWN))
144 .Times(1) 145 .Times(1)
145 .WillOnce(Return(host_)); 146 .WillOnce(Return(host_));
146 147
147 CreateDummyStream(); 148 CreateDummyStream();
148 pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE); 149 pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE);
149 pool_->OnHostIdle(host_); 150 pool_->OnHostIdle(host_);
150 EXPECT_TRUE(pool_->IsHostEligibleForPipelining(origin_)); 151 EXPECT_TRUE(pool_->IsKeyEligibleForPipelining(key_));
151 152
152 host_ = new MockHost(origin_); 153 host_ = new MockHost(key_);
153 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, 154 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key_), _,
154 PIPELINE_CAPABLE)) 155 PIPELINE_CAPABLE))
155 .Times(1) 156 .Times(1)
156 .WillOnce(Return(host_)); 157 .WillOnce(Return(host_));
157 CreateDummyStream(); 158 CreateDummyStream();
158 pool_->OnHostIdle(host_); 159 pool_->OnHostIdle(host_);
159 } 160 }
160 161
161 TEST_F(HttpPipelinedHostPoolTest, IncapableIsSticky) { 162 TEST_F(HttpPipelinedHostPoolTest, IncapableIsSticky) {
162 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, 163 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key_), _,
163 PIPELINE_UNKNOWN)) 164 PIPELINE_UNKNOWN))
164 .Times(1) 165 .Times(1)
165 .WillOnce(Return(host_)); 166 .WillOnce(Return(host_));
166 167
167 CreateDummyStream(); 168 CreateDummyStream();
168 pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE); 169 pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE);
169 pool_->OnHostDeterminedCapability(host_, PIPELINE_INCAPABLE); 170 pool_->OnHostDeterminedCapability(host_, PIPELINE_INCAPABLE);
170 pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE); 171 pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE);
171 pool_->OnHostIdle(host_); 172 pool_->OnHostIdle(host_);
172 EXPECT_FALSE(pool_->IsHostEligibleForPipelining(origin_)); 173 EXPECT_FALSE(pool_->IsKeyEligibleForPipelining(key_));
173 } 174 }
174 175
175 TEST_F(HttpPipelinedHostPoolTest, RemainsUnknownWithoutFeedback) { 176 TEST_F(HttpPipelinedHostPoolTest, RemainsUnknownWithoutFeedback) {
176 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, 177 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key_), _,
177 PIPELINE_UNKNOWN)) 178 PIPELINE_UNKNOWN))
178 .Times(1) 179 .Times(1)
179 .WillOnce(Return(host_)); 180 .WillOnce(Return(host_));
180 181
181 CreateDummyStream(); 182 CreateDummyStream();
182 pool_->OnHostIdle(host_); 183 pool_->OnHostIdle(host_);
183 EXPECT_TRUE(pool_->IsHostEligibleForPipelining(origin_)); 184 EXPECT_TRUE(pool_->IsKeyEligibleForPipelining(key_));
184 185
185 host_ = new MockHost(origin_); 186 host_ = new MockHost(key_);
186 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(origin_), _, 187 EXPECT_CALL(*factory_, CreateNewHost(pool_.get(), Ref(key_), _,
187 PIPELINE_UNKNOWN)) 188 PIPELINE_UNKNOWN))
188 .Times(1) 189 .Times(1)
189 .WillOnce(Return(host_)); 190 .WillOnce(Return(host_));
190 191
191 CreateDummyStream(); 192 CreateDummyStream();
192 pool_->OnHostIdle(host_); 193 pool_->OnHostIdle(host_);
193 } 194 }
194 195
195 TEST_F(HttpPipelinedHostPoolTest, PopulatesServerProperties) { 196 TEST_F(HttpPipelinedHostPoolTest, PopulatesServerProperties) {
196 EXPECT_EQ(PIPELINE_UNKNOWN, 197 EXPECT_EQ(PIPELINE_UNKNOWN,
197 http_server_properties_->GetPipelineCapability(host_->origin())); 198 http_server_properties_->GetPipelineCapability(
199 host_->key().origin()));
198 pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE); 200 pool_->OnHostDeterminedCapability(host_, PIPELINE_CAPABLE);
199 EXPECT_EQ(PIPELINE_CAPABLE, 201 EXPECT_EQ(PIPELINE_CAPABLE,
200 http_server_properties_->GetPipelineCapability(host_->origin())); 202 http_server_properties_->GetPipelineCapability(
203 host_->key().origin()));
201 delete host_; // Must manually delete, because it's never added to |pool_|. 204 delete host_; // Must manually delete, because it's never added to |pool_|.
202 } 205 }
203 206
204 } // anonymous namespace 207 } // anonymous namespace
205 208
206 } // namespace net 209 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698