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

Unified Diff: components/ntp_tiles/icon_cacher_impl_unittest.cc

Issue 2888393002: [Icon cacher] Add metrics for downloading favicons for NTP Tiles (Closed)
Patch Set: Comments of Chris Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: components/ntp_tiles/icon_cacher_impl_unittest.cc
diff --git a/components/ntp_tiles/icon_cacher_impl_unittest.cc b/components/ntp_tiles/icon_cacher_impl_unittest.cc
index 0e3620876310963e4e5438b4dca91aa37b8c5a44..3fac2db137e8227ca79c3ca629040792c0aad844 100644
--- a/components/ntp_tiles/icon_cacher_impl_unittest.cc
+++ b/components/ntp_tiles/icon_cacher_impl_unittest.cc
@@ -11,6 +11,7 @@
#include "base/memory/ptr_util.h"
#include "base/path_service.h"
#include "base/run_loop.h"
+#include "base/test/histogram_tester.h"
#include "base/test/mock_callback.h"
#include "base/test/scoped_task_environment.h"
#include "base/test/test_simple_task_runner.h"
@@ -30,10 +31,13 @@
#include "ui/base/ui_base_paths.h"
#include "ui/gfx/image/image_unittest_util.h"
+using base::Bucket;
using ::testing::_;
+using ::testing::ElementsAre;
using ::testing::Eq;
using ::testing::Invoke;
using ::testing::InSequence;
+using ::testing::IsEmpty;
using ::testing::NiceMock;
using ::testing::Return;
using ::testing::ReturnArg;
@@ -230,6 +234,7 @@ class IconCacherTestPopularSites : public IconCacherTestBase {
};
TEST_F(IconCacherTestPopularSites, LargeCached) {
+ base::HistogramTester histogram_tester;
base::MockCallback<base::Closure> done;
EXPECT_CALL(done, Run()).Times(0);
base::RunLoop loop;
@@ -247,9 +252,13 @@ TEST_F(IconCacherTestPopularSites, LargeCached) {
WaitForMainThreadTasksToFinish();
EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::FAVICON));
EXPECT_TRUE(IconIsCachedFor(site_.url, favicon_base::TOUCH_ICON));
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples("NewTabPage.TileFaviconFetched.popular"),
+ IsEmpty());
}
TEST_F(IconCacherTestPopularSites, LargeNotCachedAndFetchSucceeded) {
+ base::HistogramTester histogram_tester;
base::MockCallback<base::Closure> done;
base::RunLoop loop;
{
@@ -269,6 +278,9 @@ TEST_F(IconCacherTestPopularSites, LargeNotCachedAndFetchSucceeded) {
loop.Run();
EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::FAVICON));
EXPECT_TRUE(IconIsCachedFor(site_.url, favicon_base::TOUCH_ICON));
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples("NewTabPage.TileFaviconFetched.popular"),
+ ElementsAre(Bucket(/*bucket=*/0, /*count=*/1))); // bucket 0 = SUCCESS.
}
TEST_F(IconCacherTestPopularSites, SmallNotCachedAndFetchSucceeded) {
@@ -296,6 +308,7 @@ TEST_F(IconCacherTestPopularSites, SmallNotCachedAndFetchSucceeded) {
}
TEST_F(IconCacherTestPopularSites, LargeNotCachedAndFetchFailed) {
+ base::HistogramTester histogram_tester;
base::MockCallback<base::Closure> done;
EXPECT_CALL(done, Run()).Times(0);
{
@@ -314,9 +327,13 @@ TEST_F(IconCacherTestPopularSites, LargeNotCachedAndFetchFailed) {
WaitForMainThreadTasksToFinish();
EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::FAVICON));
EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::TOUCH_ICON));
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples("NewTabPage.TileFaviconFetched.popular"),
+ ElementsAre(Bucket(/*bucket=*/1, /*count=*/1))); // bucket 1 = FAILURE.
}
TEST_F(IconCacherTestPopularSites, HandlesEmptyCallbacksNicely) {
+ base::HistogramTester histogram_tester;
EXPECT_CALL(*image_fetcher_, SetDataUseServiceName(_));
EXPECT_CALL(*image_fetcher_, SetDesiredImageFrameSize(_));
EXPECT_CALL(*image_fetcher_, StartOrQueueNetworkRequest(_, _, _))
@@ -328,9 +345,14 @@ TEST_F(IconCacherTestPopularSites, HandlesEmptyCallbacksNicely) {
// Even though the callbacks are not called, the icon gets written out.
EXPECT_FALSE(IconIsCachedFor(site_.url, favicon_base::FAVICON));
EXPECT_TRUE(IconIsCachedFor(site_.url, favicon_base::TOUCH_ICON));
+ // The histogram gets reported despite empty callbacks.
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples("NewTabPage.TileFaviconFetched.popular"),
+ ElementsAre(Bucket(/*bucket=*/0, /*count=*/1))); // bucket 0 = SUCCESS.
}
TEST_F(IconCacherTestPopularSites, ProvidesDefaultIconAndSucceedsWithFetching) {
+ base::HistogramTester histogram_tester;
// The returned data string is not used by the mocked decoder.
ON_CALL(mock_resource_delegate_, GetRawDataResource(12345, _, _))
.WillByDefault(Return(""));
@@ -374,6 +396,11 @@ TEST_F(IconCacherTestPopularSites, ProvidesDefaultIconAndSucceedsWithFetching) {
fetch_loop.Run(); // Wait for the updated image.
EXPECT_THAT(GetCachedIconFor(site_.url, favicon_base::TOUCH_ICON).Size(),
Eq(gfx::Size(128, 128))); // Compares dimensions, not objects.
+ // The histogram gets reported only once (for the downloaded icon, not for the
+ // default one).
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples("NewTabPage.TileFaviconFetched.popular"),
+ ElementsAre(Bucket(/*bucket=*/0, /*count=*/1))); // bucket 0 = SUCCESS.
}
TEST_F(IconCacherTestPopularSites, LargeNotCachedAndFetchPerformedOnlyOnce) {
@@ -428,6 +455,8 @@ class IconCacherTestMostLikely : public IconCacherTestBase {
TEST_F(IconCacherTestMostLikely, Cached) {
GURL page_url("http://www.site.com");
+ base::HistogramTester histogram_tester;
+
GURL icon_url("http://www.site.com/favicon.png");
PreloadIcon(page_url, icon_url, favicon_base::TOUCH_ICON, 128, 128);
@@ -444,10 +473,14 @@ TEST_F(IconCacherTestMostLikely, Cached) {
EXPECT_FALSE(IconIsCachedFor(page_url, favicon_base::FAVICON));
EXPECT_TRUE(IconIsCachedFor(page_url, favicon_base::TOUCH_ICON));
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples("NewTabPage.TileFaviconFetched.server"),
+ IsEmpty());
}
TEST_F(IconCacherTestMostLikely, NotCachedAndFetchSucceeded) {
GURL page_url("http://www.site.com");
+ base::HistogramTester histogram_tester;
base::MockCallback<base::Closure> done;
base::RunLoop loop;
@@ -477,10 +510,14 @@ TEST_F(IconCacherTestMostLikely, NotCachedAndFetchSucceeded) {
loop.Run();
EXPECT_FALSE(IconIsCachedFor(page_url, favicon_base::FAVICON));
EXPECT_TRUE(IconIsCachedFor(page_url, favicon_base::TOUCH_ICON));
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples("NewTabPage.TileFaviconFetched.server"),
+ ElementsAre(Bucket(/*bucket=*/0, /*count=*/1))); // bucket 0 = SUCCESS.
}
TEST_F(IconCacherTestMostLikely, NotCachedAndFetchFailed) {
GURL page_url("http://www.site.com");
+ base::HistogramTester histogram_tester;
base::MockCallback<base::Closure> done;
{
@@ -509,6 +546,9 @@ TEST_F(IconCacherTestMostLikely, NotCachedAndFetchFailed) {
EXPECT_FALSE(IconIsCachedFor(page_url, favicon_base::FAVICON));
EXPECT_FALSE(IconIsCachedFor(page_url, favicon_base::TOUCH_ICON));
+ EXPECT_THAT(
+ histogram_tester.GetAllSamples("NewTabPage.TileFaviconFetched.server"),
+ ElementsAre(Bucket(/*bucket=*/1, /*count=*/1))); // bucket 1 = FAILURE.
}
TEST_F(IconCacherTestMostLikely, HandlesEmptyCallbacksNicely) {

Powered by Google App Engine
This is Rietveld 408576698