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

Side by Side Diff: components/precache/core/precache_fetcher_unittest.cc

Issue 1859023002: Fix PrecacheFetcher behavior when reaching max_bytes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Extract AppendManifestURLIfNew(). Created 4 years, 8 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
« no previous file with comments | « components/precache/core/precache_fetcher.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <set> 10 #include <set>
(...skipping 20 matching lines...) Expand all
31 #include "net/url_request/url_request_test_util.h" 31 #include "net/url_request/url_request_test_util.h"
32 #include "testing/gmock/include/gmock/gmock.h" 32 #include "testing/gmock/include/gmock/gmock.h"
33 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
34 #include "url/gurl.h" 34 #include "url/gurl.h"
35 35
36 namespace precache { 36 namespace precache {
37 37
38 namespace { 38 namespace {
39 39
40 using ::testing::_; 40 using ::testing::_;
41 using ::testing::ElementsAre;
41 using ::testing::NotNull; 42 using ::testing::NotNull;
42 using ::testing::Property; 43 using ::testing::Property;
43 44
44 const char kConfigURL[] = "http://config-url.com"; 45 const char kConfigURL[] = "http://config-url.com";
45 const char kManifestURLPrefix[] = "http://manifest-url-prefix.com/"; 46 const char kManifestURLPrefix[] = "http://manifest-url-prefix.com/";
46 const char kCustomConfigURL[] = "http://custom-config-url.com"; 47 const char kCustomConfigURL[] = "http://custom-config-url.com";
47 const char kCustomManifestURLPrefix[] = 48 const char kCustomManifestURLPrefix[] =
48 "http://custom-manifest-url-prefix.com/"; 49 "http://custom-manifest-url-prefix.com/";
49 const char kManifestFetchFailureURL[] = 50 const char kManifestFetchFailureURL[] =
50 "http://manifest-url-prefix.com/manifest-fetch-failure.com"; 51 "http://manifest-url-prefix.com/manifest-fetch-failure.com";
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 loop_.RunUntilIdle(); 523 loop_.RunUntilIdle();
523 524
524 std::multiset<GURL> expected_requested_urls; 525 std::multiset<GURL> expected_requested_urls;
525 expected_requested_urls.insert(GURL(kConfigURL)); 526 expected_requested_urls.insert(GURL(kConfigURL));
526 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); 527 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls());
527 528
528 EXPECT_FALSE(precache_delegate_.was_on_done_called()); 529 EXPECT_FALSE(precache_delegate_.was_on_done_called());
529 530
530 histogram.ExpectUniqueSample("Precache.Fetch.PercentCompleted", 0, 1); 531 histogram.ExpectUniqueSample("Precache.Fetch.PercentCompleted", 0, 1);
531 histogram.ExpectUniqueSample("Precache.Fetch.ResponseBytes.Total", 0, 1); 532 histogram.ExpectUniqueSample("Precache.Fetch.ResponseBytes.Total", 0, 1);
532 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 0); 533 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 1);
533 } 534 }
534 535
535 #if defined(PRECACHE_CONFIG_SETTINGS_URL) 536 #if defined(PRECACHE_CONFIG_SETTINGS_URL)
536 537
537 // If the default precache configuration settings URL is defined, then test that 538 // If the default precache configuration settings URL is defined, then test that
538 // it works with the PrecacheFetcher. 539 // it works with the PrecacheFetcher.
539 TEST_F(PrecacheFetcherTest, PrecacheUsingDefaultConfigSettingsURL) { 540 TEST_F(PrecacheFetcherTest, PrecacheUsingDefaultConfigSettingsURL) {
540 std::vector<std::string> starting_hosts(1, "starting-url.com"); 541 std::vector<std::string> starting_hosts(1, "starting-url.com");
541 542
542 PrecacheConfigurationSettings config; 543 PrecacheConfigurationSettings config;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 // MockURLFetcherFactory or EmbeddedTestServer, and add a test that fetches are 669 // MockURLFetcherFactory or EmbeddedTestServer, and add a test that fetches are
669 // cancelled midstream. 670 // cancelled midstream.
670 671
671 TEST_F(PrecacheFetcherTest, MaxBytesTotal) { 672 TEST_F(PrecacheFetcherTest, MaxBytesTotal) {
672 SetDefaultFlags(); 673 SetDefaultFlags();
673 const size_t kNumResources = 15; // > kMaxParallelFetches. 674 const size_t kNumResources = 15; // > kMaxParallelFetches.
674 const size_t kMaxBytesTotal = 1000; 675 const size_t kMaxBytesTotal = 1000;
675 const size_t kBytesPerResource = kMaxBytesTotal / 3; 676 const size_t kBytesPerResource = kMaxBytesTotal / 3;
676 // kBytesPerResource * kMaxParallelFeches > kMaxBytesTotal. 677 // kBytesPerResource * kMaxParallelFeches > kMaxBytesTotal.
677 678
678 std::vector<std::string> starting_hosts;
679 starting_hosts.push_back("good-manifest.com");
680
681 PrecacheConfigurationSettings config; 679 PrecacheConfigurationSettings config;
682 config.set_max_bytes_total(kMaxBytesTotal); 680 config.set_max_bytes_total(kMaxBytesTotal);
683 681
684 factory_.SetFakeResponse(GURL(kConfigURL), config.SerializeAsString(), 682 factory_.SetFakeResponse(GURL(kConfigURL), config.SerializeAsString(),
685 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 683 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
686 684
687 PrecacheManifest good_manifest; 685 PrecacheManifest good_manifest;
688 for (size_t i = 0; i < kNumResources; ++i) { 686 for (size_t i = 0; i < kNumResources; ++i) {
689 const std::string url = "http://good-manifest.com/" + std::to_string(i); 687 const std::string url = "http://good-manifest.com/" + std::to_string(i);
690 good_manifest.add_resource()->set_url(url); 688 good_manifest.add_resource()->set_url(url);
691 factory_.SetFakeResponse(GURL(url), std::string(kBytesPerResource, '.'), 689 factory_.SetFakeResponse(GURL(url), std::string(kBytesPerResource, '.'),
692 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 690 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
693 } 691 }
694 692
695 factory_.SetFakeResponse(GURL(kGoodManifestURL), 693 factory_.SetFakeResponse(GURL(kGoodManifestURL),
696 good_manifest.SerializeAsString(), net::HTTP_OK, 694 good_manifest.SerializeAsString(), net::HTTP_OK,
697 net::URLRequestStatus::SUCCESS); 695 net::URLRequestStatus::SUCCESS);
698 696
699 base::HistogramTester histogram; 697 base::HistogramTester histogram;
700 698
701 { 699 {
702 PrecacheFetcher precache_fetcher(starting_hosts, request_context_.get(), 700 PrecacheFetcher precache_fetcher({"good-manifest.com"},
703 GURL(), std::string(), 701 request_context_.get(), GURL(),
704 &precache_delegate_); 702 std::string(), &precache_delegate_);
705 precache_fetcher.Start(); 703 precache_fetcher.Start();
706 704
707 loop_.RunUntilIdle(); 705 loop_.RunUntilIdle();
708 706
709 // Destroy the PrecacheFetcher after it has finished, to record metrics. 707 // Destroy the PrecacheFetcher after it has finished, to record metrics.
710 } 708 }
711 709
712 // We don't know which will make it and which won't due to the parallelism in 710 // We don't know which will make it and which won't due to the parallelism in
713 // the pool of Fetchers. 711 // the pool of Fetchers.
714 EXPECT_GT(kNumResources, url_callback_.requested_urls().size()); 712 EXPECT_GT(kNumResources, url_callback_.requested_urls().size());
715 713
716 EXPECT_TRUE(precache_delegate_.was_on_done_called()); 714 EXPECT_TRUE(precache_delegate_.was_on_done_called());
717 715
718 histogram.ExpectUniqueSample("Precache.Fetch.PercentCompleted", 100, 1); 716 // good-manifest.com will not have been completed.
717 EXPECT_THAT(histogram.GetAllSamples("Precache.Fetch.PercentCompleted"),
718 ElementsAre(base::Bucket(0, 1)));
719 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 1); 719 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 1);
720 } 720 }
721 721
722 } // namespace 722 } // namespace
723 723
724 } // namespace precache 724 } // namespace precache
OLDNEW
« no previous file with comments | « components/precache/core/precache_fetcher.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698