Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/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 public: | |
| 16 static void SetUpTestCase() { | |
| 17 StatisticsRecorder::Initialize(); | |
|
ppi
2014/01/03 12:21:10
We shouldn't do this - the singleton gets initiali
lpromero
2014/01/03 18:14:08
Done.
| |
| 18 } | |
| 19 | |
| 20 protected: | |
| 21 virtual void SetUp() { | |
| 22 // Each test will have a clean state (no Histogram / BucketRanges | |
| 23 // registered). | |
| 24 statistics_recorder_ = new StatisticsRecorder(); | |
| 25 } | |
| 26 | |
| 27 virtual void TearDown() { | |
| 28 delete statistics_recorder_; | |
| 29 statistics_recorder_ = NULL; | |
| 30 } | |
| 31 | |
| 32 StatisticsRecorder* statistics_recorder_; | |
| 33 }; | |
| 34 | |
| 35 TEST_F(StatisticsDeltaReaderTest, Scope) { | |
| 36 // Record a histogram before the creation of the recorder. | |
| 37 UMA_HISTOGRAM_BOOLEAN("Test", true); | |
| 38 | |
| 39 StatisticsDeltaReader reader; | |
| 40 | |
| 41 // Verify that no histogram is recorded. | |
| 42 scoped_ptr<HistogramSamples> samples( | |
| 43 reader.GetHistogramSamplesSinceCreation("Test")); | |
| 44 EXPECT_TRUE(samples); | |
| 45 EXPECT_EQ(0, samples->TotalCount()); | |
| 46 | |
| 47 // Record a histogram after the creation of the recorder. | |
| 48 UMA_HISTOGRAM_BOOLEAN("Test", true); | |
| 49 | |
| 50 // Verify that one histogram is recorded. | |
| 51 samples = reader.GetHistogramSamplesSinceCreation("Test"); | |
| 52 EXPECT_TRUE(samples); | |
| 53 EXPECT_EQ(1, samples->TotalCount()); | |
| 54 } | |
| 55 | |
| 56 } // namespace base | |
| OLD | NEW |