From c30a6232df03e1efbd9f3b226777b07e087a1122 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 12 Oct 2020 14:27:29 +0200 Subject: BASELINE: Update Chromium to 85.0.4183.140 Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057 Reviewed-by: Allan Sandfeld Jensen --- chromium/base/metrics/sparse_histogram_unittest.cc | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'chromium/base/metrics/sparse_histogram_unittest.cc') diff --git a/chromium/base/metrics/sparse_histogram_unittest.cc b/chromium/base/metrics/sparse_histogram_unittest.cc index a92b68b4a6d..47d8b818920 100644 --- a/chromium/base/metrics/sparse_histogram_unittest.cc +++ b/chromium/base/metrics/sparse_histogram_unittest.cc @@ -78,6 +78,15 @@ class SparseHistogramTest : public testing::TestWithParam { return std::unique_ptr(new SparseHistogram(name)); } + void GetCountAndBucketData(SparseHistogram* histogram, + base::Histogram::Count* count, + int64_t* sum, + base::ListValue* buckets) { + // A simple wrapper around |GetCountAndBucketData| to make it visible for + // testing. + histogram->GetCountAndBucketData(count, sum, buckets); + } + const bool use_persistent_histogram_allocator_; std::unique_ptr statistics_recorder_; @@ -387,6 +396,44 @@ TEST_P(SparseHistogramTest, HistogramNameHash) { EXPECT_EQ(histogram->name_hash(), HashMetricName(kName)); } +TEST_P(SparseHistogramTest, CheckGetCountAndBucketData) { + std::unique_ptr histogram(NewSparseHistogram("Sparse")); + // Add samples in reverse order and make sure the output is in correct order. + histogram->AddCount(/*sample=*/200, /*value=*/15); + histogram->AddCount(/*sample=*/100, /*value=*/5); + // Add samples to the same bucket and make sure they'll be aggregated. + histogram->AddCount(/*sample=*/100, /*value=*/5); + + base::Histogram::Count total_count; + int64_t sum; + base::ListValue buckets; + GetCountAndBucketData(histogram.get(), &total_count, &sum, &buckets); + EXPECT_EQ(25, total_count); + EXPECT_EQ(4000, sum); + EXPECT_EQ(2u, buckets.GetSize()); + + int low, high, count; + // Check the first bucket. + base::DictionaryValue* bucket1; + EXPECT_TRUE(buckets.GetDictionary(0, &bucket1)); + EXPECT_TRUE(bucket1->GetInteger("low", &low)); + EXPECT_TRUE(bucket1->GetInteger("high", &high)); + EXPECT_TRUE(bucket1->GetInteger("count", &count)); + EXPECT_EQ(100, low); + EXPECT_EQ(101, high); + EXPECT_EQ(10, count); + + // Check the second bucket. + base::DictionaryValue* bucket2; + EXPECT_TRUE(buckets.GetDictionary(1, &bucket2)); + EXPECT_TRUE(bucket2->GetInteger("low", &low)); + EXPECT_TRUE(bucket2->GetInteger("high", &high)); + EXPECT_TRUE(bucket2->GetInteger("count", &count)); + EXPECT_EQ(200, low); + EXPECT_EQ(201, high); + EXPECT_EQ(15, count); +} + TEST_P(SparseHistogramTest, WriteAscii) { HistogramBase* histogram = SparseHistogram::FactoryGet("AsciiOut", HistogramBase::kNoFlags); -- cgit v1.2.1