Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: base/metrics/histogram_snapshot_manager_unittest.cc

Issue 1647803004: Move base to DEPS (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/metrics/histogram_snapshot_manager.cc ('k') | base/metrics/histogram_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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_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"
14
15 namespace base {
16
17 class HistogramFlattenerDeltaRecorder : public HistogramFlattener {
18 public:
19 HistogramFlattenerDeltaRecorder() {}
20
21 void RecordDelta(const HistogramBase& histogram,
22 const HistogramSamples& snapshot) override {
23 recorded_delta_histogram_names_.push_back(histogram.histogram_name());
24 }
25
26 void InconsistencyDetected(HistogramBase::Inconsistency problem) override {
27 ASSERT_TRUE(false);
28 }
29
30 void UniqueInconsistencyDetected(
31 HistogramBase::Inconsistency problem) override {
32 ASSERT_TRUE(false);
33 }
34
35 void InconsistencyDetectedInLoggedCount(int amount) override {
36 ASSERT_TRUE(false);
37 }
38
39 std::vector<std::string> GetRecordedDeltaHistogramNames() {
40 return recorded_delta_histogram_names_;
41 }
42
43 private:
44 std::vector<std::string> recorded_delta_histogram_names_;
45
46 DISALLOW_COPY_AND_ASSIGN(HistogramFlattenerDeltaRecorder);
47 };
48
49 class HistogramSnapshotManagerTest : public testing::Test {
50 protected:
51 HistogramSnapshotManagerTest()
52 : histogram_snapshot_manager_(&histogram_flattener_delta_recorder_) {}
53
54 ~HistogramSnapshotManagerTest() override {}
55
56 StatisticsRecorder statistics_recorder_;
57 HistogramFlattenerDeltaRecorder histogram_flattener_delta_recorder_;
58 HistogramSnapshotManager histogram_snapshot_manager_;
59 };
60
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);
65
66 histogram_snapshot_manager_.PrepareDeltas(HistogramBase::kNoFlags,
67 HistogramBase::kNoFlags);
68
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]);
74 }
75
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);
80
81 histogram_snapshot_manager_.PrepareDeltas(
82 HistogramBase::kNoFlags, HistogramBase::kUmaTargetedHistogramFlag);
83
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]);
89 }
90
91 TEST_F(HistogramSnapshotManagerTest,
92 PrepareDeltasUmaStabilityHistogramFlagFilter) {
93 UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2);
94 UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2);
95
96 histogram_snapshot_manager_.PrepareDeltas(
97 HistogramBase::kNoFlags, HistogramBase::kUmaStabilityHistogramFlag);
98
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]);
103 }
104
105 } // namespace base
OLDNEW
« no previous file with comments | « base/metrics/histogram_snapshot_manager.cc ('k') | base/metrics/histogram_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698