| 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 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map); | 283 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map); |
| 284 | 284 |
| 285 // Verify test_host_port_pair3 is the MRU server. | 285 // Verify test_host_port_pair3 is the MRU server. |
| 286 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); | 286 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); |
| 287 AlternateProtocolMap::const_iterator it = map.begin(); | 287 AlternateProtocolMap::const_iterator it = map.begin(); |
| 288 EXPECT_TRUE(it->first.Equals(test_host_port_pair3)); | 288 EXPECT_TRUE(it->first.Equals(test_host_port_pair3)); |
| 289 EXPECT_EQ(1234, it->second.port); | 289 EXPECT_EQ(1234, it->second.port); |
| 290 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); | 290 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); |
| 291 | 291 |
| 292 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair1)); | 292 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair1)); |
| 293 const AlternativeService alternative_service( | 293 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair2)); |
| 294 NPN_SPDY_3, test_host_port_pair1.host(), 443); | 294 alternate = impl_.GetAlternateProtocol(test_host_port_pair1); |
| 295 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 295 EXPECT_TRUE(alternate.is_broken); |
| 296 alternate = impl_.GetAlternateProtocol(test_host_port_pair2); | 296 alternate = impl_.GetAlternateProtocol(test_host_port_pair2); |
| 297 EXPECT_EQ(123, alternate.port); | 297 EXPECT_EQ(123, alternate.port); |
| 298 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); | 298 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); |
| 299 } | 299 } |
| 300 | 300 |
| 301 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) { | 301 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) { |
| 302 HostPortPair test_host_port_pair1("foo1", 80); | 302 HostPortPair test_host_port_pair1("foo1", 80); |
| 303 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0); | 303 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0); |
| 304 HostPortPair test_host_port_pair2("foo2", 80); | 304 HostPortPair test_host_port_pair2("foo2", 80); |
| 305 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1.0); | 305 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1.0); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 319 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); | 319 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); |
| 320 EXPECT_EQ(443, it->second.port); | 320 EXPECT_EQ(443, it->second.port); |
| 321 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); | 321 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); |
| 322 } | 322 } |
| 323 | 323 |
| 324 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { | 324 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { |
| 325 HostPortPair test_host_port_pair("foo", 80); | 325 HostPortPair test_host_port_pair("foo", 80); |
| 326 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); | 326 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); |
| 327 impl_.SetBrokenAlternateProtocol(test_host_port_pair); | 327 impl_.SetBrokenAlternateProtocol(test_host_port_pair); |
| 328 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 328 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); |
| 329 const AlternativeService alternative_service(NPN_SPDY_3, | 329 AlternateProtocolInfo alternate = |
| 330 test_host_port_pair.host(), 443); | 330 impl_.GetAlternateProtocol(test_host_port_pair); |
| 331 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 331 EXPECT_TRUE(alternate.is_broken); |
| 332 | 332 |
| 333 impl_.SetAlternateProtocol(test_host_port_pair, 1234, NPN_SPDY_3, 1.0); | 333 impl_.SetAlternateProtocol(test_host_port_pair, 1234, NPN_SPDY_3, 1.0); |
| 334 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 334 alternate = impl_.GetAlternateProtocol(test_host_port_pair); |
| 335 const AlternateProtocolInfo alternate = | 335 EXPECT_TRUE(alternate.is_broken) << "Second attempt should be ignored."; |
| 336 impl_.GetAlternateProtocol(test_host_port_pair); | |
| 337 EXPECT_EQ(1234, alternate.port); | |
| 338 } | 336 } |
| 339 | 337 |
| 340 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { | 338 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { |
| 341 HostPortPair test_host_port_pair("foo", 80); | 339 HostPortPair test_host_port_pair("foo", 80); |
| 342 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); | 340 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); |
| 343 impl_.SetBrokenAlternateProtocol(test_host_port_pair); | 341 impl_.SetBrokenAlternateProtocol(test_host_port_pair); |
| 344 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 342 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); |
| 345 const AlternativeService alternative_service(NPN_SPDY_3, | 343 AlternateProtocolInfo alternate = |
| 346 test_host_port_pair.host(), 443); | 344 impl_.GetAlternateProtocol(test_host_port_pair); |
| 347 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 345 EXPECT_TRUE(alternate.is_broken); |
| 348 impl_.ClearAlternateProtocol(test_host_port_pair); | 346 impl_.ClearAlternateProtocol(test_host_port_pair); |
| 349 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 347 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
| 350 } | 348 } |
| 351 | 349 |
| 352 TEST_F(AlternateProtocolServerPropertiesTest, Forced) { | 350 TEST_F(AlternateProtocolServerPropertiesTest, Forced) { |
| 353 // Test forced alternate protocols. | 351 // Test forced alternate protocols. |
| 354 | 352 |
| 355 AlternateProtocolInfo default_protocol(1234, NPN_SPDY_3, 1); | 353 AlternateProtocolInfo default_protocol(1234, NPN_SPDY_3, 1); |
| 356 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol); | 354 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol); |
| 357 | 355 |
| 358 // Verify the forced protocol. | 356 // Verify the forced protocol. |
| 359 HostPortPair test_host_port_pair("foo", 80); | 357 HostPortPair test_host_port_pair("foo", 80); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); | 451 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
| 454 | 452 |
| 455 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 453 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
| 456 canonical_protocol.protocol, | 454 canonical_protocol.protocol, |
| 457 canonical_protocol.probability); | 455 canonical_protocol.probability); |
| 458 | 456 |
| 459 impl_.SetBrokenAlternateProtocol(canonical_port_pair); | 457 impl_.SetBrokenAlternateProtocol(canonical_port_pair); |
| 460 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 458 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
| 461 } | 459 } |
| 462 | 460 |
| 461 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken2) { |
| 462 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
| 463 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
| 464 |
| 465 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
| 466 |
| 467 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
| 468 canonical_protocol.protocol, |
| 469 canonical_protocol.probability); |
| 470 |
| 471 impl_.SetBrokenAlternateProtocol(test_host_port_pair); |
| 472 AlternateProtocolInfo alternate = |
| 473 impl_.GetAlternateProtocol(test_host_port_pair); |
| 474 EXPECT_TRUE(alternate.is_broken); |
| 475 } |
| 476 |
| 463 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { | 477 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { |
| 464 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 478 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
| 465 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 479 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
| 466 | 480 |
| 467 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); | 481 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
| 468 | 482 |
| 469 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 483 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
| 470 canonical_protocol.protocol, | 484 canonical_protocol.protocol, |
| 471 canonical_protocol.probability); | 485 canonical_protocol.probability); |
| 472 | 486 |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); | 752 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); |
| 739 | 753 |
| 740 impl_.Clear(); | 754 impl_.Clear(); |
| 741 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server); | 755 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server); |
| 742 EXPECT_EQ(NULL, stats3); | 756 EXPECT_EQ(NULL, stats3); |
| 743 } | 757 } |
| 744 | 758 |
| 745 } // namespace | 759 } // namespace |
| 746 | 760 |
| 747 } // namespace net | 761 } // namespace net |
| OLD | NEW |