| Index: net/http/http_server_properties_manager_unittest.cc
|
| diff --git a/net/http/http_server_properties_manager_unittest.cc b/net/http/http_server_properties_manager_unittest.cc
|
| index d021fc502190e249ae579edfc5e0a60c9105089a..f2e36499e736850c19b757f9e8146e5d6adbf96c 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"
|
| @@ -74,14 +75,14 @@ class TestingHttpServerPropertiesManager : public HttpServerPropertiesManager {
|
| void(std::vector<std::string>* spdy_servers,
|
| SpdySettingsMap* spdy_settings_map,
|
| AlternateProtocolMap* alternate_protocol_map,
|
| - SupportsQuicMap* supports_quic_map,
|
| + IPAddressNumber* last_quic_address,
|
| ServerNetworkStatsMap* server_network_stats_map,
|
| bool detected_corrupted_prefs));
|
| MOCK_METHOD5(UpdatePrefsOnPref,
|
| void(base::ListValue* spdy_server_list,
|
| SpdySettingsMap* spdy_settings_map,
|
| AlternateProtocolMap* alternate_protocol_map,
|
| - SupportsQuicMap* supports_quic_map,
|
| + IPAddressNumber* last_quic_address,
|
| ServerNetworkStatsMap* server_network_stats_map));
|
|
|
| private:
|
| @@ -134,6 +135,12 @@ class HttpServerPropertiesManagerTest : public testing::Test {
|
| UpdatePrefsFromCacheOnNetworkThreadConcrete));
|
| }
|
|
|
| + bool HasAlternateProtocol(const HostPortPair& server) {
|
| + const AlternateProtocolInfo alternate =
|
| + http_server_props_manager_->GetAlternateProtocol(server);
|
| + return alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL;
|
| + }
|
| +
|
| //base::RunLoop loop_;
|
| TestingPrefServiceSimple pref_service_;
|
| scoped_ptr<TestingHttpServerPropertiesManager> http_server_props_manager_;
|
| @@ -163,12 +170,6 @@ TEST_F(HttpServerPropertiesManagerTest,
|
| server_pref_dict->SetWithoutPathExpansion("alternate_protocol",
|
| alternate_protocol);
|
|
|
| - // Set up SupportsQuic for www.google.com:80.
|
| - 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 up ServerNetworkStats for www.google.com:80.
|
| base::DictionaryValue* stats = new base::DictionaryValue;
|
| stats->SetInteger("srtt", 10);
|
| @@ -192,12 +193,6 @@ TEST_F(HttpServerPropertiesManagerTest,
|
| server_pref_dict1->SetWithoutPathExpansion("alternate_protocol",
|
| alternate_protocol1);
|
|
|
| - // Set up SupportsQuic for mail.google.com:80
|
| - base::DictionaryValue* supports_quic1 = new base::DictionaryValue;
|
| - supports_quic1->SetBoolean("used_quic", false);
|
| - supports_quic1->SetString("address", "bar");
|
| - server_pref_dict1->SetWithoutPathExpansion("supports_quic", supports_quic1);
|
| -
|
| // Set up ServerNetworkStats for mail.google.com:80.
|
| base::DictionaryValue* stats1 = new base::DictionaryValue;
|
| stats1->SetInteger("srtt", 20);
|
| @@ -210,6 +205,11 @@ TEST_F(HttpServerPropertiesManagerTest,
|
| new base::DictionaryValue;
|
| HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1);
|
| http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict);
|
| + base::DictionaryValue* supports_quic = new base::DictionaryValue;
|
| + supports_quic->SetBoolean("used_quic", true);
|
| + supports_quic->SetString("address", "127.0.0.1");
|
| + http_server_properties_dict->SetWithoutPathExpansion("supports_quic",
|
| + supports_quic);
|
|
|
| // Set the same value for kHttpServerProperties multiple times.
|
| pref_service_.SetManagedPref(kTestHttpServerProperties,
|
| @@ -230,8 +230,6 @@ TEST_F(HttpServerPropertiesManagerTest,
|
| HostPortPair::FromString("foo.google.com:1337")));
|
|
|
| // Verify AlternateProtocol.
|
| - ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(google_server));
|
| - ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(mail_server));
|
| AlternateProtocolInfo port_alternate_protocol =
|
| http_server_props_manager_->GetAlternateProtocol(google_server);
|
| EXPECT_EQ(443, port_alternate_protocol.port);
|
| @@ -242,13 +240,9 @@ TEST_F(HttpServerPropertiesManagerTest,
|
| EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocol.protocol);
|
|
|
| // Verify SupportsQuic.
|
| - SupportsQuic supports_quic2 =
|
| - http_server_props_manager_->GetSupportsQuic(google_server);
|
| - EXPECT_TRUE(supports_quic2.used_quic);
|
| - EXPECT_EQ("foo", supports_quic2.address);
|
| - supports_quic2 = http_server_props_manager_->GetSupportsQuic(mail_server);
|
| - EXPECT_FALSE(supports_quic2.used_quic);
|
| - EXPECT_EQ("bar", supports_quic2.address);
|
| + IPAddressNumber last_address;
|
| + EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&last_address));
|
| + EXPECT_EQ("127.0.0.1", IPAddressToString(last_address));
|
|
|
| // Verify ServerNetworkStats.
|
| const ServerNetworkStats* stats2 =
|
| @@ -276,12 +270,6 @@ TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) {
|
| 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 up ServerNetworkStats for www.google.com:65536.
|
| base::DictionaryValue* stats = new base::DictionaryValue;
|
| stats->SetInteger("srtt", 10);
|
| @@ -307,11 +295,8 @@ TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) {
|
| // Verify that nothing is set.
|
| EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(
|
| HostPortPair::FromString("www.google.com:65536")));
|
| - EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol(
|
| - HostPortPair::FromString("www.google.com:65536")));
|
| - SupportsQuic supports_quic2 = http_server_props_manager_->GetSupportsQuic(
|
| - HostPortPair::FromString("www.google.com:65536"));
|
| - EXPECT_FALSE(supports_quic2.used_quic);
|
| + EXPECT_FALSE(
|
| + HasAlternateProtocol(HostPortPair::FromString("www.google.com:65536")));
|
| const ServerNetworkStats* stats1 =
|
| http_server_props_manager_->GetServerNetworkStats(
|
| HostPortPair::FromString("www.google.com:65536"));
|
| @@ -352,8 +337,8 @@ TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) {
|
| Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
|
|
|
| // Verify AlternateProtocol is not set.
|
| - EXPECT_FALSE(http_server_props_manager_->HasAlternateProtocol(
|
| - HostPortPair::FromString("www.google.com:80")));
|
| + EXPECT_FALSE(
|
| + HasAlternateProtocol(HostPortPair::FromString("www.google.com:80")));
|
| }
|
|
|
| TEST_F(HttpServerPropertiesManagerTest, SupportsSpdy) {
|
| @@ -477,12 +462,11 @@ TEST_F(HttpServerPropertiesManagerTest, ClearAllSpdySetting) {
|
| Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
|
| }
|
|
|
| -TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) {
|
| +TEST_F(HttpServerPropertiesManagerTest, GetAlternateProtocol) {
|
| ExpectPrefsUpdate();
|
|
|
| HostPortPair spdy_server_mail("mail.google.com", 80);
|
| - EXPECT_FALSE(
|
| - http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
|
| + EXPECT_FALSE(HasAlternateProtocol(spdy_server_mail));
|
| http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443,
|
| NPN_SPDY_3, 1.0);
|
|
|
| @@ -490,32 +474,29 @@ TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) {
|
| base::RunLoop().RunUntilIdle();
|
| Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
|
|
|
| - ASSERT_TRUE(
|
| - http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
|
| - AlternateProtocolInfo port_alternate_protocol =
|
| + const AlternateProtocolInfo alternate_protocol =
|
| http_server_props_manager_->GetAlternateProtocol(spdy_server_mail);
|
| - EXPECT_EQ(443, port_alternate_protocol.port);
|
| - EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol);
|
| + EXPECT_EQ(443, alternate_protocol.port);
|
| + EXPECT_EQ(NPN_SPDY_3, alternate_protocol.protocol);
|
| + EXPECT_EQ(1.0, alternate_protocol.probability);
|
| }
|
|
|
| TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) {
|
| ExpectPrefsUpdate();
|
|
|
| - HostPortPair quic_server_mail("mail.google.com", 80);
|
| - SupportsQuic supports_quic =
|
| - http_server_props_manager_->GetSupportsQuic(quic_server_mail);
|
| - EXPECT_FALSE(supports_quic.used_quic);
|
| - EXPECT_EQ("", supports_quic.address);
|
| - http_server_props_manager_->SetSupportsQuic(quic_server_mail, true, "foo");
|
| + IPAddressNumber address;
|
| + EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address));
|
| +
|
| + IPAddressNumber actual_address;
|
| + CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address));
|
| + http_server_props_manager_->SetSupportsQuic(true, actual_address);
|
|
|
| // Run the task.
|
| base::RunLoop().RunUntilIdle();
|
| Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
|
|
|
| - SupportsQuic supports_quic1 =
|
| - http_server_props_manager_->GetSupportsQuic(quic_server_mail);
|
| - EXPECT_TRUE(supports_quic1.used_quic);
|
| - EXPECT_EQ("foo", supports_quic1.address);
|
| + EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
|
| + EXPECT_EQ(actual_address, address);
|
| }
|
|
|
| TEST_F(HttpServerPropertiesManagerTest, ServerNetworkStats) {
|
| @@ -545,7 +526,9 @@ TEST_F(HttpServerPropertiesManagerTest, Clear) {
|
| http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true);
|
| http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443,
|
| NPN_SPDY_3, 1.0);
|
| - http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo");
|
| + IPAddressNumber actual_address;
|
| + CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address));
|
| + http_server_props_manager_->SetSupportsQuic(true, actual_address);
|
| ServerNetworkStats stats;
|
| stats.srtt = base::TimeDelta::FromMicroseconds(10);
|
| http_server_props_manager_->SetServerNetworkStats(spdy_server_mail, stats);
|
| @@ -561,12 +544,10 @@ TEST_F(HttpServerPropertiesManagerTest, Clear) {
|
|
|
| EXPECT_TRUE(
|
| http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
|
| - EXPECT_TRUE(
|
| - http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
|
| - SupportsQuic supports_quic =
|
| - http_server_props_manager_->GetSupportsQuic(spdy_server_mail);
|
| - EXPECT_TRUE(supports_quic.used_quic);
|
| - EXPECT_EQ("foo", supports_quic.address);
|
| + EXPECT_TRUE(HasAlternateProtocol(spdy_server_mail));
|
| + IPAddressNumber address;
|
| + EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
|
| + EXPECT_EQ(actual_address, address);
|
| const ServerNetworkStats* stats1 =
|
| http_server_props_manager_->GetServerNetworkStats(spdy_server_mail);
|
| EXPECT_EQ(10, stats1->srtt.ToInternalValue());
|
| @@ -591,12 +572,8 @@ TEST_F(HttpServerPropertiesManagerTest, Clear) {
|
|
|
| EXPECT_FALSE(
|
| http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
|
| - EXPECT_FALSE(
|
| - http_server_props_manager_->HasAlternateProtocol(spdy_server_mail));
|
| - SupportsQuic supports_quic1 =
|
| - http_server_props_manager_->GetSupportsQuic(spdy_server_mail);
|
| - EXPECT_FALSE(supports_quic1.used_quic);
|
| - EXPECT_EQ("", supports_quic1.address);
|
| + EXPECT_FALSE(HasAlternateProtocol(spdy_server_mail));
|
| + EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address));
|
| const ServerNetworkStats* stats2 =
|
| http_server_props_manager_->GetServerNetworkStats(spdy_server_mail);
|
| EXPECT_EQ(NULL, stats2);
|
| @@ -629,11 +606,6 @@ TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) {
|
|
|
| // Set the preference for mail.google.com server.
|
| base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue;
|
| - // Set up SupportsQuic for mail.google.com:80
|
| - base::DictionaryValue* supports_quic = new base::DictionaryValue;
|
| - supports_quic->SetBoolean("used_quic", true);
|
| - supports_quic->SetString("address", "bar");
|
| - server_pref_dict1->SetWithoutPathExpansion("supports_quic", supports_quic);
|
|
|
| // Set the server preference for mail.google.com:80.
|
| servers_dict->SetWithoutPathExpansion("mail.google.com:80",
|
| @@ -644,6 +616,13 @@ TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) {
|
| HttpServerPropertiesManager::SetVersion(http_server_properties_dict, -1);
|
| http_server_properties_dict->SetWithoutPathExpansion("servers", servers_dict);
|
|
|
| + // Set up SupportsQuic for 127.0.0.1
|
| + base::DictionaryValue* supports_quic = new base::DictionaryValue;
|
| + supports_quic->SetBoolean("used_quic", true);
|
| + supports_quic->SetString("address", "127.0.0.1");
|
| + http_server_properties_dict->SetWithoutPathExpansion("supports_quic",
|
| + supports_quic);
|
| +
|
| // Set up the pref.
|
| pref_service_.SetManagedPref(kTestHttpServerProperties,
|
| http_server_properties_dict);
|
| @@ -654,8 +633,6 @@ TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) {
|
| // Verify AlternateProtocol.
|
| for (int i = 0; i < 200; ++i) {
|
| std::string server = StringPrintf("www.google.com:%d", i);
|
| - ASSERT_TRUE(http_server_props_manager_->HasAlternateProtocol(
|
| - HostPortPair::FromString(server)));
|
| AlternateProtocolInfo port_alternate_protocol =
|
| http_server_props_manager_->GetAlternateProtocol(
|
| HostPortPair::FromString(server));
|
| @@ -664,10 +641,67 @@ TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) {
|
| }
|
|
|
| // Verify SupportsQuic.
|
| - SupportsQuic supports_quic1 = http_server_props_manager_->GetSupportsQuic(
|
| - HostPortPair::FromString("mail.google.com:80"));
|
| - EXPECT_TRUE(supports_quic1.used_quic);
|
| - EXPECT_EQ("bar", supports_quic1.address);
|
| + IPAddressNumber address;
|
| + ASSERT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
|
| + 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) {
|
|
|