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

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

Issue 2657083003: Populate a basic SystemProfileProto in UKM. (Closed)
Patch Set: remove stale TODO 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
« no previous file with comments | « components/metrics/metrics_log.cc ('k') | components/ukm/ukm_service.cc » ('j') | 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.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
34 #if defined(OS_WIN)
35 #include "base/win/current_module.h"
36 #endif
37
29 namespace metrics { 38 namespace metrics {
30 39
31 namespace { 40 namespace {
32 41
33 const char kClientId[] = "bogus client ID"; 42 const char kClientId[] = "bogus client ID";
34 const int64_t kInstallDate = 1373051956; 43 const int64_t kInstallDate = 1373051956;
35 const int64_t kInstallDateExpected = 1373050800; // Computed from kInstallDate. 44 const int64_t kInstallDateExpected = 1373050800; // Computed from kInstallDate.
36 const int64_t kEnabledDate = 1373001211; 45 const int64_t kEnabledDate = 1373001211;
37 const int64_t kEnabledDateExpected = 1373000400; // Computed from kEnabledDate. 46 const int64_t kEnabledDateExpected = 1373000400; // Computed from kEnabledDate.
38 const int kSessionId = 127; 47 const int kSessionId = 127;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 TestMetricsServiceClient client; 158 TestMetricsServiceClient client;
150 TestingPrefServiceSimple prefs; 159 TestingPrefServiceSimple prefs;
151 160
152 MetricsLog log1("id", 0, MetricsLog::ONGOING_LOG, &client, &prefs); 161 MetricsLog log1("id", 0, MetricsLog::ONGOING_LOG, &client, &prefs);
153 EXPECT_EQ(MetricsLog::ONGOING_LOG, log1.log_type()); 162 EXPECT_EQ(MetricsLog::ONGOING_LOG, log1.log_type());
154 163
155 MetricsLog log2("id", 0, MetricsLog::INITIAL_STABILITY_LOG, &client, &prefs); 164 MetricsLog log2("id", 0, MetricsLog::INITIAL_STABILITY_LOG, &client, &prefs);
156 EXPECT_EQ(MetricsLog::INITIAL_STABILITY_LOG, log2.log_type()); 165 EXPECT_EQ(MetricsLog::INITIAL_STABILITY_LOG, log2.log_type());
157 } 166 }
158 167
159 TEST_F(MetricsLogTest, EmptyRecord) { 168 TEST_F(MetricsLogTest, BasicRecord) {
160 TestMetricsServiceClient client; 169 TestMetricsServiceClient client;
161 client.set_version_string("bogus version"); 170 client.set_version_string("bogus version");
162 TestingPrefServiceSimple prefs; 171 TestingPrefServiceSimple prefs;
163 MetricsLog log("totally bogus client ID", 137, MetricsLog::ONGOING_LOG, 172 MetricsLog log("totally bogus client ID", 137, MetricsLog::ONGOING_LOG,
164 &client, &prefs); 173 &client, &prefs);
165 log.CloseLog(); 174 log.CloseLog();
166 175
167 std::string encoded; 176 std::string encoded;
168 log.GetEncodedLog(&encoded); 177 log.GetEncodedLog(&encoded);
169 178
170 // A couple of fields are hard to mock, so these will be copied over directly 179 // A couple of fields are hard to mock, so these will be copied over directly
171 // for the expected output. 180 // for the expected output.
172 ChromeUserMetricsExtension parsed; 181 ChromeUserMetricsExtension parsed;
173 ASSERT_TRUE(parsed.ParseFromString(encoded)); 182 ASSERT_TRUE(parsed.ParseFromString(encoded));
174 183
175 ChromeUserMetricsExtension expected; 184 ChromeUserMetricsExtension expected;
176 expected.set_client_id(5217101509553811875); // Hashed bogus client ID 185 expected.set_client_id(5217101509553811875); // Hashed bogus client ID
177 expected.set_session_id(137); 186 expected.set_session_id(137);
178 expected.mutable_system_profile()->set_build_timestamp( 187
188 SystemProfileProto* system_profile = expected.mutable_system_profile();
189 system_profile->set_app_version("bogus version");
190 system_profile->set_channel(client.GetChannel());
191 system_profile->set_application_locale(client.GetApplicationLocale());
192
193 #if defined(SYZYASAN)
194 system_profile->set_is_asan_build(true);
195 #endif
196 metrics::SystemProfileProto::Hardware* hardware =
197 system_profile->mutable_hardware();
198 hardware->set_cpu_architecture(base::SysInfo::OperatingSystemArchitecture());
199 hardware->set_system_ram_mb(base::SysInfo::AmountOfPhysicalMemoryMB());
200 hardware->set_hardware_class(base::SysInfo::HardwareModelName());
201 #if defined(OS_WIN)
202 hardware->set_dll_base(reinterpret_cast<uint64_t>(CURRENT_MODULE()));
203 #endif
204
205 system_profile->mutable_os()->set_name(base::SysInfo::OperatingSystemName());
206 system_profile->mutable_os()->set_version(
207 base::SysInfo::OperatingSystemVersion());
208 #if defined(OS_ANDROID)
209 system_profile->mutable_os()->set_fingerprint(
210 base::android::BuildInfo::GetInstance()->android_build_fp());
211 #endif
212
213 // Hard to mock.
214 system_profile->set_build_timestamp(
179 parsed.system_profile().build_timestamp()); 215 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 216
183 EXPECT_EQ(expected.SerializeAsString(), encoded); 217 EXPECT_EQ(expected.SerializeAsString(), encoded);
184 } 218 }
185 219
186 TEST_F(MetricsLogTest, HistogramBucketFields) { 220 TEST_F(MetricsLogTest, HistogramBucketFields) {
187 // Create buckets: 1-5, 5-7, 7-8, 8-9, 9-10, 10-11, 11-12. 221 // Create buckets: 1-5, 5-7, 7-8, 8-9, 9-10, 10-11, 11-12.
188 base::BucketRanges ranges(8); 222 base::BucketRanges ranges(8);
189 ranges.set_range(0, 1); 223 ranges.set_range(0, 1);
190 ranges.set_range(1, 5); 224 ranges.set_range(1, 5);
191 ranges.set_range(2, 7); 225 ranges.set_range(2, 7);
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 TestMetricsServiceClient client; 497 TestMetricsServiceClient client;
464 client.set_product(kTestProduct); 498 client.set_product(kTestProduct);
465 TestMetricsLog log( 499 TestMetricsLog log(
466 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); 500 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
467 // Check that the product is set to |kTestProduct|. 501 // Check that the product is set to |kTestProduct|.
468 EXPECT_TRUE(log.uma_proto().has_product()); 502 EXPECT_TRUE(log.uma_proto().has_product());
469 EXPECT_EQ(kTestProduct, log.uma_proto().product()); 503 EXPECT_EQ(kTestProduct, log.uma_proto().product());
470 } 504 }
471 505
472 } // namespace metrics 506 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/metrics_log.cc ('k') | components/ukm/ukm_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698