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/memory/scoped_ptr.h" |
| 6 #include "base/metrics/histogram.h" |
| 7 #include "base/metrics/histogram_samples.h" |
| 8 #include "base/metrics/statistics_recorder.h" |
| 9 #include "base/test/statistics_delta_reader.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace base { |
| 13 |
| 14 class StatisticsDeltaReaderTest : public testing::Test { |
| 15 protected: |
| 16 virtual void SetUp() OVERRIDE { |
| 17 // Each test will have a clean state (no Histogram / BucketRanges |
| 18 // registered). |
| 19 statistics_recorder_ = new StatisticsRecorder(); |
| 20 } |
| 21 |
| 22 virtual void TearDown() OVERRIDE { |
| 23 delete statistics_recorder_; |
| 24 statistics_recorder_ = NULL; |
| 25 } |
| 26 |
| 27 StatisticsRecorder* statistics_recorder_; |
| 28 }; |
| 29 |
| 30 TEST_F(StatisticsDeltaReaderTest, Scope) { |
| 31 // Record a histogram before the creation of the recorder. |
| 32 UMA_HISTOGRAM_BOOLEAN("Test", true); |
| 33 |
| 34 StatisticsDeltaReader reader; |
| 35 |
| 36 // Verify that no histogram is recorded. |
| 37 scoped_ptr<HistogramSamples> samples( |
| 38 reader.GetHistogramSamplesSinceCreation("Test")); |
| 39 EXPECT_TRUE(samples); |
| 40 EXPECT_EQ(0, samples->TotalCount()); |
| 41 |
| 42 // Record a histogram after the creation of the recorder. |
| 43 UMA_HISTOGRAM_BOOLEAN("Test", true); |
| 44 |
| 45 // Verify that one histogram is recorded. |
| 46 samples = reader.GetHistogramSamplesSinceCreation("Test"); |
| 47 EXPECT_TRUE(samples); |
| 48 EXPECT_EQ(1, samples->TotalCount()); |
| 49 } |
| 50 |
| 51 } // namespace base |
OLD | NEW |