Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: net/http/http_server_properties_impl_unittest.cc

Issue 2901093004: Add and persist a new field in AlternativeServiceInfo to list QUIC verisons advertised (Closed)
Patch Set: fix cronet/grpc Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/test/test_mock_time_task_runner.h" 12 #include "base/test/test_mock_time_task_runner.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "net/base/host_port_pair.h" 14 #include "net/base/host_port_pair.h"
15 #include "net/base/ip_address.h" 15 #include "net/base/ip_address.h"
16 #include "net/http/http_network_session.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 #include "url/gurl.h" 18 #include "url/gurl.h"
18 19
19 namespace base { 20 namespace base {
20 class ListValue; 21 class ListValue;
21 } 22 }
22 23
23 namespace net { 24 namespace net {
24 25
25 const base::TimeDelta BROKEN_ALT_SVC_EXPIRE_DELAYS[10] = { 26 const base::TimeDelta BROKEN_ALT_SVC_EXPIRE_DELAYS[10] = {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 bool HasAlternativeService(const url::SchemeHostPort& origin) { 72 bool HasAlternativeService(const url::SchemeHostPort& origin) {
72 const AlternativeServiceInfoVector alternative_service_info_vector = 73 const AlternativeServiceInfoVector alternative_service_info_vector =
73 impl_.GetAlternativeServiceInfos(origin); 74 impl_.GetAlternativeServiceInfos(origin);
74 return !alternative_service_info_vector.empty(); 75 return !alternative_service_info_vector.empty();
75 } 76 }
76 77
77 bool SetAlternativeService(const url::SchemeHostPort& origin, 78 bool SetAlternativeService(const url::SchemeHostPort& origin,
78 const AlternativeService& alternative_service) { 79 const AlternativeService& alternative_service) {
79 const base::Time expiration = 80 const base::Time expiration =
80 base::Time::Now() + base::TimeDelta::FromDays(1); 81 base::Time::Now() + base::TimeDelta::FromDays(1);
81 return impl_.SetAlternativeService(origin, alternative_service, expiration); 82 if (alternative_service.protocol == kProtoQUIC) {
83 return impl_.SetQuicAlternativeService(
84 origin, alternative_service, expiration,
85 HttpNetworkSession::Params().quic_supported_versions);
86 } else {
87 return impl_.SetHttp2AlternativeService(origin, alternative_service,
88 expiration);
89 }
82 } 90 }
83 91
84 void MarkBrokenAndLetExpireAlternativeServiceNTimes( 92 void MarkBrokenAndLetExpireAlternativeServiceNTimes(
85 const AlternativeService& alternative_service, 93 const AlternativeService& alternative_service,
86 int num_times) {} 94 int num_times) {}
87 95
88 scoped_refptr<base::TestMockTimeTaskRunner> test_task_runner_; 96 scoped_refptr<base::TestMockTimeTaskRunner> test_task_runner_;
89 97
90 std::unique_ptr<base::TickClock> broken_services_clock_; 98 std::unique_ptr<base::TickClock> broken_services_clock_;
91 HttpServerPropertiesImpl impl_; 99 HttpServerPropertiesImpl impl_;
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 alternative_service_info_vector[0].alternative_service()); 390 alternative_service_info_vector[0].alternative_service());
383 391
384 impl_.Clear(); 392 impl_.Clear();
385 EXPECT_FALSE(HasAlternativeService(test_server)); 393 EXPECT_FALSE(HasAlternativeService(test_server));
386 } 394 }
387 395
388 TEST_F(AlternateProtocolServerPropertiesTest, ExcludeOrigin) { 396 TEST_F(AlternateProtocolServerPropertiesTest, ExcludeOrigin) {
389 AlternativeServiceInfoVector alternative_service_info_vector; 397 AlternativeServiceInfoVector alternative_service_info_vector;
390 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 398 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
391 // Same hostname, same port, TCP: should be ignored. 399 // Same hostname, same port, TCP: should be ignored.
392 AlternativeServiceInfo alternative_service_info1(kProtoHTTP2, "foo", 443, 400 AlternativeServiceInfo alternative_service_info1 =
393 expiration); 401 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
402 AlternativeService(kProtoHTTP2, "foo", 443), expiration);
394 alternative_service_info_vector.push_back(alternative_service_info1); 403 alternative_service_info_vector.push_back(alternative_service_info1);
395 // Different hostname: GetAlternativeServiceInfos should return this one. 404 // Different hostname: GetAlternativeServiceInfos should return this one.
396 AlternativeServiceInfo alternative_service_info2(kProtoHTTP2, "bar", 443, 405 AlternativeServiceInfo alternative_service_info2 =
397 expiration); 406 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
407 AlternativeService(kProtoHTTP2, "bar", 443), expiration);
398 alternative_service_info_vector.push_back(alternative_service_info2); 408 alternative_service_info_vector.push_back(alternative_service_info2);
399 // Different port: GetAlternativeServiceInfos should return this one too. 409 // Different port: GetAlternativeServiceInfos should return this one too.
400 AlternativeServiceInfo alternative_service_info3(kProtoHTTP2, "foo", 80, 410 AlternativeServiceInfo alternative_service_info3 =
401 expiration); 411 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
412 AlternativeService(kProtoHTTP2, "foo", 80), expiration);
402 alternative_service_info_vector.push_back(alternative_service_info3); 413 alternative_service_info_vector.push_back(alternative_service_info3);
403 // QUIC: GetAlternativeServices should return this one too. 414 // QUIC: GetAlternativeServices should return this one too.
404 AlternativeServiceInfo alternative_service_info4(kProtoQUIC, "foo", 443, 415 AlternativeServiceInfo alternative_service_info4 =
405 expiration); 416 AlternativeServiceInfo::CreateQuicAlternativeServiceInfo(
417 AlternativeService(kProtoQUIC, "foo", 443), expiration,
418 HttpNetworkSession::Params().quic_supported_versions);
406 alternative_service_info_vector.push_back(alternative_service_info4); 419 alternative_service_info_vector.push_back(alternative_service_info4);
407 420
408 url::SchemeHostPort test_server("https", "foo", 443); 421 url::SchemeHostPort test_server("https", "foo", 443);
409 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); 422 impl_.SetAlternativeServices(test_server, alternative_service_info_vector);
410 423
411 const AlternativeServiceInfoVector alternative_service_info_vector2 = 424 const AlternativeServiceInfoVector alternative_service_info_vector2 =
412 impl_.GetAlternativeServiceInfos(test_server); 425 impl_.GetAlternativeServiceInfos(test_server);
413 ASSERT_EQ(3u, alternative_service_info_vector2.size()); 426 ASSERT_EQ(3u, alternative_service_info_vector2.size());
414 EXPECT_EQ(alternative_service_info2, alternative_service_info_vector2[0]); 427 EXPECT_EQ(alternative_service_info2, alternative_service_info_vector2[0]);
415 EXPECT_EQ(alternative_service_info3, alternative_service_info_vector2[1]); 428 EXPECT_EQ(alternative_service_info3, alternative_service_info_vector2[1]);
416 EXPECT_EQ(alternative_service_info4, alternative_service_info_vector2[2]); 429 EXPECT_EQ(alternative_service_info4, alternative_service_info_vector2[2]);
417 } 430 }
418 431
419 TEST_F(AlternateProtocolServerPropertiesTest, Set) { 432 TEST_F(AlternateProtocolServerPropertiesTest, Set) {
420 // |test_server1| has an alternative service, which will not be 433 // |test_server1| has an alternative service, which will not be
421 // affected by SetAlternativeServiceServers(), because 434 // affected by SetAlternativeServiceServers(), because
422 // |alternative_service_map| does not have an entry for 435 // |alternative_service_map| does not have an entry for
423 // |test_server1|. 436 // |test_server1|.
424 url::SchemeHostPort test_server1("http", "foo1", 80); 437 url::SchemeHostPort test_server1("http", "foo1", 80);
425 const AlternativeService alternative_service1(kProtoHTTP2, "bar1", 443); 438 const AlternativeService alternative_service1(kProtoHTTP2, "bar1", 443);
426 const base::Time now = base::Time::Now(); 439 const base::Time now = base::Time::Now();
427 base::Time expiration1 = now + base::TimeDelta::FromDays(1); 440 base::Time expiration1 = now + base::TimeDelta::FromDays(1);
428 // 1st entry in the memory. 441 // 1st entry in the memory.
429 impl_.SetAlternativeService(test_server1, alternative_service1, expiration1); 442 impl_.SetHttp2AlternativeService(test_server1, alternative_service1,
443 expiration1);
430 444
431 // |test_server2| has an alternative service, which will be 445 // |test_server2| has an alternative service, which will be
432 // overwritten by SetAlternativeServiceServers(), because 446 // overwritten by SetAlternativeServiceServers(), because
433 // |alternative_service_map| has an entry for 447 // |alternative_service_map| has an entry for
434 // |test_server2|. 448 // |test_server2|.
435 AlternativeServiceInfoVector alternative_service_info_vector; 449 AlternativeServiceInfoVector alternative_service_info_vector;
436 const AlternativeService alternative_service2(kProtoHTTP2, "bar2", 443); 450 const AlternativeService alternative_service2(kProtoHTTP2, "bar2", 443);
437 base::Time expiration2 = now + base::TimeDelta::FromDays(2); 451 base::Time expiration2 = now + base::TimeDelta::FromDays(2);
438 alternative_service_info_vector.push_back( 452 alternative_service_info_vector.push_back(
439 AlternativeServiceInfo(alternative_service2, expiration2)); 453 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
454 alternative_service2, expiration2));
440 url::SchemeHostPort test_server2("http", "foo2", 80); 455 url::SchemeHostPort test_server2("http", "foo2", 80);
441 // 0th entry in the memory. 456 // 0th entry in the memory.
442 impl_.SetAlternativeServices(test_server2, alternative_service_info_vector); 457 impl_.SetAlternativeServices(test_server2, alternative_service_info_vector);
443 458
444 // Prepare |alternative_service_map| to be loaded by 459 // Prepare |alternative_service_map| to be loaded by
445 // SetAlternativeServiceServers(). 460 // SetAlternativeServiceServers().
446 AlternativeServiceMap alternative_service_map( 461 AlternativeServiceMap alternative_service_map(
447 AlternativeServiceMap::NO_AUTO_EVICT); 462 AlternativeServiceMap::NO_AUTO_EVICT);
448 const AlternativeService alternative_service3(kProtoHTTP2, "bar3", 123); 463 const AlternativeService alternative_service3(kProtoHTTP2, "bar3", 123);
449 base::Time expiration3 = now + base::TimeDelta::FromDays(3); 464 base::Time expiration3 = now + base::TimeDelta::FromDays(3);
450 const AlternativeServiceInfo alternative_service_info1(alternative_service3, 465 const AlternativeServiceInfo alternative_service_info1 =
451 expiration3); 466 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
467 alternative_service3, expiration3);
452 // Simulate updating data for 0th entry with data from Preferences. 468 // Simulate updating data for 0th entry with data from Preferences.
453 alternative_service_map.Put( 469 alternative_service_map.Put(
454 test_server2, 470 test_server2,
455 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info1)); 471 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info1));
456 472
457 url::SchemeHostPort test_server3("http", "foo3", 80); 473 url::SchemeHostPort test_server3("http", "foo3", 80);
458 const AlternativeService alternative_service4(kProtoHTTP2, "bar4", 1234); 474 const AlternativeService alternative_service4(kProtoHTTP2, "bar4", 1234);
459 base::Time expiration4 = now + base::TimeDelta::FromDays(4); 475 base::Time expiration4 = now + base::TimeDelta::FromDays(4);
460 const AlternativeServiceInfo alternative_service_info2(alternative_service4, 476 const AlternativeServiceInfo alternative_service_info2 =
461 expiration4); 477 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
478 alternative_service4, expiration4);
462 // Add an old entry from Preferences, this will be added to end of recency 479 // Add an old entry from Preferences, this will be added to end of recency
463 // list. 480 // list.
464 alternative_service_map.Put( 481 alternative_service_map.Put(
465 test_server3, 482 test_server3,
466 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info2)); 483 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info2));
467 484
468 // MRU list will be test_server2, test_server1, test_server3. 485 // MRU list will be test_server2, test_server1, test_server3.
469 impl_.SetAlternativeServiceServers(&alternative_service_map); 486 impl_.SetAlternativeServiceServers(&alternative_service_map);
470 487
471 // Verify alternative_service_map. 488 // Verify alternative_service_map.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 alternative_service_info_vector[0].alternative_service()); 531 alternative_service_info_vector[0].alternative_service());
515 } 532 }
516 533
517 // Regression test for https://crbug.com/516486: 534 // Regression test for https://crbug.com/516486:
518 // GetAlternativeServiceInfos() should remove |alternative_service_map_| 535 // GetAlternativeServiceInfos() should remove |alternative_service_map_|
519 // elements with empty value. 536 // elements with empty value.
520 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVector) { 537 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVector) {
521 url::SchemeHostPort server("https", "foo", 443); 538 url::SchemeHostPort server("https", "foo", 443);
522 const AlternativeService alternative_service(kProtoHTTP2, "bar", 443); 539 const AlternativeService alternative_service(kProtoHTTP2, "bar", 443);
523 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); 540 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1);
524 const AlternativeServiceInfo alternative_service_info(alternative_service, 541 const AlternativeServiceInfo alternative_service_info =
525 expiration); 542 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
543 alternative_service, expiration);
526 AlternativeServiceMap alternative_service_map( 544 AlternativeServiceMap alternative_service_map(
527 AlternativeServiceMap::NO_AUTO_EVICT); 545 AlternativeServiceMap::NO_AUTO_EVICT);
528 alternative_service_map.Put( 546 alternative_service_map.Put(
529 server, 547 server,
530 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); 548 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info));
531 549
532 // Prepare |alternative_service_map_| with a single key that has a single 550 // Prepare |alternative_service_map_| with a single key that has a single
533 // AlternativeServiceInfo with identical hostname and port. 551 // AlternativeServiceInfo with identical hostname and port.
534 impl_.SetAlternativeServiceServers(&alternative_service_map); 552 impl_.SetAlternativeServiceServers(&alternative_service_map);
535 553
(...skipping 11 matching lines...) Expand all
547 // There should still be no alternative service assigned to |server|. 565 // There should still be no alternative service assigned to |server|.
548 ASSERT_TRUE(impl_.GetAlternativeServiceInfos(server).empty()); 566 ASSERT_TRUE(impl_.GetAlternativeServiceInfos(server).empty());
549 } 567 }
550 568
551 // Regression test for https://crbug.com/516486 for the canonical host case. 569 // Regression test for https://crbug.com/516486 for the canonical host case.
552 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVectorForCanonical) { 570 TEST_F(AlternateProtocolServerPropertiesTest, EmptyVectorForCanonical) {
553 url::SchemeHostPort server("https", "foo.c.youtube.com", 443); 571 url::SchemeHostPort server("https", "foo.c.youtube.com", 443);
554 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); 572 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443);
555 const AlternativeService alternative_service(kProtoHTTP2, "", 443); 573 const AlternativeService alternative_service(kProtoHTTP2, "", 443);
556 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1); 574 base::Time expiration = base::Time::Now() - base::TimeDelta::FromDays(1);
557 const AlternativeServiceInfo alternative_service_info(alternative_service, 575 const AlternativeServiceInfo alternative_service_info =
558 expiration); 576 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
577 alternative_service, expiration);
559 AlternativeServiceMap alternative_service_map( 578 AlternativeServiceMap alternative_service_map(
560 AlternativeServiceMap::NO_AUTO_EVICT); 579 AlternativeServiceMap::NO_AUTO_EVICT);
561 alternative_service_map.Put( 580 alternative_service_map.Put(
562 canonical_server, 581 canonical_server,
563 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); 582 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info));
564 583
565 // Prepare |alternative_service_map_| with a single key that has a single 584 // Prepare |alternative_service_map_| with a single key that has a single
566 // AlternativeServiceInfo with identical hostname and port. 585 // AlternativeServiceInfo with identical hostname and port.
567 impl_.SetAlternativeServiceServers(&alternative_service_map); 586 impl_.SetAlternativeServiceServers(&alternative_service_map);
568 587
(...skipping 12 matching lines...) Expand all
581 // There should still be no alternative service assigned to 600 // There should still be no alternative service assigned to
582 // |canonical_server|. 601 // |canonical_server|.
583 ASSERT_TRUE(impl_.GetAlternativeServiceInfos(canonical_server).empty()); 602 ASSERT_TRUE(impl_.GetAlternativeServiceInfos(canonical_server).empty());
584 } 603 }
585 604
586 TEST_F(AlternateProtocolServerPropertiesTest, ClearServerWithCanonical) { 605 TEST_F(AlternateProtocolServerPropertiesTest, ClearServerWithCanonical) {
587 url::SchemeHostPort server("https", "foo.c.youtube.com", 443); 606 url::SchemeHostPort server("https", "foo.c.youtube.com", 443);
588 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); 607 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443);
589 const AlternativeService alternative_service(kProtoQUIC, "", 443); 608 const AlternativeService alternative_service(kProtoQUIC, "", 443);
590 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 609 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
591 const AlternativeServiceInfo alternative_service_info(alternative_service, 610 const AlternativeServiceInfo alternative_service_info =
592 expiration); 611 AlternativeServiceInfo::CreateQuicAlternativeServiceInfo(
612 alternative_service, expiration,
613 HttpNetworkSession::Params().quic_supported_versions);
593 614
594 impl_.SetAlternativeServices( 615 impl_.SetAlternativeServices(
595 canonical_server, 616 canonical_server,
596 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info)); 617 AlternativeServiceInfoVector(/*size=*/1, alternative_service_info));
597 618
598 // Make sure the canonical service is returned for the other server. 619 // Make sure the canonical service is returned for the other server.
599 const AlternativeServiceInfoVector alternative_service_info_vector = 620 const AlternativeServiceInfoVector alternative_service_info_vector =
600 impl_.GetAlternativeServiceInfos(server); 621 impl_.GetAlternativeServiceInfos(server);
601 ASSERT_EQ(1u, alternative_service_info_vector.size()); 622 ASSERT_EQ(1u, alternative_service_info_vector.size());
602 EXPECT_EQ(kProtoQUIC, 623 EXPECT_EQ(kProtoQUIC,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 impl_.GetAlternativeServiceInfos(test_server); 677 impl_.GetAlternativeServiceInfos(test_server);
657 ASSERT_EQ(1u, alternative_service_info_vector.size()); 678 ASSERT_EQ(1u, alternative_service_info_vector.size());
658 EXPECT_EQ(alternative_service1, 679 EXPECT_EQ(alternative_service1,
659 alternative_service_info_vector[0].alternative_service()); 680 alternative_service_info_vector[0].alternative_service());
660 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); 681 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1));
661 682
662 // SetAlternativeServices should add a broken alternative service to the map. 683 // SetAlternativeServices should add a broken alternative service to the map.
663 AlternativeServiceInfoVector alternative_service_info_vector2; 684 AlternativeServiceInfoVector alternative_service_info_vector2;
664 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 685 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
665 alternative_service_info_vector2.push_back( 686 alternative_service_info_vector2.push_back(
666 AlternativeServiceInfo(alternative_service1, expiration)); 687 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
688 alternative_service1, expiration));
667 const AlternativeService alternative_service2(kProtoHTTP2, "foo", 1234); 689 const AlternativeService alternative_service2(kProtoHTTP2, "foo", 1234);
668 alternative_service_info_vector2.push_back( 690 alternative_service_info_vector2.push_back(
669 AlternativeServiceInfo(alternative_service2, expiration)); 691 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
692 alternative_service2, expiration));
670 impl_.SetAlternativeServices(test_server, alternative_service_info_vector2); 693 impl_.SetAlternativeServices(test_server, alternative_service_info_vector2);
671 alternative_service_info_vector = 694 alternative_service_info_vector =
672 impl_.GetAlternativeServiceInfos(test_server); 695 impl_.GetAlternativeServiceInfos(test_server);
673 ASSERT_EQ(2u, alternative_service_info_vector.size()); 696 ASSERT_EQ(2u, alternative_service_info_vector.size());
674 EXPECT_EQ(alternative_service1, 697 EXPECT_EQ(alternative_service1,
675 alternative_service_info_vector[0].alternative_service()); 698 alternative_service_info_vector[0].alternative_service());
676 EXPECT_EQ(alternative_service2, 699 EXPECT_EQ(alternative_service2,
677 alternative_service_info_vector[1].alternative_service()); 700 alternative_service_info_vector[1].alternative_service());
678 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1)); 701 EXPECT_TRUE(impl_.IsAlternativeServiceBroken(alternative_service1));
679 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service2)); 702 EXPECT_FALSE(impl_.IsAlternativeServiceBroken(alternative_service2));
(...skipping 10 matching lines...) Expand all
690 713
691 TEST_F(AlternateProtocolServerPropertiesTest, MaxAge) { 714 TEST_F(AlternateProtocolServerPropertiesTest, MaxAge) {
692 AlternativeServiceInfoVector alternative_service_info_vector; 715 AlternativeServiceInfoVector alternative_service_info_vector;
693 base::Time now = base::Time::Now(); 716 base::Time now = base::Time::Now();
694 base::TimeDelta one_day = base::TimeDelta::FromDays(1); 717 base::TimeDelta one_day = base::TimeDelta::FromDays(1);
695 718
696 // First alternative service expired one day ago, should not be returned by 719 // First alternative service expired one day ago, should not be returned by
697 // GetAlternativeServiceInfos(). 720 // GetAlternativeServiceInfos().
698 const AlternativeService alternative_service1(kProtoHTTP2, "foo", 443); 721 const AlternativeService alternative_service1(kProtoHTTP2, "foo", 443);
699 alternative_service_info_vector.push_back( 722 alternative_service_info_vector.push_back(
700 AlternativeServiceInfo(alternative_service1, now - one_day)); 723 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
724 alternative_service1, now - one_day));
701 725
702 // Second alterrnative service will expire one day from now, should be 726 // Second alterrnative service will expire one day from now, should be
703 // returned by GetAlternativeSerices(). 727 // returned by GetAlternativeSerices().
704 const AlternativeService alternative_service2(kProtoHTTP2, "bar", 1234); 728 const AlternativeService alternative_service2(kProtoHTTP2, "bar", 1234);
705 alternative_service_info_vector.push_back( 729 alternative_service_info_vector.push_back(
706 AlternativeServiceInfo(alternative_service2, now + one_day)); 730 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
731 alternative_service2, now + one_day));
707 732
708 url::SchemeHostPort test_server("http", "foo", 80); 733 url::SchemeHostPort test_server("http", "foo", 80);
709 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); 734 impl_.SetAlternativeServices(test_server, alternative_service_info_vector);
710 735
711 AlternativeServiceInfoVector alternative_service_info_vector2 = 736 AlternativeServiceInfoVector alternative_service_info_vector2 =
712 impl_.GetAlternativeServiceInfos(test_server); 737 impl_.GetAlternativeServiceInfos(test_server);
713 ASSERT_EQ(1u, alternative_service_info_vector2.size()); 738 ASSERT_EQ(1u, alternative_service_info_vector2.size());
714 EXPECT_EQ(alternative_service2, 739 EXPECT_EQ(alternative_service2,
715 alternative_service_info_vector2[0].alternative_service()); 740 alternative_service_info_vector2[0].alternative_service());
716 } 741 }
717 742
718 TEST_F(AlternateProtocolServerPropertiesTest, MaxAgeCanonical) { 743 TEST_F(AlternateProtocolServerPropertiesTest, MaxAgeCanonical) {
719 AlternativeServiceInfoVector alternative_service_info_vector; 744 AlternativeServiceInfoVector alternative_service_info_vector;
720 base::Time now = base::Time::Now(); 745 base::Time now = base::Time::Now();
721 base::TimeDelta one_day = base::TimeDelta::FromDays(1); 746 base::TimeDelta one_day = base::TimeDelta::FromDays(1);
722 747
723 // First alternative service expired one day ago, should not be returned by 748 // First alternative service expired one day ago, should not be returned by
724 // GetAlternativeServiceInfos(). 749 // GetAlternativeServiceInfos().
725 const AlternativeService alternative_service1(kProtoHTTP2, "foo", 443); 750 const AlternativeService alternative_service1(kProtoHTTP2, "foo", 443);
726 alternative_service_info_vector.push_back( 751 alternative_service_info_vector.push_back(
727 AlternativeServiceInfo(alternative_service1, now - one_day)); 752 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
753 alternative_service1, now - one_day));
728 754
729 // Second alterrnative service will expire one day from now, should be 755 // Second alterrnative service will expire one day from now, should be
730 // returned by GetAlternativeSerices(). 756 // returned by GetAlternativeSerices().
731 const AlternativeService alternative_service2(kProtoHTTP2, "bar", 1234); 757 const AlternativeService alternative_service2(kProtoHTTP2, "bar", 1234);
732 alternative_service_info_vector.push_back( 758 alternative_service_info_vector.push_back(
733 AlternativeServiceInfo(alternative_service2, now + one_day)); 759 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
760 alternative_service2, now + one_day));
734 761
735 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); 762 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443);
736 impl_.SetAlternativeServices(canonical_server, 763 impl_.SetAlternativeServices(canonical_server,
737 alternative_service_info_vector); 764 alternative_service_info_vector);
738 765
739 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443); 766 url::SchemeHostPort test_server("https", "foo.c.youtube.com", 443);
740 AlternativeServiceInfoVector alternative_service_info_vector2 = 767 AlternativeServiceInfoVector alternative_service_info_vector2 =
741 impl_.GetAlternativeServiceInfos(test_server); 768 impl_.GetAlternativeServiceInfos(test_server);
742 ASSERT_EQ(1u, alternative_service_info_vector2.size()); 769 ASSERT_EQ(1u, alternative_service_info_vector2.size());
743 EXPECT_EQ(alternative_service2, 770 EXPECT_EQ(alternative_service2,
744 alternative_service_info_vector2[0].alternative_service()); 771 alternative_service_info_vector2[0].alternative_service());
745 } 772 }
746 773
747 TEST_F(AlternateProtocolServerPropertiesTest, AlternativeServiceWithScheme) { 774 TEST_F(AlternateProtocolServerPropertiesTest, AlternativeServiceWithScheme) {
748 AlternativeServiceInfoVector alternative_service_info_vector; 775 AlternativeServiceInfoVector alternative_service_info_vector;
749 const AlternativeService alternative_service1(kProtoHTTP2, "foo", 443); 776 const AlternativeService alternative_service1(kProtoHTTP2, "foo", 443);
750 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 777 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
751 alternative_service_info_vector.push_back( 778 alternative_service_info_vector.push_back(
752 AlternativeServiceInfo(alternative_service1, expiration)); 779 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
780 alternative_service1, expiration));
753 const AlternativeService alternative_service2(kProtoHTTP2, "bar", 1234); 781 const AlternativeService alternative_service2(kProtoHTTP2, "bar", 1234);
754 alternative_service_info_vector.push_back( 782 alternative_service_info_vector.push_back(
755 AlternativeServiceInfo(alternative_service2, expiration)); 783 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
784 alternative_service2, expiration));
756 // Set Alt-Svc list for |http_server|. 785 // Set Alt-Svc list for |http_server|.
757 url::SchemeHostPort http_server("http", "foo", 80); 786 url::SchemeHostPort http_server("http", "foo", 80);
758 impl_.SetAlternativeServices(http_server, alternative_service_info_vector); 787 impl_.SetAlternativeServices(http_server, alternative_service_info_vector);
759 788
760 const net::AlternativeServiceMap& map = impl_.alternative_service_map(); 789 const net::AlternativeServiceMap& map = impl_.alternative_service_map();
761 net::AlternativeServiceMap::const_iterator it = map.begin(); 790 net::AlternativeServiceMap::const_iterator it = map.begin();
762 EXPECT_TRUE(it->first.Equals(http_server)); 791 EXPECT_TRUE(it->first.Equals(http_server));
763 ASSERT_EQ(2u, it->second.size()); 792 ASSERT_EQ(2u, it->second.size());
764 EXPECT_EQ(alternative_service1, it->second[0].alternative_service()); 793 EXPECT_EQ(alternative_service1, it->second[0].alternative_service());
765 EXPECT_EQ(alternative_service2, it->second[1].alternative_service()); 794 EXPECT_EQ(alternative_service2, it->second[1].alternative_service());
(...skipping 12 matching lines...) Expand all
778 807
779 EXPECT_EQ(0u, impl_.GetAlternativeServiceInfos(http_server).size()); 808 EXPECT_EQ(0u, impl_.GetAlternativeServiceInfos(http_server).size());
780 EXPECT_EQ(2u, impl_.GetAlternativeServiceInfos(https_server).size()); 809 EXPECT_EQ(2u, impl_.GetAlternativeServiceInfos(https_server).size());
781 } 810 }
782 811
783 TEST_F(AlternateProtocolServerPropertiesTest, ClearAlternativeServices) { 812 TEST_F(AlternateProtocolServerPropertiesTest, ClearAlternativeServices) {
784 AlternativeServiceInfoVector alternative_service_info_vector; 813 AlternativeServiceInfoVector alternative_service_info_vector;
785 const AlternativeService alternative_service1(kProtoHTTP2, "foo", 443); 814 const AlternativeService alternative_service1(kProtoHTTP2, "foo", 443);
786 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 815 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
787 alternative_service_info_vector.push_back( 816 alternative_service_info_vector.push_back(
788 AlternativeServiceInfo(alternative_service1, expiration)); 817 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
818 alternative_service1, expiration));
789 const AlternativeService alternative_service2(kProtoHTTP2, "bar", 1234); 819 const AlternativeService alternative_service2(kProtoHTTP2, "bar", 1234);
790 alternative_service_info_vector.push_back( 820 alternative_service_info_vector.push_back(
791 AlternativeServiceInfo(alternative_service2, expiration)); 821 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
822 alternative_service2, expiration));
792 url::SchemeHostPort test_server("http", "foo", 80); 823 url::SchemeHostPort test_server("http", "foo", 80);
793 impl_.SetAlternativeServices(test_server, alternative_service_info_vector); 824 impl_.SetAlternativeServices(test_server, alternative_service_info_vector);
794 825
795 const net::AlternativeServiceMap& map = impl_.alternative_service_map(); 826 const net::AlternativeServiceMap& map = impl_.alternative_service_map();
796 net::AlternativeServiceMap::const_iterator it = map.begin(); 827 net::AlternativeServiceMap::const_iterator it = map.begin();
797 EXPECT_TRUE(it->first.Equals(test_server)); 828 EXPECT_TRUE(it->first.Equals(test_server));
798 ASSERT_EQ(2u, it->second.size()); 829 ASSERT_EQ(2u, it->second.size());
799 EXPECT_EQ(alternative_service1, it->second[0].alternative_service()); 830 EXPECT_EQ(alternative_service1, it->second[0].alternative_service());
800 EXPECT_EQ(alternative_service2, it->second[1].alternative_service()); 831 EXPECT_EQ(alternative_service2, it->second[1].alternative_service());
801 832
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 EXPECT_FALSE(HasAlternativeService(test_server)); 898 EXPECT_FALSE(HasAlternativeService(test_server));
868 899
869 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443); 900 url::SchemeHostPort canonical_server("https", "bar.c.youtube.com", 443);
870 EXPECT_FALSE(HasAlternativeService(canonical_server)); 901 EXPECT_FALSE(HasAlternativeService(canonical_server));
871 902
872 AlternativeServiceInfoVector alternative_service_info_vector; 903 AlternativeServiceInfoVector alternative_service_info_vector;
873 const AlternativeService canonical_alternative_service1( 904 const AlternativeService canonical_alternative_service1(
874 kProtoQUIC, "bar.c.youtube.com", 1234); 905 kProtoQUIC, "bar.c.youtube.com", 1234);
875 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); 906 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1);
876 alternative_service_info_vector.push_back( 907 alternative_service_info_vector.push_back(
877 AlternativeServiceInfo(canonical_alternative_service1, expiration)); 908 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
909 canonical_alternative_service1, expiration));
878 const AlternativeService canonical_alternative_service2(kProtoHTTP2, "", 443); 910 const AlternativeService canonical_alternative_service2(kProtoHTTP2, "", 443);
879 alternative_service_info_vector.push_back( 911 alternative_service_info_vector.push_back(
880 AlternativeServiceInfo(canonical_alternative_service2, expiration)); 912 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo(
913 canonical_alternative_service2, expiration));
881 impl_.SetAlternativeServices(canonical_server, 914 impl_.SetAlternativeServices(canonical_server,
882 alternative_service_info_vector); 915 alternative_service_info_vector);
883 916
884 // Since |test_server| does not have an alternative service itself, 917 // Since |test_server| does not have an alternative service itself,
885 // GetAlternativeServiceInfos should return those of |canonical_server|. 918 // GetAlternativeServiceInfos should return those of |canonical_server|.
886 AlternativeServiceInfoVector alternative_service_info_vector2 = 919 AlternativeServiceInfoVector alternative_service_info_vector2 =
887 impl_.GetAlternativeServiceInfos(test_server); 920 impl_.GetAlternativeServiceInfos(test_server);
888 ASSERT_EQ(2u, alternative_service_info_vector2.size()); 921 ASSERT_EQ(2u, alternative_service_info_vector2.size());
889 EXPECT_EQ(canonical_alternative_service1, 922 EXPECT_EQ(canonical_alternative_service1,
890 alternative_service_info_vector2[0].alternative_service()); 923 alternative_service_info_vector2[0].alternative_service());
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1328 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id))); 1361 EXPECT_EQ(quic_server_info1, *(impl_.GetQuicServerInfo(quic_server_id)));
1329 1362
1330 impl_.Clear(); 1363 impl_.Clear();
1331 EXPECT_EQ(0u, impl_.quic_server_info_map().size()); 1364 EXPECT_EQ(0u, impl_.quic_server_info_map().size());
1332 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id)); 1365 EXPECT_EQ(nullptr, impl_.GetQuicServerInfo(quic_server_id));
1333 } 1366 }
1334 1367
1335 } // namespace 1368 } // namespace
1336 1369
1337 } // namespace net 1370 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698