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

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: Ilya's initial comments Created 6 years, 5 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 TEST_F(HistogramTesterTest, Scope) {
19 // Record a histogram before the creation of the recorder.
20 UMA_HISTOGRAM_BOOLEAN(kHistogram1, true);
21
22 HistogramTester tester;
23
24 // Verify that no histogram is recorded.
25 scoped_ptr<HistogramSamples> samples(
26 tester.GetHistogramSamplesSinceCreation("Test"));
27 EXPECT_FALSE(samples);
28
29 // Record a histogram after the creation of the recorder.
30 UMA_HISTOGRAM_BOOLEAN(kHistogram1, true);
31
32 // Verify that one histogram is recorded.
33 samples = tester.GetHistogramSamplesSinceCreation("Test");
34 EXPECT_TRUE(samples);
35 EXPECT_EQ(1, samples->TotalCount());
36 }
37
38 TEST_F(HistogramTesterTest, TestUniqueSample) {
39 HistogramTester tester;
40
41 // Record into a sample twice
42 UMA_HISTOGRAM_COUNTS_100(kHistogram1, 2, 2);
43 UMA_HISTOGRAM_COUNTS_100(kHistogram1, 2, 1);
44
45 tester.ExpectUniqueSample(kHistogram1, 2, 3);
46 }
47
48 TEST_F(HistogramTesterTest, TestBucketsSample) {
49 HistogramTester tester;
50
51 // Record into a sample twice
52 UMA_HISTOGRAM_COUNTS_100(kHistogram1, 2, 5);
53 UMA_HISTOGRAM_COUNTS_100(kHistogram1, 3, 1);
54
55 tester.ExpectBucketCount(kHistogram1, 2, 5);
56 tester.ExpectBucketCount(kHistogram1, 3, 1);
57
58 tester.ExpectTotalCount(kHistogram1, 6);
59 }
60
61 TEST_F(HistogramTesterTest, TestBucketsSampleWithScope) {
62
Ilya Sherman 2014/07/16 18:44:46 nit: Spurious newline
Mike Lerman 2014/07/16 19:36:36 Done.
63 // Record into a sample twice, once before the tester creation and once after.
64 UMA_HISTOGRAM_COUNTS_100(kHistogram1, 2, 5);
65
66 HistogramTester tester;
67 UMA_HISTOGRAM_COUNTS_100(kHistogram1, 3, 1);
68
69 tester.ExpectBucketCount(kHistogram1, 2, 0);
70 tester.ExpectBucketCount(kHistogram1, 3, 1);
71
72 tester.ExpectTotalCount(kHistogram1, 1);
73 }
74
75 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698