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

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

Issue 2037903002: Precache manifest should not be added to fetcher pool which is full (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test Created 4 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
« 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 <memory> 10 #include <memory>
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/callback.h" 16 #include "base/callback.h"
17 #include "base/command_line.h" 17 #include "base/command_line.h"
18 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
19 #include "base/memory/ptr_util.h" 19 #include "base/memory/ptr_util.h"
20 #include "base/memory/ref_counted.h" 20 #include "base/memory/ref_counted.h"
21 #include "base/memory/weak_ptr.h" 21 #include "base/memory/weak_ptr.h"
22 #include "base/run_loop.h" 22 #include "base/run_loop.h"
23 #include "base/strings/stringprintf.h"
23 #include "base/test/histogram_tester.h" 24 #include "base/test/histogram_tester.h"
24 #include "base/threading/thread_task_runner_handle.h" 25 #include "base/threading/thread_task_runner_handle.h"
25 #include "components/precache/core/precache_switches.h" 26 #include "components/precache/core/precache_switches.h"
26 #include "components/precache/core/proto/precache.pb.h" 27 #include "components/precache/core/proto/precache.pb.h"
27 #include "components/precache/core/proto/unfinished_work.pb.h" 28 #include "components/precache/core/proto/unfinished_work.pb.h"
28 #include "net/base/load_flags.h" 29 #include "net/base/load_flags.h"
29 #include "net/http/http_response_headers.h" 30 #include "net/http/http_response_headers.h"
30 #include "net/http/http_status_code.h" 31 #include "net/http/http_status_code.h"
31 #include "net/url_request/test_url_fetcher_factory.h" 32 #include "net/url_request/test_url_fetcher_factory.h"
32 #include "net/url_request/url_request_status.h" 33 #include "net/url_request/url_request_status.h"
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 EXPECT_GT(kNumResources, url_callback_.requested_urls().size()); 975 EXPECT_GT(kNumResources, url_callback_.requested_urls().size());
975 976
976 EXPECT_TRUE(precache_delegate_.was_on_done_called()); 977 EXPECT_TRUE(precache_delegate_.was_on_done_called());
977 978
978 // good-manifest.com will not have been completed. 979 // good-manifest.com will not have been completed.
979 EXPECT_THAT(histogram.GetAllSamples("Precache.Fetch.PercentCompleted"), 980 EXPECT_THAT(histogram.GetAllSamples("Precache.Fetch.PercentCompleted"),
980 ElementsAre(base::Bucket(0, 1))); 981 ElementsAre(base::Bucket(0, 1)));
981 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 1); 982 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 1);
982 } 983 }
983 984
985 // Tests the parallel fetch behaviour when more precache resource and manifest
986 // requests are available than the maximum capacity of fetcher pool.
987 TEST_F(PrecacheFetcherTest, ParallelFetches) {
988 SetDefaultFlags();
989
990 const size_t kNumTopHosts = 5;
991 const size_t kNumResources = 15;
bengr 2016/06/07 21:14:40 This test should check the precondition that this
Raj 2016/06/08 03:10:42 Done. This test fails if the DCHECK was not remove
bengr 2016/06/08 23:49:56 That's not what I mean. If someone changes the poo
Raj 2016/06/09 00:32:46 Actually, this test will fail if pool capacity is
992
993 PrecacheConfigurationSettings config;
994 PrecacheManifest top_host_manifest[kNumTopHosts];
995 std::multiset<GURL> expected_requested_urls;
996
997 config.set_top_sites_count(kNumTopHosts);
998 factory_.SetFakeResponse(GURL(kConfigURL), config.SerializeAsString(),
999 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
1000 expected_requested_urls.insert(GURL(kConfigURL));
1001
1002 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work(
1003 new PrecacheUnfinishedWork());
1004 unfinished_work->set_start_time(base::Time::UnixEpoch().ToInternalValue());
1005
1006 for (size_t i = 0; i < kNumTopHosts; ++i) {
1007 const std::string top_host_url = base::StringPrintf("top-host-%d.com", i);
1008 unfinished_work->add_top_host()->set_hostname(top_host_url);
1009
1010 for (size_t j = 0; j < kNumResources; ++j) {
1011 const std::string resource_url =
1012 base::StringPrintf("http://top-host-%d.com/resource-%d", i, j);
1013 top_host_manifest[i].add_resource()->set_url(resource_url);
1014 factory_.SetFakeResponse(GURL(resource_url), "good", net::HTTP_OK,
1015 net::URLRequestStatus::SUCCESS);
1016 expected_requested_urls.insert(GURL(resource_url));
1017 }
1018 factory_.SetFakeResponse(GURL(kManifestURLPrefix + top_host_url),
1019 top_host_manifest[i].SerializeAsString(),
1020 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
1021 expected_requested_urls.insert(GURL(kManifestURLPrefix + top_host_url));
1022 }
1023
1024 base::HistogramTester histogram;
1025
1026 {
1027 PrecacheFetcher precache_fetcher(request_context_.get(), GURL(),
1028 std::string(), std::move(unfinished_work),
1029 kExperimentID, &precache_delegate_);
1030 precache_fetcher.Start();
1031
1032 loop_.RunUntilIdle();
1033
1034 // Destroy the PrecacheFetcher after it has finished, to record metrics.
1035 }
1036
1037 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls());
1038
1039 EXPECT_TRUE(precache_delegate_.was_on_done_called());
1040
1041 histogram.ExpectUniqueSample("Precache.Fetch.PercentCompleted", 100, 1);
1042 histogram.ExpectUniqueSample("Precache.Fetch.ResponseBytes.Total",
1043 url_callback_.total_response_bytes(), 1);
1044 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 1);
1045 }
1046
984 } // namespace 1047 } // namespace
985 1048
986 } // namespace precache 1049 } // 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