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

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

Issue 2146023003: Add UMA Precache.Freshness.Prefetch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added missing includes 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 13 matching lines...) Expand all
24 #include "base/threading/thread_task_runner_handle.h" 24 #include "base/threading/thread_task_runner_handle.h"
25 #include "components/history/core/browser/history_constants.h" 25 #include "components/history/core/browser/history_constants.h"
26 #include "components/history/core/browser/history_service.h" 26 #include "components/history/core/browser/history_service.h"
27 #include "components/history/core/browser/history_types.h" 27 #include "components/history/core/browser/history_types.h"
28 #include "components/precache/core/precache_database.h" 28 #include "components/precache/core/precache_database.h"
29 #include "components/precache/core/precache_switches.h" 29 #include "components/precache/core/precache_switches.h"
30 #include "components/precache/core/proto/unfinished_work.pb.h" 30 #include "components/precache/core/proto/unfinished_work.pb.h"
31 #include "content/public/browser/browser_thread.h" 31 #include "content/public/browser/browser_thread.h"
32 #include "content/public/test/test_browser_context.h" 32 #include "content/public/test/test_browser_context.h"
33 #include "content/public/test/test_browser_thread_bundle.h" 33 #include "content/public/test/test_browser_thread_bundle.h"
34 #include "net/http/http_response_headers.h"
35 #include "net/http/http_response_info.h"
34 #include "net/http/http_status_code.h" 36 #include "net/http/http_status_code.h"
35 #include "net/url_request/test_url_fetcher_factory.h" 37 #include "net/url_request/test_url_fetcher_factory.h"
36 #include "net/url_request/url_request_status.h" 38 #include "net/url_request/url_request_status.h"
37 #include "net/url_request/url_request_test_util.h" 39 #include "net/url_request/url_request_test_util.h"
38 #include "testing/gmock/include/gmock/gmock.h" 40 #include "testing/gmock/include/gmock/gmock.h"
39 #include "testing/gtest/include/gtest/gtest.h" 41 #include "testing/gtest/include/gtest/gtest.h"
40 #include "url/gurl.h" 42 #include "url/gurl.h"
41 43
42 namespace precache { 44 namespace precache {
43 45
44 namespace { 46 namespace {
45 47
46 using ::testing::_; 48 using ::testing::_;
47 using ::testing::ContainerEq; 49 using ::testing::ContainerEq;
48 using ::testing::ElementsAre; 50 using ::testing::ElementsAre;
51 using ::testing::UnorderedElementsAre;
49 using ::testing::Invoke; 52 using ::testing::Invoke;
50 using ::testing::IsEmpty; 53 using ::testing::IsEmpty;
51 using ::testing::Pair; 54 using ::testing::Pair;
52 using ::testing::SaveArg; 55 using ::testing::SaveArg;
53 56
54 const char kConfigURL[] = "http://config-url.com"; 57 const char kConfigURL[] = "http://config-url.com";
55 const char kManifestURLPrefix[] = "http://manifest-url-prefix.com/"; 58 const char kManifestURLPrefix[] = "http://manifest-url-prefix.com/";
56 const char kGoodManifestURL[] = 59 const char kGoodManifestURL[] =
57 "http://manifest-url-prefix.com/good-manifest.com"; 60 "http://manifest-url-prefix.com/good-manifest.com";
58 const char kEvilManifestURL[] = 61 const char kEvilManifestURL[] =
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 // Make the fetch of the precache configuration settings fail. Precaching 185 // Make the fetch of the precache configuration settings fail. Precaching
183 // should still complete normally in this case. 186 // should still complete normally in this case.
184 factory_.SetFakeResponse(GURL(kConfigURL), "", 187 factory_.SetFakeResponse(GURL(kConfigURL), "",
185 net::HTTP_INTERNAL_SERVER_ERROR, 188 net::HTTP_INTERNAL_SERVER_ERROR,
186 net::URLRequestStatus::FAILED); 189 net::URLRequestStatus::FAILED);
187 precache_manager_.reset( 190 precache_manager_.reset(
188 new PrecacheManagerUnderTest( 191 new PrecacheManagerUnderTest(
189 &browser_context_, nullptr /* sync_service */, 192 &browser_context_, nullptr /* sync_service */,
190 &history_service_, db_path, std::move(precache_database))); 193 &history_service_, db_path, std::move(precache_database)));
191 base::RunLoop().RunUntilIdle(); 194 base::RunLoop().RunUntilIdle();
195
196 info_.headers = new net::HttpResponseHeaders("");
192 } 197 }
193 198
194 // Must be declared first so that it is destroyed last. 199 // Must be declared first so that it is destroyed last.
195 content::TestBrowserThreadBundle test_browser_thread_bundle_; 200 content::TestBrowserThreadBundle test_browser_thread_bundle_;
196 base::ScopedTempDir scoped_temp_dir_; 201 base::ScopedTempDir scoped_temp_dir_;
197 PrecacheDatabase* precache_database_; 202 PrecacheDatabase* precache_database_;
198 content::TestBrowserContext browser_context_; 203 content::TestBrowserContext browser_context_;
199 std::unique_ptr<PrecacheManagerUnderTest> precache_manager_; 204 std::unique_ptr<PrecacheManagerUnderTest> precache_manager_;
200 TestURLFetcherCallback url_callback_; 205 TestURLFetcherCallback url_callback_;
201 net::FakeURLFetcherFactory factory_; 206 net::FakeURLFetcherFactory factory_;
202 TestPrecacheCompletionCallback precache_callback_; 207 TestPrecacheCompletionCallback precache_callback_;
203 testing::NiceMock<MockHistoryService> history_service_; 208 testing::NiceMock<MockHistoryService> history_service_;
204 base::HistogramTester histograms_; 209 base::HistogramTester histograms_;
210 net::HttpResponseInfo info_;
205 }; 211 };
206 212
207 TEST_F(PrecacheManagerTest, StartAndFinishPrecaching) { 213 TEST_F(PrecacheManagerTest, StartAndFinishPrecaching) {
208 EXPECT_FALSE(precache_manager_->IsPrecaching()); 214 EXPECT_FALSE(precache_manager_->IsPrecaching());
209 215
210 MockHistoryService::TopHostsCallback top_hosts_callback; 216 MockHistoryService::TopHostsCallback top_hosts_callback;
211 EXPECT_CALL(history_service_, TopHosts(NumTopHosts(), _)) 217 EXPECT_CALL(history_service_, TopHosts(NumTopHosts(), _))
212 .WillOnce(SaveArg<1>(&top_hosts_callback)); 218 .WillOnce(SaveArg<1>(&top_hosts_callback));
213 219
214 factory_.SetFakeResponse(GURL(kGoodManifestURL), "", net::HTTP_OK, 220 factory_.SetFakeResponse(GURL(kGoodManifestURL), "", net::HTTP_OK,
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 std::multiset<GURL> expected_requested_urls; 353 std::multiset<GURL> expected_requested_urls;
348 expected_requested_urls.insert(GURL(kConfigURL)); 354 expected_requested_urls.insert(GURL(kConfigURL));
349 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls()); 355 EXPECT_EQ(expected_requested_urls, url_callback_.requested_urls());
350 } 356 }
351 357
352 // TODO(rajendrant): Add unittests for 358 // TODO(rajendrant): Add unittests for
353 // PrecacheUtil::UpdatePrecacheMetricsAndState() for more test coverage. 359 // PrecacheUtil::UpdatePrecacheMetricsAndState() for more test coverage.
354 TEST_F(PrecacheManagerTest, RecordStatsForFetchWithSizeZero) { 360 TEST_F(PrecacheManagerTest, RecordStatsForFetchWithSizeZero) {
355 // Fetches with size 0 should be ignored. 361 // Fetches with size 0 should be ignored.
356 precache_manager_->RecordStatsForFetch(GURL("http://url.com"), GURL(), 362 precache_manager_->RecordStatsForFetch(GURL("http://url.com"), GURL(),
357 base::TimeDelta(), base::Time(), 0, 363 base::TimeDelta(), base::Time(), info_,
358 false); 364 0);
359 base::RunLoop().RunUntilIdle(); 365 base::RunLoop().RunUntilIdle();
360 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), IsEmpty()); 366 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), IsEmpty());
361 } 367 }
362 368
363 TEST_F(PrecacheManagerTest, RecordStatsForFetchWithNonHTTP) { 369 TEST_F(PrecacheManagerTest, RecordStatsForFetchWithNonHTTP) {
364 // Fetches for URLs with schemes other than HTTP or HTTPS should be ignored. 370 // Fetches for URLs with schemes other than HTTP or HTTPS should be ignored.
365 precache_manager_->RecordStatsForFetch(GURL("ftp://ftp.com"), GURL(), 371 precache_manager_->RecordStatsForFetch(GURL("ftp://ftp.com"), GURL(),
366 base::TimeDelta(), base::Time(), 1000, 372 base::TimeDelta(), base::Time(), info_,
367 false); 373 1000);
368 base::RunLoop().RunUntilIdle(); 374 base::RunLoop().RunUntilIdle();
369 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), IsEmpty()); 375 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), IsEmpty());
370 } 376 }
371 377
372 TEST_F(PrecacheManagerTest, RecordStatsForFetchWithEmptyURL) { 378 TEST_F(PrecacheManagerTest, RecordStatsForFetchWithEmptyURL) {
373 // Fetches for empty URLs should be ignored. 379 // Fetches for empty URLs should be ignored.
374 precache_manager_->RecordStatsForFetch(GURL(), GURL(), base::TimeDelta(), 380 precache_manager_->RecordStatsForFetch(GURL(), GURL(), base::TimeDelta(),
375 base::Time(), 1000, false); 381 base::Time(), info_, 1000);
376 base::RunLoop().RunUntilIdle(); 382 base::RunLoop().RunUntilIdle();
377 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), IsEmpty()); 383 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), IsEmpty());
378 } 384 }
379 385
380 TEST_F(PrecacheManagerTest, RecordStatsForFetchDuringPrecaching) { 386 TEST_F(PrecacheManagerTest, RecordStatsForFetchDuringPrecaching) {
381 EXPECT_CALL(history_service_, TopHosts(NumTopHosts(), _)) 387 EXPECT_CALL(history_service_, TopHosts(NumTopHosts(), _))
382 .WillOnce(ReturnHosts(history::TopHostsList())); 388 .WillOnce(ReturnHosts(history::TopHostsList()));
383 389
384 precache_manager_->StartPrecaching(precache_callback_.GetCallback()); 390 precache_manager_->StartPrecaching(precache_callback_.GetCallback());
385 391
386 EXPECT_TRUE(precache_manager_->IsPrecaching()); 392 EXPECT_TRUE(precache_manager_->IsPrecaching());
387 precache_manager_->RecordStatsForFetch(GURL("http://url.com"), GURL(), 393 precache_manager_->RecordStatsForFetch(GURL("http://url.com"), GURL(),
388 base::TimeDelta(), base::Time(), 1000, 394 base::TimeDelta(), base::Time(), info_,
389 false); 395 1000);
390 base::RunLoop().RunUntilIdle(); 396 base::RunLoop().RunUntilIdle();
391 precache_manager_->CancelPrecaching(); 397 precache_manager_->CancelPrecaching();
392 398
393 // For PrecacheFetcher and RecordURLPrecached. 399 // For PrecacheFetcher and RecordURLPrecached.
394 base::RunLoop().RunUntilIdle(); 400 base::RunLoop().RunUntilIdle();
395 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), 401 EXPECT_THAT(
396 ElementsAre(Pair("Precache.DownloadedPrecacheMotivated", 1), 402 histograms_.GetTotalCountsForPrefix("Precache."),
397 Pair("Precache.Fetch.PercentCompleted", 1), 403 UnorderedElementsAre(Pair("Precache.DownloadedPrecacheMotivated", 1),
398 Pair("Precache.Fetch.ResponseBytes.Network", 1), 404 Pair("Precache.Fetch.PercentCompleted", 1),
399 Pair("Precache.Fetch.ResponseBytes.Total", 1), 405 Pair("Precache.Fetch.ResponseBytes.Network", 1),
400 Pair("Precache.Fetch.TimeToComplete", 1), 406 Pair("Precache.Fetch.ResponseBytes.Total", 1),
401 Pair("Precache.Latency.Prefetch", 1))); 407 Pair("Precache.Fetch.TimeToComplete", 1),
408 Pair("Precache.Latency.Prefetch", 1),
409 Pair("Precache.Freshness.Prefetch", 1)));
402 } 410 }
403 411
404 TEST_F(PrecacheManagerTest, RecordStatsForFetchHTTP) { 412 TEST_F(PrecacheManagerTest, RecordStatsForFetchHTTP) {
405 precache_manager_->RecordStatsForFetch(GURL("http://http-url.com"), GURL(), 413 precache_manager_->RecordStatsForFetch(GURL("http://http-url.com"), GURL(),
406 base::TimeDelta(), base::Time(), 1000, 414 base::TimeDelta(), base::Time(), info_,
407 false); 415 1000);
408 base::RunLoop().RunUntilIdle(); 416 base::RunLoop().RunUntilIdle();
409 417
410 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), 418 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."),
411 ElementsAre(Pair("Precache.DownloadedNonPrecache", 1), 419 ElementsAre(Pair("Precache.DownloadedNonPrecache", 1),
412 Pair("Precache.Latency.NonPrefetch", 1), 420 Pair("Precache.Latency.NonPrefetch", 1),
413 Pair("Precache.Latency.NonPrefetch.NonTopHosts", 1))); 421 Pair("Precache.Latency.NonPrefetch.NonTopHosts", 1)));
414 } 422 }
415 423
416 TEST_F(PrecacheManagerTest, RecordStatsForFetchHTTPS) { 424 TEST_F(PrecacheManagerTest, RecordStatsForFetchHTTPS) {
417 precache_manager_->RecordStatsForFetch(GURL("https://https-url.com"), GURL(), 425 precache_manager_->RecordStatsForFetch(GURL("https://https-url.com"), GURL(),
418 base::TimeDelta(), base::Time(), 1000, 426 base::TimeDelta(), base::Time(), info_,
419 false); 427 1000);
420 base::RunLoop().RunUntilIdle(); 428 base::RunLoop().RunUntilIdle();
421 429
422 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), 430 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."),
423 ElementsAre(Pair("Precache.DownloadedNonPrecache", 1), 431 ElementsAre(Pair("Precache.DownloadedNonPrecache", 1),
424 Pair("Precache.Latency.NonPrefetch", 1), 432 Pair("Precache.Latency.NonPrefetch", 1),
425 Pair("Precache.Latency.NonPrefetch.NonTopHosts", 1))); 433 Pair("Precache.Latency.NonPrefetch.NonTopHosts", 1)));
426 } 434 }
427 435
428 TEST_F(PrecacheManagerTest, RecordStatsForFetchInTopHosts) { 436 TEST_F(PrecacheManagerTest, RecordStatsForFetchInTopHosts) {
429 EXPECT_CALL(history_service_, 437 EXPECT_CALL(history_service_,
430 HostRankIfAvailable(GURL("http://referrer.com"), _)) 438 HostRankIfAvailable(GURL("http://referrer.com"), _))
431 .WillOnce(Invoke( 439 .WillOnce(Invoke(
432 [](const GURL& url, const base::Callback<void(int)>& callback) { 440 [](const GURL& url, const base::Callback<void(int)>& callback) {
433 callback.Run(0); 441 callback.Run(0);
434 })); 442 }));
435 precache_manager_->RecordStatsForFetch( 443 precache_manager_->RecordStatsForFetch(
436 GURL("http://http-url.com"), GURL("http://referrer.com"), 444 GURL("http://http-url.com"), GURL("http://referrer.com"),
437 base::TimeDelta(), base::Time(), 1000, false); 445 base::TimeDelta(), base::Time(), info_, 1000);
438 base::RunLoop().RunUntilIdle(); 446 base::RunLoop().RunUntilIdle();
439 447
440 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), 448 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."),
441 ElementsAre(Pair("Precache.DownloadedNonPrecache", 1), 449 ElementsAre(Pair("Precache.DownloadedNonPrecache", 1),
442 Pair("Precache.Latency.NonPrefetch", 1), 450 Pair("Precache.Latency.NonPrefetch", 1),
443 Pair("Precache.Latency.NonPrefetch.TopHosts", 1))); 451 Pair("Precache.Latency.NonPrefetch.TopHosts", 1)));
444 } 452 }
445 453
446 TEST_F(PrecacheManagerTest, DeleteExpiredPrecacheHistory) { 454 TEST_F(PrecacheManagerTest, DeleteExpiredPrecacheHistory) {
447 // TODO(twifkak): Split this into multiple tests. 455 // TODO(twifkak): Split this into multiple tests.
448 base::HistogramTester::CountsMap expected_histogram_count_map; 456 base::HistogramTester::CountsMap expected_histogram_count_map;
449 457
450 // This test has to use Time::Now() because StartPrecaching uses Time::Now(). 458 // This test has to use Time::Now() because StartPrecaching uses Time::Now().
451 const base::Time kCurrentTime = base::Time::Now(); 459 const base::Time kCurrentTime = base::Time::Now();
452 EXPECT_CALL(history_service_, TopHosts(NumTopHosts(), _)) 460 EXPECT_CALL(history_service_, TopHosts(NumTopHosts(), _))
453 .Times(2) 461 .Times(2)
454 .WillRepeatedly(ReturnHosts(history::TopHostsList())); 462 .WillRepeatedly(ReturnHosts(history::TopHostsList()));
455 463
456 precache_manager_->StartPrecaching(precache_callback_.GetCallback()); 464 precache_manager_->StartPrecaching(precache_callback_.GetCallback());
457 EXPECT_TRUE(precache_manager_->IsPrecaching()); 465 EXPECT_TRUE(precache_manager_->IsPrecaching());
458 466
459 // Precache a bunch of URLs, with different fetch times. 467 // Precache a bunch of URLs, with different fetch times.
460 precache_manager_->RecordStatsForFetch( 468 precache_manager_->RecordStatsForFetch(
461 GURL("http://old-fetch.com"), GURL(), base::TimeDelta(), 469 GURL("http://old-fetch.com"), GURL(), base::TimeDelta(),
462 kCurrentTime - base::TimeDelta::FromDays(61), 1000, false); 470 kCurrentTime - base::TimeDelta::FromDays(61), info_, 1000);
463 precache_manager_->RecordStatsForFetch( 471 precache_manager_->RecordStatsForFetch(
464 GURL("http://recent-fetch.com"), GURL(), base::TimeDelta(), 472 GURL("http://recent-fetch.com"), GURL(), base::TimeDelta(),
465 kCurrentTime - base::TimeDelta::FromDays(59), 1000, false); 473 kCurrentTime - base::TimeDelta::FromDays(59), info_, 1000);
466 precache_manager_->RecordStatsForFetch( 474 precache_manager_->RecordStatsForFetch(
467 GURL("http://yesterday-fetch.com"), GURL(), base::TimeDelta(), 475 GURL("http://yesterday-fetch.com"), GURL(), base::TimeDelta(),
468 kCurrentTime - base::TimeDelta::FromDays(1), 1000, false); 476 kCurrentTime - base::TimeDelta::FromDays(1), info_, 1000);
469 expected_histogram_count_map["Precache.DownloadedPrecacheMotivated"] += 3; 477 expected_histogram_count_map["Precache.DownloadedPrecacheMotivated"] += 3;
470 expected_histogram_count_map["Precache.Fetch.PercentCompleted"]++; 478 expected_histogram_count_map["Precache.Fetch.PercentCompleted"]++;
471 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Network"]++; 479 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Network"]++;
472 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Total"]++; 480 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Total"]++;
473 expected_histogram_count_map["Precache.Fetch.TimeToComplete"]++; 481 expected_histogram_count_map["Precache.Fetch.TimeToComplete"]++;
474 expected_histogram_count_map["Precache.Latency.Prefetch"] += 3; 482 expected_histogram_count_map["Precache.Latency.Prefetch"] += 3;
483 expected_histogram_count_map["Precache.Freshness.Prefetch"] += 3;
475 base::RunLoop().RunUntilIdle(); 484 base::RunLoop().RunUntilIdle();
476 485
477 precache_manager_->CancelPrecaching(); 486 precache_manager_->CancelPrecaching();
478 base::RunLoop().RunUntilIdle(); 487 base::RunLoop().RunUntilIdle();
479 488
480 // Disable pause-resume. 489 // Disable pause-resume.
481 precache_database_->DeleteUnfinishedWork(); 490 precache_database_->DeleteUnfinishedWork();
482 base::RunLoop().RunUntilIdle(); 491 base::RunLoop().RunUntilIdle();
483 492
484 // For PrecacheFetcher and RecordURLPrecached. 493 // For PrecacheFetcher and RecordURLPrecached.
(...skipping 12 matching lines...) Expand all
497 expected_histogram_count_map["Precache.Fetch.PercentCompleted"]++; 506 expected_histogram_count_map["Precache.Fetch.PercentCompleted"]++;
498 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Network"]++; 507 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Network"]++;
499 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Total"]++; 508 expected_histogram_count_map["Precache.Fetch.ResponseBytes.Total"]++;
500 // For PrecacheFetcher and RecordURLPrecached. 509 // For PrecacheFetcher and RecordURLPrecached.
501 base::RunLoop().RunUntilIdle(); 510 base::RunLoop().RunUntilIdle();
502 EXPECT_FALSE(precache_manager_->IsPrecaching()); 511 EXPECT_FALSE(precache_manager_->IsPrecaching());
503 512
504 // A fetch for the same URL as the expired precache was served from the cache, 513 // A fetch for the same URL as the expired precache was served from the cache,
505 // but it isn't reported as saved bytes because it had expired in the precache 514 // but it isn't reported as saved bytes because it had expired in the precache
506 // history. 515 // history.
516 info_.was_cached = true; // From now on all fetches are cached.
507 precache_manager_->RecordStatsForFetch(GURL("http://old-fetch.com"), GURL(), 517 precache_manager_->RecordStatsForFetch(GURL("http://old-fetch.com"), GURL(),
508 base::TimeDelta(), kCurrentTime, 1000, 518 base::TimeDelta(), kCurrentTime, info_,
509 true); 519 1000);
510 expected_histogram_count_map["Precache.Fetch.TimeToComplete"]++; 520 expected_histogram_count_map["Precache.Fetch.TimeToComplete"]++;
511 expected_histogram_count_map["Precache.Latency.NonPrefetch"]++; 521 expected_histogram_count_map["Precache.Latency.NonPrefetch"]++;
512 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"]++; 522 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"]++;
513 expected_histogram_count_map["Precache.TimeSinceLastPrecache"] += 1; 523 expected_histogram_count_map["Precache.TimeSinceLastPrecache"] += 1;
514 524
515 base::RunLoop().RunUntilIdle(); 525 base::RunLoop().RunUntilIdle();
516 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), 526 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."),
517 ContainerEq(expected_histogram_count_map)); 527 ContainerEq(expected_histogram_count_map));
518 528
519 // The other precaches should not have expired, so the following fetches from 529 // The other precaches should not have expired, so the following fetches from
520 // the cache should count as saved bytes. 530 // the cache should count as saved bytes.
521 precache_manager_->RecordStatsForFetch(GURL("http://recent-fetch.com"), GURL() , 531 precache_manager_->RecordStatsForFetch(GURL("http://recent-fetch.com"),
522 base::TimeDelta(), kCurrentTime, 1000, 532 GURL(), base::TimeDelta(),
523 true); 533 kCurrentTime, info_, 1000);
524 precache_manager_->RecordStatsForFetch(GURL("http://yesterday-fetch.com"), 534 precache_manager_->RecordStatsForFetch(GURL("http://yesterday-fetch.com"),
525 GURL(), base::TimeDelta(), kCurrentTime, 535 GURL(), base::TimeDelta(),
526 1000, true); 536 kCurrentTime, info_, 1000);
527 expected_histogram_count_map["Precache.Latency.NonPrefetch"] += 2; 537 expected_histogram_count_map["Precache.Latency.NonPrefetch"] += 2;
528 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"] += 2; 538 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"] += 2;
529 expected_histogram_count_map["Precache.Saved"] += 2; 539 expected_histogram_count_map["Precache.Saved"] += 2;
530 expected_histogram_count_map["Precache.TimeSinceLastPrecache"] += 2; 540 expected_histogram_count_map["Precache.TimeSinceLastPrecache"] += 2;
541 expected_histogram_count_map["Precache.Saved.Freshness"] = 2;
531 542
532 base::RunLoop().RunUntilIdle(); 543 base::RunLoop().RunUntilIdle();
533 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), 544 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."),
534 ContainerEq(expected_histogram_count_map)); 545 ContainerEq(expected_histogram_count_map));
535 } 546 }
536 547
537 } // namespace precache 548 } // namespace precache
OLDNEW
« no previous file with comments | « components/precache/content/precache_manager.cc ('k') | components/precache/core/precache_database.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698