OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/metrics/metrics_service.h" | 5 #include "chrome/browser/metrics/metrics_service.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 GetLocalState()->SetBoolean(crash_pref, true); | 367 GetLocalState()->SetBoolean(crash_pref, true); |
368 EXPECT_TRUE(MetricsServiceHelper::IsCrashReportingEnabled()); | 368 EXPECT_TRUE(MetricsServiceHelper::IsCrashReportingEnabled()); |
369 GetLocalState()->ClearPref(crash_pref); | 369 GetLocalState()->ClearPref(crash_pref); |
370 EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled()); | 370 EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled()); |
371 #endif // !defined(OS_CHROMEOS) | 371 #endif // !defined(OS_CHROMEOS) |
372 #else // defined(GOOGLE_CHROME_BUILD) | 372 #else // defined(GOOGLE_CHROME_BUILD) |
373 // Chromium branded browsers never have crash reporting enabled. | 373 // Chromium branded browsers never have crash reporting enabled. |
374 EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled()); | 374 EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled()); |
375 #endif // defined(GOOGLE_CHROME_BUILD) | 375 #endif // defined(GOOGLE_CHROME_BUILD) |
376 } | 376 } |
| 377 |
| 378 // Check that setting the kMetricsResetIds pref to true causes the client id to |
| 379 // be reset. We do not check that the low entropy source is reset because we |
| 380 // cannot ensure that metrics service won't generate the same id again. |
| 381 TEST_F(MetricsServiceTest, ResetMetricsIDs) { |
| 382 // Set an initial client id in prefs. It should not be possible for the |
| 383 // metrics service to generate this id randomly. |
| 384 const std::string kInitialClientId = "initial client id"; |
| 385 GetLocalState()->SetString(prefs::kMetricsClientID, kInitialClientId); |
| 386 |
| 387 // Make sure the initial client id isn't reset by the metrics service. |
| 388 { |
| 389 MetricsService service; |
| 390 service.ForceClientIdCreation(); |
| 391 EXPECT_TRUE(service.metrics_ids_reset_check_performed_); |
| 392 EXPECT_EQ(kInitialClientId, service.client_id_); |
| 393 } |
| 394 |
| 395 |
| 396 // Set the reset pref to cause the IDs to be reset. |
| 397 GetLocalState()->SetBoolean(prefs::kMetricsResetIds, true); |
| 398 |
| 399 // Cause the actual reset to happen. |
| 400 { |
| 401 MetricsService service; |
| 402 service.ForceClientIdCreation(); |
| 403 EXPECT_TRUE(service.metrics_ids_reset_check_performed_); |
| 404 EXPECT_NE(kInitialClientId, service.client_id_); |
| 405 |
| 406 service.GetLowEntropySource(); |
| 407 |
| 408 EXPECT_FALSE(GetLocalState()->GetBoolean(prefs::kMetricsResetIds)); |
| 409 } |
| 410 |
| 411 std::string new_client_id = |
| 412 GetLocalState()->GetString(prefs::kMetricsClientID); |
| 413 |
| 414 EXPECT_NE(kInitialClientId, new_client_id); |
| 415 } |
OLD | NEW |