Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Unified Diff: net/http/http_server_properties_manager_unittest.cc

Issue 665083009: ABANDONED Handle multiple AlternateProtocols for each HostPortPair. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Re: 18. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_server_properties_manager.cc ('k') | net/http/http_stream_factory.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 f2e36499e736850c19b757f9e8146e5d6adbf96c..07c798750ff84fc3b060ee5cc677ca7b7dec4a44 100644
--- a/net/http/http_server_properties_manager_unittest.cc
+++ b/net/http/http_server_properties_manager_unittest.cc
@@ -136,9 +136,9 @@ class HttpServerPropertiesManagerTest : public testing::Test {
}
bool HasAlternateProtocol(const HostPortPair& server) {
- const AlternateProtocolInfo alternate =
- http_server_props_manager_->GetAlternateProtocol(server);
- return alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL;
+ const AlternateProtocols alternates =
+ http_server_props_manager_->GetAlternateProtocols(server);
+ return !alternates.empty();
}
//base::RunLoop loop_;
@@ -163,12 +163,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 ServerNetworkStats for www.google.com:80.
base::DictionaryValue* stats = new base::DictionaryValue;
@@ -185,13 +191,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 ServerNetworkStats for mail.google.com:80.
base::DictionaryValue* stats1 = new base::DictionaryValue;
@@ -230,14 +237,22 @@ TEST_F(HttpServerPropertiesManagerTest,
HostPortPair::FromString("foo.google.com:1337")));
// Verify AlternateProtocol.
- 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_TRUE(www_it != map.end());
+ 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_TRUE(mail_it != map.end());
+ 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.
IPAddressNumber last_address;
@@ -263,12 +278,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 ServerNetworkStats for www.google.com:65536.
base::DictionaryValue* stats = new base::DictionaryValue;
@@ -313,12 +330,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;
@@ -467,18 +486,18 @@ TEST_F(HttpServerPropertiesManagerTest, GetAlternateProtocol) {
HostPortPair spdy_server_mail("mail.google.com", 80);
EXPECT_FALSE(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.0);
// Run the task.
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
- const AlternateProtocolInfo alternate_protocol =
- http_server_props_manager_->GetAlternateProtocol(spdy_server_mail);
- EXPECT_EQ(443, alternate_protocol.port);
- EXPECT_EQ(NPN_SPDY_3, alternate_protocol.protocol);
- EXPECT_EQ(1.0, alternate_protocol.probability);
+ AlternateProtocols port_alternate_protocols =
+ http_server_props_manager_->GetAlternateProtocols(spdy_server_mail);
+ ASSERT_EQ(1u, port_alternate_protocols.size());
+ EXPECT_EQ(443, port_alternate_protocols[0].port);
+ EXPECT_EQ(NPN_SPDY_3, port_alternate_protocols[0].protocol);
}
TEST_F(HttpServerPropertiesManagerTest, SupportsQuic) {
@@ -524,7 +543,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.0);
IPAddressNumber actual_address;
CHECK(ParseIPLiteralToNumber("127.0.0.1", &actual_address));
@@ -597,9 +616,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);
}
@@ -633,11 +654,12 @@ TEST_F(HttpServerPropertiesManagerTest, BadSupportsQuic) {
// Verify AlternateProtocol.
for (int i = 0; i < 200; ++i) {
std::string server = StringPrintf("www.google.com:%d", i);
- AlternateProtocolInfo port_alternate_protocol =
- http_server_props_manager_->GetAlternateProtocol(
+ AlternateProtocols alternate_protocols =
+ http_server_props_manager_->GetAlternateProtocols(
HostPortPair::FromString(server));
- EXPECT_EQ(i, port_alternate_protocol.port);
- EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol.protocol);
+ ASSERT_EQ(1u, alternate_protocols.size());
+ EXPECT_EQ(i, alternate_protocols[0].port);
+ EXPECT_EQ(NPN_SPDY_3, alternate_protocols[0].protocol);
}
// Verify SupportsQuic.
@@ -650,10 +672,12 @@ 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,
+ // Set AltSvc.
+ http_server_props_manager_->AddAlternateProtocol(server_www, 443, NPN_SPDY_3,
1.0);
- http_server_props_manager_->SetAlternateProtocol(server_mail, 444,
+ http_server_props_manager_->AddAlternateProtocol(server_www, 1234,
+ NPN_SPDY_3_1, 0.7);
+ http_server_props_manager_->AddAlternateProtocol(server_mail, 444,
NPN_SPDY_3_1, 0.2);
// Set ServerNetworkStats.
@@ -673,27 +697,16 @@ TEST_F(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) {
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 char expected_json[] =
+ "{\"servers\":{\"mail.google.com:80\":{\"alternative_services\":[{"
+ "\"host\":\"mail.google.com\",\"port\":444,\"probability\":0.2,"
+ "\"protocol_str\":\"npn-spdy/3.1\"}],\"network_stats\":{\"srtt\":42}},"
+ "\"www.google.com:80\":{\"alternative_services\":[{\"host\":"
+ "\"www.google.com\",\"port\":443,\"probability\":1.0,\"protocol_str\":"
+ "\"npn-spdy/3\"},{\"host\":\"www.google.com\",\"port\":1234,"
+ "\"probability\":0.7,\"protocol_str\":\"npn-spdy/3.1\"}]}},"
+ "\"supports_quic\":{\"address\":\"127.0.0.1\",\"used_quic\":true},"
+ "\"version\":3}";
const base::Value* http_server_properties =
pref_service_.GetUserPref(kTestHttpServerProperties);
« no previous file with comments | « net/http/http_server_properties_manager.cc ('k') | net/http/http_stream_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698