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