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