summaryrefslogtreecommitdiff
path: root/chromium/base/metrics/histogram_unittest.cc
diff options
context:
space:
mode:
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,