Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / cc / base / histograms_unittest.cc
blob19bdb09bd7b406d07b6fb50c37423fc3e573d489
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.
5 #include "cc/base/histograms.h"
7 #include <limits>
9 #include "testing/gtest/include/gtest/gtest.h"
11 using base::TimeDelta;
12 using Sample = base::HistogramBase::Sample;
14 namespace cc {
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);
31 namespace {
33 TEST_F(ScopedUMAHistogramAreaTimerBaseTest, CommonCase) {
34 ExpectValidHistogramValues(TimeDelta::FromMicroseconds(500), 1000, 500, 2000);
35 ExpectValidHistogramValues(TimeDelta::FromMicroseconds(300), 1000, 300, 3333);
38 TEST_F(ScopedUMAHistogramAreaTimerBaseTest, ZeroArea) {
39 ExpectValidHistogramValues(TimeDelta::FromMicroseconds(500), 0, 500, 0);
42 TEST_F(ScopedUMAHistogramAreaTimerBaseTest, ZeroTime) {
43 // 1M pixels/ms, since the time is limited to at least 1us.
44 ExpectValidHistogramValues(TimeDelta(), 1000, 1, 1000000);
47 TEST_F(ScopedUMAHistogramAreaTimerBaseTest, ZeroTimeAndArea) {
48 ExpectValidHistogramValues(TimeDelta(), 0, 1, 0);
51 TEST_F(ScopedUMAHistogramAreaTimerBaseTest, VeryLargeTime) {
52 ExpectValidHistogramValues(TimeDelta::FromHours(24), 1000,
53 std::numeric_limits<Sample>::max(), 0);
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());
64 } // namespace
65 } // namespace cc