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/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 class HttpServerPropertiesImplTest : public testing::Test { | 56 class HttpServerPropertiesImplTest : public testing::Test { |
57 protected: | 57 protected: |
58 bool HasAlternativeService(const HostPortPair& origin) { | 58 bool HasAlternativeService(const HostPortPair& origin) { |
59 const AlternativeServiceVector alternative_service_vector = | 59 const AlternativeServiceVector alternative_service_vector = |
60 impl_.GetAlternativeServices(origin); | 60 impl_.GetAlternativeServices(origin); |
61 return !alternative_service_vector.empty(); | 61 return !alternative_service_vector.empty(); |
62 } | 62 } |
63 | 63 |
64 bool SetAlternativeService(const HostPortPair& origin, | 64 bool SetAlternativeService(const HostPortPair& origin, |
65 const AlternativeService& alternative_service) { | 65 const AlternativeService& alternative_service, |
| 66 double alternative_probability) { |
66 const base::Time expiration = | 67 const base::Time expiration = |
67 base::Time::Now() + base::TimeDelta::FromDays(1); | 68 base::Time::Now() + base::TimeDelta::FromDays(1); |
68 return impl_.SetAlternativeService(origin, alternative_service, expiration); | 69 return impl_.SetAlternativeService(origin, alternative_service, |
| 70 alternative_probability, expiration); |
69 } | 71 } |
70 | 72 |
71 void InitializeSpdySettingsUploadBandwidth(SpdySettingsMap* spdy_settings_map, | 73 void InitializeSpdySettingsUploadBandwidth(SpdySettingsMap* spdy_settings_map, |
72 const HostPortPair& spdy_server, | 74 const HostPortPair& spdy_server, |
73 uint32_t value) { | 75 uint32_t value) { |
74 SettingsMap settings_map; | 76 SettingsMap settings_map; |
75 settings_map[kSpdySettingsId] = | 77 settings_map[kSpdySettingsId] = |
76 SettingsFlagsAndValue(kSpdySettingsFlags, value); | 78 SettingsFlagsAndValue(kSpdySettingsFlags, value); |
77 spdy_settings_map->Put(spdy_server, settings_map); | 79 spdy_settings_map->Put(spdy_server, settings_map); |
78 } | 80 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); | 216 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
215 | 217 |
216 // Add docs.google.com:443 as supporting SPDY. | 218 // Add docs.google.com:443 as supporting SPDY. |
217 HostPortPair spdy_server_docs("docs.google.com", 443); | 219 HostPortPair spdy_server_docs("docs.google.com", 443); |
218 impl_.SetSupportsSpdy(spdy_server_docs, true); | 220 impl_.SetSupportsSpdy(spdy_server_docs, true); |
219 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); | 221 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
220 | 222 |
221 // Add www.youtube.com:443 as supporting QUIC. | 223 // Add www.youtube.com:443 as supporting QUIC. |
222 HostPortPair quic_server_youtube("www.youtube.com", 443); | 224 HostPortPair quic_server_youtube("www.youtube.com", 443); |
223 const AlternativeService alternative_service1(QUIC, "www.youtube.com", 443); | 225 const AlternativeService alternative_service1(QUIC, "www.youtube.com", 443); |
224 SetAlternativeService(quic_server_youtube, alternative_service1); | 226 SetAlternativeService(quic_server_youtube, alternative_service1, 1.0); |
225 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); | 227 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); |
226 | 228 |
227 // Add www.example.com:443 with two alternative services, one supporting QUIC. | 229 // Add www.example.com:443 with two alternative services, one supporting QUIC. |
228 HostPortPair quic_server_example("www.example.com", 443); | 230 HostPortPair quic_server_example("www.example.com", 443); |
229 const AlternativeService alternative_service2(NPN_HTTP_2, "", 443); | 231 const AlternativeService alternative_service2(NPN_HTTP_2, "", 443); |
230 SetAlternativeService(quic_server_example, alternative_service2); | 232 SetAlternativeService(quic_server_example, alternative_service2, 1.0); |
231 SetAlternativeService(quic_server_example, alternative_service1); | 233 SetAlternativeService(quic_server_example, alternative_service1, 1.0); |
232 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_example)); | 234 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_example)); |
233 | 235 |
234 // Verify all the entries are the same after additions. | 236 // Verify all the entries are the same after additions. |
235 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); | 237 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_google)); |
236 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); | 238 EXPECT_FALSE(impl_.SupportsRequestPriority(spdy_server_mail)); |
237 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); | 239 EXPECT_TRUE(impl_.SupportsRequestPriority(spdy_server_docs)); |
238 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); | 240 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_youtube)); |
239 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_example)); | 241 EXPECT_TRUE(impl_.SupportsRequestPriority(quic_server_example)); |
240 } | 242 } |
241 | 243 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 ASSERT_EQ(spdy_server_m, string_value_m); | 351 ASSERT_EQ(spdy_server_m, string_value_m); |
350 } | 352 } |
351 | 353 |
352 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; | 354 typedef HttpServerPropertiesImplTest AlternateProtocolServerPropertiesTest; |
353 | 355 |
354 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { | 356 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { |
355 HostPortPair test_host_port_pair("foo", 80); | 357 HostPortPair test_host_port_pair("foo", 80); |
356 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 358 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
357 | 359 |
358 AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); | 360 AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); |
359 SetAlternativeService(test_host_port_pair, alternative_service); | 361 SetAlternativeService(test_host_port_pair, alternative_service, 1.0); |
360 const AlternativeServiceVector alternative_service_vector = | 362 const AlternativeServiceVector alternative_service_vector = |
361 impl_.GetAlternativeServices(test_host_port_pair); | 363 impl_.GetAlternativeServices(test_host_port_pair); |
362 ASSERT_EQ(1u, alternative_service_vector.size()); | 364 ASSERT_EQ(1u, alternative_service_vector.size()); |
363 EXPECT_EQ(alternative_service, alternative_service_vector[0]); | 365 EXPECT_EQ(alternative_service, alternative_service_vector[0]); |
364 | 366 |
365 impl_.Clear(); | 367 impl_.Clear(); |
366 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 368 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
367 } | 369 } |
368 | 370 |
369 TEST_F(AlternateProtocolServerPropertiesTest, ExcludeOrigin) { | 371 TEST_F(AlternateProtocolServerPropertiesTest, ExcludeOrigin) { |
370 AlternativeServiceInfoVector alternative_service_info_vector; | 372 AlternativeServiceInfoVector alternative_service_info_vector; |
371 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 373 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
372 // Same hostname, same port, TCP: should be ignored. | 374 // Same hostname, same port, TCP: should be ignored. |
373 AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); | 375 AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); |
374 alternative_service_info_vector.push_back( | 376 alternative_service_info_vector.push_back( |
375 AlternativeServiceInfo(alternative_service1, expiration)); | 377 AlternativeServiceInfo(alternative_service1, 1.0, expiration)); |
376 // Different hostname: GetAlternativeServices should return this one. | 378 // Different hostname: GetAlternativeServices should return this one. |
377 AlternativeService alternative_service2(NPN_HTTP_2, "bar", 443); | 379 AlternativeService alternative_service2(NPN_HTTP_2, "bar", 443); |
378 alternative_service_info_vector.push_back( | 380 alternative_service_info_vector.push_back( |
379 AlternativeServiceInfo(alternative_service2, expiration)); | 381 AlternativeServiceInfo(alternative_service2, 1.0, expiration)); |
380 // Different port: GetAlternativeServices should return this one too. | 382 // Different port: GetAlternativeServices should return this one too. |
381 AlternativeService alternative_service3(NPN_HTTP_2, "foo", 80); | 383 AlternativeService alternative_service3(NPN_HTTP_2, "foo", 80); |
382 alternative_service_info_vector.push_back( | 384 alternative_service_info_vector.push_back( |
383 AlternativeServiceInfo(alternative_service3, expiration)); | 385 AlternativeServiceInfo(alternative_service3, 1.0, expiration)); |
384 // QUIC: GetAlternativeServices should return this one too. | 386 // QUIC: GetAlternativeServices should return this one too. |
385 AlternativeService alternative_service4(QUIC, "foo", 443); | 387 AlternativeService alternative_service4(QUIC, "foo", 443); |
386 alternative_service_info_vector.push_back( | 388 alternative_service_info_vector.push_back( |
387 AlternativeServiceInfo(alternative_service4, expiration)); | 389 AlternativeServiceInfo(alternative_service4, 1.0, expiration)); |
388 | 390 |
389 HostPortPair test_host_port_pair("foo", 443); | 391 HostPortPair test_host_port_pair("foo", 443); |
390 impl_.SetAlternativeServices(test_host_port_pair, | 392 impl_.SetAlternativeServices(test_host_port_pair, |
391 alternative_service_info_vector); | 393 alternative_service_info_vector); |
392 | 394 |
393 const AlternativeServiceVector alternative_service_vector = | 395 const AlternativeServiceVector alternative_service_vector = |
394 impl_.GetAlternativeServices(test_host_port_pair); | 396 impl_.GetAlternativeServices(test_host_port_pair); |
395 ASSERT_EQ(3u, alternative_service_vector.size()); | 397 ASSERT_EQ(3u, alternative_service_vector.size()); |
396 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); | 398 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); |
397 EXPECT_EQ(alternative_service3, alternative_service_vector[1]); | 399 EXPECT_EQ(alternative_service3, alternative_service_vector[1]); |
398 EXPECT_EQ(alternative_service4, alternative_service_vector[2]); | 400 EXPECT_EQ(alternative_service4, alternative_service_vector[2]); |
399 } | 401 } |
400 | 402 |
| 403 TEST_F(AlternateProtocolServerPropertiesTest, DefaultProbabilityExcluded) { |
| 404 HostPortPair test_host_port_pair("foo", 80); |
| 405 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); |
| 406 SetAlternativeService(test_host_port_pair, alternative_service, 0.99); |
| 407 |
| 408 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
| 409 } |
| 410 |
| 411 // GetAlternativeServices and HasAlternativeServices should only return the ones |
| 412 // with probability greater than or equal to the threshold. |
| 413 TEST_F(AlternateProtocolServerPropertiesTest, Probability) { |
| 414 impl_.SetAlternativeServiceProbabilityThreshold(0.5); |
| 415 |
| 416 AlternativeServiceInfoVector alternative_service_info_vector; |
| 417 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 418 const AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); |
| 419 alternative_service_info_vector.push_back( |
| 420 AlternativeServiceInfo(alternative_service1, 0.3, expiration)); |
| 421 const AlternativeService alternative_service2(QUIC, "bar", 123); |
| 422 alternative_service_info_vector.push_back( |
| 423 AlternativeServiceInfo(alternative_service2, 0.7, expiration)); |
| 424 const AlternativeService alternative_service3(NPN_SPDY_3_1, "baz", 443); |
| 425 alternative_service_info_vector.push_back( |
| 426 AlternativeServiceInfo(alternative_service3, 0.4, expiration)); |
| 427 const AlternativeService alternative_service4(NPN_HTTP_2, "qux", 1234); |
| 428 alternative_service_info_vector.push_back( |
| 429 AlternativeServiceInfo(alternative_service4, 0.6, expiration)); |
| 430 |
| 431 HostPortPair test_host_port_pair("foo", 80); |
| 432 impl_.SetAlternativeServices(test_host_port_pair, |
| 433 alternative_service_info_vector); |
| 434 |
| 435 const AlternativeServiceVector alternative_service_vector = |
| 436 impl_.GetAlternativeServices(test_host_port_pair); |
| 437 ASSERT_EQ(2u, alternative_service_vector.size()); |
| 438 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); |
| 439 EXPECT_EQ(alternative_service4, alternative_service_vector[1]); |
| 440 } |
| 441 |
| 442 TEST_F(AlternateProtocolServerPropertiesTest, ProbabilityExcluded) { |
| 443 impl_.SetAlternativeServiceProbabilityThreshold(0.75); |
| 444 |
| 445 HostPortPair test_host_port_pair("foo", 80); |
| 446 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); |
| 447 SetAlternativeService(test_host_port_pair, alternative_service, 0.5); |
| 448 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
| 449 } |
| 450 |
| 451 TEST_F(AlternateProtocolServerPropertiesTest, ZeroProbabilityAlwaysExcluded) { |
| 452 impl_.SetAlternativeServiceProbabilityThreshold(0.0); |
| 453 |
| 454 HostPortPair test_host_port_pair("foo", 80); |
| 455 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); |
| 456 SetAlternativeService(test_host_port_pair, alternative_service, 0); |
| 457 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
| 458 } |
| 459 |
401 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { | 460 TEST_F(AlternateProtocolServerPropertiesTest, Initialize) { |
402 // |test_host_port_pair1| has an alternative service, which will not be | 461 // |test_host_port_pair1| has an alternative service, which will not be |
403 // affected by InitializeAlternativeServiceServers(), because | 462 // affected by InitializeAlternativeServiceServers(), because |
404 // |alternative_service_map| does not have an entry for | 463 // |alternative_service_map| does not have an entry for |
405 // |test_host_port_pair1|. | 464 // |test_host_port_pair1|. |
406 HostPortPair test_host_port_pair1("foo1", 80); | 465 HostPortPair test_host_port_pair1("foo1", 80); |
407 const AlternativeService alternative_service1(NPN_HTTP_2, "bar1", 443); | 466 const AlternativeService alternative_service1(NPN_HTTP_2, "bar1", 443); |
408 const base::Time now = base::Time::Now(); | 467 const base::Time now = base::Time::Now(); |
409 base::Time expiration1 = now + base::TimeDelta::FromDays(1); | 468 base::Time expiration1 = now + base::TimeDelta::FromDays(1); |
410 // 1st entry in the memory. | 469 // 1st entry in the memory. |
411 impl_.SetAlternativeService(test_host_port_pair1, alternative_service1, | 470 impl_.SetAlternativeService(test_host_port_pair1, alternative_service1, 1.0, |
412 expiration1); | 471 expiration1); |
413 | 472 |
414 // |test_host_port_pair2| has an alternative service, which will be | 473 // |test_host_port_pair2| has an alternative service, which will be |
415 // overwritten by InitializeAlternativeServiceServers(), because | 474 // overwritten by InitializeAlternativeServiceServers(), because |
416 // |alternative_service_map| has an entry for | 475 // |alternative_service_map| has an entry for |
417 // |test_host_port_pair2|. | 476 // |test_host_port_pair2|. |
418 AlternativeServiceInfoVector alternative_service_info_vector; | 477 AlternativeServiceInfoVector alternative_service_info_vector; |
419 const AlternativeService alternative_service2(NPN_SPDY_3_1, "bar2", 443); | 478 const AlternativeService alternative_service2(NPN_SPDY_3_1, "bar2", 443); |
420 base::Time expiration2 = now + base::TimeDelta::FromDays(2); | 479 base::Time expiration2 = now + base::TimeDelta::FromDays(2); |
421 alternative_service_info_vector.push_back( | 480 alternative_service_info_vector.push_back( |
422 AlternativeServiceInfo(alternative_service2, expiration2)); | 481 AlternativeServiceInfo(alternative_service2, 1.0, expiration2)); |
423 HostPortPair test_host_port_pair2("foo2", 80); | 482 HostPortPair test_host_port_pair2("foo2", 80); |
424 // 0th entry in the memory. | 483 // 0th entry in the memory. |
425 impl_.SetAlternativeServices(test_host_port_pair2, | 484 impl_.SetAlternativeServices(test_host_port_pair2, |
426 alternative_service_info_vector); | 485 alternative_service_info_vector); |
427 | 486 |
428 // Prepare |alternative_service_map| to be loaded by | 487 // Prepare |alternative_service_map| to be loaded by |
429 // InitializeAlternativeServiceServers(). | 488 // InitializeAlternativeServiceServers(). |
430 AlternativeServiceMap alternative_service_map( | 489 AlternativeServiceMap alternative_service_map( |
431 AlternativeServiceMap::NO_AUTO_EVICT); | 490 AlternativeServiceMap::NO_AUTO_EVICT); |
432 const AlternativeService alternative_service3(NPN_HTTP_2, "bar3", 123); | 491 const AlternativeService alternative_service3(NPN_HTTP_2, "bar3", 123); |
433 base::Time expiration3 = now + base::TimeDelta::FromDays(3); | 492 base::Time expiration3 = now + base::TimeDelta::FromDays(3); |
434 const AlternativeServiceInfo alternative_service_info1(alternative_service3, | 493 const AlternativeServiceInfo alternative_service_info1(alternative_service3, |
435 expiration3); | 494 0.7, expiration3); |
436 // Simulate updating data for 0th entry with data from Preferences. | 495 // Simulate updating data for 0th entry with data from Preferences. |
437 alternative_service_map.Put( | 496 alternative_service_map.Put( |
438 test_host_port_pair2, | 497 test_host_port_pair2, |
439 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info1)); | 498 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info1)); |
440 | 499 |
441 HostPortPair test_host_port_pair3("foo3", 80); | 500 HostPortPair test_host_port_pair3("foo3", 80); |
442 const AlternativeService alternative_service4(NPN_HTTP_2, "bar4", 1234); | 501 const AlternativeService alternative_service4(NPN_HTTP_2, "bar4", 1234); |
443 base::Time expiration4 = now + base::TimeDelta::FromDays(4); | 502 base::Time expiration4 = now + base::TimeDelta::FromDays(4); |
444 const AlternativeServiceInfo alternative_service_info2(alternative_service4, | 503 const AlternativeServiceInfo alternative_service_info2(alternative_service4, |
445 expiration4); | 504 0.2, expiration4); |
446 // Add an old entry from Preferences, this will be added to end of recency | 505 // Add an old entry from Preferences, this will be added to end of recency |
447 // list. | 506 // list. |
448 alternative_service_map.Put( | 507 alternative_service_map.Put( |
449 test_host_port_pair3, | 508 test_host_port_pair3, |
450 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info2)); | 509 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info2)); |
451 | 510 |
452 // MRU list will be test_host_port_pair2, test_host_port_pair1, | 511 // MRU list will be test_host_port_pair2, test_host_port_pair1, |
453 // test_host_port_pair3. | 512 // test_host_port_pair3. |
454 impl_.InitializeAlternativeServiceServers(&alternative_service_map); | 513 impl_.InitializeAlternativeServiceServers(&alternative_service_map); |
455 | 514 |
456 // Verify alternative_service_map. | 515 // Verify alternative_service_map. |
457 const AlternativeServiceMap& map = impl_.alternative_service_map(); | 516 const AlternativeServiceMap& map = impl_.alternative_service_map(); |
458 ASSERT_EQ(3u, map.size()); | 517 ASSERT_EQ(3u, map.size()); |
459 AlternativeServiceMap::const_iterator map_it = map.begin(); | 518 AlternativeServiceMap::const_iterator map_it = map.begin(); |
460 | 519 |
461 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair2)); | 520 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair2)); |
462 ASSERT_EQ(1u, map_it->second.size()); | 521 ASSERT_EQ(1u, map_it->second.size()); |
463 EXPECT_EQ(alternative_service3, map_it->second[0].alternative_service); | 522 EXPECT_EQ(alternative_service3, map_it->second[0].alternative_service); |
| 523 EXPECT_EQ(0.7, map_it->second[0].probability); |
464 EXPECT_EQ(expiration3, map_it->second[0].expiration); | 524 EXPECT_EQ(expiration3, map_it->second[0].expiration); |
465 ++map_it; | 525 ++map_it; |
466 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair1)); | 526 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair1)); |
467 ASSERT_EQ(1u, map_it->second.size()); | 527 ASSERT_EQ(1u, map_it->second.size()); |
468 EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service); | 528 EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service); |
| 529 EXPECT_EQ(1.0, map_it->second[0].probability); |
469 EXPECT_EQ(expiration1, map_it->second[0].expiration); | 530 EXPECT_EQ(expiration1, map_it->second[0].expiration); |
470 ++map_it; | 531 ++map_it; |
471 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair3)); | 532 EXPECT_TRUE(map_it->first.Equals(test_host_port_pair3)); |
472 ASSERT_EQ(1u, map_it->second.size()); | 533 ASSERT_EQ(1u, map_it->second.size()); |
473 EXPECT_EQ(alternative_service4, map_it->second[0].alternative_service); | 534 EXPECT_EQ(alternative_service4, map_it->second[0].alternative_service); |
| 535 EXPECT_EQ(0.2, map_it->second[0].probability); |
474 EXPECT_EQ(expiration4, map_it->second[0].expiration); | 536 EXPECT_EQ(expiration4, map_it->second[0].expiration); |
475 } | 537 } |
476 | 538 |
477 // Regression test for https://crbug.com/504032: | 539 // Regression test for https://crbug.com/504032: |
478 // InitializeAlternativeServiceServers() should not crash if there is an empty | 540 // InitializeAlternativeServiceServers() should not crash if there is an empty |
479 // hostname is the mapping. | 541 // hostname is the mapping. |
480 TEST_F(AlternateProtocolServerPropertiesTest, InitializeWithEmptyHostname) { | 542 TEST_F(AlternateProtocolServerPropertiesTest, InitializeWithEmptyHostname) { |
481 const HostPortPair host_port_pair("foo", 443); | 543 const HostPortPair host_port_pair("foo", 443); |
482 const AlternativeService alternative_service_with_empty_hostname(NPN_HTTP_2, | 544 const AlternativeService alternative_service_with_empty_hostname(NPN_HTTP_2, |
483 "", 1234); | 545 "", 1234); |
484 const AlternativeService alternative_service_with_foo_hostname(NPN_HTTP_2, | 546 const AlternativeService alternative_service_with_foo_hostname(NPN_HTTP_2, |
485 "foo", 1234); | 547 "foo", 1234); |
486 SetAlternativeService(host_port_pair, | 548 SetAlternativeService(host_port_pair, alternative_service_with_empty_hostname, |
487 alternative_service_with_empty_hostname); | 549 1.0); |
488 impl_.MarkAlternativeServiceBroken(alternative_service_with_foo_hostname); | 550 impl_.MarkAlternativeServiceBroken(alternative_service_with_foo_hostname); |
489 | 551 |
490 AlternativeServiceMap alternative_service_map( | 552 AlternativeServiceMap alternative_service_map( |
491 AlternativeServiceMap::NO_AUTO_EVICT); | 553 AlternativeServiceMap::NO_AUTO_EVICT); |
492 impl_.InitializeAlternativeServiceServers(&alternative_service_map); | 554 impl_.InitializeAlternativeServiceServers(&alternative_service_map); |
493 | 555 |
494 EXPECT_TRUE( | 556 EXPECT_TRUE( |
495 impl_.IsAlternativeServiceBroken(alternative_service_with_foo_hostname)); | 557 impl_.IsAlternativeServiceBroken(alternative_service_with_foo_hostname)); |
496 const AlternativeServiceVector alternative_service_vector = | 558 const AlternativeServiceVector alternative_service_vector = |
497 impl_.GetAlternativeServices(host_port_pair); | 559 impl_.GetAlternativeServices(host_port_pair); |
498 ASSERT_EQ(1u, alternative_service_vector.size()); | 560 ASSERT_EQ(1u, alternative_service_vector.size()); |
499 EXPECT_EQ(alternative_service_with_foo_hostname, | 561 EXPECT_EQ(alternative_service_with_foo_hostname, |
500 alternative_service_vector[0]); | 562 alternative_service_vector[0]); |
501 } | 563 } |
502 | 564 |
503 // Regression test for https://crbug.com/516486: | 565 // Regression test for https://crbug.com/516486: |
504 // GetAlternativeServices() should remove |alternative_service_map_| elements | 566 // GetAlternativeServices() should remove |alternative_service_map_| elements |
505 // with empty value. | 567 // with empty value. |
506 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVector) { | 568 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVector) { |
507 HostPortPair host_port_pair("foo", 443); | 569 HostPortPair host_port_pair("foo", 443); |
508 const AlternativeService alternative_service(NPN_HTTP_2, "bar", 443); | 570 const AlternativeService alternative_service(NPN_HTTP_2, "bar", 443); |
509 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); | 571 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); |
510 const AlternativeServiceInfo alternative_service_info(alternative_service, | 572 const AlternativeServiceInfo alternative_service_info(alternative_service, |
511 expiration); | 573 1.0, expiration); |
512 AlternativeServiceMap alternative_service_map( | 574 AlternativeServiceMap alternative_service_map( |
513 AlternativeServiceMap::NO_AUTO_EVICT); | 575 AlternativeServiceMap::NO_AUTO_EVICT); |
514 alternative_service_map.Put( | 576 alternative_service_map.Put( |
515 host_port_pair, | 577 host_port_pair, |
516 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); | 578 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); |
517 | 579 |
518 // Prepare |alternative_service_map_| with a single key that has a single | 580 // Prepare |alternative_service_map_| with a single key that has a single |
519 // AlternativeServiceInfo with identical hostname and port. | 581 // AlternativeServiceInfo with identical hostname and port. |
520 impl_.InitializeAlternativeServiceServers(&alternative_service_map); | 582 impl_.InitializeAlternativeServiceServers(&alternative_service_map); |
521 | 583 |
(...skipping 15 matching lines...) Expand all Loading... |
537 ASSERT_TRUE(alternative_service_vector.empty()); | 599 ASSERT_TRUE(alternative_service_vector.empty()); |
538 } | 600 } |
539 | 601 |
540 // Regression test for https://crbug.com/516486 for the canonical host case. | 602 // Regression test for https://crbug.com/516486 for the canonical host case. |
541 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVectorForCanonical) { | 603 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVectorForCanonical) { |
542 HostPortPair host_port_pair("foo.c.youtube.com", 443); | 604 HostPortPair host_port_pair("foo.c.youtube.com", 443); |
543 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 443); | 605 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 443); |
544 const AlternativeService alternative_service(NPN_HTTP_2, "", 443); | 606 const AlternativeService alternative_service(NPN_HTTP_2, "", 443); |
545 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); | 607 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); |
546 const AlternativeServiceInfo alternative_service_info(alternative_service, | 608 const AlternativeServiceInfo alternative_service_info(alternative_service, |
547 expiration); | 609 1.0, expiration); |
548 AlternativeServiceMap alternative_service_map( | 610 AlternativeServiceMap alternative_service_map( |
549 AlternativeServiceMap::NO_AUTO_EVICT); | 611 AlternativeServiceMap::NO_AUTO_EVICT); |
550 alternative_service_map.Put( | 612 alternative_service_map.Put( |
551 canonical_host_port_pair, | 613 canonical_host_port_pair, |
552 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); | 614 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); |
553 | 615 |
554 // Prepare |alternative_service_map_| with a single key that has a single | 616 // Prepare |alternative_service_map_| with a single key that has a single |
555 // AlternativeServiceInfo with identical hostname and port. | 617 // AlternativeServiceInfo with identical hostname and port. |
556 impl_.InitializeAlternativeServiceServers(&alternative_service_map); | 618 impl_.InitializeAlternativeServiceServers(&alternative_service_map); |
557 | 619 |
(...skipping 14 matching lines...) Expand all Loading... |
572 // There should still be no alternative service assigned to | 634 // There should still be no alternative service assigned to |
573 // |canonical_host_port_pair|. | 635 // |canonical_host_port_pair|. |
574 alternative_service_vector = | 636 alternative_service_vector = |
575 impl_.GetAlternativeServices(canonical_host_port_pair); | 637 impl_.GetAlternativeServices(canonical_host_port_pair); |
576 ASSERT_TRUE(alternative_service_vector.empty()); | 638 ASSERT_TRUE(alternative_service_vector.empty()); |
577 } | 639 } |
578 | 640 |
579 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternativeServices) { | 641 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternativeServices) { |
580 HostPortPair test_host_port_pair1("foo1", 80); | 642 HostPortPair test_host_port_pair1("foo1", 80); |
581 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo1", 443); | 643 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo1", 443); |
582 SetAlternativeService(test_host_port_pair1, alternative_service1); | 644 SetAlternativeService(test_host_port_pair1, alternative_service1, 1.0); |
583 HostPortPair test_host_port_pair2("foo2", 80); | 645 HostPortPair test_host_port_pair2("foo2", 80); |
584 const AlternativeService alternative_service2(NPN_HTTP_2, "foo2", 1234); | 646 const AlternativeService alternative_service2(NPN_HTTP_2, "foo2", 1234); |
585 SetAlternativeService(test_host_port_pair2, alternative_service2); | 647 SetAlternativeService(test_host_port_pair2, alternative_service2, 1.0); |
586 | 648 |
587 const AlternativeServiceMap& map = impl_.alternative_service_map(); | 649 const AlternativeServiceMap& map = impl_.alternative_service_map(); |
588 AlternativeServiceMap::const_iterator it = map.begin(); | 650 AlternativeServiceMap::const_iterator it = map.begin(); |
589 EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); | 651 EXPECT_TRUE(it->first.Equals(test_host_port_pair2)); |
590 ASSERT_EQ(1u, it->second.size()); | 652 ASSERT_EQ(1u, it->second.size()); |
591 EXPECT_EQ(alternative_service2, it->second[0].alternative_service); | 653 EXPECT_EQ(alternative_service2, it->second[0].alternative_service); |
592 | 654 |
593 const AlternativeServiceVector alternative_service_vector = | 655 const AlternativeServiceVector alternative_service_vector = |
594 impl_.GetAlternativeServices(test_host_port_pair1); | 656 impl_.GetAlternativeServices(test_host_port_pair1); |
595 ASSERT_EQ(1u, alternative_service_vector.size()); | 657 ASSERT_EQ(1u, alternative_service_vector.size()); |
596 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 658 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
597 | 659 |
598 // GetAlternativeServices should reorder the AlternateProtocol map. | 660 // GetAlternativeServices should reorder the AlternateProtocol map. |
599 it = map.begin(); | 661 it = map.begin(); |
600 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); | 662 EXPECT_TRUE(it->first.Equals(test_host_port_pair1)); |
601 ASSERT_EQ(1u, it->second.size()); | 663 ASSERT_EQ(1u, it->second.size()); |
602 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); | 664 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); |
603 } | 665 } |
604 | 666 |
605 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { | 667 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { |
606 HostPortPair test_host_port_pair("foo", 80); | 668 HostPortPair test_host_port_pair("foo", 80); |
607 const AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); | 669 const AlternativeService alternative_service1(NPN_HTTP_2, "foo", 443); |
608 SetAlternativeService(test_host_port_pair, alternative_service1); | 670 SetAlternativeService(test_host_port_pair, alternative_service1, 1.0); |
609 AlternativeServiceVector alternative_service_vector = | 671 AlternativeServiceVector alternative_service_vector = |
610 impl_.GetAlternativeServices(test_host_port_pair); | 672 impl_.GetAlternativeServices(test_host_port_pair); |
611 ASSERT_EQ(1u, alternative_service_vector.size()); | 673 ASSERT_EQ(1u, alternative_service_vector.size()); |
612 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 674 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
613 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service1)); | 675 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service1)); |
614 | 676 |
615 // GetAlternativeServices should return the broken alternative service. | 677 // GetAlternativeServices should return the broken alternative service. |
616 impl_.MarkAlternativeServiceBroken(alternative_service1); | 678 impl_.MarkAlternativeServiceBroken(alternative_service1); |
617 alternative_service_vector = | 679 alternative_service_vector = |
618 impl_.GetAlternativeServices(test_host_port_pair); | 680 impl_.GetAlternativeServices(test_host_port_pair); |
619 ASSERT_EQ(1u, alternative_service_vector.size()); | 681 ASSERT_EQ(1u, alternative_service_vector.size()); |
620 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 682 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
621 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); | 683 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); |
622 | 684 |
623 // SetAlternativeServices should add a broken alternative service to the map. | 685 // SetAlternativeServices should add a broken alternative service to the map. |
624 AlternativeServiceInfoVector alternative_service_info_vector; | 686 AlternativeServiceInfoVector alternative_service_info_vector; |
625 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 687 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
626 alternative_service_info_vector.push_back( | 688 alternative_service_info_vector.push_back( |
627 AlternativeServiceInfo(alternative_service1, expiration)); | 689 AlternativeServiceInfo(alternative_service1, 1.0, expiration)); |
628 const AlternativeService alternative_service2(NPN_HTTP_2, "foo", 1234); | 690 const AlternativeService alternative_service2(NPN_HTTP_2, "foo", 1234); |
629 alternative_service_info_vector.push_back( | 691 alternative_service_info_vector.push_back( |
630 AlternativeServiceInfo(alternative_service2, expiration)); | 692 AlternativeServiceInfo(alternative_service2, 1.0, expiration)); |
631 impl_.SetAlternativeServices(test_host_port_pair, | 693 impl_.SetAlternativeServices(test_host_port_pair, |
632 alternative_service_info_vector); | 694 alternative_service_info_vector); |
633 alternative_service_vector = | 695 alternative_service_vector = |
634 impl_.GetAlternativeServices(test_host_port_pair); | 696 impl_.GetAlternativeServices(test_host_port_pair); |
635 ASSERT_EQ(2u, alternative_service_vector.size()); | 697 ASSERT_EQ(2u, alternative_service_vector.size()); |
636 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 698 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
637 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); | 699 EXPECT_EQ(alternative_service2, alternative_service_vector[1]); |
638 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0])); | 700 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0])); |
639 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service_vector[1])); | 701 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service_vector[1])); |
640 | 702 |
641 // SetAlternativeService should add a broken alternative service to the map. | 703 // SetAlternativeService should add a broken alternative service to the map. |
642 SetAlternativeService(test_host_port_pair, alternative_service1); | 704 SetAlternativeService(test_host_port_pair, alternative_service1, 1.0); |
643 alternative_service_vector = | 705 alternative_service_vector = |
644 impl_.GetAlternativeServices(test_host_port_pair); | 706 impl_.GetAlternativeServices(test_host_port_pair); |
645 ASSERT_EQ(1u, alternative_service_vector.size()); | 707 ASSERT_EQ(1u, alternative_service_vector.size()); |
646 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); | 708 EXPECT_EQ(alternative_service1, alternative_service_vector[0]); |
647 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0])); | 709 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service_vector[0])); |
648 } | 710 } |
649 | 711 |
650 TEST_F(AlternateProtocolServerPropertiesTest, MaxAge) { | 712 TEST_F(AlternateProtocolServerPropertiesTest, MaxAge) { |
651 AlternativeServiceInfoVector alternative_service_info_vector; | 713 AlternativeServiceInfoVector alternative_service_info_vector; |
652 base::Time now = base::Time::Now(); | 714 base::Time now = base::Time::Now(); |
653 base::TimeDelta one_day = base::TimeDelta::FromDays(1); | 715 base::TimeDelta one_day = base::TimeDelta::FromDays(1); |
654 | 716 |
655 // First alternative service expired one day ago, should not be returned by | 717 // First alternative service expired one day ago, should not be returned by |
656 // GetAlternativeServices(). | 718 // GetAlternativeServices(). |
657 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); | 719 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); |
658 alternative_service_info_vector.push_back( | 720 alternative_service_info_vector.push_back( |
659 AlternativeServiceInfo(alternative_service1, now - one_day)); | 721 AlternativeServiceInfo(alternative_service1, 1.0, now - one_day)); |
660 | 722 |
661 // Second alterrnative service will expire one day from now, should be | 723 // Second alterrnative service will expire one day from now, should be |
662 // returned by GetAlternativeSerices(). | 724 // returned by GetAlternativeSerices(). |
663 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); | 725 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); |
664 alternative_service_info_vector.push_back( | 726 alternative_service_info_vector.push_back( |
665 AlternativeServiceInfo(alternative_service2, now + one_day)); | 727 AlternativeServiceInfo(alternative_service2, 1.0, now + one_day)); |
666 | 728 |
667 HostPortPair test_host_port_pair("foo", 80); | 729 HostPortPair test_host_port_pair("foo", 80); |
668 impl_.SetAlternativeServices(test_host_port_pair, | 730 impl_.SetAlternativeServices(test_host_port_pair, |
669 alternative_service_info_vector); | 731 alternative_service_info_vector); |
670 | 732 |
671 AlternativeServiceVector alternative_service_vector = | 733 AlternativeServiceVector alternative_service_vector = |
672 impl_.GetAlternativeServices(test_host_port_pair); | 734 impl_.GetAlternativeServices(test_host_port_pair); |
673 ASSERT_EQ(1u, alternative_service_vector.size()); | 735 ASSERT_EQ(1u, alternative_service_vector.size()); |
674 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); | 736 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); |
675 } | 737 } |
676 | 738 |
677 TEST_F(AlternateProtocolServerPropertiesTest, MaxAgeCanonical) { | 739 TEST_F(AlternateProtocolServerPropertiesTest, MaxAgeCanonical) { |
678 AlternativeServiceInfoVector alternative_service_info_vector; | 740 AlternativeServiceInfoVector alternative_service_info_vector; |
679 base::Time now = base::Time::Now(); | 741 base::Time now = base::Time::Now(); |
680 base::TimeDelta one_day = base::TimeDelta::FromDays(1); | 742 base::TimeDelta one_day = base::TimeDelta::FromDays(1); |
681 | 743 |
682 // First alternative service expired one day ago, should not be returned by | 744 // First alternative service expired one day ago, should not be returned by |
683 // GetAlternativeServices(). | 745 // GetAlternativeServices(). |
684 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); | 746 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); |
685 alternative_service_info_vector.push_back( | 747 alternative_service_info_vector.push_back( |
686 AlternativeServiceInfo(alternative_service1, now - one_day)); | 748 AlternativeServiceInfo(alternative_service1, 1.0, now - one_day)); |
687 | 749 |
688 // Second alterrnative service will expire one day from now, should be | 750 // Second alterrnative service will expire one day from now, should be |
689 // returned by GetAlternativeSerices(). | 751 // returned by GetAlternativeSerices(). |
690 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); | 752 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); |
691 alternative_service_info_vector.push_back( | 753 alternative_service_info_vector.push_back( |
692 AlternativeServiceInfo(alternative_service2, now + one_day)); | 754 AlternativeServiceInfo(alternative_service2, 1.0, now + one_day)); |
693 | 755 |
694 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); | 756 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); |
695 impl_.SetAlternativeServices(canonical_host_port_pair, | 757 impl_.SetAlternativeServices(canonical_host_port_pair, |
696 alternative_service_info_vector); | 758 alternative_service_info_vector); |
697 | 759 |
698 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 760 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
699 AlternativeServiceVector alternative_service_vector = | 761 AlternativeServiceVector alternative_service_vector = |
700 impl_.GetAlternativeServices(test_host_port_pair); | 762 impl_.GetAlternativeServices(test_host_port_pair); |
701 ASSERT_EQ(1u, alternative_service_vector.size()); | 763 ASSERT_EQ(1u, alternative_service_vector.size()); |
702 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); | 764 EXPECT_EQ(alternative_service2, alternative_service_vector[0]); |
703 } | 765 } |
704 | 766 |
705 TEST_F(AlternateProtocolServerPropertiesTest, ClearAlternativeServices) { | 767 TEST_F(AlternateProtocolServerPropertiesTest, ClearAlternativeServices) { |
706 AlternativeServiceInfoVector alternative_service_info_vector; | 768 AlternativeServiceInfoVector alternative_service_info_vector; |
707 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); | 769 const AlternativeService alternative_service1(NPN_SPDY_3_1, "foo", 443); |
708 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 770 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
709 alternative_service_info_vector.push_back( | 771 alternative_service_info_vector.push_back( |
710 AlternativeServiceInfo(alternative_service1, expiration)); | 772 AlternativeServiceInfo(alternative_service1, 1.0, expiration)); |
711 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); | 773 const AlternativeService alternative_service2(NPN_HTTP_2, "bar", 1234); |
712 alternative_service_info_vector.push_back( | 774 alternative_service_info_vector.push_back( |
713 AlternativeServiceInfo(alternative_service2, expiration)); | 775 AlternativeServiceInfo(alternative_service2, 1.0, expiration)); |
714 HostPortPair test_host_port_pair("foo", 80); | 776 HostPortPair test_host_port_pair("foo", 80); |
715 impl_.SetAlternativeServices(test_host_port_pair, | 777 impl_.SetAlternativeServices(test_host_port_pair, |
716 alternative_service_info_vector); | 778 alternative_service_info_vector); |
717 | 779 |
718 const net::AlternativeServiceMap& map = impl_.alternative_service_map(); | 780 const net::AlternativeServiceMap& map = impl_.alternative_service_map(); |
719 net::AlternativeServiceMap::const_iterator it = map.begin(); | 781 net::AlternativeServiceMap::const_iterator it = map.begin(); |
720 EXPECT_TRUE(it->first.Equals(test_host_port_pair)); | 782 EXPECT_TRUE(it->first.Equals(test_host_port_pair)); |
721 ASSERT_EQ(2u, it->second.size()); | 783 ASSERT_EQ(2u, it->second.size()); |
722 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); | 784 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); |
723 EXPECT_EQ(alternative_service2, it->second[1].alternative_service); | 785 EXPECT_EQ(alternative_service2, it->second[1].alternative_service); |
724 | 786 |
725 impl_.ClearAlternativeServices(test_host_port_pair); | 787 impl_.ClearAlternativeServices(test_host_port_pair); |
726 EXPECT_TRUE(map.empty()); | 788 EXPECT_TRUE(map.empty()); |
727 } | 789 } |
728 | 790 |
729 // A broken alternative service in the mapping carries meaningful information, | 791 // A broken alternative service in the mapping carries meaningful information, |
730 // therefore it should not be ignored by SetAlternativeService(). In | 792 // therefore it should not be ignored by SetAlternativeService(). In |
731 // particular, an alternative service mapped to an origin shadows alternative | 793 // particular, an alternative service mapped to an origin shadows alternative |
732 // services of canonical hosts. | 794 // services of canonical hosts. |
733 TEST_F(AlternateProtocolServerPropertiesTest, BrokenShadowsCanonical) { | 795 TEST_F(AlternateProtocolServerPropertiesTest, BrokenShadowsCanonical) { |
734 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 796 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
735 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); | 797 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); |
736 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", | 798 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
737 1234); | 799 1234); |
738 SetAlternativeService(canonical_host_port_pair, | 800 SetAlternativeService(canonical_host_port_pair, canonical_alternative_service, |
739 canonical_alternative_service); | 801 1.0); |
740 AlternativeServiceVector alternative_service_vector = | 802 AlternativeServiceVector alternative_service_vector = |
741 impl_.GetAlternativeServices(test_host_port_pair); | 803 impl_.GetAlternativeServices(test_host_port_pair); |
742 ASSERT_EQ(1u, alternative_service_vector.size()); | 804 ASSERT_EQ(1u, alternative_service_vector.size()); |
743 EXPECT_EQ(canonical_alternative_service, alternative_service_vector[0]); | 805 EXPECT_EQ(canonical_alternative_service, alternative_service_vector[0]); |
744 | 806 |
745 const AlternativeService broken_alternative_service(NPN_HTTP_2, "foo", 443); | 807 const AlternativeService broken_alternative_service(NPN_HTTP_2, "foo", 443); |
746 impl_.MarkAlternativeServiceBroken(broken_alternative_service); | 808 impl_.MarkAlternativeServiceBroken(broken_alternative_service); |
747 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); | 809 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); |
748 | 810 |
749 SetAlternativeService(test_host_port_pair, broken_alternative_service); | 811 SetAlternativeService(test_host_port_pair, broken_alternative_service, 1.0); |
750 alternative_service_vector = | 812 alternative_service_vector = |
751 impl_.GetAlternativeServices(test_host_port_pair); | 813 impl_.GetAlternativeServices(test_host_port_pair); |
752 ASSERT_EQ(1u, alternative_service_vector.size()); | 814 ASSERT_EQ(1u, alternative_service_vector.size()); |
753 EXPECT_EQ(broken_alternative_service, alternative_service_vector[0]); | 815 EXPECT_EQ(broken_alternative_service, alternative_service_vector[0]); |
754 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); | 816 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); |
755 } | 817 } |
756 | 818 |
757 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { | 819 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { |
758 HostPortPair test_host_port_pair("foo", 80); | 820 HostPortPair test_host_port_pair("foo", 80); |
759 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); | 821 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); |
760 SetAlternativeService(test_host_port_pair, alternative_service); | 822 SetAlternativeService(test_host_port_pair, alternative_service, 1.0); |
761 impl_.MarkAlternativeServiceBroken(alternative_service); | 823 impl_.MarkAlternativeServiceBroken(alternative_service); |
762 ASSERT_TRUE(HasAlternativeService(test_host_port_pair)); | 824 ASSERT_TRUE(HasAlternativeService(test_host_port_pair)); |
763 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 825 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
764 // ClearAlternativeServices should leave a broken alternative service marked | 826 // ClearAlternativeServices should leave a broken alternative service marked |
765 // as such. | 827 // as such. |
766 impl_.ClearAlternativeServices(test_host_port_pair); | 828 impl_.ClearAlternativeServices(test_host_port_pair); |
767 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 829 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
768 } | 830 } |
769 | 831 |
770 TEST_F(AlternateProtocolServerPropertiesTest, MarkRecentlyBroken) { | 832 TEST_F(AlternateProtocolServerPropertiesTest, MarkRecentlyBroken) { |
771 HostPortPair host_port_pair("foo", 80); | 833 HostPortPair host_port_pair("foo", 80); |
772 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); | 834 const AlternativeService alternative_service(NPN_HTTP_2, "foo", 443); |
773 SetAlternativeService(host_port_pair, alternative_service); | 835 SetAlternativeService(host_port_pair, alternative_service, 1.0); |
774 | 836 |
775 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 837 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
776 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 838 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
777 | 839 |
778 impl_.MarkAlternativeServiceRecentlyBroken(alternative_service); | 840 impl_.MarkAlternativeServiceRecentlyBroken(alternative_service); |
779 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 841 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
780 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 842 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
781 | 843 |
782 impl_.ConfirmAlternativeService(alternative_service); | 844 impl_.ConfirmAlternativeService(alternative_service); |
783 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 845 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
784 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 846 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
785 } | 847 } |
786 | 848 |
787 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) { | 849 TEST_F(AlternateProtocolServerPropertiesTest, Canonical) { |
788 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 850 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
789 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 851 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
790 | 852 |
791 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); | 853 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); |
792 EXPECT_FALSE(HasAlternativeService(canonical_host_port_pair)); | 854 EXPECT_FALSE(HasAlternativeService(canonical_host_port_pair)); |
793 | 855 |
794 AlternativeServiceInfoVector alternative_service_info_vector; | 856 AlternativeServiceInfoVector alternative_service_info_vector; |
795 const AlternativeService canonical_alternative_service1( | 857 const AlternativeService canonical_alternative_service1( |
796 QUIC, "bar.c.youtube.com", 1234); | 858 QUIC, "bar.c.youtube.com", 1234); |
797 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 859 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
798 alternative_service_info_vector.push_back( | 860 alternative_service_info_vector.push_back( |
799 AlternativeServiceInfo(canonical_alternative_service1, expiration)); | 861 AlternativeServiceInfo(canonical_alternative_service1, 1.0, expiration)); |
800 const AlternativeService canonical_alternative_service2(NPN_HTTP_2, "", 443); | 862 const AlternativeService canonical_alternative_service2(NPN_HTTP_2, "", 443); |
801 alternative_service_info_vector.push_back( | 863 alternative_service_info_vector.push_back( |
802 AlternativeServiceInfo(canonical_alternative_service2, expiration)); | 864 AlternativeServiceInfo(canonical_alternative_service2, 1.0, expiration)); |
803 impl_.SetAlternativeServices(canonical_host_port_pair, | 865 impl_.SetAlternativeServices(canonical_host_port_pair, |
804 alternative_service_info_vector); | 866 alternative_service_info_vector); |
805 | 867 |
806 // Since |test_host_port_pair| does not have an alternative service itself, | 868 // Since |test_host_port_pair| does not have an alternative service itself, |
807 // GetAlternativeServices should return those of |canonical_host_port_pair|. | 869 // GetAlternativeServices should return those of |canonical_host_port_pair|. |
808 AlternativeServiceVector alternative_service_vector = | 870 AlternativeServiceVector alternative_service_vector = |
809 impl_.GetAlternativeServices(test_host_port_pair); | 871 impl_.GetAlternativeServices(test_host_port_pair); |
810 ASSERT_EQ(2u, alternative_service_vector.size()); | 872 ASSERT_EQ(2u, alternative_service_vector.size()); |
811 EXPECT_EQ(canonical_alternative_service1, alternative_service_vector[0]); | 873 EXPECT_EQ(canonical_alternative_service1, alternative_service_vector[0]); |
812 | 874 |
813 // Since |canonical_alternative_service2| has an empty host, | 875 // Since |canonical_alternative_service2| has an empty host, |
814 // GetAlternativeServices should substitute the hostname of its |origin| | 876 // GetAlternativeServices should substitute the hostname of its |origin| |
815 // argument. | 877 // argument. |
816 EXPECT_EQ(test_host_port_pair.host(), alternative_service_vector[1].host); | 878 EXPECT_EQ(test_host_port_pair.host(), alternative_service_vector[1].host); |
817 EXPECT_EQ(canonical_alternative_service2.protocol, | 879 EXPECT_EQ(canonical_alternative_service2.protocol, |
818 alternative_service_vector[1].protocol); | 880 alternative_service_vector[1].protocol); |
819 EXPECT_EQ(canonical_alternative_service2.port, | 881 EXPECT_EQ(canonical_alternative_service2.port, |
820 alternative_service_vector[1].port); | 882 alternative_service_vector[1].port); |
821 | 883 |
822 // Verify the canonical suffix. | 884 // Verify the canonical suffix. |
823 EXPECT_EQ(".c.youtube.com", | 885 EXPECT_EQ(".c.youtube.com", |
824 impl_.GetCanonicalSuffix(test_host_port_pair.host())); | 886 impl_.GetCanonicalSuffix(test_host_port_pair.host())); |
825 EXPECT_EQ(".c.youtube.com", | 887 EXPECT_EQ(".c.youtube.com", |
826 impl_.GetCanonicalSuffix(canonical_host_port_pair.host())); | 888 impl_.GetCanonicalSuffix(canonical_host_port_pair.host())); |
827 } | 889 } |
828 | 890 |
| 891 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBelowThreshold) { |
| 892 impl_.SetAlternativeServiceProbabilityThreshold(0.02); |
| 893 |
| 894 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
| 895 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); |
| 896 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
| 897 1234); |
| 898 |
| 899 SetAlternativeService(canonical_host_port_pair, canonical_alternative_service, |
| 900 0.01); |
| 901 EXPECT_FALSE(HasAlternativeService(canonical_host_port_pair)); |
| 902 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
| 903 } |
| 904 |
| 905 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalAboveThreshold) { |
| 906 impl_.SetAlternativeServiceProbabilityThreshold(0.02); |
| 907 |
| 908 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
| 909 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); |
| 910 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
| 911 1234); |
| 912 |
| 913 SetAlternativeService(canonical_host_port_pair, canonical_alternative_service, |
| 914 0.03); |
| 915 EXPECT_TRUE(HasAlternativeService(canonical_host_port_pair)); |
| 916 EXPECT_TRUE(HasAlternativeService(test_host_port_pair)); |
| 917 } |
| 918 |
829 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { | 919 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { |
830 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 920 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
831 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); | 921 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); |
832 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", | 922 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
833 1234); | 923 1234); |
834 | 924 |
835 SetAlternativeService(canonical_host_port_pair, | 925 SetAlternativeService(canonical_host_port_pair, canonical_alternative_service, |
836 canonical_alternative_service); | 926 1.0); |
837 impl_.ClearAlternativeServices(canonical_host_port_pair); | 927 impl_.ClearAlternativeServices(canonical_host_port_pair); |
838 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 928 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
839 } | 929 } |
840 | 930 |
841 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) { | 931 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalBroken) { |
842 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 932 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
843 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); | 933 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); |
844 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", | 934 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
845 1234); | 935 1234); |
846 | 936 |
847 SetAlternativeService(canonical_host_port_pair, | 937 SetAlternativeService(canonical_host_port_pair, canonical_alternative_service, |
848 canonical_alternative_service); | 938 1.0); |
849 impl_.MarkAlternativeServiceBroken(canonical_alternative_service); | 939 impl_.MarkAlternativeServiceBroken(canonical_alternative_service); |
850 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 940 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
851 } | 941 } |
852 | 942 |
853 // Adding an alternative service for a new host overrides canonical host. | 943 // Adding an alternative service for a new host overrides canonical host. |
854 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalOverride) { | 944 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalOverride) { |
855 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 945 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
856 HostPortPair bar_host_port_pair("bar.c.youtube.com", 80); | 946 HostPortPair bar_host_port_pair("bar.c.youtube.com", 80); |
857 AlternativeService bar_alternative_service(QUIC, "bar.c.youtube.com", 1234); | 947 AlternativeService bar_alternative_service(QUIC, "bar.c.youtube.com", 1234); |
858 SetAlternativeService(bar_host_port_pair, bar_alternative_service); | 948 SetAlternativeService(bar_host_port_pair, bar_alternative_service, 1.0); |
859 AlternativeServiceVector alternative_service_vector = | 949 AlternativeServiceVector alternative_service_vector = |
860 impl_.GetAlternativeServices(test_host_port_pair); | 950 impl_.GetAlternativeServices(test_host_port_pair); |
861 ASSERT_EQ(1u, alternative_service_vector.size()); | 951 ASSERT_EQ(1u, alternative_service_vector.size()); |
862 EXPECT_EQ(bar_alternative_service, alternative_service_vector[0]); | 952 EXPECT_EQ(bar_alternative_service, alternative_service_vector[0]); |
863 | 953 |
864 HostPortPair qux_host_port_pair("qux.c.youtube.com", 80); | 954 HostPortPair qux_host_port_pair("qux.c.youtube.com", 80); |
865 AlternativeService qux_alternative_service(QUIC, "qux.c.youtube.com", 443); | 955 AlternativeService qux_alternative_service(QUIC, "qux.c.youtube.com", 443); |
866 SetAlternativeService(qux_host_port_pair, qux_alternative_service); | 956 SetAlternativeService(qux_host_port_pair, qux_alternative_service, 1.0); |
867 alternative_service_vector = | 957 alternative_service_vector = |
868 impl_.GetAlternativeServices(test_host_port_pair); | 958 impl_.GetAlternativeServices(test_host_port_pair); |
869 ASSERT_EQ(1u, alternative_service_vector.size()); | 959 ASSERT_EQ(1u, alternative_service_vector.size()); |
870 EXPECT_EQ(qux_alternative_service, alternative_service_vector[0]); | 960 EXPECT_EQ(qux_alternative_service, alternative_service_vector[0]); |
871 } | 961 } |
872 | 962 |
873 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { | 963 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { |
874 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); | 964 HostPortPair test_host_port_pair("foo.c.youtube.com", 80); |
875 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); | 965 HostPortPair canonical_host_port_pair("bar.c.youtube.com", 80); |
876 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", | 966 AlternativeService canonical_alternative_service(QUIC, "bar.c.youtube.com", |
877 1234); | 967 1234); |
878 | 968 |
879 SetAlternativeService(canonical_host_port_pair, | 969 SetAlternativeService(canonical_host_port_pair, canonical_alternative_service, |
880 canonical_alternative_service); | 970 1.0); |
881 impl_.Clear(); | 971 impl_.Clear(); |
882 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); | 972 EXPECT_FALSE(HasAlternativeService(test_host_port_pair)); |
883 } | 973 } |
884 | 974 |
885 TEST_F(AlternateProtocolServerPropertiesTest, | 975 TEST_F(AlternateProtocolServerPropertiesTest, |
886 ExpireBrokenAlternateProtocolMappings) { | 976 ExpireBrokenAlternateProtocolMappings) { |
887 HostPortPair host_port_pair("foo", 443); | 977 HostPortPair host_port_pair("foo", 443); |
888 AlternativeService alternative_service(QUIC, "foo", 443); | 978 AlternativeService alternative_service(QUIC, "foo", 443); |
889 SetAlternativeService(host_port_pair, alternative_service); | 979 SetAlternativeService(host_port_pair, alternative_service, 1.0); |
890 EXPECT_TRUE(HasAlternativeService(host_port_pair)); | 980 EXPECT_TRUE(HasAlternativeService(host_port_pair)); |
891 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 981 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
892 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 982 EXPECT_FALSE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
893 | 983 |
894 base::TimeTicks past = | 984 base::TimeTicks past = |
895 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); | 985 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); |
896 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( | 986 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( |
897 impl_, alternative_service, past); | 987 impl_, alternative_service, past); |
898 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 988 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
899 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 989 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
900 | 990 |
901 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_); | 991 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_); |
902 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); | 992 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service)); |
903 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); | 993 EXPECT_TRUE(impl_.WasAlternativeServiceRecentlyBroken(alternative_service)); |
904 } | 994 } |
905 | 995 |
906 // Regression test for https://crbug.com/505413. | 996 // Regression test for https://crbug.com/505413. |
907 TEST_F(AlternateProtocolServerPropertiesTest, RemoveExpiredBrokenAltSvc) { | 997 TEST_F(AlternateProtocolServerPropertiesTest, RemoveExpiredBrokenAltSvc) { |
908 HostPortPair foo_host_port_pair("foo", 443); | 998 HostPortPair foo_host_port_pair("foo", 443); |
909 AlternativeService bar_alternative_service(QUIC, "bar", 443); | 999 AlternativeService bar_alternative_service(QUIC, "bar", 443); |
910 SetAlternativeService(foo_host_port_pair, bar_alternative_service); | 1000 SetAlternativeService(foo_host_port_pair, bar_alternative_service, 1.0); |
911 EXPECT_TRUE(HasAlternativeService(foo_host_port_pair)); | 1001 EXPECT_TRUE(HasAlternativeService(foo_host_port_pair)); |
912 | 1002 |
913 HostPortPair bar_host_port_pair1("bar", 80); | 1003 HostPortPair bar_host_port_pair1("bar", 80); |
914 AlternativeService nohost_alternative_service(QUIC, "", 443); | 1004 AlternativeService nohost_alternative_service(QUIC, "", 443); |
915 SetAlternativeService(bar_host_port_pair1, nohost_alternative_service); | 1005 SetAlternativeService(bar_host_port_pair1, nohost_alternative_service, 1.0); |
916 EXPECT_TRUE(HasAlternativeService(bar_host_port_pair1)); | 1006 EXPECT_TRUE(HasAlternativeService(bar_host_port_pair1)); |
917 | 1007 |
918 HostPortPair bar_host_port_pair2("bar", 443); | 1008 HostPortPair bar_host_port_pair2("bar", 443); |
919 AlternativeService baz_alternative_service(QUIC, "baz", 1234); | 1009 AlternativeService baz_alternative_service(QUIC, "baz", 1234); |
920 SetAlternativeService(bar_host_port_pair2, baz_alternative_service); | 1010 SetAlternativeService(bar_host_port_pair2, baz_alternative_service, 1.0); |
921 EXPECT_TRUE(HasAlternativeService(bar_host_port_pair2)); | 1011 EXPECT_TRUE(HasAlternativeService(bar_host_port_pair2)); |
922 | 1012 |
923 // Mark "bar:443" as broken. | 1013 // Mark "bar:443" as broken. |
924 base::TimeTicks past = | 1014 base::TimeTicks past = |
925 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); | 1015 base::TimeTicks::Now() - base::TimeDelta::FromSeconds(42); |
926 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( | 1016 HttpServerPropertiesImplPeer::AddBrokenAlternativeServiceWithExpirationTime( |
927 impl_, bar_alternative_service, past); | 1017 impl_, bar_alternative_service, past); |
928 | 1018 |
929 // Expire brokenness of "bar:443". | 1019 // Expire brokenness of "bar:443". |
930 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_); | 1020 HttpServerPropertiesImplPeer::ExpireBrokenAlternateProtocolMappings(impl_); |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1393 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); | 1483 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); |
1394 | 1484 |
1395 impl_.Clear(); | 1485 impl_.Clear(); |
1396 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); | 1486 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); |
1397 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); | 1487 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); |
1398 } | 1488 } |
1399 | 1489 |
1400 } // namespace | 1490 } // namespace |
1401 | 1491 |
1402 } // namespace net | 1492 } // namespace net |
OLD | NEW |