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 99647b3fef9aedeb01cecc864cc8ccb49e1fbe73..2f07619947d3e6ec40e91c2584a98839ca199a8b 100644 |
--- a/net/http/http_server_properties_manager_unittest.cc |
+++ b/net/http/http_server_properties_manager_unittest.cc |
@@ -156,12 +156,18 @@ TEST_F(HttpServerPropertiesManagerTest, |
// 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", 443); |
- alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
- server_pref_dict->SetWithoutPathExpansion("alternate_protocol", |
- alternate_protocol); |
+ // Set up alternative_services for www.google.com:80. |
+ base::DictionaryValue* alternate_protocol0 = new base::DictionaryValue; |
+ alternate_protocol0->SetInteger("port", 443); |
+ alternate_protocol0->SetString("protocol_str", "npn-spdy/3"); |
+ base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; |
+ alternate_protocol1->SetInteger("port", 1234); |
+ alternate_protocol1->SetString("protocol_str", "quic"); |
+ base::ListValue* alternative_services = new base::ListValue; |
+ alternative_services->Append(alternate_protocol0); |
+ alternative_services->Append(alternate_protocol1); |
+ server_pref_dict->SetWithoutPathExpansion("alternative_services", |
+ alternative_services); |
// Set up SupportsQuic for www.google.com:80. |
base::DictionaryValue* supports_quic = new base::DictionaryValue; |
@@ -184,13 +190,14 @@ TEST_F(HttpServerPropertiesManagerTest, |
// Set supports_spdy for mail.google.com:80 |
server_pref_dict1->SetBoolean("supports_spdy", true); |
- // Set up alternate_protocol for mail.google.com:80 |
- base::DictionaryValue* alternate_protocol1 = new base::DictionaryValue; |
- alternate_protocol1->SetInteger("port", 444); |
- alternate_protocol1->SetString("protocol_str", "npn-spdy/3.1"); |
- |
- server_pref_dict1->SetWithoutPathExpansion("alternate_protocol", |
- alternate_protocol1); |
+ // Set up alternative_services for mail.google.com:80 |
+ base::DictionaryValue* alternate_protocol2 = new base::DictionaryValue; |
+ alternate_protocol2->SetInteger("port", 444); |
+ alternate_protocol2->SetString("protocol_str", "npn-spdy/3.1"); |
+ base::ListValue* alternative_services1 = new base::ListValue; |
+ alternative_services1->Append(alternate_protocol2); |
+ server_pref_dict1->SetWithoutPathExpansion("alternative_services", |
+ alternative_services1); |
// Set up SupportsQuic for mail.google.com:80 |
base::DictionaryValue* supports_quic1 = new base::DictionaryValue; |
@@ -229,16 +236,22 @@ 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); |
- EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); |
- port_alternate_protocol = |
- http_server_props_manager_->GetAlternateProtocol(mail_server); |
- EXPECT_EQ(444, port_alternate_protocol.port); |
- EXPECT_EQ(NPN_SPDY_3_1, port_alternate_protocol.protocol); |
+ const AlternateProtocolMap& map = |
+ http_server_props_manager_->alternate_protocol_map(); |
+ AlternateProtocolMap::const_iterator www_it = map.Peek(google_server); |
+ ASSERT_NE(map.end(), www_it); |
+ const AlternateProtocols alternate_protocols0 = www_it->second; |
+ ASSERT_EQ(2u, alternate_protocols0.size()); |
+ EXPECT_EQ(443, alternate_protocols0[0].port); |
+ EXPECT_EQ(NPN_SPDY_3, alternate_protocols0[0].protocol); |
+ EXPECT_EQ(1234, alternate_protocols0[1].port); |
+ EXPECT_EQ(QUIC, alternate_protocols0[1].protocol); |
+ AlternateProtocolMap::const_iterator mail_it = map.Peek(mail_server); |
+ ASSERT_NE(map.end(), mail_it); |
+ const AlternateProtocols alternate_protocols1 = mail_it->second; |
+ ASSERT_EQ(1u, alternate_protocols1.size()); |
+ EXPECT_EQ(444, alternate_protocols1[0].port); |
+ EXPECT_EQ(NPN_SPDY_3_1, alternate_protocols1[0].protocol); |
// Verify SupportsQuic. |
SupportsQuic supports_quic2 = |
@@ -268,12 +281,14 @@ TEST_F(HttpServerPropertiesManagerTest, BadCachedHostPortPair) { |
// Set supports_spdy for www.google.com:65536. |
server_pref_dict->SetBoolean("supports_spdy", true); |
- // Set up alternate_protocol for www.google.com:65536. |
+ // Set up alternative_services 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); |
+ base::ListValue* alternative_services = new base::ListValue; |
+ alternative_services->Append(alternate_protocol); |
+ server_pref_dict->SetWithoutPathExpansion("alternative_services", |
+ alternative_services); |
// Set up SupportsQuic for www.google.com:65536. |
base::DictionaryValue* supports_quic = new base::DictionaryValue; |
@@ -327,12 +342,14 @@ TEST_F(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) { |
// Set supports_spdy for www.google.com:80. |
server_pref_dict->SetBoolean("supports_spdy", true); |
- // Set up alternate_protocol for www.google.com:80. |
+ // Set up alternative_services 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); |
+ base::ListValue* alternative_services = new base::ListValue; |
+ alternative_services->Append(alternate_protocol); |
+ server_pref_dict->SetWithoutPathExpansion("alternative_services", |
+ alternative_services); |
// Set the server preference for www.google.com:80. |
base::DictionaryValue* servers_dict = new base::DictionaryValue; |
@@ -480,15 +497,13 @@ TEST_F(HttpServerPropertiesManagerTest, HasAlternateProtocol) { |
HostPortPair spdy_server_mail("mail.google.com", 80); |
EXPECT_FALSE( |
http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
- http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, |
+ http_server_props_manager_->AddAlternateProtocol(spdy_server_mail, 443, |
NPN_SPDY_3, 1); |
// Run the task. |
base::RunLoop().RunUntilIdle(); |
Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
- ASSERT_TRUE( |
- http_server_props_manager_->HasAlternateProtocol(spdy_server_mail)); |
AlternateProtocolInfo port_alternate_protocol = |
http_server_props_manager_->GetAlternateProtocol(spdy_server_mail); |
EXPECT_EQ(443, port_alternate_protocol.port); |
@@ -540,7 +555,7 @@ TEST_F(HttpServerPropertiesManagerTest, Clear) { |
HostPortPair spdy_server_mail("mail.google.com", 443); |
http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true); |
- http_server_props_manager_->SetAlternateProtocol(spdy_server_mail, 443, |
+ http_server_props_manager_->AddAlternateProtocol(spdy_server_mail, 443, |
NPN_SPDY_3, 1); |
http_server_props_manager_->SetSupportsQuic(spdy_server_mail, true, "foo"); |
ServerNetworkStats stats; |
@@ -603,7 +618,7 @@ TEST_F(HttpServerPropertiesManagerTest, Clear) { |
Mock::VerifyAndClearExpectations(http_server_props_manager_.get()); |
} |
-// crbug.com/444956: Add 200 alternate_protocol servers followed by |
+// https://crbug.com/444956: Add 200 alternate_protocol servers followed by |
// supports_quic and verify we have read supports_quic from prefs. |
TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { |
ExpectCacheUpdate(); |
@@ -615,9 +630,11 @@ TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) { |
base::DictionaryValue* alternate_protocol = new base::DictionaryValue; |
alternate_protocol->SetInteger("port", i); |
alternate_protocol->SetString("protocol_str", "npn-spdy/3"); |
+ base::ListValue* alternative_services = new base::ListValue; |
+ alternative_services->Append(alternate_protocol); |
base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
- server_pref_dict->SetWithoutPathExpansion("alternate_protocol", |
- alternate_protocol); |
+ server_pref_dict->SetWithoutPathExpansion("alternative_services", |
+ alternative_services); |
servers_dict->SetWithoutPathExpansion(StringPrintf("www.google.com:%d", i), |
server_pref_dict); |
} |
@@ -649,19 +666,16 @@ 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( |
- net::HostPortPair::FromString(server))); |
- net::AlternateProtocolInfo port_alternate_protocol = |
+ AlternateProtocolInfo port_alternate_protocol = |
http_server_props_manager_->GetAlternateProtocol( |
- net::HostPortPair::FromString(server)); |
+ HostPortPair::FromString(server)); |
EXPECT_EQ(i, port_alternate_protocol.port); |
- EXPECT_EQ(net::NPN_SPDY_3, port_alternate_protocol.protocol); |
+ EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol); |
} |
// Verify SupportsQuic. |
- net::SupportsQuic supports_quic1 = |
- http_server_props_manager_->GetSupportsQuic( |
- net::HostPortPair::FromString("mail.google.com:80")); |
+ 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); |
} |