Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Unified Diff: components/cronet/android/histogram_manager_unittest.cc

Issue 794493002: Add UMA Histogram Manager to Cronet. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added end to end unittest Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/cronet/android/histogram_manager_unittest.cc
diff --git a/components/cronet/android/histogram_manager_unittest.cc b/components/cronet/android/histogram_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..54aee4737c7a0def7844d66ec1fff2da017f9ab5
--- /dev/null
+++ b/components/cronet/android/histogram_manager_unittest.cc
@@ -0,0 +1,66 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/cronet/android/histogram_manager.h"
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/metrics/histogram.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace cronet {
+
+namespace {
+
+class HistogramManagerTest : public testing::Test {
Alexei Svitkine (slow) 2014/12/11 15:38:58 If this class doesn't have anything in it, you can
ramant (doing other things) 2014/12/11 20:23:53 Done.
+ public:
+ HistogramManagerTest() {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(HistogramManagerTest);
+};
+
+} // namespace
+
+using metrics::ChromeUserMetricsExtension;
+using metrics::HistogramEventProto;
Alexei Svitkine (slow) 2014/12/11 15:38:58 Nit: I prefer not having using statements and just
ramant (doing other things) 2014/12/11 20:23:53 Done.
+
+TEST_F(HistogramManagerTest, HistogramBucketFields) {
ramant (doing other things) 2014/12/11 02:21:53 Tested this code by moving all HistogramManager.*
mef 2014/12/11 15:35:40 sgtm. I like making Java wrapper as thin as possib
Alexei Svitkine (slow) 2014/12/11 15:38:58 My preference is to keep this in the cronet compon
ramant (doing other things) 2014/12/11 20:23:53 Acknowledged.
ramant (doing other things) 2014/12/11 20:23:53 Done.
+ // kNoFlags filter should record all histograms.
+ UMA_HISTOGRAM_ENUMERATION("UmaHistogram", 1, 2);
+
+ ChromeUserMetricsExtension uma_proto;
+
+ std::vector<uint8> data = HistogramManager::GetInstance()->GetDeltas();
+ uma_proto.ParseFromArray(data.data(), data.size());
+ EXPECT_LT(0u, data.size());
Alexei Svitkine (slow) 2014/12/11 15:38:58 Shouldn't this expect be before ParseFromArray()?
ramant (doing other things) 2014/12/11 20:23:53 Done.
+
+ const HistogramEventProto& histogram_proto =
+ uma_proto.histogram_event(uma_proto.histogram_event_size() - 1);
+ ASSERT_EQ(1, histogram_proto.bucket_size());
+ EXPECT_FALSE(histogram_proto.bucket(0).has_min());
+ EXPECT_TRUE(histogram_proto.bucket(0).has_max());
+ EXPECT_EQ(0, histogram_proto.bucket(0).min());
+ EXPECT_EQ(2, histogram_proto.bucket(0).max());
+ EXPECT_EQ(1, histogram_proto.bucket(0).count());
+
+ UMA_STABILITY_HISTOGRAM_ENUMERATION("UmaStabilityHistogram", 2, 3);
+ std::vector<uint8> data2 = HistogramManager::GetInstance()->GetDeltas();
+ ChromeUserMetricsExtension uma_proto2;
+ uma_proto2.ParseFromArray(data2.data(), data2.size());
+ EXPECT_LT(0u, data2.size());
+
+ const HistogramEventProto& histogram_proto2 =
+ uma_proto2.histogram_event(uma_proto2.histogram_event_size() - 1);
+ ASSERT_EQ(1, histogram_proto2.bucket_size());
+ EXPECT_FALSE(histogram_proto2.bucket(0).has_min());
+ EXPECT_TRUE(histogram_proto2.bucket(0).has_max());
+ EXPECT_EQ(0, histogram_proto2.bucket(0).min());
+ EXPECT_EQ(3, histogram_proto2.bucket(0).max());
+ EXPECT_EQ(1, histogram_proto2.bucket(0).count());
+}
+
+} // namespace cronet

Powered by Google App Engine
This is Rietveld 408576698