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 1052 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); | 1063 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); |
1064 | 1064 |
1065 EXPECT_TRUE(precache_delegate_.was_on_done_called()); | 1065 EXPECT_TRUE(precache_delegate_.was_on_done_called()); |
1066 | 1066 |
1067 histogram.ExpectUniqueSample("Precache.Fetch.PercentCompleted", 100, 1); | 1067 histogram.ExpectUniqueSample("Precache.Fetch.PercentCompleted", 100, 1); |
1068 histogram.ExpectUniqueSample("Precache.Fetch.ResponseBytes.Total", | 1068 histogram.ExpectUniqueSample("Precache.Fetch.ResponseBytes.Total", |
1069 url_callback_.total_response_bytes(), 1); | 1069 url_callback_.total_response_bytes(), 1); |
1070 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 1); | 1070 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 1); |
1071 } | 1071 } |
1072 | 1072 |
| 1073 TEST_F(PrecacheFetcherTest, TopResourcesCount_ResourceBitset) { |
| 1074 SetDefaultFlags(); |
| 1075 |
| 1076 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work( |
| 1077 new PrecacheUnfinishedWork()); |
| 1078 unfinished_work->set_start_time(base::Time::UnixEpoch().ToInternalValue()); |
| 1079 unfinished_work->add_top_host()->set_hostname("good-manifest.com"); |
| 1080 |
| 1081 PrecacheConfigurationSettings config; |
| 1082 config.set_top_resources_count(2); |
| 1083 |
| 1084 PrecacheManifest good_manifest; |
| 1085 good_manifest.add_resource()->set_url("http://good-manifest.com/retrieved"); |
| 1086 good_manifest.add_resource()->set_url("http://good-manifest.com/skipped"); |
| 1087 good_manifest.add_resource()->set_url("http://good-manifest.com/retrieved"); |
| 1088 good_manifest.add_resource()->set_url("http://good-manifest.com/skipped"); |
| 1089 good_manifest.add_resource()->set_url("http://good-manifest.com/retrieved"); |
| 1090 (*good_manifest.mutable_experiments() |
| 1091 ->mutable_resources_by_experiment_group())[kExperimentID] |
| 1092 .set_bitset(0b10101); |
| 1093 |
| 1094 factory_.SetFakeResponse(GURL(kConfigURL), config.SerializeAsString(), |
| 1095 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 1096 factory_.SetFakeResponse(GURL(kGoodManifestURL), |
| 1097 good_manifest.SerializeAsString(), net::HTTP_OK, |
| 1098 net::URLRequestStatus::SUCCESS); |
| 1099 factory_.SetFakeResponse(GURL("http://good-manifest.com/retrieved"), "good", |
| 1100 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 1101 |
| 1102 base::HistogramTester histogram; |
| 1103 |
| 1104 { |
| 1105 PrecacheFetcher precache_fetcher( |
| 1106 request_context_.get(), GURL(), std::string(), |
| 1107 std::move(unfinished_work), kExperimentID, |
| 1108 precache_database_.GetWeakPtr(), task_runner(), &precache_delegate_); |
| 1109 precache_fetcher.Start(); |
| 1110 |
| 1111 base::RunLoop().RunUntilIdle(); |
| 1112 |
| 1113 // Destroy the PrecacheFetcher after it has finished, to record metrics. |
| 1114 } |
| 1115 |
| 1116 std::vector<GURL> expected_requested_urls; |
| 1117 expected_requested_urls.emplace_back(kConfigURL); |
| 1118 expected_requested_urls.emplace_back(kGoodManifestURL); |
| 1119 expected_requested_urls.emplace_back("http://good-manifest.com/retrieved"); |
| 1120 expected_requested_urls.emplace_back("http://good-manifest.com/retrieved"); |
| 1121 |
| 1122 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); |
| 1123 |
| 1124 EXPECT_TRUE(precache_delegate_.was_on_done_called()); |
| 1125 |
| 1126 histogram.ExpectUniqueSample("Precache.Fetch.PercentCompleted", 100, 1); |
| 1127 histogram.ExpectUniqueSample("Precache.Fetch.ResponseBytes.Total", |
| 1128 url_callback_.total_response_bytes(), 1); |
| 1129 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 1); |
| 1130 } |
| 1131 |
1073 // MaxBytesPerResource is impossible to test with net::FakeURLFetcherFactory: | 1132 // MaxBytesPerResource is impossible to test with net::FakeURLFetcherFactory: |
1074 // | 1133 // |
1075 // - The PrecacheFetcher::Fetcher's max_bytes logic only applies to network | 1134 // - The PrecacheFetcher::Fetcher's max_bytes logic only applies to network |
1076 // requests, and not cached requests. | 1135 // requests, and not cached requests. |
1077 // - Forcing PrecacheFetcher::Fetcher to do a network request (i.e. a second | 1136 // - Forcing PrecacheFetcher::Fetcher to do a network request (i.e. a second |
1078 // request for the same URL) requires either setting a custom error of | 1137 // request for the same URL) requires either setting a custom error of |
1079 // ERR_CACHE_MISS or setting a custom ETag response header, neither of which | 1138 // ERR_CACHE_MISS or setting a custom ETag response header, neither of which |
1080 // is possible under FakeURLFetcherFactory. | 1139 // is possible under FakeURLFetcherFactory. |
1081 // | 1140 // |
1082 // PrecacheFetcherFetcherTest.ResourceTooBig tests the bulk of the code. We'll | 1141 // PrecacheFetcherFetcherTest.ResourceTooBig tests the bulk of the code. We'll |
(...skipping 854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1937 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); | 1996 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); |
1938 | 1997 |
1939 EXPECT_TRUE(precache_delegate_.was_on_done_called()); | 1998 EXPECT_TRUE(precache_delegate_.was_on_done_called()); |
1940 | 1999 |
1941 histogram.ExpectTotalCount("Precache.Fetch.PercentCompleted", 2); | 2000 histogram.ExpectTotalCount("Precache.Fetch.PercentCompleted", 2); |
1942 histogram.ExpectTotalCount("Precache.Fetch.ResponseBytes.Total", 2); | 2001 histogram.ExpectTotalCount("Precache.Fetch.ResponseBytes.Total", 2); |
1943 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 2); | 2002 histogram.ExpectTotalCount("Precache.Fetch.TimeToComplete", 2); |
1944 } | 2003 } |
1945 | 2004 |
1946 } // namespace precache | 2005 } // namespace precache |
OLD | NEW |