OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 "cc/base/histograms.h" | |
6 | |
7 #include <limits> | |
8 | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 | |
11 using base::TimeDelta; | |
12 using Sample = base::HistogramBase::Sample; | |
13 | |
14 namespace cc { | |
15 | |
16 class ScopedUMAHistogramAreaTimerBaseTest : public ::testing::Test { | |
17 protected: | |
18 void ExpectValidHistogramValues(base::TimeDelta elapsed, | |
19 int area, | |
20 Sample expected_time_microseconds, | |
21 Sample expected_pixels_per_ms) { | |
22 Sample time_microseconds; | |
23 Sample pixels_per_ms; | |
24 ScopedUMAHistogramAreaTimerBase::GetHistogramValues( | |
25 elapsed, area, &time_microseconds, &pixels_per_ms); | |
26 EXPECT_EQ(expected_time_microseconds, time_microseconds); | |
27 EXPECT_EQ(expected_pixels_per_ms, pixels_per_ms); | |
28 } | |
29 }; | |
30 | |
31 namespace { | |
32 | |
33 TEST_F(ScopedUMAHistogramAreaTimerBaseTest, CommonCase) { | |
34 ExpectValidHistogramValues(TimeDelta::FromMicroseconds(500), 1000, 500, 2000); | |
35 ExpectValidHistogramValues(TimeDelta::FromMicroseconds(300), 1000, 300, 3333); | |
36 } | |
37 | |
38 TEST_F(ScopedUMAHistogramAreaTimerBaseTest, ZeroArea) { | |
39 ExpectValidHistogramValues(TimeDelta::FromMicroseconds(500), 0, 500, 0); | |
40 } | |
41 | |
42 TEST_F(ScopedUMAHistogramAreaTimerBaseTest, ZeroTime) { | |
43 // 1M pixels/ms, since the time is limited to at least 1us. | |
44 ExpectValidHistogramValues(TimeDelta(), 1000, 1, 1000000); | |
45 } | |
46 | |
47 TEST_F(ScopedUMAHistogramAreaTimerBaseTest, ZeroTimeAndArea) { | |
48 ExpectValidHistogramValues(TimeDelta(), 0, 1, 0); | |
49 } | |
50 | |
51 TEST_F(ScopedUMAHistogramAreaTimerBaseTest, VeryLargeTime) { | |
52 ExpectValidHistogramValues(TimeDelta::FromHours(24), 1000, | |
53 std::numeric_limits<Sample>::max(), 0); | |
54 } | |
55 | |
56 TEST_F(ScopedUMAHistogramAreaTimerBaseTest, VeryLargeArea) { | |
57 ExpectValidHistogramValues(TimeDelta::FromMicroseconds(500), 1000000000, 500, | |
58 2000000000); | |
59 ExpectValidHistogramValues(TimeDelta::FromMicroseconds(1000), | |
60 std::numeric_limits<int>::max(), 1000, | |
61 std::numeric_limits<Sample>::max()); | |
62 } | |
63 | |
64 } // namespace | |
65 } // namespace cc | |
OLD | NEW |