| 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 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 namespace net { | 22 namespace net { |
| 23 | 23 |
| 24 const int kMaxSupportsSpdyServerHosts = 500; | 24 const int kMaxSupportsSpdyServerHosts = 500; |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 class HttpServerPropertiesImplTest : public testing::Test { | 28 class HttpServerPropertiesImplTest : public testing::Test { |
| 29 protected: | 29 protected: |
| 30 bool HasAlternateProtocol(const HostPortPair& server) { | 30 bool HasAlternateProtocol(const HostPortPair& server) { |
| 31 const AlternateProtocolInfo alternate = impl_.GetAlternateProtocol(server); | 31 const AlternateProtocols alternates = impl_.GetAlternateProtocols(server); |
| 32 return alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL; | 32 return !alternates.empty(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 HttpServerPropertiesImpl impl_; | 35 HttpServerPropertiesImpl impl_; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; | 38 typedef HttpServerPropertiesImplTest SpdyServerPropertiesTest; |
| 39 | 39 |
| 40 TEST_F(SpdyServerPropertiesTest, Initialize) { | 40 TEST_F(SpdyServerPropertiesTest, Initialize) { |
| 41 HostPortPair spdy_server_google("www.google.com", 443); | 41 HostPortPair spdy_server_google("www.google.com", 443); |
| 42 std::string spdy_server_g = spdy_server_google.ToString(); | 42 std::string spdy_server_g = spdy_server_google.ToString(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 HostPortPair spdy_server_mail("mail.google.com", 443); | 93 HostPortPair spdy_server_mail("mail.google.com", 443); |
| 94 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); | 94 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| 95 | 95 |
| 96 // Add docs.google.com:443 as supporting SPDY. | 96 // Add docs.google.com:443 as supporting SPDY. |
| 97 HostPortPair spdy_server_docs("docs.google.com", 443); | 97 HostPortPair spdy_server_docs("docs.google.com", 443); |
| 98 impl_.SetSupportsSpdy(spdy_server_docs, true); | 98 impl_.SetSupportsSpdy(spdy_server_docs, true); |
| 99 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); | 99 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
| 100 | 100 |
| 101 // Add www.youtube.com:443 as supporting QUIC. | 101 // Add www.youtube.com:443 as supporting QUIC. |
| 102 HostPortPair quic_server_youtube("www.youtube.com", 443); | 102 HostPortPair quic_server_youtube("www.youtube.com", 443); |
| 103 impl_.SetAlternateProtocol(quic_server_youtube, 443, QUIC, 1); | 103 impl_.AddAlternateProtocol(quic_server_youtube, 443, QUIC, 1); |
| 104 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); | 104 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); |
| 105 | 105 |
| 106 // Verify all the entries are the same after additions. | 106 // Verify all the entries are the same after additions. |
| 107 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | 107 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
| 108 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); | 108 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
| 109 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); | 109 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
| 110 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); | 110 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); |
| 111 } | 111 } |
| 112 | 112 |
| 113 TEST_F(SpdyServerPropertiesTest, Clear) { | 113 TEST_F(SpdyServerPropertiesTest, Clear) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 ASSERT_EQ(spdy_server_g, string_value_g); | 218 ASSERT_EQ(spdy_server_g, string_value_g); |
| 219 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); | 219 ASSERT_TRUE(spdy_server_list.GetString(1, &string_value_m)); |
| 220 ASSERT_EQ(spdy_server_m, string_value_m); | 220 ASSERT_EQ(spdy_server_m, string_value_m); |
| 221 } | 221 } |
| 222 | 222 |
| 223 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; | 223 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; |
| 224 | 224 |
| 225 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { | 225 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { |
| 226 HostPortPair test_host_port_pair("foo", 80); | 226 HostPortPair test_host_port_pair("foo", 80); |
| 227 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 227 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
| 228 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); | 228 impl_.AddAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); |
| 229 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 229 const AlternateProtocols alternate_protocols = |
| 230 const AlternateProtocolInfo alternate = | 230 impl_.GetAlternateProtocols(test_host_port_pair); |
| 231 impl_.GetAlternateProtocol(test_host_port_pair); | 231 ASSERT_EQ(1u, alternate_protocols.size()); |
| 232 EXPECT_EQ(443, alternate.port); | 232 EXPECT_EQ(443, alternate_protocols[0].port); |
| 233 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); | 233 EXPECT_EQ(NPN_SPDY_3, alternate_protocols[0].protocol); |
| 234 | 234 |
| 235 impl_.Clear(); | 235 impl_.Clear(); |
| 236 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 236 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
| 237 } | 237 } |
| 238 | 238 |
| 239 TEST_F(AlternateProtocolServerPropertiesTest, DefaultProbabilityExcluded) { | 239 TEST_F(AlternateProtocolServerPropertiesTest, DefaultProbabilityExcluded) { |
| 240 HostPortPair test_host_port_pair("foo", 80); | 240 HostPortPair test_host_port_pair("foo", 80); |
| 241 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .99); | 241 impl_.AddAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 0.99); |
| 242 | 242 |
| 243 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 243 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
| 244 } | 244 } |
| 245 | 245 |
| 246 TEST_F(AlternateProtocolServerPropertiesTest, Probability) { | 246 TEST_F(AlternateProtocolServerPropertiesTest, Probability) { |
| 247 impl_.SetAlternateProtocolProbabilityThreshold(.25); | 247 impl_.SetAlternateProtocolProbabilityThreshold(0.25); |
| 248 | 248 |
| 249 HostPortPair test_host_port_pair("foo", 80); | 249 HostPortPair test_host_port_pair("foo", 80); |
| 250 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .5); | 250 impl_.AddAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 0.5); |
| 251 | 251 |
| 252 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 252 const AlternateProtocols alternate_protocols = |
| 253 const AlternateProtocolInfo alternate = | 253 impl_.GetAlternateProtocols(test_host_port_pair); |
| 254 impl_.GetAlternateProtocol(test_host_port_pair); | 254 ASSERT_EQ(1u, alternate_protocols.size()); |
| 255 EXPECT_EQ(443, alternate.port); | 255 EXPECT_EQ(443, alternate_protocols[0].port); |
| 256 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); | 256 EXPECT_EQ(NPN_SPDY_3, alternate_protocols[0].protocol); |
| 257 EXPECT_EQ(.5, alternate.probability); | 257 EXPECT_EQ(0.5, alternate_protocols[0].probability); |
| 258 } | 258 } |
| 259 | 259 |
| 260 TEST_F(AlternateProtocolServerPropertiesTest, ProbabilityExcluded) { | 260 TEST_F(AlternateProtocolServerPropertiesTest, ProbabilityExcluded) { |
| 261 impl_.SetAlternateProtocolProbabilityThreshold(.75); | 261 impl_.SetAlternateProtocolProbabilityThreshold(0.75); |
| 262 | 262 |
| 263 HostPortPair test_host_port_pair("foo", 80); | 263 HostPortPair test_host_port_pair("foo", 80); |
| 264 | 264 |
| 265 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, .5); | 265 impl_.AddAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 0.5); |
| 266 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 266 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
| 267 } | 267 } |
| 268 | 268 |
| 269 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { | 269 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { |
| 270 HostPortPair test_host_port_pair1("foo1", 80); | 270 HostPortPair test_host_port_pair1("foo1", 80); |
| 271 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0); | 271 impl_.AddAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0); |
| 272 impl_.SetBrokenAlternateProtocol(test_host_port_pair1); | 272 AlternateProtocolInfo alternate_protocol(123, NPN_SPDY_3, 1.0); |
| 273 impl_.SetBrokenAlternateProtocol(test_host_port_pair1, alternate_protocol); |
| 273 HostPortPair test_host_port_pair2("foo2", 80); | 274 HostPortPair test_host_port_pair2("foo2", 80); |
| 274 impl_.SetAlternateProtocol(test_host_port_pair2, 443, NPN_SPDY_3, 1.0); | 275 impl_.AddAlternateProtocol(test_host_port_pair2, 443, NPN_SPDY_3, 1.0); |
| 275 | 276 |
| 276 AlternateProtocolMap alternate_protocol_map( | 277 AlternateProtocolMap alternate_protocol_map( |
| 277 AlternateProtocolMap::NO_AUTO_EVICT); | 278 AlternateProtocolMap::NO_AUTO_EVICT); |
| 278 AlternateProtocolInfo alternate(123, NPN_SPDY_3, 1); | 279 AlternateProtocolInfo alternate(123, NPN_SPDY_3, 1); |
| 279 alternate_protocol_map.Put(test_host_port_pair2, alternate); | 280 alternate_protocol_map.Put(test_host_port_pair2, |
| 281 AlternateProtocols(/*size=*/1, alternate)); |
| 280 HostPortPair test_host_port_pair3("foo3", 80); | 282 HostPortPair test_host_port_pair3("foo3", 80); |
| 281 alternate.port = 1234; | 283 alternate.port = 1234; |
| 282 alternate_protocol_map.Put(test_host_port_pair3, alternate); | 284 alternate_protocol_map.Put(test_host_port_pair3, |
| 285 AlternateProtocols(/*size=*/1, alternate)); |
| 283 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map); | 286 impl_.InitializeAlternateProtocolServers(&alternate_protocol_map); |
| 284 | 287 |
| 285 // Verify test_host_port_pair3 is the MRU server. | 288 // Verify test_host_port_pair3 is the MRU server. |
| 286 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); | 289 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); |
| 287 AlternateProtocolMap::const_iterator it = map.begin(); | 290 AlternateProtocolMap::const_iterator it = map.begin(); |
| 288 EXPECT_TRUE(it->first.Equals(test_host_port_pair3)); | 291 EXPECT_TRUE(it->first.Equals(test_host_port_pair3)); |
| 289 EXPECT_EQ(1234, it->second.port); | 292 ASSERT_EQ(1u, it->second.size()); |
| 290 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); | 293 EXPECT_EQ(1234, it->second[0].port); |
| 294 EXPECT_EQ(NPN_SPDY_3, it->second[0].protocol); |
| 291 | 295 |
| 292 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair1)); | 296 AlternateProtocols alternate_protocols = |
| 293 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair2)); | 297 impl_.GetAlternateProtocols(test_host_port_pair1); |
| 294 alternate = impl_.GetAlternateProtocol(test_host_port_pair1); | 298 ASSERT_EQ(1u, alternate_protocols.size()); |
| 295 EXPECT_TRUE(alternate.is_broken); | 299 EXPECT_TRUE(alternate_protocols[0].is_broken); |
| 296 alternate = impl_.GetAlternateProtocol(test_host_port_pair2); | 300 alternate_protocols = impl_.GetAlternateProtocols(test_host_port_pair2); |
| 297 EXPECT_EQ(123, alternate.port); | 301 ASSERT_EQ(1u, alternate_protocols.size()); |
| 298 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); | 302 EXPECT_EQ(123, alternate_protocols[0].port); |
| 303 EXPECT_EQ(NPN_SPDY_3, alternate_protocols[0].protocol); |
| 299 } | 304 } |
| 300 | 305 |
| 301 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) { | 306 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternateProtocol) { |
| 302 HostPortPair test_host_port_pair1("foo1", 80); | 307 HostPortPair test_host_port_pair1("foo1", 80); |
| 303 impl_.SetAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0); | 308 impl_.AddAlternateProtocol(test_host_port_pair1, 443, NPN_SPDY_3, 1.0); |
| 304 HostPortPair test_host_port_pair2("foo2", 80); | 309 HostPortPair test_host_port_pair2("foo2", 80); |
| 305 impl_.SetAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1.0); | 310 impl_.AddAlternateProtocol(test_host_port_pair2, 1234, NPN_SPDY_3, 1.0); |
| 306 | 311 |
| 307 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); | 312 const AlternateProtocolMap& map = impl_.alternate_protocol_map(); |
| 308 AlternateProtocolMap::const_iterator it = map.begin(); | 313 AlternateProtocolMap::const_iterator it = map.begin(); |
| 309 EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); | 314 EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); |
| 310 EXPECT_EQ(1234, it->second.port); | 315 ASSERT_EQ(1u, it->second.size()); |
| 311 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); | 316 EXPECT_EQ(1234, it->second[0].port); |
| 317 EXPECT_EQ(NPN_SPDY_3, it->second[0].protocol); |
| 312 | 318 |
| 313 // GetAlternateProtocol should reorder the AlternateProtocol map. | 319 // GetAlternateProtocols should reorder the AlternateProtocol map. |
| 314 AlternateProtocolInfo alternate = | 320 const AlternateProtocols alternate_protocols = |
| 315 impl_.GetAlternateProtocol(test_host_port_pair1); | 321 impl_.GetAlternateProtocols(test_host_port_pair1); |
| 322 ASSERT_EQ(1u, alternate_protocols.size()); |
| 323 const AlternateProtocolInfo alternate = alternate_protocols[0]; |
| 316 EXPECT_EQ(443, alternate.port); | 324 EXPECT_EQ(443, alternate.port); |
| 317 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); | 325 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); |
| 318 it = map.begin(); | 326 it = map.begin(); |
| 319 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); | 327 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); |
| 320 EXPECT_EQ(443, it->second.port); | 328 ASSERT_EQ(1u, it->second.size()); |
| 321 EXPECT_EQ(NPN_SPDY_3, it->second.protocol); | 329 EXPECT_EQ(443, it->second[0].port); |
| 330 EXPECT_EQ(NPN_SPDY_3, it->second[0].protocol); |
| 331 } |
| 332 |
| 333 TEST_F(AlternateProtocolServerPropertiesTest, RemoveAlternateProtocol) { |
| 334 HostPortPair test_host_port_pair("foo", 80); |
| 335 impl_.AddAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1); |
| 336 impl_.AddAlternateProtocol(test_host_port_pair, 1234, NPN_SPDY_3, 1); |
| 337 |
| 338 const net::AlternateProtocolMap& map = impl_.alternate_protocol_map(); |
| 339 net::AlternateProtocolMap::const_iterator it = map.begin(); |
| 340 EXPECT_TRUE(it->first.Equals(test_host_port_pair)); |
| 341 ASSERT_EQ(2u, it->second.size()); |
| 342 EXPECT_EQ(443, it->second[0].port); |
| 343 EXPECT_EQ(1234, it->second[1].port); |
| 344 |
| 345 // Adding an identical entry does nothing. |
| 346 impl_.AddAlternateProtocol(test_host_port_pair, 1234, NPN_SPDY_3, 1); |
| 347 it = map.begin(); |
| 348 ASSERT_EQ(2u, it->second.size()); |
| 349 |
| 350 // Add a third one. |
| 351 impl_.AddAlternateProtocol(test_host_port_pair, 123, NPN_SPDY_3, 1); |
| 352 it = map.begin(); |
| 353 ASSERT_EQ(3u, it->second.size()); |
| 354 EXPECT_EQ(123, it->second[2].port); |
| 355 |
| 356 // Remove one by one. |
| 357 impl_.RemoveAlternateProtocol(test_host_port_pair, |
| 358 AlternateProtocolInfo(1234, NPN_SPDY_3, 1)); |
| 359 it = map.begin(); |
| 360 ASSERT_EQ(2u, it->second.size()); |
| 361 EXPECT_EQ(443, it->second[0].port); |
| 362 EXPECT_EQ(123, it->second[1].port); |
| 363 |
| 364 impl_.RemoveAlternateProtocol(test_host_port_pair, |
| 365 AlternateProtocolInfo(443, NPN_SPDY_3, 1)); |
| 366 it = map.begin(); |
| 367 ASSERT_EQ(1u, it->second.size()); |
| 368 EXPECT_EQ(123, it->second[0].port); |
| 369 |
| 370 impl_.RemoveAlternateProtocol(test_host_port_pair, |
| 371 AlternateProtocolInfo(123, NPN_SPDY_3, 1)); |
| 372 ASSERT_EQ(0u, map.size()); |
| 373 } |
| 374 |
| 375 TEST_F(AlternateProtocolServerPropertiesTest, ClearAlternateProtocols) { |
| 376 HostPortPair test_host_port_pair("foo", 80); |
| 377 impl_.AddAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1); |
| 378 impl_.AddAlternateProtocol(test_host_port_pair, 1234, NPN_SPDY_3, 1); |
| 379 |
| 380 const net::AlternateProtocolMap& map = impl_.alternate_protocol_map(); |
| 381 net::AlternateProtocolMap::const_iterator it = map.begin(); |
| 382 EXPECT_TRUE(it->first.Equals(test_host_port_pair)); |
| 383 ASSERT_EQ(2u, it->second.size()); |
| 384 EXPECT_EQ(443, it->second[0].port); |
| 385 EXPECT_EQ(1234, it->second[1].port); |
| 386 |
| 387 impl_.ClearAlternateProtocols(test_host_port_pair); |
| 388 EXPECT_EQ(0u, impl_.alternate_protocol_map().size()); |
| 322 } | 389 } |
| 323 | 390 |
| 324 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { | 391 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { |
| 325 HostPortPair test_host_port_pair("foo", 80); | 392 HostPortPair test_host_port_pair("foo", 80); |
| 326 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); | 393 impl_.AddAlternateProtocol(test_host_port_pair, 123, NPN_SPDY_3, 1.0); |
| 327 impl_.SetBrokenAlternateProtocol(test_host_port_pair); | 394 AlternateProtocolInfo alternate(123, NPN_SPDY_3, 1); |
| 328 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 395 impl_.SetBrokenAlternateProtocol(test_host_port_pair, alternate); |
| 329 AlternateProtocolInfo alternate = | 396 AlternateProtocols alternate_protocols = |
| 330 impl_.GetAlternateProtocol(test_host_port_pair); | 397 impl_.GetAlternateProtocols(test_host_port_pair); |
| 331 EXPECT_TRUE(alternate.is_broken); | 398 ASSERT_EQ(1u, alternate_protocols.size()); |
| 399 EXPECT_TRUE(alternate_protocols[0].is_broken); |
| 332 | 400 |
| 333 impl_.SetAlternateProtocol(test_host_port_pair, 1234, NPN_SPDY_3, 1.0); | 401 impl_.AddAlternateProtocol(test_host_port_pair, 123, NPN_SPDY_3, 1); |
| 334 alternate = impl_.GetAlternateProtocol(test_host_port_pair); | 402 alternate_protocols = impl_.GetAlternateProtocols(test_host_port_pair); |
| 335 EXPECT_TRUE(alternate.is_broken) << "Second attempt should be ignored."; | 403 ASSERT_EQ(1u, alternate_protocols.size()) |
| 404 << "Second attempt should be ignored."; |
| 405 EXPECT_TRUE(alternate_protocols[0].is_broken); |
| 406 |
| 407 impl_.AddAlternateProtocol(test_host_port_pair, 1234, NPN_SPDY_3, 1.0); |
| 408 alternate_protocols = impl_.GetAlternateProtocols(test_host_port_pair); |
| 409 ASSERT_EQ(2u, alternate_protocols.size()) << "Different port should be fine."; |
| 336 } | 410 } |
| 337 | 411 |
| 338 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { | 412 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { |
| 339 HostPortPair test_host_port_pair("foo", 80); | 413 HostPortPair test_host_port_pair("foo", 80); |
| 340 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); | 414 impl_.AddAlternateProtocol(test_host_port_pair, 123, NPN_SPDY_3, 1.0); |
| 341 impl_.SetBrokenAlternateProtocol(test_host_port_pair); | 415 AlternateProtocolInfo alternate(123, NPN_SPDY_3, 1); |
| 342 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 416 impl_.SetBrokenAlternateProtocol(test_host_port_pair, alternate); |
| 343 AlternateProtocolInfo alternate = | 417 AlternateProtocols alternate_protocols = |
| 344 impl_.GetAlternateProtocol(test_host_port_pair); | 418 impl_.GetAlternateProtocols(test_host_port_pair); |
| 345 EXPECT_TRUE(alternate.is_broken); | 419 ASSERT_EQ(1u, alternate_protocols.size()); |
| 346 impl_.ClearAlternateProtocol(test_host_port_pair); | 420 EXPECT_TRUE(alternate_protocols[0].is_broken); |
| 421 impl_.ClearAlternateProtocols(test_host_port_pair); |
| 347 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 422 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
| 348 } | 423 } |
| 349 | 424 |
| 350 TEST_F(AlternateProtocolServerPropertiesTest, Forced) { | 425 TEST_F(AlternateProtocolServerPropertiesTest, Forced) { |
| 351 // Test forced alternate protocols. | 426 // Test forced alternate protocols. |
| 352 | 427 |
| 353 AlternateProtocolInfo default_protocol(1234, NPN_SPDY_3, 1); | 428 AlternateProtocolInfo default_protocol(1234, NPN_SPDY_3, 1); |
| 354 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol); | 429 HttpServerPropertiesImpl::ForceAlternateProtocol(default_protocol); |
| 355 | 430 |
| 356 // Verify the forced protocol. | 431 // Verify the forced protocol. |
| 357 HostPortPair test_host_port_pair("foo", 80); | 432 HostPortPair test_host_port_pair("foo", 80); |
| 358 EXPECT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 433 AlternateProtocols alternate_protocols = |
| 359 AlternateProtocolInfo alternate = | 434 impl_.GetAlternateProtocols(test_host_port_pair); |
| 360 impl_.GetAlternateProtocol(test_host_port_pair); | 435 ASSERT_EQ(1u, alternate_protocols.size()); |
| 361 EXPECT_EQ(default_protocol.port, alternate.port); | 436 EXPECT_EQ(default_protocol.port, alternate_protocols[0].port); |
| 362 EXPECT_EQ(default_protocol.protocol, alternate.protocol); | 437 EXPECT_EQ(default_protocol.protocol, alternate_protocols[0].protocol); |
| 363 | 438 |
| 364 // Verify the real protocol overrides the forced protocol. | 439 // Verify the real protocol overrides the forced protocol. |
| 365 impl_.SetAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); | 440 impl_.AddAlternateProtocol(test_host_port_pair, 443, NPN_SPDY_3, 1.0); |
| 366 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 441 alternate_protocols = impl_.GetAlternateProtocols(test_host_port_pair); |
| 367 alternate = impl_.GetAlternateProtocol(test_host_port_pair); | 442 ASSERT_EQ(1u, alternate_protocols.size()); |
| 368 EXPECT_EQ(443, alternate.port); | 443 EXPECT_EQ(443, alternate_protocols[0].port); |
| 369 EXPECT_EQ(NPN_SPDY_3, alternate.protocol); | 444 EXPECT_EQ(NPN_SPDY_3, alternate_protocols[0].protocol); |
| 370 | 445 |
| 371 // Turn off the static, forced alternate protocol so that tests don't | 446 // Turn off the static, forced alternate protocol so that tests don't |
| 372 // have this state. | 447 // have this state. |
| 373 HttpServerPropertiesImpl::DisableForcedAlternateProtocol(); | 448 HttpServerPropertiesImpl::DisableForcedAlternateProtocol(); |
| 374 | 449 |
| 375 // Verify the forced protocol is off. | 450 // Verify the forced protocol is off. |
| 376 HostPortPair test_host_port_pair2("bar", 80); | 451 HostPortPair test_host_port_pair2("bar", 80); |
| 377 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair2)); | 452 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair2)); |
| 378 } | 453 } |
| 379 | 454 |
| 380 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) { | 455 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) { |
| 381 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 456 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
| 382 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 457 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
| 383 | 458 |
| 384 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 459 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
| 385 EXPECT_FALSE(HasAlternateProtocol(canonical_port_pair)); | 460 EXPECT_FALSE(HasAlternateProtocol(canonical_port_pair)); |
| 386 | 461 |
| 387 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); | 462 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
| 388 | 463 |
| 389 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 464 impl_.AddAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
| 390 canonical_protocol.protocol, 1.0); | 465 canonical_protocol.protocol, 1.0); |
| 391 // Verify the forced protocol. | 466 // Verify the forced protocol. |
| 392 ASSERT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 467 AlternateProtocols alternate_protocols = |
| 393 AlternateProtocolInfo alternate = | 468 impl_.GetAlternateProtocols(test_host_port_pair); |
| 394 impl_.GetAlternateProtocol(test_host_port_pair); | 469 ASSERT_EQ(1u, alternate_protocols.size()); |
| 395 EXPECT_EQ(canonical_protocol.port, alternate.port); | 470 EXPECT_EQ(canonical_protocol.port, alternate_protocols[0].port); |
| 396 EXPECT_EQ(canonical_protocol.protocol, alternate.protocol); | 471 EXPECT_EQ(canonical_protocol.protocol, alternate_protocols[0].protocol); |
| 397 | 472 |
| 398 // Verify the canonical suffix. | 473 // Verify the canonical suffix. |
| 399 EXPECT_EQ(".c.youtube.com", | 474 EXPECT_EQ(".c.youtube.com", |
| 400 impl_.GetCanonicalSuffix(test_host_port_pair.host())); | 475 impl_.GetCanonicalSuffix(test_host_port_pair.host())); |
| 401 EXPECT_EQ(".c.youtube.com", | 476 EXPECT_EQ(".c.youtube.com", |
| 402 impl_.GetCanonicalSuffix(canonical_port_pair.host())); | 477 impl_.GetCanonicalSuffix(canonical_port_pair.host())); |
| 403 } | 478 } |
| 404 | 479 |
| 405 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBelowThreshold) { | 480 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBelowThreshold) { |
| 406 impl_.SetAlternateProtocolProbabilityThreshold(0.02); | 481 impl_.SetAlternateProtocolProbabilityThreshold(0.02); |
| 407 | 482 |
| 408 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 483 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
| 409 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 484 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
| 410 AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.01); | 485 AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.01); |
| 411 | 486 |
| 412 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 487 impl_.AddAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
| 413 canonical_protocol.protocol, | 488 canonical_protocol.protocol, |
| 414 canonical_protocol.probability); | 489 canonical_protocol.probability); |
| 415 EXPECT_FALSE(HasAlternateProtocol(canonical_port_pair)); | 490 EXPECT_FALSE(HasAlternateProtocol(canonical_port_pair)); |
| 416 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 491 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
| 417 } | 492 } |
| 418 | 493 |
| 419 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalAboveThreshold) { | 494 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalAboveThreshold) { |
| 420 impl_.SetAlternateProtocolProbabilityThreshold(0.02); | 495 impl_.SetAlternateProtocolProbabilityThreshold(0.02); |
| 421 | 496 |
| 422 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 497 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
| 423 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 498 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
| 424 AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.03); | 499 AlternateProtocolInfo canonical_protocol(1234, QUIC, 0.03); |
| 425 | 500 |
| 426 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 501 impl_.AddAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
| 427 canonical_protocol.protocol, | 502 canonical_protocol.protocol, |
| 428 canonical_protocol.probability); | 503 canonical_protocol.probability); |
| 429 EXPECT_TRUE(HasAlternateProtocol(canonical_port_pair)); | 504 EXPECT_TRUE(HasAlternateProtocol(canonical_port_pair)); |
| 430 EXPECT_TRUE(HasAlternateProtocol(test_host_port_pair)); | 505 EXPECT_TRUE(HasAlternateProtocol(test_host_port_pair)); |
| 431 } | 506 } |
| 432 | 507 |
| 433 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { | 508 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { |
| 434 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 509 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
| 435 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 510 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
| 436 | 511 |
| 437 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); | 512 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
| 438 | 513 |
| 439 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 514 impl_.AddAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
| 440 canonical_protocol.protocol, | 515 canonical_protocol.protocol, |
| 441 canonical_protocol.probability); | 516 canonical_protocol.probability); |
| 442 | 517 |
| 443 impl_.ClearAlternateProtocol(canonical_port_pair); | 518 impl_.ClearAlternateProtocols(canonical_port_pair); |
| 444 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 519 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
| 445 } | 520 } |
| 446 | 521 |
| 447 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) { | 522 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) { |
| 448 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 523 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
| 449 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 524 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
| 450 | 525 |
| 451 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); | 526 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
| 452 | 527 |
| 453 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 528 impl_.AddAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
| 454 canonical_protocol.protocol, | 529 canonical_protocol.protocol, |
| 455 canonical_protocol.probability); | 530 canonical_protocol.probability); |
| 456 | 531 |
| 457 impl_.SetBrokenAlternateProtocol(canonical_port_pair); | 532 impl_.SetBrokenAlternateProtocol(test_host_port_pair, canonical_protocol); |
| 458 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 533 AlternateProtocols alternates = |
| 459 } | 534 impl_.GetAlternateProtocols(test_host_port_pair); |
| 460 | 535 ASSERT_EQ(1u, alternates.size()); |
| 461 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken2) { | 536 EXPECT_TRUE(alternates[0].is_broken); |
| 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 } | 537 } |
| 476 | 538 |
| 477 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { | 539 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { |
| 478 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 540 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
| 479 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); | 541 HostPortPair canonical_port_pair("bar.c.youtube.com", 80); |
| 480 | 542 |
| 481 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); | 543 AlternateProtocolInfo canonical_protocol(1234, QUIC, 1); |
| 482 | 544 |
| 483 impl_.SetAlternateProtocol(canonical_port_pair, canonical_protocol.port, | 545 impl_.AddAlternateProtocol(canonical_port_pair, canonical_protocol.port, |
| 484 canonical_protocol.protocol, | 546 canonical_protocol.protocol, |
| 485 canonical_protocol.probability); | 547 canonical_protocol.probability); |
| 486 | 548 |
| 487 impl_.Clear(); | 549 impl_.Clear(); |
| 488 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); | 550 EXPECT_FALSE(HasAlternateProtocol(test_host_port_pair)); |
| 489 } | 551 } |
| 490 | 552 |
| 491 typedef HttpServerPropertiesImplTest SpdySettingsServerPropertiesTest; | 553 typedef HttpServerPropertiesImplTest SpdySettingsServerPropertiesTest; |
| 492 | 554 |
| 493 TEST_F(SpdySettingsServerPropertiesTest, Initialize) { | 555 TEST_F(SpdySettingsServerPropertiesTest, Initialize) { |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); | 814 EXPECT_EQ(100, stats2->bandwidth_estimate.ToBitsPerSecond()); |
| 753 | 815 |
| 754 impl_.Clear(); | 816 impl_.Clear(); |
| 755 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server); | 817 const ServerNetworkStats* stats3 = impl_.GetServerNetworkStats(foo_server); |
| 756 EXPECT_EQ(NULL, stats3); | 818 EXPECT_EQ(NULL, stats3); |
| 757 } | 819 } |
| 758 | 820 |
| 759 } // namespace | 821 } // namespace |
| 760 | 822 |
| 761 } // namespace net | 823 } // namespace net |
| OLD | NEW |