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

Unified Diff: net/http/http_server_properties_manager_unittest.cc

Issue 1824903002: Change the AlternativeServiceMap with SchemeOriginPair key. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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.h » ('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 bf83ff78ec62e4d07d8c9a54a81862e43e576307..1caa2f5c864d1fb42ec34eb1d49b4ea7f5c99e9f 100644
--- a/net/http/http_server_properties_manager_unittest.cc
+++ b/net/http/http_server_properties_manager_unittest.cc
@@ -206,7 +206,7 @@ class HttpServerPropertiesManagerTest : public testing::TestWithParam<int> {
UpdatePrefsFromCacheOnNetworkThreadConcrete));
}
- bool HasAlternativeService(const HostPortPair& server) {
+ bool HasAlternativeService(const url::SchemeHostPort& server) {
const AlternativeServiceVector alternative_service_vector =
http_server_props_manager_->GetAlternativeServices(server);
return !alternative_service_vector.empty();
@@ -233,7 +233,9 @@ TEST_P(HttpServerPropertiesManagerTest,
base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
HostPortPair google_server("www.google.com", 80);
+ url::SchemeHostPort google_scheme_origin_pair("https", "www.google.com", 80);
HostPortPair mail_server("mail.google.com", 80);
+ url::SchemeHostPort mail_scheme_origin_pair("https", "mail.google.com", 80);
// Set supports_spdy for www.google.com:80.
server_pref_dict->SetBoolean("supports_spdy", true);
@@ -347,11 +349,12 @@ TEST_P(HttpServerPropertiesManagerTest,
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
// Verify SupportsSpdy.
- EXPECT_TRUE(
- http_server_props_manager_->SupportsRequestPriority(google_server));
- EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server));
+ EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(
+ google_scheme_origin_pair));
+ EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(
+ mail_scheme_origin_pair));
EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(
- HostPortPair::FromString("foo.google.com:1337")));
+ url::SchemeHostPort("http", "foo.google.com", 1337)));
// Verify alternative service.
if (GetParam() == 4) {
@@ -488,13 +491,16 @@ TEST_P(HttpServerPropertiesManagerTest, BadCachedHostPortPair) {
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
// Verify that nothing is set.
- EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(
- HostPortPair::FromString("www.google.com:65536")));
+ HostPortPair host_port_pair =
+ HostPortPair::FromString("www.google.com:65536");
+ url::SchemeHostPort scheme_origin("https", host_port_pair.host(),
+ host_port_pair.port());
EXPECT_FALSE(
- HasAlternativeService(HostPortPair::FromString("www.google.com:65536")));
+ http_server_props_manager_->SupportsRequestPriority(scheme_origin));
+
+ EXPECT_FALSE(HasAlternativeService(scheme_origin));
const ServerNetworkStats* stats1 =
- http_server_props_manager_->GetServerNetworkStats(
- HostPortPair::FromString("www.google.com:65536"));
+ http_server_props_manager_->GetServerNetworkStats(host_port_pair);
EXPECT_EQ(nullptr, stats1);
EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size());
}
@@ -544,8 +550,8 @@ TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) {
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
// Verify alternative service is not set.
- EXPECT_FALSE(
- HasAlternativeService(HostPortPair::FromString("www.google.com:80")));
+ url::SchemeHostPort scheme_origin("http", "www.google.com", 80);
+ EXPECT_FALSE(HasAlternativeService(scheme_origin));
}
TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) {
@@ -557,8 +563,9 @@ TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) {
// Add mail.google.com:443 as a supporting spdy server.
HostPortPair spdy_server_mail("mail.google.com", 443);
+ url::SchemeHostPort scheme_origin("https", "mail.google.com", 443);
EXPECT_FALSE(
- http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
+ http_server_props_manager_->SupportsRequestPriority(scheme_origin));
http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true);
// ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true);
@@ -567,7 +574,7 @@ TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) {
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(
- http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
+ http_server_props_manager_->SupportsRequestPriority(scheme_origin));
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
}
@@ -679,22 +686,22 @@ TEST_P(HttpServerPropertiesManagerTest, GetAlternativeServices) {
ExpectPrefsUpdate();
ExpectScheduleUpdatePrefsOnNetworkThread();
- HostPortPair spdy_server_mail("mail.google.com", 80);
- EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
+ url::SchemeHostPort scheme_origin("http", "mail.google.com", 80);
+ EXPECT_FALSE(HasAlternativeService(scheme_origin));
const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com",
443);
http_server_props_manager_->SetAlternativeService(
- spdy_server_mail, alternative_service, one_day_from_now_);
+ scheme_origin, alternative_service, one_day_from_now_);
// ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
http_server_props_manager_->SetAlternativeService(
- spdy_server_mail, alternative_service, one_day_from_now_);
+ scheme_origin, alternative_service, one_day_from_now_);
// Run the task.
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
AlternativeServiceVector alternative_service_vector =
- http_server_props_manager_->GetAlternativeServices(spdy_server_mail);
+ http_server_props_manager_->GetAlternativeServices(scheme_origin);
ASSERT_EQ(1u, alternative_service_vector.size());
EXPECT_EQ(alternative_service, alternative_service_vector[0]);
}
@@ -703,8 +710,8 @@ TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServices) {
ExpectPrefsUpdate();
ExpectScheduleUpdatePrefsOnNetworkThread();
- HostPortPair spdy_server_mail("mail.google.com", 80);
- EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
+ url::SchemeHostPort scheme_origin("http", "mail.google.com", 80);
+ EXPECT_FALSE(HasAlternativeService(scheme_origin));
AlternativeServiceInfoVector alternative_service_info_vector;
const AlternativeService alternative_service1(NPN_HTTP_2, "mail.google.com",
443);
@@ -714,69 +721,69 @@ TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServices) {
alternative_service_info_vector.push_back(
AlternativeServiceInfo(alternative_service2, one_day_from_now_));
http_server_props_manager_->SetAlternativeServices(
- spdy_server_mail, alternative_service_info_vector);
+ scheme_origin, alternative_service_info_vector);
// ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
http_server_props_manager_->SetAlternativeServices(
- spdy_server_mail, alternative_service_info_vector);
+ scheme_origin, alternative_service_info_vector);
// Run the task.
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
AlternativeServiceVector alternative_service_vector =
- http_server_props_manager_->GetAlternativeServices(spdy_server_mail);
+ http_server_props_manager_->GetAlternativeServices(scheme_origin);
ASSERT_EQ(2u, alternative_service_vector.size());
EXPECT_EQ(alternative_service1, alternative_service_vector[0]);
EXPECT_EQ(alternative_service2, alternative_service_vector[1]);
}
TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServicesEmpty) {
- HostPortPair spdy_server_mail("mail.google.com", 80);
- EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
+ url::SchemeHostPort scheme_origin("http", "mail.google.com", 80);
+ EXPECT_FALSE(HasAlternativeService(scheme_origin));
const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com",
443);
http_server_props_manager_->SetAlternativeServices(
- spdy_server_mail, AlternativeServiceInfoVector());
+ scheme_origin, AlternativeServiceInfoVector());
// ExpectScheduleUpdatePrefsOnNetworkThread() should not be called.
// Run the task.
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
- EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
+ EXPECT_FALSE(HasAlternativeService(scheme_origin));
}
TEST_P(HttpServerPropertiesManagerTest, ClearAlternativeServices) {
ExpectPrefsUpdate();
ExpectScheduleUpdatePrefsOnNetworkThread();
- HostPortPair spdy_server_mail("mail.google.com", 80);
- EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
+ url::SchemeHostPort scheme_origin("http", "mail.google.com", 80);
+ EXPECT_FALSE(HasAlternativeService(scheme_origin));
AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443);
http_server_props_manager_->SetAlternativeService(
- spdy_server_mail, alternative_service, one_day_from_now_);
+ scheme_origin, alternative_service, one_day_from_now_);
ExpectScheduleUpdatePrefsOnNetworkThread();
- http_server_props_manager_->ClearAlternativeServices(spdy_server_mail);
+ http_server_props_manager_->ClearAlternativeServices(scheme_origin);
// ExpectScheduleUpdatePrefsOnNetworkThread() should be called only once.
- http_server_props_manager_->ClearAlternativeServices(spdy_server_mail);
+ http_server_props_manager_->ClearAlternativeServices(scheme_origin);
// Run the task.
base::RunLoop().RunUntilIdle();
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
- EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
+ EXPECT_FALSE(HasAlternativeService(scheme_origin));
}
TEST_P(HttpServerPropertiesManagerTest, ConfirmAlternativeService) {
ExpectPrefsUpdate();
- HostPortPair spdy_server_mail("mail.google.com", 80);
- EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
+ url::SchemeHostPort scheme_origin("http", "mail.google.com", 80);
+ EXPECT_FALSE(HasAlternativeService(scheme_origin));
AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443);
ExpectScheduleUpdatePrefsOnNetworkThread();
http_server_props_manager_->SetAlternativeService(
- spdy_server_mail, alternative_service, one_day_from_now_);
+ scheme_origin, alternative_service, one_day_from_now_);
EXPECT_FALSE(http_server_props_manager_->IsAlternativeServiceBroken(
alternative_service));
@@ -883,10 +890,11 @@ TEST_P(HttpServerPropertiesManagerTest, Clear) {
ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly();
HostPortPair spdy_server_mail("mail.google.com", 443);
+ url::SchemeHostPort scheme_origin("http", "mail.google.com", 443);
http_server_props_manager_->SetSupportsSpdy(spdy_server_mail, true);
AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 1234);
http_server_props_manager_->SetAlternativeService(
- spdy_server_mail, alternative_service, one_day_from_now_);
+ scheme_origin, alternative_service, one_day_from_now_);
IPAddress actual_address(127, 0, 0, 1);
http_server_props_manager_->SetSupportsQuic(true, actual_address);
ServerNetworkStats stats;
@@ -908,8 +916,8 @@ TEST_P(HttpServerPropertiesManagerTest, Clear) {
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(
- http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
- EXPECT_TRUE(HasAlternativeService(spdy_server_mail));
+ http_server_props_manager_->SupportsRequestPriority(scheme_origin));
+ EXPECT_TRUE(HasAlternativeService(scheme_origin));
IPAddress address;
EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
EXPECT_EQ(actual_address, address);
@@ -938,8 +946,8 @@ TEST_P(HttpServerPropertiesManagerTest, Clear) {
base::RunLoop().Run();
EXPECT_FALSE(
- http_server_props_manager_->SupportsRequestPriority(spdy_server_mail));
- EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
+ http_server_props_manager_->SupportsRequestPriority(scheme_origin));
+ EXPECT_FALSE(HasAlternativeService(scheme_origin));
EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address));
const ServerNetworkStats* stats2 =
http_server_props_manager_->GetServerNetworkStats(spdy_server_mail);
@@ -1024,10 +1032,14 @@ TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) {
std::string server = StringPrintf("www.google.com:%d", i);
AlternativeServiceVector alternative_service_vector =
http_server_props_manager_->GetAlternativeServices(
- HostPortPair::FromString(server));
- ASSERT_EQ(1u, alternative_service_vector.size());
- EXPECT_EQ(QUIC, alternative_service_vector[0].protocol);
- EXPECT_EQ(i, alternative_service_vector[0].port);
+ url::SchemeHostPort("https", "www.google.com", i));
+ if (GetParam() > 4) {
+ ASSERT_EQ(1u, alternative_service_vector.size());
+ EXPECT_EQ(QUIC, alternative_service_vector[0].protocol);
+ EXPECT_EQ(i, alternative_service_vector[0].port);
+ } else {
+ EXPECT_EQ(0u, alternative_service_vector.size());
+ }
}
// Verify SupportsQuic.
@@ -1039,8 +1051,9 @@ TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) {
TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) {
ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly();
- const HostPortPair server_www("www.google.com", 80);
+ url::SchemeHostPort server_www("http", "www.google.com", 80);
const HostPortPair server_mail("mail.google.com", 80);
+ url::SchemeHostPort mail_server("http", "mail.google.com", 80);
// Set alternate protocol.
AlternativeServiceInfoVector alternative_service_info_vector;
@@ -1062,7 +1075,7 @@ TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) {
444);
base::Time expiration3 = base::Time::Max();
http_server_props_manager_->SetAlternativeService(
- server_mail, mail_alternative_service, expiration3);
+ mail_server, mail_alternative_service, expiration3);
// Set ServerNetworkStats.
ServerNetworkStats stats;
@@ -1122,13 +1135,13 @@ TEST_P(HttpServerPropertiesManagerTest, AddToAlternativeServiceMap) {
base::DictionaryValue* server_dict;
ASSERT_TRUE(server_value->GetAsDictionary(&server_dict));
- const HostPortPair host_port_pair("example.com", 443);
+ url::SchemeHostPort scheme_origin("https", "example.com", 443);
AlternativeServiceMap alternative_service_map(/*max_size=*/5);
EXPECT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap(
- host_port_pair, *server_dict, &alternative_service_map));
+ scheme_origin, *server_dict, &alternative_service_map));
AlternativeServiceMap::iterator it =
- alternative_service_map.Get(host_port_pair);
+ alternative_service_map.Get(scheme_origin);
ASSERT_NE(alternative_service_map.end(), it);
AlternativeServiceInfoVector alternative_service_info_vector = it->second;
ASSERT_EQ(3u, alternative_service_info_vector.size());
@@ -1189,9 +1202,9 @@ TEST_P(HttpServerPropertiesManagerTest,
alternative_service_info_vector.push_back(
AlternativeServiceInfo(valid_alternative_service, time_one_day_later));
- const HostPortPair host_port_pair("www.example.com", 443);
+ url::SchemeHostPort scheme_origin("https", "www.example.com", 443);
http_server_props_manager_->SetAlternativeServices(
- host_port_pair, alternative_service_info_vector);
+ scheme_origin, alternative_service_info_vector);
// Update cache.
ExpectPrefsUpdate();
@@ -1250,13 +1263,13 @@ TEST_P(HttpServerPropertiesManagerTest, DoNotLoadExpiredAlternativeService) {
server_pref_dict.SetWithoutPathExpansion("alternative_service",
alternative_service_list.release());
- const HostPortPair host_port_pair("example.com", 443);
+ url::SchemeHostPort scheme_origin("https", "example.com", 443);
AlternativeServiceMap alternative_service_map(/*max_size=*/5);
ASSERT_TRUE(http_server_props_manager_->AddToAlternativeServiceMap(
- host_port_pair, server_pref_dict, &alternative_service_map));
+ scheme_origin, server_pref_dict, &alternative_service_map));
AlternativeServiceMap::iterator it =
- alternative_service_map.Get(host_port_pair);
+ alternative_service_map.Get(scheme_origin);
ASSERT_NE(alternative_service_map.end(), it);
AlternativeServiceInfoVector alternative_service_info_vector = it->second;
ASSERT_EQ(1u, alternative_service_info_vector.size());
« no previous file with comments | « net/http/http_server_properties_manager.cc ('k') | net/http/http_stream_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698