9
9
10
10
#include " base/bind.h"
11
11
#include " base/test/bind_test_util.h"
12
+ #include " base/test/metrics/histogram_tester.h"
12
13
#include " base/test/scoped_task_environment.h"
13
14
#include " base/test/test_simple_task_runner.h"
14
15
#include " services/data_decoder/public/cpp/test_data_decoder_service.h"
@@ -61,6 +62,8 @@ class ExploreSitesImageHelperTest : public testing::Test {
61
62
});
62
63
}
63
64
65
+ const base::HistogramTester& histograms () const { return histogram_tester_; }
66
+
64
67
std::vector<std::unique_ptr<SkBitmap>> last_bitmap_list;
65
68
66
69
protected:
@@ -71,6 +74,7 @@ class ExploreSitesImageHelperTest : public testing::Test {
71
74
}
72
75
73
76
std::unique_ptr<service_manager::TestConnectorFactory> connector_factory_;
77
+ base::HistogramTester histogram_tester_;
74
78
};
75
79
76
80
// 1x1 webp image with color value of 0.
@@ -271,4 +275,35 @@ TEST_F(ExploreSitesImageHelperTest, TestImageHelper_CategoryImage_InvalidWebP) {
271
275
}
272
276
}
273
277
278
+ // Test that the ExploreSites.ImageDecoded UMA works.
279
+ TEST_F (ExploreSitesImageHelperTest, TestImageHelper_ImageDecodedUMA) {
280
+ ImageHelper image_helper;
281
+
282
+ // Record one success UMA from CompseSiteImage.
283
+ image_helper.ComposeSiteImage (StoreBitmap (), GetEncodedImageList (1 ),
284
+ GetConnector ());
285
+ scoped_task_environment_.RunUntilIdle ();
286
+
287
+ histograms ().ExpectTotalCount (" ExploreSites.ImageDecoded" , 1 );
288
+ histograms ().ExpectBucketCount (" ExploreSites.ImageDecoded" , true , 1 );
289
+
290
+ // Record one failure UMA from ComposeSiteImage.
291
+ EncodedImageList image_list;
292
+ image_list.push_back (std::make_unique<EncodedImageBytes>(kInvalidWebpBytes ));
293
+ image_helper.ComposeSiteImage (StoreBitmap (), std::move (image_list),
294
+ GetConnector ());
295
+ scoped_task_environment_.RunUntilIdle ();
296
+
297
+ histograms ().ExpectTotalCount (" ExploreSites.ImageDecoded" , 2 );
298
+ histograms ().ExpectBucketCount (" ExploreSites.ImageDecoded" , false , 1 );
299
+
300
+ // Record 2 samples from ComposeCategoryImage.
301
+ image_helper.ComposeCategoryImage (StoreBitmap (), kIconSize ,
302
+ GetEncodedImageList (2 ), GetConnector ());
303
+ scoped_task_environment_.RunUntilIdle ();
304
+
305
+ histograms ().ExpectTotalCount (" ExploreSites.ImageDecoded" , 4 );
306
+ histograms ().ExpectBucketCount (" ExploreSites.ImageDecoded" , true , 3 );
307
+ }
308
+
274
309
} // namespace explore_sites
0 commit comments