| 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/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 base::DictionaryValue* quic_servers_dict = new base::DictionaryValue; | 255 base::DictionaryValue* quic_servers_dict = new base::DictionaryValue; |
| 256 base::DictionaryValue* quic_server_pref_dict1 = new base::DictionaryValue; | 256 base::DictionaryValue* quic_server_pref_dict1 = new base::DictionaryValue; |
| 257 std::string quic_server_info1("quic_server_info1"); | 257 std::string quic_server_info1("quic_server_info1"); |
| 258 quic_server_pref_dict1->SetStringWithoutPathExpansion("server_info", | 258 quic_server_pref_dict1->SetStringWithoutPathExpansion("server_info", |
| 259 quic_server_info1); | 259 quic_server_info1); |
| 260 base::DictionaryValue* quic_server_pref_dict2 = new base::DictionaryValue; | 260 base::DictionaryValue* quic_server_pref_dict2 = new base::DictionaryValue; |
| 261 std::string quic_server_info2("quic_server_info2"); | 261 std::string quic_server_info2("quic_server_info2"); |
| 262 quic_server_pref_dict2->SetStringWithoutPathExpansion("server_info", | 262 quic_server_pref_dict2->SetStringWithoutPathExpansion("server_info", |
| 263 quic_server_info2); | 263 quic_server_info2); |
| 264 // Set the quic_server_info1 for www.google.com server. | 264 // Set the quic_server_info1 for www.google.com server. |
| 265 QuicServerId google_quic_server_id("www.google.com", 80, false); | 265 QuicServerId google_quic_server_id("www.google.com", 80); |
| 266 quic_servers_dict->SetWithoutPathExpansion(google_quic_server_id.ToString(), | 266 quic_servers_dict->SetWithoutPathExpansion(google_quic_server_id.ToString(), |
| 267 quic_server_pref_dict1); | 267 quic_server_pref_dict1); |
| 268 // Set the quic_server_info2 for mail.google.com server. | 268 // Set the quic_server_info2 for mail.google.com server. |
| 269 QuicServerId mail_quic_server_id("mail.google.com", 80, false); | 269 QuicServerId mail_quic_server_id("mail.google.com", 80); |
| 270 quic_servers_dict->SetWithoutPathExpansion(mail_quic_server_id.ToString(), | 270 quic_servers_dict->SetWithoutPathExpansion(mail_quic_server_id.ToString(), |
| 271 quic_server_pref_dict2); | 271 quic_server_pref_dict2); |
| 272 http_server_properties_dict->SetWithoutPathExpansion("quic_servers", | 272 http_server_properties_dict->SetWithoutPathExpansion("quic_servers", |
| 273 quic_servers_dict); | 273 quic_servers_dict); |
| 274 | 274 |
| 275 // Set the same value for kHttpServerProperties multiple times. | 275 // Set the same value for kHttpServerProperties multiple times. |
| 276 pref_service_.SetManagedPref(kTestHttpServerProperties, | 276 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 277 http_server_properties_dict); | 277 http_server_properties_dict); |
| 278 base::DictionaryValue* http_server_properties_dict2 = | 278 base::DictionaryValue* http_server_properties_dict2 = |
| 279 http_server_properties_dict->DeepCopy(); | 279 http_server_properties_dict->DeepCopy(); |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 | 741 |
| 742 const ServerNetworkStats* stats2 = | 742 const ServerNetworkStats* stats2 = |
| 743 http_server_props_manager_->GetServerNetworkStats(mail_server); | 743 http_server_props_manager_->GetServerNetworkStats(mail_server); |
| 744 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 744 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
| 745 } | 745 } |
| 746 | 746 |
| 747 TEST_F(HttpServerPropertiesManagerTest, QuicServerInfo) { | 747 TEST_F(HttpServerPropertiesManagerTest, QuicServerInfo) { |
| 748 ExpectPrefsUpdate(); | 748 ExpectPrefsUpdate(); |
| 749 ExpectScheduleUpdatePrefsOnNetworkThread(); | 749 ExpectScheduleUpdatePrefsOnNetworkThread(); |
| 750 | 750 |
| 751 QuicServerId mail_quic_server_id("mail.google.com", 80, false); | 751 QuicServerId mail_quic_server_id("mail.google.com", 80); |
| 752 EXPECT_EQ(nullptr, | 752 EXPECT_EQ(nullptr, |
| 753 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id)); | 753 http_server_props_manager_->GetQuicServerInfo(mail_quic_server_id)); |
| 754 std::string quic_server_info1("quic_server_info1"); | 754 std::string quic_server_info1("quic_server_info1"); |
| 755 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, | 755 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, |
| 756 quic_server_info1); | 756 quic_server_info1); |
| 757 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. | 757 // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. |
| 758 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, | 758 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, |
| 759 quic_server_info1); | 759 quic_server_info1); |
| 760 | 760 |
| 761 // Run the task. | 761 // Run the task. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 775 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234); | 775 AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234); |
| 776 http_server_props_manager_->SetAlternativeService( | 776 http_server_props_manager_->SetAlternativeService( |
| 777 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); | 777 spdy_server_mail, alternative_service, 1.0, one_day_from_now_); |
| 778 IPAddressNumber actual_address; | 778 IPAddressNumber actual_address; |
| 779 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); | 779 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); |
| 780 http_server_props_manager_->SetSupportsQuic(true, actual_address); | 780 http_server_props_manager_->SetSupportsQuic(true, actual_address); |
| 781 ServerNetworkStats stats; | 781 ServerNetworkStats stats; |
| 782 stats.srtt = base::TimeDelta::FromMicroseconds(10); | 782 stats.srtt = base::TimeDelta::FromMicroseconds(10); |
| 783 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); | 783 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); |
| 784 | 784 |
| 785 QuicServerId mail_quic_server_id("mail.google.com", 80, false); | 785 QuicServerId mail_quic_server_id("mail.google.com", 80); |
| 786 std::string quic_server_info1("quic_server_info1"); | 786 std::string quic_server_info1("quic_server_info1"); |
| 787 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, | 787 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, |
| 788 quic_server_info1); | 788 quic_server_info1); |
| 789 | 789 |
| 790 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 790 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 791 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 791 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 792 const uint32 value1 = 31337; | 792 const uint32 value1 = 31337; |
| 793 http_server_props_manager_->SetSpdySetting(spdy_server_mail, id1, flags1, | 793 http_server_props_manager_->SetSpdySetting(spdy_server_mail, id1, flags1, |
| 794 value1); | 794 value1); |
| 795 | 795 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 base::Time expiration3 = base::Time::Max(); | 934 base::Time expiration3 = base::Time::Max(); |
| 935 http_server_props_manager_->SetAlternativeService( | 935 http_server_props_manager_->SetAlternativeService( |
| 936 server_mail, mail_alternative_service, 0.2, expiration3); | 936 server_mail, mail_alternative_service, 0.2, expiration3); |
| 937 | 937 |
| 938 // Set ServerNetworkStats. | 938 // Set ServerNetworkStats. |
| 939 ServerNetworkStats stats; | 939 ServerNetworkStats stats; |
| 940 stats.srtt = base::TimeDelta::FromInternalValue(42); | 940 stats.srtt = base::TimeDelta::FromInternalValue(42); |
| 941 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); | 941 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); |
| 942 | 942 |
| 943 // Set quic_server_info string. | 943 // Set quic_server_info string. |
| 944 QuicServerId mail_quic_server_id("mail.google.com", 80, false); | 944 QuicServerId mail_quic_server_id("mail.google.com", 80); |
| 945 std::string quic_server_info1("quic_server_info1"); | 945 std::string quic_server_info1("quic_server_info1"); |
| 946 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, | 946 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, |
| 947 quic_server_info1); | 947 quic_server_info1); |
| 948 | 948 |
| 949 // Set SupportsQuic. | 949 // Set SupportsQuic. |
| 950 IPAddressNumber actual_address; | 950 IPAddressNumber actual_address; |
| 951 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); | 951 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); |
| 952 http_server_props_manager_->SetSupportsQuic(true, actual_address); | 952 http_server_props_manager_->SetSupportsQuic(true, actual_address); |
| 953 | 953 |
| 954 // Update cache. | 954 // Update cache. |
| 955 ExpectPrefsUpdate(); | 955 ExpectPrefsUpdate(); |
| 956 ExpectCacheUpdate(); | 956 ExpectCacheUpdate(); |
| 957 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 957 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
| 958 base::RunLoop().RunUntilIdle(); | 958 base::RunLoop().RunUntilIdle(); |
| 959 | 959 |
| 960 // Verify preferences. | 960 // Verify preferences. |
| 961 const char expected_json[] = | 961 const char expected_json[] = |
| 962 "{\"quic_servers\":{\"http://" | 962 "{\"quic_servers\":{\"https://" |
| 963 "mail.google.com:80\":{\"server_info\":\"quic_server_info1\"}}," | 963 "mail.google.com:80\":{\"server_info\":\"quic_server_info1\"}}," |
| 964 "\"servers\":{\"mail.google.com:80\":{\"alternative_service\":[{" | 964 "\"servers\":{\"mail.google.com:80\":{\"alternative_service\":[{" |
| 965 "\"expiration\":\"9223372036854775807\",\"host\":\"foo.google.com\"," | 965 "\"expiration\":\"9223372036854775807\",\"host\":\"foo.google.com\"," |
| 966 "\"port\":444,\"probability\":0.2,\"protocol_str\":\"npn-spdy/3.1\"}]," | 966 "\"port\":444,\"probability\":0.2,\"protocol_str\":\"npn-spdy/3.1\"}]," |
| 967 "\"network_stats\":{\"srtt\":42}},\"www.google.com:80\":{" | 967 "\"network_stats\":{\"srtt\":42}},\"www.google.com:80\":{" |
| 968 "\"alternative_service\":[{\"expiration\":\"13756212000000000\"," | 968 "\"alternative_service\":[{\"expiration\":\"13756212000000000\"," |
| 969 "\"port\":443,\"probability\":1.0,\"protocol_str\":\"npn-h2\"}," | 969 "\"port\":443,\"probability\":1.0,\"protocol_str\":\"npn-h2\"}," |
| 970 "{\"expiration\":\"13758804000000000\",\"host\":\"www.google.com\"," | 970 "{\"expiration\":\"13758804000000000\",\"host\":\"www.google.com\"," |
| 971 "\"port\":1234,\"probability\":0.7,\"protocol_str\":\"npn-h2\"}]}}," | 971 "\"port\":1234,\"probability\":0.7,\"protocol_str\":\"npn-h2\"}]}}," |
| 972 "\"supports_quic\":{\"address\":\"127.0.0.1\",\"used_quic\":true}," | 972 "\"supports_quic\":{\"address\":\"127.0.0.1\",\"used_quic\":true}," |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 // Shutdown comes before the task is executed. | 1136 // Shutdown comes before the task is executed. |
| 1137 http_server_props_manager_->ShutdownOnPrefThread(); | 1137 http_server_props_manager_->ShutdownOnPrefThread(); |
| 1138 // Run the task after shutdown, but before deletion. | 1138 // Run the task after shutdown, but before deletion. |
| 1139 base::RunLoop().RunUntilIdle(); | 1139 base::RunLoop().RunUntilIdle(); |
| 1140 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1140 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 1141 http_server_props_manager_.reset(); | 1141 http_server_props_manager_.reset(); |
| 1142 base::RunLoop().RunUntilIdle(); | 1142 base::RunLoop().RunUntilIdle(); |
| 1143 } | 1143 } |
| 1144 | 1144 |
| 1145 } // namespace net | 1145 } // namespace net |
| OLD | NEW |