[M73 Dev][EFL] Disable VizDisplayCompositor for EFL port
[platform/framework/web/chromium-efl.git] / components / scheduling_metrics / total_duration_metric_reporter_unittest.cc
1 // Copyright 2018 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 "components/scheduling_metrics/total_duration_metric_reporter.h"
6 #include "base/test/metrics/histogram_tester.h"
7 #include "testing/gmock/include/gmock/gmock.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace scheduling_metrics {
11
12 TEST(TotalDurationMetricReporterTest, Test) {
13   base::HistogramTester histogram_tester;
14
15   TotalDurationMetricReporter metric_reporter("TestHistogram.Positive",
16                                               "TestHistogram.Negative");
17
18   metric_reporter.RecordAdditionalDuration(base::TimeDelta::FromSeconds(1));
19   metric_reporter.RecordAdditionalDuration(base::TimeDelta::FromSeconds(2));
20   metric_reporter.RecordAdditionalDuration(base::TimeDelta::FromSeconds(5));
21
22   metric_reporter.Reset();
23
24   metric_reporter.RecordAdditionalDuration(base::TimeDelta::FromSeconds(10));
25
26   std::map<base::Histogram::Sample, base::HistogramBase::Count> result;
27
28   for (const base::Bucket& bucket :
29        histogram_tester.GetAllSamples("TestHistogram.Positive")) {
30     result[bucket.min] += bucket.count;
31   }
32   for (const base::Bucket& bucket :
33        histogram_tester.GetAllSamples("TestHistogram.Negative")) {
34     result[bucket.min] -= bucket.count;
35   }
36
37   // 1 and 3 correspond to "reverted" values.
38   EXPECT_THAT(result, testing::UnorderedElementsAre(
39                           std::make_pair(1, 0), std::make_pair(3, 0),
40                           std::make_pair(8, 1), std::make_pair(10, 1)));
41 }
42
43 }  // namespace scheduling_metrics