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_state_manager.h" | 5 #include "components/metrics/metrics_state_manager.h" |
6 | 6 |
7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
8 #include <string> | 10 #include <string> |
9 | 11 |
10 #include "base/bind.h" | 12 #include "base/bind.h" |
11 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/macros.h" |
12 #include "base/prefs/testing_pref_service.h" | 15 #include "base/prefs/testing_pref_service.h" |
13 #include "components/metrics/client_info.h" | 16 #include "components/metrics/client_info.h" |
14 #include "components/metrics/metrics_pref_names.h" | 17 #include "components/metrics/metrics_pref_names.h" |
15 #include "components/metrics/metrics_service.h" | 18 #include "components/metrics/metrics_service.h" |
16 #include "components/metrics/metrics_switches.h" | 19 #include "components/metrics/metrics_switches.h" |
17 #include "components/variations/caching_permuted_entropy_provider.h" | 20 #include "components/variations/caching_permuted_entropy_provider.h" |
18 #include "components/variations/pref_names.h" | 21 #include "components/variations/pref_names.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
20 | 23 |
21 namespace metrics { | 24 namespace metrics { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 214 |
212 state_manager->GetLowEntropySource(); | 215 state_manager->GetLowEntropySource(); |
213 | 216 |
214 EXPECT_FALSE(prefs_.GetBoolean(prefs::kMetricsResetIds)); | 217 EXPECT_FALSE(prefs_.GetBoolean(prefs::kMetricsResetIds)); |
215 } | 218 } |
216 | 219 |
217 EXPECT_NE(kInitialClientId, prefs_.GetString(prefs::kMetricsClientID)); | 220 EXPECT_NE(kInitialClientId, prefs_.GetString(prefs::kMetricsClientID)); |
218 } | 221 } |
219 | 222 |
220 TEST_F(MetricsStateManagerTest, ForceClientIdCreation) { | 223 TEST_F(MetricsStateManagerTest, ForceClientIdCreation) { |
221 const int64 kFakeInstallationDate = 12345; | 224 const int64_t kFakeInstallationDate = 12345; |
222 prefs_.SetInt64(prefs::kInstallDate, kFakeInstallationDate); | 225 prefs_.SetInt64(prefs::kInstallDate, kFakeInstallationDate); |
223 | 226 |
224 const int64 test_begin_time = base::Time::Now().ToTimeT(); | 227 const int64_t test_begin_time = base::Time::Now().ToTimeT(); |
225 | 228 |
226 // Holds ClientInfo from previous scoped test for extra checks. | 229 // Holds ClientInfo from previous scoped test for extra checks. |
227 scoped_ptr<ClientInfo> previous_client_info; | 230 scoped_ptr<ClientInfo> previous_client_info; |
228 | 231 |
229 { | 232 { |
230 scoped_ptr<MetricsStateManager> state_manager(CreateStateManager()); | 233 scoped_ptr<MetricsStateManager> state_manager(CreateStateManager()); |
231 | 234 |
232 // client_id shouldn't be auto-generated if metrics reporting is not | 235 // client_id shouldn't be auto-generated if metrics reporting is not |
233 // enabled. | 236 // enabled. |
234 EXPECT_EQ(std::string(), state_manager->client_id()); | 237 EXPECT_EQ(std::string(), state_manager->client_id()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 stored_client_info_backup_->reporting_enabled_date); | 277 stored_client_info_backup_->reporting_enabled_date); |
275 | 278 |
276 // Re-forcing client id creation shouldn't cause another backup and | 279 // Re-forcing client id creation shouldn't cause another backup and |
277 // shouldn't affect the existing client id. | 280 // shouldn't affect the existing client id. |
278 stored_client_info_backup_.reset(); | 281 stored_client_info_backup_.reset(); |
279 state_manager->ForceClientIdCreation(); | 282 state_manager->ForceClientIdCreation(); |
280 EXPECT_FALSE(stored_client_info_backup_); | 283 EXPECT_FALSE(stored_client_info_backup_); |
281 EXPECT_EQ(previous_client_info->client_id, state_manager->client_id()); | 284 EXPECT_EQ(previous_client_info->client_id, state_manager->client_id()); |
282 } | 285 } |
283 | 286 |
284 const int64 kBackupInstallationDate = 1111; | 287 const int64_t kBackupInstallationDate = 1111; |
285 const int64 kBackupReportingEnabledDate = 2222; | 288 const int64_t kBackupReportingEnabledDate = 2222; |
286 const char kBackupClientId[] = "AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE"; | 289 const char kBackupClientId[] = "AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE"; |
287 fake_client_info_backup_.reset(new ClientInfo); | 290 fake_client_info_backup_.reset(new ClientInfo); |
288 fake_client_info_backup_->client_id = kBackupClientId; | 291 fake_client_info_backup_->client_id = kBackupClientId; |
289 fake_client_info_backup_->installation_date = kBackupInstallationDate; | 292 fake_client_info_backup_->installation_date = kBackupInstallationDate; |
290 fake_client_info_backup_->reporting_enabled_date = | 293 fake_client_info_backup_->reporting_enabled_date = |
291 kBackupReportingEnabledDate; | 294 kBackupReportingEnabledDate; |
292 | 295 |
293 { | 296 { |
294 // The existence of a backup should result in the same behaviour as | 297 // The existence of a backup should result in the same behaviour as |
295 // before if we already have a client id. | 298 // before if we already have a client id. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 | 376 |
374 // The metrics-reporting-enabled date will be reset to Now(). | 377 // The metrics-reporting-enabled date will be reset to Now(). |
375 EXPECT_GE(prefs_.GetInt64(prefs::kMetricsReportingEnabledTimestamp), | 378 EXPECT_GE(prefs_.GetInt64(prefs::kMetricsReportingEnabledTimestamp), |
376 previous_client_info->reporting_enabled_date); | 379 previous_client_info->reporting_enabled_date); |
377 | 380 |
378 stored_client_info_backup_.reset(); | 381 stored_client_info_backup_.reset(); |
379 } | 382 } |
380 } | 383 } |
381 | 384 |
382 } // namespace metrics | 385 } // namespace metrics |
OLD | NEW |