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* histogram_name, bool expect_zero) { | |
71 const base::HistogramBase* histogram = | |
72 base::StatisticsRecorder::FindHistogram(histogram_name); | |
73 if (!histogram) | |
74 return 0; | |
75 | |
76 scoped_ptr<base::HistogramSamples> samples(histogram->SnapshotSamples()); | |
77 int sum = 0; | |
78 for (int i = 0; i < 100; ++i) { | |
79 int count_for_id = samples->GetCount(i); | |
80 sum += count_for_id; | |
81 | |
82 if (expect_zero) | |
83 EXPECT_EQ(0, count_for_id) << "Faulty reporting_id: " << i; | |
84 } | |
85 return sum; | |
86 } | |
87 | |
61 } // namespace | 88 } // namespace |
62 | 89 |
63 typedef InProcessBrowserTest PrefHashBrowserTest; | 90 typedef InProcessBrowserTest PrefHashBrowserTest; |
64 | 91 |
65 IN_PROC_BROWSER_TEST_F(PrefHashBrowserTest, | 92 IN_PROC_BROWSER_TEST_F(PrefHashBrowserTest, |
66 PRE_PRE_InitializeUnloadedProfiles) { | 93 PRE_PRE_InitializeUnloadedProfiles) { |
67 if (!profiles::IsMultipleProfilesEnabled()) | 94 if (!profiles::IsMultipleProfilesEnabled()) |
68 return; | 95 return; |
69 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 96 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
70 | 97 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 ProfileImpl::ResetPrefHashStore(unloaded_profile_path); | 137 ProfileImpl::ResetPrefHashStore(unloaded_profile_path); |
111 | 138 |
112 // One of the profile hash collections should be gone. | 139 // One of the profile hash collections should be gone. |
113 ASSERT_EQ(2U, hashes->size()); | 140 ASSERT_EQ(2U, hashes->size()); |
114 } | 141 } |
115 | 142 |
116 IN_PROC_BROWSER_TEST_F(PrefHashBrowserTest, | 143 IN_PROC_BROWSER_TEST_F(PrefHashBrowserTest, |
117 InitializeUnloadedProfiles) { | 144 InitializeUnloadedProfiles) { |
118 if (!profiles::IsMultipleProfilesEnabled()) | 145 if (!profiles::IsMultipleProfilesEnabled()) |
119 return; | 146 return; |
120 | 147 |
erikwright (departed)
2014/01/30 15:38:25
I'm confused. I would have thought there would be
gab
2014/01/30 15:58:52
They were initialized in the PRE_* tests; now they
erikwright (departed)
2014/01/30 16:05:58
At the very end of the previous test we Reset them
gab
2014/01/30 16:19:18
Oh you're referring to the initialization of the u
erikwright (departed)
2014/01/30 16:27:47
Ah, right.
Yeah, that would be a good idea, I thi
| |
121 const base::DictionaryValue* hashes = | 148 const base::DictionaryValue* hashes = |
122 g_browser_process->local_state()->GetDictionary( | 149 g_browser_process->local_state()->GetDictionary( |
123 prefs::kProfilePreferenceHashes); | 150 prefs::kProfilePreferenceHashes); |
124 | 151 |
125 // The deleted hash collection should be restored. | 152 // The deleted hash collection should be restored. |
126 ASSERT_EQ(3U, hashes->size()); | 153 ASSERT_EQ(3U, hashes->size()); |
127 | 154 |
128 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 155 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
129 const std::vector<Profile*> loaded_profiles = | |
130 profile_manager->GetLoadedProfiles(); | |
131 | 156 |
132 // Verify that only one profile was loaded. We assume that the unloaded | 157 // 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 | 158 // 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 | 159 // 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.). | 160 // evidence that we restored the hashes of an unloaded profile.). |
136 ASSERT_EQ(1U, loaded_profiles.size()); | 161 ASSERT_EQ(1U, profile_manager->GetLoadedProfiles().size()); |
162 | |
163 // Loading the first profile should only have produced unchanged reports. | |
164 EXPECT_EQ( | |
165 0, GetTrackedPrefHistogramCount( | |
166 "Settings.TrackedPreferenceChanged", true)); | |
167 EXPECT_EQ( | |
168 0, GetTrackedPrefHistogramCount( | |
169 "Settings.TrackedPreferenceCleared", true)); | |
170 EXPECT_EQ( | |
171 0, GetTrackedPrefHistogramCount( | |
172 "Settings.TrackedPreferenceInitialized", true)); | |
173 EXPECT_EQ( | |
174 0, GetTrackedPrefHistogramCount( | |
175 "Settings.TrackedPreferenceTrustedInitialized", true)); | |
176 EXPECT_EQ( | |
177 0, GetTrackedPrefHistogramCount( | |
178 "Settings.TrackedPreferenceMigrated", true)); | |
179 int initial_unchanged_count = | |
180 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceUnchanged", | |
181 false); | |
182 EXPECT_GT(initial_unchanged_count, 0); | |
183 | |
184 // Explicitly load the unloaded profile. | |
185 profile_manager->GetProfile(GetUnloadedProfilePath()); | |
186 ASSERT_EQ(2U, profile_manager->GetLoadedProfiles().size()); | |
187 | |
188 // Loading the unexpected profile should only generate unchanged pings; and | |
189 // should have produced as many of them as loading the first profile. | |
190 EXPECT_EQ( | |
191 0, GetTrackedPrefHistogramCount( | |
192 "Settings.TrackedPreferenceChanged", true)); | |
193 EXPECT_EQ( | |
194 0, GetTrackedPrefHistogramCount( | |
195 "Settings.TrackedPreferenceCleared", true)); | |
196 EXPECT_EQ( | |
197 0, GetTrackedPrefHistogramCount( | |
198 "Settings.TrackedPreferenceInitialized", true)); | |
199 EXPECT_EQ( | |
200 0, GetTrackedPrefHistogramCount( | |
201 "Settings.TrackedPreferenceTrustedInitialized", true)); | |
202 EXPECT_EQ( | |
203 0, GetTrackedPrefHistogramCount( | |
204 "Settings.TrackedPreferenceMigrated", true)); | |
205 EXPECT_EQ( | |
206 initial_unchanged_count * 2, | |
207 GetTrackedPrefHistogramCount("Settings.TrackedPreferenceUnchanged", | |
208 false)); | |
137 } | 209 } |
OLD | NEW |