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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 void ReplaceStringInPrefs(const std::string& find, | 231 void ReplaceStringInPrefs(const std::string& find, |
232 const std::string& replace) { | 232 const std::string& replace) { |
233 base::FileEnumerator file_enum( | 233 base::FileEnumerator file_enum( |
234 profile_dir_.path(), true, base::FileEnumerator::FILES); | 234 profile_dir_.path(), true, base::FileEnumerator::FILES); |
235 | 235 |
236 for (base::FilePath path = file_enum.Next(); !path.empty(); | 236 for (base::FilePath path = file_enum.Next(); !path.empty(); |
237 path = file_enum.Next()) { | 237 path = file_enum.Next()) { |
238 // Tamper with the file's contents | 238 // Tamper with the file's contents |
239 std::string contents; | 239 std::string contents; |
240 EXPECT_TRUE(base::ReadFileToString(path, &contents)); | 240 EXPECT_TRUE(base::ReadFileToString(path, &contents)); |
241 ReplaceSubstringsAfterOffset(&contents, 0u, find, replace); | 241 base::ReplaceSubstringsAfterOffset(&contents, 0u, find, replace); |
242 EXPECT_EQ(static_cast<int>(contents.length()), | 242 EXPECT_EQ(static_cast<int>(contents.length()), |
243 base::WriteFile(path, contents.c_str(), contents.length())); | 243 base::WriteFile(path, contents.c_str(), contents.length())); |
244 } | 244 } |
245 } | 245 } |
246 | 246 |
247 void ExpectStringValueEquals(const std::string& name, | 247 void ExpectStringValueEquals(const std::string& name, |
248 const std::string& expected) { | 248 const std::string& expected) { |
249 const base::Value* value = NULL; | 249 const base::Value* value = NULL; |
250 std::string as_string; | 250 std::string as_string; |
251 if (!pref_store_->GetValue(name, &value)) { | 251 if (!pref_store_->GetValue(name, &value)) { |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); | 574 ExpectStringValueEquals(kProtectedAtomic, kHelloWorld); |
575 | 575 |
576 // Trigger the logic that migrates it back to the unprotected preferences | 576 // Trigger the logic that migrates it back to the unprotected preferences |
577 // file. | 577 // file. |
578 pref_store_->SetValue(kProtectedAtomic, new base::StringValue(kGoodbyeWorld), | 578 pref_store_->SetValue(kProtectedAtomic, new base::StringValue(kGoodbyeWorld), |
579 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 579 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
580 LoadExistingPrefs(); | 580 LoadExistingPrefs(); |
581 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); | 581 ExpectStringValueEquals(kProtectedAtomic, kGoodbyeWorld); |
582 VerifyResetRecorded(false); | 582 VerifyResetRecorded(false); |
583 } | 583 } |
OLD | NEW |