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

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

Issue 2296543002: Quantify initial stability report edge cases. (Closed)
Patch Set: Change a metric's name Created 4 years, 3 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/metrics/metrics_pref_names.h » ('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>
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 EXPECT_TRUE(decoded_system_profile.ParseFromString(serialied_system_profile)); 269 EXPECT_TRUE(decoded_system_profile.ParseFromString(serialied_system_profile));
270 CheckSystemProfile(decoded_system_profile); 270 CheckSystemProfile(decoded_system_profile);
271 } 271 }
272 272
273 TEST_F(MetricsLogTest, LoadSavedEnvironmentFromPrefs) { 273 TEST_F(MetricsLogTest, LoadSavedEnvironmentFromPrefs) {
274 const char* kSystemProfilePref = prefs::kStabilitySavedSystemProfile; 274 const char* kSystemProfilePref = prefs::kStabilitySavedSystemProfile;
275 const char* kSystemProfileHashPref = 275 const char* kSystemProfileHashPref =
276 prefs::kStabilitySavedSystemProfileHash; 276 prefs::kStabilitySavedSystemProfileHash;
277 277
278 TestMetricsServiceClient client; 278 TestMetricsServiceClient client;
279 client.set_version_string("bogus version");
279 280
280 // The pref value is empty, so loading it from prefs should fail. 281 // The pref value is empty, so loading it from prefs should fail.
281 { 282 {
282 TestMetricsLog log( 283 TestMetricsLog log(
283 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); 284 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
284 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs()); 285 std::string app_version;
286 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs(&app_version));
287 EXPECT_TRUE(app_version.empty());
285 } 288 }
286 289
287 // Do a RecordEnvironment() call and check whether the pref is recorded. 290 // Do a RecordEnvironment() call and check whether the pref is recorded.
288 { 291 {
289 TestMetricsLog log( 292 TestMetricsLog log(
290 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); 293 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
291 log.RecordEnvironment(std::vector<MetricsProvider*>(), 294 log.RecordEnvironment(std::vector<MetricsProvider*>(),
292 std::vector<variations::ActiveGroupId>(), 295 std::vector<variations::ActiveGroupId>(),
293 kInstallDate, kEnabledDate); 296 kInstallDate, kEnabledDate);
294 EXPECT_FALSE(prefs_.GetString(kSystemProfilePref).empty()); 297 EXPECT_FALSE(prefs_.GetString(kSystemProfilePref).empty());
295 EXPECT_FALSE(prefs_.GetString(kSystemProfileHashPref).empty()); 298 EXPECT_FALSE(prefs_.GetString(kSystemProfileHashPref).empty());
296 } 299 }
297 300
298 { 301 {
299 TestMetricsLog log( 302 TestMetricsLog log(
300 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); 303 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
301 EXPECT_TRUE(log.LoadSavedEnvironmentFromPrefs()); 304 std::string app_version;
305 EXPECT_TRUE(log.LoadSavedEnvironmentFromPrefs(&app_version));
306 EXPECT_EQ("bogus version", app_version);
302 // Check some values in the system profile. 307 // Check some values in the system profile.
303 EXPECT_EQ(kInstallDateExpected, log.system_profile().install_date()); 308 EXPECT_EQ(kInstallDateExpected, log.system_profile().install_date());
304 EXPECT_EQ(kEnabledDateExpected, log.system_profile().uma_enabled_date()); 309 EXPECT_EQ(kEnabledDateExpected, log.system_profile().uma_enabled_date());
305 // Ensure that the call cleared the prefs. 310 // Ensure that the call cleared the prefs.
306 EXPECT_TRUE(prefs_.GetString(kSystemProfilePref).empty()); 311 EXPECT_TRUE(prefs_.GetString(kSystemProfilePref).empty());
307 EXPECT_TRUE(prefs_.GetString(kSystemProfileHashPref).empty()); 312 EXPECT_TRUE(prefs_.GetString(kSystemProfileHashPref).empty());
308 } 313 }
309 314
310 // 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.
311 { 316 {
312 TestMetricsLog log( 317 TestMetricsLog log(
313 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); 318 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
314 // Call RecordEnvironment() to record the pref again. 319 // Call RecordEnvironment() to record the pref again.
315 log.RecordEnvironment(std::vector<MetricsProvider*>(), 320 log.RecordEnvironment(std::vector<MetricsProvider*>(),
316 std::vector<variations::ActiveGroupId>(), 321 std::vector<variations::ActiveGroupId>(),
317 kInstallDate, kEnabledDate); 322 kInstallDate, kEnabledDate);
318 } 323 }
319 324
320 { 325 {
321 // Set the hash to a bad value. 326 // Set the hash to a bad value.
322 prefs_.SetString(kSystemProfileHashPref, "deadbeef"); 327 prefs_.SetString(kSystemProfileHashPref, "deadbeef");
323 TestMetricsLog log( 328 TestMetricsLog log(
324 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); 329 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
325 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs()); 330 std::string app_version;
331 EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs(&app_version));
332 EXPECT_TRUE(app_version.empty());
326 // Ensure that the prefs are cleared, even if the call failed. 333 // Ensure that the prefs are cleared, even if the call failed.
327 EXPECT_TRUE(prefs_.GetString(kSystemProfilePref).empty()); 334 EXPECT_TRUE(prefs_.GetString(kSystemProfilePref).empty());
328 EXPECT_TRUE(prefs_.GetString(kSystemProfileHashPref).empty()); 335 EXPECT_TRUE(prefs_.GetString(kSystemProfileHashPref).empty());
329 } 336 }
330 } 337 }
331 338
332 TEST_F(MetricsLogTest, RecordEnvironmentEnableDefault) { 339 TEST_F(MetricsLogTest, RecordEnvironmentEnableDefault) {
333 TestMetricsServiceClient client; 340 TestMetricsServiceClient client;
334 TestMetricsLog log_unknown(kClientId, kSessionId, MetricsLog::ONGOING_LOG, 341 TestMetricsLog log_unknown(kClientId, kSessionId, MetricsLog::ONGOING_LOG,
335 &client, &prefs_); 342 &client, &prefs_);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 TestMetricsServiceClient client; 463 TestMetricsServiceClient client;
457 client.set_product(kTestProduct); 464 client.set_product(kTestProduct);
458 TestMetricsLog log( 465 TestMetricsLog log(
459 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_); 466 kClientId, kSessionId, MetricsLog::ONGOING_LOG, &client, &prefs_);
460 // Check that the product is set to |kTestProduct|. 467 // Check that the product is set to |kTestProduct|.
461 EXPECT_TRUE(log.uma_proto().has_product()); 468 EXPECT_TRUE(log.uma_proto().has_product());
462 EXPECT_EQ(kTestProduct, log.uma_proto().product()); 469 EXPECT_EQ(kTestProduct, log.uma_proto().product());
463 } 470 }
464 471
465 } // namespace metrics 472 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/metrics_log.cc ('k') | components/metrics/metrics_pref_names.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698