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

Side by Side Diff: components/precache/content/precache_manager_unittest.cc

Issue 2762673002: predictors: Pass manifests from Bork to store in ResourcePrefetchPredictor. (Closed)
Patch Set: Add delegate tests for PrecacheFetcher. Created 3 years, 9 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 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/content/precache_manager.h" 5 #include "components/precache/content/precache_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 100 }
101 101
102 MOCK_CONST_METHOD2(TopHosts, 102 MOCK_CONST_METHOD2(TopHosts,
103 void(size_t num_hosts, const TopHostsCallback& callback)); 103 void(size_t num_hosts, const TopHostsCallback& callback));
104 104
105 MOCK_CONST_METHOD2(HostRankIfAvailable, 105 MOCK_CONST_METHOD2(HostRankIfAvailable,
106 void(const GURL& url, 106 void(const GURL& url,
107 const base::Callback<void(int)>& callback)); 107 const base::Callback<void(int)>& callback));
108 }; 108 };
109 109
110 class MockPrecacheManagerDelegate : public PrecacheManager::Delegate {
111 public:
112 MOCK_METHOD2(OnManifestFetched,
113 void(const std::string& host, const PrecacheManifest& manifest));
114 };
115
110 ACTION_P(ReturnHosts, starting_hosts) { 116 ACTION_P(ReturnHosts, starting_hosts) {
111 arg1.Run(starting_hosts); 117 arg1.Run(starting_hosts);
112 } 118 }
113 119
114 class TestPrecacheCompletionCallback { 120 class TestPrecacheCompletionCallback {
115 public: 121 public:
116 TestPrecacheCompletionCallback() : was_on_done_called_(false) {} 122 TestPrecacheCompletionCallback() : was_on_done_called_(false) {}
117 123
118 void OnDone(bool precaching_started) { was_on_done_called_ = true; } 124 void OnDone(bool precaching_started) { was_on_done_called_ = true; }
119 125
(...skipping 11 matching lines...) Expand all
131 }; 137 };
132 138
133 class PrecacheManagerUnderTest : public PrecacheManager { 139 class PrecacheManagerUnderTest : public PrecacheManager {
134 public: 140 public:
135 PrecacheManagerUnderTest( 141 PrecacheManagerUnderTest(
136 content::BrowserContext* browser_context, 142 content::BrowserContext* browser_context,
137 const syncer::SyncService* sync_service, 143 const syncer::SyncService* sync_service,
138 const history::HistoryService* history_service, 144 const history::HistoryService* history_service,
139 const data_reduction_proxy::DataReductionProxySettings* 145 const data_reduction_proxy::DataReductionProxySettings*
140 data_reduction_proxy_settings, 146 data_reduction_proxy_settings,
147 Delegate* delegate_,
141 const base::FilePath& db_path, 148 const base::FilePath& db_path,
142 std::unique_ptr<PrecacheDatabase> precache_database) 149 std::unique_ptr<PrecacheDatabase> precache_database)
143 : PrecacheManager(browser_context, 150 : PrecacheManager(browser_context,
144 sync_service, 151 sync_service,
145 history_service, 152 history_service,
146 data_reduction_proxy_settings, 153 data_reduction_proxy_settings,
154 delegate_,
147 db_path, 155 db_path,
148 std::move(precache_database)), 156 std::move(precache_database)),
149 control_group_(false) {} 157 control_group_(false) {}
150 bool IsInExperimentGroup() const override { return !control_group_; } 158 bool IsInExperimentGroup() const override { return !control_group_; }
151 bool IsInControlGroup() const override { return control_group_; } 159 bool IsInControlGroup() const override { return control_group_; }
152 bool IsPrecachingAllowed() const override { return true; } 160 bool IsPrecachingAllowed() const override { return true; }
153 void SetInControlGroup(bool in_control_group) { 161 void SetInControlGroup(bool in_control_group) {
154 control_group_ = in_control_group; 162 control_group_ = in_control_group;
155 } 163 }
156 164
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 net::URLRequestStatus::FAILED); 203 net::URLRequestStatus::FAILED);
196 info_.headers = new net::HttpResponseHeaders(""); 204 info_.headers = new net::HttpResponseHeaders("");
197 } 205 }
198 206
199 // precache_manager_ assumes ownership of precache_database. 207 // precache_manager_ assumes ownership of precache_database.
200 void Reset(PrecacheDatabase* precache_database) { 208 void Reset(PrecacheDatabase* precache_database) {
201 base::FilePath db_path = scoped_temp_dir_.GetPath().Append( 209 base::FilePath db_path = scoped_temp_dir_.GetPath().Append(
202 base::FilePath(FILE_PATH_LITERAL("precache_database"))); 210 base::FilePath(FILE_PATH_LITERAL("precache_database")));
203 precache_manager_.reset(new PrecacheManagerUnderTest( 211 precache_manager_.reset(new PrecacheManagerUnderTest(
204 &browser_context_, nullptr /* sync_service */, &history_service_, 212 &browser_context_, nullptr /* sync_service */, &history_service_,
205 nullptr /* data_reduction_proxy_settings */, db_path, 213 nullptr /* data_reduction_proxy_settings */,
214 &precache_manager_delegate_, db_path,
206 base::WrapUnique(precache_database))); 215 base::WrapUnique(precache_database)));
207 } 216 }
208 217
209 void Flush() { precache_database_->Flush(); } 218 void Flush() { precache_database_->Flush(); }
210 219
211 void RecordStatsForFetch(const GURL& url, 220 void RecordStatsForFetch(const GURL& url,
212 const std::string& referrer_host, 221 const std::string& referrer_host,
213 const base::Time& fetch_time, 222 const base::Time& fetch_time,
214 const net::HttpResponseInfo& info, 223 const net::HttpResponseInfo& info,
215 int64_t size, 224 int64_t size,
(...skipping 23 matching lines...) Expand all
239 // Must be declared first so that it is destroyed last. 248 // Must be declared first so that it is destroyed last.
240 content::TestBrowserThreadBundle test_browser_thread_bundle_; 249 content::TestBrowserThreadBundle test_browser_thread_bundle_;
241 base::ScopedTempDir scoped_temp_dir_; 250 base::ScopedTempDir scoped_temp_dir_;
242 PrecacheDatabase* precache_database_; 251 PrecacheDatabase* precache_database_;
243 content::TestBrowserContext browser_context_; 252 content::TestBrowserContext browser_context_;
244 std::unique_ptr<PrecacheManagerUnderTest> precache_manager_; 253 std::unique_ptr<PrecacheManagerUnderTest> precache_manager_;
245 TestURLFetcherCallback url_callback_; 254 TestURLFetcherCallback url_callback_;
246 net::FakeURLFetcherFactory factory_; 255 net::FakeURLFetcherFactory factory_;
247 TestPrecacheCompletionCallback precache_callback_; 256 TestPrecacheCompletionCallback precache_callback_;
248 testing::NiceMock<MockHistoryService> history_service_; 257 testing::NiceMock<MockHistoryService> history_service_;
258 testing::NiceMock<MockPrecacheManagerDelegate> precache_manager_delegate_;
249 base::HistogramTester histograms_; 259 base::HistogramTester histograms_;
250 net::HttpResponseInfo info_; 260 net::HttpResponseInfo info_;
251 variations::testing::VariationParamsManager variation_params_; 261 variations::testing::VariationParamsManager variation_params_;
252 }; 262 };
253 263
254 TEST_F(PrecacheManagerTest, StartAndFinishPrecaching) { 264 TEST_F(PrecacheManagerTest, StartAndFinishPrecaching) {
255 EXPECT_FALSE(precache_manager_->IsPrecaching()); 265 EXPECT_FALSE(precache_manager_->IsPrecaching());
256 266
257 MockHistoryService::TopHostsCallback top_hosts_callback; 267 MockHistoryService::TopHostsCallback top_hosts_callback;
258 EXPECT_CALL(history_service_, TopHosts(NumTopHosts(), _)) 268 EXPECT_CALL(history_service_, TopHosts(NumTopHosts(), _))
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 expected_histogram_count_map["Precache.Saved"] += 2; 683 expected_histogram_count_map["Precache.Saved"] += 2;
674 expected_histogram_count_map["Precache.TimeSinceLastPrecache"] += 2; 684 expected_histogram_count_map["Precache.TimeSinceLastPrecache"] += 2;
675 expected_histogram_count_map["Precache.Saved.Freshness"] = 2; 685 expected_histogram_count_map["Precache.Saved.Freshness"] = 2;
676 686
677 base::RunLoop().RunUntilIdle(); 687 base::RunLoop().RunUntilIdle();
678 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), 688 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."),
679 ContainerEq(expected_histogram_count_map)); 689 ContainerEq(expected_histogram_count_map));
680 } 690 }
681 691
682 } // namespace precache 692 } // namespace precache
OLDNEW
« no previous file with comments | « components/precache/content/precache_manager.cc ('k') | components/precache/core/precache_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698