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