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/prefs/profile_pref_store_manager.h" | 5 #include "chrome/browser/prefs/profile_pref_store_manager.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
84 const size_t kReportingIdCount = 3u; | 84 const size_t kReportingIdCount = 3u; |
85 | 85 |
86 } // namespace | 86 } // namespace |
87 | 87 |
88 class ProfilePrefStoreManagerTest : public testing::Test { | 88 class ProfilePrefStoreManagerTest : public testing::Test { |
89 public: | 89 public: |
90 ProfilePrefStoreManagerTest() | 90 ProfilePrefStoreManagerTest() |
91 : configuration_(kConfiguration, | 91 : configuration_(kConfiguration, |
92 kConfiguration + arraysize(kConfiguration)), | 92 kConfiguration + arraysize(kConfiguration)), |
93 profile_pref_registry_(new user_prefs::PrefRegistrySyncable), | 93 profile_pref_registry_(new user_prefs::PrefRegistrySyncable), |
94 registry_verifier_(profile_pref_registry_), | 94 registry_verifier_(profile_pref_registry_.get()), |
gab
2014/08/26 19:29:56
RegistryVerifier() should take a scoped_refptr as
| |
95 seed_("seed"), | 95 seed_("seed"), |
96 reset_recorded_(false) {} | 96 reset_recorded_(false) {} |
97 | 97 |
98 virtual void SetUp() OVERRIDE { | 98 virtual void SetUp() OVERRIDE { |
99 ProfilePrefStoreManager::RegisterPrefs(local_state_.registry()); | 99 ProfilePrefStoreManager::RegisterPrefs(local_state_.registry()); |
100 ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_); | 100 ProfilePrefStoreManager::RegisterProfilePrefs(profile_pref_registry_.get()); |
101 for (const PrefHashFilter::TrackedPreferenceMetadata* it = kConfiguration; | 101 for (const PrefHashFilter::TrackedPreferenceMetadata* it = kConfiguration; |
102 it != kConfiguration + arraysize(kConfiguration); | 102 it != kConfiguration + arraysize(kConfiguration); |
103 ++it) { | 103 ++it) { |
104 if (it->strategy == PrefHashFilter::TRACKING_STRATEGY_ATOMIC) { | 104 if (it->strategy == PrefHashFilter::TRACKING_STRATEGY_ATOMIC) { |
105 profile_pref_registry_->RegisterStringPref( | 105 profile_pref_registry_->RegisterStringPref( |
106 it->name, | 106 it->name, |
107 std::string(), | 107 std::string(), |
108 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 108 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
109 } else { | 109 } else { |
110 profile_pref_registry_->RegisterDictionaryPref( | 110 profile_pref_registry_->RegisterDictionaryPref( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 protected: | 145 protected: |
146 // Verifies whether a reset was reported via the RecordReset() hook. Also | 146 // Verifies whether a reset was reported via the RecordReset() hook. Also |
147 // verifies that GetResetTime() was set (or not) accordingly. | 147 // verifies that GetResetTime() was set (or not) accordingly. |
148 void VerifyResetRecorded(bool reset_expected) { | 148 void VerifyResetRecorded(bool reset_expected) { |
149 EXPECT_EQ(reset_expected, reset_recorded_); | 149 EXPECT_EQ(reset_expected, reset_recorded_); |
150 | 150 |
151 base::PrefServiceFactory pref_service_factory; | 151 base::PrefServiceFactory pref_service_factory; |
152 pref_service_factory.set_user_prefs(pref_store_); | 152 pref_service_factory.set_user_prefs(pref_store_); |
153 | 153 |
154 scoped_ptr<PrefService> pref_service( | 154 scoped_ptr<PrefService> pref_service( |
155 pref_service_factory.Create(profile_pref_registry_)); | 155 pref_service_factory.Create(profile_pref_registry_.get())); |
gab
2014/08/26 19:29:56
PrefServiceFactory::Create() should take a scoped_
| |
156 | 156 |
157 EXPECT_EQ( | 157 EXPECT_EQ( |
158 reset_expected, | 158 reset_expected, |
159 !ProfilePrefStoreManager::GetResetTime(pref_service.get()).is_null()); | 159 !ProfilePrefStoreManager::GetResetTime(pref_service.get()).is_null()); |
160 } | 160 } |
161 | 161 |
162 void ClearResetRecorded() { | 162 void ClearResetRecorded() { |
163 reset_recorded_ = false; | 163 reset_recorded_ = false; |
164 | 164 |
165 base::PrefServiceFactory pref_service_factory; | 165 base::PrefServiceFactory pref_service_factory; |
166 pref_service_factory.set_user_prefs(pref_store_); | 166 pref_service_factory.set_user_prefs(pref_store_); |
167 | 167 |
168 scoped_ptr<PrefService> pref_service( | 168 scoped_ptr<PrefService> pref_service( |
169 pref_service_factory.Create(profile_pref_registry_)); | 169 pref_service_factory.Create(profile_pref_registry_.get())); |
gab
2014/08/26 19:29:56
Same as above.
| |
170 | 170 |
171 ProfilePrefStoreManager::ClearResetTime(pref_service.get()); | 171 ProfilePrefStoreManager::ClearResetTime(pref_service.get()); |
172 } | 172 } |
173 | 173 |
174 void InitializePrefs() { | 174 void InitializePrefs() { |
175 // According to the implementation of ProfilePrefStoreManager, this is | 175 // According to the implementation of ProfilePrefStoreManager, this is |
176 // actually a SegregatedPrefStore backed by two underlying pref stores. | 176 // actually a SegregatedPrefStore backed by two underlying pref stores. |
177 scoped_refptr<PersistentPrefStore> pref_store = | 177 scoped_refptr<PersistentPrefStore> pref_store = |
178 manager_->CreateProfilePrefStore( | 178 manager_->CreateProfilePrefStore( |
179 main_message_loop_.message_loop_proxy(), | 179 main_message_loop_.message_loop_proxy(), |
180 base::Bind(&ProfilePrefStoreManagerTest::RecordReset, | 180 base::Bind(&ProfilePrefStoreManagerTest::RecordReset, |
181 base::Unretained(this)), | 181 base::Unretained(this)), |
182 &mock_validation_delegate_); | 182 &mock_validation_delegate_); |
183 InitializePrefStore(pref_store); | 183 InitializePrefStore(pref_store.get()); |
184 pref_store = NULL; | 184 pref_store = NULL; |
185 base::RunLoop().RunUntilIdle(); | 185 base::RunLoop().RunUntilIdle(); |
186 } | 186 } |
187 | 187 |
188 void DestroyPrefStore() { | 188 void DestroyPrefStore() { |
189 if (pref_store_) { | 189 if (pref_store_.get()) { |
190 ClearResetRecorded(); | 190 ClearResetRecorded(); |
191 // Force everything to be written to disk, triggering the PrefHashFilter | 191 // Force everything to be written to disk, triggering the PrefHashFilter |
192 // while our RegistryVerifier is watching. | 192 // while our RegistryVerifier is watching. |
193 pref_store_->CommitPendingWrite(); | 193 pref_store_->CommitPendingWrite(); |
194 base::RunLoop().RunUntilIdle(); | 194 base::RunLoop().RunUntilIdle(); |
195 | 195 |
196 pref_store_->RemoveObserver(®istry_verifier_); | 196 pref_store_->RemoveObserver(®istry_verifier_); |
197 pref_store_ = NULL; | 197 pref_store_ = NULL; |
198 // Nothing should have to happen on the background threads, but just in | 198 // Nothing should have to happen on the background threads, but just in |
199 // case... | 199 // case... |
200 base::RunLoop().RunUntilIdle(); | 200 base::RunLoop().RunUntilIdle(); |
201 } | 201 } |
202 } | 202 } |
203 | 203 |
204 void InitializeDeprecatedCombinedProfilePrefStore() { | 204 void InitializeDeprecatedCombinedProfilePrefStore() { |
205 scoped_refptr<PersistentPrefStore> pref_store = | 205 scoped_refptr<PersistentPrefStore> pref_store = |
206 manager_->CreateDeprecatedCombinedProfilePrefStore( | 206 manager_->CreateDeprecatedCombinedProfilePrefStore( |
207 main_message_loop_.message_loop_proxy()); | 207 main_message_loop_.message_loop_proxy()); |
208 InitializePrefStore(pref_store); | 208 InitializePrefStore(pref_store.get()); |
209 pref_store = NULL; | 209 pref_store = NULL; |
210 base::RunLoop().RunUntilIdle(); | 210 base::RunLoop().RunUntilIdle(); |
211 } | 211 } |
212 | 212 |
213 void InitializePrefStore(PersistentPrefStore* pref_store) { | 213 void InitializePrefStore(PersistentPrefStore* pref_store) { |
214 pref_store->AddObserver(®istry_verifier_); | 214 pref_store->AddObserver(®istry_verifier_); |
215 PersistentPrefStore::PrefReadError error = pref_store->ReadPrefs(); | 215 PersistentPrefStore::PrefReadError error = pref_store->ReadPrefs(); |
216 EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NO_FILE, error); | 216 EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NO_FILE, error); |
217 pref_store->SetValue(kTrackedAtomic, new base::StringValue(kFoobar)); | 217 pref_store->SetValue(kTrackedAtomic, new base::StringValue(kFoobar)); |
218 pref_store->SetValue(kProtectedAtomic, new base::StringValue(kHelloWorld)); | 218 pref_store->SetValue(kProtectedAtomic, new base::StringValue(kHelloWorld)); |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 LoadExistingPrefs(); | 578 LoadExistingPrefs(); |
579 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); | 579 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
580 | 580 |
581 // Trigger the logic that migrates it back to the unprotected preferences | 581 // Trigger the logic that migrates it back to the unprotected preferences |
582 // file. | 582 // file. |
583 pref_store_->SetValue(kProtectedAtomic, new base::StringValue(kGoodbyeWorld)); | 583 pref_store_->SetValue(kProtectedAtomic, new base::StringValue(kGoodbyeWorld)); |
584 LoadExistingPrefs(); | 584 LoadExistingPrefs(); |
585 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); | 585 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); |
586 VerifyResetRecorded(false); | 586 VerifyResetRecorded(false); |
587 } | 587 } |
OLD | NEW |