| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 127 |
| 128 void ExpectPrefsUpdateRepeatedly() { | 128 void ExpectPrefsUpdateRepeatedly() { |
| 129 EXPECT_CALL(*http_server_props_manager_, | 129 EXPECT_CALL(*http_server_props_manager_, |
| 130 UpdatePrefsFromCacheOnNetworkThread(_)) | 130 UpdatePrefsFromCacheOnNetworkThread(_)) |
| 131 .WillRepeatedly( | 131 .WillRepeatedly( |
| 132 Invoke(http_server_props_manager_.get(), | 132 Invoke(http_server_props_manager_.get(), |
| 133 &TestingHttpServerPropertiesManager:: | 133 &TestingHttpServerPropertiesManager:: |
| 134 UpdatePrefsFromCacheOnNetworkThreadConcrete)); | 134 UpdatePrefsFromCacheOnNetworkThreadConcrete)); |
| 135 } | 135 } |
| 136 | 136 |
| 137 bool HasAlternateProtocol(const HostPortPair& server) { |
| 138 const AlternateProtocolInfo alternate = |
| 139 http_server_props_manager_->GetAlternateProtocol(server); |
| 140 return alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL; |
| 141 } |
| 142 |
| 137 //base::RunLoop loop_; | 143 //base::RunLoop loop_; |
| 138 TestingPrefServiceSimple pref_service_; | 144 TestingPrefServiceSimple pref_service_; |
| 139 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; | 145 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; |
| 140 | 146 |
| 141 private: | 147 private: |
| 142 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); | 148 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); |
| 143 }; | 149 }; |
| 144 | 150 |
| 145 TEST_F(HttpServerPropertiesManagerTest, | 151 TEST_F(HttpServerPropertiesManagerTest, |
| 146 SingleUpdateForTwoSpdyServerPrefChanges) { | 152 SingleUpdateForTwoSpdyServerPrefChanges) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 229 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 224 | 230 |
| 225 // Verify SupportsSpdy. | 231 // Verify SupportsSpdy. |
| 226 EXPECT_TRUE( | 232 EXPECT_TRUE( |
| 227 http_server_props_manager_->SupportsRequestPriority(google_server)); | 233 http_server_props_manager_->SupportsRequestPriority(google_server)); |
| 228 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); | 234 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); |
| 229 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( | 235 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( |
| 230 HostPortPair::FromString("foo.google.com:1337"))); | 236 HostPortPair::FromString("foo.google.com:1337"))); |
| 231 | 237 |
| 232 // Verify AlternateProtocol. | 238 // Verify AlternateProtocol. |
| 233 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(google_server)); | |
| 234 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(mail_server)); | |
| 235 AlternateProtocolInfo port_alternate_protocol = | 239 AlternateProtocolInfo port_alternate_protocol = |
| 236 http_server_props_manager_->GetAlternateProtocol(google_server); | 240 http_server_props_manager_->GetAlternateProtocol(google_server); |
| 237 EXPECT_EQ(443, port_alternate_protocol.port); | 241 EXPECT_EQ(443, port_alternate_protocol.port); |
| 238 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 242 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); |
| 239 port_alternate_protocol = | 243 port_alternate_protocol = |
| 240 http_server_props_manager_->GetAlternateProtocol(mail_server); | 244 http_server_props_manager_->GetAlternateProtocol(mail_server); |
| 241 EXPECT_EQ(444, port_alternate_protocol.port); | 245 EXPECT_EQ(444, port_alternate_protocol.port); |
| 242 EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocol.protocol); | 246 EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocol.protocol); |
| 243 | 247 |
| 244 // Verify SupportsQuic. | 248 // Verify SupportsQuic. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 // Set up the pref. | 304 // Set up the pref. |
| 301 pref_service_.SetManagedPref(kTestHttpServerProperties, | 305 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 302 http_server_properties_dict); | 306 http_server_properties_dict); |
| 303 | 307 |
| 304 base::RunLoop().RunUntilIdle(); | 308 base::RunLoop().RunUntilIdle(); |
| 305 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 309 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 306 | 310 |
| 307 // Verify that nothing is set. | 311 // Verify that nothing is set. |
| 308 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( | 312 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( |
| 309 HostPortPair::FromString("www.google.com:65536"))); | 313 HostPortPair::FromString("www.google.com:65536"))); |
| 310 EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( | 314 EXPECT_FALSE( |
| 311 HostPortPair::FromString("www.google.com:65536"))); | 315 HasAlternateProtocol(HostPortPair::FromString("www.google.com:65536"))); |
| 312 SupportsQuic supports_quic2 = http_server_props_manager_->GetSupportsQuic( | 316 SupportsQuic supports_quic2 = http_server_props_manager_->GetSupportsQuic( |
| 313 HostPortPair::FromString("www.google.com:65536")); | 317 HostPortPair::FromString("www.google.com:65536")); |
| 314 EXPECT_FALSE(supports_quic2.used_quic); | 318 EXPECT_FALSE(supports_quic2.used_quic); |
| 315 const ServerNetworkStats* stats1 = | 319 const ServerNetworkStats* stats1 = |
| 316 http_server_props_manager_->GetServerNetworkStats( | 320 http_server_props_manager_->GetServerNetworkStats( |
| 317 HostPortPair::FromString("www.google.com:65536")); | 321 HostPortPair::FromString("www.google.com:65536")); |
| 318 EXPECT_EQ(NULL, stats1); | 322 EXPECT_EQ(NULL, stats1); |
| 319 } | 323 } |
| 320 | 324 |
| 321 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { | 325 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 345 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); | 349 http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); |
| 346 | 350 |
| 347 // Set up the pref. | 351 // Set up the pref. |
| 348 pref_service_.SetManagedPref(kTestHttpServerProperties, | 352 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 349 http_server_properties_dict); | 353 http_server_properties_dict); |
| 350 | 354 |
| 351 base::RunLoop().RunUntilIdle(); | 355 base::RunLoop().RunUntilIdle(); |
| 352 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 356 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 353 | 357 |
| 354 // Verify AlternateProtocol is not set. | 358 // Verify AlternateProtocol is not set. |
| 355 EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( | 359 EXPECT_FALSE( |
| 356 HostPortPair::FromString("www.google.com:80"))); | 360 HasAlternateProtocol(HostPortPair::FromString("www.google.com:80"))); |
| 357 } | 361 } |
| 358 | 362 |
| 359 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { | 363 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { |
| 360 ExpectPrefsUpdate(); | 364 ExpectPrefsUpdate(); |
| 361 | 365 |
| 362 // Post an update task to the network thread. SetSupportsSpdy calls | 366 // Post an update task to the network thread. SetSupportsSpdy calls |
| 363 // ScheduleUpdatePrefsOnNetworkThread. | 367 // ScheduleUpdatePrefsOnNetworkThread. |
| 364 | 368 |
| 365 // Add mail.google.com:443 as a supporting spdy server. | 369 // Add mail.google.com:443 as a supporting spdy server. |
| 366 HostPortPair spdy_server_mail("mail.google.com", 443); | 370 HostPortPair spdy_server_mail("mail.google.com", 443); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 base::RunLoop().RunUntilIdle(); | 474 base::RunLoop().RunUntilIdle(); |
| 471 | 475 |
| 472 // Verify that there are no entries in the settings map. | 476 // Verify that there are no entries in the settings map. |
| 473 const SpdySettingsMap& spdy_settings_map2_ret = | 477 const SpdySettingsMap& spdy_settings_map2_ret = |
| 474 http_server_props_manager_->spdy_settings_map(); | 478 http_server_props_manager_->spdy_settings_map(); |
| 475 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); | 479 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); |
| 476 | 480 |
| 477 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 481 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 478 } | 482 } |
| 479 | 483 |
| 480 TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { | 484 TEST_F(HttpServerPropertiesManagerTest, GetAlternateProtocol) { |
| 481 ExpectPrefsUpdate(); | 485 ExpectPrefsUpdate(); |
| 482 | 486 |
| 483 HostPortPair spdy_server_mail("mail.google.com", 80); | 487 HostPortPair spdy_server_mail("mail.google.com", 80); |
| 484 EXPECT_FALSE( | 488 AlternateProtocolInfo alternate_protocol = |
| 485 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | 489 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); |
| 490 EXPECT_EQ(UNINITIALIZED_ALTERNATE_PROTOCOL, alternate_protocol.protocol); |
| 486 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, | 491 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, |
| 487 NPN_SPDY_3, 1.0); | 492 NPN_SPDY_3, 1.0); |
| 488 | 493 |
| 489 // Run the task. | 494 // Run the task. |
| 490 base::RunLoop().RunUntilIdle(); | 495 base::RunLoop().RunUntilIdle(); |
| 491 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 496 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 492 | 497 |
| 493 ASSERT_TRUE( | 498 alternate_protocol = |
| 494 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | |
| 495 AlternateProtocolInfo port_alternate_protocol = | |
| 496 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); | 499 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); |
| 497 EXPECT_EQ(443, port_alternate_protocol.port); | 500 EXPECT_EQ(443, alternate_protocol.port); |
| 498 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 501 EXPECT_EQ(NPN_SPDY_3, alternate_protocol.protocol); |
| 502 EXPECT_EQ(1.0, alternate_protocol.probability); |
| 499 } | 503 } |
| 500 | 504 |
| 501 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { | 505 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { |
| 502 ExpectPrefsUpdate(); | 506 ExpectPrefsUpdate(); |
| 503 | 507 |
| 504 HostPortPair quic_server_mail("mail.google.com", 80); | 508 HostPortPair quic_server_mail("mail.google.com", 80); |
| 505 SupportsQuic supports_quic = | 509 SupportsQuic supports_quic = |
| 506 http_server_props_manager_->GetSupportsQuic(quic_server_mail); | 510 http_server_props_manager_->GetSupportsQuic(quic_server_mail); |
| 507 EXPECT_FALSE(supports_quic.used_quic); | 511 EXPECT_FALSE(supports_quic.used_quic); |
| 508 EXPECT_EQ("", supports_quic.address); | 512 EXPECT_EQ("", supports_quic.address); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 558 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 555 const uint32 value1 = 31337; | 559 const uint32 value1 = 31337; |
| 556 http_server_props_manager_->SetSpdySetting( | 560 http_server_props_manager_->SetSpdySetting( |
| 557 spdy_server_mail, id1, flags1, value1); | 561 spdy_server_mail, id1, flags1, value1); |
| 558 | 562 |
| 559 // Run the task. | 563 // Run the task. |
| 560 base::RunLoop().RunUntilIdle(); | 564 base::RunLoop().RunUntilIdle(); |
| 561 | 565 |
| 562 EXPECT_TRUE( | 566 EXPECT_TRUE( |
| 563 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 567 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); |
| 564 EXPECT_TRUE( | 568 EXPECT_TRUE(HasAlternateProtocol(spdy_server_mail)); |
| 565 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | |
| 566 SupportsQuic supports_quic = | 569 SupportsQuic supports_quic = |
| 567 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); | 570 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); |
| 568 EXPECT_TRUE(supports_quic.used_quic); | 571 EXPECT_TRUE(supports_quic.used_quic); |
| 569 EXPECT_EQ("foo", supports_quic.address); | 572 EXPECT_EQ("foo", supports_quic.address); |
| 570 const ServerNetworkStats* stats1 = | 573 const ServerNetworkStats* stats1 = |
| 571 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 574 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
| 572 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); | 575 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); |
| 573 | 576 |
| 574 // Check SPDY settings values. | 577 // Check SPDY settings values. |
| 575 const SettingsMap& settings_map1_ret = | 578 const SettingsMap& settings_map1_ret = |
| 576 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 579 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 577 ASSERT_EQ(1U, settings_map1_ret.size()); | 580 ASSERT_EQ(1U, settings_map1_ret.size()); |
| 578 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 581 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
| 579 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 582 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
| 580 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 583 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
| 581 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 584 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
| 582 EXPECT_EQ(value1, flags_and_value1_ret.second); | 585 EXPECT_EQ(value1, flags_and_value1_ret.second); |
| 583 | 586 |
| 584 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 587 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 585 | 588 |
| 586 ExpectPrefsUpdate(); | 589 ExpectPrefsUpdate(); |
| 587 | 590 |
| 588 // Clear http server data, time out if we do not get a completion callback. | 591 // Clear http server data, time out if we do not get a completion callback. |
| 589 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); | 592 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); |
| 590 base::RunLoop().Run(); | 593 base::RunLoop().Run(); |
| 591 | 594 |
| 592 EXPECT_FALSE( | 595 EXPECT_FALSE( |
| 593 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 596 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); |
| 594 EXPECT_FALSE( | 597 EXPECT_FALSE(HasAlternateProtocol(spdy_server_mail)); |
| 595 http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); | |
| 596 SupportsQuic supports_quic1 = | 598 SupportsQuic supports_quic1 = |
| 597 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); | 599 http_server_props_manager_->GetSupportsQuic(spdy_server_mail); |
| 598 EXPECT_FALSE(supports_quic1.used_quic); | 600 EXPECT_FALSE(supports_quic1.used_quic); |
| 599 EXPECT_EQ("", supports_quic1.address); | 601 EXPECT_EQ("", supports_quic1.address); |
| 600 const ServerNetworkStats* stats2 = | 602 const ServerNetworkStats* stats2 = |
| 601 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 603 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
| 602 EXPECT_EQ(NULL, stats2); | 604 EXPECT_EQ(NULL, stats2); |
| 603 | 605 |
| 604 const SettingsMap& settings_map2_ret = | 606 const SettingsMap& settings_map2_ret = |
| 605 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 607 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 // Set up the pref. | 649 // Set up the pref. |
| 648 pref_service_.SetManagedPref(kTestHttpServerProperties, | 650 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 649 http_server_properties_dict); | 651 http_server_properties_dict); |
| 650 | 652 |
| 651 base::RunLoop().RunUntilIdle(); | 653 base::RunLoop().RunUntilIdle(); |
| 652 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 654 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 653 | 655 |
| 654 // Verify AlternateProtocol. | 656 // Verify AlternateProtocol. |
| 655 for (int i = 0; i < 200; ++i) { | 657 for (int i = 0; i < 200; ++i) { |
| 656 std::string server = StringPrintf("www.google.com:%d", i); | 658 std::string server = StringPrintf("www.google.com:%d", i); |
| 657 ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol( | |
| 658 HostPortPair::FromString(server))); | |
| 659 AlternateProtocolInfo port_alternate_protocol = | 659 AlternateProtocolInfo port_alternate_protocol = |
| 660 http_server_props_manager_->GetAlternateProtocol( | 660 http_server_props_manager_->GetAlternateProtocol( |
| 661 HostPortPair::FromString(server)); | 661 HostPortPair::FromString(server)); |
| 662 EXPECT_EQ(i, port_alternate_protocol.port); | 662 EXPECT_EQ(i, port_alternate_protocol.port); |
| 663 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 663 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); |
| 664 } | 664 } |
| 665 | 665 |
| 666 // Verify SupportsQuic. | 666 // Verify SupportsQuic. |
| 667 SupportsQuic supports_quic1 = http_server_props_manager_->GetSupportsQuic( | 667 SupportsQuic supports_quic1 = http_server_props_manager_->GetSupportsQuic( |
| 668 HostPortPair::FromString("mail.google.com:80")); | 668 HostPortPair::FromString("mail.google.com:80")); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 // Run the task after shutdown, but before deletion. | 738 // Run the task after shutdown, but before deletion. |
| 739 base::RunLoop().RunUntilIdle(); | 739 base::RunLoop().RunUntilIdle(); |
| 740 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 740 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 741 http_server_props_manager_.reset(); | 741 http_server_props_manager_.reset(); |
| 742 base::RunLoop().RunUntilIdle(); | 742 base::RunLoop().RunUntilIdle(); |
| 743 } | 743 } |
| 744 | 744 |
| 745 } // namespace | 745 } // namespace |
| 746 | 746 |
| 747 } // namespace net | 747 } // namespace net |
| OLD | NEW |