Chromium Code Reviews| 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_manager.h" | 5 #include "components/cronet/histogram_manager.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/statistics_recorder.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 namespace metrics { | 13 namespace cronet { |
| 13 | 14 |
| 14 // TODO(mef): crbug.com/441441. Move components/metrics/histogram_manager.* | 15 using metrics::ChromeUserMetricsExtension; |
| 15 // files into components/android/cronet. | 16 using metrics::HistogramEventProto; |
| 17 | |
| 16 // TODO(rtenneti): enable flaky HistogramBucketFields unit test. | 18 // TODO(rtenneti): enable flaky HistogramBucketFields unit test. |
| 17 TEST(HistogramManager, DISABLED_HistogramBucketFields) { | 19 TEST(HistogramManager, HistogramBucketFields) { |
| 20 base::StatisticsRecorder::Initialize(); | |
| 18 // 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() |
| 19 // calls picking them up. | 22 // calls picking them up. |
| 20 std::vector<uint8> data_init; | 23 std::vector<uint8> data_init; |
| 21 HistogramManager::GetInstance()->GetDeltas(&data_init); | 24 HistogramManager::GetInstance()->GetDeltas(&data_init); |
| 22 | 25 |
| 23 // kNoFlags filter should record all histograms. | 26 // kNoFlags filter should record all histograms. |
| 24 UMA_HISTOGRAM_ENUMERATION("UmaHistogramManager", 1, 2); | 27 UMA_HISTOGRAM_ENUMERATION("UmaHistogramManager", 1, 2); |
| 25 | 28 |
| 26 std::vector<uint8> data; | 29 std::vector<uint8> data; |
| 27 EXPECT_TRUE(HistogramManager::GetInstance()->GetDeltas(&data)); | 30 EXPECT_TRUE(HistogramManager::GetInstance()->GetDeltas(&data)); |
| 28 EXPECT_FALSE(data.empty()); | 31 EXPECT_FALSE(data.empty()); |
| 29 ChromeUserMetricsExtension uma_proto; | 32 ChromeUserMetricsExtension uma_proto; |
| 30 EXPECT_TRUE(uma_proto.ParseFromArray( | 33 EXPECT_TRUE(uma_proto.ParseFromArray( |
| 31 reinterpret_cast<const char*>(&data[0]), data.size())); | 34 reinterpret_cast<const char*>(&data[0]), data.size())); |
| 32 EXPECT_FALSE(data.empty()); | 35 EXPECT_FALSE(data.empty()); |
| 33 | 36 |
| 34 const HistogramEventProto& histogram_proto = | 37 const HistogramEventProto& histogram_proto = |
| 35 uma_proto.histogram_event(uma_proto.histogram_event_size() - 1); | 38 uma_proto.histogram_event(uma_proto.histogram_event_size() - 1); |
| 36 ASSERT_EQ(1, histogram_proto.bucket_size()); | 39 ASSERT_EQ(1, histogram_proto.bucket_size()); |
| 37 EXPECT_LE(0, histogram_proto.bucket(0).min()); | 40 EXPECT_LE(0, histogram_proto.bucket(0).min()); |
| 38 EXPECT_LE(2, histogram_proto.bucket(0).max()); | 41 EXPECT_LE(2, histogram_proto.bucket(0).max()); |
| 39 EXPECT_EQ(1, histogram_proto.bucket(0).count()); | 42 EXPECT_EQ(1, histogram_proto.bucket(0).count()); |
| 40 | 43 |
| 41 UMA_HISTOGRAM_ENUMERATION("UmaHistogramManager2", 2, 3); | 44 UMA_HISTOGRAM_ENUMERATION("UmaHistogramManager2", 2, 3); |
| 42 std::vector<uint8> data2; | 45 std::vector<uint8> data2; |
| 43 EXPECT_TRUE(HistogramManager::GetInstance()->GetDeltas(&data2)); | 46 EXPECT_TRUE(HistogramManager::GetInstance()->GetDeltas(&data2)); |
| 44 EXPECT_FALSE(data2.empty()); | 47 EXPECT_FALSE(data2.empty()); |
| 45 ChromeUserMetricsExtension uma_proto2; | 48 metrics::ChromeUserMetricsExtension uma_proto2; |
|
xunjieli
2015/04/08 21:30:51
nit: You already have "using" for this on line 15.
mef
2015/04/08 21:41:21
Oops, I've started adding those, but decided to go
| |
| 46 EXPECT_TRUE(uma_proto2.ParseFromArray( | 49 EXPECT_TRUE(uma_proto2.ParseFromArray( |
| 47 reinterpret_cast<const char*>(&data2[0]), data2.size())); | 50 reinterpret_cast<const char*>(&data2[0]), data2.size())); |
| 48 EXPECT_FALSE(data2.empty()); | 51 EXPECT_FALSE(data2.empty()); |
| 49 | 52 |
| 50 const HistogramEventProto& histogram_proto2 = | 53 const HistogramEventProto& histogram_proto2 = |
| 51 uma_proto2.histogram_event(uma_proto2.histogram_event_size() - 1); | 54 uma_proto2.histogram_event(uma_proto2.histogram_event_size() - 1); |
| 52 ASSERT_EQ(1, histogram_proto2.bucket_size()); | 55 ASSERT_EQ(1, histogram_proto2.bucket_size()); |
| 53 EXPECT_LE(0, histogram_proto2.bucket(0).min()); | 56 EXPECT_LE(0, histogram_proto2.bucket(0).min()); |
| 54 EXPECT_LE(3, histogram_proto2.bucket(0).max()); | 57 EXPECT_LE(3, histogram_proto2.bucket(0).max()); |
| 55 EXPECT_EQ(1, histogram_proto2.bucket(0).count()); | 58 EXPECT_EQ(1, histogram_proto2.bucket(0).count()); |
| 56 } | 59 } |
| 57 | 60 |
| 58 } // namespace metrics | 61 } // namespace cronet |
| OLD | NEW |