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

Unified Diff: chrome/common/pref_service_unittest.cc

Issue 27354: Add FilePath setter/getter to pref service.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/pref_service.cc ('k') | chrome/test/data/pref_service/read.json » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/pref_service_unittest.cc
===================================================================
--- chrome/common/pref_service_unittest.cc (revision 10837)
+++ chrome/common/pref_service_unittest.cc (working copy)
@@ -20,26 +20,26 @@
virtual void SetUp() {
// Name a subdirectory of the temp directory.
ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &test_dir_));
- file_util::AppendToPath(&test_dir_, L"PrefServiceTest");
+ test_dir_ = test_dir_.AppendASCII("PrefServiceTest");
// Create a fresh, empty copy of this directory.
file_util::Delete(test_dir_, true);
file_util::CreateDirectory(test_dir_);
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_));
- file_util::AppendToPath(&data_dir_, L"pref_service");
+ data_dir_ = data_dir_.AppendASCII("pref_service");
ASSERT_TRUE(file_util::PathExists(data_dir_));
}
virtual void TearDown() {
// Clean up test directory
- ASSERT_TRUE(file_util::Delete(test_dir_, false));
+ ASSERT_TRUE(file_util::Delete(test_dir_, true));
ASSERT_FALSE(file_util::PathExists(test_dir_));
}
// the path to temporary directory used to contain the test operations
- std::wstring test_dir_;
+ FilePath test_dir_;
// the path to the directory where the test data is stored
- std::wstring data_dir_;
+ FilePath data_dir_;
};
class TestPrefObserver : public NotificationObserver {
@@ -85,13 +85,11 @@
PrefService prefs;
// Test that it fails on nonexistent file.
- std::wstring bogus_input_file = data_dir_;
- file_util::AppendToPath(&bogus_input_file, L"read.txt");
+ FilePath bogus_input_file = data_dir_.AppendASCII("read.txt");
EXPECT_FALSE(prefs.LoadPersistentPrefs(bogus_input_file));
// Test that the persistent value can be loaded.
- std::wstring input_file = data_dir_;
- file_util::AppendToPath(&input_file, L"read.json");
+ FilePath input_file = data_dir_.AppendASCII("read.json");
ASSERT_TRUE(file_util::PathExists(input_file));
ASSERT_TRUE(prefs.LoadPersistentPrefs(input_file));
@@ -108,6 +106,10 @@
EXPECT_EQ(cnn, prefs.GetString(prefs::kHomePage));
+ const wchar_t kSomeDirectory[] = L"some_directory";
+ FilePath some_path(FILE_PATH_LITERAL("/usr/sbin/"));
+ prefs.RegisterFilePathPref(kSomeDirectory, FilePath());
+
// Now test that the transient value overrides the persistent value,
// without actually altering the persistent store.
EXPECT_TRUE(prefs.transient()->SetString(prefs::kHomePage, microsoft));
@@ -126,13 +128,16 @@
prefs.SetInteger(kMaxTabs, 10);
EXPECT_EQ(10, prefs.GetInteger(kMaxTabs));
+ EXPECT_EQ(FilePath::StringType(FILE_PATH_LITERAL("/usr/local/")),
+ prefs.GetFilePath(kSomeDirectory).value());
+ prefs.SetFilePath(kSomeDirectory, some_path);
+ EXPECT_EQ(some_path.value(), prefs.GetFilePath(kSomeDirectory).value());
+
// Serialize and compare to expected output.
- std::wstring output_file = test_dir_;
- file_util::AppendToPath(&output_file, L"write.json");
+ FilePath output_file = test_dir_.AppendASCII("write.json");
prefs.pref_filename_ = output_file;
ASSERT_TRUE(prefs.SavePersistentPrefs(NULL));
- std::wstring golden_output_file = data_dir_;
- file_util::AppendToPath(&golden_output_file, L"write.golden.json");
+ FilePath golden_output_file = data_dir_.AppendASCII("write.golden.json");
ASSERT_TRUE(file_util::PathExists(golden_output_file));
ASSERT_TRUE(file_util::ContentsEqual(golden_output_file, output_file));
}
@@ -148,8 +153,7 @@
PrefService prefs;
- std::wstring persistent_file = data_dir_;
- file_util::AppendToPath(&persistent_file, L"overlay.json");
+ FilePath persistent_file = data_dir_.AppendASCII("overlay.json");
EXPECT_TRUE(prefs.LoadPersistentPrefs(persistent_file));
Value* transient_value;
@@ -275,8 +279,7 @@
TEST_F(PrefServiceTest, Observers) {
PrefService prefs;
- std::wstring input_file = data_dir_;
- file_util::AppendToPath(&input_file, L"read.json");
+ FilePath input_file = data_dir_.AppendASCII("read.json");
EXPECT_TRUE(file_util::PathExists(input_file));
EXPECT_TRUE(prefs.LoadPersistentPrefs(input_file));
@@ -316,6 +319,8 @@
prefs.RemovePrefObserver(pref_name, &obs2);
}
+// TODO(port): port this test to POSIX.
+#if defined(OS_WIN)
TEST_F(PrefServiceTest, LocalizedPrefs) {
PrefService prefs;
const wchar_t kBoolean[] = L"boolean";
@@ -337,6 +342,7 @@
prefs.SetString(kString, L"foo");
EXPECT_EQ(L"foo", prefs.GetString(kString));
}
+#endif
TEST_F(PrefServiceTest, NoObserverFire) {
PrefService prefs;
« no previous file with comments | « chrome/common/pref_service.cc ('k') | chrome/test/data/pref_service/read.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698