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