| 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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 const base::Time now = base::Time::Now(); | 434 const base::Time now = base::Time::Now(); |
| 435 base::Time expiration1 = now + base::TimeDelta::FromDays(1); | 435 base::Time expiration1 = now + base::TimeDelta::FromDays(1); |
| 436 // 1st entry in the memory. | 436 // 1st entry in the memory. |
| 437 impl_.SetAlternativeService(test_server1, alternative_service1, expiration1); | 437 impl_.SetAlternativeService(test_server1, alternative_service1, expiration1); |
| 438 | 438 |
| 439 // |test_server2| has an alternative service, which will be | 439 // |test_server2| has an alternative service, which will be |
| 440 // overwritten by InitializeAlternativeServiceServers(), because | 440 // overwritten by InitializeAlternativeServiceServers(), because |
| 441 // |alternative_service_map| has an entry for | 441 // |alternative_service_map| has an entry for |
| 442 // |test_server2|. | 442 // |test_server2|. |
| 443 AlternativeServiceInfoVector alternative_service_info_vector; | 443 AlternativeServiceInfoVector alternative_service_info_vector; |
| 444 const AlternativeService alternative_service2(NPN_SPDY_3_1, "bar2", 443); | 444 const AlternativeService alternative_service2(NPN_HTTP_2, "bar2", 443); |
| 445 base::Time expiration2 = now + base::TimeDelta::FromDays(2); | 445 base::Time expiration2 = now + base::TimeDelta::FromDays(2); |
| 446 alternative_service_info_vector.push_back( | 446 alternative_service_info_vector.push_back( |
| 447 AlternativeServiceInfo(alternative_service2, expiration2)); | 447 AlternativeServiceInfo(alternative_service2, expiration2)); |
| 448 url::SchemeHostPort test_server2("http", "foo2", 80); | 448 url::SchemeHostPort test_server2("http", "foo2", 80); |
| 449 // 0th entry in the memory. | 449 // 0th entry in the memory. |
| 450 impl_.SetAlternativeServices(test_server2, alternative_service_info_vector); | 450 impl_.SetAlternativeServices(test_server2, alternative_service_info_vector); |
| 451 | 451 |
| 452 // Prepare |alternative_service_map| to be loaded by | 452 // Prepare |alternative_service_map| to be loaded by |
| 453 // InitializeAlternativeServiceServers(). | 453 // InitializeAlternativeServiceServers(). |
| 454 AlternativeServiceMap alternative_service_map( | 454 AlternativeServiceMap alternative_service_map( |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 // cleared. | 620 // cleared. |
| 621 // GetAlternativeServices() should remove this key from | 621 // GetAlternativeServices() should remove this key from |
| 622 // |alternative_service_map_|, and SetAlternativeServices() should not crash. | 622 // |alternative_service_map_|, and SetAlternativeServices() should not crash. |
| 623 impl_.SetAlternativeServices(server, AlternativeServiceInfoVector()); | 623 impl_.SetAlternativeServices(server, AlternativeServiceInfoVector()); |
| 624 | 624 |
| 625 ASSERT_TRUE(impl_.GetAlternativeServices(server).empty()); | 625 ASSERT_TRUE(impl_.GetAlternativeServices(server).empty()); |
| 626 } | 626 } |
| 627 | 627 |
| 628 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternativeServices) { | 628 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternativeServices) { |
| 629 url::SchemeHostPort test_server1("http", "foo1", 80); | 629 url::SchemeHostPort test_server1("http", "foo1", 80); |
| 630 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo1", 443); | 630 const AlternativeService alternative_service1(NPN_HTTP_2, "foo1", 443); |
| 631 SetAlternativeService(test_server1, alternative_service1); | 631 SetAlternativeService(test_server1, alternative_service1); |
| 632 url::SchemeHostPort test_server2("http", "foo2", 80); | 632 url::SchemeHostPort test_server2("http", "foo2", 80); |
| 633 const AlternativeService alternative_service2(NPN_HTTP_2, "foo2", 1234); | 633 const AlternativeService alternative_service2(NPN_HTTP_2, "foo2", 1234); |
| 634 SetAlternativeService(test_server2, alternative_service2); | 634 SetAlternativeService(test_server2, alternative_service2); |
| 635 | 635 |
| 636 const AlternativeServiceMap& map = impl_.alternative_service_map(); | 636 const AlternativeServiceMap& map = impl_.alternative_service_map(); |
| 637 AlternativeServiceMap::const_iterator it = map.begin(); | 637 AlternativeServiceMap::const_iterator it = map.begin(); |
| 638 EXPECT_TRUE(it->first.Equals(test_server2)); | 638 EXPECT_TRUE(it->first.Equals(test_server2)); |
| 639 ASSERT_EQ(1u, it->second.size()); | 639 ASSERT_EQ(1u, it->second.size()); |
| 640 EXPECT_EQ(alternative_service2, it->second[0].alternative_service); | 640 EXPECT_EQ(alternative_service2, it->second[0].alternative_service); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0])); | 692 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0])); |
| 693 } | 693 } |
| 694 | 694 |
| 695 TEST_F(AlternateProtocolServerPropertiesTest, MaxAge) { | 695 TEST_F(AlternateProtocolServerPropertiesTest, MaxAge) { |
| 696 AlternativeServiceInfoVector alternative_service_info_vector; | 696 AlternativeServiceInfoVector alternative_service_info_vector; |
| 697 base::Time now = base::Time::Now(); | 697 base::Time now = base::Time::Now(); |
| 698 base::TimeDelta one_day = base::TimeDelta::FromDays(1); | 698 base::TimeDelta one_day = base::TimeDelta::FromDays(1); |
| 699 | 699 |
| 700 // First alternative service expired one day ago, should not be returned by | 700 // First alternative service expired one day ago, should not be returned by |
| 701 // GetAlternativeServices(). | 701 // GetAlternativeServices(). |
| 702 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); | 702 const AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); |
| 703 alternative_service_info_vector.push_back( | 703 alternative_service_info_vector.push_back( |
| 704 AlternativeServiceInfo(alternative_service1, now - one_day)); | 704 AlternativeServiceInfo(alternative_service1, now - one_day)); |
| 705 | 705 |
| 706 // Second alterrnative service will expire one day from now, should be | 706 // Second alterrnative service will expire one day from now, should be |
| 707 // returned by GetAlternativeSerices(). | 707 // returned by GetAlternativeSerices(). |
| 708 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); | 708 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); |
| 709 alternative_service_info_vector.push_back( | 709 alternative_service_info_vector.push_back( |
| 710 AlternativeServiceInfo(alternative_service2, now + one_day)); | 710 AlternativeServiceInfo(alternative_service2, now + one_day)); |
| 711 | 711 |
| 712 url::SchemeHostPort test_server("http", "foo", 80); | 712 url::SchemeHostPort test_server("http", "foo", 80); |
| 713 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); | 713 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); |
| 714 | 714 |
| 715 AlternativeServiceVector alternative_service_vector = | 715 AlternativeServiceVector alternative_service_vector = |
| 716 impl_.GetAlternativeServices(test_server); | 716 impl_.GetAlternativeServices(test_server); |
| 717 ASSERT_EQ(1u, alternative_service_vector.size()); | 717 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 718 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); | 718 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); |
| 719 } | 719 } |
| 720 | 720 |
| 721 TEST_F(AlternateProtocolServerPropertiesTest, MaxAgeCanonical) { | 721 TEST_F(AlternateProtocolServerPropertiesTest, MaxAgeCanonical) { |
| 722 AlternativeServiceInfoVector alternative_service_info_vector; | 722 AlternativeServiceInfoVector alternative_service_info_vector; |
| 723 base::Time now = base::Time::Now(); | 723 base::Time now = base::Time::Now(); |
| 724 base::TimeDelta one_day = base::TimeDelta::FromDays(1); | 724 base::TimeDelta one_day = base::TimeDelta::FromDays(1); |
| 725 | 725 |
| 726 // First alternative service expired one day ago, should not be returned by | 726 // First alternative service expired one day ago, should not be returned by |
| 727 // GetAlternativeServices(). | 727 // GetAlternativeServices(). |
| 728 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); | 728 const AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); |
| 729 alternative_service_info_vector.push_back( | 729 alternative_service_info_vector.push_back( |
| 730 AlternativeServiceInfo(alternative_service1, now - one_day)); | 730 AlternativeServiceInfo(alternative_service1, now - one_day)); |
| 731 | 731 |
| 732 // Second alterrnative service will expire one day from now, should be | 732 // Second alterrnative service will expire one day from now, should be |
| 733 // returned by GetAlternativeSerices(). | 733 // returned by GetAlternativeSerices(). |
| 734 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); | 734 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); |
| 735 alternative_service_info_vector.push_back( | 735 alternative_service_info_vector.push_back( |
| 736 AlternativeServiceInfo(alternative_service2, now + one_day)); | 736 AlternativeServiceInfo(alternative_service2, now + one_day)); |
| 737 | 737 |
| 738 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); | 738 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| 739 impl_.SetAlternativeServices(canonical_server, | 739 impl_.SetAlternativeServices(canonical_server, |
| 740 alternative_service_info_vector); | 740 alternative_service_info_vector); |
| 741 | 741 |
| 742 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); | 742 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); |
| 743 AlternativeServiceVector alternative_service_vector = | 743 AlternativeServiceVector alternative_service_vector = |
| 744 impl_.GetAlternativeServices(test_server); | 744 impl_.GetAlternativeServices(test_server); |
| 745 ASSERT_EQ(1u, alternative_service_vector.size()); | 745 ASSERT_EQ(1u, alternative_service_vector.size()); |
| 746 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); | 746 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); |
| 747 } | 747 } |
| 748 | 748 |
| 749 TEST_F(AlternateProtocolServerPropertiesTest, AlternativeServiceWithScheme) { | 749 TEST_F(AlternateProtocolServerPropertiesTest, AlternativeServiceWithScheme) { |
| 750 AlternativeServiceInfoVector alternative_service_info_vector; | 750 AlternativeServiceInfoVector alternative_service_info_vector; |
| 751 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); | 751 const AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); |
| 752 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 752 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 753 alternative_service_info_vector.push_back( | 753 alternative_service_info_vector.push_back( |
| 754 AlternativeServiceInfo(alternative_service1, expiration)); | 754 AlternativeServiceInfo(alternative_service1, expiration)); |
| 755 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); | 755 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); |
| 756 alternative_service_info_vector.push_back( | 756 alternative_service_info_vector.push_back( |
| 757 AlternativeServiceInfo(alternative_service2, expiration)); | 757 AlternativeServiceInfo(alternative_service2, expiration)); |
| 758 // Set Alt-Svc list for |http_server|. | 758 // Set Alt-Svc list for |http_server|. |
| 759 url::SchemeHostPort http_server("http", "foo", 80); | 759 url::SchemeHostPort http_server("http", "foo", 80); |
| 760 impl_.SetAlternativeServices(http_server, alternative_service_info_vector); | 760 impl_.SetAlternativeServices(http_server, alternative_service_info_vector); |
| 761 | 761 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 777 | 777 |
| 778 // Clear Alt-Svc list for |http_server|. | 778 // Clear Alt-Svc list for |http_server|. |
| 779 impl_.SetAlternativeServices(http_server, AlternativeServiceInfoVector()); | 779 impl_.SetAlternativeServices(http_server, AlternativeServiceInfoVector()); |
| 780 | 780 |
| 781 EXPECT_EQ(0u, impl_.GetAlternativeServices(http_server).size()); | 781 EXPECT_EQ(0u, impl_.GetAlternativeServices(http_server).size()); |
| 782 EXPECT_EQ(2u, impl_.GetAlternativeServices(https_server).size()); | 782 EXPECT_EQ(2u, impl_.GetAlternativeServices(https_server).size()); |
| 783 } | 783 } |
| 784 | 784 |
| 785 TEST_F(AlternateProtocolServerPropertiesTest, ClearAlternativeServices) { | 785 TEST_F(AlternateProtocolServerPropertiesTest, ClearAlternativeServices) { |
| 786 AlternativeServiceInfoVector alternative_service_info_vector; | 786 AlternativeServiceInfoVector alternative_service_info_vector; |
| 787 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); | 787 const AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); |
| 788 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 788 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 789 alternative_service_info_vector.push_back( | 789 alternative_service_info_vector.push_back( |
| 790 AlternativeServiceInfo(alternative_service1, expiration)); | 790 AlternativeServiceInfo(alternative_service1, expiration)); |
| 791 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); | 791 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); |
| 792 alternative_service_info_vector.push_back( | 792 alternative_service_info_vector.push_back( |
| 793 AlternativeServiceInfo(alternative_service2, expiration)); | 793 AlternativeServiceInfo(alternative_service2, expiration)); |
| 794 url::SchemeHostPort test_server("http", "foo", 80); | 794 url::SchemeHostPort test_server("http", "foo", 80); |
| 795 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); | 795 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); |
| 796 | 796 |
| 797 const net::AlternativeServiceMap& map = impl_.alternative_service_map(); | 797 const net::AlternativeServiceMap& map = impl_.alternative_service_map(); |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1526 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); | 1526 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); |
| 1527 | 1527 |
| 1528 impl_.Clear(); | 1528 impl_.Clear(); |
| 1529 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); | 1529 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); |
| 1530 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); | 1530 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); |
| 1531 } | 1531 } |
| 1532 | 1532 |
| 1533 } // namespace | 1533 } // namespace |
| 1534 | 1534 |
| 1535 } // namespace net | 1535 } // namespace net |
| OLD | NEW |