OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_server_properties_impl.h" | 5 #include "net/http/http_server_properties_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 class HttpServerPropertiesImplTest : public testing::Test { | 28 class HttpServerPropertiesImplTest : public testing::Test { |
29 protected: | 29 protected: |
30 HttpServerPropertiesImpl impl_; | 30 HttpServerPropertiesImpl impl_; |
31 }; | 31 }; |
32 | 32 |
33 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; | 33 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; |
34 | 34 |
35 TEST_F(SpdyServerPropertiesTest, Initialize) { | 35 TEST_F(SpdyServerPropertiesTest, Initialize) { |
36 HostPortPair spdy_server_google("www.google.com", 443); | 36 HostPortPair spdy_server_google("www.google.com", 443); |
37 std::string spdy_server_g = | 37 std::string spdy_server_g = spdy_server_google.ToString(); |
38 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_google); | |
39 | 38 |
40 HostPortPair spdy_server_docs("docs.google.com", 443); | 39 HostPortPair spdy_server_docs("docs.google.com", 443); |
41 std::string spdy_server_d = | 40 std::string spdy_server_d = spdy_server_docs.ToString(); |
42 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_docs); | |
43 | 41 |
44 // Check by initializing NULL spdy servers. | 42 // Check by initializing NULL spdy servers. |
45 impl_.InitializeSpdyServers(NULL, true); | 43 impl_.InitializeSpdyServers(NULL, true); |
46 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google)); | 44 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google)); |
47 | 45 |
48 // Check by initializing empty spdy servers. | 46 // Check by initializing empty spdy servers. |
49 std::vector<std::string> spdy_servers; | 47 std::vector<std::string> spdy_servers; |
50 impl_.InitializeSpdyServers(&spdy_servers, true); | 48 impl_.InitializeSpdyServers(&spdy_servers, true); |
51 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google)); | 49 EXPECT_FALSE(impl_.SupportsSpdy(spdy_server_google)); |
52 | 50 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 | 146 |
149 // Check empty server is not added. | 147 // Check empty server is not added. |
150 HostPortPair spdy_server_empty(std::string(), 443); | 148 HostPortPair spdy_server_empty(std::string(), 443); |
151 impl_.SetSupportsSpdy(spdy_server_empty, true); | 149 impl_.SetSupportsSpdy(spdy_server_empty, true); |
152 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 150 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
153 EXPECT_EQ(0U, spdy_server_list.GetSize()); | 151 EXPECT_EQ(0U, spdy_server_list.GetSize()); |
154 | 152 |
155 std::string string_value_g; | 153 std::string string_value_g; |
156 std::string string_value_m; | 154 std::string string_value_m; |
157 HostPortPair spdy_server_google("www.google.com", 443); | 155 HostPortPair spdy_server_google("www.google.com", 443); |
158 std::string spdy_server_g = | 156 std::string spdy_server_g = spdy_server_google.ToString(); |
159 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_google); | |
160 HostPortPair spdy_server_mail("mail.google.com", 443); | 157 HostPortPair spdy_server_mail("mail.google.com", 443); |
161 std::string spdy_server_m = | 158 std::string spdy_server_m = spdy_server_mail.ToString(); |
162 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_mail); | |
163 | 159 |
164 // Add www.google.com:443 as not supporting SPDY. | 160 // Add www.google.com:443 as not supporting SPDY. |
165 impl_.SetSupportsSpdy(spdy_server_google, false); | 161 impl_.SetSupportsSpdy(spdy_server_google, false); |
166 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 162 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
167 EXPECT_EQ(0U, spdy_server_list.GetSize()); | 163 EXPECT_EQ(0U, spdy_server_list.GetSize()); |
168 | 164 |
169 // Add www.google.com:443 as supporting SPDY. | 165 // Add www.google.com:443 as supporting SPDY. |
170 impl_.SetSupportsSpdy(spdy_server_google, true); | 166 impl_.SetSupportsSpdy(spdy_server_google, true); |
171 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 167 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
172 ASSERT_EQ(1U, spdy_server_list.GetSize()); | 168 ASSERT_EQ(1U, spdy_server_list.GetSize()); |
(...skipping 24 matching lines...) Expand all Loading... |
197 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); | 193 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_m)); |
198 ASSERT_EQ(spdy_server_m, string_value_m); | 194 ASSERT_EQ(spdy_server_m, string_value_m); |
199 } | 195 } |
200 | 196 |
201 TEST_F(SpdyServerPropertiesTest, MRUOfGetSpdyServerList) { | 197 TEST_F(SpdyServerPropertiesTest, MRUOfGetSpdyServerList) { |
202 base::ListValue spdy_server_list; | 198 base::ListValue spdy_server_list; |
203 | 199 |
204 std::string string_value_g; | 200 std::string string_value_g; |
205 std::string string_value_m; | 201 std::string string_value_m; |
206 HostPortPair spdy_server_google("www.google.com", 443); | 202 HostPortPair spdy_server_google("www.google.com", 443); |
207 std::string spdy_server_g = | 203 std::string spdy_server_g = spdy_server_google.ToString(); |
208 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_google); | |
209 HostPortPair spdy_server_mail("mail.google.com", 443); | 204 HostPortPair spdy_server_mail("mail.google.com", 443); |
210 std::string spdy_server_m = | 205 std::string spdy_server_m = spdy_server_mail.ToString(); |
211 HttpServerPropertiesImpl::GetFlattenedSpdyServer(spdy_server_mail); | |
212 | 206 |
213 // Add www.google.com:443 as supporting SPDY. | 207 // Add www.google.com:443 as supporting SPDY. |
214 impl_.SetSupportsSpdy(spdy_server_google, true); | 208 impl_.SetSupportsSpdy(spdy_server_google, true); |
215 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); | 209 impl_.GetSpdyServerList(&spdy_server_list, kMaxSupportsSpdyServerHosts); |
216 ASSERT_EQ(1U, spdy_server_list.GetSize()); | 210 ASSERT_EQ(1U, spdy_server_list.GetSize()); |
217 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); | 211 ASSERT_TRUE(spdy_server_list.GetString(0, &string_value_g)); |
218 ASSERT_EQ(spdy_server_g, string_value_g); | 212 ASSERT_EQ(spdy_server_g, string_value_g); |
219 | 213 |
220 // Add mail.google.com:443 as supporting SPDY. Verify mail.google.com:443 and | 214 // Add mail.google.com:443 as supporting SPDY. Verify mail.google.com:443 and |
221 // www.google.com:443 are in the list. | 215 // www.google.com:443 are in the list. |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 AlternateProtocolInfo alternate = | 432 AlternateProtocolInfo alternate = |
439 impl_.GetAlternateProtocol(test_host_port_pair); | 433 impl_.GetAlternateProtocol(test_host_port_pair); |
440 EXPECT_EQ(canonical_protocol.port, alternate.port); | 434 EXPECT_EQ(canonical_protocol.port, alternate.port); |
441 EXPECT_EQ(canonical_protocol.protocol, alternate.protocol); | 435 EXPECT_EQ(canonical_protocol.protocol, alternate.protocol); |
442 | 436 |
443 // Verify the canonical suffix. | 437 // Verify the canonical suffix. |
444 EXPECT_EQ(".c.youtube.com", impl_.GetCanonicalSuffix(test_host_port_pair)); | 438 EXPECT_EQ(".c.youtube.com", impl_.GetCanonicalSuffix(test_host_port_pair)); |
445 EXPECT_EQ(".c.youtube.com", impl_.GetCanonicalSuffix(canonical_port_pair)); | 439 EXPECT_EQ(".c.youtube.com", impl_.GetCanonicalSuffix(canonical_port_pair)); |
446 } | 440 } |
447 | 441 |
| 442 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBelowThreshold) { |
| 443 impl_.SetAlternateProtocolProbabilityThreshold(0.02); |
| 444 |
| 445 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
| 446 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
| 447 AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.01); |
| 448 |
| 449 impl_.SetAlternateProtocol(canonical_port_pair, |
| 450 canonical_protocol.port, |
| 451 canonical_protocol.protocol, |
| 452 canonical_protocol.probability); |
| 453 EXPECT_FALSE(impl_.HasAlternateProtocol(canonical_port_pair)); |
| 454 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); |
| 455 } |
| 456 |
| 457 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalAboveThreshold) { |
| 458 impl_.SetAlternateProtocolProbabilityThreshold(0.02); |
| 459 |
| 460 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
| 461 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
| 462 AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.03); |
| 463 |
| 464 impl_.SetAlternateProtocol(canonical_port_pair, |
| 465 canonical_protocol.port, |
| 466 canonical_protocol.protocol, |
| 467 canonical_protocol.probability); |
| 468 EXPECT_TRUE(impl_.HasAlternateProtocol(canonical_port_pair)); |
| 469 EXPECT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); |
| 470 } |
| 471 |
448 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { | 472 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { |
449 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 473 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
450 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 474 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
451 | 475 |
452 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); | 476 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
453 | 477 |
454 impl_.SetAlternateProtocol(canonical_port_pair, | 478 impl_.SetAlternateProtocol(canonical_port_pair, |
455 canonical_protocol.port, | 479 canonical_protocol.port, |
456 canonical_protocol.protocol, | 480 canonical_protocol.protocol, |
457 canonical_protocol.probability); | 481 canonical_protocol.probability); |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 EXPECT_EQ("foo", supports_quic1.address); | 751 EXPECT_EQ("foo", supports_quic1.address); |
728 | 752 |
729 impl_.Clear(); | 753 impl_.Clear(); |
730 SupportsQuic supports_quic2 = impl_.GetSupportsQuic(test_host_port_pair); | 754 SupportsQuic supports_quic2 = impl_.GetSupportsQuic(test_host_port_pair); |
731 EXPECT_FALSE(supports_quic2.used_quic); | 755 EXPECT_FALSE(supports_quic2.used_quic); |
732 EXPECT_EQ("", supports_quic2.address); | 756 EXPECT_EQ("", supports_quic2.address); |
733 } | 757 } |
734 } // namespace | 758 } // namespace |
735 | 759 |
736 } // namespace net | 760 } // namespace net |
OLD | NEW |