| 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 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 474 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 475 } | 475 } |
| 476 | 476 |
| 477 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { | 477 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { |
| 478 ExpectPrefsUpdate(); | 478 ExpectPrefsUpdate(); |
| 479 | 479 |
| 480 HostPortPair spdy_server_mail("mail.google.com", 80); | 480 HostPortPair spdy_server_mail("mail.google.com", 80); |
| 481 EXPECT_FALSE( | 481 EXPECT_FALSE( |
| 482 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 482 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
| 483 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, | 483 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, |
| 484 NPN_SPDY_3, 1); | 484 NPN_SPDY_3, 1.0); |
| 485 | 485 |
| 486 // Run the task. | 486 // Run the task. |
| 487 base::RunLoop().RunUntilIdle(); | 487 base::RunLoop().RunUntilIdle(); |
| 488 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 488 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 489 | 489 |
| 490 ASSERT_TRUE( | 490 ASSERT_TRUE( |
| 491 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 491 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
| 492 AlternateProtocolInfo port_alternate_protocol = | 492 AlternateProtocolInfo port_alternate_protocol = |
| 493 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); | 493 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); |
| 494 EXPECT_EQ(443, port_alternate_protocol.port); | 494 EXPECT_EQ(443, port_alternate_protocol.port); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 http_server_props_manager_->GetServerNetworkStats(mail_server); | 534 http_server_props_manager_->GetServerNetworkStats(mail_server); |
| 535 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 535 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
| 536 } | 536 } |
| 537 | 537 |
| 538 TEST_F(HttpServerPropertiesManagerTest, Clear) { | 538 TEST_F(HttpServerPropertiesManagerTest, Clear) { |
| 539 ExpectPrefsUpdate(); | 539 ExpectPrefsUpdate(); |
| 540 | 540 |
| 541 HostPortPair spdy_server_mail("mail.google.com", 443); | 541 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 542 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 542 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
| 543 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, | 543 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, |
| 544 NPN_SPDY_3, 1); | 544 NPN_SPDY_3, 1.0); |
| 545 http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo"); | 545 http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo"); |
| 546 ServerNetworkStats stats; | 546 ServerNetworkStats stats; |
| 547 stats.srtt = base::TimeDelta::FromMicroseconds(10); | 547 stats.srtt = base::TimeDelta::FromMicroseconds(10); |
| 548 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); | 548 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); |
| 549 | 549 |
| 550 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 550 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 551 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 551 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 552 const uint32 value1 = 31337; | 552 const uint32 value1 = 31337; |
| 553 http_server_props_manager_->SetSpdySetting( | 553 http_server_props_manager_->SetSpdySetting( |
| 554 spdy_server_mail, id1, flags1, value1); | 554 spdy_server_mail, id1, flags1, value1); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 596 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
| 597 EXPECT_EQ(NULL, stats2); | 597 EXPECT_EQ(NULL, stats2); |
| 598 | 598 |
| 599 const SettingsMap& settings_map2_ret = | 599 const SettingsMap& settings_map2_ret = |
| 600 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 600 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 601 EXPECT_EQ(0U, settings_map2_ret.size()); | 601 EXPECT_EQ(0U, settings_map2_ret.size()); |
| 602 | 602 |
| 603 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 603 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 604 } | 604 } |
| 605 | 605 |
| 606 // crbug.com/444956: Add 200 alternate_protocol servers followed by | 606 // https://crbug.com/444956: Add 200 alternate_protocol servers followed by |
| 607 // supports_quic and verify we have read supports_quic from prefs. | 607 // supports_quic and verify we have read supports_quic from prefs. |
| 608 TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { | 608 TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { |
| 609 ExpectCacheUpdate(); | 609 ExpectCacheUpdate(); |
| 610 | 610 |
| 611 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 611 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 612 | 612 |
| 613 for (int i = 0; i < 200; ++i) { | 613 for (int i = 0; i < 200; ++i) { |
| 614 // Set up alternate_protocol for www.google.com:i. | 614 // Set up alternate_protocol for www.google.com:i. |
| 615 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; | 615 base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
| 616 alternate_protocol->SetInteger("port", i); | 616 alternate_protocol->SetInteger("port", i); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 643 pref_service_.SetManagedPref(kTestHttpServerProperties, | 643 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 644 http_server_properties_dict); | 644 http_server_properties_dict); |
| 645 | 645 |
| 646 base::RunLoop().RunUntilIdle(); | 646 base::RunLoop().RunUntilIdle(); |
| 647 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 647 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 648 | 648 |
| 649 // Verify AlternateProtocol. | 649 // Verify AlternateProtocol. |
| 650 for (int i = 0; i < 200; ++i) { | 650 for (int i = 0; i < 200; ++i) { |
| 651 std::string server = StringPrintf("www.google.com:%d", i); | 651 std::string server = StringPrintf("www.google.com:%d", i); |
| 652 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( | 652 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( |
| 653 net::HostPortPair::FromString(server))); | 653 HostPortPair::FromString(server))); |
| 654 net::AlternateProtocolInfo port_alternate_protocol = | 654 AlternateProtocolInfo port_alternate_protocol = |
| 655 http_server_props_manager_->GetAlternateProtocol( | 655 http_server_props_manager_->GetAlternateProtocol( |
| 656 net::HostPortPair::FromString(server)); | 656 HostPortPair::FromString(server)); |
| 657 EXPECT_EQ(i, port_alternate_protocol.port); | 657 EXPECT_EQ(i, port_alternate_protocol.port); |
| 658 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); | 658 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); |
| 659 } | 659 } |
| 660 | 660 |
| 661 // Verify SupportsQuic. | 661 // Verify SupportsQuic. |
| 662 net::SupportsQuic supports_quic1 = | 662 SupportsQuic supports_quic1 = http_server_props_manager_->GetSupportsQuic( |
| 663 http_server_props_manager_->GetSupportsQuic( | 663 HostPortPair::FromString("mail.google.com:80")); |
| 664 net::HostPortPair::FromString("mail.google.com:80")); | |
| 665 EXPECT_TRUE(supports_quic1.used_quic); | 664 EXPECT_TRUE(supports_quic1.used_quic); |
| 666 EXPECT_EQ("bar", supports_quic1.address); | 665 EXPECT_EQ("bar", supports_quic1.address); |
| 667 } | 666 } |
| 668 | 667 |
| 669 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { | 668 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { |
| 670 // Post an update task to the UI thread. | 669 // Post an update task to the UI thread. |
| 671 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 670 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
| 672 // Shutdown comes before the task is executed. | 671 // Shutdown comes before the task is executed. |
| 673 http_server_props_manager_->ShutdownOnPrefThread(); | 672 http_server_props_manager_->ShutdownOnPrefThread(); |
| 674 http_server_props_manager_.reset(); | 673 http_server_props_manager_.reset(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 // Run the task after shutdown, but before deletion. | 733 // Run the task after shutdown, but before deletion. |
| 735 base::RunLoop().RunUntilIdle(); | 734 base::RunLoop().RunUntilIdle(); |
| 736 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 735 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 737 http_server_props_manager_.reset(); | 736 http_server_props_manager_.reset(); |
| 738 base::RunLoop().RunUntilIdle(); | 737 base::RunLoop().RunUntilIdle(); |
| 739 } | 738 } |
| 740 | 739 |
| 741 } // namespace | 740 } // namespace |
| 742 | 741 |
| 743 } // namespace net | 742 } // namespace net |
| OLD | NEW |