Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/metrics/histogram_snapshot_manager.h" | |
| 6 | |
| 7 #include <string> | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/metrics/histogram.h" | |
| 11 #include "base/metrics/histogram_delta_serialization.h" | |
| 12 #include "base/metrics/statistics_recorder.h" | |
| 13 #include "testing/gtest/include/gtest/gtest.h" | |
| 14 | |
| 15 namespace base { | |
| 16 | |
| 17 class HistogramFlattenerDeltaRecorder : public HistogramFlattener { | |
| 18 public: | |
| 19 virtual void RecordDelta(const HistogramBase& histogram, | |
| 20 const HistogramSamples& snapshot) OVERRIDE { | |
| 21 recorded_delta_histogram_names_.push_back(histogram.histogram_name()); | |
| 22 } | |
| 23 | |
| 24 virtual void InconsistencyDetected( | |
| 25 HistogramBase::Inconsistency problem) OVERRIDE { | |
| 26 ASSERT_TRUE(false); | |
| 27 } | |
| 28 | |
| 29 virtual void UniqueInconsistencyDetected( | |
| 30 HistogramBase::Inconsistency problem) OVERRIDE { | |
| 31 ASSERT_TRUE(false); | |
| 32 } | |
| 33 | |
| 34 virtual void InconsistencyDetectedInLoggedCount(int amount) OVERRIDE { | |
| 35 ASSERT_TRUE(false); | |
| 36 } | |
| 37 | |
| 38 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.
| |
| 39 }; | |
|
Ilya Sherman
2014/02/08 00:59:49
nit: DISALLOW_COPY_AND_ASSIGN
Kibeom Kim (inactive)
2014/02/10 22:24:45
Done.
| |
| 40 | |
| 41 class HistogramSnapshotManagerTest : public testing::Test { | |
| 42 protected: | |
| 43 HistogramSnapshotManagerTest() | |
| 44 : histogram_snapshot_manager_(&histogram_flattener_delta_recorder_) {} | |
| 45 | |
| 46 virtual ~HistogramSnapshotManagerTest() {} | |
| 47 | |
| 48 StatisticsRecorder statistics_recorder_; | |
| 49 HistogramFlattenerDeltaRecorder histogram_flattener_delta_recorder_; | |
| 50 HistogramSnapshotManager histogram_snapshot_manager_; | |
| 51 }; | |
| 52 | |
| 53 TEST_F(HistogramSnapshotManagerTest, PrepareDeltasNoFlagsFilter) { | |
| 54 // kNoFlags filter should record all histograms. | |
| 55 UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2); | |
| 56 UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2); | |
| 57 | |
| 58 histogram_snapshot_manager_.PrepareDeltas(HistogramBase::kNoFlags, | |
| 59 HistogramBase::kNoFlags); | |
| 60 | |
| 61 const std::vector<std::string>& histograms = | |
| 62 histogram_flattener_delta_recorder_.recorded_delta_histogram_names_; | |
| 63 EXPECT_EQ(2U, histograms.size()); | |
| 64 EXPECT_EQ("UmaHistogram", histograms[0]); | |
| 65 EXPECT_EQ("UmaStabilityHistogram", histograms[1]); | |
| 66 } | |
| 67 | |
| 68 TEST_F(HistogramSnapshotManagerTest, PrepareDeltasUmaHistogramFlagFilter) { | |
| 69 // Note that kUmaStabilityHistogramFlag includes kUmaTargetedHistogramFlag. | |
| 70 UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2); | |
| 71 UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2); | |
| 72 | |
| 73 histogram_snapshot_manager_.PrepareDeltas( | |
| 74 HistogramBase::kNoFlags, HistogramBase::kUmaTargetedHistogramFlag); | |
| 75 | |
| 76 const std::vector<std::string>& histograms = | |
| 77 histogram_flattener_delta_recorder_.recorded_delta_histogram_names_; | |
| 78 EXPECT_EQ(2U, histograms.size()); | |
| 79 EXPECT_EQ("UmaHistogram", histograms[0]); | |
| 80 EXPECT_EQ("UmaStabilityHistogram", histograms[1]); | |
| 81 } | |
| 82 | |
| 83 TEST_F(HistogramSnapshotManagerTest, | |
| 84 PrepareDeltasUmaStabilityHistogramFlagFilter) { | |
| 85 UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2); | |
| 86 UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2); | |
| 87 | |
| 88 histogram_snapshot_manager_.PrepareDeltas( | |
| 89 HistogramBase::kNoFlags, HistogramBase::kUmaStabilityHistogramFlag); | |
| 90 | |
| 91 const std::vector<std::string>& histograms = | |
| 92 histogram_flattener_delta_recorder_.recorded_delta_histogram_names_; | |
| 93 EXPECT_EQ(1U, histograms.size()); | |
| 94 EXPECT_EQ("UmaStabilityHistogram", histograms[0]); | |
| 95 } | |
| 96 | |
| 97 } // namespace base | |
|
Ilya Sherman
2014/02/08 00:59:49
Thanks for adding test coverage :)
| |
| OLD | NEW |