| 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/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/prefs/pref_registry_simple.h" | 10 #include "base/prefs/pref_registry_simple.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 128 |
| 129 void ExpectPrefsUpdateRepeatedly() { | 129 void ExpectPrefsUpdateRepeatedly() { |
| 130 EXPECT_CALL(*http_server_props_manager_, | 130 EXPECT_CALL(*http_server_props_manager_, |
| 131 UpdatePrefsFromCacheOnNetworkThread(_)) | 131 UpdatePrefsFromCacheOnNetworkThread(_)) |
| 132 .WillRepeatedly( | 132 .WillRepeatedly( |
| 133 Invoke(http_server_props_manager_.get(), | 133 Invoke(http_server_props_manager_.get(), |
| 134 &TestingHttpServerPropertiesManager:: | 134 &TestingHttpServerPropertiesManager:: |
| 135 UpdatePrefsFromCacheOnNetworkThreadConcrete)); | 135 UpdatePrefsFromCacheOnNetworkThreadConcrete)); |
| 136 } | 136 } |
| 137 | 137 |
| 138 bool HasAlternateProtocol(const HostPortPair& server) { | 138 bool HasAlternativeService(const HostPortPair& server) { |
| 139 const AlternateProtocolInfo alternate = | 139 const AlternativeService alternative_service = |
| 140 http_server_props_manager_->GetAlternateProtocol(server); | 140 http_server_props_manager_->GetAlternativeService(server); |
| 141 return alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL; | 141 return alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL; |
| 142 } | 142 } |
| 143 | 143 |
| 144 //base::RunLoop loop_; | 144 //base::RunLoop loop_; |
| 145 TestingPrefServiceSimple pref_service_; | 145 TestingPrefServiceSimple pref_service_; |
| 146 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; | 146 scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_; |
| 147 | 147 |
| 148 private: | 148 private: |
| 149 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); | 149 DISALLOW_COPY_AND_ASSIGN(HttpServerPropertiesManagerTest); |
| 150 }; | 150 }; |
| 151 | 151 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 223 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 224 | 224 |
| 225 // Verify SupportsSpdy. | 225 // Verify SupportsSpdy. |
| 226 EXPECT_TRUE( | 226 EXPECT_TRUE( |
| 227 http_server_props_manager_->SupportsRequestPriority(google_server)); | 227 http_server_props_manager_->SupportsRequestPriority(google_server)); |
| 228 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); | 228 EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server)); |
| 229 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( | 229 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( |
| 230 HostPortPair::FromString("foo.google.com:1337"))); | 230 HostPortPair::FromString("foo.google.com:1337"))); |
| 231 | 231 |
| 232 // Verify AlternateProtocol. | 232 // Verify AlternateProtocol. |
| 233 AlternateProtocolInfo port_alternate_protocol = | 233 AlternativeService alternative_service = |
| 234 http_server_props_manager_->GetAlternateProtocol(google_server); | 234 http_server_props_manager_->GetAlternativeService(google_server); |
| 235 EXPECT_EQ(443, port_alternate_protocol.port); | 235 EXPECT_EQ(443, alternative_service.port); |
| 236 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 236 EXPECT_EQ(NPN_SPDY_3, alternative_service.protocol); |
| 237 port_alternate_protocol = | 237 alternative_service = |
| 238 http_server_props_manager_->GetAlternateProtocol(mail_server); | 238 http_server_props_manager_->GetAlternativeService(mail_server); |
| 239 EXPECT_EQ(444, port_alternate_protocol.port); | 239 EXPECT_EQ(444, alternative_service.port); |
| 240 EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocol.protocol); | 240 EXPECT_EQ(NPN_SPDY_3_1, alternative_service.protocol); |
| 241 | 241 |
| 242 // Verify SupportsQuic. | 242 // Verify SupportsQuic. |
| 243 IPAddressNumber last_address; | 243 IPAddressNumber last_address; |
| 244 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); | 244 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address)); |
| 245 EXPECT_EQ("127.0.0.1", IPAddressToString(last_address)); | 245 EXPECT_EQ("127.0.0.1", IPAddressToString(last_address)); |
| 246 | 246 |
| 247 // Verify ServerNetworkStats. | 247 // Verify ServerNetworkStats. |
| 248 const ServerNetworkStats* stats2 = | 248 const ServerNetworkStats* stats2 = |
| 249 http_server_props_manager_->GetServerNetworkStats(google_server); | 249 http_server_props_manager_->GetServerNetworkStats(google_server); |
| 250 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 250 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 pref_service_.SetManagedPref(kTestHttpServerProperties, | 289 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 290 http_server_properties_dict); | 290 http_server_properties_dict); |
| 291 | 291 |
| 292 base::RunLoop().RunUntilIdle(); | 292 base::RunLoop().RunUntilIdle(); |
| 293 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 293 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 294 | 294 |
| 295 // Verify that nothing is set. | 295 // Verify that nothing is set. |
| 296 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( | 296 EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority( |
| 297 HostPortPair::FromString("www.google.com:65536"))); | 297 HostPortPair::FromString("www.google.com:65536"))); |
| 298 EXPECT_FALSE( | 298 EXPECT_FALSE( |
| 299 HasAlternateProtocol(HostPortPair::FromString("www.google.com:65536"))); | 299 HasAlternativeService(HostPortPair::FromString("www.google.com:65536"))); |
| 300 const ServerNetworkStats* stats1 = | 300 const ServerNetworkStats* stats1 = |
| 301 http_server_props_manager_->GetServerNetworkStats( | 301 http_server_props_manager_->GetServerNetworkStats( |
| 302 HostPortPair::FromString("www.google.com:65536")); | 302 HostPortPair::FromString("www.google.com:65536")); |
| 303 EXPECT_EQ(NULL, stats1); | 303 EXPECT_EQ(NULL, stats1); |
| 304 } | 304 } |
| 305 | 305 |
| 306 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { | 306 TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { |
| 307 ExpectCacheUpdate(); | 307 ExpectCacheUpdate(); |
| 308 // The prefs are automaticalls updated in the case corruption is detected. | 308 // The prefs are automaticalls updated in the case corruption is detected. |
| 309 ExpectPrefsUpdate(); | 309 ExpectPrefsUpdate(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 331 | 331 |
| 332 // Set up the pref. | 332 // Set up the pref. |
| 333 pref_service_.SetManagedPref(kTestHttpServerProperties, | 333 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 334 http_server_properties_dict); | 334 http_server_properties_dict); |
| 335 | 335 |
| 336 base::RunLoop().RunUntilIdle(); | 336 base::RunLoop().RunUntilIdle(); |
| 337 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 337 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 338 | 338 |
| 339 // Verify AlternateProtocol is not set. | 339 // Verify AlternateProtocol is not set. |
| 340 EXPECT_FALSE( | 340 EXPECT_FALSE( |
| 341 HasAlternateProtocol(HostPortPair::FromString("www.google.com:80"))); | 341 HasAlternativeService(HostPortPair::FromString("www.google.com:80"))); |
| 342 } | 342 } |
| 343 | 343 |
| 344 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { | 344 TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { |
| 345 ExpectPrefsUpdate(); | 345 ExpectPrefsUpdate(); |
| 346 | 346 |
| 347 // Post an update task to the network thread. SetSupportsSpdy calls | 347 // Post an update task to the network thread. SetSupportsSpdy calls |
| 348 // ScheduleUpdatePrefsOnNetworkThread. | 348 // ScheduleUpdatePrefsOnNetworkThread. |
| 349 | 349 |
| 350 // Add mail.google.com:443 as a supporting spdy server. | 350 // Add mail.google.com:443 as a supporting spdy server. |
| 351 HostPortPair spdy_server_mail("mail.google.com", 443); | 351 HostPortPair spdy_server_mail("mail.google.com", 443); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 base::RunLoop().RunUntilIdle(); | 455 base::RunLoop().RunUntilIdle(); |
| 456 | 456 |
| 457 // Verify that there are no entries in the settings map. | 457 // Verify that there are no entries in the settings map. |
| 458 const SpdySettingsMap& spdy_settings_map2_ret = | 458 const SpdySettingsMap& spdy_settings_map2_ret = |
| 459 http_server_props_manager_->spdy_settings_map(); | 459 http_server_props_manager_->spdy_settings_map(); |
| 460 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); | 460 ASSERT_EQ(0U, spdy_settings_map2_ret.size()); |
| 461 | 461 |
| 462 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 462 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 463 } | 463 } |
| 464 | 464 |
| 465 TEST_F(HttpServerPropertiesManagerTest, GetAlternateProtocol) { | 465 TEST_F(HttpServerPropertiesManagerTest, GetAlternativeService) { |
| 466 ExpectPrefsUpdate(); | 466 ExpectPrefsUpdate(); |
| 467 | 467 |
| 468 HostPortPair spdy_server_mail("mail.google.com", 80); | 468 HostPortPair spdy_server_mail("mail.google.com", 80); |
| 469 EXPECT_FALSE(HasAlternateProtocol(spdy_server_mail)); | 469 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
| 470 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, | 470 http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, |
| 471 NPN_SPDY_3, 1.0); | 471 NPN_SPDY_3, 1.0); |
| 472 | 472 |
| 473 // Run the task. | 473 // Run the task. |
| 474 base::RunLoop().RunUntilIdle(); | 474 base::RunLoop().RunUntilIdle(); |
| 475 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 475 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 476 | 476 |
| 477 const AlternateProtocolInfo alternate_protocol = | 477 const AlternativeService alternate_protocol = |
| 478 http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); | 478 http_server_props_manager_->GetAlternativeService(spdy_server_mail); |
| 479 EXPECT_EQ(443, alternate_protocol.port); | 479 EXPECT_EQ(443, alternate_protocol.port); |
| 480 EXPECT_EQ(NPN_SPDY_3, alternate_protocol.protocol); | 480 EXPECT_EQ(NPN_SPDY_3, alternate_protocol.protocol); |
| 481 EXPECT_EQ(1.0, alternate_protocol.probability); | |
| 482 } | 481 } |
| 483 | 482 |
| 484 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { | 483 TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { |
| 485 ExpectPrefsUpdate(); | 484 ExpectPrefsUpdate(); |
| 486 | 485 |
| 487 IPAddressNumber address; | 486 IPAddressNumber address; |
| 488 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); | 487 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 489 | 488 |
| 490 IPAddressNumber actual_address; | 489 IPAddressNumber actual_address; |
| 491 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); | 490 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 536 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 538 const uint32 value1 = 31337; | 537 const uint32 value1 = 31337; |
| 539 http_server_props_manager_->SetSpdySetting( | 538 http_server_props_manager_->SetSpdySetting( |
| 540 spdy_server_mail, id1, flags1, value1); | 539 spdy_server_mail, id1, flags1, value1); |
| 541 | 540 |
| 542 // Run the task. | 541 // Run the task. |
| 543 base::RunLoop().RunUntilIdle(); | 542 base::RunLoop().RunUntilIdle(); |
| 544 | 543 |
| 545 EXPECT_TRUE( | 544 EXPECT_TRUE( |
| 546 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 545 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); |
| 547 EXPECT_TRUE(HasAlternateProtocol(spdy_server_mail)); | 546 EXPECT_TRUE(HasAlternativeService(spdy_server_mail)); |
| 548 IPAddressNumber address; | 547 IPAddressNumber address; |
| 549 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); | 548 EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 550 EXPECT_EQ(actual_address, address); | 549 EXPECT_EQ(actual_address, address); |
| 551 const ServerNetworkStats* stats1 = | 550 const ServerNetworkStats* stats1 = |
| 552 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 551 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
| 553 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); | 552 EXPECT_EQ(10, stats1->srtt.ToInternalValue()); |
| 554 | 553 |
| 555 // Check SPDY settings values. | 554 // Check SPDY settings values. |
| 556 const SettingsMap& settings_map1_ret = | 555 const SettingsMap& settings_map1_ret = |
| 557 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 556 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 558 ASSERT_EQ(1U, settings_map1_ret.size()); | 557 ASSERT_EQ(1U, settings_map1_ret.size()); |
| 559 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); | 558 SettingsMap::const_iterator it1_ret = settings_map1_ret.find(id1); |
| 560 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); | 559 EXPECT_TRUE(it1_ret != settings_map1_ret.end()); |
| 561 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; | 560 SettingsFlagsAndValue flags_and_value1_ret = it1_ret->second; |
| 562 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); | 561 EXPECT_EQ(SETTINGS_FLAG_PERSISTED, flags_and_value1_ret.first); |
| 563 EXPECT_EQ(value1, flags_and_value1_ret.second); | 562 EXPECT_EQ(value1, flags_and_value1_ret.second); |
| 564 | 563 |
| 565 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 564 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 566 | 565 |
| 567 ExpectPrefsUpdate(); | 566 ExpectPrefsUpdate(); |
| 568 | 567 |
| 569 // Clear http server data, time out if we do not get a completion callback. | 568 // Clear http server data, time out if we do not get a completion callback. |
| 570 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); | 569 http_server_props_manager_->Clear(base::MessageLoop::QuitClosure()); |
| 571 base::RunLoop().Run(); | 570 base::RunLoop().Run(); |
| 572 | 571 |
| 573 EXPECT_FALSE( | 572 EXPECT_FALSE( |
| 574 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); | 573 http_server_props_manager_->SupportsRequestPriority(spdy_server_mail)); |
| 575 EXPECT_FALSE(HasAlternateProtocol(spdy_server_mail)); | 574 EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); |
| 576 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); | 575 EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 577 const ServerNetworkStats* stats2 = | 576 const ServerNetworkStats* stats2 = |
| 578 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); | 577 http_server_props_manager_->GetServerNetworkStats(spdy_server_mail); |
| 579 EXPECT_EQ(NULL, stats2); | 578 EXPECT_EQ(NULL, stats2); |
| 580 | 579 |
| 581 const SettingsMap& settings_map2_ret = | 580 const SettingsMap& settings_map2_ret = |
| 582 http_server_props_manager_->GetSpdySettings(spdy_server_mail); | 581 http_server_props_manager_->GetSpdySettings(spdy_server_mail); |
| 583 EXPECT_EQ(0U, settings_map2_ret.size()); | 582 EXPECT_EQ(0U, settings_map2_ret.size()); |
| 584 | 583 |
| 585 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 584 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 // Set up the pref. | 625 // Set up the pref. |
| 627 pref_service_.SetManagedPref(kTestHttpServerProperties, | 626 pref_service_.SetManagedPref(kTestHttpServerProperties, |
| 628 http_server_properties_dict); | 627 http_server_properties_dict); |
| 629 | 628 |
| 630 base::RunLoop().RunUntilIdle(); | 629 base::RunLoop().RunUntilIdle(); |
| 631 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 630 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 632 | 631 |
| 633 // Verify AlternateProtocol. | 632 // Verify AlternateProtocol. |
| 634 for (int i = 0; i < 200; ++i) { | 633 for (int i = 0; i < 200; ++i) { |
| 635 std::string server = StringPrintf("www.google.com:%d", i); | 634 std::string server = StringPrintf("www.google.com:%d", i); |
| 636 AlternateProtocolInfo port_alternate_protocol = | 635 AlternativeService alternative_service = |
| 637 http_server_props_manager_->GetAlternateProtocol( | 636 http_server_props_manager_->GetAlternativeService( |
| 638 HostPortPair::FromString(server)); | 637 HostPortPair::FromString(server)); |
| 639 EXPECT_EQ(i, port_alternate_protocol.port); | 638 EXPECT_EQ(i, alternative_service.port); |
| 640 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); | 639 EXPECT_EQ(NPN_SPDY_3, alternative_service.protocol); |
| 641 } | 640 } |
| 642 | 641 |
| 643 // Verify SupportsQuic. | 642 // Verify SupportsQuic. |
| 644 IPAddressNumber address; | 643 IPAddressNumber address; |
| 645 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); | 644 ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address)); |
| 646 EXPECT_EQ("127.0.0.1", IPAddressToString(address)); | 645 EXPECT_EQ("127.0.0.1", IPAddressToString(address)); |
| 647 } | 646 } |
| 648 | 647 |
| 649 TEST_F(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { | 648 TEST_F(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { |
| 650 const HostPortPair server_www("www.google.com", 80); | 649 const HostPortPair server_www("www.google.com", 80); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 772 // Run the task after shutdown, but before deletion. | 771 // Run the task after shutdown, but before deletion. |
| 773 base::RunLoop().RunUntilIdle(); | 772 base::RunLoop().RunUntilIdle(); |
| 774 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 773 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 775 http_server_props_manager_.reset(); | 774 http_server_props_manager_.reset(); |
| 776 base::RunLoop().RunUntilIdle(); | 775 base::RunLoop().RunUntilIdle(); |
| 777 } | 776 } |
| 778 | 777 |
| 779 } // namespace | 778 } // namespace |
| 780 | 779 |
| 781 } // namespace net | 780 } // namespace net |
| OLD | NEW |