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

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

Issue 2229983002: Send the list of used and unused resources for precache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 net::HttpResponseInfo info_; 209 net::HttpResponseInfo info_;
210 }; 210 };
211 211
212 TEST_F(PrecacheManagerTest, StartAndFinishPrecaching) { 212 TEST_F(PrecacheManagerTest, StartAndFinishPrecaching) {
213 EXPECT_FALSE(precache_manager_->IsPrecaching()); 213 EXPECT_FALSE(precache_manager_->IsPrecaching());
214 214
215 MockHistoryService::TopHostsCallback top_hosts_callback; 215 MockHistoryService::TopHostsCallback top_hosts_callback;
216 EXPECT_CALL(history_service_, TopHosts(NumTopHosts(), _)) 216 EXPECT_CALL(history_service_, TopHosts(NumTopHosts(), _))
217 .WillOnce(SaveArg<1>(&top_hosts_callback)); 217 .WillOnce(SaveArg<1>(&top_hosts_callback));
218 218
219 factory_.SetFakeResponse(GURL(kConfigURL), "", net::HTTP_OK,
220 net::URLRequestStatus::SUCCESS);
219 factory_.SetFakeResponse(GURL(kGoodManifestURL), "", net::HTTP_OK, 221 factory_.SetFakeResponse(GURL(kGoodManifestURL), "", net::HTTP_OK,
220 net::URLRequestStatus::SUCCESS); 222 net::URLRequestStatus::SUCCESS);
221 223
222 precache_manager_->StartPrecaching(precache_callback_.GetCallback()); 224 precache_manager_->StartPrecaching(precache_callback_.GetCallback());
223 base::RunLoop().RunUntilIdle(); 225 base::RunLoop().RunUntilIdle();
224 EXPECT_TRUE(precache_manager_->IsPrecaching()); 226 EXPECT_TRUE(precache_manager_->IsPrecaching());
225 227
226 top_hosts_callback.Run( 228 top_hosts_callback.Run(
227 history::TopHostsList(1, std::make_pair("good-manifest.com", 1))); 229 history::TopHostsList(1, std::make_pair("good-manifest.com", 1)));
228 base::RunLoop().RunUntilIdle(); // For PrecacheFetcher. 230 base::RunLoop().RunUntilIdle(); // For PrecacheFetcher.
229 EXPECT_FALSE(precache_manager_->IsPrecaching()); 231 EXPECT_FALSE(precache_manager_->IsPrecaching());
230 EXPECT_TRUE(precache_callback_.was_on_done_called()); 232 EXPECT_TRUE(precache_callback_.was_on_done_called());
231 233
232 std::multiset<GURL> expected_requested_urls; 234 std::multiset<GURL> expected_requested_urls;
233 expected_requested_urls.insert(GURL(kConfigURL)); 235 expected_requested_urls.insert(GURL(kConfigURL));
234 expected_requested_urls.insert(GURL(kGoodManifestURL)); 236 expected_requested_urls.insert(GURL(kGoodManifestURL));
235 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); 237 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls());
236 } 238 }
237 239
238 TEST_F(PrecacheManagerTest, StartAndFinishPrecachingWithUnfinishedHosts) { 240 TEST_F(PrecacheManagerTest, StartAndFinishPrecachingWithUnfinishedHosts) {
239 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work( 241 std::unique_ptr<PrecacheUnfinishedWork> unfinished_work(
240 new PrecacheUnfinishedWork()); 242 new PrecacheUnfinishedWork());
241 unfinished_work->add_top_host()->set_hostname("evil-manifest.com"); 243 unfinished_work->add_top_host()->set_hostname("evil-manifest.com");
242 unfinished_work->set_start_time(base::Time::Now().ToInternalValue()); 244 unfinished_work->set_start_time(base::Time::Now().ToInternalValue());
243 precache_database_->SaveUnfinishedWork(std::move(unfinished_work)); 245 precache_database_->SaveUnfinishedWork(std::move(unfinished_work));
244 246
245 EXPECT_FALSE(precache_manager_->IsPrecaching()); 247 EXPECT_FALSE(precache_manager_->IsPrecaching());
246 248
249 factory_.SetFakeResponse(GURL(kConfigURL), "", net::HTTP_OK,
250 net::URLRequestStatus::SUCCESS);
247 factory_.SetFakeResponse( 251 factory_.SetFakeResponse(
248 GURL(kEvilManifestURL), "", 252 GURL(kEvilManifestURL), "",
249 net::HTTP_OK, net::URLRequestStatus::SUCCESS); 253 net::HTTP_OK, net::URLRequestStatus::SUCCESS);
250 254
251 ASSERT_TRUE(precache_database_->GetLastPrecacheTimestamp().is_null()); 255 ASSERT_TRUE(precache_database_->GetLastPrecacheTimestamp().is_null());
252 256
253 precache_manager_->StartPrecaching(precache_callback_.GetCallback()); 257 precache_manager_->StartPrecaching(precache_callback_.GetCallback());
254 EXPECT_TRUE(precache_manager_->IsPrecaching()); 258 EXPECT_TRUE(precache_manager_->IsPrecaching());
255 259
256 base::RunLoop().RunUntilIdle(); // For PrecacheFetcher. 260 base::RunLoop().RunUntilIdle(); // For PrecacheFetcher.
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 precache_manager_->CancelPrecaching(); 400 precache_manager_->CancelPrecaching();
397 401
398 // For PrecacheFetcher and RecordURLPrecached. 402 // For PrecacheFetcher and RecordURLPrecached.
399 base::RunLoop().RunUntilIdle(); 403 base::RunLoop().RunUntilIdle();
400 EXPECT_THAT( 404 EXPECT_THAT(
401 histograms_.GetTotalCountsForPrefix("Precache."), 405 histograms_.GetTotalCountsForPrefix("Precache."),
402 UnorderedElementsAre(Pair("Precache.DownloadedPrecacheMotivated", 1), 406 UnorderedElementsAre(Pair("Precache.DownloadedPrecacheMotivated", 1),
403 Pair("Precache.Fetch.PercentCompleted", 1), 407 Pair("Precache.Fetch.PercentCompleted", 1),
404 Pair("Precache.Fetch.ResponseBytes.Network", 1), 408 Pair("Precache.Fetch.ResponseBytes.Network", 1),
405 Pair("Precache.Fetch.ResponseBytes.Total", 1), 409 Pair("Precache.Fetch.ResponseBytes.Total", 1),
406 Pair("Precache.Fetch.TimeToComplete", 1), 410 Pair("Precache.Fetch.TimeToComplete",
407 Pair("Precache.Latency.Prefetch", 1), 411 1))); // Pair("Precache.Latency.Prefetch", 1),
bengr 2016/08/11 18:49:14 Please remove the dead code. Why are these no lon
Raj 2016/08/12 19:04:20 Fixed test.
408 Pair("Precache.Freshness.Prefetch", 1))); 412 // Pair("Precache.Freshness.Prefetch", 1)));
409 } 413 }
410 414
411 TEST_F(PrecacheManagerTest, RecordStatsForFetchHTTP) { 415 TEST_F(PrecacheManagerTest, RecordStatsForFetchHTTP) {
412 precache_manager_->RecordStatsForFetch(GURL("http://http-url.com"), GURL(), 416 precache_manager_->RecordStatsForFetch(GURL("http://http-url.com"), GURL(),
413 base::TimeDelta(), base::Time(), info_, 417 base::TimeDelta(), base::Time(), info_,
414 1000); 418 1000);
415 base::RunLoop().RunUntilIdle(); 419 base::RunLoop().RunUntilIdle();
416 420
417 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), 421 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."),
418 UnorderedElementsAre( 422 UnorderedElementsAre(
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 GURL("http://recent-fetch.com"), GURL(), base::TimeDelta(), 481 GURL("http://recent-fetch.com"), GURL(), base::TimeDelta(),
478 kCurrentTime - base::TimeDelta::FromDays(59), info_, 1000); 482 kCurrentTime - base::TimeDelta::FromDays(59), info_, 1000);
479 precache_manager_->RecordStatsForFetch( 483 precache_manager_->RecordStatsForFetch(
480 GURL("http://yesterday-fetch.com"), GURL(), base::TimeDelta(), 484 GURL("http://yesterday-fetch.com"), GURL(), base::TimeDelta(),
481 kCurrentTime - base::TimeDelta::FromDays(1), info_, 1000); 485 kCurrentTime - base::TimeDelta::FromDays(1), info_, 1000);
482 expected_histogram_count_map["Precache.DownloadedPrecacheMotivated"] += 3; 486 expected_histogram_count_map["Precache.DownloadedPrecacheMotivated"] += 3;
483 expected_histogram_count_map["Precache.Fetch.PercentCompleted"]++; 487 expected_histogram_count_map["Precache.Fetch.PercentCompleted"]++;
484 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Network"]++; 488 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Network"]++;
485 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Total"]++; 489 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Total"]++;
486 expected_histogram_count_map["Precache.Fetch.TimeToComplete"]++; 490 expected_histogram_count_map["Precache.Fetch.TimeToComplete"]++;
487 expected_histogram_count_map["Precache.Latency.Prefetch"] += 3; 491 // expected_histogram_count_map["Precache.Latency.Prefetch"] += 3;
bengr 2016/08/11 18:49:14 Please remove the dead code. Why are these no lon
Raj 2016/08/12 19:04:20 Fixed test.
488 expected_histogram_count_map["Precache.Freshness.Prefetch"] += 3; 492 // expected_histogram_count_map["Precache.Freshness.Prefetch"] += 3;
489 base::RunLoop().RunUntilIdle(); 493 base::RunLoop().RunUntilIdle();
490 494
491 precache_manager_->CancelPrecaching(); 495 precache_manager_->CancelPrecaching();
492 base::RunLoop().RunUntilIdle(); 496 base::RunLoop().RunUntilIdle();
493 497
494 // Disable pause-resume. 498 // Disable pause-resume.
495 precache_database_->DeleteUnfinishedWork(); 499 precache_database_->DeleteUnfinishedWork();
496 base::RunLoop().RunUntilIdle(); 500 base::RunLoop().RunUntilIdle();
497 501
498 // For PrecacheFetcher and RecordURLPrecached. 502 // For PrecacheFetcher and RecordURLPrecached.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 expected_histogram_count_map["Precache.Saved"] += 2; 550 expected_histogram_count_map["Precache.Saved"] += 2;
547 expected_histogram_count_map["Precache.TimeSinceLastPrecache"] += 2; 551 expected_histogram_count_map["Precache.TimeSinceLastPrecache"] += 2;
548 expected_histogram_count_map["Precache.Saved.Freshness"] = 2; 552 expected_histogram_count_map["Precache.Saved.Freshness"] = 2;
549 553
550 base::RunLoop().RunUntilIdle(); 554 base::RunLoop().RunUntilIdle();
551 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), 555 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."),
552 ContainerEq(expected_histogram_count_map)); 556 ContainerEq(expected_histogram_count_map));
553 } 557 }
554 558
555 } // namespace precache 559 } // namespace precache
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698