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" | |
8 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
9 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/macros.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/prefs/pref_registry_simple.h" | 11 #include "base/prefs/pref_registry_simple.h" |
12 #include "base/prefs/testing_pref_service.h" | 12 #include "base/prefs/testing_pref_service.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/test/test_simple_task_runner.h" | 17 #include "base/test/test_simple_task_runner.h" |
18 #include "base/thread_task_runner_handle.h" | 18 #include "base/thread_task_runner_handle.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 } | 460 } |
461 | 461 |
462 TEST_F(HttpServerPropertiesManagerTest, SetSpdySetting) { | 462 TEST_F(HttpServerPropertiesManagerTest, SetSpdySetting) { |
463 ExpectPrefsUpdate(); | 463 ExpectPrefsUpdate(); |
464 ExpectScheduleUpdatePrefsOnNetworkThread(); | 464 ExpectScheduleUpdatePrefsOnNetworkThread(); |
465 | 465 |
466 // Add SpdySetting for mail.google.com:443. | 466 // Add SpdySetting for mail.google.com:443. |
467 HostPortPair spdy_server_mail("mail.google.com", 443); | 467 HostPortPair spdy_server_mail("mail.google.com", 443); |
468 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 468 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
469 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 469 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
470 const uint32 value1 = 31337; | 470 const uint32_t value1 = 31337; |
471 http_server_props_manager_->SetSpdySetting( | 471 http_server_props_manager_->SetSpdySetting( |
472 spdy_server_mail, id1, flags1, value1); | 472 spdy_server_mail, id1, flags1, value1); |
473 | 473 |
474 // Run the task. | 474 // Run the task. |
475 base::RunLoop().RunUntilIdle(); | 475 base::RunLoop().RunUntilIdle(); |
476 | 476 |
477 const SettingsMap& settings_map1_ret = | 477 const SettingsMap& settings_map1_ret = |
478 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 478 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
479 ASSERT_EQ(1U, settings_map1_ret.size()); | 479 ASSERT_EQ(1U, settings_map1_ret.size()); |
480 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 480 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
481 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 481 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
482 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 482 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
483 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 483 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
484 EXPECT_EQ(value1, flags_and_value1_ret.second); | 484 EXPECT_EQ(value1, flags_and_value1_ret.second); |
485 | 485 |
486 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 486 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
487 } | 487 } |
488 | 488 |
489 TEST_F(HttpServerPropertiesManagerTest, ClearSpdySetting) { | 489 TEST_F(HttpServerPropertiesManagerTest, ClearSpdySetting) { |
490 ExpectPrefsUpdateRepeatedly(); | 490 ExpectPrefsUpdateRepeatedly(); |
491 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 491 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
492 | 492 |
493 // Add SpdySetting for mail.google.com:443. | 493 // Add SpdySetting for mail.google.com:443. |
494 HostPortPair spdy_server_mail("mail.google.com", 443); | 494 HostPortPair spdy_server_mail("mail.google.com", 443); |
495 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 495 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
496 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 496 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
497 const uint32 value1 = 31337; | 497 const uint32_t value1 = 31337; |
498 http_server_props_manager_->SetSpdySetting( | 498 http_server_props_manager_->SetSpdySetting( |
499 spdy_server_mail, id1, flags1, value1); | 499 spdy_server_mail, id1, flags1, value1); |
500 | 500 |
501 // Run the task. | 501 // Run the task. |
502 base::RunLoop().RunUntilIdle(); | 502 base::RunLoop().RunUntilIdle(); |
503 | 503 |
504 const SettingsMap& settings_map1_ret = | 504 const SettingsMap& settings_map1_ret = |
505 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 505 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
506 ASSERT_EQ(1U, settings_map1_ret.size()); | 506 ASSERT_EQ(1U, settings_map1_ret.size()); |
507 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 507 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
(...skipping 18 matching lines...) Expand all Loading... |
526 } | 526 } |
527 | 527 |
528 TEST_F(HttpServerPropertiesManagerTest, ClearAllSpdySetting) { | 528 TEST_F(HttpServerPropertiesManagerTest, ClearAllSpdySetting) { |
529 ExpectPrefsUpdateRepeatedly(); | 529 ExpectPrefsUpdateRepeatedly(); |
530 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); | 530 ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); |
531 | 531 |
532 // Add SpdySetting for mail.google.com:443. | 532 // Add SpdySetting for mail.google.com:443. |
533 HostPortPair spdy_server_mail("mail.google.com", 443); | 533 HostPortPair spdy_server_mail("mail.google.com", 443); |
534 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 534 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
535 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 535 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
536 const uint32 value1 = 31337; | 536 const uint32_t value1 = 31337; |
537 http_server_props_manager_->SetSpdySetting( | 537 http_server_props_manager_->SetSpdySetting( |
538 spdy_server_mail, id1, flags1, value1); | 538 spdy_server_mail, id1, flags1, value1); |
539 | 539 |
540 // Run the task. | 540 // Run the task. |
541 base::RunLoop().RunUntilIdle(); | 541 base::RunLoop().RunUntilIdle(); |
542 | 542 |
543 const SettingsMap& settings_map1_ret = | 543 const SettingsMap& settings_map1_ret = |
544 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 544 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
545 ASSERT_EQ(1U, settings_map1_ret.size()); | 545 ASSERT_EQ(1U, settings_map1_ret.size()); |
546 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 546 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
783 stats.srtt = base::TimeDelta::FromMicroseconds(10); | 783 stats.srtt = base::TimeDelta::FromMicroseconds(10); |
784 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); | 784 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); |
785 | 785 |
786 QuicServerId mail_quic_server_id("mail.google.com", 80); | 786 QuicServerId mail_quic_server_id("mail.google.com", 80); |
787 std::string quic_server_info1("quic_server_info1"); | 787 std::string quic_server_info1("quic_server_info1"); |
788 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, | 788 http_server_props_manager_->SetQuicServerInfo(mail_quic_server_id, |
789 quic_server_info1); | 789 quic_server_info1); |
790 | 790 |
791 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 791 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
792 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 792 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
793 const uint32 value1 = 31337; | 793 const uint32_t value1 = 31337; |
794 http_server_props_manager_->SetSpdySetting(spdy_server_mail, id1, flags1, | 794 http_server_props_manager_->SetSpdySetting(spdy_server_mail, id1, flags1, |
795 value1); | 795 value1); |
796 | 796 |
797 // Run the task. | 797 // Run the task. |
798 base::RunLoop().RunUntilIdle(); | 798 base::RunLoop().RunUntilIdle(); |
799 | 799 |
800 EXPECT_TRUE( | 800 EXPECT_TRUE( |
801 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 801 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); |
802 EXPECT_TRUE(HasAlternativeService(spdy_server_mail)); | 802 EXPECT_TRUE(HasAlternativeService(spdy_server_mail)); |
803 IPAddressNumber address; | 803 IPAddressNumber address; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 const base::Time now = base::Time::Now(); | 1014 const base::Time now = base::Time::Now(); |
1015 const base::Time expiration = alternative_service_info_vector[0].expiration; | 1015 const base::Time expiration = alternative_service_info_vector[0].expiration; |
1016 EXPECT_LE(now + base::TimeDelta::FromHours(23), expiration); | 1016 EXPECT_LE(now + base::TimeDelta::FromHours(23), expiration); |
1017 EXPECT_GE(now + base::TimeDelta::FromDays(1), expiration); | 1017 EXPECT_GE(now + base::TimeDelta::FromDays(1), expiration); |
1018 | 1018 |
1019 EXPECT_EQ(QUIC, | 1019 EXPECT_EQ(QUIC, |
1020 alternative_service_info_vector[1].alternative_service.protocol); | 1020 alternative_service_info_vector[1].alternative_service.protocol); |
1021 EXPECT_EQ("", alternative_service_info_vector[1].alternative_service.host); | 1021 EXPECT_EQ("", alternative_service_info_vector[1].alternative_service.host); |
1022 EXPECT_EQ(123, alternative_service_info_vector[1].alternative_service.port); | 1022 EXPECT_EQ(123, alternative_service_info_vector[1].alternative_service.port); |
1023 EXPECT_DOUBLE_EQ(0.7, alternative_service_info_vector[1].probability); | 1023 EXPECT_DOUBLE_EQ(0.7, alternative_service_info_vector[1].probability); |
1024 // numeric_limits<int64>::max() represents base::Time::Max(). | 1024 // numeric_limits<int64_t>::max() represents base::Time::Max(). |
1025 EXPECT_EQ(base::Time::Max(), alternative_service_info_vector[1].expiration); | 1025 EXPECT_EQ(base::Time::Max(), alternative_service_info_vector[1].expiration); |
1026 | 1026 |
1027 EXPECT_EQ(NPN_HTTP_2, | 1027 EXPECT_EQ(NPN_HTTP_2, |
1028 alternative_service_info_vector[2].alternative_service.protocol); | 1028 alternative_service_info_vector[2].alternative_service.protocol); |
1029 EXPECT_EQ("example.org", | 1029 EXPECT_EQ("example.org", |
1030 alternative_service_info_vector[2].alternative_service.host); | 1030 alternative_service_info_vector[2].alternative_service.host); |
1031 EXPECT_EQ(1234, alternative_service_info_vector[2].alternative_service.port); | 1031 EXPECT_EQ(1234, alternative_service_info_vector[2].alternative_service.port); |
1032 EXPECT_DOUBLE_EQ(0.2, alternative_service_info_vector[2].probability); | 1032 EXPECT_DOUBLE_EQ(0.2, alternative_service_info_vector[2].probability); |
1033 base::Time expected_expiration; | 1033 base::Time expected_expiration; |
1034 ASSERT_TRUE( | 1034 ASSERT_TRUE( |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1214 // Shutdown comes before the task is executed. | 1214 // Shutdown comes before the task is executed. |
1215 http_server_props_manager_->ShutdownOnPrefThread(); | 1215 http_server_props_manager_->ShutdownOnPrefThread(); |
1216 // Run the task after shutdown, but before deletion. | 1216 // Run the task after shutdown, but before deletion. |
1217 base::RunLoop().RunUntilIdle(); | 1217 base::RunLoop().RunUntilIdle(); |
1218 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 1218 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
1219 http_server_props_manager_.reset(); | 1219 http_server_props_manager_.reset(); |
1220 base::RunLoop().RunUntilIdle(); | 1220 base::RunLoop().RunUntilIdle(); |
1221 } | 1221 } |
1222 | 1222 |
1223 } // namespace net | 1223 } // namespace net |
OLD | NEW |