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

Unified Diff: net/http/http_server_properties_impl_unittest.cc

Issue 665083009: ABANDONED Handle multiple AlternateProtocols for each HostPortPair. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Custom entries for broken_alternate_protocol_list_ and map_. Created 5 years, 11 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_impl.cc ('k') | net/http/http_server_properties_manager.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1675833881861ccfe32357e2248d7f3943e107f3..3b527c3f2a3f50344f76e63fabec5d8139ae7040 100644
--- a/net/http/http_server_properties_impl_unittest.cc
+++ b/net/http/http_server_properties_impl_unittest.cc
@@ -237,8 +237,7 @@ typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest;
TEST_F(AlternateProtocolServerPropertiesTest, Basic) {
HostPortPair test_host_port_pair("foo", 80);
EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
- impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1);
- ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
+ impl_.AddAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1);
const AlternateProtocolInfo alternate =
impl_.GetAlternateProtocol(test_host_port_pair);
EXPECT_EQ(443, alternate.port);
@@ -250,7 +249,7 @@ TEST_F(AlternateProtocolServerPropertiesTest, Basic) {
TEST_F(AlternateProtocolServerPropertiesTest, DefaultProbabilityExcluded) {
HostPortPair test_host_port_pair("foo", 80);
- impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .99);
+ impl_.AddAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .99);
EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
}
@@ -259,9 +258,8 @@ TEST_F(AlternateProtocolServerPropertiesTest, Probability) {
impl_.SetAlternateProtocolProbabilityThreshold(.25);
HostPortPair test_host_port_pair("foo", 80);
- impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .5);
+ impl_.AddAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .5);
- ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
const AlternateProtocolInfo alternate =
impl_.GetAlternateProtocol(test_host_port_pair);
EXPECT_EQ(443, alternate.port);
@@ -274,38 +272,39 @@ TEST_F(AlternateProtocolServerPropertiesTest, ProbabilityExcluded) {
HostPortPair test_host_port_pair("foo", 80);
- impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .5);
+ impl_.AddAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .5);
EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
}
TEST_F(AlternateProtocolServerPropertiesTest, Initialize) {
HostPortPair test_host_port_pair1("foo1", 80);
- impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1);
- impl_.SetBrokenAlternateProtocol(test_host_port_pair1);
+ impl_.AddAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1);
+ impl_.AddAlternateProtocol(test_host_port_pair1, 123, NPN_SPDY_3, 1);
+ AlternateProtocolInfo alternate_protocol(123, NPN_SPDY_3, 1);
+ impl_.SetBrokenAlternateProtocol(test_host_port_pair1, alternate_protocol);
HostPortPair test_host_port_pair2("foo2", 80);
- impl_.SetAlternateProtocol(test_host_port_pair2, 443, NPN_SPDY_3, 1);
+ impl_.AddAlternateProtocol(test_host_port_pair2, 443, NPN_SPDY_3, 1);
AlternateProtocolMap alternate_protocol_map(
AlternateProtocolMap::NO_AUTO_EVICT);
AlternateProtocolInfo alternate(123, NPN_SPDY_3, 1);
- alternate_protocol_map.Put(test_host_port_pair2, alternate);
+ alternate_protocol_map.Put(test_host_port_pair2,
+ AlternateProtocols(/*size=*/1, alternate));
HostPortPair test_host_port_pair3("foo3", 80);
alternate.port = 1234;
- alternate_protocol_map.Put(test_host_port_pair3, alternate);
+ alternate_protocol_map.Put(test_host_port_pair3,
+ AlternateProtocols(/*size=*/1, alternate));
impl_.InitializeAlternateProtocolServers(&alternate_protocol_map);
// Verify test_host_port_pair3 is the MRU server.
const AlternateProtocolMap& map = impl_.alternate_protocol_map();
AlternateProtocolMap::const_iterator it = map.begin();
- it = map.begin();
EXPECT_TRUE(it->first.Equals(test_host_port_pair3));
- EXPECT_EQ(1234, it->second.port);
- EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
+ ASSERT_EQ(1u, it->second.size());
+ EXPECT_EQ(1234, it->second[0].port);
+ EXPECT_EQ(NPN_SPDY_3, it->second[0].protocol);
- ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1));
- ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair2));
- alternate = impl_.GetAlternateProtocol(test_host_port_pair1);
- EXPECT_TRUE(alternate.is_broken);
+ ASSERT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair1));
alternate = impl_.GetAlternateProtocol(test_host_port_pair2);
EXPECT_EQ(123, alternate.port);
EXPECT_EQ(NPN_SPDY_3, alternate.protocol);
@@ -313,75 +312,133 @@ TEST_F(AlternateProtocolServerPropertiesTest, Initialize) {
TEST_F(AlternateProtocolServerPropertiesTest, MRUOfHasAlternateProtocol) {
HostPortPair test_host_port_pair1("foo1", 80);
- impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1);
+ impl_.AddAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1);
HostPortPair test_host_port_pair2("foo2", 80);
- impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1);
+ impl_.AddAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1);
const AlternateProtocolMap& map = impl_.alternate_protocol_map();
AlternateProtocolMap::const_iterator it = map.begin();
EXPECT_TRUE(it->first.Equals(test_host_port_pair2));
- EXPECT_EQ(1234, it->second.port);
- EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
+ ASSERT_EQ(1u, it->second.size());
+ EXPECT_EQ(1234, it->second[0].port);
+ EXPECT_EQ(NPN_SPDY_3, it->second[0].protocol);
// HasAlternateProtocol should reoder the AlternateProtocol map.
ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1));
it = map.begin();
EXPECT_TRUE(it->first.Equals(test_host_port_pair1));
- EXPECT_EQ(443, it->second.port);
- EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
+ ASSERT_EQ(1u, it->second.size());
+ EXPECT_EQ(443, it->second[0].port);
+ EXPECT_EQ(NPN_SPDY_3, it->second[0].protocol);
}
TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) {
HostPortPair test_host_port_pair1("foo1", 80);
- impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1);
+ impl_.AddAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1);
HostPortPair test_host_port_pair2("foo2", 80);
- impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1);
+ impl_.AddAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1);
const AlternateProtocolMap& map = impl_.alternate_protocol_map();
AlternateProtocolMap::const_iterator it = map.begin();
EXPECT_TRUE(it->first.Equals(test_host_port_pair2));
- EXPECT_EQ(1234, it->second.port);
- EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
+ ASSERT_EQ(1u, it->second.size());
+ EXPECT_EQ(1234, it->second[0].port);
+ EXPECT_EQ(NPN_SPDY_3, it->second[0].protocol);
- // GetAlternateProtocol should reoder the AlternateProtocol map.
+ // GetAlternateProtocol should reorder the AlternateProtocol map.
AlternateProtocolInfo alternate =
impl_.GetAlternateProtocol(test_host_port_pair1);
EXPECT_EQ(443, alternate.port);
EXPECT_EQ(NPN_SPDY_3, alternate.protocol);
it = map.begin();
EXPECT_TRUE(it->first.Equals(test_host_port_pair1));
- EXPECT_EQ(443, it->second.port);
- EXPECT_EQ(NPN_SPDY_3, it->second.protocol);
+ ASSERT_EQ(1u, it->second.size());
+ EXPECT_EQ(443, it->second[0].port);
+ EXPECT_EQ(NPN_SPDY_3, it->second[0].protocol);
+}
+
+TEST_F(AlternateProtocolServerPropertiesTest, RemoveForSingleHost) {
+ HostPortPair test_host_port_pair("foo", 80);
+ impl_.AddAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1);
+ impl_.AddAlternateProtocol(test_host_port_pair, 1234, NPN_SPDY_3, 1);
+
+ const net::AlternateProtocolMap& map = impl_.alternate_protocol_map();
+ net::AlternateProtocolMap::const_iterator it = map.begin();
+ EXPECT_TRUE(it->first.Equals(test_host_port_pair));
+ ASSERT_EQ(2u, it->second.size());
+ EXPECT_EQ(443, it->second[0].port);
+ EXPECT_EQ(1234, it->second[1].port);
+
+ // Adding an identical entry does nothing.
+ impl_.AddAlternateProtocol(test_host_port_pair, 1234, NPN_SPDY_3, 1);
+ it = map.begin();
+ ASSERT_EQ(2u, it->second.size());
+
+ // Add a third one.
+ impl_.AddAlternateProtocol(test_host_port_pair, 123, NPN_SPDY_3, 1);
+ it = map.begin();
+ ASSERT_EQ(3u, it->second.size());
+ EXPECT_EQ(123, it->second[2].port);
+
+ // Remove one by one.
+ impl_.RemoveAlternateProtocol(test_host_port_pair,
+ AlternateProtocolInfo(1234, NPN_SPDY_3, 1));
+ it = map.begin();
+ ASSERT_EQ(2u, it->second.size());
+ EXPECT_EQ(443, it->second[0].port);
+ EXPECT_EQ(123, it->second[1].port);
+
+ impl_.RemoveAlternateProtocol(test_host_port_pair,
+ AlternateProtocolInfo(443, NPN_SPDY_3, 1));
+ it = map.begin();
+ ASSERT_EQ(1u, it->second.size());
+ EXPECT_EQ(123, it->second[0].port);
+
+ impl_.RemoveAlternateProtocol(test_host_port_pair,
+ AlternateProtocolInfo(123, NPN_SPDY_3, 1));
+ ASSERT_EQ(0u, impl_.alternate_protocol_map().size());
+}
+
+TEST_F(AlternateProtocolServerPropertiesTest, ClearAlternateProtocol) {
+ HostPortPair test_host_port_pair("foo", 80);
+ impl_.AddAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1);
+ impl_.AddAlternateProtocol(test_host_port_pair, 1234, NPN_SPDY_3, 1);
+
+ const net::AlternateProtocolMap& map = impl_.alternate_protocol_map();
+ net::AlternateProtocolMap::const_iterator it = map.begin();
+ EXPECT_TRUE(it->first.Equals(test_host_port_pair));
+ ASSERT_EQ(2u, it->second.size());
+ EXPECT_EQ(443, it->second[0].port);
+ EXPECT_EQ(1234, it->second[1].port);
+
+ impl_.ClearAlternateProtocol(test_host_port_pair);
+ EXPECT_EQ(0u, impl_.alternate_protocol_map().size());
}
TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) {
HostPortPair test_host_port_pair("foo", 80);
- impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1);
- impl_.SetBrokenAlternateProtocol(test_host_port_pair);
- ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
- AlternateProtocolInfo alternate =
- impl_.GetAlternateProtocol(test_host_port_pair);
- EXPECT_TRUE(alternate.is_broken);
+ impl_.AddAlternateProtocol(test_host_port_pair, 123, NPN_SPDY_3, 1);
+ AlternateProtocolInfo alternate(123, NPN_SPDY_3, 1);
+ impl_.SetBrokenAlternateProtocol(test_host_port_pair, alternate);
+ ASSERT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
- impl_.SetAlternateProtocol(
- test_host_port_pair,
- 1234,
- NPN_SPDY_3,
- 1);
+ impl_.AddAlternateProtocol(test_host_port_pair, 123, NPN_SPDY_3, 1);
alternate = impl_.GetAlternateProtocol(test_host_port_pair);
- EXPECT_TRUE(alternate.is_broken) << "Second attempt should be ignored.";
+ ASSERT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair))
+ << "Second attempt should be ignored.";
}
TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) {
HostPortPair test_host_port_pair("foo", 80);
- impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1);
- impl_.SetBrokenAlternateProtocol(test_host_port_pair);
- ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
- AlternateProtocolInfo alternate =
- impl_.GetAlternateProtocol(test_host_port_pair);
- EXPECT_TRUE(alternate.is_broken);
+ impl_.AddAlternateProtocol(test_host_port_pair, 123, NPN_SPDY_3, 1);
+ AlternateProtocolInfo alternate(123, NPN_SPDY_3, 1);
+ impl_.SetBrokenAlternateProtocol(test_host_port_pair, alternate);
+ ASSERT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
impl_.ClearAlternateProtocol(test_host_port_pair);
EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
+ impl_.AddAlternateProtocol(test_host_port_pair, 123, NPN_SPDY_3, 1);
+ alternate = impl_.GetAlternateProtocol(test_host_port_pair);
+ EXPECT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
}
TEST_F(AlternateProtocolServerPropertiesTest, Forced) {
@@ -392,15 +449,13 @@ TEST_F(AlternateProtocolServerPropertiesTest, Forced) {
// Verify the forced protocol.
HostPortPair test_host_port_pair("foo", 80);
- EXPECT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
AlternateProtocolInfo alternate =
impl_.GetAlternateProtocol(test_host_port_pair);
EXPECT_EQ(default_protocol.port, alternate.port);
EXPECT_EQ(default_protocol.protocol, alternate.protocol);
// Verify the real protocol overrides the forced protocol.
- impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1);
- ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
+ impl_.AddAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1);
alternate = impl_.GetAlternateProtocol(test_host_port_pair);
EXPECT_EQ(443, alternate.port);
EXPECT_EQ(NPN_SPDY_3, alternate.protocol);
@@ -423,12 +478,9 @@ TEST_F(AlternateProtocolServerPropertiesTest, Canonical) {
AlternateProtocolInfo canonical_protocol(1234, QUIC, 1);
- impl_.SetAlternateProtocol(canonical_port_pair,
- canonical_protocol.port,
- canonical_protocol.protocol,
- 1);
+ impl_.AddAlternateProtocol(canonical_port_pair, canonical_protocol.port,
+ canonical_protocol.protocol, 1);
// Verify the forced protocol.
- ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair));
AlternateProtocolInfo alternate =
impl_.GetAlternateProtocol(test_host_port_pair);
EXPECT_EQ(canonical_protocol.port, alternate.port);
@@ -446,8 +498,7 @@ TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBelowThreshold) {
HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.01);
- impl_.SetAlternateProtocol(canonical_port_pair,
- canonical_protocol.port,
+ impl_.AddAlternateProtocol(canonical_port_pair, canonical_protocol.port,
canonical_protocol.protocol,
canonical_protocol.probability);
EXPECT_FALSE(impl_.HasAlternateProtocol(canonical_port_pair));
@@ -461,8 +512,7 @@ TEST_F(AlternateProtocolServerPropertiesTest, CanonicalAboveThreshold) {
HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.03);
- impl_.SetAlternateProtocol(canonical_port_pair,
- canonical_protocol.port,
+ impl_.AddAlternateProtocol(canonical_port_pair, canonical_protocol.port,
canonical_protocol.protocol,
canonical_protocol.probability);
EXPECT_TRUE(impl_.HasAlternateProtocol(canonical_port_pair));
@@ -475,8 +525,7 @@ TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) {
AlternateProtocolInfo canonical_protocol(1234, QUIC, 1);
- impl_.SetAlternateProtocol(canonical_port_pair,
- canonical_protocol.port,
+ impl_.AddAlternateProtocol(canonical_port_pair, canonical_protocol.port,
canonical_protocol.protocol,
canonical_protocol.probability);
@@ -490,40 +539,21 @@ TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) {
AlternateProtocolInfo canonical_protocol(1234, QUIC, 1);
- impl_.SetAlternateProtocol(canonical_port_pair,
- canonical_protocol.port,
+ impl_.AddAlternateProtocol(canonical_port_pair, canonical_protocol.port,
canonical_protocol.protocol,
canonical_protocol.probability);
- impl_.SetBrokenAlternateProtocol(canonical_port_pair);
+ impl_.SetBrokenAlternateProtocol(canonical_port_pair, canonical_protocol);
EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair));
}
-TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken2) {
- HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
- HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
-
- AlternateProtocolInfo canonical_protocol(1234, QUIC, 1);
-
- impl_.SetAlternateProtocol(canonical_port_pair,
- canonical_protocol.port,
- canonical_protocol.protocol,
- canonical_protocol.probability);
-
- impl_.SetBrokenAlternateProtocol(test_host_port_pair);
- AlternateProtocolInfo alternate =
- impl_.GetAlternateProtocol(test_host_port_pair);
- EXPECT_TRUE(alternate.is_broken);
-}
-
TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) {
HostPortPair test_host_port_pair("foo.c.youtube.com", 80);
HostPortPair canonical_port_pair("bar.c.youtube.com", 80);
AlternateProtocolInfo canonical_protocol(1234, QUIC, 1);
- impl_.SetAlternateProtocol(canonical_port_pair,
- canonical_protocol.port,
+ impl_.AddAlternateProtocol(canonical_port_pair, canonical_protocol.port,
canonical_protocol.protocol,
canonical_protocol.probability);
« no previous file with comments | « net/http/http_server_properties_impl.cc ('k') | net/http/http_server_properties_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698