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

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

Issue 2657083003: Populate a basic SystemProfileProto in UKM. (Closed)
Patch Set: fixes Created 3 years, 10 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
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.h" 5 #include "components/metrics/metrics_log.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
11 11
12 #include "base/base64.h" 12 #include "base/base64.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/scoped_vector.h" 14 #include "base/memory/scoped_vector.h"
15 #include "base/metrics/bucket_ranges.h" 15 #include "base/metrics/bucket_ranges.h"
16 #include "base/metrics/sample_vector.h" 16 #include "base/metrics/sample_vector.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/sys_info.h"
18 #include "base/time/time.h" 19 #include "base/time/time.h"
19 #include "components/metrics/metrics_pref_names.h" 20 #include "components/metrics/metrics_pref_names.h"
20 #include "components/metrics/metrics_state_manager.h" 21 #include "components/metrics/metrics_state_manager.h"
21 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h" 22 #include "components/metrics/proto/chrome_user_metrics_extension.pb.h"
22 #include "components/metrics/test_metrics_provider.h" 23 #include "components/metrics/test_metrics_provider.h"
23 #include "components/metrics/test_metrics_service_client.h" 24 #include "components/metrics/test_metrics_service_client.h"
24 #include "components/prefs/pref_service.h" 25 #include "components/prefs/pref_service.h"
25 #include "components/prefs/testing_pref_service.h" 26 #include "components/prefs/testing_pref_service.h"
26 #include "components/variations/active_field_trials.h" 27 #include "components/variations/active_field_trials.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 29
30 #if defined(OS_ANDROID)
31 #include "base/android/build_info.h"
32 #endif
33
29 namespace metrics { 34 namespace metrics {
30 35
31 namespace { 36 namespace {
32 37
33 const char kClientId[] = "bogus client ID"; 38 const char kClientId[] = "bogus client ID";
34 const int64_t kInstallDate = 1373051956; 39 const int64_t kInstallDate = 1373051956;
35 const int64_t kInstallDateExpected = 1373050800; // Computed from kInstallDate. 40 const int64_t kInstallDateExpected = 1373050800; // Computed from kInstallDate.
36 const int64_t kEnabledDate = 1373001211; 41 const int64_t kEnabledDate = 1373001211;
37 const int64_t kEnabledDateExpected = 1373000400; // Computed from kEnabledDate. 42 const int64_t kEnabledDateExpected = 1373000400; // Computed from kEnabledDate.
38 const int kSessionId = 127; 43 const int kSessionId = 127;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 TestMetricsServiceClient client; 154 TestMetricsServiceClient client;
150 TestingPrefServiceSimple prefs; 155 TestingPrefServiceSimple prefs;
151 156
152 MetricsLog log1("id", 0, MetricsLog::ONGOING_LOG, &client, &prefs); 157 MetricsLog log1("id", 0, MetricsLog::ONGOING_LOG, &client, &prefs);
153 EXPECT_EQ(MetricsLog::ONGOING_LOG, log1.log_type()); 158 EXPECT_EQ(MetricsLog::ONGOING_LOG, log1.log_type());
154 159
155 MetricsLog log2("id", 0, MetricsLog::INITIAL_STABILITY_LOG, &client, &prefs); 160 MetricsLog log2("id", 0, MetricsLog::INITIAL_STABILITY_LOG, &client, &prefs);
156 EXPECT_EQ(MetricsLog::INITIAL_STABILITY_LOG, log2.log_type()); 161 EXPECT_EQ(MetricsLog::INITIAL_STABILITY_LOG, log2.log_type());
157 } 162 }
158 163
159 TEST_F(MetricsLogTest, EmptyRecord) { 164 TEST_F(MetricsLogTest, BasicRecord) {
160 TestMetricsServiceClient client; 165 TestMetricsServiceClient client;
161 client.set_version_string("bogus version"); 166 client.set_version_string("bogus version");
162 TestingPrefServiceSimple prefs; 167 TestingPrefServiceSimple prefs;
163 MetricsLog log("totally bogus client ID", 137, MetricsLog::ONGOING_LOG, 168 MetricsLog log("totally bogus client ID", 137, MetricsLog::ONGOING_LOG,
164 &client, &prefs); 169 &client, &prefs);
165 log.CloseLog(); 170 log.CloseLog();
166 171
167 std::string encoded; 172 std::string encoded;
168 log.GetEncodedLog(&encoded); 173 log.GetEncodedLog(&encoded);
169 174
170 // A couple of fields are hard to mock, so these will be copied over directly 175 // A couple of fields are hard to mock, so these will be copied over directly
171 // for the expected output. 176 // for the expected output.
172 ChromeUserMetricsExtension parsed; 177 ChromeUserMetricsExtension parsed;
173 ASSERT_TRUE(parsed.ParseFromString(encoded)); 178 ASSERT_TRUE(parsed.ParseFromString(encoded));
174 179
175 ChromeUserMetricsExtension expected; 180 ChromeUserMetricsExtension expected;
176 expected.set_client_id(5217101509553811875); // Hashed bogus client ID 181 expected.set_client_id(5217101509553811875); // Hashed bogus client ID
177 expected.set_session_id(137); 182 expected.set_session_id(137);
178 expected.mutable_system_profile()->set_build_timestamp( 183
184 SystemProfileProto* system_profile = expected.mutable_system_profile();
185 system_profile->set_app_version("bogus version");
186 system_profile->set_channel(client.GetChannel());
187 system_profile->set_application_locale(client.GetApplicationLocale());
188
189 #if defined(SYZYASAN)
190 system_profile->set_is_asan_build(true);
191 #endif
192 metrics::SystemProfileProto::Hardware* hardware =
193 system_profile->mutable_hardware();
194 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
195 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
196 hardware->set_hardware_class(base::SysInfo::HardwareModelName());
197 #if defined(OS_WIN)
198 hardware->set_dll_base(reinterpret_cast<uint64_t>(CURRENT_MODULE()));
199 #endif
200
201 system_profile->mutable_os()->set_name(base::SysInfo::OperatingSystemName());
202 system_profile->mutable_os()->set_version(
203 base::SysInfo::OperatingSystemVersion());
204 #if defined(OS_ANDROID)
205 os->set_fingerprint(
206 base::android::BuildInfo::GetInstance()->android_build_fp());
207 #endif
208
209 // Hard to mock.
210 system_profile->set_build_timestamp(
179 parsed.system_profile().build_timestamp()); 211 parsed.system_profile().build_timestamp());
180 expected.mutable_system_profile()->set_app_version("bogus version");
181 expected.mutable_system_profile()->set_channel(client.GetChannel());
182 212
183 EXPECT_EQ(expected.SerializeAsString(), encoded); 213 EXPECT_EQ(expected.SerializeAsString(), encoded);
184 } 214 }
185 215
186 TEST_F(MetricsLogTest, HistogramBucketFields) { 216 TEST_F(MetricsLogTest, HistogramBucketFields) {
187 // Create buckets: 1-5, 5-7, 7-8, 8-9, 9-10, 10-11, 11-12. 217 // Create buckets: 1-5, 5-7, 7-8, 8-9, 9-10, 10-11, 11-12.
188 base::BucketRanges ranges(8); 218 base::BucketRanges ranges(8);
189 ranges.set_range(0, 1); 219 ranges.set_range(0, 1);
190 ranges.set_range(1, 5); 220 ranges.set_range(1, 5);
191 ranges.set_range(2, 7); 221 ranges.set_range(2, 7);
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 TestMetricsServiceClient client; 493 TestMetricsServiceClient client;
464 client.set_product(kTestProduct); 494 client.set_product(kTestProduct);
465 TestMetricsLog log( 495 TestMetricsLog log(
466 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); 496 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
467 // Check that the product is set to |kTestProduct|. 497 // Check that the product is set to |kTestProduct|.
468 EXPECT_TRUE(log.uma_proto().has_product()); 498 EXPECT_TRUE(log.uma_proto().has_product());
469 EXPECT_EQ(kTestProduct, log.uma_proto().product()); 499 EXPECT_EQ(kTestProduct, log.uma_proto().product());
470 } 500 }
471 501
472 } // namespace metrics 502 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698