OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_manager.h" | 5 #include "net/http/http_server_properties_manager.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 | 374 |
375 // Verify alternative service. | 375 // Verify alternative service. |
376 if (GetParam() >= 4) { | 376 if (GetParam() >= 4) { |
377 const AlternativeServiceMap& map = | 377 const AlternativeServiceMap& map = |
378 http_server_props_manager_->alternative_service_map(); | 378 http_server_props_manager_->alternative_service_map(); |
379 ASSERT_EQ(2u, map.size()); | 379 ASSERT_EQ(2u, map.size()); |
380 | 380 |
381 AlternativeServiceMap::const_iterator map_it = map.begin(); | 381 AlternativeServiceMap::const_iterator map_it = map.begin(); |
382 EXPECT_EQ("mail.google.com", map_it->first.host()); | 382 EXPECT_EQ("mail.google.com", map_it->first.host()); |
383 ASSERT_EQ(1u, map_it->second.size()); | 383 ASSERT_EQ(1u, map_it->second.size()); |
384 EXPECT_EQ(NPN_HTTP_2, map_it->second[0].alternative_service.protocol); | 384 EXPECT_EQ(kProtoHTTP2, map_it->second[0].alternative_service.protocol); |
385 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); | 385 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); |
386 EXPECT_EQ(444, map_it->second[0].alternative_service.port); | 386 EXPECT_EQ(444, map_it->second[0].alternative_service.port); |
387 ++map_it; | 387 ++map_it; |
388 EXPECT_EQ("www.google.com", map_it->first.host()); | 388 EXPECT_EQ("www.google.com", map_it->first.host()); |
389 ASSERT_EQ(2u, map_it->second.size()); | 389 ASSERT_EQ(2u, map_it->second.size()); |
390 EXPECT_EQ(NPN_HTTP_2, map_it->second[0].alternative_service.protocol); | 390 EXPECT_EQ(kProtoHTTP2, map_it->second[0].alternative_service.protocol); |
391 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); | 391 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); |
392 EXPECT_EQ(443, map_it->second[0].alternative_service.port); | 392 EXPECT_EQ(443, map_it->second[0].alternative_service.port); |
393 EXPECT_EQ(QUIC, map_it->second[1].alternative_service.protocol); | 393 EXPECT_EQ(kProtoQUIC, map_it->second[1].alternative_service.protocol); |
394 EXPECT_TRUE(map_it->second[1].alternative_service.host.empty()); | 394 EXPECT_TRUE(map_it->second[1].alternative_service.host.empty()); |
395 EXPECT_EQ(1234, map_it->second[1].alternative_service.port); | 395 EXPECT_EQ(1234, map_it->second[1].alternative_service.port); |
396 } else { | 396 } else { |
397 const AlternativeServiceMap& map = | 397 const AlternativeServiceMap& map = |
398 http_server_props_manager_->alternative_service_map(); | 398 http_server_props_manager_->alternative_service_map(); |
399 ASSERT_EQ(2u, map.size()); | 399 ASSERT_EQ(2u, map.size()); |
400 AlternativeServiceMap::const_iterator map_it = map.begin(); | 400 AlternativeServiceMap::const_iterator map_it = map.begin(); |
401 EXPECT_EQ("www.google.com", map_it->first.host()); | 401 EXPECT_EQ("www.google.com", map_it->first.host()); |
402 ASSERT_EQ(2u, map_it->second.size()); | 402 ASSERT_EQ(2u, map_it->second.size()); |
403 EXPECT_EQ(NPN_HTTP_2, map_it->second[0].alternative_service.protocol); | 403 EXPECT_EQ(kProtoHTTP2, map_it->second[0].alternative_service.protocol); |
404 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); | 404 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); |
405 EXPECT_EQ(443, map_it->second[0].alternative_service.port); | 405 EXPECT_EQ(443, map_it->second[0].alternative_service.port); |
406 EXPECT_EQ(QUIC, map_it->second[1].alternative_service.protocol); | 406 EXPECT_EQ(kProtoQUIC, map_it->second[1].alternative_service.protocol); |
407 EXPECT_TRUE(map_it->second[1].alternative_service.host.empty()); | 407 EXPECT_TRUE(map_it->second[1].alternative_service.host.empty()); |
408 EXPECT_EQ(1234, map_it->second[1].alternative_service.port); | 408 EXPECT_EQ(1234, map_it->second[1].alternative_service.port); |
409 ++map_it; | 409 ++map_it; |
410 EXPECT_EQ("mail.google.com", map_it->first.host()); | 410 EXPECT_EQ("mail.google.com", map_it->first.host()); |
411 ASSERT_EQ(1u, map_it->second.size()); | 411 ASSERT_EQ(1u, map_it->second.size()); |
412 EXPECT_EQ(NPN_HTTP_2, map_it->second[0].alternative_service.protocol); | 412 EXPECT_EQ(kProtoHTTP2, map_it->second[0].alternative_service.protocol); |
413 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); | 413 EXPECT_TRUE(map_it->second[0].alternative_service.host.empty()); |
414 EXPECT_EQ(444, map_it->second[0].alternative_service.port); | 414 EXPECT_EQ(444, map_it->second[0].alternative_service.port); |
415 } | 415 } |
416 | 416 |
417 // Verify SupportsQuic. | 417 // Verify SupportsQuic. |
418 IPAddress last_address; | 418 IPAddress last_address; |
419 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); | 419 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); |
420 EXPECT_EQ("127.0.0.1", last_address.ToString()); | 420 EXPECT_EQ("127.0.0.1", last_address.ToString()); |
421 | 421 |
422 /* | 422 /* |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 | 707 |
708 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 708 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
709 } | 709 } |
710 | 710 |
711 TEST_P(HttpServerPropertiesManagerTest, GetAlternativeServices) { | 711 TEST_P(HttpServerPropertiesManagerTest, GetAlternativeServices) { |
712 ExpectPrefsUpdate(); | 712 ExpectPrefsUpdate(); |
713 ExpectScheduleUpdatePrefsOnNetworkThread(); | 713 ExpectScheduleUpdatePrefsOnNetworkThread(); |
714 | 714 |
715 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80); | 715 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80); |
716 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 716 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
717 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", | 717 const AlternativeService alternative_service(kProtoHTTP2, "mail.google.com", |
718 443); | 718 443); |
719 http_server_props_manager_->SetAlternativeService( | 719 http_server_props_manager_->SetAlternativeService( |
720 spdy_server_mail, alternative_service, one_day_from_now_); | 720 spdy_server_mail, alternative_service, one_day_from_now_); |
721 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 721 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
722 http_server_props_manager_->SetAlternativeService( | 722 http_server_props_manager_->SetAlternativeService( |
723 spdy_server_mail, alternative_service, one_day_from_now_); | 723 spdy_server_mail, alternative_service, one_day_from_now_); |
724 | 724 |
725 // Run the task. | 725 // Run the task. |
726 base::RunLoop().RunUntilIdle(); | 726 base::RunLoop().RunUntilIdle(); |
727 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 727 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
728 | 728 |
729 AlternativeServiceVector alternative_service_vector = | 729 AlternativeServiceVector alternative_service_vector = |
730 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); | 730 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); |
731 ASSERT_EQ(1u, alternative_service_vector.size()); | 731 ASSERT_EQ(1u, alternative_service_vector.size()); |
732 EXPECT_EQ(alternative_service, alternative_service_vector[0]); | 732 EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
733 } | 733 } |
734 | 734 |
735 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServices) { | 735 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServices) { |
736 ExpectPrefsUpdate(); | 736 ExpectPrefsUpdate(); |
737 ExpectScheduleUpdatePrefsOnNetworkThread(); | 737 ExpectScheduleUpdatePrefsOnNetworkThread(); |
738 | 738 |
739 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80); | 739 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80); |
740 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 740 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
741 AlternativeServiceInfoVector alternative_service_info_vector; | 741 AlternativeServiceInfoVector alternative_service_info_vector; |
742 const AlternativeService alternative_service1(NPN_HTTP_2, "mail.google.com", | 742 const AlternativeService alternative_service1(kProtoHTTP2, "mail.google.com", |
743 443); | 743 443); |
744 alternative_service_info_vector.push_back( | 744 alternative_service_info_vector.push_back( |
745 AlternativeServiceInfo(alternative_service1, one_day_from_now_)); | 745 AlternativeServiceInfo(alternative_service1, one_day_from_now_)); |
746 const AlternativeService alternative_service2(QUIC, "mail.google.com", 1234); | 746 const AlternativeService alternative_service2(kProtoQUIC, "mail.google.com", |
| 747 1234); |
747 alternative_service_info_vector.push_back( | 748 alternative_service_info_vector.push_back( |
748 AlternativeServiceInfo(alternative_service2, one_day_from_now_)); | 749 AlternativeServiceInfo(alternative_service2, one_day_from_now_)); |
749 http_server_props_manager_->SetAlternativeServices( | 750 http_server_props_manager_->SetAlternativeServices( |
750 spdy_server_mail, alternative_service_info_vector); | 751 spdy_server_mail, alternative_service_info_vector); |
751 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 752 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
752 http_server_props_manager_->SetAlternativeServices( | 753 http_server_props_manager_->SetAlternativeServices( |
753 spdy_server_mail, alternative_service_info_vector); | 754 spdy_server_mail, alternative_service_info_vector); |
754 | 755 |
755 // Run the task. | 756 // Run the task. |
756 base::RunLoop().RunUntilIdle(); | 757 base::RunLoop().RunUntilIdle(); |
757 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 758 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
758 | 759 |
759 AlternativeServiceVector alternative_service_vector = | 760 AlternativeServiceVector alternative_service_vector = |
760 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); | 761 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); |
761 ASSERT_EQ(2u, alternative_service_vector.size()); | 762 ASSERT_EQ(2u, alternative_service_vector.size()); |
762 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 763 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
763 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); | 764 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); |
764 } | 765 } |
765 | 766 |
766 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServicesEmpty) { | 767 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServicesEmpty) { |
767 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80); | 768 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80); |
768 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 769 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
769 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", | 770 const AlternativeService alternative_service(kProtoHTTP2, "mail.google.com", |
770 443); | 771 443); |
771 http_server_props_manager_->SetAlternativeServices( | 772 http_server_props_manager_->SetAlternativeServices( |
772 spdy_server_mail, AlternativeServiceInfoVector()); | 773 spdy_server_mail, AlternativeServiceInfoVector()); |
773 // ExpectScheduleUpdatePrefsOnNetworkThread() should not be called. | 774 // ExpectScheduleUpdatePrefsOnNetworkThread() should not be called. |
774 | 775 |
775 // Run the task. | 776 // Run the task. |
776 base::RunLoop().RunUntilIdle(); | 777 base::RunLoop().RunUntilIdle(); |
777 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 778 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
778 | 779 |
779 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 780 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
780 } | 781 } |
781 | 782 |
782 TEST_P(HttpServerPropertiesManagerTest, ConfirmAlternativeService) { | 783 TEST_P(HttpServerPropertiesManagerTest, ConfirmAlternativeService) { |
783 ExpectPrefsUpdate(); | 784 ExpectPrefsUpdate(); |
784 | 785 |
785 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80); | 786 url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80); |
786 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 787 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
787 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443); | 788 AlternativeService alternative_service(kProtoHTTP2, "mail.google.com", 443); |
788 | 789 |
789 ExpectScheduleUpdatePrefsOnNetworkThread(); | 790 ExpectScheduleUpdatePrefsOnNetworkThread(); |
790 http_server_props_manager_->SetAlternativeService( | 791 http_server_props_manager_->SetAlternativeService( |
791 spdy_server_mail, alternative_service, one_day_from_now_); | 792 spdy_server_mail, alternative_service, one_day_from_now_); |
792 | 793 |
793 EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken( | 794 EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken( |
794 alternative_service)); | 795 alternative_service)); |
795 EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken( | 796 EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken( |
796 alternative_service)); | 797 alternative_service)); |
797 | 798 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
889 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( | 890 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( |
890 mail_quic_server_id)); | 891 mail_quic_server_id)); |
891 } | 892 } |
892 | 893 |
893 TEST_P(HttpServerPropertiesManagerTest, Clear) { | 894 TEST_P(HttpServerPropertiesManagerTest, Clear) { |
894 ExpectPrefsUpdate(); | 895 ExpectPrefsUpdate(); |
895 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 896 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
896 | 897 |
897 url::SchemeHostPort spdy_server("https", "mail.google.com", 443); | 898 url::SchemeHostPort spdy_server("https", "mail.google.com", 443); |
898 http_server_props_manager_->SetSupportsSpdy(spdy_server, true); | 899 http_server_props_manager_->SetSupportsSpdy(spdy_server, true); |
899 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234); | 900 AlternativeService alternative_service(kProtoHTTP2, "mail.google.com", 1234); |
900 http_server_props_manager_->SetAlternativeService( | 901 http_server_props_manager_->SetAlternativeService( |
901 spdy_server, alternative_service, one_day_from_now_); | 902 spdy_server, alternative_service, one_day_from_now_); |
902 IPAddress actual_address(127, 0, 0, 1); | 903 IPAddress actual_address(127, 0, 0, 1); |
903 http_server_props_manager_->SetSupportsQuic(true, actual_address); | 904 http_server_props_manager_->SetSupportsQuic(true, actual_address); |
904 ServerNetworkStats stats; | 905 ServerNetworkStats stats; |
905 stats.srtt = base::TimeDelta::FromMicroseconds(10); | 906 stats.srtt = base::TimeDelta::FromMicroseconds(10); |
906 http_server_props_manager_->SetServerNetworkStats(spdy_server, stats); | 907 http_server_props_manager_->SetServerNetworkStats(spdy_server, stats); |
907 | 908 |
908 QuicServerId mail_quic_server_id("mail.google.com", 80); | 909 QuicServerId mail_quic_server_id("mail.google.com", 80); |
909 std::string quic_server_info1("quic_server_info1"); | 910 std::string quic_server_info1("quic_server_info1"); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 GURL server_gurl; | 1044 GURL server_gurl; |
1044 if (GetParam() >= 5) { | 1045 if (GetParam() >= 5) { |
1045 server_gurl = GURL(StringPrintf("https://www.google.com:%d", i)); | 1046 server_gurl = GURL(StringPrintf("https://www.google.com:%d", i)); |
1046 } else { | 1047 } else { |
1047 server_gurl = GURL(StringPrintf("https://www.google.com:%d", i)); | 1048 server_gurl = GURL(StringPrintf("https://www.google.com:%d", i)); |
1048 } | 1049 } |
1049 url::SchemeHostPort server(server_gurl); | 1050 url::SchemeHostPort server(server_gurl); |
1050 AlternativeServiceVector alternative_service_vector = | 1051 AlternativeServiceVector alternative_service_vector = |
1051 http_server_props_manager_->GetAlternativeServices(server); | 1052 http_server_props_manager_->GetAlternativeServices(server); |
1052 ASSERT_EQ(1u, alternative_service_vector.size()); | 1053 ASSERT_EQ(1u, alternative_service_vector.size()); |
1053 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol); | 1054 EXPECT_EQ(kProtoQUIC, alternative_service_vector[0].protocol); |
1054 EXPECT_EQ(i, alternative_service_vector[0].port); | 1055 EXPECT_EQ(i, alternative_service_vector[0].port); |
1055 } | 1056 } |
1056 | 1057 |
1057 // Verify SupportsQuic. | 1058 // Verify SupportsQuic. |
1058 IPAddress address; | 1059 IPAddress address; |
1059 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); | 1060 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
1060 EXPECT_EQ("127.0.0.1", address.ToString()); | 1061 EXPECT_EQ("127.0.0.1", address.ToString()); |
1061 } | 1062 } |
1062 | 1063 |
1063 TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { | 1064 TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { |
1064 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 1065 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
1065 | 1066 |
1066 const url::SchemeHostPort server_www("http", "www.google.com", 80); | 1067 const url::SchemeHostPort server_www("http", "www.google.com", 80); |
1067 const url::SchemeHostPort server_mail("http", "mail.google.com", 80); | 1068 const url::SchemeHostPort server_mail("http", "mail.google.com", 80); |
1068 | 1069 |
1069 // Set alternate protocol. | 1070 // Set alternate protocol. |
1070 AlternativeServiceInfoVector alternative_service_info_vector; | 1071 AlternativeServiceInfoVector alternative_service_info_vector; |
1071 AlternativeService www_alternative_service1(NPN_HTTP_2, "", 443); | 1072 AlternativeService www_alternative_service1(kProtoHTTP2, "", 443); |
1072 base::Time expiration1; | 1073 base::Time expiration1; |
1073 ASSERT_TRUE(base::Time::FromUTCString("2036-12-01 10:00:00", &expiration1)); | 1074 ASSERT_TRUE(base::Time::FromUTCString("2036-12-01 10:00:00", &expiration1)); |
1074 alternative_service_info_vector.push_back( | 1075 alternative_service_info_vector.push_back( |
1075 AlternativeServiceInfo(www_alternative_service1, expiration1)); | 1076 AlternativeServiceInfo(www_alternative_service1, expiration1)); |
1076 AlternativeService www_alternative_service2(NPN_HTTP_2, "www.google.com", | 1077 AlternativeService www_alternative_service2(kProtoHTTP2, "www.google.com", |
1077 1234); | 1078 1234); |
1078 base::Time expiration2; | 1079 base::Time expiration2; |
1079 ASSERT_TRUE(base::Time::FromUTCString("2036-12-31 10:00:00", &expiration2)); | 1080 ASSERT_TRUE(base::Time::FromUTCString("2036-12-31 10:00:00", &expiration2)); |
1080 alternative_service_info_vector.push_back( | 1081 alternative_service_info_vector.push_back( |
1081 AlternativeServiceInfo(www_alternative_service2, expiration2)); | 1082 AlternativeServiceInfo(www_alternative_service2, expiration2)); |
1082 http_server_props_manager_->SetAlternativeServices( | 1083 http_server_props_manager_->SetAlternativeServices( |
1083 server_www, alternative_service_info_vector); | 1084 server_www, alternative_service_info_vector); |
1084 | 1085 |
1085 AlternativeService mail_alternative_service(NPN_HTTP_2, "foo.google.com", | 1086 AlternativeService mail_alternative_service(kProtoHTTP2, "foo.google.com", |
1086 444); | 1087 444); |
1087 base::Time expiration3 = base::Time::Max(); | 1088 base::Time expiration3 = base::Time::Max(); |
1088 http_server_props_manager_->SetAlternativeService( | 1089 http_server_props_manager_->SetAlternativeService( |
1089 server_mail, mail_alternative_service, expiration3); | 1090 server_mail, mail_alternative_service, expiration3); |
1090 | 1091 |
1091 // Set ServerNetworkStats. | 1092 // Set ServerNetworkStats. |
1092 ServerNetworkStats stats; | 1093 ServerNetworkStats stats; |
1093 stats.srtt = base::TimeDelta::FromInternalValue(42); | 1094 stats.srtt = base::TimeDelta::FromInternalValue(42); |
1094 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); | 1095 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); |
1095 | 1096 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1149 const url::SchemeHostPort server("https", "example.com", 443); | 1150 const url::SchemeHostPort server("https", "example.com", 443); |
1150 AlternativeServiceMap alternative_service_map(/*max_size=*/5); | 1151 AlternativeServiceMap alternative_service_map(/*max_size=*/5); |
1151 EXPECT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( | 1152 EXPECT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( |
1152 server, *server_dict, &alternative_service_map)); | 1153 server, *server_dict, &alternative_service_map)); |
1153 | 1154 |
1154 AlternativeServiceMap::iterator it = alternative_service_map.Get(server); | 1155 AlternativeServiceMap::iterator it = alternative_service_map.Get(server); |
1155 ASSERT_NE(alternative_service_map.end(), it); | 1156 ASSERT_NE(alternative_service_map.end(), it); |
1156 AlternativeServiceInfoVector alternative_service_info_vector = it->second; | 1157 AlternativeServiceInfoVector alternative_service_info_vector = it->second; |
1157 ASSERT_EQ(3u, alternative_service_info_vector.size()); | 1158 ASSERT_EQ(3u, alternative_service_info_vector.size()); |
1158 | 1159 |
1159 EXPECT_EQ(NPN_HTTP_2, | 1160 EXPECT_EQ(kProtoHTTP2, |
1160 alternative_service_info_vector[0].alternative_service.protocol); | 1161 alternative_service_info_vector[0].alternative_service.protocol); |
1161 EXPECT_EQ("", alternative_service_info_vector[0].alternative_service.host); | 1162 EXPECT_EQ("", alternative_service_info_vector[0].alternative_service.host); |
1162 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); | 1163 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); |
1163 // Expiration defaults to one day from now, testing with tolerance. | 1164 // Expiration defaults to one day from now, testing with tolerance. |
1164 const base::Time now = base::Time::Now(); | 1165 const base::Time now = base::Time::Now(); |
1165 const base::Time expiration = alternative_service_info_vector[0].expiration; | 1166 const base::Time expiration = alternative_service_info_vector[0].expiration; |
1166 EXPECT_LE(now + base::TimeDelta::FromHours(23), expiration); | 1167 EXPECT_LE(now + base::TimeDelta::FromHours(23), expiration); |
1167 EXPECT_GE(now + base::TimeDelta::FromDays(1), expiration); | 1168 EXPECT_GE(now + base::TimeDelta::FromDays(1), expiration); |
1168 | 1169 |
1169 EXPECT_EQ(QUIC, | 1170 EXPECT_EQ(kProtoQUIC, |
1170 alternative_service_info_vector[1].alternative_service.protocol); | 1171 alternative_service_info_vector[1].alternative_service.protocol); |
1171 EXPECT_EQ("", alternative_service_info_vector[1].alternative_service.host); | 1172 EXPECT_EQ("", alternative_service_info_vector[1].alternative_service.host); |
1172 EXPECT_EQ(123, alternative_service_info_vector[1].alternative_service.port); | 1173 EXPECT_EQ(123, alternative_service_info_vector[1].alternative_service.port); |
1173 // numeric_limits<int64_t>::max() represents base::Time::Max(). | 1174 // numeric_limits<int64_t>::max() represents base::Time::Max(). |
1174 EXPECT_EQ(base::Time::Max(), alternative_service_info_vector[1].expiration); | 1175 EXPECT_EQ(base::Time::Max(), alternative_service_info_vector[1].expiration); |
1175 | 1176 |
1176 EXPECT_EQ(NPN_HTTP_2, | 1177 EXPECT_EQ(kProtoHTTP2, |
1177 alternative_service_info_vector[2].alternative_service.protocol); | 1178 alternative_service_info_vector[2].alternative_service.protocol); |
1178 EXPECT_EQ("example.org", | 1179 EXPECT_EQ("example.org", |
1179 alternative_service_info_vector[2].alternative_service.host); | 1180 alternative_service_info_vector[2].alternative_service.host); |
1180 EXPECT_EQ(1234, alternative_service_info_vector[2].alternative_service.port); | 1181 EXPECT_EQ(1234, alternative_service_info_vector[2].alternative_service.port); |
1181 base::Time expected_expiration; | 1182 base::Time expected_expiration; |
1182 ASSERT_TRUE( | 1183 ASSERT_TRUE( |
1183 base::Time::FromUTCString("2036-12-31 10:00:00", &expected_expiration)); | 1184 base::Time::FromUTCString("2036-12-31 10:00:00", &expected_expiration)); |
1184 EXPECT_EQ(expected_expiration, alternative_service_info_vector[2].expiration); | 1185 EXPECT_EQ(expected_expiration, alternative_service_info_vector[2].expiration); |
1185 } | 1186 } |
1186 | 1187 |
(...skipping 16 matching lines...) Expand all Loading... |
1203 } | 1204 } |
1204 | 1205 |
1205 // Do not persist expired or broken alternative service entries to disk. | 1206 // Do not persist expired or broken alternative service entries to disk. |
1206 TEST_P(HttpServerPropertiesManagerTest, | 1207 TEST_P(HttpServerPropertiesManagerTest, |
1207 DoNotPersistExpiredOrBrokenAlternativeService) { | 1208 DoNotPersistExpiredOrBrokenAlternativeService) { |
1208 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 1209 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
1209 | 1210 |
1210 AlternativeServiceInfoVector alternative_service_info_vector; | 1211 AlternativeServiceInfoVector alternative_service_info_vector; |
1211 | 1212 |
1212 const AlternativeService broken_alternative_service( | 1213 const AlternativeService broken_alternative_service( |
1213 NPN_HTTP_2, "broken.example.com", 443); | 1214 kProtoHTTP2, "broken.example.com", 443); |
1214 const base::Time time_one_day_later = | 1215 const base::Time time_one_day_later = |
1215 base::Time::Now() + base::TimeDelta::FromDays(1); | 1216 base::Time::Now() + base::TimeDelta::FromDays(1); |
1216 alternative_service_info_vector.push_back( | 1217 alternative_service_info_vector.push_back( |
1217 AlternativeServiceInfo(broken_alternative_service, time_one_day_later)); | 1218 AlternativeServiceInfo(broken_alternative_service, time_one_day_later)); |
1218 http_server_props_manager_->MarkAlternativeServiceBroken( | 1219 http_server_props_manager_->MarkAlternativeServiceBroken( |
1219 broken_alternative_service); | 1220 broken_alternative_service); |
1220 | 1221 |
1221 const AlternativeService expired_alternative_service( | 1222 const AlternativeService expired_alternative_service( |
1222 NPN_HTTP_2, "expired.example.com", 443); | 1223 kProtoHTTP2, "expired.example.com", 443); |
1223 const base::Time time_one_day_ago = | 1224 const base::Time time_one_day_ago = |
1224 base::Time::Now() - base::TimeDelta::FromDays(1); | 1225 base::Time::Now() - base::TimeDelta::FromDays(1); |
1225 alternative_service_info_vector.push_back( | 1226 alternative_service_info_vector.push_back( |
1226 AlternativeServiceInfo(expired_alternative_service, time_one_day_ago)); | 1227 AlternativeServiceInfo(expired_alternative_service, time_one_day_ago)); |
1227 | 1228 |
1228 const AlternativeService valid_alternative_service(NPN_HTTP_2, | 1229 const AlternativeService valid_alternative_service(kProtoHTTP2, |
1229 "valid.example.com", 443); | 1230 "valid.example.com", 443); |
1230 alternative_service_info_vector.push_back( | 1231 alternative_service_info_vector.push_back( |
1231 AlternativeServiceInfo(valid_alternative_service, time_one_day_later)); | 1232 AlternativeServiceInfo(valid_alternative_service, time_one_day_later)); |
1232 | 1233 |
1233 const url::SchemeHostPort server("https", "www.example.com", 443); | 1234 const url::SchemeHostPort server("https", "www.example.com", 443); |
1234 http_server_props_manager_->SetAlternativeServices( | 1235 http_server_props_manager_->SetAlternativeServices( |
1235 server, alternative_service_info_vector); | 1236 server, alternative_service_info_vector); |
1236 | 1237 |
1237 // Update cache. | 1238 // Update cache. |
1238 ExpectPrefsUpdate(); | 1239 ExpectPrefsUpdate(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1297 const url::SchemeHostPort server("https", "example.com", 443); | 1298 const url::SchemeHostPort server("https", "example.com", 443); |
1298 AlternativeServiceMap alternative_service_map(/*max_size=*/5); | 1299 AlternativeServiceMap alternative_service_map(/*max_size=*/5); |
1299 ASSERT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( | 1300 ASSERT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( |
1300 server, server_pref_dict, &alternative_service_map)); | 1301 server, server_pref_dict, &alternative_service_map)); |
1301 | 1302 |
1302 AlternativeServiceMap::iterator it = alternative_service_map.Get(server); | 1303 AlternativeServiceMap::iterator it = alternative_service_map.Get(server); |
1303 ASSERT_NE(alternative_service_map.end(), it); | 1304 ASSERT_NE(alternative_service_map.end(), it); |
1304 AlternativeServiceInfoVector alternative_service_info_vector = it->second; | 1305 AlternativeServiceInfoVector alternative_service_info_vector = it->second; |
1305 ASSERT_EQ(1u, alternative_service_info_vector.size()); | 1306 ASSERT_EQ(1u, alternative_service_info_vector.size()); |
1306 | 1307 |
1307 EXPECT_EQ(NPN_HTTP_2, | 1308 EXPECT_EQ(kProtoHTTP2, |
1308 alternative_service_info_vector[0].alternative_service.protocol); | 1309 alternative_service_info_vector[0].alternative_service.protocol); |
1309 EXPECT_EQ("valid.example.com", | 1310 EXPECT_EQ("valid.example.com", |
1310 alternative_service_info_vector[0].alternative_service.host); | 1311 alternative_service_info_vector[0].alternative_service.host); |
1311 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); | 1312 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); |
1312 EXPECT_EQ(one_day_from_now_, alternative_service_info_vector[0].expiration); | 1313 EXPECT_EQ(one_day_from_now_, alternative_service_info_vector[0].expiration); |
1313 } | 1314 } |
1314 | 1315 |
1315 TEST_P(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { | 1316 TEST_P(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { |
1316 // Post an update task to the UI thread. | 1317 // Post an update task to the UI thread. |
1317 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 1318 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1378 // Shutdown comes before the task is executed. | 1379 // Shutdown comes before the task is executed. |
1379 http_server_props_manager_->ShutdownOnPrefThread(); | 1380 http_server_props_manager_->ShutdownOnPrefThread(); |
1380 // Run the task after shutdown, but before deletion. | 1381 // Run the task after shutdown, but before deletion. |
1381 base::RunLoop().RunUntilIdle(); | 1382 base::RunLoop().RunUntilIdle(); |
1382 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1383 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
1383 http_server_props_manager_.reset(); | 1384 http_server_props_manager_.reset(); |
1384 base::RunLoop().RunUntilIdle(); | 1385 base::RunLoop().RunUntilIdle(); |
1385 } | 1386 } |
1386 | 1387 |
1387 } // namespace net | 1388 } // namespace net |
OLD | NEW |