Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / base / metrics / histogram_snapshot_manager_unittest.cc
blobe6672ea7eb241906ff017e2f9cdc4c745ad0dc81
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.
5 #include "base/metrics/histogram_snapshot_manager.h"
7 #include <string>
8 #include <vector>
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"
15 namespace base {
17 class HistogramFlattenerDeltaRecorder : public HistogramFlattener {
18 public:
19 HistogramFlattenerDeltaRecorder() {}
21 virtual void RecordDelta(const HistogramBase& histogram,
22 const HistogramSamples& snapshot) OVERRIDE {
23 recorded_delta_histogram_names_.push_back(histogram.histogram_name());
26 virtual void InconsistencyDetected(
27 HistogramBase::Inconsistency problem) OVERRIDE {
28 ASSERT_TRUE(false);
31 virtual void UniqueInconsistencyDetected(
32 HistogramBase::Inconsistency problem) OVERRIDE {
33 ASSERT_TRUE(false);
36 virtual void InconsistencyDetectedInLoggedCount(int amount) OVERRIDE {
37 ASSERT_TRUE(false);
40 std::vector<std::string> GetRecordedDeltaHistogramNames() {
41 return recorded_delta_histogram_names_;
44 private:
45 std::vector<std::string> recorded_delta_histogram_names_;
47 DISALLOW_COPY_AND_ASSIGN(HistogramFlattenerDeltaRecorder);
50 class HistogramSnapshotManagerTest : public testing::Test {
51 protected:
52 HistogramSnapshotManagerTest()
53 : histogram_snapshot_manager_(&histogram_flattener_delta_recorder_) {}
55 virtual ~HistogramSnapshotManagerTest() {}
57 StatisticsRecorder statistics_recorder_;
58 HistogramFlattenerDeltaRecorder histogram_flattener_delta_recorder_;
59 HistogramSnapshotManager histogram_snapshot_manager_;
62 TEST_F(HistogramSnapshotManagerTest, PrepareDeltasNoFlagsFilter) {
63 // kNoFlags filter should record all histograms.
64 UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2);
65 UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2);
67 histogram_snapshot_manager_.PrepareDeltas(HistogramBase::kNoFlags,
68 HistogramBase::kNoFlags);
70 const std::vector<std::string>& histograms =
71 histogram_flattener_delta_recorder_.GetRecordedDeltaHistogramNames();
72 EXPECT_EQ(2U, histograms.size());
73 EXPECT_EQ("UmaHistogram", histograms[0]);
74 EXPECT_EQ("UmaStabilityHistogram", histograms[1]);
77 TEST_F(HistogramSnapshotManagerTest, PrepareDeltasUmaHistogramFlagFilter) {
78 // Note that kUmaStabilityHistogramFlag includes kUmaTargetedHistogramFlag.
79 UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2);
80 UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2);
82 histogram_snapshot_manager_.PrepareDeltas(
83 HistogramBase::kNoFlags, HistogramBase::kUmaTargetedHistogramFlag);
85 const std::vector<std::string>& histograms =
86 histogram_flattener_delta_recorder_.GetRecordedDeltaHistogramNames();
87 EXPECT_EQ(2U, histograms.size());
88 EXPECT_EQ("UmaHistogram", histograms[0]);
89 EXPECT_EQ("UmaStabilityHistogram", histograms[1]);
92 TEST_F(HistogramSnapshotManagerTest,
93 PrepareDeltasUmaStabilityHistogramFlagFilter) {
94 UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2);
95 UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2);
97 histogram_snapshot_manager_.PrepareDeltas(
98 HistogramBase::kNoFlags, HistogramBase::kUmaStabilityHistogramFlag);
100 const std::vector<std::string>& histograms =
101 histogram_flattener_delta_recorder_.GetRecordedDeltaHistogramNames();
102 EXPECT_EQ(1U, histograms.size());
103 EXPECT_EQ("UmaStabilityHistogram", histograms[0]);
106 } // namespace base