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

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

Issue 2949513005: Update param types of HttpServerPropertiesImpl setters and getters. Fix MRU order when loading (Closed)
Patch Set: Added missing newline Created 3 years, 6 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) 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 <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 // when calling Serialize(). 101 // when calling Serialize().
102 std::string spdy_server_g = https_www_server.Serialize(); 102 std::string spdy_server_g = https_www_server.Serialize();
103 std::string spdy_server_p = http_photo_server.Serialize(); 103 std::string spdy_server_p = http_photo_server.Serialize();
104 104
105 url::SchemeHostPort http_google_server("http", "www.google.com", 443); 105 url::SchemeHostPort http_google_server("http", "www.google.com", 443);
106 url::SchemeHostPort https_photos_server("https", "photos.google.com", 443); 106 url::SchemeHostPort https_photos_server("https", "photos.google.com", 443);
107 url::SchemeHostPort valid_google_server((GURL("https://www.google.com"))); 107 url::SchemeHostPort valid_google_server((GURL("https://www.google.com")));
108 108
109 // Initializing https://www.google.com:443 and https://photos.google.com:443 109 // Initializing https://www.google.com:443 and https://photos.google.com:443
110 // as spdy servers. 110 // as spdy servers.
111 std::vector<std::string> spdy_servers1; 111 std::unique_ptr<SpdyServersMap> spdy_servers1 =
112 spdy_servers1.push_back(spdy_server_g); // Will be 0th index. 112 base::MakeUnique<SpdyServersMap>(SpdyServersMap::NO_AUTO_EVICT);
113 spdy_servers1.push_back(spdy_server_p); // Will be 1st index. 113 spdy_servers1->Put(spdy_server_g, true);
114 impl_.SetSpdyServers(&spdy_servers1, true); 114 spdy_servers1->Put(spdy_server_p, true);
115 impl_.SetSpdyServers(std::move(spdy_servers1));
115 EXPECT_TRUE(impl_.SupportsRequestPriority(http_photo_server)); 116 EXPECT_TRUE(impl_.SupportsRequestPriority(http_photo_server));
116 EXPECT_TRUE(impl_.SupportsRequestPriority(https_www_server)); 117 EXPECT_TRUE(impl_.SupportsRequestPriority(https_www_server));
117 EXPECT_FALSE(impl_.SupportsRequestPriority(http_google_server)); 118 EXPECT_FALSE(impl_.SupportsRequestPriority(http_google_server));
118 EXPECT_FALSE(impl_.SupportsRequestPriority(https_photos_server)); 119 EXPECT_FALSE(impl_.SupportsRequestPriority(https_photos_server));
119 EXPECT_TRUE(impl_.SupportsRequestPriority(valid_google_server)); 120 EXPECT_TRUE(impl_.SupportsRequestPriority(valid_google_server));
120 } 121 }
121 122
122 TEST_F(SpdyServerPropertiesTest, Set) { 123 TEST_F(SpdyServerPropertiesTest, Set) {
123 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); 124 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443);
124 std::string spdy_server_g = spdy_server_google.Serialize(); 125 std::string spdy_server_g = spdy_server_google.Serialize();
125 126
126 url::SchemeHostPort spdy_server_photos("https", "photos.google.com", 443); 127 url::SchemeHostPort spdy_server_photos("https", "photos.google.com", 443);
127 std::string spdy_server_p = spdy_server_photos.Serialize(); 128 std::string spdy_server_p = spdy_server_photos.Serialize();
128 129
129 url::SchemeHostPort spdy_server_docs("https", "docs.google.com", 443); 130 url::SchemeHostPort spdy_server_docs("https", "docs.google.com", 443);
130 std::string spdy_server_d = spdy_server_docs.Serialize(); 131 std::string spdy_server_d = spdy_server_docs.Serialize();
131 132
132 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); 133 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443);
133 std::string spdy_server_m = spdy_server_mail.Serialize(); 134 std::string spdy_server_m = spdy_server_mail.Serialize();
134 135
135 // Check by initializing NULL spdy servers.
136 impl_.SetSpdyServers(NULL, true);
137 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google));
138
139 // Check by initializing empty spdy servers. 136 // Check by initializing empty spdy servers.
140 std::vector<std::string> spdy_servers; 137 std::unique_ptr<SpdyServersMap> spdy_servers =
141 impl_.SetSpdyServers(&spdy_servers, true); 138 base::MakeUnique<SpdyServersMap>(SpdyServersMap::NO_AUTO_EVICT);
139 impl_.SetSpdyServers(std::move(spdy_servers));
142 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); 140 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google));
143 141
144 // Check by initializing www.google.com:443 and photos.google.com:443 as spdy 142 // Check by initializing www.google.com:443 and photos.google.com:443 as spdy
145 // servers. 143 // servers.
146 std::vector<std::string> spdy_servers1; 144 std::unique_ptr<SpdyServersMap> spdy_servers1 =
147 spdy_servers1.push_back(spdy_server_g); // Will be 0th index. 145 base::MakeUnique<SpdyServersMap>(SpdyServersMap::NO_AUTO_EVICT);
148 spdy_servers1.push_back(spdy_server_p); // Will be 1st index. 146 spdy_servers1->Put(spdy_server_g, true);
149 impl_.SetSpdyServers(&spdy_servers1, true); 147 spdy_servers1->Put(spdy_server_p, true);
148 impl_.SetSpdyServers(std::move(spdy_servers1));
149 // Note: these calls affect MRU order.
150 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google));
150 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_photos)); 151 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_photos));
151 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google));
152 152
153 // Verify spdy_server_g and spdy_server_d are in the list in the same order. 153 // Verify spdy_server_g and spdy_server_d are in the list in MRU order.
154 base::ListValue spdy_server_list; 154 std::vector<std::string> returned_spdy_servers;
155 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 155 impl_.GetSpdyServerList(&returned_spdy_servers, kMaxSupportsSpdyServerHosts);
156 EXPECT_EQ(2U, spdy_server_list.GetSize()); 156 ASSERT_EQ(2U, returned_spdy_servers.size());
157 std::string string_value_g; 157 EXPECT_EQ(spdy_server_p, returned_spdy_servers[0]);
158 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); // 0th index. 158 EXPECT_EQ(spdy_server_g, returned_spdy_servers[1]);
159 ASSERT_EQ(spdy_server_g, string_value_g);
160 std::string string_value_p;
161 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_p)); // 1st index.
162 ASSERT_EQ(spdy_server_p, string_value_p);
163 159
164 // Check by initializing mail.google.com:443 and docs.google.com:443 as spdy 160 // Check by initializing mail.google.com:443 and docs.google.com:443 as spdy
165 // servers. 161 // servers.
166 std::vector<std::string> spdy_servers2; 162 std::unique_ptr<SpdyServersMap> spdy_servers2 =
167 spdy_servers2.push_back(spdy_server_m); // Will be 2nd index. 163 base::MakeUnique<SpdyServersMap>(SpdyServersMap::NO_AUTO_EVICT);
168 spdy_servers2.push_back(spdy_server_d); // Will be 3rd index. 164 spdy_servers2->Put(spdy_server_m, true);
169 impl_.SetSpdyServers(&spdy_servers2, true); 165 spdy_servers2->Put(spdy_server_d, true);
166 impl_.SetSpdyServers(std::move(spdy_servers2));
170 167
171 // Verify all the servers are in the list in the same order. 168 // Verify all the servers are in the list in MRU order. Note that
172 spdy_server_list.Clear(); 169 // SetSpdyServers will put existing spdy server entries in front of newly
173 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 170 // added entries.
174 EXPECT_EQ(4U, spdy_server_list.GetSize()); 171 returned_spdy_servers.clear();
172 impl_.GetSpdyServerList(&returned_spdy_servers, kMaxSupportsSpdyServerHosts);
173 ASSERT_EQ(4U, returned_spdy_servers.size());
175 174
176 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); 175 EXPECT_EQ(spdy_server_p, returned_spdy_servers[0]);
177 ASSERT_EQ(spdy_server_g, string_value_g); 176 EXPECT_EQ(spdy_server_g, returned_spdy_servers[1]);
178 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_p)); 177 EXPECT_EQ(spdy_server_d, returned_spdy_servers[2]);
179 ASSERT_EQ(spdy_server_p, string_value_p); 178 EXPECT_EQ(spdy_server_m, returned_spdy_servers[3]);
180 std::string string_value_m;
181 ASSERT_TRUE(spdy_server_list.GetString(2, &string_value_m));
182 ASSERT_EQ(spdy_server_m, string_value_m);
183 std::string string_value_d;
184 ASSERT_TRUE(spdy_server_list.GetString(3, &string_value_d));
185 ASSERT_EQ(spdy_server_d, string_value_d);
186 179
180 // Check these in reverse MRU order so that MRU order stays the same.
181 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_mail));
187 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); 182 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs));
188 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_mail)); 183 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google));
189 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_photos)); 184 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_photos));
190 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google));
191 185
192 // Verify new data that is being initialized overwrites what is already in the 186 // Verify new data that is being initialized overwrites what is already in the
193 // memory and also verify the recency list order. 187 // memory and also verify the recency list order.
194 // 188 //
195 // Change supports SPDY value for photos and mails servers and order of 189 // Change supports SPDY value for photos and mails servers and order of
196 // initalization shouldn't matter. 190 // initalization shouldn't matter.
197 std::vector<std::string> spdy_servers3; 191 std::unique_ptr<SpdyServersMap> spdy_servers3 =
198 spdy_servers3.push_back(spdy_server_m); 192 base::MakeUnique<SpdyServersMap>(SpdyServersMap::NO_AUTO_EVICT);
199 spdy_servers3.push_back(spdy_server_p); 193 spdy_servers3->Put(spdy_server_m, false);
200 impl_.SetSpdyServers(&spdy_servers3, false); 194 spdy_servers3->Put(spdy_server_p, false);
195 impl_.SetSpdyServers(std::move(spdy_servers3));
201 196
202 // Verify the entries are in the same order. 197 // Verify the entries are in the same order.
203 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); 198 returned_spdy_servers.clear();
204 ASSERT_EQ(spdy_server_g, string_value_g); 199 impl_.GetSpdyServerList(&returned_spdy_servers, kMaxSupportsSpdyServerHosts);
205 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_p)); 200 EXPECT_EQ(2U, returned_spdy_servers.size());
206 ASSERT_EQ(spdy_server_p, string_value_p); 201
207 ASSERT_TRUE(spdy_server_list.GetString(2, &string_value_m)); 202 ASSERT_EQ(spdy_server_g, returned_spdy_servers[0]);
208 ASSERT_EQ(spdy_server_m, string_value_m); 203 ASSERT_EQ(spdy_server_d, returned_spdy_servers[1]);
209 ASSERT_TRUE(spdy_server_list.GetString(3, &string_value_d));
210 ASSERT_EQ(spdy_server_d, string_value_d);
211 204
212 // Verify photos and mail servers don't support SPDY and other servers support 205 // Verify photos and mail servers don't support SPDY and other servers support
213 // SPDY. 206 // SPDY.
207 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail));
214 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); 208 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs));
215 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); 209 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google));
216 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_photos)); 210 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_photos));
217 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google));
218 } 211 }
219 212
220 TEST_F(SpdyServerPropertiesTest, SupportsRequestPriorityTest) { 213 TEST_F(SpdyServerPropertiesTest, SupportsRequestPriorityTest) {
221 url::SchemeHostPort spdy_server_empty("https", std::string(), 443); 214 url::SchemeHostPort spdy_server_empty("https", std::string(), 443);
222 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_empty)); 215 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_empty));
223 216
224 // Add www.google.com:443 as supporting SPDY. 217 // Add www.google.com:443 as supporting SPDY.
225 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); 218 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443);
226 impl_.SetSupportsSpdy(spdy_server_google, true); 219 impl_.SetSupportsSpdy(spdy_server_google, true);
227 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); 220 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 259
267 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); 260 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google));
268 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_mail)); 261 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_mail));
269 262
270 impl_.Clear(); 263 impl_.Clear();
271 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google)); 264 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_google));
272 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); 265 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail));
273 } 266 }
274 267
275 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) { 268 TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) {
276 base::ListValue spdy_server_list; 269 std::vector<std::string> spdy_servers;
277 270
278 // Check there are no spdy_servers. 271 // Check there are no spdy_servers.
279 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 272 impl_.GetSpdyServerList(&spdy_servers, kMaxSupportsSpdyServerHosts);
280 EXPECT_EQ(0U, spdy_server_list.GetSize()); 273 EXPECT_EQ(0U, spdy_servers.size());
281 274
282 // Check empty server is not added. 275 // Check empty server is not added.
283 url::SchemeHostPort spdy_server_empty("https", std::string(), 443); 276 url::SchemeHostPort spdy_server_empty("https", std::string(), 443);
284 impl_.SetSupportsSpdy(spdy_server_empty, true); 277 impl_.SetSupportsSpdy(spdy_server_empty, true);
285 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 278 impl_.GetSpdyServerList(&spdy_servers, kMaxSupportsSpdyServerHosts);
286 EXPECT_EQ(0U, spdy_server_list.GetSize()); 279 EXPECT_EQ(0U, spdy_servers.size());
287 280
288 std::string string_value_g;
289 std::string string_value_m;
290 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); 281 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443);
291 std::string spdy_server_g = spdy_server_google.Serialize(); 282 std::string spdy_server_g = spdy_server_google.Serialize();
292 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); 283 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443);
293 std::string spdy_server_m = spdy_server_mail.Serialize(); 284 std::string spdy_server_m = spdy_server_mail.Serialize();
294 285
295 // Add www.google.com:443 as not supporting SPDY. 286 // Add www.google.com:443 as not supporting SPDY.
296 impl_.SetSupportsSpdy(spdy_server_google, false); 287 impl_.SetSupportsSpdy(spdy_server_google, false);
297 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 288 impl_.GetSpdyServerList(&spdy_servers, kMaxSupportsSpdyServerHosts);
298 EXPECT_EQ(0U, spdy_server_list.GetSize()); 289 EXPECT_EQ(0U, spdy_servers.size());
299 290
300 // Add www.google.com:443 as supporting SPDY. 291 // Add www.google.com:443 as supporting SPDY.
301 impl_.SetSupportsSpdy(spdy_server_google, true); 292 impl_.SetSupportsSpdy(spdy_server_google, true);
302 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 293 impl_.GetSpdyServerList(&spdy_servers, kMaxSupportsSpdyServerHosts);
303 ASSERT_EQ(1U, spdy_server_list.GetSize()); 294 ASSERT_EQ(1U, spdy_servers.size());
304 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); 295 ASSERT_EQ(spdy_server_g, spdy_servers[0]);
305 ASSERT_EQ(spdy_server_g, string_value_g);
306 296
307 // Add mail.google.com:443 as not supporting SPDY. 297 // Add mail.google.com:443 as not supporting SPDY.
308 impl_.SetSupportsSpdy(spdy_server_mail, false); 298 impl_.SetSupportsSpdy(spdy_server_mail, false);
309 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 299 impl_.GetSpdyServerList(&spdy_servers, kMaxSupportsSpdyServerHosts);
310 ASSERT_EQ(1U, spdy_server_list.GetSize()); 300 ASSERT_EQ(1U, spdy_servers.size());
311 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); 301 ASSERT_EQ(spdy_server_g, spdy_servers[0]);
312 ASSERT_EQ(spdy_server_g, string_value_g);
313 302
314 // Add mail.google.com:443 as supporting SPDY. 303 // Add mail.google.com:443 as supporting SPDY.
315 impl_.SetSupportsSpdy(spdy_server_mail, true); 304 impl_.SetSupportsSpdy(spdy_server_mail, true);
316 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 305 impl_.GetSpdyServerList(&spdy_servers, kMaxSupportsSpdyServerHosts);
317 ASSERT_EQ(2U, spdy_server_list.GetSize()); 306 ASSERT_EQ(2U, spdy_servers.size());
318 307
319 // Verify www.google.com:443 and mail.google.com:443 are in the list. 308 // Verify www.google.com:443 and mail.google.com:443 are in the list.
320 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); 309 ASSERT_EQ(spdy_server_m, spdy_servers[0]);
321 ASSERT_EQ(spdy_server_m, string_value_m); 310 ASSERT_EQ(spdy_server_g, spdy_servers[1]);
322 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_g));
323 ASSERT_EQ(spdy_server_g, string_value_g);
324 311
325 // Request for only one server and verify that we get only one server. 312 // Request for only one server and verify that we get only one server.
326 impl_.GetSpdyServerList(&spdy_server_list, 1); 313 impl_.GetSpdyServerList(&spdy_servers, 1);
327 ASSERT_EQ(1U, spdy_server_list.GetSize()); 314 ASSERT_EQ(1U, spdy_servers.size());
328 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); 315 ASSERT_EQ(spdy_server_m, spdy_servers[0]);
329 ASSERT_EQ(spdy_server_m, string_value_m);
330 } 316 }
331 317
332 TEST_F(SpdyServerPropertiesTest, MRUOfGetSpdyServerList) { 318 TEST_F(SpdyServerPropertiesTest, MRUOfGetSpdyServers) {
333 base::ListValue spdy_server_list; 319 std::vector<std::string> spdy_servers;
334 320
335 std::string string_value_g;
336 std::string string_value_m;
337 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); 321 url::SchemeHostPort spdy_server_google("https", "www.google.com", 443);
338 std::string spdy_server_g = spdy_server_google.Serialize(); 322 std::string spdy_server_g = spdy_server_google.Serialize();
339 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); 323 url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443);
340 std::string spdy_server_m = spdy_server_mail.Serialize(); 324 std::string spdy_server_m = spdy_server_mail.Serialize();
341 325
342 // Add www.google.com:443 as supporting SPDY. 326 // Add www.google.com:443 as supporting SPDY.
343 impl_.SetSupportsSpdy(spdy_server_google, true); 327 impl_.SetSupportsSpdy(spdy_server_google, true);
344 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 328 impl_.GetSpdyServerList(&spdy_servers, kMaxSupportsSpdyServerHosts);
345 ASSERT_EQ(1U, spdy_server_list.GetSize()); 329 ASSERT_EQ(1U, spdy_servers.size());
346 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); 330 ASSERT_EQ(spdy_server_g, spdy_servers[0]);
347 ASSERT_EQ(spdy_server_g, string_value_g);
348 331
349 // Add mail.google.com:443 as supporting SPDY. Verify mail.google.com:443 and 332 // Add mail.google.com:443 as supporting SPDY. Verify mail.google.com:443 and
350 // www.google.com:443 are in the list. 333 // www.google.com:443 are in the list.
351 impl_.SetSupportsSpdy(spdy_server_mail, true); 334 impl_.SetSupportsSpdy(spdy_server_mail, true);
352 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 335 impl_.GetSpdyServerList(&spdy_servers, kMaxSupportsSpdyServerHosts);
353 ASSERT_EQ(2U, spdy_server_list.GetSize()); 336 ASSERT_EQ(2U, spdy_servers.size());
354 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); 337 ASSERT_EQ(spdy_server_m, spdy_servers[0]);
355 ASSERT_EQ(spdy_server_m, string_value_m); 338 ASSERT_EQ(spdy_server_g, spdy_servers[1]);
356 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_g));
357 ASSERT_EQ(spdy_server_g, string_value_g);
358 339
359 // Get www.google.com:443 should reorder SpdyServerHostPortMap. Verify that it 340 // Get www.google.com:443 should reorder SpdyServerHostPortMap. Verify that it
360 // is www.google.com:443 is the MRU server. 341 // is www.google.com:443 is the MRU server.
361 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); 342 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google));
362 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); 343 impl_.GetSpdyServerList(&spdy_servers, kMaxSupportsSpdyServerHosts);
363 ASSERT_EQ(2U, spdy_server_list.GetSize()); 344 ASSERT_EQ(2U, spdy_servers.size());
364 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); 345 ASSERT_EQ(spdy_server_g, spdy_servers[0]);
365 ASSERT_EQ(spdy_server_g, string_value_g); 346 ASSERT_EQ(spdy_server_m, spdy_servers[1]);
366 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m));
367 ASSERT_EQ(spdy_server_m, string_value_m);
368 } 347 }
369 348
370 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; 349 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest;
371 350
372 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { 351 TEST_F(AlternateProtocolServerPropertiesTest, Basic) {
373 url::SchemeHostPort test_server("http", "foo", 80); 352 url::SchemeHostPort test_server("http", "foo", 80);
374 EXPECT_FALSE(HasAlternativeService(test_server)); 353 EXPECT_FALSE(HasAlternativeService(test_server));
375 354
376 AlternativeService alternative_service(kProtoHTTP2, "foo", 443); 355 AlternativeService alternative_service(kProtoHTTP2, "foo", 443);
377 SetAlternativeService(test_server, alternative_service); 356 SetAlternativeService(test_server, alternative_service);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 const AlternativeService alternative_service2(kProtoHTTP2, "bar2", 443); 415 const AlternativeService alternative_service2(kProtoHTTP2, "bar2", 443);
437 base::Time expiration2 = now + base::TimeDelta::FromDays(2); 416 base::Time expiration2 = now + base::TimeDelta::FromDays(2);
438 alternative_service_info_vector.push_back( 417 alternative_service_info_vector.push_back(
439 AlternativeServiceInfo(alternative_service2, expiration2)); 418 AlternativeServiceInfo(alternative_service2, expiration2));
440 url::SchemeHostPort test_server2("http", "foo2", 80); 419 url::SchemeHostPort test_server2("http", "foo2", 80);
441 // 0th entry in the memory. 420 // 0th entry in the memory.
442 impl_.SetAlternativeServices(test_server2, alternative_service_info_vector); 421 impl_.SetAlternativeServices(test_server2, alternative_service_info_vector);
443 422
444 // Prepare |alternative_service_map| to be loaded by 423 // Prepare |alternative_service_map| to be loaded by
445 // SetAlternativeServiceServers(). 424 // SetAlternativeServiceServers().
446 AlternativeServiceMap alternative_service_map( 425 std::unique_ptr<AlternativeServiceMap> alternative_service_map =
447 AlternativeServiceMap::NO_AUTO_EVICT); 426 base::MakeUnique<AlternativeServiceMap>(
427 AlternativeServiceMap::NO_AUTO_EVICT);
448 const AlternativeService alternative_service3(kProtoHTTP2, "bar3", 123); 428 const AlternativeService alternative_service3(kProtoHTTP2, "bar3", 123);
449 base::Time expiration3 = now + base::TimeDelta::FromDays(3); 429 base::Time expiration3 = now + base::TimeDelta::FromDays(3);
450 const AlternativeServiceInfo alternative_service_info1(alternative_service3, 430 const AlternativeServiceInfo alternative_service_info1(alternative_service3,
451 expiration3); 431 expiration3);
452 // Simulate updating data for 0th entry with data from Preferences. 432 // Simulate updating data for 0th entry with data from Preferences.
453 alternative_service_map.Put( 433 alternative_service_map->Put(
454 test_server2, 434 test_server2,
455 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info1)); 435 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info1));
456 436
457 url::SchemeHostPort test_server3("http", "foo3", 80); 437 url::SchemeHostPort test_server3("http", "foo3", 80);
458 const AlternativeService alternative_service4(kProtoHTTP2, "bar4", 1234); 438 const AlternativeService alternative_service4(kProtoHTTP2, "bar4", 1234);
459 base::Time expiration4 = now + base::TimeDelta::FromDays(4); 439 base::Time expiration4 = now + base::TimeDelta::FromDays(4);
460 const AlternativeServiceInfo alternative_service_info2(alternative_service4, 440 const AlternativeServiceInfo alternative_service_info2(alternative_service4,
461 expiration4); 441 expiration4);
462 // Add an old entry from Preferences, this will be added to end of recency 442 // Add an old entry from Preferences, this will be added to end of recency
463 // list. 443 // list.
464 alternative_service_map.Put( 444 alternative_service_map->Put(
465 test_server3, 445 test_server3,
466 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info2)); 446 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info2));
467 447
468 // MRU list will be test_server2, test_server1, test_server3. 448 // MRU list will be test_server2, test_server1, test_server3.
469 impl_.SetAlternativeServiceServers(&alternative_service_map); 449 impl_.SetAlternativeServiceServers(std::move(alternative_service_map));
470 450
471 // Verify alternative_service_map. 451 // Verify alternative_service_map.
472 const AlternativeServiceMap& map = impl_.alternative_service_map(); 452 const AlternativeServiceMap& map = impl_.alternative_service_map();
473 ASSERT_EQ(3u, map.size()); 453 ASSERT_EQ(3u, map.size());
474 AlternativeServiceMap::const_iterator map_it = map.begin(); 454 AlternativeServiceMap::const_iterator map_it = map.begin();
475 455
476 EXPECT_TRUE(map_it->first.Equals(test_server2)); 456 EXPECT_TRUE(map_it->first.Equals(test_server2));
477 ASSERT_EQ(1u, map_it->second.size()); 457 ASSERT_EQ(1u, map_it->second.size());
478 EXPECT_EQ(alternative_service3, map_it->second[0].alternative_service()); 458 EXPECT_EQ(alternative_service3, map_it->second[0].alternative_service());
479 EXPECT_EQ(expiration3, map_it->second[0].expiration()); 459 EXPECT_EQ(expiration3, map_it->second[0].expiration());
(...skipping 14 matching lines...) Expand all
494 // hostname is the mapping. 474 // hostname is the mapping.
495 TEST_F(AlternateProtocolServerPropertiesTest, SetWithEmptyHostname) { 475 TEST_F(AlternateProtocolServerPropertiesTest, SetWithEmptyHostname) {
496 url::SchemeHostPort server("https", "foo", 443); 476 url::SchemeHostPort server("https", "foo", 443);
497 const AlternativeService alternative_service_with_empty_hostname(kProtoHTTP2, 477 const AlternativeService alternative_service_with_empty_hostname(kProtoHTTP2,
498 "", 1234); 478 "", 1234);
499 const AlternativeService alternative_service_with_foo_hostname(kProtoHTTP2, 479 const AlternativeService alternative_service_with_foo_hostname(kProtoHTTP2,
500 "foo", 1234); 480 "foo", 1234);
501 SetAlternativeService(server, alternative_service_with_empty_hostname); 481 SetAlternativeService(server, alternative_service_with_empty_hostname);
502 impl_.MarkAlternativeServiceBroken(alternative_service_with_foo_hostname); 482 impl_.MarkAlternativeServiceBroken(alternative_service_with_foo_hostname);
503 483
504 AlternativeServiceMap alternative_service_map( 484 std::unique_ptr<AlternativeServiceMap> alternative_service_map =
505 AlternativeServiceMap::NO_AUTO_EVICT); 485 base::MakeUnique<AlternativeServiceMap>(
506 impl_.SetAlternativeServiceServers(&alternative_service_map); 486 AlternativeServiceMap::NO_AUTO_EVICT);
487 impl_.SetAlternativeServiceServers(std::move(alternative_service_map));
507 488
508 EXPECT_TRUE( 489 EXPECT_TRUE(
509 impl_.IsAlternativeServiceBroken(alternative_service_with_foo_hostname)); 490 impl_.IsAlternativeServiceBroken(alternative_service_with_foo_hostname));
510 const AlternativeServiceInfoVector alternative_service_info_vector = 491 const AlternativeServiceInfoVector alternative_service_info_vector =
511 impl_.GetAlternativeServiceInfos(server); 492 impl_.GetAlternativeServiceInfos(server);
512 ASSERT_EQ(1u, alternative_service_info_vector.size()); 493 ASSERT_EQ(1u, alternative_service_info_vector.size());
513 EXPECT_EQ(alternative_service_with_foo_hostname, 494 EXPECT_EQ(alternative_service_with_foo_hostname,
514 alternative_service_info_vector[0].alternative_service()); 495 alternative_service_info_vector[0].alternative_service());
515 } 496 }
516 497
517 // Regression test for https://crbug.com/516486: 498 // Regression test for https://crbug.com/516486:
518 // GetAlternativeServiceInfos() should remove |alternative_service_map_| 499 // GetAlternativeServiceInfos() should remove |alternative_service_map_|
519 // elements with empty value. 500 // elements with empty value.
520 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVector) { 501 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVector) {
521 url::SchemeHostPort server("https", "foo", 443); 502 url::SchemeHostPort server("https", "foo", 443);
522 const AlternativeService alternative_service(kProtoHTTP2, "bar", 443); 503 const AlternativeService alternative_service(kProtoHTTP2, "bar", 443);
523 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); 504 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1);
524 const AlternativeServiceInfo alternative_service_info(alternative_service, 505 const AlternativeServiceInfo alternative_service_info(alternative_service,
525 expiration); 506 expiration);
526 AlternativeServiceMap alternative_service_map( 507 std::unique_ptr<AlternativeServiceMap> alternative_service_map =
527 AlternativeServiceMap::NO_AUTO_EVICT); 508 base::MakeUnique<AlternativeServiceMap>(
528 alternative_service_map.Put( 509 AlternativeServiceMap::NO_AUTO_EVICT);
510 alternative_service_map->Put(
529 server, 511 server,
530 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); 512 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info));
531 513
532 // Prepare |alternative_service_map_| with a single key that has a single 514 // Prepare |alternative_service_map_| with a single key that has a single
533 // AlternativeServiceInfo with identical hostname and port. 515 // AlternativeServiceInfo with identical hostname and port.
534 impl_.SetAlternativeServiceServers(&alternative_service_map); 516 impl_.SetAlternativeServiceServers(std::move(alternative_service_map));
535 517
536 // GetAlternativeServiceInfos() should remove such AlternativeServiceInfo from 518 // GetAlternativeServiceInfos() should remove such AlternativeServiceInfo from
537 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector 519 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector
538 // corresponding to |server|. 520 // corresponding to |server|.
539 ASSERT_TRUE(impl_.GetAlternativeServiceInfos(server).empty()); 521 ASSERT_TRUE(impl_.GetAlternativeServiceInfos(server).empty());
540 522
541 // GetAlternativeServiceInfos() should remove this key from 523 // GetAlternativeServiceInfos() should remove this key from
542 // |alternative_service_map_|, and SetAlternativeServices() should not crash. 524 // |alternative_service_map_|, and SetAlternativeServices() should not crash.
543 impl_.SetAlternativeServices( 525 impl_.SetAlternativeServices(
544 server, 526 server,
545 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); 527 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info));
546 528
547 // There should still be no alternative service assigned to |server|. 529 // There should still be no alternative service assigned to |server|.
548 ASSERT_TRUE(impl_.GetAlternativeServiceInfos(server).empty()); 530 ASSERT_TRUE(impl_.GetAlternativeServiceInfos(server).empty());
549 } 531 }
550 532
551 // Regression test for https://crbug.com/516486 for the canonical host case. 533 // Regression test for https://crbug.com/516486 for the canonical host case.
552 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVectorForCanonical) { 534 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVectorForCanonical) {
553 url::SchemeHostPort server("https", "foo.c.youtube.com", 443); 535 url::SchemeHostPort server("https", "foo.c.youtube.com", 443);
554 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); 536 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443);
555 const AlternativeService alternative_service(kProtoHTTP2, "", 443); 537 const AlternativeService alternative_service(kProtoHTTP2, "", 443);
556 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); 538 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1);
557 const AlternativeServiceInfo alternative_service_info(alternative_service, 539 const AlternativeServiceInfo alternative_service_info(alternative_service,
558 expiration); 540 expiration);
559 AlternativeServiceMap alternative_service_map( 541 std::unique_ptr<AlternativeServiceMap> alternative_service_map =
560 AlternativeServiceMap::NO_AUTO_EVICT); 542 base::MakeUnique<AlternativeServiceMap>(
561 alternative_service_map.Put( 543 AlternativeServiceMap::NO_AUTO_EVICT);
544 alternative_service_map->Put(
562 canonical_server, 545 canonical_server,
563 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); 546 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info));
564 547
565 // Prepare |alternative_service_map_| with a single key that has a single 548 // Prepare |alternative_service_map_| with a single key that has a single
566 // AlternativeServiceInfo with identical hostname and port. 549 // AlternativeServiceInfo with identical hostname and port.
567 impl_.SetAlternativeServiceServers(&alternative_service_map); 550 impl_.SetAlternativeServiceServers(std::move(alternative_service_map));
568 551
569 // GetAlternativeServiceInfos() should remove such AlternativeServiceInfo from 552 // GetAlternativeServiceInfos() should remove such AlternativeServiceInfo from
570 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector 553 // |alternative_service_map_|, emptying the AlternativeServiceInfoVector
571 // corresponding to |canonical_server|, even when looking up 554 // corresponding to |canonical_server|, even when looking up
572 // alternative services for |server|. 555 // alternative services for |server|.
573 ASSERT_TRUE(impl_.GetAlternativeServiceInfos(server).empty()); 556 ASSERT_TRUE(impl_.GetAlternativeServiceInfos(server).empty());
574 557
575 // GetAlternativeServiceInfos() should remove this key from 558 // GetAlternativeServiceInfos() should remove this key from
576 // |alternative_service_map_|, and SetAlternativeServices() should not crash. 559 // |alternative_service_map_|, and SetAlternativeServices() should not crash.
577 impl_.SetAlternativeServices( 560 impl_.SetAlternativeServices(
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service2)); 1070 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service2));
1088 } 1071 }
1089 1072
1090 typedef HttpServerPropertiesImplTest SupportsQuicServerPropertiesTest; 1073 typedef HttpServerPropertiesImplTest SupportsQuicServerPropertiesTest;
1091 1074
1092 TEST_F(SupportsQuicServerPropertiesTest, Set) { 1075 TEST_F(SupportsQuicServerPropertiesTest, Set) {
1093 HostPortPair quic_server_google("www.google.com", 443); 1076 HostPortPair quic_server_google("www.google.com", 443);
1094 1077
1095 // Check by initializing empty address. 1078 // Check by initializing empty address.
1096 IPAddress initial_address; 1079 IPAddress initial_address;
1097 impl_.SetSupportsQuic(&initial_address); 1080 impl_.SetSupportsQuic(initial_address);
1098 1081
1099 IPAddress address; 1082 IPAddress address;
1100 EXPECT_FALSE(impl_.GetSupportsQuic(&address)); 1083 EXPECT_FALSE(impl_.GetSupportsQuic(&address));
1101 EXPECT_TRUE(address.empty()); 1084 EXPECT_TRUE(address.empty());
1102 1085
1103 // Check by initializing with a valid address. 1086 // Check by initializing with a valid address.
1104 initial_address = IPAddress::IPv4Localhost(); 1087 initial_address = IPAddress::IPv4Localhost();
1105 impl_.SetSupportsQuic(&initial_address); 1088 impl_.SetSupportsQuic(initial_address);
1106 1089
1107 EXPECT_TRUE(impl_.GetSupportsQuic(&address)); 1090 EXPECT_TRUE(impl_.GetSupportsQuic(&address));
1108 EXPECT_EQ(initial_address, address); 1091 EXPECT_EQ(initial_address, address);
1109 } 1092 }
1110 1093
1111 TEST_F(SupportsQuicServerPropertiesTest, SetSupportsQuic) { 1094 TEST_F(SupportsQuicServerPropertiesTest, SetSupportsQuic) {
1112 IPAddress address; 1095 IPAddress address;
1113 EXPECT_FALSE(impl_.GetSupportsQuic(&address)); 1096 EXPECT_FALSE(impl_.GetSupportsQuic(&address));
1114 EXPECT_TRUE(address.empty()); 1097 EXPECT_TRUE(address.empty());
1115 1098
1116 IPAddress actual_address(127, 0, 0, 1); 1099 IPAddress actual_address(127, 0, 0, 1);
1117 impl_.SetSupportsQuic(true, actual_address); 1100 impl_.SetSupportsQuic(true, actual_address);
1118 1101
1119 EXPECT_TRUE(impl_.GetSupportsQuic(&address)); 1102 EXPECT_TRUE(impl_.GetSupportsQuic(&address));
1120 EXPECT_EQ(actual_address, address); 1103 EXPECT_EQ(actual_address, address);
1121 1104
1122 impl_.Clear(); 1105 impl_.Clear();
1123 1106
1124 EXPECT_FALSE(impl_.GetSupportsQuic(&address)); 1107 EXPECT_FALSE(impl_.GetSupportsQuic(&address));
1125 } 1108 }
1126 1109
1127 typedef HttpServerPropertiesImplTest ServerNetworkStatsServerPropertiesTest; 1110 typedef HttpServerPropertiesImplTest ServerNetworkStatsServerPropertiesTest;
1128 1111
1129 TEST_F(ServerNetworkStatsServerPropertiesTest, Set) { 1112 TEST_F(ServerNetworkStatsServerPropertiesTest, Set) {
1130 url::SchemeHostPort google_server("https", "www.google.com", 443); 1113 url::SchemeHostPort google_server("https", "www.google.com", 443);
1131 1114
1132 // Check by initializing empty ServerNetworkStats. 1115 // Check by initializing empty ServerNetworkStats.
1133 ServerNetworkStatsMap init_server_network_stats_map( 1116 std::unique_ptr<ServerNetworkStatsMap> init_server_network_stats_map =
1134 ServerNetworkStatsMap::NO_AUTO_EVICT); 1117 base::MakeUnique<ServerNetworkStatsMap>(
1135 impl_.SetServerNetworkStats(&init_server_network_stats_map); 1118 ServerNetworkStatsMap::NO_AUTO_EVICT);
1119 impl_.SetServerNetworkStats(std::move(init_server_network_stats_map));
1136 const ServerNetworkStats* stats = impl_.GetServerNetworkStats(google_server); 1120 const ServerNetworkStats* stats = impl_.GetServerNetworkStats(google_server);
1137 EXPECT_EQ(NULL, stats); 1121 EXPECT_EQ(NULL, stats);
1138 1122
1139 // Check by initializing with www.google.com:443. 1123 // Check by initializing with www.google.com:443.
1140 ServerNetworkStats stats_google; 1124 ServerNetworkStats stats_google;
1141 stats_google.srtt = base::TimeDelta::FromMicroseconds(10); 1125 stats_google.srtt = base::TimeDelta::FromMicroseconds(10);
1142 stats_google.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(100); 1126 stats_google.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(100);
1143 init_server_network_stats_map.Put(google_server, stats_google); 1127 init_server_network_stats_map = base::MakeUnique<ServerNetworkStatsMap>(
1144 impl_.SetServerNetworkStats(&init_server_network_stats_map); 1128 ServerNetworkStatsMap::NO_AUTO_EVICT);
1129 init_server_network_stats_map->Put(google_server, stats_google);
1130 impl_.SetServerNetworkStats(std::move(init_server_network_stats_map));
1145 1131
1146 // Verify data for www.google.com:443. 1132 // Verify data for www.google.com:443.
1147 ASSERT_EQ(1u, impl_.server_network_stats_map().size()); 1133 ASSERT_EQ(1u, impl_.server_network_stats_map().size());
1148 EXPECT_EQ(stats_google, *(impl_.GetServerNetworkStats(google_server))); 1134 EXPECT_EQ(stats_google, *(impl_.GetServerNetworkStats(google_server)));
1149 1135
1150 // Test recency order and overwriting of data. 1136 // Test recency order and overwriting of data.
1151 // 1137 //
1152 // |docs_server| has a ServerNetworkStats, which will be overwritten by 1138 // |docs_server| has a ServerNetworkStats, which will be overwritten by
1153 // SetServerNetworkStats(), because |server_network_stats_map| has an 1139 // SetServerNetworkStats(), because |server_network_stats_map| has an
1154 // entry for |docs_server|. 1140 // entry for |docs_server|.
1155 url::SchemeHostPort docs_server("https", "docs.google.com", 443); 1141 url::SchemeHostPort docs_server("https", "docs.google.com", 443);
1156 ServerNetworkStats stats_docs; 1142 ServerNetworkStats stats_docs;
1157 stats_docs.srtt = base::TimeDelta::FromMicroseconds(20); 1143 stats_docs.srtt = base::TimeDelta::FromMicroseconds(20);
1158 stats_docs.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(200); 1144 stats_docs.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(200);
1159 // Recency order will be |docs_server| and |google_server|. 1145 // Recency order will be |docs_server| and |google_server|.
1160 impl_.SetServerNetworkStats(docs_server, stats_docs); 1146 impl_.SetServerNetworkStats(docs_server, stats_docs);
1161 1147
1162 // Prepare |server_network_stats_map| to be loaded by 1148 // Prepare |server_network_stats_map| to be loaded by
1163 // SetServerNetworkStats(). 1149 // SetServerNetworkStats().
1164 ServerNetworkStatsMap server_network_stats_map( 1150 std::unique_ptr<ServerNetworkStatsMap> server_network_stats_map =
1165 ServerNetworkStatsMap::NO_AUTO_EVICT); 1151 base::MakeUnique<ServerNetworkStatsMap>(
1152 ServerNetworkStatsMap::NO_AUTO_EVICT);
1166 1153
1167 // Change the values for |docs_server|. 1154 // Change the values for |docs_server|.
1168 ServerNetworkStats new_stats_docs; 1155 ServerNetworkStats new_stats_docs;
1169 new_stats_docs.srtt = base::TimeDelta::FromMicroseconds(25); 1156 new_stats_docs.srtt = base::TimeDelta::FromMicroseconds(25);
1170 new_stats_docs.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(250); 1157 new_stats_docs.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(250);
1171 server_network_stats_map.Put(docs_server, new_stats_docs); 1158 server_network_stats_map->Put(docs_server, new_stats_docs);
1172 // Add data for mail.google.com:443. 1159 // Add data for mail.google.com:443.
1173 url::SchemeHostPort mail_server("https", "mail.google.com", 443); 1160 url::SchemeHostPort mail_server("https", "mail.google.com", 443);
1174 ServerNetworkStats stats_mail; 1161 ServerNetworkStats stats_mail;
1175 stats_mail.srtt = base::TimeDelta::FromMicroseconds(30); 1162 stats_mail.srtt = base::TimeDelta::FromMicroseconds(30);
1176 stats_mail.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(300); 1163 stats_mail.bandwidth_estimate = QuicBandwidth::FromBitsPerSecond(300);
1177 server_network_stats_map.Put(mail_server, stats_mail); 1164 server_network_stats_map->Put(mail_server, stats_mail);
1178 1165
1179 // Recency order will be |docs_server|, |google_server| and |mail_server|. 1166 // Recency order will be |docs_server|, |google_server| and |mail_server|.
1180 impl_.SetServerNetworkStats(&server_network_stats_map); 1167 impl_.SetServerNetworkStats(std::move(server_network_stats_map));
1181 1168
1182 const ServerNetworkStatsMap& map = impl_.server_network_stats_map(); 1169 const ServerNetworkStatsMap& map = impl_.server_network_stats_map();
1183 ASSERT_EQ(3u, map.size()); 1170 ASSERT_EQ(3u, map.size());
1184 ServerNetworkStatsMap::const_iterator map_it = map.begin(); 1171 ServerNetworkStatsMap::const_iterator map_it = map.begin();
1185 1172
1186 EXPECT_TRUE(map_it->first.Equals(docs_server)); 1173 EXPECT_TRUE(map_it->first.Equals(docs_server));
1187 EXPECT_EQ(new_stats_docs, map_it->second); 1174 EXPECT_EQ(new_stats_docs, map_it->second);
1188 ++map_it; 1175 ++map_it;
1189 EXPECT_TRUE(map_it->first.Equals(google_server)); 1176 EXPECT_TRUE(map_it->first.Equals(google_server));
1190 EXPECT_EQ(stats_google, map_it->second); 1177 EXPECT_EQ(stats_google, map_it->second);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 TEST_F(QuicServerInfoServerPropertiesTest, Set) { 1219 TEST_F(QuicServerInfoServerPropertiesTest, Set) {
1233 HostPortPair google_server("www.google.com", 443); 1220 HostPortPair google_server("www.google.com", 443);
1234 QuicServerId google_quic_server_id(google_server, PRIVACY_MODE_ENABLED); 1221 QuicServerId google_quic_server_id(google_server, PRIVACY_MODE_ENABLED);
1235 1222
1236 EXPECT_EQ(QuicServerInfoMap::NO_AUTO_EVICT, 1223 EXPECT_EQ(QuicServerInfoMap::NO_AUTO_EVICT,
1237 impl_.quic_server_info_map().max_size()); 1224 impl_.quic_server_info_map().max_size());
1238 impl_.SetMaxServerConfigsStoredInProperties(10); 1225 impl_.SetMaxServerConfigsStoredInProperties(10);
1239 EXPECT_EQ(10u, impl_.quic_server_info_map().max_size()); 1226 EXPECT_EQ(10u, impl_.quic_server_info_map().max_size());
1240 1227
1241 // Check empty map. 1228 // Check empty map.
1242 QuicServerInfoMap init_quic_server_info_map(QuicServerInfoMap::NO_AUTO_EVICT); 1229 std::unique_ptr<QuicServerInfoMap> init_quic_server_info_map =
1243 impl_.SetQuicServerInfoMap(&init_quic_server_info_map); 1230 base::MakeUnique<QuicServerInfoMap>(QuicServerInfoMap::NO_AUTO_EVICT);
1231 impl_.SetQuicServerInfoMap(std::move(init_quic_server_info_map));
1244 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); 1232 EXPECT_EQ(0u, impl_.quic_server_info_map().size());
1245 1233
1246 // Check by initializing with www.google.com:443. 1234 // Check by initializing with www.google.com:443.
1247 std::string google_server_info("google_quic_server_info"); 1235 std::string google_server_info("google_quic_server_info");
1248 init_quic_server_info_map.Put(google_quic_server_id, google_server_info); 1236 init_quic_server_info_map =
1249 impl_.SetQuicServerInfoMap(&init_quic_server_info_map); 1237 base::MakeUnique<QuicServerInfoMap>(QuicServerInfoMap::NO_AUTO_EVICT);
1238 init_quic_server_info_map->Put(google_quic_server_id, google_server_info);
1239 impl_.SetQuicServerInfoMap(std::move(init_quic_server_info_map));
1250 1240
1251 // Verify data for www.google.com:443. 1241 // Verify data for www.google.com:443.
1252 EXPECT_EQ(1u, impl_.quic_server_info_map().size()); 1242 EXPECT_EQ(1u, impl_.quic_server_info_map().size());
1253 EXPECT_EQ(google_server_info, 1243 EXPECT_EQ(google_server_info,
1254 *impl_.GetQuicServerInfo(google_quic_server_id)); 1244 *impl_.GetQuicServerInfo(google_quic_server_id));
1255 1245
1256 // Test recency order and overwriting of data. 1246 // Test recency order and overwriting of data.
1257 // 1247 //
1258 // |docs_server| has a QuicServerInfo, which will be overwritten by 1248 // |docs_server| has a QuicServerInfo, which will be overwritten by
1259 // SetQuicServerInfoMap(), because |quic_server_info_map| has an 1249 // SetQuicServerInfoMap(), because |quic_server_info_map| has an
1260 // entry for |docs_server|. 1250 // entry for |docs_server|.
1261 HostPortPair docs_server("docs.google.com", 443); 1251 HostPortPair docs_server("docs.google.com", 443);
1262 QuicServerId docs_quic_server_id(docs_server, PRIVACY_MODE_ENABLED); 1252 QuicServerId docs_quic_server_id(docs_server, PRIVACY_MODE_ENABLED);
1263 std::string docs_server_info("docs_quic_server_info"); 1253 std::string docs_server_info("docs_quic_server_info");
1264 impl_.SetQuicServerInfo(docs_quic_server_id, docs_server_info); 1254 impl_.SetQuicServerInfo(docs_quic_server_id, docs_server_info);
1265 1255
1266 // Recency order will be |docs_server| and |google_server|. 1256 // Recency order will be |docs_server| and |google_server|.
1267 const QuicServerInfoMap& map = impl_.quic_server_info_map(); 1257 const QuicServerInfoMap& map = impl_.quic_server_info_map();
1268 ASSERT_EQ(2u, map.size()); 1258 ASSERT_EQ(2u, map.size());
1269 QuicServerInfoMap::const_iterator map_it = map.begin(); 1259 QuicServerInfoMap::const_iterator map_it = map.begin();
1270 EXPECT_EQ(map_it->first, docs_quic_server_id); 1260 EXPECT_EQ(map_it->first, docs_quic_server_id);
1271 EXPECT_EQ(docs_server_info, map_it->second); 1261 EXPECT_EQ(docs_server_info, map_it->second);
1272 ++map_it; 1262 ++map_it;
1273 EXPECT_EQ(map_it->first, google_quic_server_id); 1263 EXPECT_EQ(map_it->first, google_quic_server_id);
1274 EXPECT_EQ(google_server_info, map_it->second); 1264 EXPECT_EQ(google_server_info, map_it->second);
1275 1265
1276 // Prepare |quic_server_info_map| to be loaded by 1266 // Prepare |quic_server_info_map| to be loaded by
1277 // SetQuicServerInfoMap(). 1267 // SetQuicServerInfoMap().
1278 QuicServerInfoMap quic_server_info_map(QuicServerInfoMap::NO_AUTO_EVICT); 1268 std::unique_ptr<QuicServerInfoMap> quic_server_info_map =
1269 base::MakeUnique<QuicServerInfoMap>(QuicServerInfoMap::NO_AUTO_EVICT);
1279 // Change the values for |docs_server|. 1270 // Change the values for |docs_server|.
1280 std::string new_docs_server_info("new_docs_quic_server_info"); 1271 std::string new_docs_server_info("new_docs_quic_server_info");
1281 quic_server_info_map.Put(docs_quic_server_id, new_docs_server_info); 1272 quic_server_info_map->Put(docs_quic_server_id, new_docs_server_info);
1282 // Add data for mail.google.com:443. 1273 // Add data for mail.google.com:443.
1283 HostPortPair mail_server("mail.google.com", 443); 1274 HostPortPair mail_server("mail.google.com", 443);
1284 QuicServerId mail_quic_server_id(mail_server, PRIVACY_MODE_ENABLED); 1275 QuicServerId mail_quic_server_id(mail_server, PRIVACY_MODE_ENABLED);
1285 std::string mail_server_info("mail_quic_server_info"); 1276 std::string mail_server_info("mail_quic_server_info");
1286 quic_server_info_map.Put(mail_quic_server_id, mail_server_info); 1277 quic_server_info_map->Put(mail_quic_server_id, mail_server_info);
1287 impl_.SetQuicServerInfoMap(&quic_server_info_map); 1278 impl_.SetQuicServerInfoMap(std::move(quic_server_info_map));
1288 1279
1289 // Recency order will be |docs_server|, |google_server| and |mail_server|. 1280 // Recency order will be |docs_server|, |google_server| and |mail_server|.
1290 const QuicServerInfoMap& memory_map = impl_.quic_server_info_map(); 1281 const QuicServerInfoMap& memory_map = impl_.quic_server_info_map();
1291 ASSERT_EQ(3u, memory_map.size()); 1282 ASSERT_EQ(3u, memory_map.size());
1292 QuicServerInfoMap::const_iterator memory_map_it = memory_map.begin(); 1283 QuicServerInfoMap::const_iterator memory_map_it = memory_map.begin();
1293 EXPECT_EQ(memory_map_it->first, docs_quic_server_id); 1284 EXPECT_EQ(memory_map_it->first, docs_quic_server_id);
1294 EXPECT_EQ(new_docs_server_info, memory_map_it->second); 1285 EXPECT_EQ(new_docs_server_info, memory_map_it->second);
1295 ++memory_map_it; 1286 ++memory_map_it;
1296 EXPECT_EQ(memory_map_it->first, google_quic_server_id); 1287 EXPECT_EQ(memory_map_it->first, google_quic_server_id);
1297 EXPECT_EQ(google_server_info, memory_map_it->second); 1288 EXPECT_EQ(google_server_info, memory_map_it->second);
(...skipping 30 matching lines...) Expand all
1328 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); 1319 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id)));
1329 1320
1330 impl_.Clear(); 1321 impl_.Clear();
1331 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); 1322 EXPECT_EQ(0u, impl_.quic_server_info_map().size());
1332 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); 1323 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id));
1333 } 1324 }
1334 1325
1335 } // namespace 1326 } // namespace
1336 1327
1337 } // namespace net 1328 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698