| OLD | NEW |
| 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 TestMetricsLog log( | 243 TestMetricsLog log( |
| 244 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); | 244 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); |
| 245 | 245 |
| 246 std::vector<variations::ActiveGroupId> synthetic_trials; | 246 std::vector<variations::ActiveGroupId> synthetic_trials; |
| 247 // Add two synthetic trials. | 247 // Add two synthetic trials. |
| 248 synthetic_trials.push_back(kSyntheticTrials[0]); | 248 synthetic_trials.push_back(kSyntheticTrials[0]); |
| 249 synthetic_trials.push_back(kSyntheticTrials[1]); | 249 synthetic_trials.push_back(kSyntheticTrials[1]); |
| 250 | 250 |
| 251 log.RecordEnvironment(std::vector<MetricsProvider*>(), | 251 log.RecordEnvironment(std::vector<MetricsProvider*>(), |
| 252 synthetic_trials, | 252 synthetic_trials, |
| 253 kInstallDate); | 253 kInstallDate, kEnabledDate); |
| 254 // Check that the system profile on the log has the correct values set. | 254 // Check that the system profile on the log has the correct values set. |
| 255 CheckSystemProfile(log.system_profile()); | 255 CheckSystemProfile(log.system_profile()); |
| 256 | 256 |
| 257 // Check that the system profile has also been written to prefs. | 257 // Check that the system profile has also been written to prefs. |
| 258 const std::string base64_system_profile = | 258 const std::string base64_system_profile = |
| 259 prefs_.GetString(prefs::kStabilitySavedSystemProfile); | 259 prefs_.GetString(prefs::kStabilitySavedSystemProfile); |
| 260 EXPECT_FALSE(base64_system_profile.empty()); | 260 EXPECT_FALSE(base64_system_profile.empty()); |
| 261 std::string serialied_system_profile; | 261 std::string serialied_system_profile; |
| 262 EXPECT_TRUE(base::Base64Decode(base64_system_profile, | 262 EXPECT_TRUE(base::Base64Decode(base64_system_profile, |
| 263 &serialied_system_profile)); | 263 &serialied_system_profile)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 279 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); | 279 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); |
| 280 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs()); | 280 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs()); |
| 281 } | 281 } |
| 282 | 282 |
| 283 // Do a RecordEnvironment() call and check whether the pref is recorded. | 283 // Do a RecordEnvironment() call and check whether the pref is recorded. |
| 284 { | 284 { |
| 285 TestMetricsLog log( | 285 TestMetricsLog log( |
| 286 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); | 286 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); |
| 287 log.RecordEnvironment(std::vector<MetricsProvider*>(), | 287 log.RecordEnvironment(std::vector<MetricsProvider*>(), |
| 288 std::vector<variations::ActiveGroupId>(), | 288 std::vector<variations::ActiveGroupId>(), |
| 289 kInstallDate); | 289 kInstallDate, kEnabledDate); |
| 290 EXPECT_FALSE(prefs_.GetString(kSystemProfilePref).empty()); | 290 EXPECT_FALSE(prefs_.GetString(kSystemProfilePref).empty()); |
| 291 EXPECT_FALSE(prefs_.GetString(kSystemProfileHashPref).empty()); | 291 EXPECT_FALSE(prefs_.GetString(kSystemProfileHashPref).empty()); |
| 292 } | 292 } |
| 293 | 293 |
| 294 { | 294 { |
| 295 TestMetricsLog log( | 295 TestMetricsLog log( |
| 296 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); | 296 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); |
| 297 EXPECT_TRUE(log.LoadSavedEnvironmentFromPrefs()); | 297 EXPECT_TRUE(log.LoadSavedEnvironmentFromPrefs()); |
| 298 // Check some values in the system profile. | 298 // Check some values in the system profile. |
| 299 EXPECT_EQ(kInstallDateExpected, log.system_profile().install_date()); | 299 EXPECT_EQ(kInstallDateExpected, log.system_profile().install_date()); |
| 300 EXPECT_EQ(kEnabledDateExpected, log.system_profile().uma_enabled_date()); | 300 EXPECT_EQ(kEnabledDateExpected, log.system_profile().uma_enabled_date()); |
| 301 // Ensure that the call cleared the prefs. | 301 // Ensure that the call cleared the prefs. |
| 302 EXPECT_TRUE(prefs_.GetString(kSystemProfilePref).empty()); | 302 EXPECT_TRUE(prefs_.GetString(kSystemProfilePref).empty()); |
| 303 EXPECT_TRUE(prefs_.GetString(kSystemProfileHashPref).empty()); | 303 EXPECT_TRUE(prefs_.GetString(kSystemProfileHashPref).empty()); |
| 304 } | 304 } |
| 305 | 305 |
| 306 // Ensure that a non-matching hash results in the pref being invalid. | 306 // Ensure that a non-matching hash results in the pref being invalid. |
| 307 { | 307 { |
| 308 TestMetricsLog log( | 308 TestMetricsLog log( |
| 309 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); | 309 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); |
| 310 // Call RecordEnvironment() to record the pref again. | 310 // Call RecordEnvironment() to record the pref again. |
| 311 log.RecordEnvironment(std::vector<MetricsProvider*>(), | 311 log.RecordEnvironment(std::vector<MetricsProvider*>(), |
| 312 std::vector<variations::ActiveGroupId>(), | 312 std::vector<variations::ActiveGroupId>(), |
| 313 kInstallDate); | 313 kInstallDate, kEnabledDate); |
| 314 } | 314 } |
| 315 | 315 |
| 316 { | 316 { |
| 317 // Set the hash to a bad value. | 317 // Set the hash to a bad value. |
| 318 prefs_.SetString(kSystemProfileHashPref, "deadbeef"); | 318 prefs_.SetString(kSystemProfileHashPref, "deadbeef"); |
| 319 TestMetricsLog log( | 319 TestMetricsLog log( |
| 320 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); | 320 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); |
| 321 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs()); | 321 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs()); |
| 322 // Ensure that the prefs are cleared, even if the call failed. | 322 // Ensure that the prefs are cleared, even if the call failed. |
| 323 EXPECT_TRUE(prefs_.GetString(kSystemProfilePref).empty()); | 323 EXPECT_TRUE(prefs_.GetString(kSystemProfilePref).empty()); |
| 324 EXPECT_TRUE(prefs_.GetString(kSystemProfileHashPref).empty()); | 324 EXPECT_TRUE(prefs_.GetString(kSystemProfileHashPref).empty()); |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 | 327 |
| 328 TEST_F(MetricsLogTest, InitialLogStabilityMetrics) { | 328 TEST_F(MetricsLogTest, InitialLogStabilityMetrics) { |
| 329 TestMetricsServiceClient client; | 329 TestMetricsServiceClient client; |
| 330 TestMetricsLog log(kClientId, | 330 TestMetricsLog log(kClientId, |
| 331 kSessionId, | 331 kSessionId, |
| 332 MetricsLog::INITIAL_STABILITY_LOG, | 332 MetricsLog::INITIAL_STABILITY_LOG, |
| 333 &client, | 333 &client, |
| 334 &prefs_); | 334 &prefs_); |
| 335 std::vector<MetricsProvider*> metrics_providers; | 335 std::vector<MetricsProvider*> metrics_providers; |
| 336 log.RecordEnvironment(metrics_providers, | 336 log.RecordEnvironment(metrics_providers, |
| 337 std::vector<variations::ActiveGroupId>(), | 337 std::vector<variations::ActiveGroupId>(), |
| 338 kInstallDate); | 338 kInstallDate, kEnabledDate); |
| 339 log.RecordStabilityMetrics(metrics_providers, base::TimeDelta(), | 339 log.RecordStabilityMetrics(metrics_providers, base::TimeDelta(), |
| 340 base::TimeDelta()); | 340 base::TimeDelta()); |
| 341 const SystemProfileProto_Stability& stability = | 341 const SystemProfileProto_Stability& stability = |
| 342 log.system_profile().stability(); | 342 log.system_profile().stability(); |
| 343 // Required metrics: | 343 // Required metrics: |
| 344 EXPECT_TRUE(stability.has_launch_count()); | 344 EXPECT_TRUE(stability.has_launch_count()); |
| 345 EXPECT_TRUE(stability.has_crash_count()); | 345 EXPECT_TRUE(stability.has_crash_count()); |
| 346 // Initial log metrics: | 346 // Initial log metrics: |
| 347 EXPECT_TRUE(stability.has_incomplete_shutdown_count()); | 347 EXPECT_TRUE(stability.has_incomplete_shutdown_count()); |
| 348 EXPECT_TRUE(stability.has_breakpad_registration_success_count()); | 348 EXPECT_TRUE(stability.has_breakpad_registration_success_count()); |
| 349 EXPECT_TRUE(stability.has_breakpad_registration_failure_count()); | 349 EXPECT_TRUE(stability.has_breakpad_registration_failure_count()); |
| 350 EXPECT_TRUE(stability.has_debugger_present_count()); | 350 EXPECT_TRUE(stability.has_debugger_present_count()); |
| 351 EXPECT_TRUE(stability.has_debugger_not_present_count()); | 351 EXPECT_TRUE(stability.has_debugger_not_present_count()); |
| 352 } | 352 } |
| 353 | 353 |
| 354 TEST_F(MetricsLogTest, OngoingLogStabilityMetrics) { | 354 TEST_F(MetricsLogTest, OngoingLogStabilityMetrics) { |
| 355 TestMetricsServiceClient client; | 355 TestMetricsServiceClient client; |
| 356 TestMetricsLog log( | 356 TestMetricsLog log( |
| 357 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); | 357 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); |
| 358 std::vector<MetricsProvider*> metrics_providers; | 358 std::vector<MetricsProvider*> metrics_providers; |
| 359 log.RecordEnvironment(metrics_providers, | 359 log.RecordEnvironment(metrics_providers, |
| 360 std::vector<variations::ActiveGroupId>(), | 360 std::vector<variations::ActiveGroupId>(), |
| 361 kInstallDate); | 361 kInstallDate, kEnabledDate); |
| 362 log.RecordStabilityMetrics(metrics_providers, base::TimeDelta(), | 362 log.RecordStabilityMetrics(metrics_providers, base::TimeDelta(), |
| 363 base::TimeDelta()); | 363 base::TimeDelta()); |
| 364 const SystemProfileProto_Stability& stability = | 364 const SystemProfileProto_Stability& stability = |
| 365 log.system_profile().stability(); | 365 log.system_profile().stability(); |
| 366 // Required metrics: | 366 // Required metrics: |
| 367 EXPECT_TRUE(stability.has_launch_count()); | 367 EXPECT_TRUE(stability.has_launch_count()); |
| 368 EXPECT_TRUE(stability.has_crash_count()); | 368 EXPECT_TRUE(stability.has_crash_count()); |
| 369 // Initial log metrics: | 369 // Initial log metrics: |
| 370 EXPECT_FALSE(stability.has_incomplete_shutdown_count()); | 370 EXPECT_FALSE(stability.has_incomplete_shutdown_count()); |
| 371 EXPECT_FALSE(stability.has_breakpad_registration_success_count()); | 371 EXPECT_FALSE(stability.has_breakpad_registration_success_count()); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 399 TestMetricsServiceClient client; | 399 TestMetricsServiceClient client; |
| 400 client.set_product(kTestProduct); | 400 client.set_product(kTestProduct); |
| 401 TestMetricsLog log( | 401 TestMetricsLog log( |
| 402 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); | 402 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); |
| 403 // Check that the product is set to |kTestProduct|. | 403 // Check that the product is set to |kTestProduct|. |
| 404 EXPECT_TRUE(log.uma_proto().has_product()); | 404 EXPECT_TRUE(log.uma_proto().has_product()); |
| 405 EXPECT_EQ(kTestProduct, log.uma_proto().product()); | 405 EXPECT_EQ(kTestProduct, log.uma_proto().product()); |
| 406 } | 406 } |
| 407 | 407 |
| 408 } // namespace metrics | 408 } // namespace metrics |
| OLD | NEW |