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

Side by Side Diff: base/test/histogram_tester_unittest.cc

Issue 379283002: Rework UMAHistogramHelper and StatisticsDeltaReader into [Chrome]HistogramTester. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ChromeOS tests Created 6 years, 4 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 | Annotate | Revision Log
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/test/histogram_tester.h"
6
7 #include "base/memory/scoped_ptr.h"
8 #include "base/metrics/histogram.h"
9 #include "base/metrics/histogram_samples.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace base {
13
14 const std::string kHistogram1 = "Test1";
15 const std::string kHistogram2 = "Test2";
16 const std::string kHistogram3 = "Test3";
17
18 typedef testing::Test HistogramTesterTest;
19
20 TEST_F(HistogramTesterTest, Scope) {
21 // Record a histogram before the creation of the recorder.
22 UMA_HISTOGRAM_BOOLEAN(kHistogram1, true);
23
24 HistogramTester tester;
25
26 // Verify that no histogram is recorded.
27 scoped_ptr<HistogramSamples> samples(
28 tester.GetHistogramSamplesSinceCreation(kHistogram1));
29 EXPECT_FALSE(samples);
30
31 // Record a histogram after the creation of the recorder.
32 UMA_HISTOGRAM_BOOLEAN(kHistogram1, true);
33
34 // Verify that one histogram is recorded.
35 samples = tester.GetHistogramSamplesSinceCreation(kHistogram1);
36 EXPECT_TRUE(samples);
37 EXPECT_EQ(1, samples->TotalCount());
38 }
39
40 TEST_F(HistogramTesterTest, TestUniqueSample) {
41 HistogramTester tester;
42
43 // Record into a sample thrice
44 UMA_HISTOGRAM_COUNTS_100(kHistogram1, 2);
45 UMA_HISTOGRAM_COUNTS_100(kHistogram1, 2);
46 UMA_HISTOGRAM_COUNTS_100(kHistogram1, 2);
47
48 tester.ExpectUniqueSample(kHistogram1, 2, 3);
49 }
50
51 TEST_F(HistogramTesterTest, TestBucketsSample) {
52 HistogramTester tester;
53
54 // Record into a sample twice
55 UMA_HISTOGRAM_COUNTS_100(kHistogram1, 2);
56 UMA_HISTOGRAM_COUNTS_100(kHistogram1, 2);
57 UMA_HISTOGRAM_COUNTS_100(kHistogram1, 2);
58 UMA_HISTOGRAM_COUNTS_100(kHistogram1, 2);
59 UMA_HISTOGRAM_COUNTS_100(kHistogram1, 3);
60
61 tester.ExpectBucketCount(kHistogram1, 2, 4);
62 tester.ExpectBucketCount(kHistogram1, 3, 1);
63
64 tester.ExpectTotalCount(kHistogram1, 6);
65 }
66
67 TEST_F(HistogramTesterTest, TestBucketsSampleWithScope) {
68 // Record into a sample twice, once before the tester creation and once after.
69 UMA_HISTOGRAM_COUNTS_100(kHistogram1, 2);
70
71 HistogramTester tester;
72 UMA_HISTOGRAM_COUNTS_100(kHistogram1, 3);
73
74 tester.ExpectBucketCount(kHistogram1, 2, 0);
75 tester.ExpectBucketCount(kHistogram1, 3, 1);
76
77 tester.ExpectTotalCount(kHistogram1, 1);
78 }
79
80 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698