• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "components/metrics/cloned_install_detector.h"
6 
7 #include "base/prefs/testing_pref_service.h"
8 #include "components/metrics/machine_id_provider.h"
9 #include "components/metrics/metrics_pref_names.h"
10 #include "components/metrics/metrics_state_manager.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 
13 namespace metrics {
14 
15 namespace {
16 
17 const std::string kTestRawId = "test";
18 // Hashed machine id for |kTestRawId|.
19 const int kTestHashedId = 2216819;
20 
21 }  // namespace
22 
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.
TEST(ClonedInstallDetectorTest,SaveId)26 TEST(ClonedInstallDetectorTest, SaveId) {
27   TestingPrefServiceSimple prefs;
28   ClonedInstallDetector::RegisterPrefs(prefs.registry());
29 
30   scoped_ptr<ClonedInstallDetector> detector(
31       new ClonedInstallDetector(MachineIdProvider::CreateInstance()));
32 
33   detector->SaveMachineId(&prefs, kTestRawId);
34 
35   EXPECT_EQ(kTestHashedId, prefs.GetInteger(prefs::kMetricsMachineId));
36 }
37 
TEST(ClonedInstallDetectorTest,DetectClone)38 TEST(ClonedInstallDetectorTest, DetectClone) {
39   TestingPrefServiceSimple prefs;
40   MetricsStateManager::RegisterPrefs(prefs.registry());
41 
42   // Save a machine id that will cause a clone to be detected.
43   prefs.SetInteger(prefs::kMetricsMachineId, kTestHashedId + 1);
44 
45   scoped_ptr<ClonedInstallDetector> detector(
46       new ClonedInstallDetector(MachineIdProvider::CreateInstance()));
47 
48   detector->SaveMachineId(&prefs, kTestRawId);
49 
50   EXPECT_TRUE(prefs.GetBoolean(prefs::kMetricsResetIds));
51 }
52 
53 }  // namespace metrics
54