| 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 224 |
| 225 // Verify SupportsSpdy. | 225 // Verify SupportsSpdy. |
| 226 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(google_server)); | 226 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(google_server)); |
| 227 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(mail_server)); | 227 EXPECT_TRUE(http_server_props_manager_->SupportsSpdy(mail_server)); |
| 228 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( | 228 EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( |
| 229 HostPortPair::FromString("foo.google.com:1337"))); | 229 HostPortPair::FromString("foo.google.com:1337"))); |
| 230 | 230 |
| 231 // Verify AlternateProtocol. | 231 // Verify AlternateProtocol. |
| 232 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(google_server)); | 232 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(google_server)); |
| 233 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(mail_server)); | 233 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(mail_server)); |
| 234 AlternateProtocolInfo port_alternate_protocol = | 234 AlternateProtocols port_alternate_protocols = |
| 235 http_server_props_manager_->GetAlternateProtocol(google_server); | 235 http_server_props_manager_->GetAlternateProtocols(google_server); |
| 236 EXPECT_EQ(443, port_alternate_protocol.port); | 236 ASSERT_EQ(1u, port_alternate_protocols.size()); |
| 237 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 237 EXPECT_EQ(443, port_alternate_protocols[0].port); |
| 238 port_alternate_protocol = | 238 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocols[0].protocol); |
| 239 http_server_props_manager_->GetAlternateProtocol(mail_server); | 239 port_alternate_protocols = |
| 240 EXPECT_EQ(444, port_alternate_protocol.port); | 240 http_server_props_manager_->GetAlternateProtocols(mail_server); |
| 241 EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocol.protocol); | 241 ASSERT_EQ(1u, port_alternate_protocols.size()); |
| 242 EXPECT_EQ(444, port_alternate_protocols[0].port); |
| 243 EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocols[0].protocol); |
| 242 | 244 |
| 243 // Verify SupportsQuic. | 245 // Verify SupportsQuic. |
| 244 SupportsQuic supports_quic2 = | 246 SupportsQuic supports_quic2 = |
| 245 http_server_props_manager_->GetSupportsQuic(google_server); | 247 http_server_props_manager_->GetSupportsQuic(google_server); |
| 246 EXPECT_TRUE(supports_quic2.used_quic); | 248 EXPECT_TRUE(supports_quic2.used_quic); |
| 247 EXPECT_EQ("foo", supports_quic2.address); | 249 EXPECT_EQ("foo", supports_quic2.address); |
| 248 supports_quic2 = http_server_props_manager_->GetSupportsQuic(mail_server); | 250 supports_quic2 = http_server_props_manager_->GetSupportsQuic(mail_server); |
| 249 EXPECT_FALSE(supports_quic2.used_quic); | 251 EXPECT_FALSE(supports_quic2.used_quic); |
| 250 EXPECT_EQ("bar", supports_quic2.address); | 252 EXPECT_EQ("bar", supports_quic2.address); |
| 251 | 253 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 | 475 |
| 474 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 476 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 475 } | 477 } |
| 476 | 478 |
| 477 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { | 479 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { |
| 478 ExpectPrefsUpdate(); | 480 ExpectPrefsUpdate(); |
| 479 | 481 |
| 480 HostPortPair spdy_server_mail("mail.google.com", 80); | 482 HostPortPair spdy_server_mail("mail.google.com", 80); |
| 481 EXPECT_FALSE( | 483 EXPECT_FALSE( |
| 482 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 484 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
| 483 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, | 485 http_server_props_manager_->AddAlternateProtocol(spdy_server_mail, 443, |
| 484 NPN_SPDY_3, 1); | 486 NPN_SPDY_3, 1); |
| 485 | 487 |
| 486 // Run the task. | 488 // Run the task. |
| 487 base::RunLoop().RunUntilIdle(); | 489 base::RunLoop().RunUntilIdle(); |
| 488 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 490 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 489 | 491 |
| 490 ASSERT_TRUE( | 492 ASSERT_TRUE( |
| 491 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 493 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
| 492 AlternateProtocolInfo port_alternate_protocol = | 494 AlternateProtocols port_alternate_protocols = |
| 493 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); | 495 http_server_props_manager_->GetAlternateProtocols(spdy_server_mail); |
| 494 EXPECT_EQ(443, port_alternate_protocol.port); | 496 ASSERT_EQ(1u, port_alternate_protocols.size()); |
| 495 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 497 EXPECT_EQ(443, port_alternate_protocols[0].port); |
| 498 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocols[0].protocol); |
| 496 } | 499 } |
| 497 | 500 |
| 498 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { | 501 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { |
| 499 ExpectPrefsUpdate(); | 502 ExpectPrefsUpdate(); |
| 500 | 503 |
| 501 HostPortPair quic_server_mail("mail.google.com", 80); | 504 HostPortPair quic_server_mail("mail.google.com", 80); |
| 502 SupportsQuic supports_quic = | 505 SupportsQuic supports_quic = |
| 503 http_server_props_manager_->GetSupportsQuic(quic_server_mail); | 506 http_server_props_manager_->GetSupportsQuic(quic_server_mail); |
| 504 EXPECT_FALSE(supports_quic.used_quic); | 507 EXPECT_FALSE(supports_quic.used_quic); |
| 505 EXPECT_EQ("", supports_quic.address); | 508 EXPECT_EQ("", supports_quic.address); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 533 const ServerNetworkStats* stats2 = | 536 const ServerNetworkStats* stats2 = |
| 534 http_server_props_manager_->GetServerNetworkStats(mail_server); | 537 http_server_props_manager_->GetServerNetworkStats(mail_server); |
| 535 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 538 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
| 536 } | 539 } |
| 537 | 540 |
| 538 TEST_F(HttpServerPropertiesManagerTest, Clear) { | 541 TEST_F(HttpServerPropertiesManagerTest, Clear) { |
| 539 ExpectPrefsUpdate(); | 542 ExpectPrefsUpdate(); |
| 540 | 543 |
| 541 HostPortPair spdy_server_mail("mail.google.com", 443); | 544 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 542 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 545 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
| 543 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, | 546 http_server_props_manager_->AddAlternateProtocol(spdy_server_mail, 443, |
| 544 NPN_SPDY_3, 1); | 547 NPN_SPDY_3, 1); |
| 545 http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo"); | 548 http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo"); |
| 546 ServerNetworkStats stats; | 549 ServerNetworkStats stats; |
| 547 stats.srtt = base::TimeDelta::FromMicroseconds(10); | 550 stats.srtt = base::TimeDelta::FromMicroseconds(10); |
| 548 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); | 551 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); |
| 549 | 552 |
| 550 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 553 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 551 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 554 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 552 const uint32 value1 = 31337; | 555 const uint32 value1 = 31337; |
| 553 http_server_props_manager_->SetSpdySetting( | 556 http_server_props_manager_->SetSpdySetting( |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 pref_service_.SetManagedPref(kTestHttpServerProperties, | 646 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 644 http_server_properties_dict); | 647 http_server_properties_dict); |
| 645 | 648 |
| 646 base::RunLoop().RunUntilIdle(); | 649 base::RunLoop().RunUntilIdle(); |
| 647 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 650 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 648 | 651 |
| 649 // Verify AlternateProtocol. | 652 // Verify AlternateProtocol. |
| 650 for (int i = 0; i < 200; ++i) { | 653 for (int i = 0; i < 200; ++i) { |
| 651 std::string server = StringPrintf("www.google.com:%d", i); | 654 std::string server = StringPrintf("www.google.com:%d", i); |
| 652 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( | 655 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( |
| 653 net::HostPortPair::FromString(server))); | 656 HostPortPair::FromString(server))); |
| 654 net::AlternateProtocolInfo port_alternate_protocol = | 657 AlternateProtocols port_alternate_protocols = |
| 655 http_server_props_manager_->GetAlternateProtocol( | 658 http_server_props_manager_->GetAlternateProtocols( |
| 656 net::HostPortPair::FromString(server)); | 659 HostPortPair::FromString(server)); |
| 657 EXPECT_EQ(i, port_alternate_protocol.port); | 660 EXPECT_EQ(1u, port_alternate_protocols.size()); |
| 658 EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); | 661 EXPECT_EQ(i, port_alternate_protocols[0].port); |
| 662 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocols[0].protocol); |
| 659 } | 663 } |
| 660 | 664 |
| 661 // Verify SupportsQuic. | 665 // Verify SupportsQuic. |
| 662 net::SupportsQuic supports_quic1 = | 666 SupportsQuic supports_quic1 = http_server_props_manager_->GetSupportsQuic( |
| 663 http_server_props_manager_->GetSupportsQuic( | 667 HostPortPair::FromString("mail.google.com:80")); |
| 664 net::HostPortPair::FromString("mail.google.com:80")); | |
| 665 EXPECT_TRUE(supports_quic1.used_quic); | 668 EXPECT_TRUE(supports_quic1.used_quic); |
| 666 EXPECT_EQ("bar", supports_quic1.address); | 669 EXPECT_EQ("bar", supports_quic1.address); |
| 667 } | 670 } |
| 668 | 671 |
| 669 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { | 672 TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { |
| 670 // Post an update task to the UI thread. | 673 // Post an update task to the UI thread. |
| 671 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 674 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
| 672 // Shutdown comes before the task is executed. | 675 // Shutdown comes before the task is executed. |
| 673 http_server_props_manager_->ShutdownOnPrefThread(); | 676 http_server_props_manager_->ShutdownOnPrefThread(); |
| 674 http_server_props_manager_.reset(); | 677 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. | 737 // Run the task after shutdown, but before deletion. |
| 735 base::RunLoop().RunUntilIdle(); | 738 base::RunLoop().RunUntilIdle(); |
| 736 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 739 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 737 http_server_props_manager_.reset(); | 740 http_server_props_manager_.reset(); |
| 738 base::RunLoop().RunUntilIdle(); | 741 base::RunLoop().RunUntilIdle(); |
| 739 } | 742 } |
| 740 | 743 |
| 741 } // namespace | 744 } // namespace |
| 742 | 745 |
| 743 } // namespace net | 746 } // namespace net |
| OLD | NEW |