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 <set> | 5 #include <set> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/macros.h" | |
10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
12 #include "base/metrics/histogram_base.h" | |
13 #include "base/metrics/histogram_samples.h" | |
14 #include "base/metrics/statistics_recorder.h" | |
11 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
12 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
13 #include "base/values.h" | 17 #include "base/values.h" |
14 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
19 #include "chrome/browser/prefs/pref_hash_store.h" | |
15 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/profiles/profile_impl.h" | 21 #include "chrome/browser/profiles/profile_impl.h" |
17 #include "chrome/browser/profiles/profile_info_cache.h" | 22 #include "chrome/browser/profiles/profile_info_cache.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 23 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/browser/profiles/profiles_state.h" | 24 #include "chrome/browser/profiles/profiles_state.h" |
20 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
21 #include "chrome/test/base/in_process_browser_test.h" | 26 #include "chrome/test/base/in_process_browser_test.h" |
22 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
23 | 28 |
24 namespace { | 29 namespace { |
(...skipping 26 matching lines...) Expand all Loading... | |
51 std::set<base::FilePath> profile_paths; | 56 std::set<base::FilePath> profile_paths; |
52 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) | 57 for (size_t i = 0; i < cache.GetNumberOfProfiles(); ++i) |
53 profile_paths.insert(cache.GetPathOfProfileAtIndex(i)); | 58 profile_paths.insert(cache.GetPathOfProfileAtIndex(i)); |
54 for (size_t i = 0; i < loaded_profiles.size(); ++i) | 59 for (size_t i = 0; i < loaded_profiles.size(); ++i) |
55 EXPECT_EQ(1U, profile_paths.erase(loaded_profiles[i]->GetPath())); | 60 EXPECT_EQ(1U, profile_paths.erase(loaded_profiles[i]->GetPath())); |
56 if (profile_paths.size()) | 61 if (profile_paths.size()) |
57 return *profile_paths.begin(); | 62 return *profile_paths.begin(); |
58 return base::FilePath(); | 63 return base::FilePath(); |
59 } | 64 } |
60 | 65 |
66 // Returns the number of times |histogram_name| was reported so far; adding the | |
67 // results of the first 100 buckets (there are only ~14 reporting IDs as of this | |
68 // writting; varies depending on the platform). If |expect_zero| is true, this | |
69 // method will explicitly report IDs that are non-zero for ease of diagnosis. | |
70 int GetTrackedPrefHistogramCount(const char* const histogram_name, | |
Bernhard Bauer
2014/01/30 10:36:53
Do we actually need both of these const's? I think
gab
2014/01/30 14:52:13
Sure, I like to put const as much as possible, but
| |
71 bool expect_zero) { | |
72 const base::HistogramBase* histogram = | |
73 base::StatisticsRecorder::FindHistogram(histogram_name); | |
74 if (!histogram) | |
75 return 0; | |
76 | |
77 scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); | |
78 int sum = 0; | |
79 for (int i = 0; i < 100; ++i) { | |
80 int count_for_id = samples->GetCount(i); | |
81 sum += count_for_id; | |
82 | |
83 if (expect_zero) | |
84 EXPECT_EQ(0, count_for_id) << "Faulty reporting_id: " << i; | |
85 } | |
86 return sum; | |
87 } | |
88 | |
61 } // namespace | 89 } // namespace |
62 | 90 |
63 typedef InProcessBrowserTest PrefHashBrowserTest; | 91 typedef InProcessBrowserTest PrefHashBrowserTest; |
64 | 92 |
65 IN_PROC_BROWSER_TEST_F(PrefHashBrowserTest, | 93 IN_PROC_BROWSER_TEST_F(PrefHashBrowserTest, |
66 PRE_PRE_InitializeUnloadedProfiles) { | 94 PRE_PRE_InitializeUnloadedProfiles) { |
67 if (!profiles::IsMultipleProfilesEnabled()) | 95 if (!profiles::IsMultipleProfilesEnabled()) |
68 return; | 96 return; |
69 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 97 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
70 | 98 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 return; | 147 return; |
120 | 148 |
121 const base::DictionaryValue* hashes = | 149 const base::DictionaryValue* hashes = |
122 g_browser_process->local_state()->GetDictionary( | 150 g_browser_process->local_state()->GetDictionary( |
123 prefs::kProfilePreferenceHashes); | 151 prefs::kProfilePreferenceHashes); |
124 | 152 |
125 // The deleted hash collection should be restored. | 153 // The deleted hash collection should be restored. |
126 ASSERT_EQ(3U, hashes->size()); | 154 ASSERT_EQ(3U, hashes->size()); |
127 | 155 |
128 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 156 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
129 const std::vector<Profile*> loaded_profiles = | |
130 profile_manager->GetLoadedProfiles(); | |
131 | 157 |
132 // Verify that only one profile was loaded. We assume that the unloaded | 158 // Verify that only one profile was loaded. We assume that the unloaded |
133 // profile is the same one that wasn't loaded in the last launch (i.e., it's | 159 // profile is the same one that wasn't loaded in the last launch (i.e., it's |
134 // the one whose hash store we reset, and the fact that it is now restored is | 160 // the one whose hash store we reset, and the fact that it is now restored is |
135 // evidence that we restored the hashes of an unloaded profile.). | 161 // evidence that we restored the hashes of an unloaded profile.). |
136 ASSERT_EQ(1U, loaded_profiles.size()); | 162 ASSERT_EQ(1U, profile_manager->GetLoadedProfiles().size()); |
163 | |
164 // Loading the first profile should only have produced unchanged reports. | |
165 EXPECT_EQ( | |
166 0, GetTrackedPrefHistogramCount( | |
167 "Settings.TrackedPreferenceChanged", true)); | |
168 EXPECT_EQ( | |
169 0, GetTrackedPrefHistogramCount( | |
170 "Settings.TrackedPreferenceCleared", true)); | |
171 EXPECT_EQ( | |
172 0, GetTrackedPrefHistogramCount( | |
173 "Settings.TrackedPreferenceInitialized", true)); | |
174 EXPECT_EQ( | |
175 0, GetTrackedPrefHistogramCount( | |
176 "Settings.TrackedPreferenceTrustedInitialized", true)); | |
177 EXPECT_EQ( | |
178 0, GetTrackedPrefHistogramCount( | |
179 "Settings.TrackedPreferenceMigrated", true)); | |
180 int initial_unchanged_count = | |
181 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceUnchanged", | |
182 false); | |
183 EXPECT_GT(initial_unchanged_count, 0); | |
184 | |
185 // Explicitly load the unloaded profile. | |
186 const Profile* second_profile = | |
187 profile_manager->GetProfile(GetUnloadedProfilePath()); | |
188 ASSERT_EQ(2U, profile_manager->GetLoadedProfiles().size()); | |
189 | |
190 // Loading the unexpected profile should only generate unchanged pings; and | |
191 // should have produced as many of them as loading the first profile. | |
192 EXPECT_EQ( | |
193 0, GetTrackedPrefHistogramCount( | |
194 "Settings.TrackedPreferenceChanged", true)); | |
195 EXPECT_EQ( | |
196 0, GetTrackedPrefHistogramCount( | |
197 "Settings.TrackedPreferenceCleared", true)); | |
198 EXPECT_EQ( | |
199 0, GetTrackedPrefHistogramCount( | |
200 "Settings.TrackedPreferenceInitialized", true)); | |
201 EXPECT_EQ( | |
202 0, GetTrackedPrefHistogramCount( | |
203 "Settings.TrackedPreferenceTrustedInitialized", true)); | |
204 EXPECT_EQ( | |
205 0, GetTrackedPrefHistogramCount( | |
206 "Settings.TrackedPreferenceMigrated", true)); | |
207 EXPECT_EQ( | |
208 initial_unchanged_count * 2, | |
209 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceUnchanged", | |
210 false)); | |
137 } | 211 } |
OLD | NEW |