| OLD | NEW | 
|   1 // Copyright 2014 The Chromium Authors. All rights reserved. |   1 // Copyright 2014 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 "components/metrics/histogram_encoder.h" |   5 #include "components/metrics/histogram_encoder.h" | 
|   6  |   6  | 
|   7 #include <string> |   7 #include <string> | 
|   8  |   8  | 
|   9 #include "base/basictypes.h" |   9 #include "base/basictypes.h" | 
|  10 #include "base/metrics/bucket_ranges.h" |  10 #include "base/metrics/bucket_ranges.h" | 
|  11 #include "base/metrics/sample_vector.h" |  11 #include "base/metrics/sample_vector.h" | 
|  12 #include "testing/gtest/include/gtest/gtest.h" |  12 #include "testing/gtest/include/gtest/gtest.h" | 
|  13  |  13  | 
|  14 namespace metrics { |  14 namespace metrics { | 
|  15  |  15  | 
|  16 TEST(HistogramEncoder, HistogramBucketFields) { |  16 TEST(HistogramEncoder, HistogramBucketFields) { | 
|  17   // Create buckets: 1-5, 5-7, 7-8, 8-9, 9-10, 10-11, 11-12. |  17   // Create buckets: 1-5, 5-7, 7-8, 8-9, 9-10, 10-11, 11-12. | 
|  18   base::BucketRanges ranges(8); |  18   base::BucketRanges ranges(8); | 
|  19   ranges.set_range(0, 1); |  19   ranges.set_range(0, 1); | 
|  20   ranges.set_range(1, 5); |  20   ranges.set_range(1, 5); | 
|  21   ranges.set_range(2, 7); |  21   ranges.set_range(2, 7); | 
|  22   ranges.set_range(3, 8); |  22   ranges.set_range(3, 8); | 
|  23   ranges.set_range(4, 9); |  23   ranges.set_range(4, 9); | 
|  24   ranges.set_range(5, 10); |  24   ranges.set_range(5, 10); | 
|  25   ranges.set_range(6, 11); |  25   ranges.set_range(6, 11); | 
|  26   ranges.set_range(7, 12); |  26   ranges.set_range(7, 12); | 
|  27  |  27  | 
|  28   base::SampleVector samples(&ranges); |  28   base::SampleVector samples(1, &ranges); | 
|  29   samples.Accumulate(3, 1);   // Bucket 1-5. |  29   samples.Accumulate(3, 1);   // Bucket 1-5. | 
|  30   samples.Accumulate(6, 1);   // Bucket 5-7. |  30   samples.Accumulate(6, 1);   // Bucket 5-7. | 
|  31   samples.Accumulate(8, 1);   // Bucket 8-9. (7-8 skipped) |  31   samples.Accumulate(8, 1);   // Bucket 8-9. (7-8 skipped) | 
|  32   samples.Accumulate(10, 1);  // Bucket 10-11. (9-10 skipped) |  32   samples.Accumulate(10, 1);  // Bucket 10-11. (9-10 skipped) | 
|  33   samples.Accumulate(11, 1);  // Bucket 11-12. |  33   samples.Accumulate(11, 1);  // Bucket 11-12. | 
|  34  |  34  | 
|  35   ChromeUserMetricsExtension uma_proto; |  35   ChromeUserMetricsExtension uma_proto; | 
|  36   EncodeHistogramDelta("Test", samples, &uma_proto); |  36   EncodeHistogramDelta("Test", samples, &uma_proto); | 
|  37  |  37  | 
|  38   const HistogramEventProto& histogram_proto = |  38   const HistogramEventProto& histogram_proto = | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
|  63   EXPECT_FALSE(histogram_proto.bucket(3).has_max()); |  63   EXPECT_FALSE(histogram_proto.bucket(3).has_max()); | 
|  64   EXPECT_EQ(10, histogram_proto.bucket(3).min()); |  64   EXPECT_EQ(10, histogram_proto.bucket(3).min()); | 
|  65  |  65  | 
|  66   // 11-12 becomes /-12 (last record must keep max, min is same as max - 1). |  66   // 11-12 becomes /-12 (last record must keep max, min is same as max - 1). | 
|  67   EXPECT_FALSE(histogram_proto.bucket(4).has_min()); |  67   EXPECT_FALSE(histogram_proto.bucket(4).has_min()); | 
|  68   EXPECT_TRUE(histogram_proto.bucket(4).has_max()); |  68   EXPECT_TRUE(histogram_proto.bucket(4).has_max()); | 
|  69   EXPECT_EQ(12, histogram_proto.bucket(4).max()); |  69   EXPECT_EQ(12, histogram_proto.bucket(4).max()); | 
|  70 } |  70 } | 
|  71  |  71  | 
|  72 }  // namespace metrics |  72 }  // namespace metrics | 
| OLD | NEW |