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

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

Issue 370813003: Move kInstallDate from chrome/common/pref_names.h to components/metrics/metrics_pref_names.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review:isherman Created 6 years, 5 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 | Annotate | Revision Log
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 <string> 7 #include <string>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 EXPECT_EQ(10, histogram_proto.bucket(3).min()); 234 EXPECT_EQ(10, histogram_proto.bucket(3).min());
235 235
236 // 11-12 becomes /-12 (last record must keep max, min is same as max - 1). 236 // 11-12 becomes /-12 (last record must keep max, min is same as max - 1).
237 EXPECT_FALSE(histogram_proto.bucket(4).has_min()); 237 EXPECT_FALSE(histogram_proto.bucket(4).has_min());
238 EXPECT_TRUE(histogram_proto.bucket(4).has_max()); 238 EXPECT_TRUE(histogram_proto.bucket(4).has_max());
239 EXPECT_EQ(12, histogram_proto.bucket(4).max()); 239 EXPECT_EQ(12, histogram_proto.bucket(4).max());
240 } 240 }
241 241
242 TEST_F(MetricsLogTest, RecordEnvironment) { 242 TEST_F(MetricsLogTest, RecordEnvironment) {
243 TestMetricsServiceClient client; 243 TestMetricsServiceClient client;
244 client.set_install_date(kInstallDate);
245 TestMetricsLog log( 244 TestMetricsLog log(
246 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); 245 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
247 246
248 std::vector<variations::ActiveGroupId> synthetic_trials; 247 std::vector<variations::ActiveGroupId> synthetic_trials;
249 // Add two synthetic trials. 248 // Add two synthetic trials.
250 synthetic_trials.push_back(kSyntheticTrials[0]); 249 synthetic_trials.push_back(kSyntheticTrials[0]);
251 synthetic_trials.push_back(kSyntheticTrials[1]); 250 synthetic_trials.push_back(kSyntheticTrials[1]);
252 251
253 log.RecordEnvironment(std::vector<MetricsProvider*>(), 252 log.RecordEnvironment(std::vector<MetricsProvider*>(),
254 synthetic_trials); 253 synthetic_trials,
254 kInstallDate);
255 // Check that the system profile on the log has the correct values set. 255 // Check that the system profile on the log has the correct values set.
256 CheckSystemProfile(log.system_profile()); 256 CheckSystemProfile(log.system_profile());
257 257
258 // Check that the system profile has also been written to prefs. 258 // Check that the system profile has also been written to prefs.
259 const std::string base64_system_profile = 259 const std::string base64_system_profile =
260 prefs_.GetString(prefs::kStabilitySavedSystemProfile); 260 prefs_.GetString(prefs::kStabilitySavedSystemProfile);
261 EXPECT_FALSE(base64_system_profile.empty()); 261 EXPECT_FALSE(base64_system_profile.empty());
262 std::string serialied_system_profile; 262 std::string serialied_system_profile;
263 EXPECT_TRUE(base::Base64Decode(base64_system_profile, 263 EXPECT_TRUE(base::Base64Decode(base64_system_profile,
264 &serialied_system_profile)); 264 &serialied_system_profile));
265 SystemProfileProto decoded_system_profile; 265 SystemProfileProto decoded_system_profile;
266 EXPECT_TRUE(decoded_system_profile.ParseFromString(serialied_system_profile)); 266 EXPECT_TRUE(decoded_system_profile.ParseFromString(serialied_system_profile));
267 CheckSystemProfile(decoded_system_profile); 267 CheckSystemProfile(decoded_system_profile);
268 } 268 }
269 269
270 TEST_F(MetricsLogTest, LoadSavedEnvironmentFromPrefs) { 270 TEST_F(MetricsLogTest, LoadSavedEnvironmentFromPrefs) {
271 const char* kSystemProfilePref = prefs::kStabilitySavedSystemProfile; 271 const char* kSystemProfilePref = prefs::kStabilitySavedSystemProfile;
272 const char* kSystemProfileHashPref = 272 const char* kSystemProfileHashPref =
273 prefs::kStabilitySavedSystemProfileHash; 273 prefs::kStabilitySavedSystemProfileHash;
274 274
275 TestMetricsServiceClient client; 275 TestMetricsServiceClient client;
276 client.set_install_date(kInstallDate);
277 276
278 // The pref value is empty, so loading it from prefs should fail. 277 // The pref value is empty, so loading it from prefs should fail.
279 { 278 {
280 TestMetricsLog log( 279 TestMetricsLog log(
281 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); 280 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
282 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs()); 281 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs());
283 } 282 }
284 283
285 // Do a RecordEnvironment() call and check whether the pref is recorded. 284 // Do a RecordEnvironment() call and check whether the pref is recorded.
286 { 285 {
287 TestMetricsLog log( 286 TestMetricsLog log(
288 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); 287 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
289 log.RecordEnvironment(std::vector<MetricsProvider*>(), 288 log.RecordEnvironment(std::vector<MetricsProvider*>(),
290 std::vector<variations::ActiveGroupId>()); 289 std::vector<variations::ActiveGroupId>(),
290 kInstallDate);
291 EXPECT_FALSE(prefs_.GetString(kSystemProfilePref).empty()); 291 EXPECT_FALSE(prefs_.GetString(kSystemProfilePref).empty());
292 EXPECT_FALSE(prefs_.GetString(kSystemProfileHashPref).empty()); 292 EXPECT_FALSE(prefs_.GetString(kSystemProfileHashPref).empty());
293 } 293 }
294 294
295 { 295 {
296 TestMetricsLog log( 296 TestMetricsLog log(
297 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); 297 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
298 EXPECT_TRUE(log.LoadSavedEnvironmentFromPrefs()); 298 EXPECT_TRUE(log.LoadSavedEnvironmentFromPrefs());
299 // Check some values in the system profile. 299 // Check some values in the system profile.
300 EXPECT_EQ(kInstallDateExpected, log.system_profile().install_date()); 300 EXPECT_EQ(kInstallDateExpected, log.system_profile().install_date());
301 EXPECT_EQ(kEnabledDateExpected, log.system_profile().uma_enabled_date()); 301 EXPECT_EQ(kEnabledDateExpected, log.system_profile().uma_enabled_date());
302 // Ensure that the call cleared the prefs. 302 // Ensure that the call cleared the prefs.
303 EXPECT_TRUE(prefs_.GetString(kSystemProfilePref).empty()); 303 EXPECT_TRUE(prefs_.GetString(kSystemProfilePref).empty());
304 EXPECT_TRUE(prefs_.GetString(kSystemProfileHashPref).empty()); 304 EXPECT_TRUE(prefs_.GetString(kSystemProfileHashPref).empty());
305 } 305 }
306 306
307 // Ensure that a non-matching hash results in the pref being invalid. 307 // Ensure that a non-matching hash results in the pref being invalid.
308 { 308 {
309 TestMetricsLog log( 309 TestMetricsLog log(
310 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); 310 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
311 // Call RecordEnvironment() to record the pref again. 311 // Call RecordEnvironment() to record the pref again.
312 log.RecordEnvironment(std::vector<MetricsProvider*>(), 312 log.RecordEnvironment(std::vector<MetricsProvider*>(),
313 std::vector<variations::ActiveGroupId>()); 313 std::vector<variations::ActiveGroupId>(),
314 kInstallDate);
314 } 315 }
315 316
316 { 317 {
317 // Set the hash to a bad value. 318 // Set the hash to a bad value.
318 prefs_.SetString(kSystemProfileHashPref, "deadbeef"); 319 prefs_.SetString(kSystemProfileHashPref, "deadbeef");
319 TestMetricsLog log( 320 TestMetricsLog log(
320 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); 321 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
321 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs()); 322 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs());
322 // Ensure that the prefs are cleared, even if the call failed. 323 // Ensure that the prefs are cleared, even if the call failed.
323 EXPECT_TRUE(prefs_.GetString(kSystemProfilePref).empty()); 324 EXPECT_TRUE(prefs_.GetString(kSystemProfilePref).empty());
324 EXPECT_TRUE(prefs_.GetString(kSystemProfileHashPref).empty()); 325 EXPECT_TRUE(prefs_.GetString(kSystemProfileHashPref).empty());
325 } 326 }
326 } 327 }
327 328
328 TEST_F(MetricsLogTest, InitialLogStabilityMetrics) { 329 TEST_F(MetricsLogTest, InitialLogStabilityMetrics) {
329 TestMetricsServiceClient client; 330 TestMetricsServiceClient client;
330 TestMetricsLog log(kClientId, 331 TestMetricsLog log(kClientId,
331 kSessionId, 332 kSessionId,
332 MetricsLog::INITIAL_STABILITY_LOG, 333 MetricsLog::INITIAL_STABILITY_LOG,
333 &client, 334 &client,
334 &prefs_); 335 &prefs_);
335 std::vector<MetricsProvider*> metrics_providers; 336 std::vector<MetricsProvider*> metrics_providers;
336 log.RecordEnvironment(metrics_providers, 337 log.RecordEnvironment(metrics_providers,
337 std::vector<variations::ActiveGroupId>()); 338 std::vector<variations::ActiveGroupId>(),
339 kInstallDate);
338 log.RecordStabilityMetrics(metrics_providers, base::TimeDelta(), 340 log.RecordStabilityMetrics(metrics_providers, base::TimeDelta(),
339 base::TimeDelta()); 341 base::TimeDelta());
340 const SystemProfileProto_Stability& stability = 342 const SystemProfileProto_Stability& stability =
341 log.system_profile().stability(); 343 log.system_profile().stability();
342 // Required metrics: 344 // Required metrics:
343 EXPECT_TRUE(stability.has_launch_count()); 345 EXPECT_TRUE(stability.has_launch_count());
344 EXPECT_TRUE(stability.has_crash_count()); 346 EXPECT_TRUE(stability.has_crash_count());
345 // Initial log metrics: 347 // Initial log metrics:
346 EXPECT_TRUE(stability.has_incomplete_shutdown_count()); 348 EXPECT_TRUE(stability.has_incomplete_shutdown_count());
347 EXPECT_TRUE(stability.has_breakpad_registration_success_count()); 349 EXPECT_TRUE(stability.has_breakpad_registration_success_count());
348 EXPECT_TRUE(stability.has_breakpad_registration_failure_count()); 350 EXPECT_TRUE(stability.has_breakpad_registration_failure_count());
349 EXPECT_TRUE(stability.has_debugger_present_count()); 351 EXPECT_TRUE(stability.has_debugger_present_count());
350 EXPECT_TRUE(stability.has_debugger_not_present_count()); 352 EXPECT_TRUE(stability.has_debugger_not_present_count());
351 } 353 }
352 354
353 TEST_F(MetricsLogTest, OngoingLogStabilityMetrics) { 355 TEST_F(MetricsLogTest, OngoingLogStabilityMetrics) {
354 TestMetricsServiceClient client; 356 TestMetricsServiceClient client;
355 TestMetricsLog log( 357 TestMetricsLog log(
356 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); 358 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
357 std::vector<MetricsProvider*> metrics_providers; 359 std::vector<MetricsProvider*> metrics_providers;
358 log.RecordEnvironment(metrics_providers, 360 log.RecordEnvironment(metrics_providers,
359 std::vector<variations::ActiveGroupId>()); 361 std::vector<variations::ActiveGroupId>(),
362 kInstallDate);
360 log.RecordStabilityMetrics(metrics_providers, base::TimeDelta(), 363 log.RecordStabilityMetrics(metrics_providers, base::TimeDelta(),
361 base::TimeDelta()); 364 base::TimeDelta());
362 const SystemProfileProto_Stability& stability = 365 const SystemProfileProto_Stability& stability =
363 log.system_profile().stability(); 366 log.system_profile().stability();
364 // Required metrics: 367 // Required metrics:
365 EXPECT_TRUE(stability.has_launch_count()); 368 EXPECT_TRUE(stability.has_launch_count());
366 EXPECT_TRUE(stability.has_crash_count()); 369 EXPECT_TRUE(stability.has_crash_count());
367 // Initial log metrics: 370 // Initial log metrics:
368 EXPECT_FALSE(stability.has_incomplete_shutdown_count()); 371 EXPECT_FALSE(stability.has_incomplete_shutdown_count());
369 EXPECT_FALSE(stability.has_breakpad_registration_success_count()); 372 EXPECT_FALSE(stability.has_breakpad_registration_success_count());
370 EXPECT_FALSE(stability.has_breakpad_registration_failure_count()); 373 EXPECT_FALSE(stability.has_breakpad_registration_failure_count());
371 EXPECT_FALSE(stability.has_debugger_present_count()); 374 EXPECT_FALSE(stability.has_debugger_present_count());
372 EXPECT_FALSE(stability.has_debugger_not_present_count()); 375 EXPECT_FALSE(stability.has_debugger_not_present_count());
373 } 376 }
374 377
375 TEST_F(MetricsLogTest, ChromeChannelWrittenToProtobuf) { 378 TEST_F(MetricsLogTest, ChromeChannelWrittenToProtobuf) {
376 TestMetricsServiceClient client; 379 TestMetricsServiceClient client;
377 TestMetricsLog log( 380 TestMetricsLog log(
378 "user@test.com", kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); 381 "user@test.com", kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
379 EXPECT_TRUE(log.uma_proto().system_profile().has_channel()); 382 EXPECT_TRUE(log.uma_proto().system_profile().has_channel());
380 } 383 }
381 384
382 } // namespace metrics 385 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698