| 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 <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { | 372 TEST_F(AlternateProtocolServerPropertiesTest, Basic) { |
| 373 url::SchemeHostPort test_server("http", "foo", 80); | 373 url::SchemeHostPort test_server("http", "foo", 80); |
| 374 EXPECT_FALSE(HasAlternativeService(test_server)); | 374 EXPECT_FALSE(HasAlternativeService(test_server)); |
| 375 | 375 |
| 376 AlternativeService alternative_service(kProtoHTTP2, "foo", 443); | 376 AlternativeService alternative_service(kProtoHTTP2, "foo", 443); |
| 377 SetAlternativeService(test_server, alternative_service); | 377 SetAlternativeService(test_server, alternative_service); |
| 378 const AlternativeServiceInfoVector alternative_service_info_vector = | 378 const AlternativeServiceInfoVector alternative_service_info_vector = |
| 379 impl_.GetAlternativeServiceInfos(test_server); | 379 impl_.GetAlternativeServiceInfos(test_server); |
| 380 ASSERT_EQ(1u, alternative_service_info_vector.size()); | 380 ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 381 EXPECT_EQ(alternative_service, | 381 EXPECT_EQ(alternative_service, |
| 382 alternative_service_info_vector[0].alternative_service); | 382 alternative_service_info_vector[0].alternative_service()); |
| 383 | 383 |
| 384 impl_.Clear(); | 384 impl_.Clear(); |
| 385 EXPECT_FALSE(HasAlternativeService(test_server)); | 385 EXPECT_FALSE(HasAlternativeService(test_server)); |
| 386 } | 386 } |
| 387 | 387 |
| 388 TEST_F(AlternateProtocolServerPropertiesTest, ExcludeOrigin) { | 388 TEST_F(AlternateProtocolServerPropertiesTest, ExcludeOrigin) { |
| 389 AlternativeServiceInfoVector alternative_service_info_vector; | 389 AlternativeServiceInfoVector alternative_service_info_vector; |
| 390 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 390 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 391 // Same hostname, same port, TCP: should be ignored. | 391 // Same hostname, same port, TCP: should be ignored. |
| 392 AlternativeServiceInfo alternative_service_info1(kProtoHTTP2, "foo", 443, | 392 AlternativeServiceInfo alternative_service_info1(kProtoHTTP2, "foo", 443, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 // MRU list will be test_server2, test_server1, test_server3. | 468 // MRU list will be test_server2, test_server1, test_server3. |
| 469 impl_.SetAlternativeServiceServers(&alternative_service_map); | 469 impl_.SetAlternativeServiceServers(&alternative_service_map); |
| 470 | 470 |
| 471 // Verify alternative_service_map. | 471 // Verify alternative_service_map. |
| 472 const AlternativeServiceMap& map = impl_.alternative_service_map(); | 472 const AlternativeServiceMap& map = impl_.alternative_service_map(); |
| 473 ASSERT_EQ(3u, map.size()); | 473 ASSERT_EQ(3u, map.size()); |
| 474 AlternativeServiceMap::const_iterator map_it = map.begin(); | 474 AlternativeServiceMap::const_iterator map_it = map.begin(); |
| 475 | 475 |
| 476 EXPECT_TRUE(map_it->first.Equals(test_server2)); | 476 EXPECT_TRUE(map_it->first.Equals(test_server2)); |
| 477 ASSERT_EQ(1u, map_it->second.size()); | 477 ASSERT_EQ(1u, map_it->second.size()); |
| 478 EXPECT_EQ(alternative_service3, map_it->second[0].alternative_service); | 478 EXPECT_EQ(alternative_service3, map_it->second[0].alternative_service()); |
| 479 EXPECT_EQ(expiration3, map_it->second[0].expiration); | 479 EXPECT_EQ(expiration3, map_it->second[0].expiration()); |
| 480 ++map_it; | 480 ++map_it; |
| 481 EXPECT_TRUE(map_it->first.Equals(test_server1)); | 481 EXPECT_TRUE(map_it->first.Equals(test_server1)); |
| 482 ASSERT_EQ(1u, map_it->second.size()); | 482 ASSERT_EQ(1u, map_it->second.size()); |
| 483 EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service); | 483 EXPECT_EQ(alternative_service1, map_it->second[0].alternative_service()); |
| 484 EXPECT_EQ(expiration1, map_it->second[0].expiration); | 484 EXPECT_EQ(expiration1, map_it->second[0].expiration()); |
| 485 ++map_it; | 485 ++map_it; |
| 486 EXPECT_TRUE(map_it->first.Equals(test_server3)); | 486 EXPECT_TRUE(map_it->first.Equals(test_server3)); |
| 487 ASSERT_EQ(1u, map_it->second.size()); | 487 ASSERT_EQ(1u, map_it->second.size()); |
| 488 EXPECT_EQ(alternative_service4, map_it->second[0].alternative_service); | 488 EXPECT_EQ(alternative_service4, map_it->second[0].alternative_service()); |
| 489 EXPECT_EQ(expiration4, map_it->second[0].expiration); | 489 EXPECT_EQ(expiration4, map_it->second[0].expiration()); |
| 490 } | 490 } |
| 491 | 491 |
| 492 // Regression test for https://crbug.com/504032: | 492 // Regression test for https://crbug.com/504032: |
| 493 // SetAlternativeServiceServers() should not crash if there is an empty | 493 // SetAlternativeServiceServers() should not crash if there is an empty |
| 494 // hostname is the mapping. | 494 // hostname is the mapping. |
| 495 TEST_F(AlternateProtocolServerPropertiesTest, SetWithEmptyHostname) { | 495 TEST_F(AlternateProtocolServerPropertiesTest, SetWithEmptyHostname) { |
| 496 url::SchemeHostPort server("https", "foo", 443); | 496 url::SchemeHostPort server("https", "foo", 443); |
| 497 const AlternativeService alternative_service_with_empty_hostname(kProtoHTTP2, | 497 const AlternativeService alternative_service_with_empty_hostname(kProtoHTTP2, |
| 498 "", 1234); | 498 "", 1234); |
| 499 const AlternativeService alternative_service_with_foo_hostname(kProtoHTTP2, | 499 const AlternativeService alternative_service_with_foo_hostname(kProtoHTTP2, |
| 500 "foo", 1234); | 500 "foo", 1234); |
| 501 SetAlternativeService(server, alternative_service_with_empty_hostname); | 501 SetAlternativeService(server, alternative_service_with_empty_hostname); |
| 502 impl_.MarkAlternativeServiceBroken(alternative_service_with_foo_hostname); | 502 impl_.MarkAlternativeServiceBroken(alternative_service_with_foo_hostname); |
| 503 | 503 |
| 504 AlternativeServiceMap alternative_service_map( | 504 AlternativeServiceMap alternative_service_map( |
| 505 AlternativeServiceMap::NO_AUTO_EVICT); | 505 AlternativeServiceMap::NO_AUTO_EVICT); |
| 506 impl_.SetAlternativeServiceServers(&alternative_service_map); | 506 impl_.SetAlternativeServiceServers(&alternative_service_map); |
| 507 | 507 |
| 508 EXPECT_TRUE( | 508 EXPECT_TRUE( |
| 509 impl_.IsAlternativeServiceBroken(alternative_service_with_foo_hostname)); | 509 impl_.IsAlternativeServiceBroken(alternative_service_with_foo_hostname)); |
| 510 const AlternativeServiceInfoVector alternative_service_info_vector = | 510 const AlternativeServiceInfoVector alternative_service_info_vector = |
| 511 impl_.GetAlternativeServiceInfos(server); | 511 impl_.GetAlternativeServiceInfos(server); |
| 512 ASSERT_EQ(1u, alternative_service_info_vector.size()); | 512 ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 513 EXPECT_EQ(alternative_service_with_foo_hostname, | 513 EXPECT_EQ(alternative_service_with_foo_hostname, |
| 514 alternative_service_info_vector[0].alternative_service); | 514 alternative_service_info_vector[0].alternative_service()); |
| 515 } | 515 } |
| 516 | 516 |
| 517 // Regression test for https://crbug.com/516486: | 517 // Regression test for https://crbug.com/516486: |
| 518 // GetAlternativeServiceInfos() should remove |alternative_service_map_| | 518 // GetAlternativeServiceInfos() should remove |alternative_service_map_| |
| 519 // elements with empty value. | 519 // elements with empty value. |
| 520 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVector) { | 520 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVector) { |
| 521 url::SchemeHostPort server("https", "foo", 443); | 521 url::SchemeHostPort server("https", "foo", 443); |
| 522 const AlternativeService alternative_service(kProtoHTTP2, "bar", 443); | 522 const AlternativeService alternative_service(kProtoHTTP2, "bar", 443); |
| 523 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); | 523 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); |
| 524 const AlternativeServiceInfo alternative_service_info(alternative_service, | 524 const AlternativeServiceInfo alternative_service_info(alternative_service, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 | 593 |
| 594 impl_.SetAlternativeServices( | 594 impl_.SetAlternativeServices( |
| 595 canonical_server, | 595 canonical_server, |
| 596 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); | 596 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); |
| 597 | 597 |
| 598 // Make sure the canonical service is returned for the other server. | 598 // Make sure the canonical service is returned for the other server. |
| 599 const AlternativeServiceInfoVector alternative_service_info_vector = | 599 const AlternativeServiceInfoVector alternative_service_info_vector = |
| 600 impl_.GetAlternativeServiceInfos(server); | 600 impl_.GetAlternativeServiceInfos(server); |
| 601 ASSERT_EQ(1u, alternative_service_info_vector.size()); | 601 ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 602 EXPECT_EQ(kProtoQUIC, | 602 EXPECT_EQ(kProtoQUIC, |
| 603 alternative_service_info_vector[0].alternative_service.protocol); | 603 alternative_service_info_vector[0].alternative_service().protocol); |
| 604 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service.port); | 604 EXPECT_EQ(443, alternative_service_info_vector[0].alternative_service().port); |
| 605 | 605 |
| 606 // Now clear the alternatives for the other server and make sure it stays | 606 // Now clear the alternatives for the other server and make sure it stays |
| 607 // cleared. | 607 // cleared. |
| 608 // GetAlternativeServices() should remove this key from | 608 // GetAlternativeServices() should remove this key from |
| 609 // |alternative_service_map_|, and SetAlternativeServices() should not crash. | 609 // |alternative_service_map_|, and SetAlternativeServices() should not crash. |
| 610 impl_.SetAlternativeServices(server, AlternativeServiceInfoVector()); | 610 impl_.SetAlternativeServices(server, AlternativeServiceInfoVector()); |
| 611 | 611 |
| 612 ASSERT_TRUE(impl_.GetAlternativeServiceInfos(server).empty()); | 612 ASSERT_TRUE(impl_.GetAlternativeServiceInfos(server).empty()); |
| 613 } | 613 } |
| 614 | 614 |
| 615 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternativeServiceInfos) { | 615 TEST_F(AlternateProtocolServerPropertiesTest, MRUOfGetAlternativeServiceInfos) { |
| 616 url::SchemeHostPort test_server1("http", "foo1", 80); | 616 url::SchemeHostPort test_server1("http", "foo1", 80); |
| 617 const AlternativeService alternative_service1(kProtoHTTP2, "foo1", 443); | 617 const AlternativeService alternative_service1(kProtoHTTP2, "foo1", 443); |
| 618 SetAlternativeService(test_server1, alternative_service1); | 618 SetAlternativeService(test_server1, alternative_service1); |
| 619 url::SchemeHostPort test_server2("http", "foo2", 80); | 619 url::SchemeHostPort test_server2("http", "foo2", 80); |
| 620 const AlternativeService alternative_service2(kProtoHTTP2, "foo2", 1234); | 620 const AlternativeService alternative_service2(kProtoHTTP2, "foo2", 1234); |
| 621 SetAlternativeService(test_server2, alternative_service2); | 621 SetAlternativeService(test_server2, alternative_service2); |
| 622 | 622 |
| 623 const AlternativeServiceMap& map = impl_.alternative_service_map(); | 623 const AlternativeServiceMap& map = impl_.alternative_service_map(); |
| 624 AlternativeServiceMap::const_iterator it = map.begin(); | 624 AlternativeServiceMap::const_iterator it = map.begin(); |
| 625 EXPECT_TRUE(it->first.Equals(test_server2)); | 625 EXPECT_TRUE(it->first.Equals(test_server2)); |
| 626 ASSERT_EQ(1u, it->second.size()); | 626 ASSERT_EQ(1u, it->second.size()); |
| 627 EXPECT_EQ(alternative_service2, it->second[0].alternative_service); | 627 EXPECT_EQ(alternative_service2, it->second[0].alternative_service()); |
| 628 | 628 |
| 629 const AlternativeServiceInfoVector alternative_service_info_vector = | 629 const AlternativeServiceInfoVector alternative_service_info_vector = |
| 630 impl_.GetAlternativeServiceInfos(test_server1); | 630 impl_.GetAlternativeServiceInfos(test_server1); |
| 631 ASSERT_EQ(1u, alternative_service_info_vector.size()); | 631 ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 632 EXPECT_EQ(alternative_service1, | 632 EXPECT_EQ(alternative_service1, |
| 633 alternative_service_info_vector[0].alternative_service); | 633 alternative_service_info_vector[0].alternative_service()); |
| 634 | 634 |
| 635 // GetAlternativeServices should reorder the AlternateProtocol map. | 635 // GetAlternativeServices should reorder the AlternateProtocol map. |
| 636 it = map.begin(); | 636 it = map.begin(); |
| 637 EXPECT_TRUE(it->first.Equals(test_server1)); | 637 EXPECT_TRUE(it->first.Equals(test_server1)); |
| 638 ASSERT_EQ(1u, it->second.size()); | 638 ASSERT_EQ(1u, it->second.size()); |
| 639 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); | 639 EXPECT_EQ(alternative_service1, it->second[0].alternative_service()); |
| 640 } | 640 } |
| 641 | 641 |
| 642 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { | 642 TEST_F(AlternateProtocolServerPropertiesTest, SetBroken) { |
| 643 url::SchemeHostPort test_server("http", "foo", 80); | 643 url::SchemeHostPort test_server("http", "foo", 80); |
| 644 const AlternativeService alternative_service1(kProtoHTTP2, "foo", 443); | 644 const AlternativeService alternative_service1(kProtoHTTP2, "foo", 443); |
| 645 SetAlternativeService(test_server, alternative_service1); | 645 SetAlternativeService(test_server, alternative_service1); |
| 646 AlternativeServiceInfoVector alternative_service_info_vector = | 646 AlternativeServiceInfoVector alternative_service_info_vector = |
| 647 impl_.GetAlternativeServiceInfos(test_server); | 647 impl_.GetAlternativeServiceInfos(test_server); |
| 648 ASSERT_EQ(1u, alternative_service_info_vector.size()); | 648 ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 649 EXPECT_EQ(alternative_service1, | 649 EXPECT_EQ(alternative_service1, |
| 650 alternative_service_info_vector[0].alternative_service); | 650 alternative_service_info_vector[0].alternative_service()); |
| 651 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service1)); | 651 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service1)); |
| 652 | 652 |
| 653 // GetAlternativeServiceInfos should return the broken alternative service. | 653 // GetAlternativeServiceInfos should return the broken alternative service. |
| 654 impl_.MarkAlternativeServiceBroken(alternative_service1); | 654 impl_.MarkAlternativeServiceBroken(alternative_service1); |
| 655 alternative_service_info_vector = | 655 alternative_service_info_vector = |
| 656 impl_.GetAlternativeServiceInfos(test_server); | 656 impl_.GetAlternativeServiceInfos(test_server); |
| 657 ASSERT_EQ(1u, alternative_service_info_vector.size()); | 657 ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 658 EXPECT_EQ(alternative_service1, | 658 EXPECT_EQ(alternative_service1, |
| 659 alternative_service_info_vector[0].alternative_service); | 659 alternative_service_info_vector[0].alternative_service()); |
| 660 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); | 660 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); |
| 661 | 661 |
| 662 // SetAlternativeServices should add a broken alternative service to the map. | 662 // SetAlternativeServices should add a broken alternative service to the map. |
| 663 AlternativeServiceInfoVector alternative_service_info_vector2; | 663 AlternativeServiceInfoVector alternative_service_info_vector2; |
| 664 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 664 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 665 alternative_service_info_vector2.push_back( | 665 alternative_service_info_vector2.push_back( |
| 666 AlternativeServiceInfo(alternative_service1, expiration)); | 666 AlternativeServiceInfo(alternative_service1, expiration)); |
| 667 const AlternativeService alternative_service2(kProtoHTTP2, "foo", 1234); | 667 const AlternativeService alternative_service2(kProtoHTTP2, "foo", 1234); |
| 668 alternative_service_info_vector2.push_back( | 668 alternative_service_info_vector2.push_back( |
| 669 AlternativeServiceInfo(alternative_service2, expiration)); | 669 AlternativeServiceInfo(alternative_service2, expiration)); |
| 670 impl_.SetAlternativeServices(test_server, alternative_service_info_vector2); | 670 impl_.SetAlternativeServices(test_server, alternative_service_info_vector2); |
| 671 alternative_service_info_vector = | 671 alternative_service_info_vector = |
| 672 impl_.GetAlternativeServiceInfos(test_server); | 672 impl_.GetAlternativeServiceInfos(test_server); |
| 673 ASSERT_EQ(2u, alternative_service_info_vector.size()); | 673 ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 674 EXPECT_EQ(alternative_service1, | 674 EXPECT_EQ(alternative_service1, |
| 675 alternative_service_info_vector[0].alternative_service); | 675 alternative_service_info_vector[0].alternative_service()); |
| 676 EXPECT_EQ(alternative_service2, | 676 EXPECT_EQ(alternative_service2, |
| 677 alternative_service_info_vector[1].alternative_service); | 677 alternative_service_info_vector[1].alternative_service()); |
| 678 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); | 678 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); |
| 679 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service2)); | 679 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service2)); |
| 680 | 680 |
| 681 // SetAlternativeService should add a broken alternative service to the map. | 681 // SetAlternativeService should add a broken alternative service to the map. |
| 682 SetAlternativeService(test_server, alternative_service1); | 682 SetAlternativeService(test_server, alternative_service1); |
| 683 alternative_service_info_vector = | 683 alternative_service_info_vector = |
| 684 impl_.GetAlternativeServiceInfos(test_server); | 684 impl_.GetAlternativeServiceInfos(test_server); |
| 685 ASSERT_EQ(1u, alternative_service_info_vector.size()); | 685 ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 686 EXPECT_EQ(alternative_service1, | 686 EXPECT_EQ(alternative_service1, |
| 687 alternative_service_info_vector[0].alternative_service); | 687 alternative_service_info_vector[0].alternative_service()); |
| 688 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); | 688 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); |
| 689 } | 689 } |
| 690 | 690 |
| 691 TEST_F(AlternateProtocolServerPropertiesTest, MaxAge) { | 691 TEST_F(AlternateProtocolServerPropertiesTest, MaxAge) { |
| 692 AlternativeServiceInfoVector alternative_service_info_vector; | 692 AlternativeServiceInfoVector alternative_service_info_vector; |
| 693 base::Time now = base::Time::Now(); | 693 base::Time now = base::Time::Now(); |
| 694 base::TimeDelta one_day = base::TimeDelta::FromDays(1); | 694 base::TimeDelta one_day = base::TimeDelta::FromDays(1); |
| 695 | 695 |
| 696 // First alternative service expired one day ago, should not be returned by | 696 // First alternative service expired one day ago, should not be returned by |
| 697 // GetAlternativeServiceInfos(). | 697 // GetAlternativeServiceInfos(). |
| 698 const AlternativeService alternative_service1(kProtoHTTP2, "foo", 443); | 698 const AlternativeService alternative_service1(kProtoHTTP2, "foo", 443); |
| 699 alternative_service_info_vector.push_back( | 699 alternative_service_info_vector.push_back( |
| 700 AlternativeServiceInfo(alternative_service1, now - one_day)); | 700 AlternativeServiceInfo(alternative_service1, now - one_day)); |
| 701 | 701 |
| 702 // Second alterrnative service will expire one day from now, should be | 702 // Second alterrnative service will expire one day from now, should be |
| 703 // returned by GetAlternativeSerices(). | 703 // returned by GetAlternativeSerices(). |
| 704 const AlternativeService alternative_service2(kProtoHTTP2, "bar", 1234); | 704 const AlternativeService alternative_service2(kProtoHTTP2, "bar", 1234); |
| 705 alternative_service_info_vector.push_back( | 705 alternative_service_info_vector.push_back( |
| 706 AlternativeServiceInfo(alternative_service2, now + one_day)); | 706 AlternativeServiceInfo(alternative_service2, now + one_day)); |
| 707 | 707 |
| 708 url::SchemeHostPort test_server("http", "foo", 80); | 708 url::SchemeHostPort test_server("http", "foo", 80); |
| 709 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); | 709 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); |
| 710 | 710 |
| 711 AlternativeServiceInfoVector alternative_service_info_vector2 = | 711 AlternativeServiceInfoVector alternative_service_info_vector2 = |
| 712 impl_.GetAlternativeServiceInfos(test_server); | 712 impl_.GetAlternativeServiceInfos(test_server); |
| 713 ASSERT_EQ(1u, alternative_service_info_vector2.size()); | 713 ASSERT_EQ(1u, alternative_service_info_vector2.size()); |
| 714 EXPECT_EQ(alternative_service2, | 714 EXPECT_EQ(alternative_service2, |
| 715 alternative_service_info_vector2[0].alternative_service); | 715 alternative_service_info_vector2[0].alternative_service()); |
| 716 } | 716 } |
| 717 | 717 |
| 718 TEST_F(AlternateProtocolServerPropertiesTest, MaxAgeCanonical) { | 718 TEST_F(AlternateProtocolServerPropertiesTest, MaxAgeCanonical) { |
| 719 AlternativeServiceInfoVector alternative_service_info_vector; | 719 AlternativeServiceInfoVector alternative_service_info_vector; |
| 720 base::Time now = base::Time::Now(); | 720 base::Time now = base::Time::Now(); |
| 721 base::TimeDelta one_day = base::TimeDelta::FromDays(1); | 721 base::TimeDelta one_day = base::TimeDelta::FromDays(1); |
| 722 | 722 |
| 723 // First alternative service expired one day ago, should not be returned by | 723 // First alternative service expired one day ago, should not be returned by |
| 724 // GetAlternativeServiceInfos(). | 724 // GetAlternativeServiceInfos(). |
| 725 const AlternativeService alternative_service1(kProtoHTTP2, "foo", 443); | 725 const AlternativeService alternative_service1(kProtoHTTP2, "foo", 443); |
| 726 alternative_service_info_vector.push_back( | 726 alternative_service_info_vector.push_back( |
| 727 AlternativeServiceInfo(alternative_service1, now - one_day)); | 727 AlternativeServiceInfo(alternative_service1, now - one_day)); |
| 728 | 728 |
| 729 // Second alterrnative service will expire one day from now, should be | 729 // Second alterrnative service will expire one day from now, should be |
| 730 // returned by GetAlternativeSerices(). | 730 // returned by GetAlternativeSerices(). |
| 731 const AlternativeService alternative_service2(kProtoHTTP2, "bar", 1234); | 731 const AlternativeService alternative_service2(kProtoHTTP2, "bar", 1234); |
| 732 alternative_service_info_vector.push_back( | 732 alternative_service_info_vector.push_back( |
| 733 AlternativeServiceInfo(alternative_service2, now + one_day)); | 733 AlternativeServiceInfo(alternative_service2, now + one_day)); |
| 734 | 734 |
| 735 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); | 735 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| 736 impl_.SetAlternativeServices(canonical_server, | 736 impl_.SetAlternativeServices(canonical_server, |
| 737 alternative_service_info_vector); | 737 alternative_service_info_vector); |
| 738 | 738 |
| 739 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); | 739 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); |
| 740 AlternativeServiceInfoVector alternative_service_info_vector2 = | 740 AlternativeServiceInfoVector alternative_service_info_vector2 = |
| 741 impl_.GetAlternativeServiceInfos(test_server); | 741 impl_.GetAlternativeServiceInfos(test_server); |
| 742 ASSERT_EQ(1u, alternative_service_info_vector2.size()); | 742 ASSERT_EQ(1u, alternative_service_info_vector2.size()); |
| 743 EXPECT_EQ(alternative_service2, | 743 EXPECT_EQ(alternative_service2, |
| 744 alternative_service_info_vector2[0].alternative_service); | 744 alternative_service_info_vector2[0].alternative_service()); |
| 745 } | 745 } |
| 746 | 746 |
| 747 TEST_F(AlternateProtocolServerPropertiesTest, AlternativeServiceWithScheme) { | 747 TEST_F(AlternateProtocolServerPropertiesTest, AlternativeServiceWithScheme) { |
| 748 AlternativeServiceInfoVector alternative_service_info_vector; | 748 AlternativeServiceInfoVector alternative_service_info_vector; |
| 749 const AlternativeService alternative_service1(kProtoHTTP2, "foo", 443); | 749 const AlternativeService alternative_service1(kProtoHTTP2, "foo", 443); |
| 750 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | 750 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 751 alternative_service_info_vector.push_back( | 751 alternative_service_info_vector.push_back( |
| 752 AlternativeServiceInfo(alternative_service1, expiration)); | 752 AlternativeServiceInfo(alternative_service1, expiration)); |
| 753 const AlternativeService alternative_service2(kProtoHTTP2, "bar", 1234); | 753 const AlternativeService alternative_service2(kProtoHTTP2, "bar", 1234); |
| 754 alternative_service_info_vector.push_back( | 754 alternative_service_info_vector.push_back( |
| 755 AlternativeServiceInfo(alternative_service2, expiration)); | 755 AlternativeServiceInfo(alternative_service2, expiration)); |
| 756 // Set Alt-Svc list for |http_server|. | 756 // Set Alt-Svc list for |http_server|. |
| 757 url::SchemeHostPort http_server("http", "foo", 80); | 757 url::SchemeHostPort http_server("http", "foo", 80); |
| 758 impl_.SetAlternativeServices(http_server, alternative_service_info_vector); | 758 impl_.SetAlternativeServices(http_server, alternative_service_info_vector); |
| 759 | 759 |
| 760 const net::AlternativeServiceMap& map = impl_.alternative_service_map(); | 760 const net::AlternativeServiceMap& map = impl_.alternative_service_map(); |
| 761 net::AlternativeServiceMap::const_iterator it = map.begin(); | 761 net::AlternativeServiceMap::const_iterator it = map.begin(); |
| 762 EXPECT_TRUE(it->first.Equals(http_server)); | 762 EXPECT_TRUE(it->first.Equals(http_server)); |
| 763 ASSERT_EQ(2u, it->second.size()); | 763 ASSERT_EQ(2u, it->second.size()); |
| 764 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); | 764 EXPECT_EQ(alternative_service1, it->second[0].alternative_service()); |
| 765 EXPECT_EQ(alternative_service2, it->second[1].alternative_service); | 765 EXPECT_EQ(alternative_service2, it->second[1].alternative_service()); |
| 766 | 766 |
| 767 // Check Alt-Svc list should not be set for |https_server|. | 767 // Check Alt-Svc list should not be set for |https_server|. |
| 768 url::SchemeHostPort https_server("https", "foo", 80); | 768 url::SchemeHostPort https_server("https", "foo", 80); |
| 769 EXPECT_EQ(0u, impl_.GetAlternativeServiceInfos(https_server).size()); | 769 EXPECT_EQ(0u, impl_.GetAlternativeServiceInfos(https_server).size()); |
| 770 | 770 |
| 771 // Set Alt-Svc list for |https_server|. | 771 // Set Alt-Svc list for |https_server|. |
| 772 impl_.SetAlternativeServices(https_server, alternative_service_info_vector); | 772 impl_.SetAlternativeServices(https_server, alternative_service_info_vector); |
| 773 EXPECT_EQ(2u, impl_.GetAlternativeServiceInfos(https_server).size()); | 773 EXPECT_EQ(2u, impl_.GetAlternativeServiceInfos(https_server).size()); |
| 774 EXPECT_EQ(2u, impl_.GetAlternativeServiceInfos(http_server).size()); | 774 EXPECT_EQ(2u, impl_.GetAlternativeServiceInfos(http_server).size()); |
| 775 | 775 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 789 const AlternativeService alternative_service2(kProtoHTTP2, "bar", 1234); | 789 const AlternativeService alternative_service2(kProtoHTTP2, "bar", 1234); |
| 790 alternative_service_info_vector.push_back( | 790 alternative_service_info_vector.push_back( |
| 791 AlternativeServiceInfo(alternative_service2, expiration)); | 791 AlternativeServiceInfo(alternative_service2, expiration)); |
| 792 url::SchemeHostPort test_server("http", "foo", 80); | 792 url::SchemeHostPort test_server("http", "foo", 80); |
| 793 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); | 793 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); |
| 794 | 794 |
| 795 const net::AlternativeServiceMap& map = impl_.alternative_service_map(); | 795 const net::AlternativeServiceMap& map = impl_.alternative_service_map(); |
| 796 net::AlternativeServiceMap::const_iterator it = map.begin(); | 796 net::AlternativeServiceMap::const_iterator it = map.begin(); |
| 797 EXPECT_TRUE(it->first.Equals(test_server)); | 797 EXPECT_TRUE(it->first.Equals(test_server)); |
| 798 ASSERT_EQ(2u, it->second.size()); | 798 ASSERT_EQ(2u, it->second.size()); |
| 799 EXPECT_EQ(alternative_service1, it->second[0].alternative_service); | 799 EXPECT_EQ(alternative_service1, it->second[0].alternative_service()); |
| 800 EXPECT_EQ(alternative_service2, it->second[1].alternative_service); | 800 EXPECT_EQ(alternative_service2, it->second[1].alternative_service()); |
| 801 | 801 |
| 802 impl_.SetAlternativeServices(test_server, AlternativeServiceInfoVector()); | 802 impl_.SetAlternativeServices(test_server, AlternativeServiceInfoVector()); |
| 803 EXPECT_TRUE(map.empty()); | 803 EXPECT_TRUE(map.empty()); |
| 804 } | 804 } |
| 805 | 805 |
| 806 // A broken alternative service in the mapping carries meaningful information, | 806 // A broken alternative service in the mapping carries meaningful information, |
| 807 // therefore it should not be ignored by SetAlternativeService(). In | 807 // therefore it should not be ignored by SetAlternativeService(). In |
| 808 // particular, an alternative service mapped to an origin shadows alternative | 808 // particular, an alternative service mapped to an origin shadows alternative |
| 809 // services of canonical hosts. | 809 // services of canonical hosts. |
| 810 TEST_F(AlternateProtocolServerPropertiesTest, BrokenShadowsCanonical) { | 810 TEST_F(AlternateProtocolServerPropertiesTest, BrokenShadowsCanonical) { |
| 811 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); | 811 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); |
| 812 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); | 812 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| 813 AlternativeService canonical_alternative_service(kProtoQUIC, | 813 AlternativeService canonical_alternative_service(kProtoQUIC, |
| 814 "bar.c.youtube.com", 1234); | 814 "bar.c.youtube.com", 1234); |
| 815 SetAlternativeService(canonical_server, canonical_alternative_service); | 815 SetAlternativeService(canonical_server, canonical_alternative_service); |
| 816 AlternativeServiceInfoVector alternative_service_info_vector = | 816 AlternativeServiceInfoVector alternative_service_info_vector = |
| 817 impl_.GetAlternativeServiceInfos(test_server); | 817 impl_.GetAlternativeServiceInfos(test_server); |
| 818 ASSERT_EQ(1u, alternative_service_info_vector.size()); | 818 ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 819 EXPECT_EQ(canonical_alternative_service, | 819 EXPECT_EQ(canonical_alternative_service, |
| 820 alternative_service_info_vector[0].alternative_service); | 820 alternative_service_info_vector[0].alternative_service()); |
| 821 | 821 |
| 822 const AlternativeService broken_alternative_service(kProtoHTTP2, "foo", 443); | 822 const AlternativeService broken_alternative_service(kProtoHTTP2, "foo", 443); |
| 823 impl_.MarkAlternativeServiceBroken(broken_alternative_service); | 823 impl_.MarkAlternativeServiceBroken(broken_alternative_service); |
| 824 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); | 824 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); |
| 825 | 825 |
| 826 SetAlternativeService(test_server, broken_alternative_service); | 826 SetAlternativeService(test_server, broken_alternative_service); |
| 827 alternative_service_info_vector = | 827 alternative_service_info_vector = |
| 828 impl_.GetAlternativeServiceInfos(test_server); | 828 impl_.GetAlternativeServiceInfos(test_server); |
| 829 ASSERT_EQ(1u, alternative_service_info_vector.size()); | 829 ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 830 EXPECT_EQ(broken_alternative_service, | 830 EXPECT_EQ(broken_alternative_service, |
| 831 alternative_service_info_vector[0].alternative_service); | 831 alternative_service_info_vector[0].alternative_service()); |
| 832 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); | 832 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(broken_alternative_service)); |
| 833 } | 833 } |
| 834 | 834 |
| 835 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { | 835 TEST_F(AlternateProtocolServerPropertiesTest, ClearBroken) { |
| 836 url::SchemeHostPort test_server("http", "foo", 80); | 836 url::SchemeHostPort test_server("http", "foo", 80); |
| 837 const AlternativeService alternative_service(kProtoHTTP2, "foo", 443); | 837 const AlternativeService alternative_service(kProtoHTTP2, "foo", 443); |
| 838 SetAlternativeService(test_server, alternative_service); | 838 SetAlternativeService(test_server, alternative_service); |
| 839 impl_.MarkAlternativeServiceBroken(alternative_service); | 839 impl_.MarkAlternativeServiceBroken(alternative_service); |
| 840 ASSERT_TRUE(HasAlternativeService(test_server)); | 840 ASSERT_TRUE(HasAlternativeService(test_server)); |
| 841 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); | 841 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service)); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 AlternativeServiceInfo(canonical_alternative_service2, expiration)); | 880 AlternativeServiceInfo(canonical_alternative_service2, expiration)); |
| 881 impl_.SetAlternativeServices(canonical_server, | 881 impl_.SetAlternativeServices(canonical_server, |
| 882 alternative_service_info_vector); | 882 alternative_service_info_vector); |
| 883 | 883 |
| 884 // Since |test_server| does not have an alternative service itself, | 884 // Since |test_server| does not have an alternative service itself, |
| 885 // GetAlternativeServiceInfos should return those of |canonical_server|. | 885 // GetAlternativeServiceInfos should return those of |canonical_server|. |
| 886 AlternativeServiceInfoVector alternative_service_info_vector2 = | 886 AlternativeServiceInfoVector alternative_service_info_vector2 = |
| 887 impl_.GetAlternativeServiceInfos(test_server); | 887 impl_.GetAlternativeServiceInfos(test_server); |
| 888 ASSERT_EQ(2u, alternative_service_info_vector2.size()); | 888 ASSERT_EQ(2u, alternative_service_info_vector2.size()); |
| 889 EXPECT_EQ(canonical_alternative_service1, | 889 EXPECT_EQ(canonical_alternative_service1, |
| 890 alternative_service_info_vector2[0].alternative_service); | 890 alternative_service_info_vector2[0].alternative_service()); |
| 891 | 891 |
| 892 // Since |canonical_alternative_service2| has an empty host, | 892 // Since |canonical_alternative_service2| has an empty host, |
| 893 // GetAlternativeServiceInfos should substitute the hostname of its |origin| | 893 // GetAlternativeServiceInfos should substitute the hostname of its |origin| |
| 894 // argument. | 894 // argument. |
| 895 EXPECT_EQ(test_server.host(), | 895 EXPECT_EQ(test_server.host(), |
| 896 alternative_service_info_vector2[1].alternative_service.host); | 896 alternative_service_info_vector2[1].alternative_service().host); |
| 897 EXPECT_EQ(canonical_alternative_service2.protocol, | 897 EXPECT_EQ(canonical_alternative_service2.protocol, |
| 898 alternative_service_info_vector2[1].alternative_service.protocol); | 898 alternative_service_info_vector2[1].alternative_service().protocol); |
| 899 EXPECT_EQ(canonical_alternative_service2.port, | 899 EXPECT_EQ(canonical_alternative_service2.port, |
| 900 alternative_service_info_vector2[1].alternative_service.port); | 900 alternative_service_info_vector2[1].alternative_service().port); |
| 901 | 901 |
| 902 // Verify the canonical suffix. | 902 // Verify the canonical suffix. |
| 903 EXPECT_EQ(".c.youtube.com", *impl_.GetCanonicalSuffix(test_server.host())); | 903 EXPECT_EQ(".c.youtube.com", *impl_.GetCanonicalSuffix(test_server.host())); |
| 904 EXPECT_EQ(".c.youtube.com", | 904 EXPECT_EQ(".c.youtube.com", |
| 905 *impl_.GetCanonicalSuffix(canonical_server.host())); | 905 *impl_.GetCanonicalSuffix(canonical_server.host())); |
| 906 } | 906 } |
| 907 | 907 |
| 908 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { | 908 TEST_F(AlternateProtocolServerPropertiesTest, ClearCanonical) { |
| 909 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); | 909 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); |
| 910 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); | 910 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 932 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalOverride) { | 932 TEST_F(AlternateProtocolServerPropertiesTest, CanonicalOverride) { |
| 933 url::SchemeHostPort foo_server("https", "foo.c.youtube.com", 443); | 933 url::SchemeHostPort foo_server("https", "foo.c.youtube.com", 443); |
| 934 url::SchemeHostPort bar_server("https", "bar.c.youtube.com", 443); | 934 url::SchemeHostPort bar_server("https", "bar.c.youtube.com", 443); |
| 935 AlternativeService bar_alternative_service(kProtoQUIC, "bar.c.youtube.com", | 935 AlternativeService bar_alternative_service(kProtoQUIC, "bar.c.youtube.com", |
| 936 1234); | 936 1234); |
| 937 SetAlternativeService(bar_server, bar_alternative_service); | 937 SetAlternativeService(bar_server, bar_alternative_service); |
| 938 AlternativeServiceInfoVector alternative_service_info_vector = | 938 AlternativeServiceInfoVector alternative_service_info_vector = |
| 939 impl_.GetAlternativeServiceInfos(foo_server); | 939 impl_.GetAlternativeServiceInfos(foo_server); |
| 940 ASSERT_EQ(1u, alternative_service_info_vector.size()); | 940 ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 941 EXPECT_EQ(bar_alternative_service, | 941 EXPECT_EQ(bar_alternative_service, |
| 942 alternative_service_info_vector[0].alternative_service); | 942 alternative_service_info_vector[0].alternative_service()); |
| 943 | 943 |
| 944 url::SchemeHostPort qux_server("https", "qux.c.youtube.com", 443); | 944 url::SchemeHostPort qux_server("https", "qux.c.youtube.com", 443); |
| 945 AlternativeService qux_alternative_service(kProtoQUIC, "qux.c.youtube.com", | 945 AlternativeService qux_alternative_service(kProtoQUIC, "qux.c.youtube.com", |
| 946 443); | 946 443); |
| 947 SetAlternativeService(qux_server, qux_alternative_service); | 947 SetAlternativeService(qux_server, qux_alternative_service); |
| 948 alternative_service_info_vector = | 948 alternative_service_info_vector = |
| 949 impl_.GetAlternativeServiceInfos(foo_server); | 949 impl_.GetAlternativeServiceInfos(foo_server); |
| 950 ASSERT_EQ(1u, alternative_service_info_vector.size()); | 950 ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 951 EXPECT_EQ(qux_alternative_service, | 951 EXPECT_EQ(qux_alternative_service, |
| 952 alternative_service_info_vector[0].alternative_service); | 952 alternative_service_info_vector[0].alternative_service()); |
| 953 } | 953 } |
| 954 | 954 |
| 955 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { | 955 TEST_F(AlternateProtocolServerPropertiesTest, ClearWithCanonical) { |
| 956 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); | 956 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); |
| 957 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); | 957 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); |
| 958 AlternativeService canonical_alternative_service(kProtoQUIC, | 958 AlternativeService canonical_alternative_service(kProtoQUIC, |
| 959 "bar.c.youtube.com", 1234); | 959 "bar.c.youtube.com", 1234); |
| 960 | 960 |
| 961 SetAlternativeService(canonical_server, canonical_alternative_service); | 961 SetAlternativeService(canonical_server, canonical_alternative_service); |
| 962 impl_.Clear(); | 962 impl_.Clear(); |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1328 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); | 1328 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); |
| 1329 | 1329 |
| 1330 impl_.Clear(); | 1330 impl_.Clear(); |
| 1331 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); | 1331 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); |
| 1332 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); | 1332 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); |
| 1333 } | 1333 } |
| 1334 | 1334 |
| 1335 } // namespace | 1335 } // namespace |
| 1336 | 1336 |
| 1337 } // namespace net | 1337 } // namespace net |
| OLD | NEW |