Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: net/http/http_server_properties_manager_unittest.cc

Issue 1699653002: Remove support for Alt-Svc/Alternate Protocol Probability (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix BIDI Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_server_properties_manager.cc ('k') | net/http/http_stream_factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 677
678 TEST_P(HttpServerPropertiesManagerTest, GetAlternativeServices) { 678 TEST_P(HttpServerPropertiesManagerTest, GetAlternativeServices) {
679 ExpectPrefsUpdate(); 679 ExpectPrefsUpdate();
680 ExpectScheduleUpdatePrefsOnNetworkThread(); 680 ExpectScheduleUpdatePrefsOnNetworkThread();
681 681
682 HostPortPair spdy_server_mail("mail.google.com", 80); 682 HostPortPair spdy_server_mail("mail.google.com", 80);
683 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); 683 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
684 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 684 const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com",
685 443); 685 443);
686 http_server_props_manager_->SetAlternativeService( 686 http_server_props_manager_->SetAlternativeService(
687 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); 687 spdy_server_mail, alternative_service, one_day_from_now_);
688 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. 688 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
689 http_server_props_manager_->SetAlternativeService( 689 http_server_props_manager_->SetAlternativeService(
690 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); 690 spdy_server_mail, alternative_service, one_day_from_now_);
691 691
692 // Run the task. 692 // Run the task.
693 base::RunLoop().RunUntilIdle(); 693 base::RunLoop().RunUntilIdle();
694 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 694 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
695 695
696 AlternativeServiceVector alternative_service_vector = 696 AlternativeServiceVector alternative_service_vector =
697 http_server_props_manager_->GetAlternativeServices(spdy_server_mail); 697 http_server_props_manager_->GetAlternativeServices(spdy_server_mail);
698 ASSERT_EQ(1u, alternative_service_vector.size()); 698 ASSERT_EQ(1u, alternative_service_vector.size());
699 EXPECT_EQ(alternative_service, alternative_service_vector[0]); 699 EXPECT_EQ(alternative_service, alternative_service_vector[0]);
700 } 700 }
701 701
702 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServices) { 702 TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServices) {
703 ExpectPrefsUpdate(); 703 ExpectPrefsUpdate();
704 ExpectScheduleUpdatePrefsOnNetworkThread(); 704 ExpectScheduleUpdatePrefsOnNetworkThread();
705 705
706 HostPortPair spdy_server_mail("mail.google.com", 80); 706 HostPortPair spdy_server_mail("mail.google.com", 80);
707 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); 707 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
708 AlternativeServiceInfoVector alternative_service_info_vector; 708 AlternativeServiceInfoVector alternative_service_info_vector;
709 const AlternativeService alternative_service1(NPN_HTTP_2, "mail.google.com", 709 const AlternativeService alternative_service1(NPN_HTTP_2, "mail.google.com",
710 443); 710 443);
711 alternative_service_info_vector.push_back( 711 alternative_service_info_vector.push_back(
712 AlternativeServiceInfo(alternative_service1, 1.0, one_day_from_now_)); 712 AlternativeServiceInfo(alternative_service1, one_day_from_now_));
713 const AlternativeService alternative_service2(QUIC, "mail.google.com", 1234); 713 const AlternativeService alternative_service2(QUIC, "mail.google.com", 1234);
714 alternative_service_info_vector.push_back( 714 alternative_service_info_vector.push_back(
715 AlternativeServiceInfo(alternative_service2, 1.0, one_day_from_now_)); 715 AlternativeServiceInfo(alternative_service2, one_day_from_now_));
716 http_server_props_manager_->SetAlternativeServices( 716 http_server_props_manager_->SetAlternativeServices(
717 spdy_server_mail, alternative_service_info_vector); 717 spdy_server_mail, alternative_service_info_vector);
718 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. 718 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
719 http_server_props_manager_->SetAlternativeServices( 719 http_server_props_manager_->SetAlternativeServices(
720 spdy_server_mail, alternative_service_info_vector); 720 spdy_server_mail, alternative_service_info_vector);
721 721
722 // Run the task. 722 // Run the task.
723 base::RunLoop().RunUntilIdle(); 723 base::RunLoop().RunUntilIdle();
724 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 724 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
725 725
(...skipping 21 matching lines...) Expand all
747 } 747 }
748 748
749 TEST_P(HttpServerPropertiesManagerTest, ClearAlternativeServices) { 749 TEST_P(HttpServerPropertiesManagerTest, ClearAlternativeServices) {
750 ExpectPrefsUpdate(); 750 ExpectPrefsUpdate();
751 ExpectScheduleUpdatePrefsOnNetworkThread(); 751 ExpectScheduleUpdatePrefsOnNetworkThread();
752 752
753 HostPortPair spdy_server_mail("mail.google.com", 80); 753 HostPortPair spdy_server_mail("mail.google.com", 80);
754 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); 754 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
755 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443); 755 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443);
756 http_server_props_manager_->SetAlternativeService( 756 http_server_props_manager_->SetAlternativeService(
757 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); 757 spdy_server_mail, alternative_service, one_day_from_now_);
758 ExpectScheduleUpdatePrefsOnNetworkThread(); 758 ExpectScheduleUpdatePrefsOnNetworkThread();
759 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail); 759 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail);
760 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. 760 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
761 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail); 761 http_server_props_manager_->ClearAlternativeServices(spdy_server_mail);
762 762
763 // Run the task. 763 // Run the task.
764 base::RunLoop().RunUntilIdle(); 764 base::RunLoop().RunUntilIdle();
765 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 765 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
766 766
767 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); 767 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
768 } 768 }
769 769
770 TEST_P(HttpServerPropertiesManagerTest, ConfirmAlternativeService) { 770 TEST_P(HttpServerPropertiesManagerTest, ConfirmAlternativeService) {
771 ExpectPrefsUpdate(); 771 ExpectPrefsUpdate();
772 772
773 HostPortPair spdy_server_mail("mail.google.com", 80); 773 HostPortPair spdy_server_mail("mail.google.com", 80);
774 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); 774 EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
775 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443); 775 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443);
776 776
777 ExpectScheduleUpdatePrefsOnNetworkThread(); 777 ExpectScheduleUpdatePrefsOnNetworkThread();
778 http_server_props_manager_->SetAlternativeService( 778 http_server_props_manager_->SetAlternativeService(
779 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); 779 spdy_server_mail, alternative_service, one_day_from_now_);
780 780
781 EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken( 781 EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken(
782 alternative_service)); 782 alternative_service));
783 EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken( 783 EXPECT_FALSE(http_server_props_manager_->WasAlternativeServiceRecentlyBroken(
784 alternative_service)); 784 alternative_service));
785 785
786 ExpectScheduleUpdatePrefsOnNetworkThread(); 786 ExpectScheduleUpdatePrefsOnNetworkThread();
787 http_server_props_manager_->MarkAlternativeServiceBroken(alternative_service); 787 http_server_props_manager_->MarkAlternativeServiceBroken(alternative_service);
788 EXPECT_TRUE(http_server_props_manager_->IsAlternativeServiceBroken( 788 EXPECT_TRUE(http_server_props_manager_->IsAlternativeServiceBroken(
789 alternative_service)); 789 alternative_service));
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 } 879 }
880 880
881 TEST_P(HttpServerPropertiesManagerTest, Clear) { 881 TEST_P(HttpServerPropertiesManagerTest, Clear) {
882 ExpectPrefsUpdate(); 882 ExpectPrefsUpdate();
883 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); 883 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly();
884 884
885 HostPortPair spdy_server_mail("mail.google.com", 443); 885 HostPortPair spdy_server_mail("mail.google.com", 443);
886 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); 886 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true);
887 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234); 887 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234);
888 http_server_props_manager_->SetAlternativeService( 888 http_server_props_manager_->SetAlternativeService(
889 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); 889 spdy_server_mail, alternative_service, one_day_from_now_);
890 IPAddress actual_address(127, 0, 0, 1); 890 IPAddress actual_address(127, 0, 0, 1);
891 http_server_props_manager_->SetSupportsQuic(true, actual_address); 891 http_server_props_manager_->SetSupportsQuic(true, actual_address);
892 ServerNetworkStats stats; 892 ServerNetworkStats stats;
893 stats.srtt = base::TimeDelta::FromMicroseconds(10); 893 stats.srtt = base::TimeDelta::FromMicroseconds(10);
894 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); 894 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats);
895 895
896 QuicServerId mail_quic_server_id("mail.google.com", 80); 896 QuicServerId mail_quic_server_id("mail.google.com", 80);
897 std::string quic_server_info1("quic_server_info1"); 897 std::string quic_server_info1("quic_server_info1");
898 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, 898 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id,
899 quic_server_info1); 899 quic_server_info1);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 1041
1042 const HostPortPair server_www("www.google.com", 80); 1042 const HostPortPair server_www("www.google.com", 80);
1043 const HostPortPair server_mail("mail.google.com", 80); 1043 const HostPortPair server_mail("mail.google.com", 80);
1044 1044
1045 // Set alternate protocol. 1045 // Set alternate protocol.
1046 AlternativeServiceInfoVector alternative_service_info_vector; 1046 AlternativeServiceInfoVector alternative_service_info_vector;
1047 AlternativeService www_alternative_service1(NPN_HTTP_2, "", 443); 1047 AlternativeService www_alternative_service1(NPN_HTTP_2, "", 443);
1048 base::Time expiration1; 1048 base::Time expiration1;
1049 ASSERT_TRUE(base::Time::FromUTCString("2036-12-01 10:00:00", &expiration1)); 1049 ASSERT_TRUE(base::Time::FromUTCString("2036-12-01 10:00:00", &expiration1));
1050 alternative_service_info_vector.push_back( 1050 alternative_service_info_vector.push_back(
1051 AlternativeServiceInfo(www_alternative_service1, 1.0, expiration1)); 1051 AlternativeServiceInfo(www_alternative_service1, expiration1));
1052 AlternativeService www_alternative_service2(NPN_HTTP_2, "www.google.com", 1052 AlternativeService www_alternative_service2(NPN_HTTP_2, "www.google.com",
1053 1234); 1053 1234);
1054 base::Time expiration2; 1054 base::Time expiration2;
1055 ASSERT_TRUE(base::Time::FromUTCString("2036-12-31 10:00:00", &expiration2)); 1055 ASSERT_TRUE(base::Time::FromUTCString("2036-12-31 10:00:00", &expiration2));
1056 alternative_service_info_vector.push_back( 1056 alternative_service_info_vector.push_back(
1057 AlternativeServiceInfo(www_alternative_service2, 0.7, expiration2)); 1057 AlternativeServiceInfo(www_alternative_service2, expiration2));
1058 http_server_props_manager_->SetAlternativeServices( 1058 http_server_props_manager_->SetAlternativeServices(
1059 server_www, alternative_service_info_vector); 1059 server_www, alternative_service_info_vector);
1060 1060
1061 AlternativeService mail_alternative_service(NPN_SPDY_3_1, "foo.google.com", 1061 AlternativeService mail_alternative_service(NPN_SPDY_3_1, "foo.google.com",
1062 444); 1062 444);
1063 base::Time expiration3 = base::Time::Max(); 1063 base::Time expiration3 = base::Time::Max();
1064 http_server_props_manager_->SetAlternativeService( 1064 http_server_props_manager_->SetAlternativeService(
1065 server_mail, mail_alternative_service, 0.2, expiration3); 1065 server_mail, mail_alternative_service, expiration3);
1066 1066
1067 // Set ServerNetworkStats. 1067 // Set ServerNetworkStats.
1068 ServerNetworkStats stats; 1068 ServerNetworkStats stats;
1069 stats.srtt = base::TimeDelta::FromInternalValue(42); 1069 stats.srtt = base::TimeDelta::FromInternalValue(42);
1070 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); 1070 http_server_props_manager_->SetServerNetworkStats(server_mail, stats);
1071 1071
1072 // Set quic_server_info string. 1072 // Set quic_server_info string.
1073 QuicServerId mail_quic_server_id("mail.google.com", 80); 1073 QuicServerId mail_quic_server_id("mail.google.com", 80);
1074 std::string quic_server_info1("quic_server_info1"); 1074 std::string quic_server_info1("quic_server_info1");
1075 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, 1075 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id,
1076 quic_server_info1); 1076 quic_server_info1);
1077 1077
1078 // Set SupportsQuic. 1078 // Set SupportsQuic.
1079 IPAddress actual_address(127, 0, 0, 1); 1079 IPAddress actual_address(127, 0, 0, 1);
1080 http_server_props_manager_->SetSupportsQuic(true, actual_address); 1080 http_server_props_manager_->SetSupportsQuic(true, actual_address);
1081 1081
1082 // Update cache. 1082 // Update cache.
1083 ExpectPrefsUpdate(); 1083 ExpectPrefsUpdate();
1084 ExpectCacheUpdate(); 1084 ExpectCacheUpdate();
1085 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); 1085 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread();
1086 base::RunLoop().RunUntilIdle(); 1086 base::RunLoop().RunUntilIdle();
1087 1087
1088 // Verify preferences. 1088 // Verify preferences.
1089 const char expected_json[] = 1089 const char expected_json[] =
1090 "{\"quic_servers\":{\"https://" 1090 "{\"quic_servers\":{\"https://"
1091 "mail.google.com:80\":{\"server_info\":\"quic_server_info1\"}}," 1091 "mail.google.com:80\":{\"server_info\":\"quic_server_info1\"}},"
1092 "\"servers\":[" 1092 "\"servers\":["
1093 "{\"www.google.com:80\":{" 1093 "{\"www.google.com:80\":{"
1094 "\"alternative_service\":[{\"expiration\":\"13756212000000000\"," 1094 "\"alternative_service\":[{\"expiration\":\"13756212000000000\","
1095 "\"port\":443,\"probability\":1.0,\"protocol_str\":\"npn-h2\"}," 1095 "\"port\":443,\"protocol_str\":\"npn-h2\"},"
1096 "{\"expiration\":\"13758804000000000\",\"host\":\"www.google.com\"," 1096 "{\"expiration\":\"13758804000000000\",\"host\":\"www.google.com\","
1097 "\"port\":1234,\"probability\":0.7,\"protocol_str\":\"npn-h2\"}]}}," 1097 "\"port\":1234,\"protocol_str\":\"npn-h2\"}]}},"
1098 "{\"mail.google.com:80\":{\"alternative_service\":[{" 1098 "{\"mail.google.com:80\":{\"alternative_service\":[{"
1099 "\"expiration\":\"9223372036854775807\",\"host\":\"foo.google.com\"," 1099 "\"expiration\":\"9223372036854775807\",\"host\":\"foo.google.com\","
1100 "\"port\":444,\"probability\":0.2,\"protocol_str\":\"npn-spdy/3.1\"}]," 1100 "\"port\":444,\"protocol_str\":\"npn-spdy/3.1\"}],"
1101 "\"network_stats\":{\"srtt\":42}}}" 1101 "\"network_stats\":{\"srtt\":42}}}"
1102 "]," 1102 "],"
1103 "\"supports_quic\":{\"address\":\"127.0.0.1\",\"used_quic\":true}," 1103 "\"supports_quic\":{\"address\":\"127.0.0.1\",\"used_quic\":true},"
1104 "\"version\":4}"; 1104 "\"version\":4}";
1105 1105
1106 const base::Value* http_server_properties = 1106 const base::Value* http_server_properties =
1107 &pref_delegate_->GetServerProperties(); 1107 &pref_delegate_->GetServerProperties();
1108 std::string preferences_json; 1108 std::string preferences_json;
1109 EXPECT_TRUE( 1109 EXPECT_TRUE(
1110 base::JSONWriter::Write(*http_server_properties, &preferences_json)); 1110 base::JSONWriter::Write(*http_server_properties, &preferences_json));
1111 EXPECT_EQ(expected_json, preferences_json); 1111 EXPECT_EQ(expected_json, preferences_json);
1112 } 1112 }
1113 1113
1114 TEST_P(HttpServerPropertiesManagerTest, AddToAlternativeServiceMap) { 1114 TEST_P(HttpServerPropertiesManagerTest, AddToAlternativeServiceMap) {
1115 scoped_ptr<base::Value> server_value = base::JSONReader::Read( 1115 scoped_ptr<base::Value> server_value = base::JSONReader::Read(
1116 "{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"npn-h2\"}," 1116 "{\"alternative_service\":[{\"port\":443,\"protocol_str\":\"npn-h2\"},"
1117 "{\"port\":123,\"protocol_str\":\"quic\",\"probability\":0.7," 1117 "{\"port\":123,\"protocol_str\":\"quic\","
1118 "\"expiration\":\"9223372036854775807\"},{\"host\":\"example.org\"," 1118 "\"expiration\":\"9223372036854775807\"},{\"host\":\"example.org\","
1119 "\"port\":1234,\"protocol_str\":\"npn-h2\",\"probability\":0.2," 1119 "\"port\":1234,\"protocol_str\":\"npn-h2\","
1120 "\"expiration\":\"13758804000000000\"}]}"); 1120 "\"expiration\":\"13758804000000000\"}]}");
1121 ASSERT_TRUE(server_value); 1121 ASSERT_TRUE(server_value);
1122 base::DictionaryValue* server_dict; 1122 base::DictionaryValue* server_dict;
1123 ASSERT_TRUE(server_value->GetAsDictionary(&server_dict)); 1123 ASSERT_TRUE(server_value->GetAsDictionary(&server_dict));
1124 1124
1125 const HostPortPair host_port_pair("example.com", 443); 1125 const HostPortPair host_port_pair("example.com", 443);
1126 AlternativeServiceMap alternative_service_map(/*max_size=*/5); 1126 AlternativeServiceMap alternative_service_map(/*max_size=*/5);
1127 EXPECT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( 1127 EXPECT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap(
1128 host_port_pair, *server_dict, &alternative_service_map)); 1128 host_port_pair, *server_dict, &alternative_service_map));
1129 1129
1130 AlternativeServiceMap::iterator it = 1130 AlternativeServiceMap::iterator it =
1131 alternative_service_map.Get(host_port_pair); 1131 alternative_service_map.Get(host_port_pair);
1132 ASSERT_NE(alternative_service_map.end(), it); 1132 ASSERT_NE(alternative_service_map.end(), it);
1133 AlternativeServiceInfoVector alternative_service_info_vector = it->second; 1133 AlternativeServiceInfoVector alternative_service_info_vector = it->second;
1134 ASSERT_EQ(3u, alternative_service_info_vector.size()); 1134 ASSERT_EQ(3u, alternative_service_info_vector.size());
1135 1135
1136 EXPECT_EQ(NPN_HTTP_2, 1136 EXPECT_EQ(NPN_HTTP_2,
1137 alternative_service_info_vector[0].alternative_service.protocol); 1137 alternative_service_info_vector[0].alternative_service.protocol);
1138 EXPECT_EQ("", alternative_service_info_vector[0].alternative_service.host); 1138 EXPECT_EQ("", alternative_service_info_vector[0].alternative_service.host);
1139 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); 1139 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port);
1140 // Probability defaults to 1.0.
1141 EXPECT_DOUBLE_EQ(1.0, alternative_service_info_vector[0].probability);
1142 // Expiration defaults to one day from now, testing with tolerance. 1140 // Expiration defaults to one day from now, testing with tolerance.
1143 const base::Time now = base::Time::Now(); 1141 const base::Time now = base::Time::Now();
1144 const base::Time expiration = alternative_service_info_vector[0].expiration; 1142 const base::Time expiration = alternative_service_info_vector[0].expiration;
1145 EXPECT_LE(now + base::TimeDelta::FromHours(23), expiration); 1143 EXPECT_LE(now + base::TimeDelta::FromHours(23), expiration);
1146 EXPECT_GE(now + base::TimeDelta::FromDays(1), expiration); 1144 EXPECT_GE(now + base::TimeDelta::FromDays(1), expiration);
1147 1145
1148 EXPECT_EQ(QUIC, 1146 EXPECT_EQ(QUIC,
1149 alternative_service_info_vector[1].alternative_service.protocol); 1147 alternative_service_info_vector[1].alternative_service.protocol);
1150 EXPECT_EQ("", alternative_service_info_vector[1].alternative_service.host); 1148 EXPECT_EQ("", alternative_service_info_vector[1].alternative_service.host);
1151 EXPECT_EQ(123, alternative_service_info_vector[1].alternative_service.port); 1149 EXPECT_EQ(123, alternative_service_info_vector[1].alternative_service.port);
1152 EXPECT_DOUBLE_EQ(0.7, alternative_service_info_vector[1].probability);
1153 // numeric_limits<int64_t>::max() represents base::Time::Max(). 1150 // numeric_limits<int64_t>::max() represents base::Time::Max().
1154 EXPECT_EQ(base::Time::Max(), alternative_service_info_vector[1].expiration); 1151 EXPECT_EQ(base::Time::Max(), alternative_service_info_vector[1].expiration);
1155 1152
1156 EXPECT_EQ(NPN_HTTP_2, 1153 EXPECT_EQ(NPN_HTTP_2,
1157 alternative_service_info_vector[2].alternative_service.protocol); 1154 alternative_service_info_vector[2].alternative_service.protocol);
1158 EXPECT_EQ("example.org", 1155 EXPECT_EQ("example.org",
1159 alternative_service_info_vector[2].alternative_service.host); 1156 alternative_service_info_vector[2].alternative_service.host);
1160 EXPECT_EQ(1234, alternative_service_info_vector[2].alternative_service.port); 1157 EXPECT_EQ(1234, alternative_service_info_vector[2].alternative_service.port);
1161 EXPECT_DOUBLE_EQ(0.2, alternative_service_info_vector[2].probability);
1162 base::Time expected_expiration; 1158 base::Time expected_expiration;
1163 ASSERT_TRUE( 1159 ASSERT_TRUE(
1164 base::Time::FromUTCString("2036-12-31 10:00:00", &expected_expiration)); 1160 base::Time::FromUTCString("2036-12-31 10:00:00", &expected_expiration));
1165 EXPECT_EQ(expected_expiration, alternative_service_info_vector[2].expiration); 1161 EXPECT_EQ(expected_expiration, alternative_service_info_vector[2].expiration);
1166 } 1162 }
1167 1163
1168 // Do not persist expired or broken alternative service entries to disk. 1164 // Do not persist expired or broken alternative service entries to disk.
1169 TEST_P(HttpServerPropertiesManagerTest, 1165 TEST_P(HttpServerPropertiesManagerTest,
1170 DoNotPersistExpiredOrBrokenAlternativeService) { 1166 DoNotPersistExpiredOrBrokenAlternativeService) {
1171 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); 1167 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly();
1172 1168
1173 AlternativeServiceInfoVector alternative_service_info_vector; 1169 AlternativeServiceInfoVector alternative_service_info_vector;
1174 1170
1175 const AlternativeService broken_alternative_service( 1171 const AlternativeService broken_alternative_service(
1176 NPN_HTTP_2, "broken.example.com", 443); 1172 NPN_HTTP_2, "broken.example.com", 443);
1177 const base::Time time_one_day_later = 1173 const base::Time time_one_day_later =
1178 base::Time::Now() + base::TimeDelta::FromDays(1); 1174 base::Time::Now() + base::TimeDelta::FromDays(1);
1179 alternative_service_info_vector.push_back(AlternativeServiceInfo( 1175 alternative_service_info_vector.push_back(
1180 broken_alternative_service, 1.0, time_one_day_later)); 1176 AlternativeServiceInfo(broken_alternative_service, time_one_day_later));
1181 http_server_props_manager_->MarkAlternativeServiceBroken( 1177 http_server_props_manager_->MarkAlternativeServiceBroken(
1182 broken_alternative_service); 1178 broken_alternative_service);
1183 1179
1184 const AlternativeService expired_alternative_service( 1180 const AlternativeService expired_alternative_service(
1185 NPN_HTTP_2, "expired.example.com", 443); 1181 NPN_HTTP_2, "expired.example.com", 443);
1186 const base::Time time_one_day_ago = 1182 const base::Time time_one_day_ago =
1187 base::Time::Now() - base::TimeDelta::FromDays(1); 1183 base::Time::Now() - base::TimeDelta::FromDays(1);
1188 alternative_service_info_vector.push_back(AlternativeServiceInfo( 1184 alternative_service_info_vector.push_back(
1189 expired_alternative_service, 1.0, time_one_day_ago)); 1185 AlternativeServiceInfo(expired_alternative_service, time_one_day_ago));
1190 1186
1191 const AlternativeService valid_alternative_service(NPN_HTTP_2, 1187 const AlternativeService valid_alternative_service(NPN_HTTP_2,
1192 "valid.example.com", 443); 1188 "valid.example.com", 443);
1193 alternative_service_info_vector.push_back(AlternativeServiceInfo( 1189 alternative_service_info_vector.push_back(
1194 valid_alternative_service, 1.0, time_one_day_later)); 1190 AlternativeServiceInfo(valid_alternative_service, time_one_day_later));
1195 1191
1196 const HostPortPair host_port_pair("www.example.com", 443); 1192 const HostPortPair host_port_pair("www.example.com", 443);
1197 http_server_props_manager_->SetAlternativeServices( 1193 http_server_props_manager_->SetAlternativeServices(
1198 host_port_pair, alternative_service_info_vector); 1194 host_port_pair, alternative_service_info_vector);
1199 1195
1200 // Update cache. 1196 // Update cache.
1201 ExpectPrefsUpdate(); 1197 ExpectPrefsUpdate();
1202 ExpectCacheUpdate(); 1198 ExpectCacheUpdate();
1203 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); 1199 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread();
1204 base::RunLoop().RunUntilIdle(); 1200 base::RunLoop().RunUntilIdle();
(...skipping 24 matching lines...) Expand all
1229 EXPECT_EQ("valid.example.com", hostname); 1225 EXPECT_EQ("valid.example.com", hostname);
1230 } 1226 }
1231 1227
1232 // Test that expired alternative service entries on disk are ignored. 1228 // Test that expired alternative service entries on disk are ignored.
1233 TEST_P(HttpServerPropertiesManagerTest, DoNotLoadExpiredAlternativeService) { 1229 TEST_P(HttpServerPropertiesManagerTest, DoNotLoadExpiredAlternativeService) {
1234 scoped_ptr<base::ListValue> alternative_service_list(new base::ListValue); 1230 scoped_ptr<base::ListValue> alternative_service_list(new base::ListValue);
1235 base::DictionaryValue* expired_dict = new base::DictionaryValue; 1231 base::DictionaryValue* expired_dict = new base::DictionaryValue;
1236 expired_dict->SetString("protocol_str", "npn-h2"); 1232 expired_dict->SetString("protocol_str", "npn-h2");
1237 expired_dict->SetString("host", "expired.example.com"); 1233 expired_dict->SetString("host", "expired.example.com");
1238 expired_dict->SetInteger("port", 443); 1234 expired_dict->SetInteger("port", 443);
1239 expired_dict->SetDouble("probability", 1.0);
1240 base::Time time_one_day_ago = 1235 base::Time time_one_day_ago =
1241 base::Time::Now() - base::TimeDelta::FromDays(1); 1236 base::Time::Now() - base::TimeDelta::FromDays(1);
1242 expired_dict->SetString( 1237 expired_dict->SetString(
1243 "expiration", base::Int64ToString(time_one_day_ago.ToInternalValue())); 1238 "expiration", base::Int64ToString(time_one_day_ago.ToInternalValue()));
1244 alternative_service_list->Append(expired_dict); 1239 alternative_service_list->Append(expired_dict);
1245 1240
1246 base::DictionaryValue* valid_dict = new base::DictionaryValue; 1241 base::DictionaryValue* valid_dict = new base::DictionaryValue;
1247 valid_dict->SetString("protocol_str", "npn-h2"); 1242 valid_dict->SetString("protocol_str", "npn-h2");
1248 valid_dict->SetString("host", "valid.example.com"); 1243 valid_dict->SetString("host", "valid.example.com");
1249 valid_dict->SetInteger("port", 443); 1244 valid_dict->SetInteger("port", 443);
1250 valid_dict->SetDouble("probability", 1.0);
1251 valid_dict->SetString( 1245 valid_dict->SetString(
1252 "expiration", base::Int64ToString(one_day_from_now_.ToInternalValue())); 1246 "expiration", base::Int64ToString(one_day_from_now_.ToInternalValue()));
1253 alternative_service_list->Append(valid_dict); 1247 alternative_service_list->Append(valid_dict);
1254 1248
1255 base::DictionaryValue server_pref_dict; 1249 base::DictionaryValue server_pref_dict;
1256 server_pref_dict.SetWithoutPathExpansion("alternative_service", 1250 server_pref_dict.SetWithoutPathExpansion("alternative_service",
1257 alternative_service_list.release()); 1251 alternative_service_list.release());
1258 1252
1259 const HostPortPair host_port_pair("example.com", 443); 1253 const HostPortPair host_port_pair("example.com", 443);
1260 AlternativeServiceMap alternative_service_map(/*max_size=*/5); 1254 AlternativeServiceMap alternative_service_map(/*max_size=*/5);
1261 ASSERT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap( 1255 ASSERT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap(
1262 host_port_pair, server_pref_dict, &alternative_service_map)); 1256 host_port_pair, server_pref_dict, &alternative_service_map));
1263 1257
1264 AlternativeServiceMap::iterator it = 1258 AlternativeServiceMap::iterator it =
1265 alternative_service_map.Get(host_port_pair); 1259 alternative_service_map.Get(host_port_pair);
1266 ASSERT_NE(alternative_service_map.end(), it); 1260 ASSERT_NE(alternative_service_map.end(), it);
1267 AlternativeServiceInfoVector alternative_service_info_vector = it->second; 1261 AlternativeServiceInfoVector alternative_service_info_vector = it->second;
1268 ASSERT_EQ(1u, alternative_service_info_vector.size()); 1262 ASSERT_EQ(1u, alternative_service_info_vector.size());
1269 1263
1270 EXPECT_EQ(NPN_HTTP_2, 1264 EXPECT_EQ(NPN_HTTP_2,
1271 alternative_service_info_vector[0].alternative_service.protocol); 1265 alternative_service_info_vector[0].alternative_service.protocol);
1272 EXPECT_EQ("valid.example.com", 1266 EXPECT_EQ("valid.example.com",
1273 alternative_service_info_vector[0].alternative_service.host); 1267 alternative_service_info_vector[0].alternative_service.host);
1274 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); 1268 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port);
1275 EXPECT_DOUBLE_EQ(1.0, alternative_service_info_vector[0].probability);
1276 EXPECT_EQ(one_day_from_now_, alternative_service_info_vector[0].expiration); 1269 EXPECT_EQ(one_day_from_now_, alternative_service_info_vector[0].expiration);
1277 } 1270 }
1278 1271
1279 TEST_P(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { 1272 TEST_P(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) {
1280 // Post an update task to the UI thread. 1273 // Post an update task to the UI thread.
1281 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); 1274 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread();
1282 // Shutdown comes before the task is executed. 1275 // Shutdown comes before the task is executed.
1283 http_server_props_manager_->ShutdownOnPrefThread(); 1276 http_server_props_manager_->ShutdownOnPrefThread();
1284 http_server_props_manager_.reset(); 1277 http_server_props_manager_.reset();
1285 // Run the task after shutdown and deletion. 1278 // Run the task after shutdown and deletion.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 // Shutdown comes before the task is executed. 1335 // Shutdown comes before the task is executed.
1343 http_server_props_manager_->ShutdownOnPrefThread(); 1336 http_server_props_manager_->ShutdownOnPrefThread();
1344 // Run the task after shutdown, but before deletion. 1337 // Run the task after shutdown, but before deletion.
1345 base::RunLoop().RunUntilIdle(); 1338 base::RunLoop().RunUntilIdle();
1346 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); 1339 Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
1347 http_server_props_manager_.reset(); 1340 http_server_props_manager_.reset();
1348 base::RunLoop().RunUntilIdle(); 1341 base::RunLoop().RunUntilIdle();
1349 } 1342 }
1350 1343
1351 } // namespace net 1344 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_manager.cc ('k') | net/http/http_stream_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698