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

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

Issue 180743026: Relanding 255326 "HttpServerProperties - Implement MRU for AlternateProtocolMap. Persist" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use Erase to fix compilation error Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_server_properties_impl.cc ('k') | net/http/http_stream_factory_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_server_properties_impl.h" 5 #include "net/http/http_server_properties_impl.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 impl_.Clear(); 199 impl_.Clear();
200 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); 200 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
201 } 201 }
202 202
203 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { 203 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) {
204 HostPortPair test_host_port_pair1("foo1", 80); 204 HostPortPair test_host_port_pair1("foo1", 80);
205 impl_.SetBrokenAlternateProtocol(test_host_port_pair1); 205 impl_.SetBrokenAlternateProtocol(test_host_port_pair1);
206 HostPortPair test_host_port_pair2("foo2", 80); 206 HostPortPair test_host_port_pair2("foo2", 80);
207 impl_.SetAlternateProtocol(test_host_port_pair2, 443, NPN_SPDY_3); 207 impl_.SetAlternateProtocol(test_host_port_pair2, 443, NPN_SPDY_3);
208 208
209 AlternateProtocolMap alternate_protocol_map; 209 AlternateProtocolMap alternate_protocol_map(
210 AlternateProtocolMap::NO_AUTO_EVICT);
210 PortAlternateProtocolPair port_alternate_protocol_pair; 211 PortAlternateProtocolPair port_alternate_protocol_pair;
211 port_alternate_protocol_pair.port = 123; 212 port_alternate_protocol_pair.port = 123;
212 port_alternate_protocol_pair.protocol = NPN_SPDY_3; 213 port_alternate_protocol_pair.protocol = NPN_SPDY_3;
213 alternate_protocol_map[test_host_port_pair2] = port_alternate_protocol_pair; 214 alternate_protocol_map.Put(test_host_port_pair2,
215 port_alternate_protocol_pair);
216 HostPortPair test_host_port_pair3("foo3", 80);
217 port_alternate_protocol_pair.port = 1234;
218 alternate_protocol_map.Put(test_host_port_pair3,
219 port_alternate_protocol_pair);
214 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map); 220 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map);
215 221
222 // Verify test_host_port_pair3 is the MRU server.
223 const net::AlternateProtocolMap& map = impl_.alternate_protocol_map();
224 net::AlternateProtocolMap::const_iterator it = map.begin();
225 it = map.begin();
226 EXPECT_TRUE(it->first.Equals(test_host_port_pair3));
227 EXPECT_EQ(1234, it->second.port);
228 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
229
216 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1)); 230 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1));
217 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair2)); 231 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair2));
218 port_alternate_protocol_pair = 232 port_alternate_protocol_pair =
219 impl_.GetAlternateProtocol(test_host_port_pair1); 233 impl_.GetAlternateProtocol(test_host_port_pair1);
220 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, port_alternate_protocol_pair.protocol); 234 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, port_alternate_protocol_pair.protocol);
221 port_alternate_protocol_pair = 235 port_alternate_protocol_pair =
222 impl_.GetAlternateProtocol(test_host_port_pair2); 236 impl_.GetAlternateProtocol(test_host_port_pair2);
223 EXPECT_EQ(123, port_alternate_protocol_pair.port); 237 EXPECT_EQ(123, port_alternate_protocol_pair.port);
224 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol_pair.protocol); 238 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol_pair.protocol);
225 } 239 }
226 240
241 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfHasAlternateProtocol) {
242 HostPortPair test_host_port_pair1("foo1", 80);
243 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3);
244 HostPortPair test_host_port_pair2("foo2", 80);
245 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3);
246
247 const net::AlternateProtocolMap& map = impl_.alternate_protocol_map();
248 net::AlternateProtocolMap::const_iterator it = map.begin();
249 EXPECT_TRUE(it->first.Equals(test_host_port_pair2));
250 EXPECT_EQ(1234, it->second.port);
251 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
252
253 // HasAlternateProtocol should reoder the AlternateProtocol map.
254 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1));
255 it = map.begin();
256 EXPECT_TRUE(it->first.Equals(test_host_port_pair1));
257 EXPECT_EQ(443, it->second.port);
258 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
259 }
260
261 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) {
262 HostPortPair test_host_port_pair1("foo1", 80);
263 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3);
264 HostPortPair test_host_port_pair2("foo2", 80);
265 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3);
266
267 const net::AlternateProtocolMap& map = impl_.alternate_protocol_map();
268 net::AlternateProtocolMap::const_iterator it = map.begin();
269 EXPECT_TRUE(it->first.Equals(test_host_port_pair2));
270 EXPECT_EQ(1234, it->second.port);
271 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
272
273 // GetAlternateProtocol should reoder the AlternateProtocol map.
274 PortAlternateProtocolPair alternate =
275 impl_.GetAlternateProtocol(test_host_port_pair1);
276 EXPECT_EQ(443, alternate.port);
277 EXPECT_EQ(NPN_SPDY_3, alternate.protocol);
278 it = map.begin();
279 EXPECT_TRUE(it->first.Equals(test_host_port_pair1));
280 EXPECT_EQ(443, it->second.port);
281 EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
282 }
283
227 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { 284 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) {
228 HostPortPair test_host_port_pair("foo", 80); 285 HostPortPair test_host_port_pair("foo", 80);
229 impl_.SetBrokenAlternateProtocol(test_host_port_pair); 286 impl_.SetBrokenAlternateProtocol(test_host_port_pair);
230 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); 287 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
231 PortAlternateProtocolPair alternate = 288 PortAlternateProtocolPair alternate =
232 impl_.GetAlternateProtocol(test_host_port_pair); 289 impl_.GetAlternateProtocol(test_host_port_pair);
233 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); 290 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol);
234 291
235 impl_.SetAlternateProtocol( 292 impl_.SetAlternateProtocol(
236 test_host_port_pair, 293 test_host_port_pair,
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 EXPECT_EQ(value3, flags_and_value3_ret.second); 497 EXPECT_EQ(value3, flags_and_value3_ret.second);
441 498
442 impl_.Clear(); 499 impl_.Clear();
443 EXPECT_EQ(0U, impl_.GetSpdySettings(spdy_server_google).size()); 500 EXPECT_EQ(0U, impl_.GetSpdySettings(spdy_server_google).size());
444 EXPECT_EQ(0U, impl_.GetSpdySettings(spdy_server_docs).size()); 501 EXPECT_EQ(0U, impl_.GetSpdySettings(spdy_server_docs).size());
445 } 502 }
446 503
447 } // namespace 504 } // namespace
448 505
449 } // namespace net 506 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_impl.cc ('k') | net/http/http_stream_factory_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698