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

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

Issue 1531983003: Changes to QuicServerInfoMap initialization to maintain MRU order of the (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_server_network_stats_mru_cache
Patch Set: rebase TOT Created 5 years 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
« no previous file with comments | « net/http/http_server_properties_impl.cc ('k') | no next file » | 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 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 1199
1200 impl_.Clear(); 1200 impl_.Clear();
1201 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server); 1201 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server);
1202 EXPECT_EQ(NULL, stats3); 1202 EXPECT_EQ(NULL, stats3);
1203 } 1203 }
1204 1204
1205 typedef HttpServerPropertiesImplTest QuicServerInfoServerPropertiesTest; 1205 typedef HttpServerPropertiesImplTest QuicServerInfoServerPropertiesTest;
1206 1206
1207 TEST_F(QuicServerInfoServerPropertiesTest, Initialize) { 1207 TEST_F(QuicServerInfoServerPropertiesTest, Initialize) {
1208 HostPortPair google_server("www.google.com", 443); 1208 HostPortPair google_server("www.google.com", 443);
1209 QuicServerId quic_server_id(google_server, PRIVACY_MODE_ENABLED); 1209 QuicServerId google_quic_server_id(google_server, PRIVACY_MODE_ENABLED);
1210 1210
1211 // Check empty map. 1211 // Check empty map.
1212 QuicServerInfoMap quic_server_info_map(QuicServerInfoMap::NO_AUTO_EVICT); 1212 QuicServerInfoMap init_quic_server_info_map(QuicServerInfoMap::NO_AUTO_EVICT);
1213 impl_.InitializeQuicServerInfoMap(&quic_server_info_map); 1213 impl_.InitializeQuicServerInfoMap(&init_quic_server_info_map);
1214 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); 1214 EXPECT_EQ(0u, impl_.quic_server_info_map().size());
1215 1215
1216 // Check by adding a QuicServerInfo into the map. 1216 // Check by initializing with www.google.com:443.
1217 std::string quic_server_info1("quic_server_info1"); 1217 std::string google_server_info("google_quic_server_info");
1218 quic_server_info_map.Put(quic_server_id, quic_server_info1); 1218 init_quic_server_info_map.Put(google_quic_server_id, google_server_info);
1219 impl_.InitializeQuicServerInfoMap(&init_quic_server_info_map);
1220
1221 // Verify data for www.google.com:443.
1222 EXPECT_EQ(1u, impl_.quic_server_info_map().size());
1223 EXPECT_EQ(google_server_info,
1224 *impl_.GetQuicServerInfo(google_quic_server_id));
1225
1226 // Test recency order and overwriting of data.
1227 //
1228 // |docs_server| has a QuicServerInfo, which will be overwritten by
1229 // InitializeQuicServerInfoMap(), because |quic_server_info_map| has an
1230 // entry for |docs_server|.
1231 HostPortPair docs_server("docs.google.com", 443);
1232 QuicServerId docs_quic_server_id(docs_server, PRIVACY_MODE_ENABLED);
1233 std::string docs_server_info("docs_quic_server_info");
1234 impl_.SetQuicServerInfo(docs_quic_server_id, docs_server_info);
1235
1236 // Recency order will be |docs_server| and |google_server|.
1237 const QuicServerInfoMap& map = impl_.quic_server_info_map();
1238 ASSERT_EQ(2u, map.size());
1239 QuicServerInfoMap::const_iterator map_it = map.begin();
1240 EXPECT_EQ(map_it->first, docs_quic_server_id);
1241 EXPECT_EQ(docs_server_info, map_it->second);
1242 ++map_it;
1243 EXPECT_EQ(map_it->first, google_quic_server_id);
1244 EXPECT_EQ(google_server_info, map_it->second);
1245
1246 // Prepare |quic_server_info_map| to be loaded by
1247 // InitializeQuicServerInfoMap().
1248 QuicServerInfoMap quic_server_info_map(QuicServerInfoMap::NO_AUTO_EVICT);
1249 // Change the values for |docs_server|.
1250 std::string new_docs_server_info("new_docs_quic_server_info");
1251 quic_server_info_map.Put(docs_quic_server_id, new_docs_server_info);
1252 // Add data for mail.google.com:443.
1253 HostPortPair mail_server("mail.google.com", 443);
1254 QuicServerId mail_quic_server_id(mail_server, PRIVACY_MODE_ENABLED);
1255 std::string mail_server_info("mail_quic_server_info");
1256 quic_server_info_map.Put(mail_quic_server_id, mail_server_info);
1219 impl_.InitializeQuicServerInfoMap(&quic_server_info_map); 1257 impl_.InitializeQuicServerInfoMap(&quic_server_info_map);
1220 1258
1221 EXPECT_EQ(1u, impl_.quic_server_info_map().size()); 1259 // Recency order will be |docs_server|, |google_server| and |mail_server|.
1222 EXPECT_EQ(quic_server_info1, *impl_.GetQuicServerInfo(quic_server_id)); 1260 const QuicServerInfoMap& memory_map = impl_.quic_server_info_map();
1261 ASSERT_EQ(3u, memory_map.size());
1262 QuicServerInfoMap::const_iterator memory_map_it = memory_map.begin();
1263 EXPECT_EQ(memory_map_it->first, docs_quic_server_id);
1264 EXPECT_EQ(new_docs_server_info, memory_map_it->second);
1265 ++memory_map_it;
1266 EXPECT_EQ(memory_map_it->first, google_quic_server_id);
1267 EXPECT_EQ(google_server_info, memory_map_it->second);
1268 ++memory_map_it;
1269 EXPECT_EQ(memory_map_it->first, mail_quic_server_id);
1270 EXPECT_EQ(mail_server_info, memory_map_it->second);
1223 } 1271 }
1224 1272
1225 TEST_F(QuicServerInfoServerPropertiesTest, SetQuicServerInfo) { 1273 TEST_F(QuicServerInfoServerPropertiesTest, SetQuicServerInfo) {
1226 HostPortPair foo_server("foo", 80); 1274 HostPortPair foo_server("foo", 80);
1227 QuicServerId quic_server_id(foo_server, PRIVACY_MODE_ENABLED); 1275 QuicServerId quic_server_id(foo_server, PRIVACY_MODE_ENABLED);
1228 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); 1276 EXPECT_EQ(0u, impl_.quic_server_info_map().size());
1229 1277
1230 std::string quic_server_info1("quic_server_info1"); 1278 std::string quic_server_info1("quic_server_info1");
1231 impl_.SetQuicServerInfo(quic_server_id, quic_server_info1); 1279 impl_.SetQuicServerInfo(quic_server_id, quic_server_info1);
1232 1280
1233 EXPECT_EQ(1u, impl_.quic_server_info_map().size()); 1281 EXPECT_EQ(1u, impl_.quic_server_info_map().size());
1234 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); 1282 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id)));
1235 1283
1236 impl_.Clear(); 1284 impl_.Clear();
1237 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); 1285 EXPECT_EQ(0u, impl_.quic_server_info_map().size());
1238 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); 1286 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id));
1239 } 1287 }
1240 1288
1241 } // namespace 1289 } // namespace
1242 1290
1243 } // namespace net 1291 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698