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

Unified Diff: net/http/http_server_properties_impl_unittest.cc

Issue 1216703002: Implement multiple alternative services per origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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_impl_unittest.cc
diff --git a/net/http/http_server_properties_impl_unittest.cc b/net/http/http_server_properties_impl_unittest.cc
index 243c3fdd978b6cabfd63688c39115c2603f5ec00..c9a9d54e50146893817c4d447d3cbb678d896666 100644
--- a/net/http/http_server_properties_impl_unittest.cc
+++ b/net/http/http_server_properties_impl_unittest.cc
@@ -46,9 +46,9 @@ namespace {
class HttpServerPropertiesImplTest : public testing::Test {
protected:
bool HasAlternativeService(const HostPortPair& origin) {
- const AlternativeService alternative_service =
- impl_.GetAlternativeService(origin);
- return alternative_service.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL;
+ const AlternativeServiceVector alternative_service_vector =
+ impl_.GetAlternativeServices(origin);
+ return !alternative_service_vector.empty();
}
HttpServerPropertiesImpl impl_;
@@ -119,15 +119,23 @@ TEST_F(SpdyServerPropertiesTest, SupportsRequestPriorityTest) {
// Add www.youtube.com:443 as supporting QUIC.
HostPortPair quic_server_youtube("www.youtube.com", 443);
- const AlternativeService alternative_service(QUIC, "www.youtube.com", 443);
- impl_.SetAlternativeService(quic_server_youtube, alternative_service, 1.0);
+ const AlternativeService alternative_service1(QUIC, "www.youtube.com", 443);
+ impl_.AddAlternativeService(quic_server_youtube, alternative_service1, 1.0);
EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube));
+ // Add www.example.com:443 with two alternative services, one supporting QUIC.
+ HostPortPair quic_server_example("www.example.com", 443);
+ const AlternativeService alternative_service2(NPN_SPDY_4, "", 443);
+ impl_.AddAlternativeService(quic_server_example, alternative_service2, 1.0);
+ impl_.AddAlternativeService(quic_server_example, alternative_service1, 1.0);
+ EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_example));
+
// Verify all the entries are the same after additions.
EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google));
EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail));
EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs));
EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube));
+ EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_example));
}
TEST_F(SpdyServerPropertiesTest, Clear) {
@@ -247,11 +255,11 @@ TEST_F(AlternateProtocolServerPropertiesTest, Basic) {
EXPECT_FALSE(HasAlternativeService(test_host_port_pair));
AlternativeService alternative_service(NPN_SPDY_4, "foo", 443);
- impl_.SetAlternativeService(test_host_port_pair, alternative_service, 1.0);
- ASSERT_TRUE(HasAlternativeService(test_host_port_pair));
- alternative_service = impl_.GetAlternativeService(test_host_port_pair);
- EXPECT_EQ(443, alternative_service.port);
- EXPECT_EQ(NPN_SPDY_4, alternative_service.protocol);
+ impl_.AddAlternativeService(test_host_port_pair, alternative_service, 1.0);
+ const AlternativeServiceVector alternative_service_vector =
+ impl_.GetAlternativeServices(test_host_port_pair);
+ ASSERT_EQ(1u, alternative_service_vector.size());
+ EXPECT_EQ(alternative_service, alternative_service_vector[0]);
impl_.Clear();
EXPECT_FALSE(HasAlternativeService(test_host_port_pair));
@@ -260,25 +268,36 @@ TEST_F(AlternateProtocolServerPropertiesTest, Basic) {
TEST_F(AlternateProtocolServerPropertiesTest, DefaultProbabilityExcluded) {
HostPortPair test_host_port_pair("foo", 80);
const AlternativeService alternative_service(NPN_SPDY_4, "foo", 443);
- impl_.SetAlternativeService(test_host_port_pair, alternative_service, 0.99);
+ impl_.AddAlternativeService(test_host_port_pair, alternative_service, 0.99);
EXPECT_FALSE(HasAlternativeService(test_host_port_pair));
}
+// GetAlternativeServices and HasAlternativeServices should only return the ones
+// with probability greater than or equal to the threshold.
TEST_F(AlternateProtocolServerPropertiesTest, Probability) {
- impl_.SetAlternativeServiceProbabilityThreshold(0.25);
+ impl_.SetAlternativeServiceProbabilityThreshold(0.5);
HostPortPair test_host_port_pair("foo", 80);
- const AlternativeService alternative_service(NPN_SPDY_4, "foo", 443);
- impl_.SetAlternativeService(test_host_port_pair, alternative_service, 0.5);
+ const AlternativeService alternative_service1(NPN_SPDY_4, "foo", 443);
+ impl_.AddAlternativeService(test_host_port_pair, alternative_service1, 0.3);
+
+ EXPECT_FALSE(HasAlternativeService(test_host_port_pair));
+
+ const AlternativeService alternative_service2(QUIC, "bar", 123);
+ impl_.AddAlternativeService(test_host_port_pair, alternative_service2, 0.7);
+ const AlternativeService alternative_service3(NPN_SPDY_3_1, "baz", 443);
+ impl_.AddAlternativeService(test_host_port_pair, alternative_service3, 0.4);
+ const AlternativeService alternative_service4(NPN_SPDY_4, "qux", 1234);
+ impl_.AddAlternativeService(test_host_port_pair, alternative_service4, 0.6);
+
EXPECT_TRUE(HasAlternativeService(test_host_port_pair));
- AlternativeServiceMap::const_iterator it =
- impl_.alternative_service_map().Peek(test_host_port_pair);
- ASSERT_TRUE(it != impl_.alternative_service_map().end());
- EXPECT_EQ(443, it->second.alternative_service.port);
- EXPECT_EQ(NPN_SPDY_4, it->second.alternative_service.protocol);
- EXPECT_EQ(0.5, it->second.probability);
+ const AlternativeServiceVector alternative_service_vector =
+ impl_.GetAlternativeServices(test_host_port_pair);
+ ASSERT_EQ(2u, alternative_service_vector.size());
+ EXPECT_EQ(alternative_service2, alternative_service_vector[0]);
+ EXPECT_EQ(alternative_service4, alternative_service_vector[1]);
}
TEST_F(AlternateProtocolServerPropertiesTest, ProbabilityExcluded) {
@@ -286,43 +305,100 @@ TEST_F(AlternateProtocolServerPropertiesTest, ProbabilityExcluded) {
HostPortPair test_host_port_pair("foo", 80);
const AlternativeService alternative_service(NPN_SPDY_4, "foo", 443);
- impl_.SetAlternativeService(test_host_port_pair, alternative_service, 0.5);
+ impl_.AddAlternativeService(test_host_port_pair, alternative_service, 0.5);
EXPECT_FALSE(HasAlternativeService(test_host_port_pair));
}
TEST_F(AlternateProtocolServerPropertiesTest, Initialize) {
+ // |test_host_port_pair1| has one alternative service, which is non-broken,
+ // and thus will be removed by InitializeAlternativeServiceServers().
HostPortPair test_host_port_pair1("foo1", 80);
- const AlternativeService alternative_service1(NPN_SPDY_4, "foo1", 443);
- impl_.SetAlternativeService(test_host_port_pair1, alternative_service1, 1.0);
- impl_.MarkAlternativeServiceBroken(alternative_service1);
+ const AlternativeService alternative_service1(NPN_SPDY_4, "bar1", 443);
+ impl_.AddAlternativeService(test_host_port_pair1, alternative_service1, 1.0);
+ // |test_host_port_pair2| has two alternative services. The broken one will
+ // remain, the non-broken one will be removed by
+ // InitializeAlternativeServiceServers().
HostPortPair test_host_port_pair2("foo2", 80);
- const AlternativeService alternative_service2(NPN_SPDY_4, "foo2", 443);
- impl_.SetAlternativeService(test_host_port_pair2, alternative_service2, 1.0);
-
+ const AlternativeService alternative_service2(NPN_SPDY_3_1, "bar2", 443);
+ impl_.AddAlternativeService(test_host_port_pair2, alternative_service2, 1.0);
+ impl_.MarkAlternativeServiceBroken(alternative_service2);
+ const AlternativeService alternative_service3(NPN_SPDY_3_1, "bar3", 1234);
+ impl_.AddAlternativeService(test_host_port_pair2, alternative_service3, 0.8);
+
+ // Prepare |alternative_service_map| to be loaded by
+ // InitializeAlternativeServiceServers().
AlternativeServiceMap alternative_service_map(
AlternativeServiceMap::NO_AUTO_EVICT);
- AlternativeServiceInfo alternative_service_info(NPN_SPDY_4, "bar", 123, 1.0);
- alternative_service_map.Put(test_host_port_pair2, alternative_service_info);
+ const AlternativeService alternative_service4(NPN_SPDY_4, "bar4", 123);
+ const AlternativeServiceInfo alternative_service_info1(alternative_service4,
+ 0.7);
+ alternative_service_map.Put(
+ test_host_port_pair2,
+ AlternativeServiceInfoVector(/*size=*/1, alternative_service_info1));
+
HostPortPair test_host_port_pair3("foo3", 80);
- alternative_service_info.alternative_service.port = 1234;
- alternative_service_map.Put(test_host_port_pair3, alternative_service_info);
+ const AlternativeService alternative_service5(NPN_SPDY_4, "bar5", 1234);
+ const AlternativeServiceInfo alternative_service_info2(alternative_service5,
+ 0.2);
+ alternative_service_map.Put(
+ test_host_port_pair3,
+ AlternativeServiceInfoVector(/*size=*/1, alternative_service_info2));
+
impl_.InitializeAlternativeServiceServers(&alternative_service_map);
- // Verify test_host_port_pair3 is the MRU server.
+ // Verify alternative_service_map.
const AlternativeServiceMap& map = impl_.alternative_service_map();
- AlternativeServiceMap::const_iterator it = map.begin();
- ASSERT_TRUE(it != map.end());
- EXPECT_TRUE(it->first.Equals(test_host_port_pair3));
- EXPECT_EQ(NPN_SPDY_4, it->second.alternative_service.protocol);
- EXPECT_EQ(1234, it->second.alternative_service.port);
+ ASSERT_EQ(2u, map.size());
+ AlternativeServiceMap::const_iterator map_it = map.begin();
+ EXPECT_TRUE(map_it->first.Equals(test_host_port_pair3));
+ ASSERT_EQ(1u, map_it->second.size());
+ EXPECT_EQ(alternative_service5, map_it->second[0].alternative_service);
+ EXPECT_EQ(0.2, map_it->second[0].probability);
+ ++map_it;
+ EXPECT_TRUE(map_it->first.Equals(test_host_port_pair2));
+ ASSERT_EQ(2u, map_it->second.size());
+ EXPECT_EQ(alternative_service2, map_it->second[0].alternative_service);
+ EXPECT_EQ(1.0, map_it->second[0].probability);
+ EXPECT_EQ(alternative_service4, map_it->second[1].alternative_service);
+ EXPECT_EQ(0.7, map_it->second[1].probability);
+}
+
+TEST_F(AlternateProtocolServerPropertiesTest, AddAlternativeService) {
+ const HostPortPair host_port_pair("foo", 443);
+ const AlternativeService alternative_service1(NPN_SPDY_4, "bar", 123);
+ impl_.AddAlternativeService(host_port_pair, alternative_service1, 1.0);
- ASSERT_TRUE(HasAlternativeService(test_host_port_pair1));
- EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1));
- const AlternativeService alternative_service =
- impl_.GetAlternativeService(test_host_port_pair2);
- EXPECT_EQ(NPN_SPDY_4, alternative_service.protocol);
- EXPECT_EQ(123, alternative_service.port);
+ const AlternativeServiceMap& map = impl_.alternative_service_map();
+ AlternativeServiceMap::const_iterator map_it = map.begin();
+ ASSERT_EQ("foo", map_it->first.host());
+ EXPECT_EQ(1u, map_it->second.size());
+ EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service);
+ EXPECT_EQ(1.0, map_it->second[0].probability);
+
+ // Same alternative service with same probability should cause no change.
+ impl_.AddAlternativeService(host_port_pair, alternative_service1, 1.0);
+ EXPECT_EQ(1u, map_it->second.size());
+ EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service);
+ EXPECT_EQ(1.0, map_it->second[0].probability);
+
+ // Same alternative service with different probability should overwrite.
+ impl_.AddAlternativeService(host_port_pair, alternative_service1, 0.8);
+ EXPECT_EQ(1u, map_it->second.size());
+ EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service);
+ EXPECT_EQ(0.8, map_it->second[0].probability);
+
+ // Different alternative service should be added.
+ const AlternativeService alternative_service2(QUIC, "", 123);
+ impl_.AddAlternativeService(host_port_pair, alternative_service2, 0.2);
+ EXPECT_EQ(2u, map_it->second.size());
+ EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service);
+ EXPECT_EQ(0.8, map_it->second[0].probability);
+ EXPECT_EQ(alternative_service2, map_it->second[1].alternative_service);
+ EXPECT_EQ(0.2, map_it->second[1].probability);
+
+ impl_.ClearAlternativeServices(host_port_pair);
+ EXPECT_EQ(0u, map.size());
}
// Regression test for https://crbug.com/504032:
@@ -334,7 +410,7 @@ TEST_F(AlternateProtocolServerPropertiesTest, InitializeWithEmptyHostname) {
"", 1234);
const AlternativeService alternative_service_with_foo_hostname(NPN_SPDY_4,
"foo", 1234);
- impl_.SetAlternativeService(host_port_pair,
+ impl_.AddAlternativeService(host_port_pair,
alternative_service_with_empty_hostname, 1.0);
impl_.MarkAlternativeServiceBroken(alternative_service_with_foo_hostname);
@@ -344,88 +420,140 @@ TEST_F(AlternateProtocolServerPropertiesTest, InitializeWithEmptyHostname) {
EXPECT_TRUE(
impl_.IsAlternativeServiceBroken(alternative_service_with_foo_hostname));
- EXPECT_TRUE(impl_.GetAlternativeService(host_port_pair) ==
- alternative_service_with_foo_hostname);
+ const AlternativeServiceVector alternative_service_vector =
+ impl_.GetAlternativeServices(host_port_pair);
+ ASSERT_EQ(1u, alternative_service_vector.size());
+ EXPECT_EQ(alternative_service_with_foo_hostname,
+ alternative_service_vector[0]);
}
-TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) {
+TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternativeServices) {
HostPortPair test_host_port_pair1("foo1", 80);
- const AlternativeService alternative_service1(NPN_SPDY_4, "foo1", 443);
- impl_.SetAlternativeService(test_host_port_pair1, alternative_service1, 1.0);
+ const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo1", 443);
+ impl_.AddAlternativeService(test_host_port_pair1, alternative_service1, 1.0);
HostPortPair test_host_port_pair2("foo2", 80);
const AlternativeService alternative_service2(NPN_SPDY_4, "foo2", 1234);
- impl_.SetAlternativeService(test_host_port_pair2, alternative_service2, 1.0);
+ impl_.AddAlternativeService(test_host_port_pair2, alternative_service2, 1.0);
const AlternativeServiceMap& map = impl_.alternative_service_map();
AlternativeServiceMap::const_iterator it = map.begin();
EXPECT_TRUE(it->first.Equals(test_host_port_pair2));
- EXPECT_EQ(NPN_SPDY_4, it->second.alternative_service.protocol);
- EXPECT_EQ(1234, it->second.alternative_service.port);
-
- // GetAlternativeService should reorder the AlternateProtocol map.
- const AlternativeService alternative_service =
- impl_.GetAlternativeService(test_host_port_pair1);
- EXPECT_EQ(443, alternative_service.port);
- EXPECT_EQ(NPN_SPDY_4, alternative_service.protocol);
+ ASSERT_EQ(1u, it->second.size());
+ EXPECT_EQ(alternative_service2, it->second[0].alternative_service);
+
+ const AlternativeServiceVector alternative_service_vector =
+ impl_.GetAlternativeServices(test_host_port_pair1);
+ ASSERT_EQ(1u, alternative_service_vector.size());
+ EXPECT_EQ(alternative_service1, alternative_service_vector[0]);
+
+ // GetAlternativeServices should reorder the AlternateProtocol map.
it = map.begin();
EXPECT_TRUE(it->first.Equals(test_host_port_pair1));
- EXPECT_EQ(NPN_SPDY_4, it->second.alternative_service.protocol);
- EXPECT_EQ(443, it->second.alternative_service.port);
+ ASSERT_EQ(1u, it->second.size());
+ EXPECT_EQ(alternative_service1, it->second[0].alternative_service);
}
TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) {
HostPortPair test_host_port_pair("foo", 80);
const AlternativeService alternative_service1(NPN_SPDY_4, "foo", 443);
- impl_.SetAlternativeService(test_host_port_pair, alternative_service1, 1.0);
+ impl_.AddAlternativeService(test_host_port_pair, alternative_service1, 1.0);
+ AlternativeServiceVector alternative_service_vector =
+ impl_.GetAlternativeServices(test_host_port_pair);
+ ASSERT_EQ(1u, alternative_service_vector.size());
+ EXPECT_EQ(alternative_service1, alternative_service_vector[0]);
+ EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service1));
+
+ // GetAlternativeServices should return broken alternative services as well.
impl_.MarkAlternativeServiceBroken(alternative_service1);
- ASSERT_TRUE(HasAlternativeService(test_host_port_pair));
+ alternative_service_vector =
+ impl_.GetAlternativeServices(test_host_port_pair);
+ ASSERT_EQ(1u, alternative_service_vector.size());
+ EXPECT_EQ(alternative_service1, alternative_service_vector[0]);
EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1));
+ // AddAlternativeService should not change anything.
+ impl_.AddAlternativeService(test_host_port_pair, alternative_service1, 1.0);
+ alternative_service_vector =
+ impl_.GetAlternativeServices(test_host_port_pair);
+ ASSERT_EQ(1u, alternative_service_vector.size());
+ EXPECT_EQ(alternative_service1, alternative_service_vector[0]);
+ EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0]));
+
+ // When adding another alternative service, the broken one should remain in
+ // the mapping.
const AlternativeService alternative_service2(NPN_SPDY_4, "foo", 1234);
- impl_.SetAlternativeService(test_host_port_pair, alternative_service2, 1.0);
- EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1));
- EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service2));
- EXPECT_EQ(1234, impl_.GetAlternativeService(test_host_port_pair).port);
+ impl_.AddAlternativeService(test_host_port_pair, alternative_service2, 1.0);
+ alternative_service_vector =
+ impl_.GetAlternativeServices(test_host_port_pair);
+ ASSERT_EQ(2u, alternative_service_vector.size());
+ EXPECT_EQ(alternative_service1, alternative_service_vector[0]);
+ EXPECT_EQ(alternative_service2, alternative_service_vector[1]);
+ EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0]));
+ EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service_vector[1]));
+}
+
+TEST_F(AlternateProtocolServerPropertiesTest, ClearAlternativeServices) {
+ HostPortPair test_host_port_pair("foo", 80);
+ const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443);
+ const AlternativeService alternative_service2(NPN_SPDY_4, "bar", 1234);
+ impl_.AddAlternativeService(test_host_port_pair, alternative_service1, 1.0);
+ impl_.AddAlternativeService(test_host_port_pair, alternative_service2, 1.0);
+
+ const net::AlternativeServiceMap& map = impl_.alternative_service_map();
+ net::AlternativeServiceMap::const_iterator it = map.begin();
+ EXPECT_TRUE(it->first.Equals(test_host_port_pair));
+ ASSERT_EQ(2u, it->second.size());
+ EXPECT_EQ(alternative_service1, it->second[0].alternative_service);
+ EXPECT_EQ(alternative_service2, it->second[1].alternative_service);
+
+ impl_.ClearAlternativeServices(test_host_port_pair);
+ EXPECT_EQ(0u, map.size());
}
// A broken alternative service in the mapping carries meaningful information,
-// therefore it should not be ignored by SetAlternativeService(). In
+// therefore it should not be ignored by AddAlternativeService(). In
// particular, an alternative service mapped to an origin shadows alternative
// services of canonical hosts.
TEST_F(AlternateProtocolServerPropertiesTest, BrokenShadowsCanonical) {
HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
- HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
- AlternativeService canonical_altsvc(QUIC, "bar.c.youtube.com", 1234);
- impl_.SetAlternativeService(canonical_port_pair, canonical_altsvc, 1.0);
- EXPECT_TRUE(impl_.GetAlternativeService(test_host_port_pair) ==
- canonical_altsvc);
+ HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80);
+ AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com",
+ 1234);
+ impl_.AddAlternativeService(canonical_host_port_pair,
+ canonical_alternative_service, 1.0);
+ AlternativeServiceVector alternative_service_vector =
+ impl_.GetAlternativeServices(test_host_port_pair);
+ ASSERT_EQ(1u, alternative_service_vector.size());
+ EXPECT_EQ(canonical_alternative_service, alternative_service_vector[0]);
const AlternativeService broken_alternative_service(NPN_SPDY_4, "foo", 443);
impl_.MarkAlternativeServiceBroken(broken_alternative_service);
EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service));
- impl_.SetAlternativeService(test_host_port_pair, broken_alternative_service,
+ impl_.AddAlternativeService(test_host_port_pair, broken_alternative_service,
1.0);
- ASSERT_EQ(broken_alternative_service,
- impl_.GetAlternativeService(test_host_port_pair));
+ alternative_service_vector =
+ impl_.GetAlternativeServices(test_host_port_pair);
+ ASSERT_EQ(1u, alternative_service_vector.size());
+ EXPECT_EQ(broken_alternative_service, alternative_service_vector[0]);
EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service));
}
TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) {
HostPortPair test_host_port_pair("foo", 80);
const AlternativeService alternative_service(NPN_SPDY_4, "foo", 443);
- impl_.SetAlternativeService(test_host_port_pair, alternative_service, 1.0);
+ impl_.AddAlternativeService(test_host_port_pair, alternative_service, 1.0);
impl_.MarkAlternativeServiceBroken(alternative_service);
ASSERT_TRUE(HasAlternativeService(test_host_port_pair));
EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service));
- impl_.ClearAlternativeService(test_host_port_pair);
+ impl_.ClearAlternativeServices(test_host_port_pair);
EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service));
}
TEST_F(AlternateProtocolServerPropertiesTest, MarkRecentlyBroken) {
HostPortPair host_port_pair("foo", 80);
const AlternativeService alternative_service(NPN_SPDY_4, "foo", 443);
- impl_.SetAlternativeService(host_port_pair, alternative_service, 1.0);
+ impl_.AddAlternativeService(host_port_pair, alternative_service, 1.0);
EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service));
EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service));
@@ -443,51 +571,51 @@ TEST_F(AlternateProtocolServerPropertiesTest, Canonical) {
HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
EXPECT_FALSE(HasAlternativeService(test_host_port_pair));
- HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
- EXPECT_FALSE(HasAlternativeService(canonical_port_pair));
-
- AlternativeService canonical_altsvc(QUIC, "bar.c.youtube.com", 1234);
- impl_.SetAlternativeService(canonical_port_pair, canonical_altsvc, 1.0);
- // Verify the forced protocol.
- ASSERT_TRUE(HasAlternativeService(test_host_port_pair));
- const AlternativeService alternative_service =
- impl_.GetAlternativeService(test_host_port_pair);
- EXPECT_EQ(canonical_altsvc.port, alternative_service.port);
- EXPECT_EQ(canonical_altsvc.protocol, alternative_service.protocol);
+ HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80);
+ EXPECT_FALSE(HasAlternativeService(canonical_host_port_pair));
+
+ const AlternativeService canonical_alternative_service1(
+ QUIC, "bar.c.youtube.com", 1234);
+ impl_.AddAlternativeService(canonical_host_port_pair,
+ canonical_alternative_service1, 1.0);
+ const AlternativeService canonical_alternative_service2(NPN_SPDY_4, "", 443);
+ impl_.AddAlternativeService(canonical_host_port_pair,
+ canonical_alternative_service2, 1.0);
+
+ // Since |test_host_port_pair| does not have an alternative service itself,
+ // GetAlternativeServices should return those of |canonical_host_port_pair|.
+ AlternativeServiceVector alternative_service_vector =
+ impl_.GetAlternativeServices(test_host_port_pair);
+ ASSERT_EQ(2u, alternative_service_vector.size());
+ EXPECT_EQ(canonical_alternative_service1, alternative_service_vector[0]);
+
+ // Since |canonical_alternative_service2| has an empty host,
+ // GetAlternativeServices should substitute the hostname of its |origin|
+ // argument.
+ EXPECT_EQ(test_host_port_pair.host(), alternative_service_vector[1].host);
+ EXPECT_EQ(canonical_alternative_service2.protocol,
+ alternative_service_vector[1].protocol);
+ EXPECT_EQ(canonical_alternative_service2.port,
+ alternative_service_vector[1].port);
// Verify the canonical suffix.
EXPECT_EQ(".c.youtube.com",
impl_.GetCanonicalSuffix(test_host_port_pair.host()));
EXPECT_EQ(".c.youtube.com",
- impl_.GetCanonicalSuffix(canonical_port_pair.host()));
-}
-
-TEST_F(AlternateProtocolServerPropertiesTest, CanonicalDefaultHost) {
- HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
- EXPECT_FALSE(HasAlternativeService(test_host_port_pair));
-
- HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
- EXPECT_FALSE(HasAlternativeService(canonical_port_pair));
-
- AlternativeService canonical_altsvc(QUIC, "", 1234);
- impl_.SetAlternativeService(canonical_port_pair, canonical_altsvc, 1.0);
- ASSERT_TRUE(HasAlternativeService(test_host_port_pair));
- const AlternativeService alternative_service =
- impl_.GetAlternativeService(test_host_port_pair);
- EXPECT_EQ(canonical_altsvc.protocol, alternative_service.protocol);
- EXPECT_EQ(test_host_port_pair.host(), alternative_service.host);
- EXPECT_EQ(canonical_altsvc.port, alternative_service.port);
+ impl_.GetCanonicalSuffix(canonical_host_port_pair.host()));
}
TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBelowThreshold) {
impl_.SetAlternativeServiceProbabilityThreshold(0.02);
HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
- HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
- AlternativeService canonical_altsvc(QUIC, "bar.c.youtube.com", 1234);
+ HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80);
+ AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com",
+ 1234);
- impl_.SetAlternativeService(canonical_port_pair, canonical_altsvc, 0.01);
- EXPECT_FALSE(HasAlternativeService(canonical_port_pair));
+ impl_.AddAlternativeService(canonical_host_port_pair,
+ canonical_alternative_service, 0.01);
+ EXPECT_FALSE(HasAlternativeService(canonical_host_port_pair));
EXPECT_FALSE(HasAlternativeService(test_host_port_pair));
}
@@ -495,31 +623,37 @@ TEST_F(AlternateProtocolServerPropertiesTest, CanonicalAboveThreshold) {
impl_.SetAlternativeServiceProbabilityThreshold(0.02);
HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
- HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
- AlternativeService canonical_altsvc(QUIC, "bar.c.youtube.com", 1234);
+ HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80);
+ AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com",
+ 1234);
- impl_.SetAlternativeService(canonical_port_pair, canonical_altsvc, 0.03);
- EXPECT_TRUE(HasAlternativeService(canonical_port_pair));
+ impl_.AddAlternativeService(canonical_host_port_pair,
+ canonical_alternative_service, 0.03);
+ EXPECT_TRUE(HasAlternativeService(canonical_host_port_pair));
EXPECT_TRUE(HasAlternativeService(test_host_port_pair));
}
TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) {
HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
- HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
- AlternativeService canonical_altsvc(QUIC, "bar.c.youtube.com", 1234);
+ HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80);
+ AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com",
+ 1234);
- impl_.SetAlternativeService(canonical_port_pair, canonical_altsvc, 1.0);
- impl_.ClearAlternativeService(canonical_port_pair);
+ impl_.AddAlternativeService(canonical_host_port_pair,
+ canonical_alternative_service, 1.0);
+ impl_.ClearAlternativeServices(canonical_host_port_pair);
EXPECT_FALSE(HasAlternativeService(test_host_port_pair));
}
TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) {
HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
- HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
- AlternativeService canonical_altsvc(QUIC, "bar.c.youtube.com", 1234);
+ HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80);
+ AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com",
+ 1234);
- impl_.SetAlternativeService(canonical_port_pair, canonical_altsvc, 1.0);
- impl_.MarkAlternativeServiceBroken(canonical_altsvc);
+ impl_.AddAlternativeService(canonical_host_port_pair,
+ canonical_alternative_service, 1.0);
+ impl_.MarkAlternativeServiceBroken(canonical_alternative_service);
EXPECT_FALSE(HasAlternativeService(test_host_port_pair));
}
@@ -528,23 +662,29 @@ TEST_F(AlternateProtocolServerPropertiesTest, CanonicalOverride) {
HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
HostPortPair bar_host_port_pair("bar.c.youtube.com", 80);
AlternativeService bar_alternative_service(QUIC, "bar.c.youtube.com", 1234);
- impl_.SetAlternativeService(bar_host_port_pair, bar_alternative_service, 1.0);
- AlternativeService altsvc = impl_.GetAlternativeService(test_host_port_pair);
- EXPECT_EQ(1234, altsvc.port);
+ impl_.AddAlternativeService(bar_host_port_pair, bar_alternative_service, 1.0);
+ AlternativeServiceVector alternative_service_vector =
+ impl_.GetAlternativeServices(test_host_port_pair);
+ ASSERT_EQ(1u, alternative_service_vector.size());
+ EXPECT_EQ(bar_alternative_service, alternative_service_vector[0]);
HostPortPair qux_host_port_pair("qux.c.youtube.com", 80);
AlternativeService qux_alternative_service(QUIC, "qux.c.youtube.com", 443);
- impl_.SetAlternativeService(qux_host_port_pair, qux_alternative_service, 1.0);
- altsvc = impl_.GetAlternativeService(test_host_port_pair);
- EXPECT_EQ(443, altsvc.port);
+ impl_.AddAlternativeService(qux_host_port_pair, qux_alternative_service, 1.0);
+ alternative_service_vector =
+ impl_.GetAlternativeServices(test_host_port_pair);
+ ASSERT_EQ(1u, alternative_service_vector.size());
+ EXPECT_EQ(qux_alternative_service, alternative_service_vector[0]);
}
TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) {
HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
- HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
- AlternativeService canonical_altsvc(QUIC, "bar.c.youtube.com", 1234);
+ HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80);
+ AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com",
+ 1234);
- impl_.SetAlternativeService(canonical_port_pair, canonical_altsvc, 1.0);
+ impl_.AddAlternativeService(canonical_host_port_pair,
+ canonical_alternative_service, 1.0);
impl_.Clear();
EXPECT_FALSE(HasAlternativeService(test_host_port_pair));
}
@@ -553,7 +693,7 @@ TEST_F(AlternateProtocolServerPropertiesTest,
ExpireBrokenAlternateProtocolMappings) {
HostPortPair host_port_pair("foo", 443);
AlternativeService alternative_service(QUIC, "foo", 443);
- impl_.SetAlternativeService(host_port_pair, alternative_service, 1.0);
+ impl_.AddAlternativeService(host_port_pair, alternative_service, 1.0);
EXPECT_TRUE(HasAlternativeService(host_port_pair));
EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service));
EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service));

Powered by Google App Engine
This is Rietveld 408576698