| 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 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair2)); | 293 const AlternativeService alternative_service( |
| 294 alternate = impl_.GetAlternateProtocol(test_host_port_pair1); | 294 NPN_SPDY_3, test_host_port_pair1.host(), 443); |
| 295 EXPECT_TRUE(alternate.is_broken); | 295 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 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 AlternateProtocolInfo alternate = | 329 const AlternativeService alternative_service(NPN_SPDY_3, |
| 330 impl_.GetAlternateProtocol(test_host_port_pair); | 330 test_host_port_pair.host(), 443); |
| 331 EXPECT_TRUE(alternate.is_broken); | 331 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 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 alternate = impl_.GetAlternateProtocol(test_host_port_pair); | 334 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 335 EXPECT_TRUE(alternate.is_broken) << "Second attempt should be ignored."; | 335 const AlternateProtocolInfo alternate = |
| 336 impl_.GetAlternateProtocol(test_host_port_pair); |
| 337 EXPECT_EQ(1234, alternate.port); |
| 336 } | 338 } |
| 337 | 339 |
| 338 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { | 340 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { |
| 339 HostPortPair test_host_port_pair("foo", 80); | 341 HostPortPair test_host_port_pair("foo", 80); |
| 340 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); | 342 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); |
| 341 impl_.SetBrokenAlternateProtocol(test_host_port_pair); | 343 impl_.SetBrokenAlternateProtocol(test_host_port_pair); |
| 342 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 344 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); |
| 343 AlternateProtocolInfo alternate = | 345 const AlternativeService alternative_service(NPN_SPDY_3, |
| 344 impl_.GetAlternateProtocol(test_host_port_pair); | 346 test_host_port_pair.host(), 443); |
| 345 EXPECT_TRUE(alternate.is_broken); | 347 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 346 impl_.ClearAlternateProtocol(test_host_port_pair); | 348 impl_.ClearAlternateProtocol(test_host_port_pair); |
| 347 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 349 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| 348 } | 350 } |
| 349 | 351 |
| 350 TEST_F(AlternateProtocolServerPropertiesTest, Forced) { | 352 TEST_F(AlternateProtocolServerPropertiesTest, Forced) { |
| 351 // Test forced alternate protocols. | 353 // Test forced alternate protocols. |
| 352 | 354 |
| 353 AlternateProtocolInfo default_protocol(1234, NPN_SPDY_3, 1); | 355 AlternateProtocolInfo default_protocol(1234, NPN_SPDY_3, 1); |
| 354 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol); | 356 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol); |
| 355 | 357 |
| 356 // Verify the forced protocol. | 358 // Verify the forced protocol. |
| 357 HostPortPair test_host_port_pair("foo", 80); | 359 HostPortPair test_host_port_pair("foo", 80); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); | 453 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
| 452 | 454 |
| 453 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 455 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
| 454 canonical_protocol.protocol, | 456 canonical_protocol.protocol, |
| 455 canonical_protocol.probability); | 457 canonical_protocol.probability); |
| 456 | 458 |
| 457 impl_.SetBrokenAlternateProtocol(canonical_port_pair); | 459 impl_.SetBrokenAlternateProtocol(canonical_port_pair); |
| 458 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 460 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
| 459 } | 461 } |
| 460 | 462 |
| 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 | |
| 477 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { | 463 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { |
| 478 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 464 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
| 479 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 465 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
| 480 | 466 |
| 481 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); | 467 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
| 482 | 468 |
| 483 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 469 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
| 484 canonical_protocol.protocol, | 470 canonical_protocol.protocol, |
| 485 canonical_protocol.probability); | 471 canonical_protocol.probability); |
| 486 | 472 |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); | 738 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); |
| 753 | 739 |
| 754 impl_.Clear(); | 740 impl_.Clear(); |
| 755 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server); | 741 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server); |
| 756 EXPECT_EQ(NULL, stats3); | 742 EXPECT_EQ(NULL, stats3); |
| 757 } | 743 } |
| 758 | 744 |
| 759 } // namespace | 745 } // namespace |
| 760 | 746 |
| 761 } // namespace net | 747 } // namespace net |
| OLD | NEW |