diff options
author | bnc <bnc@chromium.org> | 2015-02-05 08:19:39 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-05 16:21:03 +0000 |
commit | 4d5b877dcab754769ee594a043c75e9bcf27d776 (patch) | |
tree | e7fb661deee2c86b7d1f0b6aeaadb72277386ae9 /net/http/http_server_properties_manager_unittest.cc | |
parent | 8a522834e604f3683f3d9741181dfeb1a03d4998 (diff) | |
download | chromium_src-4d5b877dcab754769ee594a043c75e9bcf27d776.zip chromium_src-4d5b877dcab754769ee594a043c75e9bcf27d776.tar.gz chromium_src-4d5b877dcab754769ee594a043c75e9bcf27d776.tar.bz2 |
Add HttpServerPropertiesManagerTest.UpdateCacheWithPrefs.
Add HttpServerPropertiesManagerTest.UpdateCacheWithPrefs to test that
preferences like AlternateProtocol, SupportsQuic, and ServerNetworkStats are
saved to PrefService properly.
BUG=392575
Review URL: https://codereview.chromium.org/893403005
Cr-Commit-Position: refs/heads/master@{#314822}
Diffstat (limited to 'net/http/http_server_properties_manager_unittest.cc')
-rw-r--r-- | net/http/http_server_properties_manager_unittest.cc | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/net/http/http_server_properties_manager_unittest.cc b/net/http/http_server_properties_manager_unittest.cc index 6443d4b..f2e3649 100644 --- a/net/http/http_server_properties_manager_unittest.cc +++ b/net/http/http_server_properties_manager_unittest.cc @@ -5,6 +5,7 @@ #include "net/http/http_server_properties_manager.h" #include "base/basictypes.h" +#include "base/json/json_writer.h" #include "base/message_loop/message_loop.h" #include "base/prefs/pref_registry_simple.h" #include "base/prefs/testing_pref_service.h" @@ -645,6 +646,64 @@ TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { EXPECT_EQ("127.0.0.1", IPAddressToString(address)); } +TEST_F(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) { + const HostPortPair server_www("www.google.com", 80); + const HostPortPair server_mail("mail.google.com", 80); + + // Set alternate protocol. + http_server_props_manager_->SetAlternateProtocol(server_www, 443, NPN_SPDY_3, + 1.0); + http_server_props_manager_->SetAlternateProtocol(server_mail, 444, + NPN_SPDY_3_1, 0.2); + + // Set ServerNetworkStats. + ServerNetworkStats stats; + stats.srtt = base::TimeDelta::FromInternalValue(42); + http_server_props_manager_->SetServerNetworkStats(server_mail, stats); + + // Set SupportsQuic. + IPAddressNumber actual_address; + CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address)); + http_server_props_manager_->SetSupportsQuic(true, actual_address); + + // Update cache. + ExpectPrefsUpdate(); + ExpectCacheUpdate(); + http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); + base::RunLoop().RunUntilIdle(); + + // Verify preferences. + const char expected_json[] = "{" + "\"servers\":{" + "\"mail.google.com:80\":{" + "\"alternate_protocol\":{" + "\"port\":444,\"probability\":0.2,\"protocol_str\":\"npn-spdy/3.1\"" + "}," + "\"network_stats\":{" + "\"srtt\":42" + "}" + "}," + "\"www.google.com:80\":{" + "\"alternate_protocol\":{" + "\"port\":443,\"probability\":1.0,\"protocol_str\":\"npn-spdy/3\"" + "}" + "}" + "}," + "\"supports_quic\":{" + "\"address\":\"127.0.0.1\",\"used_quic\":true" + "}," + "\"version\":3" + "}"; + + const base::Value* http_server_properties = + pref_service_.GetUserPref(kTestHttpServerProperties); + ASSERT_NE(nullptr, http_server_properties); + std::string preferences_json; + EXPECT_TRUE( + base::JSONWriter::Write(http_server_properties, &preferences_json)); + EXPECT_EQ(expected_json, preferences_json); +} + TEST_F(HttpServerPropertiesManagerTest, ShutdownWithPendingUpdateCache0) { // Post an update task to the UI thread. http_server_props_manager_->ScheduleUpdateCacheOnPrefThread(); |