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