| 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 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 | 518 |
| 519 TEST_F(HttpServerPropertiesManagerTest, ServerNetworkStats) { | 519 TEST_F(HttpServerPropertiesManagerTest, ServerNetworkStats) { |
| 520 ExpectPrefsUpdate(); | 520 ExpectPrefsUpdate(); |
| 521 | 521 |
| 522 HostPortPair mail_server("mail.google.com", 80); | 522 HostPortPair mail_server("mail.google.com", 80); |
| 523 const ServerNetworkStats* stats = | 523 const ServerNetworkStats* stats = |
| 524 http_server_props_manager_->GetServerNetworkStats(mail_server); | 524 http_server_props_manager_->GetServerNetworkStats(mail_server); |
| 525 EXPECT_EQ(NULL, stats); | 525 EXPECT_EQ(NULL, stats); |
| 526 ServerNetworkStats stats1; | 526 ServerNetworkStats stats1; |
| 527 stats1.srtt = base::TimeDelta::FromMicroseconds(10); | 527 stats1.srtt = base::TimeDelta::FromMicroseconds(10); |
| 528 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1); | 528 EXPECT_TRUE( |
| 529 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1)); |
| 530 // ExpectPrefsUpdate() should be called only once. |
| 531 EXPECT_FALSE( |
| 532 http_server_props_manager_->SetServerNetworkStats(mail_server, stats1)); |
| 529 | 533 |
| 530 // Run the task. | 534 // Run the task. |
| 531 base::RunLoop().RunUntilIdle(); | 535 base::RunLoop().RunUntilIdle(); |
| 532 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 536 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 533 | 537 |
| 534 const ServerNetworkStats* stats2 = | 538 const ServerNetworkStats* stats2 = |
| 535 http_server_props_manager_->GetServerNetworkStats(mail_server); | 539 http_server_props_manager_->GetServerNetworkStats(mail_server); |
| 536 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); | 540 EXPECT_EQ(10, stats2->srtt.ToInternalValue()); |
| 537 } | 541 } |
| 538 | 542 |
| 539 TEST_F(HttpServerPropertiesManagerTest, Clear) { | 543 TEST_F(HttpServerPropertiesManagerTest, Clear) { |
| 540 ExpectPrefsUpdate(); | 544 ExpectPrefsUpdate(); |
| 541 | 545 |
| 542 HostPortPair spdy_server_mail("mail.google.com", 443); | 546 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 543 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); | 547 http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
| 544 AlternativeService alternative_service(NPN_SPDY_4, "mail.google.com", 443); | 548 AlternativeService alternative_service(NPN_SPDY_4, "mail.google.com", 443); |
| 545 EXPECT_TRUE(http_server_props_manager_->SetAlternativeService( | 549 EXPECT_TRUE(http_server_props_manager_->SetAlternativeService( |
| 546 spdy_server_mail, alternative_service, 1.0)); | 550 spdy_server_mail, alternative_service, 1.0)); |
| 547 // ExpectPrefsUpdate() should be called only once. | 551 // ExpectPrefsUpdate() should be called only once. |
| 548 EXPECT_FALSE(http_server_props_manager_->SetAlternativeService( | 552 EXPECT_FALSE(http_server_props_manager_->SetAlternativeService( |
| 549 spdy_server_mail, alternative_service, 1.0)); | 553 spdy_server_mail, alternative_service, 1.0)); |
| 550 IPAddressNumber actual_address; | 554 IPAddressNumber actual_address; |
| 551 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); | 555 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); |
| 552 http_server_props_manager_->SetSupportsQuic(true, actual_address); | 556 http_server_props_manager_->SetSupportsQuic(true, actual_address); |
| 553 ServerNetworkStats stats; | 557 ServerNetworkStats stats; |
| 554 stats.srtt = base::TimeDelta::FromMicroseconds(10); | 558 stats.srtt = base::TimeDelta::FromMicroseconds(10); |
| 555 http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats); | 559 EXPECT_TRUE(http_server_props_manager_->SetServerNetworkStats( |
| 560 spdy_server_mail, stats)); |
| 561 EXPECT_FALSE(http_server_props_manager_->SetServerNetworkStats( |
| 562 spdy_server_mail, stats)); |
| 556 | 563 |
| 557 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; | 564 const SpdySettingsIds id1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 558 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; | 565 const SpdySettingsFlags flags1 = SETTINGS_FLAG_PLEASE_PERSIST; |
| 559 const uint32 value1 = 31337; | 566 const uint32 value1 = 31337; |
| 560 http_server_props_manager_->SetSpdySetting( | 567 http_server_props_manager_->SetSpdySetting( |
| 561 spdy_server_mail, id1, flags1, value1); | 568 spdy_server_mail, id1, flags1, value1); |
| 562 | 569 |
| 563 // Run the task. | 570 // Run the task. |
| 564 base::RunLoop().RunUntilIdle(); | 571 base::RunLoop().RunUntilIdle(); |
| 565 | 572 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 EXPECT_FALSE(http_server_props_manager_->SetAlternativeService( | 689 EXPECT_FALSE(http_server_props_manager_->SetAlternativeService( |
| 683 server_www, www_altsvc, 1.0)); | 690 server_www, www_altsvc, 1.0)); |
| 684 EXPECT_TRUE(http_server_props_manager_->SetAlternativeService( | 691 EXPECT_TRUE(http_server_props_manager_->SetAlternativeService( |
| 685 server_mail, mail_altsvc, 0.2)); | 692 server_mail, mail_altsvc, 0.2)); |
| 686 EXPECT_FALSE(http_server_props_manager_->SetAlternativeService( | 693 EXPECT_FALSE(http_server_props_manager_->SetAlternativeService( |
| 687 server_mail, mail_altsvc, 0.2)); | 694 server_mail, mail_altsvc, 0.2)); |
| 688 | 695 |
| 689 // Set ServerNetworkStats. | 696 // Set ServerNetworkStats. |
| 690 ServerNetworkStats stats; | 697 ServerNetworkStats stats; |
| 691 stats.srtt = base::TimeDelta::FromInternalValue(42); | 698 stats.srtt = base::TimeDelta::FromInternalValue(42); |
| 692 http_server_props_manager_->SetServerNetworkStats(server_mail, stats); | 699 EXPECT_TRUE( |
| 700 http_server_props_manager_->SetServerNetworkStats(server_mail, stats)); |
| 693 | 701 |
| 694 // Set SupportsQuic. | 702 // Set SupportsQuic. |
| 695 IPAddressNumber actual_address; | 703 IPAddressNumber actual_address; |
| 696 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); | 704 CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); |
| 697 http_server_props_manager_->SetSupportsQuic(true, actual_address); | 705 http_server_props_manager_->SetSupportsQuic(true, actual_address); |
| 698 | 706 |
| 699 // Update cache. | 707 // Update cache. |
| 700 ExpectPrefsUpdate(); | 708 ExpectPrefsUpdate(); |
| 701 ExpectCacheUpdate(); | 709 ExpectCacheUpdate(); |
| 702 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); | 710 http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 // Run the task after shutdown, but before deletion. | 798 // Run the task after shutdown, but before deletion. |
| 791 base::RunLoop().RunUntilIdle(); | 799 base::RunLoop().RunUntilIdle(); |
| 792 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); | 800 Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
| 793 http_server_props_manager_.reset(); | 801 http_server_props_manager_.reset(); |
| 794 base::RunLoop().RunUntilIdle(); | 802 base::RunLoop().RunUntilIdle(); |
| 795 } | 803 } |
| 796 | 804 |
| 797 } // namespace | 805 } // namespace |
| 798 | 806 |
| 799 } // namespace net | 807 } // namespace net |
| OLD | NEW |