diff options
author | rtenneti <rtenneti@chromium.org> | 2015-06-03 18:01:08 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-04 01:01:44 +0000 |
commit | 56dea0b92d05e42340e4e4e2c991819ee2634adf (patch) | |
tree | 551a0ce89a3737d5533e7a7762e60ceb9d32382d /net/http/http_server_properties_manager_unittest.cc | |
parent | 3d7990c2db2181834232559d778566f51a5b35fa (diff) | |
download | chromium_src-56dea0b92d05e42340e4e4e2c991819ee2634adf.zip chromium_src-56dea0b92d05e42340e4e4e2c991819ee2634adf.tar.gz chromium_src-56dea0b92d05e42340e4e4e2c991819ee2634adf.tar.bz2 |
HttpServerProperties - Don't persist if SetAlternativeService is called
with the same origin (HostPortPair) and value (AlternativeServiceInfo).
This change reduces the number of times SetAlternativeService tries
to persist HttpServerProperties to disk (currently 40% of persist calls
are due to SetAlternativeService).
BUG=451256
R=rch@chromium.org
Review URL: https://codereview.chromium.org/1156053004
Cr-Commit-Position: refs/heads/master@{#332755}
Diffstat (limited to 'net/http/http_server_properties_manager_unittest.cc')
-rw-r--r-- | net/http/http_server_properties_manager_unittest.cc | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/net/http/http_server_properties_manager_unittest.cc b/net/http/http_server_properties_manager_unittest.cc index 7125b9f..be17d9a 100644 --- a/net/http/http_server_properties_manager_unittest.cc +++ b/net/http/http_server_properties_manager_unittest.cc @@ -45,7 +45,6 @@ class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager { // Make these methods public for testing. using HttpServerPropertiesManager::ScheduleUpdateCacheOnPrefThread; - using HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkThread; // Post tasks without a delay during tests. void StartPrefsUpdateTimerOnNetworkThread(base::TimeDelta delay) override { @@ -68,6 +67,10 @@ class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager { HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(callback); } + void ScheduleUpdatePrefsOnNetworkThreadConcrete(Location location) { + HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkThread(location); + } + void ScheduleUpdatePrefsOnNetworkThread() { // Picked a random Location as caller. HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkThread( @@ -76,6 +79,7 @@ class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager { MOCK_METHOD0(UpdateCacheFromPrefsOnPrefThread, void()); MOCK_METHOD1(UpdatePrefsFromCacheOnNetworkThread, void(const base::Closure&)); + MOCK_METHOD1(ScheduleUpdatePrefsOnNetworkThread, void(Location location)); MOCK_METHOD6(UpdateCacheFromPrefsOnNetworkThread, void(std::vector<std::string>* spdy_servers, SpdySettingsMap* spdy_settings_map, @@ -123,6 +127,22 @@ class HttpServerPropertiesManagerTest : public testing::Test { UpdateCacheFromPrefsOnUIConcrete)); } + void ExpectScheduleUpdatePrefsOnNetworkThread() { + EXPECT_CALL(*http_server_props_manager_, + ScheduleUpdatePrefsOnNetworkThread(_)) + .WillOnce(Invoke(http_server_props_manager_.get(), + &TestingHttpServerPropertiesManager:: + ScheduleUpdatePrefsOnNetworkThreadConcrete)); + } + + void ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly() { + EXPECT_CALL(*http_server_props_manager_, + ScheduleUpdatePrefsOnNetworkThread(_)) + .WillRepeatedly(Invoke(http_server_props_manager_.get(), + &TestingHttpServerPropertiesManager:: + ScheduleUpdatePrefsOnNetworkThreadConcrete)); + } + void ExpectPrefsUpdate() { EXPECT_CALL(*http_server_props_manager_, UpdatePrefsFromCacheOnNetworkThread(_)) @@ -267,6 +287,7 @@ TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { ExpectCacheUpdate(); // The prefs are automaticalls updated in the case corruption is detected. ExpectPrefsUpdate(); + ExpectScheduleUpdatePrefsOnNetworkThread(); base::DictionaryValue* server_pref_dict = new base::DictionaryValue; @@ -320,6 +341,7 @@ TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { ExpectCacheUpdate(); // The prefs are automaticalls updated in the case corruption is detected. ExpectPrefsUpdate(); + ExpectScheduleUpdatePrefsOnNetworkThread(); base::DictionaryValue* server_pref_dict = new base::DictionaryValue; @@ -358,6 +380,7 @@ TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { ExpectPrefsUpdate(); + ExpectScheduleUpdatePrefsOnNetworkThread(); // Post an update task to the network thread. SetSupportsSpdy calls // ScheduleUpdatePrefsOnNetworkThread. @@ -378,6 +401,7 @@ TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { TEST_F(HttpServerPropertiesManagerTest, SetSpdySetting) { ExpectPrefsUpdate(); + ExpectScheduleUpdatePrefsOnNetworkThread(); // Add SpdySetting for mail.google.com:443. HostPortPair spdy_server_mail("mail.google.com", 443); @@ -404,6 +428,7 @@ TEST_F(HttpServerPropertiesManagerTest, SetSpdySetting) { TEST_F(HttpServerPropertiesManagerTest, ClearSpdySetting) { ExpectPrefsUpdateRepeatedly(); + ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); // Add SpdySetting for mail.google.com:443. HostPortPair spdy_server_mail("mail.google.com", 443); @@ -442,6 +467,7 @@ TEST_F(HttpServerPropertiesManagerTest, ClearSpdySetting) { TEST_F(HttpServerPropertiesManagerTest, ClearAllSpdySetting) { ExpectPrefsUpdateRepeatedly(); + ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); // Add SpdySetting for mail.google.com:443. HostPortPair spdy_server_mail("mail.google.com", 443); @@ -479,12 +505,16 @@ TEST_F(HttpServerPropertiesManagerTest, ClearAllSpdySetting) { TEST_F(HttpServerPropertiesManagerTest, GetAlternativeService) { ExpectPrefsUpdate(); + ExpectScheduleUpdatePrefsOnNetworkThread(); HostPortPair spdy_server_mail("mail.google.com", 80); EXPECT_FALSE(HasAlternativeService(spdy_server_mail)); AlternativeService alternative_service(NPN_SPDY_4, "mail.google.com", 443); http_server_props_manager_->SetAlternativeService(spdy_server_mail, alternative_service, 1.0); + // ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once. + http_server_props_manager_->SetAlternativeService(spdy_server_mail, + alternative_service, 1.0); // Run the task. base::RunLoop().RunUntilIdle(); @@ -498,6 +528,7 @@ TEST_F(HttpServerPropertiesManagerTest, GetAlternativeService) { TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { ExpectPrefsUpdate(); + ExpectScheduleUpdatePrefsOnNetworkThread(); IPAddressNumber address; EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address)); @@ -516,6 +547,7 @@ TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) { TEST_F(HttpServerPropertiesManagerTest, ServerNetworkStats) { ExpectPrefsUpdate(); + ExpectScheduleUpdatePrefsOnNetworkThread(); HostPortPair mail_server("mail.google.com", 80); const ServerNetworkStats* stats = @@ -536,6 +568,7 @@ TEST_F(HttpServerPropertiesManagerTest, ServerNetworkStats) { TEST_F(HttpServerPropertiesManagerTest, Clear) { ExpectPrefsUpdate(); + ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); HostPortPair spdy_server_mail("mail.google.com", 443); http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); @@ -666,6 +699,8 @@ TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { } TEST_F(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { + ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly(); + const HostPortPair server_www("www.google.com", 80); const HostPortPair server_mail("mail.google.com", 80); |