OLD | NEW |
(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 // Record into a sample twice, once before the tester creation and once after. |
| 63 UMA_HISTOGRAM_COUNTS_100(kHistogram1, 2, 5); |
| 64 |
| 65 HistogramTester tester; |
| 66 UMA_HISTOGRAM_COUNTS_100(kHistogram1, 3, 1); |
| 67 |
| 68 tester.ExpectBucketCount(kHistogram1, 2, 0); |
| 69 tester.ExpectBucketCount(kHistogram1, 3, 1); |
| 70 |
| 71 tester.ExpectTotalCount(kHistogram1, 1); |
| 72 } |
| 73 |
| 74 } // namespace base |
OLD | NEW |