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

Side by Side Diff: third_party/WebKit/Source/platform/HistogramTest.cpp

Issue 1936853002: Assert event timestamp to be monotonic and not from future Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change to histogram Created 4 years, 2 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/Histogram.h" 5 #include "platform/Histogram.h"
6 6
7 #include "base/metrics/histogram_samples.h" 7 #include "base/metrics/histogram_samples.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace blink { 10 namespace blink {
11 11
12 class ScopedUsHistogramTimerTest : public ::testing::Test { 12 class ScopedUsHistogramTimerTest : public ::testing::Test {
13 public: 13 public:
14 static void advanceClock(double microseconds) 14 static void advanceClock(double microseconds)
15 { 15 {
16 s_timeElapsed += microseconds; 16 s_timeElapsed += microseconds;
17 } 17 }
18 18
19 protected: 19 protected:
20 static double returnMockTime() 20 static double returnMockTime()
21 { 21 {
22 return s_timeElapsed; 22 return s_timeElapsed;
23 } 23 }
24 24
25 virtual void SetUp() 25 virtual void SetUp()
26 { 26 {
27 s_timeElapsed = 0.0; 27 s_timeElapsed = 0.0;
28 m_originalTimeFunction = setTimeFunctionsForTesting(returnMockTime); 28 m_originalMonotonicTimeFunction = setMonotonicallyIncreasingTimeFunction ForTesting(returnMockTime);
29 m_originalCurrentTimeFunction = setCurrentTimeFunctionForTesting(returnM ockTime);
29 } 30 }
30 31
31 virtual void TearDown() 32 virtual void TearDown()
32 { 33 {
33 setTimeFunctionsForTesting(m_originalTimeFunction); 34 setMonotonicallyIncreasingTimeFunctionForTesting(m_originalMonotonicTime Function);
35 setCurrentTimeFunctionForTesting(m_originalCurrentTimeFunction);
34 } 36 }
35 37
36 private: 38 private:
37 static double s_timeElapsed; 39 static double s_timeElapsed;
38 TimeFunction m_originalTimeFunction; 40 TimeFunction m_originalMonotonicTimeFunction;
41 TimeFunction m_originalCurrentTimeFunction;
39 }; 42 };
40 43
41 double ScopedUsHistogramTimerTest::s_timeElapsed; 44 double ScopedUsHistogramTimerTest::s_timeElapsed;
42 45
43 class TestCustomCountHistogram : public CustomCountHistogram { 46 class TestCustomCountHistogram : public CustomCountHistogram {
44 public: 47 public:
45 TestCustomCountHistogram(const char* name, base::HistogramBase::Sample min, base::HistogramBase::Sample max, int32_t bucketCount) 48 TestCustomCountHistogram(const char* name, base::HistogramBase::Sample min, base::HistogramBase::Sample max, int32_t bucketCount)
46 : CustomCountHistogram(name, min, max, bucketCount) {} 49 : CustomCountHistogram(name, min, max, bucketCount) {}
47 50
48 base::HistogramBase* histogram() { return m_histogram; } 51 base::HistogramBase* histogram() { return m_histogram; }
49 }; 52 };
50 53
51 TEST_F(ScopedUsHistogramTimerTest, Basic) 54 TEST_F(ScopedUsHistogramTimerTest, Basic)
52 { 55 {
53 TestCustomCountHistogram scopedUsCounter("test", 0, 10000000, 50); 56 TestCustomCountHistogram scopedUsCounter("test", 0, 10000000, 50);
54 { 57 {
55 ScopedUsHistogramTimer timer(scopedUsCounter); 58 ScopedUsHistogramTimer timer(scopedUsCounter);
56 advanceClock(0.5); 59 advanceClock(0.5);
57 } 60 }
58 // 0.5s == 500000us 61 // 0.5s == 500000us
59 EXPECT_EQ(500000, scopedUsCounter.histogram()->SnapshotSamples()->sum()); 62 EXPECT_EQ(500000, scopedUsCounter.histogram()->SnapshotSamples()->sum());
60 } 63 }
61 64
62 } // namespace blink 65 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698