OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/precache/core/precache_fetcher.h" | 5 #include "components/precache/core/precache_fetcher.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <cstring> | 9 #include <cstring> |
10 #include <memory> | 10 #include <memory> |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
569 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); | 569 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); |
570 | 570 |
571 EXPECT_TRUE(precache_delegate_.was_on_done_called()); | 571 EXPECT_TRUE(precache_delegate_.was_on_done_called()); |
572 | 572 |
573 histogram.ExpectUniqueSample("Precache.Fetch.PercentCompleted", 100, 1); | 573 histogram.ExpectUniqueSample("Precache.Fetch.PercentCompleted", 100, 1); |
574 histogram.ExpectUniqueSample("Precache.Fetch.ResponseBytes.Total", | 574 histogram.ExpectUniqueSample("Precache.Fetch.ResponseBytes.Total", |
575 url_callback_.total_response_bytes(), 1); | 575 url_callback_.total_response_bytes(), 1); |
576 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 1); | 576 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 1); |
577 } | 577 } |
578 | 578 |
579 TEST_F(PrecacheFetcherTest, PrecacheResourceSelection) { | 579 class PrecacheFetcherResourceSelectionTest |
580 : public PrecacheFetcherTest, | |
581 public testing::WithParamInterface<PrecacheResourceSelection> { | |
582 public: | |
583 // Set bits for kGoodResourceURL, kGoodResourceURLB and kGoodResourceURLD. | |
584 static PrecacheResourceSelection DeprecatedBitset() { | |
585 PrecacheResourceSelection ret; | |
586 ret.set_deprecated_bitset(0b10101); | |
jamartin
2017/02/22 22:14:01
Can you please change the testcase for one that it
twifkak
2017/02/22 23:55:03
Done. Made it multibyte, too, to test the mixed or
| |
587 return ret; | |
588 } | |
589 | |
590 // Set bits for kGoodResourceURL, kGoodResourceURLB and kGoodResourceURLD. | |
591 static PrecacheResourceSelection Bitset() { | |
592 PrecacheResourceSelection ret; | |
593 ret.set_bitset("\x15"); | |
594 return ret; | |
595 } | |
596 }; | |
597 | |
598 TEST_P(PrecacheFetcherResourceSelectionTest, Basic) { | |
580 SetDefaultFlags(); | 599 SetDefaultFlags(); |
581 | 600 |
582 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work( | 601 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work( |
583 new PrecacheUnfinishedWork()); | 602 new PrecacheUnfinishedWork()); |
584 unfinished_work->add_top_host()->set_hostname("good-manifest.com"); | 603 unfinished_work->add_top_host()->set_hostname("good-manifest.com"); |
585 unfinished_work->set_start_time(base::Time::UnixEpoch().ToInternalValue()); | 604 unfinished_work->set_start_time(base::Time::UnixEpoch().ToInternalValue()); |
586 | 605 |
587 PrecacheConfigurationSettings config; | 606 PrecacheConfigurationSettings config; |
588 | 607 |
589 PrecacheManifest good_manifest; | 608 PrecacheManifest good_manifest; |
590 PrecacheResourceSelection resource_selection; | 609 PrecacheResourceSelection resource_selection; |
591 good_manifest.add_resource()->set_url(kGoodResourceURL); | 610 good_manifest.add_resource()->set_url(kGoodResourceURL); |
592 good_manifest.add_resource()->set_url(kGoodResourceURLA); | 611 good_manifest.add_resource()->set_url(kGoodResourceURLA); |
593 good_manifest.add_resource()->set_url(kGoodResourceURLB); | 612 good_manifest.add_resource()->set_url(kGoodResourceURLB); |
594 good_manifest.add_resource()->set_url(kGoodResourceURLC); | 613 good_manifest.add_resource()->set_url(kGoodResourceURLC); |
595 good_manifest.add_resource()->set_url(kGoodResourceURLD); | 614 good_manifest.add_resource()->set_url(kGoodResourceURLD); |
596 | 615 |
597 // Set bits for kGoodResourceURL, kGoodResourceURLB and kGoodResourceURLD. | |
598 resource_selection.set_bitset(0b10101); | |
599 (*good_manifest.mutable_experiments() | 616 (*good_manifest.mutable_experiments() |
600 ->mutable_resources_by_experiment_group())[kExperimentID] = | 617 ->mutable_resources_by_experiment_group())[kExperimentID] = GetParam(); |
601 resource_selection; | |
602 | 618 |
603 factory_.SetFakeResponse(GURL(kConfigURL), config.SerializeAsString(), | 619 factory_.SetFakeResponse(GURL(kConfigURL), config.SerializeAsString(), |
604 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 620 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
605 factory_.SetFakeResponse(GURL(kGoodManifestURL), | 621 factory_.SetFakeResponse(GURL(kGoodManifestURL), |
606 good_manifest.SerializeAsString(), net::HTTP_OK, | 622 good_manifest.SerializeAsString(), net::HTTP_OK, |
607 net::URLRequestStatus::SUCCESS); | 623 net::URLRequestStatus::SUCCESS); |
608 factory_.SetFakeResponse(GURL(kGoodResourceURL), "good", net::HTTP_OK, | 624 factory_.SetFakeResponse(GURL(kGoodResourceURL), "good", net::HTTP_OK, |
609 net::URLRequestStatus::SUCCESS); | 625 net::URLRequestStatus::SUCCESS); |
610 factory_.SetFakeResponse(GURL(kGoodResourceURLB), "good URL B", net::HTTP_OK, | 626 factory_.SetFakeResponse(GURL(kGoodResourceURLB), "good URL B", net::HTTP_OK, |
611 net::URLRequestStatus::SUCCESS); | 627 net::URLRequestStatus::SUCCESS); |
(...skipping 24 matching lines...) Expand all Loading... | |
636 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); | 652 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); |
637 | 653 |
638 EXPECT_TRUE(precache_delegate_.was_on_done_called()); | 654 EXPECT_TRUE(precache_delegate_.was_on_done_called()); |
639 | 655 |
640 histogram.ExpectUniqueSample("Precache.Fetch.PercentCompleted", 100, 1); | 656 histogram.ExpectUniqueSample("Precache.Fetch.PercentCompleted", 100, 1); |
641 histogram.ExpectUniqueSample("Precache.Fetch.ResponseBytes.Total", | 657 histogram.ExpectUniqueSample("Precache.Fetch.ResponseBytes.Total", |
642 url_callback_.total_response_bytes(), 1); | 658 url_callback_.total_response_bytes(), 1); |
643 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 1); | 659 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 1); |
644 } | 660 } |
645 | 661 |
646 TEST_F(PrecacheFetcherTest, PrecacheResourceSelectionMissingBitset) { | 662 TEST_P(PrecacheFetcherResourceSelectionTest, MissingBitset) { |
647 SetDefaultFlags(); | 663 SetDefaultFlags(); |
648 | 664 |
649 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work( | 665 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work( |
650 new PrecacheUnfinishedWork()); | 666 new PrecacheUnfinishedWork()); |
651 unfinished_work->add_top_host()->set_hostname("good-manifest.com"); | 667 unfinished_work->add_top_host()->set_hostname("good-manifest.com"); |
652 unfinished_work->set_start_time(base::Time::UnixEpoch().ToInternalValue()); | 668 unfinished_work->set_start_time(base::Time::UnixEpoch().ToInternalValue()); |
653 | 669 |
654 PrecacheConfigurationSettings config; | 670 PrecacheConfigurationSettings config; |
655 | 671 |
656 PrecacheManifest good_manifest; | 672 PrecacheManifest good_manifest; |
657 PrecacheResourceSelection resource_selection; | 673 PrecacheResourceSelection resource_selection; |
658 good_manifest.add_resource()->set_url(kGoodResourceURL); | 674 good_manifest.add_resource()->set_url(kGoodResourceURL); |
659 good_manifest.add_resource()->set_url(kGoodResourceURLA); | 675 good_manifest.add_resource()->set_url(kGoodResourceURLA); |
660 good_manifest.add_resource()->set_url(kGoodResourceURLB); | 676 good_manifest.add_resource()->set_url(kGoodResourceURLB); |
661 good_manifest.add_resource()->set_url(kGoodResourceURLC); | 677 good_manifest.add_resource()->set_url(kGoodResourceURLC); |
662 good_manifest.add_resource()->set_url(kGoodResourceURLD); | 678 good_manifest.add_resource()->set_url(kGoodResourceURLD); |
663 | 679 |
664 // Set bits for a different experiment group. | 680 // Set bits for a different experiment group. |
665 resource_selection.set_bitset(0b1); | |
666 (*good_manifest.mutable_experiments() | 681 (*good_manifest.mutable_experiments() |
667 ->mutable_resources_by_experiment_group())[kExperimentID + 1] = | 682 ->mutable_resources_by_experiment_group())[kExperimentID + 1] = |
668 resource_selection; | 683 GetParam(); |
669 | 684 |
670 // Resource selection bitset for the experiment group will be missing and all | 685 // Resource selection bitset for the experiment group will be missing and all |
671 // resources will be fetched. | 686 // resources will be fetched. |
672 factory_.SetFakeResponse(GURL(kConfigURL), config.SerializeAsString(), | 687 factory_.SetFakeResponse(GURL(kConfigURL), config.SerializeAsString(), |
673 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 688 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
674 factory_.SetFakeResponse(GURL(kGoodManifestURL), | 689 factory_.SetFakeResponse(GURL(kGoodManifestURL), |
675 good_manifest.SerializeAsString(), net::HTTP_OK, | 690 good_manifest.SerializeAsString(), net::HTTP_OK, |
676 net::URLRequestStatus::SUCCESS); | 691 net::URLRequestStatus::SUCCESS); |
677 factory_.SetFakeResponse(GURL(kGoodResourceURL), "good", net::HTTP_OK, | 692 factory_.SetFakeResponse(GURL(kGoodResourceURL), "good", net::HTTP_OK, |
678 net::URLRequestStatus::SUCCESS); | 693 net::URLRequestStatus::SUCCESS); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
711 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); | 726 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); |
712 | 727 |
713 EXPECT_TRUE(precache_delegate_.was_on_done_called()); | 728 EXPECT_TRUE(precache_delegate_.was_on_done_called()); |
714 | 729 |
715 histogram.ExpectUniqueSample("Precache.Fetch.PercentCompleted", 100, 1); | 730 histogram.ExpectUniqueSample("Precache.Fetch.PercentCompleted", 100, 1); |
716 histogram.ExpectUniqueSample("Precache.Fetch.ResponseBytes.Total", | 731 histogram.ExpectUniqueSample("Precache.Fetch.ResponseBytes.Total", |
717 url_callback_.total_response_bytes(), 1); | 732 url_callback_.total_response_bytes(), 1); |
718 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 1); | 733 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 1); |
719 } | 734 } |
720 | 735 |
736 INSTANTIATE_TEST_CASE_P( | |
737 PrecacheFetcherResourceSelectionTest, | |
738 PrecacheFetcherResourceSelectionTest, | |
739 testing::Values(PrecacheFetcherResourceSelectionTest::DeprecatedBitset(), | |
740 PrecacheFetcherResourceSelectionTest::Bitset())); | |
741 | |
721 TEST_F(PrecacheFetcherTest, PrecachePauseResume) { | 742 TEST_F(PrecacheFetcherTest, PrecachePauseResume) { |
722 SetDefaultFlags(); | 743 SetDefaultFlags(); |
723 | 744 |
724 PrecacheConfigurationSettings config; | 745 PrecacheConfigurationSettings config; |
725 config.set_top_sites_count(3); | 746 config.set_top_sites_count(3); |
726 | 747 |
727 std::unique_ptr<PrecacheUnfinishedWork> initial_work( | 748 std::unique_ptr<PrecacheUnfinishedWork> initial_work( |
728 new PrecacheUnfinishedWork()); | 749 new PrecacheUnfinishedWork()); |
729 initial_work->add_top_host()->set_hostname("manifest1.com"); | 750 initial_work->add_top_host()->set_hostname("manifest1.com"); |
730 initial_work->add_top_host()->set_hostname("manifest2.com"); | 751 initial_work->add_top_host()->set_hostname("manifest2.com"); |
(...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1937 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); | 1958 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); |
1938 | 1959 |
1939 EXPECT_TRUE(precache_delegate_.was_on_done_called()); | 1960 EXPECT_TRUE(precache_delegate_.was_on_done_called()); |
1940 | 1961 |
1941 histogram.ExpectTotalCount("Precache.Fetch.PercentCompleted", 2); | 1962 histogram.ExpectTotalCount("Precache.Fetch.PercentCompleted", 2); |
1942 histogram.ExpectTotalCount("Precache.Fetch.ResponseBytes.Total", 2); | 1963 histogram.ExpectTotalCount("Precache.Fetch.ResponseBytes.Total", 2); |
1943 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 2); | 1964 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 2); |
1944 } | 1965 } |
1945 | 1966 |
1946 } // namespace precache | 1967 } // namespace precache |
OLD | NEW |