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

Unified Diff: net/http/http_server_properties_manager_unittest.cc

Issue 1878143005: SHP 4: Change AlternativeServiceMap to use SchemeHostPort as the key. No change to Pref data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@SHP_3
Patch Set: fix cronet && SpdyNetworkTransactionUnittests 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
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 7d50be24225287960c7530509aca57f9ed6fec5e..32e9e5204c074dfa2139ea92fcc7ff46484a3f97 100644
--- a/net/http/http_server_properties_manager_unittest.cc
+++ b/net/http/http_server_properties_manager_unittest.cc
@@ -18,6 +18,7 @@
#include "net/base/ip_address.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
namespace net {
@@ -205,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();
@@ -232,12 +233,10 @@ TEST_P(HttpServerPropertiesManagerTest,
// it twice. Only expect a single cache update.
base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
- HostPortPair google_server("www.google.com", 80);
// TODO(zhongyi): change scheme to http once Pref data is also migrated
// SchemeHostPort.
- url::SchemeHostPort google_scheme_host_port("https", "www.google.com", 80);
- url::SchemeHostPort mail_scheme_host_port("https", "mail.google.com", 80);
- HostPortPair mail_server("mail.google.com", 80);
+ url::SchemeHostPort google_server("https", "www.google.com", 80);
+ url::SchemeHostPort mail_server("https", "mail.google.com", 80);
// Set supports_spdy for www.google.com:80.
server_pref_dict->SetBoolean("supports_spdy", true);
@@ -351,16 +350,15 @@ TEST_P(HttpServerPropertiesManagerTest,
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
// Verify SupportsSpdy.
- EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(
- google_scheme_host_port));
- EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(
- mail_scheme_host_port));
- HostPortPair foo_server = HostPortPair::FromString("foo.google.com:1337");
- url::SchemeHostPort foo_scheme_host_port("http", foo_server.host(),
- foo_server.port());
+ EXPECT_TRUE(
+ http_server_props_manager_->SupportsRequestPriority(google_server));
+ EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(mail_server));
+ HostPortPair foo_host_port_pair =
+ HostPortPair::FromString("foo.google.com:1337");
+ url::SchemeHostPort foo_server("http", foo_host_port_pair.host(),
+ foo_host_port_pair.port());
- EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(
- foo_scheme_host_port));
+ EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(foo_server));
// Verify alternative service.
if (GetParam() == 4) {
@@ -411,11 +409,10 @@ TEST_P(HttpServerPropertiesManagerTest,
// Verify ServerNetworkStats.
const ServerNetworkStats* stats2 =
- http_server_props_manager_->GetServerNetworkStats(
- google_scheme_host_port);
+ http_server_props_manager_->GetServerNetworkStats(google_server);
EXPECT_EQ(10, stats2->srtt.ToInternalValue());
const ServerNetworkStats* stats3 =
- http_server_props_manager_->GetServerNetworkStats(mail_scheme_host_port);
+ http_server_props_manager_->GetServerNetworkStats(mail_server);
EXPECT_EQ(20, stats3->srtt.ToInternalValue());
// Verify QuicServerInfo.
@@ -498,17 +495,16 @@ TEST_P(HttpServerPropertiesManagerTest, BadCachedHostPortPair) {
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
// Verify that nothing is set.
- HostPortPair google_server = HostPortPair::FromString("www.google.com:65536");
- url::SchemeHostPort google_scheme_host_port("http", google_server.host(),
- google_server.port());
+ HostPortPair google_host_port_pair =
+ HostPortPair::FromString("www.google.com:65536");
+ url::SchemeHostPort gooler_server("http", google_host_port_pair.host(),
+ google_host_port_pair.port());
- EXPECT_FALSE(http_server_props_manager_->SupportsRequestPriority(
- google_scheme_host_port));
EXPECT_FALSE(
- HasAlternativeService(HostPortPair::FromString("www.google.com:65536")));
+ http_server_props_manager_->SupportsRequestPriority(gooler_server));
+ EXPECT_FALSE(HasAlternativeService(gooler_server));
const ServerNetworkStats* stats1 =
- http_server_props_manager_->GetServerNetworkStats(
- google_scheme_host_port);
+ http_server_props_manager_->GetServerNetworkStats(gooler_server);
EXPECT_EQ(nullptr, stats1);
EXPECT_EQ(0u, http_server_props_manager_->quic_server_info_map().size());
}
@@ -559,7 +555,7 @@ TEST_P(HttpServerPropertiesManagerTest, BadCachedAltProtocolPort) {
// Verify alternative service is not set.
EXPECT_FALSE(
- HasAlternativeService(HostPortPair::FromString("www.google.com:80")));
+ HasAlternativeService(url::SchemeHostPort("http", "www.google.com", 80)));
}
TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) {
@@ -570,7 +566,6 @@ TEST_P(HttpServerPropertiesManagerTest, SupportsSpdy) {
// ScheduleUpdatePrefsOnNetworkThread.
// Add mail.google.com:443 as a supporting spdy server.
- HostPortPair spdy_server_mail("mail.google.com", 443);
url::SchemeHostPort spdy_server("https", "mail.google.com", 443);
EXPECT_FALSE(
http_server_props_manager_->SupportsRequestPriority(spdy_server));
@@ -693,7 +688,7 @@ TEST_P(HttpServerPropertiesManagerTest, GetAlternativeServices) {
ExpectPrefsUpdate();
ExpectScheduleUpdatePrefsOnNetworkThread();
- HostPortPair spdy_server_mail("mail.google.com", 80);
+ url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80);
EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com",
443);
@@ -717,7 +712,7 @@ TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServices) {
ExpectPrefsUpdate();
ExpectScheduleUpdatePrefsOnNetworkThread();
- HostPortPair spdy_server_mail("mail.google.com", 80);
+ url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80);
EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
AlternativeServiceInfoVector alternative_service_info_vector;
const AlternativeService alternative_service1(NPN_HTTP_2, "mail.google.com",
@@ -745,7 +740,7 @@ TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServices) {
}
TEST_P(HttpServerPropertiesManagerTest, SetAlternativeServicesEmpty) {
- HostPortPair spdy_server_mail("mail.google.com", 80);
+ url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80);
EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
const AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com",
443);
@@ -764,7 +759,7 @@ TEST_P(HttpServerPropertiesManagerTest, ClearAlternativeServices) {
ExpectPrefsUpdate();
ExpectScheduleUpdatePrefsOnNetworkThread();
- HostPortPair spdy_server_mail("mail.google.com", 80);
+ url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80);
EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443);
http_server_props_manager_->SetAlternativeService(
@@ -784,7 +779,7 @@ TEST_P(HttpServerPropertiesManagerTest, ClearAlternativeServices) {
TEST_P(HttpServerPropertiesManagerTest, ConfirmAlternativeService) {
ExpectPrefsUpdate();
- HostPortPair spdy_server_mail("mail.google.com", 80);
+ url::SchemeHostPort spdy_server_mail("http", "mail.google.com", 80);
EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
AlternativeService alternative_service(NPN_HTTP_2, "mail.google.com", 443);
@@ -896,12 +891,11 @@ TEST_P(HttpServerPropertiesManagerTest, Clear) {
ExpectPrefsUpdate();
ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly();
- HostPortPair spdy_server_mail("mail.google.com", 443);
url::SchemeHostPort spdy_server("https", "mail.google.com", 443);
http_server_props_manager_->SetSupportsSpdy(spdy_server, 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_);
+ spdy_server, alternative_service, one_day_from_now_);
IPAddress actual_address(127, 0, 0, 1);
http_server_props_manager_->SetSupportsQuic(true, actual_address);
ServerNetworkStats stats;
@@ -922,7 +916,7 @@ TEST_P(HttpServerPropertiesManagerTest, Clear) {
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(http_server_props_manager_->SupportsRequestPriority(spdy_server));
- EXPECT_TRUE(HasAlternativeService(spdy_server_mail));
+ EXPECT_TRUE(HasAlternativeService(spdy_server));
IPAddress address;
EXPECT_TRUE(http_server_props_manager_->GetSupportsQuic(&address));
EXPECT_EQ(actual_address, address);
@@ -952,7 +946,7 @@ TEST_P(HttpServerPropertiesManagerTest, Clear) {
EXPECT_FALSE(
http_server_props_manager_->SupportsRequestPriority(spdy_server));
- EXPECT_FALSE(HasAlternativeService(spdy_server_mail));
+ EXPECT_FALSE(HasAlternativeService(spdy_server));
EXPECT_FALSE(http_server_props_manager_->GetSupportsQuic(&address));
const ServerNetworkStats* stats2 =
http_server_props_manager_->GetServerNetworkStats(spdy_server);
@@ -977,7 +971,7 @@ TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) {
if (GetParam() == 4)
servers_list = new base::ListValue;
- for (int i = 0; i < 200; ++i) {
+ for (int i = 1; i <= 200; ++i) {
// Set up alternative_service for www.google.com:i.
base::DictionaryValue* alternative_service_dict = new base::DictionaryValue;
alternative_service_dict->SetString("protocol_str", "quic");
@@ -988,12 +982,14 @@ TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) {
server_pref_dict->SetWithoutPathExpansion("alternative_service",
alternative_service_list);
if (GetParam() == 4) {
+ // TODO(zhongyi): add scheme once disc data is migrated.
servers_dict->SetWithoutPathExpansion(
StringPrintf("www.google.com:%d", i), server_pref_dict);
// |servers_list| takes ownership of |servers_dict|.
servers_list->AppendIfNotPresent(servers_dict);
servers_dict = new base::DictionaryValue;
} else {
+ // TODO(zhongyi): add scheme once disc data is migrated.
servers_dict->SetWithoutPathExpansion(
StringPrintf("www.google.com:%d", i), server_pref_dict);
}
@@ -1003,6 +999,7 @@ TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) {
base::DictionaryValue* server_pref_dict1 = new base::DictionaryValue;
// Set the server preference for mail.google.com:80.
+ // TODO(zhongyi): add scheme once disc data is migrated.
servers_dict->SetWithoutPathExpansion("mail.google.com:80",
server_pref_dict1);
base::DictionaryValue http_server_properties_dict;
@@ -1033,11 +1030,12 @@ TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) {
Mock::VerifyAndClearExpectations(http_server_props_manager_.get());
// Verify alternative service.
- for (int i = 0; i < 200; ++i) {
- std::string server = StringPrintf("www.google.com:%d", i);
+ for (int i = 1; i <= 200; ++i) {
+ // TODO(zhongyi): remove hardcoded scheme once disc data is migrated.
+ GURL server_gurl(StringPrintf("https://www.google.com:%d", i));
+ url::SchemeHostPort server(server_gurl);
AlternativeServiceVector alternative_service_vector =
- http_server_props_manager_->GetAlternativeServices(
- HostPortPair::FromString(server));
+ http_server_props_manager_->GetAlternativeServices(server);
ASSERT_EQ(1u, alternative_service_vector.size());
EXPECT_EQ(QUIC, alternative_service_vector[0].protocol);
EXPECT_EQ(i, alternative_service_vector[0].port);
@@ -1052,7 +1050,7 @@ TEST_P(HttpServerPropertiesManagerTest, BadSupportsQuic) {
TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) {
ExpectScheduleUpdatePrefsOnNetworkThreadRepeatedly();
- const HostPortPair server_www("www.google.com", 80);
+ const url::SchemeHostPort server_www("http", "www.google.com", 80);
const url::SchemeHostPort server_mail("http", "mail.google.com", 80);
// Set alternate protocol.
@@ -1075,8 +1073,7 @@ TEST_P(HttpServerPropertiesManagerTest, UpdateCacheWithPrefs) {
444);
base::Time expiration3 = base::Time::Max();
http_server_props_manager_->SetAlternativeService(
- HostPortPair(server_mail.host(), server_mail.port()),
- mail_alternative_service, expiration3);
+ server_mail, mail_alternative_service, expiration3);
// Set ServerNetworkStats.
ServerNetworkStats stats;
@@ -1136,13 +1133,12 @@ TEST_P(HttpServerPropertiesManagerTest, AddToAlternativeServiceMap) {
base::DictionaryValue* server_dict;
ASSERT_TRUE(server_value->GetAsDictionary(&server_dict));
- const HostPortPair host_port_pair("example.com", 443);
+ const url::SchemeHostPort server("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));
+ server, *server_dict, &alternative_service_map));
- AlternativeServiceMap::iterator it =
- alternative_service_map.Get(host_port_pair);
+ AlternativeServiceMap::iterator it = alternative_service_map.Get(server);
ASSERT_NE(alternative_service_map.end(), it);
AlternativeServiceInfoVector alternative_service_info_vector = it->second;
ASSERT_EQ(3u, alternative_service_info_vector.size());
@@ -1203,9 +1199,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);
+ const url::SchemeHostPort server("https", "www.example.com", 443);
http_server_props_manager_->SetAlternativeServices(
- host_port_pair, alternative_service_info_vector);
+ server, alternative_service_info_vector);
// Update cache.
ExpectPrefsUpdate();
@@ -1265,13 +1261,12 @@ TEST_P(HttpServerPropertiesManagerTest, DoNotLoadExpiredAlternativeService) {
server_pref_dict.SetWithoutPathExpansion("alternative_service",
alternative_service_list.release());
- const HostPortPair host_port_pair("example.com", 443);
+ const url::SchemeHostPort server("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));
+ server, server_pref_dict, &alternative_service_map));
- AlternativeServiceMap::iterator it =
- alternative_service_map.Get(host_port_pair);
+ AlternativeServiceMap::iterator it = alternative_service_map.Get(server);
ASSERT_NE(alternative_service_map.end(), it);
AlternativeServiceInfoVector alternative_service_info_vector = it->second;
ASSERT_EQ(1u, alternative_service_info_vector.size());

Powered by Google App Engine
This is Rietveld 408576698