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

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: removed unnecessary ConvertAndroidStabilityPrefsToHistograms() call and added missing OVERRIDE Created 6 years, 11 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> GetRecordedDeltaHistogramNames() {
39 return recorded_delta_histogram_names_;
40 }
41
42 void ClearRecordedData() { recorded_delta_histogram_names_.clear(); }
43
44 private:
45 std::vector<std::string> recorded_delta_histogram_names_;
46 };
47
48 TEST(HistogramSnapshotManagerTest, PrepareDeltasHistogramFilter) {
49 StatisticsRecorder statistics_recorder;
50 HistogramFlattenerDeltaRecorder histogram_flattener_delta_recorder;
51 HistogramSnapshotManager histogram_snapshot_manager(
52 &histogram_flattener_delta_recorder);
53 std::vector<std::string> recorded_delta_histogram_names;
54
55 // kNoFlags filter should record all histograms.
56 UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2);
57 UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2);
58 histogram_snapshot_manager.PrepareDeltas(HistogramBase::kNoFlags,
59 HistogramBase::kNoFlags);
60 recorded_delta_histogram_names =
61 histogram_flattener_delta_recorder.GetRecordedDeltaHistogramNames();
62 EXPECT_EQ((unsigned)2, recorded_delta_histogram_names.size());
63 EXPECT_EQ("UmaHistogram", recorded_delta_histogram_names[0]);
64 EXPECT_EQ("UmaStabilityHistogram", recorded_delta_histogram_names[1]);
65 histogram_flattener_delta_recorder.ClearRecordedData();
Alexei Svitkine (slow) 2014/01/27 19:12:54 Instead of calling ClearRecordedData() after each
Kibeom Kim (inactive) 2014/01/29 01:52:32 Done.
66
67 // Record histograms that have kUmaTargetedHistogramFlag.
68 UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2);
69 UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2);
70 histogram_snapshot_manager.PrepareDeltas(
71 HistogramBase::kNoFlags, HistogramBase::kUmaTargetedHistogramFlag);
72 recorded_delta_histogram_names =
73 histogram_flattener_delta_recorder.GetRecordedDeltaHistogramNames();
74 EXPECT_EQ((unsigned)2, recorded_delta_histogram_names.size());
75 EXPECT_EQ("UmaHistogram", recorded_delta_histogram_names[0]);
76 EXPECT_EQ("UmaStabilityHistogram", recorded_delta_histogram_names[1]);
77 histogram_flattener_delta_recorder.ClearRecordedData();
78
79 // Record only histograms that have kStabilityHistogramFlag.
80 UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2);
81 UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2);
82 histogram_snapshot_manager.PrepareDeltas(
83 HistogramBase::kNoFlags, HistogramBase::kStabilityHistogramFlag);
84 recorded_delta_histogram_names =
85 histogram_flattener_delta_recorder.GetRecordedDeltaHistogramNames();
86 EXPECT_EQ((unsigned)1, recorded_delta_histogram_names.size());
87 EXPECT_EQ("UmaStabilityHistogram", recorded_delta_histogram_names[0]);
88 histogram_flattener_delta_recorder.ClearRecordedData();
89
90 // Record only histograms that have both kUmaTargetedHistogramFlag and
91 // kStabilityHistogramFlag.
92 UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2);
93 UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 1, 2);
94 histogram_snapshot_manager.PrepareDeltas(
95 HistogramBase::kNoFlags,
96 static_cast<HistogramBase::Flags>(
97 HistogramBase::kUmaTargetedHistogramFlag |
98 HistogramBase::kStabilityHistogramFlag));
99 recorded_delta_histogram_names =
100 histogram_flattener_delta_recorder.GetRecordedDeltaHistogramNames();
101 EXPECT_EQ((unsigned)1, recorded_delta_histogram_names.size());
102 EXPECT_EQ("UmaStabilityHistogram", recorded_delta_histogram_names[0]);
103 histogram_flattener_delta_recorder.ClearRecordedData();
104 }
105
106 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698