Chromium Code Reviews| 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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 } | 285 } |
| 286 | 286 |
| 287 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { | 287 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { |
| 288 HostPortPair test_host_port_pair1("foo1", 80); | 288 HostPortPair test_host_port_pair1("foo1", 80); |
| 289 impl_.SetBrokenAlternateProtocol(test_host_port_pair1); | 289 impl_.SetBrokenAlternateProtocol(test_host_port_pair1); |
| 290 HostPortPair test_host_port_pair2("foo2", 80); | 290 HostPortPair test_host_port_pair2("foo2", 80); |
| 291 impl_.SetAlternateProtocol(test_host_port_pair2, 443, NPN_SPDY_3, 1); | 291 impl_.SetAlternateProtocol(test_host_port_pair2, 443, NPN_SPDY_3, 1); |
| 292 | 292 |
| 293 AlternateProtocolMap alternate_protocol_map( | 293 AlternateProtocolMap alternate_protocol_map( |
| 294 AlternateProtocolMap::NO_AUTO_EVICT); | 294 AlternateProtocolMap::NO_AUTO_EVICT); |
| 295 AlternateProtocolInfo port_alternate_protocol_pair(123, NPN_SPDY_3, 1); | 295 AlternateProtocolInfo alternate(123, NPN_SPDY_3, 1); |
| 296 alternate_protocol_map.Put(test_host_port_pair2, | 296 alternate_protocol_map.Put(test_host_port_pair2, alternate); |
| 297 port_alternate_protocol_pair); | |
| 298 HostPortPair test_host_port_pair3("foo3", 80); | 297 HostPortPair test_host_port_pair3("foo3", 80); |
| 299 port_alternate_protocol_pair.port = 1234; | 298 alternate.port = 1234; |
| 300 alternate_protocol_map.Put(test_host_port_pair3, | 299 alternate_protocol_map.Put(test_host_port_pair3, alternate); |
| 301 port_alternate_protocol_pair); | |
| 302 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map); | 300 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map); |
| 303 | 301 |
| 304 // Verify test_host_port_pair3 is the MRU server. | 302 // Verify test_host_port_pair3 is the MRU server. |
| 305 const net::AlternateProtocolMap& map = impl_.alternate_protocol_map(); | 303 const net::AlternateProtocolMap& map = impl_.alternate_protocol_map(); |
| 306 net::AlternateProtocolMap::const_iterator it = map.begin(); | 304 net::AlternateProtocolMap::const_iterator it = map.begin(); |
| 307 it = map.begin(); | 305 it = map.begin(); |
| 308 EXPECT_TRUE(it->first.Equals(test_host_port_pair3)); | 306 EXPECT_TRUE(it->first.Equals(test_host_port_pair3)); |
| 309 EXPECT_EQ(1234, it->second.port); | 307 EXPECT_EQ(1234, it->second.port); |
| 310 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); | 308 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); |
| 311 | 309 |
| 312 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1)); | 310 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair1)); |
| 313 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair2)); | 311 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair2)); |
| 314 port_alternate_protocol_pair = | 312 alternate = impl_.GetAlternateProtocol(test_host_port_pair1); |
| 315 impl_.GetAlternateProtocol(test_host_port_pair1); | 313 EXPECT_TRUE(alternate.is_broken); |
| 316 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, port_alternate_protocol_pair.protocol); | 314 alternate = impl_.GetAlternateProtocol(test_host_port_pair2); |
| 317 port_alternate_protocol_pair = | 315 EXPECT_EQ(123, alternate.port); |
| 318 impl_.GetAlternateProtocol(test_host_port_pair2); | 316 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); |
| 319 EXPECT_EQ(123, port_alternate_protocol_pair.port); | |
| 320 EXPECT_EQ(NPN_SPDY_3, port_alternate_protocol_pair.protocol); | |
| 321 } | 317 } |
| 322 | 318 |
| 323 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfHasAlternateProtocol) { | 319 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfHasAlternateProtocol) { |
| 324 HostPortPair test_host_port_pair1("foo1", 80); | 320 HostPortPair test_host_port_pair1("foo1", 80); |
| 325 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1); | 321 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1); |
| 326 HostPortPair test_host_port_pair2("foo2", 80); | 322 HostPortPair test_host_port_pair2("foo2", 80); |
| 327 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1); | 323 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1); |
| 328 | 324 |
| 329 const net::AlternateProtocolMap& map = impl_.alternate_protocol_map(); | 325 const net::AlternateProtocolMap& map = impl_.alternate_protocol_map(); |
| 330 net::AlternateProtocolMap::const_iterator it = map.begin(); | 326 net::AlternateProtocolMap::const_iterator it = map.begin(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 EXPECT_EQ(443, it->second.port); | 358 EXPECT_EQ(443, it->second.port); |
| 363 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); | 359 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); |
| 364 } | 360 } |
| 365 | 361 |
| 366 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { | 362 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { |
| 367 HostPortPair test_host_port_pair("foo", 80); | 363 HostPortPair test_host_port_pair("foo", 80); |
| 368 impl_.SetBrokenAlternateProtocol(test_host_port_pair); | 364 impl_.SetBrokenAlternateProtocol(test_host_port_pair); |
| 369 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); | 365 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); |
| 370 AlternateProtocolInfo alternate = | 366 AlternateProtocolInfo alternate = |
| 371 impl_.GetAlternateProtocol(test_host_port_pair); | 367 impl_.GetAlternateProtocol(test_host_port_pair); |
| 372 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); | 368 EXPECT_TRUE(alternate.is_broken); |
| 373 | 369 |
| 374 impl_.SetAlternateProtocol( | 370 impl_.SetAlternateProtocol( |
| 375 test_host_port_pair, | 371 test_host_port_pair, |
| 376 1234, | 372 1234, |
| 377 NPN_SPDY_3, | 373 NPN_SPDY_3, |
| 378 1); | 374 1); |
| 379 alternate = impl_.GetAlternateProtocol(test_host_port_pair); | 375 alternate = impl_.GetAlternateProtocol(test_host_port_pair); |
| 380 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol) | 376 EXPECT_TRUE(alternate.is_broken) |
| 381 << "Second attempt should be ignored."; | 377 << "Second attempt should be ignored."; |
|
Ryan Hamilton
2014/11/05 17:05:20
nit: can this fit on one line?
Bence
2014/11/06 00:26:00
Sorry, git cl format is broken on my machine.
Don
| |
| 382 } | 378 } |
| 383 | 379 |
| 384 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { | 380 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { |
| 385 HostPortPair test_host_port_pair("foo", 80); | 381 HostPortPair test_host_port_pair("foo", 80); |
| 386 impl_.SetBrokenAlternateProtocol(test_host_port_pair); | 382 impl_.SetBrokenAlternateProtocol(test_host_port_pair); |
| 387 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); | 383 ASSERT_TRUE(impl_.HasAlternateProtocol(test_host_port_pair)); |
| 388 AlternateProtocolInfo alternate = | 384 AlternateProtocolInfo alternate = |
| 389 impl_.GetAlternateProtocol(test_host_port_pair); | 385 impl_.GetAlternateProtocol(test_host_port_pair); |
| 390 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); | 386 EXPECT_TRUE(alternate.is_broken); |
| 391 impl_.ClearAlternateProtocol(test_host_port_pair); | 387 impl_.ClearAlternateProtocol(test_host_port_pair); |
| 392 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); | 388 EXPECT_FALSE(impl_.HasAlternateProtocol(test_host_port_pair)); |
| 393 } | 389 } |
| 394 | 390 |
| 395 TEST_F(AlternateProtocolServerPropertiesTest, Forced) { | 391 TEST_F(AlternateProtocolServerPropertiesTest, Forced) { |
| 396 // Test forced alternate protocols. | 392 // Test forced alternate protocols. |
| 397 | 393 |
| 398 AlternateProtocolInfo default_protocol(1234, NPN_SPDY_3, 1); | 394 AlternateProtocolInfo default_protocol(1234, NPN_SPDY_3, 1); |
| 399 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol); | 395 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol); |
| 400 | 396 |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 712 EXPECT_EQ("foo", supports_quic1.address); | 708 EXPECT_EQ("foo", supports_quic1.address); |
| 713 | 709 |
| 714 impl_.Clear(); | 710 impl_.Clear(); |
| 715 SupportsQuic supports_quic2 = impl_.GetSupportsQuic(test_host_port_pair); | 711 SupportsQuic supports_quic2 = impl_.GetSupportsQuic(test_host_port_pair); |
| 716 EXPECT_FALSE(supports_quic2.used_quic); | 712 EXPECT_FALSE(supports_quic2.used_quic); |
| 717 EXPECT_EQ("", supports_quic2.address); | 713 EXPECT_EQ("", supports_quic2.address); |
| 718 } | 714 } |
| 719 } // namespace | 715 } // namespace |
| 720 | 716 |
| 721 } // namespace net | 717 } // namespace net |
| OLD | NEW |