Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: chrome/browser/prefs/profile_pref_store_manager_unittest.cc

Issue 1143343005: chrome/browser: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop.h"
16 #include "base/prefs/json_pref_store.h" 15 #include "base/prefs/json_pref_store.h"
17 #include "base/prefs/persistent_pref_store.h" 16 #include "base/prefs/persistent_pref_store.h"
18 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
19 #include "base/prefs/pref_service_factory.h" 18 #include "base/prefs/pref_service_factory.h"
20 #include "base/prefs/pref_store.h" 19 #include "base/prefs/pref_store.h"
21 #include "base/prefs/testing_pref_service.h" 20 #include "base/prefs/testing_pref_service.h"
22 #include "base/run_loop.h" 21 #include "base/run_loop.h"
23 #include "base/strings/string_util.h" 22 #include "base/strings/string_util.h"
24 #include "base/values.h" 23 #include "base/values.h"
25 #include "chrome/browser/prefs/tracked/mock_validation_delegate.h" 24 #include "chrome/browser/prefs/tracked/mock_validation_delegate.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 pref_service_factory.Create(profile_pref_registry_.get())); 161 pref_service_factory.Create(profile_pref_registry_.get()));
163 162
164 ProfilePrefStoreManager::ClearResetTime(pref_service.get()); 163 ProfilePrefStoreManager::ClearResetTime(pref_service.get());
165 } 164 }
166 165
167 void InitializePrefs() { 166 void InitializePrefs() {
168 // According to the implementation of ProfilePrefStoreManager, this is 167 // According to the implementation of ProfilePrefStoreManager, this is
169 // actually a SegregatedPrefStore backed by two underlying pref stores. 168 // actually a SegregatedPrefStore backed by two underlying pref stores.
170 scoped_refptr<PersistentPrefStore> pref_store = 169 scoped_refptr<PersistentPrefStore> pref_store =
171 manager_->CreateProfilePrefStore( 170 manager_->CreateProfilePrefStore(
172 main_message_loop_.message_loop_proxy(), 171 main_message_loop_.task_runner(),
173 base::Bind(&ProfilePrefStoreManagerTest::RecordReset, 172 base::Bind(&ProfilePrefStoreManagerTest::RecordReset,
174 base::Unretained(this)), 173 base::Unretained(this)),
175 &mock_validation_delegate_); 174 &mock_validation_delegate_);
176 InitializePrefStore(pref_store.get()); 175 InitializePrefStore(pref_store.get());
177 pref_store = NULL; 176 pref_store = NULL;
178 base::RunLoop().RunUntilIdle(); 177 base::RunLoop().RunUntilIdle();
179 } 178 }
180 179
181 void DestroyPrefStore() { 180 void DestroyPrefStore() {
182 if (pref_store_.get()) { 181 if (pref_store_.get()) {
183 ClearResetRecorded(); 182 ClearResetRecorded();
184 // Force everything to be written to disk, triggering the PrefHashFilter 183 // Force everything to be written to disk, triggering the PrefHashFilter
185 // while our RegistryVerifier is watching. 184 // while our RegistryVerifier is watching.
186 pref_store_->CommitPendingWrite(); 185 pref_store_->CommitPendingWrite();
187 base::RunLoop().RunUntilIdle(); 186 base::RunLoop().RunUntilIdle();
188 187
189 pref_store_->RemoveObserver(&registry_verifier_); 188 pref_store_->RemoveObserver(&registry_verifier_);
190 pref_store_ = NULL; 189 pref_store_ = NULL;
191 // Nothing should have to happen on the background threads, but just in 190 // Nothing should have to happen on the background threads, but just in
192 // case... 191 // case...
193 base::RunLoop().RunUntilIdle(); 192 base::RunLoop().RunUntilIdle();
194 } 193 }
195 } 194 }
196 195
197 void InitializeDeprecatedCombinedProfilePrefStore() { 196 void InitializeDeprecatedCombinedProfilePrefStore() {
198 scoped_refptr<PersistentPrefStore> pref_store = 197 scoped_refptr<PersistentPrefStore> pref_store =
199 manager_->CreateDeprecatedCombinedProfilePrefStore( 198 manager_->CreateDeprecatedCombinedProfilePrefStore(
200 main_message_loop_.message_loop_proxy()); 199 main_message_loop_.task_runner());
201 InitializePrefStore(pref_store.get()); 200 InitializePrefStore(pref_store.get());
202 pref_store = NULL; 201 pref_store = NULL;
203 base::RunLoop().RunUntilIdle(); 202 base::RunLoop().RunUntilIdle();
204 } 203 }
205 204
206 void InitializePrefStore(PersistentPrefStore* pref_store) { 205 void InitializePrefStore(PersistentPrefStore* pref_store) {
207 pref_store->AddObserver(&registry_verifier_); 206 pref_store->AddObserver(&registry_verifier_);
208 PersistentPrefStore::PrefReadError error = pref_store->ReadPrefs(); 207 PersistentPrefStore::PrefReadError error = pref_store->ReadPrefs();
209 EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NO_FILE, error); 208 EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NO_FILE, error);
210 pref_store->SetValue(kTrackedAtomic, new base::StringValue(kFoobar), 209 pref_store->SetValue(kTrackedAtomic, new base::StringValue(kFoobar),
211 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 210 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
212 pref_store->SetValue(kProtectedAtomic, new base::StringValue(kHelloWorld), 211 pref_store->SetValue(kProtectedAtomic, new base::StringValue(kHelloWorld),
213 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 212 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
214 pref_store->SetValue(kUnprotectedPref, new base::StringValue(kFoobar), 213 pref_store->SetValue(kUnprotectedPref, new base::StringValue(kFoobar),
215 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 214 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
216 pref_store->RemoveObserver(&registry_verifier_); 215 pref_store->RemoveObserver(&registry_verifier_);
217 pref_store->CommitPendingWrite(); 216 pref_store->CommitPendingWrite();
218 base::RunLoop().RunUntilIdle(); 217 base::RunLoop().RunUntilIdle();
219 } 218 }
220 219
221 void LoadExistingPrefs() { 220 void LoadExistingPrefs() {
222 DestroyPrefStore(); 221 DestroyPrefStore();
223 pref_store_ = manager_->CreateProfilePrefStore( 222 pref_store_ = manager_->CreateProfilePrefStore(
224 main_message_loop_.message_loop_proxy(), 223 main_message_loop_.task_runner(),
225 base::Bind(&ProfilePrefStoreManagerTest::RecordReset, 224 base::Bind(&ProfilePrefStoreManagerTest::RecordReset,
226 base::Unretained(this)), 225 base::Unretained(this)),
227 NULL); 226 NULL);
228 pref_store_->AddObserver(&registry_verifier_); 227 pref_store_->AddObserver(&registry_verifier_);
229 pref_store_->ReadPrefs(); 228 pref_store_->ReadPrefs();
230 } 229 }
231 230
232 void ReplaceStringInPrefs(const std::string& find, 231 void ReplaceStringInPrefs(const std::string& find,
233 const std::string& replace) { 232 const std::string& replace) {
234 base::FileEnumerator file_enum( 233 base::FileEnumerator file_enum(
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); 574 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld);
576 575
577 // Trigger the logic that migrates it back to the unprotected preferences 576 // Trigger the logic that migrates it back to the unprotected preferences
578 // file. 577 // file.
579 pref_store_->SetValue(kProtectedAtomic, new base::StringValue(kGoodbyeWorld), 578 pref_store_->SetValue(kProtectedAtomic, new base::StringValue(kGoodbyeWorld),
580 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 579 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
581 LoadExistingPrefs(); 580 LoadExistingPrefs();
582 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); 581 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld);
583 VerifyResetRecorded(false); 582 VerifyResetRecorded(false);
584 } 583 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/leveldb_pref_store_unittest.cc ('k') | chrome/browser/prerender/prerender_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698