Update V8 to version 4.7.47.
[chromium-blink-merge.git] / base / metrics / histogram_snapshot_manager_unittest.cc
blobe9e7398bca9fa9761263c8878b780430c3c1f233
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_delta_serialization.h"
11 #include "base/metrics/histogram_macros.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 void RecordDelta(const HistogramBase& histogram,
22 const HistogramSamples& snapshot) override {
23 recorded_delta_histogram_names_.push_back(histogram.histogram_name());
26 void InconsistencyDetected(HistogramBase::Inconsistency problem) override {
27 ASSERT_TRUE(false);
30 void UniqueInconsistencyDetected(
31 HistogramBase::Inconsistency problem) override {
32 ASSERT_TRUE(false);
35 void InconsistencyDetectedInLoggedCount(int amount) override {
36 ASSERT_TRUE(false);
39 std::vector<std::string> GetRecordedDeltaHistogramNames() {
40 return recorded_delta_histogram_names_;
43 private:
44 std::vector<std::string> recorded_delta_histogram_names_;
46 DISALLOW_COPY_AND_ASSIGN(HistogramFlattenerDeltaRecorder);
49 class HistogramSnapshotManagerTest : public testing::Test {
50 protected:
51 HistogramSnapshotManagerTest()
52 : histogram_snapshot_manager_(&histogram_flattener_delta_recorder_) {}
54 ~HistogramSnapshotManagerTest() override {}
56 StatisticsRecorder statistics_recorder_;
57 HistogramFlattenerDeltaRecorder histogram_flattener_delta_recorder_;
58 HistogramSnapshotManager histogram_snapshot_manager_;
61 TEST_F(HistogramSnapshotManagerTest, PrepareDeltasNoFlagsFilter) {
62 // kNoFlags filter should record all histograms.
63 UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2);
64 UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2);
66 histogram_snapshot_manager_.PrepareDeltas(HistogramBase::kNoFlags,
67 HistogramBase::kNoFlags);
69 const std::vector<std::string>& histograms =
70 histogram_flattener_delta_recorder_.GetRecordedDeltaHistogramNames();
71 EXPECT_EQ(2U, histograms.size());
72 EXPECT_EQ("UmaHistogram", histograms[0]);
73 EXPECT_EQ("UmaStabilityHistogram", histograms[1]);
76 TEST_F(HistogramSnapshotManagerTest, PrepareDeltasUmaHistogramFlagFilter) {
77 // Note that kUmaStabilityHistogramFlag includes kUmaTargetedHistogramFlag.
78 UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2);
79 UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2);
81 histogram_snapshot_manager_.PrepareDeltas(
82 HistogramBase::kNoFlags, HistogramBase::kUmaTargetedHistogramFlag);
84 const std::vector<std::string>& histograms =
85 histogram_flattener_delta_recorder_.GetRecordedDeltaHistogramNames();
86 EXPECT_EQ(2U, histograms.size());
87 EXPECT_EQ("UmaHistogram", histograms[0]);
88 EXPECT_EQ("UmaStabilityHistogram", histograms[1]);
91 TEST_F(HistogramSnapshotManagerTest,
92 PrepareDeltasUmaStabilityHistogramFlagFilter) {
93 UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2);
94 UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2);
96 histogram_snapshot_manager_.PrepareDeltas(
97 HistogramBase::kNoFlags, HistogramBase::kUmaStabilityHistogramFlag);
99 const std::vector<std::string>& histograms =
100 histogram_flattener_delta_recorder_.GetRecordedDeltaHistogramNames();
101 EXPECT_EQ(1U, histograms.size());
102 EXPECT_EQ("UmaStabilityHistogram", histograms[0]);
105 } // namespace base