| 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/cronet/histogram_manager.h" | 5 #include "components/cronet/histogram_manager.h" |
| 6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 7 #include <string> | 9 #include <string> |
| 8 | 10 |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/metrics/statistics_recorder.h" | 11 #include "base/metrics/statistics_recorder.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 namespace cronet { | 14 namespace cronet { |
| 14 | 15 |
| 15 using metrics::ChromeUserMetricsExtension; | 16 using metrics::ChromeUserMetricsExtension; |
| 16 using metrics::HistogramEventProto; | 17 using metrics::HistogramEventProto; |
| 17 | 18 |
| 18 TEST(HistogramManager, HistogramBucketFields) { | 19 TEST(HistogramManager, HistogramBucketFields) { |
| 19 base::StatisticsRecorder::Initialize(); | 20 base::StatisticsRecorder::Initialize(); |
| 20 // Capture histograms at the start of the test to avoid later GetDeltas() | 21 // Capture histograms at the start of the test to avoid later GetDeltas() |
| 21 // calls picking them up. | 22 // calls picking them up. |
| 22 std::vector<uint8> data_init; | 23 std::vector<uint8_t> data_init; |
| 23 HistogramManager::GetInstance()->GetDeltas(&data_init); | 24 HistogramManager::GetInstance()->GetDeltas(&data_init); |
| 24 | 25 |
| 25 // kNoFlags filter should record all histograms. | 26 // kNoFlags filter should record all histograms. |
| 26 UMA_HISTOGRAM_ENUMERATION("UmaHistogramManager", 1, 2); | 27 UMA_HISTOGRAM_ENUMERATION("UmaHistogramManager", 1, 2); |
| 27 | 28 |
| 28 std::vector<uint8> data; | 29 std::vector<uint8_t> data; |
| 29 EXPECT_TRUE(HistogramManager::GetInstance()->GetDeltas(&data)); | 30 EXPECT_TRUE(HistogramManager::GetInstance()->GetDeltas(&data)); |
| 30 EXPECT_FALSE(data.empty()); | 31 EXPECT_FALSE(data.empty()); |
| 31 ChromeUserMetricsExtension uma_proto; | 32 ChromeUserMetricsExtension uma_proto; |
| 32 EXPECT_TRUE(uma_proto.ParseFromArray( | 33 EXPECT_TRUE(uma_proto.ParseFromArray( |
| 33 reinterpret_cast<const char*>(&data[0]), data.size())); | 34 reinterpret_cast<const char*>(&data[0]), data.size())); |
| 34 EXPECT_FALSE(data.empty()); | 35 EXPECT_FALSE(data.empty()); |
| 35 | 36 |
| 36 const HistogramEventProto& histogram_proto = | 37 const HistogramEventProto& histogram_proto = |
| 37 uma_proto.histogram_event(uma_proto.histogram_event_size() - 1); | 38 uma_proto.histogram_event(uma_proto.histogram_event_size() - 1); |
| 38 ASSERT_EQ(1, histogram_proto.bucket_size()); | 39 ASSERT_EQ(1, histogram_proto.bucket_size()); |
| 39 EXPECT_LE(0, histogram_proto.bucket(0).min()); | 40 EXPECT_LE(0, histogram_proto.bucket(0).min()); |
| 40 EXPECT_LE(2, histogram_proto.bucket(0).max()); | 41 EXPECT_LE(2, histogram_proto.bucket(0).max()); |
| 41 EXPECT_EQ(1, histogram_proto.bucket(0).count()); | 42 EXPECT_EQ(1, histogram_proto.bucket(0).count()); |
| 42 | 43 |
| 43 UMA_HISTOGRAM_ENUMERATION("UmaHistogramManager2", 2, 3); | 44 UMA_HISTOGRAM_ENUMERATION("UmaHistogramManager2", 2, 3); |
| 44 std::vector<uint8> data2; | 45 std::vector<uint8_t> data2; |
| 45 EXPECT_TRUE(HistogramManager::GetInstance()->GetDeltas(&data2)); | 46 EXPECT_TRUE(HistogramManager::GetInstance()->GetDeltas(&data2)); |
| 46 EXPECT_FALSE(data2.empty()); | 47 EXPECT_FALSE(data2.empty()); |
| 47 ChromeUserMetricsExtension uma_proto2; | 48 ChromeUserMetricsExtension uma_proto2; |
| 48 EXPECT_TRUE(uma_proto2.ParseFromArray( | 49 EXPECT_TRUE(uma_proto2.ParseFromArray( |
| 49 reinterpret_cast<const char*>(&data2[0]), data2.size())); | 50 reinterpret_cast<const char*>(&data2[0]), data2.size())); |
| 50 EXPECT_FALSE(data2.empty()); | 51 EXPECT_FALSE(data2.empty()); |
| 51 | 52 |
| 52 const HistogramEventProto& histogram_proto2 = | 53 const HistogramEventProto& histogram_proto2 = |
| 53 uma_proto2.histogram_event(uma_proto2.histogram_event_size() - 1); | 54 uma_proto2.histogram_event(uma_proto2.histogram_event_size() - 1); |
| 54 ASSERT_EQ(1, histogram_proto2.bucket_size()); | 55 ASSERT_EQ(1, histogram_proto2.bucket_size()); |
| 55 EXPECT_LE(0, histogram_proto2.bucket(0).min()); | 56 EXPECT_LE(0, histogram_proto2.bucket(0).min()); |
| 56 EXPECT_LE(3, histogram_proto2.bucket(0).max()); | 57 EXPECT_LE(3, histogram_proto2.bucket(0).max()); |
| 57 EXPECT_EQ(1, histogram_proto2.bucket(0).count()); | 58 EXPECT_EQ(1, histogram_proto2.bucket(0).count()); |
| 58 } | 59 } |
| 59 | 60 |
| 60 } // namespace cronet | 61 } // namespace cronet |
| OLD | NEW |