[M120 Migration][VD] Enable direct rendering for TVPlus
[platform/framework/web/chromium-efl.git] / components / metrics / histogram_encoder_unittest.cc
1 // Copyright 2014 The Chromium Authors
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/metrics/histogram_encoder.h"
6
7 #include <string>
8
9 #include "base/metrics/bucket_ranges.h"
10 #include "base/metrics/sample_vector.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace metrics {
14
15 TEST(HistogramEncoder, HistogramBucketFields) {
16   // Create buckets: 1-5, 5-7, 7-8, 8-9, 9-10, 10-11, 11-12.
17   base::BucketRanges ranges(8);
18   ranges.set_range(0, 1);
19   ranges.set_range(1, 5);
20   ranges.set_range(2, 7);
21   ranges.set_range(3, 8);
22   ranges.set_range(4, 9);
23   ranges.set_range(5, 10);
24   ranges.set_range(6, 11);
25   ranges.set_range(7, 12);
26
27   base::SampleVector samples(1, &ranges);
28   samples.Accumulate(3, 1);   // Bucket 1-5.
29   samples.Accumulate(6, 1);   // Bucket 5-7.
30   samples.Accumulate(8, 1);   // Bucket 8-9. (7-8 skipped)
31   samples.Accumulate(10, 1);  // Bucket 10-11. (9-10 skipped)
32   samples.Accumulate(11, 1);  // Bucket 11-12.
33
34   ChromeUserMetricsExtension uma_proto;
35   EncodeHistogramDelta("Test", samples, &uma_proto);
36
37   const HistogramEventProto& histogram_proto =
38       uma_proto.histogram_event(uma_proto.histogram_event_size() - 1);
39
40   // Buckets with samples: 1-5, 5-7, 8-9, 10-11, 11-12.
41   // Should become: 1-/, 5-7, /-9, 10-/, /-12.
42   ASSERT_EQ(5, histogram_proto.bucket_size());
43
44   // 1-5 becomes 1-/ (max is same as next min).
45   EXPECT_TRUE(histogram_proto.bucket(0).has_min());
46   EXPECT_FALSE(histogram_proto.bucket(0).has_max());
47   EXPECT_EQ(1, histogram_proto.bucket(0).min());
48
49   // 5-7 stays 5-7 (no optimization possible).
50   EXPECT_TRUE(histogram_proto.bucket(1).has_min());
51   EXPECT_TRUE(histogram_proto.bucket(1).has_max());
52   EXPECT_EQ(5, histogram_proto.bucket(1).min());
53   EXPECT_EQ(7, histogram_proto.bucket(1).max());
54
55   // 8-9 becomes /-9 (min is same as max - 1).
56   EXPECT_FALSE(histogram_proto.bucket(2).has_min());
57   EXPECT_TRUE(histogram_proto.bucket(2).has_max());
58   EXPECT_EQ(9, histogram_proto.bucket(2).max());
59
60   // 10-11 becomes 10-/ (both optimizations apply, omit max is prioritized).
61   EXPECT_TRUE(histogram_proto.bucket(3).has_min());
62   EXPECT_FALSE(histogram_proto.bucket(3).has_max());
63   EXPECT_EQ(10, histogram_proto.bucket(3).min());
64
65   // 11-12 becomes /-12 (last record must keep max, min is same as max - 1).
66   EXPECT_FALSE(histogram_proto.bucket(4).has_min());
67   EXPECT_TRUE(histogram_proto.bucket(4).has_max());
68   EXPECT_EQ(12, histogram_proto.bucket(4).max());
69 }
70
71 }  // namespace metrics