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

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

Issue 137623002: Let MetricsService know about some Android Activities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed patchset 7's comments Created 6 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
OLDNEW
(Empty)
1 // Copyright 2013 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_;
39 };
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 std::vector<std::string>& histograms =
Alexei Svitkine (slow) 2014/01/29 16:54:09 Non-const refs are generally not allowed. Either m
Kibeom Kim (inactive) 2014/01/29 20:16:07 Done.
62 histogram_flattener_delta_recorder_.recorded_delta_histogram_names_;
63 EXPECT_EQ((unsigned)2, histograms.size());
Alexei Svitkine (slow) 2014/01/29 16:54:09 (unsigned)2 -> 2U Same below.
Kibeom Kim (inactive) 2014/01/29 20:16:07 Done.
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 std::vector<std::string>& histograms =
77 histogram_flattener_delta_recorder_.recorded_delta_histogram_names_;
78 EXPECT_EQ((unsigned)2, 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 std::vector<std::string>& histograms =
92 histogram_flattener_delta_recorder_.recorded_delta_histogram_names_;
93 EXPECT_EQ((unsigned)1, histograms.size());
94 EXPECT_EQ("UmaStabilityHistogram", histograms[0]);
95 }
96
97 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698