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