Chromium Code Reviews| Index: base/metrics/histogram_snapshot_manager_unittest.cc |
| diff --git a/base/metrics/histogram_snapshot_manager_unittest.cc b/base/metrics/histogram_snapshot_manager_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4b3a1b8647d27765a35171c6aafef97939e8fe22 |
| --- /dev/null |
| +++ b/base/metrics/histogram_snapshot_manager_unittest.cc |
| @@ -0,0 +1,97 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/metrics/histogram_snapshot_manager.h" |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/metrics/histogram.h" |
| +#include "base/metrics/histogram_delta_serialization.h" |
| +#include "base/metrics/statistics_recorder.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace base { |
| + |
| +class HistogramFlattenerDeltaRecorder : public HistogramFlattener { |
| + public: |
| + virtual void RecordDelta(const HistogramBase& histogram, |
| + const HistogramSamples& snapshot) OVERRIDE { |
| + recorded_delta_histogram_names_.push_back(histogram.histogram_name()); |
| + } |
| + |
| + virtual void InconsistencyDetected( |
| + HistogramBase::Inconsistency problem) OVERRIDE { |
| + ASSERT_TRUE(false); |
| + } |
| + |
| + virtual void UniqueInconsistencyDetected( |
| + HistogramBase::Inconsistency problem) OVERRIDE { |
| + ASSERT_TRUE(false); |
| + } |
| + |
| + virtual void InconsistencyDetectedInLoggedCount(int amount) OVERRIDE { |
| + ASSERT_TRUE(false); |
| + } |
| + |
| + std::vector<std::string> recorded_delta_histogram_names_; |
|
Ilya Sherman
2014/02/08 00:59:49
nit: Please set this to have private visibility, a
Kibeom Kim (inactive)
2014/02/10 22:24:45
Done.
|
| +}; |
|
Ilya Sherman
2014/02/08 00:59:49
nit: DISALLOW_COPY_AND_ASSIGN
Kibeom Kim (inactive)
2014/02/10 22:24:45
Done.
|
| + |
| +class HistogramSnapshotManagerTest : public testing::Test { |
| + protected: |
| + HistogramSnapshotManagerTest() |
| + : histogram_snapshot_manager_(&histogram_flattener_delta_recorder_) {} |
| + |
| + virtual ~HistogramSnapshotManagerTest() {} |
| + |
| + StatisticsRecorder statistics_recorder_; |
| + HistogramFlattenerDeltaRecorder histogram_flattener_delta_recorder_; |
| + HistogramSnapshotManager histogram_snapshot_manager_; |
| +}; |
| + |
| +TEST_F(HistogramSnapshotManagerTest, PrepareDeltasNoFlagsFilter) { |
| + // kNoFlags filter should record all histograms. |
| + UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2); |
| + UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2); |
| + |
| + histogram_snapshot_manager_.PrepareDeltas(HistogramBase::kNoFlags, |
| + HistogramBase::kNoFlags); |
| + |
| + const std::vector<std::string>& histograms = |
| + histogram_flattener_delta_recorder_.recorded_delta_histogram_names_; |
| + EXPECT_EQ(2U, histograms.size()); |
| + EXPECT_EQ("UmaHistogram", histograms[0]); |
| + EXPECT_EQ("UmaStabilityHistogram", histograms[1]); |
| +} |
| + |
| +TEST_F(HistogramSnapshotManagerTest, PrepareDeltasUmaHistogramFlagFilter) { |
| + // Note that kUmaStabilityHistogramFlag includes kUmaTargetedHistogramFlag. |
| + UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2); |
| + UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2); |
| + |
| + histogram_snapshot_manager_.PrepareDeltas( |
| + HistogramBase::kNoFlags, HistogramBase::kUmaTargetedHistogramFlag); |
| + |
| + const std::vector<std::string>& histograms = |
| + histogram_flattener_delta_recorder_.recorded_delta_histogram_names_; |
| + EXPECT_EQ(2U, histograms.size()); |
| + EXPECT_EQ("UmaHistogram", histograms[0]); |
| + EXPECT_EQ("UmaStabilityHistogram", histograms[1]); |
| +} |
| + |
| +TEST_F(HistogramSnapshotManagerTest, |
| + PrepareDeltasUmaStabilityHistogramFlagFilter) { |
| + UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2); |
| + UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2); |
| + |
| + histogram_snapshot_manager_.PrepareDeltas( |
| + HistogramBase::kNoFlags, HistogramBase::kUmaStabilityHistogramFlag); |
| + |
| + const std::vector<std::string>& histograms = |
| + histogram_flattener_delta_recorder_.recorded_delta_histogram_names_; |
| + EXPECT_EQ(1U, histograms.size()); |
| + EXPECT_EQ("UmaStabilityHistogram", histograms[0]); |
| +} |
| + |
| +} // namespace base |
|
Ilya Sherman
2014/02/08 00:59:49
Thanks for adding test coverage :)
|