| 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 "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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 EXPECT_EQ(444, map_it->second[0].alternative_service.port); | 404 EXPECT_EQ(444, map_it->second[0].alternative_service.port); |
| 405 } | 405 } |
| 406 | 406 |
| 407 // Verify SupportsQuic. | 407 // Verify SupportsQuic. |
| 408 IPAddress last_address; | 408 IPAddress last_address; |
| 409 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); | 409 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); |
| 410 EXPECT_EQ("127.0.0.1", last_address.ToString()); | 410 EXPECT_EQ("127.0.0.1", last_address.ToString()); |
| 411 | 411 |
| 412 // Verify ServerNetworkStats. | 412 // Verify ServerNetworkStats. |
| 413 const ServerNetworkStats* stats2 = | 413 const ServerNetworkStats* stats2 = |
| 414 http_server_props_manager_->GetServerNetworkStats(google_server); | 414 http_server_props_manager_->GetServerNetworkStats( |
| 415 google_scheme_host_port); |
| 415 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 416 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
| 416 const ServerNetworkStats* stats3 = | 417 const ServerNetworkStats* stats3 = |
| 417 http_server_props_manager_->GetServerNetworkStats(mail_server); | 418 http_server_props_manager_->GetServerNetworkStats(mail_scheme_host_port); |
| 418 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); | 419 EXPECT_EQ(20, stats3->srtt.ToInternalValue()); |
| 419 | 420 |
| 420 // Verify QuicServerInfo. | 421 // Verify QuicServerInfo. |
| 421 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( | 422 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( |
| 422 google_quic_server_id)); | 423 google_quic_server_id)); |
| 423 EXPECT_EQ(quic_server_info2, *http_server_props_manager_->GetQuicServerInfo( | 424 EXPECT_EQ(quic_server_info2, *http_server_props_manager_->GetQuicServerInfo( |
| 424 mail_quic_server_id)); | 425 mail_quic_server_id)); |
| 425 EXPECT_EQ(quic_server_info3, *http_server_props_manager_->GetQuicServerInfo( | 426 EXPECT_EQ(quic_server_info3, *http_server_props_manager_->GetQuicServerInfo( |
| 426 play_quic_server_id)); | 427 play_quic_server_id)); |
| 427 | 428 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 HostPortPair google_server = HostPortPair::FromString("www.google.com:65536"); | 501 HostPortPair google_server = HostPortPair::FromString("www.google.com:65536"); |
| 501 url::SchemeHostPort google_scheme_host_port("http", google_server.host(), | 502 url::SchemeHostPort google_scheme_host_port("http", google_server.host(), |
| 502 google_server.port()); | 503 google_server.port()); |
| 503 | 504 |
| 504 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( | 505 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( |
| 505 google_scheme_host_port)); | 506 google_scheme_host_port)); |
| 506 EXPECT_FALSE( | 507 EXPECT_FALSE( |
| 507 HasAlternativeService(HostPortPair::FromString("www.google.com:65536"))); | 508 HasAlternativeService(HostPortPair::FromString("www.google.com:65536"))); |
| 508 const ServerNetworkStats* stats1 = | 509 const ServerNetworkStats* stats1 = |
| 509 http_server_props_manager_->GetServerNetworkStats( | 510 http_server_props_manager_->GetServerNetworkStats( |
| 510 HostPortPair::FromString("www.google.com:65536")); | 511 google_scheme_host_port); |
| 511 EXPECT_EQ(nullptr, stats1); | 512 EXPECT_EQ(nullptr, stats1); |
| 512 EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size()); | 513 EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size()); |
| 513 } | 514 } |
| 514 | 515 |
| 515 TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { | 516 TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { |
| 516 ExpectCacheUpdate(); | 517 ExpectCacheUpdate(); |
| 517 // The prefs are automaticalls updated in the case corruption is detected. | 518 // The prefs are automaticalls updated in the case corruption is detected. |
| 518 ExpectPrefsUpdate(); | 519 ExpectPrefsUpdate(); |
| 519 ExpectScheduleUpdatePrefsOnNetworkThread(); | 520 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 520 | 521 |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 844 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 844 | 845 |
| 845 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); | 846 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 846 EXPECT_EQ(actual_address, address); | 847 EXPECT_EQ(actual_address, address); |
| 847 } | 848 } |
| 848 | 849 |
| 849 TEST_P(HttpServerPropertiesManagerTest, ServerNetworkStats) { | 850 TEST_P(HttpServerPropertiesManagerTest, ServerNetworkStats) { |
| 850 ExpectPrefsUpdate(); | 851 ExpectPrefsUpdate(); |
| 851 ExpectScheduleUpdatePrefsOnNetworkThread(); | 852 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 852 | 853 |
| 853 HostPortPair mail_server("mail.google.com", 80); | 854 url::SchemeHostPort mail_server("http", "mail.google.com", 80); |
| 854 const ServerNetworkStats* stats = | 855 const ServerNetworkStats* stats = |
| 855 http_server_props_manager_->GetServerNetworkStats(mail_server); | 856 http_server_props_manager_->GetServerNetworkStats(mail_server); |
| 856 EXPECT_EQ(nullptr, stats); | 857 EXPECT_EQ(nullptr, stats); |
| 857 ServerNetworkStats stats1; | 858 ServerNetworkStats stats1; |
| 858 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 859 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
| 859 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); | 860 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); |
| 860 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 861 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
| 861 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); | 862 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); |
| 862 | 863 |
| 863 // Run the task. | 864 // Run the task. |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 898 HostPortPair spdy_server_mail("mail.google.com", 443); | 899 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 899 url::SchemeHostPort spdy_server("https", "mail.google.com", 443); | 900 url::SchemeHostPort spdy_server("https", "mail.google.com", 443); |
| 900 http_server_props_manager_->SetSupportsSpdy(spdy_server, true); | 901 http_server_props_manager_->SetSupportsSpdy(spdy_server, true); |
| 901 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234); | 902 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234); |
| 902 http_server_props_manager_->SetAlternativeService( | 903 http_server_props_manager_->SetAlternativeService( |
| 903 spdy_server_mail, alternative_service, one_day_from_now_); | 904 spdy_server_mail, alternative_service, one_day_from_now_); |
| 904 IPAddress actual_address(127, 0, 0, 1); | 905 IPAddress actual_address(127, 0, 0, 1); |
| 905 http_server_props_manager_->SetSupportsQuic(true, actual_address); | 906 http_server_props_manager_->SetSupportsQuic(true, actual_address); |
| 906 ServerNetworkStats stats; | 907 ServerNetworkStats stats; |
| 907 stats.srtt = base::TimeDelta::FromMicroseconds(10); | 908 stats.srtt = base::TimeDelta::FromMicroseconds(10); |
| 908 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); | 909 http_server_props_manager_->SetServerNetworkStats(spdy_server, stats); |
| 909 | 910 |
| 910 QuicServerId mail_quic_server_id("mail.google.com", 80); | 911 QuicServerId mail_quic_server_id("mail.google.com", 80); |
| 911 std::string quic_server_info1("quic_server_info1"); | 912 std::string quic_server_info1("quic_server_info1"); |
| 912 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, | 913 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, |
| 913 quic_server_info1); | 914 quic_server_info1); |
| 914 | 915 |
| 915 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 916 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 916 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 917 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 917 const uint32_t value1 = 31337; | 918 const uint32_t value1 = 31337; |
| 918 http_server_props_manager_->SetSpdySetting(spdy_server, id1, flags1, value1); | 919 http_server_props_manager_->SetSpdySetting(spdy_server, id1, flags1, value1); |
| 919 | 920 |
| 920 // Run the task. | 921 // Run the task. |
| 921 base::RunLoop().RunUntilIdle(); | 922 base::RunLoop().RunUntilIdle(); |
| 922 | 923 |
| 923 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(spdy_server)); | 924 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(spdy_server)); |
| 924 EXPECT_TRUE(HasAlternativeService(spdy_server_mail)); | 925 EXPECT_TRUE(HasAlternativeService(spdy_server_mail)); |
| 925 IPAddress address; | 926 IPAddress address; |
| 926 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); | 927 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 927 EXPECT_EQ(actual_address, address); | 928 EXPECT_EQ(actual_address, address); |
| 928 const ServerNetworkStats* stats1 = | 929 const ServerNetworkStats* stats1 = |
| 929 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 930 http_server_props_manager_->GetServerNetworkStats(spdy_server); |
| 930 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); | 931 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); |
| 931 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( | 932 EXPECT_EQ(quic_server_info1, *http_server_props_manager_->GetQuicServerInfo( |
| 932 mail_quic_server_id)); | 933 mail_quic_server_id)); |
| 933 | 934 |
| 934 // Check SPDY settings values. | 935 // Check SPDY settings values. |
| 935 const SettingsMap& settings_map1_ret = | 936 const SettingsMap& settings_map1_ret = |
| 936 http_server_props_manager_->GetSpdySettings(spdy_server); | 937 http_server_props_manager_->GetSpdySettings(spdy_server); |
| 937 ASSERT_EQ(1U, settings_map1_ret.size()); | 938 ASSERT_EQ(1U, settings_map1_ret.size()); |
| 938 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 939 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
| 939 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 940 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
| 940 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 941 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
| 941 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 942 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
| 942 EXPECT_EQ(value1, flags_and_value1_ret.second); | 943 EXPECT_EQ(value1, flags_and_value1_ret.second); |
| 943 | 944 |
| 944 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 945 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 945 | 946 |
| 946 ExpectPrefsUpdate(); | 947 ExpectPrefsUpdate(); |
| 947 | 948 |
| 948 // Clear http server data, time out if we do not get a completion callback. | 949 // Clear http server data, time out if we do not get a completion callback. |
| 949 http_server_props_manager_->Clear(base::MessageLoop::QuitWhenIdleClosure()); | 950 http_server_props_manager_->Clear(base::MessageLoop::QuitWhenIdleClosure()); |
| 950 base::RunLoop().Run(); | 951 base::RunLoop().Run(); |
| 951 | 952 |
| 952 EXPECT_FALSE( | 953 EXPECT_FALSE( |
| 953 http_server_props_manager_->SupportsRequestPriority(spdy_server)); | 954 http_server_props_manager_->SupportsRequestPriority(spdy_server)); |
| 954 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); | 955 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
| 955 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); | 956 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 956 const ServerNetworkStats* stats2 = | 957 const ServerNetworkStats* stats2 = |
| 957 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 958 http_server_props_manager_->GetServerNetworkStats(spdy_server); |
| 958 EXPECT_EQ(nullptr, stats2); | 959 EXPECT_EQ(nullptr, stats2); |
| 959 EXPECT_EQ(nullptr, | 960 EXPECT_EQ(nullptr, |
| 960 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id)); | 961 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id)); |
| 961 | 962 |
| 962 const SettingsMap& settings_map2_ret = | 963 const SettingsMap& settings_map2_ret = |
| 963 http_server_props_manager_->GetSpdySettings(spdy_server); | 964 http_server_props_manager_->GetSpdySettings(spdy_server); |
| 964 EXPECT_EQ(0U, settings_map2_ret.size()); | 965 EXPECT_EQ(0U, settings_map2_ret.size()); |
| 965 | 966 |
| 966 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 967 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 967 } | 968 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 // Verify SupportsQuic. | 1046 // Verify SupportsQuic. |
| 1046 IPAddress address; | 1047 IPAddress address; |
| 1047 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); | 1048 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 1048 EXPECT_EQ("127.0.0.1", address.ToString()); | 1049 EXPECT_EQ("127.0.0.1", address.ToString()); |
| 1049 } | 1050 } |
| 1050 | 1051 |
| 1051 TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { | 1052 TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { |
| 1052 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 1053 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
| 1053 | 1054 |
| 1054 const HostPortPair server_www("www.google.com", 80); | 1055 const HostPortPair server_www("www.google.com", 80); |
| 1055 const HostPortPair server_mail("mail.google.com", 80); | 1056 const url::SchemeHostPort server_mail("http", "mail.google.com", 80); |
| 1056 | 1057 |
| 1057 // Set alternate protocol. | 1058 // Set alternate protocol. |
| 1058 AlternativeServiceInfoVector alternative_service_info_vector; | 1059 AlternativeServiceInfoVector alternative_service_info_vector; |
| 1059 AlternativeService www_alternative_service1(NPN_HTTP_2, "", 443); | 1060 AlternativeService www_alternative_service1(NPN_HTTP_2, "", 443); |
| 1060 base::Time expiration1; | 1061 base::Time expiration1; |
| 1061 ASSERT_TRUE(base::Time::FromUTCString("2036-12-01 10:00:00", &expiration1)); | 1062 ASSERT_TRUE(base::Time::FromUTCString("2036-12-01 10:00:00", &expiration1)); |
| 1062 alternative_service_info_vector.push_back( | 1063 alternative_service_info_vector.push_back( |
| 1063 AlternativeServiceInfo(www_alternative_service1, expiration1)); | 1064 AlternativeServiceInfo(www_alternative_service1, expiration1)); |
| 1064 AlternativeService www_alternative_service2(NPN_HTTP_2, "www.google.com", | 1065 AlternativeService www_alternative_service2(NPN_HTTP_2, "www.google.com", |
| 1065 1234); | 1066 1234); |
| 1066 base::Time expiration2; | 1067 base::Time expiration2; |
| 1067 ASSERT_TRUE(base::Time::FromUTCString("2036-12-31 10:00:00", &expiration2)); | 1068 ASSERT_TRUE(base::Time::FromUTCString("2036-12-31 10:00:00", &expiration2)); |
| 1068 alternative_service_info_vector.push_back( | 1069 alternative_service_info_vector.push_back( |
| 1069 AlternativeServiceInfo(www_alternative_service2, expiration2)); | 1070 AlternativeServiceInfo(www_alternative_service2, expiration2)); |
| 1070 http_server_props_manager_->SetAlternativeServices( | 1071 http_server_props_manager_->SetAlternativeServices( |
| 1071 server_www, alternative_service_info_vector); | 1072 server_www, alternative_service_info_vector); |
| 1072 | 1073 |
| 1073 AlternativeService mail_alternative_service(NPN_SPDY_3_1, "foo.google.com", | 1074 AlternativeService mail_alternative_service(NPN_SPDY_3_1, "foo.google.com", |
| 1074 444); | 1075 444); |
| 1075 base::Time expiration3 = base::Time::Max(); | 1076 base::Time expiration3 = base::Time::Max(); |
| 1076 http_server_props_manager_->SetAlternativeService( | 1077 http_server_props_manager_->SetAlternativeService( |
| 1077 server_mail, mail_alternative_service, expiration3); | 1078 HostPortPair(server_mail.host(), server_mail.port()), |
| 1079 mail_alternative_service, expiration3); |
| 1078 | 1080 |
| 1079 // Set ServerNetworkStats. | 1081 // Set ServerNetworkStats. |
| 1080 ServerNetworkStats stats; | 1082 ServerNetworkStats stats; |
| 1081 stats.srtt = base::TimeDelta::FromInternalValue(42); | 1083 stats.srtt = base::TimeDelta::FromInternalValue(42); |
| 1082 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); | 1084 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); |
| 1083 | 1085 |
| 1084 // Set quic_server_info string. | 1086 // Set quic_server_info string. |
| 1085 QuicServerId mail_quic_server_id("mail.google.com", 80); | 1087 QuicServerId mail_quic_server_id("mail.google.com", 80); |
| 1086 std::string quic_server_info1("quic_server_info1"); | 1088 std::string quic_server_info1("quic_server_info1"); |
| 1087 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, | 1089 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1348 // Shutdown comes before the task is executed. | 1350 // Shutdown comes before the task is executed. |
| 1349 http_server_props_manager_->ShutdownOnPrefThread(); | 1351 http_server_props_manager_->ShutdownOnPrefThread(); |
| 1350 // Run the task after shutdown, but before deletion. | 1352 // Run the task after shutdown, but before deletion. |
| 1351 base::RunLoop().RunUntilIdle(); | 1353 base::RunLoop().RunUntilIdle(); |
| 1352 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1354 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 1353 http_server_props_manager_.reset(); | 1355 http_server_props_manager_.reset(); |
| 1354 base::RunLoop().RunUntilIdle(); | 1356 base::RunLoop().RunUntilIdle(); |
| 1355 } | 1357 } |
| 1356 | 1358 |
| 1357 } // namespace net | 1359 } // namespace net |
| OLD | NEW |