Chromium Code Reviews| 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/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/prefs/pref_registry_simple.h" | 9 #include "base/prefs/pref_registry_simple.h" |
| 10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| (...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 661 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 661 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); |
| 662 } | 662 } |
| 663 | 663 |
| 664 // Verify SupportsQuic. | 664 // Verify SupportsQuic. |
| 665 SupportsQuic supports_quic1 = http_server_props_manager_->GetSupportsQuic( | 665 SupportsQuic supports_quic1 = http_server_props_manager_->GetSupportsQuic( |
| 666 HostPortPair::FromString("mail.google.com:80")); | 666 HostPortPair::FromString("mail.google.com:80")); |
| 667 EXPECT_TRUE(supports_quic1.used_quic); | 667 EXPECT_TRUE(supports_quic1.used_quic); |
| 668 EXPECT_EQ("bar", supports_quic1.address); | 668 EXPECT_EQ("bar", supports_quic1.address); |
| 669 } | 669 } |
| 670 | 670 |
| 671 TEST_F(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { | |
| 672 const HostPortPair server_www("www.google.com", 80); | |
| 673 const HostPortPair server_mail("mail.google.com", 80); | |
| 674 | |
| 675 // Set alternate protocol. | |
| 676 http_server_props_manager_->SetAlternateProtocol(server_www, 443, NPN_SPDY_3, | |
| 677 1.0); | |
| 678 http_server_props_manager_->SetAlternateProtocol(server_mail, 444, | |
| 679 NPN_SPDY_3_1, 0.2); | |
| 680 | |
| 681 // Set SupportsQuic. | |
| 682 http_server_props_manager_->SetSupportsQuic(server_www, true, "foo"); | |
| 683 | |
| 684 // Set ServerNetworkStats. | |
| 685 ServerNetworkStats stats; | |
| 686 stats.srtt = base::TimeDelta::FromInternalValue(42); | |
| 687 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); | |
| 688 | |
| 689 ExpectPrefsUpdate(); | |
| 690 ExpectCacheUpdate(); | |
| 691 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | |
| 692 base::RunLoop().RunUntilIdle(); | |
| 693 | |
| 694 const base::Value* http_server_properties = | |
| 695 pref_service_.GetUserPref(kTestHttpServerProperties); | |
|
Ryan Hamilton
2015/02/04 22:33:29
Oh nice! This is great.
I do wonder if we can make
Bence
2015/02/05 14:53:24
Done.
| |
| 696 ASSERT_NE(nullptr, http_server_properties); | |
| 697 const base::DictionaryValue* http_server_properties_dict = | |
| 698 new base::DictionaryValue; | |
| 699 ASSERT_TRUE( | |
| 700 http_server_properties->GetAsDictionary(&http_server_properties_dict)); | |
| 701 const base::DictionaryValue* servers_dict = new base::DictionaryValue; | |
| 702 ASSERT_TRUE( | |
| 703 http_server_properties_dict->GetDictionary("servers", &servers_dict)); | |
| 704 ASSERT_EQ(2u, servers_dict->size()); | |
| 705 | |
| 706 // Verify alternate protocol. | |
| 707 const base::DictionaryValue* www_prefs_dict = new base::DictionaryValue; | |
| 708 ASSERT_TRUE(servers_dict->GetDictionaryWithoutPathExpansion( | |
| 709 "www.google.com:80", &www_prefs_dict)); | |
| 710 const base::DictionaryValue* www_altproto_dict = new base::DictionaryValue; | |
| 711 ASSERT_TRUE( | |
| 712 www_prefs_dict->GetDictionary("alternate_protocol", &www_altproto_dict)); | |
| 713 int port; | |
| 714 ASSERT_TRUE(www_altproto_dict->GetInteger("port", &port)); | |
| 715 EXPECT_EQ(443, port); | |
| 716 std::string protocol_str; | |
| 717 ASSERT_TRUE(www_altproto_dict->GetString("protocol_str", &protocol_str)); | |
| 718 EXPECT_EQ("npn-spdy/3", protocol_str); | |
| 719 double probability; | |
| 720 ASSERT_TRUE(www_altproto_dict->GetDouble("probability", &probability)); | |
| 721 EXPECT_EQ(1.0, probability); | |
| 722 | |
| 723 const base::DictionaryValue* mail_prefs_dict = new base::DictionaryValue; | |
| 724 ASSERT_TRUE(servers_dict->GetDictionaryWithoutPathExpansion( | |
| 725 "mail.google.com:80", &mail_prefs_dict)); | |
| 726 const base::DictionaryValue* mail_altproto_dict = new base::DictionaryValue; | |
| 727 ASSERT_TRUE(mail_prefs_dict->GetDictionary("alternate_protocol", | |
| 728 &mail_altproto_dict)); | |
| 729 ASSERT_TRUE(mail_altproto_dict->GetInteger("port", &port)); | |
| 730 EXPECT_EQ(444, port); | |
| 731 ASSERT_TRUE(mail_altproto_dict->GetString("protocol_str", &protocol_str)); | |
| 732 EXPECT_EQ("npn-spdy/3.1", protocol_str); | |
| 733 ASSERT_TRUE(mail_altproto_dict->GetDouble("probability", &probability)); | |
| 734 EXPECT_EQ(0.2, probability); | |
| 735 | |
| 736 // Verify SupportsQuic. | |
| 737 const base::DictionaryValue* supports_quic_dict = new base::DictionaryValue; | |
| 738 ASSERT_TRUE( | |
| 739 www_prefs_dict->GetDictionary("supports_quic", &supports_quic_dict)); | |
| 740 bool used_quic; | |
| 741 ASSERT_TRUE(supports_quic_dict->GetBoolean("used_quic", &used_quic)); | |
| 742 EXPECT_TRUE(used_quic); | |
| 743 std::string address; | |
| 744 ASSERT_TRUE(supports_quic_dict->GetString("address", &address)); | |
| 745 EXPECT_EQ("foo", address); | |
| 746 | |
| 747 ASSERT_FALSE(mail_prefs_dict->GetDictionaryWithoutPathExpansion( | |
| 748 "supports_quic", &supports_quic_dict)); | |
|
Ryan Hamilton
2015/02/04 22:33:29
I have a CL in flight which changes the supports q
Bence
2015/02/05 14:53:24
Rebased, changed test to adapt to your CL. Done.
| |
| 749 | |
| 750 // Verify ServerNetworkStats. | |
| 751 const base::DictionaryValue* stats_dict = new base::DictionaryValue; | |
| 752 ASSERT_FALSE(www_prefs_dict->GetDictionaryWithoutPathExpansion( | |
| 753 "network_stats", &stats_dict)); | |
| 754 | |
| 755 ASSERT_TRUE(mail_prefs_dict->GetDictionaryWithoutPathExpansion( | |
| 756 "network_stats", &stats_dict)); | |
| 757 int srtt; | |
| 758 ASSERT_TRUE(stats_dict->GetInteger("srtt", &srtt)); | |
| 759 EXPECT_EQ(42, srtt); | |
| 760 } | |
| 761 | |
| 671 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { | 762 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { |
| 672 // Post an update task to the UI thread. | 763 // Post an update task to the UI thread. |
| 673 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 764 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
| 674 // Shutdown comes before the task is executed. | 765 // Shutdown comes before the task is executed. |
| 675 http_server_props_manager_->ShutdownOnPrefThread(); | 766 http_server_props_manager_->ShutdownOnPrefThread(); |
| 676 http_server_props_manager_.reset(); | 767 http_server_props_manager_.reset(); |
| 677 // Run the task after shutdown and deletion. | 768 // Run the task after shutdown and deletion. |
| 678 base::RunLoop().RunUntilIdle(); | 769 base::RunLoop().RunUntilIdle(); |
| 679 } | 770 } |
| 680 | 771 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 736 // Run the task after shutdown, but before deletion. | 827 // Run the task after shutdown, but before deletion. |
| 737 base::RunLoop().RunUntilIdle(); | 828 base::RunLoop().RunUntilIdle(); |
| 738 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 829 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 739 http_server_props_manager_.reset(); | 830 http_server_props_manager_.reset(); |
| 740 base::RunLoop().RunUntilIdle(); | 831 base::RunLoop().RunUntilIdle(); |
| 741 } | 832 } |
| 742 | 833 |
| 743 } // namespace | 834 } // namespace |
| 744 | 835 |
| 745 } // namespace net | 836 } // namespace net |
| OLD | NEW |