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

Side by Side Diff: components/metrics/metrics_log_base_unittest.cc

Issue 301633006: Move ChromeOS hardware class init out of MetricsService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 6 months 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 unified diff | Download patch
« no previous file with comments | « components/metrics/metrics_log_base.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/metrics_log_base.h" 5 #include "components/metrics/metrics_log_base.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/metrics/bucket_ranges.h" 10 #include "base/metrics/bucket_ranges.h"
(...skipping 24 matching lines...) Expand all
35 MetricsLogBase log1("id", 0, MetricsLogBase::ONGOING_LOG, "1.2.3"); 35 MetricsLogBase log1("id", 0, MetricsLogBase::ONGOING_LOG, "1.2.3");
36 EXPECT_EQ(MetricsLogBase::ONGOING_LOG, log1.log_type()); 36 EXPECT_EQ(MetricsLogBase::ONGOING_LOG, log1.log_type());
37 37
38 MetricsLogBase log2("id", 0, MetricsLogBase::INITIAL_STABILITY_LOG, "1.2.3"); 38 MetricsLogBase log2("id", 0, MetricsLogBase::INITIAL_STABILITY_LOG, "1.2.3");
39 EXPECT_EQ(MetricsLogBase::INITIAL_STABILITY_LOG, log2.log_type()); 39 EXPECT_EQ(MetricsLogBase::INITIAL_STABILITY_LOG, log2.log_type());
40 } 40 }
41 41
42 TEST(MetricsLogBaseTest, EmptyRecord) { 42 TEST(MetricsLogBaseTest, EmptyRecord) {
43 MetricsLogBase log("totally bogus client ID", 137, 43 MetricsLogBase log("totally bogus client ID", 137,
44 MetricsLogBase::ONGOING_LOG, "bogus version"); 44 MetricsLogBase::ONGOING_LOG, "bogus version");
45 log.set_hardware_class("sample-class");
46 log.CloseLog(); 45 log.CloseLog();
47 46
48 std::string encoded; 47 std::string encoded;
49 log.GetEncodedLog(&encoded); 48 log.GetEncodedLog(&encoded);
50 49
51 // A couple of fields are hard to mock, so these will be copied over directly 50 // A couple of fields are hard to mock, so these will be copied over directly
52 // for the expected output. 51 // for the expected output.
53 metrics::ChromeUserMetricsExtension parsed; 52 metrics::ChromeUserMetricsExtension parsed;
54 ASSERT_TRUE(parsed.ParseFromString(encoded)); 53 ASSERT_TRUE(parsed.ParseFromString(encoded));
55 54
56 metrics::ChromeUserMetricsExtension expected; 55 metrics::ChromeUserMetricsExtension expected;
57 expected.set_client_id(5217101509553811875); // Hashed bogus client ID 56 expected.set_client_id(5217101509553811875); // Hashed bogus client ID
58 expected.set_session_id(137); 57 expected.set_session_id(137);
59 expected.mutable_system_profile()->set_build_timestamp( 58 expected.mutable_system_profile()->set_build_timestamp(
60 parsed.system_profile().build_timestamp()); 59 parsed.system_profile().build_timestamp());
61 expected.mutable_system_profile()->set_app_version("bogus version"); 60 expected.mutable_system_profile()->set_app_version("bogus version");
62 expected.mutable_system_profile()->mutable_hardware()->set_hardware_class(
63 "sample-class");
64 61
65 EXPECT_EQ(expected.SerializeAsString(), encoded); 62 EXPECT_EQ(expected.SerializeAsString(), encoded);
66 } 63 }
67 64
68 TEST(MetricsLogBaseTest, HistogramBucketFields) { 65 TEST(MetricsLogBaseTest, HistogramBucketFields) {
69 // Create buckets: 1-5, 5-7, 7-8, 8-9, 9-10, 10-11, 11-12. 66 // Create buckets: 1-5, 5-7, 7-8, 8-9, 9-10, 10-11, 11-12.
70 base::BucketRanges ranges(8); 67 base::BucketRanges ranges(8);
71 ranges.set_range(0, 1); 68 ranges.set_range(0, 1);
72 ranges.set_range(1, 5); 69 ranges.set_range(1, 5);
73 ranges.set_range(2, 7); 70 ranges.set_range(2, 7);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 EXPECT_FALSE(histogram_proto.bucket(3).has_max()); 113 EXPECT_FALSE(histogram_proto.bucket(3).has_max());
117 EXPECT_EQ(10, histogram_proto.bucket(3).min()); 114 EXPECT_EQ(10, histogram_proto.bucket(3).min());
118 115
119 // 11-12 becomes /-12 (last record must keep max, min is same as max - 1). 116 // 11-12 becomes /-12 (last record must keep max, min is same as max - 1).
120 EXPECT_FALSE(histogram_proto.bucket(4).has_min()); 117 EXPECT_FALSE(histogram_proto.bucket(4).has_min());
121 EXPECT_TRUE(histogram_proto.bucket(4).has_max()); 118 EXPECT_TRUE(histogram_proto.bucket(4).has_max());
122 EXPECT_EQ(12, histogram_proto.bucket(4).max()); 119 EXPECT_EQ(12, histogram_proto.bucket(4).max());
123 } 120 }
124 121
125 } // namespace metrics 122 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/metrics_log_base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698