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

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

Issue 2200863002: Add UMA Precache.CacheStatus.NonPrefetch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
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
« no previous file with comments | « no previous file | components/precache/core/precache_database.cc » ('j') | 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/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 29 matching lines...) Expand all
40 #include "testing/gmock/include/gmock/gmock.h" 40 #include "testing/gmock/include/gmock/gmock.h"
41 #include "testing/gtest/include/gtest/gtest.h" 41 #include "testing/gtest/include/gtest/gtest.h"
42 #include "url/gurl.h" 42 #include "url/gurl.h"
43 43
44 namespace precache { 44 namespace precache {
45 45
46 namespace { 46 namespace {
47 47
48 using ::testing::_; 48 using ::testing::_;
49 using ::testing::ContainerEq; 49 using ::testing::ContainerEq;
50 using ::testing::ElementsAre;
51 using ::testing::UnorderedElementsAre; 50 using ::testing::UnorderedElementsAre;
52 using ::testing::Invoke; 51 using ::testing::Invoke;
53 using ::testing::IsEmpty; 52 using ::testing::IsEmpty;
54 using ::testing::Pair; 53 using ::testing::Pair;
55 using ::testing::SaveArg; 54 using ::testing::SaveArg;
56 55
57 const char kConfigURL[] = "http://config-url.com"; 56 const char kConfigURL[] = "http://config-url.com";
58 const char kManifestURLPrefix[] = "http://manifest-url-prefix.com/"; 57 const char kManifestURLPrefix[] = "http://manifest-url-prefix.com/";
59 const char kGoodManifestURL[] = 58 const char kGoodManifestURL[] =
60 "http://manifest-url-prefix.com/good-manifest.com"; 59 "http://manifest-url-prefix.com/good-manifest.com";
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 Pair("Precache.Freshness.Prefetch", 1))); 403 Pair("Precache.Freshness.Prefetch", 1)));
405 } 404 }
406 405
407 TEST_F(PrecacheManagerTest, RecordStatsForFetchHTTP) { 406 TEST_F(PrecacheManagerTest, RecordStatsForFetchHTTP) {
408 precache_manager_->RecordStatsForFetch(GURL("http://http-url.com"), GURL(), 407 precache_manager_->RecordStatsForFetch(GURL("http://http-url.com"), GURL(),
409 base::TimeDelta(), base::Time(), info_, 408 base::TimeDelta(), base::Time(), info_,
410 1000); 409 1000);
411 base::RunLoop().RunUntilIdle(); 410 base::RunLoop().RunUntilIdle();
412 411
413 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), 412 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."),
414 ElementsAre(Pair("Precache.DownloadedNonPrecache", 1), 413 UnorderedElementsAre(
415 Pair("Precache.Latency.NonPrefetch", 1), 414 Pair("Precache.DownloadedNonPrecache", 1),
416 Pair("Precache.Latency.NonPrefetch.NonTopHosts", 1))); 415 Pair("Precache.CacheStatus.NonPrefetch", 1),
416 Pair("Precache.Latency.NonPrefetch", 1),
417 Pair("Precache.Latency.NonPrefetch.NonTopHosts", 1)));
417 } 418 }
418 419
419 TEST_F(PrecacheManagerTest, RecordStatsForFetchHTTPS) { 420 TEST_F(PrecacheManagerTest, RecordStatsForFetchHTTPS) {
420 precache_manager_->RecordStatsForFetch(GURL("https://https-url.com"), GURL(), 421 precache_manager_->RecordStatsForFetch(GURL("https://https-url.com"), GURL(),
421 base::TimeDelta(), base::Time(), info_, 422 base::TimeDelta(), base::Time(), info_,
422 1000); 423 1000);
423 base::RunLoop().RunUntilIdle(); 424 base::RunLoop().RunUntilIdle();
424 425
425 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), 426 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."),
426 ElementsAre(Pair("Precache.DownloadedNonPrecache", 1), 427 UnorderedElementsAre(
427 Pair("Precache.Latency.NonPrefetch", 1), 428 Pair("Precache.DownloadedNonPrecache", 1),
428 Pair("Precache.Latency.NonPrefetch.NonTopHosts", 1))); 429 Pair("Precache.CacheStatus.NonPrefetch", 1),
430 Pair("Precache.Latency.NonPrefetch", 1),
431 Pair("Precache.Latency.NonPrefetch.NonTopHosts", 1)));
429 } 432 }
430 433
431 TEST_F(PrecacheManagerTest, RecordStatsForFetchInTopHosts) { 434 TEST_F(PrecacheManagerTest, RecordStatsForFetchInTopHosts) {
432 EXPECT_CALL(history_service_, 435 EXPECT_CALL(history_service_,
433 HostRankIfAvailable(GURL("http://referrer.com"), _)) 436 HostRankIfAvailable(GURL("http://referrer.com"), _))
434 .WillOnce(Invoke( 437 .WillOnce(Invoke(
435 [](const GURL& url, const base::Callback<void(int)>& callback) { 438 [](const GURL& url, const base::Callback<void(int)>& callback) {
436 callback.Run(0); 439 callback.Run(0);
437 })); 440 }));
438 precache_manager_->RecordStatsForFetch( 441 precache_manager_->RecordStatsForFetch(
439 GURL("http://http-url.com"), GURL("http://referrer.com"), 442 GURL("http://http-url.com"), GURL("http://referrer.com"),
440 base::TimeDelta(), base::Time(), info_, 1000); 443 base::TimeDelta(), base::Time(), info_, 1000);
441 base::RunLoop().RunUntilIdle(); 444 base::RunLoop().RunUntilIdle();
442 445
443 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), 446 EXPECT_THAT(
444 ElementsAre(Pair("Precache.DownloadedNonPrecache", 1), 447 histograms_.GetTotalCountsForPrefix("Precache."),
445 Pair("Precache.Latency.NonPrefetch", 1), 448 UnorderedElementsAre(Pair("Precache.DownloadedNonPrecache", 1),
446 Pair("Precache.Latency.NonPrefetch.TopHosts", 1))); 449 Pair("Precache.CacheStatus.NonPrefetch", 1),
450 Pair("Precache.Latency.NonPrefetch", 1),
451 Pair("Precache.Latency.NonPrefetch.TopHosts", 1)));
447 } 452 }
448 453
449 TEST_F(PrecacheManagerTest, DeleteExpiredPrecacheHistory) { 454 TEST_F(PrecacheManagerTest, DeleteExpiredPrecacheHistory) {
450 // TODO(twifkak): Split this into multiple tests. 455 // TODO(twifkak): Split this into multiple tests.
451 base::HistogramTester::CountsMap expected_histogram_count_map; 456 base::HistogramTester::CountsMap expected_histogram_count_map;
452 457
453 // 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().
454 const base::Time kCurrentTime = base::Time::Now(); 459 const base::Time kCurrentTime = base::Time::Now();
455 EXPECT_CALL(history_service_, TopHosts(NumTopHosts(), _)) 460 EXPECT_CALL(history_service_, TopHosts(NumTopHosts(), _))
456 .Times(2) 461 .Times(2)
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 EXPECT_FALSE(precache_manager_->IsPrecaching()); 511 EXPECT_FALSE(precache_manager_->IsPrecaching());
507 512
508 // 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,
509 // 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
510 // history. 515 // history.
511 info_.was_cached = true; // From now on all fetches are cached. 516 info_.was_cached = true; // From now on all fetches are cached.
512 precache_manager_->RecordStatsForFetch(GURL("http://old-fetch.com"), GURL(), 517 precache_manager_->RecordStatsForFetch(GURL("http://old-fetch.com"), GURL(),
513 base::TimeDelta(), kCurrentTime, info_, 518 base::TimeDelta(), kCurrentTime, info_,
514 1000); 519 1000);
515 expected_histogram_count_map["Precache.Fetch.TimeToComplete"]++; 520 expected_histogram_count_map["Precache.Fetch.TimeToComplete"]++;
521 expected_histogram_count_map["Precache.CacheStatus.NonPrefetch"]++;
516 expected_histogram_count_map["Precache.Latency.NonPrefetch"]++; 522 expected_histogram_count_map["Precache.Latency.NonPrefetch"]++;
517 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"]++; 523 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"]++;
518 524
519 base::RunLoop().RunUntilIdle(); 525 base::RunLoop().RunUntilIdle();
520 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), 526 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."),
521 ContainerEq(expected_histogram_count_map)); 527 ContainerEq(expected_histogram_count_map));
522 528
523 // 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
524 // the cache should count as saved bytes. 530 // the cache should count as saved bytes.
525 precache_manager_->RecordStatsForFetch(GURL("http://recent-fetch.com"), 531 precache_manager_->RecordStatsForFetch(GURL("http://recent-fetch.com"),
526 GURL(), base::TimeDelta(), 532 GURL(), base::TimeDelta(),
527 kCurrentTime, info_, 1000); 533 kCurrentTime, info_, 1000);
528 precache_manager_->RecordStatsForFetch(GURL("http://yesterday-fetch.com"), 534 precache_manager_->RecordStatsForFetch(GURL("http://yesterday-fetch.com"),
529 GURL(), base::TimeDelta(), 535 GURL(), base::TimeDelta(),
530 kCurrentTime, info_, 1000); 536 kCurrentTime, info_, 1000);
537 expected_histogram_count_map["Precache.CacheStatus.NonPrefetch"] += 2;
531 expected_histogram_count_map["Precache.Latency.NonPrefetch"] += 2; 538 expected_histogram_count_map["Precache.Latency.NonPrefetch"] += 2;
532 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"] += 2; 539 expected_histogram_count_map["Precache.Latency.NonPrefetch.NonTopHosts"] += 2;
533 expected_histogram_count_map["Precache.Saved"] += 2; 540 expected_histogram_count_map["Precache.Saved"] += 2;
534 expected_histogram_count_map["Precache.Saved.Freshness"] = 2; 541 expected_histogram_count_map["Precache.Saved.Freshness"] = 2;
535 542
536 base::RunLoop().RunUntilIdle(); 543 base::RunLoop().RunUntilIdle();
537 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."), 544 EXPECT_THAT(histograms_.GetTotalCountsForPrefix("Precache."),
538 ContainerEq(expected_histogram_count_map)); 545 ContainerEq(expected_histogram_count_map));
539 } 546 }
540 547
541 } // namespace precache 548 } // namespace precache
OLDNEW
« no previous file with comments | « no previous file | components/precache/core/precache_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698