diff options
Diffstat (limited to 'chromium/base/metrics/sparse_histogram_unittest.cc')
-rw-r--r-- | chromium/base/metrics/sparse_histogram_unittest.cc | 47 |
1 files changed, 47 insertions, 0 deletions
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<bool> { return std::unique_ptr<SparseHistogram>(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<StatisticsRecorder> statistics_recorder_; @@ -387,6 +396,44 @@ TEST_P(SparseHistogramTest, HistogramNameHash) { EXPECT_EQ(histogram->name_hash(), HashMetricName(kName)); } +TEST_P(SparseHistogramTest, CheckGetCountAndBucketData) { + std::unique_ptr<SparseHistogram> 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); |