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/histogram_unittest.cc | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'chromium/base/metrics/histogram_unittest.cc') diff --git a/chromium/base/metrics/histogram_unittest.cc b/chromium/base/metrics/histogram_unittest.cc index aef19340d4b..d7addaaa266 100644 --- a/chromium/base/metrics/histogram_unittest.cc +++ b/chromium/base/metrics/histogram_unittest.cc @@ -101,6 +101,15 @@ class HistogramTest : public testing::TestWithParam { return h->SnapshotAllSamples(); } + void GetCountAndBucketData(Histogram* 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_; @@ -899,6 +908,46 @@ TEST_P(HistogramTest, ExpiredHistogramTest) { EXPECT_EQ(2, samples->TotalCount()); } +TEST_P(HistogramTest, CheckGetCountAndBucketData) { + const size_t kBucketCount = 50; + Histogram* histogram = static_cast(Histogram::FactoryGet( + "AddCountHistogram", 10, 100, kBucketCount, HistogramBase::kNoFlags)); + // Add samples in reverse order and make sure the output is in correct order. + histogram->AddCount(/*sample=*/30, /*value=*/14); + histogram->AddCount(/*sample=*/20, /*value=*/15); + histogram->AddCount(/*sample=*/20, /*value=*/15); + histogram->AddCount(/*sample=*/30, /*value=*/14); + + base::Histogram::Count total_count; + int64_t sum; + base::ListValue buckets; + GetCountAndBucketData(histogram, &total_count, &sum, &buckets); + EXPECT_EQ(58, total_count); + EXPECT_EQ(1440, 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(20, low); + EXPECT_EQ(21, high); + EXPECT_EQ(30, 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(30, low); + EXPECT_EQ(31, high); + EXPECT_EQ(28, count); +} + TEST_P(HistogramTest, WriteAscii) { HistogramBase* histogram = LinearHistogram::FactoryGet("AsciiOut", /*minimum=*/1, /*maximum=*/10, -- cgit v1.2.1