Chromium Code Reviews| 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 f4edadb6a79e235ce81f88fcd093d4fccc86a3a1..3de0c8117c622b9a93926c5f52697b3a6b3fdc4b 100644 |
| --- a/net/http/http_server_properties_impl_unittest.cc |
| +++ b/net/http/http_server_properties_impl_unittest.cc |
| @@ -14,6 +14,7 @@ |
| #include "net/base/host_port_pair.h" |
| #include "net/base/ip_address.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#include "url/gurl.h" |
| namespace base { |
| class ListValue; |
| @@ -102,18 +103,44 @@ class HttpServerPropertiesImplTest : public testing::Test { |
| typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; |
| +TEST_F(SpdyServerPropertiesTest, InitializeWithSchemeHostPort) { |
| + // Check spdy servers are correctly sett with SchemeHostPort key. |
|
Ryan Hamilton
2016/04/07 18:27:40
s/sett/set/
Zhongyi Shi
2016/04/07 21:19:34
Done.
|
| + url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| + url::SchemeHostPort spdy_server_photos("http", "photos.google.com", 80); |
| + // Servers with port equal to default port in scheme will drop port components |
| + // when calling Serialize(). |
| + std::string spdy_server_g = spdy_server_google.Serialize(); |
| + std::string spdy_server_p = spdy_server_photos.Serialize(); |
| + |
| + url::SchemeHostPort http_google_server("http", "www.google.com", 443); |
| + url::SchemeHostPort https_photos_server("https", "photos.google.com", 443); |
| + url::SchemeHostPort valid_google_server((GURL("https://www.google.com"))); |
|
Ryan Hamilton
2016/04/07 18:27:40
nit: there are 5 variables here which are all SHP,
Zhongyi Shi
2016/04/07 21:19:34
Done.
|
| + |
| + // Initializing https://www.google.com:443 and https://photos.google.com:443 |
| + // as spdy servers. |
| + std::vector<std::string> spdy_servers1; |
| + spdy_servers1.push_back(spdy_server_g); // Will be 0th index. |
| + spdy_servers1.push_back(spdy_server_p); // Will be 1st index. |
| + impl_.InitializeSpdyServers(&spdy_servers1, true); |
| + EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_photos)); |
| + EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| + EXPECT_FALSE(impl_.SupportsRequestPriority(http_google_server)); |
| + EXPECT_FALSE(impl_.SupportsRequestPriority(https_photos_server)); |
| + EXPECT_TRUE(impl_.SupportsRequestPriority(valid_google_server)); |
| +} |
| + |
| TEST_F(SpdyServerPropertiesTest, Initialize) { |
| - HostPortPair spdy_server_google("www.google.com", 443); |
| - std::string spdy_server_g = spdy_server_google.ToString(); |
| + url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| + std::string spdy_server_g = spdy_server_google.Serialize(); |
| - HostPortPair spdy_server_photos("photos.google.com", 443); |
| - std::string spdy_server_p = spdy_server_photos.ToString(); |
| + url::SchemeHostPort spdy_server_photos("https", "photos.google.com", 443); |
| + std::string spdy_server_p = spdy_server_photos.Serialize(); |
| - HostPortPair spdy_server_docs("docs.google.com", 443); |
| - std::string spdy_server_d = spdy_server_docs.ToString(); |
| + url::SchemeHostPort spdy_server_docs("https", "docs.google.com", 443); |
| + std::string spdy_server_d = spdy_server_docs.Serialize(); |
| - HostPortPair spdy_server_mail("mail.google.com", 443); |
| - std::string spdy_server_m = spdy_server_mail.ToString(); |
| + url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| + std::string spdy_server_m = spdy_server_mail.Serialize(); |
| // Check by initializing NULL spdy servers. |
| impl_.InitializeSpdyServers(NULL, true); |
| @@ -201,49 +228,51 @@ TEST_F(SpdyServerPropertiesTest, Initialize) { |
| } |
| TEST_F(SpdyServerPropertiesTest, SupportsRequestPriorityTest) { |
| - HostPortPair spdy_server_empty(std::string(), 443); |
| + url::SchemeHostPort spdy_server_empty("https", std::string(), 443); |
| EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_empty)); |
| // Add www.google.com:443 as supporting SPDY. |
| - HostPortPair spdy_server_google("www.google.com", 443); |
| + url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| impl_.SetSupportsSpdy(spdy_server_google, true); |
| EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| // Add mail.google.com:443 as not supporting SPDY. |
| - HostPortPair spdy_server_mail("mail.google.com", 443); |
| + url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| // Add docs.google.com:443 as supporting SPDY. |
| - HostPortPair spdy_server_docs("docs.google.com", 443); |
| + url::SchemeHostPort spdy_server_docs("https", "docs.google.com", 443); |
| impl_.SetSupportsSpdy(spdy_server_docs, true); |
| EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
| // Add www.youtube.com:443 as supporting QUIC. |
| HostPortPair quic_server_youtube("www.youtube.com", 443); |
| + url::SchemeHostPort youtube_server("https", "www.youtube.com", 443); |
| const AlternativeService alternative_service1(QUIC, "www.youtube.com", 443); |
| SetAlternativeService(quic_server_youtube, alternative_service1); |
| - EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); |
| + EXPECT_TRUE(impl_.SupportsRequestPriority(youtube_server)); |
| // Add www.example.com:443 with two alternative services, one supporting QUIC. |
| HostPortPair quic_server_example("www.example.com", 443); |
| + url::SchemeHostPort example_server("https", "www.example.com", 443); |
| const AlternativeService alternative_service2(NPN_HTTP_2, "", 443); |
| SetAlternativeService(quic_server_example, alternative_service2); |
| SetAlternativeService(quic_server_example, alternative_service1); |
| - EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_example)); |
| + EXPECT_TRUE(impl_.SupportsRequestPriority(example_server)); |
| // 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)); |
| + EXPECT_TRUE(impl_.SupportsRequestPriority(youtube_server)); |
| + EXPECT_TRUE(impl_.SupportsRequestPriority(example_server)); |
| } |
| TEST_F(SpdyServerPropertiesTest, Clear) { |
| // Add www.google.com:443 and mail.google.com:443 as supporting SPDY. |
| - HostPortPair spdy_server_google("www.google.com", 443); |
| + url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| impl_.SetSupportsSpdy(spdy_server_google, true); |
| - HostPortPair spdy_server_mail("mail.google.com", 443); |
| + url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| impl_.SetSupportsSpdy(spdy_server_mail, true); |
| EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| @@ -262,17 +291,17 @@ TEST_F(SpdyServerPropertiesTest, GetSpdyServerList) { |
| EXPECT_EQ(0U, spdy_server_list.GetSize()); |
| // Check empty server is not added. |
| - HostPortPair spdy_server_empty(std::string(), 443); |
| + url::SchemeHostPort spdy_server_empty("https", std::string(), 443); |
| impl_.SetSupportsSpdy(spdy_server_empty, true); |
| impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
| EXPECT_EQ(0U, spdy_server_list.GetSize()); |
| std::string string_value_g; |
| std::string string_value_m; |
| - HostPortPair spdy_server_google("www.google.com", 443); |
| - std::string spdy_server_g = spdy_server_google.ToString(); |
| - HostPortPair spdy_server_mail("mail.google.com", 443); |
| - std::string spdy_server_m = spdy_server_mail.ToString(); |
| + url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| + std::string spdy_server_g = spdy_server_google.Serialize(); |
| + url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| + std::string spdy_server_m = spdy_server_mail.Serialize(); |
| // Add www.google.com:443 as not supporting SPDY. |
| impl_.SetSupportsSpdy(spdy_server_google, false); |
| @@ -316,10 +345,10 @@ TEST_F(SpdyServerPropertiesTest, MRUOfGetSpdyServerList) { |
| std::string string_value_g; |
| std::string string_value_m; |
| - HostPortPair spdy_server_google("www.google.com", 443); |
| - std::string spdy_server_g = spdy_server_google.ToString(); |
| - HostPortPair spdy_server_mail("mail.google.com", 443); |
| - std::string spdy_server_m = spdy_server_mail.ToString(); |
| + url::SchemeHostPort spdy_server_google("https", "www.google.com", 443); |
| + std::string spdy_server_g = spdy_server_google.Serialize(); |
| + url::SchemeHostPort spdy_server_mail("https", "mail.google.com", 443); |
| + std::string spdy_server_m = spdy_server_mail.Serialize(); |
| // Add www.google.com:443 as supporting SPDY. |
| impl_.SetSupportsSpdy(spdy_server_google, true); |