QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / chrome / browser / metrics / cloned_install_detector_unittest.cc
blob4c2647941965fcfd607636aa18364c3346199810
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 "components/metrics/cloned_install_detector.h"
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"
13 namespace metrics {
15 namespace {
17 const std::string kTestRawId = "test";
18 // Hashed machine id for |kTestRawId|.
19 const int kTestHashedId = 2216819;
21 } // namespace
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