| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 300 |
| 301 { | 301 { |
| 302 TestMetricsLog log( | 302 TestMetricsLog log( |
| 303 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); | 303 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); |
| 304 std::string app_version; | 304 std::string app_version; |
| 305 EXPECT_TRUE(log.LoadSavedEnvironmentFromPrefs(&app_version)); | 305 EXPECT_TRUE(log.LoadSavedEnvironmentFromPrefs(&app_version)); |
| 306 EXPECT_EQ("bogus version", app_version); | 306 EXPECT_EQ("bogus version", app_version); |
| 307 // Check some values in the system profile. | 307 // Check some values in the system profile. |
| 308 EXPECT_EQ(kInstallDateExpected, log.system_profile().install_date()); | 308 EXPECT_EQ(kInstallDateExpected, log.system_profile().install_date()); |
| 309 EXPECT_EQ(kEnabledDateExpected, log.system_profile().uma_enabled_date()); | 309 EXPECT_EQ(kEnabledDateExpected, log.system_profile().uma_enabled_date()); |
| 310 // Ensure that the call cleared the prefs. | 310 // Ensure that the call did not clear the prefs. |
| 311 EXPECT_TRUE(prefs_.GetString(kSystemProfilePref).empty()); | 311 EXPECT_FALSE(prefs_.GetString(kSystemProfilePref).empty()); |
| 312 EXPECT_TRUE(prefs_.GetString(kSystemProfileHashPref).empty()); | 312 EXPECT_FALSE(prefs_.GetString(kSystemProfileHashPref).empty()); |
| 313 } | 313 } |
| 314 | 314 |
| 315 // Ensure that a non-matching hash results in the pref being invalid. | 315 // Ensure that a non-matching hash results in the pref being invalid. |
| 316 { | 316 { |
| 317 TestMetricsLog log( | 317 TestMetricsLog log( |
| 318 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); | 318 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); |
| 319 // Call RecordEnvironment() to record the pref again. | 319 // Call RecordEnvironment() to record the pref again. |
| 320 log.RecordEnvironment(std::vector<MetricsProvider*>(), | 320 log.RecordEnvironment(std::vector<MetricsProvider*>(), |
| 321 std::vector<variations::ActiveGroupId>(), | 321 std::vector<variations::ActiveGroupId>(), |
| 322 kInstallDate, kEnabledDate); | 322 kInstallDate, kEnabledDate); |
| 323 } | 323 } |
| 324 | 324 |
| 325 { | 325 { |
| 326 // Set the hash to a bad value. | 326 // Set the hash to a bad value. |
| 327 prefs_.SetString(kSystemProfileHashPref, "deadbeef"); | 327 prefs_.SetString(kSystemProfileHashPref, "deadbeef"); |
| 328 TestMetricsLog log( | 328 TestMetricsLog log( |
| 329 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); | 329 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); |
| 330 std::string app_version; | 330 std::string app_version; |
| 331 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs(&app_version)); | 331 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs(&app_version)); |
| 332 EXPECT_TRUE(app_version.empty()); | 332 EXPECT_TRUE(app_version.empty()); |
| 333 // Ensure that the prefs are cleared, even if the call failed. | 333 // Ensure that the prefs are not cleared, even if the call failed. |
| 334 EXPECT_TRUE(prefs_.GetString(kSystemProfilePref).empty()); | 334 EXPECT_FALSE(prefs_.GetString(kSystemProfilePref).empty()); |
| 335 EXPECT_TRUE(prefs_.GetString(kSystemProfileHashPref).empty()); | 335 EXPECT_FALSE(prefs_.GetString(kSystemProfileHashPref).empty()); |
| 336 } | 336 } |
| 337 } | 337 } |
| 338 | 338 |
| 339 TEST_F(MetricsLogTest, RecordEnvironmentEnableDefault) { | 339 TEST_F(MetricsLogTest, RecordEnvironmentEnableDefault) { |
| 340 TestMetricsServiceClient client; | 340 TestMetricsServiceClient client; |
| 341 TestMetricsLog log_unknown(kClientId, kSessionId, MetricsLog::ONGOING_LOG, | 341 TestMetricsLog log_unknown(kClientId, kSessionId, MetricsLog::ONGOING_LOG, |
| 342 &client, &prefs_); | 342 &client, &prefs_); |
| 343 | 343 |
| 344 std::vector<variations::ActiveGroupId> synthetic_trials; | 344 std::vector<variations::ActiveGroupId> synthetic_trials; |
| 345 | 345 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 TestMetricsServiceClient client; | 463 TestMetricsServiceClient client; |
| 464 client.set_product(kTestProduct); | 464 client.set_product(kTestProduct); |
| 465 TestMetricsLog log( | 465 TestMetricsLog log( |
| 466 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); | 466 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); |
| 467 // Check that the product is set to |kTestProduct|. | 467 // Check that the product is set to |kTestProduct|. |
| 468 EXPECT_TRUE(log.uma_proto().has_product()); | 468 EXPECT_TRUE(log.uma_proto().has_product()); |
| 469 EXPECT_EQ(kTestProduct, log.uma_proto().product()); | 469 EXPECT_EQ(kTestProduct, log.uma_proto().product()); |
| 470 } | 470 } |
| 471 | 471 |
| 472 } // namespace metrics | 472 } // namespace metrics |
| OLD | NEW |