| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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 "platform/Histogram.h" |
| 6 |
| 7 #include "base/metrics/histogram_samples.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 namespace blink { |
| 11 |
| 12 class ScopedUsHistogramTimerTest : public ::testing::Test { |
| 13 public: |
| 14 static void advanceClock(double microseconds) |
| 15 { |
| 16 s_timeElapsed += microseconds; |
| 17 } |
| 18 |
| 19 protected: |
| 20 static double returnMockTime() |
| 21 { |
| 22 return s_timeElapsed; |
| 23 } |
| 24 |
| 25 virtual void SetUp() |
| 26 { |
| 27 s_timeElapsed = 0.0; |
| 28 m_originalTimeFunction = setTimeFunctionsForTesting(returnMockTime); |
| 29 } |
| 30 |
| 31 virtual void TearDown() |
| 32 { |
| 33 setTimeFunctionsForTesting(m_originalTimeFunction); |
| 34 } |
| 35 |
| 36 private: |
| 37 static double s_timeElapsed; |
| 38 TimeFunction m_originalTimeFunction; |
| 39 }; |
| 40 |
| 41 double ScopedUsHistogramTimerTest::s_timeElapsed; |
| 42 |
| 43 class TestCustomCountHistogram : public CustomCountHistogram { |
| 44 public: |
| 45 TestCustomCountHistogram(const char* name, base::HistogramBase::Sample min,
base::HistogramBase::Sample max, int32_t bucketCount) |
| 46 : CustomCountHistogram(name, min, max, bucketCount) {} |
| 47 |
| 48 base::HistogramBase* histogram() { return m_histogram; } |
| 49 }; |
| 50 |
| 51 TEST_F(ScopedUsHistogramTimerTest, Basic) |
| 52 { |
| 53 TestCustomCountHistogram scopedUsCounter("test", 0, 10000000, 50); |
| 54 { |
| 55 ScopedUsHistogramTimer timer(scopedUsCounter); |
| 56 advanceClock(0.5); |
| 57 } |
| 58 // 0.5s == 500000us |
| 59 EXPECT_EQ(500000, scopedUsCounter.histogram()->SnapshotSamples()->sum()); |
| 60 } |
| 61 |
| 62 } // namespace blink |
| OLD | NEW |