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
3 // found in the LICENSE file.
5 #include "chrome/browser/metrics/cloned_install_detector.h"
7 #include "base/prefs/testing_pref_service.h"
8 #include "chrome/browser/metrics/machine_id_provider.h"
9 #include "chrome/browser/metrics/metrics_state_manager.h"
10 #include "chrome/common/pref_names.h"
11 #include "testing/gtest/include/gtest/gtest.h"
17 const std::string kTestRawId = "test";
18 // Hashed machine id for |kTestRawId|.
19 const int kTestHashedId = 2216819;
23 // TODO(jwd): Change these test to test the full flow and histogram outputs. It
24 // should also remove the need to make the test a friend of
25 // ClonedInstallDetector.
26 TEST(ClonedInstallDetectorTest, SaveId) {
27 TestingPrefServiceSimple prefs;
28 ClonedInstallDetector::RegisterPrefs(prefs.registry());
30 scoped_ptr<ClonedInstallDetector> detector(
31 new ClonedInstallDetector(MachineIdProvider::CreateInstance()));
33 detector->SaveMachineId(&prefs, kTestRawId);
35 EXPECT_EQ(kTestHashedId, prefs.GetInteger(prefs::kMetricsMachineId));
38 TEST(ClonedInstallDetectorTest, DetectClone) {
39 TestingPrefServiceSimple prefs;
40 MetricsStateManager::RegisterPrefs(prefs.registry());
42 // Save a machine id that will cause a clone to be detected.
43 prefs.SetInteger(prefs::kMetricsMachineId, kTestHashedId + 1);
45 scoped_ptr<ClonedInstallDetector> detector(
46 new ClonedInstallDetector(MachineIdProvider::CreateInstance()));
48 detector->SaveMachineId(&prefs, kTestRawId);
50 EXPECT_TRUE(prefs.GetBoolean(prefs::kMetricsResetIds));
53 } // namespace metrics