diff options
author | mmenke <mmenke@chromium.org> | 2014-11-18 11:53:07 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-18 19:53:26 +0000 |
commit | 0b59561e232b2a638425439c52e36f2d461380b9 (patch) | |
tree | 97da659278d91867982f21eb9c6e5614d583d6f8 /net/http/http_server_properties_manager_unittest.cc | |
parent | cbc4581a0193e89222085cf5afd88563f130a561 (diff) | |
download | chromium_src-0b59561e232b2a638425439c52e36f2d461380b9.zip chromium_src-0b59561e232b2a638425439c52e36f2d461380b9.tar.gz chromium_src-0b59561e232b2a638425439c52e36f2d461380b9.tar.bz2 |
Make HttpServerPropertiesManager's port checking more robust.
If we're going to handle corruption, bad port checking should be
correct.
BUG=433895
Review URL: https://codereview.chromium.org/739633003
Cr-Commit-Position: refs/heads/master@{#304655}
Diffstat (limited to 'net/http/http_server_properties_manager_unittest.cc')
-rw-r--r-- | net/http/http_server_properties_manager_unittest.cc | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/net/http/http_server_properties_manager_unittest.cc b/net/http/http_server_properties_manager_unittest.cc index db58c92..bb8b68c 100644 --- a/net/http/http_server_properties_manager_unittest.cc +++ b/net/http/http_server_properties_manager_unittest.cc @@ -241,6 +241,95 @@ TEST_F(HttpServerPropertiesManagerTest, EXPECT_EQ("bar", supports_quic2.address); } +TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { + ExpectCacheUpdate(); + // The prefs are automaticalls updated in the case corruption is detected. + ExpectPrefsUpdate(); + + base::DictionaryValue* server_pref_dict = new base::DictionaryValue; + + // Set supports_spdy for www.google.com:65536. + server_pref_dict->SetBoolean("supports_spdy", true); + + // Set up alternate_protocol for www.google.com:65536. + base::DictionaryValue* alternate_protocol = new base::DictionaryValue; + alternate_protocol->SetInteger("port", 80); + alternate_protocol->SetString("protocol_str", "npn-spdy/3"); + server_pref_dict->SetWithoutPathExpansion("alternate_protocol", + alternate_protocol); + + // Set up SupportsQuic for www.google.com:65536. + base::DictionaryValue* supports_quic = new base::DictionaryValue; + supports_quic->SetBoolean("used_quic", true); + supports_quic->SetString("address", "foo"); + server_pref_dict->SetWithoutPathExpansion("supports_quic", supports_quic); + + // Set the server preference for www.google.com:65536. + base::DictionaryValue* servers_dict = new base::DictionaryValue; + servers_dict->SetWithoutPathExpansion("www.google.com:65536", + server_pref_dict); + + base::DictionaryValue* http_server_properties_dict = + new base::DictionaryValue; + HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); + http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); + + // Set up the pref. + pref_service_.SetManagedPref(kTestHttpServerProperties, + http_server_properties_dict); + + base::RunLoop().RunUntilIdle(); + Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); + + // Verify that nothing is set. + EXPECT_FALSE(http_server_props_manager_->SupportsSpdy( + net::HostPortPair::FromString("www.google.com:65536"))); + EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( + net::HostPortPair::FromString("www.google.com:65536"))); + net::SupportsQuic supports_quic2 = + http_server_props_manager_->GetSupportsQuic( + net::HostPortPair::FromString("www.google.com:65536")); + EXPECT_FALSE(supports_quic2.used_quic); +} + +TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { + ExpectCacheUpdate(); + // The prefs are automaticalls updated in the case corruption is detected. + ExpectPrefsUpdate(); + + base::DictionaryValue* server_pref_dict = new base::DictionaryValue; + + // Set supports_spdy for www.google.com:80. + server_pref_dict->SetBoolean("supports_spdy", true); + + // Set up alternate_protocol for www.google.com:80. + base::DictionaryValue* alternate_protocol = new base::DictionaryValue; + alternate_protocol->SetInteger("port", 65536); + alternate_protocol->SetString("protocol_str", "npn-spdy/3"); + server_pref_dict->SetWithoutPathExpansion("alternate_protocol", + alternate_protocol); + + // Set the server preference for www.google.com:80. + base::DictionaryValue* servers_dict = new base::DictionaryValue; + servers_dict->SetWithoutPathExpansion("www.google.com:80", server_pref_dict); + + base::DictionaryValue* http_server_properties_dict = + new base::DictionaryValue; + HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1); + http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict); + + // Set up the pref. + pref_service_.SetManagedPref(kTestHttpServerProperties, + http_server_properties_dict); + + base::RunLoop().RunUntilIdle(); + Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); + + // Verify AlternateProtocol is not set. + EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol( + net::HostPortPair::FromString("www.google.com:80"))); +} + TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) { ExpectPrefsUpdate(); |