summaryrefslogtreecommitdiff
path: root/chromium/base/metrics/histogram_unittest.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-12 14:27:29 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-13 09:35:20 +0000
commitc30a6232df03e1efbd9f3b226777b07e087a1122 (patch)
treee992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/base/metrics/histogram_unittest.cc
parent7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff)
downloadqtwebengine-chromium-85-based.tar.gz
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/base/metrics/histogram_unittest.cc')
-rw-r--r--chromium/base/metrics/histogram_unittest.cc49
1 files changed, 49 insertions, 0 deletions
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<bool> {
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<StatisticsRecorder> 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*>(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,