OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_server_properties_impl.h" | 5 #include "net/http/http_server_properties_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 | 369 |
370 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { | 370 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { |
371 // |test_host_port_pair1| has an alternative service, which will not be | 371 // |test_host_port_pair1| has an alternative service, which will not be |
372 // affected by InitializeAlternativeServiceServers(), because | 372 // affected by InitializeAlternativeServiceServers(), because |
373 // |alternative_service_map| does not have an entry for | 373 // |alternative_service_map| does not have an entry for |
374 // |test_host_port_pair1|. | 374 // |test_host_port_pair1|. |
375 HostPortPair test_host_port_pair1("foo1", 80); | 375 HostPortPair test_host_port_pair1("foo1", 80); |
376 const AlternativeService alternative_service1(NPN_HTTP_2, "bar1", 443); | 376 const AlternativeService alternative_service1(NPN_HTTP_2, "bar1", 443); |
377 const base::Time now = base::Time::Now(); | 377 const base::Time now = base::Time::Now(); |
378 base::Time expiration1 = now + base::TimeDelta::FromDays(1); | 378 base::Time expiration1 = now + base::TimeDelta::FromDays(1); |
| 379 // 1st entry in the memory. |
379 impl_.SetAlternativeService(test_host_port_pair1, alternative_service1, 1.0, | 380 impl_.SetAlternativeService(test_host_port_pair1, alternative_service1, 1.0, |
380 expiration1); | 381 expiration1); |
381 | 382 |
382 // |test_host_port_pair2| has an alternative service, which will be | 383 // |test_host_port_pair2| has an alternative service, which will be |
383 // overwritten by InitializeAlternativeServiceServers(), because | 384 // overwritten by InitializeAlternativeServiceServers(), because |
384 // |alternative_service_map| has an entry for | 385 // |alternative_service_map| has an entry for |
385 // |test_host_port_pair2|. | 386 // |test_host_port_pair2|. |
386 AlternativeServiceInfoVector alternative_service_info_vector; | 387 AlternativeServiceInfoVector alternative_service_info_vector; |
387 const AlternativeService alternative_service2(NPN_SPDY_3_1, "bar2", 443); | 388 const AlternativeService alternative_service2(NPN_SPDY_3_1, "bar2", 443); |
388 base::Time expiration2 = now + base::TimeDelta::FromDays(2); | 389 base::Time expiration2 = now + base::TimeDelta::FromDays(2); |
389 alternative_service_info_vector.push_back( | 390 alternative_service_info_vector.push_back( |
390 AlternativeServiceInfo(alternative_service2, 1.0, expiration2)); | 391 AlternativeServiceInfo(alternative_service2, 1.0, expiration2)); |
391 HostPortPair test_host_port_pair2("foo2", 80); | 392 HostPortPair test_host_port_pair2("foo2", 80); |
| 393 // 0th entry in the memory. |
392 impl_.SetAlternativeServices(test_host_port_pair2, | 394 impl_.SetAlternativeServices(test_host_port_pair2, |
393 alternative_service_info_vector); | 395 alternative_service_info_vector); |
394 | 396 |
395 // Prepare |alternative_service_map| to be loaded by | 397 // Prepare |alternative_service_map| to be loaded by |
396 // InitializeAlternativeServiceServers(). | 398 // InitializeAlternativeServiceServers(). |
397 AlternativeServiceMap alternative_service_map( | 399 AlternativeServiceMap alternative_service_map( |
398 AlternativeServiceMap::NO_AUTO_EVICT); | 400 AlternativeServiceMap::NO_AUTO_EVICT); |
399 const AlternativeService alternative_service3(NPN_HTTP_2, "bar3", 123); | 401 const AlternativeService alternative_service3(NPN_HTTP_2, "bar3", 123); |
400 base::Time expiration3 = now + base::TimeDelta::FromDays(3); | 402 base::Time expiration3 = now + base::TimeDelta::FromDays(3); |
401 const AlternativeServiceInfo alternative_service_info1(alternative_service3, | 403 const AlternativeServiceInfo alternative_service_info1(alternative_service3, |
402 0.7, expiration3); | 404 0.7, expiration3); |
| 405 // Simulate updating data for 0th entry with data from Preferences. |
403 alternative_service_map.Put( | 406 alternative_service_map.Put( |
404 test_host_port_pair2, | 407 test_host_port_pair2, |
405 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info1)); | 408 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info1)); |
406 | 409 |
407 HostPortPair test_host_port_pair3("foo3", 80); | 410 HostPortPair test_host_port_pair3("foo3", 80); |
408 const AlternativeService alternative_service4(NPN_HTTP_2, "bar4", 1234); | 411 const AlternativeService alternative_service4(NPN_HTTP_2, "bar4", 1234); |
409 base::Time expiration4 = now + base::TimeDelta::FromDays(4); | 412 base::Time expiration4 = now + base::TimeDelta::FromDays(4); |
410 const AlternativeServiceInfo alternative_service_info2(alternative_service4, | 413 const AlternativeServiceInfo alternative_service_info2(alternative_service4, |
411 0.2, expiration4); | 414 0.2, expiration4); |
| 415 // Add an old entry from Preferences, this will be added to end of recency |
| 416 // list. |
412 alternative_service_map.Put( | 417 alternative_service_map.Put( |
413 test_host_port_pair3, | 418 test_host_port_pair3, |
414 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info2)); | 419 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info2)); |
415 | 420 |
| 421 // MRU list will be test_host_port_pair2, test_host_port_pair1, |
| 422 // test_host_port_pair3. |
416 impl_.InitializeAlternativeServiceServers(&alternative_service_map); | 423 impl_.InitializeAlternativeServiceServers(&alternative_service_map); |
417 | 424 |
418 // Verify alternative_service_map. | 425 // Verify alternative_service_map. |
419 const AlternativeServiceMap& map = impl_.alternative_service_map(); | 426 const AlternativeServiceMap& map = impl_.alternative_service_map(); |
420 ASSERT_EQ(3u, map.size()); | 427 ASSERT_EQ(3u, map.size()); |
421 AlternativeServiceMap::const_iterator map_it = map.begin(); | 428 AlternativeServiceMap::const_iterator map_it = map.begin(); |
422 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair3)); | 429 |
423 ASSERT_EQ(1u, map_it->second.size()); | |
424 EXPECT_EQ(alternative_service4, map_it->second[0].alternative_service); | |
425 EXPECT_EQ(0.2, map_it->second[0].probability); | |
426 EXPECT_EQ(expiration4, map_it->second[0].expiration); | |
427 ++map_it; | |
428 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair2)); | 430 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair2)); |
429 ASSERT_EQ(1u, map_it->second.size()); | 431 ASSERT_EQ(1u, map_it->second.size()); |
430 EXPECT_EQ(alternative_service3, map_it->second[0].alternative_service); | 432 EXPECT_EQ(alternative_service3, map_it->second[0].alternative_service); |
431 EXPECT_EQ(0.7, map_it->second[0].probability); | 433 EXPECT_EQ(0.7, map_it->second[0].probability); |
432 EXPECT_EQ(expiration3, map_it->second[0].expiration); | 434 EXPECT_EQ(expiration3, map_it->second[0].expiration); |
433 ++map_it; | 435 ++map_it; |
434 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair1)); | 436 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair1)); |
435 ASSERT_EQ(1u, map_it->second.size()); | 437 ASSERT_EQ(1u, map_it->second.size()); |
436 EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service); | 438 EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service); |
437 EXPECT_EQ(1.0, map_it->second[0].probability); | 439 EXPECT_EQ(1.0, map_it->second[0].probability); |
438 EXPECT_EQ(expiration1, map_it->second[0].expiration); | 440 EXPECT_EQ(expiration1, map_it->second[0].expiration); |
| 441 ++map_it; |
| 442 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair3)); |
| 443 ASSERT_EQ(1u, map_it->second.size()); |
| 444 EXPECT_EQ(alternative_service4, map_it->second[0].alternative_service); |
| 445 EXPECT_EQ(0.2, map_it->second[0].probability); |
| 446 EXPECT_EQ(expiration4, map_it->second[0].expiration); |
439 } | 447 } |
440 | 448 |
441 // Regression test for https://crbug.com/504032: | 449 // Regression test for https://crbug.com/504032: |
442 // InitializeAlternativeServiceServers() should not crash if there is an empty | 450 // InitializeAlternativeServiceServers() should not crash if there is an empty |
443 // hostname is the mapping. | 451 // hostname is the mapping. |
444 TEST_F(AlternateProtocolServerPropertiesTest, InitializeWithEmptyHostname) { | 452 TEST_F(AlternateProtocolServerPropertiesTest, InitializeWithEmptyHostname) { |
445 const HostPortPair host_port_pair("foo", 443); | 453 const HostPortPair host_port_pair("foo", 443); |
446 const AlternativeService alternative_service_with_empty_hostname(NPN_HTTP_2, | 454 const AlternativeService alternative_service_with_empty_hostname(NPN_HTTP_2, |
447 "", 1234); | 455 "", 1234); |
448 const AlternativeService alternative_service_with_foo_hostname(NPN_HTTP_2, | 456 const AlternativeService alternative_service_with_foo_hostname(NPN_HTTP_2, |
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); | 1242 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); |
1235 | 1243 |
1236 impl_.Clear(); | 1244 impl_.Clear(); |
1237 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); | 1245 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); |
1238 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); | 1246 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); |
1239 } | 1247 } |
1240 | 1248 |
1241 } // namespace | 1249 } // namespace |
1242 | 1250 |
1243 } // namespace net | 1251 } // namespace net |
OLD | NEW |