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 "chrome/browser/metrics/cloned_install_detector.h" | 5 #include "chrome/browser/metrics/cloned_install_detector.h" |
6 | 6 |
7 #include "base/prefs/testing_pref_service.h" | 7 #include "base/prefs/testing_pref_service.h" |
8 #include "chrome/browser/metrics/machine_id_provider.h" | 8 #include "chrome/browser/metrics/machine_id_provider.h" |
9 #include "chrome/browser/metrics/metrics_service.h" | |
9 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 namespace metrics { | 13 namespace metrics { |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 const std::string kTestRawId = "test"; | 17 const std::string kTestRawId = "test"; |
17 // Hashed machine id for |kTestRawId|. | 18 // Hashed machine id for |kTestRawId|. |
18 const int kTestHashedId = 2216819; | 19 const int kTestHashedId = 2216819; |
19 | 20 |
20 } // namespace | 21 } // namespace |
21 | 22 |
22 // TODO(jwd): Change this test to test the full flow and histogram outputs. It | 23 // TODO(jwd): Change these test to test the full flow and histogram outputs. It |
23 // should also remove the need to make the test a friend of | 24 // should also remove the need to make the test a friend of |
24 // ClonedInstallDetector. | 25 // ClonedInstallDetector. |
25 TEST(ClonedInstallDetectorTest, SaveId) { | 26 TEST(ClonedInstallDetectorTest, SaveId) { |
26 TestingPrefServiceSimple prefs; | 27 TestingPrefServiceSimple prefs; |
27 ClonedInstallDetector::RegisterPrefs(prefs.registry()); | 28 ClonedInstallDetector::RegisterPrefs(prefs.registry()); |
28 | 29 |
29 scoped_ptr<ClonedInstallDetector> detector( | 30 scoped_ptr<ClonedInstallDetector> detector( |
30 new ClonedInstallDetector(MachineIdProvider::CreateInstance())); | 31 new ClonedInstallDetector(MachineIdProvider::CreateInstance())); |
31 | 32 |
32 detector->SaveMachineId(&prefs, kTestRawId); | 33 detector->SaveMachineId(&prefs, kTestRawId); |
33 | 34 |
34 EXPECT_EQ(kTestHashedId, prefs.GetInteger(prefs::kMetricsMachineId)); | 35 EXPECT_EQ(kTestHashedId, prefs.GetInteger(prefs::kMetricsMachineId)); |
35 } | 36 } |
36 | 37 |
38 TEST(ClonedInstallDetectorTest, DetectClone) { | |
39 TestingPrefServiceSimple prefs; | |
40 ClonedInstallDetector::RegisterPrefs(prefs.registry()); | |
41 MetricsService::RegisterPrefs(prefs.registry()); | |
42 | |
43 // Save a machine id that will cause a clone to be detected. | |
44 prefs.SetInteger(prefs::kMetricsMachineId, kTestHashedId + 1); | |
45 | |
46 scoped_ptr<ClonedInstallDetector> detector( | |
47 new ClonedInstallDetector(MachineIdProvider::CreateInstance())); | |
48 | |
49 detector->SaveMachineId(&prefs, kTestRawId); | |
50 | |
51 EXPECT_TRUE(prefs::kMetricsResetIds); | |
Alexei Svitkine (slow)
2014/03/28 19:02:50
This needs to actually fetch the pref and check it
jwd
2014/03/28 19:43:15
Heh, yes, good catch.
Done
| |
52 } | |
53 | |
37 } // namespace metrics | 54 } // namespace metrics |
OLD | NEW |