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_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 1147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1158 | 1158 |
1159 EXPECT_FALSE(impl_.GetSupportsQuic(&address)); | 1159 EXPECT_FALSE(impl_.GetSupportsQuic(&address)); |
1160 } | 1160 } |
1161 | 1161 |
1162 typedef HttpServerPropertiesImplTest ServerNetworkStatsServerPropertiesTest; | 1162 typedef HttpServerPropertiesImplTest ServerNetworkStatsServerPropertiesTest; |
1163 | 1163 |
1164 TEST_F(ServerNetworkStatsServerPropertiesTest, Initialize) { | 1164 TEST_F(ServerNetworkStatsServerPropertiesTest, Initialize) { |
1165 HostPortPair google_server("www.google.com", 443); | 1165 HostPortPair google_server("www.google.com", 443); |
1166 | 1166 |
1167 // Check by initializing empty ServerNetworkStats. | 1167 // Check by initializing empty ServerNetworkStats. |
1168 ServerNetworkStatsMap server_network_stats_map( | 1168 ServerNetworkStatsMap init_server_network_stats_map( |
1169 ServerNetworkStatsMap::NO_AUTO_EVICT); | 1169 ServerNetworkStatsMap::NO_AUTO_EVICT); |
1170 impl_.InitializeServerNetworkStats(&server_network_stats_map); | 1170 impl_.InitializeServerNetworkStats(&init_server_network_stats_map); |
1171 const ServerNetworkStats* stats = impl_.GetServerNetworkStats(google_server); | 1171 const ServerNetworkStats* stats = impl_.GetServerNetworkStats(google_server); |
1172 EXPECT_EQ(NULL, stats); | 1172 EXPECT_EQ(NULL, stats); |
1173 | 1173 |
1174 // Check by initializing with www.google.com:443. | 1174 // Check by initializing with www.google.com:443. |
1175 ServerNetworkStats stats1; | 1175 ServerNetworkStats stats_google; |
1176 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 1176 stats_google.srtt = base::TimeDelta::FromMicroseconds(10); |
1177 stats1.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(100); | 1177 stats_google.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(100); |
1178 server_network_stats_map.Put(google_server, stats1); | 1178 init_server_network_stats_map.Put(google_server, stats_google); |
| 1179 impl_.InitializeServerNetworkStats(&init_server_network_stats_map); |
| 1180 |
| 1181 // Verify data for www.google.com:443. |
| 1182 ASSERT_EQ(1u, impl_.server_network_stats_map().size()); |
| 1183 EXPECT_EQ(stats_google, *(impl_.GetServerNetworkStats(google_server))); |
| 1184 |
| 1185 // Test recency order and overwriting of data. |
| 1186 // |
| 1187 // |docs_server| has a ServerNetworkStats, which will be overwritten by |
| 1188 // InitializeServerNetworkStats(), because |server_network_stats_map| has an |
| 1189 // entry for |docs_server|. |
| 1190 HostPortPair docs_server("docs.google.com", 443); |
| 1191 ServerNetworkStats stats_docs; |
| 1192 stats_docs.srtt = base::TimeDelta::FromMicroseconds(20); |
| 1193 stats_docs.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(200); |
| 1194 // Recency order will be |docs_server| and |google_server|. |
| 1195 impl_.SetServerNetworkStats(docs_server, stats_docs); |
| 1196 |
| 1197 // Prepare |server_network_stats_map| to be loaded by |
| 1198 // InitializeServerNetworkStats(). |
| 1199 ServerNetworkStatsMap server_network_stats_map( |
| 1200 ServerNetworkStatsMap::NO_AUTO_EVICT); |
| 1201 |
| 1202 // Change the values for |docs_server|. |
| 1203 ServerNetworkStats new_stats_docs; |
| 1204 new_stats_docs.srtt = base::TimeDelta::FromMicroseconds(25); |
| 1205 new_stats_docs.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(250); |
| 1206 server_network_stats_map.Put(docs_server, new_stats_docs); |
| 1207 // Add data for mail.google.com:443. |
| 1208 HostPortPair mail_server("mail.google.com", 443); |
| 1209 ServerNetworkStats stats_mail; |
| 1210 stats_mail.srtt = base::TimeDelta::FromMicroseconds(30); |
| 1211 stats_mail.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(300); |
| 1212 server_network_stats_map.Put(mail_server, stats_mail); |
| 1213 |
| 1214 // Recency order will be |docs_server|, |google_server| and |mail_server|. |
1179 impl_.InitializeServerNetworkStats(&server_network_stats_map); | 1215 impl_.InitializeServerNetworkStats(&server_network_stats_map); |
1180 | 1216 |
1181 const ServerNetworkStats* stats2 = impl_.GetServerNetworkStats(google_server); | 1217 const ServerNetworkStatsMap& map = impl_.server_network_stats_map(); |
1182 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 1218 ASSERT_EQ(3u, map.size()); |
1183 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); | 1219 ServerNetworkStatsMap::const_iterator map_it = map.begin(); |
| 1220 |
| 1221 EXPECT_TRUE(map_it->first.Equals(docs_server)); |
| 1222 EXPECT_EQ(new_stats_docs, map_it->second); |
| 1223 ++map_it; |
| 1224 EXPECT_TRUE(map_it->first.Equals(google_server)); |
| 1225 EXPECT_EQ(stats_google, map_it->second); |
| 1226 ++map_it; |
| 1227 EXPECT_TRUE(map_it->first.Equals(mail_server)); |
| 1228 EXPECT_EQ(stats_mail, map_it->second); |
1184 } | 1229 } |
1185 | 1230 |
1186 TEST_F(ServerNetworkStatsServerPropertiesTest, SetServerNetworkStats) { | 1231 TEST_F(ServerNetworkStatsServerPropertiesTest, SetServerNetworkStats) { |
1187 HostPortPair foo_server("foo", 80); | 1232 HostPortPair foo_server("foo", 80); |
1188 const ServerNetworkStats* stats = impl_.GetServerNetworkStats(foo_server); | 1233 const ServerNetworkStats* stats = impl_.GetServerNetworkStats(foo_server); |
1189 EXPECT_EQ(NULL, stats); | 1234 EXPECT_EQ(NULL, stats); |
1190 | 1235 |
1191 ServerNetworkStats stats1; | 1236 ServerNetworkStats stats1; |
1192 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 1237 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
1193 stats1.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(100); | 1238 stats1.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(100); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); | 1279 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); |
1235 | 1280 |
1236 impl_.Clear(); | 1281 impl_.Clear(); |
1237 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); | 1282 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); |
1238 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); | 1283 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); |
1239 } | 1284 } |
1240 | 1285 |
1241 } // namespace | 1286 } // namespace |
1242 | 1287 |
1243 } // namespace net | 1288 } // namespace net |
OLD | NEW |