blob: af599e704a0df6135f7e48b5359e34ef9a52fcb7 [file] [log] [blame]
rtenneti72546962014-12-15 21:41:591// 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
mefc2bd1aa2015-04-09 03:26:535#include "components/cronet/histogram_manager.h"
rtenneti72546962014-12-15 21:41:596
avibc5337b2015-12-25 23:16:337#include <stdint.h>
8
rtenneti72546962014-12-15 21:41:599#include <string>
10
asvitkine8341e9072017-01-20 01:27:1611#include "base/metrics/histogram_macros.h"
mefc2bd1aa2015-04-09 03:26:5312#include "base/metrics/statistics_recorder.h"
rtenneti72546962014-12-15 21:41:5913#include "testing/gtest/include/gtest/gtest.h"
14
mefc2bd1aa2015-04-09 03:26:5315namespace cronet {
rtenneti72546962014-12-15 21:41:5916
mefc2bd1aa2015-04-09 03:26:5317using metrics::ChromeUserMetricsExtension;
18using metrics::HistogramEventProto;
19
20TEST(HistogramManager, HistogramBucketFields) {
21 base::StatisticsRecorder::Initialize();
rtenneti72546962014-12-15 21:41:5922 // Capture histograms at the start of the test to avoid later GetDeltas()
23 // calls picking them up.
avibc5337b2015-12-25 23:16:3324 std::vector<uint8_t> data_init;
rtenneti72546962014-12-15 21:41:5925 HistogramManager::GetInstance()->GetDeltas(&data_init);
26
27 // kNoFlags filter should record all histograms.
28 UMA_HISTOGRAM_ENUMERATION("UmaHistogramManager", 1, 2);
29
avibc5337b2015-12-25 23:16:3330 std::vector<uint8_t> data;
rtenneti72546962014-12-15 21:41:5931 EXPECT_TRUE(HistogramManager::GetInstance()->GetDeltas(&data));
32 EXPECT_FALSE(data.empty());
33 ChromeUserMetricsExtension uma_proto;
34 EXPECT_TRUE(uma_proto.ParseFromArray(
35 reinterpret_cast<const char*>(&data[0]), data.size()));
36 EXPECT_FALSE(data.empty());
37
38 const HistogramEventProto& histogram_proto =
39 uma_proto.histogram_event(uma_proto.histogram_event_size() - 1);
40 ASSERT_EQ(1, histogram_proto.bucket_size());
41 EXPECT_LE(0, histogram_proto.bucket(0).min());
42 EXPECT_LE(2, histogram_proto.bucket(0).max());
43 EXPECT_EQ(1, histogram_proto.bucket(0).count());
44
45 UMA_HISTOGRAM_ENUMERATION("UmaHistogramManager2", 2, 3);
avibc5337b2015-12-25 23:16:3346 std::vector<uint8_t> data2;
rtenneti72546962014-12-15 21:41:5947 EXPECT_TRUE(HistogramManager::GetInstance()->GetDeltas(&data2));
48 EXPECT_FALSE(data2.empty());
49 ChromeUserMetricsExtension uma_proto2;
50 EXPECT_TRUE(uma_proto2.ParseFromArray(
51 reinterpret_cast<const char*>(&data2[0]), data2.size()));
52 EXPECT_FALSE(data2.empty());
53
54 const HistogramEventProto& histogram_proto2 =
55 uma_proto2.histogram_event(uma_proto2.histogram_event_size() - 1);
56 ASSERT_EQ(1, histogram_proto2.bucket_size());
57 EXPECT_LE(0, histogram_proto2.bucket(0).min());
58 EXPECT_LE(3, histogram_proto2.bucket(0).max());
59 EXPECT_EQ(1, histogram_proto2.bucket(0).count());
60}
61
mefc2bd1aa2015-04-09 03:26:5362} // namespace cronet